@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,15 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import IconCode from '@arco-design/web-react/icon/react-icon/IconCode';
3
+ import { cs, NIL, TRULY } from '@block-kit/utils';
4
+ import { INLINE_CODE } from '../../inline-code/types/index.js';
5
+ import { useToolbarContext } from '../context/provider.js';
6
+
7
+ const InlineCode = () => {
8
+ const { keys, refreshMarks, editor } = useToolbarContext();
9
+ return (jsx("div", { className: cs("menu-toolbar-item", keys[INLINE_CODE] && "active"), onClick: () => {
10
+ editor.command.exec(INLINE_CODE, { value: keys[INLINE_CODE] ? NIL : TRULY });
11
+ refreshMarks();
12
+ }, children: jsx(IconCode, {}) }));
13
+ };
14
+
15
+ export { InlineCode };
@@ -0,0 +1,16 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import IconItalic from '@arco-design/web-react/icon/react-icon/IconItalic';
3
+ import { cs, NIL, TRULY } from '@block-kit/utils';
4
+ import { ITALIC_KEY } from '../../italic/types/index.js';
5
+ import { useToolbarContext } from '../context/provider.js';
6
+
7
+ const Italic = () => {
8
+ const { keys, refreshMarks, editor } = useToolbarContext();
9
+ const onExec = () => {
10
+ editor.command.exec(ITALIC_KEY, { value: keys[ITALIC_KEY] ? NIL : TRULY });
11
+ refreshMarks();
12
+ };
13
+ return (jsx("div", { className: cs("menu-toolbar-item", keys[ITALIC_KEY] && "active"), onClick: onExec, children: jsx(IconItalic, {}) }));
14
+ };
15
+
16
+ export { Italic };
@@ -0,0 +1,17 @@
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
+ import Trigger from '@arco-design/web-react/es/Trigger';
3
+ import '@arco-design/web-react/es/Trigger/style';
4
+ import IconCheck from '@arco-design/web-react/icon/react-icon/IconCheck';
5
+ import IconDown from '@arco-design/web-react/icon/react-icon/IconDown';
6
+ import { NIL } from '@block-kit/utils';
7
+ import { LINE_HEIGHT_KEY } from '../../line-height/types/index.js';
8
+ import { LineHeightIcon } from '../../shared/icons/line-height.js';
9
+ import { useToolbarContext } from '../context/provider.js';
10
+
11
+ const STEP = [...Array.from({ length: 11 }, (_, i) => i * 0.1 + 1.5), 3].map(v => v.toFixed(1).toString());
12
+ const LineHeight = () => {
13
+ const { keys, refreshMarks, editor } = useToolbarContext();
14
+ return (jsx(Trigger, { trigger: "click", popupAlign: { bottom: 10 }, getPopupContainer: e => e.parentElement || document.body, popup: () => (jsxs("div", { className: "block-kit-toolbar-dropdown", onClick: refreshMarks, children: [jsxs("div", { className: "block-kit-toolbar-height-item kit-toolbar-node", onClick: () => editor.command.exec(LINE_HEIGHT_KEY, { value: NIL }), children: [!keys[LINE_HEIGHT_KEY] && jsx(IconCheck, {}), "\u9ED8\u8BA4"] }), STEP.map(item => (jsxs("div", { className: "block-kit-toolbar-height-item kit-toolbar-node", onClick: () => editor.command.exec(LINE_HEIGHT_KEY, { value: item }), children: [keys[LINE_HEIGHT_KEY] === item && jsx(IconCheck, {}), item] }, item)))] })), children: jsxs("div", { className: "menu-toolbar-item", children: [jsx(LineHeightIcon, {}), jsx(IconDown, { className: "menu-toolbar-icon-down" })] }) }));
15
+ };
16
+
17
+ export { LineHeight };
@@ -0,0 +1,99 @@
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
+ import Button from '@arco-design/web-react/es/Button';
3
+ import '@arco-design/web-react/es/Button/style';
4
+ import Form from '@arco-design/web-react/es/Form';
5
+ import '@arco-design/web-react/es/Form/style';
6
+ import Input from '@arco-design/web-react/es/Input';
7
+ import '@arco-design/web-react/es/Input/style';
8
+ import Switch from '@arco-design/web-react/es/Switch';
9
+ import '@arco-design/web-react/es/Switch/style';
10
+ import Trigger from '@arco-design/web-react/es/Trigger';
11
+ import '@arco-design/web-react/es/Trigger/style';
12
+ import useForm from '@arco-design/web-react/es/Form/useForm';
13
+ import IconLink from '@arco-design/web-react/icon/react-icon/IconLink';
14
+ import IconRight from '@arco-design/web-react/icon/react-icon/IconRight';
15
+ import { APPLY_SOURCE, EDITOR_EVENT } from '@block-kit/core';
16
+ import { cs, TRULY, NIL } from '@block-kit/utils';
17
+ import { useState, useEffect } from 'react';
18
+ import { LINK_KEY, LINK_BLANK_KEY, LINK_TEMP_KEY } from '../../link/types/index.js';
19
+ import { useToolbarContext } from '../context/provider.js';
20
+
21
+ const Link = props => {
22
+ const [form] = useForm();
23
+ const [visible, setVisible] = useState(false);
24
+ const [collapsed, setCollapsed] = useState(true);
25
+ const { keys, refreshMarks, editor, selection } = useToolbarContext();
26
+ const onConfirm = () => {
27
+ const sel = editor.selection.get();
28
+ if (!sel)
29
+ return void 0;
30
+ const insert = form.getFieldValue("link-insert");
31
+ const href = form.getFieldValue(LINK_KEY);
32
+ const blank = form.getFieldValue(LINK_BLANK_KEY);
33
+ if (!href)
34
+ return void 0;
35
+ const filteredHref = props.filterXSS ? props.filterXSS(href) : href;
36
+ if (sel.isCollapsed) {
37
+ // 折叠选区的情况下则插入文本
38
+ if (!insert)
39
+ return void 0;
40
+ editor.lookup.marks = Object.assign(Object.assign({}, editor.lookup.marks), { [LINK_KEY]: filteredHref });
41
+ if (blank) {
42
+ editor.lookup.marks[LINK_BLANK_KEY] = TRULY;
43
+ }
44
+ editor.perform.insertText(sel, insert);
45
+ }
46
+ else {
47
+ // 非折叠选区则应用链接
48
+ editor.perform.applyMarks(sel, {
49
+ [LINK_KEY]: filteredHref,
50
+ [LINK_BLANK_KEY]: blank ? TRULY : NIL,
51
+ [LINK_TEMP_KEY]: NIL,
52
+ }, { autoCaret: false });
53
+ }
54
+ setVisible(false);
55
+ refreshMarks();
56
+ };
57
+ const onDelete = () => {
58
+ const sel = editor.selection.get();
59
+ if (!sel || sel.isCollapsed) {
60
+ setVisible(false);
61
+ return void 0;
62
+ }
63
+ editor.perform.applyMarks(sel, { [LINK_TEMP_KEY]: NIL, [LINK_BLANK_KEY]: NIL, [LINK_KEY]: NIL }, { autoCaret: false });
64
+ setVisible(false);
65
+ refreshMarks();
66
+ };
67
+ useEffect(() => {
68
+ if (visible) {
69
+ form.resetFields();
70
+ const sel = editor.selection.get();
71
+ const state = sel && sel.isCollapsed;
72
+ setCollapsed(!!state);
73
+ }
74
+ }, [editor.selection, form, visible]);
75
+ const onFocus = () => {
76
+ const sel = editor.selection.get();
77
+ if (sel && !sel.isCollapsed) {
78
+ // 由于焦点转移, 因此需要将临时标记应用到选区
79
+ editor.perform.applyMarks(sel, { [LINK_TEMP_KEY]: TRULY }, { autoCaret: false, source: APPLY_SOURCE.NO_UNDO });
80
+ editor.event.once(EDITOR_EVENT.SELECTION_CHANGE, () => {
81
+ // 这里是需要等待渲染后再执行, 否则会导致选区校正无法获取 LineNode
82
+ Promise.resolve().then(() => {
83
+ editor.perform.applyMarks(sel, { [LINK_TEMP_KEY]: NIL }, { autoCaret: false, source: APPLY_SOURCE.NO_UNDO });
84
+ });
85
+ });
86
+ }
87
+ };
88
+ const go = () => {
89
+ const href = form.getFieldValue(LINK_KEY);
90
+ if (!href)
91
+ return void 0;
92
+ window.open(href, "_blank");
93
+ };
94
+ return (jsx(Trigger, { popupVisible: visible, onVisibleChange: setVisible, trigger: "click", popupAlign: { bottom: 10 }, getPopupContainer: e => e.parentElement || document.body, popup: () => {
95
+ return (jsxs("div", { className: "block-kit-link-popup", children: [jsxs(Form, { initialValues: keys, form: form, size: "small", labelCol: { span: 6, offset: 0 }, wrapperCol: { span: 18, offset: 0 }, labelAlign: "left", onSubmit: onConfirm, children: [collapsed && (jsx(Form.Item, { label: "\u6587\u672C\u5185\u5BB9", field: "link-insert", children: jsx(Input, { "data-no-prevent": true, autoComplete: "off", size: "mini", placeholder: "\u8F93\u5165\u6587\u672C" }) })), jsx(Form.Item, { label: "\u94FE\u63A5\u5730\u5740", field: LINK_KEY, children: jsx(Input, { "data-no-prevent": true, autoComplete: "off", size: "mini", placeholder: "\u8F93\u5165\u94FE\u63A5", onFocus: onFocus, addAfter: jsx(IconRight, { onClick: go, className: "block-kit-link-popup-go" }) }) }), jsx(Form.Item, { label: "\u65B0\u9875\u9762\u6253\u5F00", field: LINK_BLANK_KEY, triggerPropName: "checked", children: jsx(Switch, {}) })] }), jsxs("div", { className: "block-kit-link-popup-button", children: [jsx(Button, { size: "mini", htmlType: "submit", type: "primary", onClick: onConfirm, children: "\u786E\u5B9A" }), jsx(Button, { size: "mini", type: "primary", status: "danger", onClick: onDelete, children: "\u5220\u9664" })] })] }));
96
+ }, children: jsx("div", { className: cs("menu-toolbar-item", keys[LINK_KEY] && selection && !selection.isCollapsed && "active"), children: jsx(IconLink, {}) }) }));
97
+ };
98
+
99
+ export { Link };
@@ -0,0 +1,17 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import IconOrderedList from '@arco-design/web-react/icon/react-icon/IconOrderedList';
3
+ import { cs, TRULY } from '@block-kit/utils';
4
+ import { ORDER_LIST_KEY } from '../../order-list/types/index.js';
5
+ import { isOrderList } from '../../order-list/utils/is.js';
6
+ import { useToolbarContext } from '../context/provider.js';
7
+
8
+ const OrderList = () => {
9
+ const { keys, refreshMarks, editor } = useToolbarContext();
10
+ const isOrder = isOrderList(keys);
11
+ return (jsx("div", { className: cs("menu-toolbar-item", isOrder && "active"), onClick: () => {
12
+ editor.command.exec(ORDER_LIST_KEY, { value: TRULY });
13
+ refreshMarks();
14
+ }, children: jsx(IconOrderedList, {}) }));
15
+ };
16
+
17
+ export { OrderList };
@@ -0,0 +1,15 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import IconQuote from '@arco-design/web-react/icon/react-icon/IconQuote';
3
+ import { cs, TRULY } from '@block-kit/utils';
4
+ import { QUOTE_KEY } from '../../quote/types/index.js';
5
+ import { useToolbarContext } from '../context/provider.js';
6
+
7
+ const Quote = () => {
8
+ const { keys, refreshMarks, editor } = useToolbarContext();
9
+ return (jsx("div", { className: cs("menu-toolbar-item", keys[QUOTE_KEY] && "active"), onClick: () => {
10
+ editor.command.exec(QUOTE_KEY, { value: TRULY });
11
+ refreshMarks();
12
+ }, children: jsx(IconQuote, {}) }));
13
+ };
14
+
15
+ export { Quote };
@@ -0,0 +1,15 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import IconStrikethrough from '@arco-design/web-react/icon/react-icon/IconStrikethrough';
3
+ import { cs, NIL, TRULY } from '@block-kit/utils';
4
+ import { STRIKE_KEY } from '../../strike/types/index.js';
5
+ import { useToolbarContext } from '../context/provider.js';
6
+
7
+ const Strike = () => {
8
+ const { keys, refreshMarks, editor } = useToolbarContext();
9
+ return (jsx("div", { className: cs("menu-toolbar-item", keys[STRIKE_KEY] && "active"), onClick: () => {
10
+ editor.command.exec(STRIKE_KEY, { value: keys[STRIKE_KEY] ? NIL : TRULY });
11
+ refreshMarks();
12
+ }, children: jsx(IconStrikethrough, {}) }));
13
+ };
14
+
15
+ export { Strike };
@@ -0,0 +1,15 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import IconUnderline from '@arco-design/web-react/icon/react-icon/IconUnderline';
3
+ import { cs, NIL, TRULY } from '@block-kit/utils';
4
+ import { UNDERLINE_KEY } from '../../underline/types/index.js';
5
+ import { useToolbarContext } from '../context/provider.js';
6
+
7
+ const Underline = () => {
8
+ const { keys, refreshMarks, editor } = useToolbarContext();
9
+ return (jsx("div", { className: cs("menu-toolbar-item", keys[UNDERLINE_KEY] && "active"), onClick: () => {
10
+ editor.command.exec(UNDERLINE_KEY, { value: keys[UNDERLINE_KEY] ? NIL : TRULY });
11
+ refreshMarks();
12
+ }, children: jsx(IconUnderline, {}) }));
13
+ };
14
+
15
+ export { Underline };
@@ -1,7 +1,3 @@
1
- const PLUGIN_EVENTS = {
2
- SHORTCUT_MARKS_CHANGE: "SHORTCUT_MARKS_CHANGE",
3
- };
4
-
5
1
  const filterMarkMap = (ops) => {
6
2
  const firstOp = ops[0];
7
3
  if (!firstOp || !firstOp.attributes)
@@ -43,4 +39,4 @@ const filterLineMarkMap = (attrs) => {
43
39
  return target;
44
40
  };
45
41
 
46
- export { PLUGIN_EVENTS as P, filterMarkMap as a, filterLineMarkMap as f };
42
+ export { filterLineMarkMap, filterMarkMap };
@@ -2,22 +2,18 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var tslib_es6 = require('../tslib.es6-d44c9a95.js');
5
+ var tslib_es6 = require('../tslib.es6-9953fd0d.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');
9
9
  var react = require('@block-kit/react');
10
10
  var utils = require('@block-kit/utils');
11
11
  var indent_types_index = require('../indent/types/index.js');
12
- var dom = require('../dom-cb8b8e40.js');
13
- var is$1 = require('../is-473d664a.js');
12
+ var shared_utils_dom = require('../shared/utils/dom.js');
13
+ var shared_utils_is = require('../shared/utils/is.js');
14
14
  var bulletList_types_index = require('./types/index.js');
15
- var is = require('../is-fa1755d0.js');
16
-
17
- const BulletListView = props => {
18
- const { level, children } = props;
19
- return (jsxRuntime.jsx("ul", { className: "block-kit-bullet-list", children: jsxRuntime.jsx("li", { className: utils.cs("block-kit-bullet-item", `block-kit-li-level-${level % 3}`), children: children }) }));
20
- };
15
+ var bulletList_utils_is = require('./utils/is.js');
16
+ var bulletList_view_list = require('./view/list.js');
21
17
 
22
18
  class BulletListPlugin extends react.EditorPlugin {
23
19
  constructor(editor) {
@@ -31,13 +27,13 @@ class BulletListPlugin extends react.EditorPlugin {
31
27
  this.editor.event.off(core.EDITOR_EVENT.KEY_DOWN, this.onKeyDown);
32
28
  }
33
29
  match(attrs) {
34
- return is.isBulletList(attrs);
30
+ return bulletList_utils_is.isBulletList(attrs);
35
31
  }
36
32
  renderLine(context) {
37
33
  const level = Number(context.attributes[indent_types_index.INDENT_LEVEL_KEY]) || 0;
38
34
  // 这里需要注意, 必须要将 context.children 作为 React 的子元素
39
35
  // 否则, 在 React 的渲染过程中, 会出现奇怪的 Crash 问题
40
- return (jsxRuntime.jsx(BulletListView, { level: level, editor: this.editor, context: context, children: context.children }));
36
+ return (jsxRuntime.jsx(bulletList_view_list.BulletListView, { level: level, editor: this.editor, context: context, children: context.children }));
41
37
  }
42
38
  onExec(payload) {
43
39
  const editor = this.editor;
@@ -47,7 +43,7 @@ class BulletListPlugin extends react.EditorPlugin {
47
43
  const { start, end } = sel;
48
44
  // 先检查当前需要设置/解除列表状态
49
45
  const lines = editor.state.block.getLines().slice(start.line, end.line + 1);
50
- const isBullet = lines.every(line => is.isBulletList(line.attributes));
46
+ const isBullet = lines.every(line => bulletList_utils_is.isBulletList(line.attributes));
51
47
  // 计算需要操作的范围
52
48
  const rawPoint = core.RawPoint.fromPoint(this.editor, core.Point.from(start.line, 0));
53
49
  if (!rawPoint)
@@ -83,10 +79,10 @@ class BulletListPlugin extends react.EditorPlugin {
83
79
  const attrs = startLine.attributes;
84
80
  // 当前行是列表行, 且按下回车键, 且选区折叠, 且当前行是空行
85
81
  // => 处理列表的缩进等级
86
- if (is$1.isKeyCode(event, utils.KEY_CODE.ENTER) &&
87
- is.isBulletList(attrs) &&
82
+ if (shared_utils_is.isKeyCode(event, utils.KEY_CODE.ENTER) &&
83
+ bulletList_utils_is.isBulletList(attrs) &&
88
84
  sel.isCollapsed &&
89
- is$1.isEmptyLine(startLine)) {
85
+ shared_utils_is.isEmptyLine(startLine)) {
90
86
  const level = Number(attrs[indent_types_index.INDENT_LEVEL_KEY]);
91
87
  const nextAttrs = {};
92
88
  if (level > 0) {
@@ -100,17 +96,17 @@ class BulletListPlugin extends react.EditorPlugin {
100
96
  }
101
97
  const delta$1 = new delta.Delta().retain(startLine.start + startLine.length - 1).retain(1, nextAttrs);
102
98
  this.editor.state.apply(delta$1, { autoCaret: false });
103
- dom.preventContextEvent(event, context);
99
+ shared_utils_dom.preventContextEvent(event, context);
104
100
  return void 0;
105
101
  }
106
102
  // 当前行是列表行, 且按下回车键, 且选区折叠, 且位于行首, 且上一行是列表行
107
103
  // => 继续列表格式, 避免默认的处理, 保持列表的连续性
108
- if (is$1.isKeyCode(event, utils.KEY_CODE.ENTER) &&
109
- is.isBulletList(attrs) &&
104
+ if (shared_utils_is.isKeyCode(event, utils.KEY_CODE.ENTER) &&
105
+ bulletList_utils_is.isBulletList(attrs) &&
110
106
  sel.isCollapsed &&
111
107
  sel.start.offset === 0 &&
112
108
  prevLine &&
113
- is.isBulletList(prevLine.attributes)) {
109
+ bulletList_utils_is.isBulletList(prevLine.attributes)) {
114
110
  const nextAttrs = Object.assign({}, prevLine.attributes);
115
111
  if (attrs[indent_types_index.INDENT_LEVEL_KEY]) {
116
112
  // 缩进层级优先取当前行的缩进层级
@@ -118,27 +114,27 @@ class BulletListPlugin extends react.EditorPlugin {
118
114
  }
119
115
  const delta$1 = new delta.Delta().retain(startLine.start).insertEOL(nextAttrs);
120
116
  this.editor.state.apply(delta$1);
121
- dom.preventContextEvent(event, context);
117
+ shared_utils_dom.preventContextEvent(event, context);
122
118
  return void 0;
123
119
  }
124
120
  // 当前行是列表行, 且按下回车键
125
121
  // => 在列表行内部插入换行符, 且携带列表状态
126
- if (is$1.isKeyCode(event, utils.KEY_CODE.ENTER) && is.isBulletList(attrs) && sel.start.offset) {
122
+ if (shared_utils_is.isKeyCode(event, utils.KEY_CODE.ENTER) && bulletList_utils_is.isBulletList(attrs) && sel.start.offset) {
127
123
  this.editor.perform.insertBreak(sel, attrs);
128
- dom.preventContextEvent(event, context);
124
+ shared_utils_dom.preventContextEvent(event, context);
129
125
  return void 0;
130
126
  }
131
127
  // 当前行是列表行, 且折叠选区, 且在行首, 且按下退格键
132
128
  // => 将当前行的列表状态移除, 保留缩进的等级
133
- if (is$1.isKeyCode(event, utils.KEY_CODE.BACKSPACE) &&
129
+ if (shared_utils_is.isKeyCode(event, utils.KEY_CODE.BACKSPACE) &&
134
130
  sel.isCollapsed &&
135
- is.isBulletList(attrs) &&
131
+ bulletList_utils_is.isBulletList(attrs) &&
136
132
  !sel.start.offset) {
137
133
  const delta$1 = new delta.Delta()
138
134
  .retain(startLine.start + startLine.length - 1)
139
135
  .retain(1, { [bulletList_types_index.LIST_TYPE_KEY]: utils.NIL });
140
136
  this.editor.state.apply(delta$1, { autoCaret: false });
141
- dom.preventContextEvent(event, context);
137
+ shared_utils_dom.preventContextEvent(event, context);
142
138
  return void 0;
143
139
  }
144
140
  }
@@ -1,6 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var bulletList_types_index = require('./bullet-list/types/index.js');
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var bulletList_types_index = require('../types/index.js');
4
6
 
5
7
  /**
6
8
  * 检查无序列表
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+ var utils = require('@block-kit/utils');
7
+
8
+ const BulletListView = props => {
9
+ const { level, children } = props;
10
+ return (jsxRuntime.jsx("ul", { className: "block-kit-bullet-list", children: jsxRuntime.jsx("li", { className: utils.cs("block-kit-bullet-item", `block-kit-li-level-${level % 3}`), children: children }) }));
11
+ };
12
+
13
+ exports.BulletListView = BulletListView;
@@ -2,23 +2,23 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var tslib_es6 = require('../tslib.es6-d44c9a95.js');
5
+ var tslib_es6 = require('../tslib.es6-9953fd0d.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');
9
9
  var react = require('@block-kit/react');
10
10
  var utils = require('@block-kit/utils');
11
- var selection = require('../selection-868f15c1.js');
12
- var is = require('../is-473d664a.js');
11
+ var shared_components_selection = require('../shared/components/selection.js');
12
+ var shared_modules_selection = require('../shared/modules/selection.js');
13
+ var shared_utils_is = require('../shared/utils/is.js');
13
14
  var divider_types_index = require('./types/index.js');
14
- require('react');
15
15
 
16
16
  class DividerPlugin extends react.EditorPlugin {
17
17
  constructor(editor) {
18
18
  super();
19
19
  this.editor = editor;
20
20
  this.key = divider_types_index.DIVIDER_KEY;
21
- this.selection = new selection.SelectionPlugin(editor);
21
+ this.selection = new shared_modules_selection.SelectionPlugin(editor);
22
22
  editor.command.register(divider_types_index.DIVIDER_KEY, this.onExec);
23
23
  }
24
24
  destroy() {
@@ -30,7 +30,7 @@ class DividerPlugin extends react.EditorPlugin {
30
30
  const line = sel && editor.state.block.getLine(sel.start.line);
31
31
  if (!sel || !line)
32
32
  return void 0;
33
- const isEmptyTextLine = is.isEmptyLine(line);
33
+ const isEmptyTextLine = shared_utils_is.isEmptyLine(line);
34
34
  let nextLineIndex = line.index + 1;
35
35
  const delta$1 = new delta.Delta();
36
36
  if (isEmptyTextLine) {
@@ -54,7 +54,7 @@ class DividerPlugin extends react.EditorPlugin {
54
54
  return !!attrs[divider_types_index.DIVIDER_KEY];
55
55
  }
56
56
  renderLeaf(context) {
57
- return (jsxRuntime.jsx(selection.SelectionHOC, { selection: this.selection, leaf: context.leafState, children: jsxRuntime.jsx(react.Void, { tag: "div", className: "block-kit-divider-container", context: context, children: jsxRuntime.jsx("div", { className: "block-kit-divider" }) }) }));
57
+ return (jsxRuntime.jsx(shared_components_selection.SelectionHOC, { selection: this.selection, leaf: context.leafState, children: jsxRuntime.jsx(react.Void, { tag: "div", className: "block-kit-divider-container", context: context, children: jsxRuntime.jsx("div", { className: "block-kit-divider" }) }) }));
58
58
  }
59
59
  }
60
60
  tslib_es6.__decorate([
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var tslib_es6 = require('../tslib.es6-d44c9a95.js');
5
+ var tslib_es6 = require('../tslib.es6-9953fd0d.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');
@@ -2,127 +2,17 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var tslib_es6 = require('../tslib.es6-d44c9a95.js');
5
+ var tslib_es6 = require('../tslib.es6-9953fd0d.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');
9
9
  var react = require('@block-kit/react');
10
10
  var utils = require('@block-kit/utils');
11
- var selection = require('../selection-868f15c1.js');
12
- var dom = require('../dom-cb8b8e40.js');
13
- var is = require('../is-473d664a.js');
11
+ var shared_modules_selection = require('../shared/modules/selection.js');
12
+ var shared_utils_dom = require('../shared/utils/dom.js');
13
+ var shared_utils_is = require('../shared/utils/is.js');
14
14
  var image_types_index = require('./types/index.js');
15
- var icon = require('@arco-design/web-react/icon');
16
- var webReact = require('@arco-design/web-react');
17
- var React = require('react');
18
-
19
- const Preview = webReact.Image.Preview;
20
- const ImageWrapper = props => {
21
- const { readonly } = react.useReadonly();
22
- const [src, setImage] = React.useState("");
23
- const ref = React.useRef(null);
24
- const enable = readonly || props.selected;
25
- const preview = (e) => {
26
- // https://developer.mozilla.org/zh-CN/docs/Web/API/MouseEvent/button
27
- if (e.button !== 0)
28
- return;
29
- enable && setImage(props.src || "");
30
- };
31
- const onMouseDown = (e) => {
32
- const resider = e.target;
33
- if (!ref.current)
34
- return void 0;
35
- // 这里直接取图片的宽高,若取原始图宽高会导致拖拽缩放问题
36
- const width = ref.current.clientWidth;
37
- const height = ref.current.clientHeight;
38
- e.stopPropagation();
39
- e.preventDefault();
40
- if (resider instanceof HTMLDivElement && resider.dataset.type && width && height) {
41
- const startX = e.clientX;
42
- const startY = e.clientY;
43
- const startWidth = Number(width);
44
- const startHeight = Number(height);
45
- const ratio = startWidth / startHeight;
46
- const type = resider.dataset.type;
47
- const range = props.leaf.toRange();
48
- const raw = core.RawRange.fromRange(props.editor, range);
49
- if (!raw)
50
- return;
51
- const onMouseMove = utils.throttle((event) => {
52
- const currentX = event.clientX;
53
- const currentY = event.clientY;
54
- const diffX = currentX - startX;
55
- const diffY = currentY - startY;
56
- let nextWidth = startWidth;
57
- let nextHeight = startHeight;
58
- switch (type) {
59
- case "lt":
60
- nextWidth = nextWidth - diffX;
61
- nextHeight = nextHeight - diffY;
62
- break;
63
- case "rt":
64
- nextWidth = nextWidth + diffX;
65
- nextHeight = nextHeight - diffY;
66
- break;
67
- case "lb":
68
- nextWidth = nextWidth - diffX;
69
- nextHeight = nextHeight + diffY;
70
- break;
71
- case "rb":
72
- nextWidth = nextWidth + diffX;
73
- nextHeight = nextHeight + diffY;
74
- break;
75
- }
76
- if (nextWidth / nextHeight > ratio) {
77
- nextHeight = nextWidth / ratio;
78
- }
79
- else {
80
- nextWidth = nextHeight * ratio;
81
- }
82
- const delta$1 = new delta.Delta().retain(raw.start).retain(raw.len, {
83
- [image_types_index.IMAGE_WIDTH]: String(Math.max(nextWidth, 100)),
84
- [image_types_index.IMAGE_HEIGHT]: String(Math.max(nextHeight, 100)),
85
- });
86
- props.editor.state.apply(delta$1, { autoCaret: false });
87
- }, 10);
88
- const onMouseUp = () => {
89
- document.removeEventListener("mousemove", onMouseMove);
90
- document.removeEventListener("mouseup", onMouseUp);
91
- };
92
- document.addEventListener("mousemove", onMouseMove);
93
- document.addEventListener("mouseup", onMouseUp);
94
- }
95
- };
96
- return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [src && jsxRuntime.jsx(Preview, { src: src, visible: !!src, onVisibleChange: v => !v && setImage("") }), !readonly && (jsxRuntime.jsxs(React.Fragment, { children: [jsxRuntime.jsx("div", { className: utils.cs(enable && "block-kit-image-resider"), "data-type": "lt", onMouseDown: onMouseDown }), jsxRuntime.jsx("div", { className: utils.cs(enable && "block-kit-image-resider"), "data-type": "rt", onMouseDown: onMouseDown }), jsxRuntime.jsx("div", { className: utils.cs(enable && "block-kit-image-resider"), "data-type": "lb", onMouseDown: onMouseDown }), jsxRuntime.jsx("div", { className: utils.cs(enable && "block-kit-image-resider"), "data-type": "rb", onMouseDown: onMouseDown })] })), jsxRuntime.jsx("div", { ref: ref, onMouseDown: preview, className: utils.cs(enable && "block-kit-image-preview"), children: props.children })] }));
97
- };
98
-
99
- const ImageView = props => {
100
- const { selection: selection$1, context, editor } = props;
101
- const attrs = context.attributes || {};
102
- const src = attrs[image_types_index.IMAGE_SRC];
103
- const width = attrs[image_types_index.IMAGE_WIDTH];
104
- const height = attrs[image_types_index.IMAGE_HEIGHT];
105
- const status = attrs[image_types_index.IMAGE_STATUS];
106
- const onImageLoad = event => {
107
- const target = event.target;
108
- if (width && height)
109
- return void 0;
110
- const { naturalHeight, naturalWidth } = target;
111
- const scale = naturalHeight / naturalWidth;
112
- const next = {
113
- [image_types_index.IMAGE_WIDTH]: String(naturalWidth),
114
- [image_types_index.IMAGE_HEIGHT]: String(naturalHeight),
115
- [image_types_index.IMAGE_SCALE]: String(scale),
116
- };
117
- const range = context.leafState.toRange();
118
- const rawRange = core.RawRange.fromRange(editor, range);
119
- if (!rawRange)
120
- return void 0;
121
- const delta$1 = new delta.Delta().retain(rawRange.start).retain(rawRange.len, next);
122
- editor.state.apply(delta$1, { source: core.APPLY_SOURCE.NO_UNDO, autoCaret: false });
123
- };
124
- return (jsxRuntime.jsxs(react.Void, { className: "block-kit-image-container", context: context, children: [status === image_types_index.LOADING_STATUS.LOADING && (jsxRuntime.jsx("div", { className: "block-kit-image-loading", children: jsxRuntime.jsx(icon.IconLoading, {}) })), jsxRuntime.jsx(selection.SelectionHOC, { selection: selection$1, leaf: context.leafState, children: jsxRuntime.jsx(ImageWrapper, { editor: props.editor, src: src, leaf: context.leafState, children: jsxRuntime.jsx("img", { className: "block-kit-image", src: src, onLoad: onImageLoad, width: utils.Styles.pixelate(width), height: utils.Styles.pixelate(height) }) }) })] }));
125
- };
15
+ var image_view_image = require('./view/image.js');
126
16
 
127
17
  class ImagePlugin extends react.EditorPlugin {
128
18
  constructor(editor) {
@@ -130,7 +20,7 @@ class ImagePlugin extends react.EditorPlugin {
130
20
  this.editor = editor;
131
21
  this.key = image_types_index.IMAGE_KEY;
132
22
  this.input = null;
133
- this.selection = new selection.SelectionPlugin(editor);
23
+ this.selection = new shared_modules_selection.SelectionPlugin(editor);
134
24
  editor.command.register(image_types_index.IMAGE_KEY, this.onExec);
135
25
  }
136
26
  destroy() {
@@ -142,7 +32,7 @@ class ImagePlugin extends react.EditorPlugin {
142
32
  return !!attrs[image_types_index.IMAGE_KEY];
143
33
  }
144
34
  renderLeaf(context) {
145
- return (jsxRuntime.jsx(ImageView, { editor: this.editor, context: context, selection: this.selection }));
35
+ return (jsxRuntime.jsx(image_view_image.ImageView, { editor: this.editor, context: context, selection: this.selection }));
146
36
  }
147
37
  pickMultiImage() {
148
38
  let imageInput = this.input;
@@ -153,7 +43,7 @@ class ImagePlugin extends react.EditorPlugin {
153
43
  imageInput.hidden = true;
154
44
  imageInput.setAttribute("multiple", "true");
155
45
  this.input = imageInput;
156
- dom.getMountDOM(this.editor).append(imageInput);
46
+ shared_utils_dom.getMountDOM(this.editor).append(imageInput);
157
47
  }
158
48
  return new Promise(resolve => {
159
49
  imageInput.onchange = e => {
@@ -179,7 +69,7 @@ class ImagePlugin extends react.EditorPlugin {
179
69
  if (!sel || !line || !files)
180
70
  return void 0;
181
71
  // 开始计算索引值
182
- const isEmptyTextLine = is.isEmptyLine(line);
72
+ const isEmptyTextLine = shared_utils_is.isEmptyLine(line);
183
73
  let nextLineIndex = line.index;
184
74
  const delta$1 = new delta.Delta();
185
75
  let index = line.start;
@@ -214,7 +104,7 @@ class ImagePlugin extends react.EditorPlugin {
214
104
  for (let i = 0; i < packIndex.length; i++) {
215
105
  const file = files[i];
216
106
  const refIndex = packIndex[i];
217
- const ref = editor.ref.pack(core.RawRange.from(refIndex, 0));
107
+ const ref = editor.tracer.pack(core.RawRange.from(refIndex, 0));
218
108
  // 独立并行上传, 且独立 unpack
219
109
  this.uploadImage(file)
220
110
  .then(res => {