@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
@@ -0,0 +1,217 @@
1
+ var _excluded = ["canBeRemoved", "canBeReplaced"],
2
+ _excluded2 = ["key"],
3
+ _excluded3 = ["canBeEmpty", "canInsertTextBefore", "canInsertTextAfter"],
4
+ _excluded4 = ["key"];
5
+ 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); }
6
+ function _objectDestructuringEmpty(obj) { if (obj == null) throw new TypeError("Cannot destructure " + obj); }
7
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
8
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
9
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
10
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
11
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
12
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
13
+ function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); }
14
+ function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
15
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
16
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
17
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
18
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19
+ 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); } }
20
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
21
+ 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; }
22
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
23
+ 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); }
24
+ import { DecoratorNode, ElementNode } from 'lexical';
25
+
26
+ /**
27
+ * - EN: Common behavior flags for custom nodes.
28
+ * - CN: 自定义节点的通用行为标记。
29
+ */
30
+
31
+ /**
32
+ * - EN: Extra behavior flags for element nodes.
33
+ * - CN: 元素节点的附加行为标记。
34
+ */
35
+
36
+ /**
37
+ * - EN: A helper wrapping base behaviors (remove/replace) with guard flags.
38
+ * - CN: 封装基础行为(删除/替换)并根据标记进行限制的帮助器。
39
+ *
40
+ * @param props Node behavior flags | 节点行为标记
41
+ * @param superMethods Methods delegated to the underlying node | 委托给底层节点的方法
42
+ */
43
+ export var BaseNodeHelper = /*#__PURE__*/function () {
44
+ function BaseNodeHelper(props, superMethods) {
45
+ var _this = this;
46
+ _classCallCheck(this, BaseNodeHelper);
47
+ _defineProperty(this, "__props", void 0);
48
+ _defineProperty(this, "__superMethods", void 0);
49
+ _defineProperty(this, "hooks", {
50
+ remove: function remove(preserveEmptyParent) {
51
+ var _this$__props;
52
+ if (((_this$__props = _this.__props) === null || _this$__props === void 0 ? void 0 : _this$__props.canBeRemoved) === false) {
53
+ return;
54
+ }
55
+ _this.__superMethods.remove(preserveEmptyParent);
56
+ },
57
+ replace: function replace(replaceWith, includeChildren) {
58
+ var _this$__props2;
59
+ if (((_this$__props2 = _this.__props) === null || _this$__props2 === void 0 ? void 0 : _this$__props2.canBeReplaced) === false) {
60
+ return _this;
61
+ }
62
+ return _this.__superMethods.replace(replaceWith, includeChildren);
63
+ }
64
+ });
65
+ this.__props = props;
66
+ this.__superMethods = superMethods;
67
+ }
68
+ _createClass(BaseNodeHelper, [{
69
+ key: "getUnderlyingProps",
70
+ value:
71
+ /**
72
+ * - EN: Strip helper-only flags from props for DOM usage.
73
+ * - CN: 去除仅用于帮助器的标记属性,得到用于 DOM 的纯属性。
74
+ *
75
+ * @param props Props including helper flags | 含帮助标记的属性
76
+ */
77
+ function getUnderlyingProps(props) {
78
+ /* eslint-disable @typescript-eslint/no-unused-vars */
79
+ var canBeRemoved = props.canBeRemoved,
80
+ canBeReplaced = props.canBeReplaced,
81
+ restProps = _objectWithoutProperties(props, _excluded);
82
+ /* eslint-enable @typescript-eslint/no-unused-vars */
83
+ return restProps;
84
+ }
85
+ }]);
86
+ return BaseNodeHelper;
87
+ }();
88
+
89
+ /**
90
+ * - EN: Base element node with behavior flags.
91
+ * - CN: 带行为标记的基础元素节点。
92
+ */
93
+ export var BaseElementNode = /*#__PURE__*/function (_ElementNode) {
94
+ _inherits(BaseElementNode, _ElementNode);
95
+ var _super = _createSuper(BaseElementNode);
96
+ function BaseElementNode(props) {
97
+ var _thisSuper, _thisSuper2, _this2;
98
+ _classCallCheck(this, BaseElementNode);
99
+ var _ref = props || {},
100
+ key = _ref.key,
101
+ restProps = _objectWithoutProperties(_ref, _excluded2);
102
+ _this2 = _super.call(this, key);
103
+ _defineProperty(_assertThisInitialized(_this2), "__props", void 0);
104
+ _defineProperty(_assertThisInitialized(_this2), "__base", void 0);
105
+ _this2.__props = restProps;
106
+ _this2.__base = new BaseNodeHelper(_this2.__props, {
107
+ remove: function remove() {
108
+ return _get((_thisSuper = _assertThisInitialized(_this2), _getPrototypeOf(BaseElementNode.prototype)), "remove", _thisSuper).call(_thisSuper);
109
+ },
110
+ replace: function replace(replaceWith, includeChildren) {
111
+ return _get((_thisSuper2 = _assertThisInitialized(_this2), _getPrototypeOf(BaseElementNode.prototype)), "replace", _thisSuper2).call(_thisSuper2, replaceWith, includeChildren);
112
+ }
113
+ });
114
+ Object.keys(_this2.__base.hooks).forEach(function (key) {
115
+ var method = _this2.__base.hooks[key];
116
+ if (typeof method === 'function') {
117
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
118
+ _this2[key] = method.bind(_this2.__base);
119
+ }
120
+ });
121
+ return _this2;
122
+ }
123
+ _createClass(BaseElementNode, [{
124
+ key: "canBeEmpty",
125
+ value: function canBeEmpty() {
126
+ var _this$__props$canBeEm, _this$__props3;
127
+ return (_this$__props$canBeEm = (_this$__props3 = this.__props) === null || _this$__props3 === void 0 ? void 0 : _this$__props3.canBeEmpty) !== null && _this$__props$canBeEm !== void 0 ? _this$__props$canBeEm : false;
128
+ }
129
+ }, {
130
+ key: "canInsertTextBefore",
131
+ value: function canInsertTextBefore() {
132
+ var _this$__props$canInse, _this$__props4;
133
+ return (_this$__props$canInse = (_this$__props4 = this.__props) === null || _this$__props4 === void 0 ? void 0 : _this$__props4.canInsertTextBefore) !== null && _this$__props$canInse !== void 0 ? _this$__props$canInse : true;
134
+ }
135
+ }, {
136
+ key: "canInsertTextAfter",
137
+ value: function canInsertTextAfter() {
138
+ var _this$__props$canInse2, _this$__props5;
139
+ return (_this$__props$canInse2 = (_this$__props5 = this.__props) === null || _this$__props5 === void 0 ? void 0 : _this$__props5.canInsertTextAfter) !== null && _this$__props$canInse2 !== void 0 ? _this$__props$canInse2 : true;
140
+ }
141
+
142
+ /**
143
+ * - EN: Strip element-specific flags and return DOM props.
144
+ * - CN: 去除元素特有的标记并返回 DOM 属性。
145
+ *
146
+ * @param props Element props including flags | 含标记的元素属性
147
+ */
148
+ }, {
149
+ key: "getUnderlyingProps",
150
+ value: function getUnderlyingProps(props) {
151
+ var baseProps = this.__base.getUnderlyingProps(props !== null && props !== void 0 ? props : {});
152
+ /* eslint-disable @typescript-eslint/no-unused-vars */
153
+ var canBeEmpty = baseProps.canBeEmpty,
154
+ canInsertTextBefore = baseProps.canInsertTextBefore,
155
+ canInsertTextAfter = baseProps.canInsertTextAfter,
156
+ restProps = _objectWithoutProperties(baseProps, _excluded3);
157
+ /* eslint-enable @typescript-eslint/no-unused-vars */
158
+ return restProps;
159
+ }
160
+ }]);
161
+ return BaseElementNode;
162
+ }(ElementNode);
163
+
164
+ /**
165
+ * - EN: Base decorator node with behavior flags.
166
+ * - CN: 带行为标记的基础装饰器节点。
167
+ */
168
+ export var BaseDecoratorNode = /*#__PURE__*/function (_DecoratorNode) {
169
+ _inherits(BaseDecoratorNode, _DecoratorNode);
170
+ var _super2 = _createSuper(BaseDecoratorNode);
171
+ function BaseDecoratorNode(props) {
172
+ var _thisSuper3, _thisSuper4, _this3;
173
+ _classCallCheck(this, BaseDecoratorNode);
174
+ var _ref2 = props || {},
175
+ key = _ref2.key,
176
+ restProps = _objectWithoutProperties(_ref2, _excluded4);
177
+ _this3 = _super2.call(this, key);
178
+ _defineProperty(_assertThisInitialized(_this3), "__props", void 0);
179
+ _defineProperty(_assertThisInitialized(_this3), "__base", void 0);
180
+ _this3.__props = restProps;
181
+ _this3.__base = new BaseNodeHelper(_this3.__props, {
182
+ remove: function remove() {
183
+ return _get((_thisSuper3 = _assertThisInitialized(_this3), _getPrototypeOf(BaseDecoratorNode.prototype)), "remove", _thisSuper3).call(_thisSuper3);
184
+ },
185
+ replace: function replace(replaceWith, includeChildren) {
186
+ return _get((_thisSuper4 = _assertThisInitialized(_this3), _getPrototypeOf(BaseDecoratorNode.prototype)), "replace", _thisSuper4).call(_thisSuper4, replaceWith, includeChildren);
187
+ }
188
+ });
189
+ Object.keys(_this3.__base.hooks).forEach(function (key) {
190
+ var method = _this3.__base.hooks[key];
191
+ if (typeof method === 'function') {
192
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
193
+ _this3[key] = method.bind(_this3.__base);
194
+ }
195
+ });
196
+ return _this3;
197
+ }
198
+
199
+ /**
200
+ * - EN: Strip decorator-specific flags and return DOM props.
201
+ * - CN: 去除装饰器特有的标记并返回 DOM 属性。
202
+ *
203
+ * @param props Decorator props including flags | 含标记的装饰器属性
204
+ */
205
+ _createClass(BaseDecoratorNode, [{
206
+ key: "getUnderlyingProps",
207
+ value: function getUnderlyingProps(props) {
208
+ var baseProps = this.__base.getUnderlyingProps(props !== null && props !== void 0 ? props : {});
209
+ /* eslint-disable @typescript-eslint/no-unused-vars */
210
+ var restProps = Object.assign({}, (_objectDestructuringEmpty(baseProps), baseProps));
211
+ /* eslint-enable @typescript-eslint/no-unused-vars */
212
+ return restProps;
213
+ }
214
+ }]);
215
+ return BaseDecoratorNode;
216
+ }(DecoratorNode);
217
+ //# sourceMappingURL=base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["DecoratorNode","ElementNode","BaseNodeHelper","props","superMethods","_this","_classCallCheck","_defineProperty","remove","preserveEmptyParent","_this$__props","__props","canBeRemoved","__superMethods","replace","replaceWith","includeChildren","_this$__props2","canBeReplaced","_createClass","key","value","getUnderlyingProps","restProps","_objectWithoutProperties","_excluded","BaseElementNode","_ElementNode","_inherits","_super","_createSuper","_thisSuper","_thisSuper2","_this2","_ref","_excluded2","call","_assertThisInitialized","__base","_get","_getPrototypeOf","prototype","Object","keys","hooks","forEach","method","bind","canBeEmpty","_this$__props$canBeEm","_this$__props3","canInsertTextBefore","_this$__props$canInse","_this$__props4","canInsertTextAfter","_this$__props$canInse2","_this$__props5","baseProps","_excluded3","BaseDecoratorNode","_DecoratorNode","_super2","_thisSuper3","_thisSuper4","_this3","_ref2","_excluded4","assign","_objectDestructuringEmpty"],"sources":["../../../../src/components/Lexical/nodes/base.ts"],"sourcesContent":["import type { LexicalNode } from 'lexical';\nimport { DecoratorNode, ElementNode } from 'lexical';\n\n/**\n * - EN: Common behavior flags for custom nodes.\n * - CN: 自定义节点的通用行为标记。\n */\nexport interface BaseNodeProps {\n /**\n * - EN: Whether the node can be removed. Default `true`.\n * - CN: 是否可被删除,默认 `true`。\n */\n canBeRemoved?: boolean;\n /**\n * - EN: Whether the node can be replaced. Default `true`.\n * - CN: 是否可被替换,默认 `true`。\n */\n canBeReplaced?: boolean;\n}\n/**\n * - EN: Extra behavior flags for element nodes.\n * - CN: 元素节点的附加行为标记。\n */\nexport interface BaseElementProps extends BaseNodeProps {\n /**\n * - EN: Whether an element is allowed to be empty. Default `false`.\n * - CN: 是否允许节点为空,默认 `false`。\n */\n canBeEmpty?: boolean;\n /**\n * - EN: Allow inserting text at the start of the element. Default `true`.\n * - CN: 是否允许在节点内的起始位置插入文本,默认 `true`。\n */\n canInsertTextBefore?: boolean;\n /**\n * - EN: Allow inserting text at the end of the element. Default `true`.\n * - CN: 是否允许在节点内的结束位置插入文本,默认 `true`。\n */\n canInsertTextAfter?: boolean;\n}\n\nexport type BaseDecoratorNodeProps = BaseNodeProps;\n\n/**\n * - EN: A helper wrapping base behaviors (remove/replace) with guard flags.\n * - CN: 封装基础行为(删除/替换)并根据标记进行限制的帮助器。\n *\n * @param props Node behavior flags | 节点行为标记\n * @param superMethods Methods delegated to the underlying node | 委托给底层节点的方法\n */\nexport class BaseNodeHelper<P extends BaseNodeProps> {\n __props: (P & BaseNodeProps) | undefined;\n __superMethods: Pick<LexicalNode, 'replace' | 'remove'>;\n\n constructor(props: P | undefined, superMethods: Pick<LexicalNode, 'replace' | 'remove'>) {\n this.__props = props as P & BaseNodeProps;\n this.__superMethods = superMethods;\n }\n\n hooks = {\n remove: (preserveEmptyParent?: boolean): void => {\n if (this.__props?.canBeRemoved === false) {\n return;\n }\n this.__superMethods.remove(preserveEmptyParent);\n },\n\n replace: <N extends LexicalNode>(replaceWith: N, includeChildren?: boolean): N => {\n if (this.__props?.canBeReplaced === false) {\n return this as unknown as N;\n }\n return this.__superMethods.replace(replaceWith, includeChildren);\n },\n };\n /**\n * - EN: Strip helper-only flags from props for DOM usage.\n * - CN: 去除仅用于帮助器的标记属性,得到用于 DOM 的纯属性。\n *\n * @param props Props including helper flags | 含帮助标记的属性\n */\n getUnderlyingProps(props: P & BaseNodeProps): Omit<P, keyof BaseNodeProps> {\n /* eslint-disable @typescript-eslint/no-unused-vars */\n const { canBeRemoved, canBeReplaced, ...restProps } = props;\n /* eslint-enable @typescript-eslint/no-unused-vars */\n return restProps as P;\n }\n}\n\n/**\n * - EN: Base element node with behavior flags.\n * - CN: 带行为标记的基础元素节点。\n */\nexport class BaseElementNode<P extends BaseElementProps> extends ElementNode {\n __props: P | undefined;\n __base: BaseNodeHelper<P>;\n\n constructor(props?: P & { key?: string }) {\n const { key, ...restProps } = props || {};\n super(key);\n this.__props = restProps as P;\n this.__base = new BaseNodeHelper<P>(this.__props, {\n remove: () => super.remove(),\n replace: (replaceWith, includeChildren) => super.replace(replaceWith, includeChildren),\n });\n Object.keys(this.__base.hooks).forEach((key) => {\n const method = this.__base.hooks[key as keyof typeof this.__base.hooks];\n if (typeof method === 'function') {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this[key as keyof this] = method.bind(this.__base) as any;\n }\n });\n }\n\n canBeEmpty(): boolean {\n return this.__props?.canBeEmpty ?? false;\n }\n\n canInsertTextBefore(): boolean {\n return this.__props?.canInsertTextBefore ?? true;\n }\n\n canInsertTextAfter(): boolean {\n return this.__props?.canInsertTextAfter ?? true;\n }\n\n /**\n * - EN: Strip element-specific flags and return DOM props.\n * - CN: 去除元素特有的标记并返回 DOM 属性。\n *\n * @param props Element props including flags | 含标记的元素属性\n */\n getUnderlyingProps(props: P | undefined): Omit<P, keyof BaseElementProps> {\n const baseProps = this.__base.getUnderlyingProps(props ?? ({} as P));\n /* eslint-disable @typescript-eslint/no-unused-vars */\n const { canBeEmpty, canInsertTextBefore, canInsertTextAfter, ...restProps } = baseProps;\n /* eslint-enable @typescript-eslint/no-unused-vars */\n return restProps as P;\n }\n}\n\n/**\n * - EN: Base decorator node with behavior flags.\n * - CN: 带行为标记的基础装饰器节点。\n */\nexport class BaseDecoratorNode<T, P extends BaseDecoratorNodeProps> extends DecoratorNode<T> {\n __props: P | undefined;\n __base: BaseNodeHelper<P>;\n\n constructor(props?: P & { key?: string }) {\n const { key, ...restProps } = props || {};\n super(key);\n this.__props = restProps as P;\n\n this.__base = new BaseNodeHelper<P>(this.__props, {\n remove: () => super.remove(),\n replace: (replaceWith, includeChildren) => super.replace(replaceWith, includeChildren),\n });\n Object.keys(this.__base.hooks).forEach((key) => {\n const method = this.__base.hooks[key as keyof typeof this.__base.hooks];\n if (typeof method === 'function') {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n this[key as keyof this] = method.bind(this.__base) as any;\n }\n });\n }\n\n /**\n * - EN: Strip decorator-specific flags and return DOM props.\n * - CN: 去除装饰器特有的标记并返回 DOM 属性。\n *\n * @param props Decorator props including flags | 含标记的装饰器属性\n */\n getUnderlyingProps(props: P | undefined): Omit<P, keyof BaseDecoratorNodeProps> {\n const baseProps = this.__base.getUnderlyingProps(props ?? ({} as P));\n /* eslint-disable @typescript-eslint/no-unused-vars */\n const { ...restProps } = baseProps;\n /* eslint-enable @typescript-eslint/no-unused-vars */\n return restProps as P;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AACA,SAASA,aAAa,EAAEC,WAAW,QAAQ,SAAS;;AAEpD;AACA;AACA;AACA;;AAaA;AACA;AACA;AACA;;AAqBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAaC,cAAc;EAIzB,SAAAA,eAAYC,KAAoB,EAAEC,YAAqD,EAAE;IAAA,IAAAC,KAAA;IAAAC,eAAA,OAAAJ,cAAA;IAAAK,eAAA;IAAAA,eAAA;IAAAA,eAAA,gBAKjF;MACNC,MAAM,EAAE,SAAAA,OAACC,mBAA6B,EAAW;QAAA,IAAAC,aAAA;QAC/C,IAAI,EAAAA,aAAA,GAAAL,KAAI,CAACM,OAAO,cAAAD,aAAA,uBAAZA,aAAA,CAAcE,YAAY,MAAK,KAAK,EAAE;UACxC;QACF;QACAP,KAAI,CAACQ,cAAc,CAACL,MAAM,CAACC,mBAAmB,CAAC;MACjD,CAAC;MAEDK,OAAO,EAAE,SAAAA,QAAwBC,WAAc,EAAEC,eAAyB,EAAQ;QAAA,IAAAC,cAAA;QAChF,IAAI,EAA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;AACA;AACA;AACA;EALE7C,YAAA,CAAAwC,iBAAA;IAAAvC,GAAA;IAAAC,KAAA,EAMA,SAAAC,mBAAmBnB,KAAoB,EAAyC;MAC9E,IAAMsD,SAAS,GAAG,IAAI,CAACnB,MAAM,CAAChB,kBAAkB,CAACnB,KAAK,aAALA,KAAK,cAALA,KAAK,GAAK,CAAC,CAAO,CAAC;MACpE;MACA,IAAWoB,SAAS,GAAAmB,MAAA,CAAAyB,MAAA,MAAAC,yBAAA,CAAKX,SAAS,GAATA,SAAS;MAClC;MACA,OAAOlC,SAAS;IAClB;EAAC;EAAA,OAAAoC,iBAAA;AAAA,EAlCyE3D,aAAa"}
@@ -1,4 +1,4 @@
1
- /// <reference types="react" />
1
+ import type { RefObject } from 'react';
2
2
  /**
3
3
  * - **EN:** Get a mutable ref object and automatically update the value change
4
4
  * - **CN:** 获取一个可变的ref对象,并自动更新值变化
@@ -7,5 +7,5 @@
7
7
  *
8
8
  * @returns A mutable ref object, but the reference is immutable | 可变的ref对象,但引用不可变
9
9
  */
