@lobehub/editor 1.4.7 → 1.5.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.
Files changed (98) hide show
  1. package/es/editor-kernel/kernel.d.ts +4 -1
  2. package/es/editor-kernel/kernel.js +56 -1
  3. package/es/index.d.ts +2 -0
  4. package/es/index.js +2 -0
  5. package/es/locale/index.d.ts +7 -0
  6. package/es/locale/index.js +7 -0
  7. package/es/plugins/code/command/index.d.ts +3 -0
  8. package/es/plugins/code/command/index.js +48 -0
  9. package/es/plugins/code/index.d.ts +3 -0
  10. package/es/plugins/code/index.js +3 -0
  11. package/es/plugins/code/node/code.d.ts +19 -0
  12. package/es/plugins/{common/node/LexicalLineBreakNode.js → code/node/code.js} +93 -95
  13. package/es/plugins/code/plugin/index.d.ts +5 -0
  14. package/es/plugins/{common/node/ParagraphNode.js → code/plugin/index.js} +40 -33
  15. package/es/plugins/code/plugin/registry.d.ts +3 -0
  16. package/es/plugins/code/plugin/registry.js +48 -0
  17. package/es/plugins/code/react/CodeReactPlugin.d.ts +4 -0
  18. package/es/plugins/code/react/CodeReactPlugin.js +31 -0
  19. package/es/plugins/code/react/index.d.ts +1 -0
  20. package/es/plugins/code/react/index.js +1 -0
  21. package/es/plugins/code/react/style.d.ts +3 -0
  22. package/es/plugins/code/react/style.js +10 -0
  23. package/es/plugins/code/react/type.d.ts +3 -0
  24. package/es/plugins/code/react/type.js +1 -0
  25. package/es/plugins/common/data-source/json-data-source.js +42 -5
  26. package/es/plugins/common/data-source/text-data-source.js +2 -2
  27. package/es/plugins/common/index.d.ts +1 -0
  28. package/es/plugins/common/index.js +1 -0
  29. package/es/plugins/common/node/ElementDOMSlot.d.ts +3 -5
  30. package/es/plugins/common/node/ElementDOMSlot.js +29 -56
  31. package/es/plugins/common/node/cursor.d.ts +12 -0
  32. package/es/plugins/common/node/cursor.js +303 -0
  33. package/es/plugins/common/plugin/index.js +11 -9
  34. package/es/plugins/common/plugin/register.d.ts +3 -1
  35. package/es/plugins/common/plugin/register.js +46 -13
  36. package/es/plugins/link/command/index.d.ts +5 -1
  37. package/es/plugins/link/command/index.js +21 -3
  38. package/es/plugins/link/react/ReactLinkPlugin.js +6 -9
  39. package/es/plugins/link/react/components/LinkEdit.d.ts +2 -1
  40. package/es/plugins/link/react/components/LinkEdit.js +195 -51
  41. package/es/plugins/link/react/components/LinkToolbar.d.ts +10 -0
  42. package/es/plugins/link/react/components/LinkToolbar.js +73 -0
  43. package/es/plugins/link/react/style.d.ts +3 -2
  44. package/es/plugins/link/react/style.js +8 -5
  45. package/es/plugins/list/command/index.d.ts +1 -0
  46. package/es/plugins/list/command/index.js +1 -0
  47. package/es/plugins/list/plugin/checkList.d.ts +3 -0
  48. package/es/plugins/list/plugin/checkList.js +167 -0
  49. package/es/plugins/list/plugin/index.js +9 -2
  50. package/es/plugins/list/react/style.js +4 -2
  51. package/es/plugins/markdown/data-source/markdown-data-source.js +5 -1
  52. package/es/plugins/markdown/service/shortcut.d.ts +3 -3
  53. package/es/plugins/math/command/index.d.ts +13 -0
  54. package/es/plugins/math/command/index.js +47 -0
  55. package/es/plugins/math/index.d.ts +3 -0
  56. package/es/plugins/math/index.js +3 -0
  57. package/es/plugins/math/node/index.d.ts +45 -0
  58. package/es/plugins/math/node/index.js +259 -0
  59. package/es/plugins/math/plugin/index.d.ts +11 -0
  60. package/es/plugins/math/plugin/index.js +103 -0
  61. package/es/plugins/math/react/component/MathEditor.d.ts +10 -0
  62. package/es/plugins/math/react/component/MathEditor.js +253 -0
  63. package/es/plugins/math/react/component/MathEditorContainer.d.ts +14 -0
  64. package/es/plugins/math/react/component/MathEditorContainer.js +60 -0
  65. package/es/plugins/math/react/component/MathEditorContent.d.ts +26 -0
  66. package/es/plugins/math/react/component/MathEditorContent.js +163 -0
  67. package/es/plugins/math/react/component/MathInline.d.ts +10 -0
  68. package/es/plugins/math/react/component/MathInline.js +105 -0
  69. package/es/plugins/math/react/component/Placeholder.d.ts +3 -0
  70. package/es/plugins/math/react/component/Placeholder.js +19 -0
  71. package/es/plugins/math/react/index.d.ts +3 -0
  72. package/es/plugins/math/react/index.js +43 -0
  73. package/es/plugins/math/react/style.d.ts +6 -0
  74. package/es/plugins/math/react/style.js +16 -0
  75. package/es/plugins/math/react/type.d.ts +13 -0
  76. package/es/plugins/math/react/type.js +1 -0
  77. package/es/plugins/slash/react/ReactSlashPlugin.js +12 -10
  78. package/es/react/FloatMenu/FloatMenu.d.ts +4 -0
  79. package/es/react/FloatMenu/FloatMenu.js +49 -0
  80. package/es/react/FloatMenu/index.d.ts +2 -0
  81. package/es/react/FloatMenu/index.js +2 -0
  82. package/es/react/FloatMenu/type.d.ts +19 -0
  83. package/es/react/FloatMenu/type.js +1 -0
  84. package/es/react/SlashMenu/SlashMenu.js +32 -48
  85. package/es/react/SlashMenu/type.d.ts +5 -13
  86. package/es/react/hooks/useEditorState/index.d.ts +4 -0
  87. package/es/react/hooks/useEditorState/index.js +40 -4
  88. package/es/react/index.d.ts +1 -0
  89. package/es/react/index.js +1 -0
  90. package/es/types/global.d.ts +4 -0
  91. package/es/types/kernel.d.ts +26 -1
  92. package/package.json +2 -1
  93. package/es/plugins/common/node/LexicalLineBreakNode.d.ts +0 -31
  94. package/es/plugins/common/node/ParagraphNode.d.ts +0 -7
  95. package/es/plugins/link/react/components/Toolbar.d.ts +0 -7
  96. package/es/plugins/link/react/components/Toolbar.js +0 -63
  97. /package/es/react/{SlashMenu → FloatMenu}/style.d.ts +0 -0
  98. /package/es/react/{SlashMenu → FloatMenu}/style.js +0 -0
