@block-kit/plugin 1.0.0 → 1.0.3

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 (137) hide show
  1. package/dist/es/bullet-list/index.js +6 -10
  2. package/dist/es/{is-2b264ec8.js → bullet-list/utils/is.js} +2 -2
  3. package/dist/es/bullet-list/view/list.js +9 -0
  4. package/dist/es/divider/index.js +4 -4
  5. package/dist/es/emoji/index.js +1 -1
  6. package/dist/es/image/index.js +11 -121
  7. package/dist/es/image/view/image.js +39 -0
  8. package/dist/es/image/view/wrapper.js +91 -0
  9. package/dist/es/indent/index.js +2 -2
  10. package/dist/es/index.css +1 -1
  11. package/dist/es/index.d.ts +1 -1
  12. package/dist/es/index.js +10 -24
  13. package/dist/es/inline-code/index.js +1 -1
  14. package/dist/es/link/index.js +5 -17
  15. package/dist/es/link/view/a.js +18 -0
  16. package/dist/es/mention/index.js +28 -13
  17. package/dist/es/mention/modules/suggest.js +98 -0
  18. package/dist/es/mention/utils/constant.js +24 -0
  19. package/dist/es/mention/view/suggest.js +72 -0
  20. package/dist/es/order-list/index.js +9 -148
  21. package/dist/es/order-list/utils/format.js +75 -0
  22. package/dist/es/order-list/utils/is.js +12 -0
  23. package/dist/es/order-list/utils/serial.js +68 -0
  24. package/dist/es/order-list/view/list.js +10 -0
  25. package/dist/es/quote/index.js +3 -3
  26. package/dist/es/{selection-badfb0bc.js → shared/components/selection.js} +3 -31
  27. package/dist/es/shared/icons/divider.js +5 -0
  28. package/dist/es/shared/icons/emoji.js +5 -0
  29. package/dist/es/shared/icons/font-color.js +5 -0
  30. package/dist/es/shared/icons/font-size.js +5 -0
  31. package/dist/es/shared/icons/justify.js +5 -0
  32. package/dist/es/shared/icons/line-height.js +5 -0
  33. package/dist/es/shared/icons/text.js +5 -0
  34. package/dist/es/shared/modules/selection.js +32 -0
  35. package/dist/es/{dom-71a99400.js → shared/utils/dom.js} +1 -1
  36. package/dist/es/shared/utils/event.js +5 -0
  37. package/dist/es/{is-3de778e2.js → shared/utils/is.js} +1 -1
  38. package/dist/es/shortcut/index.js +8 -27
  39. package/dist/es/shortcut/modules/preset.js +23 -0
  40. package/dist/es/toolbar/context/basic.js +69 -0
  41. package/dist/es/toolbar/context/float.js +67 -0
  42. package/dist/es/toolbar/context/provider.js +12 -0
  43. package/dist/es/toolbar/index.d.ts +1 -1
  44. package/dist/es/toolbar/index.js +45 -34
  45. package/dist/es/toolbar/modules/align.js +24 -0
  46. package/dist/es/toolbar/modules/bold.js +16 -0
  47. package/dist/es/toolbar/modules/bullet-list.js +17 -0
  48. package/dist/es/toolbar/modules/cut.js +7 -0
  49. package/dist/es/toolbar/modules/divider.js +15 -0
  50. package/dist/es/toolbar/modules/emoji.js +26 -0
  51. package/dist/es/toolbar/modules/font-color.js +50 -0
  52. package/dist/es/toolbar/modules/font-size.js +21 -0
  53. package/dist/es/toolbar/modules/heading.js +23 -0
  54. package/dist/es/toolbar/modules/history.js +35 -0
  55. package/dist/es/toolbar/modules/image.js +15 -0
  56. package/dist/es/toolbar/modules/inline-code.js +15 -0
  57. package/dist/es/toolbar/modules/italic.js +16 -0
  58. package/dist/es/toolbar/modules/line-height.js +17 -0
  59. package/dist/es/toolbar/modules/link.js +99 -0
  60. package/dist/es/toolbar/modules/order-list.js +17 -0
  61. package/dist/es/toolbar/modules/quote.js +15 -0
  62. package/dist/es/toolbar/modules/strike.js +15 -0
  63. package/dist/es/toolbar/modules/underline.js +15 -0
  64. package/dist/es/{marks-ac0ec630.js → toolbar/utils/marks.js} +1 -5
  65. package/dist/lib/bullet-list/index.js +21 -25
  66. package/dist/lib/{is-fa1755d0.js → bullet-list/utils/is.js} +3 -1
  67. package/dist/lib/bullet-list/view/list.js +13 -0
  68. package/dist/lib/divider/index.js +7 -7
  69. package/dist/lib/emoji/index.js +1 -1
  70. package/dist/lib/image/index.js +10 -120
  71. package/dist/lib/image/view/image.js +47 -0
  72. package/dist/lib/image/view/wrapper.js +99 -0
  73. package/dist/lib/indent/index.js +3 -3
  74. package/dist/lib/index.css +1 -1
  75. package/dist/lib/index.d.ts +1 -1
  76. package/dist/lib/index.js +24 -38
  77. package/dist/lib/inline-code/index.js +1 -1
  78. package/dist/lib/link/index.js +3 -15
  79. package/dist/lib/link/view/a.js +22 -0
  80. package/dist/lib/mention/index.js +26 -15
  81. package/dist/lib/mention/modules/suggest.js +106 -0
  82. package/dist/lib/mention/utils/constant.js +29 -0
  83. package/dist/lib/mention/view/suggest.js +76 -0
  84. package/dist/lib/order-list/index.js +34 -173
  85. package/dist/lib/order-list/utils/format.js +79 -0
  86. package/dist/lib/{is-18806678.js → order-list/utils/is.js} +4 -2
  87. package/dist/lib/order-list/utils/serial.js +72 -0
  88. package/dist/lib/order-list/view/list.js +14 -0
  89. package/dist/lib/quote/index.js +12 -12
  90. package/dist/lib/{selection-868f15c1.js → shared/components/selection.js} +2 -29
  91. package/dist/lib/shared/icons/divider.js +9 -0
  92. package/dist/lib/shared/icons/emoji.js +9 -0
  93. package/dist/lib/shared/icons/font-color.js +9 -0
  94. package/dist/lib/shared/icons/font-size.js +9 -0
  95. package/dist/lib/shared/icons/justify.js +9 -0
  96. package/dist/lib/shared/icons/line-height.js +9 -0
  97. package/dist/lib/shared/icons/text.js +9 -0
  98. package/dist/lib/shared/modules/selection.js +36 -0
  99. package/dist/lib/{dom-cb8b8e40.js → shared/utils/dom.js} +2 -0
  100. package/dist/lib/shared/utils/event.js +9 -0
  101. package/dist/lib/{is-473d664a.js → shared/utils/is.js} +2 -0
  102. package/dist/lib/shortcut/index.js +11 -30
  103. package/dist/lib/shortcut/modules/preset.js +27 -0
  104. package/dist/lib/toolbar/context/basic.js +73 -0
  105. package/dist/lib/toolbar/context/float.js +75 -0
  106. package/dist/lib/toolbar/context/provider.js +21 -0
  107. package/dist/lib/toolbar/index.d.ts +1 -1
  108. package/dist/lib/toolbar/index.js +45 -38
  109. package/dist/lib/toolbar/modules/align.js +36 -0
  110. package/dist/lib/toolbar/modules/bold.js +24 -0
  111. package/dist/lib/toolbar/modules/bullet-list.js +25 -0
  112. package/dist/lib/toolbar/modules/cut.js +11 -0
  113. package/dist/lib/toolbar/modules/divider.js +19 -0
  114. package/dist/lib/toolbar/modules/emoji.js +35 -0
  115. package/dist/lib/toolbar/modules/font-color.js +59 -0
  116. package/dist/lib/toolbar/modules/font-size.js +31 -0
  117. package/dist/lib/toolbar/modules/heading.js +35 -0
  118. package/dist/lib/toolbar/modules/history.js +44 -0
  119. package/dist/lib/toolbar/modules/image.js +23 -0
  120. package/dist/lib/toolbar/modules/inline-code.js +23 -0
  121. package/dist/lib/toolbar/modules/italic.js +24 -0
  122. package/dist/lib/toolbar/modules/line-height.js +27 -0
  123. package/dist/lib/toolbar/modules/link.js +114 -0
  124. package/dist/lib/toolbar/modules/order-list.js +25 -0
  125. package/dist/lib/toolbar/modules/quote.js +23 -0
  126. package/dist/lib/toolbar/modules/strike.js +23 -0
  127. package/dist/lib/toolbar/modules/underline.js +23 -0
  128. package/dist/lib/{marks-a30b8a0f.js → toolbar/utils/marks.js} +1 -4
  129. package/dist/styles/index.css +1 -0
  130. package/package.json +7 -6
  131. package/dist/es/index-1e46887d.js +0 -205
  132. package/dist/es/index-ddc2e5ac.js +0 -493
  133. package/dist/es/is-7f3ae820.js +0 -12
  134. package/dist/lib/index-f50053bf.js +0 -506
  135. package/dist/lib/index-ffc4bb34.js +0 -212
  136. /package/dist/es/{tslib.es6-83956cc1.js → tslib.es6-910e0469.js} +0 -0
  137. /package/dist/lib/{tslib.es6-d44c9a95.js → tslib.es6-9953fd0d.js} +0 -0
