@payloadcms/richtext-lexical 3.61.0-canary.5 → 3.61.0-internal.1898a30
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/dist/cell/rscEntry.d.ts +2 -10
- package/dist/cell/rscEntry.d.ts.map +1 -1
- package/dist/cell/rscEntry.js +1 -2
- package/dist/cell/rscEntry.js.map +1 -1
- package/dist/exports/client/Field-5VLZM7KJ.js +2 -0
- package/dist/exports/client/Field-5VLZM7KJ.js.map +7 -0
- package/dist/exports/client/RelationshipComponent-UCIWIEVD.js +2 -0
- package/dist/exports/client/RelationshipComponent-UCIWIEVD.js.map +7 -0
- package/dist/exports/client/bundled.css +1 -1
- package/dist/exports/client/chunk-52JG5GGJ.js +2 -0
- package/dist/exports/client/chunk-52JG5GGJ.js.map +7 -0
- package/dist/exports/client/chunk-U4AOQOHA.js +12 -0
- package/dist/exports/client/chunk-U4AOQOHA.js.map +7 -0
- package/dist/exports/client/component-5YLBQB5B.js +2 -0
- package/dist/exports/client/component-5YLBQB5B.js.map +7 -0
- package/dist/exports/client/componentInline-QEXUNJU4.js +2 -0
- package/dist/exports/client/index.js +22 -22
- package/dist/exports/client/index.js.map +3 -3
- package/dist/exports/react/index.d.ts +1 -1
- package/dist/exports/react/index.d.ts.map +1 -1
- package/dist/exports/react/index.js.map +1 -1
- package/dist/features/blocks/client/component/BlockContent.js +1 -1
- package/dist/features/blocks/client/component/BlockContent.js.map +1 -1
- package/dist/features/blocks/client/component/index.d.ts +1 -0
- package/dist/features/blocks/client/component/index.d.ts.map +1 -1
- package/dist/features/blocks/client/component/index.js +23 -20
- package/dist/features/blocks/client/component/index.js.map +1 -1
- package/dist/features/blocks/client/componentInline/index.d.ts +2 -1
- package/dist/features/blocks/client/componentInline/index.d.ts.map +1 -1
- package/dist/features/blocks/client/componentInline/index.js +6 -6
- package/dist/features/blocks/client/componentInline/index.js.map +1 -1
- package/dist/features/blocks/client/nodes/BlocksNode.d.ts +1 -1
- package/dist/features/blocks/client/nodes/BlocksNode.d.ts.map +1 -1
- package/dist/features/blocks/client/nodes/BlocksNode.js +2 -1
- package/dist/features/blocks/client/nodes/BlocksNode.js.map +1 -1
- package/dist/features/blocks/client/nodes/InlineBlocksNode.d.ts +1 -1
- package/dist/features/blocks/client/nodes/InlineBlocksNode.d.ts.map +1 -1
- package/dist/features/blocks/client/nodes/InlineBlocksNode.js +2 -1
- package/dist/features/blocks/client/nodes/InlineBlocksNode.js.map +1 -1
- package/dist/features/blocks/server/nodes/BlocksNode.d.ts +1 -0
- package/dist/features/blocks/server/nodes/BlocksNode.d.ts.map +1 -1
- package/dist/features/blocks/server/nodes/BlocksNode.js +6 -0
- package/dist/features/blocks/server/nodes/BlocksNode.js.map +1 -1
- package/dist/features/blocks/server/nodes/InlineBlocksNode.d.ts +1 -1
- package/dist/features/blocks/server/nodes/InlineBlocksNode.d.ts.map +1 -1
- package/dist/features/blocks/server/nodes/InlineBlocksNode.js +3 -2
- package/dist/features/blocks/server/nodes/InlineBlocksNode.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/Component/index.d.ts +2 -14
- package/dist/features/converters/lexicalToJSX/Component/index.d.ts.map +1 -1
- package/dist/features/converters/lexicalToJSX/Component/index.js +4 -2
- package/dist/features/converters/lexicalToJSX/Component/index.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/index.d.ts +16 -1
- package/dist/features/converters/lexicalToJSX/converter/index.d.ts.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/index.js +76 -4
- package/dist/features/converters/lexicalToJSX/converter/index.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/types.d.ts +14 -10
- package/dist/features/converters/lexicalToJSX/converter/types.d.ts.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/types.js.map +1 -1
- package/dist/features/debug/jsxConverter/client/plugin/index.js +1 -1
- package/dist/features/debug/jsxConverter/client/plugin/index.js.map +1 -1
- package/dist/features/migrations/slateToLexical/feature.server.d.ts +29 -0
- package/dist/features/migrations/slateToLexical/feature.server.d.ts.map +1 -1
- package/dist/features/migrations/slateToLexical/feature.server.js +18 -0
- package/dist/features/migrations/slateToLexical/feature.server.js.map +1 -1
- package/dist/features/relationship/client/components/RelationshipComponent.d.ts +1 -1
- package/dist/features/relationship/client/components/RelationshipComponent.d.ts.map +1 -1
- package/dist/features/relationship/client/components/RelationshipComponent.js +2 -2
- package/dist/features/relationship/client/components/RelationshipComponent.js.map +1 -1
- package/dist/features/relationship/server/nodes/RelationshipNode.d.ts +1 -0
- package/dist/features/relationship/server/nodes/RelationshipNode.d.ts.map +1 -1
- package/dist/features/relationship/server/nodes/RelationshipNode.js +6 -0
- package/dist/features/relationship/server/nodes/RelationshipNode.js.map +1 -1
- package/dist/features/typesServer.d.ts +2 -2
- package/dist/features/typesServer.d.ts.map +1 -1
- package/dist/features/typesServer.js.map +1 -1
- package/dist/features/upload/client/component/index.d.ts +1 -0
- package/dist/features/upload/client/component/index.d.ts.map +1 -1
- package/dist/features/upload/client/component/index.js +2 -2
- package/dist/features/upload/client/component/index.js.map +1 -1
- package/dist/features/upload/client/nodes/UploadNode.d.ts +2 -2
- package/dist/features/upload/client/nodes/UploadNode.d.ts.map +1 -1
- package/dist/features/upload/client/nodes/UploadNode.js +2 -1
- package/dist/features/upload/client/nodes/UploadNode.js.map +1 -1
- package/dist/features/upload/server/nodes/UploadNode.d.ts +2 -1
- package/dist/features/upload/server/nodes/UploadNode.d.ts.map +1 -1
- package/dist/features/upload/server/nodes/UploadNode.js +6 -0
- package/dist/features/upload/server/nodes/UploadNode.js.map +1 -1
- package/dist/field/Field.d.ts.map +1 -1
- package/dist/field/Field.js +50 -38
- package/dist/field/Field.js.map +1 -1
- package/dist/field/RichTextViewProvider.d.ts +84 -0
- package/dist/field/RichTextViewProvider.d.ts.map +1 -0
- package/dist/field/RichTextViewProvider.js +92 -0
- package/dist/field/RichTextViewProvider.js.map +1 -0
- package/dist/field/ViewSelector.d.ts +4 -0
- package/dist/field/ViewSelector.d.ts.map +1 -0
- package/dist/field/ViewSelector.js +89 -0
- package/dist/field/ViewSelector.js.map +1 -0
- package/dist/field/bundled.css +1 -1
- package/dist/field/index.d.ts.map +1 -1
- package/dist/field/index.js +63 -41
- package/dist/field/index.js.map +1 -1
- package/dist/field/rscEntry.d.ts +2 -3
- package/dist/field/rscEntry.d.ts.map +1 -1
- package/dist/field/rscEntry.js +15 -1
- package/dist/field/rscEntry.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -24
- package/dist/index.js.map +1 -1
- package/dist/lexical/LexicalEditor.d.ts.map +1 -1
- package/dist/lexical/LexicalEditor.js +2 -1
- package/dist/lexical/LexicalEditor.js.map +1 -1
- package/dist/lexical/LexicalProvider.d.ts.map +1 -1
- package/dist/lexical/LexicalProvider.js +12 -3
- package/dist/lexical/LexicalProvider.js.map +1 -1
- package/dist/lexical/config/client/loader.d.ts.map +1 -1
- package/dist/lexical/config/client/loader.js +2 -4
- package/dist/lexical/config/client/loader.js.map +1 -1
- package/dist/lexical/nodes/index.d.ts +12 -2
- package/dist/lexical/nodes/index.d.ts.map +1 -1
- package/dist/lexical/nodes/index.js +195 -2
- package/dist/lexical/nodes/index.js.map +1 -1
- package/dist/lexical/plugins/NodeViewOverridePlugin/index.d.ts +2 -0
- package/dist/lexical/plugins/NodeViewOverridePlugin/index.d.ts.map +1 -0
- package/dist/lexical/plugins/NodeViewOverridePlugin/index.js +48 -0
- package/dist/lexical/plugins/NodeViewOverridePlugin/index.js.map +1 -0
- package/dist/lexical/plugins/handles/utils/setHandlePosition.d.ts.map +1 -1
- package/dist/lexical/plugins/handles/utils/setHandlePosition.js +1 -1
- package/dist/lexical/plugins/handles/utils/setHandlePosition.js.map +1 -1
- package/dist/lexical/theme/EditorTheme.d.ts.map +1 -1
- package/dist/lexical/theme/EditorTheme.js +3 -39
- package/dist/lexical/theme/EditorTheme.js.map +1 -1
- package/dist/lexical/ui/ContentEditable.d.ts.map +1 -1
- package/dist/lexical/ui/ContentEditable.js +16 -9
- package/dist/lexical/ui/ContentEditable.js.map +1 -1
- package/dist/types.d.ts +138 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/editorConfigFactory.js +1 -1
- package/dist/utilities/editorConfigFactory.js.map +1 -1
- package/dist/utilities/generateImportMap.d.ts +2 -0
- package/dist/utilities/generateImportMap.d.ts.map +1 -1
- package/dist/utilities/generateImportMap.js +6 -13
- package/dist/utilities/generateImportMap.js.map +1 -1
- package/dist/{getDefaultSanitizedEditorConfig.d.ts → utilities/getDefaultSanitizedEditorConfig.d.ts} +1 -1
- package/dist/utilities/getDefaultSanitizedEditorConfig.d.ts.map +1 -0
- package/dist/{getDefaultSanitizedEditorConfig.js → utilities/getDefaultSanitizedEditorConfig.js} +2 -2
- package/dist/utilities/getDefaultSanitizedEditorConfig.js.map +1 -0
- package/dist/utilities/initLexicalFeatures.d.ts.map +1 -1
- package/dist/utilities/initLexicalFeatures.js +12 -13
- package/dist/utilities/initLexicalFeatures.js.map +1 -1
- package/dist/validate/hasText.d.ts +6 -1
- package/dist/validate/hasText.d.ts.map +1 -1
- package/dist/validate/hasText.js +10 -4
- package/dist/validate/hasText.js.map +1 -1
- package/package.json +6 -6
- package/dist/exports/client/Field-YYMTSGSP.js +0 -2
- package/dist/exports/client/Field-YYMTSGSP.js.map +0 -7
- package/dist/exports/client/RelationshipComponent-JXQOFHXF.js +0 -2
- package/dist/exports/client/RelationshipComponent-JXQOFHXF.js.map +0 -7
- package/dist/exports/client/chunk-AFXLIYGL.js +0 -12
- package/dist/exports/client/chunk-AFXLIYGL.js.map +0 -7
- package/dist/exports/client/chunk-RPFDD27K.js +0 -2
- package/dist/exports/client/chunk-RPFDD27K.js.map +0 -7
- package/dist/exports/client/component-WT25HAJA.js +0 -2
- package/dist/exports/client/component-WT25HAJA.js.map +0 -7
- package/dist/exports/client/componentInline-BVC77WQC.js +0 -2
- package/dist/getDefaultSanitizedEditorConfig.d.ts.map +0 -1
- package/dist/getDefaultSanitizedEditorConfig.js.map +0 -1
- /package/dist/exports/client/{componentInline-BVC77WQC.js.map → componentInline-QEXUNJU4.js.map} +0 -0
|
@@ -1,19 +1,91 @@
|
|
|
1
1
|
/* eslint-disable no-console */import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { hasText } from '../../../../validate/hasText.js';
|
|
4
|
+
/**
|
|
5
|
+
* Creates a JSX converter from a NodeMapValue
|
|
6
|
+
*/
|
|
7
|
+
function createConverterFromNodeMapValue(viewDef) {
|
|
8
|
+
return args => {
|
|
9
|
+
const converterArgs = {
|
|
10
|
+
...args,
|
|
11
|
+
isEditor: false,
|
|
12
|
+
isJSXConverter: true
|
|
13
|
+
};
|
|
14
|
+
// If Component is provided, use it
|
|
15
|
+
if (viewDef.Component) {
|
|
16
|
+
return viewDef.Component(converterArgs);
|
|
17
|
+
}
|
|
18
|
+
// If html is provided (as a function or string), use it
|
|
19
|
+
// Note: Using span instead of div to avoid forcing block-level semantics
|
|
20
|
+
if (viewDef.html) {
|
|
21
|
+
const htmlContent = typeof viewDef.html === 'function' ? viewDef.html(converterArgs) : viewDef.html;
|
|
22
|
+
return /*#__PURE__*/_jsx("span", {
|
|
23
|
+
dangerouslySetInnerHTML: {
|
|
24
|
+
__html: htmlContent
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return null;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Converts a LexicalEditorNodeMap into JSXConverters
|
|
33
|
+
*/
|
|
34
|
+
function nodeMapToConverters(nodeMap) {
|
|
35
|
+
const converters = {};
|
|
36
|
+
for (const [nodeType, value] of Object.entries(nodeMap)) {
|
|
37
|
+
if (!value || typeof value !== 'object') {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
// Handle special keys: blocks, inlineBlocks
|
|
41
|
+
if (nodeType === 'blocks') {
|
|
42
|
+
converters.blocks = {};
|
|
43
|
+
for (const [blockType, _viewDef] of Object.entries(value)) {
|
|
44
|
+
const viewDef = _viewDef;
|
|
45
|
+
if (viewDef.Component || viewDef.html) {
|
|
46
|
+
converters.blocks[blockType] = createConverterFromNodeMapValue(viewDef);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (nodeType === 'inlineBlocks') {
|
|
52
|
+
converters.inlineBlocks = {};
|
|
53
|
+
for (const [blockType, _viewDef] of Object.entries(value)) {
|
|
54
|
+
const viewDef = _viewDef;
|
|
55
|
+
if (viewDef.Component || viewDef.html) {
|
|
56
|
+
converters.inlineBlocks[blockType] = createConverterFromNodeMapValue(viewDef);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
// Handle regular node types
|
|
62
|
+
const viewDef = value;
|
|
63
|
+
if (viewDef.Component || viewDef.html) {
|
|
64
|
+
converters[nodeType] = createConverterFromNodeMapValue(viewDef);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return converters;
|
|
68
|
+
}
|
|
4
69
|
export function convertLexicalToJSX({
|
|
5
70
|
converters,
|
|
6
71
|
data,
|
|
7
72
|
disableIndent,
|
|
8
|
-
disableTextAlign
|
|
73
|
+
disableTextAlign,
|
|
74
|
+
nodeMap
|
|
9
75
|
}) {
|
|
10
76
|
if (hasText(data)) {
|
|
77
|
+
// Merge nodeMap converters with existing converters
|
|
78
|
+
// NodeMap converters override existing converters
|
|
79
|
+
const mergedConverters = nodeMap ? {
|
|
80
|
+
...converters,
|
|
81
|
+
...nodeMapToConverters(nodeMap)
|
|
82
|
+
} : converters;
|
|
11
83
|
return convertLexicalNodesToJSX({
|
|
12
|
-
converters,
|
|
84
|
+
converters: mergedConverters,
|
|
13
85
|
disableIndent,
|
|
14
86
|
disableTextAlign,
|
|
15
|
-
nodes: data
|
|
16
|
-
parent: data
|
|
87
|
+
nodes: data.root.children,
|
|
88
|
+
parent: data.root
|
|
17
89
|
});
|
|
18
90
|
}
|
|
19
91
|
return /*#__PURE__*/_jsx(_Fragment, {});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["jsx","_jsx","Fragment","_Fragment","React","hasText","convertLexicalToJSX","converters","data","disableIndent","disableTextAlign","convertLexicalNodesToJSX","nodes","root","children","parent","unknownConverter","unknown","jsxArray","map","node","i","converterForNode","type","blocks","fields","blockType","console","error","inlineBlocks","reactNode","converted","childIndex","nodesToJSX","args","style","Array","isArray","includes","format","textAlign","indent","paddingInlineStart","Number","isValidElement","newStyle","props","cloneElement","key","filter","Boolean"],"sources":["../../../../../src/features/converters/lexicalToJSX/converter/index.tsx"],"sourcesContent":["/* eslint-disable no-console */\nimport type { SerializedEditorState, SerializedLexicalNode } from 'lexical'\n\nimport React from 'react'\n\nimport type { SerializedBlockNode, SerializedInlineBlockNode } from '../../../../nodeTypes.js'\nimport type { JSXConverter, JSXConverters, SerializedLexicalNodeWithParent } from './types.js'\n\nimport { hasText } from '../../../../validate/hasText.js'\n\nexport type ConvertLexicalToJSXArgs = {\n converters: JSXConverters\n data: SerializedEditorState\n disableIndent?: boolean | string[]\n disableTextAlign?: boolean | string[]\n}\n\nexport function convertLexicalToJSX({\n converters,\n data,\n disableIndent,\n disableTextAlign,\n}: ConvertLexicalToJSXArgs): React.ReactNode {\n if (hasText(data)) {\n return convertLexicalNodesToJSX({\n converters,\n disableIndent,\n disableTextAlign,\n nodes: data?.root?.children,\n parent: data?.root,\n })\n }\n return <></>\n}\n\nexport function convertLexicalNodesToJSX({\n converters,\n disableIndent,\n disableTextAlign,\n nodes,\n parent,\n}: {\n converters: JSXConverters\n disableIndent?: boolean | string[]\n disableTextAlign?: boolean | string[]\n nodes: SerializedLexicalNode[]\n parent: SerializedLexicalNodeWithParent\n}): React.ReactNode[] {\n const unknownConverter: JSXConverter<any> = converters.unknown as JSXConverter<any>\n\n const jsxArray: React.ReactNode[] = nodes.map((node, i) => {\n let converterForNode: JSXConverter<any> | undefined\n if (node.type === 'block') {\n converterForNode = converters?.blocks?.[(node as SerializedBlockNode)?.fields?.blockType]\n if (!converterForNode && !unknownConverter) {\n console.error(\n `Lexical => JSX converter: Blocks converter: found ${(node as SerializedBlockNode)?.fields?.blockType} block, but no converter is provided`,\n )\n }\n } else if (node.type === 'inlineBlock') {\n converterForNode =\n converters?.inlineBlocks?.[(node as SerializedInlineBlockNode)?.fields?.blockType]\n if (!converterForNode && !unknownConverter) {\n console.error(\n `Lexical => JSX converter: Inline Blocks converter: found ${(node as SerializedInlineBlockNode)?.fields?.blockType} inline block, but no converter is provided`,\n )\n }\n } else {\n converterForNode = converters[node.type] as JSXConverter<any>\n }\n\n try {\n if (!converterForNode && unknownConverter) {\n converterForNode = unknownConverter\n }\n\n let reactNode: React.ReactNode\n if (converterForNode) {\n const converted =\n typeof converterForNode === 'function'\n ? converterForNode({\n childIndex: i,\n converters,\n node,\n nodesToJSX: (args) => {\n return convertLexicalNodesToJSX({\n converters: args.converters ?? converters,\n disableIndent: args.disableIndent ?? disableIndent,\n disableTextAlign: args.disableTextAlign ?? disableTextAlign,\n nodes: args.nodes,\n parent: args.parent ?? {\n ...node,\n parent,\n },\n })\n },\n parent,\n })\n : converterForNode\n reactNode = converted\n } else {\n reactNode = <span key={i}>unknown node</span>\n }\n\n const style: React.CSSProperties = {}\n\n // Check if disableTextAlign is not true and does not include node type\n if (\n !disableTextAlign &&\n (!Array.isArray(disableTextAlign) || !disableTextAlign?.includes(node.type))\n ) {\n if ('format' in node && node.format) {\n switch (node.format) {\n case 'center':\n style.textAlign = 'center'\n break\n case 'end':\n style.textAlign = 'right'\n break\n case 'justify':\n style.textAlign = 'justify'\n break\n case 'left':\n //style.textAlign = 'left'\n // Do nothing, as left is the default\n break\n case 'right':\n style.textAlign = 'right'\n break\n case 'start':\n style.textAlign = 'left'\n break\n }\n }\n }\n\n if (\n !disableIndent &&\n (!Array.isArray(disableIndent) || !disableIndent?.includes(node.type))\n ) {\n if ('indent' in node && node.indent && node.type !== 'listitem') {\n // the unit should be px. Do not change it to rem, em, or something else.\n // The quantity should be 40px. Do not change it either.\n // See rationale in\n // https://github.com/payloadcms/payload/issues/13130#issuecomment-3058348085\n style.paddingInlineStart = `${Number(node.indent) * 40}px`\n }\n }\n\n if (React.isValidElement(reactNode)) {\n // Inject style into reactNode\n if (style.textAlign || style.paddingInlineStart) {\n const newStyle = {\n ...style,\n // @ts-expect-error type better later\n ...(reactNode?.props?.style ?? {}),\n // reactNode style comes after, thus a textAlign specified in the converter has priority over the one we inject here\n }\n\n return React.cloneElement(reactNode, {\n key: i,\n // @ts-expect-error type better later\n style: newStyle,\n })\n }\n return React.cloneElement(reactNode, {\n key: i,\n })\n }\n\n return reactNode\n } catch (error) {\n console.error('Error converting lexical node to JSX:', error, 'node:', node)\n return null\n }\n })\n\n return jsxArray.filter(Boolean)\n}\n"],"mappings":"AAAA,+BAA6B,SAAAA,GAAA,IAAAC,IAAA,EAAAC,QAAA,IAAAC,SAAA;AAG7B,OAAOC,KAAA,MAAW;AAKlB,SAASC,OAAO,QAAQ;AASxB,OAAO,SAASC,oBAAoB;EAClCC,UAAU;EACVC,IAAI;EACJC,aAAa;EACbC;AAAgB,CACQ;EACxB,IAAIL,OAAA,CAAQG,IAAA,GAAO;IACjB,OAAOG,wBAAA,CAAyB;MAC9BJ,UAAA;MACAE,aAAA;MACAC,gBAAA;MACAE,KAAA,EAAOJ,IAAA,EAAMK,IAAA,EAAMC,QAAA;MACnBC,MAAA,EAAQP,IAAA,EAAMK;IAChB;EACF;EACA,oBAAOZ,IAAA,CAAAE,SAAA;AACT;AAEA,OAAO,SAASQ,yBAAyB;EACvCJ,UAAU;EACVE,aAAa;EACbC,gBAAgB;EAChBE,KAAK;EACLG;AAAM,CAOP;EACC,MAAMC,gBAAA,GAAsCT,UAAA,CAAWU,OAAO;EAE9D,MAAMC,QAAA,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IL,KAAA,CAAMO,kBAAkB,EAAE;UAC/C,MAAMG,QAAA,GAAW;YACf,GAAGV,KAAK;YACR;YACA,IAAIL,SAAA,EAAWgB,KAAA,EAAOX,KAAA,IAAS,CAAC,CAAC;UAEnC;UAEA,oBAAO/B,KAAA,CAAM2C,YAAY,CAACjB,SAAA,EAAW;YACnCkB,GAAA,EAAK3B,CAAA;YACL;YACAc,KAAA,EAAOU;UACT;QACF;QACA,oBAAOzC,KAAA,CAAM2C,YAAY,CAACjB,SAAA,EAAW;UACnCkB,GAAA,EAAK3B;QACP;MACF;MAEA,OAAOS,SAAA;IACT,EAAE,OAAOF,KAAA,EAAO;MACdD,OAAA,CAAQC,KAAK,CAAC,yCAAyCA,KAAA,EAAO,SAASR,IAAA;MACvE,OAAO;IACT;EACF;EAEA,OAAOF,QAAA,CAAS+B,MAAM,CAACC,OAAA;AACzB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["jsx","_jsx","Fragment","_Fragment","React","hasText","createConverterFromNodeMapValue","viewDef","args","converterArgs","isEditor","isJSXConverter","Component","html","htmlContent","dangerouslySetInnerHTML","__html","nodeMapToConverters","nodeMap","converters","nodeType","value","Object","entries","blocks","blockType","_viewDef","inlineBlocks","convertLexicalToJSX","data","disableIndent","disableTextAlign","mergedConverters","convertLexicalNodesToJSX","nodes","root","children","parent","unknownConverter","unknown","jsxArray","map","node","i","converterForNode","type","fields","console","error","reactNode","converted","childIndex","nodesToJSX","style","Array","isArray","includes","format","textAlign","indent","paddingInlineStart","Number","isValidElement","newStyle","props","cloneElement","key","filter","Boolean"],"sources":["../../../../../src/features/converters/lexicalToJSX/converter/index.tsx"],"sourcesContent":["/* eslint-disable no-console */\nimport type { SerializedEditorState, SerializedLexicalNode } from 'lexical'\n\nimport React from 'react'\n\nimport type { SerializedBlockNode, SerializedInlineBlockNode } from '../../../../nodeTypes.js'\nimport type { LexicalEditorNodeMap, NodeMapValue } from '../../../../types.js'\nimport type { JSXConverter, JSXConverters, SerializedLexicalNodeWithParent } from './types.js'\n\nimport { hasText } from '../../../../validate/hasText.js'\n\n/**\n * Creates a JSX converter from a NodeMapValue\n */\nfunction createConverterFromNodeMapValue(viewDef: NodeMapValue): JSXConverter {\n return (args) => {\n const converterArgs = {\n ...args,\n isEditor: false as const,\n isJSXConverter: true as const,\n }\n\n // If Component is provided, use it\n if (viewDef.Component) {\n return viewDef.Component(converterArgs)\n }\n\n // If html is provided (as a function or string), use it\n // Note: Using span instead of div to avoid forcing block-level semantics\n if (viewDef.html) {\n const htmlContent =\n typeof viewDef.html === 'function' ? viewDef.html(converterArgs) : viewDef.html\n\n return <span dangerouslySetInnerHTML={{ __html: htmlContent }} />\n }\n\n return null\n }\n}\n\n/**\n * Converts a LexicalEditorNodeMap into JSXConverters\n */\nfunction nodeMapToConverters(nodeMap: LexicalEditorNodeMap): JSXConverters {\n const converters: JSXConverters = {}\n\n for (const [nodeType, value] of Object.entries(nodeMap)) {\n if (!value || typeof value !== 'object') {\n continue\n }\n\n // Handle special keys: blocks, inlineBlocks\n if (nodeType === 'blocks') {\n converters.blocks = {}\n for (const [blockType, _viewDef] of Object.entries(value)) {\n const viewDef = _viewDef as NodeMapValue\n if (viewDef.Component || viewDef.html) {\n converters.blocks[blockType] = createConverterFromNodeMapValue(viewDef)\n }\n }\n continue\n }\n\n if (nodeType === 'inlineBlocks') {\n converters.inlineBlocks = {}\n for (const [blockType, _viewDef] of Object.entries(value)) {\n const viewDef = _viewDef as NodeMapValue\n if (viewDef.Component || viewDef.html) {\n converters.inlineBlocks[blockType] = createConverterFromNodeMapValue(viewDef)\n }\n }\n continue\n }\n\n // Handle regular node types\n const viewDef = value as NodeMapValue\n\n if (viewDef.Component || viewDef.html) {\n converters[nodeType] = createConverterFromNodeMapValue(viewDef)\n }\n }\n\n return converters\n}\n\nexport type ConvertLexicalToJSXArgs = {\n converters: JSXConverters\n /**\n * Serialized editor state to render.\n */\n data: SerializedEditorState\n /**\n * If true, disables indentation globally. If an array, disables for specific node `type` values.\n */\n disableIndent?: boolean | string[]\n /**\n * If true, disables text alignment globally. If an array, disables for specific node `type` values.\n */\n disableTextAlign?: boolean | string[]\n /**\n * You can use the lexical editor node map or view map as converters. NodeMap converters will override converters passed\n * in the `converters` prop. If a LexicalEditorViewMap is provided, the `default` view will be used.\n */\n nodeMap?: LexicalEditorNodeMap\n}\n\nexport function convertLexicalToJSX({\n converters,\n data,\n disableIndent,\n disableTextAlign,\n nodeMap,\n}: ConvertLexicalToJSXArgs): React.ReactNode {\n if (hasText(data)) {\n // Merge nodeMap converters with existing converters\n // NodeMap converters override existing converters\n const mergedConverters = nodeMap\n ? {\n ...converters,\n ...nodeMapToConverters(nodeMap),\n }\n : converters\n\n return convertLexicalNodesToJSX({\n converters: mergedConverters,\n disableIndent,\n disableTextAlign,\n nodes: data.root.children,\n parent: data.root,\n })\n }\n return <></>\n}\n\nexport function convertLexicalNodesToJSX({\n converters,\n disableIndent,\n disableTextAlign,\n nodes,\n parent,\n}: {\n converters: JSXConverters\n disableIndent?: boolean | string[]\n disableTextAlign?: boolean | string[]\n nodes: SerializedLexicalNode[]\n parent: SerializedLexicalNodeWithParent\n}): React.ReactNode[] {\n const unknownConverter: JSXConverter<any> = converters.unknown as JSXConverter<any>\n\n const jsxArray: React.ReactNode[] = nodes.map((node, i) => {\n let converterForNode: JSXConverter<any> | undefined\n if (node.type === 'block') {\n converterForNode = converters?.blocks?.[(node as SerializedBlockNode)?.fields?.blockType]\n if (!converterForNode && !unknownConverter) {\n console.error(\n `Lexical => JSX converter: Blocks converter: found ${(node as SerializedBlockNode)?.fields?.blockType} block, but no converter is provided`,\n )\n }\n } else if (node.type === 'inlineBlock') {\n converterForNode =\n converters?.inlineBlocks?.[(node as SerializedInlineBlockNode)?.fields?.blockType]\n if (!converterForNode && !unknownConverter) {\n console.error(\n `Lexical => JSX converter: Inline Blocks converter: found ${(node as SerializedInlineBlockNode)?.fields?.blockType} inline block, but no converter is provided`,\n )\n }\n } else {\n converterForNode = converters[node.type] as JSXConverter<any>\n }\n\n try {\n if (!converterForNode && unknownConverter) {\n converterForNode = unknownConverter\n }\n\n let reactNode: React.ReactNode\n if (converterForNode) {\n const converted =\n typeof converterForNode === 'function'\n ? converterForNode({\n childIndex: i,\n converters,\n node,\n nodesToJSX: (args) => {\n return convertLexicalNodesToJSX({\n converters: args.converters ?? converters,\n disableIndent: args.disableIndent ?? disableIndent,\n disableTextAlign: args.disableTextAlign ?? disableTextAlign,\n nodes: args.nodes,\n parent: args.parent ?? {\n ...node,\n parent,\n },\n })\n },\n parent,\n })\n : converterForNode\n reactNode = converted\n } else {\n reactNode = <span key={i}>unknown node</span>\n }\n\n const style: React.CSSProperties = {}\n\n // Check if disableTextAlign is not true and does not include node type\n if (\n !disableTextAlign &&\n (!Array.isArray(disableTextAlign) || !disableTextAlign?.includes(node.type))\n ) {\n if ('format' in node && node.format) {\n switch (node.format) {\n case 'center':\n style.textAlign = 'center'\n break\n case 'end':\n style.textAlign = 'right'\n break\n case 'justify':\n style.textAlign = 'justify'\n break\n case 'left':\n //style.textAlign = 'left'\n // Do nothing, as left is the default\n break\n case 'right':\n style.textAlign = 'right'\n break\n case 'start':\n style.textAlign = 'left'\n break\n }\n }\n }\n\n if (\n !disableIndent &&\n (!Array.isArray(disableIndent) || !disableIndent?.includes(node.type))\n ) {\n if ('indent' in node && node.indent && node.type !== 'listitem') {\n // the unit should be px. Do not change it to rem, em, or something else.\n // The quantity should be 40px. Do not change it either.\n // See rationale in\n // https://github.com/payloadcms/payload/issues/13130#issuecomment-3058348085\n style.paddingInlineStart = `${Number(node.indent) * 40}px`\n }\n }\n\n if (React.isValidElement(reactNode)) {\n // Inject style into reactNode\n if (style.textAlign || style.paddingInlineStart) {\n const newStyle = {\n ...style,\n // @ts-expect-error type better later\n ...(reactNode?.props?.style ?? {}),\n // reactNode style comes after, thus a textAlign specified in the converter has priority over the one we inject here\n }\n\n return React.cloneElement(reactNode, {\n key: i,\n // @ts-expect-error type better later\n style: newStyle,\n })\n }\n return React.cloneElement(reactNode, {\n key: i,\n })\n }\n\n return reactNode\n } catch (error) {\n console.error('Error converting lexical node to JSX:', error, 'node:', node)\n return null\n }\n })\n\n return jsxArray.filter(Boolean)\n}\n"],"mappings":"AAAA,+BAA6B,SAAAA,GAAA,IAAAC,IAAA,EAAAC,QAAA,IAAAC,SAAA;AAG7B,OAAOC,KAAA,MAAW;AAMlB,SAASC,OAAO,QAAQ;AAExB;;;AAGA,SAASC,gCAAgCC,OAAqB;EAC5D,OAAQC,IAAA;IACN,MAAMC,aAAA,GAAgB;MACpB,GAAGD,IAAI;MACPE,QAAA,EAAU;MACVC,cAAA,EAAgB;IAClB;IAEA;IACA,IAAIJ,OAAA,CAAQK,SAAS,EAAE;MACrB,OAAOL,OAAA,CAAQK,SAAS,CAACH,aAAA;IAC3B;IAEA;IACA;IACA,IAAIF,OAAA,CAAQM,IAAI,EAAE;MAChB,MAAMC,WAAA,GACJ,OAAOP,OAAA,CAAQM,IAAI,KAAK,aAAaN,OAAA,CAAQM,IAAI,CAACJ,aAAA,IAAiBF,OAAA,CAAQM,IAAI;MAEjF,oBAAOZ,IAAA,CAAC;QAAKc,uBAAA,EAAyB;UAAEC,MAAA,EAAQF;QAAY;;IAC9D;IAEA,OAAO;EACT;AACF;AAEA;;;AAGA,SAASG,oBAAoBC,OAA6B;EACxD,MAAMC,UAAA,GAA4B,CAAC;EAEnC,KAAK,MAAM,CAACC,QAAA,EAAUC,KAAA,CAAM,IAAIC,MAAA,CAAOC,OAAO,CAACL,OAAA,GAAU;IACvD,IAAI,CAACG,KAAA,IAAS,OAAOA,KAAA,KAAU,UAAU;MACvC;IACF;IAEA;IACA,IAAID,QAAA,KAAa,UAAU;MACzBD,UAAA,CAAWK,MAAM,GAAG,CAAC;MACrB,KAAK,MAAM,CAACC,SAAA,EAAWC,QAAA,CAAS,IAAIJ,MAAA,CAAOC,OAAO,CAACF,KAAA,GAAQ;QACzD,MAAMd,OAAA,GAAUmB,QAAA;QAChB,I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iB,MAAM,IAAI,MAAM;QAC5D;MACF;MAEA,iBAAIvD,KAAA,CAAM0D,cAAc,CAACb,SAAA,GAAY;QACnC;QACA,IAAII,KAAA,CAAMK,SAAS,IAAIL,KAAA,CAAMO,kBAAkB,EAAE;UAC/C,MAAMG,QAAA,GAAW;YACf,GAAGV,KAAK;YACR;YACA,IAAIJ,SAAA,EAAWe,KAAA,EAAOX,KAAA,IAAS,CAAC,CAAC;UAEnC;UAEA,oBAAOjD,KAAA,CAAM6D,YAAY,CAAChB,SAAA,EAAW;YACnCiB,GAAA,EAAKvB,CAAA;YACL;YACAU,KAAA,EAAOU;UACT;QACF;QACA,oBAAO3D,KAAA,CAAM6D,YAAY,CAAChB,SAAA,EAAW;UACnCiB,GAAA,EAAKvB;QACP;MACF;MAEA,OAAOM,SAAA;IACT,EAAE,OAAOD,KAAA,EAAO;MACdD,OAAA,CAAQC,KAAK,CAAC,yCAAyCA,KAAA,EAAO,SAASN,IAAA;MACvE,OAAO;IACT;EACF;EAEA,OAAOF,QAAA,CAAS2B,MAAM,CAACC,OAAA;AACzB","ignoreList":[]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { SerializedLexicalNode } from 'lexical';
|
|
2
2
|
import type { DefaultNodeTypes, SerializedBlockNode, SerializedInlineBlockNode } from '../../../../nodeTypes.js';
|
|
3
|
-
export type
|
|
3
|
+
export type JSXConverterArgs<TNode extends {
|
|
4
4
|
[key: string]: any;
|
|
5
5
|
type?: string;
|
|
6
|
-
} = SerializedLexicalNode> =
|
|
6
|
+
} = SerializedLexicalNode> = {
|
|
7
7
|
childIndex: number;
|
|
8
8
|
converters: JSXConverters;
|
|
9
|
-
node:
|
|
9
|
+
node: TNode;
|
|
10
10
|
nodesToJSX: (args: {
|
|
11
11
|
converters?: JSXConverters;
|
|
12
12
|
disableIndent?: boolean | string[];
|
|
@@ -15,8 +15,12 @@ export type JSXConverter<T extends {
|
|
|
15
15
|
parent?: SerializedLexicalNodeWithParent;
|
|
16
16
|
}) => React.ReactNode[];
|
|
17
17
|
parent: SerializedLexicalNodeWithParent;
|
|
18
|
-
}
|
|
19
|
-
export type
|
|
18
|
+
};
|
|
19
|
+
export type JSXConverter<TNode extends {
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
type?: string;
|
|
22
|
+
} = SerializedLexicalNode> = ((args: JSXConverterArgs<TNode>) => React.ReactNode) | React.ReactNode;
|
|
23
|
+
export type JSXConverters<TNodes extends {
|
|
20
24
|
[key: string]: any;
|
|
21
25
|
type?: string;
|
|
22
26
|
} = DefaultNodeTypes | SerializedBlockNode<{
|
|
@@ -30,27 +34,27 @@ export type JSXConverters<T extends {
|
|
|
30
34
|
[blockSlug: string]: JSXConverter<any>;
|
|
31
35
|
} | JSXConverter<any> | undefined;
|
|
32
36
|
} & {
|
|
33
|
-
[nodeType in Exclude<NonNullable<
|
|
37
|
+
[nodeType in Exclude<NonNullable<TNodes['type']>, 'block' | 'inlineBlock'>]?: JSXConverter<Extract<TNodes, {
|
|
34
38
|
type: nodeType;
|
|
35
39
|
}>>;
|
|
36
40
|
} & {
|
|
37
41
|
blocks?: {
|
|
38
|
-
[K in Extract<Extract<
|
|
42
|
+
[K in Extract<Extract<TNodes, {
|
|
39
43
|
type: 'block';
|
|
40
44
|
}> extends SerializedBlockNode<infer B> ? B extends {
|
|
41
45
|
blockType: string;
|
|
42
|
-
} ? B['blockType'] : never : never, string>]?: JSXConverter<Extract<
|
|
46
|
+
} ? B['blockType'] : never : never, string>]?: JSXConverter<Extract<TNodes, {
|
|
43
47
|
type: 'block';
|
|
44
48
|
}> extends SerializedBlockNode<infer B> ? SerializedBlockNode<Extract<B, {
|
|
45
49
|
blockType: K;
|
|
46
50
|
}>> : SerializedBlockNode>;
|
|
47
51
|
};
|
|
48
52
|
inlineBlocks?: {
|
|
49
|
-
[K in Extract<Extract<
|
|
53
|
+
[K in Extract<Extract<TNodes, {
|
|
50
54
|
type: 'inlineBlock';
|
|
51
55
|
}> extends SerializedInlineBlockNode<infer B> ? B extends {
|
|
52
56
|
blockType: string;
|
|
53
|
-
} ? B['blockType'] : never : never, string>]?: JSXConverter<Extract<
|
|
57
|
+
} ? B['blockType'] : never : never, string>]?: JSXConverter<Extract<TNodes, {
|
|
54
58
|
type: 'inlineBlock';
|
|
55
59
|
}> extends SerializedInlineBlockNode<infer B> ? SerializedInlineBlockNode<Extract<B, {
|
|
56
60
|
blockType: K;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/features/converters/lexicalToJSX/converter/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEpD,OAAO,KAAK,EACV,gBAAgB,EAChB,mBAAmB,EACnB,yBAAyB,EAC1B,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/features/converters/lexicalToJSX/converter/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAEpD,OAAO,KAAK,EACV,gBAAgB,EAChB,mBAAmB,EACnB,yBAAyB,EAC1B,MAAM,0BAA0B,CAAA;AAEjC,MAAM,MAAM,gBAAgB,CAC1B,KAAK,SAAS;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,qBAAqB,IACzE;IACF,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,aAAa,CAAA;IACzB,IAAI,EAAE,KAAK,CAAA;IACX,UAAU,EAAE,CAAC,IAAI,EAAE;QACjB,UAAU,CAAC,EAAE,aAAa,CAAA;QAC1B,aAAa,CAAC,EAAE,OAAO,GAAG,MAAM,EAAE,CAAA;QAClC,gBAAgB,CAAC,EAAE,OAAO,GAAG,MAAM,EAAE,CAAA;QACrC,KAAK,EAAE,qBAAqB,EAAE,CAAA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ters/lexicalToJSX/converter/types.ts"],"sourcesContent":["import type { SerializedLexicalNode } from 'lexical'\n\nimport type {\n DefaultNodeTypes,\n SerializedBlockNode,\n SerializedInlineBlockNode,\n} from '../../../../nodeTypes.js'\nexport type
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../../../src/features/converters/lexicalToJSX/converter/types.ts"],"sourcesContent":["import type { SerializedLexicalNode } from 'lexical'\n\nimport type {\n DefaultNodeTypes,\n SerializedBlockNode,\n SerializedInlineBlockNode,\n} from '../../../../nodeTypes.js'\n\nexport type JSXConverterArgs<\n TNode extends { [key: string]: any; type?: string } = SerializedLexicalNode,\n> = {\n childIndex: number\n converters: JSXConverters\n node: TNode\n nodesToJSX: (args: {\n converters?: JSXConverters\n disableIndent?: boolean | string[]\n disableTextAlign?: boolean | string[]\n nodes: SerializedLexicalNode[]\n parent?: SerializedLexicalNodeWithParent\n }) => React.ReactNode[]\n parent: SerializedLexicalNodeWithParent\n}\nexport type JSXConverter<\n TNode extends { [key: string]: any; type?: string } = SerializedLexicalNode,\n> = ((args: JSXConverterArgs<TNode>) => React.ReactNode) | React.ReactNode\n\nexport type JSXConverters<\n TNodes extends { [key: string]: any; type?: string } =\n | DefaultNodeTypes\n | SerializedBlockNode<{ blockName?: null | string; blockType: string }> // need these to ensure types for blocks and inlineBlocks work if no generics are provided\n | SerializedInlineBlockNode<{ blockName?: null | string; blockType: string }>, // need these to ensure types for blocks and inlineBlocks work if no generics are provided\n> = {\n [key: string]:\n | {\n [blockSlug: string]: JSXConverter<any>\n }\n | JSXConverter<any>\n | undefined\n} & {\n [nodeType in Exclude<NonNullable<TNodes['type']>, 'block' | 'inlineBlock'>]?: JSXConverter<\n Extract<TNodes, { type: nodeType }>\n >\n} & {\n blocks?: {\n [K in Extract<\n Extract<TNodes, { type: 'block' }> extends SerializedBlockNode<infer B>\n ? B extends { blockType: string }\n ? B['blockType']\n : never\n : never,\n string\n >]?: JSXConverter<\n Extract<TNodes, { type: 'block' }> extends SerializedBlockNode<infer B>\n ? SerializedBlockNode<Extract<B, { blockType: K }>>\n : SerializedBlockNode\n >\n }\n inlineBlocks?: {\n [K in Extract<\n Extract<TNodes, { type: 'inlineBlock' }> extends SerializedInlineBlockNode<infer B>\n ? B extends { blockType: string }\n ? B['blockType']\n : never\n : never,\n string\n >]?: JSXConverter<\n Extract<TNodes, { type: 'inlineBlock' }> extends SerializedInlineBlockNode<infer B>\n ? SerializedInlineBlockNode<Extract<B, { blockType: K }>>\n : SerializedInlineBlockNode\n >\n }\n unknown?: JSXConverter<SerializedLexicalNode>\n}\nexport type SerializedLexicalNodeWithParent = {\n parent?: SerializedLexicalNode\n} & SerializedLexicalNode\n"],"mappings":"AA0EA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","useEffect","useState","defaultJSXConverters","RichText","RichTextPlugin","$","editor","t0","getEditorState","toJSON","editorState","setEditorState","t1","t2","registerUpdateListener","t3","editorState_0","_jsx","className","children","converters","data"],"sources":["../../../../../../src/features/debug/jsxConverter/client/plugin/index.tsx"],"sourcesContent":["'use client'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'\nimport { useEffect, useState } from 'react'\n\n// eslint-disable-next-line payload/no-imports-from-exports-dir\nimport { defaultJSXConverters, RichText } from '../../../../../exports/react/index.js'\nimport './style.scss'\n\nexport function RichTextPlugin() {\n const [editor] = useLexicalComposerContext()\n const [editorState, setEditorState] = useState(editor.getEditorState().toJSON())\n\n useEffect(() => {\n return editor.registerUpdateListener(({ editorState }) => {\n setEditorState(editorState.toJSON())\n })\n }, [editor])\n\n return (\n <div className=\"debug-jsx-converter\">\n <RichText converters={defaultJSXConverters} data={editorState} />\n </div>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAEA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,SAAS,EAAEC,QAAQ,QAAQ;AAEpC;AACA,SAASC,oBAAoB,EAAEC,QAAQ,QAAQ;AAG/C,OAAO,SAAAC,eAAA;EAAA,MAAAC,CAAA,GAAAP,EAAA;EACL,OAAAQ,MAAA,IAAiBP,yBAAA;EAAA,IAAAQ,EAAA;EAAA,IAAAF,CAAA,QAAAC,MAAA;IAC8BC,EAAA,
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","useEffect","useState","defaultJSXConverters","RichText","RichTextPlugin","$","editor","t0","getEditorState","toJSON","editorState","setEditorState","t1","t2","registerUpdateListener","t3","editorState_0","_jsx","className","children","converters","data"],"sources":["../../../../../../src/features/debug/jsxConverter/client/plugin/index.tsx"],"sourcesContent":["'use client'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext'\nimport { useEffect, useState } from 'react'\n\n// eslint-disable-next-line payload/no-imports-from-exports-dir\nimport { defaultJSXConverters, RichText } from '../../../../../exports/react/index.js'\nimport './style.scss'\n\nexport function RichTextPlugin() {\n const [editor] = useLexicalComposerContext()\n const [editorState, setEditorState] = useState(() => editor.getEditorState().toJSON())\n\n useEffect(() => {\n return editor.registerUpdateListener(({ editorState }) => {\n setEditorState(editorState.toJSON())\n })\n }, [editor])\n\n return (\n <div className=\"debug-jsx-converter\">\n <RichText converters={defaultJSXConverters} data={editorState} />\n </div>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAEA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,SAAS,EAAEC,QAAQ,QAAQ;AAEpC;AACA,SAASC,oBAAoB,EAAEC,QAAQ,QAAQ;AAG/C,OAAO,SAAAC,eAAA;EAAA,MAAAC,CAAA,GAAAP,EAAA;EACL,OAAAQ,MAAA,IAAiBP,yBAAA;EAAA,IAAAQ,EAAA;EAAA,IAAAF,CAAA,QAAAC,MAAA;IAC8BC,EAAA,GAAAA,CAAA,KAAMD,MAAA,CAAAE,cAAA,CAAqB,EAAAC,MAAA,CAAS;IAAAJ,CAAA,MAAAC,MAAA;IAAAD,CAAA,MAAAE,EAAA;EAAA;IAAAA,EAAA,GAAAF,CAAA;EAAA;EAAnF,OAAAK,WAAA,EAAAC,cAAA,IAAsCV,QAAA,CAASM,EAAoC;EAAA,IAAAK,EAAA;EAAA,IAAAC,EAAA;EAAA,IAAAR,CAAA,QAAAC,MAAA;IAEzEM,EAAA,GAAAA,CAAA,KACDN,MAAA,CAAAQ,sBAAA,CAAAC,EAAA;MAA+B;QAAAL,WAAA,EAAAM;MAAA,IAAAD,EAAe;MACnDJ,cAAA,CAAeD,aAAA,CAAAD,MAAA,CAAkB;IAAA,CACnC;IACCI,EAAA,IAACP,MAAA;IAAOD,CAAA,MAAAC,MAAA;IAAAD,CAAA,MAAAO,EAAA;IAAAP,CAAA,MAAAQ,EAAA;EAAA;IAAAD,EAAA,GAAAP,CAAA;IAAAQ,EAAA,GAAAR,CAAA;EAAA;EAJXL,SAAA,CAAUY,EAIV,EAAGC,EAAQ;EAAA,IAAAE,EAAA;EAAA,IAAAV,CAAA,QAAAK,WAAA;IAGTK,EAAA,GAAAE,IAAA,CAAC;MAAAC,SAAA,EAAc;MAAAC,QAAA,EACbF,IAAA,CAAAd,QAAA;QAAAiB,UAAA,EAAAlB,oBAAA;QAAAmB,IAAA,EAAkDX;MAAA,C;;;;;;;SADpDK,E","ignoreList":[]}
|
|
@@ -1,10 +1,39 @@
|
|
|
1
1
|
import type { SlateNodeConverter } from './converter/types.js';
|
|
2
2
|
export type SlateToLexicalFeatureProps = {
|
|
3
|
+
/**
|
|
4
|
+
* Custom converters to transform Slate nodes to Lexical nodes.
|
|
5
|
+
* Can be an array of converters or a function that receives default converters and returns an array.
|
|
6
|
+
* @default defaultSlateConverters
|
|
7
|
+
*/
|
|
3
8
|
converters?: (({ defaultConverters }: {
|
|
4
9
|
defaultConverters: SlateNodeConverter[];
|
|
5
10
|
}) => SlateNodeConverter[]) | SlateNodeConverter[];
|
|
11
|
+
/**
|
|
12
|
+
* When true, disables the afterRead hook that converts Slate data on-the-fly.
|
|
13
|
+
* Set this to true when running the migration script. That way, this feature is only used
|
|
14
|
+
* to "pass through" the converters to the migration script.
|
|
15
|
+
* @default false
|
|
16
|
+
*/
|
|
6
17
|
disableHooks?: boolean;
|
|
7
18
|
};
|
|
19
|
+
/**
|
|
20
|
+
* Enables on-the-fly conversion of Slate data to Lexical format through an afterRead hook.
|
|
21
|
+
* Used for testing migrations before running the permanent migration script.
|
|
22
|
+
* Only converts data that is in Slate format (arrays); Lexical data passes through unchanged.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* lexicalEditor({
|
|
27
|
+
* features: ({ defaultFeatures }) => [
|
|
28
|
+
* ...defaultFeatures,
|
|
29
|
+
* SlateToLexicalFeature({
|
|
30
|
+
* converters: [...defaultSlateConverters, MyCustomConverter],
|
|
31
|
+
* disableHooks: false, // Set to true during migration script
|
|
32
|
+
* }),
|
|
33
|
+
* ],
|
|
34
|
+
* })
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
8
37
|
export declare const SlateToLexicalFeature: import("../../typesServer.js").FeatureProviderProviderServer<SlateToLexicalFeatureProps, {
|
|
9
38
|
converters?: SlateNodeConverter[];
|
|
10
39
|
}, undefined>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature.server.d.ts","sourceRoot":"","sources":["../../../../src/features/migrations/slateToLexical/feature.server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAO9D,MAAM,MAAM,0BAA0B,GAAG;IACvC,UAAU,CAAC,EACP,CAAC,CAAC,EAAE,iBAAiB,EAAE,EAAE;QAAE,iBAAiB,EAAE,kBAAkB,EAAE,CAAA;KAAE,KAAK,kBAAkB,EAAE,CAAC,GAC9F,kBAAkB,EAAE,CAAA;IACxB,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,CAAA;AAED,eAAO,MAAM,qBAAqB;iBAGjB,kBAAkB,EAAE;aAkDnC,CAAA"}
|
|
1
|
+
{"version":3,"file":"feature.server.d.ts","sourceRoot":"","sources":["../../../../src/features/migrations/slateToLexical/feature.server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAO9D,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;OAIG;IACH,UAAU,CAAC,EACP,CAAC,CAAC,EAAE,iBAAiB,EAAE,EAAE;QAAE,iBAAiB,EAAE,kBAAkB,EAAE,CAAA;KAAE,KAAK,kBAAkB,EAAE,CAAC,GAC9F,kBAAkB,EAAE,CAAA;IACxB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB,CAAA;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,qBAAqB;iBAGjB,kBAAkB,EAAE;aAkDnC,CAAA"}
|
|
@@ -2,6 +2,24 @@ import { createServerFeature } from '../../../utilities/createServerFeature.js';
|
|
|
2
2
|
import { defaultSlateConverters } from './converter/defaultConverters.js';
|
|
3
3
|
import { convertSlateToLexical } from './converter/index.js';
|
|
4
4
|
import { UnknownConvertedNode } from './nodes/unknownConvertedNode/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* Enables on-the-fly conversion of Slate data to Lexical format through an afterRead hook.
|
|
7
|
+
* Used for testing migrations before running the permanent migration script.
|
|
8
|
+
* Only converts data that is in Slate format (arrays); Lexical data passes through unchanged.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* lexicalEditor({
|
|
13
|
+
* features: ({ defaultFeatures }) => [
|
|
14
|
+
* ...defaultFeatures,
|
|
15
|
+
* SlateToLexicalFeature({
|
|
16
|
+
* converters: [...defaultSlateConverters, MyCustomConverter],
|
|
17
|
+
* disableHooks: false, // Set to true during migration script
|
|
18
|
+
* }),
|
|
19
|
+
* ],
|
|
20
|
+
* })
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
5
23
|
export const SlateToLexicalFeature = createServerFeature({
|
|
6
24
|
feature: ({
|
|
7
25
|
props
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature.server.js","names":["createServerFeature","defaultSlateConverters","convertSlateToLexical","UnknownConvertedNode","SlateToLexicalFeature","feature","props","converters","defaultConverters","ClientFeature","hooks","disableHooks","undefined","afterRead","value","Array","isArray","slateData","nodes","node","sanitizedServerFeatureProps","key"],"sources":["../../../../src/features/migrations/slateToLexical/feature.server.ts"],"sourcesContent":["import type { SlateNodeConverter } from './converter/types.js'\n\nimport { createServerFeature } from '../../../utilities/createServerFeature.js'\nimport { defaultSlateConverters } from './converter/defaultConverters.js'\nimport { convertSlateToLexical } from './converter/index.js'\nimport { UnknownConvertedNode } from './nodes/unknownConvertedNode/index.js'\n\nexport type SlateToLexicalFeatureProps = {\n converters?:\n | (({ defaultConverters }: { defaultConverters: SlateNodeConverter[] }) => SlateNodeConverter[])\n | SlateNodeConverter[]\n disableHooks?: boolean\n}\n\nexport const SlateToLexicalFeature = createServerFeature<\n SlateToLexicalFeatureProps,\n {\n converters?: SlateNodeConverter[]\n }\n>({\n feature: ({ props }) => {\n if (!props) {\n props = {}\n }\n\n let converters: SlateNodeConverter[] = []\n if (props?.converters && typeof props?.converters === 'function') {\n converters = props.converters({ defaultConverters: defaultSlateConverters })\n } else if (props.converters && typeof props?.converters !== 'function') {\n converters = props.converters\n } else {\n converters = defaultSlateConverters\n }\n\n props.converters = converters\n\n return {\n ClientFeature: '@payloadcms/richtext-lexical/client#SlateToLexicalFeatureClient',\n hooks: props.disableHooks\n ? undefined\n : {\n afterRead: [\n ({ value }) => {\n if (!value || !Array.isArray(value) || 'root' in value) {\n // incomingEditorState null or not from Slate\n return value\n }\n\n // Slate => convert to lexical\n return convertSlateToLexical({\n converters: props.converters as SlateNodeConverter[],\n slateData: value,\n })\n },\n ],\n },\n nodes: [\n {\n node: UnknownConvertedNode,\n },\n ],\n sanitizedServerFeatureProps: {\n converters,\n },\n }\n },\n key: 'slateToLexical',\n})\n"],"mappings":"AAEA,SAASA,mBAAmB,QAAQ;AACpC,SAASC,sBAAsB,QAAQ;AACvC,SAASC,qBAAqB,QAAQ;AACtC,SAASC,oBAAoB,QAAQ;
|
|
1
|
+
{"version":3,"file":"feature.server.js","names":["createServerFeature","defaultSlateConverters","convertSlateToLexical","UnknownConvertedNode","SlateToLexicalFeature","feature","props","converters","defaultConverters","ClientFeature","hooks","disableHooks","undefined","afterRead","value","Array","isArray","slateData","nodes","node","sanitizedServerFeatureProps","key"],"sources":["../../../../src/features/migrations/slateToLexical/feature.server.ts"],"sourcesContent":["import type { SlateNodeConverter } from './converter/types.js'\n\nimport { createServerFeature } from '../../../utilities/createServerFeature.js'\nimport { defaultSlateConverters } from './converter/defaultConverters.js'\nimport { convertSlateToLexical } from './converter/index.js'\nimport { UnknownConvertedNode } from './nodes/unknownConvertedNode/index.js'\n\nexport type SlateToLexicalFeatureProps = {\n /**\n * Custom converters to transform Slate nodes to Lexical nodes.\n * Can be an array of converters or a function that receives default converters and returns an array.\n * @default defaultSlateConverters\n */\n converters?:\n | (({ defaultConverters }: { defaultConverters: SlateNodeConverter[] }) => SlateNodeConverter[])\n | SlateNodeConverter[]\n /**\n * When true, disables the afterRead hook that converts Slate data on-the-fly.\n * Set this to true when running the migration script. That way, this feature is only used\n * to \"pass through\" the converters to the migration script.\n * @default false\n */\n disableHooks?: boolean\n}\n\n/**\n * Enables on-the-fly conversion of Slate data to Lexical format through an afterRead hook.\n * Used for testing migrations before running the permanent migration script.\n * Only converts data that is in Slate format (arrays); Lexical data passes through unchanged.\n *\n * @example\n * ```ts\n * lexicalEditor({\n * features: ({ defaultFeatures }) => [\n * ...defaultFeatures,\n * SlateToLexicalFeature({\n * converters: [...defaultSlateConverters, MyCustomConverter],\n * disableHooks: false, // Set to true during migration script\n * }),\n * ],\n * })\n * ```\n */\nexport const SlateToLexicalFeature = createServerFeature<\n SlateToLexicalFeatureProps,\n {\n converters?: SlateNodeConverter[]\n }\n>({\n feature: ({ props }) => {\n if (!props) {\n props = {}\n }\n\n let converters: SlateNodeConverter[] = []\n if (props?.converters && typeof props?.converters === 'function') {\n converters = props.converters({ defaultConverters: defaultSlateConverters })\n } else if (props.converters && typeof props?.converters !== 'function') {\n converters = props.converters\n } else {\n converters = defaultSlateConverters\n }\n\n props.converters = converters\n\n return {\n ClientFeature: '@payloadcms/richtext-lexical/client#SlateToLexicalFeatureClient',\n hooks: props.disableHooks\n ? undefined\n : {\n afterRead: [\n ({ value }) => {\n if (!value || !Array.isArray(value) || 'root' in value) {\n // incomingEditorState null or not from Slate\n return value\n }\n\n // Slate => convert to lexical\n return convertSlateToLexical({\n converters: props.converters as SlateNodeConverter[],\n slateData: value,\n })\n },\n ],\n },\n nodes: [\n {\n node: UnknownConvertedNode,\n },\n ],\n sanitizedServerFeatureProps: {\n converters,\n },\n }\n },\n key: 'slateToLexical',\n})\n"],"mappings":"AAEA,SAASA,mBAAmB,QAAQ;AACpC,SAASC,sBAAsB,QAAQ;AACvC,SAASC,qBAAqB,QAAQ;AACtC,SAASC,oBAAoB,QAAQ;AAoBrC;;;;;;;;;;;;;;;;;;AAkBA,OAAO,MAAMC,qBAAA,GAAwBJ,mBAAA,CAKnC;EACAK,OAAA,EAASA,CAAC;IAAEC;EAAK,CAAE;IACjB,IAAI,CAACA,KAAA,EAAO;MACVA,KAAA,GAAQ,CAAC;IACX;IAEA,IAAIC,UAAA,GAAmC,EAAE;IACzC,IAAID,KAAA,EAAOC,UAAA,IAAc,OAAOD,KAAA,EAAOC,UAAA,KAAe,YAAY;MAChEA,UAAA,GAAaD,KAAA,CAAMC,UAAU,CAAC;QAAEC,iBAAA,EAAmBP;MAAuB;IAC5E,OAAO,IAAIK,KAAA,CAAMC,UAAU,IAAI,OAAOD,KAAA,EAAOC,UAAA,KAAe,YAAY;MACtEA,UAAA,GAAaD,KAAA,CAAMC,UAAU;IAC/B,OAAO;MACLA,UAAA,GAAaN,sBAAA;IACf;IAEAK,KAAA,CAAMC,UAAU,GAAGA,UAAA;IAEnB,OAAO;MACLE,aAAA,EAAe;MACfC,KAAA,EAAOJ,KAAA,CAAMK,YAAY,GACrBC,SAAA,GACA;QACEC,SAAA,EAAW,CACT,CAAC;UAAEC;QAAK,CAAE;UACR,IAAI,CAACA,KAAA,IAAS,CAACC,KAAA,CAAMC,OAAO,CAACF,KAAA,KAAU,UAAUA,KAAA,EAAO;YACtD;YACA,OAAOA,KAAA;UACT;UAEA;UACA,OAAOZ,qBAAA,CAAsB;YAC3BK,UAAA,EAAYD,KAAA,CAAMC,UAAU;YAC5BU,SAAA,EAAWH;UACb;QACF;MAEJ;MACJI,KAAA,EAAO,CACL;QACEC,IAAA,EAAMhB;MACR,EACD;MACDiB,2BAAA,EAA6B;QAC3Bb;MACF;IACF;EACF;EACAc,GAAA,EAAK;AACP","ignoreList":[]}
|
|
@@ -3,7 +3,7 @@ import React from 'react';
|
|
|
3
3
|
import type { RelationshipData } from '../../server/nodes/RelationshipNode.js';
|
|
4
4
|
import './index.scss';
|
|
5
5
|
type Props = {
|
|
6
|
-
className
|
|
6
|
+
className: string;
|
|
7
7
|
data: RelationshipData;
|
|
8
8
|
format?: ElementFormatType;
|
|
9
9
|
nodeKey?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RelationshipComponent.d.ts","sourceRoot":"","sources":["../../../../../src/features/relationship/client/components/RelationshipComponent.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAOhD,OAAO,KAAoD,MAAM,OAAO,CAAA;AAExE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAA;AAG9E,OAAO,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"RelationshipComponent.d.ts","sourceRoot":"","sources":["../../../../../src/features/relationship/client/components/RelationshipComponent.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAOhD,OAAO,KAAoD,MAAM,OAAO,CAAA;AAExE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAA;AAG9E,OAAO,cAAc,CAAA;AAOrB,KAAK,KAAK,GAAG;IACX,SAAS,EAAE,MAAM,CAAA;IACjB,IAAI,EAAE,gBAAgB,CAAA;IACtB,MAAM,CAAC,EAAE,iBAAiB,CAAA;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CA2GjD,CAAA"}
|
|
@@ -9,12 +9,12 @@ import { $getNodeByKey } from 'lexical';
|
|
|
9
9
|
import React, { useCallback, useReducer, useRef, useState } from 'react';
|
|
10
10
|
import { useLexicalDocumentDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDocumentDrawer.js';
|
|
11
11
|
import { INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND } from '../drawer/commands.js';
|
|
12
|
-
const baseClass = 'lexical-relationship';
|
|
13
12
|
const initialParams = {
|
|
14
13
|
depth: 0
|
|
15
14
|
};
|
|
16
15
|
export const RelationshipComponent = props => {
|
|
17
16
|
const {
|
|
17
|
+
className: baseClass,
|
|
18
18
|
data: {
|
|
19
19
|
relationTo,
|
|
20
20
|
value
|
|
@@ -73,7 +73,7 @@ export const RelationshipComponent = props => {
|
|
|
73
73
|
dispatchCacheBust();
|
|
74
74
|
}, [cacheBust, setParams, closeDocumentDrawer]);
|
|
75
75
|
return /*#__PURE__*/_jsxs("div", {
|
|
76
|
-
className: baseClass
|
|
76
|
+
className: `${baseClass}__contents`,
|
|
77
77
|
contentEditable: false,
|
|
78
78
|
ref: relationshipElemRef,
|
|
79
79
|
children: [/*#__PURE__*/_jsxs("div", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RelationshipComponent.js","names":["useLexicalComposerContext","useLexicalEditable","getTranslation","Button","useConfig","usePayloadAPI","useTranslation","$getNodeByKey","React","useCallback","useReducer","useRef","useState","useLexicalDocumentDrawer","INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND","
|
|
1
|
+
{"version":3,"file":"RelationshipComponent.js","names":["useLexicalComposerContext","useLexicalEditable","getTranslation","Button","useConfig","usePayloadAPI","useTranslation","$getNodeByKey","React","useCallback","useReducer","useRef","useState","useLexicalDocumentDrawer","INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND","initialParams","depth","RelationshipComponent","props","className","baseClass","data","relationTo","value","nodeKey","Error","relationshipElemRef","editor","isEditable","config","routes","api","serverURL","getEntityConfig","relatedCollection","collectionSlug","i18n","t","cacheBust","dispatchCacheBust","state","setParams","slug","closeDocumentDrawer","DocumentDrawer","DocumentDrawerToggler","id","removeRelationship","update","remove","updateRelationship","_jsxs","contentEditable","ref","_jsx","label","labels","singular","admin","useAsTitle","buttonStyle","disabled","el","icon","onClick","dispatchCommand","replace","round","tooltip","e","preventDefault","onSave"],"sources":["../../../../../src/features/relationship/client/components/RelationshipComponent.tsx"],"sourcesContent":["'use client'\nimport type { ElementFormatType } from 'lexical'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { useLexicalEditable } from '@lexical/react/useLexicalEditable'\nimport { getTranslation } from '@payloadcms/translations'\nimport { Button, useConfig, usePayloadAPI, useTranslation } from '@payloadcms/ui'\nimport { $getNodeByKey } from 'lexical'\nimport React, { useCallback, useReducer, useRef, useState } from 'react'\n\nimport type { RelationshipData } from '../../server/nodes/RelationshipNode.js'\n\nimport { useLexicalDocumentDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDocumentDrawer.js'\nimport './index.scss'\nimport { INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND } from '../drawer/commands.js'\n\nconst initialParams = {\n depth: 0,\n}\n\ntype Props = {\n className: string\n data: RelationshipData\n format?: ElementFormatType\n nodeKey?: string\n}\n\nexport const RelationshipComponent: React.FC<Props> = (props) => {\n const {\n className: baseClass,\n data: { relationTo, value },\n nodeKey,\n } = props\n\n if (typeof value === 'object') {\n throw new Error(\n 'Relationship value should be a string or number. The Lexical Relationship component should not receive the populated value object.',\n )\n }\n\n const relationshipElemRef = useRef<HTMLDivElement | null>(null)\n\n const [editor] = useLexicalComposerContext()\n const isEditable = useLexicalEditable()\n const {\n config: {\n routes: { api },\n serverURL,\n },\n getEntityConfig,\n } = useConfig()\n\n const [relatedCollection] = useState(() => getEntityConfig({ collectionSlug: relationTo }))\n\n const { i18n, t } = useTranslation()\n const [cacheBust, dispatchCacheBust] = useReducer((state) => state + 1, 0)\n const [{ data }, { setParams }] = usePayloadAPI(\n `${serverURL}${api}/${relatedCollection.slug}/${value}`,\n { initialParams },\n )\n\n const { closeDocumentDrawer, DocumentDrawer, DocumentDrawerToggler } = useLexicalDocumentDrawer({\n id: value,\n collectionSlug: relatedCollection.slug,\n })\n\n const removeRelationship = useCallback(() => {\n editor.update(() => {\n $getNodeByKey(nodeKey!)?.remove()\n })\n }, [editor, nodeKey])\n\n const updateRelationship = React.useCallback(() => {\n setParams({\n ...initialParams,\n cacheBust, // do this to get the usePayloadAPI to re-fetch the data even though the URL string hasn't changed\n })\n\n closeDocumentDrawer()\n dispatchCacheBust()\n }, [cacheBust, setParams, closeDocumentDrawer])\n\n return (\n <div className={`${baseClass}__contents`} contentEditable={false} ref={relationshipElemRef}>\n <div className={`${baseClass}__wrap`}>\n <p className={`${baseClass}__label`}>\n {t('fields:labelRelationship', {\n label: relatedCollection.labels?.singular\n ? getTranslation(relatedCollection.labels?.singular, i18n)\n : relatedCollection.slug,\n })}\n </p>\n <DocumentDrawerToggler className={`${baseClass}__doc-drawer-toggler`}>\n <p className={`${baseClass}__title`}>\n {data ? data[relatedCollection?.admin?.useAsTitle || 'id'] : value}\n </p>\n </DocumentDrawerToggler>\n </div>\n {isEditable && (\n <div className={`${baseClass}__actions`}>\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__swapButton`}\n disabled={!isEditable}\n el=\"button\"\n icon=\"swap\"\n onClick={() => {\n if (nodeKey) {\n editor.dispatchCommand(INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND, {\n replace: { nodeKey },\n })\n }\n }}\n round\n tooltip={t('fields:swapRelationship')}\n />\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={!isEditable}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n removeRelationship()\n }}\n round\n tooltip={t('fields:removeRelationship')}\n />\n </div>\n )}\n\n {!!value && <DocumentDrawer onSave={updateRelationship} />}\n </div>\n )\n}\n"],"mappings":"AAAA;;;AAGA,SAASA,yBAAyB,QAAQ;AAC1C,SAASC,kBAAkB,QAAQ;AACnC,SAASC,cAAc,QAAQ;AAC/B,SAASC,MAAM,EAAEC,SAAS,EAAEC,aAAa,EAAEC,cAAc,QAAQ;AACjE,SAASC,aAAa,QAAQ;AAC9B,OAAOC,KAAA,IAASC,WAAW,EAAEC,UAAU,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAIjE,SAASC,wBAAwB,QAAQ;AAEzC,SAASC,uCAAuC,QAAQ;AAExD,MAAMC,aAAA,GAAgB;EACpBC,KAAA,EAAO;AACT;AASA,OAAO,MAAMC,qBAAA,GAA0CC,KAAA;EACrD,MAAM;IACJC,SAAA,EAAWC,SAAS;IACpBC,IAAA,EAAM;MAAEC,UAAU;MAAEC;IAAK,CAAE;IAC3BC;EAAO,CACR,GAAGN,KAAA;EAEJ,IAAI,OAAOK,KAAA,KAAU,UAAU;IAC7B,MAAM,IAAIE,KAAA,CACR;EAEJ;EAEA,MAAMC,mBAAA,GAAsBf,MAAA,CAA8B;EAE1D,MAAM,CAACgB,MAAA,CAAO,GAAG3B,yBAAA;EACjB,MAAM4B,UAAA,GAAa3B,kBAAA;EACnB,MAAM;IACJ4B,MAAA,EAAQ;MACNC,MAAA,EAAQ;QAAEC;MAAG,CAAE;MACfC;IAAS,CACV;IACDC;EAAe,CAChB,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-23,6 +23,7 @@ export declare class RelationshipServerNode extends DecoratorBlockNode {
|
|
|
23
23
|
static importDOM(): DOMConversionMap<HTMLDivElement> | null;
|
|
24
24
|
static importJSON(serializedNode: SerializedRelationshipNode): RelationshipServerNode;
|
|
25
25
|
static isInline(): false;
|
|
26
|
+
createDOM(config?: EditorConfig): HTMLElement;
|
|
26
27
|
decorate(_editor: LexicalEditor, _config: EditorConfig): JSX.Element;
|
|
27
28
|
exportDOM(): DOMExportOutput;
|
|
28
29
|
exportJSON(): SerializedRelationshipNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RelationshipNode.d.ts","sourceRoot":"","sources":["../../../../../src/features/relationship/server/nodes/RelationshipNode.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,6CAA6C,CAAA;AAC/F,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AACrE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAA;
|
|
1
|
+
{"version":3,"file":"RelationshipNode.d.ts","sourceRoot":"","sources":["../../../../../src/features/relationship/server/nodes/RelationshipNode.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,6CAA6C,CAAA;AAC/F,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAA;AACrE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAA;AAEhF,OAAO,EAEL,KAAK,gBAAgB,EAErB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,OAAO,EACb,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK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AAG,IAAI,GAAG,sBAAsB,GAAG,SAAS,GAC5D,IAAI,IAAI,sBAAsB,CAEhC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { DecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js';
|
|
2
|
+
import { addClassNamesToElement } from '@lexical/utils';
|
|
2
3
|
import { $applyNodeReplacement } from 'lexical';
|
|
3
4
|
function $relationshipElementToServerNode(domNode) {
|
|
4
5
|
const id = domNode.getAttribute('data-lexical-relationship-id');
|
|
@@ -62,6 +63,11 @@ export class RelationshipServerNode extends DecoratorBlockNode {
|
|
|
62
63
|
static isInline() {
|
|
63
64
|
return false;
|
|
64
65
|
}
|
|
66
|
+
createDOM(config) {
|
|
67
|
+
const element = document.createElement('div');
|
|
68
|
+
addClassNamesToElement(element, config?.theme?.relationship);
|
|
69
|
+
return element;
|
|
70
|
+
}
|
|
65
71
|
decorate(_editor, _config) {
|
|
66
72
|
return null;
|
|
67
73
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RelationshipNode.js","names":["DecoratorBlockNode","$applyNodeReplacement","$relationshipElementToServerNode","domNode","id","getAttribute","relationTo","node","$createServerRelationshipNode","value","RelationshipServerNode","__data","constructor","data","format","key","clone","__format","__key","getType","importDOM","div","hasAttribute","conversion","priority","importJSON","serializedNode","version","importedData","setFormat","isInline","
|
|
1
|
+
{"version":3,"file":"RelationshipNode.js","names":["DecoratorBlockNode","addClassNamesToElement","$applyNodeReplacement","$relationshipElementToServerNode","domNode","id","getAttribute","relationTo","node","$createServerRelationshipNode","value","RelationshipServerNode","__data","constructor","data","format","key","clone","__format","__key","getType","importDOM","div","hasAttribute","conversion","priority","importJSON","serializedNode","version","importedData","setFormat","isInline","createDOM","config","element","document","createElement","theme","relationship","decorate","_editor","_config","exportDOM","setAttribute","String","text","createTextNode","getTextContent","append","exportJSON","getData","type","getLatest","setData","writable","getWritable","$isServerRelationshipNode"],"sources":["../../../../../src/features/relationship/server/nodes/RelationshipNode.tsx"],"sourcesContent":["import type { SerializedDecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js'\nimport type { CollectionSlug, DataFromCollectionSlug } from 'payload'\nimport type { JSX } from 'react'\n\nimport { DecoratorBlockNode } from '@lexical/react/LexicalDecoratorBlockNode.js'\nimport { addClassNamesToElement } from '@lexical/utils'\nimport {\n $applyNodeReplacement,\n type DOMConversionMap,\n type DOMConversionOutput,\n type DOMExportOutput,\n type EditorConfig,\n type ElementFormatType,\n type LexicalEditor,\n type LexicalNode,\n type NodeKey,\n} from 'lexical'\n\nimport type { StronglyTypedLeafNode } from '../../../../nodeTypes.js'\n\nexport type RelationshipData = {\n [TCollectionSlug in CollectionSlug]: {\n relationTo: TCollectionSlug\n value: DataFromCollectionSlug<TCollectionSlug> | number | string\n }\n}[CollectionSlug]\n\nexport type SerializedRelationshipNode = RelationshipData &\n StronglyTypedLeafNode<SerializedDecoratorBlockNode, 'relationship'>\n\nfunction $relationshipElementToServerNode(domNode: HTMLDivElement): DOMConversionOutput | null {\n const id = domNode.getAttribute('data-lexical-relationship-id')\n const relationTo = domNode.getAttribute('data-lexical-relationship-relationTo')\n\n if (id != null && relationTo != null) {\n const node = $createServerRelationshipNode({\n relationTo,\n value: id,\n })\n return { node }\n }\n return null\n}\n\nexport class RelationshipServerNode extends DecoratorBlockNode {\n __data: RelationshipData\n\n constructor({\n data,\n format,\n key,\n }: {\n data: RelationshipData\n format?: ElementFormatType\n key?: NodeKey\n }) {\n super(format, key)\n this.__data = data\n }\n\n static override clone(node: RelationshipServerNode): RelationshipServerNode {\n return new this({\n data: node.__data,\n format: node.__format,\n key: node.__key,\n })\n }\n\n static override getType(): string {\n return 'relationship'\n }\n\n static override importDOM(): DOMConversionMap<HTMLDivElement> | null {\n return {\n div: (domNode: HTMLDivElement) => {\n if (\n !domNode.hasAttribute('data-lexical-relationship-relationTo') ||\n !domNode.hasAttribute('data-lexical-relationship-id')\n ) {\n return null\n }\n return {\n conversion: $relationshipElementToServerNode,\n priority: 2,\n }\n },\n }\n }\n\n static override importJSON(serializedNode: SerializedRelationshipNode): RelationshipServerNode {\n if (serializedNode.version === 1 && (serializedNode?.value as unknown as { id: string })?.id) {\n serializedNode.value = (serializedNode.value as unknown as { id: string }).id\n }\n\n const importedData: RelationshipData = {\n relationTo: serializedNode.relationTo,\n value: serializedNode.value,\n }\n const node = $createServerRelationshipNode(importedData)\n node.setFormat(serializedNode.format)\n return node\n }\n\n static isInline(): false {\n return false\n }\n\n override createDOM(config?: EditorConfig): HTMLElement {\n const element = document.createElement('div')\n addClassNamesToElement(element, config?.theme?.relationship)\n return element\n }\n\n override decorate(_editor: LexicalEditor, _config: EditorConfig): JSX.Element {\n return null as unknown as JSX.Element\n }\n\n override exportDOM(): DOMExportOutput {\n const element = document.createElement('div')\n element.setAttribute(\n 'data-lexical-relationship-id',\n String(typeof this.__data?.value === 'object' ? this.__data?.value?.id : this.__data?.value),\n )\n element.setAttribute('data-lexical-relationship-relationTo', this.__data?.relationTo)\n\n const text = document.createTextNode(this.getTextContent())\n element.append(text)\n return { element }\n }\n\n override exportJSON(): SerializedRelationshipNode {\n return {\n ...super.exportJSON(),\n ...this.getData(),\n type: 'relationship',\n version: 2,\n }\n }\n\n getData(): RelationshipData {\n return this.getLatest().__data\n }\n\n override getTextContent(): string {\n return `${this.__data?.relationTo} relation to ${typeof this.__data?.value === 'object' ? this.__data?.value?.id : this.__data?.value}`\n }\n\n setData(data: RelationshipData): void {\n const writable = this.getWritable()\n writable.__data = data\n }\n}\n\nexport function $createServerRelationshipNode(data: RelationshipData): RelationshipServerNode {\n return $applyNodeReplacement(\n new RelationshipServerNode({\n data,\n }),\n )\n}\n\nexport function $isServerRelationshipNode(\n node: LexicalNode | null | RelationshipServerNode | undefined,\n): node is RelationshipServerNode {\n return node instanceof RelationshipServerNode\n}\n"],"mappings":"AAIA,SAASA,kBAAkB,QAAQ;AACnC,SAASC,sBAAsB,QAAQ;AACvC,SACEC,qBAAqB,QA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M,EAAEL,UAAA,gBAA0B,OAAO,IAAI,CAACK,MAAM,EAAEF,KAAA,KAAU,WAAW,IAAI,CAACE,MAAM,EAAEF,KAAA,EAAOL,EAAA,GAAK,IAAI,CAACO,MAAM,EAAEF,KAAA,EAAO;EACzI;EAEA2C,QAAQvC,IAAsB,EAAQ;IACpC,MAAMwC,QAAA,GAAW,IAAI,CAACC,WAAW;IACjCD,QAAA,CAAS1C,MAAM,GAAGE,IAAA;EACpB;AACF;AAEA,OAAO,SAASL,8BAA8BK,IAAsB;EAClE,OAAOZ,qBAAA,CACL,IAAIS,sBAAA,CAAuB;IACzBG;EACF;AAEJ;AAEA,OAAO,SAAS0C,0BACdhD,IAA6D;EAE7D,OAAOA,IAAA,YAAgBG,sBAAA;AACzB","ignoreList":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { GenericLanguages, I18n, I18nClient } from '@payloadcms/translations';
|
|
2
2
|
import type { JSONSchema4 } from 'json-schema';
|
|
3
3
|
import type { Klass, LexicalNode, LexicalNodeReplacement, SerializedEditorState, SerializedLexicalNode } from 'lexical';
|
|
4
|
-
import type {
|
|
4
|
+
import type { Field, FieldSchemaMap, ImportMapGenerators, JsonObject, PayloadComponent, PayloadRequest, PopulateType, ReplaceAny, RequestContext, RichTextField, RichTextHooks, SanitizedConfig, ValidateOptions, ValidationFieldError } from 'payload';
|
|
5
5
|
import type { ServerEditorConfig } from '../lexical/config/types.js';
|
|
6
6
|
import type { Transformer } from '../packages/@lexical/markdown/index.js';
|
|
7
7
|
import type { LexicalRichTextField } from '../types.js';
|
|
@@ -221,7 +221,7 @@ export type ServerFeature<ServerProps, ClientFeatureProps> = {
|
|
|
221
221
|
*/
|
|
222
222
|
componentImports?: {
|
|
223
223
|
[key: string]: PayloadComponent;
|
|
224
|
-
} |
|
|
224
|
+
} | ImportMapGenerators[0] | PayloadComponent[];
|
|
225
225
|
generatedTypes?: {
|
|
226
226
|
modifyOutputSchema: (args: {
|
|
227
227
|
collectionIDFieldTypes: {
|