siyuan 1.1.5 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,223 +1,16 @@
1
1
  import {
2
- App, Config, Editor,
2
+ App,
3
+ Config,
4
+ Editor,
5
+ IAV,
3
6
  IObject,
4
- IOperation, IPosition, IWebSocketData, Menu,
7
+ IOperation,
8
+ IPosition,
9
+ IWebSocketData,
10
+ Menu,
5
11
  } from "./../siyuan";
6
12
  import {Model} from "./layout/Model";
7
13
 
8
- type TTurnIntoOne = "BlocksMergeSuperBlock" | "Blocks2ULs" | "Blocks2OLs" | "Blocks2TLs" | "Blocks2Blockquote"
9
-
10
- type TTurnIntoOneSub = "row" | "col"
11
-
12
- type TTurnInto = "Blocks2Ps" | "Blocks2Hs"
13
-
14
- type THintSource = "search" | "av" | "hint";
15
-
16
- export type TProtyleAction = "cb-get-append" | // 向下滚动加载
17
- "cb-get-before" | // 向上滚动加载
18
- "cb-get-unchangeid" | // 上下滚动,定位时不修改 blockid
19
- "cb-get-hl" | // 高亮
20
- "cb-get-focus" | // 光标定位
21
- "cb-get-focusfirst" | // 动态定位到第一个块
22
- "cb-get-setid" | // 无折叠大纲点击 重置 blockid
23
- "cb-get-outline" | // 大纲点击
24
- "cb-get-all" | // 获取所有块
25
- "cb-get-backlink" | // 悬浮窗为传递型需展示上下文
26
- "cb-get-unundo" | // 不需要记录历史
27
- "cb-get-scroll" | // 滚动到指定位置,用于直接打开文档,必有 rootID
28
- "cb-get-context" | // 包含上下文
29
- "cb-get-rootscroll" | // 如果为 rootID 就滚动到指定位置,必有 rootID
30
- "cb-get-html" | // 直接渲染,不需要再 /api/block/getDocInfo,否则搜索表格无法定位
31
- "cb-get-history" | // 历史渲染
32
- "cb-get-opennew" // 编辑器只读后新建文件需为临时解锁状态 & https://github.com/siyuan-note/siyuan/issues/12197
33
-
34
- export type TEditorMode = "preview" | "wysiwyg"
35
-
36
- interface ILuteNode {
37
- TokensStr: () => string;
38
- __internal_object__: {
39
- Parent: {
40
- Type: number,
41
- },
42
- HeadingLevel: string,
43
- };
44
- }
45
-
46
- /** @link https://ld246.com/article/1549638745630#options-toolbar */
47
- interface IMenuItem {
48
- /** 唯一标示 */
49
- name: string;
50
- /** 提示 */
51
- tip?: string;
52
- /** 语言 key */
53
- lang?: string;
54
- /** svg 图标 */
55
- icon?: string;
56
- /** 快捷键 */
57
- hotkey?: string;
58
- /** 提示的位置 */
59
- tipPosition?: string;
60
-
61
- click?(protyle: Protyle): void;
62
- }
63
-
64
- interface IBreadcrumb {
65
- id: string,
66
- name: string,
67
- type: string,
68
- subType: string,
69
- children: []
70
- }
71
-
72
- interface IOperations {
73
- doOperations: IOperation[],
74
- undoOperations: IOperation[]
75
- }
76
-
77
- interface IHintData {
78
- id?: string;
79
- html: string;
80
- value: string;
81
- filter?: string[];
82
- focus?: boolean;
83
- }
84
-
85
- export interface IProtyleOptions {
86
- history?: {
87
- created?: string
88
- snapshot?: string
89
- },
90
- backlinkData?: {
91
- blockPaths: IBreadcrumb[],
92
- dom: string
93
- expand: boolean
94
- }[],
95
- action?: TProtyleAction[],
96
- mode?: TEditorMode,
97
- blockId?: string
98
- rootId?: string
99
- originalRefBlockIDs?: IObject
100
- key?: string
101
- defId?: string
102
- render?: {
103
- background?: boolean
104
- title?: boolean
105
- titleShowTop?: boolean
106
- hideTitleOnZoom?: boolean
107
- gutter?: boolean
108
- scroll?: boolean
109
- breadcrumb?: boolean
110
- breadcrumbDocName?: boolean
111
- }
112
- /** 内部调试时使用 */
113
- _lutePath?: string;
114
- /** 是否显示日志。默认值: false */
115
- debugger?: boolean;
116
- /** 是否启用打字机模式。默认值: false */
117
- typewriterMode?: boolean;
118
- /** 多语言。默认值: 'zh_CN' */
119
- lang?: string;
120
- /** @link https://ld246.com/article/1549638745630#options-toolbar */
121
- toolbar?: Array<string | IMenuItem>;
122
- /** @link https://ld246.com/article/1549638745630#options-classes */
123
- classes?: {
124
- preview?: string;
125
- };
126
- click?: {
127
- /** 点击末尾是否阻止插入新块 */
128
- preventInsetEmptyBlock?: boolean
129
- }
130
-
131
- handleEmptyContent?(): void
132
-
133
- /** 编辑器异步渲染完成后的回调方法 */
134
- after?(protyle: Protyle): void;
135
- }
136
-
137
- // REF: https://github.com/siyuan-note/siyuan/blob/dev/app/src/types/protyle.d.ts
138
- export interface IProtyle {
139
- getInstance: () => Protyle,
140
- observerLoad?: ResizeObserver,
141
- observer?: ResizeObserver,
142
- app: App,
143
- transactionTime: number,
144
- id: string,
145
- query?: {
146
- key: string,
147
- method: number
148
- types: Config.IUILayoutTabSearchConfigTypes
149
- },
150
- block: {
151
- id?: string,
152
- scroll?: boolean
153
- parentID?: string,
154
- parent2ID?: string,
155
- rootID?: string,
156
- showAll?: boolean
157
- mode?: number
158
- blockCount?: number
159
- action?: string[]
160
- },
161
- disabled: boolean,
162
- selectElement?: HTMLElement,
163
- ws?: Model,
164
- notebookId?: string
165
- path?: string
166
- model?: Editor,
167
- updated: boolean;
168
- element: HTMLElement;
169
- scroll?: Scroll,
170
- gutter?: Gutter,
171
- breadcrumb?: Breadcrumb,
172
- title?: Title,
173
- background?: Background,
174
- contentElement?: HTMLElement,
175
- options: IProtyleOptions;
176
- lute?: Lute;
177
- toolbar?: Toolbar,
178
- preview?: Preview;
179
- hint?: Hint;
180
- upload?: Upload;
181
- undo?: Undo;
182
- wysiwyg?: WYSIWYG
183
- }
184
-
185
- declare class Viz {
186
- public static instance(): Promise<Viz>;
187
-
188
- renderSVGElement: (code: string) => SVGElement;
189
- }
190
-
191
- declare class Viewer {
192
- public destroyed: boolean;
193
-
194
- constructor(element: Element, options: {
195
- title: [number, (image: HTMLImageElement, imageData: IObject) => string],
196
- button: boolean,
197
- initialViewIndex?: number,
198
- transition: boolean,
199
- hidden: () => void,
200
- toolbar: {
201
- zoomIn: boolean,
202
- zoomOut: boolean,
203
- oneToOne: boolean,
204
- reset: boolean,
205
- prev: boolean,
206
- play: boolean,
207
- next: boolean,
208
- rotateLeft: boolean,
209
- rotateRight: boolean,
210
- flipHorizontal: boolean,
211
- flipVertical: boolean,
212
- close: () => void
213
- }
214
- })
215
-
216
- public destroy(): void
217
-
218
- public show(): void
219
- }
220
-
221
14
  declare class Breadcrumb {
222
15
  element: HTMLElement;
223
16
 
@@ -344,6 +137,11 @@ declare class Preview {
344
137
  private processZHTable;
345
138
  }
346
139
 
140
+ interface IOperations {
141
+ doOperations: IOperation[],
142
+ undoOperations: IOperation[]
143
+ }
144
+
347
145
  declare class Undo {
348
146
  private hasUndo;
349
147
  redoStack: IOperations[];
@@ -433,34 +231,331 @@ export declare class Toolbar {
433
231
  public showContent(protyle: IProtyle, range: Range, nodeElement: Element): void
434
232
  }
435
233
 
436
- export class Lute {
437
- public static WalkStop: number;
438
- public static WalkSkipChildren: number;
439
- public static WalkContinue: number;
440
- public static Version: string;
441
- public static Caret: string;
234
+ export class Protyle {
442
235
 
443
- public static New(): Lute;
236
+ public readonly version: string;
237
+ public protyle: IProtyle;
444
238
 
445
- public static EChartsMindmapStr(text: string): string;
239
+ constructor(app: App, element: HTMLElement, options?: IProtyleOptions)
446
240
 
447
- public static NewNodeID(): string;
241
+ /** 聚焦到编辑器 */
242
+ public focus(): void
448
243
 
449
- public static Sanitize(html: string): string;
244
+ /** 上传是否还在进行中 */
245
+ public isUploading(): boolean
450
246
 
451
- public static EscapeHTMLStr(str: string): string;
247
+ /** 清空 undo & redo 栈 */
248
+ public clearStack(): void
452
249
 
453
- public static UnEscapeHTMLStr(str: string): string;
250
+ /** 销毁编辑器 */
251
+ public destroy(): void
454
252
 
455
- public static GetHeadingID(node: ILuteNode): string;
253
+ public resize(): void
456
254
 
457
- public static BlockDOM2Content(html: string): string;
255
+ public reload(focus: boolean): void
458
256
 
459
- private constructor();
257
+ /**
258
+ * @param {boolean} [isBlock=false]
259
+ * @param {boolean} [useProtyleRange=false]
260
+ */
261
+ public insert(html: string, isBlock?: boolean, useProtyleRange?: boolean): void
460
262
 
461
- public BlockDOM2Content(text: string): string;
263
+ public transaction(doOperations: IOperation[], undoOperations?: IOperation[]): void;
462
264
 
463
- public BlockDOM2EscapeMarkerContent(text: string): string;
265
+ /**
266
+ * 多个块转换为一个块
267
+ * @param {TTurnIntoOneSub} [subType] type 为 "BlocksMergeSuperBlock" 时必传
268
+ */
269
+ public turnIntoOneTransaction(selectsElement: Element[], type: TTurnIntoOne, subType?: TTurnIntoOneSub): void
270
+
271
+ /**
272
+ * 多个块转换
273
+ * @param {Element} [nodeElement] 优先使用包含 protyle-wysiwyg--select 的块,否则使用 nodeElement 单块
274
+ * @param type
275
+ * @param {number} [subType] type 为 "Blocks2Hs" 时必传
276
+ */
277
+ public turnIntoTransaction(nodeElement: Element, type: TTurnInto, subType?: number): void
278
+
279
+ public updateTransaction(id: string, newHTML: string, html: string): void
280
+
281
+ public updateBatchTransaction(nodeElements: Element[], cb: (e: HTMLElement) => void): void
282
+
283
+ public getRange(element: Element): Range
284
+
285
+ public hasClosestBlock(element: Node): false | HTMLElement
286
+
287
+ /**
288
+ * @param {boolean} [toStart=true]
289
+ */
290
+ public focusBlock(element: Element, toStart?: boolean): false | Range
291
+
292
+ public disable(): void
293
+
294
+ public enable(): void
295
+
296
+ public renderAVAttribute(element: HTMLElement, id: string, cb?: (element: HTMLElement) => void): void
297
+ }
298
+
299
+ export class ProtyleMethod {
300
+ /**
301
+ * @description 使用 graphviz 进行渲染
302
+ * @param {string} [cdn=Constants.PROTYLE_CDN]
303
+ */
304
+ public static graphvizRender(element: Element, cdn?: string): void
305
+
306
+ /**
307
+ * @description 为 element 中的代码块进行高亮渲染
308
+ * @param {string} [cdn=Constants.PROTYLE_CDN]
309
+ * @param {number} [zoom=1]
310
+ */
311
+ public static highlightRender(element: Element, cdn?: string, zoom?: number): void
312
+
313
+ /**
314
+ * @description 对数学公式进行渲染
315
+ * @param {string} [cdn=Constants.PROTYLE_CDN]
316
+ * @param {boolean} [maxWidth=false]
317
+ */
318
+ public static mathRender(element: Element, cdn?: string, maxWidth?: boolean): void;
319
+
320
+ /**
321
+ * @description mermaid.js 渲染,支持流程图/时序图/甘特图渲染等
322
+ * @param {string} [cdn=Constants.PROTYLE_CDN]
323
+ */
324
+ public static mermaidRender(element: Element, cdn?: string): void;
325
+
326
+ /**
327
+ * @description flowchart.js 渲染
328
+ * @param {string} [cdn=Constants.PROTYLE_CDN]
329
+ */
330
+ public static flowchartRender(element: Element, cdn?: string): void;
331
+
332
+ /**
333
+ * @description 图表渲染
334
+ * @param {string} [cdn=Constants.PROTYLE_CDN]
335
+ */
336
+ public static chartRender(element: Element, cdn?: string): void;
337
+
338
+ /**
339
+ * @description 五线谱渲染
340
+ * @param {string} [cdn=Constants.PROTYLE_CDN]
341
+ */
342
+ public static abcRender(element: Element, cdn?: string): void;
343
+
344
+ /**
345
+ * @description 脑图渲染
346
+ * @param {string} [cdn=Constants.PROTYLE_CDN]
347
+ */
348
+ public static mindmapRender(element: Element, cdn?: string): void;
349
+
350
+ /**
351
+ * @description UML 渲染
352
+ * @param {string} [cdn=Constants.PROTYLE_CDN]
353
+ */
354
+ public static plantumlRender(element: Element, cdn?: string): void;
355
+
356
+ /**
357
+ * @description 数据库渲染
358
+ * @param {boolean} [renderAll=true]
359
+ */
360
+ public static avRender(element: Element, protyle: IProtyle, cb?: (data: IAV) => void, renderAll?: boolean, avData?: IAV): Promise<void>;
361
+
362
+ /**
363
+ * @description html 渲染
364
+ */
365
+ public static htmlRender(element: Element): void;
366
+ }
367
+
368
+ interface ILuteNode {
369
+ TokensStr: () => string;
370
+ __internal_object__: {
371
+ Parent: {
372
+ Type: number,
373
+ },
374
+ HeadingLevel: string,
375
+ };
376
+ }
377
+
378
+ type THintSource = "search" | "av" | "hint";
379
+
380
+ type TTurnIntoOne = "BlocksMergeSuperBlock" | "Blocks2ULs" | "Blocks2OLs" | "Blocks2TLs" | "Blocks2Blockquote"
381
+
382
+ type TTurnIntoOneSub = "row" | "col"
383
+
384
+ type TTurnInto = "Blocks2Ps" | "Blocks2Hs"
385
+
386
+ type TEditorMode = "preview" | "wysiwyg"
387
+
388
+ type ILuteRenderCallback = (node: ILuteNode, entering: boolean) => [string, number];
389
+
390
+ export type TProtyleAction = "cb-get-append" | // 向下滚动加载
391
+ "cb-get-before" | // 向上滚动加载
392
+ "cb-get-unchangeid" | // 上下滚动,定位时不修改 blockid
393
+ "cb-get-hl" | // 高亮
394
+ "cb-get-focus" | // 光标定位
395
+ "cb-get-focusfirst" | // 动态定位到第一个块
396
+ "cb-get-setid" | // 无折叠大纲点击 重置 blockid
397
+ "cb-get-outline" | // 大纲点击
398
+ "cb-get-all" | // 获取所有块
399
+ "cb-get-backlink" | // 悬浮窗为传递型需展示上下文
400
+ "cb-get-unundo" | // 不需要记录历史
401
+ "cb-get-scroll" | // 滚动到指定位置,用于直接打开文档,必有 rootID
402
+ "cb-get-context" | // 包含上下文
403
+ "cb-get-rootscroll" | // 如果为 rootID 就滚动到指定位置,必有 rootID
404
+ "cb-get-html" | // 直接渲染,不需要再 /api/block/getDocInfo,否则搜索表格无法定位
405
+ "cb-get-history" | // 历史渲染
406
+ "cb-get-opennew" // 编辑器只读后新建文件需为临时解锁状态 & https://github.com/siyuan-note/siyuan/issues/12197
407
+
408
+ /** @link https://ld246.com/article/1588412297062 */
409
+ interface ILuteRender {
410
+ renderDocument?: ILuteRenderCallback;
411
+ renderParagraph?: ILuteRenderCallback;
412
+ renderText?: ILuteRenderCallback;
413
+ renderCodeBlock?: ILuteRenderCallback;
414
+ renderCodeBlockOpenMarker?: ILuteRenderCallback;
415
+ renderCodeBlockInfoMarker?: ILuteRenderCallback;
416
+ renderCodeBlockCode?: ILuteRenderCallback;
417
+ renderCodeBlockCloseMarker?: ILuteRenderCallback;
418
+ renderMathBlock?: ILuteRenderCallback;
419
+ renderMathBlockOpenMarker?: ILuteRenderCallback;
420
+ renderMathBlockContent?: ILuteRenderCallback;
421
+ renderMathBlockCloseMarker?: ILuteRenderCallback;
422
+ renderBlockquote?: ILuteRenderCallback;
423
+ renderBlockquoteMarker?: ILuteRenderCallback;
424
+ renderHeading?: ILuteRenderCallback;
425
+ renderHeadingC8hMarker?: ILuteRenderCallback;
426
+ renderList?: ILuteRenderCallback;
427
+ renderListItem?: ILuteRenderCallback;
428
+ renderTaskListItemMarker?: ILuteRenderCallback;
429
+ renderThematicBreak?: ILuteRenderCallback;
430
+ renderHTML?: ILuteRenderCallback;
431
+ renderTable?: ILuteRenderCallback;
432
+ renderTableHead?: ILuteRenderCallback;
433
+ renderTableRow?: ILuteRenderCallback;
434
+ renderTableCell?: ILuteRenderCallback;
435
+ renderCodeSpan?: ILuteRenderCallback;
436
+ renderCodeSpanOpenMarker?: ILuteRenderCallback;
437
+ renderCodeSpanContent?: ILuteRenderCallback;
438
+ renderCodeSpanCloseMarker?: ILuteRenderCallback;
439
+ renderInlineMath?: ILuteRenderCallback;
440
+ renderInlineMathOpenMarker?: ILuteRenderCallback;
441
+ renderInlineMathContent?: ILuteRenderCallback;
442
+ renderInlineMathCloseMarker?: ILuteRenderCallback;
443
+ renderEmphasis?: ILuteRenderCallback;
444
+ renderEmAsteriskOpenMarker?: ILuteRenderCallback;
445
+ renderEmAsteriskCloseMarker?: ILuteRenderCallback;
446
+ renderEmUnderscoreOpenMarker?: ILuteRenderCallback;
447
+ renderEmUnderscoreCloseMarker?: ILuteRenderCallback;
448
+ renderStrong?: ILuteRenderCallback;
449
+ renderStrongA6kOpenMarker?: ILuteRenderCallback;
450
+ renderStrongA6kCloseMarker?: ILuteRenderCallback;
451
+ renderStrongU8eOpenMarker?: ILuteRenderCallback;
452
+ renderStrongU8eCloseMarker?: ILuteRenderCallback;
453
+ renderStrikethrough?: ILuteRenderCallback;
454
+ renderStrikethrough1OpenMarker?: ILuteRenderCallback;
455
+ renderStrikethrough1CloseMarker?: ILuteRenderCallback;
456
+ renderStrikethrough2OpenMarker?: ILuteRenderCallback;
457
+ renderStrikethrough2CloseMarker?: ILuteRenderCallback;
458
+ renderHardBreak?: ILuteRenderCallback;
459
+ renderSoftBreak?: ILuteRenderCallback;
460
+ renderInlineHTML?: ILuteRenderCallback;
461
+ renderLink?: ILuteRenderCallback;
462
+ renderOpenBracket?: ILuteRenderCallback;
463
+ renderCloseBracket?: ILuteRenderCallback;
464
+ renderOpenParen?: ILuteRenderCallback;
465
+ renderCloseParen?: ILuteRenderCallback;
466
+ renderLinkText?: ILuteRenderCallback;
467
+ renderLinkSpace?: ILuteRenderCallback;
468
+ renderLinkDest?: ILuteRenderCallback;
469
+ renderLinkTitle?: ILuteRenderCallback;
470
+ renderImage?: ILuteRenderCallback;
471
+ renderBang?: ILuteRenderCallback;
472
+ renderEmoji?: ILuteRenderCallback;
473
+ renderEmojiUnicode?: ILuteRenderCallback;
474
+ renderEmojiImg?: ILuteRenderCallback;
475
+ renderEmojiAlias?: ILuteRenderCallback;
476
+ renderBackslash?: ILuteRenderCallback;
477
+ renderBackslashContent?: ILuteRenderCallback;
478
+ }
479
+
480
+ interface IBreadcrumb {
481
+ id: string,
482
+ name: string,
483
+ type: string,
484
+ subType: string,
485
+ children: []
486
+ }
487
+
488
+ interface ILuteOptions extends IMarkdownConfig {
489
+ emojis: IObject;
490
+ emojiSite: string;
491
+ headingAnchor: boolean;
492
+ lazyLoadImage?: string;
493
+ }
494
+
495
+ declare class Viz {
496
+ public static instance(): Promise<Viz>;
497
+
498
+ renderSVGElement: (code: string) => SVGElement;
499
+ }
500
+
501
+ declare class Viewer {
502
+ public destroyed: boolean;
503
+
504
+ constructor(element: Element, options: {
505
+ title: [number, (image: HTMLImageElement, imageData: IObject) => string],
506
+ button: boolean,
507
+ initialViewIndex?: number,
508
+ transition: boolean,
509
+ hidden: () => void,
510
+ toolbar: {
511
+ zoomIn: boolean,
512
+ zoomOut: boolean,
513
+ oneToOne: boolean,
514
+ reset: boolean,
515
+ prev: boolean,
516
+ play: boolean,
517
+ next: boolean,
518
+ rotateLeft: boolean,
519
+ rotateRight: boolean,
520
+ flipHorizontal: boolean,
521
+ flipVertical: boolean,
522
+ close: () => void
523
+ }
524
+ })
525
+
526
+ public destroy(): void
527
+
528
+ public show(): void
529
+ }
530
+
531
+ export class Lute {
532
+ public static WalkStop: number;
533
+ public static WalkSkipChildren: number;
534
+ public static WalkContinue: number;
535
+ public static Version: string;
536
+ public static Caret: string;
537
+
538
+ public static New(): Lute;
539
+
540
+ public static EChartsMindmapStr(text: string): string;
541
+
542
+ public static NewNodeID(): string;
543
+
544
+ public static Sanitize(html: string): string;
545
+
546
+ public static EscapeHTMLStr(str: string): string;
547
+
548
+ public static UnEscapeHTMLStr(str: string): string;
549
+
550
+ public static GetHeadingID(node: ILuteNode): string;
551
+
552
+ public static BlockDOM2Content(html: string): string;
553
+
554
+ private constructor();
555
+
556
+ public BlockDOM2Content(text: string): string;
557
+
558
+ public BlockDOM2EscapeMarkerContent(text: string): string;
464
559
 
465
560
  public SetSpin(enable: boolean): void;
466
561
 
@@ -553,69 +648,268 @@ export class Lute {
553
648
  public HTML2Md(html: string): string;
554
649
 
555
650
  public HTML2BlockDOM(html: string): string;
556
- }
557
-
558
- export class Protyle {
559
-
560
- public readonly version: string;
561
- public protyle: IProtyle;
562
-
563
- constructor(app: App, element: HTMLElement, options?: IProtyleOptions)
564
-
565
- /** 聚焦到编辑器 */
566
- public focus(): void
567
-
568
- /** 上传是否还在进行中 */
569
- public isUploading(): boolean
570
651
 
571
- /** 清空 undo & redo 栈 */
572
- public clearStack(): void
652
+ public SetUnorderedListMarker(marker: string): void;
653
+ }
573
654
 
574
- /** 销毁编辑器 */
575
- public destroy(): void
655
+ declare const webkitAudioContext: {
656
+ prototype: AudioContext
657
+ new(contextOptions?: AudioContextOptions): AudioContext,
658
+ };
659
+
660
+ /** @link https://ld246.com/article/1549638745630#options-upload */
661
+ interface IUpload {
662
+ /** 上传 url */
663
+ url?: string;
664
+ /** 上传文件最大 Byte */
665
+ max?: number;
666
+ /** 剪切板中包含图片地址时,使用此 url 重新上传 */
667
+ linkToImgUrl?: string;
668
+ /** CORS 上传验证,头为 X-Upload-Token */
669
+ token?: string;
670
+ /** 文件上传类型,同 [input accept](https://www.w3schools.com/tags/att_input_accept.asp) */
671
+ accept?: string;
672
+ /** 跨站点访问控制。默认值: false */
673
+ withCredentials?: boolean;
674
+ /** 请求头设置 */
675
+ headers?: IObject;
676
+ /** 额外请求参数 */
677
+ extraData?: { [key: string]: string | Blob };
678
+ /** 上传字段名。默认值:file[] */
679
+ fieldName?: string;
680
+
681
+ /** 每次上传前都会重新设置请求头 */
682
+ setHeaders?(): IObject;
683
+
684
+ /** 上传成功回调 */
685
+ success?(editor: HTMLDivElement, msg: string): void;
686
+
687
+ /** 上传失败回调 */
688
+ error?(msg: string): void;
689
+
690
+ /** 文件名安全处理。 默认值: name => name.replace(/\W/g, '') */
691
+ filename?(name: string): string;
692
+
693
+ /** 校验,成功时返回 true 否则返回错误信息 */
694
+ validate?(files: File[]): string | boolean;
695
+
696
+ /** 自定义上传,当发生错误时返回错误信息 */
697
+ handler?(files: File[]): string | null;
698
+
699
+ /** 对服务端返回的数据进行转换,以满足内置的数据结构 */
700
+ format?(files: File[], responseText: string): string;
701
+
702
+ /** 将上传的文件处理后再返回 */
703
+ file?(files: File[]): File[];
704
+
705
+ /** 图片地址上传后的回调 */
706
+ linkToImgCallback?(responseText: string): void;
707
+ }
576
708
 
577
- public resize(): void
709
+ interface IScrollAttr {
710
+ rootId: string,
711
+ startId: string,
712
+ endId: string
713
+ scrollTop: number,
714
+ focusId?: string,
715
+ focusStart?: number
716
+ focusEnd?: number
717
+ zoomInId?: string
718
+ }
578
719
 
579
- public reload(focus: boolean): void
720
+ /** @link https://ld246.com/article/1549638745630#options-toolbar */
721
+ interface IMenuItem {
722
+ /** 唯一标示 */
723
+ name: string;
724
+ /** 提示 */
725
+ tip?: string;
726
+ /** 语言 key */
727
+ lang?: string;
728
+ /** svg 图标 */
729
+ icon?: string;
730
+ /** 快捷键 */
731
+ hotkey?: string;
732
+ /** 提示的位置 */
733
+ tipPosition?: string;
580
734
 
581
- /**
582
- * @param {boolean} [isBlock=false]
583
- * @param {boolean} [useProtyleRange=false]
584
- */
585
- public insert(html: string, isBlock?: boolean, useProtyleRange?: boolean): void
735
+ click?(protyle: Protyle): void;
736
+ }
586
737
 
587
- public transaction(doOperations: IOperation[], undoOperations?: IOperation[]): void;
738
+ /** @link https://ld246.com/article/1549638745630#options-preview-markdown */
739
+ interface IMarkdownConfig {
740
+ /** 段落开头是否空两格。默认值: false */
741
+ paragraphBeginningSpace?: boolean;
742
+ /** 是否启用过滤 XSS。默认值: true */
743
+ sanitize?: boolean;
744
+ /** 为列表添加标记,以便[自定义列表样式](https://github.com/Vanessa219/vditor/issues/390) 默认值:false */
745
+ listStyle?: boolean;
746
+ }
588
747
 
589
- /**
590
- * 多个块转换为一个块
591
- * @param {TTurnIntoOneSub} [subType] type 为 "BlocksMergeSuperBlock" 时必传
592
- */
593
- public turnIntoOneTransaction(selectsElement: Element[], type: TTurnIntoOne, subType?: TTurnIntoOneSub): void
748
+ /** @link https://ld246.com/article/1549638745630#options-preview */
749
+ interface IPreview {
750
+ /** 预览 debounce 毫秒间隔。默认值: 1000 */
751
+ delay?: number;
752
+ /** 显示模式。默认值: 'both' */
753
+ mode?: "both" | "editor";
754
+ /** md 解析请求 */
755
+ url?: string;
756
+ /** @link https://ld246.com/article/1549638745630#options-preview-markdown */
757
+ markdown?: IMarkdownConfig;
758
+ /** @link https://ld246.com/article/1549638745630#options-preview-actions */
759
+ actions?: Array<IPreviewAction | IPreviewActionCustom>;
760
+
761
+ /** 渲染之前回调 */
762
+ transform?(html: string): string;
763
+ }
594
764
 
595
- /**
596
- * 多个块转换
597
- * @param {Element} [nodeElement] 优先使用包含 protyle-wysiwyg--select 的块,否则使用 nodeElement 单块
598
- * @param type
599
- * @param {number} [subType] type 为 "Blocks2Hs" 时必传
600
- */
601
- public turnIntoTransaction(nodeElement: Element, type: TTurnInto, subType?: number): void
765
+ type IPreviewAction = "desktop" | "tablet" | "mobile" | "mp-wechat" | "zhihu" | "yuque";
766
+
767
+ interface IPreviewActionCustom {
768
+ /** 键名 */
769
+ key: string;
770
+ /** 按钮文本 */
771
+ text: string;
772
+ /** 按钮 className 值 */
773
+ className?: string;
774
+ /** 点击回调 */
775
+ click: (key: string) => void;
776
+ }
602
777
 
603
- public updateTransaction(id: string, newHTML: string, html: string): void
778
+ interface IHintData {
779
+ id?: string;
780
+ html: string;
781
+ value: string;
782
+ filter?: string[];
783
+ focus?: boolean;
784
+ }
604
785
 
605
- public updateBatchTransaction(nodeElements: Element[], cb: (e: HTMLElement) => void): void
786
+ interface IHintExtend {
787
+ key: string;
606
788
 
607
- public getRange(element: Element): Range
789
+ hint?(value: string, protyle: IProtyle, source: THintSource): IHintData[];
790
+ }
608
791
 
609
- public hasClosestBlock(element: Node): false | HTMLElement
792
+ /** @link https://ld246.com/article/1549638745630#options-hint */
793
+ interface IHint {
794
+ /** 常用表情提示 HTML */
795
+ emojiTail?: string;
796
+ /** 提示 debounce 毫秒间隔。默认值: 200 */
797
+ delay?: number;
798
+ /** 默认表情,可从 [lute/emoji_map](https://github.com/88250/lute/blob/master/parse/emoji_map.go#L32) 中选取,也可自定义 */
799
+ emoji?: IObject;
800
+ emojiPath?: string;
801
+ extend?: IHintExtend[];
802
+ }
610
803
 
611
- /**
612
- * @param {boolean} [toStart=true]
613
- */
614
- public focusBlock(element: Element, toStart?: boolean): false | Range
804
+ /** @link https://ld246.com/article/1549638745630#options */
805
+ export interface IProtyleOptions {
806
+ history?: {
807
+ created?: string
808
+ snapshot?: string
809
+ },
810
+ backlinkData?: {
811
+ blockPaths: IBreadcrumb[],
812
+ dom: string
813
+ expand: boolean
814
+ }[],
815
+ action?: TProtyleAction[],
816
+ scrollPosition?: ScrollLogicalPosition,
817
+ mode?: TEditorMode,
818
+ blockId?: string
819
+ rootId?: string
820
+ originalRefBlockIDs?: IObject
821
+ key?: string
822
+ defIds?: string[]
823
+ render?: {
824
+ background?: boolean
825
+ title?: boolean
826
+ titleShowTop?: boolean
827
+ gutter?: boolean
828
+ scroll?: boolean
829
+ breadcrumb?: boolean
830
+ breadcrumbDocName?: boolean
831
+ hideTitleOnZoom?: boolean
832
+ }
833
+ /** 内部调试时使用 */
834
+ _lutePath?: string;
835
+ /** 是否启用打字机模式。默认值: false */
836
+ typewriterMode?: boolean;
837
+ /** 多语言。默认值: 'zh_CN' */
838
+ lang?: string;
839
+ /** @link https://ld246.com/article/1549638745630#options-toolbar */
840
+ toolbar?: Array<string | IMenuItem>;
841
+ /** @link https://ld246.com/article/1549638745630#options-preview */
842
+ preview?: IPreview;
843
+ /** @link https://ld246.com/article/1549638745630#options-hint */
844
+ hint?: IHint;
845
+ /** @link https://ld246.com/article/1549638745630#options-upload */
846
+ upload?: IUpload;
847
+ /** @link https://ld246.com/article/1549638745630#options-classes */
848
+ classes?: {
849
+ preview?: string;
850
+ };
851
+ click?: {
852
+ /** 点击末尾是否阻止插入新块 */
853
+ preventInsetEmptyBlock?: boolean
854
+ }
615
855
 
616
- public disable(): void
856
+ handleEmptyContent?(): void
617
857
 
618
- public enable(): void
858
+ /** 编辑器异步渲染完成后的回调方法 */
859
+ after?(protyle: Protyle): void;
860
+ }
619
861
 
620
- public renderAVAttribute(element: HTMLElement, id: string, cb?: (element: HTMLElement) => void): void
862
+ // REF: https://github.com/siyuan-note/siyuan/blob/dev/app/src/types/protyle.d.ts
863
+ export interface IProtyle {
864
+ highlight: {
865
+ mark: Highlight
866
+ markHL: Highlight
867
+ ranges: Range[]
868
+ rangeIndex: number
869
+ styleElement: HTMLStyleElement
870
+ }
871
+ getInstance: () => Protyle,
872
+ observerLoad?: ResizeObserver,
873
+ observer?: ResizeObserver,
874
+ app: App,
875
+ transactionTime: number,
876
+ id: string,
877
+ query?: {
878
+ key: string,
879
+ method: number
880
+ types: Config.IUILayoutTabSearchConfigTypes
881
+ },
882
+ block: {
883
+ id?: string,
884
+ scroll?: boolean
885
+ parentID?: string,
886
+ parent2ID?: string,
887
+ rootID?: string,
888
+ showAll?: boolean
889
+ mode?: number
890
+ blockCount?: number
891
+ action?: string[]
892
+ },
893
+ disabled: boolean,
894
+ selectElement?: HTMLElement,
895
+ ws?: Model,
896
+ notebookId?: string
897
+ path?: string
898
+ model?: Editor,
899
+ updated: boolean;
900
+ element: HTMLElement;
901
+ scroll?: Scroll,
902
+ gutter?: Gutter,
903
+ breadcrumb?: Breadcrumb,
904
+ title?: Title,
905
+ background?: Background,
906
+ contentElement?: HTMLElement,
907
+ options: IProtyleOptions;
908
+ lute?: Lute;
909
+ toolbar?: Toolbar,
910
+ preview?: Preview;
911
+ hint?: Hint;
912
+ upload?: Upload;
913
+ undo?: Undo;
914
+ wysiwyg?: WYSIWYG
621
915
  }