@@ -0,0 +1,98 @@
1
+ import { _ as __decorate } from '../../tslib.es6-910e0469.js';
2
+ import { jsx } from 'react/jsx-runtime';
3
+ import { Point, EDITOR_EVENT, relativeTo, Range } from '@block-kit/core';
4
+ import { deltaToText, Delta } from '@block-kit/delta';
5
+ import { Bind, KEY_CODE } from '@block-kit/utils';
6
+ import ReactDOM from 'react-dom';
7
+ import { getMountDOM } from '../../shared/utils/dom.js';
8
+ import { isKeyCode } from '../../shared/utils/is.js';
9
+ import { SUGGEST_OFFSET } from '../utils/constant.js';
10
+ import { Suggest } from '../view/suggest.js';
11
+
12
+ class SuggestModule {
13
+ constructor(editor) {
14
+ this.editor = editor;
15
+ this.rect = null;
16
+ this.isMountSuggest = false;
17
+ this.mountSuggestNode = null;
18
+ this.point = new Point(0, 0);
19
+ editor.event.on(EDITOR_EVENT.KEY_DOWN, this.onKeydown, 101);
20
+ }
21
+ destroy() {
22
+ this.unmountSuggestPanel();
23
+ this.editor.event.off(EDITOR_EVENT.KEY_DOWN, this.onKeydown);
24
+ this.editor.event.off(EDITOR_EVENT.SELECTION_CHANGE, this.onSelectionChange);
25
+ }
26
+ onKeydown(event) {
27
+ if (isKeyCode(event, KEY_CODE.D2) && event.shiftKey) {
28
+ const sel = this.editor.selection.get();
29
+ const caretRect = this.editor.rect.getRawCaretRect();
30
+ if (!caretRect || !sel)
31
+ return void 0;
32
+ const editorRect = this.editor.rect.getEditorRect();
33
+ const rect = relativeTo(caretRect, editorRect);
34
+ // 这里是 CSS 预设的面板高度
35
+ const PANEL_HEIGHT = 150;
36
+ if (caretRect.bottom + PANEL_HEIGHT <= window.innerHeight) {
37
+ // 放置于下方
38
+ rect.top = rect.bottom + SUGGEST_OFFSET;
39
+ }
40
+ else {
41
+ // 放置于上方
42
+ rect.top = rect.top - PANEL_HEIGHT - SUGGEST_OFFSET;
43
+ }
44
+ this.rect = { top: rect.top, left: rect.left };
45
+ this.point = sel.start.clone();
46
+ this.editor.event.on(EDITOR_EVENT.SELECTION_CHANGE, this.onSelectionChange);
47
+ }
48
+ if (this.isMountSuggest && isKeyCode(event, KEY_CODE.ESC)) {
49
+ this.unmountSuggestPanel();
50
+ }
51
+ }
52
+ onSelectionChange(event) {
53
+ const { current } = event;
54
+ if (!current ||
55
+ !current.isCollapsed ||
56
+ current.start.line !== this.point.line ||
57
+ current.start.offset <= this.point.offset) {
58
+ this.unmountSuggestPanel();
59
+ return void 0;
60
+ }
61
+ const ops = this.editor.lookup.getFragment(new Range(this.point, current.end));
62
+ if (!ops)
63
+ return void 0;
64
+ const text = deltaToText(new Delta(ops));
65
+ this.mountSuggestPanel(text.slice(1));
66
+ }
67
+ mountSuggestPanel(text = "") {
68
+ if (!this.rect)
69
+ return void 0;
70
+ if (!this.mountSuggestNode) {
71
+ this.mountSuggestNode = document.createElement("div");
72
+ this.mountSuggestNode.dataset.type = "mention";
73
+ getMountDOM(this.editor).appendChild(this.mountSuggestNode);
74
+ }
75
+ const top = this.rect.top;
76
+ const left = this.rect.left;
77
+ const dom = this.mountSuggestNode;
78
+ this.isMountSuggest = true;
79
+ ReactDOM.render(jsx(Suggest, { controller: this, top: top, left: left, text: text }), dom);
80
+ }
81
+ unmountSuggestPanel() {
82
+ if (this.isMountSuggest && this.mountSuggestNode) {
83
+ ReactDOM.unmountComponentAtNode(this.mountSuggestNode);
84
+ }
85
+ this.mountSuggestNode && this.mountSuggestNode.remove();
86
+ this.editor.event.off(EDITOR_EVENT.SELECTION_CHANGE, this.onSelectionChange);
87
+ this.mountSuggestNode = null;
88
+ this.isMountSuggest = false;
89
+ }
90
+ }
91
+ __decorate([
92
+ Bind
93
+ ], SuggestModule.prototype, "onKeydown", null);
94
+ __decorate([
95
+ Bind
96
+ ], SuggestModule.prototype, "onSelectionChange", null);
97
+
98
+ export { SuggestModule };
@@ -0,0 +1,24 @@
1
+ const SUGGEST_OFFSET = 5;
2
+ const DATA = [
3
+ "Alice",
4
+ "Bob",
5
+ "Charlie",
6
+ "David",
7
+ "Eve",
8
+ "Frank",
9
+ "Grace",
10
+ "Heidi",
11
+ "Ivan",
12
+ "Judy",
13
+ "Mallory",
14
+ "Oscar",
15
+ "Peggy",
16
+ "Romeo",
17
+ "Sybil",
18
+ "Trudy",
19
+ "Victor",
20
+ "Walter",
21
+ "Zoe",
22
+ ];
23
+
24
+ export { DATA, SUGGEST_OFFSET };
@@ -0,0 +1,72 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { Range, RawRange, EDITOR_EVENT } from '@block-kit/core';
3
+ import { Delta } from '@block-kit/delta';
4
+ import { KEY_CODE, TRULY, preventNativeEvent, cs } from '@block-kit/utils';
5
+ import { useMemoFn } from '@block-kit/utils/dist/es/hooks';
6
+ import { useRef, useState, useMemo, useEffect } from 'react';
7
+ import { scrollIfNeeded, preventContextEvent } from '../../shared/utils/dom.js';
8
+ import { isKeyCode } from '../../shared/utils/is.js';
9
+ import { MENTION_KEY, MENTION_NAME } from '../types/index.js';
10
+ import { DATA } from '../utils/constant.js';
11
+
12
+ const Suggest = props => {
13
+ const { controller } = props;
14
+ const editor = controller.editor;
15
+ const ref = useRef(null);
16
+ const [activeIndex, setActiveIndex] = useState(0);
17
+ const list = useMemo(() => {
18
+ setActiveIndex(0);
19
+ if (!props.text)
20
+ return DATA;
21
+ return DATA.filter(it => {
22
+ return it.toUpperCase().includes(props.text.toUpperCase());
23
+ });
24
+ }, [props.text]);
25
+ const onKeydown = useMemoFn((event, context) => {
26
+ if (isKeyCode(event, KEY_CODE.DOWN)) {
27
+ const nextIndex = (activeIndex + 1) % list.length;
28
+ setActiveIndex(nextIndex);
29
+ const container = ref.current;
30
+ const child = container && container.children[nextIndex];
31
+ container && child && scrollIfNeeded(container, child, 5);
32
+ preventContextEvent(event, context);
33
+ }
34
+ if (isKeyCode(event, KEY_CODE.UP)) {
35
+ const prevIndex = (activeIndex - 1 + list.length) % list.length;
36
+ setActiveIndex(prevIndex);
37
+ const container = ref.current;
38
+ const child = container && container.children[prevIndex];
39
+ container && child && scrollIfNeeded(container, child, 5);
40
+ preventContextEvent(event, context);
41
+ }
42
+ if (isKeyCode(event, KEY_CODE.ENTER)) {
43
+ const item = list[activeIndex];
44
+ preventContextEvent(event, context);
45
+ const sel = editor.selection.get();
46
+ if (!item || !sel)
47
+ return void 0;
48
+ const range = new Range(controller.point, sel.end);
49
+ const raw = RawRange.fromRange(editor, range);
50
+ if (!raw)
51
+ return void 0;
52
+ const delta = new Delta()
53
+ .retain(raw.start)
54
+ .delete(raw.len)
55
+ .insert(" ", {
56
+ [MENTION_KEY]: TRULY,
57
+ [MENTION_NAME]: item,
58
+ });
59
+ editor.state.apply(delta);
60
+ controller.unmountSuggestPanel();
61
+ }
62
+ });
63
+ useEffect(() => {
64
+ editor.event.on(EDITOR_EVENT.KEY_DOWN, onKeydown, 80);
65
+ return () => {
66
+ editor.event.off(EDITOR_EVENT.KEY_DOWN, onKeydown);
67
+ };
68
+ }, [onKeydown, editor.event]);
69
+ return (jsxs("div", { ref: ref, className: "block-kit-suggest-panel", style: { top: props.top, left: props.left }, onMouseDown: preventNativeEvent, children: [list.map((it, index) => (jsx("div", { className: cs("block-kit-suggest-item", index === activeIndex && "active"), children: it }, index))), !list.length && jsx("div", { className: "block-kit-suggest-empty", children: "No result" })] }));
70
+ };
71
+
72
+ export { Suggest };
@@ -1,156 +1,17 @@
1
- import { _ as __decorate } from '../tslib.es6-83956cc1.js';
2
- import { jsxs, jsx } from 'react/jsx-runtime';
1
+ import { _ as __decorate } from '../tslib.es6-910e0469.js';
2
+ import { jsx } from 'react/jsx-runtime';
3
3
  import { EDITOR_EVENT, RawPoint, Point } from '@block-kit/core';
