@tiny-codes/react-easy 1.3.1 → 1.4.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 (65) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/es/components/FormItemControl/index.d.ts +7 -7
  3. package/es/components/FormItemControl/index.js +6 -6
  4. package/es/components/FormItemControl/index.js.map +1 -1
  5. package/es/components/Lexical/helpers/index.d.ts +73 -0
  6. package/es/components/Lexical/helpers/index.js +286 -0
  7. package/es/components/Lexical/helpers/index.js.map +1 -0
  8. package/es/components/Lexical/index.d.ts +6 -0
  9. package/es/components/Lexical/index.js +7 -0
  10. package/es/components/Lexical/index.js.map +1 -0
  11. package/es/components/Lexical/nodes/CloseIcon.d.ts +71 -0
  12. package/es/components/Lexical/nodes/CloseIcon.js +176 -0
  13. package/es/components/Lexical/nodes/CloseIcon.js.map +1 -0
  14. package/es/components/Lexical/nodes/DivNode.d.ts +45 -0
  15. package/es/components/Lexical/nodes/DivNode.js +191 -0
  16. package/es/components/Lexical/nodes/DivNode.js.map +1 -0
  17. package/es/components/Lexical/nodes/ExtendTextNode.d.ts +46 -0
  18. package/es/components/Lexical/nodes/ExtendTextNode.js +134 -0
  19. package/es/components/Lexical/nodes/ExtendTextNode.js.map +1 -0
  20. package/es/components/Lexical/nodes/SelectNode.d.ts +74 -0
  21. package/es/components/Lexical/nodes/SelectNode.js +239 -0
  22. package/es/components/Lexical/nodes/SelectNode.js.map +1 -0
  23. package/es/components/Lexical/nodes/base.d.ts +102 -0
  24. package/es/components/Lexical/nodes/base.js +217 -0
  25. package/es/components/Lexical/nodes/base.js.map +1 -0
  26. package/es/hooks/useRefValue.d.ts +2 -2
  27. package/es/hooks/useRefValue.js.map +1 -1
  28. package/es/utils/index.d.ts +1 -0
  29. package/es/utils/index.js +1 -0
  30. package/es/utils/index.js.map +1 -1
  31. package/es/utils/string.d.ts +7 -0
  32. package/es/utils/string.js +15 -0
  33. package/es/utils/string.js.map +1 -0
  34. package/lib/components/FormItemControl/index.d.ts +7 -7
  35. package/lib/components/FormItemControl/index.js.map +1 -1
  36. package/lib/components/Lexical/helpers/index.d.ts +73 -0
  37. package/lib/components/Lexical/helpers/index.js +222 -0
  38. package/lib/components/Lexical/helpers/index.js.map +7 -0
  39. package/lib/components/Lexical/index.d.ts +6 -0
  40. package/lib/components/Lexical/index.js +34 -0
  41. package/lib/components/Lexical/index.js.map +7 -0
  42. package/lib/components/Lexical/nodes/CloseIcon.d.ts +71 -0
  43. package/lib/components/Lexical/nodes/CloseIcon.js +149 -0
  44. package/lib/components/Lexical/nodes/CloseIcon.js.map +7 -0
  45. package/lib/components/Lexical/nodes/DivNode.d.ts +45 -0
  46. package/lib/components/Lexical/nodes/DivNode.js +139 -0
  47. package/lib/components/Lexical/nodes/DivNode.js.map +7 -0
  48. package/lib/components/Lexical/nodes/ExtendTextNode.d.ts +46 -0
  49. package/lib/components/Lexical/nodes/ExtendTextNode.js +95 -0
  50. package/lib/components/Lexical/nodes/ExtendTextNode.js.map +7 -0
  51. package/lib/components/Lexical/nodes/SelectNode.d.ts +74 -0
  52. package/lib/components/Lexical/nodes/SelectNode.js +156 -0
  53. package/lib/components/Lexical/nodes/SelectNode.js.map +7 -0
  54. package/lib/components/Lexical/nodes/base.d.ts +102 -0
  55. package/lib/components/Lexical/nodes/base.js +134 -0
  56. package/lib/components/Lexical/nodes/base.js.map +7 -0
  57. package/lib/hooks/useRefValue.d.ts +2 -2
  58. package/lib/hooks/useRefValue.js.map +2 -2
  59. package/lib/utils/index.d.ts +1 -0
  60. package/lib/utils/index.js +3 -1
  61. package/lib/utils/index.js.map +2 -2
  62. package/lib/utils/string.d.ts +7 -0
  63. package/lib/utils/string.js +37 -0
  64. package/lib/utils/string.js.map +7 -0
  65. package/package.json +20 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ## 1.4.1
6
+
7
+ 2025-8-10
8
+
9
+ ### Features
10
+
11
+ - 🔥 Add `CloseIcon` component for `Lexical`.
12
+
13
+ ## 1.4.0
14
+
15
+ 2025-8-7
16
+
17
+ ### Features
18
+
19
+ - 🔥 Add some custom nodes and helpers for `Lexical`.
20
+
5
21
  ## 1.3.1
6
22
 
7
23
  2025-8-1
@@ -2,16 +2,16 @@ import type { FC, ReactNode } from 'react';
2
2
  export interface FormItemControlProps {
3
3
  children: (options: {
4
4
  value: any;
5
- onChange?: (value: any) => void;
5
+ onChange: (value: any) => void;
6
6
  }) => ReactNode;
7
7
  }
