Merge pull request #7 from siyuan-note/dev
Up to date with `plugin-sample` v0.0.5
This commit is contained in:
commit
c8497611ce
7 changed files with 279 additions and 46 deletions
23
README.md
23
README.md
|
@ -178,3 +178,26 @@ The github action is included in this sample, you can use it to publish your new
|
||||||
prerelease: true # change this to false
|
prerelease: true # change this to false
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## How to remove svelte dependencies
|
||||||
|
|
||||||
|
This plugin is packaged in vite and provides a dependency on the svelte framework. However, in practice some developers may not want to use svelte and only want to use the vite package.
|
||||||
|
|
||||||
|
In fact you can use this template without using svelte without any modifications at all. The compilation-related parts of the svelte compilation are loaded into the vite workflow as plugins, so even if you don't have svelte in your project, it won't matter much.
|
||||||
|
|
||||||
|
If you insist on removing all svelte dependencies so that they do not pollute your workspace, you can perform the following steps. 1.
|
||||||
|
|
||||||
|
1. delete the
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"@sveltejs/vite-plugin-svelte": "^2.0.3",
|
||||||
|
"@tsconfig/svelte": "^4.0.1",
|
||||||
|
"svelte": "^3.57.0"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
2. delete the `svelte.config.js` file
|
||||||
|
3. delete the following line from the `vite.config.js` file
|
||||||
|
- Line 6: `import { svelte } from "@sveltejs/vite-plugin-svelte"`
|
||||||
|
- Line 20: `svelte(),`
|
||||||
|
4. delete line 37 of `tsconfig.json` from `"svelte"` 5.
|
||||||
|
5. re-run `pnpm i`
|
||||||
|
|
|
@ -167,4 +167,25 @@ PR 社区集市仓库。
|
||||||
prerelease: true # 把这个改为 false
|
prerelease: true # 把这个改为 false
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 如何去掉 svelte 依赖
|
||||||
|
|
||||||
|
本插件使用 vite 打包,并提供了 svelte 框架依赖。不过实际情况下可能有些开发者并不想要 svelte,只希望使用 vite 打包。
|
||||||
|
|
||||||
|
实际上你可以完全不做任何修改,就可以在不使用 svelte 的前提下使用这个模板。与 svelte 编译的编译相关的部分是以插件的形式载入到 vite 的工作流中,所以即使你的项目里面没有 svelte,也不会有太大的影响。
|
||||||
|
|
||||||
|
如果你执意希望删除掉所有 svelte 依赖以免它们污染你的工作空间,可以执行一下步骤:
|
||||||
|
|
||||||
|
1. 删掉 package.json 中的
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"@sveltejs/vite-plugin-svelte": "^2.0.3",
|
||||||
|
"@tsconfig/svelte": "^4.0.1",
|
||||||
|
"svelte": "^3.57.0"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
2. 删掉 `svelte.config.js` 文件
|
||||||
|
3. 删掉 `vite.config.js` 文件中的
|
||||||
|
- 第六行: `import { svelte } from "@sveltejs/vite-plugin-svelte"`
|
||||||
|
- 第二十行: `svelte(),`
|
||||||
|
4. 删掉 `tsconfig.json` 中 37 行 `"svelte"`
|
||||||
|
5. 重新执行 `pnpm i`
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
<!--
|
|
||||||
* Copyright (c) 2023 frostime. All rights reserved.
|
|
||||||
* https://github.com/frostime/sy-plugin-template-vite
|
|
||||||
-->
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onDestroy, onMount } from "svelte";
|
import { onDestroy, onMount } from "svelte";
|
||||||
import { version } from "./api";
|
import { version } from "./api";
|
||||||
import { showMessage } from "siyuan";
|
import { showMessage } from "siyuan";
|
||||||
|
import Typo from "./libs/b3-typography.svelte";
|
||||||
|
|
||||||
export let name: string;
|
export let name: string;
|
||||||
export let i18n: any;
|
export let i18n: any;
|
||||||
|
|
||||||
|
@ -43,9 +41,10 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<Typo>
|
||||||
|
<h2>Wellcome to plugin sample with vite & svelte</h2>
|
||||||
<p>{@html i18n.makesure}</p>
|
<p>{@html i18n.makesure}</p>
|
||||||
</div>
|
</Typo>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
120
src/index.ts
120
src/index.ts
|
@ -1,7 +1,3 @@
|
||||||
/**
|
|
||||||
* Copyright (c) 2023 frostime. All rights reserved.
|
|
||||||
* https://github.com/frostime/sy-plugin-template-vite
|
|
||||||
*/
|
|
||||||
import { Plugin, showMessage, confirm, Dialog, Menu, isMobile, openTab } from "siyuan";
|
import { Plugin, showMessage, confirm, Dialog, Menu, isMobile, openTab } from "siyuan";
|
||||||
import "./index.scss";
|
import "./index.scss";
|
||||||
|
|
||||||
|
@ -15,14 +11,11 @@ const DOCK_TYPE = "dock_tab";
|
||||||
|
|
||||||
export default class SamplePlugin extends Plugin {
|
export default class SamplePlugin extends Plugin {
|
||||||
|
|
||||||
counter: { [key: string]: number } = {
|
|
||||||
hello: 0,
|
|
||||||
};
|
|
||||||
private customTab: () => any;
|
private customTab: () => any;
|
||||||
|
|
||||||
async onload() {
|
async onload() {
|
||||||
showMessage("Hello SiYuan Plugin");
|
showMessage("Hello SiYuan Plugin");
|
||||||
console.log(this.i18n.helloPlugin);
|
this.data[STORAGE_NAME] = {readonlyText: "Readonly"};
|
||||||
|
|
||||||
const topBarElement = this.addTopBar({
|
const topBarElement = this.addTopBar({
|
||||||
icon: "iconEmoji",
|
icon: "iconEmoji",
|
||||||
|
@ -79,10 +72,35 @@ export default class SamplePlugin extends Plugin {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onLayoutReady() {
|
||||||
|
this.loadData(STORAGE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
onunload() {
|
||||||
|
console.log(this.i18n.byePlugin);
|
||||||
|
showMessage("Goodbye SiYuan Plugin");
|
||||||
|
console.log("onunload");
|
||||||
|
}
|
||||||
|
|
||||||
private wsEvent({ detail }: any) {
|
private wsEvent({ detail }: any) {
|
||||||
console.log(detail);
|
console.log(detail);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private blockIconEvent({detail}: any) {
|
||||||
|
console.log(detail);
|
||||||
|
detail.menu.addSeparator(0);
|
||||||
|
const ids: string[] = [];
|
||||||
|
detail.blockElements.forEach((item: HTMLElement) => {
|
||||||
|
ids.push(item.getAttribute("data-node-id"));
|
||||||
|
});
|
||||||
|
detail.menu.addItem({
|
||||||
|
index: 1,
|
||||||
|
iconHTML: "",
|
||||||
|
type: "readonly",
|
||||||
|
label: "IDs<br>" + ids.join("<br>"),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private async addMenu(rect: DOMRect) {
|
private async addMenu(rect: DOMRect) {
|
||||||
const menu = new Menu("topBarSample", () => {
|
const menu = new Menu("topBarSample", () => {
|
||||||
console.log(this.i18n.byeMenu);
|
console.log(this.i18n.byeMenu);
|
||||||
|
@ -126,26 +144,80 @@ export default class SamplePlugin extends Plugin {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
menu.addItem({
|
||||||
|
icon: "iconLayout",
|
||||||
|
label: "Open Float Layer(open help)",
|
||||||
|
click: () => {
|
||||||
|
this.addFloatLayer({
|
||||||
|
ids: ["20230523173319-xj1l3qu", "20230523173321-55o0w2n"],
|
||||||
|
defIds: ["20230523173323-imgm9tp", "20230523173324-cxu98t3"],
|
||||||
|
x: window.innerWidth - 768 - 120,
|
||||||
|
y: 32
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
menu.addItem({
|
menu.addItem({
|
||||||
icon: "iconTrashcan",
|
icon: "iconTrashcan",
|
||||||
label: "Remove Data",
|
label: "Remove Data",
|
||||||
click: () => {
|
click: () => {
|
||||||
this.removeData(STORAGE_NAME);
|
this.removeData(STORAGE_NAME).then(() => {
|
||||||
|
this.data[STORAGE_NAME] = {readonlyText: "Readonly"};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
menu.addItem({
|
menu.addItem({
|
||||||
icon: "iconSelect",
|
icon: "iconScrollHoriz",
|
||||||
label: "On ws-main",
|
label: "Event Bus",
|
||||||
click: () => {
|
type: "submenu",
|
||||||
this.eventBus.on("ws-main", this.wsEvent);
|
submenu: [{
|
||||||
}
|
icon: "iconSelect",
|
||||||
});
|
label: "On ws-main",
|
||||||
menu.addItem({
|
click: () => {
|
||||||
icon: "iconClose",
|
this.eventBus.on("ws-main", this.wsEvent);
|
||||||
label: "Off ws-main",
|
}
|
||||||
click: () => {
|
}, {
|
||||||
this.eventBus.off("ws-main", this.wsEvent);
|
icon: "iconClose",
|
||||||
}
|
label: "Off ws-main",
|
||||||
|
click: () => {
|
||||||
|
this.eventBus.off("ws-main", this.wsEvent);
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
icon: "iconSelect",
|
||||||
|
label: "On click-blockicon",
|
||||||
|
click: () => {
|
||||||
|
this.eventBus.on("click-blockicon", this.blockIconEvent);
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
icon: "iconClose",
|
||||||
|
label: "Off click-blockicon",
|
||||||
|
click: () => {
|
||||||
|
this.eventBus.off("click-blockicon", this.blockIconEvent);
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
icon: "iconSelect",
|
||||||
|
label: "On click-pdf",
|
||||||
|
click: () => {
|
||||||
|
this.eventBus.on("click-pdf", this.wsEvent);
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
icon: "iconClose",
|
||||||
|
label: "Off click-pdf",
|
||||||
|
click: () => {
|
||||||
|
this.eventBus.off("click-pdf", this.wsEvent);
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
icon: "iconSelect",
|
||||||
|
label: "On click-editorcontent",
|
||||||
|
click: () => {
|
||||||
|
this.eventBus.on("click-editorcontent", this.wsEvent);
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
icon: "iconClose",
|
||||||
|
label: "Off click-editorcontent",
|
||||||
|
click: () => {
|
||||||
|
this.eventBus.off("click-editorcontent", this.wsEvent);
|
||||||
|
}
|
||||||
|
}]
|
||||||
});
|
});
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
menu.addItem({
|
menu.addItem({
|
||||||
|
@ -181,7 +253,6 @@ export default class SamplePlugin extends Plugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
private openHelloInDialog() {
|
private openHelloInDialog() {
|
||||||
this.counter.hello++;
|
|
||||||
let dialog = new Dialog({
|
let dialog = new Dialog({
|
||||||
title: "Hello World",
|
title: "Hello World",
|
||||||
content: `<div id="helloPanel"></div>`,
|
content: `<div id="helloPanel"></div>`,
|
||||||
|
@ -198,9 +269,4 @@ export default class SamplePlugin extends Plugin {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async onunload() {
|
|
||||||
showMessage("Goodbye SiYuan Plugin");
|
|
||||||
console.log("onunload");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
<ul class="b3-list b3-list--background">
|
|
||||||
<li class="b3-list-item">
|
|
||||||
<svg class="b3-list-item__graphic"><use xlink:href="#iconEdit"></use></svg>
|
|
||||||
<span class="b3-list-item__text">
|
|
||||||
<slot></slot>
|
|
||||||
</span>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
3
src/libs/b3-typography.svelte
Normal file
3
src/libs/b3-typography.svelte
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<div class="item__readme b3-typography">
|
||||||
|
<slot/>
|
||||||
|
</div>
|
139
src/siyuan.d.ts
vendored
139
src/siyuan.d.ts
vendored
|
@ -1,14 +1,27 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2023, SiYuan, frostime, Terwer . All rights reserved.
|
|
||||||
*/
|
|
||||||
|
|
||||||
declare module "siyuan" {
|
declare module "siyuan" {
|
||||||
type TEventBus = "ws-main"
|
type TEventBus = "ws-main" | "click-blockicon" | "click-editorcontent" | "click-pdf"
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface Window {
|
||||||
|
Lute: Lute
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
interface IObject {
|
interface IObject {
|
||||||
[key: string]: string;
|
[key: string]: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ILuteNode {
|
||||||
|
TokensStr: () => string;
|
||||||
|
__internal_object__: {
|
||||||
|
Parent: {
|
||||||
|
Type: number,
|
||||||
|
},
|
||||||
|
HeadingLevel: string,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
interface IWebSocketData {
|
interface IWebSocketData {
|
||||||
cmd: string
|
cmd: string
|
||||||
callback?: string
|
callback?: string
|
||||||
|
@ -93,6 +106,8 @@ declare module "siyuan" {
|
||||||
|
|
||||||
onunload(): void;
|
onunload(): void;
|
||||||
|
|
||||||
|
onLayoutReady(): void;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @param {string} [options.position=right]
|
* @param {string} [options.position=right]
|
||||||
*/
|
*/
|
||||||
|
@ -132,6 +147,14 @@ declare module "siyuan" {
|
||||||
update?: () => void,
|
update?: () => void,
|
||||||
init: () => void
|
init: () => void
|
||||||
}): any
|
}): any
|
||||||
|
|
||||||
|
addFloatLayer(options: {
|
||||||
|
ids: string[],
|
||||||
|
defIds?: string[],
|
||||||
|
x?: number,
|
||||||
|
y?: number,
|
||||||
|
targetElement?: HTMLElement
|
||||||
|
}): void
|
||||||
}
|
}
|
||||||
|
|
||||||
export class EventBus {
|
export class EventBus {
|
||||||
|
@ -182,4 +205,110 @@ declare module "siyuan" {
|
||||||
|
|
||||||
close(): void;
|
close(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
declare class Lute {
|
||||||
|
public static WalkStop: number;
|
||||||
|
public static WalkSkipChildren: number;
|
||||||
|
public static WalkContinue: number;
|
||||||
|
public static Version: string;
|
||||||
|
public static Caret: string;
|
||||||
|
|
||||||
|
public static New(): Lute;
|
||||||
|
|
||||||
|
public static EChartsMindmapStr(text: string): string;
|
||||||
|
|
||||||
|
public static NewNodeID(): string;
|
||||||
|
|
||||||
|
public static Sanitize(html: string): string;
|
||||||
|
|
||||||
|
public static EscapeHTMLStr(str: string): string;
|
||||||
|
|
||||||
|
public static UnEscapeHTMLStr(str: string): string;
|
||||||
|
|
||||||
|
public static GetHeadingID(node: ILuteNode): string;
|
||||||
|
|
||||||
|
public static BlockDOM2Content(html: string): string;
|
||||||
|
|
||||||
|
private constructor();
|
||||||
|
|
||||||
|
public BlockDOM2Content(text: string): string;
|
||||||
|
|
||||||
|
public BlockDOM2EscapeMarkerContent(text: string): string;
|
||||||
|
|
||||||
|
public SetTextMark(enable: boolean): void;
|
||||||
|
|
||||||
|
public SetHeadingID(enable: boolean): void;
|
||||||
|
|
||||||
|
public SetProtyleMarkNetImg(enable: boolean): void;
|
||||||
|
|
||||||
|
public SetSpellcheck(enable: boolean): void;
|
||||||
|
|
||||||
|
public SetFileAnnotationRef(enable: boolean): void;
|
||||||
|
|
||||||
|
public SetSetext(enable: boolean): void;
|
||||||
|
|
||||||
|
public SetYamlFrontMatter(enable: boolean): void;
|
||||||
|
|
||||||
|
public SetChineseParagraphBeginningSpace(enable: boolean): void;
|
||||||
|
|
||||||
|
public SetRenderListStyle(enable: boolean): void;
|
||||||
|
|
||||||
|
public SetImgPathAllowSpace(enable: boolean): void;
|
||||||
|
|
||||||
|
public SetKramdownIAL(enable: boolean): void;
|
||||||
|
|
||||||
|
public BlockDOM2Md(html: string): string;
|
||||||
|
|
||||||
|
public BlockDOM2StdMd(html: string): string;
|
||||||
|
|
||||||
|
public SetGitConflict(enable: boolean): void;
|
||||||
|
|
||||||
|
public SetSuperBlock(enable: boolean): void;
|
||||||
|
|
||||||
|
public SetTag(enable: boolean): void;
|
||||||
|
|
||||||
|
public SetMark(enable: boolean): void;
|
||||||
|
|
||||||
|
public SetSub(enable: boolean): void;
|
||||||
|
|
||||||
|
public SetSup(enable: boolean): void;
|
||||||
|
|
||||||
|
public SetBlockRef(enable: boolean): void;
|
||||||
|
|
||||||
|
public SetSanitize(enable: boolean): void;
|
||||||
|
|
||||||
|
public SetHeadingAnchor(enable: boolean): void;
|
||||||
|
|
||||||
|
public SetImageLazyLoading(imagePath: string): void;
|
||||||
|
|
||||||
|
public SetInlineMathAllowDigitAfterOpenMarker(enable: boolean): void;
|
||||||
|
|
||||||
|
public SetToC(enable: boolean): void;
|
||||||
|
|
||||||
|
public SetIndentCodeBlock(enable: boolean): void;
|
||||||
|
|
||||||
|
public SetParagraphBeginningSpace(enable: boolean): void;
|
||||||
|
|
||||||
|
public SetFootnotes(enable: boolean): void;
|
||||||
|
|
||||||
|
public SetLinkRef(enalbe: boolean): void;
|
||||||
|
|
||||||
|
public SetEmojiSite(emojiSite: string): void;
|
||||||
|
|
||||||
|
public PutEmojis(emojis: IObject): void;
|
||||||
|
|
||||||
|
public SpinBlockDOM(html: string): string;
|
||||||
|
|
||||||
|
public Md2BlockDOM(html: string): string;
|
||||||
|
|
||||||
|
public SetProtyleWYSIWYG(wysiwyg: boolean): void;
|
||||||
|
|
||||||
|
public MarkdownStr(name: string, md: string): string;
|
||||||
|
|
||||||
|
public IsValidLinkDest(text: string): boolean;
|
||||||
|
|
||||||
|
public BlockDOM2InlineBlockDOM(html: string): string;
|
||||||
|
|
||||||
|
public BlockDOM2HTML(html: string): string;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue