@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,32 @@
1
+ import { _ as __decorate } from '../../tslib.es6-910e0469.js';
2
+ import { EDITOR_EVENT } from '@block-kit/core';
3
+ import { Bind } from '@block-kit/utils';
4
+
5
+ class SelectionPlugin {
6
+ constructor(editor) {
7
+ this.editor = editor;
8
+ this.idToView = new Map();
9
+ editor.event.on(EDITOR_EVENT.SELECTION_CHANGE, this.onSelectionChange);
10
+ }
11
+ destroy() {
12
+ this.idToView.clear();
13
+ this.editor.event.off(EDITOR_EVENT.SELECTION_CHANGE, this.onSelectionChange);
14
+ }
15
+ mountView(id, view) {
16
+ this.idToView.set(id, view);
17
+ }
18
+ unmountView(id) {
19
+ this.idToView.delete(id);
20
+ }
21
+ onSelectionChange(e) {
22
+ const current = e.current;
23
+ this.idToView.forEach(view => {
24
+ view.onSelectionChange(current);
25
+ });
26
+ }
27
+ }
28
+ __decorate([
29
+ Bind
30
+ ], SelectionPlugin.prototype, "onSelectionChange", null);
31
+
32
+ export { SelectionPlugin };
@@ -42,4 +42,4 @@ const scrollIfNeeded = (container, child, buffer = 0) => {
42
42
  }
43
43
  };
44
44
 
45
- export { setMountDOM as a, getMountDOM as g, preventContextEvent as p, scrollIfNeeded as s };
45
+ export { getMountDOM, preventContextEvent, scrollIfNeeded, setMountDOM };
@@ -0,0 +1,5 @@
1
+ const PLUGIN_EVENTS = {
2
+ SHORTCUT_MARKS_CHANGE: "SHORTCUT_MARKS_CHANGE",
3
+ };
4
+
5
+ export { PLUGIN_EVENTS };
@@ -12,4 +12,4 @@ const isKeyCode = (event, code) => {
12
12
  return event.keyCode === code;
13
13
  };
14
14
 
15
- export { isKeyCode as a, isEmptyLine as i };
15
+ export { isEmptyLine, isKeyCode };
@@ -1,29 +1,10 @@
1
- import { _ as __decorate } from '../tslib.es6-83956cc1.js';
1
+ import { _ as __decorate } from '../tslib.es6-910e0469.js';
2
2
  import { CorePlugin, EDITOR_EVENT } from '@block-kit/core';
3
- import { CTRL_KEY, KEY_CODE, NIL, TRULY, Bind } from '@block-kit/utils';
4
- import { f as filterLineMarkMap, a as filterMarkMap, P as PLUGIN_EVENTS } from '../marks-ac0ec630.js';
5
- import { BOLD_KEY } from '../bold/types/index.js';
6
- import { ITALIC_KEY } from '../italic/types/index.js';
7
- import { a as isKeyCode } from '../is-3de778e2.js';
3
+ import { Bind } from '@block-kit/utils';
4
+ import { PLUGIN_EVENTS } from '../shared/utils/event.js';
5
+ import { filterLineMarkMap, filterMarkMap } from '../toolbar/utils/marks.js';
6
+ import { PRESET_SHORTCUT } from './modules/preset.js';
8
7
  import { SHORTCUT_KEY } from './types/index.js';
9
- import '@block-kit/delta';
10
-
11
- const PRESET_SHORTCUT = {
12
- [BOLD_KEY]: (event, payload) => {
13
- if (event[CTRL_KEY] && isKeyCode(event, KEY_CODE.B) && payload.sel) {
14
- const { editor, keys, sel } = payload;
15
- editor.perform.applyMarks(sel, { [BOLD_KEY]: keys[BOLD_KEY] ? NIL : TRULY });
16
- return true;
17
- }
18
- },
19
- [ITALIC_KEY]: (event, payload) => {
20
- if (event[CTRL_KEY] && isKeyCode(event, KEY_CODE.I) && payload.sel) {
21
- const { editor, keys, sel } = payload;
22
- editor.perform.applyMarks(sel, { [ITALIC_KEY]: keys[ITALIC_KEY] ? NIL : TRULY });
23
- return true;
24
- }
25
- },
26
- };
27
8
 
