@tiny-codes/react-easy 1.3.1 → 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 +8 -0
- 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/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,87 @@
|
|
|
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/nodes/ExtendTextNode.tsx
|
|
20
|
+
var ExtendTextNode_exports = {};
|
|
21
|
+
__export(ExtendTextNode_exports, {
|
|
22
|
+
$createExtendTextNode: () => $createExtendTextNode,
|
|
23
|
+
$isExtendTextNode: () => $isExtendTextNode,
|
|
24
|
+
ExtendTextNode: () => ExtendTextNode
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(ExtendTextNode_exports);
|
|
27
|
+
var import_lexical = require("lexical");
|
|
28
|
+
var import_base = require("./base");
|
|
29
|
+
var ExtendTextNode = class extends import_lexical.TextNode {
|
|
30
|
+
constructor(props) {
|
|
31
|
+
const { key, ...restProps } = props || {};
|
|
32
|
+
super(props == null ? void 0 : props.text, key);
|
|
33
|
+
this.__props = restProps;
|
|
34
|
+
this.__base = new import_base.BaseNodeHelper(this.__props, {
|
|
35
|
+
remove: () => super.remove(),
|
|
36
|
+
replace: (replaceWith, includeChildren) => super.replace(replaceWith, includeChildren)
|
|
37
|
+
});
|
|
38
|
+
Object.keys(this.__base.hooks).forEach((key2) => {
|
|
39
|
+
const method = this.__base.hooks[key2];
|
|
40
|
+
if (typeof method === "function") {
|
|
41
|
+
this[key2] = method.bind(this.__base);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
this.replace = (replaceWith, includeChildren) => {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
if (((_a = this.__props) == null ? void 0 : _a.canBeReplaced) === false) {
|
|
47
|
+
this.setTextContent(((_b = this.__props) == null ? void 0 : _b.text) || "");
|
|
48
|
+
this.selectNext();
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
return super.replace(replaceWith, includeChildren);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
static getType() {
|
|
55
|
+
return "html.TextNode";
|
|
56
|
+
}
|
|
57
|
+
static clone(node) {
|
|
58
|
+
return new ExtendTextNode({ ...node.__props, text: node.__text, key: node.getKey() });
|
|
59
|
+
}
|
|
60
|
+
static importJSON(serializedNode) {
|
|
61
|
+
return $createExtendTextNode({
|
|
62
|
+
...serializedNode.props,
|
|
63
|
+
text: serializedNode.text
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
exportJSON() {
|
|
67
|
+
return {
|
|
68
|
+
...super.exportJSON(),
|
|
69
|
+
props: this.__props,
|
|
70
|
+
text: this.__text,
|
|
71
|
+
type: this.getType()
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
function $createExtendTextNode(props) {
|
|
76
|
+
return new ExtendTextNode(props);
|
|
77
|
+
}
|
|
78
|
+
function $isExtendTextNode(node) {
|
|
79
|
+
return node instanceof ExtendTextNode;
|
|
80
|
+
}
|
|
81
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
82
|
+
0 && (module.exports = {
|
|
83
|
+
$createExtendTextNode,
|
|
84
|
+
$isExtendTextNode,
|
|
85
|
+
ExtendTextNode
|
|
86
|
+
});
|
|
87
|
+
//# sourceMappingURL=ExtendTextNode.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/components/Lexical/nodes/ExtendTextNode.tsx"],
|
|
4
|
+
"sourcesContent": ["import type { LexicalNode, NodeKey, SerializedTextNode, Spread } from 'lexical';\nimport { TextNode } from 'lexical';\nimport type { BaseNodeProps } from './base';\nimport { BaseNodeHelper } from './base';\n\nexport interface ExtendTextNodeProps extends BaseNodeProps {\n text?: string;\n}\n\nexport class ExtendTextNode extends TextNode {\n __props: ExtendTextNodeProps | undefined;\n __base: BaseNodeHelper<ExtendTextNodeProps>;\n\n constructor(props?: ExtendTextNodeProps & { key?: NodeKey }) {\n const { key, ...restProps } = props || {};\n super(props?.text, key);\n this.__props = restProps;\n this.__base = new BaseNodeHelper<ExtendTextNodeProps>(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 this.replace = <N extends LexicalNode>(replaceWith: N, includeChildren?: boolean): N => {\n if (this.__props?.canBeReplaced === false) {\n this.setTextContent(this.__props?.text || '');\n this.selectNext();\n return this as unknown as N;\n }\n return super.replace(replaceWith, includeChildren);\n };\n }\n\n static getType(): string {\n return 'html.TextNode';\n }\n\n static clone(node: ExtendTextNode): ExtendTextNode {\n return new ExtendTextNode({ ...node.__props, text: node.__text, key: node.getKey() });\n }\n\n static importJSON(serializedNode: SerializedExtendTextNode): ExtendTextNode {\n return $createExtendTextNode({\n ...serializedNode.props,\n text: serializedNode.text,\n });\n }\n\n exportJSON(): SerializedExtendTextNode {\n return {\n ...super.exportJSON(),\n props: this.__props,\n text: this.__text,\n type: this.getType(),\n };\n }\n}\n\nexport type SerializedExtendTextNode = Spread<\n {\n props?: ExtendTextNodeProps;\n text: string;\n },\n SerializedTextNode\n>;\n\nexport function $createExtendTextNode(props?: ExtendTextNodeProps): ExtendTextNode {\n return new ExtendTextNode(props);\n}\n\nexport function $isExtendTextNode(node: LexicalNode | null | undefined): node is ExtendTextNode {\n return node instanceof ExtendTextNode;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAAyB;AAEzB,kBAA+B;AAMxB,IAAM,iBAAN,cAA6B,wBAAS;AAAA,EAI3C,YAAY,OAAiD;AAC3D,UAAM,EAAE,KAAK,GAAG,UAAU,IAAI,SAAS,CAAC;AACxC,UAAM,+BAAO,MAAM,GAAG;AACtB,SAAK,UAAU;AACf,SAAK,SAAS,IAAI,2BAAoC,KAAK,SAAS;AAAA,MAClE,QAAQ,MAAM,MAAM,OAAO;AAAA,MAC3B,SAAS,CAAC,aAAa,oBAAoB,MAAM,QAAQ,aAAa,eAAe;AAAA,IACvF,CAAC;AACD,WAAO,KAAK,KAAK,OAAO,KAAK,EAAE,QAAQ,CAACA,SAAQ;AAC9C,YAAM,SAAS,KAAK,OAAO,MAAMA,IAAqC;AACtE,UAAI,OAAO,WAAW,YAAY;AAEhC,aAAKA,IAAiB,IAAI,OAAO,KAAK,KAAK,MAAM;AAAA,MACnD;AAAA,IACF,CAAC;AACD,SAAK,UAAU,CAAwB,aAAgB,oBAAiC;AA5B5F;AA6BM,YAAI,UAAK,YAAL,mBAAc,mBAAkB,OAAO;AACzC,aAAK,iBAAe,UAAK,YAAL,mBAAc,SAAQ,EAAE;AAC5C,aAAK,WAAW;AAChB,eAAO;AAAA,MACT;AACA,aAAO,MAAM,QAAQ,aAAa,eAAe;AAAA,IACnD;AAAA,EACF;AAAA,EAEA,OAAO,UAAkB;AACvB,WAAO;AAAA,EACT;AAAA,EAEA,OAAO,MAAM,MAAsC;AACjD,WAAO,IAAI,eAAe,EAAE,GAAG,KAAK,SAAS,MAAM,KAAK,QAAQ,KAAK,KAAK,OAAO,EAAE,CAAC;AAAA,EACtF;AAAA,EAEA,OAAO,WAAW,gBAA0D;AAC1E,WAAO,sBAAsB;AAAA,MAC3B,GAAG,eAAe;AAAA,MAClB,MAAM,eAAe;AAAA,IACvB,CAAC;AAAA,EACH;AAAA,EAEA,aAAuC;AACrC,WAAO;AAAA,MACL,GAAG,MAAM,WAAW;AAAA,MACpB,OAAO,KAAK;AAAA,MACZ,MAAM,KAAK;AAAA,MACX,MAAM,KAAK,QAAQ;AAAA,IACrB;AAAA,EACF;AACF;AAUO,SAAS,sBAAsB,OAA6C;AACjF,SAAO,IAAI,eAAe,KAAK;AACjC;AAEO,SAAS,kBAAkB,MAA8D;AAC9F,SAAO,gBAAgB;AACzB;",
|
|
6
|
+
"names": ["key"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
|
+
import type { SelectProps } from 'antd';
|
|
3
|
+
import type { BaseOptionType, DefaultOptionType } from 'antd/es/select';
|
|
4
|
+
import type { LexicalEditor, LexicalNode, SerializedLexicalNode, Spread } from 'lexical';
|
|
5
|
+
import type { BaseDecoratorNodeProps } from './base';
|
|
6
|
+
import { BaseDecoratorNode } from './base';
|
|
7
|
+
export interface SelectNodeProps<ValueType = any, OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType> extends SelectProps<ValueType, OptionType>, BaseDecoratorNodeProps {
|
|
8
|
+
/**
|
|
9
|
+
* 在获取editor的textContent时,是否将选项的label作为文本内容插入到编辑器中,默认 `value`
|
|
10
|
+
*
|
|
11
|
+
* - `label` - 将选项的label作为文本内容
|
|
12
|
+
* - `value` - 将选项的value作为文本内容
|
|
13
|
+
*/
|
|
14
|
+
textContentMode?: 'label' | 'value';
|
|
15
|
+
/** 是否在`textContext`两边添加一个空格,默认`true` */
|
|
16
|
+
spaceAround?: boolean;
|
|
17
|
+
/** 容器样式 */
|
|
18
|
+
containerStyle?: CSSProperties;
|
|
19
|
+
}
|
|
20
|
+
export declare class SelectNode<ValueType = any, OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType> extends BaseDecoratorNode<ReactNode, SelectNodeProps<ValueType, OptionType>> {
|
|
21
|
+
__value: ValueType | undefined;
|
|
22
|
+
constructor(props?: SelectNodeProps<ValueType, OptionType> & {
|
|
23
|
+
key?: string;
|
|
24
|
+
});
|
|
25
|
+
static getType(): string;
|
|
26
|
+
static clone<ValueType = any, OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType>(node: SelectNode<ValueType, OptionType>): SelectNode<ValueType, OptionType>;
|
|
27
|
+
static importJSON<ValueType = any, OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType>(serializedNode: SerializedSelectNode<ValueType, OptionType>): SelectNode<ValueType, OptionType>;
|
|
28
|
+
exportJSON(): SerializedSelectNode<ValueType, OptionType>;
|
|
29
|
+
createDOM(): HTMLElement;
|
|
30
|
+
updateDOM(): false;
|
|
31
|
+
decorate(): ReactNode;
|
|
32
|
+
isInline(): boolean;
|
|
33
|
+
getTextContent(): string;
|
|
34
|
+
getValue(): ValueType | undefined;
|
|
35
|
+
setValue(value: ValueType | undefined): void;
|
|
36
|
+
getPropValue(propName: keyof SelectNodeProps<ValueType, OptionType>): any;
|
|
37
|
+
setProps(props: SelectNodeProps<ValueType, OptionType>): void;
|
|
38
|
+
}
|
|
39
|
+
export declare function $createSelectNode<ValueType = any, OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType>(props?: SelectNodeProps<ValueType, OptionType>): SelectNode<ValueType, OptionType>;
|
|
40
|
+
export declare function $isSelectNode(node: LexicalNode | null | undefined): node is SelectNode<any, any>;
|
|
41
|
+
export declare function $insertSelectNode<ValueType = any, OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType>(editor: LexicalEditor, props: SelectNodeProps<ValueType, OptionType>): void;
|
|
42
|
+
export type SerializedSelectNode<ValueType = any, OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType> = Spread<{
|
|
43
|
+
props?: SelectNodeProps<ValueType, OptionType>;
|
|
44
|
+
}, SerializedLexicalNode>;
|
|
@@ -0,0 +1,157 @@
|
|
|
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/nodes/SelectNode.tsx
|
|
20
|
+
var SelectNode_exports = {};
|
|
21
|
+
__export(SelectNode_exports, {
|
|
22
|
+
$createSelectNode: () => $createSelectNode,
|
|
23
|
+
$insertSelectNode: () => $insertSelectNode,
|
|
24
|
+
$isSelectNode: () => $isSelectNode,
|
|
25
|
+
SelectNode: () => SelectNode
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(SelectNode_exports);
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
var import_LexicalComposerContext = require("@lexical/react/LexicalComposerContext");
|
|
30
|
+
var import_antd = require("antd");
|
|
31
|
+
var import_helpers = require("../helpers");
|
|
32
|
+
var import_base = require("./base");
|
|
33
|
+
var SelectNode = class extends import_base.BaseDecoratorNode {
|
|
34
|
+
constructor(props) {
|
|
35
|
+
super(props);
|
|
36
|
+
this.__value = (props == null ? void 0 : props.defaultValue) ?? void 0;
|
|
37
|
+
}
|
|
38
|
+
static getType() {
|
|
39
|
+
return "antd.Select";
|
|
40
|
+
}
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
|
+
static clone(node) {
|
|
43
|
+
return new SelectNode({ ...node.__props, key: node.getKey() });
|
|
44
|
+
}
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
+
static importJSON(serializedNode) {
|
|
47
|
+
return $createSelectNode(serializedNode.props);
|
|
48
|
+
}
|
|
49
|
+
exportJSON() {
|
|
50
|
+
return {
|
|
51
|
+
...super.exportJSON(),
|
|
52
|
+
props: this.__props,
|
|
53
|
+
type: this.getType(),
|
|
54
|
+
version: 1
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
createDOM() {
|
|
58
|
+
var _a;
|
|
59
|
+
const span = document.createElement("span");
|
|
60
|
+
(0, import_helpers.updateDomStyle)(span, (_a = this.__props) == null ? void 0 : _a.containerStyle);
|
|
61
|
+
return span;
|
|
62
|
+
}
|
|
63
|
+
updateDOM() {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
decorate() {
|
|
67
|
+
return /* @__PURE__ */ React.createElement(SelectComponent, { node: this });
|
|
68
|
+
}
|
|
69
|
+
isInline() {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
getTextContent() {
|
|
73
|
+
var _a, _b, _c, _d;
|
|
74
|
+
let content;
|
|
75
|
+
const valueContent = this.__value ? String(this.__value) : "";
|
|
76
|
+
if (((_a = this.__props) == null ? void 0 : _a.textContentMode) === "label") {
|
|
77
|
+
const option = (_c = (_b = this.__props) == null ? void 0 : _b.options) == null ? void 0 : _c.find((opt) => opt.value === this.__value);
|
|
78
|
+
content = (option == null ? void 0 : option.label) ? String(option.label) : valueContent;
|
|
79
|
+
} else {
|
|
80
|
+
content = valueContent;
|
|
81
|
+
}
|
|
82
|
+
if (((_d = this.__props) == null ? void 0 : _d.spaceAround) !== false) {
|
|
83
|
+
return ` ${content} `;
|
|
84
|
+
}
|
|
85
|
+
return content;
|
|
86
|
+
}
|
|
87
|
+
getValue() {
|
|
88
|
+
return this.__value;
|
|
89
|
+
}
|
|
90
|
+
setValue(value) {
|
|
91
|
+
const writable = this.getWritable();
|
|
92
|
+
writable.__value = value;
|
|
93
|
+
}
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
95
|
+
getPropValue(propName) {
|
|
96
|
+
var _a;
|
|
97
|
+
return (_a = this.__props) == null ? void 0 : _a[propName];
|
|
98
|
+
}
|
|
99
|
+
setProps(props) {
|
|
100
|
+
const writable = this.getWritable();
|
|
101
|
+
writable.__props = {
|
|
102
|
+
...writable.__props,
|
|
103
|
+
...props
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
function SelectComponent({
|
|
108
|
+
node
|
|
109
|
+
}) {
|
|
110
|
+
const { textContentMode, spaceAround, containerStyle, ...selectProps } = node.__props || {};
|
|
111
|
+
const [editor] = (0, import_LexicalComposerContext.useLexicalComposerContext)();
|
|
112
|
+
const handleChange = (0, import_react.useCallback)(
|
|
113
|
+
(value, options) => {
|
|
114
|
+
editor.update(() => {
|
|
115
|
+
var _a, _b;
|
|
116
|
+
node.setValue(value);
|
|
117
|
+
(_b = (_a = node.__props) == null ? void 0 : _a.onChange) == null ? void 0 : _b.call(_a, value, options);
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
[editor, node]
|
|
121
|
+
);
|
|
122
|
+
const handleClear = (0, import_react.useCallback)(() => {
|
|
123
|
+
editor.update(() => {
|
|
124
|
+
var _a, _b;
|
|
125
|
+
node.setValue(void 0);
|
|
126
|
+
(_b = (_a = node.__props) == null ? void 0 : _a.onClear) == null ? void 0 : _b.call(_a);
|
|
127
|
+
});
|
|
128
|
+
}, [editor, node]);
|
|
129
|
+
return /* @__PURE__ */ React.createElement(import_antd.Select, { ...selectProps, value: node.getValue(), onChange: handleChange, onClear: handleClear });
|
|
130
|
+
}
|
|
131
|
+
function $createSelectNode(props) {
|
|
132
|
+
return new SelectNode(props);
|
|
133
|
+
}
|
|
134
|
+
function $isSelectNode(node) {
|
|
135
|
+
return node instanceof SelectNode;
|
|
136
|
+
}
|
|
137
|
+
function $insertSelectNode(editor, props) {
|
|
138
|
+
editor.update(() => {
|
|
139
|
+
const selectNode = $createSelectNode({
|
|
140
|
+
...props,
|
|
141
|
+
containerStyle: {
|
|
142
|
+
paddingLeft: "8px",
|
|
143
|
+
paddingRight: "8px",
|
|
144
|
+
...props.containerStyle
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
(0, import_helpers.insertNodeAtCursor)(editor, selectNode);
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
151
|
+
0 && (module.exports = {
|
|
152
|
+
$createSelectNode,
|
|
153
|
+
$insertSelectNode,
|
|
154
|
+
$isSelectNode,
|
|
155
|
+
SelectNode
|
|
156
|
+
});
|
|
157
|
+
//# sourceMappingURL=SelectNode.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/components/Lexical/nodes/SelectNode.tsx"],
|
|
4
|
+
"sourcesContent": ["import { type CSSProperties, type ReactNode, useCallback } from 'react';\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';\nimport { Select } from 'antd';\nimport type { SelectProps } from 'antd';\nimport type { BaseOptionType, DefaultOptionType } from 'antd/es/select';\nimport type { LexicalEditor, LexicalNode, SerializedLexicalNode, Spread } from 'lexical';\nimport { insertNodeAtCursor, updateDomStyle } from '../helpers';\nimport type { BaseDecoratorNodeProps } from './base';\nimport { BaseDecoratorNode } from './base';\n\nexport interface SelectNodeProps<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ValueType = any,\n OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType,\n> extends SelectProps<ValueType, OptionType>,\n BaseDecoratorNodeProps {\n /**\n * 在获取editor的textContent时,是否将选项的label作为文本内容插入到编辑器中,默认 `value`\n *\n * - `label` - 将选项的label作为文本内容\n * - `value` - 将选项的value作为文本内容\n */\n textContentMode?: 'label' | 'value';\n /** 是否在`textContext`两边添加一个空格,默认`true` */\n spaceAround?: boolean;\n /** 容器样式 */\n containerStyle?: CSSProperties;\n}\n\nexport class SelectNode<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ValueType = any,\n OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType,\n> extends BaseDecoratorNode<ReactNode, SelectNodeProps<ValueType, OptionType>> {\n __value: ValueType | undefined;\n\n constructor(props?: SelectNodeProps<ValueType, OptionType> & { key?: string }) {\n super(props);\n this.__value = props?.defaultValue ?? undefined;\n }\n static getType(): string {\n return 'antd.Select';\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n static clone<ValueType = any, OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType>(\n node: SelectNode<ValueType, OptionType>\n ): SelectNode<ValueType, OptionType> {\n return new SelectNode<ValueType, OptionType>({ ...node.__props, key: node.getKey() });\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n static importJSON<ValueType = any, OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType>(\n serializedNode: SerializedSelectNode<ValueType, OptionType>\n ): SelectNode<ValueType, OptionType> {\n return $createSelectNode(serializedNode.props);\n }\n\n exportJSON(): SerializedSelectNode<ValueType, OptionType> {\n return {\n ...super.exportJSON(),\n props: this.__props,\n type: this.getType(),\n version: 1,\n };\n }\n\n createDOM(): HTMLElement {\n const span = document.createElement('span');\n updateDomStyle(span, this.__props?.containerStyle);\n return span;\n }\n\n updateDOM(): false {\n return false;\n }\n\n decorate(): ReactNode {\n return <SelectComponent node={this} />;\n }\n\n isInline(): boolean {\n return true;\n }\n\n getTextContent(): string {\n let content: string;\n const valueContent = this.__value ? String(this.__value) : '';\n if (this.__props?.textContentMode === 'label') {\n const option = this.__props?.options?.find((opt) => opt.value === this.__value);\n content = option?.label ? String(option.label) : valueContent;\n } else {\n content = valueContent;\n }\n if (this.__props?.spaceAround !== false) {\n return ` ${content} `;\n }\n return content;\n }\n\n getValue(): ValueType | undefined {\n return this.__value;\n }\n\n setValue(value: ValueType | undefined): void {\n const writable = this.getWritable();\n writable.__value = value;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n getPropValue(propName: keyof SelectNodeProps<ValueType, OptionType>): any {\n return this.__props?.[propName];\n }\n\n setProps(props: SelectNodeProps<ValueType, OptionType>): void {\n const writable = this.getWritable();\n writable.__props = {\n ...writable.__props,\n ...props,\n };\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction SelectComponent<ValueType = any, OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType>({\n node,\n}: SelectComponentProps<ValueType, OptionType>): ReactNode {\n /* eslint-disable @typescript-eslint/no-unused-vars */\n const { textContentMode, spaceAround, containerStyle, ...selectProps } = node.__props || {};\n /* eslint-enable @typescript-eslint/no-unused-vars */\n const [editor] = useLexicalComposerContext();\n\n const handleChange = useCallback<NonNullable<SelectNodeProps<ValueType, OptionType>['onChange']>>(\n (value, options) => {\n editor.update(() => {\n node.setValue(value);\n node.__props?.onChange?.(value, options);\n });\n },\n [editor, node]\n );\n\n const handleClear = useCallback(() => {\n editor.update(() => {\n node.setValue(undefined);\n node.__props?.onClear?.();\n });\n }, [editor, node]);\n\n return <Select {...selectProps} value={node.getValue()} onChange={handleChange} onClear={handleClear} />;\n}\n\nexport function $createSelectNode<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ValueType = any,\n OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType,\n>(props?: SelectNodeProps<ValueType, OptionType>): SelectNode<ValueType, OptionType> {\n return new SelectNode<ValueType, OptionType>(props);\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function $isSelectNode(node: LexicalNode | null | undefined): node is SelectNode<any, any> {\n return node instanceof SelectNode;\n}\n\nexport function $insertSelectNode<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ValueType = any,\n OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType,\n>(editor: LexicalEditor, props: SelectNodeProps<ValueType, OptionType>): void {\n editor.update(() => {\n const selectNode = $createSelectNode<ValueType, OptionType>({\n ...props,\n containerStyle: {\n paddingLeft: '8px',\n paddingRight: '8px',\n ...props.containerStyle,\n },\n });\n insertNodeAtCursor(editor, selectNode);\n });\n}\n\ninterface SelectComponentProps<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ValueType = any,\n OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType,\n> {\n node: SelectNode<ValueType, OptionType>;\n}\nexport type SerializedSelectNode<\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ValueType = any,\n OptionType extends BaseOptionType | DefaultOptionType = DefaultOptionType,\n> = Spread<\n {\n props?: SelectNodeProps<ValueType, OptionType>;\n },\n SerializedLexicalNode\n>;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAgE;AAChE,oCAA0C;AAC1C,kBAAuB;AAIvB,qBAAmD;AAEnD,kBAA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AAa,kBAAyC;AAAA,MAC1D,GAAG;AAAA,MACH,gBAAgB;AAAA,QACd,aAAa;AAAA,QACb,cAAc;AAAA,QACd,GAAG,MAAM;AAAA,MACX;AAAA,IACF,CAAC;AACD,2CAAmB,QAAQ,UAAU;AAAA,EACvC,CAAC;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -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,116 @@
|
|
|
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/nodes/base.ts
|
|
20
|
+
var base_exports = {};
|
|
21
|
+
__export(base_exports, {
|
|
22
|
+
BaseDecoratorNode: () => BaseDecoratorNode,
|
|
23
|
+
BaseElementNode: () => BaseElementNode,
|
|
24
|
+
BaseNodeHelper: () => BaseNodeHelper
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(base_exports);
|
|
27
|
+
var import_lexical = require("lexical");
|
|
28
|
+
var BaseNodeHelper = class {
|
|
29
|
+
constructor(props, superMethods) {
|
|
30
|
+
this.hooks = {
|
|
31
|
+
remove: (preserveEmptyParent) => {
|
|
32
|
+
var _a;
|
|
33
|
+
if (((_a = this.__props) == null ? void 0 : _a.canBeRemoved) === false) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
this.__superMethods.remove(preserveEmptyParent);
|
|
37
|
+
},
|
|
38
|
+
replace: (replaceWith, includeChildren) => {
|
|
39
|
+
var _a;
|
|
40
|
+
if (((_a = this.__props) == null ? void 0 : _a.canBeReplaced) === false) {
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
return this.__superMethods.replace(replaceWith, includeChildren);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
this.__props = props;
|
|
47
|
+
this.__superMethods = superMethods;
|
|
48
|
+
}
|
|
49
|
+
getUnderlyingProps(props) {
|
|
50
|
+
const { canBeRemoved, canBeReplaced, ...restProps } = props;
|
|
51
|
+
return restProps;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var BaseElementNode = class extends import_lexical.ElementNode {
|
|
55
|
+
constructor(props) {
|
|
56
|
+
const { key, ...restProps } = props || {};
|
|
57
|
+
super(key);
|
|
58
|
+
this.__props = restProps;
|
|
59
|
+
this.__base = new BaseNodeHelper(this.__props, {
|
|
60
|
+
remove: () => super.remove(),
|
|
61
|
+
replace: (replaceWith, includeChildren) => super.replace(replaceWith, includeChildren)
|
|
62
|
+
});
|
|
63
|
+
Object.keys(this.__base.hooks).forEach((key2) => {
|
|
64
|
+
const method = this.__base.hooks[key2];
|
|
65
|
+
if (typeof method === "function") {
|
|
66
|
+
this[key2] = method.bind(this.__base);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
canBeEmpty() {
|
|
71
|
+
var _a;
|
|
72
|
+
return ((_a = this.__props) == null ? void 0 : _a.canBeEmpty) ?? false;
|
|
73
|
+
}
|
|
74
|
+
canInsertTextBefore() {
|
|
75
|
+
var _a;
|
|
76
|
+
return ((_a = this.__props) == null ? void 0 : _a.canInsertTextBefore) ?? true;
|
|
77
|
+
}
|
|
78
|
+
canInsertTextAfter() {
|
|
79
|
+
var _a;
|
|
80
|
+
return ((_a = this.__props) == null ? void 0 : _a.canInsertTextAfter) ?? true;
|
|
81
|
+
}
|
|
82
|
+
getUnderlyingProps(props) {
|
|
83
|
+
const baseProps = this.__base.getUnderlyingProps(props ?? {});
|
|
84
|
+
const { canBeEmpty, canInsertTextBefore, canInsertTextAfter, ...restProps } = baseProps;
|
|
85
|
+
return restProps;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
var BaseDecoratorNode = class extends import_lexical.DecoratorNode {
|
|
89
|
+
constructor(props) {
|
|
90
|
+
const { key, ...restProps } = props || {};
|
|
91
|
+
super(key);
|
|
92
|
+
this.__props = restProps;
|
|
93
|
+
this.__base = new BaseNodeHelper(this.__props, {
|
|
94
|
+
remove: () => super.remove(),
|
|
95
|
+
replace: (replaceWith, includeChildren) => super.replace(replaceWith, includeChildren)
|
|
96
|
+
});
|
|
97
|
+
Object.keys(this.__base.hooks).forEach((key2) => {
|
|
98
|
+
const method = this.__base.hooks[key2];
|
|
99
|
+
if (typeof method === "function") {
|
|
100
|
+
this[key2] = method.bind(this.__base);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
getUnderlyingProps(props) {
|
|
105
|
+
const baseProps = this.__base.getUnderlyingProps(props ?? {});
|
|
106
|
+
const { ...restProps } = baseProps;
|
|
107
|
+
return restProps;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
111
|
+
0 && (module.exports = {
|
|
112
|
+
BaseDecoratorNode,
|
|
113
|
+
BaseElementNode,
|
|
114
|
+
BaseNodeHelper
|
|
115
|
+
});
|
|
116
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/components/Lexical/nodes/base.ts"],
|
|
4
|
+
"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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAA2C;AAwBpC,IAAM,iBAAN,MAA8C;AAAA,EAInD,YAAY,OAAsB,cAAuD;AAKzF,iBAAQ;AAAA,MACN,QAAQ,CAAC,wBAAwC;AAnCrD;AAoCM,cAAI,UAAK,YAAL,mBAAc,kBAAiB,OAAO;AACxC;AAAA,QACF;AACA,aAAK,eAAe,OAAO,mBAAmB;AAAA,MAChD;AAAA,MAEA,SAAS,CAAwB,aAAgB,oBAAiC;AA1CtF;AA2CM,cAAI,UAAK,YAAL,mBAAc,mBAAkB,OAAO;AACzC,iBAAO;AAAA,QACT;AACA,eAAO,KAAK,eAAe,QAAQ,aAAa,eAAe;AAAA,MACjE;AAAA,IACF;AAlBE,SAAK,UAAU;AACf,SAAK,iBAAiB;AAAA,EACxB;AAAA,EAiBA,mBAAmB,OAAwD;AAEzE,UAAM,EAAE,cAAc,eAAe,GAAG,UAAU,IAAI;AAEtD,WAAO;AAAA,EACT;AACF;AAEO,IAAM,kBAAN,cAA0D,2BAAY;AAAA,EAI3E,YAAY,OAA8B;AACxC,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O,KAAK,EAAE,QAAQ,CAACA,SAAQ;AAC9C,YAAM,SAAS,KAAK,OAAO,MAAMA,IAAqC;AACtE,UAAI,OAAO,WAAW,YAAY;AAEhC,aAAKA,IAAiB,IAAI,OAAO,KAAK,KAAK,MAAM;AAAA,MACnD;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEA,mBAAmB,OAA6D;AAC9E,UAAM,YAAY,KAAK,OAAO,mBAAmB,SAAU,CAAC,CAAO;AAEnE,UAAM,EAAE,GAAG,UAAU,IAAI;AAEzB,WAAO;AAAA,EACT;AACF;",
|
|
6
|
+
"names": ["key"]
|
|
7
|
+
}
|
|
@@ -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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/hooks/useRefValue.ts"],
|
|
4
|
-
"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"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAuB;AAUvB,IAAM,cAAc,CAAI,UAA2B;AACjD,QAAM,UAAM,qBAAU,KAAK;AAC3B,MAAI,UAAU;AACd,SAAO;AACT;AAEA,IAAO,sBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiny-codes/react-easy",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Simplify React and AntDesign development with practical components and hooks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -20,6 +20,23 @@
|
|
|
20
20
|
},
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"author": "李凤宝(Leo) <shijistar@gmail.com>",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"import": "./es/index.js",
|
|
26
|
+
"require": "./lib/index.js",
|
|
27
|
+
"default": "./lib/index.js",
|
|
28
|
+
"node": "./lib/index.js",
|
|
29
|
+
"types": "./lib/index.d.ts"
|
|
30
|
+
},
|
|
31
|
+
"./lexical": {
|
|
32
|
+
"import": "./es/components/Lexical/index.js",
|
|
33
|
+
"require": "./lib/components/Lexical/index.js",
|
|
34
|
+
"default": "./lib/components/Lexical/index.js",
|
|
35
|
+
"node": "./lib/components/Lexical/index.js",
|
|
36
|
+
"types": "./lib/components/Lexical/index.d.ts"
|
|
37
|
+
},
|
|
38
|
+
"./package.json": "./package.json"
|
|
39
|
+
},
|
|
23
40
|
"main": "lib/index.js",
|
|
24
41
|
"module": "es/index.js",
|
|
25
42
|
"types": "lib/index.d.ts",
|
|
@@ -36,7 +53,9 @@
|
|
|
36
53
|
"prepublishOnly": "npm run build"
|
|
37
54
|
},
|
|
38
55
|
"dependencies": {
|
|
56
|
+
"@lexical/react": "^0.33.1",
|
|
39
57
|
"i18next": "^24.2.3",
|
|
58
|
+
"lexical": "^0.33.1",
|
|
40
59
|
"react-contexify": "^6.0.0"
|
|
41
60
|
},
|
|
42
61
|
"devDependencies": {
|