10
- declare const useRefValue: <T>(value: T) => import("react").RefObject<T>;
10
+ declare const useRefValue: <T>(value: T) => RefObject<T>;
11
11
  export default useRefValue;
@@ -1 +1 @@
1
- {"version":3,"names":["useRef","useRefValue","value","ref","current"],"sources":["../../src/hooks/useRefValue.ts"],"sourcesContent":["import { useRef } from 'react';\n\n/**\n * - **EN:** Get a mutable ref object and automatically update the value change\n * - **CN:** 获取一个可变的ref对象,并自动更新值变化\n *\n * @param value the wrapped value | 被包装的值\n *\n * @returns A mutable ref object, but the reference is immutable | 可变的ref对象,但引用不可变\n */\nconst useRefValue = <T>(value: T) => {\n const ref = useRef<T>(value);\n ref.current = value;\n return ref;\n};\n\nexport default useRefValue;\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,OAAO;;AAE9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,WAAW,GAAG,SAAdA,WAAWA,CAAOC,KAAQ,EAAK;EACnC,IAAMC,GAAG,GAAGH,MAAM,CAAIE,KAAK,CAAC;EAC5BC,GAAG,CAACC,OAAO,GAAGF,KAAK;EACnB,OAAOC,GAAG;AACZ,CAAC;AAED,eAAeF,WAAW"}
1
+ {"version":3,"names":["useRef","useRefValue","value","ref","current"],"sources":["../../src/hooks/useRefValue.ts"],"sourcesContent":["import type { RefObject } from 'react';\nimport { useRef } from 'react';\n\n/**\n * - **EN:** Get a mutable ref object and automatically update the value change\n * - **CN:** 获取一个可变的ref对象,并自动更新值变化\n *\n * @param value the wrapped value | 被包装的值\n *\n * @returns A mutable ref object, but the reference is immutable | 可变的ref对象,但引用不可变\n */\nconst useRefValue = <T>(value: T): RefObject<T> => {\n const ref = useRef<T>(value);\n ref.current = value;\n return ref;\n};\n\nexport default useRefValue;\n"],"mappings":"AACA,SAASA,MAAM,QAAQ,OAAO;;AAE9B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAMC,WAAW,GAAG,SAAdA,WAAWA,CAAOC,KAAQ,EAAmB;EACjD,IAAMC,GAAG,GAAGH,MAAM,CAAIE,KAAK,CAAC;EAC5BC,GAAG,CAACC,OAAO,GAAGF,KAAK;EACnB,OAAOC,GAAG;AACZ,CAAC;AAED,eAAeF,WAAW"}
@@ -1,2 +1,3 @@
1
1
  export * from './color';
2
2
  export * from './math';
3
+ export * from './string';
package/es/utils/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./color";
2
2
  export * from "./math";
3
+ export * from "./string";
3
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from './color';\nexport * from './math';\n"],"mappings":"AAAA;AACA"}
1
+ {"version":3,"names":[],"sources":["../../src/utils/index.ts"],"sourcesContent":["export * from './color';\nexport * from './math';\nexport * from './string';\n"],"mappings":"AAAA;AACA;AACA"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * - EN: Generate a random string of alphanumeric characters.
3
+ * - CN: 生成一个随机的字母数字字符串。
4
+ *
5
+ * @param length Length of the random string | 随机字符串的长度
6
+ */
7
+ export declare function randomChars(length: number): string;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * - EN: Generate a random string of alphanumeric characters.
3
+ * - CN: 生成一个随机的字母数字字符串。
4
+ *
5
+ * @param length Length of the random string | 随机字符串的长度
6
+ */
7
+ export function randomChars(length) {
8
+ var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
9
+ var result = '';
10
+ for (var i = 0; i < length; i++) {
11
+ result += chars.charAt(Math.floor(Math.random() * chars.length));
12
+ }
13
+ return result;
14
+ }
15
+ //# sourceMappingURL=string.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["randomChars","length","chars","result","i","charAt","Math","floor","random"],"sources":["../../src/utils/string.ts"],"sourcesContent":["/**\n * - EN: Generate a random string of alphanumeric characters.\n * - CN: 生成一个随机的字母数字字符串。\n *\n * @param length Length of the random string | 随机字符串的长度\n */\nexport function randomChars(length: number): string {\n const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';\n let result = '';\n for (let i = 0; i < length; i++) {\n result += chars.charAt(Math.floor(Math.random() * chars.length));\n }\n return result;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,WAAWA,CAACC,MAAc,EAAU;EAClD,IAAMC,KAAK,GAAG,gEAAgE;EAC9E,IAAIC,MAAM,GAAG,EAAE;EACf,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,MAAM,EAAEG,CAAC,EAAE,EAAE;IAC/BD,MAAM,IAAID,KAAK,CAACG,MAAM,CAACC,IAAI,CAACC,KAAK,CAACD,IAAI,CAACE,MAAM,CAAC,CAAC,GAAGN,KAAK,CAACD,MAAM,CAAC,CAAC;EAClE;EACA,OAAOE,MAAM;AACf"}
@@ -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,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/FormItemControl/index.tsx"],
4
- "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"],
4
+ "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"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,IAAM,kBAA4C,CAAC,UAAU;AAE3D,QAAM,EAAE,UAAU,OAAO,SAAS,IAAI;AAOtC,SAAO,SAAS,EAAE,OAAO,SAAS,CAAC;AACrC;AAEA,IAAO,0BAAQ;",
6
6
  "names": []
7
7
  }