4
4
  import { Delta } from '@block-kit/delta';
5
5
  import { EditorPlugin } from '@block-kit/react';
6
- import { preventNativeEvent, cs, Bind, KEY_CODE, NIL } from '@block-kit/utils';
6
+ import { Bind, KEY_CODE, NIL } from '@block-kit/utils';
7
7
  import { LIST_TYPE_KEY } from '../bullet-list/types/index.js';
8
8
  import { INDENT_LEVEL_KEY } from '../indent/types/index.js';
9
- import { p as preventContextEvent } from '../dom-71a99400.js';
10
- import { a as isKeyCode, i as isEmptyLine } from '../is-3de778e2.js';
11
- import { LIST_RESTART_KEY, LIST_START_KEY, ORDER_LIST_KEY, ORDER_LIST_TYPE } from './types/index.js';
12
- import { i as isOrderList } from '../is-7f3ae820.js';
13
-
14
- /**
15
- * 批量刷新选区的列表序号 [批量刷新简单方便]
16
- * - 从选区开始的第一个列表项开始,逐个刷新序号
17
- * - 全量刷新序号数据, 最后需要在渲染时批量刷新
18
- * @param editor
19
- * @param sel
20
- */
21
- const applyNewOrderList = (editor, range) => {
22
- const sel = range || editor.selection.get();
23
- if (!sel)
24
- return void 0;
25
- const startPoint = sel.start;
26
- const block = editor.state.block;
27
- let start = startPoint.line;
28
- const selStartLine = block.getLine(sel.start.line);
29
- const selEndLine = block.getLine(sel.end.line);
30
- const selEndNextLine = selEndLine && selEndLine.next();
31
- // 如果当前行不是列表项,且选区结尾下一行是列表项,则从下一行开始探查
32
- if (selStartLine &&
33
- !isOrderList(selStartLine.attributes) &&
34
- selEndNextLine &&
35
- isOrderList(selEndNextLine.attributes)) {
36
- start++;
37
- }
38
- // 如果 start 的行属性不存在列表项, 则无需刷新
39
- const currentLine = block.getLine(start);
40
- if (!currentLine || !isOrderList(currentLine.attributes)) {
41
- return void 0;
42
- }
43
- // 向前查找到第一个列表项
44
- while (--start >= 0) {
45
- const line = block.getLine(start);
46
- if (!line || !isOrderList(line.attributes)) {
47
- start++;
48
- break;
49
- }
50
- }
51
- const delta = new Delta();
52
- const startLine = block.getLine(start);
53
- if (!startLine)
54
- return void 0;
55
- delta.retain(startLine.start);
56
- // 逐行刷新序号
57
- const levelToIndex = {};
58
- for (let i = start; i < block.size; i++) {
59
- const line = block.getLine(i);
60
- const attrs = line && line.attributes;
61
- if (!line || !attrs || !isOrderList(attrs))
62
- break;
63
- const level = attrs[INDENT_LEVEL_KEY];
64
- // 重置序号
65
- if (attrs[LIST_RESTART_KEY]) {
66
- levelToIndex[level] = 1;
67
- }
68
- const index = levelToIndex[level] || 1;
69
- levelToIndex[level] = index + 1;
70
- delta.retain(line.length - 1);
71
- delta.retain(1, { [LIST_START_KEY]: String(index) });
72
- }
73
- editor.state.apply(delta, { autoCaret: false });
74
- };
75
-
76
- const latinCache = {};
77
- const romanCache = {};
78
- const startToLatin = (start) => {
79
- if (start < 1)
80
- return "";
81
- const cache = latinCache[start];
82
- if (cache)
83
- return cache;
84
- // 1 -> a, 27 -> aa
85
- let res = "";
86
- let n = start - 1;
87
- while (n >= 0) {
88
- res = String.fromCharCode((n % 26) + 97) + res;
89
- n = Math.floor(n / 26) - 1;
90
- }
91
- latinCache[start] = res;
92
- return res;
93
- };
94
- const startToRoman = (start) => {
95
- if (start < 1 || start > 5000)
96
- return "";
97
- const cache = romanCache[start];
98
- if (cache)
99
- return cache;
100
- // https://github.com/bpampuch/pdfmake/blob/7af85/src/DocMeasure.js#L315
101
- const lookup = {
102
- m: 1000,
103
- cm: 900,
104
- d: 500,
105
- cd: 400,
106
- c: 100,
107
- xc: 90,
108
- l: 50,
109
- xl: 40,
110
- x: 10,
111
- ix: 9,
112
- v: 5,
113
- iv: 4,
114
- i: 1,
115
- };
116
- let res = "";
117
- let n = start;
118
- for (const i of Object.keys(lookup)) {
119
- while (n >= lookup[i]) {
120
- res = res + i;
121
- n = n - lookup[i];
122
- }
123
- }
124
- romanCache[start] = res;
125
- return res;
126
- };
127
- /**
128
- * 序列化有序列表前缀值
129
- * @param start
130
- * @param level
131
- */
132
- const formatListLevel = (start, level) => {
133
- let serial = "";
134
- const value = level % 3;
135
- if (value === 0) {
136
- // 1 -> 1
137
- serial = start.toString();
138
- }
139
- else if (value === 1) {
140
- // 1 -> a
141
- serial = startToLatin(start);
142
- }
143
- else if (value === 2) {
144
- // 1 -> i
145
- serial = startToRoman(start);
146
- }
147
- return serial + ".";
148
- };
149
-
150
- const OrderListView = props => {
151
- const { level, start, children } = props;
152
- return (jsxs("ol", { className: "block-kit-order-list", children: [jsx("div", { contentEditable: false, className: "block-kit-order-indicator", onMouseDown: preventNativeEvent, children: formatListLevel(start, level) }), jsx("li", { value: start, className: cs("block-kit-order-item", `block-kit-li-level-${level % 3}`), children: children })] }));
153
- };
9
+ import { preventContextEvent } from '../shared/utils/dom.js';
10
+ import { isKeyCode, isEmptyLine } from '../shared/utils/is.js';
11
+ import { ORDER_LIST_KEY, LIST_START_KEY, LIST_RESTART_KEY, ORDER_LIST_TYPE } from './types/index.js';
12
+ import { isOrderList } from './utils/is.js';
13
+ import { applyNewOrderList } from './utils/serial.js';
14
+ import { OrderListView } from './view/list.js';
154
15
 
