Skip to content

Commit 473df4b

Browse files
committed
🎨 #10090
1 parent 013b06d commit 473df4b

File tree

6 files changed

+35
-7
lines changed

6 files changed

+35
-7
lines changed

app/src/plugin/index.ts

+9
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export class Plugin {
5656
/// #endif
5757
}
5858
} = {};
59+
private protyleOptionsValue: IOptions;
5960

6061
constructor(options: {
6162
app: App,
@@ -307,4 +308,12 @@ export class Plugin {
307308
defIds: options.defIds,
308309
}));
309310
};
311+
312+
set protyleOptions(options: IOptions) {
313+
this.protyleOptionsValue = options;
314+
}
315+
316+
get protyleOptions() {
317+
return this.protyleOptionsValue;
318+
}
310319
}

app/src/protyle/index.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {avRender} from "./render/av/render";
4040
import {focusBlock, getEditorRange} from "./util/selection";
4141
import {hasClosestBlock} from "./util/hasClosest";
4242
import {setStorageVal} from "./util/compatibility";
43+
import {merge} from "./util/merge";
4344

4445
export class Protyle {
4546

@@ -52,9 +53,14 @@ export class Protyle {
5253
*/
5354
constructor(app: App, id: HTMLElement, options?: IOptions) {
5455
this.version = Constants.SIYUAN_VERSION;
55-
const getOptions = new Options(options);
56+
let pluginsOptions: IOptions = options;
57+
app.plugins.forEach(item => {
58+
if (item.protyleOptions) {
59+
pluginsOptions = merge(pluginsOptions, item.protyleOptions);
60+
}
61+
})
62+
const getOptions = new Options(pluginsOptions);
5663
const mergedOptions = getOptions.merge();
57-
5864
this.protyle = {
5965
getInstance: () => this,
6066
app,

app/src/protyle/toolbar/ToolbarItem.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {getEventName} from "../util/compatibility";
22
import {updateHotkeyTip} from "../util/compatibility";
3+
import {Constants} from "../../constants";
34

45
export class ToolbarItem {
56
public element: HTMLElement;
@@ -17,7 +18,11 @@ export class ToolbarItem {
1718
}
1819
this.element.addEventListener(getEventName(), (event) => {
1920
event.preventDefault();
20-
protyle.toolbar.setInlineMark(protyle, menuItem.name, "toolbar");
21+
if (Constants.INLINE_TYPE.includes(menuItem.name)) {
22+
protyle.toolbar.setInlineMark(protyle, menuItem.name, "toolbar");
23+
} else if (menuItem.click) {
24+
menuItem.click(protyle.getInstance());
25+
}
2126
});
2227
}
2328
}

app/src/protyle/toolbar/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ export class Toolbar {
229229
case "a":
230230
menuItemObj = new Link(protyle, menuItem);
231231
break;
232+
default:
233+
menuItemObj = new ToolbarItem(protyle, menuItem);
234+
break;
232235
}
233236
if (!menuItemObj) {
234237
return;

app/src/protyle/wysiwyg/keydown.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1288,8 +1288,10 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
12881288
findToolbar = true;
12891289
if (["a", "block-ref", "inline-math", "inline-memo", "text"].includes(menuItem.name)) {
12901290
protyle.toolbar.element.querySelector(`[data-type="${menuItem.name}"]`).dispatchEvent(new CustomEvent("click"));
1291-
} else {
1291+
} else if (Constants.INLINE_TYPE.includes(menuItem.name)) {
12921292
protyle.toolbar.setInlineMark(protyle, menuItem.name, "range");
1293+
} else if (menuItem.click) {
1294+
menuItem.click(protyle.getInstance());
12931295
}
12941296
return true;
12951297
}

app/src/types/protyle.d.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,18 @@ interface IUpload {
303303
interface IMenuItem {
304304
/** 唯一标示 */
305305
name: string;
306+
/** 提示 */
307+
tip?: string;
308+
/** 语言 key */
306309
lang?: string;
307310
/** svg 图标 */
308311
icon?: string;
309-
/** 提示 */
310-
tip?: string;
311312
/** 快捷键 */
312313
hotkey?: string;
313-
/** 插入编辑器中的后缀 */
314+
/** 提示的位置 */
314315
tipPosition?: string;
316+
317+
click?(protyle: import("../protyle").Protyle): void;
315318
}
316319

317320
/** @link https://ld246.com/article/1549638745630#options-preview-markdown */

0 commit comments

Comments
 (0)