@block-kit/plugin 1.0.0 → 1.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.
- package/dist/es/align/{index.js → align/index.js} +1 -1
- package/dist/es/background/{index.js → background/index.js} +1 -1
- package/dist/es/bold/{index.js → bold/index.js} +1 -1
- package/dist/es/bullet-list/{index.js → bullet-list/index.js} +8 -12
- package/dist/es/{is-2b264ec8.js → bullet-list/utils/bullet-list/utils/is.js} +2 -2
- package/dist/es/bullet-list/view/bullet-list/view/list.js +9 -0
- package/dist/es/divider/{index.js → divider/index.js} +5 -5
- package/dist/es/emoji/{index.js → emoji/index.js} +2 -2
- package/dist/es/font-color/{index.js → font-color/index.js} +1 -1
- package/dist/es/font-size/{index.js → font-size/index.js} +1 -1
- package/dist/es/heading/{index.js → heading/index.js} +1 -1
- package/dist/es/image/image/index.js +135 -0
- package/dist/es/image/view/image/view/image.js +39 -0
- package/dist/es/image/view/image/view/wrapper.js +90 -0
- package/dist/es/indent/{index.js → indent/index.js} +3 -3
- package/dist/es/index.css +1 -1
- package/dist/es/index.js +50 -64
- package/dist/es/inline-code/{index.js → inline-code/index.js} +2 -2
- package/dist/es/italic/{index.js → italic/index.js} +1 -1
- package/dist/es/line-height/{index.js → line-height/index.js} +1 -1
- package/dist/es/link/{index.js → link/index.js} +5 -17
- package/dist/es/link/view/link/view/a.js +18 -0
- package/dist/es/mention/mention/index.js +28 -0
- package/dist/es/mention/modules/mention/modules/suggest.js +98 -0
- package/dist/es/mention/utils/mention/utils/constant.js +24 -0
- package/dist/es/mention/view/mention/view/suggest.js +72 -0
- package/dist/es/{tslib.es6-83956cc1.js → node_modules/.pnpm/tslib@2.8.1/node_modules/tslib/tslib.es6.mjs.js} +1 -1
- package/dist/es/order-list/{index.js → order-list/index.js} +11 -150
- package/dist/es/order-list/utils/order-list/utils/format.js +75 -0
- package/dist/es/order-list/utils/order-list/utils/is.js +12 -0
- package/dist/es/order-list/utils/order-list/utils/serial.js +68 -0
- package/dist/es/order-list/view/order-list/view/list.js +10 -0
- package/dist/es/quote/{index.js → quote/index.js} +4 -4
- package/dist/es/{selection-badfb0bc.js → shared/components/shared/components/selection.js} +3 -31
- package/dist/es/shared/icons/shared/icons/divider.js +5 -0
- package/dist/es/shared/icons/shared/icons/emoji.js +5 -0
- package/dist/es/shared/icons/shared/icons/font-color.js +5 -0
- package/dist/es/shared/icons/shared/icons/font-size.js +5 -0
- package/dist/es/shared/icons/shared/icons/justify.js +5 -0
- package/dist/es/shared/icons/shared/icons/line-height.js +5 -0
- package/dist/es/shared/icons/shared/icons/text.js +5 -0
- package/dist/es/shared/modules/shared/modules/selection.js +32 -0
- package/dist/es/{dom-71a99400.js → shared/utils/shared/utils/dom.js} +1 -1
- package/dist/es/shared/utils/shared/utils/event.js +5 -0
- package/dist/es/{is-3de778e2.js → shared/utils/shared/utils/is.js} +1 -1
- package/dist/es/shortcut/modules/shortcut/modules/preset.js +23 -0
- package/dist/es/shortcut/{index.js → shortcut/index.js} +6 -25
- package/dist/es/strike/{index.js → strike/index.js} +1 -1
- package/dist/es/toolbar/context/toolbar/context/basic.js +69 -0
- package/dist/es/toolbar/context/toolbar/context/float.js +67 -0
- package/dist/es/toolbar/context/toolbar/context/provider.js +12 -0
- package/dist/es/toolbar/modules/toolbar/modules/align.js +20 -0
- package/dist/es/toolbar/modules/toolbar/modules/bold.js +16 -0
- package/dist/es/toolbar/modules/toolbar/modules/bullet-list.js +17 -0
- package/dist/es/toolbar/modules/toolbar/modules/cut.js +7 -0
- package/dist/es/toolbar/modules/toolbar/modules/divider.js +15 -0
- package/dist/es/toolbar/modules/toolbar/modules/emoji.js +25 -0
- package/dist/es/toolbar/modules/toolbar/modules/font-color.js +49 -0
- package/dist/es/toolbar/modules/toolbar/modules/font-size.js +19 -0
- package/dist/es/toolbar/modules/toolbar/modules/heading.js +19 -0
- package/dist/es/toolbar/modules/toolbar/modules/history.js +34 -0
- package/dist/es/toolbar/modules/toolbar/modules/image.js +15 -0
- package/dist/es/toolbar/modules/toolbar/modules/inline-code.js +15 -0
- package/dist/es/toolbar/modules/toolbar/modules/italic.js +16 -0
- package/dist/es/toolbar/modules/toolbar/modules/line-height.js +15 -0
- package/dist/es/toolbar/modules/toolbar/modules/link.js +89 -0
- package/dist/es/toolbar/modules/toolbar/modules/order-list.js +17 -0
- package/dist/es/toolbar/modules/toolbar/modules/quote.js +15 -0
- package/dist/es/toolbar/modules/toolbar/modules/strike.js +15 -0
- package/dist/es/toolbar/modules/toolbar/modules/underline.js +15 -0
- package/dist/es/toolbar/toolbar/index.js +45 -0
- package/dist/es/toolbar/types/toolbar/types/index.js +7 -0
- package/dist/es/{marks-ac0ec630.js → toolbar/utils/toolbar/utils/marks.js} +1 -5
- package/dist/es/underline/{index.js → underline/index.js} +1 -1
- package/dist/lib/bullet-list/index.js +21 -25
- package/dist/lib/{is-fa1755d0.js → bullet-list/utils/is.js} +3 -1
- package/dist/lib/bullet-list/view/list.js +13 -0
- package/dist/lib/divider/index.js +7 -7
- package/dist/lib/emoji/index.js +1 -1
- package/dist/lib/image/index.js +9 -119
- package/dist/lib/image/view/image.js +43 -0
- package/dist/lib/image/view/wrapper.js +94 -0
- package/dist/lib/indent/index.js +3 -3
- package/dist/lib/index.css +1 -1
- package/dist/lib/index.js +23 -37
- package/dist/lib/inline-code/index.js +1 -1
- package/dist/lib/link/index.js +3 -15
- package/dist/lib/link/view/a.js +22 -0
- package/dist/lib/mention/index.js +26 -15
- package/dist/lib/mention/modules/suggest.js +106 -0
- package/dist/lib/mention/utils/constant.js +29 -0
- package/dist/lib/mention/view/suggest.js +76 -0
- package/dist/lib/order-list/index.js +34 -173
- package/dist/lib/order-list/utils/format.js +79 -0
- package/dist/lib/{is-18806678.js → order-list/utils/is.js} +4 -2
- package/dist/lib/order-list/utils/serial.js +72 -0
- package/dist/lib/order-list/view/list.js +14 -0
- package/dist/lib/quote/index.js +12 -12
- package/dist/lib/{selection-868f15c1.js → shared/components/selection.js} +2 -29
- package/dist/lib/shared/icons/divider.js +9 -0
- package/dist/lib/shared/icons/emoji.js +9 -0
- package/dist/lib/shared/icons/font-color.js +9 -0
- package/dist/lib/shared/icons/font-size.js +9 -0
- package/dist/lib/shared/icons/justify.js +9 -0
- package/dist/lib/shared/icons/line-height.js +9 -0
- package/dist/lib/shared/icons/text.js +9 -0
- package/dist/lib/shared/modules/selection.js +36 -0
- package/dist/lib/{dom-cb8b8e40.js → shared/utils/dom.js} +2 -0
- package/dist/lib/shared/utils/event.js +9 -0
- package/dist/lib/{is-473d664a.js → shared/utils/is.js} +2 -0
- package/dist/lib/shortcut/index.js +8 -27
- package/dist/lib/shortcut/modules/preset.js +27 -0
- package/dist/lib/toolbar/context/basic.js +73 -0
- package/dist/lib/toolbar/context/float.js +75 -0
- package/dist/lib/toolbar/context/provider.js +21 -0
- package/dist/lib/toolbar/index.js +45 -38
- package/dist/lib/toolbar/modules/align.js +24 -0
- package/dist/lib/toolbar/modules/bold.js +20 -0
- package/dist/lib/toolbar/modules/bullet-list.js +21 -0
- package/dist/lib/toolbar/modules/cut.js +11 -0
- package/dist/lib/toolbar/modules/divider.js +19 -0
- package/dist/lib/toolbar/modules/emoji.js +33 -0
- package/dist/lib/toolbar/modules/font-color.js +53 -0
- package/dist/lib/toolbar/modules/font-size.js +23 -0
- package/dist/lib/toolbar/modules/heading.js +23 -0
- package/dist/lib/toolbar/modules/history.js +38 -0
- package/dist/lib/toolbar/modules/image.js +19 -0
- package/dist/lib/toolbar/modules/inline-code.js +19 -0
- package/dist/lib/toolbar/modules/italic.js +20 -0
- package/dist/lib/toolbar/modules/line-height.js +19 -0
- package/dist/lib/toolbar/modules/link.js +97 -0
- package/dist/lib/toolbar/modules/order-list.js +21 -0
- package/dist/lib/toolbar/modules/quote.js +19 -0
- package/dist/lib/toolbar/modules/strike.js +19 -0
- package/dist/lib/toolbar/modules/underline.js +19 -0
- package/dist/lib/{marks-a30b8a0f.js → toolbar/utils/marks.js} +1 -4
- package/dist/styles/index.css +1 -0
- package/package.json +6 -6
- package/dist/es/image/index.js +0 -245
- package/dist/es/index-1e46887d.js +0 -205
- package/dist/es/index-ddc2e5ac.js +0 -493
- package/dist/es/is-7f3ae820.js +0 -12
- package/dist/es/mention/index.js +0 -13
- package/dist/es/toolbar/index.js +0 -34
- package/dist/es/toolbar/types/index.js +0 -7
- package/dist/lib/index-f50053bf.js +0 -506
- package/dist/lib/index-ffc4bb34.js +0 -212
- /package/dist/es/align/types/{index.js → align/types/index.js} +0 -0
- /package/dist/es/background/types/{index.js → background/types/index.js} +0 -0
- /package/dist/es/bold/types/{index.js → bold/types/index.js} +0 -0
- /package/dist/es/bullet-list/types/{index.js → bullet-list/types/index.js} +0 -0
- /package/dist/es/divider/types/{index.js → divider/types/index.js} +0 -0
- /package/dist/es/emoji/types/{index.js → emoji/types/index.js} +0 -0
- /package/dist/es/font-color/types/{index.js → font-color/types/index.js} +0 -0
- /package/dist/es/font-size/types/{index.js → font-size/types/index.js} +0 -0
- /package/dist/es/heading/types/{index.js → heading/types/index.js} +0 -0
- /package/dist/es/image/types/{index.js → image/types/index.js} +0 -0
- /package/dist/es/indent/types/{index.js → indent/types/index.js} +0 -0
- /package/dist/es/inline-code/types/{index.js → inline-code/types/index.js} +0 -0
- /package/dist/es/italic/types/{index.js → italic/types/index.js} +0 -0
- /package/dist/es/line-height/types/{index.js → line-height/types/index.js} +0 -0
- /package/dist/es/link/types/{index.js → link/types/index.js} +0 -0
- /package/dist/es/mention/types/{index.js → mention/types/index.js} +0 -0
- /package/dist/es/order-list/types/{index.js → order-list/types/index.js} +0 -0
- /package/dist/es/quote/types/{index.js → quote/types/index.js} +0 -0
- /package/dist/es/shortcut/types/{index.js → shortcut/types/index.js} +0 -0
- /package/dist/es/strike/types/{index.js → strike/types/index.js} +0 -0
- /package/dist/es/underline/types/{index.js → underline/types/index.js} +0 -0
- /package/dist/lib/{tslib.es6-d44c9a95.js → tslib.es6-82029525.js} +0 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib_es6 = require('../../tslib.es6-82029525.js');
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
var core = require('@block-kit/core');
|
|
8
|
+
var delta = require('@block-kit/delta');
|
|
9
|
+
var utils = require('@block-kit/utils');
|
|
10
|
+
var ReactDOM = require('react-dom');
|
|
11
|
+
var shared_utils_dom = require('../../shared/utils/dom.js');
|
|
12
|
+
var shared_utils_is = require('../../shared/utils/is.js');
|
|
13
|
+
var mention_utils_constant = require('../utils/constant.js');
|
|
14
|
+
var mention_view_suggest = require('../view/suggest.js');
|
|
15
|
+
|
|
16
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
17
|
+
|
|
18
|
+
var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
|
|
19
|
+
|
|
20
|
+
class SuggestModule {
|
|
21
|
+
constructor(editor) {
|
|
22
|
+
this.editor = editor;
|
|
23
|
+
this.rect = null;
|
|
24
|
+
this.isMountSuggest = false;
|
|
25
|
+
this.mountSuggestNode = null;
|
|
26
|
+
this.point = new core.Point(0, 0);
|
|
27
|
+
editor.event.on(core.EDITOR_EVENT.KEY_DOWN, this.onKeydown, 101);
|
|
28
|
+
}
|
|
29
|
+
destroy() {
|
|
30
|
+
this.unmountSuggestPanel();
|
|
31
|
+
this.editor.event.off(core.EDITOR_EVENT.KEY_DOWN, this.onKeydown);
|
|
32
|
+
this.editor.event.off(core.EDITOR_EVENT.SELECTION_CHANGE, this.onSelectionChange);
|
|
33
|
+
}
|
|
34
|
+
onKeydown(event) {
|
|
35
|
+
if (shared_utils_is.isKeyCode(event, utils.KEY_CODE.D2) && event.shiftKey) {
|
|
36
|
+
const sel = this.editor.selection.get();
|
|
37
|
+
const caretRect = this.editor.rect.getRawCaretRect();
|
|
38
|
+
if (!caretRect || !sel)
|
|
39
|
+
return void 0;
|
|
40
|
+
const editorRect = this.editor.rect.getEditorRect();
|
|
41
|
+
const rect = core.relativeTo(caretRect, editorRect);
|
|
42
|
+
// 这里是 CSS 预设的面板高度
|
|
43
|
+
const PANEL_HEIGHT = 150;
|
|
44
|
+
if (caretRect.bottom + PANEL_HEIGHT <= window.innerHeight) {
|
|
45
|
+
// 放置于下方
|
|
46
|
+
rect.top = rect.bottom + mention_utils_constant.SUGGEST_OFFSET;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
// 放置于上方
|
|
50
|
+
rect.top = rect.top - PANEL_HEIGHT - mention_utils_constant.SUGGEST_OFFSET;
|
|
51
|
+
}
|
|
52
|
+
this.rect = { top: rect.top, left: rect.left };
|
|
53
|
+
this.point = sel.start.clone();
|
|
54
|
+
this.editor.event.on(core.EDITOR_EVENT.SELECTION_CHANGE, this.onSelectionChange);
|
|
55
|
+
}
|
|
56
|
+
if (this.isMountSuggest && shared_utils_is.isKeyCode(event, utils.KEY_CODE.ESC)) {
|
|
57
|
+
this.unmountSuggestPanel();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
onSelectionChange(event) {
|
|
61
|
+
const { current } = event;
|
|
62
|
+
if (!current ||
|
|
63
|
+
!current.isCollapsed ||
|
|
64
|
+
current.start.line !== this.point.line ||
|
|
65
|
+
current.start.offset <= this.point.offset) {
|
|
66
|
+
this.unmountSuggestPanel();
|
|
67
|
+
return void 0;
|
|
68
|
+
}
|
|
69
|
+
const ops = this.editor.collect.getFragment(new core.Range(this.point, current.end));
|
|
70
|
+
if (!ops)
|
|
71
|
+
return void 0;
|
|
72
|
+
const text = delta.deltaToText(new delta.Delta(ops));
|
|
73
|
+
this.mountSuggestPanel(text.slice(1));
|
|
74
|
+
}
|
|
75
|
+
mountSuggestPanel(text = "") {
|
|
76
|
+
if (!this.rect)
|
|
77
|
+
return void 0;
|
|
78
|
+
if (!this.mountSuggestNode) {
|
|
79
|
+
this.mountSuggestNode = document.createElement("div");
|
|
80
|
+
this.mountSuggestNode.dataset.type = "mention";
|
|
81
|
+
shared_utils_dom.getMountDOM(this.editor).appendChild(this.mountSuggestNode);
|
|
82
|
+
}
|
|
83
|
+
const top = this.rect.top;
|
|
84
|
+
const left = this.rect.left;
|
|
85
|
+
const dom = this.mountSuggestNode;
|
|
86
|
+
this.isMountSuggest = true;
|
|
87
|
+
ReactDOM__default["default"].render(jsxRuntime.jsx(mention_view_suggest.Suggest, { controller: this, top: top, left: left, text: text }), dom);
|
|
88
|
+
}
|
|
89
|
+
unmountSuggestPanel() {
|
|
90
|
+
if (this.isMountSuggest && this.mountSuggestNode) {
|
|
91
|
+
ReactDOM__default["default"].unmountComponentAtNode(this.mountSuggestNode);
|
|
92
|
+
}
|
|
93
|
+
this.mountSuggestNode && this.mountSuggestNode.remove();
|
|
94
|
+
this.editor.event.off(core.EDITOR_EVENT.SELECTION_CHANGE, this.onSelectionChange);
|
|
95
|
+
this.mountSuggestNode = null;
|
|
96
|
+
this.isMountSuggest = false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
tslib_es6.__decorate([
|
|
100
|
+
utils.Bind
|
|
101
|
+
], SuggestModule.prototype, "onKeydown", null);
|
|
102
|
+
tslib_es6.__decorate([
|
|
103
|
+
utils.Bind
|
|
104
|
+
], SuggestModule.prototype, "onSelectionChange", null);
|
|
105
|
+
|
|
106
|
+
exports.SuggestModule = SuggestModule;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const SUGGEST_OFFSET = 5;
|
|
6
|
+
const DATA = [
|
|
7
|
+
"Alice",
|
|
8
|
+
"Bob",
|
|
9
|
+
"Charlie",
|
|
10
|
+
"David",
|
|
11
|
+
"Eve",
|
|
12
|
+
"Frank",
|
|
13
|
+
"Grace",
|
|
14
|
+
"Heidi",
|
|
15
|
+
"Ivan",
|
|
16
|
+
"Judy",
|
|
17
|
+
"Mallory",
|
|
18
|
+
"Oscar",
|
|
19
|
+
"Peggy",
|
|
20
|
+
"Romeo",
|
|
21
|
+
"Sybil",
|
|
22
|
+
"Trudy",
|
|
23
|
+
"Victor",
|
|
24
|
+
"Walter",
|
|
25
|
+
"Zoe",
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
exports.DATA = DATA;
|
|
29
|
+
exports.SUGGEST_OFFSET = SUGGEST_OFFSET;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
+
var core = require('@block-kit/core');
|
|
7
|
+
var delta = require('@block-kit/delta');
|
|
8
|
+
var utils = require('@block-kit/utils');
|
|
9
|
+
var hooks = require('@block-kit/utils/dist/es/hooks');
|
|
10
|
+
var React = require('react');
|
|
11
|
+
var shared_utils_dom = require('../../shared/utils/dom.js');
|
|
12
|
+
var shared_utils_is = require('../../shared/utils/is.js');
|
|
13
|
+
var mention_types_index = require('../types/index.js');
|
|
14
|
+
var mention_utils_constant = require('../utils/constant.js');
|
|
15
|
+
|
|
16
|
+
const Suggest = props => {
|
|
17
|
+
const { controller } = props;
|
|
18
|
+
const editor = controller.editor;
|
|
19
|
+
const ref = React.useRef(null);
|
|
20
|
+
const [activeIndex, setActiveIndex] = React.useState(0);
|
|
21
|
+
const list = React.useMemo(() => {
|
|
22
|
+
setActiveIndex(0);
|
|
23
|
+
if (!props.text)
|
|
24
|
+
return mention_utils_constant.DATA;
|
|
25
|
+
return mention_utils_constant.DATA.filter(it => {
|
|
26
|
+
return it.toUpperCase().includes(props.text.toUpperCase());
|
|
27
|
+
});
|
|
28
|
+
}, [props.text]);
|
|
29
|
+
const onKeydown = hooks.useMemoFn((event, context) => {
|
|
30
|
+
if (shared_utils_is.isKeyCode(event, utils.KEY_CODE.DOWN)) {
|
|
31
|
+
const nextIndex = (activeIndex + 1) % list.length;
|
|
32
|
+
setActiveIndex(nextIndex);
|
|
33
|
+
const container = ref.current;
|
|
34
|
+
const child = container && container.children[nextIndex];
|
|
35
|
+
container && child && shared_utils_dom.scrollIfNeeded(container, child, 5);
|
|
36
|
+
shared_utils_dom.preventContextEvent(event, context);
|
|
37
|
+
}
|
|
38
|
+
if (shared_utils_is.isKeyCode(event, utils.KEY_CODE.UP)) {
|
|
39
|
+
const prevIndex = (activeIndex - 1 + list.length) % list.length;
|
|
40
|
+
setActiveIndex(prevIndex);
|
|
41
|
+
const container = ref.current;
|
|
42
|
+
const child = container && container.children[prevIndex];
|
|
43
|
+
container && child && shared_utils_dom.scrollIfNeeded(container, child, 5);
|
|
44
|
+
shared_utils_dom.preventContextEvent(event, context);
|
|
45
|
+
}
|
|
46
|
+
if (shared_utils_is.isKeyCode(event, utils.KEY_CODE.ENTER)) {
|
|
47
|
+
const item = list[activeIndex];
|
|
48
|
+
shared_utils_dom.preventContextEvent(event, context);
|
|
49
|
+
const sel = editor.selection.get();
|
|
50
|
+
if (!item || !sel)
|
|
51
|
+
return void 0;
|
|
52
|
+
const range = new core.Range(controller.point, sel.end);
|
|
53
|
+
const raw = core.RawRange.fromRange(editor, range);
|
|
54
|
+
if (!raw)
|
|
55
|
+
return void 0;
|
|
56
|
+
const delta$1 = new delta.Delta()
|
|
57
|
+
.retain(raw.start)
|
|
58
|
+
.delete(raw.len)
|
|
59
|
+
.insert(" ", {
|
|
60
|
+
[mention_types_index.MENTION_KEY]: utils.TRULY,
|
|
61
|
+
[mention_types_index.MENTION_NAME]: item,
|
|
62
|
+
});
|
|
63
|
+
editor.state.apply(delta$1);
|
|
64
|
+
controller.unmountSuggestPanel();
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
React.useEffect(() => {
|
|
68
|
+
editor.event.on(core.EDITOR_EVENT.KEY_DOWN, onKeydown, 80);
|
|
69
|
+
return () => {
|
|
70
|
+
editor.event.off(core.EDITOR_EVENT.KEY_DOWN, onKeydown);
|
|
71
|
+
};
|
|
72
|
+
}, [onKeydown, editor.event]);
|
|
73
|
+
return (jsxRuntime.jsxs("div", { ref: ref, className: "block-kit-suggest-panel", style: { top: props.top, left: props.left }, onMouseDown: utils.preventNativeEvent, children: [list.map((it, index) => (jsxRuntime.jsx("div", { className: utils.cs("block-kit-suggest-item", index === activeIndex && "active"), children: it }, index))), !list.length && jsxRuntime.jsx("div", { className: "block-kit-suggest-empty", children: "No result" })] }));
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
exports.Suggest = Suggest;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var tslib_es6 = require('../tslib.es6-
|
|
5
|
+
var tslib_es6 = require('../tslib.es6-82029525.js');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
7
|
var core = require('@block-kit/core');
|
|
8
8
|
var delta = require('@block-kit/delta');
|
|
@@ -10,151 +10,12 @@ var react = require('@block-kit/react');
|
|
|
10
10
|
var utils = require('@block-kit/utils');
|
|
11
11
|
var bulletList_types_index = require('../bullet-list/types/index.js');
|
|
12
12
|
var indent_types_index = require('../indent/types/index.js');
|
|
13
|
-
var
|
|
14
|
-
var
|
|
13
|
+
var shared_utils_dom = require('../shared/utils/dom.js');
|
|
14
|
+
var shared_utils_is = require('../shared/utils/is.js');
|
|
15
15
|
var orderList_types_index = require('./types/index.js');
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
* 批量刷新选区的列表序号 [批量刷新简单方便]
|
|
20
|
-
* - 从选区开始的第一个列表项开始,逐个刷新序号
|
|
21
|
-
* - 全量刷新序号数据, 最后需要在渲染时批量刷新
|
|
22
|
-
* @param editor
|
|
23
|
-
* @param sel
|
|
24
|
-
*/
|
|
25
|
-
const applyNewOrderList = (editor, range) => {
|
|
26
|
-
const sel = range || editor.selection.get();
|
|
27
|
-
if (!sel)
|
|
28
|
-
return void 0;
|
|
29
|
-
const startPoint = sel.start;
|
|
30
|
-
const block = editor.state.block;
|
|
31
|
-
let start = startPoint.line;
|
|
32
|
-
const selStartLine = block.getLine(sel.start.line);
|
|
33
|
-
const selEndLine = block.getLine(sel.end.line);
|
|
34
|
-
const selEndNextLine = selEndLine && selEndLine.next();
|
|
35
|
-
// 如果当前行不是列表项,且选区结尾下一行是列表项,则从下一行开始探查
|
|
36
|
-
if (selStartLine &&
|
|
37
|
-
!is.isOrderList(selStartLine.attributes) &&
|
|
38
|
-
selEndNextLine &&
|
|
39
|
-
is.isOrderList(selEndNextLine.attributes)) {
|
|
40
|
-
start++;
|
|
41
|
-
}
|
|
42
|
-
// 如果 start 的行属性不存在列表项, 则无需刷新
|
|
43
|
-
const currentLine = block.getLine(start);
|
|
44
|
-
if (!currentLine || !is.isOrderList(currentLine.attributes)) {
|
|
45
|
-
return void 0;
|
|
46
|
-
}
|
|
47
|
-
// 向前查找到第一个列表项
|
|
48
|
-
while (--start >= 0) {
|
|
49
|
-
const line = block.getLine(start);
|
|
50
|
-
if (!line || !is.isOrderList(line.attributes)) {
|
|
51
|
-
start++;
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const delta$1 = new delta.Delta();
|
|
56
|
-
const startLine = block.getLine(start);
|
|
57
|
-
if (!startLine)
|
|
58
|
-
return void 0;
|
|
59
|
-
delta$1.retain(startLine.start);
|
|
60
|
-
// 逐行刷新序号
|
|
61
|
-
const levelToIndex = {};
|
|
62
|
-
for (let i = start; i < block.size; i++) {
|
|
63
|
-
const line = block.getLine(i);
|
|
64
|
-
const attrs = line && line.attributes;
|
|
65
|
-
if (!line || !attrs || !is.isOrderList(attrs))
|
|
66
|
-
break;
|
|
67
|
-
const level = attrs[indent_types_index.INDENT_LEVEL_KEY];
|
|
68
|
-
// 重置序号
|
|
69
|
-
if (attrs[orderList_types_index.LIST_RESTART_KEY]) {
|
|
70
|
-
levelToIndex[level] = 1;
|
|
71
|
-
}
|
|
72
|
-
const index = levelToIndex[level] || 1;
|
|
73
|
-
levelToIndex[level] = index + 1;
|
|
74
|
-
delta$1.retain(line.length - 1);
|
|
75
|
-
delta$1.retain(1, { [orderList_types_index.LIST_START_KEY]: String(index) });
|
|
76
|
-
}
|
|
77
|
-
editor.state.apply(delta$1, { autoCaret: false });
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const latinCache = {};
|
|
81
|
-
const romanCache = {};
|
|
82
|
-
const startToLatin = (start) => {
|
|
83
|
-
if (start < 1)
|
|
84
|
-
return "";
|
|
85
|
-
const cache = latinCache[start];
|
|
86
|
-
if (cache)
|
|
87
|
-
return cache;
|
|
88
|
-
// 1 -> a, 27 -> aa
|
|
89
|
-
let res = "";
|
|
90
|
-
let n = start - 1;
|
|
91
|
-
while (n >= 0) {
|
|
92
|
-
res = String.fromCharCode((n % 26) + 97) + res;
|
|
93
|
-
n = Math.floor(n / 26) - 1;
|
|
94
|
-
}
|
|
95
|
-
latinCache[start] = res;
|
|
96
|
-
return res;
|
|
97
|
-
};
|
|
98
|
-
const startToRoman = (start) => {
|
|
99
|
-
if (start < 1 || start > 5000)
|
|
100
|
-
return "";
|
|
101
|
-
const cache = romanCache[start];
|
|
102
|
-
if (cache)
|
|
103
|
-
return cache;
|
|
104
|
-
// https://github.com/bpampuch/pdfmake/blob/7af85/src/DocMeasure.js#L315
|
|
105
|
-
const lookup = {
|
|
106
|
-
m: 1000,
|
|
107
|
-
cm: 900,
|
|
108
|
-
d: 500,
|
|
109
|
-
cd: 400,
|
|
110
|
-
c: 100,
|
|
111
|
-
xc: 90,
|
|
112
|
-
l: 50,
|
|
113
|
-
xl: 40,
|
|
114
|
-
x: 10,
|
|
115
|
-
ix: 9,
|
|
116
|
-
v: 5,
|
|
117
|
-
iv: 4,
|
|
118
|
-
i: 1,
|
|
119
|
-
};
|
|
120
|
-
let res = "";
|
|
121
|
-
let n = start;
|
|
122
|
-
for (const i of Object.keys(lookup)) {
|
|
123
|
-
while (n >= lookup[i]) {
|
|
124
|
-
res = res + i;
|
|
125
|
-
n = n - lookup[i];
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
romanCache[start] = res;
|
|
129
|
-
return res;
|
|
130
|
-
};
|
|
131
|
-
/**
|
|
132
|
-
* 序列化有序列表前缀值
|
|
133
|
-
* @param start
|
|
134
|
-
* @param level
|
|
135
|
-
*/
|
|
136
|
-
const formatListLevel = (start, level) => {
|
|
137
|
-
let serial = "";
|
|
138
|
-
const value = level % 3;
|
|
139
|
-
if (value === 0) {
|
|
140
|
-
// 1 -> 1
|
|
141
|
-
serial = start.toString();
|
|
142
|
-
}
|
|
143
|
-
else if (value === 1) {
|
|
144
|
-
// 1 -> a
|
|
145
|
-
serial = startToLatin(start);
|
|
146
|
-
}
|
|
147
|
-
else if (value === 2) {
|
|
148
|
-
// 1 -> i
|
|
149
|
-
serial = startToRoman(start);
|
|
150
|
-
}
|
|
151
|
-
return serial + ".";
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
const OrderListView = props => {
|
|
155
|
-
const { level, start, children } = props;
|
|
156
|
-
return (jsxRuntime.jsxs("ol", { className: "block-kit-order-list", children: [jsxRuntime.jsx("div", { contentEditable: false, className: "block-kit-order-indicator", onMouseDown: utils.preventNativeEvent, children: formatListLevel(start, level) }), jsxRuntime.jsx("li", { value: start, className: utils.cs("block-kit-order-item", `block-kit-li-level-${level % 3}`), children: children })] }));
|
|
157
|
-
};
|
|
16
|
+
var orderList_utils_is = require('./utils/is.js');
|
|
17
|
+
var orderList_utils_serial = require('./utils/serial.js');
|
|
18
|
+
var orderList_view_list = require('./view/list.js');
|
|
158
19
|
|
|
159
20
|
class OrderListPlugin extends react.EditorPlugin {
|
|
160
21
|
constructor(editor) {
|
|
@@ -168,12 +29,12 @@ class OrderListPlugin extends react.EditorPlugin {
|
|
|
168
29
|
this.editor.event.off(core.EDITOR_EVENT.KEY_DOWN, this.onKeyDown);
|
|
169
30
|
}
|
|
170
31
|
match(attrs) {
|
|
171
|
-
return
|
|
32
|
+
return orderList_utils_is.isOrderList(attrs);
|
|
172
33
|
}
|
|
173
34
|
renderLine(context) {
|
|
174
35
|
const level = Number(context.attributes[indent_types_index.INDENT_LEVEL_KEY]) || 0;
|
|
175
36
|
const start = Number(context.attributes[orderList_types_index.LIST_START_KEY]) || 1;
|
|
176
|
-
return (jsxRuntime.jsx(OrderListView, { level: level, start: start, editor: this.editor, context: context, children: context.children }));
|
|
37
|
+
return (jsxRuntime.jsx(orderList_view_list.OrderListView, { level: level, start: start, editor: this.editor, context: context, children: context.children }));
|
|
177
38
|
}
|
|
178
39
|
onExec(payload) {
|
|
179
40
|
const editor = this.editor;
|
|
@@ -183,7 +44,7 @@ class OrderListPlugin extends react.EditorPlugin {
|
|
|
183
44
|
const { start, end } = sel;
|
|
184
45
|
// 先检查当前需要设置/解除列表状态
|
|
185
46
|
const lines = editor.state.block.getLines().slice(start.line, end.line + 1);
|
|
186
|
-
const isList = lines.every(line =>
|
|
47
|
+
const isList = lines.every(line => orderList_utils_is.isOrderList(line.attributes));
|
|
187
48
|
// 计算需要操作的范围
|
|
188
49
|
const rawPoint = core.RawPoint.fromPoint(this.editor, core.Point.from(start.line, 0));
|
|
189
50
|
if (!rawPoint)
|
|
@@ -210,7 +71,7 @@ class OrderListPlugin extends react.EditorPlugin {
|
|
|
210
71
|
delta$1.retain(1, attrs);
|
|
211
72
|
}
|
|
212
73
|
this.editor.state.apply(delta$1, { autoCaret: false });
|
|
213
|
-
applyNewOrderList(this.editor, sel);
|
|
74
|
+
orderList_utils_serial.applyNewOrderList(this.editor, sel);
|
|
214
75
|
}
|
|
215
76
|
onKeyDown(event, context) {
|
|
216
77
|
const sel = this.editor.selection.get();
|
|
@@ -224,10 +85,10 @@ class OrderListPlugin extends react.EditorPlugin {
|
|
|
224
85
|
const attrs = startLine.attributes;
|
|
225
86
|
// 当前行是列表行, 且按下回车键, 且选区折叠, 且当前行是空内容行
|
|
226
87
|
// => 处理列表的缩进等级
|
|
227
|
-
if (
|
|
228
|
-
|
|
88
|
+
if (shared_utils_is.isKeyCode(event, utils.KEY_CODE.ENTER) &&
|
|
89
|
+
orderList_utils_is.isOrderList(attrs) &&
|
|
229
90
|
sel.isCollapsed &&
|
|
230
|
-
|
|
91
|
+
shared_utils_is.isEmptyLine(startLine)) {
|
|
231
92
|
const level = Number(attrs[indent_types_index.INDENT_LEVEL_KEY]);
|
|
232
93
|
const nextAttrs = {};
|
|
233
94
|
if (level > 0) {
|
|
@@ -243,18 +104,18 @@ class OrderListPlugin extends react.EditorPlugin {
|
|
|
243
104
|
}
|
|
244
105
|
const delta$1 = new delta.Delta().retain(startLine.start + startLine.length - 1).retain(1, nextAttrs);
|
|
245
106
|
this.editor.state.apply(delta$1, { autoCaret: false });
|
|
246
|
-
applyNewOrderList(this.editor, sel);
|
|
247
|
-
|
|
107
|
+
orderList_utils_serial.applyNewOrderList(this.editor, sel);
|
|
108
|
+
shared_utils_dom.preventContextEvent(event, context);
|
|
248
109
|
return void 0;
|
|
249
110
|
}
|
|
250
111
|
// 当前行是列表行, 且按下回车键, 且选区折叠, 且位于行首, 且上一行是列表行
|
|
251
112
|
// => 继续编号, 避免默认的处理, 保持列表的连续性
|
|
252
|
-
if (
|
|
253
|
-
|
|
113
|
+
if (shared_utils_is.isKeyCode(event, utils.KEY_CODE.ENTER) &&
|
|
114
|
+
orderList_utils_is.isOrderList(attrs) &&
|
|
254
115
|
sel.isCollapsed &&
|
|
255
116
|
!sel.start.offset &&
|
|
256
117
|
prevLine &&
|
|
257
|
-
|
|
118
|
+
orderList_utils_is.isOrderList(prevLine.attributes)) {
|
|
258
119
|
const nextAttrs = Object.assign({}, prevLine.attributes);
|
|
259
120
|
if (attrs[indent_types_index.INDENT_LEVEL_KEY]) {
|
|
260
121
|
// 缩进层级优先取当前行的缩进层级
|
|
@@ -262,23 +123,23 @@ class OrderListPlugin extends react.EditorPlugin {
|
|
|
262
123
|
}
|
|
263
124
|
const delta$1 = new delta.Delta().retain(startLine.start).insertEOL(nextAttrs);
|
|
264
125
|
this.editor.state.apply(delta$1);
|
|
265
|
-
applyNewOrderList(this.editor, sel);
|
|
266
|
-
|
|
126
|
+
orderList_utils_serial.applyNewOrderList(this.editor, sel);
|
|
127
|
+
shared_utils_dom.preventContextEvent(event, context);
|
|
267
128
|
return void 0;
|
|
268
129
|
}
|
|
269
130
|
// 当前行是列表行, 且按下回车键
|
|
270
131
|
// => 在列表行内部插入换行符, 且携带列表状态
|
|
271
|
-
if (
|
|
132
|
+
if (shared_utils_is.isKeyCode(event, utils.KEY_CODE.ENTER) && orderList_utils_is.isOrderList(attrs)) {
|
|
272
133
|
this.editor.perform.insertBreak(sel, attrs);
|
|
273
|
-
applyNewOrderList(this.editor, sel);
|
|
274
|
-
|
|
134
|
+
orderList_utils_serial.applyNewOrderList(this.editor, sel);
|
|
135
|
+
shared_utils_dom.preventContextEvent(event, context);
|
|
275
136
|
return void 0;
|
|
276
137
|
}
|
|
277
138
|
// 当前行是列表行, 且折叠选区, 且在行首, 且按下退格键
|
|
278
139
|
// => 将当前行的列表状态移除, 保留缩进的等级
|
|
279
|
-
if (
|
|
140
|
+
if (shared_utils_is.isKeyCode(event, utils.KEY_CODE.BACKSPACE) &&
|
|
280
141
|
sel.isCollapsed &&
|
|
281
|
-
|
|
142
|
+
orderList_utils_is.isOrderList(attrs) &&
|
|
282
143
|
!sel.start.offset) {
|
|
283
144
|
const delta$1 = new delta.Delta().retain(startLine.start + startLine.length - 1).retain(1, {
|
|
284
145
|
[bulletList_types_index.LIST_TYPE_KEY]: utils.NIL,
|
|
@@ -286,24 +147,24 @@ class OrderListPlugin extends react.EditorPlugin {
|
|
|
286
147
|
[orderList_types_index.LIST_RESTART_KEY]: utils.NIL,
|
|
287
148
|
});
|
|
288
149
|
this.editor.state.apply(delta$1, { autoCaret: false });
|
|
289
|
-
applyNewOrderList(this.editor, sel);
|
|
290
|
-
|
|
150
|
+
orderList_utils_serial.applyNewOrderList(this.editor, sel);
|
|
151
|
+
shared_utils_dom.preventContextEvent(event, context);
|
|
291
152
|
return void 0;
|
|
292
153
|
}
|
|
293
154
|
// 当前行是列表行, 按下 Tab 键
|
|
294
155
|
// => 由列表的缩进状态调整列表的序号
|
|
295
|
-
if (
|
|
296
|
-
applyNewOrderList(this.editor, sel);
|
|
297
|
-
|
|
156
|
+
if (shared_utils_is.isKeyCode(event, utils.KEY_CODE.TAB) && orderList_utils_is.isOrderList(attrs)) {
|
|
157
|
+
orderList_utils_serial.applyNewOrderList(this.editor, sel);
|
|
158
|
+
shared_utils_dom.preventContextEvent(event, context);
|
|
298
159
|
return void 0;
|
|
299
160
|
}
|
|
300
161
|
// 处于当前行的行首, 且不存在其他行属性, 且前一行是列表行
|
|
301
162
|
// => 将当前上一行属性移到当前行, 且刷新列表值
|
|
302
|
-
if (
|
|
163
|
+
if (shared_utils_is.isKeyCode(event, utils.KEY_CODE.BACKSPACE) &&
|
|
303
164
|
!sel.start.offset &&
|
|
304
165
|
!Object.keys(attrs).length &&
|
|
305
166
|
prevLine &&
|
|
306
|
-
|
|
167
|
+
orderList_utils_is.isOrderList(prevLine.attributes)) {
|
|
307
168
|
const prevAttrs = Object.assign({}, prevLine.attributes);
|
|
308
169
|
const delta$1 = new delta.Delta()
|
|
309
170
|
.retain(startLine.start - 1)
|
|
@@ -311,8 +172,8 @@ class OrderListPlugin extends react.EditorPlugin {
|
|
|
311
172
|
.retain(startLine.length - 1)
|
|
312
173
|
.retain(1, prevAttrs);
|
|
313
174
|
this.editor.state.apply(delta$1);
|
|
314
|
-
applyNewOrderList(this.editor, sel);
|
|
315
|
-
|
|
175
|
+
orderList_utils_serial.applyNewOrderList(this.editor, sel);
|
|
176
|
+
shared_utils_dom.preventContextEvent(event, context);
|
|
316
177
|
return void 0;
|
|
317
178
|
}
|
|
318
179
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const latinCache = {};
|
|
6
|
+
const romanCache = {};
|
|
7
|
+
const startToLatin = (start) => {
|
|
8
|
+
if (start < 1)
|
|
9
|
+
return "";
|
|
10
|
+
const cache = latinCache[start];
|
|
11
|
+
if (cache)
|
|
12
|
+
return cache;
|
|
13
|
+
// 1 -> a, 27 -> aa
|
|
14
|
+
let res = "";
|
|
15
|
+
let n = start - 1;
|
|
16
|
+
while (n >= 0) {
|
|
17
|
+
res = String.fromCharCode((n % 26) + 97) + res;
|
|
18
|
+
n = Math.floor(n / 26) - 1;
|
|
19
|
+
}
|
|
20
|
+
latinCache[start] = res;
|
|
21
|
+
return res;
|
|
22
|
+
};
|
|
23
|
+
const startToRoman = (start) => {
|
|
24
|
+
if (start < 1 || start > 5000)
|
|
25
|
+
return "";
|
|
26
|
+
const cache = romanCache[start];
|
|
27
|
+
if (cache)
|
|
28
|
+
return cache;
|
|
29
|
+
// https://github.com/bpampuch/pdfmake/blob/7af85/src/DocMeasure.js#L315
|
|
30
|
+
const lookup = {
|
|
31
|
+
m: 1000,
|
|
32
|
+
cm: 900,
|
|
33
|
+
d: 500,
|
|
34
|
+
cd: 400,
|
|
35
|
+
c: 100,
|
|
36
|
+
xc: 90,
|
|
37
|
+
l: 50,
|
|
38
|
+
xl: 40,
|
|
39
|
+
x: 10,
|
|
40
|
+
ix: 9,
|
|
41
|
+
v: 5,
|
|
42
|
+
iv: 4,
|
|
43
|
+
i: 1,
|
|
44
|
+
};
|
|
45
|
+
let res = "";
|
|
46
|
+
let n = start;
|
|
47
|
+
for (const i of Object.keys(lookup)) {
|
|
48
|
+
while (n >= lookup[i]) {
|
|
49
|
+
res = res + i;
|
|
50
|
+
n = n - lookup[i];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
romanCache[start] = res;
|
|
54
|
+
return res;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* 序列化有序列表前缀值
|
|
58
|
+
* @param start
|
|
59
|
+
* @param level
|
|
60
|
+
*/
|
|
61
|
+
const formatListLevel = (start, level) => {
|
|
62
|
+
let serial = "";
|
|
63
|
+
const value = level % 3;
|
|
64
|
+
if (value === 0) {
|
|
65
|
+
// 1 -> 1
|
|
66
|
+
serial = start.toString();
|
|
67
|
+
}
|
|
68
|
+
else if (value === 1) {
|
|
69
|
+
// 1 -> a
|
|
70
|
+
serial = startToLatin(start);
|
|
71
|
+
}
|
|
72
|
+
else if (value === 2) {
|
|
73
|
+
// 1 -> i
|
|
74
|
+
serial = startToRoman(start);
|
|
75
|
+
}
|
|
76
|
+
return serial + ".";
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
exports.formatListLevel = formatListLevel;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var bulletList_types_index = require('../../bullet-list/types/index.js');
|
|
6
|
+
var orderList_types_index = require('../types/index.js');
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* 检查有序列表
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var delta = require('@block-kit/delta');
|
|
6
|
+
var indent_types_index = require('../../indent/types/index.js');
|
|
7
|
+
var orderList_types_index = require('../types/index.js');
|
|
8
|
+
var orderList_utils_is = require('./is.js');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 批量刷新选区的列表序号 [批量刷新简单方便]
|
|
12
|
+
* - 从选区开始的第一个列表项开始,逐个刷新序号
|
|
13
|
+
* - 全量刷新序号数据, 最后需要在渲染时批量刷新
|
|
14
|
+
* @param editor
|
|
15
|
+
* @param sel
|
|
16
|
+
*/
|
|
17
|
+
const applyNewOrderList = (editor, range) => {
|
|
18
|
+
const sel = range || editor.selection.get();
|
|
19
|
+
if (!sel)
|
|
20
|
+
return void 0;
|
|
21
|
+
const startPoint = sel.start;
|
|
22
|
+
const block = editor.state.block;
|
|
23
|
+
let start = startPoint.line;
|
|
24
|
+
const selStartLine = block.getLine(sel.start.line);
|
|
25
|
+
const selEndLine = block.getLine(sel.end.line);
|
|
26
|
+
const selEndNextLine = selEndLine && selEndLine.next();
|
|
27
|
+
// 如果当前行不是列表项,且选区结尾下一行是列表项,则从下一行开始探查
|
|
28
|
+
if (selStartLine &&
|
|
29
|
+
!orderList_utils_is.isOrderList(selStartLine.attributes) &&
|
|
30
|
+
selEndNextLine &&
|
|
31
|
+
orderList_utils_is.isOrderList(selEndNextLine.attributes)) {
|
|
32
|
+
start++;
|
|
33
|
+
}
|
|
34
|
+
// 如果 start 的行属性不存在列表项, 则无需刷新
|
|
35
|
+
const currentLine = block.getLine(start);
|
|
36
|
+
if (!currentLine || !orderList_utils_is.isOrderList(currentLine.attributes)) {
|
|
37
|
+
return void 0;
|
|
38
|
+
}
|
|
39
|
+
// 向前查找到第一个列表项
|
|
40
|
+
while (--start >= 0) {
|
|
41
|
+
const line = block.getLine(start);
|
|
42
|
+
if (!line || !orderList_utils_is.isOrderList(line.attributes)) {
|
|
43
|
+
start++;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const delta$1 = new delta.Delta();
|
|
48
|
+
const startLine = block.getLine(start);
|
|
49
|
+
if (!startLine)
|
|
50
|
+
return void 0;
|
|
51
|
+
delta$1.retain(startLine.start);
|
|
52
|
+
// 逐行刷新序号
|
|
53
|
+
const levelToIndex = {};
|
|
54
|
+
for (let i = start; i < block.size; i++) {
|
|
55
|
+
const line = block.getLine(i);
|
|
56
|
+
const attrs = line && line.attributes;
|
|
57
|
+
if (!line || !attrs || !orderList_utils_is.isOrderList(attrs))
|
|
58
|
+
break;
|
|
59
|
+
const level = attrs[indent_types_index.INDENT_LEVEL_KEY];
|
|
60
|
+
// 重置序号
|
|
61
|
+
if (attrs[orderList_types_index.LIST_RESTART_KEY]) {
|
|
62
|
+
levelToIndex[level] = 1;
|
|
63
|
+
}
|
|
64
|
+
const index = levelToIndex[level] || 1;
|
|
65
|
+
levelToIndex[level] = index + 1;
|
|
66
|
+
delta$1.retain(line.length - 1);
|
|
67
|
+
delta$1.retain(1, { [orderList_types_index.LIST_START_KEY]: String(index) });
|
|
68
|
+
}
|
|
69
|
+
editor.state.apply(delta$1, { autoCaret: false });
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
exports.applyNewOrderList = applyNewOrderList;
|