@tiny-codes/react-easy 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/es/components/ConfirmAction/withConfirmAction.js +23 -1
- package/es/components/ConfirmAction/withConfirmAction.js.map +1 -1
- package/es/components/Lexical/helpers/index.d.ts +58 -0
- package/es/components/Lexical/helpers/index.js +249 -0
- package/es/components/Lexical/helpers/index.js.map +1 -0
- package/es/components/Lexical/index.d.ts +5 -0
- package/es/components/Lexical/index.js +6 -0
- package/es/components/Lexical/index.js.map +1 -0
- package/es/components/Lexical/nodes/DivNode.d.ts +25 -0
- package/es/components/Lexical/nodes/DivNode.js +163 -0
- package/es/components/Lexical/nodes/DivNode.js.map +1 -0
- package/es/components/Lexical/nodes/ExtendTextNode.d.ts +24 -0
- package/es/components/Lexical/nodes/ExtendTextNode.js +102 -0
- package/es/components/Lexical/nodes/ExtendTextNode.js.map +1 -0
- package/es/components/Lexical/nodes/SelectNode.d.ts +44 -0
- package/es/components/Lexical/nodes/SelectNode.js +204 -0
- package/es/components/Lexical/nodes/SelectNode.js.map +1 -0
- package/es/components/Lexical/nodes/base.d.ts +51 -0
- package/es/components/Lexical/nodes/base.js +168 -0
- package/es/components/Lexical/nodes/base.js.map +1 -0
- package/es/hooks/useRefValue.d.ts +2 -2
- package/es/hooks/useRefValue.js.map +1 -1
- package/lib/components/ConfirmAction/withConfirmAction.js +5 -1
- package/lib/components/ConfirmAction/withConfirmAction.js.map +2 -2
- package/lib/components/Lexical/helpers/index.d.ts +58 -0
- package/lib/components/Lexical/helpers/index.js +198 -0
- package/lib/components/Lexical/helpers/index.js.map +7 -0
- package/lib/components/Lexical/index.d.ts +5 -0
- package/lib/components/Lexical/index.js +32 -0
- package/lib/components/Lexical/index.js.map +7 -0
- package/lib/components/Lexical/nodes/DivNode.d.ts +25 -0
- package/lib/components/Lexical/nodes/DivNode.js +139 -0
- package/lib/components/Lexical/nodes/DivNode.js.map +7 -0
- package/lib/components/Lexical/nodes/ExtendTextNode.d.ts +24 -0
- package/lib/components/Lexical/nodes/ExtendTextNode.js +87 -0
- package/lib/components/Lexical/nodes/ExtendTextNode.js.map +7 -0
- package/lib/components/Lexical/nodes/SelectNode.d.ts +44 -0
- package/lib/components/Lexical/nodes/SelectNode.js +157 -0
- package/lib/components/Lexical/nodes/SelectNode.js.map +7 -0
- package/lib/components/Lexical/nodes/base.d.ts +51 -0
- package/lib/components/Lexical/nodes/base.js +116 -0
- package/lib/components/Lexical/nodes/base.js.map +7 -0
- package/lib/hooks/useRefValue.d.ts +2 -2
- package/lib/hooks/useRefValue.js.map +2 -2
- package/package.json +20 -1
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { LexicalNode } from 'lexical';
|
|
2
|
+
import { DecoratorNode, ElementNode } from 'lexical';
|
|
3
|
+
export interface BaseNodeProps {
|
|
4
|
+
/** 是否可被删除,默认 `true` */
|
|
5
|
+
canBeRemoved?: boolean;
|
|
6
|
+
/** 是否可被替换,默认 `true` */
|
|
7
|
+
canBeReplaced?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface BaseElementProps extends BaseNodeProps {
|
|
10
|
+
/**
|
|
11
|
+
* 是否允许节点为空,默认 `false`
|
|
12
|
+
*
|
|
13
|
+
* - `true` - 允许节点为空
|
|
14
|
+
* - `false` - 不允许节点为空,当最后一个子节点被删除后,节点也会被删除
|
|
15
|
+
*/
|
|
16
|
+
canBeEmpty?: boolean;
|
|
17
|
+
/** 是否允许在节点内的起始位置插入文本,默认 `true` */
|
|
18
|
+
canInsertTextBefore?: boolean;
|
|
19
|
+
/** 是否允许在节点内的结束位置插入文本,默认 `true` */
|
|
20
|
+
canInsertTextAfter?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export type BaseDecoratorNodeProps = BaseNodeProps;
|
|
23
|
+
export declare class BaseNodeHelper<P extends BaseNodeProps> {
|
|
24
|
+
__props: (P & BaseNodeProps) | undefined;
|
|
25
|
+
__superMethods: Pick<LexicalNode, 'replace' | 'remove'>;
|
|
26
|
+
constructor(props: P | undefined, superMethods: Pick<LexicalNode, 'replace' | 'remove'>);
|
|
27
|
+
hooks: {
|
|
28
|
+
remove: (preserveEmptyParent?: boolean) => void;
|
|
29
|
+
replace: <N extends LexicalNode>(replaceWith: N, includeChildren?: boolean) => N;
|
|
30
|
+
};
|
|
31
|
+
getUnderlyingProps(props: P & BaseNodeProps): Omit<P, keyof BaseNodeProps>;
|
|
32
|
+
}
|
|
33
|
+
export declare class BaseElementNode<P extends BaseElementProps> extends ElementNode {
|
|
34
|
+
__props: P | undefined;
|
|
35
|
+
__base: BaseNodeHelper<P>;
|
|
36
|
+
constructor(props?: P & {
|
|
37
|
+
key?: string;
|
|
38
|
+
});
|
|
39
|
+
canBeEmpty(): boolean;
|
|
40
|
+
canInsertTextBefore(): boolean;
|
|
41
|
+
canInsertTextAfter(): boolean;
|
|
42
|
+
getUnderlyingProps(props: P | undefined): Omit<P, keyof BaseElementProps>;
|
|
43
|
+
}
|
|
44
|
+
export declare class BaseDecoratorNode<T, P extends BaseDecoratorNodeProps> extends DecoratorNode<T> {
|
|
45
|
+
__props: P | undefined;
|
|
46
|
+
__base: BaseNodeHelper<P>;
|
|
47
|
+
constructor(props?: P & {
|
|
48
|
+
key?: string;
|
|
49
|
+
});
|
|
50
|
+
getUnderlyingProps(props: P | undefined): Omit<P, keyof BaseDecoratorNodeProps>;
|
|
51
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
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
|
+
export var BaseNodeHelper = /*#__PURE__*/function () {
|
|
26
|
+
function BaseNodeHelper(props, superMethods) {
|
|
27
|
+
var _this = this;
|
|
28
|
+
_classCallCheck(this, BaseNodeHelper);
|
|
29
|
+
_defineProperty(this, "__props", void 0);
|
|
30
|
+
_defineProperty(this, "__superMethods", void 0);
|
|
31
|
+
_defineProperty(this, "hooks", {
|
|
32
|
+
remove: function remove(preserveEmptyParent) {
|
|
33
|
+
var _this$__props;
|
|
34
|
+
if (((_this$__props = _this.__props) === null || _this$__props === void 0 ? void 0 : _this$__props.canBeRemoved) === false) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
_this.__superMethods.remove(preserveEmptyParent);
|
|
38
|
+
},
|
|
39
|
+
replace: function replace(replaceWith, includeChildren) {
|
|
40
|
+
var _this$__props2;
|
|
41
|
+
if (((_this$__props2 = _this.__props) === null || _this$__props2 === void 0 ? void 0 : _this$__props2.canBeReplaced) === false) {
|
|
42
|
+
return _this;
|
|
43
|
+
}
|
|
44
|
+
return _this.__superMethods.replace(replaceWith, includeChildren);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
this.__props = props;
|
|
48
|
+
this.__superMethods = superMethods;
|
|
49
|
+
}
|
|
50
|
+
_createClass(BaseNodeHelper, [{
|
|
51
|
+
key: "getUnderlyingProps",
|
|
52
|
+
value: function getUnderlyingProps(props) {
|
|
53
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
54
|
+
var canBeRemoved = props.canBeRemoved,
|
|
55
|
+
canBeReplaced = props.canBeReplaced,
|
|
56
|
+
restProps = _objectWithoutProperties(props, _excluded);
|
|
57
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
58
|
+
return restProps;
|
|
59
|
+
}
|
|
60
|
+
}]);
|
|
61
|
+
return BaseNodeHelper;
|
|
62
|
+
}();
|
|
63
|
+
export var BaseElementNode = /*#__PURE__*/function (_ElementNode) {
|
|
64
|
+
_inherits(BaseElementNode, _ElementNode);
|
|
65
|
+
var _super = _createSuper(BaseElementNode);
|
|
66
|
+
function BaseElementNode(props) {
|
|
67
|
+
var _thisSuper, _thisSuper2, _this2;
|
|
68
|
+
_classCallCheck(this, BaseElementNode);
|
|
69
|
+
var _ref = props || {},
|
|
70
|
+
key = _ref.key,
|
|
71
|
+
restProps = _objectWithoutProperties(_ref, _excluded2);
|
|
72
|
+
_this2 = _super.call(this, key);
|
|
73
|
+
_defineProperty(_assertThisInitialized(_this2), "__props", void 0);
|
|
74
|
+
_defineProperty(_assertThisInitialized(_this2), "__base", void 0);
|
|
75
|
+
_this2.__props = restProps;
|
|
76
|
+
_this2.__base = new BaseNodeHelper(_this2.__props, {
|
|
77
|
+
remove: function remove() {
|
|
78
|
+
return _get((_thisSuper = _assertThisInitialized(_this2), _getPrototypeOf(BaseElementNode.prototype)), "remove", _thisSuper).call(_thisSuper);
|
|
79
|
+
},
|
|
80
|
+
replace: function replace(replaceWith, includeChildren) {
|
|
81
|
+
return _get((_thisSuper2 = _assertThisInitialized(_this2), _getPrototypeOf(BaseElementNode.prototype)), "replace", _thisSuper2).call(_thisSuper2, replaceWith, includeChildren);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
Object.keys(_this2.__base.hooks).forEach(function (key) {
|
|
85
|
+
var method = _this2.__base.hooks[key];
|
|
86
|
+
if (typeof method === 'function') {
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
88
|
+
_this2[key] = method.bind(_this2.__base);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
return _this2;
|
|
92
|
+
}
|
|
93
|
+
_createClass(BaseElementNode, [{
|
|
94
|
+
key: "canBeEmpty",
|
|
95
|
+
value: function canBeEmpty() {
|
|
96
|
+
var _this$__props$canBeEm, _this$__props3;
|
|
97
|
+
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;
|
|
98
|
+
}
|
|
99
|
+
}, {
|
|
100
|
+
key: "canInsertTextBefore",
|
|
101
|
+
value: function canInsertTextBefore() {
|
|
102
|
+
var _this$__props$canInse, _this$__props4;
|
|
103
|
+
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;
|
|
104
|
+
}
|
|
105
|
+
}, {
|
|
106
|
+
key: "canInsertTextAfter",
|
|
107
|
+
value: function canInsertTextAfter() {
|
|
108
|
+
var _this$__props$canInse2, _this$__props5;
|
|
109
|
+
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;
|
|
110
|
+
}
|
|
111
|
+
}, {
|
|
112
|
+
key: "getUnderlyingProps",
|
|
113
|
+
value: function getUnderlyingProps(props) {
|
|
114
|
+
var baseProps = this.__base.getUnderlyingProps(props !== null && props !== void 0 ? props : {});
|
|
115
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
116
|
+
var canBeEmpty = baseProps.canBeEmpty,
|
|
117
|
+
canInsertTextBefore = baseProps.canInsertTextBefore,
|
|
118
|
+
canInsertTextAfter = baseProps.canInsertTextAfter,
|
|
119
|
+
restProps = _objectWithoutProperties(baseProps, _excluded3);
|
|
120
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
121
|
+
return restProps;
|
|
122
|
+
}
|
|
123
|
+
}]);
|
|
124
|
+
return BaseElementNode;
|
|
125
|
+
}(ElementNode);
|
|
126
|
+
export var BaseDecoratorNode = /*#__PURE__*/function (_DecoratorNode) {
|
|
127
|
+
_inherits(BaseDecoratorNode, _DecoratorNode);
|
|
128
|
+
var _super2 = _createSuper(BaseDecoratorNode);
|
|
129
|
+
function BaseDecoratorNode(props) {
|
|
130
|
+
var _thisSuper3, _thisSuper4, _this3;
|
|
131
|
+
_classCallCheck(this, BaseDecoratorNode);
|
|
132
|
+
var _ref2 = props || {},
|
|
133
|
+
key = _ref2.key,
|
|
134
|
+
restProps = _objectWithoutProperties(_ref2, _excluded4);
|
|
135
|
+
_this3 = _super2.call(this, key);
|
|
136
|
+
_defineProperty(_assertThisInitialized(_this3), "__props", void 0);
|
|
137
|
+
_defineProperty(_assertThisInitialized(_this3), "__base", void 0);
|
|
138
|
+
_this3.__props = restProps;
|
|
139
|
+
_this3.__base = new BaseNodeHelper(_this3.__props, {
|
|
140
|
+
remove: function remove() {
|
|
141
|
+
return _get((_thisSuper3 = _assertThisInitialized(_this3), _getPrototypeOf(BaseDecoratorNode.prototype)), "remove", _thisSuper3).call(_thisSuper3);
|
|
142
|
+
},
|
|
143
|
+
replace: function replace(replaceWith, includeChildren) {
|
|
144
|
+
return _get((_thisSuper4 = _assertThisInitialized(_this3), _getPrototypeOf(BaseDecoratorNode.prototype)), "replace", _thisSuper4).call(_thisSuper4, replaceWith, includeChildren);
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
Object.keys(_this3.__base.hooks).forEach(function (key) {
|
|
148
|
+
var method = _this3.__base.hooks[key];
|
|
149
|
+
if (typeof method === 'function') {
|
|
150
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
151
|
+
_this3[key] = method.bind(_this3.__base);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
return _this3;
|
|
155
|
+
}
|
|
156
|
+
_createClass(BaseDecoratorNode, [{
|
|
157
|
+
key: "getUnderlyingProps",
|
|
158
|
+
value: function getUnderlyingProps(props) {
|
|
159
|
+
var baseProps = this.__base.getUnderlyingProps(props !== null && props !== void 0 ? props : {});
|
|
160
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
161
|
+
var restProps = Object.assign({}, (_objectDestructuringEmpty(baseProps), baseProps));
|
|
162
|
+
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
163
|
+
return restProps;
|
|
164
|
+
}
|
|
165
|
+
}]);
|
|
166
|
+
return BaseDecoratorNode;
|
|
167
|
+
}(DecoratorNode);
|
|
168
|
+
//# 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\nexport interface BaseNodeProps {\n /** 是否可被删除,默认 `true` */\n canBeRemoved?: boolean;\n /** 是否可被替换,默认 `true` */\n canBeReplaced?: boolean;\n}\nexport interface BaseElementProps extends BaseNodeProps {\n /**\n * 是否允许节点为空,默认 `false`\n *\n * - `true` - 允许节点为空\n * - `false` - 不允许节点为空,当最后一个子节点被删除后,节点也会被删除\n */\n canBeEmpty?: boolean;\n /** 是否允许在节点内的起始位置插入文本,默认 `true` */\n canInsertTextBefore?: boolean;\n /** 是否允许在节点内的结束位置插入文本,默认 `true` */\n canInsertTextAfter?: boolean;\n}\n\nexport type BaseDecoratorNodeProps = BaseNodeProps;\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 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\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 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\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 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;AAwBpD,WAAaC,cAAc;EAIzB,SAAAA,eAAYC,KAAoB,EAAEC,YAAqD,EAAE;IAAA,IAAAC,KAAA;IAAAC,eAAA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AC,UAACzB,GAAG,EAAK;MAC9C,IAAM0B,MAAM,GAAGkB,MAAA,CAAK1B,MAAM,CAACM,KAAK,CAACxB,GAAG,CAAmC;MACvE,IAAI,OAAO0B,MAAM,KAAK,UAAU,EAAE;QAChC;QACAkB,MAAA,CAAK5C,GAAG,CAAe,GAAG0B,MAAM,CAACC,IAAI,CAACiB,MAAA,CAAK1B,MAAM,CAAQ;MAC3D;IACF,CAAC,CAAC;IAAC,OAAA0B,MAAA;EACL;EAAC7C,YAAA,CAAAwC,iBAAA;IAAAvC,GAAA;IAAAC,KAAA,EAED,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,EA5ByE3D,aAAa"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
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) =>
|
|
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":"
|
|
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"}
|
|
@@ -47,6 +47,10 @@ function withConfirmActionInternal(ActionComponent, renderDefaultProps, defaultP
|
|
|
47
47
|
const setOnOk = (0, import_react.useCallback)((handler) => {
|
|
48
48
|
saveFuncRef.current = handler;
|
|
49
49
|
}, []);
|
|
50
|
+
const triggerOnOK = (0, import_react.useCallback)(async (...args) => {
|
|
51
|
+
var _a;
|
|
52
|
+
return (_a = saveFuncRef.current) == null ? void 0 : _a.call(saveFuncRef, ...args);
|
|
53
|
+
}, []);
|
|
50
54
|
(0, import_react.useImperativeHandle)(ref, () => {
|
|
51
55
|
return {
|
|
52
56
|
...actionRef.current,
|
|
@@ -57,7 +61,7 @@ function withConfirmActionInternal(ActionComponent, renderDefaultProps, defaultP
|
|
|
57
61
|
ConfirmActionWithRef,
|
|
58
62
|
{
|
|
59
63
|
...propsWithDefaults,
|
|
60
|
-
onOk:
|
|
64
|
+
onOk: triggerOnOK,
|
|
61
65
|
ref: actionRef
|
|
62
66
|
}
|
|
63
67
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/ConfirmAction/withConfirmAction.tsx"],
|
|
4
|
-
"sourcesContent": ["import type { ComponentType, PropsWithoutRef, ReactNode, RefAttributes } from 'react';\nimport { forwardRef, useCallback, useImperativeHandle, useRef, useState } from 'react';\nimport type { ActionCompConstraint, ConfirmActionProps, ConfirmActionRef } from '.';\nimport { genRenderer, withDefaultConfirmActionProps } from '.';\nimport { Button, type ButtonProps, Switch, type SwitchProps, Typography } from 'antd';\nimport type { LinkProps } from 'antd/es/typography/Link';\nimport { isForwardRef } from 'react-is';\n\n/**\n * - **EN:** Generate a confirm box component with custom trigger and default props\n * - **CN:** 将一个组件包装成一个确认弹框组件,支持自定义触发器和默认属性\n *\n * @param actionComponent Custom trigger component | 自定义触发器组件\n * @param defaultProps Default properties of the confirm box | 确认弹框的默认属性\n */\nexport default function withConfirmAction<\n P extends ActionCompConstraint,\n OuterTriggerProp extends object,\n OuterEvent extends keyof OuterTriggerProp,\n Ref extends object,\n>(\n ActionComponent: ActionComponentInterface<P, Ref>,\n defaultProps?:\n | Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>>\n | ((\n actualProps: Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>\n ) => Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>>)\n) {\n return withConfirmActionInternal(\n ActionComponent,\n {\n confirmType: 'normal',\n },\n defaultProps\n );\n}\n\nexport function withConfirmActionInternal<\n P extends ActionCompConstraint,\n OuterTriggerProp extends object,\n OuterEvent extends keyof OuterTriggerProp,\n Ref extends object,\n>(\n ActionComponent: ActionComponentInterface<P, Ref>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n renderDefaultProps: Partial<ConfirmActionProps<any, never>> & { confirmType: 'normal' | 'delete' },\n defaultProps?:\n | Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>>\n | ((\n actualProps: Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>\n ) => Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>>)\n) {\n const ConfirmActionWithRef = forwardRef(genRenderer(renderDefaultProps));\n ConfirmActionWithRef.displayName = 'ForwardRef(ConfirmAction)';\n\n const WrappedActionComponent = forwardRef<Ref, ConfirmActionProps<OuterTriggerProp, OuterEvent>>(\n (propsWithDefaults, ref) => {\n const actionRef = useRef<ConfirmActionRef>(null);\n const [customRef, setCustomRef] = useState<Ref | null>(null);\n const saveFuncRef = useRef<(...triggerEventArgs: any[]) => unknown | Promise<unknown>>(undefined);\n\n // Receive the onSave callback method passed by the form component\n const setOnOk: ActionCompConstraint['setOK'] = useCallback((handler) => {\n saveFuncRef.current = handler;\n }, []);\n\n // Merge the default ref and custom ref and output to the parent component\n useImperativeHandle(ref, () => {\n return {\n ...actionRef.current,\n ...customRef,\n } as ConfirmActionRef<Ref>;\n }, [customRef]);\n\n // Render the default trigger DOM element, and pass it to the custom ActionComponent\n const triggerDom = (\n <ConfirmActionWithRef\n {...(propsWithDefaults as ConfirmActionProps<object, never>)}\n onOk={
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA+E;AAE/E,eAA2D;AAC3D,kBAA+E;AAE/E,sBAA6B;AASd,SAAR,kBAML,iBACA,cAKA;AACA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,MACE,aAAa;AAAA,IACf;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,0BAMd,iBAEA,oBACA,cAKA;AACA,QAAM,2BAAuB,6BAAW,sBAAY,kBAAkB,CAAC;AACvE,uBAAqB,cAAc;AAEnC,QAAM,6BAAyB;AAAA,IAC7B,CAAC,mBAAmB,QAAQ;AAC1B,YAAM,gBAAY,qBAAyB,IAAI;AAC/C,YAAM,CAAC,WAAW,YAAY,QAAI,uBAAqB,IAAI;AAC3D,YAAM,kBAAc,qBAAmE,MAAS;AAGhG,YAAM,cAAyC,0BAAY,CAAC,YAAY;AACtE,oBAAY,UAAU;AAAA,MACxB,GAAG,CAAC,CAAC;AAGL,4CAAoB,KAAK,MAAM;AAC7B,eAAO;AAAA,UACL,GAAG,UAAU;AAAA,UACb,GAAG;AAAA,QACL;AAAA,MACF,GAAG,CAAC,SAAS,CAAC;AAGd,YAAM,aACJ;AAAA,QAAC;AAAA;AAAA,UACE,GAAI;AAAA,UACL,MAAM
|
|
4
|
+
"sourcesContent": ["import type { ComponentType, PropsWithoutRef, ReactNode, RefAttributes } from 'react';\nimport { forwardRef, useCallback, useImperativeHandle, useRef, useState } from 'react';\nimport type { ActionCompConstraint, ConfirmActionProps, ConfirmActionRef } from '.';\nimport { genRenderer, withDefaultConfirmActionProps } from '.';\nimport { Button, type ButtonProps, Switch, type SwitchProps, Typography } from 'antd';\nimport type { LinkProps } from 'antd/es/typography/Link';\nimport { isForwardRef } from 'react-is';\n\n/**\n * - **EN:** Generate a confirm box component with custom trigger and default props\n * - **CN:** 将一个组件包装成一个确认弹框组件,支持自定义触发器和默认属性\n *\n * @param actionComponent Custom trigger component | 自定义触发器组件\n * @param defaultProps Default properties of the confirm box | 确认弹框的默认属性\n */\nexport default function withConfirmAction<\n P extends ActionCompConstraint,\n OuterTriggerProp extends object,\n OuterEvent extends keyof OuterTriggerProp,\n Ref extends object,\n>(\n ActionComponent: ActionComponentInterface<P, Ref>,\n defaultProps?:\n | Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>>\n | ((\n actualProps: Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>\n ) => Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>>)\n) {\n return withConfirmActionInternal(\n ActionComponent,\n {\n confirmType: 'normal',\n },\n defaultProps\n );\n}\n\nexport function withConfirmActionInternal<\n P extends ActionCompConstraint,\n OuterTriggerProp extends object,\n OuterEvent extends keyof OuterTriggerProp,\n Ref extends object,\n>(\n ActionComponent: ActionComponentInterface<P, Ref>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n renderDefaultProps: Partial<ConfirmActionProps<any, never>> & { confirmType: 'normal' | 'delete' },\n defaultProps?:\n | Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>>\n | ((\n actualProps: Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>\n ) => Partial<Omit<P, keyof ActionCompConstraint> & ConfirmActionProps<OuterTriggerProp, OuterEvent>>)\n) {\n const ConfirmActionWithRef = forwardRef(genRenderer(renderDefaultProps));\n ConfirmActionWithRef.displayName = 'ForwardRef(ConfirmAction)';\n\n const WrappedActionComponent = forwardRef<Ref, ConfirmActionProps<OuterTriggerProp, OuterEvent>>(\n (propsWithDefaults, ref) => {\n const actionRef = useRef<ConfirmActionRef>(null);\n const [customRef, setCustomRef] = useState<Ref | null>(null);\n const saveFuncRef = useRef<(...triggerEventArgs: any[]) => unknown | Promise<unknown>>(undefined);\n\n // Receive the onSave callback method passed by the form component\n const setOnOk: ActionCompConstraint['setOK'] = useCallback((handler) => {\n saveFuncRef.current = handler;\n }, []);\n const triggerOnOK = useCallback(async (...args: any[]) => {\n return saveFuncRef.current?.(...args);\n }, []);\n\n // Merge the default ref and custom ref and output to the parent component\n useImperativeHandle(ref, () => {\n return {\n ...actionRef.current,\n ...customRef,\n } as ConfirmActionRef<Ref>;\n }, [customRef]);\n\n // Render the default trigger DOM element, and pass it to the custom ActionComponent\n const triggerDom = (\n <ConfirmActionWithRef\n {...(propsWithDefaults as ConfirmActionProps<object, never>)}\n onOk={triggerOnOK}\n ref={actionRef}\n />\n );\n\n return (\n <ActionComponent\n {...(propsWithDefaults as P)}\n ref={isForwardRef(ActionComponent) ? setCustomRef : undefined}\n setOK={setOnOk}\n triggerDom={triggerDom}\n />\n );\n }\n );\n WrappedActionComponent.displayName = 'ConfirmAction(ActionComponent)';\n\n const withDefaults = withDefaultConfirmActionProps(\n WrappedActionComponent,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n defaultProps as any\n ) as unknown as ComponentType<\n Omit<ConfirmActionProps<OuterTriggerProp, OuterEvent>, 'triggerComponent'> & RefAttributes<ConfirmActionRef>\n >;\n // return withDefaults;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return addTriggers<P, OuterTriggerProp, OuterEvent, Ref>(withDefaults as any);\n}\n\n/**\n * - **EN:** Add trigger types to the ModalAction component\n * - **CN:** 给ModalAction组件添加子触发器类型\n */\nfunction addTriggers<\n P extends ActionCompConstraint,\n OuterTriggerProp extends object,\n OuterEvent extends keyof OuterTriggerProp,\n Ref extends object,\n>(comp: ComponentType<ConfirmActionProps<OuterTriggerProp, OuterEvent> & RefAttributes<ConfirmActionRef<Ref>>>) {\n const patchedComp = comp as unknown as WithGenericTriggers<P, Ref>;\n // Type of button trigger\n patchedComp.Button = withDefaultConfirmActionProps<P, ButtonProps, 'onClick', Ref>(\n // @ts-expect-error: because the type is a little bit complex, so we ignore the type error here\n comp,\n {\n triggerComponent: Button,\n triggerEvent: 'onClick',\n triggerProps: {},\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ) as any;\n // Type of switch trigger\n patchedComp.Switch = withDefaultConfirmActionProps<P, SwitchProps, 'onChange', Ref>(\n // @ts-expect-error: because the type is a little bit complex, so we ignore the type error here\n comp,\n {\n triggerComponent: Switch,\n triggerEvent: 'onChange',\n triggerProps: {},\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ) as any;\n // Type of link trigger\n patchedComp.Link = withDefaultConfirmActionProps<P, LinkProps, 'onClick', Ref>(\n // @ts-expect-error: because the type is a little bit complex, so we ignore the type error here\n comp,\n {\n triggerComponent: Typography.Link,\n triggerEvent: 'onClick',\n triggerProps: {\n style: { whiteSpace: 'nowrap' },\n },\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ) as any;\n return patchedComp;\n}\n\n/**\n * - **EN:** ModalAction component type\n * - **CN:** ModalAction组件的类型\n */\nexport type ActionComponentInterface<P extends ActionCompConstraint, Ref extends object> = ComponentType<\n P & RefAttributes<ConfirmActionRef<Ref>>\n>;\n\ntype WithGenericTriggers<P extends ActionCompConstraint, Ref extends object> = (<\n TriggerProp extends object,\n Event extends keyof TriggerProp,\n>(\n props: PropsWithoutRef<Omit<P, keyof ActionCompConstraint>> &\n ConfirmActionProps<TriggerProp, Event> &\n RefAttributes<ConfirmActionRef<Ref>>\n) => ReactNode) &\n TypedTriggers<P, Ref>;\n\n/**\n * - **EN:** Built-in trigger types (specified form components)\n * - **CN:** 内置的几种触发器类型(已指定表单组件)\n */\nexport interface TypedTriggers<P extends ActionCompConstraint, Ref extends object> {\n /**\n * - **EN:** Dialog with button type trigger\n * - **CN:** 按钮类型的弹窗\n */\n Button: ConfirmActionWithTrigger<P, ButtonProps, 'onClick', Ref>;\n /**\n * - **EN:** Dialog with switch type trigger\n * - **CN:** 开关类型的弹窗\n */\n Switch: ConfirmActionWithTrigger<P, SwitchProps, 'onChange', Ref>;\n /**\n * - **EN:** Dialog with link type trigger\n * - **CN:** 链接类型的弹窗\n */\n Link: ConfirmActionWithTrigger<P, LinkProps, 'onClick', Ref>;\n}\n\n/**\n * - **EN:** ModalAction with specified trigger type (specified form component)\n * - **CN:** 已指定Trigger类型的ModalAction(并且已指定表单组件)\n */\ntype ConfirmActionWithTrigger<\n P extends ActionCompConstraint,\n TriggerProp extends object,\n Event extends keyof TriggerProp,\n Ref extends object,\n OMIT extends string = never,\n> = ComponentType<\n Omit<\n PropsWithoutRef<Omit<P, keyof ActionCompConstraint>> & ConfirmActionProps<TriggerProp, Event>,\n 'triggerComponent' | 'triggerEvent' | OMIT\n > &\n RefAttributes<ConfirmActionRef<Ref>>\n>;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAA+E;AAE/E,eAA2D;AAC3D,kBAA+E;AAE/E,sBAA6B;AASd,SAAR,kBAML,iBACA,cAKA;AACA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,MACE,aAAa;AAAA,IACf;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,0BAMd,iBAEA,oBACA,cAKA;AACA,QAAM,2BAAuB,6BAAW,sBAAY,kBAAkB,CAAC;AACvE,uBAAqB,cAAc;AAEnC,QAAM,6BAAyB;AAAA,IAC7B,CAAC,mBAAmB,QAAQ;AAC1B,YAAM,gBAAY,qBAAyB,IAAI;AAC/C,YAAM,CAAC,WAAW,YAAY,QAAI,uBAAqB,IAAI;AAC3D,YAAM,kBAAc,qBAAmE,MAAS;AAGhG,YAAM,cAAyC,0BAAY,CAAC,YAAY;AACtE,oBAAY,UAAU;AAAA,MACxB,GAAG,CAAC,CAAC;AACL,YAAM,kBAAc,0BAAY,UAAU,SAAgB;AAjEhE;AAkEQ,gBAAO,iBAAY,YAAZ,qCAAsB,GAAG;AAAA,MAClC,GAAG,CAAC,CAAC;AAGL,4CAAoB,KAAK,MAAM;AAC7B,eAAO;AAAA,UACL,GAAG,UAAU;AAAA,UACb,GAAG;AAAA,QACL;AAAA,MACF,GAAG,CAAC,SAAS,CAAC;AAGd,YAAM,aACJ;AAAA,QAAC;AAAA;AAAA,UACE,GAAI;AAAA,UACL,MAAM;AAAA,UACN,KAAK;AAAA;AAAA,MACP;AAGF,aACE;AAAA,QAAC;AAAA;AAAA,UACE,GAAI;AAAA,UACL,SAAK,8BAAa,eAAe,IAAI,eAAe;AAAA,UACpD,OAAO;AAAA,UACP;AAAA;AAAA,MACF;AAAA,IAEJ;AAAA,EACF;AACA,yBAAuB,cAAc;AAErC,QAAM,mBAAe;AAAA,IACnB;AAAA;AAAA,IAEA;AAAA,EACF;AAKA,SAAO,YAAkD,YAAmB;AAC9E;AAMA,SAAS,YAKP,MAA8G;AAC9G,QAAM,cAAc;AAEpB,cAAY,aAAS;AAAA;AAAA,IAEnB;AAAA,IACA;AAAA,MACE,kBAAkB;AAAA,MAClB,cAAc;AAAA,MACd,cAAc,CAAC;AAAA,IACjB;AAAA;AAAA,EAEF;AAEA,cAAY,aAAS;AAAA;AAAA,IAEnB;AAAA,IACA;AAAA,MACE,kBAAkB;AAAA,MAClB,cAAc;AAAA,MACd,cAAc,CAAC;AAAA,IACjB;AAAA;AAAA,EAEF;AAEA,cAAY,WAAO;AAAA;AAAA,IAEjB;AAAA,IACA;AAAA,MACE,kBAAkB,uBAAW;AAAA,MAC7B,cAAc;AAAA,MACd,cAAc;AAAA,QACZ,OAAO,EAAE,YAAY,SAAS;AAAA,MAChC;AAAA,IACF;AAAA;AAAA,EAEF;AACA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { CSSProperties, HtmlHTMLAttributes } from 'react';
|
|
2
|
+
import type { LexicalEditor, LexicalNode } from 'lexical';
|
|
3
|
+
/**
|
|
4
|
+
* 将节点插入到当前光标位置
|
|
5
|
+
*
|
|
6
|
+
* @param editor LexicalEditor 实例
|
|
7
|
+
* @param node 要插入的节点
|
|
8
|
+
*/
|
|
9
|
+
export declare function insertNodeAtCursor(editor: LexicalEditor, node: LexicalNode): void;
|
|
10
|
+
/**
|
|
11
|
+
* 将文本插入到当前光标位置
|
|
12
|
+
*
|
|
13
|
+
* @param editor LexicalEditor 实例
|
|
14
|
+
* @param text 要插入的文本
|
|
15
|
+
*/
|
|
16
|
+
export declare function insertTextAtCursor(editor: LexicalEditor, text: string): void;
|
|
17
|
+
/**
|
|
18
|
+
* 清空编辑器内容
|
|
19
|
+
*
|
|
20
|
+
* @param editor LexicalEditor 实例
|
|
21
|
+
*/
|
|
22
|
+
export declare function clearEditorContent(editor: LexicalEditor): void;
|
|
23
|
+
/**
|
|
24
|
+
* 查找符合条件的节点
|
|
25
|
+
*
|
|
26
|
+
* @param editor LexicalEditor 实例
|
|
27
|
+
* @param predicate 用于匹配节点的函数
|
|
28
|
+
* @param options 选项
|
|
29
|
+
*
|
|
30
|
+
* @returns 符合条件的节点数组
|
|
31
|
+
*/
|
|
32
|
+
export declare function findNode<T extends LexicalNode>(editor: LexicalEditor, predicate: (node: LexicalNode) => boolean): T | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* 查找所有符合条件的节点数组
|
|
35
|
+
*
|
|
36
|
+
* @param editor LexicalEditor 实例
|
|
37
|
+
* @param predicate 用于匹配节点的函数
|
|
38
|
+
* @param options 选项
|
|
39
|
+
*
|
|
40
|
+
* @returns 符合条件的节点数组
|
|
41
|
+
*/
|
|
42
|
+
export declare function findNodes<T extends LexicalNode>(editor: LexicalEditor, predicate: (node: LexicalNode) => boolean, options?: {
|
|
43
|
+
stopOnFirstMatch?: boolean;
|
|
44
|
+
}): T[];
|
|
45
|
+
/**
|
|
46
|
+
* 更新 DOM 元素的属性
|
|
47
|
+
*
|
|
48
|
+
* @param dom 要更新的 DOM 元素
|
|
49
|
+
* @param props 要设置的属性
|
|
50
|
+
*/
|
|
51
|
+
export declare function updateDomProps(dom: HTMLElement | undefined, props: HtmlHTMLAttributes<HTMLElement>): void;
|
|
52
|
+
/**
|
|
53
|
+
* 更新 DOM 元素的样式
|
|
54
|
+
*
|
|
55
|
+
* @param dom 要更新的 DOM 元素
|
|
56
|
+
* @param style 要设置的样式
|
|
57
|
+
*/
|
|
58
|
+
export declare function updateDomStyle(dom: HTMLElement | undefined, style: CSSProperties | undefined): void;
|
|
@@ -0,0 +1,198 @@
|
|
|
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
|
+
insertNodeAtCursor: () => insertNodeAtCursor,
|
|
26
|
+
insertTextAtCursor: () => insertTextAtCursor,
|
|
27
|
+
updateDomProps: () => updateDomProps,
|
|
28
|
+
updateDomStyle: () => updateDomStyle
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(helpers_exports);
|
|
31
|
+
var import_lexical = require("lexical");
|
|
32
|
+
var import_DivNode = require("../nodes/DivNode");
|
|
33
|
+
function insertNodeAtCursor(editor, node) {
|
|
34
|
+
editor.update(() => {
|
|
35
|
+
const selection = (0, import_lexical.$getSelection)();
|
|
36
|
+
if (selection) {
|
|
37
|
+
if ((0, import_lexical.$isRangeSelection)(selection)) {
|
|
38
|
+
const lastNode = selection.focus.getNode();
|
|
39
|
+
if (lastNode) {
|
|
40
|
+
if ((0, import_lexical.$isParagraphNode)(lastNode)) {
|
|
41
|
+
lastNode.append(node);
|
|
42
|
+
} else if ((0, import_lexical.$isTextNode)(lastNode)) {
|
|
43
|
+
lastNode.insertAfter(node);
|
|
44
|
+
} else if ((0, import_DivNode.$isDivNode)(lastNode)) {
|
|
45
|
+
lastNode.append(node);
|
|
46
|
+
} else {
|
|
47
|
+
selection.insertNodes([node]);
|
|
48
|
+
}
|
|
49
|
+
node.selectNext();
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
selection.insertNodes([node]);
|
|
53
|
+
node.selectNext();
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
const root = (0, import_lexical.$getRoot)();
|
|
57
|
+
let nodeToInsert = node;
|
|
58
|
+
if ((0, import_lexical.$isElementNode)(node) || (0, import_lexical.$isDecoratorNode)(node)) {
|
|
59
|
+
nodeToInsert = node;
|
|
60
|
+
} else {
|
|
61
|
+
const container = (0, import_DivNode.$createDivNode)({
|
|
62
|
+
style: { display: "inline-block" }
|
|
63
|
+
});
|
|
64
|
+
container.append(node);
|
|
65
|
+
nodeToInsert = container;
|
|
66
|
+
}
|
|
67
|
+
root.append(nodeToInsert);
|
|
68
|
+
node.selectNext();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function insertTextAtCursor(editor, text) {
|
|
73
|
+
editor == null ? void 0 : editor.update(() => {
|
|
74
|
+
const textNode = (0, import_lexical.$createTextNode)(text);
|
|
75
|
+
const root = (0, import_lexical.$getRoot)();
|
|
76
|
+
const selection = (0, import_lexical.$getSelection)();
|
|
77
|
+
if (selection) {
|
|
78
|
+
selection.insertText(text);
|
|
79
|
+
} else {
|
|
80
|
+
const lastNode = root.getLastChild();
|
|
81
|
+
if (lastNode && (0, import_lexical.$isParagraphNode)(lastNode)) {
|
|
82
|
+
lastNode.append(textNode);
|
|
83
|
+
} else {
|
|
84
|
+
const container = (0, import_DivNode.$createDivNode)({
|
|
85
|
+
style: { display: "inline-block" }
|
|
86
|
+
});
|
|
87
|
+
container.append(textNode);
|
|
88
|
+
root.append(container);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
function clearEditorContent(editor) {
|
|
94
|
+
const state = editor.getEditorState();
|
|
95
|
+
const stateJson = state.toJSON();
|
|
96
|
+
const newJson = {
|
|
97
|
+
...stateJson,
|
|
98
|
+
root: {
|
|
99
|
+
...stateJson.root,
|
|
100
|
+
children: [
|
|
101
|
+
{
|
|
102
|
+
children: [],
|
|
103
|
+
direction: null,
|
|
104
|
+
format: "",
|
|
105
|
+
indent: 0,
|
|
106
|
+
type: "paragraph",
|
|
107
|
+
version: 1,
|
|
108
|
+
textFormat: 0,
|
|
109
|
+
textStyle: ""
|
|
110
|
+
}
|
|
111
|
+
]
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const emptyState = editor.parseEditorState(JSON.stringify(newJson));
|
|
115
|
+
editor.setEditorState(emptyState);
|
|
116
|
+
editor.update(() => {
|
|
117
|
+
const root = (0, import_lexical.$getRoot)();
|
|
118
|
+
root.clear();
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function findNode(editor, predicate) {
|
|
122
|
+
const matched = findNodes(editor, predicate, { stopOnFirstMatch: true });
|
|
123
|
+
return matched[0];
|
|
124
|
+
}
|
|
125
|
+
function findNodes(editor, predicate, options) {
|
|
126
|
+
const matched = [];
|
|
127
|
+
editor.getEditorState().read(() => {
|
|
128
|
+
const root = (0, import_lexical.$getRoot)();
|
|
129
|
+
const traverse = (node, result) => {
|
|
130
|
+
if (predicate(node)) {
|
|
131
|
+
result.push(node);
|
|
132
|
+
if (options == null ? void 0 : options.stopOnFirstMatch) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if ((0, import_lexical.$isElementNode)(node)) {
|
|
137
|
+
const children = node.getChildren();
|
|
138
|
+
for (const child of children) {
|
|
139
|
+
traverse(child, result);
|
|
140
|
+
if ((options == null ? void 0 : options.stopOnFirstMatch) && result.length > 0) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
traverse(root, matched);
|
|
147
|
+
});
|
|
148
|
+
return matched;
|
|
149
|
+
}
|
|
150
|
+
function updateDomProps(dom, props) {
|
|
151
|
+
if (!dom)
|
|
152
|
+
return;
|
|
153
|
+
Array.from(dom.attributes).forEach((attr) => {
|
|
154
|
+
if (!attr.name.startsWith("data-lexical")) {
|
|
155
|
+
dom.removeAttribute(attr.name);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
dom.removeAttribute("style");
|
|
159
|
+
dom.removeAttribute("class");
|
|
160
|
+
if (props) {
|
|
161
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
162
|
+
if (key === "style" && value) {
|
|
163
|
+
Object.entries(value).forEach(([styleKey, styleValue]) => {
|
|
164
|
+
if (styleValue !== void 0) {
|
|
165
|
+
dom.style[styleKey] = styleValue;
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
} else if (key === "className" && value) {
|
|
169
|
+
dom.className = value;
|
|
170
|
+
} else if (value !== void 0 && value !== null) {
|
|
171
|
+
dom.setAttribute(key, value.toString());
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function updateDomStyle(dom, style) {
|
|
177
|
+
if (!dom)
|
|
178
|
+
return;
|
|
179
|
+
dom.removeAttribute("style");
|
|
180
|
+
if (style) {
|
|
181
|
+
Object.entries(style).forEach(([styleKey, styleValue]) => {
|
|
182
|
+
if (styleValue !== void 0) {
|
|
183
|
+
dom.style[styleKey] = styleValue;
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
189
|
+
0 && (module.exports = {
|
|
190
|
+
clearEditorContent,
|
|
191
|
+
findNode,
|
|
192
|
+
findNodes,
|
|
193
|
+
insertNodeAtCursor,
|
|
194
|
+
insertTextAtCursor,
|
|
195
|
+
updateDomProps,
|
|
196
|
+
updateDomStyle
|
|
197
|
+
});
|
|
198
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/components/Lexical/helpers/index.ts"],
|
|
4
|
+
"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 * 将节点插入到当前光标位置\n *\n * @param editor LexicalEditor 实例\n * @param node 要插入的节点\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 * 将文本插入到当前光标位置\n *\n * @param editor LexicalEditor 实例\n * @param text 要插入的文本\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 * 清空编辑器内容\n *\n * @param editor 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 * 查找符合条件的节点\n *\n * @param editor LexicalEditor 实例\n * @param predicate 用于匹配节点的函数\n * @param options 选项\n *\n * @returns 符合条件的节点数组\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 * 查找所有符合条件的节点数组\n *\n * @param editor LexicalEditor 实例\n * @param predicate 用于匹配节点的函数\n * @param options 选项\n *\n * @returns 符合条件的节点数组\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 * 更新 DOM 元素的属性\n *\n * @param dom 要更新的 DOM 元素\n * @param props 要设置的属性\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 * 更新 DOM 元素的样式\n *\n * @param dom 要更新的 DOM 元素\n * @param style 要设置的样式\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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA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