8
8
  /**
9
- * - **EN:** FormItemControl is a component that wraps custom content into a valid Form.Item control.
10
- * It provides a value and an onChange function to the children, allowing them to interact with
11
- * the form state. This is useful for creating custom form controls that need to integrate with
12
- * Ant Design's Form.Item.
13
- * - **CN:** FormItemControl 是一个将自定义内容包装成有效的 Form.Item 控件的组件。它向子组件提供了一个 `value` 和一个 `onChange`
14
- * 函数,使得子组件能够与表单状态进行交互。 这对于创建需要与 Ant Design 的 `Form.Item` 集成的自定义表单控件非常有用。
9
+ * - **EN:** FormItemControl is a component that wraps custom content into a valid Form.Item control,
10
+ * and must be used as a direct child of Form.Item. It provides its children with a `value` and an
11
+ * `onChange` function, allowing them to interact with the form state. This is useful for creating
12
+ * custom form controls that need to integrate with Ant Design's Form.Item.
13
+ * - **CN:** FormItemControl 是一个将自定义内容包装成有效的 Form.Item 控件的组件,必须作为 Form.Item 的直接子节点使用。它向子组件提供了一个
14
+ * `value` 和一个 `onChange` 函数,使得子组件能够与表单状态进行交互。这对于创建需要与 Ant Design 的 `Form.Item` 集成的自定义表单控件非常有用。
15
15
  */
16
16
  declare const FormItemControl: FC<FormItemControlProps>;
17
17
  export default FormItemControl;
@@ -1,10 +1,10 @@
1
1
  /**
2
- * - **EN:** FormItemControl is a component that wraps custom content into a valid Form.Item control.
3
- * It provides a value and an onChange function to the children, allowing them to interact with
4
- * the form state. This is useful for creating custom form controls that need to integrate with
5
- * Ant Design's Form.Item.
6
- * - **CN:** FormItemControl 是一个将自定义内容包装成有效的 Form.Item 控件的组件。它向子组件提供了一个 `value` 和一个 `onChange`
7
- * 函数,使得子组件能够与表单状态进行交互。 这对于创建需要与 Ant Design 的 `Form.Item` 集成的自定义表单控件非常有用。
2
+ * - **EN:** FormItemControl is a component that wraps custom content into a valid Form.Item control,
3
+ * and must be used as a direct child of Form.Item. It provides its children with a `value` and an
4
+ * `onChange` function, allowing them to interact with the form state. This is useful for creating
5
+ * custom form controls that need to integrate with Ant Design's Form.Item.
6
+ * - **CN:** FormItemControl 是一个将自定义内容包装成有效的 Form.Item 控件的组件,必须作为 Form.Item 的直接子节点使用。它向子组件提供了一个
7
+ * `value` 和一个 `onChange` 函数,使得子组件能够与表单状态进行交互。这对于创建需要与 Ant Design 的 `Form.Item` 集成的自定义表单控件非常有用。
8
8
  */
