@lobehub/editor 3.9.1 → 3.10.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/const/hotkey.js +12 -12
- package/es/editor-kernel/data-source.d.ts +1 -1
- package/es/editor-kernel/data-source.js +1 -1
- package/es/editor-kernel/kernel.d.ts +1 -1
- package/es/editor-kernel/kernel.js +2 -2
- package/es/plugins/common/data-source/json-data-source.d.ts +1 -1
- package/es/plugins/common/data-source/json-data-source.js +2 -1
- package/es/plugins/litexml/index.d.ts +1 -0
- package/es/plugins/litexml/index.js +1 -0
- package/es/plugins/litexml/react/hooks/useHasDiffNode.d.ts +4 -0
- package/es/plugins/litexml/react/hooks/useHasDiffNode.js +61 -0
- package/es/types/kernel.d.ts +1 -1
- package/package.json +30 -1
package/es/const/hotkey.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { COMMAND_PRIORITY_LOW } from 'lexical';
|
|
2
2
|
import { HotkeyEnum, HotkeyScopeEnum, KeyEnum } from "../types/hotkey";
|
|
3
3
|
var combineKeys = function combineKeys(keys) {
|
|
4
4
|
return keys.join('+');
|
|
@@ -6,58 +6,58 @@ var combineKeys = function combineKeys(keys) {
|
|
|
6
6
|
export var HOTKEYS_REGISTRATION = [{
|
|
7
7
|
id: HotkeyEnum.Undo,
|
|
8
8
|
keys: combineKeys([KeyEnum.Mod, 'z']),
|
|
9
|
-
priority:
|
|
9
|
+
priority: COMMAND_PRIORITY_LOW,
|
|
10
10
|
scopes: [HotkeyScopeEnum.Format]
|
|
11
11
|
}, {
|
|
12
12
|
id: HotkeyEnum.Redo,
|
|
13
13
|
keys: combineKeys([KeyEnum.Mod, 'y']),
|
|
14
|
-
priority:
|
|
14
|
+
priority: COMMAND_PRIORITY_LOW,
|
|
15
15
|
scopes: [HotkeyScopeEnum.Format]
|
|
16
16
|
}, {
|
|
17
17
|
id: HotkeyEnum.Bold,
|
|
18
18
|
keys: combineKeys([KeyEnum.Mod, 'b']),
|
|
19
|
-
priority:
|
|
19
|
+
priority: COMMAND_PRIORITY_LOW,
|
|
20
20
|
scopes: [HotkeyScopeEnum.Format]
|
|
21
21
|
}, {
|
|
22
22
|
id: HotkeyEnum.Italic,
|
|
23
23
|
keys: combineKeys([KeyEnum.Mod, 'i']),
|
|
24
|
-
priority:
|
|
24
|
+
priority: COMMAND_PRIORITY_LOW,
|
|
25
25
|
scopes: [HotkeyScopeEnum.Format]
|
|
26
26
|
}, {
|
|
27
27
|
id: HotkeyEnum.Underline,
|
|
28
28
|
keys: combineKeys([KeyEnum.Mod, 'u']),
|
|
29
|
-
priority:
|
|
29
|
+
priority: COMMAND_PRIORITY_LOW,
|
|
30
30
|
scopes: [HotkeyScopeEnum.Format]
|
|
31
31
|
}, {
|
|
32
32
|
id: HotkeyEnum.Strikethrough,
|
|
33
33
|
keys: combineKeys([KeyEnum.Mod, KeyEnum.Shift, 'x']),
|
|
34
|
-
priority:
|
|
34
|
+
priority: COMMAND_PRIORITY_LOW,
|
|
35
35
|
scopes: [HotkeyScopeEnum.Format]
|
|
36
36
|
}, {
|
|
37
37
|
id: HotkeyEnum.CodeInline,
|
|
38
38
|
keys: combineKeys([KeyEnum.Mod, 'e']),
|
|
39
|
-
priority:
|
|
39
|
+
priority: COMMAND_PRIORITY_LOW,
|
|
40
40
|
scopes: [HotkeyScopeEnum.Format, HotkeyScopeEnum.Plugin]
|
|
41
41
|
}, {
|
|
42
42
|
id: HotkeyEnum.Link,
|
|
43
43
|
keys: combineKeys([KeyEnum.Mod, KeyEnum.Shift, 'k']),
|
|
44
|
-
priority:
|
|
44
|
+
priority: COMMAND_PRIORITY_LOW,
|
|
45
45
|
scopes: [HotkeyScopeEnum.Format, HotkeyScopeEnum.Plugin]
|
|
46
46
|
},
|
|
47
47
|
// List hotkeys
|
|
48
48
|
{
|
|
49
49
|
id: HotkeyEnum.NumberList,
|
|
50
50
|
keys: combineKeys([KeyEnum.Mod, KeyEnum.Shift, '7']),
|
|
51
|
-
priority:
|
|
51
|
+
priority: COMMAND_PRIORITY_LOW,
|
|
52
52
|
scopes: [HotkeyScopeEnum.Insert, HotkeyScopeEnum.Plugin]
|
|
53
53
|
}, {
|
|
54
54
|
id: HotkeyEnum.BulletList,
|
|
55
55
|
keys: combineKeys([KeyEnum.Mod, KeyEnum.Shift, '8']),
|
|
56
|
-
priority:
|
|
56
|
+
priority: COMMAND_PRIORITY_LOW,
|
|
57
57
|
scopes: [HotkeyScopeEnum.Insert, HotkeyScopeEnum.Plugin]
|
|
58
58
|
}, {
|
|
59
59
|
id: HotkeyEnum.PasteAsPlainText,
|
|
60
60
|
keys: combineKeys([KeyEnum.Mod, KeyEnum.Shift, 'v']),
|
|
61
|
-
priority:
|
|
61
|
+
priority: COMMAND_PRIORITY_LOW,
|
|
62
62
|
scopes: [HotkeyScopeEnum.Format]
|
|
63
63
|
}];
|
|
@@ -6,6 +6,6 @@ export default class DataSource {
|
|
|
6
6
|
protected dataType: string;
|
|
7
7
|
constructor(dataType: string);
|
|
8
8
|
get type(): string;
|
|
9
|
-
read(editor: LexicalEditor, data: any): void;
|
|
9
|
+
read(editor: LexicalEditor, data: any, options?: Record<string, unknown>): void;
|
|
10
10
|
write(editor: LexicalEditor, options?: IWriteOptions): any;
|
|
11
11
|
}
|
|
@@ -40,7 +40,7 @@ export declare class Kernel extends EventEmitter implements IEditorKernel {
|
|
|
40
40
|
setRootElement(dom: HTMLElement, editable?: boolean): LexicalEditor;
|
|
41
41
|
setEditable(editable: boolean): void;
|
|
42
42
|
initNodeEditor(): LexicalEditor;
|
|
43
|
-
setDocument(type: string, content: any): void;
|
|
43
|
+
setDocument(type: string, content: any, options?: Record<string, unknown>): void;
|
|
44
44
|
focus(): void;
|
|
45
45
|
blur(): void;
|
|
46
46
|
getDocument(type: string): DataSource | undefined;
|
|
@@ -261,7 +261,7 @@ export var Kernel = /*#__PURE__*/function (_EventEmitter) {
|
|
|
261
261
|
}
|
|
262
262
|
}, {
|
|
263
263
|
key: "setDocument",
|
|
264
|
-
value: function setDocument(type, content) {
|
|
264
|
+
value: function setDocument(type, content, options) {
|
|
265
265
|
var datasource = this.dataTypeMap.get(type);
|
|
266
266
|
if (!datasource) {
|
|
267
267
|
this.logger.error("\u274C DataSource for type \"".concat(type, "\" not found"));
|
|
@@ -271,7 +271,7 @@ export var Kernel = /*#__PURE__*/function (_EventEmitter) {
|
|
|
271
271
|
this.logger.error('❌ Editor not initialized');
|
|
272
272
|
throw new Error("Editor is not initialized.");
|
|
273
273
|
}
|
|
274
|
-
datasource.read(this.editor, content);
|
|
274
|
+
datasource.read(this.editor, content, options);
|
|
275
275
|
this.emit('documentChange', type, content);
|
|
276
276
|
this.logger.debug("\uD83D\uDCE5 Set ".concat(type, " document"));
|
|
277
277
|
}
|
|
@@ -2,6 +2,6 @@ import type { LexicalEditor } from 'lexical';
|
|
|
2
2
|
import { DataSource } from "../../../editor-kernel";
|
|
3
3
|
import type { IWriteOptions } from "../../../editor-kernel/data-source";
|
|
4
4
|
export default class JSONDataSource extends DataSource {
|
|
5
|
-
read(editor: LexicalEditor, data: any): void;
|
|
5
|
+
read(editor: LexicalEditor, data: any, options?: Record<string, unknown>): void;
|
|
6
6
|
write(editor: LexicalEditor, options?: IWriteOptions): any;
|
|
7
7
|
}
|
|
@@ -40,6 +40,7 @@ var JSONDataSource = /*#__PURE__*/function (_DataSource) {
|
|
|
40
40
|
_createClass(JSONDataSource, [{
|
|
41
41
|
key: "read",
|
|
42
42
|
value: function read(editor, data) {
|
|
43
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
43
44
|
var dataObj;
|
|
44
45
|
if (typeof data === 'string') {
|
|
45
46
|
dataObj = JSON.parse(data);
|
|
@@ -69,7 +70,7 @@ var JSONDataSource = /*#__PURE__*/function (_DataSource) {
|
|
|
69
70
|
};
|
|
70
71
|
process(dataObj.root);
|
|
71
72
|
// @ts-expect-error add id option
|
|
72
|
-
if (dataObj.keepId) {
|
|
73
|
+
if (dataObj.keepId || options.keepId) {
|
|
73
74
|
var state = editor.parseEditorState({
|
|
74
75
|
root: INodeHelper.createRootNode()
|
|
75
76
|
}, function (state) {
|
|
@@ -4,5 +4,6 @@ export { default as LitexmlDataSource } from './data-source/litexml-data-source'
|
|
|
4
4
|
export type { LitexmlPluginOptions } from './plugin';
|
|
5
5
|
export { LitexmlPlugin } from './plugin';
|
|
6
6
|
export { ReactLiteXmlPlugin } from './react';
|
|
7
|
+
export { useHasDiffNode } from './react/hooks/useHasDiffNode';
|
|
7
8
|
export type { XMLReaderFunc, XMLReaderRecord, XMLWriterFunc, XMLWriterRecord, } from './service/litexml-service';
|
|
8
9
|
export { ILitexmlService, LitexmlService } from './service/litexml-service';
|
|
@@ -3,4 +3,5 @@ export { DiffAction, LITEXML_DIFFNODE_ALL_COMMAND, LITEXML_DIFFNODE_COMMAND } fr
|
|
|
3
3
|
export { default as LitexmlDataSource } from "./data-source/litexml-data-source";
|
|
4
4
|
export { LitexmlPlugin } from "./plugin";
|
|
5
5
|
export { ReactLiteXmlPlugin } from "./react";
|
|
6
|
+
export { useHasDiffNode } from "./react/hooks/useHasDiffNode";
|
|
6
7
|
export { ILitexmlService, LitexmlService } from "./service/litexml-service";
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
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."); }
|
|
3
|
+
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; } }
|
|
4
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
5
|
+
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; } } }; }
|
|
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 _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; }
|
|
8
|
+
import { useEffect, useState } from 'react';
|
|
9
|
+
function hasDiffNode(editor) {
|
|
10
|
+
var _editor$getLexicalEdi;
|
|
11
|
+
var values = (_editor$getLexicalEdi = editor.getLexicalEditor()) === null || _editor$getLexicalEdi === void 0 ? void 0 : _editor$getLexicalEdi.getEditorState()._nodeMap.values();
|
|
12
|
+
if (!values) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
var _iterator = _createForOfIteratorHelper(values),
|
|
16
|
+
_step;
|
|
17
|
+
try {
|
|
18
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
19
|
+
var node = _step.value;
|
|
20
|
+
if (node.getType() === 'diff') {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
} catch (err) {
|
|
25
|
+
_iterator.e(err);
|
|
26
|
+
} finally {
|
|
27
|
+
_iterator.f();
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
export function useHasDiffNode(editor) {
|
|
32
|
+
var _useState = useState(!!editor.getLexicalEditor()),
|
|
33
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
34
|
+
hasInit = _useState2[0],
|
|
35
|
+
setHasInit = _useState2[1];
|
|
36
|
+
var _useState3 = useState(hasDiffNode(editor)),
|
|
37
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
38
|
+
hasDiff = _useState4[0],
|
|
39
|
+
setHasDiff = _useState4[1];
|
|
40
|
+
useEffect(function () {
|
|
41
|
+
var handle = function handle() {
|
|
42
|
+
setHasInit(true);
|
|
43
|
+
};
|
|
44
|
+
editor.on('initialized', handle);
|
|
45
|
+
return function () {
|
|
46
|
+
editor.off('initialized', handle);
|
|
47
|
+
};
|
|
48
|
+
}, [editor]);
|
|
49
|
+
useEffect(function () {
|
|
50
|
+
var _editor$getLexicalEdi2;
|
|
51
|
+
var unregister = (_editor$getLexicalEdi2 = editor.getLexicalEditor()) === null || _editor$getLexicalEdi2 === void 0 ? void 0 : _editor$getLexicalEdi2.registerUpdateListener(function () {
|
|
52
|
+
setHasDiff(hasDiffNode(editor));
|
|
53
|
+
});
|
|
54
|
+
return function () {
|
|
55
|
+
unregister === null || unregister === void 0 || unregister();
|
|
56
|
+
};
|
|
57
|
+
}, [editor, hasInit]);
|
|
58
|
+
return {
|
|
59
|
+
hasDiff: hasDiff
|
|
60
|
+
};
|
|
61
|
+
}
|
package/es/types/kernel.d.ts
CHANGED
|
@@ -186,7 +186,7 @@ export interface IEditor {
|
|
|
186
186
|
* @param type
|
|
187
187
|
* @param content
|
|
188
188
|
*/
|
|
189
|
-
setDocument(type: string, content: any): void;
|
|
189
|
+
setDocument(type: string, content: any, options?: Record<string, unknown>): void;
|
|
190
190
|
/**
|
|
191
191
|
* Enable or disable editor editing capability
|
|
192
192
|
* @param editable
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/editor",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.10.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",
|
|
@@ -29,6 +29,35 @@
|
|
|
29
29
|
"react.d.ts",
|
|
30
30
|
"react.js"
|
|
31
31
|
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "npm run build:clean && father build && npm run build:packages",
|
|
34
|
+
"build:clean": "tsx ./scripts/clean.ts",
|
|
35
|
+
"build:packages": "tsx ./scripts/build.ts",
|
|
36
|
+
"build:watch": "father dev",
|
|
37
|
+
"ci": "npm run lint:circular && npm run lint && npm run type-check",
|
|
38
|
+
"clean": "rm -r es lib dist coverage .dumi/tmp .eslintcache node_modules/.cache",
|
|
39
|
+
"dev": "dumi dev",
|
|
40
|
+
"docs:build": "dumi build",
|
|
41
|
+
"docs:build-analyze": "ANALYZE=1 dumi build",
|
|
42
|
+
"docs:dev": "dumi dev",
|
|
43
|
+
"doctor": "father doctor",
|
|
44
|
+
"postinstall": "node scripts/patch-lexical.js",
|
|
45
|
+
"lint": "eslint \"{src,tests}/**/*.{js,jsx,ts,tsx}\" --fix",
|
|
46
|
+
"lint:circular": "dpdm src/**/*.{ts,tsx} --warning false --tree false --exit-code circular:1 -T true",
|
|
47
|
+
"lint:md": "remark . --quiet --frail --output",
|
|
48
|
+
"lint:style": "stylelint \"{src,tests}/**/*.{js,jsx,ts,tsx,less}\" --fix",
|
|
49
|
+
"prepack": "clean-package",
|
|
50
|
+
"postpack": "clean-package restore",
|
|
51
|
+
"prepare": "husky && npm run setup",
|
|
52
|
+
"prettier": "prettier -c --write --no-error-on-unmatched-pattern \"**/**\"",
|
|
53
|
+
"release": "semantic-release",
|
|
54
|
+
"setup": "dumi setup",
|
|
55
|
+
"start": "npm run docs:dev",
|
|
56
|
+
"test": "vitest",
|
|
57
|
+
"test:coverage": "vitest run --coverage --passWithNoTests",
|
|
58
|
+
"test:watch": "vitest --watch",
|
|
59
|
+
"type-check": "tsc --noEmit"
|
|
60
|
+
},
|
|
32
61
|
"dependencies": {
|
|
33
62
|
"@floating-ui/dom": "^1.7.4",
|
|
34
63
|
"@floating-ui/react": "^0.27.16",
|