@lobehub/editor 1.11.0 → 1.12.0

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 (48) hide show
  1. package/es/editor-kernel/inode/helper.d.ts +9 -6
  2. package/es/editor-kernel/inode/helper.js +27 -0
  3. package/es/editor-kernel/inode/text-node.d.ts +2 -9
  4. package/es/plugins/code/plugin/index.d.ts +1 -1
  5. package/es/plugins/code/plugin/index.js +12 -1
  6. package/es/plugins/codeblock/command/index.d.ts +6 -0
  7. package/es/plugins/codeblock/command/index.js +1 -0
  8. package/es/plugins/codeblock/plugin/CodeHighlighterShiki.d.ts +7 -0
  9. package/es/plugins/codeblock/plugin/CodeHighlighterShiki.js +43 -2
  10. package/es/plugins/codeblock/plugin/FacadeShiki.d.ts +8 -1
  11. package/es/plugins/codeblock/plugin/FacadeShiki.js +95 -6
  12. package/es/plugins/codeblock/plugin/index.js +74 -29
  13. package/es/plugins/common/data-source/json-data-source.d.ts +2 -2
  14. package/es/plugins/common/data-source/json-data-source.js +2 -10
  15. package/es/plugins/common/index.d.ts +1 -1
  16. package/es/plugins/common/index.js +1 -1
  17. package/es/plugins/common/node/cursor.d.ts +3 -1
  18. package/es/plugins/common/node/cursor.js +9 -0
  19. package/es/plugins/common/plugin/index.d.ts +1 -1
  20. package/es/plugins/common/plugin/index.js +28 -1
  21. package/es/plugins/common/plugin/mdReader.d.ts +2 -0
  22. package/es/plugins/common/plugin/mdReader.js +59 -0
  23. package/es/plugins/common/react/ReactPlainText.d.ts +1 -1
  24. package/es/plugins/common/utils/index.d.ts +2 -2
  25. package/es/plugins/hr/plugin/index.js +26 -22
  26. package/es/plugins/link/plugin/index.js +42 -26
  27. package/es/plugins/list/plugin/index.js +121 -63
  28. package/es/plugins/list/utils/index.d.ts +3 -3
  29. package/es/plugins/markdown/data-source/markdown/parse.d.ts +10 -0
  30. package/es/plugins/markdown/data-source/markdown/parse.js +82 -0
  31. package/es/plugins/markdown/data-source/markdown/supersub.d.ts +1 -0
  32. package/es/plugins/markdown/data-source/markdown/supersub.js +14 -0
  33. package/es/plugins/markdown/data-source/markdown-data-source.d.ts +4 -4
  34. package/es/plugins/markdown/data-source/markdown-data-source.js +8 -2
  35. package/es/plugins/markdown/plugin/index.js +135 -2
  36. package/es/plugins/markdown/service/shortcut.d.ts +15 -85
  37. package/es/plugins/markdown/service/shortcut.js +34 -293
  38. package/es/plugins/markdown/service/transformers.d.ts +60 -0
  39. package/es/plugins/markdown/service/transformers.js +286 -0
  40. package/es/plugins/markdown/utils/index.d.ts +45 -1
  41. package/es/plugins/markdown/utils/index.js +147 -1
  42. package/es/plugins/markdown/utils/logger.d.ts +7 -0
  43. package/es/plugins/markdown/utils/logger.js +2 -0
  44. package/es/plugins/math/plugin/index.js +64 -45
  45. package/es/plugins/table/plugin/index.js +71 -26
  46. package/es/react/hooks/useEditorState/index.js +43 -21
  47. package/es/types/global.d.ts +64 -0
  48. package/package.json +2 -1
@@ -15,6 +15,7 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
15
15
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
16
16
  import { $isTableNode, TableCellNode, TableRowNode, registerTableCellUnmergeTransform, registerTablePlugin, registerTableSelectionObserver, setScrollableTablesActive } from '@lexical/table';
17
17
  import { cx } from 'antd-style';
18
+ import { INodeHelper } from "../../../editor-kernel/inode/helper";
18
19
  import { KernelPlugin } from "../../../editor-kernel/plugin";
19
20
  import { IMarkdownShortCutService } from "../../markdown";
20
21
  import { registerTableCommand } from "../command";
@@ -29,7 +30,6 @@ export var TablePlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
29
30
  _inherits(TablePlugin, _KernelPlugin);
30
31
  var _super = _createSuper(TablePlugin);
