mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 09:30:14 +01:00
This commit is contained in:
parent
013b06dcce
commit
473df4b185
6 changed files with 35 additions and 7 deletions
|
|
@ -56,6 +56,7 @@ export class Plugin {
|
||||||
/// #endif
|
/// #endif
|
||||||
}
|
}
|
||||||
} = {};
|
} = {};
|
||||||
|
private protyleOptionsValue: IOptions;
|
||||||
|
|
||||||
constructor(options: {
|
constructor(options: {
|
||||||
app: App,
|
app: App,
|
||||||
|
|
@ -307,4 +308,12 @@ export class Plugin {
|
||||||
defIds: options.defIds,
|
defIds: options.defIds,
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
set protyleOptions(options: IOptions) {
|
||||||
|
this.protyleOptionsValue = options;
|
||||||
|
}
|
||||||
|
|
||||||
|
get protyleOptions() {
|
||||||
|
return this.protyleOptionsValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ import {avRender} from "./render/av/render";
|
||||||
import {focusBlock, getEditorRange} from "./util/selection";
|
import {focusBlock, getEditorRange} from "./util/selection";
|
||||||
import {hasClosestBlock} from "./util/hasClosest";
|
import {hasClosestBlock} from "./util/hasClosest";
|
||||||
import {setStorageVal} from "./util/compatibility";
|
import {setStorageVal} from "./util/compatibility";
|
||||||
|
import {merge} from "./util/merge";
|
||||||
|
|
||||||
export class Protyle {
|
export class Protyle {
|
||||||
|
|
||||||
|
|
@ -52,9 +53,14 @@ export class Protyle {
|
||||||
*/
|
*/
|
||||||
constructor(app: App, id: HTMLElement, options?: IOptions) {
|
constructor(app: App, id: HTMLElement, options?: IOptions) {
|
||||||
this.version = Constants.SIYUAN_VERSION;
|
this.version = Constants.SIYUAN_VERSION;
|
||||||
const getOptions = new Options(options);
|
let pluginsOptions: IOptions = options;
|
||||||
|
app.plugins.forEach(item => {
|
||||||
|
if (item.protyleOptions) {
|
||||||
|
pluginsOptions = merge(pluginsOptions, item.protyleOptions);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const getOptions = new Options(pluginsOptions);
|
||||||
const mergedOptions = getOptions.merge();
|
const mergedOptions = getOptions.merge();
|
||||||
|
|
||||||
this.protyle = {
|
this.protyle = {
|
||||||
getInstance: () => this,
|
getInstance: () => this,
|
||||||
app,
|
app,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import {getEventName} from "../util/compatibility";
|
import {getEventName} from "../util/compatibility";
|
||||||
import {updateHotkeyTip} from "../util/compatibility";
|
import {updateHotkeyTip} from "../util/compatibility";
|
||||||
|
import {Constants} from "../../constants";
|
||||||
|
|
||||||
export class ToolbarItem {
|
export class ToolbarItem {
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
|
|
@ -17,7 +18,11 @@ export class ToolbarItem {
|
||||||
}
|
}
|
||||||
this.element.addEventListener(getEventName(), (event) => {
|
this.element.addEventListener(getEventName(), (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
if (Constants.INLINE_TYPE.includes(menuItem.name)) {
|
||||||
protyle.toolbar.setInlineMark(protyle, menuItem.name, "toolbar");
|
protyle.toolbar.setInlineMark(protyle, menuItem.name, "toolbar");
|
||||||
|
} else if (menuItem.click) {
|
||||||
|
menuItem.click(protyle.getInstance());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -229,6 +229,9 @@ export class Toolbar {
|
||||||
case "a":
|
case "a":
|
||||||
menuItemObj = new Link(protyle, menuItem);
|
menuItemObj = new Link(protyle, menuItem);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
menuItemObj = new ToolbarItem(protyle, menuItem);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (!menuItemObj) {
|
if (!menuItemObj) {
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -1288,8 +1288,10 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
|
||||||
findToolbar = true;
|
findToolbar = true;
|
||||||
if (["a", "block-ref", "inline-math", "inline-memo", "text"].includes(menuItem.name)) {
|
if (["a", "block-ref", "inline-math", "inline-memo", "text"].includes(menuItem.name)) {
|
||||||
protyle.toolbar.element.querySelector(`[data-type="${menuItem.name}"]`).dispatchEvent(new CustomEvent("click"));
|
protyle.toolbar.element.querySelector(`[data-type="${menuItem.name}"]`).dispatchEvent(new CustomEvent("click"));
|
||||||
} else {
|
} else if (Constants.INLINE_TYPE.includes(menuItem.name)) {
|
||||||
protyle.toolbar.setInlineMark(protyle, menuItem.name, "range");
|
protyle.toolbar.setInlineMark(protyle, menuItem.name, "range");
|
||||||
|
} else if (menuItem.click) {
|
||||||
|
menuItem.click(protyle.getInstance());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
9
app/src/types/protyle.d.ts
vendored
9
app/src/types/protyle.d.ts
vendored
|
|
@ -303,15 +303,18 @@ interface IUpload {
|
||||||
interface IMenuItem {
|
interface IMenuItem {
|
||||||
/** 唯一标示 */
|
/** 唯一标示 */
|
||||||
name: string;
|
name: string;
|
||||||
|
/** 提示 */
|
||||||
|
tip?: string;
|
||||||
|
/** 语言 key */
|
||||||
lang?: string;
|
lang?: string;
|
||||||
/** svg 图标 */
|
/** svg 图标 */
|
||||||
icon?: string;
|
icon?: string;
|
||||||
/** 提示 */
|
|
||||||
tip?: string;
|
|
||||||
/** 快捷键 */
|
/** 快捷键 */
|
||||||
hotkey?: string;
|
hotkey?: string;
|
||||||
/** 插入编辑器中的后缀 */
|
/** 提示的位置 */
|
||||||
tipPosition?: string;
|
tipPosition?: string;
|
||||||
|
|
||||||
|
click?(protyle: import("../protyle").Protyle): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @link https://ld246.com/article/1549638745630#options-preview-markdown */
|
/** @link https://ld246.com/article/1549638745630#options-preview-markdown */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue