@tiny-codes/react-easy 1.4.0 → 1.4.2
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/FormItemControl/index.d.ts +7 -7
- package/es/components/FormItemControl/index.js +6 -6
- package/es/components/FormItemControl/index.js.map +1 -1
- package/es/components/Lexical/helpers/index.d.ts +39 -24
- package/es/components/Lexical/helpers/index.js +63 -24
- package/es/components/Lexical/helpers/index.js.map +1 -1
- package/es/components/Lexical/index.d.ts +1 -0
- package/es/components/Lexical/index.js +1 -0
- package/es/components/Lexical/index.js.map +1 -1
- package/es/components/Lexical/nodes/CloseIcon.d.ts +71 -0
- package/es/components/Lexical/nodes/CloseIcon.js +176 -0
- package/es/components/Lexical/nodes/CloseIcon.js.map +1 -0
- package/es/components/Lexical/nodes/DivNode.d.ts +20 -0
- package/es/components/Lexical/nodes/DivNode.js +32 -4
- package/es/components/Lexical/nodes/DivNode.js.map +1 -1
- package/es/components/Lexical/nodes/ExtendTextNode.d.ts +23 -1
- package/es/components/Lexical/nodes/ExtendTextNode.js +38 -6
- package/es/components/Lexical/nodes/ExtendTextNode.js.map +1 -1
- package/es/components/Lexical/nodes/SelectNode.d.ts +39 -9
- package/es/components/Lexical/nodes/SelectNode.js +42 -7
- package/es/components/Lexical/nodes/SelectNode.js.map +1 -1
- package/es/components/Lexical/nodes/base.d.ts +59 -8
- package/es/components/Lexical/nodes/base.js +50 -1
- package/es/components/Lexical/nodes/base.js.map +1 -1
- package/es/utils/index.d.ts +1 -0
- package/es/utils/index.js +1 -0
- package/es/utils/index.js.map +1 -1
- package/es/utils/string.d.ts +7 -0
- package/es/utils/string.js +15 -0
- package/es/utils/string.js.map +1 -0
- package/lib/components/FormItemControl/index.d.ts +7 -7
- package/lib/components/FormItemControl/index.js.map +1 -1
- package/lib/components/Lexical/helpers/index.d.ts +39 -24
- package/lib/components/Lexical/helpers/index.js +26 -0
- package/lib/components/Lexical/helpers/index.js.map +2 -2
- package/lib/components/Lexical/index.d.ts +1 -0
- package/lib/components/Lexical/index.js +3 -1
- package/lib/components/Lexical/index.js.map +2 -2
- package/lib/components/Lexical/nodes/CloseIcon.d.ts +71 -0
- package/lib/components/Lexical/nodes/CloseIcon.js +149 -0
- package/lib/components/Lexical/nodes/CloseIcon.js.map +7 -0
- package/lib/components/Lexical/nodes/DivNode.d.ts +20 -0
- package/lib/components/Lexical/nodes/DivNode.js +1 -1
- package/lib/components/Lexical/nodes/DivNode.js.map +2 -2
- package/lib/components/Lexical/nodes/ExtendTextNode.d.ts +23 -1
- package/lib/components/Lexical/nodes/ExtendTextNode.js +9 -1
- package/lib/components/Lexical/nodes/ExtendTextNode.js.map +2 -2
- package/lib/components/Lexical/nodes/SelectNode.d.ts +39 -9
- package/lib/components/Lexical/nodes/SelectNode.js +2 -2
- package/lib/components/Lexical/nodes/SelectNode.js.map +2 -2
- package/lib/components/Lexical/nodes/base.d.ts +59 -8
- package/lib/components/Lexical/nodes/base.js +18 -0
- package/lib/components/Lexical/nodes/base.js.map +2 -2
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +3 -1
- package/lib/utils/index.js.map +2 -2
- package/lib/utils/string.d.ts +7 -0
- package/lib/utils/string.js +37 -0
- package/lib/utils/string.js.map +7 -0
- package/package.json +1 -1
|
@@ -22,6 +22,7 @@ __export(helpers_exports, {
|
|
|
22
22
|
clearEditorContent: () => clearEditorContent,
|
|
23
23
|
findNode: () => findNode,
|
|
24
24
|
findNodes: () => findNodes,
|
|
25
|
+
getDomAttributes: () => getDomAttributes,
|
|
25
26
|
insertNodeAtCursor: () => insertNodeAtCursor,
|
|
26
27
|
insertTextAtCursor: () => insertTextAtCursor,
|
|
27
28
|
updateDomProps: () => updateDomProps,
|
|
@@ -167,6 +168,8 @@ function updateDomProps(dom, props) {
|
|
|
167
168
|
});
|
|
168
169
|
} else if (key === "className" && value) {
|
|
169
170
|
dom.className = value;
|
|
171
|
+
} else if (key.startsWith("on") && typeof value === "function") {
|
|
172
|
+
dom[key.toLowerCase()] = value;
|
|
170
173
|
} else if (value !== void 0 && value !== null) {
|
|
171
174
|
dom.setAttribute(key, value.toString());
|
|
172
175
|
}
|
|
@@ -185,11 +188,34 @@ function updateDomStyle(dom, style) {
|
|
|
185
188
|
});
|
|
186
189
|
}
|
|
187
190
|
}
|
|
191
|
+
function getDomAttributes(dom) {
|
|
192
|
+
if (!dom)
|
|
193
|
+
return void 0;
|
|
194
|
+
const attributes = {};
|
|
195
|
+
Array.from(dom.attributes).forEach((attr) => {
|
|
196
|
+
if (attr.name === "class" || attr.name === "style") {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
attributes[attr.name] = attr.value;
|
|
200
|
+
});
|
|
201
|
+
if (dom.className) {
|
|
202
|
+
attributes.className = dom.className;
|
|
203
|
+
}
|
|
204
|
+
if (dom.style) {
|
|
205
|
+
const styles = {};
|
|
206
|
+
Array.from(dom.style).forEach((styleName) => {
|
|
207
|
+
styles[styleName] = dom.style[styleName];
|
|
208
|
+
});
|
|
209
|
+
attributes.style = styles;
|
|
210
|
+
}
|
|
211
|
+
return attributes;
|
|
212
|
+
}
|
|
188
213
|
// Annotate the CommonJS export names for ESM import in node:
|
|
189
214
|
0 && (module.exports = {
|
|
190
215
|
clearEditorContent,
|
|
191
216
|
findNode,
|
|
192
217
|
findNodes,
|
|
218
|
+
getDomAttributes,
|
|
193
219
|
insertNodeAtCursor,
|
|
194
220
|
insertTextAtCursor,
|
|
195
221
|
updateDomProps,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 *
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,qBASO;AACP,qBAA2C;
|
|
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 * - EN: Insert a node at the current cursor position.\n * - CN: 将节点插入到当前光标位置。\n *\n * @param editor LexicalEditor instance | LexicalEditor 实例\n * @param node Node to insert | 要插入的节点\n */\nexport function insertNodeAtCursor(editor: LexicalEditor, node: LexicalNode): void {\n editor.update(() => {\n const selection = $getSelection();\n if (selection) {\n if ($isRangeSelection(selection)) {\n // 如果没有选取,则直接在根节点末尾插入\n const lastNode = selection.focus.getNode();\n if (lastNode) {\n if ($isParagraphNode(lastNode)) {\n lastNode.append(node);\n } else if ($isTextNode(lastNode)) {\n // 如果最后一个节点是文本节点,则在其后插入 SelectNode\n lastNode.insertAfter(node);\n } else if ($isDivNode(lastNode)) {\n lastNode.append(node);\n } else {\n selection.insertNodes([node]);\n }\n node.selectNext();\n }\n } else {\n selection.insertNodes([node]);\n node.selectNext();\n }\n } else {\n const root = $getRoot();\n let nodeToInsert: LexicalNode = node;\n if ($isElementNode(node) || $isDecoratorNode(node)) {\n nodeToInsert = node;\n } else {\n const container = $createDivNode({\n style: { display: 'inline-block' },\n });\n container.append(node);\n nodeToInsert = container;\n }\n root.append(nodeToInsert);\n node.selectNext();\n }\n });\n}\n\n/**\n * - EN: Insert text at the current cursor position.\n * - CN: 将文本插入到当前光标位置。\n *\n * @param editor LexicalEditor instance | LexicalEditor 实例\n * @param text Text to insert | 要插入的文本\n */\nexport function insertTextAtCursor(editor: LexicalEditor, text: string): void {\n editor?.update(() => {\n const textNode = $createTextNode(text);\n const root = $getRoot();\n const selection = $getSelection();\n if (selection) {\n // 插入光标位置\n selection.insertText(text);\n } else {\n // 如果没有选取,则直接在根节点末尾插入\n const lastNode = root.getLastChild();\n if (lastNode && $isParagraphNode(lastNode)) {\n lastNode.append(textNode);\n } else {\n const container = $createDivNode({\n style: { display: 'inline-block' },\n });\n container.append(textNode);\n root.append(container);\n }\n }\n });\n}\n\n/**\n * - EN: Clear the editor content.\n * - CN: 清空编辑器内容。\n *\n * @param editor LexicalEditor instance | LexicalEditor 实例\n */\nexport function clearEditorContent(editor: LexicalEditor) {\n const state = editor.getEditorState();\n const stateJson = state.toJSON();\n // 默认创建一个ParagraphNode\n const newJson = {\n ...stateJson,\n root: {\n ...stateJson.root,\n children: [\n {\n children: [],\n direction: null,\n format: '',\n indent: 0,\n type: 'paragraph',\n version: 1,\n textFormat: 0,\n textStyle: '',\n },\n ],\n },\n };\n const emptyState = editor.parseEditorState(JSON.stringify(newJson));\n editor.setEditorState(emptyState);\n editor.update(() => {\n const root = $getRoot();\n root.clear();\n });\n}\n\n/**\n * - EN: Find the first node that matches the predicate.\n * - CN: 查找第一个符合条件的节点。\n *\n * @param editor LexicalEditor instance | LexicalEditor 实例\n * @param predicate Function to test whether a node matches | 用于匹配节点的函数\n *\n * @returns The matched node, or undefined | 符合条件的第一个节点,或 undefined\n */\nexport function findNode<T extends LexicalNode>(\n editor: LexicalEditor,\n predicate: (node: LexicalNode) => boolean\n): T | undefined {\n const matched = findNodes<T>(editor, predicate, { stopOnFirstMatch: true });\n return matched[0];\n}\n/**\n * - EN: Find all nodes that match the predicate.\n * - CN: 查找所有符合条件的节点数组。\n *\n * @param editor LexicalEditor instance | LexicalEditor 实例\n * @param predicate Function to test whether a node matches | 用于匹配节点的函数\n * @param options Options | 选项\n *\n * @returns An array of matched nodes | 符合条件的节点数组\n */\nexport function findNodes<T extends LexicalNode>(\n editor: LexicalEditor,\n predicate: (node: LexicalNode) => boolean,\n options?: {\n stopOnFirstMatch?: boolean;\n }\n): T[] {\n const matched: T[] = [];\n editor.getEditorState().read(() => {\n const root = $getRoot();\n const traverse = (node: LexicalNode, result: T[]) => {\n if (predicate(node)) {\n result.push(node as unknown as T);\n if (options?.stopOnFirstMatch) {\n return;\n }\n }\n if ($isElementNode(node)) {\n const children = node.getChildren();\n for (const child of children) {\n traverse(child, result);\n if (options?.stopOnFirstMatch && result.length > 0) {\n return;\n }\n }\n }\n };\n traverse(root, matched);\n });\n return matched;\n}\n\n/**\n * - EN: Update properties on a DOM element.\n * - CN: 更新 DOM 元素的属性。\n *\n * @param dom Target DOM element to update | 要更新的 DOM 元素\n * @param props Props to set on the element | 要设置的属性\n */\nexport function updateDomProps(dom: HTMLElement | undefined, props: HtmlHTMLAttributes<HTMLElement>): void {\n if (!dom) return;\n Array.from(dom.attributes).forEach((attr) => {\n if (!attr.name.startsWith('data-lexical')) {\n dom.removeAttribute(attr.name);\n }\n });\n\n dom.removeAttribute('style');\n dom.removeAttribute('class');\n\n if (props) {\n Object.entries(props).forEach(([key, value]) => {\n if (key === 'style' && value) {\n Object.entries(value as CSSProperties).forEach(([styleKey, styleValue]) => {\n if (styleValue !== undefined) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (dom.style as any)[styleKey] = styleValue;\n }\n });\n } else if (key === 'className' && value) {\n dom.className = value as string;\n } else if (key.startsWith('on') && typeof value === 'function') {\n dom[key.toLowerCase() as 'onclick'] = value as (event: MouseEvent) => void;\n } else if (value !== undefined && value !== null) {\n dom.setAttribute(key, value.toString());\n }\n });\n }\n}\n\n/**\n * - EN: Update style on a DOM element.\n * - CN: 更新 DOM 元素的样式。\n *\n * @param dom Target DOM element to update | 要更新的 DOM 元素\n * @param style Style to set | 要设置的样式\n */\nexport function updateDomStyle(dom: HTMLElement | undefined, style: CSSProperties | undefined): void {\n if (!dom) return;\n dom.removeAttribute('style');\n if (style) {\n Object.entries(style).forEach(([styleKey, styleValue]) => {\n if (styleValue !== undefined) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (dom.style as any)[styleKey] = styleValue;\n }\n });\n }\n}\n\n/**\n * - EN: Get attributes from a DOM element.\n * - CN: 从 DOM 元素获取属性。\n *\n * @param dom Target DOM element | 目标 DOM 元素\n *\n * @returns Element attributes | 元素属性\n */\nexport function getDomAttributes(dom: HTMLElement | undefined): HtmlHTMLAttributes<HTMLElement> | undefined {\n if (!dom) return undefined;\n\n const attributes: HtmlHTMLAttributes<HTMLElement> = {};\n Array.from(dom.attributes).forEach((attr) => {\n if (attr.name === 'class' || attr.name === 'style') {\n return;\n }\n attributes[attr.name as keyof HtmlHTMLAttributes<HTMLElement>] = attr.value;\n });\n\n if (dom.className) {\n attributes.className = dom.className;\n }\n\n if (dom.style) {\n const styles: CSSProperties = {};\n Array.from(dom.style).forEach((styleName) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (styles as any)[styleName] = (dom.style as any)[styleName];\n });\n attributes.style = styles;\n }\n\n return attributes;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,qBASO;AACP,qBAA2C;AASpC,SAAS,mBAAmB,QAAuB,MAAyB;AACjF,SAAO,OAAO,MAAM;AAClB,UAAM,gBAAY,8BAAc;AAChC,QAAI,WAAW;AACb,cAAI,kCAAkB,SAAS,GAAG;AAEhC,cAAM,WAAW,UAAU,MAAM,QAAQ;AACzC,YAAI,UAAU;AACZ,kBAAI,iCAAiB,QAAQ,GAAG;AAC9B,qBAAS,OAAO,IAAI;AAAA,UACtB,eAAW,4BAAY,QAAQ,GAAG;AAEhC,qBAAS,YAAY,IAAI;AAAA,UAC3B,eAAW,2BAAW,QAAQ,GAAG;AAC/B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AAO;AACb,UAAM,SAAwB,CAAC;AAC/B,UAAM,KAAK,IAAI,KAAK,EAAE,QAAQ,CAAC,cAAc;AAE3C,MAAC,OAAe,SAAS,IAAK,IAAI,MAAc,SAAS;AAAA,IAC3D,CAAC;AACD,eAAW,QAAQ;AAAA,EACrB;AAEA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -21,12 +21,14 @@ __reExport(Lexical_exports, require("./nodes/base"), module.exports);
|
|
|
21
21
|
__reExport(Lexical_exports, require("./nodes/DivNode"), module.exports);
|
|
22
22
|
__reExport(Lexical_exports, require("./nodes/SelectNode"), module.exports);
|
|
23
23
|
__reExport(Lexical_exports, require("./nodes/ExtendTextNode"), module.exports);
|
|
24
|
+
__reExport(Lexical_exports, require("./nodes/CloseIcon"), module.exports);
|
|
24
25
|
// Annotate the CommonJS export names for ESM import in node:
|
|
25
26
|
0 && (module.exports = {
|
|
26
27
|
...require("./helpers"),
|
|
27
28
|
...require("./nodes/base"),
|
|
28
29
|
...require("./nodes/DivNode"),
|
|
29
30
|
...require("./nodes/SelectNode"),
|
|
30
|
-
...require("./nodes/ExtendTextNode")
|
|
31
|
+
...require("./nodes/ExtendTextNode"),
|
|
32
|
+
...require("./nodes/CloseIcon")
|
|
31
33
|
});
|
|
32
34
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/Lexical/index.ts"],
|
|
4
|
-
"sourcesContent": ["export * from './helpers';\nexport * from './nodes/base';\nexport * from './nodes/DivNode';\nexport * from './nodes/SelectNode';\nexport * from './nodes/ExtendTextNode';\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,4BAAc,sBAAd;AACA,4BAAc,yBADd;AAEA,4BAAc,4BAFd;AAGA,4BAAc,+BAHd;AAIA,4BAAc,mCAJd;",
|
|
4
|
+
"sourcesContent": ["export * from './helpers';\nexport * from './nodes/base';\nexport * from './nodes/DivNode';\nexport * from './nodes/SelectNode';\nexport * from './nodes/ExtendTextNode';\nexport * from './nodes/CloseIcon';\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,4BAAc,sBAAd;AACA,4BAAc,yBADd;AAEA,4BAAc,4BAFd;AAGA,4BAAc,+BAHd;AAIA,4BAAc,mCAJd;AAKA,4BAAc,8BALd;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type CSSProperties, type HtmlHTMLAttributes, type ReactNode } from 'react';
|
|
2
|
+
import type { LexicalNode, SerializedLexicalNode, Spread } from 'lexical';
|
|
3
|
+
import type { BaseDecoratorNodeProps, BaseNodeProps } from './base';
|
|
4
|
+
import { BaseDecoratorNode } from './base';
|
|
5
|
+
export interface CloseIconNodeProps extends HtmlHTMLAttributes<HTMLSpanElement>, BaseDecoratorNodeProps {
|
|
6
|
+
/**
|
|
7
|
+
* - EN: Parent element class name, used to add positioning styles to the parent element.
|
|
8
|
+
* - CN: 父元素的类名,用于给父元素添加定位样式
|
|
9
|
+
*/
|
|
10
|
+
parentClassName: string;
|
|
11
|
+
/**
|
|
12
|
+
* - EN: The custom icon to display, optional
|
|
13
|
+
* - CN: 要显示的自定义图标,可选
|
|
14
|
+
*/
|
|
15
|
+
icon?: ReactNode;
|
|
16
|
+
/**
|
|
17
|
+
* - EN: The default class name for the close icon element. This property is invalid if `icon` is
|
|
18
|
+
* set.
|
|
19
|
+
* - CN: 默认关闭图标元素的类名,如果设置了 `icon` 则该属性无效
|
|
20
|
+
*/
|
|
21
|
+
iconClassName?: string;
|
|
22
|
+
/**
|
|
23
|
+
* - EN: The custom style for the close icon element. This property is invalid if `icon` is set.
|
|
24
|
+
* - CN: 自定义关闭图标元素的样式,如果设置了 `icon` 则该属性无效
|
|
25
|
+
*/
|
|
26
|
+
iconStyle?: CSSProperties;
|
|
27
|
+
/**
|
|
28
|
+
* - EN: The click event handler for the close icon element.
|
|
29
|
+
* - CN: 关闭图标元素的点击事件
|
|
30
|
+
*/
|
|
31
|
+
onClick?: (e: React.MouseEvent<HTMLSpanElement>) => void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* - EN: A node that represents a close icon.
|
|
35
|
+
* - CN: 一个关闭图标的节点。
|
|
36
|
+
*/
|
|
37
|
+
export declare class CloseIconNode extends BaseDecoratorNode<ReactNode, CloseIconNodeProps> {
|
|
38
|
+
__hashId: string;
|
|
39
|
+
constructor(props: CloseIconNodeProps & {
|
|
40
|
+
key?: string;
|
|
41
|
+
});
|
|
42
|
+
static getType(): string;
|
|
43
|
+
static clone(node: CloseIconNode): CloseIconNode;
|
|
44
|
+
static importJSON(serializedNode: SerializedCloseIconNode): CloseIconNode;
|
|
45
|
+
exportJSON(): SerializedCloseIconNode;
|
|
46
|
+
createDOM(): HTMLElement;
|
|
47
|
+
updateDOM(): boolean;
|
|
48
|
+
decorate(): ReactNode;
|
|
49
|
+
isInline(): boolean;
|
|
50
|
+
getPropValue(propName: keyof CloseIconNodeProps): CloseIconNodeProps[typeof propName];
|
|
51
|
+
setProps(props: Partial<CloseIconNodeProps>): void;
|
|
52
|
+
getUnderlyingProps(props: CloseIconNodeProps | undefined): Omit<CloseIconNodeProps, keyof BaseNodeProps>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* - EN: Factory to create a CloseIconNode.
|
|
56
|
+
* - CN: 创建 CloseIconNode 的工厂函数。
|
|
57
|
+
*
|
|
58
|
+
* @param props Props for the CloseIcon node | CloseIcon 节点的属性
|
|
59
|
+
*/
|
|
60
|
+
export declare function $createCloseIconNode(props: CloseIconNodeProps): CloseIconNode;
|
|
61
|
+
/**
|
|
62
|
+
* - EN: Type guard to check whether a node is CloseIconNode.
|
|
63
|
+
* - CN: 判断节点是否为 CloseIconNode 的类型守卫。
|
|
64
|
+
*
|
|
65
|
+
* @param node Node to test | 要检测的节点
|
|
66
|
+
*/
|
|
67
|
+
export declare function $isCloseIconNode(node: LexicalNode | null | undefined): node is CloseIconNode;
|
|
68
|
+
type SerializedCloseIconNode = Spread<{
|
|
69
|
+
props: CloseIconNodeProps;
|
|
70
|
+
}, SerializedLexicalNode>;
|
|
71
|
+
export {};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/components/Lexical/nodes/CloseIcon.tsx
|
|
30
|
+
var CloseIcon_exports = {};
|
|
31
|
+
__export(CloseIcon_exports, {
|
|
32
|
+
$createCloseIconNode: () => $createCloseIconNode,
|
|
33
|
+
$isCloseIconNode: () => $isCloseIconNode,
|
|
34
|
+
CloseIconNode: () => CloseIconNode
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(CloseIcon_exports);
|
|
37
|
+
var import_antd = require("antd");
|
|
38
|
+
var import_classnames = __toESM(require("classnames"));
|
|
39
|
+
var import_icons = require("@ant-design/icons");
|
|
40
|
+
var import_utils = require("../../../utils");
|
|
41
|
+
var import_helpers = require("../helpers");
|
|
42
|
+
var import_base = require("./base");
|
|
43
|
+
var CLOSE_ICON_CLASSNAME = "lexical-close-icon";
|
|
44
|
+
var CloseIconNode = class extends import_base.BaseDecoratorNode {
|
|
45
|
+
constructor(props) {
|
|
46
|
+
super(props);
|
|
47
|
+
this.__hashId = `hash-${(0, import_utils.randomChars)(6)}`;
|
|
48
|
+
}
|
|
49
|
+
static getType() {
|
|
50
|
+
return "CloseIcon";
|
|
51
|
+
}
|
|
52
|
+
static clone(node) {
|
|
53
|
+
return new CloseIconNode({ ...node.__props, key: node.getKey() });
|
|
54
|
+
}
|
|
55
|
+
static importJSON(serializedNode) {
|
|
56
|
+
return $createCloseIconNode(serializedNode.props);
|
|
57
|
+
}
|
|
58
|
+
exportJSON() {
|
|
59
|
+
return {
|
|
60
|
+
...super.exportJSON(),
|
|
61
|
+
props: this.__props,
|
|
62
|
+
type: this.getType(),
|
|
63
|
+
version: 1
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
createDOM() {
|
|
67
|
+
var _a;
|
|
68
|
+
const span = document.createElement("span");
|
|
69
|
+
const underlyingProps = this.getUnderlyingProps(this.__props);
|
|
70
|
+
const className = (0, import_classnames.default)(CLOSE_ICON_CLASSNAME, this.__hashId, underlyingProps == null ? void 0 : underlyingProps.className);
|
|
71
|
+
(0, import_helpers.updateDomProps)(span, { ...underlyingProps, className });
|
|
72
|
+
const stylesheet = document.createElement("style");
|
|
73
|
+
const token = import_antd.theme.getDesignToken();
|
|
74
|
+
const parentCls = ((_a = this.__props) == null ? void 0 : _a.parentClassName) ? `.${this.__props.parentClassName}` : "";
|
|
75
|
+
stylesheet.innerHTML = `
|
|
76
|
+
${parentCls ? `
|
|
77
|
+
${parentCls} {
|
|
78
|
+
position: relative;
|
|
79
|
+
}
|
|
80
|
+
` : ""}
|
|
81
|
+
${parentCls} .${CLOSE_ICON_CLASSNAME}.${this.__hashId} {
|
|
82
|
+
position: absolute;
|
|
83
|
+
top: 0;
|
|
84
|
+
right: 0;
|
|
85
|
+
transform: translate(50%, -50%);
|
|
86
|
+
color: ${token.colorTextDisabled};
|
|
87
|
+
font-size: ${token.fontSizeSM}px;
|
|
88
|
+
line-height: 0;
|
|
89
|
+
z-index: 1;
|
|
90
|
+
opacity: 0;
|
|
91
|
+
cursor: pointer;
|
|
92
|
+
pointer-events: none;
|
|
93
|
+
transition: opacity 0.2s ease;
|
|
94
|
+
}
|
|
95
|
+
${parentCls}:hover .${CLOSE_ICON_CLASSNAME}.${this.__hashId} {
|
|
96
|
+
opacity: 1;
|
|
97
|
+
pointer-events: auto;
|
|
98
|
+
}
|
|
99
|
+
${parentCls}:hover .${CLOSE_ICON_CLASSNAME}.${this.__hashId}:hover {
|
|
100
|
+
color: ${token.colorTextSecondary};
|
|
101
|
+
}
|
|
102
|
+
`;
|
|
103
|
+
span.append(stylesheet);
|
|
104
|
+
return span;
|
|
105
|
+
}
|
|
106
|
+
updateDOM() {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
decorate() {
|
|
110
|
+
return /* @__PURE__ */ React.createElement(CloseIconComponent, { node: this });
|
|
111
|
+
}
|
|
112
|
+
isInline() {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
getPropValue(propName) {
|
|
116
|
+
var _a;
|
|
117
|
+
return (_a = this.__props) == null ? void 0 : _a[propName];
|
|
118
|
+
}
|
|
119
|
+
setProps(props) {
|
|
120
|
+
const writable = this.getWritable();
|
|
121
|
+
writable.__props = {
|
|
122
|
+
...writable.__props,
|
|
123
|
+
...props
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
getUnderlyingProps(props) {
|
|
127
|
+
const excludeProps = super.getUnderlyingProps(props);
|
|
128
|
+
const { icon, iconClassName, iconStyle, onClick, ...rest } = excludeProps || {};
|
|
129
|
+
return rest;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
function CloseIconComponent({ node }) {
|
|
133
|
+
const { icon, iconClassName, iconStyle, onClick } = node.__props || {};
|
|
134
|
+
const closeIcon = icon ?? /* @__PURE__ */ React.createElement(import_icons.CloseCircleOutlined, { className: (0, import_classnames.default)(node.__hashId, iconClassName), style: iconStyle, onClick });
|
|
135
|
+
return closeIcon;
|
|
136
|
+
}
|
|
137
|
+
function $createCloseIconNode(props) {
|
|
138
|
+
return new CloseIconNode(props);
|
|
139
|
+
}
|
|
140
|
+
function $isCloseIconNode(node) {
|
|
141
|
+
return node instanceof CloseIconNode;
|
|
142
|
+
}
|
|
143
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
144
|
+
0 && (module.exports = {
|
|
145
|
+
$createCloseIconNode,
|
|
146
|
+
$isCloseIconNode,
|
|
147
|
+
CloseIconNode
|
|
148
|
+
});
|
|
149
|
+
//# sourceMappingURL=CloseIcon.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/components/Lexical/nodes/CloseIcon.tsx"],
|
|
4
|
+
"sourcesContent": ["import { type CSSProperties, type HtmlHTMLAttributes, type ReactNode } from 'react';\nimport { theme } from 'antd';\nimport classNames from 'classnames';\nimport type { LexicalNode, SerializedLexicalNode, Spread } from 'lexical';\nimport { CloseCircleOutlined } from '@ant-design/icons';\nimport { randomChars } from '../../../utils';\nimport { updateDomProps } from '../helpers';\nimport type { BaseDecoratorNodeProps, BaseNodeProps } from './base';\nimport { BaseDecoratorNode } from './base';\n\nconst CLOSE_ICON_CLASSNAME = 'lexical-close-icon';\n\nexport interface CloseIconNodeProps extends HtmlHTMLAttributes<HTMLSpanElement>, BaseDecoratorNodeProps {\n /**\n * - EN: Parent element class name, used to add positioning styles to the parent element.\n * - CN: 父元素的类名,用于给父元素添加定位样式\n */\n parentClassName: string;\n /**\n * - EN: The custom icon to display, optional\n * - CN: 要显示的自定义图标,可选\n */\n icon?: ReactNode;\n /**\n * - EN: The default class name for the close icon element. This property is invalid if `icon` is\n * set.\n * - CN: 默认关闭图标元素的类名,如果设置了 `icon` 则该属性无效\n */\n iconClassName?: string;\n /**\n * - EN: The custom style for the close icon element. This property is invalid if `icon` is set.\n * - CN: 自定义关闭图标元素的样式,如果设置了 `icon` 则该属性无效\n */\n iconStyle?: CSSProperties;\n /**\n * - EN: The click event handler for the close icon element.\n * - CN: 关闭图标元素的点击事件\n */\n onClick?: (e: React.MouseEvent<HTMLSpanElement>) => void;\n}\n\n/**\n * - EN: A node that represents a close icon.\n * - CN: 一个关闭图标的节点。\n */\nexport class CloseIconNode extends BaseDecoratorNode<ReactNode, CloseIconNodeProps> {\n __hashId: string;\n\n constructor(props: CloseIconNodeProps & { key?: string }) {\n super(props);\n this.__hashId = `hash-${randomChars(6)}`;\n }\n\n static getType(): string {\n return 'CloseIcon';\n }\n\n static clone(node: CloseIconNode): CloseIconNode {\n return new CloseIconNode({ ...node.__props!, key: node.getKey() });\n }\n\n static importJSON(serializedNode: SerializedCloseIconNode): CloseIconNode {\n return $createCloseIconNode(serializedNode.props);\n }\n\n exportJSON(): SerializedCloseIconNode {\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 const underlyingProps = this.getUnderlyingProps(this.__props);\n const className = classNames(CLOSE_ICON_CLASSNAME, this.__hashId, underlyingProps?.className);\n updateDomProps(span, { ...underlyingProps, className });\n const stylesheet = document.createElement('style');\n const token = theme.getDesignToken();\n const parentCls = this.__props?.parentClassName ? `.${this.__props.parentClassName}` : '';\n stylesheet.innerHTML = `\n ${\n parentCls\n ? `\n ${parentCls} { \n position: relative;\n }\n `\n : ''\n }\n ${parentCls} .${CLOSE_ICON_CLASSNAME}.${this.__hashId} {\n position: absolute;\n top: 0;\n right: 0;\n transform: translate(50%, -50%);\n color: ${token.colorTextDisabled};\n font-size: ${token.fontSizeSM}px;\n line-height: 0;\n z-index: 1;\n opacity: 0;\n cursor: pointer;\n pointer-events: none;\n transition: opacity 0.2s ease;\n }\n ${parentCls}:hover .${CLOSE_ICON_CLASSNAME}.${this.__hashId} {\n opacity: 1;\n pointer-events: auto;\n }\n ${parentCls}:hover .${CLOSE_ICON_CLASSNAME}.${this.__hashId}:hover {\n color: ${token.colorTextSecondary};\n }\n `;\n span.append(stylesheet);\n return span;\n }\n\n updateDOM() {\n return false;\n }\n\n decorate(): ReactNode {\n return <CloseIconComponent node={this} />;\n }\n\n isInline(): boolean {\n return false;\n }\n\n getPropValue(propName: keyof CloseIconNodeProps): CloseIconNodeProps[typeof propName] {\n return this.__props?.[propName];\n }\n\n setProps(props: Partial<CloseIconNodeProps>): void {\n const writable = this.getWritable();\n writable.__props = {\n ...writable.__props!,\n ...props,\n };\n }\n\n getUnderlyingProps(props: CloseIconNodeProps | undefined): Omit<CloseIconNodeProps, keyof BaseNodeProps> {\n const excludeProps = super.getUnderlyingProps(props);\n /* eslint-disable @typescript-eslint/no-unused-vars */\n const { icon, iconClassName, iconStyle, onClick, ...rest } = excludeProps || {};\n /* eslint-enable @typescript-eslint/no-unused-vars */\n return rest;\n }\n}\n\n/**\n * - EN: React decorator component rendered for CloseIconNode.\n * - CN: CloseIconNode 对应的 React 装饰组件。\n *\n * @param node The bound CloseIconNode instance | 关联的 CloseIconNode 实例\n */\nfunction CloseIconComponent({ node }: CloseIconComponentProps): ReactNode {\n const { icon, iconClassName, iconStyle, onClick } = node.__props || {};\n\n const closeIcon = icon ?? (\n <CloseCircleOutlined className={classNames(node.__hashId, iconClassName)} style={iconStyle} onClick={onClick} />\n );\n return closeIcon;\n}\n\n/**\n * - EN: Factory to create a CloseIconNode.\n * - CN: 创建 CloseIconNode 的工厂函数。\n *\n * @param props Props for the CloseIcon node | CloseIcon 节点的属性\n */\nexport function $createCloseIconNode(props: CloseIconNodeProps): CloseIconNode {\n return new CloseIconNode(props);\n}\n\n/**\n * - EN: Type guard to check whether a node is CloseIconNode.\n * - CN: 判断节点是否为 CloseIconNode 的类型守卫。\n *\n * @param node Node to test | 要检测的节点\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function $isCloseIconNode(node: LexicalNode | null | undefined): node is CloseIconNode {\n return node instanceof CloseIconNode;\n}\n\ninterface CloseIconComponentProps {\n node: CloseIconNode;\n}\ntype SerializedCloseIconNode = Spread<\n {\n props: CloseIconNodeProps;\n },\n SerializedLexicalNode\n>;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,kBAAsB;AACtB,wBAAuB;AAEvB,mBAAoC;AACpC,mBAA4B;AAC5B,qBAA+B;AAE/B,kBAAkC;AAElC,IAAM,uBAAuB;AAmCtB,IAAM,gBAAN,cAA4B,8BAAiD;AAAA,EAGlF,YAAY,OAA8C;AACxD,UAAM,KAAK;AACX,SAAK,WAAW,YAAQ,0BAAY,CAAC;AAAA,EACvC;AAAA,EAEA,OAAO,UAAkB;AACvB,WAAO;AAAA,EACT;AAAA,EAEA,OAAO,MAAM,MAAoC;AAC/C,WAAO,IAAI,cAAc,EAAE,GAAG,KAAK,SAAU,KAAK,KAAK,OAAO,EAAE,CAAC;AAAA,EACnE;AAAA,EAEA,OAAO,WAAW,gBAAwD;AACxE,WAAO,qBAAqB,eAAe,KAAK;AAAA,EAClD;AAAA,EA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AAA,MACZ,GAAG;AAAA,IACL;AAAA,EACF;AAAA,EAEA,mBAAmB,OAAsF;AACvG,UAAM,eAAe,MAAM,mBAAmB,KAAK;AAEnD,UAAM,EAAE,MAAM,eAAe,WAAW,SAAS,GAAG,KAAK,IAAI,gBAAgB,CAAC;AAE9E,WAAO;AAAA,EACT;AACF;AAQA,SAAS,mBAAmB,EAAE,KAAK,GAAuC;AACxE,QAAM,EAAE,MAAM,eAAe,WAAW,QAAQ,IAAI,KAAK,WAAW,CAAC;AAErE,QAAM,YAAY,QAChB,oCAAC,oCAAoB,eAAW,kBAAAA,SAAW,KAAK,UAAU,aAAa,GAAG,OAAO,WAAW,SAAkB;AAEhH,SAAO;AACT;AAQO,SAAS,qBAAqB,OAA0C;AAC7E,SAAO,IAAI,cAAc,KAAK;AAChC;AASO,SAAS,iBAAiB,MAA6D;AAC5F,SAAO,gBAAgB;AACzB;",
|
|
6
|
+
"names": ["classNames"]
|
|
7
|
+
}
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import type { CSSProperties, HtmlHTMLAttributes } from 'react';
|
|
2
2
|
import type { DOMConversionMap, DOMExportOutput, LexicalNode, SerializedElementNode, Spread } from 'lexical';
|
|
3
3
|
import { BaseElementNode, type BaseElementProps } from './base';
|
|
4
|
+
/**
|
|
5
|
+
* - EN: Props for the DivNode, combining DOM div attributes and element behavior flags.
|
|
6
|
+
* - CN: DivNode 的属性,包含 DOM div 属性与元素行为标记。
|
|
7
|
+
*/
|
|
4
8
|
export interface DivNodeProps extends HtmlHTMLAttributes<HTMLDivElement>, BaseElementProps {
|
|
5
9
|
}
|
|
6
10
|
export type SerializedDivNode = Spread<{
|
|
7
11
|
props?: DivNodeProps;
|
|
8
12
|
}, SerializedElementNode>;
|
|
13
|
+
/**
|
|
14
|
+
* - EN: Lexical element node that renders a DOM div with controlled props.
|
|
15
|
+
* - CN: 渲染为 DOM div 且可控制属性的 Lexical 元素节点。
|
|
16
|
+
*/
|
|
9
17
|
export declare class DivNode extends BaseElementNode<DivNodeProps> {
|
|
10
18
|
static getType(): string;
|
|
11
19
|
static clone(node: DivNode): DivNode;
|
|
@@ -21,5 +29,17 @@ export declare class DivNode extends BaseElementNode<DivNodeProps> {
|
|
|
21
29
|
setProps(props: DivNodeProps): void;
|
|
22
30
|
private shallowEqual;
|
|
23
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* - EN: Factory to create a DivNode.
|
|
34
|
+
* - CN: 创建 DivNode 的工厂函数。
|
|
35
|
+
*
|
|
36
|
+
* @param props Props for the DivNode | DivNode 的属性
|
|
37
|
+
*/
|
|
24
38
|
export declare function $createDivNode(props?: DivNodeProps): DivNode;
|
|
39
|
+
/**
|
|
40
|
+
* - EN: Type guard to check if a node is DivNode.
|
|
41
|
+
* - CN: 判断节点是否为 DivNode 的类型守卫。
|
|
42
|
+
*
|
|
43
|
+
* @param node Node to test | 要检测的节点
|
|
44
|
+
*/
|
|
25
45
|
export declare function $isDivNode(node: LexicalNode | null | undefined): node is DivNode;
|
|
@@ -77,7 +77,7 @@ var DivNode = class extends import_base.BaseElementNode {
|
|
|
77
77
|
}
|
|
78
78
|
isInline() {
|
|
79
79
|
var _a, _b;
|
|
80
|
-
const display = (_b = (_a = this.__props) == null ? void 0 : _a.style) == null ? void 0 : _b.display;
|
|
80
|
+
const display = ((_b = (_a = this.__props) == null ? void 0 : _a.style) == null ? void 0 : _b.display) ?? "block";
|
|
81
81
|
return display === "inline" || display === "inline-flex" || display === "inline-block" || display === "inline-grid" || display === "inline-table" || display === "inline-list-item";
|
|
82
82
|
}
|
|
83
83
|
getPropValue(key) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/components/Lexical/nodes/DivNode.tsx"],
|
|
4
|
-
"sourcesContent": ["import type { CSSProperties, HtmlHTMLAttributes } from 'react';\nimport type {\n DOMConversionMap,\n DOMConversionOutput,\n DOMExportOutput,\n LexicalNode,\n SerializedElementNode,\n Spread,\n} from 'lexical';\nimport { updateDomProps } from '../helpers';\nimport { BaseElementNode, type BaseElementProps } from './base';\n\nexport interface DivNodeProps extends HtmlHTMLAttributes<HTMLDivElement>, BaseElementProps {}\n\nexport type SerializedDivNode = Spread<\n {\n props?: DivNodeProps;\n },\n SerializedElementNode\n>;\n\nexport class DivNode extends BaseElementNode<DivNodeProps> {\n static getType(): string {\n return 'html.div';\n }\n\n static clone(node: DivNode): DivNode {\n return new DivNode({ ...node.__props, key: node.getKey() });\n }\n\n protected getForceDisplay(): CSSProperties['display'] {\n return undefined;\n }\n\n createDOM(): HTMLElement {\n const div = document.createElement('div');\n const domProps = this.getUnderlyingProps(this.__props);\n if (domProps) {\n updateDomProps(div, domProps);\n }\n return div;\n }\n\n updateDOM(prevNode: DivNode, dom: HTMLElement): boolean {\n const prevProps = prevNode.__props;\n const currentProps = this.__props;\n const propsChanged = !this.shallowEqual(prevProps, currentProps);\n if (propsChanged) {\n updateDomProps(dom, this.getUnderlyingProps(currentProps));\n }\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,qBAA+B;AAC/B,kBAAuD;
|
|
4
|
+
"sourcesContent": ["import type { CSSProperties, HtmlHTMLAttributes } from 'react';\nimport type {\n DOMConversionMap,\n DOMConversionOutput,\n DOMExportOutput,\n LexicalNode,\n SerializedElementNode,\n Spread,\n} from 'lexical';\nimport { updateDomProps } from '../helpers';\nimport { BaseElementNode, type BaseElementProps } from './base';\n\n/**\n * - EN: Props for the DivNode, combining DOM div attributes and element behavior flags.\n * - CN: DivNode 的属性,包含 DOM div 属性与元素行为标记。\n */\nexport interface DivNodeProps extends HtmlHTMLAttributes<HTMLDivElement>, BaseElementProps {}\n\nexport type SerializedDivNode = Spread<\n {\n props?: DivNodeProps;\n },\n SerializedElementNode\n>;\n\n/**\n * - EN: Lexical element node that renders a DOM div with controlled props.\n * - CN: 渲染为 DOM div 且可控制属性的 Lexical 元素节点。\n */\nexport class DivNode extends BaseElementNode<DivNodeProps> {\n static getType(): string {\n return 'html.div';\n }\n\n static clone(node: DivNode): DivNode {\n return new DivNode({ ...node.__props, key: node.getKey() });\n }\n\n protected getForceDisplay(): CSSProperties['display'] {\n return undefined;\n }\n\n createDOM(): HTMLElement {\n const div = document.createElement('div');\n const domProps = this.getUnderlyingProps(this.__props);\n if (domProps) {\n updateDomProps(div, domProps);\n }\n return div;\n }\n\n updateDOM(prevNode: DivNode, dom: HTMLElement): boolean {\n const prevProps = prevNode.__props;\n const currentProps = this.__props;\n const propsChanged = !this.shallowEqual(prevProps, currentProps);\n if (propsChanged) {\n updateDomProps(dom, this.getUnderlyingProps(currentProps));\n }\n return false;\n }\n\n static importDOM(): DOMConversionMap | null {\n return {\n div: (node: Node) => ({\n conversion: convertDivElement,\n priority: 1,\n }),\n };\n }\n\n static importJSON(serializedNode: SerializedDivNode): DivNode {\n return $createDivNode(serializedNode.props);\n }\n\n exportJSON(): SerializedDivNode {\n return {\n ...super.exportJSON(),\n props: this.__props,\n type: this.getType(),\n };\n }\n\n exportDOM(): DOMExportOutput {\n const element = this.createDOM();\n return { element };\n }\n\n isInline(): boolean {\n const display = this.__props?.style?.display ?? 'block';\n return (\n display === 'inline' ||\n display === 'inline-flex' ||\n display === 'inline-block' ||\n display === 'inline-grid' ||\n display === 'inline-table' ||\n display === 'inline-list-item'\n );\n }\n\n getPropValue<K extends keyof DivNodeProps>(key: K): DivNodeProps[K] | undefined {\n return this.__props?.[key];\n }\n setProps(props: DivNodeProps): void {\n const writable = this.getWritable();\n writable.__props = {\n ...writable.__props,\n ...props,\n style: {\n ...writable.__props?.style,\n ...props.style,\n },\n };\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n private shallowEqual(obj1: any, obj2: any): boolean {\n if (obj1 === obj2) return true;\n if (!obj1 || !obj2) return false;\n\n const keys1 = Object.keys(obj1);\n const keys2 = Object.keys(obj2);\n\n if (keys1.length !== keys2.length) return false;\n\n for (const key of keys1) {\n if (key === 'style') {\n // - EN: Special handling for style objects.\n // - CN: 特殊处理 style 对象。\n if (!this.shallowEqual(obj1[key], obj2[key])) return false;\n } else if (obj1[key] !== obj2[key]) {\n return false;\n }\n }\n\n return true;\n }\n}\n/**\n * - EN: Convert a DOM node to a DivNode during import.\n * - CN: 在导入时将 DOM 节点转换为 DivNode。\n *\n * @param domNode Source DOM node | 源 DOM 节点\n */\nfunction convertDivElement(domNode: Node): DOMConversionOutput {\n const element = domNode as HTMLElement;\n if (element.nodeName === 'DIV') {\n return { node: $createDivNode() };\n }\n return { node: null };\n}\n/**\n * - EN: Factory to create a DivNode.\n * - CN: 创建 DivNode 的工厂函数。\n *\n * @param props Props for the DivNode | DivNode 的属性\n */\nexport function $createDivNode(props?: DivNodeProps): DivNode {\n return new DivNode(props);\n}\n/**\n * - EN: Type guard to check if a node is DivNode.\n * - CN: 判断节点是否为 DivNode 的类型守卫。\n *\n * @param node Node to test | 要检测的节点\n */\nexport function $isDivNode(node: LexicalNode | null | undefined): node is DivNode {\n return node instanceof DivNode;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,qBAA+B;AAC/B,kBAAuD;AAmBhD,IAAM,UAAN,cAAsB,4BAA8B;AAAA,EACzD,OAAO,UAAkB;AACvB,WAAO;AAAA,EACT;AAAA,EAEA,OAAO,MAAM,MAAwB;AACnC,WAAO,IAAI,QAAQ,EAAE,GAAG,KAAK,SAAS,KAAK,KAAK,OAAO,EAAE,CAAC;AAAA,EAC5D;AAAA,EAEU,kBAA4C;AACpD,WAAO;AAAA,EACT;AAAA,EAEA,YAAyB;AACvB,UAAM,MAAM,SAAS,cAAc,KAAK;AACxC,UAAM,WAAW,KAAK,mBAAmB,KAAK,OAAO;AACrD,QAAI,UAAU;AACZ,yCAAe,KAAK,QAAQ;AAAA,IAC9B;AACA,WAAO;AAAA,EACT;A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,aAAO;AAC1B,QAAI,CAAC,QAAQ,CAAC;AAAM,aAAO;AAE3B,UAAM,QAAQ,OAAO,KAAK,IAAI;AAC9B,UAAM,QAAQ,OAAO,KAAK,IAAI;AAE9B,QAAI,MAAM,WAAW,MAAM;AAAQ,aAAO;AAE1C,eAAW,OAAO,OAAO;AACvB,UAAI,QAAQ,SAAS;AAGnB,YAAI,CAAC,KAAK,aAAa,KAAK,GAAG,GAAG,KAAK,GAAG,CAAC;AAAG,iBAAO;AAAA,MACvD,WAAW,KAAK,GAAG,MAAM,KAAK,GAAG,GAAG;AAClC,eAAO;AAAA,MACT;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;AAOA,SAAS,kBAAkB,SAAoC;AAC7D,QAAM,UAAU;AAChB,MAAI,QAAQ,aAAa,OAAO;AAC9B,WAAO,EAAE,MAAM,eAAe,EAAE;AAAA,EAClC;AACA,SAAO,EAAE,MAAM,KAAK;AACtB;AAOO,SAAS,eAAe,OAA+B;AAC5D,SAAO,IAAI,QAAQ,KAAK;AAC1B;AAOO,SAAS,WAAW,MAAuD;AAChF,SAAO,gBAAgB;AACzB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,9 +2,18 @@ import type { LexicalNode, NodeKey, SerializedTextNode, Spread } from 'lexical';
|
|
|
2
2
|
import { TextNode } from 'lexical';
|
|
3
3
|
import type { BaseNodeProps } from './base';
|
|
4
4
|
import { BaseNodeHelper } from './base';
|
|
5
|
+
/**
|
|
6
|
+
* - EN: Extra props for ExtendTextNode.
|
|
7
|
+
* - CN: ExtendTextNode 的附加属性。
|
|
8
|
+
*/
|
|
5
9
|
export interface ExtendTextNodeProps extends BaseNodeProps {
|
|
6
10
|
text?: string;
|
|
11
|
+
prefixText?: string;
|
|
7
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* - EN: A TextNode with extra behavior flags and controlled replacement.
|
|
15
|
+
* - CN: 带有额外行为标记并可控制替换行为的 TextNode。
|
|
16
|
+
*/
|
|
8
17
|
export declare class ExtendTextNode extends TextNode {
|
|
9
18
|
__props: ExtendTextNodeProps | undefined;
|
|
10
19
|
__base: BaseNodeHelper<ExtendTextNodeProps>;
|
|
@@ -16,9 +25,22 @@ export declare class ExtendTextNode extends TextNode {
|
|
|
16
25
|
static importJSON(serializedNode: SerializedExtendTextNode): ExtendTextNode;
|
|
17
26
|
exportJSON(): SerializedExtendTextNode;
|
|
18
27
|
}
|
|
19
|
-
|
|
28
|
+
type SerializedExtendTextNode = Spread<{
|
|
20
29
|
props?: ExtendTextNodeProps;
|
|
21
30
|
text: string;
|
|
22
31
|
}, SerializedTextNode>;
|
|
32
|
+
/**
|
|
33
|
+
* - EN: Factory to create an ExtendTextNode.
|
|
34
|
+
* - CN: 创建 ExtendTextNode 的工厂函数。
|
|
35
|
+
*
|
|
36
|
+
* @param props Props for the node | 节点的属性
|
|
37
|
+
*/
|
|
23
38
|
export declare function $createExtendTextNode(props?: ExtendTextNodeProps): ExtendTextNode;
|
|
39
|
+
/**
|
|
40
|
+
* - EN: Type guard to check whether a node is ExtendTextNode.
|
|
41
|
+
* - CN: 判断节点是否为 ExtendTextNode 的类型守卫。
|
|
42
|
+
*
|
|
43
|
+
* @param node Node to test | 要检测的节点
|
|
44
|
+
*/
|
|
24
45
|
export declare function $isExtendTextNode(node: LexicalNode | null | undefined): node is ExtendTextNode;
|
|
46
|
+
export {};
|
|
@@ -41,10 +41,18 @@ var ExtendTextNode = class extends import_lexical.TextNode {
|
|
|
41
41
|
this[key2] = method.bind(this.__base);
|
|
42
42
|
}
|
|
43
43
|
});
|
|
44
|
+
this.remove = (preserveEmptyParent) => {
|
|
45
|
+
var _a;
|
|
46
|
+
if (((_a = this.__props) == null ? void 0 : _a.canBeRemoved) === false) {
|
|
47
|
+
this.setTextContent(this.__props.prefixText ?? " ");
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
super.remove(preserveEmptyParent);
|
|
51
|
+
};
|
|
44
52
|
this.replace = (replaceWith, includeChildren) => {
|
|
45
53
|
var _a, _b;
|
|
46
54
|
if (((_a = this.__props) == null ? void 0 : _a.canBeReplaced) === false) {
|
|
47
|
-
this.setTextContent(((_b = this.__props) == null ? void 0 : _b.text) || "");
|
|
55
|
+
this.setTextContent(((_b = this.__props) == null ? void 0 : _b.text) || " ");
|
|
48
56
|
this.selectNext();
|
|
49
57
|
return this;
|
|
50
58
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAAyB;AAEzB,kBAA+B;
|
|
4
|
+
"sourcesContent": ["import type { LexicalNode, NodeKey, SerializedTextNode, Spread } from 'lexical';\nimport { TextNode } from 'lexical';\nimport type { BaseNodeProps } from './base';\nimport { BaseNodeHelper } from './base';\n\n/**\n * - EN: Extra props for ExtendTextNode.\n * - CN: ExtendTextNode 的附加属性。\n */\nexport interface ExtendTextNodeProps extends BaseNodeProps {\n text?: string;\n prefixText?: string;\n}\n\n/**\n * - EN: A TextNode with extra behavior flags and controlled replacement.\n * - CN: 带有额外行为标记并可控制替换行为的 TextNode。\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.remove = (preserveEmptyParent?: boolean): void => {\n if (this.__props?.canBeRemoved === false) {\n this.setTextContent(this.__props.prefixText ?? ' ');\n return;\n }\n super.remove(preserveEmptyParent);\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\ntype SerializedExtendTextNode = Spread<\n {\n props?: ExtendTextNodeProps;\n text: string;\n },\n SerializedTextNode\n>;\n\n/**\n * - EN: Factory to create an ExtendTextNode.\n * - CN: 创建 ExtendTextNode 的工厂函数。\n *\n * @param props Props for the node | 节点的属性\n */\nexport function $createExtendTextNode(props?: ExtendTextNodeProps): ExtendTextNode {\n return new ExtendTextNode(props);\n}\n\n/**\n * - EN: Type guard to check whether a node is ExtendTextNode.\n * - CN: 判断节点是否为 ExtendTextNode 的类型守卫。\n *\n * @param node Node to test | 要检测的节点\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;AAexB,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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