155
16
  class OrderListPlugin extends EditorPlugin {
156
17
  constructor(editor) {
@@ -0,0 +1,75 @@
1
+ const latinCache = {};
2
+ const romanCache = {};
3
+ const startToLatin = (start) => {
4
+ if (start < 1)
5
+ return "";
6
+ const cache = latinCache[start];
7
+ if (cache)
8
+ return cache;
9
+ // 1 -> a, 27 -> aa
10
+ let res = "";
11
+ let n = start - 1;
12
+ while (n >= 0) {
13
+ res = String.fromCharCode((n % 26) + 97) + res;
14
+ n = Math.floor(n / 26) - 1;
15
+ }
16
+ latinCache[start] = res;
17
+ return res;
18
+ };
19
+ const startToRoman = (start) => {
20
+ if (start < 1 || start > 5000)
21
+ return "";
22
+ const cache = romanCache[start];
23
+ if (cache)
24
+ return cache;
25
+ // https://github.com/bpampuch/pdfmake/blob/7af85/src/DocMeasure.js#L315
26
+ const lookup = {
27
+ m: 1000,
28
+ cm: 900,
29
+ d: 500,
30
+ cd: 400,
31
+ c: 100,
32
+ xc: 90,
33
+ l: 50,
34
+ xl: 40,
35
+ x: 10,
36
+ ix: 9,
37
+ v: 5,
38
+ iv: 4,
39
+ i: 1,
40
+ };
41
+ let res = "";
42
+ let n = start;
43
+ for (const i of Object.keys(lookup)) {
44
+ while (n >= lookup[i]) {
45
+ res = res + i;
46
+ n = n - lookup[i];
47
+ }
48
+ }
49
+ romanCache[start] = res;
50
+ return res;
51
+ };
52
+ /**
53
+ * 序列化有序列表前缀值
54
+ * @param start
55
+ * @param level
56
+ */
57
+ const formatListLevel = (start, level) => {
58
+ let serial = "";
59
+ const value = level % 3;
60
+ if (value === 0) {
61
+ // 1 -> 1
62
+ serial = start.toString();
63
+ }
64
+ else if (value === 1) {
65
+ // 1 -> a
66
+ serial = startToLatin(start);
67
+ }
68
+ else if (value === 2) {
69
+ // 1 -> i
70
+ serial = startToRoman(start);
71
+ }
72
+ return serial + ".";
73
+ };
74
+
75
+ export { formatListLevel };
@@ -0,0 +1,12 @@
1
+ import { LIST_TYPE_KEY } from '../../bullet-list/types/index.js';
2
+ import { ORDER_LIST_TYPE } from '../types/index.js';
3
+
4
+ /**
5
+ * 检查有序列表
6
+ * @param attrs
7
+ */
8
+ const isOrderList = (attrs) => {
9
+ return attrs[LIST_TYPE_KEY] === ORDER_LIST_TYPE;
10
+ };
11
+
12
+ export { isOrderList };
@@ -0,0 +1,68 @@
1
+ import { Delta } from '@block-kit/delta';
2
+ import { INDENT_LEVEL_KEY } from '../../indent/types/index.js';
3
+ import { LIST_RESTART_KEY, LIST_START_KEY } from '../types/index.js';
4
+ import { isOrderList } from './is.js';
5
+
6
+ /**
7
+ * 批量刷新选区的列表序号 [批量刷新简单方便]
8
+ * - 从选区开始的第一个列表项开始,逐个刷新序号
9
+ * - 全量刷新序号数据, 最后需要在渲染时批量刷新
10
+ * @param editor
11
+ * @param sel
12
+ */
13
+ const applyNewOrderList = (editor, range) => {
14
+ const sel = range || editor.selection.get();
15
+ if (!sel)
16
+ return void 0;
17
+ const startPoint = sel.start;
18
+ const block = editor.state.block;
19
+ let start = startPoint.line;
20
+ const selStartLine = block.getLine(sel.start.line);
21
+ const selEndLine = block.getLine(sel.end.line);
22
+ const selEndNextLine = selEndLine && selEndLine.next();
23
+ // 如果当前行不是列表项,且选区结尾下一行是列表项,则从下一行开始探查
24
+ if (selStartLine &&
25
+ !isOrderList(selStartLine.attributes) &&
26
+ selEndNextLine &&
27
+ isOrderList(selEndNextLine.attributes)) {
28
+ start++;
29
+ }
30
+ // 如果 start 的行属性不存在列表项, 则无需刷新
31
+ const currentLine = block.getLine(start);
32
+ if (!currentLine || !isOrderList(currentLine.attributes)) {
33
+ return void 0;
34
+ }
35
+ // 向前查找到第一个列表项
36
+ while (--start >= 0) {
37
+ const line = block.getLine(start);
38
+ if (!line || !isOrderList(line.attributes)) {
39
+ start++;
40
+ break;
41
+ }
42
+ }
43
+ const delta = new Delta();
44
+ const startLine = block.getLine(start);
45
+ if (!startLine)
46
+ return void 0;
47
+ delta.retain(startLine.start);
48
+ // 逐行刷新序号
49
+ const levelToIndex = {};
50
+ for (let i = start; i < block.size; i++) {
51
+ const line = block.getLine(i);
52
+ const attrs = line && line.attributes;
53
+ if (!line || !attrs || !isOrderList(attrs))
54
+ break;
55
+ const level = attrs[INDENT_LEVEL_KEY];
56
+ // 重置序号
57
+ if (attrs[LIST_RESTART_KEY]) {
58
+ levelToIndex[level] = 1;
59
+ }
60
+ const index = levelToIndex[level] || 1;
61
+ levelToIndex[level] = index + 1;
62
+ delta.retain(line.length - 1);
63
+ delta.retain(1, { [LIST_START_KEY]: String(index) });
64
+ }
65
+ editor.state.apply(delta, { autoCaret: false });
66
+ };
67
+
68
+ export { applyNewOrderList };
@@ -0,0 +1,10 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import { preventNativeEvent, cs } from '@block-kit/utils';
3
+ import { formatListLevel } from '../utils/format.js';
4
+
5
+ const OrderListView = props => {
6
+ const { level, start, children } = props;
7
+ return (jsxs("ol", { className: "block-kit-order-list", children: [jsx("div", { contentEditable: false, className: "block-kit-order-indicator", onMouseDown: preventNativeEvent, children: formatListLevel(start, level) }), jsx("li", { value: start, className: cs("block-kit-order-item", `block-kit-li-level-${level % 3}`), children: children })] }));
8
+ };
9
+
10
+ export { OrderListView };
@@ -1,11 +1,11 @@
1
- import { _ as __decorate } from '../tslib.es6-83956cc1.js';
1
+ import { _ as __decorate } from '../tslib.es6-910e0469.js';
2
2
  import { jsx } from 'react/jsx-runtime';
3
3
  import { EDITOR_EVENT, RawPoint, Point } from '@block-kit/core';
4
4
  import { Delta } from '@block-kit/delta';
5
5
  import { InjectWrapKeys, EditorPlugin } from '@block-kit/react';
6
6
  import { Bind, KEY_CODE, NIL, TRULY } from '@block-kit/utils';
7
- import { p as preventContextEvent } from '../dom-71a99400.js';
8
- import { a as isKeyCode, i as isEmptyLine } from '../is-3de778e2.js';
7
+ import { preventContextEvent } from '../shared/utils/dom.js';
8
+ import { isKeyCode, isEmptyLine } from '../shared/utils/is.js';
9
9
  import { QUOTE_KEY } from './types/index.js';
10
10
 
11
11
  class QuotePlugin extends EditorPlugin {
@@ -1,9 +1,8 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
- import { Range, EDITOR_EVENT } from '@block-kit/core';
2
+ import { Range } from '@block-kit/core';
3
3
  import { ReadonlyContext } from '@block-kit/react';
4
- import { getId, cs, Bind } from '@block-kit/utils';
4
+ import { getId, cs } from '@block-kit/utils';
5
5
  import React from 'react';
6
- import { _ as __decorate } from './tslib.es6-83956cc1.js';
7
6
 
8
7
  class SelectionHOC extends React.PureComponent {
9
8
  constructor(props) {
@@ -51,31 +50,4 @@ class SelectionHOC extends React.PureComponent {
51
50
  }
52
51
  SelectionHOC.contextType = ReadonlyContext;
53
52
 
54
- class SelectionPlugin {
55
- constructor(editor) {
56
- this.editor = editor;
57
- this.idToView = new Map();
58
- editor.event.on(EDITOR_EVENT.SELECTION_CHANGE, this.onSelectionChange);
59
- }
60
- destroy() {
61
- this.idToView.clear();
62
- this.editor.event.off(EDITOR_EVENT.SELECTION_CHANGE, this.onSelectionChange);
63
- }
64
- mountView(id, view) {
65
- this.idToView.set(id, view);
66
- }
67
- unmountView(id) {
68
- this.idToView.delete(id);
69
- }
70
- onSelectionChange(e) {
71
- const current = e.current;
72
- this.idToView.forEach(view => {
73
- view.onSelectionChange(current);
74
- });
75
- }
76
- }
77
- __decorate([
78
- Bind
79
- ], SelectionPlugin.prototype, "onSelectionChange", null);
80
-
81
- export { SelectionHOC as S, SelectionPlugin as a };
53
+ export { SelectionHOC };
@@ -0,0 +1,5 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+
3
+ const DividerIcon = () => (jsx("svg", { className: "arco-icon", viewBox: "0 0 1024 1024", xmlns: "http://www.w3.org/2000/svg", width: "1em", height: "1em", fill: "currentColor", children: jsx("path", { d: "M64.128 810.666667h128a21.333333 21.333333 0 0 1 21.333333 21.333333v42.666667a21.333333 21.333333 0 0 1-21.333333 21.333333h-128a21.333333 21.333333 0 0 1-21.333333-21.333333v-42.666667a21.333333 21.333333 0 0 1 21.333333-21.333333z m384 0h128a21.333333 21.333333 0 0 1 21.333333 21.333333v42.666667a21.333333 21.333333 0 0 1-21.333333 21.333333h-128a21.333333 21.333333 0 0 1-21.333333-21.333333v-42.666667a21.333333 21.333333 0 0 1 21.333333-21.333333z m384 0h128a21.333333 21.333333 0 0 1 21.333333 21.333333v42.666667a21.333333 21.333333 0 0 1-21.333333 21.333333h-128a21.333333 21.333333 0 0 1-21.333333-21.333333v-42.666667a21.333333 21.333333 0 0 1 21.333333-21.333333z m-768-682.666667h128a21.333333 21.333333 0 0 1 21.333333 21.333333v42.666667a21.333333 21.333333 0 0 1-21.333333 21.333333h-128a21.333333 21.333333 0 0 1-21.333333-21.333333V149.333333a21.333333 21.333333 0 0 1 21.333333-21.333333z m384 0h128a21.333333 21.333333 0 0 1 21.333333 21.333333v42.666667a21.333333 21.333333 0 0 1-21.333333 21.333333h-128a21.333333 21.333333 0 0 1-21.333333-21.333333V149.333333a21.333333 21.333333 0 0 1 21.333333-21.333333z m384 0h128a21.333333 21.333333 0 0 1 21.333333 21.333333v42.666667a21.333333 21.333333 0 0 1-21.333333 21.333333h-128a21.333333 21.333333 0 0 1-21.333333-21.333333V149.333333a21.333333 21.333333 0 0 1 21.333333-21.333333zM64 469.333333h896a21.333333 21.333333 0 0 1 21.333333 21.333334v42.666666a21.333333 21.333333 0 0 1-21.333333 21.333334H64a21.333333 21.333333 0 0 1-21.333333-21.333334v-42.666666a21.333333 21.333333 0 0 1 21.333333-21.333334z" }) }));
4
+
5
+ export { DividerIcon };
@@ -0,0 +1,5 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+
3
+ const EmojiIcon = () => (jsxs("svg", { className: "arco-icon", viewBox: "0 0 1024 1024", version: "1.1", xmlns: "http://www.w3.org/2000/svg", "p-id": "5996", width: "1em", height: "1em", fill: "currentColor", children: [jsx("path", { d: "M512 128a384 384 0 1 0 0 768 384 384 0 0 0 0-768zM42.666667 512C42.666667 252.8 252.8 42.666667 512 42.666667s469.333333 210.133333 469.333333 469.333333-210.133333 469.333333-469.333333 469.333333S42.666667 771.2 42.666667 512z m533.333333-64a42.666667 42.666667 0 0 1 42.666667-42.666667h85.333333a42.666667 42.666667 0 1 1 0 85.333334h-85.333333a42.666667 42.666667 0 0 1-42.666667-42.666667z m-254.165333 193.834667a42.666667 42.666667 0 0 1 60.330666 0 183.594667 183.594667 0 0 0 259.669334 0 42.666667 42.666667 0 0 1 60.330666 60.330666 268.928 268.928 0 0 1-380.330666 0 42.666667 42.666667 0 0 1 0-60.330666z" }), jsx("path", { d: "M362.666667 362.666667a42.666667 42.666667 0 0 1 42.666666 42.666666v80a42.666667 42.666667 0 0 1-85.333333 0V405.333333a42.666667 42.666667 0 0 1 42.666667-42.666666z" })] }));
4
+
5
+ export { EmojiIcon };
@@ -0,0 +1,5 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+
3
+ const FontColorIcon = () => (jsx("svg", { className: "arco-icon", viewBox: "0 0 1024 1024", version: "1.1", xmlns: "http://www.w3.org/2000/svg", width: "1em", height: "1em", fill: "currentColor", children: jsx("path", { d: "M594.9 842.3h-94.3l-67.4-180.9H158L94.4 842.3H0.1l251.7-660.9h91.3l251.8 660.9zM406.7 586.7l-99.8-274.8c-3.1-8.8-6.5-24.2-10.2-46.1h-2.1c-3.1 19.9-6.7 35.3-10.7 46.1l-99 274.8h221.8z m284.2-183.4c46.9-29.3 101.1-43.9 162.6-43.9 113.8 0 170.7 59.7 170.7 179.2v303.8h-82.8v-73h-2.1c-32.7 56-80.9 84.1-144.6 84.1-45.8 0-82.2-12.4-109.2-37.1-27-24.7-40.5-58.2-40.5-100.3 0-88.2 52.2-139.5 156.6-154l139.9-19.6c0-77.1-31.9-115.6-95.6-115.6-56.6 0-108.2 19.1-154.9 57.2v-80.8z m139.9 217.1c-38.7 5.1-65.4 14.8-80 29-14.7 14.2-22 34.1-22 59.7 0 22.5 8 40.8 23.9 55 15.9 14.2 37 21.3 63.1 21.3 36.4 0 66.4-12.8 90-38.4 23.6-25.6 35.4-57.7 35.4-96.4v-45.2l-110.4 15z" }) }));
4
+
5
+ export { FontColorIcon };
@@ -0,0 +1,5 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+
3
+ const FontSizeIcon = () => (jsxs("svg", { className: "arco-icon", viewBox: "0 0 1024 1024", version: "1.1", xmlns: "http://www.w3.org/2000/svg", width: "1em", height: "1em", fill: "currentColor", children: [jsx("path", { d: "M597.333333 853.333333h85.333334L426.666667 170.666667H341.333333L85.333333 853.333333h85.333334l80-213.333333h266.666666z m-314.666666-298.666666L384 284.458667 485.333333 554.666667z" }), jsx("path", { d: "M918.784 331.178667V257.450667L832 170.666667l-86.784 86.784v73.728L810.666667 265.685333v492.629334l-65.450667-65.493334v73.728L832 853.333333l86.784-86.784v-73.728L853.333333 758.314667V265.685333l65.450667 65.493334z" })] }));
4
+
5
+ export { FontSizeIcon };
@@ -0,0 +1,5 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+
3
+ const JustifyIcon = () => (jsx("svg", { className: "arco-icon", viewBox: "0 0 1024 1024", version: "1.1", xmlns: "http://www.w3.org/2000/svg", width: "1em", height: "1em", fill: "currentColor", children: jsx("path", { d: "M875.975111 823.978667a36.010667 36.010667 0 1 1 0 72.021333H148.024889a36.010667 36.010667 0 1 1 0-72.021333h727.950222z m0-231.992889a36.010667 36.010667 0 1 1 0 72.021333H148.024889a36.010667 36.010667 0 1 1 0-72.021333h727.950222z m0-231.992889a36.010667 36.010667 0 1 1 0 72.021333H148.024889a36.010667 36.010667 0 0 1 0-72.021333h727.950222z m0-231.992889a36.010667 36.010667 0 1 1 0 72.021333H148.024889a36.010667 36.010667 0 0 1 0-72.021333h727.950222z", fill: "currentColor" }) }));
4
+
5
+ export { JustifyIcon };
@@ -0,0 +1,5 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+
3
+ const LineHeightIcon = () => (jsx("svg", { className: "arco-icon", viewBox: "0 0 1024 1024", version: "1.1", xmlns: "http://www.w3.org/2000/svg", width: "1em", height: "1em", fill: "currentColor", children: jsx("path", { d: "M469.333333 170.666667h426.666667v85.333333H469.333333V170.666667zM256 298.666667v170.666666H170.666667V298.666667H42.666667l170.666666-170.666667 170.666667 170.666667H256z m0 426.666666h128l-170.666667 170.666667-170.666666-170.666667h128v-170.666666h85.333333v170.666666z m213.333333 42.666667h426.666667v85.333333H469.333333v-85.333333z m-85.333333-298.666667h512v85.333334H384v-85.333334z" }) }));
4
+
5
+ export { LineHeightIcon };
@@ -0,0 +1,5 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+
3
+ const TextIcon = () => (jsx("svg", { className: "arco-icon", viewBox: "0 0 1024 1024", version: "1.1", xmlns: "http://www.w3.org/2000/svg", width: "1em", height: "1em", fill: "currentColor", children: jsx("path", { d: "M853.333333 138.666667H170.666667c-17.066667 0-32 14.933333-32 32v128c0 17.066667 14.933333 32 32 32s32-14.933333 32-32V202.666667h277.333333v618.666666H384c-17.066667 0-32 14.933333-32 32s14.933333 32 32 32h256c17.066667 0 32-14.933333 32-32s-14.933333-32-32-32h-96v-618.666666h277.333333V298.666667c0 17.066667 14.933333 32 32 32s32-14.933333 32-32V170.666667c0-17.066667-14.933333-32-32-32z" }) }));
4
+
5
+ export { TextIcon };