-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
328 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"publishTool": "Publish Tool", | ||
"setting": "Setting", | ||
"cancel": "Cancel", | ||
"save": "Save" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"publishTool": "发布工具", | ||
"setting": "设置", | ||
"cancel": "取消", | ||
"save": "保存" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<script lang="ts"> | ||
import Counter from "./lib/Counter.svelte" | ||
const message = "Hello, World!" | ||
</script> | ||
|
||
<main> | ||
<div> | ||
This is svelte {message} | ||
<Counter /> | ||
|
||
<!-- | ||
<div class="b3-dialog__content"> | ||
<textarea class="b3-text-field fn__block" placeholder="readonly text in the menu" /> | ||
</div> | ||
<div class="b3-dialog__action"> | ||
<button class="b3-button b3-button--cancel">${this.i18n.cancel}</button> | ||
<div class="fn__space" /> | ||
<button class="b3-button b3-button--text">${this.i18n.save}</button> | ||
</div> | ||
</div> | ||
--> | ||
</div> | ||
</main> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,49 @@ | ||
import { Plugin } from "siyuan" | ||
import { Plugin, showMessage, confirm, Dialog, Menu, isMobile, openTab, adaptHotkey } from "siyuan" | ||
import App from "./App.svelte" | ||
|
||
const STORAGE_NAME = "menu-config" | ||
const SETTING_CONTAINER = "publish-tool-setting" | ||
|
||
// https://github.com/sveltejs/svelte-preprocess/issues/91#issuecomment-548527600 | ||
export default class PublishTool extends Plugin { | ||
// lifecycle | ||
onload() { | ||
console.log("Publish Tool loaded") | ||
console.log(`Publish Tool loaded ${new Date().getTime()}`) | ||
} | ||
|
||
onunload() { | ||
console.log("Publish Tool unloaded") | ||
} | ||
|
||
openSetting() { | ||
this._show_setting_dialog() | ||
} | ||
|
||
// private functions | ||
_show_setting_dialog() { | ||
new Dialog({ | ||
title: `${this.i18n.setting} - ${this.i18n.publishTool}`, | ||
content: `<div id="${SETTING_CONTAINER}"></div>`, | ||
width: isMobile() ? "92vw" : "520px", | ||
}) | ||
|
||
// setting | ||
new App({ | ||
target: document.getElementById(SETTING_CONTAINER) as HTMLElement, | ||
}) | ||
|
||
// const inputElement = dialog.element.querySelector("textarea") as HTMLTextAreaElement | ||
// const btnsElement = dialog.element.querySelectorAll(".b3-button") | ||
// dialog.bindInput(inputElement, () => { | ||
// ;(btnsElement[1] as HTMLButtonElement).click() | ||
// }) | ||
// inputElement.focus() | ||
// btnsElement[0].addEventListener("click", () => { | ||
// dialog.destroy() | ||
// }) | ||
// btnsElement[1].addEventListener("click", () => { | ||
// this.saveData(STORAGE_NAME, inputElement.value) | ||
// dialog.destroy() | ||
// }) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<script lang="ts"> | ||
let count = 0 | ||
const increment = () => { | ||
count += 1 | ||
} | ||
</script> | ||
|
||
<button on:click={increment}> | ||
count is {count} | ||
</button> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
declare module "siyuan" { | ||
type TEventBus = "ws-main" | ||
|
||
interface IObject { | ||
[key: string]: string; | ||
} | ||
|
||
interface IWebSocketData { | ||
cmd: string; | ||
callback?: string; | ||
data: any; | ||
msg: string; | ||
code: number; | ||
sid: string; | ||
} | ||
|
||
declare interface IPluginDockTab { | ||
position: "LeftTop" | "LeftBottom" | "RightTop" | "RightBottom" | "BottomLeft" | "BottomRight", | ||
size: { width: number, height: number }, | ||
icon: string, | ||
hotkey?: string, | ||
title: string, | ||
} | ||
|
||
interface IMenuItemOption { | ||
label?: string, | ||
click?: (element: HTMLElement) => void, | ||
type?: "separator" | "submenu" | "readonly", | ||
accelerator?: string, | ||
action?: string, | ||
id?: string, | ||
submenu?: IMenuItemOption[] | ||
disabled?: boolean | ||
icon?: string | ||
iconHTML?: string | ||
current?: boolean | ||
bind?: (element: HTMLElement) => void | ||
} | ||
|
||
export function fetchPost(url: string, data?: any, cb?: (response: IWebSocketData) => void, headers?: IObject): void; | ||
|
||
export function fetchSyncPost(url: string, data?: any): Promise<IWebSocketData>; | ||
|
||
export function fetchGet(url: string, cb: (response: IWebSocketData) => void): void; | ||
|
||
export function openTab(options: { | ||
custom?: { | ||
title: string, | ||
icon: string, | ||
data?: any | ||
fn?: () => any, | ||
} // card 和自定义页签 必填 | ||
position?: "right" | "bottom", | ||
keepCursor?: boolean // 是否跳转到新 tab 上 | ||
removeCurrentTab?: boolean // 在当前页签打开时需移除原有页签 | ||
afterOpen?: () => void // 打开后回调 | ||
}): void | ||
|
||
export function isMobile(): boolean; | ||
|
||
export function adaptHotkey(hotkey: string): string; | ||
|
||
export function confirm(title: string, text: string, confirmCB?: () => void, cancelCB?: () => void): void; | ||
|
||
/** | ||
* @param timeout - ms. 0: manual close;-1: always show; 6000: default | ||
* @param {string} [type=info] | ||
*/ | ||
export function showMessage(text: string, timeout?: number, type?: "info" | "error", id?: string): void; | ||
|
||
export class App { | ||
plugins: Plugin[]; | ||
} | ||
|
||
export abstract class Plugin { | ||
eventBus: EventBus; | ||
i18n: IObject; | ||
data: any; | ||
name: string; | ||
|
||
constructor(options: { | ||
app: App, | ||
id: string, | ||
name: string, | ||
i18n: IObject | ||
}) | ||
|
||
onload(): void; | ||
|
||
onunload(): void; | ||
|
||
/* | ||
* @param {string} [options.position=right] | ||
*/ | ||
addTopBar(options: { | ||
icon: string, | ||
title: string, | ||
callback: (evt: MouseEvent) => void | ||
position?: "right" | "left" | ||
}): HTMLDivElement; | ||
|
||
openSetting(): void | ||
|
||
// registerCommand(command: IPluginCommand): void; | ||
|
||
// registerSettingRender(settingRender: SettingRender): void; | ||
|
||
loadData(storageName: string): Promise<any>; | ||
|
||
saveData(storageName: string, content: any): Promise<void>; | ||
|
||
addTab(options: { | ||
type: string, | ||
destroy?: () => void, | ||
resize?: () => void, | ||
update?: () => void, | ||
init: () => void | ||
}): () => any | ||
|
||
addDock(options: { | ||
config: IPluginDockTab, | ||
data: any, | ||
type: string, | ||
destroy?: () => void, | ||
resize?: () => void, | ||
update?: () => void, | ||
init: () => void | ||
}): any | ||
} | ||
|
||
export class EventBus { | ||
on(type: TEventBus, listener: (event: CustomEvent<any>) => void): void; | ||
|
||
once(type: TEventBus, listener: (event: CustomEvent<any>) => void): void; | ||
|
||
off(type: TEventBus, listener: (event: CustomEvent<any>) => void): void; | ||
|
||
emit(type: TEventBus, detail?: any): boolean; | ||
} | ||
|
||
export class Dialog { | ||
|
||
element: HTMLElement; | ||
|
||
constructor(options: { | ||
title?: string, | ||
transparent?: boolean, | ||
content: string, | ||
width?: string | ||
height?: string, | ||
destroyCallback?: (options?: IObject) => void | ||
disableClose?: boolean | ||
disableAnimation?: boolean | ||
}); | ||
|
||
destroy(options?: IObject): void; | ||
|
||
bindInput(inputElement: HTMLInputElement | HTMLTextAreaElement, enterEvent?: () => void): void; | ||
} | ||
|
||
export class Menu { | ||
constructor(id?: string, closeCB?: () => void); | ||
|
||
showSubMenu(subMenuElement: HTMLElement): void; | ||
|
||
addItem(options: IMenuItemOption): HTMLElement; | ||
|
||
addSeparator(): void; | ||
|
||
open(options: { x: number, y: number, h?: number, w?: number, isLeft?: boolean }): void; | ||
|
||
/* | ||
* @param {string} [position=all] | ||
*/ | ||
fullscreen(position?: "bottom" | "all"): void; | ||
|
||
close(): void; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.