28
9
  class Shortcut extends CorePlugin {
29
10
  constructor(editor, config) {
@@ -48,15 +29,15 @@ class Shortcut extends CorePlugin {
48
29
  const { start, end } = current;
49
30
  const lineMarkMap = filterLineMarkMap(lines.slice(start.line, end.line + 1).map(line => line.attributes));
50
31
  if (current.isCollapsed) {
51
- return Object.assign(Object.assign({}, this.editor.collect.marks), lineMarkMap);
32
+ return Object.assign(Object.assign({}, this.editor.lookup.marks), lineMarkMap);
52
33
  }
53
34
  const ops = [];
54
35
  if (current.isCollapsed) {
55
- const op = this.editor.collect.getOpAtPoint(current.start);
36
+ const op = this.editor.lookup.getOpAtPoint(current.start);
56
37
  op && ops.push(op);
57
38
  }
58
39
  else {
59
- const fragment = this.editor.collect.getFragment();
40
+ const fragment = this.editor.lookup.getFragment();
60
41
  fragment && ops.push(...fragment);
61
42
  }
62
43
  const markMap = filterMarkMap(ops);
@@ -0,0 +1,23 @@
1
+ import { CTRL_KEY, KEY_CODE, NIL, TRULY } from '@block-kit/utils';
2
+ import { BOLD_KEY } from '../../bold/types/index.js';
3
+ import { ITALIC_KEY } from '../../italic/types/index.js';
4
+ import { isKeyCode } from '../../shared/utils/is.js';
5
+
6
+ const PRESET_SHORTCUT = {
7
+ [BOLD_KEY]: (event, payload) => {
8
+ if (event[CTRL_KEY] && isKeyCode(event, KEY_CODE.B) && payload.sel) {
9
+ const { editor, keys, sel } = payload;
10
+ editor.perform.applyMarks(sel, { [BOLD_KEY]: keys[BOLD_KEY] ? NIL : TRULY });
11
+ return true;
12
+ }
13
+ },
14
+ [ITALIC_KEY]: (event, payload) => {
15
+ if (event[CTRL_KEY] && isKeyCode(event, KEY_CODE.I) && payload.sel) {
16
+ const { editor, keys, sel } = payload;
17
+ editor.perform.applyMarks(sel, { [ITALIC_KEY]: keys[ITALIC_KEY] ? NIL : TRULY });
18
+ return true;
19
+ }
20
+ },
21
+ };
22
+
23
+ export { PRESET_SHORTCUT };
@@ -0,0 +1,69 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { EDITOR_EVENT } from '@block-kit/core';
3
+ import { useEditorStatic } from '@block-kit/react';
4
+ import { cs } from '@block-kit/utils';
5
+ import { useMemoFn } from '@block-kit/utils/dist/es/hooks';
6
+ import { forwardRef, useState, useEffect } from 'react';
7
+ import { PLUGIN_EVENTS } from '../../shared/utils/event.js';
8
+ import { filterLineMarkMap, filterMarkMap } from '../utils/marks.js';
9
+ import { ToolbarContext } from './provider.js';
10
+
11
+ const Toolbar = /*#__PURE__*/ forwardRef((props, ref) => {
12
+ const { editor } = useEditorStatic();
13
+ const [keys, setKeys] = useState({});
14
+ const refreshMarks = useMemoFn(() => {
15
+ const current = editor.selection.get();
16
+ if (!current) {
17
+ setKeys({});
18
+ return void 0;
19
+ }
20
+ const lines = editor.state.block.getLines();
21
+ const { start, end } = current;
22
+ const lineMarkMap = filterLineMarkMap(lines.slice(start.line, end.line + 1).map(line => line.attributes));
23
+ if (current.isCollapsed) {
24
+ setKeys(Object.assign(Object.assign({}, editor.lookup.marks), lineMarkMap));
25
+ return void 0;
26
+ }
27
+ const ops = [];
28
+ if (current.isCollapsed) {
29
+ const op = editor.lookup.getOpAtPoint(current.start);
30
+ op && ops.push(op);
31
+ }
32
+ else {
33
+ const fragment = editor.lookup.getFragment();
34
+ fragment && ops.push(...fragment);
35
+ }
36
+ const markMap = filterMarkMap(ops);
37
+ setKeys(Object.assign(Object.assign({}, markMap), lineMarkMap));
38
+ });
39
+ useEffect(() => {
40
+ editor.event.on(EDITOR_EVENT.SELECTION_CHANGE, refreshMarks);
41
+ editor.event.on(PLUGIN_EVENTS.SHORTCUT_MARKS_CHANGE, refreshMarks);
42
+ return () => {
43
+ editor.event.off(EDITOR_EVENT.SELECTION_CHANGE, refreshMarks);
44
+ editor.event.off(PLUGIN_EVENTS.SHORTCUT_MARKS_CHANGE, refreshMarks);
45
+ };
46
+ }, [editor.event, refreshMarks]);
47
+ // 浮动工具栏的情况下, 挂载时需要刷新 marks
48
+ useEffect(() => {
49
+ refreshMarks();
50
+ }, [refreshMarks]);
51
+ return (jsx("div", { ref: ref, style: props.styles, className: cs("block-kit-menu-toolbar", props.className), onMouseDown: e => {
52
+ const target = e.target;
53
+ // 避免 float 的情况下触发按下事件
54
+ e.stopPropagation();
55
+ // 存在需要抢夺焦点的情况, 例如超链接输入的弹出层
56
+ if (target instanceof HTMLElement && target.hasAttribute("data-no-prevent")) {
57
+ return void 0;
58
+ }
59
+ e.preventDefault();
60
+ }, children: jsx(ToolbarContext.Provider, { value: {
61
+ keys,
62
+ editor,
63
+ setKeys,
64
+ refreshMarks,
65
+ selection: editor.selection.get(),
66
+ }, children: props.children }) }));
67
+ });
68
+
69
+ export { Toolbar };
@@ -0,0 +1,67 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { EDITOR_EVENT } from '@block-kit/core';
3
+ import { useEditorStatic, useReadonly } from '@block-kit/react';
4
+ import { cs } from '@block-kit/utils';
5
+ import { useMemoFn } from '@block-kit/utils/dist/es/hooks';
6
+ import { useRef, useState, useEffect, useMemo } from 'react';
7
+ import ReactDOM from 'react-dom';
8
+ import { getMountDOM } from '../../shared/utils/dom.js';
9
+ import { Toolbar } from './basic.js';
10
+
11
+ const FloatToolbar = props => {
12
+ const { editor } = useEditorStatic();
13
+ const { readonly } = useReadonly();
14
+ const ref = useRef(null);
15
+ const [visible, setVisible] = useState(false);
16
+ const [isMouseDown, setIsMouseDown] = useState(false);
17
+ const onWeakUp = useMemoFn((wakeUp) => {
18
+ if (editor.state.isFocused() && wakeUp) {
19
+ setVisible(true);
20
+ }
21
+ else {
22
+ setVisible(false);
23
+ }
24
+ });
25
+ useEffect(() => {
26
+ if (readonly)
27
+ return void 0;
28
+ const onMouseUp = () => {
29
+ setIsMouseDown(false);
30
+ };
31
+ const onMouseDown = () => {
32
+ setIsMouseDown(true);
33
+ };
34
+ const onSelectionChange = (e) => {
35
+ const { current } = e;
36
+ const isWakeUp = current ? !current.isCollapsed : false;
37
+ onWeakUp(isWakeUp);
38
+ };
39
+ document.addEventListener(EDITOR_EVENT.MOUSE_UP, onMouseUp);
40
+ document.addEventListener(EDITOR_EVENT.MOUSE_DOWN, onMouseDown);
41
+ editor.event.on(EDITOR_EVENT.SELECTION_CHANGE, onSelectionChange);
42
+ return () => {
43
+ document.removeEventListener(EDITOR_EVENT.MOUSE_UP, onMouseUp);
44
+ document.removeEventListener(EDITOR_EVENT.MOUSE_DOWN, onMouseDown);
45
+ editor.event.off(EDITOR_EVENT.SELECTION_CHANGE, onSelectionChange);
46
+ };
47
+ }, [editor, onWeakUp, readonly]);
48
+ const { left, top } = useMemo(() => {
49
+ if (!readonly && visible && !isMouseDown) {
50
+ const rect = editor.rect.getSelectionRect();
51
+ if (rect) {
52
+ const topOffset = props.offsetTop || 0;
53
+ const leftOffset = props.offsetLeft || 0;
54
+ const t = rect.top + topOffset;
55
+ const l = rect.left + rect.width / 2 + leftOffset;
56
+ return { top: t, left: l };
57
+ }
58
+ }
59
+ return { top: -999999, left: -999999 };
60
+ }, [editor.rect, readonly, visible, isMouseDown, props.offsetLeft, props.offsetTop]);
61
+ // 只读状态 / 不可见 / 鼠标按下 时隐藏
62
+ return readonly || !visible || isMouseDown
63
+ ? null
64
+ : ReactDOM.createPortal(jsx(Toolbar, { ref: ref, className: cs("block-kit-float-toolbar", props.className), styles: { top: top, left: left }, children: props.children }), getMountDOM(editor));
65
+ };
66
+
67
+ export { FloatToolbar };
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+
3
+ const ToolbarContext = React.createContext({
4
+ keys: {},
5
+ setKeys: () => null,
6
+ refreshMarks: () => null,
7
+ editor: null,
8
+ selection: null,
9
+ });
10
+ const useToolbarContext = () => React.useContext(ToolbarContext);
11
+
12
+ export { ToolbarContext, useToolbarContext };
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  export { Toolbar } from "./context/basic";
3
3
  export { FloatToolbar } from "./context/float";
4
- export declare const Mixin: {
4
+ export declare const ToolBarMixin: {
5
5
  Cut: import("react").FC;
6
6
  Bold: import("react").FC;
7
7
  Link: import("react").FC<{
@@ -1,34 +1,45 @@
1
- export { F as FloatToolbar, M as Mixin, T as Toolbar } from '../index-ddc2e5ac.js';
2
- import 'react/jsx-runtime';
3
- import '@arco-design/web-react';
4
- import '@arco-design/web-react/icon';
5
- import '@block-kit/utils';
6
- import '../align/types/index.js';
7
- import 'react';
8
- import '../bold/types/index.js';
9
- import '../bullet-list/types/index.js';
10
- import '../is-2b264ec8.js';
11
- import '../divider/types/index.js';
12
- import '@emoji-mart/react';
13
- import '../emoji/types/index.js';
14
- import '../background/types/index.js';
15
- import '../font-color/types/index.js';
16
- import '../font-size/types/index.js';
17
- import '../heading/types/index.js';
18
- import '@block-kit/core';
19
- import '@block-kit/utils/dist/es/hooks';
20
- import '../image/types/index.js';
21
- import '../inline-code/types/index.js';
22
- import '../italic/types/index.js';
23
- import '../line-height/types/index.js';
24
- import '@arco-design/web-react/es/Form/useForm';
25
- import '../link/types/index.js';
26
- import '../order-list/types/index.js';
27
- import '../is-7f3ae820.js';
28
- import '../quote/types/index.js';
29
- import '../strike/types/index.js';
30
- import '../underline/types/index.js';
31
- import '@block-kit/react';
32
- import '../marks-ac0ec630.js';
33
- import 'react-dom';
34
- import '../dom-71a99400.js';
1
+ import { Align } from './modules/align.js';
2
+ import { Bold } from './modules/bold.js';
3
+ import { BulletList } from './modules/bullet-list.js';
4
+ import { Cut } from './modules/cut.js';
5
+ import { Divider } from './modules/divider.js';
6
+ import { Emoji } from './modules/emoji.js';
7
+ import { FontColor } from './modules/font-color.js';
8
+ import { FontSize } from './modules/font-size.js';
9
+ import { Heading } from './modules/heading.js';
10
+ import { History } from './modules/history.js';
11
+ import { Image } from './modules/image.js';
12
+ import { InlineCode } from './modules/inline-code.js';
13
+ import { Italic } from './modules/italic.js';
14
+ import { LineHeight } from './modules/line-height.js';
15
+ import { Link } from './modules/link.js';
16
+ import { OrderList } from './modules/order-list.js';
17
+ import { Quote } from './modules/quote.js';
18
+ import { Strike } from './modules/strike.js';
19
+ import { Underline } from './modules/underline.js';
20
+ export { Toolbar } from './context/basic.js';
21
+ export { FloatToolbar } from './context/float.js';
22
+
23
+ const ToolBarMixin = {
24
+ Cut,
25
+ Bold,
26
+ Link,
27
+ Quote,
28
+ Image,
29
+ Align,
30
+ Emoji,
31
+ Italic,
32
+ Strike,
33
+ History,
34
+ Heading,
35
+ Divider,
36
+ FontSize,
37
+ FontColor,
38
+ OrderList,
39
+ Underline,
40
+ BulletList,
41
+ InlineCode,
42
+ LineHeight,
43
+ };
44
+
45
+ export { ToolBarMixin };
@@ -0,0 +1,24 @@
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 IconAlignCenter from '@arco-design/web-react/icon/react-icon/IconAlignCenter';
5
+ import IconAlignLeft from '@arco-design/web-react/icon/react-icon/IconAlignLeft';
6
+ import IconAlignRight from '@arco-design/web-react/icon/react-icon/IconAlignRight';
7
+ import IconDown from '@arco-design/web-react/icon/react-icon/IconDown';
8
+ import { NIL } from '@block-kit/utils';
9
+ import { ALIGN_KEY } from '../../align/types/index.js';
10
+ import { JustifyIcon } from '../../shared/icons/justify.js';
11
+ import { useToolbarContext } from '../context/provider.js';
12
+
13
+ const MAP = {
14
+ left: jsx(IconAlignLeft, {}),
15
+ center: jsx(IconAlignCenter, {}),
16
+ right: jsx(IconAlignRight, {}),
17
+ justify: jsx(JustifyIcon, {}),
18
+ };
19
+ const Align = () => {
20
+ const { keys, refreshMarks, editor } = useToolbarContext();
21
+ 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: [jsx("div", { className: "kit-toolbar-node", onClick: () => editor.command.exec(ALIGN_KEY, { value: NIL }), children: jsx(IconAlignLeft, {}) }), jsx("div", { className: "kit-toolbar-node", onClick: () => editor.command.exec(ALIGN_KEY, { value: "center" }), children: jsx(IconAlignCenter, {}) }), jsx("div", { className: "kit-toolbar-node", onClick: () => editor.command.exec(ALIGN_KEY, { value: "right" }), children: jsx(IconAlignRight, {}) }), jsx("div", { className: "kit-toolbar-node", onClick: () => editor.command.exec(ALIGN_KEY, { value: "justify" }), children: jsx(JustifyIcon, {}) })] })), children: jsxs("div", { className: "menu-toolbar-item", children: [MAP[keys[ALIGN_KEY]] || jsx(IconAlignLeft, {}), jsx(IconDown, { className: "menu-toolbar-icon-down" })] }) }));
22
+ };
23
+
24
+ export { Align };
@@ -0,0 +1,16 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import IconBold from '@arco-design/web-react/icon/react-icon/IconBold';
3
+ import { cs, NIL, TRULY } from '@block-kit/utils';
4
+ import { BOLD_KEY } from '../../bold/types/index.js';
5
+ import { useToolbarContext } from '../context/provider.js';
6
+
7
+ const Bold = () => {
8
+ const { keys, refreshMarks, editor } = useToolbarContext();
9
+ const onExec = () => {
10
+ editor.command.exec(BOLD_KEY, { value: keys[BOLD_KEY] ? NIL : TRULY });
11
+ refreshMarks();
12
+ };
13
+ return (jsx("div", { className: cs("menu-toolbar-item", keys[BOLD_KEY] && "active"), onClick: onExec, children: jsx(IconBold, {}) }));
14
+ };
15
+
16
+ export { Bold };
@@ -0,0 +1,17 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import IconUnorderedList from '@arco-design/web-react/icon/react-icon/IconUnorderedList';
3
+ import { cs, TRULY } from '@block-kit/utils';
4
+ import { BULLET_LIST_KEY } from '../../bullet-list/types/index.js';
5
+ import { isBulletList } from '../../bullet-list/utils/is.js';
6
+ import { useToolbarContext } from '../context/provider.js';
7
+
8
+ const BulletList = () => {
9
+ const { keys, refreshMarks, editor } = useToolbarContext();
10
+ const isBullet = isBulletList(keys);
11
+ return (jsx("div", { className: cs("menu-toolbar-item", isBullet && "active"), onClick: () => {
12
+ editor.command.exec(BULLET_LIST_KEY, { value: TRULY });
13
+ refreshMarks();
14
+ }, children: jsx(IconUnorderedList, {}) }));
15
+ };
16
+
17
+ export { BulletList };
@@ -0,0 +1,7 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+
3
+ const Cut = () => {
4
+ return jsx("div", { className: "menu-toolbar-cut" });
5
+ };
6
+
7
+ export { Cut };
@@ -0,0 +1,15 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { cs, TRULY } from '@block-kit/utils';
3
+ import { DIVIDER_KEY } from '../../divider/types/index.js';
4
+ import { DividerIcon } from '../../shared/icons/divider.js';
5
+ import { useToolbarContext } from '../context/provider.js';
6
+
7
+ const Divider = () => {
8
+ const { refreshMarks, editor } = useToolbarContext();
9
+ return (jsx("div", { className: cs("menu-toolbar-item"), onClick: () => {
10
+ editor.command.exec(DIVIDER_KEY, { value: TRULY });
11
+ refreshMarks();
12
+ }, children: jsx(DividerIcon, {}) }));
13
+ };
14
+
15
+ export { Divider };
@@ -0,0 +1,26 @@
1
+ import { jsx } 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 Picker from '@emoji-mart/react';
5
+ import { cs } from '@block-kit/utils';
6
+ import { EMOJI_KEY } from '../../emoji/types/index.js';
7
+ import { EmojiIcon } from '../../shared/icons/emoji.js';
8
+ import { useToolbarContext } from '../context/provider.js';
9
+
10
+ const Emoji = () => {
11
+ const { editor } = useToolbarContext();
12
+ return (jsx(Trigger, { className: "menu-toolbar-emoji-trigger", popupAlign: { bottom: 10 }, getPopupContainer: e => e.parentElement || document.body, popup: () => (jsx(Picker, { theme: document.body.getAttribute("arco-theme") === "dark" ? "dark" : "light", searchPosition: "none", previewPosition: "none", categories: [
13
+ "frequent",
14
+ "people",
15
+ "nature",
16
+ "foods",
17
+ "activity",
18
+ "places",
19
+ "objects",
20
+ "symbols",
21
+ ], onEmojiSelect: (emoji) => {
22
+ editor.command.exec(EMOJI_KEY, { value: emoji.id });
23
+ }, maxFrequentRows: 2 })), trigger: "click", children: jsx("div", { className: cs("menu-toolbar-item"), children: jsx(EmojiIcon, {}) }) }));
24
+ };
25
+
26
+ export { Emoji };
@@ -0,0 +1,50 @@
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 IconDown from '@arco-design/web-react/icon/react-icon/IconDown';
5
+ import { cs } from '@block-kit/utils';
6
+ import { BACKGROUND_KEY } from '../../background/types/index.js';
7
+ import { FONT_COLOR_KEY } from '../../font-color/types/index.js';
8
+ import { FontColorIcon } from '../../shared/icons/font-color.js';
9
+ import { useToolbarContext } from '../context/provider.js';
10
+
11
+ const COLOR = [
12
+ "",
13
+ "rgb(143, 149, 158)",
14
+ "rgb(216, 57, 49)",
15
+ "rgb(222, 120, 2)",
16
+ "rgb(220, 155, 4)",
17
+ "rgb(46, 161, 33)",
18
+ "rgb(36, 91, 219)",
19
+ "rgb(100, 37, 208)",
20
+ ];
21
+ const BACKGROUND = [
22
+ "",
23
+ "rgb(242, 243, 245)",
24
+ "rgb(251, 191, 188)",
25
+ "rgba(254, 212, 164, 0.8)",
26
+ "rgba(255, 246, 122, 0.8)",
27
+ "rgba(183, 237, 177, 0.8)",
28
+ "rgba(186, 206, 253, 0.7)",
29
+ "rgba(205, 178, 250, 0.7)",
30
+ "rgba(222, 224, 227, 0.8)",
31
+ "rgb(187, 191, 196)",
32
+ "rgb(247, 105, 100)",
33
+ "rgb(255, 165, 61)",
34
+ "rgb(255, 233, 40)",
35
+ "rgb(98, 210, 86)",
36
+ "rgba(78, 131, 253, 0.55)",
37
+ "rgba(147, 90, 246, 0.55)",
38
+ ];
39
+ const FontColor = () => {
40
+ const { keys, refreshMarks, editor } = useToolbarContext();
41
+ return (jsx(Trigger, { trigger: "click", popupAlign: { bottom: 10 }, getPopupContainer: e => e.parentElement || document.body, popup: () => (jsxs("div", { className: "block-kit-toolbar-dropdown block-kit-color-picker", onClick: refreshMarks, children: [jsx("div", { className: "kit-color-picker-label", children: "\u5B57\u4F53\u989C\u8272" }), jsx("div", { className: "kit-picker-group", children: COLOR.map(it => (jsx("div", { className: cs("kit-picker-item-wrapper", keys[FONT_COLOR_KEY] === it && "active", !keys[FONT_COLOR_KEY] && !it && "active"), style: { color: it ? it : void 0 }, onClick: () => {
42
+ editor.command.exec(FONT_COLOR_KEY, { value: it });
43
+ refreshMarks();
44
+ }, children: jsx("div", { className: "kit-picker-item", children: jsx(FontColorIcon, {}) }) }, it))) }), jsx("div", { className: "kit-color-picker-label", children: "\u80CC\u666F\u989C\u8272" }), jsx("div", { className: "kit-picker-group kit-picker-background-case", children: BACKGROUND.map(it => (jsx("div", { className: cs("kit-picker-item-wrapper", keys[BACKGROUND_KEY] === it && "active", !keys[BACKGROUND_KEY] && !it && "active"), onClick: () => {
45
+ editor.command.exec(BACKGROUND_KEY, { value: it });
46
+ refreshMarks();
47
+ }, children: jsx("div", { style: { background: it ? it : void 0 }, className: cs("kit-picker-item", !it && "kit-picker-item-empty-background") }) }, it))) })] })), children: jsxs("div", { className: "menu-toolbar-item kit-color-case", children: [jsx("div", { className: "kit-color-block", style: { color: keys[FONT_COLOR_KEY], background: keys[BACKGROUND_KEY] }, children: jsx(FontColorIcon, {}) }), jsx(IconDown, { className: "menu-toolbar-icon-down" })] }) }));
48
+ };
49
+
50
+ export { FontColor };
@@ -0,0 +1,21 @@
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 { useRef } from 'react';
8
+ import { FONT_SIZE_KEY } from '../../font-size/types/index.js';
9
+ import { FontSizeIcon } from '../../shared/icons/font-size.js';
10
+ import { useToolbarContext } from '../context/provider.js';
11
+
12
+ const STEP = Array(10)
13
+ .fill(null)
14
+ .map((_, i) => String(i + 12));
15
+ const FontSize = () => {
16
+ const triggerRef = useRef(null);
17
+ const { keys, refreshMarks, editor } = useToolbarContext();
18
+ return (jsx(Trigger, { ref: triggerRef, popupAlign: { bottom: 10 }, trigger: "click", 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(FONT_SIZE_KEY, { value: NIL }), children: [!keys[FONT_SIZE_KEY] && jsx(IconCheck, {}), "\u9ED8\u8BA4"] }), STEP.map(item => (jsxs("div", { className: "block-kit-toolbar-height-item kit-toolbar-node", onClick: () => editor.command.exec(FONT_SIZE_KEY, { value: item }), children: [keys[FONT_SIZE_KEY] === item && jsx(IconCheck, {}), item, "px"] }, item)))] })), children: jsxs("div", { className: "menu-toolbar-item", children: [jsx(FontSizeIcon, {}), jsx(IconDown, { className: "menu-toolbar-icon-down" })] }) }));
19
+ };
20
+
21
+ export { FontSize };
@@ -0,0 +1,23 @@
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 IconDown from '@arco-design/web-react/icon/react-icon/IconDown';
5
+ import IconH1 from '@arco-design/web-react/icon/react-icon/IconH1';
6
+ import IconH2 from '@arco-design/web-react/icon/react-icon/IconH2';
7
+ import IconH3 from '@arco-design/web-react/icon/react-icon/IconH3';
8
+ import { NIL } from '@block-kit/utils';
9
+ import { HEADING_KEY } from '../../heading/types/index.js';
10
+ import { TextIcon } from '../../shared/icons/text.js';
11
+ import { useToolbarContext } from '../context/provider.js';
12
+
13
+ const MAP = {
14
+ h1: jsx(IconH1, {}),
15
+ h2: jsx(IconH2, {}),
16
+ h3: jsx(IconH3, {}),
17
+ };
18
+ const Heading = () => {
19
+ const { keys, refreshMarks, editor: { command }, } = useToolbarContext();
20
+ 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: [jsx("div", { className: "kit-toolbar-node", onClick: () => command.exec(HEADING_KEY, { value: NIL }), children: jsx(TextIcon, {}) }), jsx("div", { className: "kit-toolbar-node", onClick: () => command.exec(HEADING_KEY, { value: "h1" }), children: jsx(IconH1, {}) }), jsx("div", { className: "kit-toolbar-node", onClick: () => command.exec(HEADING_KEY, { value: "h2" }), children: jsx(IconH2, {}) }), jsx("div", { className: "kit-toolbar-node", onClick: () => command.exec(HEADING_KEY, { value: "h3" }), children: jsx(IconH3, {}) })] })), children: jsxs("div", { className: "menu-toolbar-item", children: [MAP[keys[HEADING_KEY]] || jsx(TextIcon, {}), jsx(IconDown, { className: "menu-toolbar-icon-down" })] }) }));
21
+ };
22
+
23
+ export { Heading };
@@ -0,0 +1,35 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import IconRedo from '@arco-design/web-react/icon/react-icon/IconRedo';
3
+ import IconUndo from '@arco-design/web-react/icon/react-icon/IconUndo';
4
+ import { EDITOR_EVENT } from '@block-kit/core';
5
+ import { cs } from '@block-kit/utils';
6
+ import { useMemoFn } from '@block-kit/utils/dist/es/hooks';
7
+ import { useState, useEffect, Fragment } from 'react';
8
+ import { useToolbarContext } from '../context/provider.js';
9
+
10
+ const History = () => {
11
+ const { editor, refreshMarks } = useToolbarContext();
12
+ const [undoable, setUndoable] = useState(false);
13
+ const [redoable, setRedoable] = useState(false);
14
+ const refresh = useMemoFn(() => {
15
+ setUndoable(editor.history.isUndoAble());
16
+ setRedoable(editor.history.isRedoAble());
17
+ });
18
+ useEffect(() => {
19
+ editor.event.on(EDITOR_EVENT.CONTENT_CHANGE, refresh, 1000);
20
+ return () => {
21
+ editor.event.off(EDITOR_EVENT.CONTENT_CHANGE, refresh);
22
+ };
23
+ }, [editor, refresh]);
24
+ const undo = () => {
25
+ editor.history.undo();
26
+ refreshMarks();
27
+ };
28
+ const redo = () => {
29
+ editor.history.redo();
30
+ refreshMarks();
31
+ };
32
+ return (jsxs(Fragment, { children: [jsx("div", { className: cs("menu-toolbar-item", !undoable && "disable"), onClick: undo, children: jsx(IconUndo, {}) }), jsx("div", { className: cs("menu-toolbar-item", !redoable && "disable"), onClick: redo, children: jsx(IconRedo, {}) })] }));
33
+ };
34
+
35
+ export { History };
@@ -0,0 +1,15 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import IconImage from '@arco-design/web-react/icon/react-icon/IconImage';
3
+ import { cs, TRULY } from '@block-kit/utils';
4
+ import { IMAGE_KEY } from '../../image/types/index.js';
5
+ import { useToolbarContext } from '../context/provider.js';
6
+
7
+ const Image = () => {
8
+ const { refreshMarks, editor } = useToolbarContext();
9
+ return (jsx("div", { className: cs("menu-toolbar-item"), onClick: () => {
10
+ editor.command.exec(IMAGE_KEY, { value: TRULY });
11
+ refreshMarks();
12
+ }, children: jsx(IconImage, {}) }));
13
+ };
14
+
15
+ export { Image };