31
32
  function TablePlugin(kernel, options) {
32
- var _kernel$requireServic, _kernel$requireServic2, _kernel$requireServic3;
33
33
  var _this;
34
34
  _classCallCheck(this, TablePlugin);
35
35
  _this = _super.call(this);
@@ -44,31 +44,6 @@ export var TablePlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
44
44
  tableCellSelected: 'editor_table_cell_selected',
45
45
  tableScrollableWrapper: cx('editor_table_scrollable_wrapper', options === null || options === void 0 ? void 0 : options.theme)
46
46
  });
47
- (_kernel$requireServic = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic === void 0 || _kernel$requireServic.registerMarkdownWriter(TableNode.getType(), function (ctx) {
48
- ctx.wrap('', '\n');
49
- });
50
- (_kernel$requireServic2 = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic2 === void 0 || _kernel$requireServic2.registerMarkdownWriter(TableRowNode.getType(), function (ctx, node) {
51
- var parent = node.getParent();
52
- if (!$isTableNode(parent)) {
53
- return;
54
- }
55
- if (!node.getPreviousSibling()) {
56
- var _parent$getColWidths;
57
- ctx.wrap('', "\n".concat((_parent$getColWidths = parent.getColWidths()) === null || _parent$getColWidths === void 0 ? void 0 : _parent$getColWidths.map(function () {
58
- return '|:--';
59
- }).join(''), "|\n"));
60
- } else {
61
- ctx.wrap('', '\n');
62
- }
63
- });
64
- (_kernel$requireServic3 = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic3 === void 0 || _kernel$requireServic3.registerMarkdownWriter(TableCellNode.getType(), function (ctx, node) {
65
- ctx.addProcessor(tableCellProcessor);
66
- if (!node.getNextSibling()) {
67
- ctx.wrap('|', '|');
68
- } else {
69
- ctx.wrap('|', '');
70
- }
71
- });
72
47
  return _this;
73
48
  }
74
49
  _createClass(TablePlugin, [{
@@ -79,6 +54,76 @@ export var TablePlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
79
54
  this.register(registerTableSelectionObserver(editor));
80
55
  this.register(registerTableCellUnmergeTransform(editor));
81
56
  this.register(registerTableCommand(editor));
57
+ this.registerMarkdown();
58
+ }
59
+ }, {
60
+ key: "registerMarkdown",
61
+ value: function registerMarkdown() {
62
+ var markdownService = this.kernel.requireService(IMarkdownShortCutService);
63
+ if (!markdownService) {
64
+ return;
65
+ }
66
+ markdownService.registerMarkdownWriter(TableNode.getType(), function (ctx) {
67
+ ctx.wrap('', '\n');
68
+ });
69
+ markdownService.registerMarkdownWriter(TableRowNode.getType(), function (ctx, node) {
70
+ var parent = node.getParent();
71
+ if (!$isTableNode(parent)) {
72
+ return;
73
+ }
74
+ if (!node.getPreviousSibling()) {
75
+ var _parent$getColWidths;
76
+ ctx.wrap('', "\n".concat((_parent$getColWidths = parent.getColWidths()) === null || _parent$getColWidths === void 0 ? void 0 : _parent$getColWidths.map(function () {
77
+ return '|:--';
78
+ }).join(''), "|\n"));
79
+ } else {
80
+ ctx.wrap('', '\n');
81
+ }
82
+ });
83
+ markdownService.registerMarkdownWriter(TableCellNode.getType(), function (ctx, node) {
84
+ ctx.addProcessor(tableCellProcessor);
85
+ if (!node.getNextSibling()) {
86
+ ctx.wrap('|', '|');
87
+ } else {
88
+ ctx.wrap('|', '');
89
+ }
90
+ });
91
+ markdownService.registerMarkdownReader('table', function (node, children) {
92
+ var _node$children$;
93
+ var colLen = ((_node$children$ = node.children[0]) === null || _node$children$ === void 0 ? void 0 : _node$children$.children.length) || 1;
94
+ return INodeHelper.createElementNode('table', {
95
+ children: children,
96
+ // eslint-disable-next-line unicorn/no-new-array
97
+ colWidths: new Array(colLen).fill(750 / colLen),
98
+ direction: null,
99
+ format: '',
100
+ indent: 0,
101
+ version: 1
102
+ });
103
+ });
104
+ markdownService.registerMarkdownReader('tableRow', function (_node, children) {
105
+ return INodeHelper.createElementNode('tablerow', {
106
+ children: children,
107
+ direction: 'ltr',
108
+ format: '',
109
+ height: 33,
110
+ indent: 0,
111
+ version: 1
112
+ });
113
+ });
114
+ markdownService.registerMarkdownReader('tableCell', function (_node, children) {
115
+ return INodeHelper.createElementNode('tablecell', {
116
+ backgroundColor: null,
117
+ children: children,
118
+ colSpan: 1,
119
+ direction: 'ltr',
120
+ format: '',
121
+ headerState: 0,
122
+ indent: 0,
123
+ rowSpan: 1,
124
+ version: 1
125
+ });
126
+ });
82
127
  }
83
128
  }]);
84
129
  return TablePlugin;
@@ -57,36 +57,44 @@ export function useEditorState(editor) {
57
57
  setIsStrikethrough = _useState12[1];
58
58
  var _useState13 = useState(false),
59
59
  _useState14 = _slicedToArray(_useState13, 2),
60
- isCode = _useState14[0],
61
- setIsCode = _useState14[1];
60
+ isSubscript = _useState14[0],
61
+ setIsSubscript = _useState14[1];
62
62
  var _useState15 = useState(false),
63
63
  _useState16 = _slicedToArray(_useState15, 2),
64
- isLink = _useState16[0],
65
- setIsLink = _useState16[1];
64
+ isSuperscript = _useState16[0],
65
+ setIsSuperscript = _useState16[1];
66
66
  var _useState17 = useState(false),
67
67
  _useState18 = _slicedToArray(_useState17, 2),
68
- isCodeblock = _useState18[0],
69
- setIsInCodeblok = _useState18[1];
68
+ isCode = _useState18[0],
69
+ setIsCode = _useState18[1];
70
70
  var _useState19 = useState(false),
71
71
  _useState20 = _slicedToArray(_useState19, 2),
72
- isBlockquote = _useState20[0],
73
- setIsInBlockquote = _useState20[1];
74
- var _useState21 = useState(null),
72
+ isLink = _useState20[0],
73
+ setIsLink = _useState20[1];
74
+ var _useState21 = useState(false),
75
75
  _useState22 = _slicedToArray(_useState21, 2),
76
- codeblockLang = _useState22[0],
77
- setCodeblockLang = _useState22[1];
78
- var _useState23 = useState(true),
76
+ isCodeblock = _useState22[0],
77
+ setIsInCodeblok = _useState22[1];
78
+ var _useState23 = useState(false),
79
79
  _useState24 = _slicedToArray(_useState23, 2),
80
- isEmpty = _useState24[0],
81
- setIsEmpty = _useState24[1];
82
- var _useState25 = useState(false),
80
+ isBlockquote = _useState24[0],
81
+ setIsInBlockquote = _useState24[1];
82
+ var _useState25 = useState(null),
83
83
  _useState26 = _slicedToArray(_useState25, 2),
84
- isSelected = _useState26[0],
85
- setIsSelected = _useState26[1];
86
- var _useState27 = useState(null),
84
+ codeblockLang = _useState26[0],
85
+ setCodeblockLang = _useState26[1];
86
+ var _useState27 = useState(true),
87
87
  _useState28 = _slicedToArray(_useState27, 2),
88
- blockType = _useState28[0],
89
- setBlockType = _useState28[1];
88
+ isEmpty = _useState28[0],
89
+ setIsEmpty = _useState28[1];
90
+ var _useState29 = useState(false),
91
+ _useState30 = _slicedToArray(_useState29, 2),
92
+ isSelected = _useState30[0],
93
+ setIsSelected = _useState30[1];
94
+ var _useState31 = useState(null),
95
+ _useState32 = _slicedToArray(_useState31, 2),
96
+ blockType = _useState32[0],
97
+ setBlockType = _useState32[1];
90
98
  var $handleHeadingNode = useCallback(function (selectedElement) {
91
99
  var type = $isHeadingNode(selectedElement) ? selectedElement.getTag() : selectedElement.getType();
92
100
  setBlockType(type);
@@ -105,6 +113,8 @@ export function useEditorState(editor) {
105
113
  setIsItalic(selection.hasFormat('italic'));
106
114
  setIsUnderline(selection.hasFormat('underline'));
107
115
  setIsStrikethrough(selection.hasFormat('strikethrough'));
116
+ setIsSubscript(selection.hasFormat('subscript'));
117
+ setIsSuperscript(selection.hasFormat('superscript'));
108
118
  setIsCode($isSelectionInCodeInline(lexicalEditor));
109
119
  var anchorNode = selection.anchor.getNode();
110
120
  var focusNode = selection.focus.getNode();
@@ -135,6 +145,8 @@ export function useEditorState(editor) {
135
145
  setIsItalic(false);
136
146
  setIsUnderline(false);
137
147
  setIsStrikethrough(false);
148
+ setIsSubscript(false);
149
+ setIsSuperscript(false);
138
150
  setIsCode(false);
139
151
  setIsLink(false);
140
152
  setIsInCodeblok(false);
@@ -164,6 +176,12 @@ export function useEditorState(editor) {
164
176
  var italic = useCallback(function () {
165
177
  formatText('italic');
166
178
  }, [formatText]);
179
+ var subscript = useCallback(function () {
180
+ formatText('subscript');
181
+ }, [formatText]);
182
+ var superscript = useCallback(function () {
183
+ formatText('superscript');
184
+ }, [formatText]);
167
185
  var code = useCallback(function () {
168
186
  editor === null || editor === void 0 || editor.dispatchCommand(INSERT_CODEINLINE_COMMAND, undefined);
169
187
  }, [formatText]);
@@ -360,14 +378,18 @@ export function useEditorState(editor) {
360
378
  isItalic: isItalic,
361
379
  isSelected: isSelected,
362
380
  isStrikethrough: isStrikethrough,
381
+ isSubscript: isSubscript,
382
+ isSuperscript: isSuperscript,
363
383
  isUnderline: isUnderline,
364
384
  italic: italic,
365
385
  numberList: numberList,
366
386
  redo: redo,
367
387
  strikethrough: strikethrough,
388
+ subscript: subscript,
389
+ superscript: superscript,
368
390
  underline: underline,
369
391
  undo: undo,
370
392
  updateCodeblockLang: updateCodeblockLang
371
393
  };
372
- }, [blockType, canRedo, canUndo, codeblockLang, isBold, isCode, isEmpty, isBlockquote, isCodeblock, isItalic, isSelected, isStrikethrough, isUnderline, italic]);
394
+ }, [blockType, canRedo, canUndo, codeblockLang, isBold, isCode, isEmpty, isBlockquote, isCodeblock, isItalic, isSelected, isStrikethrough, isUnderline, isSubscript, isSuperscript, italic]);
373
395
  }
@@ -1,6 +1,52 @@
1
1
  import type { LobeCustomStylish, LobeCustomToken } from '@lobehub/ui';
2
2
  import 'antd-style';
3
3
  import 'lexical/LexicalEditor';
4
+ import type { Data, Literal } from 'mdast';
5
+
6
+ /**
7
+ * Info associated with mdast superscript (flow) nodes by the ecosystem.
8
+ */
9
+ export type SuperscriptData = Data;
10
+
11
+ /**
12
+ * Superscript (flow).
13
+ */
14
+ export interface Superscript extends Literal {
15
+ /**
16
+ * Data associated with the mdast superscript (flow).
17
+ */
18
+ data?: SuperscriptData | undefined;
19
+
20
+ /**
21
+ * Custom information relating to the node.
22
+ */
23
+ meta?: string | null | undefined;
24
+
25
+ /**
26
+ * Node type of superscript (flow).
27
+ */
28
+ type: 'superscript';
29
+ }
30
+
31
+ /**
32
+ * Subscript (flow).
33
+ */
34
+ export interface Subscript extends Literal {
35
+ /**
36
+ * Data associated with the mdast superscript (flow).
37
+ */
38
+ data?: SuperscriptData | undefined;
39
+
40
+ /**
41
+ * Custom information relating to the node.
42
+ */
43
+ meta?: string | null | undefined;
44
+
45
+ /**
46
+ * Node type of subscript (flow).
47
+ */
48
+ type: 'subscript';
49
+ }
4
50
 
5
51
  declare module 'antd-style' {
6
52
  // eslint-disable-next-line @typescript-eslint/no-empty-interface
@@ -22,3 +68,21 @@ declare module '*.svg' {
22
68
  declare namespace globalThis {
23
69
  let __DEV__: boolean | undefined;
24
70
  }
71
+
72
+ // Add nodes to tree.
73
+ declare module 'mdast' {
74
+ interface BlockContentMap {
75
+ subscript: Subscript;
76
+ superscript: Superscript;
77
+ }
78
+
79
+ interface PhrasingContentMap {
80
+ subscript: Subscript;
81
+ superscript: Superscript;
82
+ }
83
+
84
+ interface RootContentMap {
85
+ subscript: Subscript;
86
+ superscript: Superscript;
87
+ }
88
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/editor",
3
- "version": "1.11.0",
3
+ "version": "1.12.0",
4
4
  "description": "A powerful and extensible rich text editor built on Meta's Lexical framework, providing a modern editing experience with React integration.",
5
5
  "keywords": [
6
6
  "lobehub",
@@ -56,6 +56,7 @@
56
56
  "react-error-boundary": "^6.0.0",
57
57
  "react-layout-kit": "^2.0.0",
58
58
  "react-merge-refs": "^3.0.2",
59
+ "remark-supersub": "^1.0.0",
59
60
  "shiki": "^3.9.2",
60
61
  "ts-key-enum": "^3.0.13",
61
62
  "use-merge-value": "^1.2.0"