@lobehub/editor 1.34.4 → 1.35.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.
@@ -125,6 +125,7 @@ export var ImagePlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
125
125
  }, {
126
126
  key: "registerLiteXml",
127
127
  value: function registerLiteXml() {
128
+ var _this3 = this;
128
129
  var litexmlService = this.kernel.requireService(ILitexmlService);
129
130
  if (!litexmlService) {
130
131
  return;
@@ -161,6 +162,15 @@ export var ImagePlugin = (_class = /*#__PURE__*/function (_KernelPlugin) {
161
162
  return false;
162
163
  });
163
164
  litexmlService.registerXMLReader('img', function (xmlNode) {
165
+ var _this3$config;
166
+ if (((_this3$config = _this3.config) === null || _this3$config === void 0 ? void 0 : _this3$config.defaultBlockImage) !== false) {
167
+ return INodeHelper.createElementNode(BlockImageNode.getType(), {
168
+ altText: xmlNode.getAttribute('alt') || '',
169
+ maxWidth: xmlNode.getAttribute('max-width') ? parseInt(xmlNode.getAttribute('max-width'), 10) : undefined,
170
+ src: xmlNode.getAttribute('src') || '',
171
+ width: xmlNode.getAttribute('width') ? parseInt(xmlNode.getAttribute('width'), 10) : undefined
172
+ });
173
+ }
164
174
  if (xmlNode.getAttribute('block') === 'true') {
165
175
  return INodeHelper.createElementNode(BlockImageNode.getType(), {
166
176
  altText: xmlNode.getAttribute('alt') || '',
@@ -7,4 +7,7 @@ export declare const LITEXML_DIFFNODE_COMMAND: import("lexical").LexicalCommand<
7
7
  action: DiffAction;
8
8
  nodeKey: string;
9
9
  }>;
10
+ export declare const LITEXML_DIFFNODE_ALL_COMMAND: import("lexical").LexicalCommand<{
11
+ action: DiffAction;
12
+ }>;
10
13
  export declare function registerLiteXMLDiffCommand(editor: LexicalEditor): () => void;
@@ -1,11 +1,67 @@
1
1
  import { mergeRegister } from '@lexical/utils';
2
- import { $getNodeByKey, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
2
+ import { $getNodeByKey, $isElementNode, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
3
+ import { DiffNode } from "../node/DiffNode";
3
4
  export var DiffAction = /*#__PURE__*/function (DiffAction) {
4
5
  DiffAction[DiffAction["Reject"] = 0] = "Reject";
5
6
  DiffAction[DiffAction["Accept"] = 1] = "Accept";
6
7
  return DiffAction;
7
8
  }({});
8
9
  export var LITEXML_DIFFNODE_COMMAND = createCommand('LITEXML_DIFFNODE_COMMAND');
10
+ export var LITEXML_DIFFNODE_ALL_COMMAND = createCommand('LITEXML_DIFFNODE_ALL_COMMAND');
11
+ function doAction(node, action) {
12
+ if (node.diffType === 'modify') {
13
+ var children = node.getChildren();
14
+ if (action === DiffAction.Accept) {
15
+ node.replace(children[1], false).selectEnd();
16
+ } else if (action === DiffAction.Reject) {
17
+ node.replace(children[0], false).selectEnd();
18
+ }
19
+ }
20
+ if (node.diffType === 'remove') {
21
+ if (action === DiffAction.Accept) {
22
+ node.remove();
23
+ } else if (action === DiffAction.Reject) {
24
+ var _children = node.getChildren();
25
+ node.replace(_children[0], false).selectEnd();
26
+ }
27
+ }
28
+ if (node.diffType === 'add') {
29
+ if (action === DiffAction.Accept) {
30
+ var _children2 = node.getChildren();
31
+ node.replace(_children2[0], false).selectEnd();
32
+ } else if (action === DiffAction.Reject) {
33
+ node.remove();
34
+ }
35
+ }
36
+ if (node.diffType === 'listItemModify') {
37
+ var _children3 = node.getChildren();
38
+ if (action === DiffAction.Accept) {
39
+ var lastChild = _children3[1];
40
+ if (!$isElementNode(lastChild)) {
41
+ throw new Error('Expected element node as child of DiffNode');
42
+ }
43
+ var nodeChildrens = lastChild.getChildren();
44
+ for (var i = nodeChildrens.length - 1; i >= 0; i--) {
45
+ node.insertAfter(nodeChildrens[i]);
46
+ }
47
+ var parent = node.getParentOrThrow();
48
+ node.remove();
49
+ parent.selectEnd();
50
+ } else if (action === DiffAction.Reject) {
51
+ var firstChild = _children3[0];
52
+ if (!$isElementNode(firstChild)) {
53
+ throw new Error('Expected element node as child of DiffNode');
54
+ }
55
+ var _nodeChildrens = firstChild.getChildren();
56
+ for (var _i = _nodeChildrens.length - 1; _i >= 0; _i--) {
57
+ node.insertAfter(_nodeChildrens[_i]);
58
+ }
59
+ var _parent = node.getParentOrThrow();
60
+ node.remove();
61
+ _parent.selectEnd();
62
+ }
63
+ }
64
+ }
9
65
  export function registerLiteXMLDiffCommand(editor) {
10
66
  return mergeRegister(editor.registerCommand(LITEXML_DIFFNODE_COMMAND, function (payload) {
11
67
  var action = payload.action,
@@ -17,30 +73,23 @@ export function registerLiteXMLDiffCommand(editor) {
17
73
  return false;
18
74
  }
19
75
  editor.update(function () {
20
- if (node.diffType === 'modify') {
21
- var children = node.getChildren();
22
- if (action === DiffAction.Accept) {
23
- node.replace(children[1], false).selectEnd();
24
- } else if (action === DiffAction.Reject) {
25
- node.replace(children[0], false).selectEnd();
26
- }
27
- }
28
- if (node.diffType === 'remove') {
29
- if (action === DiffAction.Accept) {
30
- node.remove();
31
- } else if (action === DiffAction.Reject) {
32
- var _children = node.getChildren();
33
- node.replace(_children[0], false).selectEnd();
34
- }
35
- }
36
- if (node.diffType === 'add') {
37
- if (action === DiffAction.Accept) {
38
- var _children2 = node.getChildren();
39
- node.replace(_children2[0], false).selectEnd();
40
- } else if (action === DiffAction.Reject) {
41
- node.remove();
42
- }
43
- }
76
+ doAction(node, action);
77
+ });
78
+ return false;
79
+ }, COMMAND_PRIORITY_EDITOR), editor.registerCommand(LITEXML_DIFFNODE_ALL_COMMAND, function (payload) {
80
+ var action = payload.action;
81
+ var nodes = editor.read(function () {
82
+ return Array.from(editor._editorState._nodeMap.values()).filter(function (n) {
83
+ return n instanceof DiffNode && !!n.getParent();
84
+ });
85
+ });
86
+ if (!nodes.length) {
87
+ return false;
88
+ }
89
+ editor.update(function () {
90
+ nodes.forEach(function (node) {
91
+ doAction(node, action);
92
+ });
44
93
  });
45
94
  return false;
46
95
  }, COMMAND_PRIORITY_EDITOR));
@@ -9,7 +9,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
9
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
10
  /* eslint-disable @typescript-eslint/no-use-before-define */
11
11
  import { mergeRegister } from '@lexical/utils';
12
- import { $getNodeByKey, $insertNodes, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
12
+ import { $createParagraphNode, $getNodeByKey, $insertNodes, $isElementNode, COMMAND_PRIORITY_EDITOR, createCommand } from 'lexical';
13
13
  import { $closest } from "../../../editor-kernel";
14
14
  import { $createDiffNode } from "../node/DiffNode";
15
15
  import { $cloneNode, $parseSerializedNodeImpl, charToId } from "../utils";
@@ -59,14 +59,35 @@ function finalizeModifyBlocks(modifyBlockNodes, diffNodeMap, editor) {
59
59
  var _iterator = _createForOfIteratorHelper(modifyBlockNodes),
60
60
  _step;
61
61
  try {
62
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
62
+ var _loop = function _loop() {
63
63
  var blockNodeKey = _step.value;
64
64
  var blockNode = $getNodeByKey(blockNodeKey);
65
65
  var diffNode = diffNodeMap.get(blockNodeKey);
66
66
  if (diffNode && blockNode) {
67
- diffNode.append($cloneNode(blockNode, editor));
68
- blockNode.replace(diffNode, false);
67
+ // 如果是列表项,可能需要特殊处理
68
+ if (blockNode.getType() === 'listitem' && $isElementNode(blockNode)) {
69
+ var newDiffNode = $createDiffNode('listItemModify');
70
+ var firstChild = diffNode.getFirstChild();
71
+ if (firstChild && $isElementNode(firstChild)) {
72
+ newDiffNode.append(firstChild);
73
+ }
74
+ var children = blockNode.getChildren();
75
+ var p = $createParagraphNode();
76
+ children.forEach(function (child) {
77
+ child.remove();
78
+ p.append(child);
79
+ });
80
+ newDiffNode.append(p);
81
+ blockNode.append(newDiffNode);
82
+ return 1; // continue
83
+ } else {
84
+ diffNode.append($cloneNode(blockNode, editor));
85
+ blockNode.replace(diffNode, false);
86
+ }
69
87
  }
88
+ };
89
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
90
+ if (_loop()) continue;
70
91
  }
71
92
  } catch (err) {
72
93
  _iterator.e(err);
@@ -1,4 +1,5 @@
1
1
  export { LITEXML_APPLY_COMMAND, LITEXML_INSERT_COMMAND, LITEXML_MODIFY_COMMAND, LITEXML_REMOVE_COMMAND, } from './command';
2
+ export { DiffAction, LITEXML_DIFFNODE_ALL_COMMAND, LITEXML_DIFFNODE_COMMAND, } from './command/diffCommand';
2
3
  export { default as LitexmlDataSource } from './data-source/litexml-data-source';
3
4
  export type { LitexmlPluginOptions } from './plugin';
4
5
  export { LitexmlPlugin } from './plugin';
@@ -1,4 +1,5 @@
1
1
  export { LITEXML_APPLY_COMMAND, LITEXML_INSERT_COMMAND, LITEXML_MODIFY_COMMAND, LITEXML_REMOVE_COMMAND } from "./command";
2
+ export { DiffAction, LITEXML_DIFFNODE_ALL_COMMAND, LITEXML_DIFFNODE_COMMAND } from "./command/diffCommand";
2
3
  export { default as LitexmlDataSource } from "./data-source/litexml-data-source";
3
4
  export { LitexmlPlugin } from "./plugin";
4
5
  export { ReactLiteXmlPlugin } from "./react";
@@ -1,7 +1,8 @@
1
1
  import { DOMExportOutput, EditorConfig, ElementDOMSlot, LexicalEditor, LexicalUpdateJSON, SerializedElementNode, Spread } from 'lexical';
2
2
  import { CardLikeElementNode } from "../../common/node/cursor";
3
+ export type DiffType = 'add' | 'remove' | 'modify' | 'unchanged' | 'listItemModify';
3
4
  export type SerializedDiffNode = Spread<{
4
- diffType: 'add' | 'remove' | 'modify' | 'unchanged';
5
+ diffType: DiffType;
5
6
  }, SerializedElementNode>;
6
7
  /** DiffNode - contains two block children: original and modified */
7
8
  export declare class DiffNode extends CardLikeElementNode {
@@ -10,9 +11,9 @@ export declare class DiffNode extends CardLikeElementNode {
10
11
  static importJSON(serializedNode: SerializedDiffNode): DiffNode;
11
12
  static importDOM(): null;
12
13
  private __diffType;
13
- constructor(type: 'add' | 'remove' | 'modify' | 'unchanged', key?: string);
14
- get diffType(): 'add' | 'remove' | 'modify' | 'unchanged';
15
- setDiffType(type: 'add' | 'remove' | 'modify' | 'unchanged'): this;
14
+ constructor(type: DiffType, key?: string);
15
+ get diffType(): DiffType;
16
+ setDiffType(type: DiffType): this;
16
17
  updateFromJSON(serializedNode: LexicalUpdateJSON<SerializedDiffNode>): this;
17
18
  exportJSON(): SerializedDiffNode;
18
19
  exportDOM(editor: LexicalEditor): DOMExportOutput;
@@ -22,5 +23,5 @@ export declare class DiffNode extends CardLikeElementNode {
22
23
  isInline(): boolean;
23
24
  isCardLike(): boolean;
24
25
  }
25
- export declare function $createDiffNode(diffType?: 'add' | 'remove' | 'modify' | 'unchanged'): DiffNode;
26
+ export declare function $createDiffNode(diffType?: DiffType): DiffNode;
26
27
  export declare function $isDiffNode(node: unknown): node is DiffNode;
@@ -4,5 +4,5 @@ import { createStyles } from 'antd-style';
4
4
  export var useStyles = createStyles(function (_ref) {
5
5
  var css = _ref.css,
6
6
  token = _ref.token;
7
- return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: relative;\n\n .toolbar {\n position: absolute;\n z-index: 10;\n inset-block-end: -4px;\n inset-inline-end: 0;\n transform: translateY(100%);\n\n opacity: 0;\n }\n\n &:hover {\n .toolbar {\n opacity: 1;\n }\n }\n\n &[data-diff-type='add'] .content {\n position: relative;\n margin-block: 4px;\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n }\n\n &[data-diff-type='remove'] .content {\n position: relative;\n margin-block: 4px;\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n\n > *:first-child * {\n color: ", " !important;\n text-decoration: line-through !important;\n }\n }\n\n &[data-diff-type='modify'] .content {\n position: relative;\n margin-block: 4px;\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n\n /* first child: original (deleted) */\n\n /* > *:first-child {} */\n\n /* visually indicate deletion with strike-through for text nodes */\n > *:first-child * {\n color: ", " !important;\n text-decoration: line-through !important;\n }\n\n /* second child: modified/new - normal appearance */\n > *:nth-child(2) {\n color: inherit;\n opacity: 1;\n }\n }\n "])), token.colorSuccess, token.colorError, token.colorTextQuaternary, token.colorWarning, token.colorTextQuaternary);
7
+ return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: relative;\n\n .toolbar {\n position: absolute;\n z-index: 10;\n inset-block-end: 0;\n inset-inline-end: 8px;\n\n opacity: 0;\n }\n\n &:hover {\n .toolbar {\n opacity: 1;\n }\n }\n\n &[data-diff-type='add'] .content {\n position: relative;\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n }\n\n &[data-diff-type='remove'] .content {\n position: relative;\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n\n > *:first-child * {\n color: ", " !important;\n text-decoration: line-through !important;\n }\n }\n\n &[data-diff-type='listItemModify'] {\n display: inline-block;\n\n p {\n display: block !important;\n }\n }\n\n &[data-diff-type='listItemModify'] .content {\n position: relative;\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n\n /* first child: original (deleted) */\n\n /* > *:first-child {} */\n\n /* visually indicate deletion with strike-through for text nodes */\n > *:first-child * {\n color: ", " !important;\n text-decoration: line-through !important;\n }\n\n /* second child: modified/new - normal appearance */\n > *:nth-child(2) {\n color: inherit;\n opacity: 1;\n }\n }\n\n &[data-diff-type='modify'] .content {\n position: relative;\n margin-block-start: calc(var(--lobe-markdown-margin-multiple) * 0.5em);\n padding-inline-end: 4px;\n border-inline-end: 3px solid ", ";\n\n /* first child: original (deleted) */\n\n /* > *:first-child {} */\n\n /* visually indicate deletion with strike-through for text nodes */\n > *:first-child * {\n color: ", " !important;\n text-decoration: line-through !important;\n }\n\n /* second child: modified/new - normal appearance */\n > *:nth-child(2) {\n color: inherit;\n opacity: 1;\n }\n }\n "])), token.colorSuccess, token.colorError, token.colorTextQuaternary, token.colorWarning, token.colorTextQuaternary, token.colorWarning, token.colorTextQuaternary);
8
8
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/editor",
3
- "version": "1.34.4",
3
+ "version": "1.35.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",