9
9
  var FormItemControl = function FormItemControl(props) {
10
10
  // eslint-disable-next-line react/prop-types
@@ -1 +1 @@
1
- {"version":3,"names":["FormItemControl","props","_ref","children","value","onChange"],"sources":["../../../src/components/FormItemControl/index.tsx"],"sourcesContent":["import type { FC, ReactNode } from 'react';\n\nexport interface FormItemControlProps {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n children: (options: { value: any; onChange?: (value: any) => void }) => ReactNode;\n}\n\n/**\n * - **EN:** FormItemControl is a component that wraps custom content into a valid Form.Item control.\n * It provides a value and an onChange function to the children, allowing them to interact with\n * the form state. This is useful for creating custom form controls that need to integrate with\n * Ant Design's Form.Item.\n * - **CN:** FormItemControl 是一个将自定义内容包装成有效的 Form.Item 控件的组件。它向子组件提供了一个 `value` 和一个 `onChange`\n * 函数,使得子组件能够与表单状态进行交互。 这对于创建需要与 Ant Design 的 `Form.Item` 集成的自定义表单控件非常有用。\n */\nconst FormItemControl: FC<FormItemControlProps> = (props) => {\n // eslint-disable-next-line react/prop-types\n const { children, value, onChange } = props as FormItemControlProps & {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n value?: any;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onChange?: (value: any) => void;\n };\n\n return children({ value, onChange });\n};\n\nexport default FormItemControl;\n"],"mappings":"AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMA,eAAyC,GAAG,SAA5CA,eAAyCA,CAAIC,KAAK,EAAK;EAC3D;EACA,IAAAC,IAAA,GAAsCD,KAAK;IAAnCE,QAAQ,GAAAD,IAAA,CAARC,QAAQ;IAAEC,KAAK,GAAAF,IAAA,CAALE,KAAK;IAAEC,QAAQ,GAAAH,IAAA,CAARG,QAAQ;EAOjC,OAAOF,QAAQ,CAAC;IAAEC,KAAK,EAALA,KAAK;IAAEC,QAAQ,EAARA;EAAS,CAAC,CAAC;AACtC,CAAC;AAED,eAAeL,eAAe"}
1
+ {"version":3,"names":["FormItemControl","props","_ref","children","value","onChange"],"sources":["../../../src/components/FormItemControl/index.tsx"],"sourcesContent":["import type { FC, ReactNode } from 'react';\n\nexport interface FormItemControlProps {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n children: (options: { value: any; onChange: (value: any) => void }) => ReactNode;\n}\n\n/**\n * - **EN:** FormItemControl is a component that wraps custom content into a valid Form.Item control,\n * and must be used as a direct child of Form.Item. It provides its children with a `value` and an\n * `onChange` function, allowing them to interact with the form state. This is useful for creating\n * custom form controls that need to integrate with Ant Design's Form.Item.\n * - **CN:** FormItemControl 是一个将自定义内容包装成有效的 Form.Item 控件的组件,必须作为 Form.Item 的直接子节点使用。它向子组件提供了一个\n * `value` 和一个 `onChange` 函数,使得子组件能够与表单状态进行交互。这对于创建需要与 Ant Design 的 `Form.Item` 集成的自定义表单控件非常有用。\n */\nconst FormItemControl: FC<FormItemControlProps> = (props) => {\n // eslint-disable-next-line react/prop-types\n const { children, value, onChange } = props as FormItemControlProps & {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n value: any;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onChange: (value: any) => void;\n };\n\n return children({ value, onChange });\n};\n\nexport default FormItemControl;\n"],"mappings":"AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMA,eAAyC,GAAG,SAA5CA,eAAyCA,CAAIC,KAAK,EAAK;EAC3D;EACA,IAAAC,IAAA,GAAsCD,KAAK;IAAnCE,QAAQ,GAAAD,IAAA,CAARC,QAAQ;IAAEC,KAAK,GAAAF,IAAA,CAALE,KAAK;IAAEC,QAAQ,GAAAH,IAAA,CAARG,QAAQ;EAOjC,OAAOF,QAAQ,CAAC;IAAEC,KAAK,EAALA,KAAK;IAAEC,QAAQ,EAARA;EAAS,CAAC,CAAC;AACtC,CAAC;AAED,eAAeL,eAAe"}
@@ -0,0 +1,73 @@
1
+ import type { CSSProperties, HtmlHTMLAttributes } from 'react';
2
+ import type { LexicalEditor, LexicalNode } from 'lexical';
3
+ /**
4
+ * - EN: Insert a node at the current cursor position.
5
+ * - CN: 将节点插入到当前光标位置。
6
+ *
7
+ * @param editor LexicalEditor instance | LexicalEditor 实例
8
+ * @param node Node to insert | 要插入的节点
9
+ */
10
+ export declare function insertNodeAtCursor(editor: LexicalEditor, node: LexicalNode): void;
11
+ /**
12
+ * - EN: Insert text at the current cursor position.
13
+ * - CN: 将文本插入到当前光标位置。
14
+ *
15
+ * @param editor LexicalEditor instance | LexicalEditor 实例
16
+ * @param text Text to insert | 要插入的文本
17
+ */
18
+ export declare function insertTextAtCursor(editor: LexicalEditor, text: string): void;
19
+ /**
20
+ * - EN: Clear the editor content.
21
+ * - CN: 清空编辑器内容。
22
+ *
23
+ * @param editor LexicalEditor instance | LexicalEditor 实例
24
+ */
25
+ export declare function clearEditorContent(editor: LexicalEditor): void;
26
+ /**
27
+ * - EN: Find the first node that matches the predicate.
28
+ * - CN: 查找第一个符合条件的节点。
29
+ *
30
+ * @param editor LexicalEditor instance | LexicalEditor 实例
31
+ * @param predicate Function to test whether a node matches | 用于匹配节点的函数
32
+ *
33
+ * @returns The matched node, or undefined | 符合条件的第一个节点,或 undefined
34
+ */
35
+ export declare function findNode<T extends LexicalNode>(editor: LexicalEditor, predicate: (node: LexicalNode) => boolean): T | undefined;
36
+ /**
37
+ * - EN: Find all nodes that match the predicate.
38
+ * - CN: 查找所有符合条件的节点数组。
39
+ *
40
+ * @param editor LexicalEditor instance | LexicalEditor 实例
41
+ * @param predicate Function to test whether a node matches | 用于匹配节点的函数
42
+ * @param options Options | 选项
43
+ *
44
+ * @returns An array of matched nodes | 符合条件的节点数组
45
+ */
46
+ export declare function findNodes<T extends LexicalNode>(editor: LexicalEditor, predicate: (node: LexicalNode) => boolean, options?: {
47
+ stopOnFirstMatch?: boolean;
48
+ }): T[];
49
+ /**
50
+ * - EN: Update properties on a DOM element.
51
+ * - CN: 更新 DOM 元素的属性。
52
+ *
53
+ * @param dom Target DOM element to update | 要更新的 DOM 元素
54
+ * @param props Props to set on the element | 要设置的属性
55
+ */
56
+ export declare function updateDomProps(dom: HTMLElement | undefined, props: HtmlHTMLAttributes<HTMLElement>): void;
57
+ /**
58
+ * - EN: Update style on a DOM element.
59
+ * - CN: 更新 DOM 元素的样式。
60
+ *
61
+ * @param dom Target DOM element to update | 要更新的 DOM 元素
62
+ * @param style Style to set | 要设置的样式
63
+ */
64
+ export declare function updateDomStyle(dom: HTMLElement | undefined, style: CSSProperties | undefined): void;
65
+ /**
66
+ * - EN: Get attributes from a DOM element.
67
+ * - CN: 从 DOM 元素获取属性。
68
+ *
69
+ * @param dom Target DOM element | 目标 DOM 元素
70
+ *
71
+ * @returns Element attributes | 元素属性
72
+ */
73
+ export declare function getDomAttributes(dom: HTMLElement | undefined): HtmlHTMLAttributes<HTMLElement> | undefined;
@@ -0,0 +1,286 @@
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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
+ 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."); }
4
+ 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; } }
5
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
6
+ 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; } } }; }
7
+ 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); }
8
+ 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; }
9
+ 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; }
10
+ 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; }
11
+ 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; }
12
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
13
+ 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); }
14
+ import { $createTextNode, $getRoot, $getSelection, $isDecoratorNode, $isElementNode, $isParagraphNode, $isRangeSelection, $isTextNode } from 'lexical';
15
+ import { $createDivNode, $isDivNode } from "../nodes/DivNode";
16
+
17
+ /**
18
+ * - EN: Insert a node at the current cursor position.
19
+ * - CN: 将节点插入到当前光标位置。
20
+ *
21
+ * @param editor LexicalEditor instance | LexicalEditor 实例
22
+ * @param node Node to insert | 要插入的节点
23
+ */
24
+ export function insertNodeAtCursor(editor, node) {
25
+ editor.update(function () {
26
+ var selection = $getSelection();
27
+ if (selection) {
28
+ if ($isRangeSelection(selection)) {
29
+ // 如果没有选取,则直接在根节点末尾插入
30
+ var lastNode = selection.focus.getNode();
31
+ if (lastNode) {
32
+ if ($isParagraphNode(lastNode)) {
33
+ lastNode.append(node);
34
+ } else if ($isTextNode(lastNode)) {
35
+ // 如果最后一个节点是文本节点,则在其后插入 SelectNode
36
+ lastNode.insertAfter(node);
37
+ } else if ($isDivNode(lastNode)) {
38
+ lastNode.append(node);
39
+ } else {
40
+ selection.insertNodes([node]);
41
+ }
42
+ node.selectNext();
43
+ }
44
+ } else {
45
+ selection.insertNodes([node]);
46
+ node.selectNext();
47
+ }
48
+ } else {
49
+ var root = $getRoot();
50
+ var nodeToInsert = node;
51
+ if ($isElementNode(node) || $isDecoratorNode(node)) {
52
+ nodeToInsert = node;
53
+ } else {
54
+ var container = $createDivNode({
55
+ style: {
56
+ display: 'inline-block'
57
+ }
58
+ });
59
+ container.append(node);
60
+ nodeToInsert = container;
61
+ }
62
+ root.append(nodeToInsert);
63
+ node.selectNext();
64
+ }
65
+ });
66
+ }
67
+
68
+ /**
69
+ * - EN: Insert text at the current cursor position.
70
+ * - CN: 将文本插入到当前光标位置。
71
+ *
72
+ * @param editor LexicalEditor instance | LexicalEditor 实例
73
+ * @param text Text to insert | 要插入的文本
74
+ */
75
+ export function insertTextAtCursor(editor, text) {
76
+ editor === null || editor === void 0 || editor.update(function () {
77
+ var textNode = $createTextNode(text);
78
+ var root = $getRoot();
79
+ var selection = $getSelection();
80
+ if (selection) {
81
+ // 插入光标位置
82
+ selection.insertText(text);
83
+ } else {
84
+ // 如果没有选取,则直接在根节点末尾插入
85
+ var lastNode = root.getLastChild();
86
+ if (lastNode && $isParagraphNode(lastNode)) {
87
+ lastNode.append(textNode);
88
+ } else {
89
+ var container = $createDivNode({
90
+ style: {
91
+ display: 'inline-block'
92
+ }
93
+ });
94
+ container.append(textNode);
95
+ root.append(container);
96
+ }
97
+ }
98
+ });
99
+ }
100
+
101
+ /**
102
+ * - EN: Clear the editor content.
103
+ * - CN: 清空编辑器内容。
104
+ *
105
+ * @param editor LexicalEditor instance | LexicalEditor 实例
106
+ */
107
+ export function clearEditorContent(editor) {
108
+ var state = editor.getEditorState();
109
+ var stateJson = state.toJSON();
110
+ // 默认创建一个ParagraphNode
111
+ var newJson = _objectSpread(_objectSpread({}, stateJson), {}, {
112
+ root: _objectSpread(_objectSpread({}, stateJson.root), {}, {
113
+ children: [{
114
+ children: [],
115
+ direction: null,
116
+ format: '',
117
+ indent: 0,
118
+ type: 'paragraph',
119
+ version: 1,
120
+ textFormat: 0,
121
+ textStyle: ''
122
+ }]
123
+ })
124
+ });
125
+ var emptyState = editor.parseEditorState(JSON.stringify(newJson));
126
+ editor.setEditorState(emptyState);
127
+ editor.update(function () {
128
+ var root = $getRoot();
129
+ root.clear();
130
+ });
131
+ }
132
+
133
+ /**
134
+ * - EN: Find the first node that matches the predicate.
135
+ * - CN: 查找第一个符合条件的节点。
136
+ *
137
+ * @param editor LexicalEditor instance | LexicalEditor 实例
138
+ * @param predicate Function to test whether a node matches | 用于匹配节点的函数
139
+ *
140
+ * @returns The matched node, or undefined | 符合条件的第一个节点,或 undefined
141
+ */
142
+ export function findNode(editor, predicate) {
143
+ var matched = findNodes(editor, predicate, {
144
+ stopOnFirstMatch: true
145
+ });
146
+ return matched[0];
147
+ }
148
+ /**
149
+ * - EN: Find all nodes that match the predicate.
150
+ * - CN: 查找所有符合条件的节点数组。
151
+ *
152
+ * @param editor LexicalEditor instance | LexicalEditor 实例
153
+ * @param predicate Function to test whether a node matches | 用于匹配节点的函数
154
+ * @param options Options | 选项
155
+ *
156
+ * @returns An array of matched nodes | 符合条件的节点数组
157
+ */
158
+ export function findNodes(editor, predicate, options) {
159
+ var matched = [];
160
+ editor.getEditorState().read(function () {
161
+ var root = $getRoot();
162
+ var traverse = function traverse(node, result) {
163
+ if (predicate(node)) {
164
+ result.push(node);
165
+ if (options !== null && options !== void 0 && options.stopOnFirstMatch) {
166
+ return;
167
+ }
168
+ }
169
+ if ($isElementNode(node)) {
170
+ var children = node.getChildren();
171
+ var _iterator = _createForOfIteratorHelper(children),
172
+ _step;
173
+ try {
174
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
175
+ var child = _step.value;
176
+ traverse(child, result);
177
+ if (options !== null && options !== void 0 && options.stopOnFirstMatch && result.length > 0) {
178
+ return;
179
+ }
180
+ }
181
+ } catch (err) {
182
+ _iterator.e(err);
183
+ } finally {
184
+ _iterator.f();
185
+ }
186
+ }
187
+ };
188
+ traverse(root, matched);
189
+ });
190
+ return matched;
191
+ }
192
+
193
+ /**
194
+ * - EN: Update properties on a DOM element.
195
+ * - CN: 更新 DOM 元素的属性。
196
+ *
197
+ * @param dom Target DOM element to update | 要更新的 DOM 元素
198
+ * @param props Props to set on the element | 要设置的属性
199
+ */
200
+ export function updateDomProps(dom, props) {
201
+ if (!dom) return;
202
+ Array.from(dom.attributes).forEach(function (attr) {
203
+ if (!attr.name.startsWith('data-lexical')) {
204
+ dom.removeAttribute(attr.name);
205
+ }
206
+ });
207
+ dom.removeAttribute('style');
208
+ dom.removeAttribute('class');
209
+ if (props) {
210
+ Object.entries(props).forEach(function (_ref) {
211
+ var _ref2 = _slicedToArray(_ref, 2),
212
+ key = _ref2[0],
213
+ value = _ref2[1];
214
+ if (key === 'style' && value) {
215
+ Object.entries(value).forEach(function (_ref3) {
216
+ var _ref4 = _slicedToArray(_ref3, 2),
217
+ styleKey = _ref4[0],
218
+ styleValue = _ref4[1];
219
+ if (styleValue !== undefined) {
220
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
221
+ dom.style[styleKey] = styleValue;
222
+ }
223
+ });
224
+ } else if (key === 'className' && value) {
225
+ dom.className = value;
226
+ } else if (value !== undefined && value !== null) {
227
+ dom.setAttribute(key, value.toString());
228
+ }
229
+ });
230
+ }
231
+ }
232
+
233
+ /**
234
+ * - EN: Update style on a DOM element.
235
+ * - CN: 更新 DOM 元素的样式。
236
+ *
237
+ * @param dom Target DOM element to update | 要更新的 DOM 元素
238
+ * @param style Style to set | 要设置的样式
239
+ */
240
+ export function updateDomStyle(dom, style) {
241
+ if (!dom) return;
242
+ dom.removeAttribute('style');
243
+ if (style) {
244
+ Object.entries(style).forEach(function (_ref5) {
245
+ var _ref6 = _slicedToArray(_ref5, 2),
246
+ styleKey = _ref6[0],
247
+ styleValue = _ref6[1];
248
+ if (styleValue !== undefined) {
249
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
250
+ dom.style[styleKey] = styleValue;
251
+ }
252
+ });
253
+ }
254
+ }
255
+
256
+ /**
257
+ * - EN: Get attributes from a DOM element.
258
+ * - CN: 从 DOM 元素获取属性。
259
+ *
260
+ * @param dom Target DOM element | 目标 DOM 元素
261
+ *
262
+ * @returns Element attributes | 元素属性
263
+ */
264
+ export function getDomAttributes(dom) {
265
+ if (!dom) return undefined;
266
+ var attributes = {};
267
+ Array.from(dom.attributes).forEach(function (attr) {
268
+ if (attr.name === 'class' || attr.name === 'style') {
269
+ return;
270
+ }
271
+ attributes[attr.name] = attr.value;
272
+ });
273
+ if (dom.className) {
274
+ attributes.className = dom.className;
275
+ }
276
+ if (dom.style) {
277
+ var styles = {};
278
+ Array.from(dom.style).forEach(function (styleName) {
279
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
280
+ styles[styleName] = dom.style[styleName];
281
+ });
282
+ attributes.style = styles;
283
+ }
284
+ return attributes;
285
+ }
286
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["$createTextNode","$getRoot","$getSelection","$isDecoratorNode","$isElementNode","$isParagraphNode","$isRangeSelection","$isTextNode","$createDivNode","$isDivNode","insertNodeAtCursor","editor","node","update","selection","lastNode","focus","getNode","append","insertAfter","insertNodes","selectNext","root","nodeToInsert","container","style","display","insertTextAtCursor","text","textNode","insertText","getLastChild","clearEditorContent","state","getEditorState","stateJson","toJSON","newJson","_objectSpread","children","direction","format","indent","type","version","textFormat","textStyle","emptyState","parseEditorState","JSON","stringify","setEditorState","clear","findNode","predicate","matched","findNodes","stopOnFirstMatch","options","read","traverse","result","push","getChildren","_iterator","_createForOfIteratorHelper","_step","s","n","done","child","value","length","err","e","f","updateDomProps","dom","props","Array","from","attributes","forEach","attr","name","startsWith","removeAttribute","Object","entries","_ref","_ref2","_slicedToArray","key","_ref3","_ref4","styleKey","styleValue","undefined","className","setAttribute","toString","updateDomStyle","_ref5","_ref6","getDomAttributes","styles","styleName"],"sources":["../../../../src/components/Lexical/helpers/index.ts"],"sourcesContent":["import type { CSSProperties, HtmlHTMLAttributes } from 'react';\nimport type { LexicalEditor, LexicalNode } from 'lexical';\nimport {\n $createTextNode,\n $getRoot,\n $getSelection,\n $isDecoratorNode,\n $isElementNode,\n $isParagraphNode,\n $isRangeSelection,\n $isTextNode,\n} from 'lexical';\nimport { $createDivNode, $isDivNode } from '../nodes/DivNode';\n\n/**\n * - EN: Insert a node at the current cursor position.\n * - CN: 将节点插入到当前光标位置。\n *\n * @param editor LexicalEditor instance | LexicalEditor 实例\n * @param node Node to insert | 要插入的节点\n */\nexport function insertNodeAtCursor(editor: LexicalEditor, node: LexicalNode): void {\n editor.update(() => {\n const selection = $getSelection();\n if (selection) {\n if ($isRangeSelection(selection)) {\n // 如果没有选取,则直接在根节点末尾插入\n const lastNode = selection.focus.getNode();\n if (lastNode) {\n if ($isParagraphNode(lastNode)) {\n lastNode.append(node);\n } else if ($isTextNode(lastNode)) {\n // 如果最后一个节点是文本节点,则在其后插入 SelectNode\n lastNode.insertAfter(node);\n } else if ($isDivNode(lastNode)) {\n lastNode.append(node);\n } else {\n selection.insertNodes([node]);\n }\n node.selectNext();\n }\n } else {\n selection.insertNodes([node]);\n node.selectNext();\n }\n } else {\n const root = $getRoot();\n let nodeToInsert: LexicalNode = node;\n if ($isElementNode(node) || $isDecoratorNode(node)) {\n nodeToInsert = node;\n } else {\n const container = $createDivNode({\n style: { display: 'inline-block' },\n });\n container.append(node);\n nodeToInsert = container;\n }\n root.append(nodeToInsert);\n node.selectNext();\n }\n });\n}\n\n/**\n * - EN: Insert text at the current cursor position.\n * - CN: 将文本插入到当前光标位置。\n *\n * @param editor LexicalEditor instance | LexicalEditor 实例\n * @param text Text to insert | 要插入的文本\n */\nexport function insertTextAtCursor(editor: LexicalEditor, text: string): void {\n editor?.update(() => {\n const textNode = $createTextNode(text);\n const root = $getRoot();\n const selection = $getSelection();\n if (selection) {\n // 插入光标位置\n selection.insertText(text);\n } else {\n // 如果没有选取,则直接在根节点末尾插入\n const lastNode = root.getLastChild();\n if (lastNode && $isParagraphNode(lastNode)) {\n lastNode.append(textNode);\n } else {\n const container = $createDivNode({\n style: { display: 'inline-block' },\n });\n container.append(textNode);\n root.append(container);\n }\n }\n });\n}\n\n/**\n * - EN: Clear the editor content.\n * - CN: 清空编辑器内容。\n *\n * @param editor LexicalEditor instance | LexicalEditor 实例\n */\nexport function clearEditorContent(editor: LexicalEditor) {\n const state = editor.getEditorState();\n const stateJson = state.toJSON();\n // 默认创建一个ParagraphNode\n const newJson = {\n ...stateJson,\n root: {\n ...stateJson.root,\n children: [\n {\n children: [],\n direction: null,\n format: '',\n indent: 0,\n type: 'paragraph',\n version: 1,\n textFormat: 0,\n textStyle: '',\n },\n ],\n },\n };\n const emptyState = editor.parseEditorState(JSON.stringify(newJson));\n editor.setEditorState(emptyState);\n editor.update(() => {\n const root = $getRoot();\n root.clear();\n });\n}\n\n/**\n * - EN: Find the first node that matches the predicate.\n * - CN: 查找第一个符合条件的节点。\n *\n * @param editor LexicalEditor instance | LexicalEditor 实例\n * @param predicate Function to test whether a node matches | 用于匹配节点的函数\n *\n * @returns The matched node, or undefined | 符合条件的第一个节点,或 undefined\n */\nexport function findNode<T extends LexicalNode>(\n editor: LexicalEditor,\n predicate: (node: LexicalNode) => boolean\n): T | undefined {\n const matched = findNodes<T>(editor, predicate, { stopOnFirstMatch: true });\n return matched[0];\n}\n/**\n * - EN: Find all nodes that match the predicate.\n * - CN: 查找所有符合条件的节点数组。\n *\n * @param editor LexicalEditor instance | LexicalEditor 实例\n * @param predicate Function to test whether a node matches | 用于匹配节点的函数\n * @param options Options | 选项\n *\n * @returns An array of matched nodes | 符合条件的节点数组\n */\nexport function findNodes<T extends LexicalNode>(\n editor: LexicalEditor,\n predicate: (node: LexicalNode) => boolean,\n options?: {\n stopOnFirstMatch?: boolean;\n }\n): T[] {\n const matched: T[] = [];\n editor.getEditorState().read(() => {\n const root = $getRoot();\n const traverse = (node: LexicalNode, result: T[]) => {\n if (predicate(node)) {\n result.push(node as unknown as T);\n if (options?.stopOnFirstMatch) {\n return;\n }\n }\n if ($isElementNode(node)) {\n const children = node.getChildren();\n for (const child of children) {\n traverse(child, result);\n if (options?.stopOnFirstMatch && result.length > 0) {\n return;\n }\n }\n }\n };\n traverse(root, matched);\n });\n return matched;\n}\n\n/**\n * - EN: Update properties on a DOM element.\n * - CN: 更新 DOM 元素的属性。\n *\n * @param dom Target DOM element to update | 要更新的 DOM 元素\n * @param props Props to set on the element | 要设置的属性\n */\nexport function updateDomProps(dom: HTMLElement | undefined, props: HtmlHTMLAttributes<HTMLElement>): void {\n if (!dom) return;\n Array.from(dom.attributes).forEach((attr) => {\n if (!attr.name.startsWith('data-lexical')) {\n dom.removeAttribute(attr.name);\n }\n });\n\n dom.removeAttribute('style');\n dom.removeAttribute('class');\n\n if (props) {\n Object.entries(props).forEach(([key, value]) => {\n if (key === 'style' && value) {\n Object.entries(value as CSSProperties).forEach(([styleKey, styleValue]) => {\n if (styleValue !== undefined) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (dom.style as any)[styleKey] = styleValue;\n }\n });\n } else if (key === 'className' && value) {\n dom.className = value as string;\n } else if (value !== undefined && value !== null) {\n dom.setAttribute(key, value.toString());\n }\n });\n }\n}\n\n/**\n * - EN: Update style on a DOM element.\n * - CN: 更新 DOM 元素的样式。\n *\n * @param dom Target DOM element to update | 要更新的 DOM 元素\n * @param style Style to set | 要设置的样式\n */\nexport function updateDomStyle(dom: HTMLElement | undefined, style: CSSProperties | undefined): void {\n if (!dom) return;\n dom.removeAttribute('style');\n if (style) {\n Object.entries(style).forEach(([styleKey, styleValue]) => {\n if (styleValue !== undefined) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (dom.style as any)[styleKey] = styleValue;\n }\n });\n }\n}\n\n/**\n * - EN: Get attributes from a DOM element.\n * - CN: 从 DOM 元素获取属性。\n *\n * @param dom Target DOM element | 目标 DOM 元素\n *\n * @returns Element attributes | 元素属性\n */\nexport function getDomAttributes(dom: HTMLElement | undefined): HtmlHTMLAttributes<HTMLElement> | undefined {\n if (!dom) return undefined;\n\n const attributes: HtmlHTMLAttributes<HTMLElement> = {};\n Array.from(dom.attributes).forEach((attr) => {\n if (attr.name === 'class' || attr.name === 'style') {\n return;\n }\n attributes[attr.name as keyof HtmlHTMLAttributes<HTMLElement>] = attr.value;\n });\n\n if (dom.className) {\n attributes.className = dom.className;\n }\n\n if (dom.style) {\n const styles: CSSProperties = {};\n Array.from(dom.style).forEach((styleName) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (styles as any)[styleName] = (dom.style as any)[styleName];\n });\n attributes.style = styles;\n }\n\n return attributes;\n}\n"],"mappings":";;;;;;;;;;;;;AAEA,SACEA,eAAe,EACfC,QAAQ,EACRC,aAAa,EACbC,gBAAgB,EAChBC,cAAc,EACdC,gBAAgB,EAChBC,iBAAiB,EACjBC,WAAW,QACN,SAAS;AAChB,SAASC,cAAc,EAAEC,UAAU;;AAEnC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAACC,MAAqB,EAAEC,IAAiB,EAAQ;EACjFD,MAAM,CAACE,MAAM,CAAC,YAAM;IAClB,IAAMC,SAAS,GAAGZ,aAAa,CAAC,CAAC;IACjC,IAAIY,SAAS,EAAE;MACb,IAAIR,iBAAiB,CAACQ,SAAS,CAAC,EAAE;QAChC;QACA,IAAMC,QAAQ,GAAGD,SAAS,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OAAO,SAASQ,gBAAgBA,CAAC3B,GAA4B,EAA+C;EAC1G,IAAI,CAACA,GAAG,EAAE,OAAOoB,SAAS;EAE1B,IAAMhB,UAA2C,GAAG,CAAC,CAAC;EACtDF,KAAK,CAACC,IAAI,CAACH,GAAG,CAACI,UAAU,CAAC,CAACC,OAAO,CAAC,UAACC,IAAI,EAAK;IAC3C,IAAIA,IAAI,CAACC,IAAI,KAAK,OAAO,IAAID,IAAI,CAACC,IAAI,KAAK,OAAO,EAAE;MAClD;IACF;IACAH,UAAU,CAACE,IAAI,CAACC,IAAI,CAA0C,GAAGD,IAAI,CAACZ,KAAK;EAC7E,CAAC,CAAC;EAEF,IAAIM,GAAG,CAACqB,SAAS,EAAE;IACjBjB,UAAU,CAACiB,SAAS,GAAGrB,GAAG,CAACqB,SAAS;EACtC;EAEA,IAAIrB,GAAG,CAACpD,KAAK,EAAE;IACb,IAAMgF,MAAqB,GAAG,CAAC,CAAC;IAChC1B,KAAK,CAACC,IAAI,CAACH,GAAG,CAACpD,KAAK,CAAC,CAACyD,OAAO,CAAC,UAACwB,SAAS,EAAK;MAC3C;MACCD,MAAM,CAASC,SAAS,CAAC,GAAI7B,GAAG,CAACpD,KAAK,CAASiF,SAAS,CAAC;IAC5D,CAAC,CAAC;IACFzB,UAAU,CAACxD,KAAK,GAAGgF,MAAM;EAC3B;EAEA,OAAOxB,UAAU;AACnB"}
@@ -0,0 +1,6 @@
1
+ export * from './helpers';
2
+ export * from './nodes/base';
3
+ export * from './nodes/DivNode';
4
+ export * from './nodes/SelectNode';
5
+ export * from './nodes/ExtendTextNode';
6
+ export * from './nodes/CloseIcon';
@@ -0,0 +1,7 @@
1
+ export * from "./helpers";
2
+ export * from "./nodes/base";
3
+ export * from "./nodes/DivNode";
4
+ export * from "./nodes/SelectNode";
5
+ export * from "./nodes/ExtendTextNode";
6
+ export * from "./nodes/CloseIcon";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["../../../src/components/Lexical/index.ts"],"sourcesContent":["export * from './helpers';\nexport * from './nodes/base';\nexport * from './nodes/DivNode';\nexport * from './nodes/SelectNode';\nexport * from './nodes/ExtendTextNode';\nexport * from './nodes/CloseIcon';\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA"}
@@ -0,0 +1,71 @@
1
+ import { type CSSProperties, type HtmlHTMLAttributes, type ReactNode } from 'react';
2
+ import type { LexicalNode, SerializedLexicalNode, Spread } from 'lexical';
3
+ import type { BaseDecoratorNodeProps, BaseNodeProps } from './base';
4
+ import { BaseDecoratorNode } from './base';
5
+ export interface CloseIconNodeProps extends HtmlHTMLAttributes<HTMLSpanElement>, BaseDecoratorNodeProps {
6
+ /**
7
+ * - EN: Parent element class name, used to add positioning styles to the parent element.
8
+ * - CN: 父元素的类名,用于给父元素添加定位样式
9
+ */
10
+ parentClassName: string;
11
+ /**
12
+ * - EN: The custom icon to display, optional
13
+ * - CN: 要显示的自定义图标,可选
14
+ */
15
+ icon?: ReactNode;
16
+ /**
17
+ * - EN: The default class name for the close icon element. This property is invalid if `icon` is
18
+ * set.
19
+ * - CN: 默认关闭图标元素的类名,如果设置了 `icon` 则该属性无效
20
+ */
21
+ iconClassName?: string;
22
+ /**
23
+ * - EN: The custom style for the close icon element. This property is invalid if `icon` is set.
24
+ * - CN: 自定义关闭图标元素的样式,如果设置了 `icon` 则该属性无效
25
+ */
26
+ iconStyle?: CSSProperties;
27
+ /**
28
+ * - EN: The click event handler for the close icon element.
29
+ * - CN: 关闭图标元素的点击事件
30
+ */
31
+ onClick?: (e: React.MouseEvent<HTMLSpanElement>) => void;
32
+ }
33
+ /**
34
+ * - EN: A node that represents a close icon.
35
+ * - CN: 一个关闭图标的节点。
36
+ */
37
+ export declare class CloseIconNode extends BaseDecoratorNode<ReactNode, CloseIconNodeProps> {
38
+ __hashId: string;
39
+ constructor(props: CloseIconNodeProps & {
40
+ key?: string;
41
+ });
42
+ static getType(): string;
43
+ static clone(node: CloseIconNode): CloseIconNode;
44
+ static importJSON(serializedNode: SerializedCloseIconNode): CloseIconNode;
45
+ exportJSON(): SerializedCloseIconNode;
46
+ createDOM(): HTMLElement;
47
+ updateDOM(): boolean;
48
+ decorate(): ReactNode;
49
+ isInline(): boolean;
50
+ getPropValue(propName: keyof CloseIconNodeProps): CloseIconNodeProps[typeof propName];
51
+ setProps(props: Partial<CloseIconNodeProps>): void;
52
+ getUnderlyingProps(props: CloseIconNodeProps | undefined): Omit<CloseIconNodeProps, keyof BaseNodeProps>;
53
+ }
54
+ /**
55
+ * - EN: Factory to create a CloseIconNode.
56
+ * - CN: 创建 CloseIconNode 的工厂函数。
57
+ *
58
+ * @param props Props for the CloseIcon node | CloseIcon 节点的属性
59
+ */
60
+ export declare function $createCloseIconNode(props: CloseIconNodeProps): CloseIconNode;
61
+ /**
62
+ * - EN: Type guard to check whether a node is CloseIconNode.
63
+ * - CN: 判断节点是否为 CloseIconNode 的类型守卫。
64
+ *
65
+ * @param node Node to test | 要检测的节点
66
+ */
67
+ export declare function $isCloseIconNode(node: LexicalNode | null | undefined): node is CloseIconNode;
68
+ type SerializedCloseIconNode = Spread<{
69
+ props: CloseIconNodeProps;
70
+ }, SerializedLexicalNode>;
71
+ export {};