@lobehub/editor 1.29.0 → 1.30.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.
- package/es/editor-kernel/kernel.js +2 -2
- package/es/editor-kernel/utils.d.ts +2 -1
- package/es/editor-kernel/utils.js +9 -2
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/es/plugins/code/plugin/index.js +24 -1
- package/es/plugins/codeblock/plugin/index.js +47 -3
- package/es/plugins/common/plugin/index.js +108 -3
- package/es/plugins/file/plugin/index.js +62 -16
- package/es/plugins/hr/plugin/index.js +25 -1
- package/es/plugins/image/node/basie-image-node.d.ts +2 -10
- package/es/plugins/image/node/basie-image-node.js +5 -30
- package/es/plugins/image/node/block-image-node.d.ts +1 -1
- package/es/plugins/image/node/block-image-node.js +3 -8
- package/es/plugins/image/node/image-node.d.ts +1 -1
- package/es/plugins/image/node/image-node.js +3 -8
- package/es/plugins/image/plugin/index.js +101 -17
- package/es/plugins/link/plugin/index.js +38 -4
- package/es/plugins/list/plugin/index.js +61 -0
- package/es/plugins/litexml/command/index.d.ts +16 -0
- package/es/plugins/litexml/command/index.js +91 -0
- package/es/plugins/litexml/data-source/litexml-data-source.d.ts +60 -0
- package/es/plugins/litexml/data-source/litexml-data-source.js +435 -0
- package/es/plugins/litexml/index.d.ts +7 -0
- package/es/plugins/litexml/index.js +5 -0
- package/es/plugins/litexml/plugin/index.d.ts +16 -0
- package/es/plugins/litexml/plugin/index.js +59 -0
- package/es/plugins/litexml/react/index.d.ts +3 -0
- package/es/plugins/litexml/react/index.js +22 -0
- package/es/plugins/litexml/service/litexml-service.d.ts +85 -0
- package/es/plugins/litexml/service/litexml-service.js +101 -0
- package/es/plugins/litexml/utils/index.d.ts +2 -0
- package/es/plugins/litexml/utils/index.js +33 -0
- package/es/plugins/math/plugin/index.js +40 -0
- package/es/plugins/mention/plugin/index.d.ts +1 -1
- package/es/plugins/mention/plugin/index.js +30 -4
- package/es/plugins/slash/react/ReactSlashPlugin.js +2 -1
- package/es/plugins/table/plugin/index.js +81 -0
- package/es/react/hooks/useEditorState/index.js +2 -1
- package/package.json +7 -6
|
@@ -0,0 +1,101 @@
|
|
|
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 _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
5
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
6
|
+
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); }
|
|
7
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
8
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
9
|
+
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; }
|
|
10
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
11
|
+
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); } }
|
|
12
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
13
|
+
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; }
|
|
14
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
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
|
+
import { genServiceId } from "../../../editor-kernel";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* XML Reader function type - converts XML element to Lexical node
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* XML Writer function type - converts Lexical node to XML string
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
// return IXmlNode if handled, false to continue with default
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Record of XML readers indexed by tag name
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Record of XML writers indexed by node type
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* ILitexmlService - Service interface for extending Litexml plugin
|
|
38
|
+
* Allows other plugins to register custom XML readers and writers
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Service ID for Litexml service
|
|
43
|
+
*/
|
|
44
|
+
// eslint-disable-next-line @typescript-eslint/no-redeclare, no-redeclare
|
|
45
|
+
export var ILitexmlService = genServiceId('ILitexmlService');
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Default implementation of ILitexmlService
|
|
49
|
+
*/
|
|
50
|
+
export var LitexmlService = /*#__PURE__*/function () {
|
|
51
|
+
function LitexmlService() {
|
|
52
|
+
_classCallCheck(this, LitexmlService);
|
|
53
|
+
_defineProperty(this, "readers", {});
|
|
54
|
+
_defineProperty(this, "writers", {});
|
|
55
|
+
}
|
|
56
|
+
_createClass(LitexmlService, [{
|
|
57
|
+
key: "registerXMLReader",
|
|
58
|
+
value: function registerXMLReader(tagName, reader) {
|
|
59
|
+
var key = tagName.toLowerCase();
|
|
60
|
+
if (this.readers[key]) {
|
|
61
|
+
// If reader already exists, convert to array
|
|
62
|
+
var existing = this.readers[key];
|
|
63
|
+
this.readers[key] = Array.isArray(existing) ? [].concat(_toConsumableArray(existing), [reader]) : [existing, reader];
|
|
64
|
+
} else {
|
|
65
|
+
this.readers[key] = reader;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}, {
|
|
69
|
+
key: "registerXMLWriter",
|
|
70
|
+
value: function registerXMLWriter(nodeType, writer) {
|
|
71
|
+
if (this.writers[nodeType]) {
|
|
72
|
+
// If writer already exists, convert to array
|
|
73
|
+
var existing = this.writers[nodeType];
|
|
74
|
+
this.writers[nodeType] = Array.isArray(existing) ? [].concat(_toConsumableArray(existing), [writer]) : [existing, writer];
|
|
75
|
+
} else {
|
|
76
|
+
this.writers[nodeType] = writer;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}, {
|
|
80
|
+
key: "getXMLReaders",
|
|
81
|
+
value: function getXMLReaders() {
|
|
82
|
+
return _objectSpread({}, this.readers);
|
|
83
|
+
}
|
|
84
|
+
}, {
|
|
85
|
+
key: "getXMLWriters",
|
|
86
|
+
value: function getXMLWriters() {
|
|
87
|
+
return _objectSpread({}, this.writers);
|
|
88
|
+
}
|
|
89
|
+
}, {
|
|
90
|
+
key: "hasXMLReader",
|
|
91
|
+
value: function hasXMLReader(tagName) {
|
|
92
|
+
return !!this.readers[tagName.toLowerCase()];
|
|
93
|
+
}
|
|
94
|
+
}, {
|
|
95
|
+
key: "hasXMLWriter",
|
|
96
|
+
value: function hasXMLWriter(nodeType) {
|
|
97
|
+
return !!this.writers[nodeType];
|
|
98
|
+
}
|
|
99
|
+
}]);
|
|
100
|
+
return LitexmlService;
|
|
101
|
+
}();
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
2
|
+
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); }
|
|
3
|
+
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; }
|
|
4
|
+
import { $isElementNode } from 'lexical';
|
|
5
|
+
export function $parseSerializedNodeImpl(serializedNode, editor) {
|
|
6
|
+
var type = serializedNode.type;
|
|
7
|
+
var registeredNode = editor._nodes.get(type);
|
|
8
|
+
if (registeredNode === undefined) {
|
|
9
|
+
throw new Error("parseEditorState: type \"".concat(type, "\" not found"));
|
|
10
|
+
}
|
|
11
|
+
var nodeClass = registeredNode.klass;
|
|
12
|
+
if (serializedNode.type !== nodeClass.getType()) {
|
|
13
|
+
throw new Error("LexicalNode: Node ".concat(nodeClass.name, " does not implement .importJSON()."));
|
|
14
|
+
}
|
|
15
|
+
var node = nodeClass.importJSON(serializedNode);
|
|
16
|
+
var children = serializedNode.children;
|
|
17
|
+
if ($isElementNode(node) && Array.isArray(children)) {
|
|
18
|
+
var _iterator = _createForOfIteratorHelper(children),
|
|
19
|
+
_step;
|
|
20
|
+
try {
|
|
21
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
22
|
+
var serializedJSONChildNode = _step.value;
|
|
23
|
+
var childNode = $parseSerializedNodeImpl(serializedJSONChildNode, editor);
|
|
24
|
+
node.append(childNode);
|
|
25
|
+
}
|
|
26
|
+
} catch (err) {
|
|
27
|
+
_iterator.e(err);
|
|
28
|
+
} finally {
|
|
29
|
+
_iterator.f();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return node;
|
|
33
|
+
}
|
|
@@ -22,6 +22,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
22
22
|
import { $createNodeSelection, $setSelection } from 'lexical';
|
|
23
23
|
import { INodeHelper } from "../../../editor-kernel/inode/helper";
|
|
24
24
|
import { KernelPlugin } from "../../../editor-kernel/plugin";
|
|
25
|
+
import { ILitexmlService } from "../../litexml";
|
|
25
26
|
import { IMarkdownShortCutService } from "../../markdown/service/shortcut";
|
|
26
27
|
import { createDebugLogger } from "../../../utils/debug";
|
|
27
28
|
import { registerMathCommand } from "../command";
|
|
@@ -56,6 +57,45 @@ export var MathPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
56
57
|
value: function onInit(editor) {
|
|
57
58
|
this.register(registerMathCommand(editor));
|
|
58
59
|
this.registerMarkdown();
|
|
60
|
+
this.registerLiteXml();
|
|
61
|
+
}
|
|
62
|
+
}, {
|
|
63
|
+
key: "registerLiteXml",
|
|
64
|
+
value: function registerLiteXml() {
|
|
65
|
+
var litexmlService = this.kernel.requireService(ILitexmlService);
|
|
66
|
+
if (!litexmlService) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
litexmlService.registerXMLWriter(MathInlineNode.getType(), function (node, ctx) {
|
|
70
|
+
if (node instanceof MathInlineNode) {
|
|
71
|
+
var attributes = {
|
|
72
|
+
code: node.getTextContent()
|
|
73
|
+
};
|
|
74
|
+
return ctx.createXmlNode('math', attributes);
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
77
|
+
});
|
|
78
|
+
litexmlService.registerXMLWriter(MathBlockNode.getType(), function (node, ctx) {
|
|
79
|
+
if (node instanceof MathBlockNode) {
|
|
80
|
+
var attributes = {
|
|
81
|
+
code: node.getTextContent()
|
|
82
|
+
};
|
|
83
|
+
return ctx.createXmlNode('mathBlock', attributes);
|
|
84
|
+
}
|
|
85
|
+
return false;
|
|
86
|
+
});
|
|
87
|
+
litexmlService.registerXMLReader('math', function (xmlNode) {
|
|
88
|
+
return INodeHelper.createElementNode(MathInlineNode.getType(), {
|
|
89
|
+
code: xmlNode.getAttribute('code') || '',
|
|
90
|
+
version: 1
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
litexmlService.registerXMLReader('mathBlock', function (xmlNode) {
|
|
94
|
+
return INodeHelper.createElementNode(MathBlockNode.getType(), {
|
|
95
|
+
code: xmlNode.getAttribute('code') || '',
|
|
96
|
+
version: 1
|
|
97
|
+
});
|
|
98
|
+
});
|
|
59
99
|
}
|
|
60
100
|
}, {
|
|
61
101
|
key: "registerMarkdown",
|
|
@@ -6,7 +6,7 @@ import { MentionNode, SerializedMentionNode } from '../node/MentionNode';
|
|
|
6
6
|
export interface MentionPluginOptions {
|
|
7
7
|
decorator: (node: MentionNode, editor: LexicalEditor) => any;
|
|
8
8
|
markdownReader?: (node: Html, children: INode[]) => SerializedMentionNode | null | false;
|
|
9
|
-
markdownWriter?: (
|
|
9
|
+
markdownWriter?: (mention: MentionNode) => string;
|
|
10
10
|
theme?: {
|
|
11
11
|
mention?: string;
|
|
12
12
|
};
|
|
@@ -13,7 +13,9 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
13
13
|
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; }
|
|
14
14
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
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
|
+
import { INodeHelper } from "../../../editor-kernel/inode/helper";
|
|
16
17
|
import { KernelPlugin } from "../../../editor-kernel/plugin";
|
|
18
|
+
import { ILitexmlService } from "../../litexml";
|
|
17
19
|
import { IMarkdownShortCutService, MARKDOWN_READER_LEVEL_HIGH } from "../../markdown/service/shortcut";
|
|
18
20
|
import { registerMentionCommand } from "../command";
|
|
19
21
|
import { $isMentionNode, MentionNode } from "../node/MentionNode";
|
|
@@ -46,14 +48,38 @@ export var MentionPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
46
48
|
this.register(registerMentionCommand(editor));
|
|
47
49
|
this.register(registerMentionNodeSelectionObserver(editor));
|
|
48
50
|
this.registerMarkdown();
|
|
51
|
+
this.registerLiteXml();
|
|
52
|
+
}
|
|
53
|
+
}, {
|
|
54
|
+
key: "registerLiteXml",
|
|
55
|
+
value: function registerLiteXml() {
|
|
56
|
+
var _this$kernel$requireS, _this$kernel$requireS2;
|
|
57
|
+
(_this$kernel$requireS = this.kernel.requireService(ILitexmlService)) === null || _this$kernel$requireS === void 0 || _this$kernel$requireS.registerXMLWriter(MentionNode.getType(), function (node, ctx) {
|
|
58
|
+
if ($isMentionNode(node)) {
|
|
59
|
+
var attributes = {
|
|
60
|
+
label: node.label
|
|
61
|
+
};
|
|
62
|
+
if (node.metadata && Object.keys(node.metadata).length > 0) {
|
|
63
|
+
attributes.metadata = JSON.stringify(node.metadata);
|
|
64
|
+
}
|
|
65
|
+
return ctx.createXmlNode('mention', attributes);
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
});
|
|
69
|
+
(_this$kernel$requireS2 = this.kernel.requireService(ILitexmlService)) === null || _this$kernel$requireS2 === void 0 || _this$kernel$requireS2.registerXMLReader('mention', function (xmlNode) {
|
|
70
|
+
return INodeHelper.createElementNode(MentionNode.getType(), {
|
|
71
|
+
label: xmlNode.getAttribute('label') || '',
|
|
72
|
+
metadata: xmlNode.getAttribute('metadata') ? JSON.parse(xmlNode.getAttribute('metadata')) : {}
|
|
73
|
+
});
|
|
74
|
+
});
|
|
49
75
|
}
|
|
50
76
|
}, {
|
|
51
77
|
key: "registerMarkdown",
|
|
52
78
|
value: function registerMarkdown() {
|
|
53
|
-
var _this$kernel$
|
|
79
|
+
var _this$kernel$requireS3,
|
|
54
80
|
_this2 = this,
|
|
55
81
|
_this$config;
|
|
56
|
-
(_this$kernel$
|
|
82
|
+
(_this$kernel$requireS3 = this.kernel.requireService(IMarkdownShortCutService)) === null || _this$kernel$requireS3 === void 0 || _this$kernel$requireS3.registerMarkdownWriter(MentionNode.getType(), function (ctx, node) {
|
|
57
83
|
if ($isMentionNode(node)) {
|
|
58
84
|
var _this2$config;
|
|
59
85
|
if ((_this2$config = _this2.config) !== null && _this2$config !== void 0 && _this2$config.markdownWriter) {
|
|
@@ -64,8 +90,8 @@ export var MentionPlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
64
90
|
}
|
|
65
91
|
});
|
|
66
92
|
if ((_this$config = this.config) !== null && _this$config !== void 0 && _this$config.markdownReader) {
|
|
67
|
-
var _this$kernel$
|
|
68
|
-
(_this$kernel$
|
|
93
|
+
var _this$kernel$requireS4;
|
|
94
|
+
(_this$kernel$requireS4 = this.kernel.requireService(IMarkdownShortCutService)) === null || _this$kernel$requireS4 === void 0 || _this$kernel$requireS4.registerMarkdownReader('html', function (node, children) {
|
|
69
95
|
var _this2$config2;
|
|
70
96
|
return (_this2$config2 = _this2.config) !== null && _this2$config2 !== void 0 && _this2$config2.markdownReader ? _this2.config.markdownReader(node, children) || false : false;
|
|
71
97
|
// return this.config?.markdownReader ? this.config.markdownReader(node, children) || false : false;
|
|
@@ -9,6 +9,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
9
9
|
import { mergeRegister } from '@lexical/utils';
|
|
10
10
|
import { COMMAND_PRIORITY_CRITICAL, KEY_ARROW_DOWN_COMMAND, KEY_ARROW_UP_COMMAND, KEY_DOWN_COMMAND, KEY_ESCAPE_COMMAND, KEY_TAB_COMMAND } from 'lexical';
|
|
11
11
|
import { Children, useCallback, useLayoutEffect, useRef, useState } from 'react';
|
|
12
|
+
import { noop } from "../../../editor-kernel";
|
|
12
13
|
import { useLexicalEditor } from "../../../editor-kernel/react";
|
|
13
14
|
import { useLexicalComposerContext } from "../../../editor-kernel/react/react-context";
|
|
14
15
|
import { SlashPlugin } from "../plugin/index";
|
|
@@ -51,7 +52,7 @@ var ReactSlashPlugin = function ReactSlashPlugin(_ref) {
|
|
|
51
52
|
dropdownPosition = _useState12[0],
|
|
52
53
|
setDropdownPosition = _useState12[1];
|
|
53
54
|
var cancelRef = useRef({
|
|
54
|
-
cancel:
|
|
55
|
+
cancel: noop
|
|
55
56
|
});
|
|
56
57
|
var triggerMapRef = useRef(new Map());
|
|
57
58
|
var close = useCallback(function () {
|
|
@@ -17,6 +17,7 @@ import { $isTableNode, TableCellNode, TableRowNode, registerTableCellUnmergeTran
|
|
|
17
17
|
import { cx } from 'antd-style';
|
|
18
18
|
import { INodeHelper } from "../../../editor-kernel/inode/helper";
|
|
19
19
|
import { KernelPlugin } from "../../../editor-kernel/plugin";
|
|
20
|
+
import { ILitexmlService } from "../../litexml";
|
|
20
21
|
import { IMarkdownShortCutService } from "../../markdown/service/shortcut";
|
|
21
22
|
import { registerTableCommand } from "../command";
|
|
22
23
|
import { TableNode, patchTableNode } from "../node";
|
|
@@ -55,6 +56,86 @@ export var TablePlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
|
|
|
55
56
|
this.register(registerTableCellUnmergeTransform(editor));
|
|
56
57
|
this.register(registerTableCommand(editor));
|
|
57
58
|
this.registerMarkdown();
|
|
59
|
+
this.registerLiteXml();
|
|
60
|
+
}
|
|
61
|
+
}, {
|
|
62
|
+
key: "registerLiteXml",
|
|
63
|
+
value: function registerLiteXml() {
|
|
64
|
+
var litexmlService = this.kernel.requireService(ILitexmlService);
|
|
65
|
+
if (!litexmlService) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
litexmlService.registerXMLWriter(TableNode.getType(), function (node, ctx) {
|
|
69
|
+
if ($isTableNode(node)) {
|
|
70
|
+
var attributes = {};
|
|
71
|
+
var colWidths = node.getColWidths();
|
|
72
|
+
if (colWidths && colWidths.length > 0) {
|
|
73
|
+
attributes.colWidths = colWidths.join(',');
|
|
74
|
+
}
|
|
75
|
+
return ctx.createXmlNode('table', attributes);
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
});
|
|
79
|
+
litexmlService.registerXMLWriter(TableRowNode.getType(), function (node, ctx) {
|
|
80
|
+
if (node instanceof TableRowNode) {
|
|
81
|
+
return ctx.createXmlNode('tr', {});
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
84
|
+
});
|
|
85
|
+
litexmlService.registerXMLWriter(TableCellNode.getType(), function (node, ctx) {
|
|
86
|
+
if (node instanceof TableCellNode) {
|
|
87
|
+
var attributes = {};
|
|
88
|
+
if (node.getColSpan() > 1) {
|
|
89
|
+
attributes.colSpan = node.getColSpan().toString();
|
|
90
|
+
}
|
|
91
|
+
if (node.getRowSpan() > 1) {
|
|
92
|
+
attributes.rowSpan = node.getRowSpan().toString();
|
|
93
|
+
}
|
|
94
|
+
if (node.getBackgroundColor()) {
|
|
95
|
+
attributes.backgroundColor = node.getBackgroundColor();
|
|
96
|
+
}
|
|
97
|
+
return ctx.createXmlNode('td', attributes);
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
});
|
|
101
|
+
litexmlService.registerXMLReader('table', function (xmlNode, children) {
|
|
102
|
+
var colWidthsAttr = xmlNode.getAttribute('colWidths');
|
|
103
|
+
var colWidths = colWidthsAttr ? colWidthsAttr.split(',').map(function (width) {
|
|
104
|
+
return parseInt(width, 10);
|
|
105
|
+
}) : [];
|
|
106
|
+
return INodeHelper.createElementNode(TableNode.getType(), {
|
|
107
|
+
children: children,
|
|
108
|
+
// eslint-disable-next-line unicorn/no-new-array
|
|
109
|
+
colWidths: colWidths.length > 0 ? colWidths : [750],
|
|
110
|
+
direction: null,
|
|
111
|
+
format: '',
|
|
112
|
+
indent: 0,
|
|
113
|
+
version: 1
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
litexmlService.registerXMLReader('tr', function (_xmlNode, children) {
|
|
117
|
+
return INodeHelper.createElementNode(TableRowNode.getType(), {
|
|
118
|
+
children: children,
|
|
119
|
+
direction: 'ltr',
|
|
120
|
+
format: '',
|
|
121
|
+
height: 33,
|
|
122
|
+
indent: 0,
|
|
123
|
+
version: 1
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
litexmlService.registerXMLReader('td', function (xmlNode, children) {
|
|
127
|
+
return INodeHelper.createElementNode(TableCellNode.getType(), {
|
|
128
|
+
backgroundColor: xmlNode.getAttribute('backgroundColor') || null,
|
|
129
|
+
children: children,
|
|
130
|
+
colSpan: xmlNode.getAttribute('colSpan') ? parseInt(xmlNode.getAttribute('colSpan'), 10) : 1,
|
|
131
|
+
direction: 'ltr',
|
|
132
|
+
format: '',
|
|
133
|
+
headerState: 0,
|
|
134
|
+
indent: 0,
|
|
135
|
+
rowSpan: xmlNode.getAttribute('rowSpan') ? parseInt(xmlNode.getAttribute('rowSpan'), 10) : 1,
|
|
136
|
+
version: 1
|
|
137
|
+
});
|
|
138
|
+
});
|
|
58
139
|
}
|
|
59
140
|
}, {
|
|
60
141
|
key: "registerMarkdown",
|
|
@@ -12,6 +12,7 @@ import { $getNearestNodeOfType, mergeRegister } from '@lexical/utils';
|
|
|
12
12
|
import { $createNodeSelection, $getSelection, $isParagraphNode, $isRangeSelection, $setSelection, CAN_REDO_COMMAND, CAN_UNDO_COMMAND, COMMAND_PRIORITY_LOW, FORMAT_TEXT_COMMAND, REDO_COMMAND, SELECTION_CHANGE_COMMAND, UNDO_COMMAND } from 'lexical';
|
|
13
13
|
import { debounce } from 'lodash-es';
|
|
14
14
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
15
|
+
import { noop } from "../../../editor-kernel";
|
|
15
16
|
import { INSERT_CODEINLINE_COMMAND } from "../../../plugins/code";
|
|
16
17
|
import { $isSelectionInCodeInline } from "../../../plugins/code/node/code";
|
|
17
18
|
import { UPDATE_CODEBLOCK_LANG } from "../../../plugins/codeblock";
|
|
@@ -376,7 +377,7 @@ export function useEditorState(editor) {
|
|
|
376
377
|
useEffect(function () {
|
|
377
378
|
if (!editor) return;
|
|
378
379
|
var lexicalEditor = editor.getLexicalEditor();
|
|
379
|
-
var cleanup =
|
|
380
|
+
var cleanup = noop;
|
|
380
381
|
var debounceUpdate = debounce(function () {
|
|
381
382
|
lexicalEditor === null || lexicalEditor === void 0 || lexicalEditor.read(function () {
|
|
382
383
|
$updateToolbar();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/editor",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.30.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",
|
|
@@ -39,13 +39,14 @@
|
|
|
39
39
|
"@lexical/selection": "^0.38.2",
|
|
40
40
|
"@lexical/table": "^0.38.2",
|
|
41
41
|
"@lexical/utils": "^0.38.2",
|
|
42
|
-
"@shikijs/core": "^3.
|
|
43
|
-
"@shikijs/engine-javascript": "^3.
|
|
42
|
+
"@shikijs/core": "^3.19.0",
|
|
43
|
+
"@shikijs/engine-javascript": "^3.19.0",
|
|
44
|
+
"@xmldom/xmldom": "^0.8.11",
|
|
44
45
|
"ahooks": "^3.9.6",
|
|
45
46
|
"antd-style": "^3.7.1",
|
|
46
47
|
"debug": "^4.4.3",
|
|
47
48
|
"eventemitter3": "^5.0.1",
|
|
48
|
-
"framer-motion": "^12.23.
|
|
49
|
+
"framer-motion": "^12.23.25",
|
|
49
50
|
"fuse.js": "^7.1.0",
|
|
50
51
|
"katex": "^0.16.25",
|
|
51
52
|
"lexical": "^0.38.2",
|
|
@@ -54,11 +55,11 @@
|
|
|
54
55
|
"polished": "^4.3.1",
|
|
55
56
|
"re-resizable": "^6.11.2",
|
|
56
57
|
"react-error-boundary": "^6.0.0",
|
|
57
|
-
"react-layout-kit": "^2.0.
|
|
58
|
+
"react-layout-kit": "^2.0.1",
|
|
58
59
|
"react-merge-refs": "^3.0.2",
|
|
59
60
|
"remark-cjk-friendly": "^1.2.3",
|
|
60
61
|
"remark-supersub": "^1.0.0",
|
|
61
|
-
"shiki": "^3.
|
|
62
|
+
"shiki": "^3.19.0",
|
|
62
63
|
"ts-key-enum": "^3.0.13",
|
|
63
64
|
"use-merge-value": "^1.2.0"
|
|
64
65
|
},
|