@@ -1,7 +1,9 @@
1
1
  var _templateObject;
2
2
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
3
3
  import { createStyles } from 'antd-style';
4
+ import { readableColor } from 'polished';
4
5
  export var useStyles = createStyles(function (_ref) {
5
- var css = _ref.css;
6
- return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n .editor_listUnordered&,\n .editor_listOrdered& {\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n margin-inline-start: 1em;\n padding-inline-start: 0;\n list-style-position: outside;\n\n > .editor_listUnordered,\n > ol {\n margin-block: 0;\n }\n\n > .editor_listItem {\n margin-inline-start: 1em;\n }\n }\n\n .editor_listOrdered& {\n list-style: auto;\n }\n\n .editor_listUnordered& {\n list-style-type: none;\n\n > .editor_listItem:not(:has(ul)) {\n &::before {\n content: '-';\n display: inline-block;\n margin-inline: -1em 0.5em;\n opacity: 0.5;\n }\n }\n }\n\n .editor_listItem {\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 0.33em);\n font-family: var(--listitem-marker-font-family);\n font-size: var(--listitem-marker-font-size);\n background-color: var(--listitem-marker-background-color);\n\n &::marker {\n font-family: var(--listitem-marker-font-family);\n font-size: var(--listitem-marker-font-size);\n color: var(--listitem-marker-color);\n background-color: var(--listitem-marker-background-color);\n }\n\n p {\n display: inline;\n }\n\n .editor_listUnordered,\n .editor_listOrdered {\n margin: 0;\n }\n }\n\n .editor_listItemNested {\n list-style-type: none;\n }\n "])));
6
+ var css = _ref.css,
7
+ token = _ref.token;
8
+ return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n .editor_listUnordered&,\n .editor_listOrdered& {\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n margin-inline-start: 1em;\n padding-inline-start: 0;\n list-style-position: outside;\n\n > .editor_listUnordered,\n > ol {\n margin-block: 0;\n }\n\n > .editor_listItem {\n margin-inline-start: 1em;\n }\n }\n\n .editor_listOrdered& {\n list-style: auto;\n }\n\n .editor_listUnordered& {\n list-style-type: none;\n\n > .editor_listItem:not(:has(ul)):not([role='checkbox']) {\n &::before {\n content: '-';\n display: inline-block;\n margin-inline: -1em 0.5em;\n opacity: 0.5;\n }\n }\n }\n\n .editor_listItem {\n margin-block: calc(var(--lobe-markdown-margin-multiple) * 0.33em);\n font-family: var(--listitem-marker-font-family);\n font-size: var(--listitem-marker-font-size);\n background-color: var(--listitem-marker-background-color);\n\n &::marker {\n font-family: var(--listitem-marker-font-family);\n font-size: var(--listitem-marker-font-size);\n color: var(--listitem-marker-color);\n background-color: var(--listitem-marker-background-color);\n }\n\n p {\n display: inline;\n }\n\n .editor_listUnordered,\n .editor_listOrdered {\n margin: 0;\n }\n }\n\n [role='checkbox'] {\n position: relative;\n }\n\n .editor_listItemChecked::before,\n .editor_listItemUnchecked::before {\n border: 1px solid ", ";\n border-radius: 4px;\n }\n\n .editor_listItemChecked::before {\n background: ", ";\n }\n\n .editor_listItemChecked:not(:has(ul))::after {\n cursor: pointer;\n content: '';\n\n position: absolute;\n inset-block-start: 50%;\n inset-inline-start: 0.2em;\n transform: rotate(45deg) scale(1) translate(-50%, -50%);\n\n display: block;\n\n width: 0.3em;\n height: 0.6em;\n margin-inline: -1.35em 0.5em;\n border: 2px solid ", ";\n border-block-start: 0;\n border-inline-start: 0;\n\n background-size: cover;\n\n transition: all 0.2s cubic-bezier(0.12, 0.4, 0.29, 1.46) 0.1s;\n }\n\n .editor_listItemUnchecked:not(:has(ul))::before,\n .editor_listItemChecked:not(:has(ul))::before {\n cursor: pointer;\n content: '';\n\n position: absolute;\n inset-block-start: 50%;\n inset-inline-start: 0;\n transform: translateY(-50%);\n\n display: inline-block;\n display: block;\n\n width: 1em;\n height: 1em;\n margin-inline: -1.4em 0.5em;\n\n background-size: cover;\n }\n\n .editor_listItemNested {\n list-style-type: none;\n }\n "])), token.colorBorder, token.colorPrimary, readableColor(token.colorPrimary));
7
9
  });
