1.2.4 • Published 5 months ago

siyuan-package-custom-block v1.2.4

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Siyuan Package Custom Block

SiYuan Custom Block helper based on HTML block.

Core logic

Add a root node in HTML block as a root of morden app. Storage initial data in the data-custom-bloc k-data attribute of element, data-type for block type identifier of current plugin, data-plugin for different plugin.

Generate Content Example

<div><div data-custom-block-id="20230817220934-xfjsliu" data-custom-block-data="%7B%7D" data-type="DataviewBlock" data-plugin="siyuan-plugin-dataview"></div></div>
{: id="20230817220934-xfjsliu" updated="20237422934"}

Plugin Code Example

const siyuan = require("siyuan");
const { CustomBlock, CustomBlockManager } = require('siyuan-package-custom-block');

class CarouselBlock extends CustomBlock {
  static type = "CarouselBlock";
  static css = ".hello { color: red; }";

  onBlockMenu(e) {
    // e.detail: BlocksElement, menu, protyle
  }

  onMount(el, data, plugin) {
    console.log("hello world");
    el.insertAdjacentHTML(
      "afterbegin",
      `<div class="hello">hello ${data.name}</div>`
    );
  }
}

module.exports = class P extends siyuan.Plugin {
  onload() {
    CustomBlockManager.init(this);
    CustomBlockManager.load(CarouselBlock);
    const content = CustomBlockManager.buildBlock(CarouselBlock.type, {
      name: "123",
    });
    console.log(content);
    navigator.clipboard.writeText(content);
  }
};

Attention

Update block is not working, still work on it.

1.2.0

5 months ago

1.1.0

5 months ago

1.2.4

5 months ago

1.2.3

5 months ago

1.2.2

5 months ago

1.2.1

5 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago