@kaitify/core 0.0.1-beta.9 → 0.0.1

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.
Files changed (39) hide show
  1. package/README.md +2 -2
  2. package/lib/extensions/Extension.d.ts +14 -14
  3. package/lib/extensions/align/index.d.ts +9 -0
  4. package/lib/extensions/attachment/index.d.ts +15 -0
  5. package/lib/extensions/back-color/index.d.ts +9 -0
  6. package/lib/extensions/blockquote/index.d.ts +15 -0
  7. package/lib/extensions/bold/index.d.ts +9 -0
  8. package/lib/extensions/code/index.d.ts +15 -0
  9. package/lib/extensions/code-block/index.d.ts +18 -0
  10. package/lib/extensions/color/index.d.ts +9 -0
  11. package/lib/extensions/font-family/index.d.ts +9 -0
  12. package/lib/extensions/font-size/index.d.ts +9 -0
  13. package/lib/extensions/heading/index.d.ts +15 -0
  14. package/lib/extensions/history/index.d.ts +12 -0
  15. package/lib/extensions/horizontal/index.d.ts +3 -0
  16. package/lib/extensions/image/index.d.ts +12 -0
  17. package/lib/extensions/indent/index.d.ts +10 -0
  18. package/lib/extensions/italic/index.d.ts +9 -0
  19. package/lib/extensions/line-height/index.d.ts +9 -0
  20. package/lib/extensions/link/index.d.ts +15 -0
  21. package/lib/extensions/list/index.d.ts +26 -0
  22. package/lib/extensions/math/index.d.ts +12 -0
  23. package/lib/extensions/strikethrough/index.d.ts +9 -0
  24. package/lib/extensions/subscript/index.d.ts +9 -0
  25. package/lib/extensions/superscript/index.d.ts +9 -0
  26. package/lib/extensions/table/index.d.ts +30 -0
  27. package/lib/extensions/task/index.d.ts +15 -0
  28. package/lib/extensions/text/index.d.ts +21 -0
  29. package/lib/extensions/underline/index.d.ts +9 -0
  30. package/lib/extensions/video/index.d.ts +12 -0
  31. package/lib/kaitify-core.es.js +1137 -629
  32. package/lib/kaitify-core.umd.js +2 -2
  33. package/lib/model/Editor.d.ts +66 -27
  34. package/lib/model/KNode.d.ts +10 -7
  35. package/lib/model/config/format-rules.d.ts +13 -3
  36. package/lib/model/config/function.d.ts +2 -2
  37. package/lib/tools/index.d.ts +10 -2
  38. package/package.json +3 -3
  39. package/lib/model/config/dom-observe.d.ts +0 -10
@@ -3,6 +3,21 @@ import { Selection } from './Selection';
3
3
  import { History } from './History';
4
4
  import { RuleFunctionType } from './config/format-rules';
5
5
  import { Extension } from '../extensions';
6
+ /**
7
+ * 中文输入的记录数据类型
8
+ */
9
+ export type EditorCompositionDataType = {
10
+ isInput: boolean;
11
+ oldHtml?: string;
12
+ newHtml?: string;
13
+ };
14
+ /**
15
+ * 非法dom更新数据类型
16
+ */
17
+ export type EditorObserverUpdateDataType = {
18
+ elm: Node;
19
+ type: 'add' | 'remove' | 'update';
20
+ };
6
21
  /**
7
22
  * 编辑器获取光标范围内节点数据的类型
8
23
  */