@@ -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,222 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/components/Lexical/helpers/index.ts
20
+ var helpers_exports = {};
21
+ __export(helpers_exports, {
22
+ clearEditorContent: () => clearEditorContent,
23
+ findNode: () => findNode,
24
+ findNodes: () => findNodes,
25
+ getDomAttributes: () => getDomAttributes,
26
+ insertNodeAtCursor: () => insertNodeAtCursor,
27
+ insertTextAtCursor: () => insertTextAtCursor,
28
+ updateDomProps: () => updateDomProps,
29
+ updateDomStyle: () => updateDomStyle
30
+ });
31
+ module.exports = __toCommonJS(helpers_exports);
32
+ var import_lexical = require("lexical");
33
+ var import_DivNode = require("../nodes/DivNode");
34
+ function insertNodeAtCursor(editor, node) {
35
+ editor.update(() => {
36
+ const selection = (0, import_lexical.$getSelection)();
37
+ if (selection) {
38
+ if ((0, import_lexical.$isRangeSelection)(selection)) {
39
+ const lastNode = selection.focus.getNode();
40
+ if (lastNode) {
41
+ if ((0, import_lexical.$isParagraphNode)(lastNode)) {
42
+ lastNode.append(node);
43
+ } else if ((0, import_lexical.$isTextNode)(lastNode)) {
44
+ lastNode.insertAfter(node);
45
+ } else if ((0, import_DivNode.$isDivNode)(lastNode)) {
46
+ lastNode.append(node);
47
+ } else {
48
+ selection.insertNodes([node]);
49
+ }
50
+ node.selectNext();
51
+ }
52
+ } else {
53
+ selection.insertNodes([node]);
54
+ node.selectNext();
55
+ }
56
+ } else {
57
+ const root = (0, import_lexical.$getRoot)();
58
+ let nodeToInsert = node;
59
+ if ((0, import_lexical.$isElementNode)(node) || (0, import_lexical.$isDecoratorNode)(node)) {
60
+ nodeToInsert = node;
61
+ } else {
62
+ const container = (0, import_DivNode.$createDivNode)({
63
+ style: { display: "inline-block" }
64
+ });
65
+ container.append(node);
66
+ nodeToInsert = container;
67
+ }
68
+ root.append(nodeToInsert);
69
+ node.selectNext();
70
+ }
71
+ });
72
+ }
73
+ function insertTextAtCursor(editor, text) {
74
+ editor == null ? void 0 : editor.update(() => {
75
+ const textNode = (0, import_lexical.$createTextNode)(text);
76
+ const root = (0, import_lexical.$getRoot)();
77
+ const selection = (0, import_lexical.$getSelection)();
78
+ if (selection) {
79
+ selection.insertText(text);
80
+ } else {
81
+ const lastNode = root.getLastChild();
82
+ if (lastNode && (0, import_lexical.$isParagraphNode)(lastNode)) {
83
+ lastNode.append(textNode);
84
+ } else {
85
+ const container = (0, import_DivNode.$createDivNode)({
86
+ style: { display: "inline-block" }
87
+ });
88
+ container.append(textNode);
89
+ root.append(container);
90
+ }
91
+ }
92
+ });
93
+ }
94
+ function clearEditorContent(editor) {
95
+ const state = editor.getEditorState();
96
+ const stateJson = state.toJSON();
97
+ const newJson = {
98
+ ...stateJson,
99
+ root: {
100
+ ...stateJson.root,
101
+ children: [
102
+ {
103
+ children: [],
104
+ direction: null,
105
+ format: "",
106
+ indent: 0,
107
+ type: "paragraph",
108
+ version: 1,
109
+ textFormat: 0,
110
+ textStyle: ""
111
+ }
112
+ ]
113
+ }
114
+ };
115
+ const emptyState = editor.parseEditorState(JSON.stringify(newJson));
116
+ editor.setEditorState(emptyState);
117
+ editor.update(() => {
118
+ const root = (0, import_lexical.$getRoot)();
119
+ root.clear();
120
+ });
121
+ }
122
+ function findNode(editor, predicate) {
123
+ const matched = findNodes(editor, predicate, { stopOnFirstMatch: true });
124
+ return matched[0];
125
+ }
126
+ function findNodes(editor, predicate, options) {
127
+ const matched = [];
128
+ editor.getEditorState().read(() => {
129
+ const root = (0, import_lexical.$getRoot)();
130
+ const traverse = (node, result) => {
131
+ if (predicate(node)) {
132
+ result.push(node);
133
+ if (options == null ? void 0 : options.stopOnFirstMatch) {
134
+ return;
135
+ }
136
+ }
137
+ if ((0, import_lexical.$isElementNode)(node)) {
138
+ const children = node.getChildren();
139
+ for (const child of children) {
140
+ traverse(child, result);
141
+ if ((options == null ? void 0 : options.stopOnFirstMatch) && result.length > 0) {
142
+ return;
143
+ }
144
+ }
145
+ }
146
+ };
147
+ traverse(root, matched);
148
+ });
149
+ return matched;
150
+ }
151
+ function updateDomProps(dom, props) {
152
+ if (!dom)
153
+ return;
154
+ Array.from(dom.attributes).forEach((attr) => {
155
+ if (!attr.name.startsWith("data-lexical")) {
156
+ dom.removeAttribute(attr.name);
157
+ }
158
+ });
159
+ dom.removeAttribute("style");
160
+ dom.removeAttribute("class");
161
+ if (props) {
162
+ Object.entries(props).forEach(([key, value]) => {
163
+ if (key === "style" && value) {
164
+ Object.entries(value).forEach(([styleKey, styleValue]) => {
165
+ if (styleValue !== void 0) {
166
+ dom.style[styleKey] = styleValue;
167
+ }
168
+ });
169
+ } else if (key === "className" && value) {
170
+ dom.className = value;
171
+ } else if (value !== void 0 && value !== null) {
172
+ dom.setAttribute(key, value.toString());
173
+ }
174
+ });
175
+ }
176
+ }
177
+ function updateDomStyle(dom, style) {
178
+ if (!dom)
179
+ return;
180
+ dom.removeAttribute("style");
181
+ if (style) {
182
+ Object.entries(style).forEach(([styleKey, styleValue]) => {
183
+ if (styleValue !== void 0) {
184
+ dom.style[styleKey] = styleValue;
185
+ }
186
+ });
187
+ }
188
+ }
189
+ function getDomAttributes(dom) {
190
+ if (!dom)
191
+ return void 0;
192
+ const attributes = {};
193
+ Array.from(dom.attributes).forEach((attr) => {
194
+ if (attr.name === "class" || attr.name === "style") {
195
+ return;
196
+ }
197
+ attributes[attr.name] = attr.value;
198
+ });
199
+ if (dom.className) {
200
+ attributes.className = dom.className;
201
+ }
202
+ if (dom.style) {
203
+ const styles = {};
204
+ Array.from(dom.style).forEach((styleName) => {
205
+ styles[styleName] = dom.style[styleName];
206
+ });
207
+ attributes.style = styles;
208
+ }
209
+ return attributes;
210
+ }
211
+ // Annotate the CommonJS export names for ESM import in node:
212
+ 0 && (module.exports = {
213
+ clearEditorContent,
214
+ findNode,
215
+ findNodes,
216
+ getDomAttributes,
217
+ insertNodeAtCursor,
218
+ insertTextAtCursor,
219
+ updateDomProps,
220
+ updateDomStyle
221
+ });
222
+ //# sourceMappingURL=index.js.map