@@ -56,8 +56,12 @@ var MarkdownDataSource = /*#__PURE__*/function (_DataSource) {
56
56
  if ($isElementNode(child)) {
57
57
  currentCtx = currentCtx.newChild();
58
58
  }
59
+ var skipChildren = false;
59
60
  if (writer) {
60
- writer(currentCtx, child);
61
+ skipChildren = writer(currentCtx, child);
62
+ }
63
+ if (skipChildren) {
64
+ return;
61
65
  }
62
66
  if ($isElementNode(child)) {
63
67
  child.getChildren().forEach(function (child) {
@@ -82,7 +82,7 @@ export interface IMarkdownShortCutService {
82
82
  * @param type Lexical Node type
83
83
  * @param writer
84
84
  */
85
- registerMarkdownWriter(type: string, writer: (ctx: IMarkdownWriterContext, node: LexicalNode) => void): void;
85
+ registerMarkdownWriter(type: string, writer: (ctx: IMarkdownWriterContext, node: LexicalNode) => void | boolean): void;
86
86
  }
87
87
  export declare const IMarkdownShortCutService: IServiceID<IMarkdownShortCutService>;
88
88
  export declare class MarkdownShortCutService implements IMarkdownShortCutService {
@@ -92,7 +92,7 @@ export declare class MarkdownShortCutService implements IMarkdownShortCutService
92
92
  private textMatchTransformers;
93
93
  private _markdownWriters;
94
94
  constructor(kernel?: import("../../../types/kernel").IEditorKernel | undefined);
95
- get markdownWriters(): Record<string, (ctx: IMarkdownWriterContext, node: LexicalNode) => void>;
95
+ get markdownWriters(): Record<string, (ctx: IMarkdownWriterContext, node: LexicalNode) => boolean | void>;
96
96
  private _textFormatTransformersByTrigger;
97
97
  private _textMatchTransformersByTrigger;
98
98
  get textMatchTransformersByTrigger(): Readonly<Record<string, Readonly<{
@@ -137,5 +137,5 @@ export declare class MarkdownShortCutService implements IMarkdownShortCutService
137
137
  registerMarkdownShortCuts(transformers: Transformer[]): void;
138
138
  testTransformers(parentNode: ElementNode, anchorNode: TextNode, anchorOffset: number, trigger?: 'enter'): boolean;
139
139
  runTransformers(parentNode: ElementNode, anchorNode: TextNode, anchorOffset: number, trigger?: 'enter'): boolean;
140
- registerMarkdownWriter(type: string, writer: (ctx: IMarkdownWriterContext, node: LexicalNode) => void): void;
140
+ registerMarkdownWriter(type: string, writer: (ctx: IMarkdownWriterContext, node: LexicalNode) => boolean | void): void;
141
141
  }
@@ -0,0 +1,13 @@
1
+ import { LexicalEditor } from 'lexical';
2
+ export declare const INSERT_MATH_COMMAND: import("lexical").LexicalCommand<{
3
+ code: string;
4
+ }>;
5
+ export declare const UPDATE_MATH_COMMAND: import("lexical").LexicalCommand<{
6
+ code: string;
7
+ key: string;
8
+ }>;
9
+ export declare const SELECT_MATH_SIDE_COMMAND: import("lexical").LexicalCommand<{
10
+ key: string;
11
+ prev?: boolean | undefined;
12
+ }>;
13
+ export declare function registerMathCommand(editor: LexicalEditor): () => void;
@@ -0,0 +1,47 @@
1
+ import { $wrapNodeInElement, mergeRegister } from '@lexical/utils';
2
+ import { $createParagraphNode, $getNodeByKey, $insertNodes, $isRootOrShadowRoot, COMMAND_PRIORITY_HIGH, createCommand } from 'lexical';
3
+ import { $createMathInlineNode } from "../node/index";
4
+ export var INSERT_MATH_COMMAND = createCommand('INSERT_MATH_COMMAND');
5
+ export var UPDATE_MATH_COMMAND = createCommand('UPDATE_MATH_COMMAND');
6
+ export var SELECT_MATH_SIDE_COMMAND = createCommand('SELECT_MATH_SIDE_COMMAND');
7
+ export function registerMathCommand(editor) {
8
+ return mergeRegister(editor.registerCommand(INSERT_MATH_COMMAND, function (payload) {
9
+ var code = payload.code;
10
+ editor.update(function () {
11
+ var mathNode = $createMathInlineNode(code);
12
+ $insertNodes([mathNode]); // Insert a zero-width space to ensure the image is not the last child
13
+ if ($isRootOrShadowRoot(mathNode.getParentOrThrow())) {
14
+ $wrapNodeInElement(mathNode, $createParagraphNode).selectEnd();
15
+ }
16
+ });
17
+ return true;
18
+ }, COMMAND_PRIORITY_HIGH // Priority
19
+ ), editor.registerCommand(UPDATE_MATH_COMMAND, function (payload) {
20
+ var code = payload.code,
21
+ key = payload.key;
22
+ editor.update(function () {
23
+ var mathCode = $getNodeByKey(key);
24
+ if (mathCode) {
25
+ mathCode.updateCode(code);
26
+ mathCode.selectNext();
27
+ }
28
+ });
29
+ return true;
30
+ }, COMMAND_PRIORITY_HIGH // Priority
31
+ ), editor.registerCommand(SELECT_MATH_SIDE_COMMAND, function (payload) {
32
+ var key = payload.key,
33
+ prev = payload.prev;
34
+ editor.update(function () {
35
+ var mathNode = $getNodeByKey(key);
36
+ if (mathNode) {
37
+ if (prev) {
38
+ mathNode.selectPrevious();
39
+ } else {
40
+ mathNode.selectNext();
41
+ }
42
+ }
43
+ });
44
+ return true;
45
+ }, COMMAND_PRIORITY_HIGH // Priority
46
+ ));
47
+ }
@@ -0,0 +1,3 @@
1
+ export { INSERT_MATH_COMMAND } from './command';
2
+ export { MathPlugin } from './plugin';
3
+ export { ReactMathPlugin } from './react';
@@ -0,0 +1,3 @@
1
+ export { INSERT_MATH_COMMAND } from "./command";
2
+ export { MathPlugin } from "./plugin";
3
+ export { ReactMathPlugin } from "./react";
@@ -0,0 +1,45 @@
1
+ import { DOMConversionMap, DOMConversionOutput, DOMExportOutput, DecoratorNode, EditorConfig, LexicalEditor, LexicalNode, LexicalUpdateJSON, SerializedLexicalNode, Spread } from 'lexical';
2
+ export type SerializedMathInlineNode = Spread<{
3
+ code: string;
4
+ }, SerializedLexicalNode>;
5
+ export declare class MathInlineNode extends DecoratorNode<unknown> {
6
+ static getType(): string;
7
+ static clone(node: MathInlineNode): MathInlineNode;
8
+ static importJSON(serializedNode: SerializedMathInlineNode): MathInlineNode;
9
+ static importDOM(): DOMConversionMap | null;
10
+ __code: string;
11
+ constructor(code?: string, key?: string);
12
+ get code(): string;
13
+ updateCode(newCode: string): void;
14
+ exportDOM(): DOMExportOutput;
15
+ createDOM(config: EditorConfig): HTMLElement;
16
+ exportJSON(): SerializedMathInlineNode;
17
+ updateFromJSON(serializedNode: LexicalUpdateJSON<SerializedMathInlineNode>): this;
18
+ getTextContent(): string;
19
+ isInline(): boolean;
20
+ updateDOM(): boolean;
21
+ decorate(editor: LexicalEditor): unknown;
22
+ }
23
+ export declare class MathBlockNode extends DecoratorNode<unknown> {
24
+ static getType(): string;
25
+ static clone(node: MathBlockNode): MathBlockNode;
26
+ static importJSON(serializedNode: SerializedMathInlineNode): MathBlockNode;
27
+ static importDOM(): DOMConversionMap | null;
28
+ __code: string;
29
+ constructor(code?: string, key?: string);
30
+ get code(): string;
31
+ updateCode(newCode: string): void;
32
+ exportDOM(): DOMExportOutput;
33
+ createDOM(config: EditorConfig): HTMLElement;
34
+ exportJSON(): SerializedMathInlineNode;
35
+ updateFromJSON(serializedNode: LexicalUpdateJSON<SerializedMathInlineNode>): this;
36
+ getTextContent(): string;
37
+ isInline(): boolean;
38
+ updateDOM(): boolean;
39
+ decorate(editor: LexicalEditor): unknown;
40
+ }
41
+ export declare function $createMathInlineNode(code?: string): MathInlineNode;
42
+ export declare function $createMathBlockNode(code?: string): MathBlockNode;
43
+ export declare function $convertMathInlineElement(): DOMConversionOutput;
44
+ export declare function $convertMathBlockElement(): DOMConversionOutput;
45
+ export declare function $isMathNode(node: LexicalNode): node is MathInlineNode | MathBlockNode;
@@ -0,0 +1,259 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
6
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
7
+ function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
8
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
9
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
10
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
11
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
12
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
13
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
14
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
15
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
16
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
17
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
18
+ 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); }
19
+ /* eslint-disable @typescript-eslint/no-use-before-define */
20
+ import { addClassNamesToElement } from '@lexical/utils';
21
+ import { $applyNodeReplacement, DecoratorNode } from 'lexical';
22
+ import { getKernelFromEditor } from "../../../editor-kernel";
23
+ export var MathInlineNode = /*#__PURE__*/function (_DecoratorNode) {
24
+ _inherits(MathInlineNode, _DecoratorNode);
25
+ var _super = _createSuper(MathInlineNode);
26
+ function MathInlineNode() {
27
+ var _this;
28
+ var code = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
29
+ var key = arguments.length > 1 ? arguments[1] : undefined;
30
+ _classCallCheck(this, MathInlineNode);
31
+ _this = _super.call(this, key);
32
+ _defineProperty(_assertThisInitialized(_this), "__code", void 0);
33
+ _this.__code = code;
34
+ return _this;
35
+ }
36
+ _createClass(MathInlineNode, [{
37
+ key: "code",
38
+ get: function get() {
39
+ return this.__code;
40
+ }
41
+ }, {
42
+ key: "updateCode",
43
+ value: function updateCode(newCode) {
44
+ var writer = this.getWritable();
45
+ writer.__code = newCode;
46
+ }
47
+ }, {
48
+ key: "exportDOM",
49
+ value: function exportDOM() {
50
+ var span = document.createElement('span');
51
+ span.className = 'math-inline';
52
+ return {
53
+ element: span
54
+ };
55
+ }
56
+ }, {
57
+ key: "createDOM",
58
+ value: function createDOM(config) {
59
+ var element = document.createElement('span');
60
+ addClassNamesToElement(element, config.theme.mathInline);
61
+ return element;
62
+ }
63
+ }, {
64
+ key: "exportJSON",
65
+ value: function exportJSON() {
66
+ return _objectSpread(_objectSpread({}, _get(_getPrototypeOf(MathInlineNode.prototype), "exportJSON", this).call(this)), {}, {
67
+ code: this.__code
68
+ });
69
+ }
70
+ }, {
71
+ key: "updateFromJSON",
72
+ value: function updateFromJSON(serializedNode) {
73
+ var node = _get(_getPrototypeOf(MathInlineNode.prototype), "updateFromJSON", this).call(this, serializedNode);
74
+ this.__code = serializedNode.code || '';
75
+ return node;
76
+ }
77
+ }, {
78
+ key: "getTextContent",
79
+ value: function getTextContent() {
80
+ return "$".concat(this.code, "$");
81
+ }
82
+ }, {
83
+ key: "isInline",
84
+ value: function isInline() {
85
+ return true;
86
+ }
87
+ }, {
88
+ key: "updateDOM",
89
+ value: function updateDOM() {
90
+ return false;
91
+ }
92
+ }, {
93
+ key: "decorate",
94
+ value: function decorate(editor) {
95
+ var _getKernelFromEditor, _getKernelFromEditor$;
96
+ return ((_getKernelFromEditor = getKernelFromEditor(editor)) === null || _getKernelFromEditor === void 0 || (_getKernelFromEditor$ = _getKernelFromEditor.getDecorator(MathInlineNode.getType())) === null || _getKernelFromEditor$ === void 0 ? void 0 : _getKernelFromEditor$(this, editor)) || null;
97
+ }
98
+ }], [{
99
+ key: "getType",
100
+ value: function getType() {
101
+ return 'math';
102
+ }
103
+ }, {
104
+ key: "clone",
105
+ value: function clone(node) {
106
+ return new MathInlineNode(node.__code, node.__key);
107
+ }
108
+ }, {
109
+ key: "importJSON",
110
+ value: function importJSON(serializedNode) {
111
+ return $createMathInlineNode().updateFromJSON(serializedNode);
112
+ }
113
+ }, {
114
+ key: "importDOM",
115
+ value: function importDOM() {
116
+ return {
117
+ span: function span(node) {
118
+ if (node.classList.contains('math-inline')) {
119
+ return {
120
+ conversion: $convertMathInlineElement,
121
+ priority: 0
122
+ };
123
+ }
124
+ return null;
125
+ }
126
+ };
127
+ }
128
+ }]);
129
+ return MathInlineNode;
130
+ }(DecoratorNode);
131
+ export var MathBlockNode = /*#__PURE__*/function (_DecoratorNode2) {
132
+ _inherits(MathBlockNode, _DecoratorNode2);
133
+ var _super2 = _createSuper(MathBlockNode);
134
+ function MathBlockNode() {
135
+ var _this2;
136
+ var code = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
137
+ var key = arguments.length > 1 ? arguments[1] : undefined;
138
+ _classCallCheck(this, MathBlockNode);
139
+ _this2 = _super2.call(this, key);
140
+ _defineProperty(_assertThisInitialized(_this2), "__code", void 0);
141
+ _this2.__code = code;
142
+ return _this2;
143
+ }
144
+ _createClass(MathBlockNode, [{
145
+ key: "code",
146
+ get: function get() {
147
+ return this.__code;
148
+ }
149
+ }, {
150
+ key: "updateCode",
151
+ value: function updateCode(newCode) {
152
+ var writer = this.getWritable();
153
+ writer.__code = newCode;
154
+ }
155
+ }, {
156
+ key: "exportDOM",
157
+ value: function exportDOM() {
158
+ var div = document.createElement('div');
159
+ div.className = 'math-block';
160
+ return {
161
+ element: div
162
+ };
163
+ }
164
+ }, {
165
+ key: "createDOM",
166
+ value: function createDOM(config) {
167
+ var element = document.createElement('div');
168
+ addClassNamesToElement(element, config.theme.mathBlock);
169
+ return element;
170
+ }
171
+ }, {
172
+ key: "exportJSON",
173
+ value: function exportJSON() {
174
+ return _objectSpread(_objectSpread({}, _get(_getPrototypeOf(MathBlockNode.prototype), "exportJSON", this).call(this)), {}, {
175
+ code: this.__code
176
+ });
177
+ }
178
+ }, {
179
+ key: "updateFromJSON",
180
+ value: function updateFromJSON(serializedNode) {
181
+ var node = _get(_getPrototypeOf(MathBlockNode.prototype), "updateFromJSON", this).call(this, serializedNode);
182
+ this.__code = serializedNode.code || '';
183
+ return node;
184
+ }
185
+ }, {
186
+ key: "getTextContent",
187
+ value: function getTextContent() {
188
+ return "$$\n".concat(this.code, "\n$$\n");
189
+ }
190
+ }, {
191
+ key: "isInline",
192
+ value: function isInline() {
193
+ return false;
194
+ }
195
+ }, {
196
+ key: "updateDOM",
197
+ value: function updateDOM() {
198
+ return false;
199
+ }
200
+ }, {
201
+ key: "decorate",
202
+ value: function decorate(editor) {
203
+ var _getKernelFromEditor2, _getKernelFromEditor3;
204
+ return ((_getKernelFromEditor2 = getKernelFromEditor(editor)) === null || _getKernelFromEditor2 === void 0 || (_getKernelFromEditor3 = _getKernelFromEditor2.getDecorator(MathBlockNode.getType())) === null || _getKernelFromEditor3 === void 0 ? void 0 : _getKernelFromEditor3(this, editor)) || null;
205
+ }
206
+ }], [{
207
+ key: "getType",
208
+ value: function getType() {
209
+ return 'mathBlock';
210
+ }
211
+ }, {
212
+ key: "clone",
213
+ value: function clone(node) {
214
+ return new MathBlockNode(node.__code, node.__key);
215
+ }
216
+ }, {
217
+ key: "importJSON",
218
+ value: function importJSON(serializedNode) {
219
+ return $createMathBlockNode().updateFromJSON(serializedNode);
220
+ }
221
+ }, {
222
+ key: "importDOM",
223
+ value: function importDOM() {
224
+ return {
225
+ div: function div(node) {
226
+ if (node.classList.contains('math-block')) {
227
+ return {
228
+ conversion: $convertMathBlockElement,
229
+ priority: 0
230
+ };
231
+ }
232
+ return null;
233
+ }
234
+ };
235
+ }
236
+ }]);
237
+ return MathBlockNode;
238
+ }(DecoratorNode);
239
+ export function $createMathInlineNode() {
240
+ var code = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
241
+ return $applyNodeReplacement(new MathInlineNode(code));
242
+ }
243
+ export function $createMathBlockNode() {
244
+ var code = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
245
+ return $applyNodeReplacement(new MathBlockNode(code));
246
+ }
247
+ export function $convertMathInlineElement() {
248
+ return {
249
+ node: $createMathInlineNode()
250
+ };
251
+ }
252
+ export function $convertMathBlockElement() {
253
+ return {
254
+ node: $createMathBlockNode()
255
+ };
256
+ }
257
+ export function $isMathNode(node) {
258
+ return node instanceof MathInlineNode || node instanceof MathBlockNode;
259
+ }
@@ -0,0 +1,11 @@
1
+ import { LexicalEditor } from 'lexical';
2
+ import { IEditorPluginConstructor } from "../../../types";
3
+ import { MathBlockNode, MathInlineNode } from '../node';
4
+ export interface MathPluginOptions {
5
+ decorator: (node: MathInlineNode | MathBlockNode, editor: LexicalEditor) => unknown;
6
+ theme?: {
7
+ mathBlock?: string;
8
+ mathInline?: string;
9
+ };
10
+ }
11
+ export declare const MathPlugin: IEditorPluginConstructor<MathPluginOptions>;
@@ -0,0 +1,103 @@
1
+ var _class;
2
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
5
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
7
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
8
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
9
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
11
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
12
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
13
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
14
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
15
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
16
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
17
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
18
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
19
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
20
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
21
+ 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); }
22
+ import { $createNodeSelection, $setSelection } from 'lexical';
23
+ import { KernelPlugin } from "../../../editor-kernel/plugin";
24
+ import { IMarkdownShortCutService } from "../../markdown";
25
+ import { registerMathCommand } from "../command";
26
+ import { $createMathBlockNode, $createMathInlineNode, MathBlockNode, MathInlineNode } from "../node";
27
+
28
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
29
+
30
+ export var MathPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
31
+ _inherits(MathPlugin, _KernelPlugin);
32
+ var _super = _createSuper(MathPlugin);
33
+ function MathPlugin(kernel, config) {
34
+ var _kernel$requireServic, _kernel$requireServic2, _kernel$requireServic3, _kernel$requireServic4;
35
+ var _this;
36
+ _classCallCheck(this, MathPlugin);
37
+ _this = _super.call(this);
38
+ _this.kernel = kernel;
39
+ _this.config = config;
40
+ kernel.registerNodes([MathInlineNode, MathBlockNode]);
41
+ if (config !== null && config !== void 0 && config.theme) {
42
+ kernel.registerThemes(config === null || config === void 0 ? void 0 : config.theme);
43
+ }
44
+ kernel.registerDecorator(MathInlineNode.getType(), function (node, editor) {
45
+ return config !== null && config !== void 0 && config.decorator ? config.decorator(node, editor) : null;
46
+ });
47
+ kernel.registerDecorator(MathBlockNode.getType(), function (node, editor) {
48
+ return config !== null && config !== void 0 && config.decorator ? config.decorator(node, editor) : null;
49
+ });
50
+ (_kernel$requireServic = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic === void 0 || _kernel$requireServic.registerMarkdownShortCut({
51
+ regExp: /\$([^$]+)\$\s?$/,
52
+ replace: function replace(textNode, match) {
53
+ var _match = _slicedToArray(match, 2),
54
+ code = _match[1];
55
+ var mathNode = $createMathInlineNode(code);
56
+ console.log(mathNode);
57
+ // textNode.replace(mathNode);
58
+ textNode.insertBefore(mathNode);
59
+ textNode.setTextContent('');
60
+ textNode.select();
61
+ // mathNode.selectEnd();
62
+
63
+ return;
64
+ },
65
+ trigger: '$',
66
+ type: 'text-match'
67
+ });
68
+ (_kernel$requireServic2 = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic2 === void 0 || _kernel$requireServic2.registerMarkdownShortCut({
69
+ regExp: /^(\$\$)$/,
70
+ replace: function replace(parentNode, _1, _2, isImport) {
71
+ var node = $createMathBlockNode();
72
+
73
+ // TODO: Get rid of isImport flag
74
+ if (isImport || parentNode.getNextSibling()) {
75
+ parentNode.replace(node);
76
+ } else {
77
+ parentNode.insertBefore(node);
78
+ }
79
+ var sel = $createNodeSelection();
80
+ sel.add(node.getKey());
81
+ $setSelection(sel);
82
+ },
83
+ trigger: 'enter',
84
+ type: 'element'
85
+ });
86
+ (_kernel$requireServic3 = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic3 === void 0 || _kernel$requireServic3.registerMarkdownWriter(MathInlineNode.getType(), function (ctx, node) {
87
+ ctx.appendLine(node.getTextContent());
88
+ return true;
89
+ });
90
+ (_kernel$requireServic4 = kernel.requireService(IMarkdownShortCutService)) === null || _kernel$requireServic4 === void 0 || _kernel$requireServic4.registerMarkdownWriter(MathBlockNode.getType(), function (ctx, node) {
91
+ ctx.appendLine(node.getTextContent());
92
+ return true;
93
+ });
94
+ return _this;
95
+ }
96
+ _createClass(MathPlugin, [{
97
+ key: "onInit",
98
+ value: function onInit(editor) {
99
+ this.register(registerMathCommand(editor));
100
+ }
101
+ }]);
102
+ return MathPlugin;
103
+ }(KernelPlugin), _defineProperty(_class, "pluginName", 'MathPlugin'), _class);
@@ -0,0 +1,10 @@
1
+ import { type FC, type ReactNode } from 'react';
2
+ interface MathEditProps {
3
+ /** 自定义渲染组件,接收 MathEditorContent 作为子节点 */
4
+ renderComp?: FC<{
5
+ children: ReactNode;
6
+ open?: boolean;
7
+ }>;
8
+ }
9
+ declare const MathEdit: import("react").NamedExoticComponent<MathEditProps>;
10
+ export default MathEdit;