@@ -71,7 +86,7 @@ export type EditorConfigureOptionType = {
71
86
  /**
72
87
  * 自定义dom转为非文本节点的后续处理
73
88
  */
74
- domParseNodeCallback?: (this: Editor, node: KNode) => KNode;
89
+ onDomParseNode?: (this: Editor, node: KNode) => KNode;
75
90
  /**
76
91
  * 视图渲染时触发,如果返回true则表示继续使用默认逻辑,返回false则不走默认逻辑,需要自定义渲染视图
77
92
  */
@@ -131,27 +146,27 @@ export type EditorConfigureOptionType = {
131
146
  /**
132
147
  * 节点粘贴保留标记的自定义方法
133
148
  */
134
- pasteKeepMarks?: (this: Editor, node: KNode) => KNodeMarksType;
149
+ onPasteKeepMarks?: (this: Editor, node: KNode) => KNodeMarksType;
135
150
  /**
136
151
  * 节点粘贴保留样式的自定义方法
137
152
  */
138
- pasteKeepStyles?: (this: Editor, node: KNode) => KNodeStylesType;
153
+ onPasteKeepStyles?: (this: Editor, node: KNode) => KNodeStylesType;
139
154
  /**
140
155
  * 视图更新前回调方法
141
156
  */
142
- beforeUpdateView?: (this: Editor) => void;
157
+ onBeforeUpdateView?: (this: Editor) => void;
143
158
  /**
144
159
  * 视图更新后回调方法
145
160
  */
146
- afterUpdateView?: (this: Editor) => void;
161
+ onAfterUpdateView?: (this: Editor) => void;
147
162
  /**
148
163
  * 在删除和换行操作中块节点从其父节点中抽离出去成为与父节点同级的节点后触发,如果返回true则表示继续使用默认逻辑,会将该节点转为段落,返回false则不走默认逻辑,需要自定义处理
149
164
  */
150
- onDetachMentBlockFromParentCallback?: (this: Editor, node: KNode) => boolean;
165
+ onDetachMentBlockFromParent?: (this: Editor, node: KNode) => boolean;
151
166
  /**
152
167
  * 编辑器updateView执行时,通过比对新旧节点数组获取需要格式化的节点,在这些节点被格式化前,触发此方法,回调参数即当前需要被格式化的节点,该方法返回一个节点,返回的节点将会被格式化,如果你不需要任何特殊处理,返回入参提供的节点即可
153
168
  */
154
- beforePatchNodeToFormat?: (this: Editor, node: KNode) => KNode;
169
+ onBeforePatchNodeToFormat?: (this: Editor, node: KNode) => KNode;
155
170
  /**
156
171
  * 编辑器的初始默认值
157
172
  */
@@ -228,7 +243,7 @@ export declare class Editor {
228
243
  /**
229
244
  * 自定义dom转为非文本节点的后续处理【初始化后不可修改】
230
245
  */
231
- domParseNodeCallback?: (this: Editor, node: KNode) => KNode;
246
+ onDomParseNode?: (this: Editor, node: KNode) => KNode;
232
247
  /**
233
248
  * 视图渲染时触发,如果返回true则表示继续使用默认逻辑,返回false则不走默认逻辑,需要自定义渲染视图【初始化后不可修改】
234
249
  */
@@ -288,27 +303,27 @@ export declare class Editor {
288
303
  /**
289
304
  * 节点粘贴保留标记的自定义方法【初始化后不可修改】
290
305
  */
291
- pasteKeepMarks?: (this: Editor, node: KNode) => KNodeMarksType;
306
+ onPasteKeepMarks?: (this: Editor, node: KNode) => KNodeMarksType;
292
307
  /**
293
308
  * 节点粘贴保留样式的自定义方法【初始化后不可修改】
294
309
  */
295
- pasteKeepStyles?: (this: Editor, node: KNode) => KNodeStylesType;
310
+ onPasteKeepStyles?: (this: Editor, node: KNode) => KNodeStylesType;
296
311
  /**
297
312
  * 视图更新前回调方法【初始化后不可修改】
298
313
  */
299
- beforeUpdateView?: (this: Editor) => void;
314
+ onBeforeUpdateView?: (this: Editor) => void;
300
315
  /**
301
316
  * 视图更新后回调方法【初始化后不可修改】
302
317
  */
303
- afterUpdateView?: (this: Editor) => void;
318
+ onAfterUpdateView?: (this: Editor) => void;
304
319
  /**
305
320
  * 在删除和换行操作中块节点节点从其父节点中抽离出去成为与父节点同级的节点后触发,如果返回true则表示继续使用默认逻辑,会将该节点转为段落,返回false则不走默认逻辑,需要自定义处理【初始化后不可修改】
306
321
  */
307
- onDetachMentBlockFromParentCallback?: (this: Editor, node: KNode) => boolean;
322
+ onDetachMentBlockFromParent?: (this: Editor, node: KNode) => boolean;
308
323
  /**
309
324
  * 编辑器updateView执行时,通过比对新旧节点数组获取需要格式化的节点,在这些节点被格式化前,触发此方法,回调参数即当前需要被格式化的节点,该方法返回一个节点,返回的节点将会被格式化,如果你不需要任何特殊处理,返回入参提供的节点即可【初始化后不可修改】
310
325
  */
311
- beforePatchNodeToFormat?: (this: Editor, node: KNode) => KNode;
326
+ onBeforePatchNodeToFormat?: (this: Editor, node: KNode) => KNode;
312
327
  /**
313
328
  * 唯一id【不可修改】【open】
314
329
  */
@@ -334,17 +349,13 @@ export declare class Editor {
334
349
  */
335
350
  oldStackNodes: KNode[];
336
351
  /**
337
- * 是否在输入中文【不可修改】
352
+ * 中文输入的记录数据【不可修改】
338
353
  */
339
- isComposition: boolean;
354
+ compositionData: EditorCompositionDataType;
340
355
  /**
341
356
  * 是否编辑器内部渲染真实光标引起selctionChange事件【不可修改】
342
357
  */
343
358
  internalCauseSelectionChange: boolean;
344
- /**
345
- * 是否用户操作的删除行为,如果是用户操作的删除行为,则在处理不可编辑的节点是会删除该节点,如果是API调用的删除方法则走正常的删除逻辑【不可修改】
346
- */
347
- isUserDelection: boolean;
348
359
  /**
349
360
  * dom监听【不可修改】
350
361
  */
@@ -377,6 +388,10 @@ export declare class Editor {
377
388
  * 是否深色模式
378
389
  */
379
390
  isDark(): boolean;
391
+ /**
392
+ * 判断编辑器是否为空,这里的空指的是编辑器内只有一个段落,并且段落里只有占位符
393
+ */
394
+ isEmpty(): boolean;
380
395
  /**
381
396
  * dom转KNode
382
397
  */
@@ -408,11 +423,11 @@ export declare class Editor {
408
423
  /**
409
424
  * 获取某个节点内的最后一个可以设置光标点的节点,包括自身
410
425
  */
411
- getLastSelectionNodeInChildren(node: KNode): KNode | null;
426
+ getLastSelectionNode(node: KNode): KNode | null;
412
427
  /**
413
428
  * 获取某个节点内的第一个可以设置光标点的节点,包括自身
414
429
  */
415
- getFirstSelectionNodeInChildren(node: KNode): KNode | null;
430
+ getFirstSelectionNode(node: KNode): KNode | null;
416
431
  /**
417
432
  * 查找指定节点之前可以设置为光标点的非空节点,不包括自身
418
433
  */
@@ -436,7 +451,7 @@ export declare class Editor {
436
451
  /**
437
452
  * 判断光标是否在某个节点内,start表示只判断起点,end表示只判断终点,all表示起点和终点都判断
438
453
  */
439
- isSelectionInNode(node: KNode, type?: 'all' | 'start' | 'end' | undefined): boolean;
454
+ isSelectionInTargetNode(node: KNode, type?: 'all' | 'start' | 'end' | undefined): boolean;
440
455
  /**
441
456
  * 获取光标选区内的节点数据
442
457
  */
@@ -466,7 +481,12 @@ export declare class Editor {
466
481
  */
467
482
  insertText(text: string): void;
468
483
  /**
469
- * 向选区进行换行,如果所在块节点只有占位符并且块节点不是段落则会转为段落
484
+ * 向选区进行换行
485
+ * 1. 所在块节点只有占位符并且块节点不是段落则会转为段落
486
+ * 2. 非代码块样式内换行是插入换行符\n
487
+ * 2. 光标所在块节点是固定块节点,则无法换行
488
+ * 3. 光标所在块节点只有占位符,并且其存在父节点,且父节点不是固定块节点,会从父节点抽离到与父节点同级
489
+ * 4. 光标所在块节点只有占位符,并且不存在父节点,且不是段落,则会转为段落
470
490
  */
471
491
  insertParagraph(): void;
472
492
  /**
@@ -486,7 +506,9 @@ export declare class Editor {
486
506
  */
487
507
  updateRealSelection(): Promise<void>;
488
508
  /**
489
- * 重新渲染编辑器视图,不会触发onChange
509
+ * 重新渲染编辑器视图
510
+ * 1. 不会触发onChange事件;
511
+ * 2. 不会渲染真实光标
490
512
  */
491
513
  review(value: string): Promise<void>;
492
514
  /**
@@ -494,9 +516,26 @@ export declare class Editor {
494
516
  */
495
517
  destroy(): void;
496
518
  /**
497
- * 获取编辑器的纯文本内容
519
+ * 获取编辑器的纯文本内容,excludeBreak表示是否排除换行符\n,excludeZeroWidthText表示是否排除零宽度空白字符
520
+ */
521
+ getContent(excludeBreak?: boolean, excludeZeroWidthText?: boolean): string;
522
+ /**
523
+ * 获取编辑器的html内容,该方法会返回一个包含style标签和div标签的html内容。自行展示html内容时可保证样式与编辑器一致,但是对于附件等有交互事件的元素交互事件会失效
524
+ * cssText用于自定义哪些样式需要保留
525
+ */
526
+ getHTML(filterCssText?: (cssText: string) => boolean): string;
527
+ /**
528
+ * 判断光标是否完全在可视范围内
529
+ */
530
+ isSelectionInView(): boolean;
531
+ /**
532
+ * 移除对编辑器的dom监听
533
+ */
534
+ removeDomObserve(): void;
535
+ /**
536
+ * 设置对编辑器的dom监听,主要解决非法dom插入问题
498
537
  */
499
- getContent(): string;
538
+ setDomObserve(): void;
500
539
  /**
501
540
  * 配置编辑器,返回创建的编辑器
502
541
  */
@@ -44,7 +44,7 @@ export type KNodeCreateOptionType = {
44
44
  children?: KNodeCreateOptionType[];
45
45
  };
46
46
  /**
47
- * 创建零宽度无断空白文本节点的入参类型
47
+ * 创建零宽度空白文本节点的入参类型
48
48
  */
49
49
  export type ZeroWidthTextKNodeCreateOptionType = {
50
50
  marks?: KNodeMarksType;
@@ -148,7 +148,7 @@ export declare class KNode {
148
148
  */
149
149
  isEmpty(): boolean;
150
150
  /**
151
- * 【API】是否零宽度无断空白文本节点
151
+ * 【API】是否零宽度空白文本节点
152
152
  */
153
153
  isZeroWidthText(): boolean;
154
154
  /**
@@ -184,7 +184,7 @@ export declare class KNode {
184
184
  */
185
185
  isEqualMarks(node: KNode): boolean;
186
186
  /**
187
- * 【API】判断当前节点是否在拥有代码块样式的块级节点内(包括自身)
187
+ * 【API】判断当前节点是否在拥有代码块样式的块级节点内(包括自身),是的话返回该块级节点,否则返回null
188
188
  */
189
189
  isInCodeBlockStyle(): KNode | null;
190
190
  /**
@@ -206,11 +206,11 @@ export declare class KNode {
206
206
  /**
207
207
  * 【API】如果当前节点是文本节点或者闭合节点,则判断是不是指定节点后代中所有文本节点和闭合节点中的第一个
208
208
  */
209
- firstTextClosedInNode: (node: KNode) => boolean;
209
+ firstInTargetNode: (node: KNode) => boolean;
210
210
  /**
211
211
  * 【API】如果当前节点是文本节点或者闭合节点,则判断是不是指定节点后代中所有文本节点和闭合节点中的最后一个
212
212
  */
213
- lastTextClosedInNode(node: KNode): boolean;
213
+ lastInTargetNode(node: KNode): boolean;
214
214
  /**
215
215
  * 【API】获取当前节点在某个节点数组中的前一个非空节点
216
216
  */
@@ -228,7 +228,10 @@ export declare class KNode {
228
228
  */
229
229
  getMatchNode(options: KNodeMatchOptionType): KNode | null;
230
230
  /**
231
- * 【API】获取当前节点下的所有可聚焦的节点,如果自身符合也会包括在内,type是all获取闭合节点和文本节点,type是closed获取闭合节点,type是text获取文本节点
231
+ * 【API】获取当前节点下的所有可聚焦的节点,如果自身符合也会包括在内
232
+ * 1. type 是 all 获取闭合节点和文本节点;
233
+ * 2. type 是 closed 获取闭合节点;
234
+ * 3. type 是 text 获取文本节点
232
235
  */
233
236
  getFocusNodes: (type?: "all" | "closed" | "text" | undefined) => KNode[];
234
237
  /**
@@ -236,7 +239,7 @@ export declare class KNode {
236
239
  */
237
240
  static create(options: KNodeCreateOptionType): KNode;
238
241
  /**
239
- * 【API】创建零宽度无断空白文本节点
242
+ * 【API】创建零宽度空白文本节点
240
243
  */
241
244
  static createZeroWidthText(options?: ZeroWidthTextKNodeCreateOptionType): KNode;
242
245
  /**
@@ -12,11 +12,13 @@ export type RuleFunctionType = (state: {
12
12
  */
13
13
  export declare const fomratBlockTagParse: RuleFunctionType;
14
14
  /**
15
- * 针对子节点中的块节点:行内节点的子节点中含有块节点则该节点转为块节点;子节点中的其他节点也转为块节点
15
+ * 针对子节点中的块节点:
16
+ * 1. 子节点中含有块节点则该节点转为块节点;
17
+ * 2. 子节点中含有块节点,则其他节点也转为块节点
16
18
  */
17
19
  export declare const formatBlockInChildren: RuleFunctionType;
18
20
  /**
19
- * 针对节点自身:处理不可编辑的非块级节点:在两侧添加零宽度无断空白字符 & 重置不可编辑节点内的光标位置
21
+ * 针对节点自身:处理不可编辑的非块级节点:在两侧添加零宽度空白字符 & 重置不可编辑节点内的光标位置
20
22
  */
21
23
  export declare const formatUneditableNoodes: RuleFunctionType;
22
24
  /**
@@ -24,7 +26,15 @@ export declare const formatUneditableNoodes: RuleFunctionType;
24
26
  */
25
27
  export declare const formatPlaceholderMerge: RuleFunctionType;
26
28
  /**
27
- * 针对节点自身:将文本节点内连续的零宽度无断空白字符合并(光标可能会更新)
29
+ * 针对节点自身:
30
+ * 1. 统一将文本节点内的\r\n换成\n,解决Windows兼容问题
31
+ * 2. 统一将文本节点内的&nbsp;(\u00A0)换成普通空格
32
+ * 3. 统一将文本节点内的零宽度无断空格换成零宽度空格(\uFEFF -> \u200B)
33
+ * 4. 统一将文本节点内的\n后面加上零宽度空白字符
34
+ */
35
+ export declare const formatLineBreakSpaceText: RuleFunctionType;
36
+ /**
37
+ * 针对节点自身:将文本节点内连续的零宽度空白字符合并(光标可能会更新)
28
38
  */
29
39
  export declare const formatZeroWidthTextMerge: RuleFunctionType;
30
40
  /**
@@ -59,7 +59,7 @@ export declare const handlerForPasteKeepMarksAndStyles: (this: Editor, nodes: KN
59
59
  */
60
60
  export declare const handlerForPasteFiles: (this: Editor, files: FileList) => Promise<void>;
61
61
  /**
62
- * 处理某个节点数组,针对为空的块级节点补充占位符
62
+ * 处理某个节点数组,针对为空的块级节点补充占位符,目前仅用于粘贴处理
63
63
  */
64
64
  export declare const fillPlaceholderToEmptyBlock: (this: Editor, nodes: KNode[]) => void;
65
65
  /**
@@ -71,7 +71,7 @@ export declare const handlerForPasteDrop: (this: Editor, dataTransfer: DataTrans
71
71
  */
72
72
  export declare const removeBlockFromParentToSameLevel: (this: Editor, node: KNode) => void;
73
73
  /**
74
- * 光标所在的块节点不是只有占位,且非固定块节点,非代码块样式的块节点,在该块节点内正常换行方法
74
+ * 光标所在的块节点不是只有占位符,且非固定块节点,非代码块样式的块节点,在该块节点内正常换行方法
75
75
  */
76
76
  export declare const handlerForNormalInsertParagraph: (this: Editor) => void;
77
77
  /**
@@ -8,11 +8,11 @@ export declare const createUniqueKey: () => number;
8
8
  */
9
9
  export declare const createGuid: () => number;
10
10
  /**
11
- * 判断字符串是否零宽度无断空白字符
11
+ * 判断字符串是否零宽度空白字符
12
12
  */
13
13
  export declare const isZeroWidthText: (val: string) => boolean;
14
14
  /**
15
- * 获取一个零宽度无断空白字符
15
+ * 获取一个零宽度空白字符
16
16
  */
17
17
  export declare const getZeroWidthText: () => string;
18
18
  /**
@@ -47,3 +47,11 @@ export declare const delay: (num?: number | undefined) => Promise<void>;
47
47
  * 删除对象的某个属性
48
48
  */
49
49
  export declare const deleteProperty: <T>(val: any, propertyName: string) => T;
50
+ /**
51
+ * 键盘Tab是否按下
52
+ */
53
+ export declare const isOnlyTab: (e: KeyboardEvent) => boolean;
54
+ /**
55
+ * 键盘Tab和shift是否一起按下
56
+ */
57
+ export declare const isTabWithShift: (e: KeyboardEvent) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaitify/core",
3
- "version": "0.0.1-beta.9",
3
+ "version": "0.0.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "author": "so-better",
@@ -17,11 +17,11 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "csstype": "^3.1.3",
20
- "dap-util": "^1.5.9",
20
+ "dap-util": "1.6.0",
21
21
  "highlight.js": "^11.10.0",
22
22
  "interactjs": "^1.10.27",
23
23
  "katex": "^0.16.11",
24
- "vue": "^3.5.12"
24
+ "vue": "^3.3.13"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/katex": "^0.16.7",
@@ -1,10 +0,0 @@
1
- import { Editor } from '../Editor';
2
- /**
3
- * 移除对编辑器的dom监听
4
- */
5
- export declare const removeDomObserve: (editor: Editor) => void;
6
- /**
7
- * 设置对编辑器的dom监听,主要解决非法dom插入问题
8
- * 中文输入和updateView时不会启用dom监听
9
- */
10
- export declare const setDomObserve: (editor: Editor) => void;