@payloadcms/richtext-lexical 4.0.0-canary.0 → 4.0.0-internal.183b315
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/@types/assets.d.js +2 -0
- package/dist/@types/assets.d.js.map +1 -0
- package/dist/cell/rscEntry.d.ts.map +1 -1
- package/dist/cell/rscEntry.js +5 -5
- package/dist/cell/rscEntry.js.map +1 -1
- package/dist/exports/client/Field-VYBSMSRY.js +2 -0
- package/dist/exports/client/Field-VYBSMSRY.js.map +7 -0
- package/dist/exports/client/{RelationshipComponent-RZL743CS.js → RelationshipComponent-YCPAKOL7.js} +1 -1
- package/dist/exports/client/RelationshipComponent-YCPAKOL7.js.map +7 -0
- package/dist/exports/client/bundled.css +1 -1
- package/dist/exports/client/{chunk-XIJE2UCQ.js → chunk-ZYXHC5CY.js} +2 -2
- package/dist/exports/client/chunk-ZYXHC5CY.js.map +7 -0
- package/dist/exports/client/{component-KESPRYJR.js → component-PHZQBOJE.js} +1 -1
- package/dist/exports/client/component-PHZQBOJE.js.map +7 -0
- package/dist/exports/client/componentInline-R3EPNYWF.js +2 -0
- package/dist/exports/client/index.d.ts +1 -0
- package/dist/exports/client/index.d.ts.map +1 -1
- package/dist/exports/client/index.js +25 -25
- package/dist/exports/client/index.js.map +4 -4
- package/dist/exports/server/rsc.browser.d.ts +11 -0
- package/dist/exports/server/rsc.browser.d.ts.map +1 -0
- package/dist/exports/server/rsc.browser.js +10 -0
- package/dist/exports/server/rsc.browser.js.map +1 -0
- package/dist/features/blockquote/server/index.d.ts +1 -4
- package/dist/features/blockquote/server/index.d.ts.map +1 -1
- package/dist/features/blockquote/server/index.js +2 -0
- package/dist/features/blockquote/server/index.js.map +1 -1
- package/dist/features/blockquote/server/schema.d.ts +8 -0
- package/dist/features/blockquote/server/schema.d.ts.map +1 -0
- package/dist/features/blockquote/server/schema.js +15 -0
- package/dist/features/blockquote/server/schema.js.map +1 -0
- package/dist/features/blocks/client/component/index.d.ts +1 -1
- package/dist/features/blocks/client/component/index.d.ts.map +1 -1
- package/dist/features/blocks/client/component/index.js +1 -1
- package/dist/features/blocks/client/component/index.js.map +1 -1
- package/dist/features/blocks/client/componentInline/index.d.ts +1 -1
- package/dist/features/blocks/client/componentInline/index.d.ts.map +1 -1
- package/dist/features/blocks/client/componentInline/index.js +1 -1
- package/dist/features/blocks/client/componentInline/index.js.map +1 -1
- package/dist/features/blocks/client/markdown/markdownTransformer.js +4 -4
- package/dist/features/blocks/client/markdown/markdownTransformer.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.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.map +1 -1
- package/dist/features/blocks/client/plugin/index.d.ts +1 -1
- package/dist/features/blocks/client/plugin/index.d.ts.map +1 -1
- package/dist/features/blocks/client/plugin/index.js.map +1 -1
- package/dist/features/blocks/premade/CodeBlock/Component/Block.d.ts.map +1 -1
- package/dist/features/blocks/premade/CodeBlock/Component/Block.js +1 -0
- package/dist/features/blocks/premade/CodeBlock/Component/Block.js.map +1 -1
- package/dist/features/blocks/server/graphQLPopulationPromise.d.ts +1 -2
- package/dist/features/blocks/server/graphQLPopulationPromise.d.ts.map +1 -1
- package/dist/features/blocks/server/graphQLPopulationPromise.js.map +1 -1
- package/dist/features/blocks/server/index.d.ts +1 -0
- package/dist/features/blocks/server/index.d.ts.map +1 -1
- package/dist/features/blocks/server/index.js +20 -66
- package/dist/features/blocks/server/index.js.map +1 -1
- package/dist/features/blocks/server/markdown/markdownTransformer.js +4 -4
- package/dist/features/blocks/server/markdown/markdownTransformer.js.map +1 -1
- package/dist/features/blocks/server/nodes/BlocksNode.d.ts +1 -18
- package/dist/features/blocks/server/nodes/BlocksNode.d.ts.map +1 -1
- package/dist/features/blocks/server/nodes/BlocksNode.js.map +1 -1
- package/dist/features/blocks/server/nodes/InlineBlocksNode.d.ts +2 -10
- package/dist/features/blocks/server/nodes/InlineBlocksNode.d.ts.map +1 -1
- package/dist/features/blocks/server/nodes/InlineBlocksNode.js.map +1 -1
- package/dist/features/blocks/server/schema.d.ts +45 -0
- package/dist/features/blocks/server/schema.d.ts.map +1 -0
- package/dist/features/blocks/server/schema.js +139 -0
- package/dist/features/blocks/server/schema.js.map +1 -0
- package/dist/features/blocks/server/validate.d.ts +1 -2
- package/dist/features/blocks/server/validate.d.ts.map +1 -1
- package/dist/features/blocks/server/validate.js.map +1 -1
- package/dist/features/converters/lexicalToHtml/async/converters/upload.js.map +1 -1
- package/dist/features/converters/lexicalToHtml/async/types.d.ts +14 -15
- package/dist/features/converters/lexicalToHtml/async/types.d.ts.map +1 -1
- package/dist/features/converters/lexicalToHtml/async/types.js.map +1 -1
- package/dist/features/converters/lexicalToHtml/sync/converters/upload.js.map +1 -1
- package/dist/features/converters/lexicalToHtml/sync/types.d.ts +14 -15
- package/dist/features/converters/lexicalToHtml/sync/types.d.ts.map +1 -1
- package/dist/features/converters/lexicalToHtml/sync/types.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/Component/index.d.ts +4 -2
- package/dist/features/converters/lexicalToJSX/Component/index.d.ts.map +1 -1
- package/dist/features/converters/lexicalToJSX/Component/index.js +5 -4
- package/dist/features/converters/lexicalToJSX/Component/index.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/converters/upload.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/types.d.ts +12 -14
- 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/converters/lexicalToPlaintext/sync/types.d.ts +12 -14
- package/dist/features/converters/lexicalToPlaintext/sync/types.d.ts.map +1 -1
- package/dist/features/converters/lexicalToPlaintext/sync/types.js.map +1 -1
- package/dist/features/experimental_table/server/index.d.ts +1 -6
- package/dist/features/experimental_table/server/index.d.ts.map +1 -1
- package/dist/features/experimental_table/server/index.js +4 -0
- package/dist/features/experimental_table/server/index.js.map +1 -1
- package/dist/features/experimental_table/server/schema.d.ts +27 -0
- package/dist/features/experimental_table/server/schema.d.ts.map +1 -0
- package/dist/features/experimental_table/server/schema.js +107 -0
- package/dist/features/experimental_table/server/schema.js.map +1 -0
- package/dist/features/heading/server/index.d.ts +2 -4
- package/dist/features/heading/server/index.d.ts.map +1 -1
- package/dist/features/heading/server/index.js +2 -0
- package/dist/features/heading/server/index.js.map +1 -1
- package/dist/features/heading/server/schema.d.ts +10 -0
- package/dist/features/heading/server/schema.d.ts.map +1 -0
- package/dist/features/heading/server/schema.js +37 -0
- package/dist/features/heading/server/schema.js.map +1 -0
- package/dist/features/horizontalRule/client/nodes/HorizontalRuleNode.d.ts +1 -1
- package/dist/features/horizontalRule/client/nodes/HorizontalRuleNode.d.ts.map +1 -1
- package/dist/features/horizontalRule/client/nodes/HorizontalRuleNode.js.map +1 -1
- package/dist/features/horizontalRule/server/index.d.ts +1 -0
- package/dist/features/horizontalRule/server/index.d.ts.map +1 -1
- package/dist/features/horizontalRule/server/index.js +2 -0
- package/dist/features/horizontalRule/server/index.js.map +1 -1
- package/dist/features/horizontalRule/server/nodes/HorizontalRuleNode.d.ts +1 -5
- package/dist/features/horizontalRule/server/nodes/HorizontalRuleNode.d.ts.map +1 -1
- package/dist/features/horizontalRule/server/nodes/HorizontalRuleNode.js.map +1 -1
- package/dist/features/horizontalRule/server/schema.d.ts +7 -0
- package/dist/features/horizontalRule/server/schema.d.ts.map +1 -0
- package/dist/features/horizontalRule/server/schema.js +25 -0
- package/dist/features/horizontalRule/server/schema.js.map +1 -0
- package/dist/features/link/client/index.d.ts.map +1 -1
- package/dist/features/link/client/index.js.map +1 -1
- package/dist/features/link/client/plugins/autoLink/index.d.ts +1 -1
- package/dist/features/link/client/plugins/autoLink/index.d.ts.map +1 -1
- package/dist/features/link/client/plugins/autoLink/index.js.map +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js.map +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/types.d.ts +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/types.d.ts.map +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/types.js.map +1 -1
- package/dist/features/link/client/plugins/link/index.js.map +1 -1
- package/dist/features/link/markdownTransformer.d.ts +1 -1
- package/dist/features/link/markdownTransformer.d.ts.map +1 -1
- package/dist/features/link/markdownTransformer.js.map +1 -1
- package/dist/features/link/markdownTransformer.spec.js.map +1 -1
- package/dist/features/link/nodes/AutoLinkNode.d.ts +3 -3
- package/dist/features/link/nodes/AutoLinkNode.d.ts.map +1 -1
- package/dist/features/link/nodes/AutoLinkNode.js +2 -1
- package/dist/features/link/nodes/AutoLinkNode.js.map +1 -1
- package/dist/features/link/nodes/LinkNode.d.ts +3 -3
- package/dist/features/link/nodes/LinkNode.d.ts.map +1 -1
- package/dist/features/link/nodes/LinkNode.js +2 -1
- package/dist/features/link/nodes/LinkNode.js.map +1 -1
- package/dist/features/link/server/baseFields.js.map +1 -1
- package/dist/features/link/server/graphQLPopulationPromise.d.ts +1 -1
- package/dist/features/link/server/graphQLPopulationPromise.d.ts.map +1 -1
- package/dist/features/link/server/graphQLPopulationPromise.js.map +1 -1
- package/dist/features/link/server/index.d.ts +2 -1
- package/dist/features/link/server/index.d.ts.map +1 -1
- package/dist/features/link/server/index.js +3 -0
- package/dist/features/link/server/index.js.map +1 -1
- package/dist/features/link/server/schema.d.ts +32 -0
- package/dist/features/link/server/schema.d.ts.map +1 -0
- package/dist/features/link/server/schema.js +169 -0
- package/dist/features/link/server/schema.js.map +1 -0
- package/dist/features/link/server/validate.d.ts +1 -1
- package/dist/features/link/server/validate.d.ts.map +1 -1
- package/dist/features/link/server/validate.js.map +1 -1
- package/dist/features/lists/checklist/server/index.d.ts.map +1 -1
- package/dist/features/lists/checklist/server/index.js +3 -0
- package/dist/features/lists/checklist/server/index.js.map +1 -1
- package/dist/features/lists/orderedList/server/index.d.ts.map +1 -1
- package/dist/features/lists/orderedList/server/index.js +3 -0
- package/dist/features/lists/orderedList/server/index.js.map +1 -1
- package/dist/features/lists/plugin/index.d.ts +0 -9
- package/dist/features/lists/plugin/index.d.ts.map +1 -1
- package/dist/features/lists/plugin/index.js.map +1 -1
- package/dist/features/lists/shared/schema.d.ts +18 -0
- package/dist/features/lists/shared/schema.d.ts.map +1 -0
- package/dist/features/lists/shared/schema.js +62 -0
- package/dist/features/lists/shared/schema.js.map +1 -0
- package/dist/features/lists/unorderedList/server/index.d.ts.map +1 -1
- package/dist/features/lists/unorderedList/server/index.js +3 -0
- package/dist/features/lists/unorderedList/server/index.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.map +1 -1
- package/dist/features/relationship/client/nodes/RelationshipNode.d.ts +1 -1
- package/dist/features/relationship/client/nodes/RelationshipNode.d.ts.map +1 -1
- package/dist/features/relationship/client/nodes/RelationshipNode.js.map +1 -1
- package/dist/features/relationship/client/plugins/index.d.ts +1 -1
- package/dist/features/relationship/client/plugins/index.d.ts.map +1 -1
- package/dist/features/relationship/client/plugins/index.js.map +1 -1
- package/dist/features/relationship/client/utils/useEnabledRelationships.d.ts.map +1 -1
- package/dist/features/relationship/client/utils/useEnabledRelationships.js +9 -40
- package/dist/features/relationship/client/utils/useEnabledRelationships.js.map +1 -1
- package/dist/features/relationship/server/graphQLPopulationPromise.d.ts +1 -1
- package/dist/features/relationship/server/graphQLPopulationPromise.d.ts.map +1 -1
- package/dist/features/relationship/server/graphQLPopulationPromise.js.map +1 -1
- package/dist/features/relationship/server/index.d.ts +1 -0
- package/dist/features/relationship/server/index.d.ts.map +1 -1
- package/dist/features/relationship/server/index.js +2 -0
- package/dist/features/relationship/server/index.js.map +1 -1
- package/dist/features/relationship/server/nodes/RelationshipNode.d.ts +1 -10
- package/dist/features/relationship/server/nodes/RelationshipNode.d.ts.map +1 -1
- package/dist/features/relationship/server/nodes/RelationshipNode.js.map +1 -1
- package/dist/features/relationship/server/schema.d.ts +28 -0
- package/dist/features/relationship/server/schema.d.ts.map +1 -0
- package/dist/features/relationship/server/schema.js +80 -0
- package/dist/features/relationship/server/schema.js.map +1 -0
- package/dist/features/relationship/shared/filterEnabledRelationshipCollections.d.ts +23 -0
- package/dist/features/relationship/shared/filterEnabledRelationshipCollections.d.ts.map +1 -0
- package/dist/features/relationship/shared/filterEnabledRelationshipCollections.js +34 -0
- package/dist/features/relationship/shared/filterEnabledRelationshipCollections.js.map +1 -0
- package/dist/features/toolbars/shared/ToolbarDropdown/index.js.map +1 -1
- package/dist/features/typesServer.d.ts +17 -40
- 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 -1
- package/dist/features/upload/client/component/index.d.ts.map +1 -1
- package/dist/features/upload/client/component/index.js.map +1 -1
- package/dist/features/upload/client/nodes/UploadNode.d.ts +1 -1
- package/dist/features/upload/client/nodes/UploadNode.d.ts.map +1 -1
- package/dist/features/upload/client/nodes/UploadNode.js.map +1 -1
- package/dist/features/upload/client/plugin/index.d.ts +1 -1
- package/dist/features/upload/client/plugin/index.d.ts.map +1 -1
- package/dist/features/upload/client/plugin/index.js.map +1 -1
- package/dist/features/upload/server/graphQLPopulationPromise.d.ts +1 -1
- package/dist/features/upload/server/graphQLPopulationPromise.d.ts.map +1 -1
- package/dist/features/upload/server/graphQLPopulationPromise.js.map +1 -1
- package/dist/features/upload/server/index.d.ts +1 -0
- package/dist/features/upload/server/index.d.ts.map +1 -1
- package/dist/features/upload/server/index.js +3 -2
- package/dist/features/upload/server/index.js.map +1 -1
- package/dist/features/upload/server/nodes/UploadNode.d.ts +1 -55
- package/dist/features/upload/server/nodes/UploadNode.d.ts.map +1 -1
- package/dist/features/upload/server/nodes/UploadNode.js.map +1 -1
- package/dist/features/upload/server/nodes/conversions.d.ts.map +1 -1
- package/dist/features/upload/server/nodes/conversions.js.map +1 -1
- package/dist/features/upload/server/schema.d.ts +52 -0
- package/dist/features/upload/server/schema.d.ts.map +1 -0
- package/dist/features/upload/server/schema.js +129 -0
- package/dist/features/upload/server/schema.js.map +1 -0
- package/dist/features/upload/server/validate.d.ts +1 -1
- package/dist/features/upload/server/validate.d.ts.map +1 -1
- package/dist/features/upload/server/validate.js.map +1 -1
- package/dist/field/Diff/converters/upload/index.js.map +1 -1
- package/dist/field/bundled.css +1 -1
- package/dist/field/clientEntry.d.ts +29 -0
- package/dist/field/clientEntry.d.ts.map +1 -0
- package/dist/field/clientEntry.js +86 -0
- package/dist/field/clientEntry.js.map +1 -0
- package/dist/field/index.css +9 -12
- package/dist/field/index.js +1 -1
- package/dist/field/index.js.map +1 -1
- package/dist/field/rscEntry.d.ts.map +1 -1
- package/dist/field/rscEntry.js +2 -0
- package/dist/field/rscEntry.js.map +1 -1
- package/dist/index.d.ts +8 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -4
- package/dist/index.js.map +1 -1
- package/dist/lexical/LexicalEditor.d.ts.map +1 -1
- package/dist/lexical/LexicalEditor.js +36 -2
- package/dist/lexical/LexicalEditor.js.map +1 -1
- package/dist/lexical/LexicalProvider.d.ts.map +1 -1
- package/dist/lexical/LexicalProvider.js +22 -7
- 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 +5 -1
- package/dist/lexical/config/client/loader.js.map +1 -1
- package/dist/lexical/config/server/sanitize.d.ts.map +1 -1
- package/dist/lexical/config/server/sanitize.js +9 -11
- package/dist/lexical/config/server/sanitize.js.map +1 -1
- package/dist/lexical/plugins/DecoratorPlugin/index.js.map +1 -1
- package/dist/types/builtInNodes.d.ts +14 -0
- package/dist/types/builtInNodes.d.ts.map +1 -0
- package/dist/types/builtInNodes.js +203 -0
- package/dist/types/builtInNodes.js.map +1 -0
- package/dist/types/index.d.ts +16 -17
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/jsonSchemaHelpers.d.ts +30 -0
- package/dist/types/jsonSchemaHelpers.d.ts.map +1 -0
- package/dist/types/jsonSchemaHelpers.js +58 -0
- package/dist/types/jsonSchemaHelpers.js.map +1 -0
- package/dist/types/nodeTypes.d.ts +115 -61
- package/dist/types/nodeTypes.d.ts.map +1 -1
- package/dist/types/nodeTypes.js +3 -2
- package/dist/types/nodeTypes.js.map +1 -1
- package/dist/types/schema.d.ts.map +1 -1
- package/dist/types/schema.js +67 -65
- package/dist/types/schema.js.map +1 -1
- package/dist/utilities/buildEditorState.d.ts +17 -3
- package/dist/utilities/buildEditorState.d.ts.map +1 -1
- package/dist/utilities/buildEditorState.js +8 -0
- package/dist/utilities/buildEditorState.js.map +1 -1
- package/dist/utilities/buildInitialState.d.ts +2 -1
- package/dist/utilities/buildInitialState.d.ts.map +1 -1
- package/dist/utilities/buildInitialState.js.map +1 -1
- package/dist/utilities/generateImportMap.d.ts.map +1 -1
- package/dist/utilities/generateImportMap.js +7 -3
- package/dist/utilities/generateImportMap.js.map +1 -1
- package/package.json +8 -7
- package/dist/exports/client/Field-G5Z2HM5Y.js +0 -2
- package/dist/exports/client/Field-G5Z2HM5Y.js.map +0 -7
- package/dist/exports/client/RelationshipComponent-RZL743CS.js.map +0 -7
- package/dist/exports/client/chunk-XIJE2UCQ.js.map +0 -7
- package/dist/exports/client/component-KESPRYJR.js.map +0 -7
- package/dist/exports/client/componentInline-R2RSJX4K.js +0 -2
- package/dist/features/link/nodes/types.d.ts +0 -27
- package/dist/features/link/nodes/types.d.ts.map +0 -1
- package/dist/features/link/nodes/types.js +0 -2
- package/dist/features/link/nodes/types.js.map +0 -1
- /package/dist/exports/client/{componentInline-R2RSJX4K.js.map → componentInline-R3EPNYWF.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LinkNode.js","names":["addClassNamesToElement","isHTMLAnchorElement","ObjectID","$applyNodeReplacement","$createTextNode","$getSelection","$isElementNode","$isRangeSelection","createCommand","ElementNode","SUPPORTED_URL_PROTOCOLS","Set","LinkNode","__fields","__id","constructor","id","fields","linkType","newTab","key","clone","node","__key","getType","importDOM","a","conversion","$convertAnchorElement","priority","importJSON","serializedNode","$createLinkNode","updateFromJSON","version","doc","value","default","toHexString","canBeEmpty","canInsertTextAfter","canInsertTextBefore","createDOM","config","element","document","createElement","href","sanitizeUrl","url","target","rel","manageRel","theme","link","exportJSON","getFields","returnObject","type","getID","extractWithChild","child","selection","destination","anchorNode","anchor","getNode","focusNode","focus","isParentOf","getTextContent","length","getLatest","insertNewAfter","restoreSelection","getParentOrThrow","linkNode","append","isInline","parsedUrl","URL","has","protocol","e","setFields","writable","getWritable","setID","updateDOM","prevNode","removeAttribute","domNode","content","textContent","getAttribute","$isLinkNode","TOGGLE_LINK_COMMAND","$toggleLink","payload","selectedNodes","nodes","extract","forEach","parent","getParent","children","getChildren","insertBefore","remove","firstNode","$getLinkAncestor","text","getLastChild","prevParent","is","getPreviousSibling","insertAfter","$getAncestor","ancestor","predicate","input","action","result","mutableInput","includes","re","RegExp","replace","trim"],"sources":["../../../../src/features/link/nodes/LinkNode.ts"],"sourcesContent":["import type {\n BaseSelection,\n DOMConversionMap,\n DOMConversionOutput,\n EditorConfig,\n ElementNode as ElementNodeType,\n LexicalCommand,\n LexicalNode,\n LexicalUpdateJSON,\n NodeKey,\n RangeSelection,\n} from 'lexical'\n\nimport { addClassNamesToElement, isHTMLAnchorElement } from '@lexical/utils'\nimport ObjectID from 'bson-objectid'\nimport {\n $applyNodeReplacement,\n $createTextNode,\n $getSelection,\n $isElementNode,\n $isRangeSelection,\n createCommand,\n ElementNode,\n} from 'lexical'\n\nimport type { LinkPayload } from '../client/plugins/floatingLinkEditor/types.js'\nimport type { LinkFields, SerializedLinkNode } from './types.js'\n\nconst SUPPORTED_URL_PROTOCOLS = new Set(['http:', 'https:', 'mailto:', 'sms:', 'tel:'])\n\n/** @noInheritDoc */\nexport class LinkNode extends ElementNode {\n __fields: LinkFields\n __id: string\n\n constructor({\n id,\n fields = {\n linkType: 'custom',\n newTab: false,\n },\n key,\n }: {\n fields?: LinkFields\n id: string\n key?: NodeKey\n }) {\n super(key)\n this.__fields = fields\n this.__id = id\n }\n\n static override clone(node: LinkNode): LinkNode {\n return new this({\n id: node.__id,\n fields: node.__fields,\n key: node.__key,\n })\n }\n\n static override getType(): string {\n return 'link'\n }\n\n static override importDOM(): DOMConversionMap | null {\n return {\n a: (node: Node) => ({\n conversion: $convertAnchorElement,\n priority: 1,\n }),\n }\n }\n\n static override importJSON(serializedNode: SerializedLinkNode): LinkNode {\n const node = $createLinkNode({}).updateFromJSON(serializedNode)\n\n /**\n * @todo remove this in 4.0\n */\n if (\n serializedNode.version === 1 &&\n typeof serializedNode.fields?.doc?.value === 'object' &&\n serializedNode.fields?.doc?.value?.id\n ) {\n serializedNode.fields.doc.value = serializedNode.fields.doc.value.id\n serializedNode.version = 2\n }\n\n if (serializedNode.version === 2 && !serializedNode.id) {\n serializedNode.id = new ObjectID.default().toHexString()\n serializedNode.version = 3\n }\n return node\n }\n\n override canBeEmpty(): false {\n return false\n }\n\n override canInsertTextAfter(): false {\n return false\n }\n\n override canInsertTextBefore(): false {\n return false\n }\n\n override createDOM(config: EditorConfig): HTMLAnchorElement {\n const element = document.createElement('a')\n if (this.__fields?.linkType === 'custom') {\n element.href = this.sanitizeUrl(this.__fields.url ?? '')\n }\n if (this.__fields?.newTab ?? false) {\n element.target = '_blank'\n }\n\n if (this.__fields?.newTab === true && this.__fields?.linkType === 'custom') {\n element.rel = manageRel(element.rel, 'add', 'noopener')\n }\n\n addClassNamesToElement(element, config.theme.link)\n return element\n }\n\n override exportJSON(): SerializedLinkNode {\n const fields = this.getFields()\n\n if (fields?.linkType === 'internal') {\n delete fields.url\n } else if (fields?.linkType === 'custom') {\n delete fields.doc\n }\n\n const returnObject: SerializedLinkNode = {\n ...super.exportJSON(),\n type: 'link',\n fields,\n version: 3,\n }\n const id = this.getID()\n if (id) {\n returnObject.id = id\n }\n return returnObject\n }\n\n override extractWithChild(\n child: LexicalNode,\n selection: BaseSelection,\n destination: 'clone' | 'html',\n ): boolean {\n if (!$isRangeSelection(selection)) {\n return false\n }\n\n const anchorNode = selection.anchor.getNode()\n const focusNode = selection.focus.getNode()\n\n return (\n this.isParentOf(anchorNode) &&\n this.isParentOf(focusNode) &&\n selection.getTextContent().length > 0\n )\n }\n\n getFields(): LinkFields {\n return this.getLatest().__fields\n }\n\n getID(): string {\n return this.getLatest().__id\n }\n\n override insertNewAfter(\n selection: RangeSelection,\n restoreSelection = true,\n ): ElementNodeType | null {\n const element = this.getParentOrThrow().insertNewAfter(selection, restoreSelection)\n if ($isElementNode(element)) {\n const linkNode = $createLinkNode({ fields: this.__fields })\n element.append(linkNode)\n return linkNode\n }\n return null\n }\n\n override isInline(): true {\n return true\n }\n\n sanitizeUrl(url: string): string {\n try {\n const parsedUrl = new URL(url)\n\n if (!SUPPORTED_URL_PROTOCOLS.has(parsedUrl.protocol)) {\n return 'about:blank'\n }\n } catch (e) {\n return 'https://'\n }\n return url\n }\n\n setFields(fields: LinkFields): this {\n const writable = this.getWritable()\n writable.__fields = fields\n return writable\n }\n\n setID(id: string): this {\n const writable = this.getWritable()\n writable.__id = id\n return writable\n }\n\n override updateDOM(prevNode: this, anchor: HTMLAnchorElement, config: EditorConfig): boolean {\n const url = this.__fields?.url\n const newTab = this.__fields?.newTab\n if (url != null && url !== prevNode.__fields?.url && this.__fields?.linkType === 'custom') {\n anchor.href = url\n }\n if (this.__fields?.linkType === 'internal' && prevNode.__fields?.linkType === 'custom') {\n anchor.removeAttribute('href')\n }\n\n // TODO: not 100% sure why we're settign rel to '' - revisit\n // Start rel config here, then check newTab below\n if (anchor.rel == null) {\n anchor.rel = ''\n }\n\n if (newTab !== prevNode.__fields?.newTab) {\n if (newTab ?? false) {\n anchor.target = '_blank'\n if (this.__fields?.linkType === 'custom') {\n anchor.rel = manageRel(anchor.rel, 'add', 'noopener')\n }\n } else {\n anchor.removeAttribute('target')\n anchor.rel = manageRel(anchor.rel, 'remove', 'noopener')\n }\n }\n\n return false\n }\n\n override updateFromJSON(serializedNode: LexicalUpdateJSON<SerializedLinkNode>): this {\n return super\n .updateFromJSON(serializedNode)\n .setFields(serializedNode.fields)\n .setID(serializedNode.id as string)\n }\n}\n\nfunction $convertAnchorElement(domNode: Node): DOMConversionOutput {\n let node: LinkNode | null = null\n if (isHTMLAnchorElement(domNode)) {\n const content = domNode.textContent\n if (content !== null && content !== '') {\n node = $createLinkNode({\n id: new ObjectID.default().toHexString(),\n fields: {\n doc: null,\n linkType: 'custom',\n newTab: domNode.getAttribute('target') === '_blank',\n url: domNode.getAttribute('href') ?? '',\n },\n })\n }\n }\n return { node }\n}\n\nexport function $createLinkNode({ id, fields }: { fields?: LinkFields; id?: string }): LinkNode {\n return $applyNodeReplacement(\n new LinkNode({\n id: id ?? new ObjectID.default().toHexString(),\n fields,\n }),\n )\n}\n\nexport function $isLinkNode(node: LexicalNode | null | undefined): node is LinkNode {\n return node instanceof LinkNode\n}\n\nexport const TOGGLE_LINK_COMMAND: LexicalCommand<LinkPayload | null> =\n createCommand('TOGGLE_LINK_COMMAND')\n\nexport function $toggleLink(payload: ({ fields: LinkFields } & LinkPayload) | null): void {\n const selection = $getSelection()\n\n if (!$isRangeSelection(selection) && (payload === null || !payload.selectedNodes?.length)) {\n return\n }\n const nodes = $isRangeSelection(selection)\n ? selection.extract()\n : payload === null\n ? []\n : payload.selectedNodes\n\n if (payload === null) {\n // Remove LinkNodes\n nodes?.forEach((node) => {\n const parent = node.getParent()\n\n if ($isLinkNode(parent)) {\n const children = parent.getChildren()\n\n children.forEach((child) => {\n parent.insertBefore(child)\n })\n\n parent.remove()\n }\n })\n\n return\n }\n // Add or merge LinkNodes\n if (nodes?.length === 1) {\n const firstNode = nodes[0]!\n // if the first node is a LinkNode or if its\n // parent is a LinkNode, we update the URL, target and rel.\n const linkNode: LinkNode | null = $isLinkNode(firstNode)\n ? firstNode\n : $getLinkAncestor(firstNode)\n if (linkNode !== null) {\n linkNode.setFields(payload.fields)\n\n if (payload.text != null && payload.text !== linkNode.getTextContent()) {\n // remove all children and add child with new textcontent:\n linkNode.append($createTextNode(payload.text))\n linkNode.getChildren().forEach((child) => {\n if (child !== linkNode.getLastChild()) {\n child.remove()\n }\n })\n }\n return\n }\n }\n\n let prevParent: ElementNodeType | LinkNode | null = null\n let linkNode: LinkNode | null = null\n\n nodes?.forEach((node) => {\n const parent = node.getParent()\n\n if (parent === linkNode || parent === null || ($isElementNode(node) && !node.isInline())) {\n return\n }\n\n if ($isLinkNode(parent)) {\n linkNode = parent\n parent.setFields(payload.fields)\n if (payload.text != null && payload.text !== parent.getTextContent()) {\n // remove all children and add child with new textcontent:\n parent.append($createTextNode(payload.text))\n parent.getChildren().forEach((child) => {\n if (child !== parent.getLastChild()) {\n child.remove()\n }\n })\n }\n return\n }\n\n if (!parent.is(prevParent)) {\n prevParent = parent\n linkNode = $createLinkNode({ fields: payload.fields })\n\n if ($isLinkNode(parent)) {\n if (node.getPreviousSibling() === null) {\n parent.insertBefore(linkNode)\n } else {\n parent.insertAfter(linkNode)\n }\n } else {\n node.insertBefore(linkNode)\n }\n }\n\n if ($isLinkNode(node)) {\n if (node.is(linkNode)) {\n return\n }\n if (linkNode !== null) {\n const children = node.getChildren()\n linkNode.append(...children)\n }\n\n node.remove()\n return\n }\n\n if (linkNode !== null) {\n linkNode.append(node)\n }\n })\n}\n\nfunction $getLinkAncestor(node: LexicalNode): LinkNode | null {\n return $getAncestor(node, (ancestor) => $isLinkNode(ancestor)) as LinkNode\n}\n\nfunction $getAncestor(\n node: LexicalNode,\n predicate: (ancestor: LexicalNode) => boolean,\n): LexicalNode | null {\n let parent: LexicalNode | null = node\n while (parent !== null) {\n parent = parent.getParent()\n if (parent === null || predicate(parent)) {\n break\n }\n }\n return parent\n}\n\nfunction manageRel(input: string, action: 'add' | 'remove', value: string): string {\n let result: string\n let mutableInput = `${input}`\n if (action === 'add') {\n // if we somehow got out of sync - clean up\n if (mutableInput.includes(value)) {\n const re = new RegExp(value, 'g')\n mutableInput = mutableInput.replace(re, '').trim()\n }\n mutableInput = mutableInput.trim()\n result = mutableInput.length === 0 ? `${value}` : `${mutableInput} ${value}`\n } else {\n const re = new RegExp(value, 'g')\n result = mutableInput.replace(re, '').trim()\n }\n return result\n}\n"],"mappings":"AAaA,SAASA,sBAAsB,EAAEC,mBAAmB,QAAQ;AAC5D,OAAOC,QAAA,MAAc;AACrB,SACEC,qBAAqB,EACrBC,eAAe,EACfC,aAAa,EACbC,cAAc,EACdC,iBAAiB,EACjBC,aAAa,EACbC,WAAW,QACN;AAKP,MAAMC,uBAAA,GAA0B,IAAIC,GAAA,CAAI,CAAC,SAAS,UAAU,WAAW,QAAQ,OAAO;AAEtF;AACA,OAAO,MAAMC,QAAA,SAAiBH,WAAA;EAC5BI,QAAA;EACAC,IAAA;EAEAC,YAAY;IACVC,EAAE;IACFC,MAAA,GAAS;MACPC,QAAA,EAAU;MACVC,MAAA,EAAQ;IACV,CAAC;IACDC;EAAG,CAKJ,EAAE;IACD,KAAK,CAACA,GAAA;IACN,IAAI,CAACP,QAAQ,GAAGI,MAAA;IAChB,IAAI,CAACH,IAAI,GAAGE,EAAA;EACd;EAEA,OAAgBK,MAAMC,IAAc,EAAY;IAC9C,OAAO,IAAI,IAAI,CAAC;MACdN,EAAA,EAAIM,IAAA,CAAKR,IAAI;MACbG,MAAA,EAAQK,IAAA,CAAKT,QAAQ;MACrBO,GAAA,EAAKE,IAAA,CAAKC;IACZ;EACF;EAEA,OAAgBC,QAAA,EAAkB;IAChC,OAAO;EACT;EAEA,OAAgBC,UAAA,EAAqC;IACnD,OAAO;MACLC,CAA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a,EAAEC,MAAwB,EAAErF,KAAa;EACvE,IAAIsF,MAAA;EACJ,IAAIC,YAAA,GAAe,GAAGH,KAAA,EAAO;EAC7B,IAAIC,MAAA,KAAW,OAAO;IACpB;IACA,IAAIE,YAAA,CAAaC,QAAQ,CAACxF,KAAA,GAAQ;MAChC,MAAMyF,EAAA,GAAK,IAAIC,MAAA,CAAO1F,KAAA,EAAO;MAC7BuF,YAAA,GAAeA,YAAA,CAAaI,OAAO,CAACF,EAAA,EAAI,IAAIG,IAAI;IAClD;IACAL,YAAA,GAAeA,YAAA,CAAaK,IAAI;IAChCN,MAAA,GAASC,YAAA,CAAapD,MAAM,KAAK,IAAI,GAAGnC,KAAA,EAAO,GAAG,GAAGuF,YAAA,IAAgBvF,KAAA,EAAO;EAC9E,OAAO;IACL,MAAMyF,EAAA,GAAK,IAAIC,MAAA,CAAO1F,KAAA,EAAO;IAC7BsF,MAAA,GAASC,YAAA,CAAaI,OAAO,CAACF,EAAA,EAAI,IAAIG,IAAI;EAC5C;EACA,OAAON,MAAA;AACT","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"LinkNode.js","names":["addClassNamesToElement","isHTMLAnchorElement","ObjectID","$applyNodeReplacement","$createTextNode","$getSelection","$isElementNode","$isRangeSelection","createCommand","ElementNode","SUPPORTED_URL_PROTOCOLS","Set","LinkNode","__fields","__id","constructor","id","fields","linkType","newTab","key","clone","node","__key","getType","importDOM","a","conversion","$convertAnchorElement","priority","importJSON","serializedNode","$createLinkNode","updateFromJSON","version","doc","value","default","toHexString","canBeEmpty","canInsertTextAfter","canInsertTextBefore","createDOM","config","element","document","createElement","href","sanitizeUrl","url","target","rel","manageRel","theme","link","exportJSON","getFields","returnObject","type","getID","extractWithChild","child","selection","destination","anchorNode","anchor","getNode","focusNode","focus","isParentOf","getTextContent","length","getLatest","insertNewAfter","restoreSelection","getParentOrThrow","linkNode","append","isInline","parsedUrl","URL","has","protocol","e","setFields","writable","getWritable","setID","updateDOM","prevNode","removeAttribute","_serializedNode","domNode","content","textContent","getAttribute","$isLinkNode","TOGGLE_LINK_COMMAND","$toggleLink","payload","selectedNodes","nodes","extract","forEach","parent","getParent","children","getChildren","insertBefore","remove","firstNode","$getLinkAncestor","text","getLastChild","prevParent","is","getPreviousSibling","insertAfter","$getAncestor","ancestor","predicate","input","action","result","mutableInput","includes","re","RegExp","replace","trim"],"sources":["../../../../src/features/link/nodes/LinkNode.ts"],"sourcesContent":["import type {\n BaseSelection,\n DOMConversionMap,\n DOMConversionOutput,\n EditorConfig,\n ElementNode as ElementNodeType,\n LexicalCommand,\n LexicalNode,\n LexicalUpdateJSON,\n NodeKey,\n RangeSelection,\n SerializedElementNode,\n} from 'lexical'\n\nimport { addClassNamesToElement, isHTMLAnchorElement } from '@lexical/utils'\nimport ObjectID from 'bson-objectid'\nimport {\n $applyNodeReplacement,\n $createTextNode,\n $getSelection,\n $isElementNode,\n $isRangeSelection,\n createCommand,\n ElementNode,\n} from 'lexical'\n\nimport type { LinkPayload } from '../client/plugins/floatingLinkEditor/types.js'\nimport type { LinkFields, SerializedLinkNode } from '../server/schema.js'\n\nconst SUPPORTED_URL_PROTOCOLS = new Set(['http:', 'https:', 'mailto:', 'sms:', 'tel:'])\n\n/** @noInheritDoc */\nexport class LinkNode extends ElementNode {\n __fields: LinkFields\n __id: string\n\n constructor({\n id,\n fields = {\n linkType: 'custom',\n newTab: false,\n },\n key,\n }: {\n fields?: LinkFields\n id: string\n key?: NodeKey\n }) {\n super(key)\n this.__fields = fields\n this.__id = id\n }\n\n static override clone(node: LinkNode): LinkNode {\n return new this({\n id: node.__id,\n fields: node.__fields,\n key: node.__key,\n })\n }\n\n static override getType(): string {\n return 'link'\n }\n\n static override importDOM(): DOMConversionMap | null {\n return {\n a: (node: Node) => ({\n conversion: $convertAnchorElement,\n priority: 1,\n }),\n }\n }\n\n static override importJSON(serializedNode: SerializedLinkNode): LinkNode {\n const node = $createLinkNode({}).updateFromJSON(serializedNode)\n\n /**\n * @todo remove this in 4.0\n */\n if (\n serializedNode.version === 1 &&\n typeof serializedNode.fields?.doc?.value === 'object' &&\n serializedNode.fields?.doc?.value?.id\n ) {\n serializedNode.fields.doc.value = serializedNode.fields.doc.value.id\n serializedNode.version = 2\n }\n\n if (serializedNode.version === 2 && !serializedNode.id) {\n serializedNode.id = new ObjectID.default().toHexString()\n serializedNode.version = 3\n }\n return node\n }\n\n override canBeEmpty(): false {\n return false\n }\n\n override canInsertTextAfter(): false {\n return false\n }\n\n override canInsertTextBefore(): false {\n return false\n }\n\n override createDOM(config: EditorConfig): HTMLAnchorElement {\n const element = document.createElement('a')\n if (this.__fields?.linkType === 'custom') {\n element.href = this.sanitizeUrl(this.__fields.url ?? '')\n }\n if (this.__fields?.newTab ?? false) {\n element.target = '_blank'\n }\n\n if (this.__fields?.newTab === true && this.__fields?.linkType === 'custom') {\n element.rel = manageRel(element.rel, 'add', 'noopener')\n }\n\n addClassNamesToElement(element, config.theme.link)\n return element\n }\n\n override exportJSON(): SerializedLinkNode {\n const fields = this.getFields()\n\n if (fields?.linkType === 'internal') {\n delete fields.url\n } else if (fields?.linkType === 'custom') {\n delete fields.doc\n }\n\n const returnObject: SerializedLinkNode = {\n ...super.exportJSON(),\n type: 'link',\n fields,\n version: 3,\n }\n const id = this.getID()\n if (id) {\n returnObject.id = id\n }\n return returnObject\n }\n\n override extractWithChild(\n child: LexicalNode,\n selection: BaseSelection,\n destination: 'clone' | 'html',\n ): boolean {\n if (!$isRangeSelection(selection)) {\n return false\n }\n\n const anchorNode = selection.anchor.getNode()\n const focusNode = selection.focus.getNode()\n\n return (\n this.isParentOf(anchorNode) &&\n this.isParentOf(focusNode) &&\n selection.getTextContent().length > 0\n )\n }\n\n getFields(): LinkFields {\n return this.getLatest().__fields\n }\n\n getID(): string {\n return this.getLatest().__id\n }\n\n override insertNewAfter(\n selection: RangeSelection,\n restoreSelection = true,\n ): ElementNodeType | null {\n const element = this.getParentOrThrow().insertNewAfter(selection, restoreSelection)\n if ($isElementNode(element)) {\n const linkNode = $createLinkNode({ fields: this.__fields })\n element.append(linkNode)\n return linkNode\n }\n return null\n }\n\n override isInline(): true {\n return true\n }\n\n sanitizeUrl(url: string): string {\n try {\n const parsedUrl = new URL(url)\n\n if (!SUPPORTED_URL_PROTOCOLS.has(parsedUrl.protocol)) {\n return 'about:blank'\n }\n } catch (e) {\n return 'https://'\n }\n return url\n }\n\n setFields(fields: LinkFields): this {\n const writable = this.getWritable()\n writable.__fields = fields\n return writable\n }\n\n setID(id: string): this {\n const writable = this.getWritable()\n writable.__id = id\n return writable\n }\n\n override updateDOM(prevNode: this, anchor: HTMLAnchorElement, config: EditorConfig): boolean {\n const url = this.__fields?.url\n const newTab = this.__fields?.newTab\n if (url != null && url !== prevNode.__fields?.url && this.__fields?.linkType === 'custom') {\n anchor.href = url\n }\n if (this.__fields?.linkType === 'internal' && prevNode.__fields?.linkType === 'custom') {\n anchor.removeAttribute('href')\n }\n\n // TODO: not 100% sure why we're settign rel to '' - revisit\n // Start rel config here, then check newTab below\n if (anchor.rel == null) {\n anchor.rel = ''\n }\n\n if (newTab !== prevNode.__fields?.newTab) {\n if (newTab ?? false) {\n anchor.target = '_blank'\n if (this.__fields?.linkType === 'custom') {\n anchor.rel = manageRel(anchor.rel, 'add', 'noopener')\n }\n } else {\n anchor.removeAttribute('target')\n anchor.rel = manageRel(anchor.rel, 'remove', 'noopener')\n }\n }\n\n return false\n }\n\n override updateFromJSON(_serializedNode: LexicalUpdateJSON<SerializedElementNode>): this {\n const serializedNode = _serializedNode as unknown as SerializedLinkNode\n return super\n .updateFromJSON(serializedNode)\n .setFields(serializedNode.fields)\n .setID(serializedNode.id as string)\n }\n}\n\nfunction $convertAnchorElement(domNode: Node): DOMConversionOutput {\n let node: LinkNode | null = null\n if (isHTMLAnchorElement(domNode)) {\n const content = domNode.textContent\n if (content !== null && content !== '') {\n node = $createLinkNode({\n id: new ObjectID.default().toHexString(),\n fields: {\n doc: null,\n linkType: 'custom',\n newTab: domNode.getAttribute('target') === '_blank',\n url: domNode.getAttribute('href') ?? '',\n },\n })\n }\n }\n return { node }\n}\n\nexport function $createLinkNode({ id, fields }: { fields?: LinkFields; id?: string }): LinkNode {\n return $applyNodeReplacement(\n new LinkNode({\n id: id ?? new ObjectID.default().toHexString(),\n fields,\n }),\n )\n}\n\nexport function $isLinkNode(node: LexicalNode | null | undefined): node is LinkNode {\n return node instanceof LinkNode\n}\n\nexport const TOGGLE_LINK_COMMAND: LexicalCommand<LinkPayload | null> =\n createCommand('TOGGLE_LINK_COMMAND')\n\nexport function $toggleLink(payload: ({ fields: LinkFields } & LinkPayload) | null): void {\n const selection = $getSelection()\n\n if (!$isRangeSelection(selection) && (payload === null || !payload.selectedNodes?.length)) {\n return\n }\n const nodes = $isRangeSelection(selection)\n ? selection.extract()\n : payload === null\n ? []\n : payload.selectedNodes\n\n if (payload === null) {\n // Remove LinkNodes\n nodes?.forEach((node) => {\n const parent = node.getParent()\n\n if ($isLinkNode(parent)) {\n const children = parent.getChildren()\n\n children.forEach((child) => {\n parent.insertBefore(child)\n })\n\n parent.remove()\n }\n })\n\n return\n }\n // Add or merge LinkNodes\n if (nodes?.length === 1) {\n const firstNode = nodes[0]!\n // if the first node is a LinkNode or if its\n // parent is a LinkNode, we update the URL, target and rel.\n const linkNode: LinkNode | null = $isLinkNode(firstNode)\n ? firstNode\n : $getLinkAncestor(firstNode)\n if (linkNode !== null) {\n linkNode.setFields(payload.fields)\n\n if (payload.text != null && payload.text !== linkNode.getTextContent()) {\n // remove all children and add child with new textcontent:\n linkNode.append($createTextNode(payload.text))\n linkNode.getChildren().forEach((child) => {\n if (child !== linkNode.getLastChild()) {\n child.remove()\n }\n })\n }\n return\n }\n }\n\n let prevParent: ElementNodeType | LinkNode | null = null\n let linkNode: LinkNode | null = null\n\n nodes?.forEach((node) => {\n const parent = node.getParent()\n\n if (parent === linkNode || parent === null || ($isElementNode(node) && !node.isInline())) {\n return\n }\n\n if ($isLinkNode(parent)) {\n linkNode = parent\n parent.setFields(payload.fields)\n if (payload.text != null && payload.text !== parent.getTextContent()) {\n // remove all children and add child with new textcontent:\n parent.append($createTextNode(payload.text))\n parent.getChildren().forEach((child) => {\n if (child !== parent.getLastChild()) {\n child.remove()\n }\n })\n }\n return\n }\n\n if (!parent.is(prevParent)) {\n prevParent = parent\n linkNode = $createLinkNode({ fields: payload.fields })\n\n if ($isLinkNode(parent)) {\n if (node.getPreviousSibling() === null) {\n parent.insertBefore(linkNode)\n } else {\n parent.insertAfter(linkNode)\n }\n } else {\n node.insertBefore(linkNode)\n }\n }\n\n if ($isLinkNode(node)) {\n if (node.is(linkNode)) {\n return\n }\n if (linkNode !== null) {\n const children = node.getChildren()\n linkNode.append(...children)\n }\n\n node.remove()\n return\n }\n\n if (linkNode !== null) {\n linkNode.append(node)\n }\n })\n}\n\nfunction $getLinkAncestor(node: LexicalNode): LinkNode | null {\n return $getAncestor(node, (ancestor) => $isLinkNode(ancestor)) as LinkNode\n}\n\nfunction $getAncestor(\n node: LexicalNode,\n predicate: (ancestor: LexicalNode) => boolean,\n): LexicalNode | null {\n let parent: LexicalNode | null = node\n while (parent !== null) {\n parent = parent.getParent()\n if (parent === null || predicate(parent)) {\n break\n }\n }\n return parent\n}\n\nfunction manageRel(input: string, action: 'add' | 'remove', value: string): string {\n let result: string\n let mutableInput = `${input}`\n if (action === 'add') {\n // if we somehow got out of sync - clean up\n if (mutableInput.includes(value)) {\n const re = new RegExp(value, 'g')\n mutableInput = mutableInput.replace(re, '').trim()\n }\n mutableInput = mutableInput.trim()\n result = mutableInput.length === 0 ? `${value}` : `${mutableInput} ${value}`\n } else {\n const re = new RegExp(value, 'g')\n result = mutableInput.replace(re, '').trim()\n }\n return result\n}\n"],"mappings":"AAcA,SAASA,sBAAsB,EAAEC,mBAAmB,QAAQ;AAC5D,OAAOC,QAAA,MAAc;AACrB,SACEC,qBAAqB,EACrBC,eAAe,EACfC,aAAa,EACbC,cAAc,EACdC,iBAAiB,EACjBC,aAAa,EACbC,WAAW,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3F,KAAA,EAAO;IAC7BuF,MAAA,GAASC,YAAA,CAAaI,OAAO,CAACF,EAAA,EAAI,IAAIG,IAAI;EAC5C;EACA,OAAON,MAAA;AACT","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"baseFields.js","names":["validateUrl","validateUrlMinimal","getBaseFields","config","enabledCollections","disabledCollections","maxDepth","enabledRelations","collections","filter","slug","includes","map","admin","enableRichTextLink","hidden","baseFields","name","type","label","t","required","description","defaultValue","options","value","hooks","beforeChange","encodeURIComponent","validate","siblingData","linkType","length","push","condition","_data","_siblingData","filterOptions","relationTo","req","user","find","baseFilter","baseListFilter","limit","page","sort"],"sources":["../../../../src/features/link/server/baseFields.ts"],"sourcesContent":["import type {\n CollectionSlug,\n FieldAffectingData,\n RadioField,\n SanitizedConfig,\n TextField,\n TextFieldSingleValidation,\n TypedUser,\n} from 'payload'\n\nimport type { LinkFields } from '
|
|
1
|
+
{"version":3,"file":"baseFields.js","names":["validateUrl","validateUrlMinimal","getBaseFields","config","enabledCollections","disabledCollections","maxDepth","enabledRelations","collections","filter","slug","includes","map","admin","enableRichTextLink","hidden","baseFields","name","type","label","t","required","description","defaultValue","options","value","hooks","beforeChange","encodeURIComponent","validate","siblingData","linkType","length","push","condition","_data","_siblingData","filterOptions","relationTo","req","user","find","baseFilter","baseListFilter","limit","page","sort"],"sources":["../../../../src/features/link/server/baseFields.ts"],"sourcesContent":["import type {\n CollectionSlug,\n FieldAffectingData,\n RadioField,\n SanitizedConfig,\n TextField,\n TextFieldSingleValidation,\n TypedUser,\n} from 'payload'\n\nimport type { LinkFields } from './schema.js'\n\nimport { validateUrl, validateUrlMinimal } from '../../../lexical/utils/url.js'\n\nexport const getBaseFields = (\n config: SanitizedConfig,\n enabledCollections?: CollectionSlug[],\n disabledCollections?: CollectionSlug[],\n maxDepth?: number,\n): FieldAffectingData[] => {\n let enabledRelations: CollectionSlug[]\n\n /**\n * Figure out which relations should be enabled (enabledRelations) based on a collection's admin.enableRichTextLink property,\n * or the Link Feature's enabledCollections and disabledCollections properties which override it.\n */\n if (enabledCollections) {\n enabledRelations = enabledCollections\n } else if (disabledCollections) {\n enabledRelations = config.collections\n .filter(({ slug }) => !disabledCollections.includes(slug))\n .map(({ slug }) => slug)\n } else {\n enabledRelations = config.collections\n .filter(({ admin: { enableRichTextLink, hidden } }) => {\n if (typeof hidden !== 'function' && hidden) {\n return false\n }\n return enableRichTextLink\n })\n .map(({ slug }) => slug)\n }\n\n const baseFields: FieldAffectingData[] = [\n {\n name: 'text',\n type: 'text',\n label: ({ t }) => t('fields:textToDisplay'),\n required: true,\n },\n {\n name: 'linkType',\n type: 'radio',\n admin: {\n description: ({ t }) => t('fields:chooseBetweenCustomTextOrDocument'),\n },\n defaultValue: 'custom',\n label: ({ t }) => t('fields:linkType'),\n options: [\n {\n label: ({ t }) => t('fields:customURL'),\n value: 'custom',\n },\n ],\n required: true,\n } as RadioField,\n {\n name: 'url',\n type: 'text',\n hooks: {\n beforeChange: [\n ({ value }) => {\n if (!value) {\n return\n }\n\n if (!validateUrl(value)) {\n return encodeURIComponent(value)\n }\n return value\n },\n ],\n },\n label: ({ t }) => t('fields:enterURL'),\n required: true,\n validate: ((value: string, options) => {\n if ((options?.siblingData as LinkFields)?.linkType === 'internal') {\n return // no validation needed, as no url should exist for internal links\n }\n if (!validateUrlMinimal(value)) {\n return 'Invalid URL'\n }\n }) as TextFieldSingleValidation,\n },\n ]\n\n // Only display internal link-specific fields / options / conditions if there are enabled relations\n if (enabledRelations?.length) {\n ;(baseFields[1] as RadioField).options.push({\n label: ({ t }) => t('fields:internalLink'),\n value: 'internal',\n })\n ;(baseFields[2] as TextField).admin = {\n condition: (_data, _siblingData) => {\n return _siblingData.linkType !== 'internal'\n },\n }\n\n baseFields.push({\n name: 'doc',\n admin: {\n condition: (_data, _siblingData) => {\n return _siblingData.linkType === 'internal'\n },\n },\n // when admin.hidden is a function we need to dynamically call hidden with the user to know if the collection should be shown\n type: 'relationship',\n filterOptions:\n !enabledCollections && !disabledCollections\n ? async ({ relationTo, req, user }) => {\n const admin = config.collections.find(({ slug }) => slug === relationTo)?.admin\n\n const hidden = admin?.hidden\n if (typeof hidden === 'function' && hidden({ user } as { user: TypedUser })) {\n return false\n }\n\n const baseFilter = admin?.baseFilter ?? admin?.baseListFilter\n return (\n (await baseFilter?.({\n limit: 0,\n page: 1,\n req,\n sort: 'id',\n })) ?? true\n )\n }\n : null,\n label: ({ t }) => t('fields:chooseDocumentToLink'),\n maxDepth,\n relationTo: enabledRelations,\n required: true,\n })\n }\n\n baseFields.push({\n name: 'newTab',\n type: 'checkbox',\n label: ({ t }) => t('fields:openInNewTab'),\n })\n\n return baseFields\n}\n"],"mappings":"AAYA,SAASA,WAAW,EAAEC,kBAAkB,QAAQ;AAEhD,OAAO,MAAMC,aAAA,GAAgBA,CAC3BC,MAAA,EACAC,kBAAA,EACAC,mBAAA,EACAC,QAAA;EAEA,IAAIC,gBAAA;EAEJ;;;;EAIA,IAAIH,kBAAA,EAAoB;IACtBG,gBAAA,GAAmBH,kBAAA;EACrB,OAAO,IAAIC,mBAAA,EAAqB;IAC9BE,gBAAA,GAAmBJ,MAAA,CAAOK,WAAW,CAClCC,MAAM,CAAC,CAAC;MAAEC;IAAI,CAAE,KAAK,CAACL,mBAAA,CAAoBM,QAAQ,CAACD,IAAA,GACnDE,GAAG,CAAC,CAAC;MAAEF;IAAI,CAAE,KAAKA,IAAA;EACvB,OAAO;IACLH,gBAAA,GAAmBJ,MAAA,CAAOK,WAAW,CAClCC,MAAM,CAAC,CAAC;MAAEI,KAAA,EAAO;QAAEC,kBAAkB;QAAEC;MAAM;IAAE,CAAE;MAChD,IAAI,OAAOA,MAAA,KAAW,cAAcA,MAAA,EAAQ;QAC1C,OAAO;MACT;MACA,OAAOD,kBAAA;IACT,GACCF,GAAG,CAAC,CAAC;MAAEF;IAAI,CAAE,KAAKA,IAAA;EACvB;EAEA,MAAMM,UAAA,GAAmC,CACvC;IACEC,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5 +1,5 @@
|
|
|
1
1
|
import type { PopulationPromise } from '../../typesServer.js';
|
|
2
|
-
import type { SerializedLinkNode } from '../nodes/types.js';
|
|
3
2
|
import type { LinkFeatureServerProps } from './index.js';
|
|
3
|
+
import type { SerializedLinkNode } from './schema.js';
|
|
4
4
|
export declare const linkPopulationPromiseHOC: (props: LinkFeatureServerProps) => PopulationPromise<SerializedLinkNode>;
|
|
5
5
|
//# sourceMappingURL=graphQLPopulationPromise.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphQLPopulationPromise.d.ts","sourceRoot":"","sources":["../../../../src/features/link/server/graphQLPopulationPromise.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"graphQLPopulationPromise.d.ts","sourceRoot":"","sources":["../../../../src/features/link/server/graphQLPopulationPromise.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAC7D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAIrD,eAAO,MAAM,wBAAwB,GACnC,OAAO,sBAAsB,KAC5B,iBAAiB,CAAC,kBAAkB,CA8CtC,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphQLPopulationPromise.js","names":["recursivelyPopulateFieldsForGraphQL","linkPopulationPromiseHOC","props","context","currentDepth","depth","draft","editorPopulationPromises","field","fieldPromises","findMany","flattenLocales","node","overrideAccess","parentIsLocalized","populationPromises","req","showHiddenFields","fields","length","Array","isArray","data","localized","siblingDoc"],"sources":["../../../../src/features/link/server/graphQLPopulationPromise.ts"],"sourcesContent":["import type { PopulationPromise } from '../../typesServer.js'\nimport type {
|
|
1
|
+
{"version":3,"file":"graphQLPopulationPromise.js","names":["recursivelyPopulateFieldsForGraphQL","linkPopulationPromiseHOC","props","context","currentDepth","depth","draft","editorPopulationPromises","field","fieldPromises","findMany","flattenLocales","node","overrideAccess","parentIsLocalized","populationPromises","req","showHiddenFields","fields","length","Array","isArray","data","localized","siblingDoc"],"sources":["../../../../src/features/link/server/graphQLPopulationPromise.ts"],"sourcesContent":["import type { PopulationPromise } from '../../typesServer.js'\nimport type { LinkFeatureServerProps } from './index.js'\nimport type { SerializedLinkNode } from './schema.js'\n\nimport { recursivelyPopulateFieldsForGraphQL } from '../../../populateGraphQL/recursivelyPopulateFieldsForGraphQL.js'\n\nexport const linkPopulationPromiseHOC = (\n props: LinkFeatureServerProps,\n): PopulationPromise<SerializedLinkNode> => {\n return ({\n context,\n currentDepth,\n depth,\n draft,\n editorPopulationPromises,\n field,\n fieldPromises,\n findMany,\n flattenLocales,\n node,\n overrideAccess,\n parentIsLocalized,\n populationPromises,\n req,\n showHiddenFields,\n }) => {\n if (!props.fields?.length) {\n return\n }\n\n /**\n * Should populate all fields, including the doc field (for internal links), as it's treated like a normal field\n */\n if (Array.isArray(props.fields)) {\n recursivelyPopulateFieldsForGraphQL({\n context,\n currentDepth,\n data: node.fields,\n depth,\n draft,\n editorPopulationPromises,\n fieldPromises,\n fields: props.fields,\n findMany,\n flattenLocales,\n overrideAccess,\n parentIsLocalized: parentIsLocalized || field.localized || false,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc: node.fields,\n })\n }\n }\n}\n"],"mappings":"AAIA,SAASA,mCAAmC,QAAQ;AAEpD,OAAO,MAAMC,wBAAA,GACXC,KAAA;EAEA,OAAO,CAAC;IACNC,OAAO;IACPC,YAAY;IACZC,KAAK;IACLC,KAAK;IACLC,wBAAwB;IACxBC,KAAK;IACLC,aAAa;IACbC,QAAQ;IACRC,cAAc;IACdC,IAAI;IACJC,cAAc;IACdC,iBAAiB;IACjBC,kBAAkB;IAClBC,GAAG;IACHC;EAAgB,CACjB;IACC,IAAI,CAACf,KAAA,CAAMgB,MAAM,EAAEC,MAAA,EAAQ;MACzB;IACF;IAEA;;;IAGA,IAAIC,KAAA,CAAMC,OAAO,CAACnB,KAAA,CAAMgB,MAAM,GAAG;MAC/BlB,mCAAA,CAAoC;QAClCG,OAAA;QACAC,YAAA;QACAkB,IAAA,EAAMV,IAAA,CAAKM,MAAM;QACjBb,KAAA;QACAC,KAAA;QACAC,wBAAA;QACAE,aAAA;QACAS,MAAA,EAAQhB,KAAA,CAAMgB,MAAM;QACpBR,QAAA;QACAC,cAAA;QACAE,cAAA;QACAC,iBAAA,EAAmBA,iBAAA,IAAqBN,KAAA,CAAMe,SAAS,IAAI;QAC3DR,kBAAA;QACAC,GAAA;QACAC,gBAAA;QACAO,UAAA,EAAYZ,IAAA,CAAKM;MACnB;IACF;EACF;AACF","ignoreList":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { CollectionSlug, Field, FieldAffectingData, SanitizedConfig } from 'payload';
|
|
2
2
|
import type { ClientProps } from '../client/index.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type SerializedLinkNode } from './schema.js';
|
|
4
|
+
export type { LinkFields, SerializedAutoLinkNode, SerializedLinkNode } from './schema.js';
|
|
4
5
|
export type ExclusiveLinkCollectionsProps = {
|
|
5
6
|
/**
|
|
6
7
|
* The collections that should be disabled for internal linking. Overrides the `enableRichTextLink` property in the collection config.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/features/link/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAEd,KAAK,EACL,kBAAkB,EAElB,eAAe,EAChB,MAAM,SAAS,CAAA;AAKhB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/features/link/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EAEd,KAAK,EACL,kBAAkB,EAElB,eAAe,EAChB,MAAM,SAAS,CAAA;AAKhB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AASrD,OAAO,EAGL,KAAK,kBAAkB,EACxB,MAAM,aAAa,CAAA;AAIpB,YAAY,EAAE,UAAU,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAEzF,MAAM,MAAM,6BAA6B,GACrC;IACE;;;QAGI;IACJ,mBAAmB,CAAC,EAAE,cAAc,EAAE,CAAA;IAGtC,kBAAkB,CAAC,EAAE,KAAK,CAAA;CAC3B,GACD;IAEE,mBAAmB,CAAC,EAAE,KAAK,CAAA;IAE3B;;;QAGI;IACJ,kBAAkB,CAAC,EAAE,cAAc,EAAE,CAAA;CACtC,CAAA;AAEL,MAAM,MAAM,sBAAsB,GAAG;IACnC;;;;;;;;OAQG;IACH,gBAAgB,CAAC,EAAE,cAAc,GAAG,IAAI,CAAA;IACxC;;;OAGG;IACH,MAAM,CAAC,EACH,CAAC,CAAC,IAAI,EAAE;QACN,MAAM,EAAE,eAAe,CAAA;QACvB,aAAa,EAAE,kBAAkB,EAAE,CAAA;KACpC,KAAK,CAAC,KAAK,GAAG,kBAAkB,CAAC,EAAE,CAAC,GACrC,KAAK,EAAE,CAAA;IACX;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,kBAAkB,CAAA;KAAE,KAAK,MAAM,CAAA;IACtE;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB,GAAG,6BAA6B,CAAA;AAEjC,eAAO,MAAM,WAAW,2HA+GtB,CAAA"}
|
|
@@ -6,6 +6,7 @@ import { AutoLinkNode } from '../nodes/AutoLinkNode.js';
|
|
|
6
6
|
import { LinkNode } from '../nodes/LinkNode.js';
|
|
7
7
|
import { linkPopulationPromiseHOC } from './graphQLPopulationPromise.js';
|
|
8
8
|
import { i18n } from './i18n.js';
|
|
9
|
+
import { createAutoLinkNodeJSONSchema, createLinkNodeJSONSchema } from './schema.js';
|
|
9
10
|
import { transformExtraFields } from './transformExtraFields.js';
|
|
10
11
|
import { linkValidation } from './validate.js';
|
|
11
12
|
export const LinkFeature = createServerFeature({
|
|
@@ -68,6 +69,7 @@ export const LinkFeature = createServerFeature({
|
|
|
68
69
|
internalDocToHref: props.internalDocToHref
|
|
69
70
|
})],
|
|
70
71
|
nodes: [props?.disableAutoLinks === true ? null : createNode({
|
|
72
|
+
jsonSchema: createAutoLinkNodeJSONSchema(sanitizedFieldsWithoutText),
|
|
71
73
|
node: AutoLinkNode,
|
|
72
74
|
// Since AutoLinkNodes are just internal links, they need no hooks or graphQL population promises
|
|
73
75
|
validations: [linkValidation(props, sanitizedFieldsWithoutText)]
|
|
@@ -81,6 +83,7 @@ export const LinkFeature = createServerFeature({
|
|
|
81
83
|
return node?.fields;
|
|
82
84
|
},
|
|
83
85
|
graphQLPopulationPromises: [linkPopulationPromiseHOC(props)],
|
|
86
|
+
jsonSchema: createLinkNodeJSONSchema(sanitizedFieldsWithoutText),
|
|
84
87
|
node: LinkNode,
|
|
85
88
|
validations: [linkValidation(props, sanitizedFieldsWithoutText)]
|
|
86
89
|
})].filter(Boolean),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["sanitizeFields","createServerFeature","createNode","createLinkMarkdownTransformer","AutoLinkNode","LinkNode","linkPopulationPromiseHOC","i18n","transformExtraFields","linkValidation","LinkFeature","feature","config","_config","isRoot","parentIsLocalized","props","validRelationships","collections","map","c","slug","_transformedFields","fields","enabledCollections","disabledCollections","maxDepth","sanitizedFields","requireFieldLevelRichTextEditor","sanitizedFieldsWithoutText","filter","field","name","linkTypeField","linkURLField","defaultLinkType","defaultValue","undefined","defaultLinkURL","ClientFeature","clientFeatureProps","disableAutoLinks","generateSchemaMap","Array","isArray","length","schemaMap","Map","set","markdownTransformers","internalDocToHref","nodes","node","validations","getSubFields","getSubFieldsData","graphQLPopulationPromises","Boolean","sanitizedServerFeatureProps","key"],"sources":["../../../../src/features/link/server/index.ts"],"sourcesContent":["import type {\n CollectionSlug,\n Config,\n Field,\n FieldAffectingData,\n FieldSchemaMap,\n SanitizedConfig,\n} from 'payload'\n\nimport { sanitizeFields } from 'payload'\n\nimport type { NodeWithHooks } from '../../typesServer.js'\nimport type { ClientProps } from '../client/index.js'\nimport type { SerializedLinkNode } from '../nodes/types.js'\n\nimport { createServerFeature } from '../../../utilities/createServerFeature.js'\nimport { createNode } from '../../typeUtilities.js'\nimport { createLinkMarkdownTransformer } from '../markdownTransformer.js'\nimport { AutoLinkNode } from '../nodes/AutoLinkNode.js'\nimport { LinkNode } from '../nodes/LinkNode.js'\nimport { linkPopulationPromiseHOC } from './graphQLPopulationPromise.js'\nimport { i18n } from './i18n.js'\nimport { transformExtraFields } from './transformExtraFields.js'\nimport { linkValidation } from './validate.js'\n\nexport type ExclusiveLinkCollectionsProps =\n | {\n /**\n * The collections that should be disabled for internal linking. Overrides the `enableRichTextLink` property in the collection config.\n * When this property is set, `enabledCollections` will not be available.\n **/\n disabledCollections?: CollectionSlug[]\n\n // Ensures that enabledCollections is not available when disabledCollections is set\n enabledCollections?: never\n }\n | {\n // Ensures that disabledCollections is not available when enabledCollections is set\n disabledCollections?: never\n\n /**\n * The collections that should be enabled for internal linking. Overrides the `enableRichTextLink` property in the collection config\n * When this property is set, `disabledCollections` will not be available.\n **/\n enabledCollections?: CollectionSlug[]\n }\n\nexport type LinkFeatureServerProps = {\n /**\n * Disables the automatic creation of links from URLs pasted into the editor, as well\n * as auto link nodes.\n *\n * If set to 'creationOnly', only the creation of new auto link nodes will be disabled.\n * Existing auto link nodes will still be editable.\n *\n * @default false\n */\n disableAutoLinks?: 'creationOnly' | true\n /**\n * A function or array defining additional fields for the link feature. These will be\n * displayed in the link editor drawer.\n */\n fields?:\n | ((args: {\n config: SanitizedConfig\n defaultFields: FieldAffectingData[]\n }) => (Field | FieldAffectingData)[])\n | Field[]\n /**\n * Resolves an internal link node to a URL string for use in the markdown converter.\n * Internal links store a doc reference rather than a URL, so without this the markdown\n * output will have an empty href: `[link text]()`.\n */\n internalDocToHref?: (args: { linkNode: SerializedLinkNode }) => string\n /**\n * Sets a maximum population depth for the internal doc default field of link, regardless of the remaining depth when the field is reached.\n * This behaves exactly like the maxDepth properties of relationship and upload fields.\n *\n * {@link https://payloadcms.com/docs/getting-started/concepts#field-level-max-depth}\n */\n maxDepth?: number\n} & ExclusiveLinkCollectionsProps\n\nexport const LinkFeature = createServerFeature<\n LinkFeatureServerProps,\n LinkFeatureServerProps,\n ClientProps\n>({\n feature: async ({ config: _config, isRoot, parentIsLocalized, props }) => {\n if (!props) {\n props = {}\n }\n const validRelationships = _config.collections.map((c) => c.slug) || []\n\n const _transformedFields = transformExtraFields(\n props.fields ? props.fields : null,\n _config,\n props.enabledCollections,\n props.disabledCollections,\n props.maxDepth,\n )\n\n const sanitizedFields = await sanitizeFields({\n config: _config as unknown as Config,\n fields: _transformedFields,\n parentIsLocalized,\n requireFieldLevelRichTextEditor: isRoot,\n validRelationships,\n })\n props.fields = sanitizedFields\n\n // the text field is not included in the node data.\n // Thus, for tasks like validation, we do not want to pass it a text field in the schema which will never have data.\n // Otherwise, it will cause a validation error (field is required).\n const sanitizedFieldsWithoutText = sanitizedFields.filter(\n (field) => !('name' in field) || field.name !== 'text',\n )\n\n let linkTypeField: Field | null = null\n let linkURLField: Field | null = null\n\n for (const field of sanitizedFields) {\n if ('name' in field && field.name === 'linkType') {\n linkTypeField = field\n }\n\n if ('name' in field && field.name === 'url') {\n linkURLField = field\n }\n }\n\n const defaultLinkType = linkTypeField\n ? 'defaultValue' in linkTypeField && typeof linkTypeField.defaultValue === 'string'\n ? linkTypeField.defaultValue\n : 'custom'\n : undefined\n\n const defaultLinkURL = linkURLField\n ? 'defaultValue' in linkURLField && typeof linkURLField.defaultValue === 'string'\n ? linkURLField.defaultValue\n : 'https://'\n : undefined\n\n return {\n ClientFeature: '@payloadcms/richtext-lexical/client#LinkFeatureClient',\n clientFeatureProps: {\n defaultLinkType,\n defaultLinkURL,\n disableAutoLinks: props.disableAutoLinks,\n disabledCollections: props.disabledCollections,\n enabledCollections: props.enabledCollections,\n } as ClientProps,\n generateSchemaMap: () => {\n if (!sanitizedFields || !Array.isArray(sanitizedFields) || sanitizedFields.length === 0) {\n return null\n }\n\n const schemaMap: FieldSchemaMap = new Map()\n schemaMap.set('fields', {\n fields: sanitizedFields,\n })\n\n return schemaMap\n },\n i18n,\n markdownTransformers: [\n createLinkMarkdownTransformer({ internalDocToHref: props.internalDocToHref }),\n ],\n nodes: [\n props?.disableAutoLinks === true\n ? null\n : createNode({\n node: AutoLinkNode,\n // Since AutoLinkNodes are just internal links, they need no hooks or graphQL population promises\n validations: [linkValidation(props, sanitizedFieldsWithoutText)],\n }),\n createNode({\n getSubFields: () => {\n return sanitizedFieldsWithoutText\n },\n getSubFieldsData: ({ node }) => {\n return node?.fields\n },\n graphQLPopulationPromises: [linkPopulationPromiseHOC(props)],\n node: LinkNode,\n validations: [linkValidation(props, sanitizedFieldsWithoutText)],\n }),\n ].filter(Boolean) as Array<NodeWithHooks>,\n sanitizedServerFeatureProps: props,\n }\n },\n key: 'link',\n})\n"],"mappings":"AASA,SAASA,cAAc,QAAQ;AAM/B,SAASC,mBAAmB,QAAQ;AACpC,SAASC,UAAU,QAAQ;AAC3B,SAASC,6BAA6B,QAAQ;AAC9C,SAASC,YAAY,QAAQ;AAC7B,SAASC,QAAQ,QAAQ;AACzB,SAASC,wBAAwB,QAAQ;AACzC,SAASC,IAAI,QAAQ;AACrB,SAASC,oBAAoB,QAAQ;AACrC,SAASC,cAAc,QAAQ;AA4D/B,OAAO,MAAMC,WAAA,GAAcT,mBAAA,CAIzB;EACAU,OAAA,EAAS,MAAAA,CAAO;IAAEC,MAAA,EAAQC,OAAO;IAAEC,MAAM;IAAEC,iBAAiB;IAAEC;EAAK,CAAE;IACnE,IAAI,CAACA,KAA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|
|
1
|
+
{"version":3,"file":"index.js","names":["sanitizeFields","createServerFeature","createNode","createLinkMarkdownTransformer","AutoLinkNode","LinkNode","linkPopulationPromiseHOC","i18n","createAutoLinkNodeJSONSchema","createLinkNodeJSONSchema","transformExtraFields","linkValidation","LinkFeature","feature","config","_config","isRoot","parentIsLocalized","props","validRelationships","collections","map","c","slug","_transformedFields","fields","enabledCollections","disabledCollections","maxDepth","sanitizedFields","requireFieldLevelRichTextEditor","sanitizedFieldsWithoutText","filter","field","name","linkTypeField","linkURLField","defaultLinkType","defaultValue","undefined","defaultLinkURL","ClientFeature","clientFeatureProps","disableAutoLinks","generateSchemaMap","Array","isArray","length","schemaMap","Map","set","markdownTransformers","internalDocToHref","nodes","jsonSchema","node","validations","getSubFields","getSubFieldsData","graphQLPopulationPromises","Boolean","sanitizedServerFeatureProps","key"],"sources":["../../../../src/features/link/server/index.ts"],"sourcesContent":["import type {\n CollectionSlug,\n Config,\n Field,\n FieldAffectingData,\n FieldSchemaMap,\n SanitizedConfig,\n} from 'payload'\n\nimport { sanitizeFields } from 'payload'\n\nimport type { NodeWithHooks } from '../../typesServer.js'\nimport type { ClientProps } from '../client/index.js'\n\nimport { createServerFeature } from '../../../utilities/createServerFeature.js'\nimport { createNode } from '../../typeUtilities.js'\nimport { createLinkMarkdownTransformer } from '../markdownTransformer.js'\nimport { AutoLinkNode } from '../nodes/AutoLinkNode.js'\nimport { LinkNode } from '../nodes/LinkNode.js'\nimport { linkPopulationPromiseHOC } from './graphQLPopulationPromise.js'\nimport { i18n } from './i18n.js'\nimport {\n createAutoLinkNodeJSONSchema,\n createLinkNodeJSONSchema,\n type SerializedLinkNode,\n} from './schema.js'\nimport { transformExtraFields } from './transformExtraFields.js'\nimport { linkValidation } from './validate.js'\n\nexport type { LinkFields, SerializedAutoLinkNode, SerializedLinkNode } from './schema.js'\n\nexport type ExclusiveLinkCollectionsProps =\n | {\n /**\n * The collections that should be disabled for internal linking. Overrides the `enableRichTextLink` property in the collection config.\n * When this property is set, `enabledCollections` will not be available.\n **/\n disabledCollections?: CollectionSlug[]\n\n // Ensures that enabledCollections is not available when disabledCollections is set\n enabledCollections?: never\n }\n | {\n // Ensures that disabledCollections is not available when enabledCollections is set\n disabledCollections?: never\n\n /**\n * The collections that should be enabled for internal linking. Overrides the `enableRichTextLink` property in the collection config\n * When this property is set, `disabledCollections` will not be available.\n **/\n enabledCollections?: CollectionSlug[]\n }\n\nexport type LinkFeatureServerProps = {\n /**\n * Disables the automatic creation of links from URLs pasted into the editor, as well\n * as auto link nodes.\n *\n * If set to 'creationOnly', only the creation of new auto link nodes will be disabled.\n * Existing auto link nodes will still be editable.\n *\n * @default false\n */\n disableAutoLinks?: 'creationOnly' | true\n /**\n * A function or array defining additional fields for the link feature. These will be\n * displayed in the link editor drawer.\n */\n fields?:\n | ((args: {\n config: SanitizedConfig\n defaultFields: FieldAffectingData[]\n }) => (Field | FieldAffectingData)[])\n | Field[]\n /**\n * Resolves an internal link node to a URL string for use in the markdown converter.\n * Internal links store a doc reference rather than a URL, so without this the markdown\n * output will have an empty href: `[link text]()`.\n */\n internalDocToHref?: (args: { linkNode: SerializedLinkNode }) => string\n /**\n * Sets a maximum population depth for the internal doc default field of link, regardless of the remaining depth when the field is reached.\n * This behaves exactly like the maxDepth properties of relationship and upload fields.\n *\n * {@link https://payloadcms.com/docs/getting-started/concepts#field-level-max-depth}\n */\n maxDepth?: number\n} & ExclusiveLinkCollectionsProps\n\nexport const LinkFeature = createServerFeature<\n LinkFeatureServerProps,\n LinkFeatureServerProps,\n ClientProps\n>({\n feature: async ({ config: _config, isRoot, parentIsLocalized, props }) => {\n if (!props) {\n props = {}\n }\n const validRelationships = _config.collections.map((c) => c.slug) || []\n\n const _transformedFields = transformExtraFields(\n props.fields ? props.fields : null,\n _config,\n props.enabledCollections,\n props.disabledCollections,\n props.maxDepth,\n )\n\n const sanitizedFields = await sanitizeFields({\n config: _config as unknown as Config,\n fields: _transformedFields,\n parentIsLocalized,\n requireFieldLevelRichTextEditor: isRoot,\n validRelationships,\n })\n props.fields = sanitizedFields\n\n // the text field is not included in the node data.\n // Thus, for tasks like validation, we do not want to pass it a text field in the schema which will never have data.\n // Otherwise, it will cause a validation error (field is required).\n const sanitizedFieldsWithoutText = sanitizedFields.filter(\n (field) => !('name' in field) || field.name !== 'text',\n )\n\n let linkTypeField: Field | null = null\n let linkURLField: Field | null = null\n\n for (const field of sanitizedFields) {\n if ('name' in field && field.name === 'linkType') {\n linkTypeField = field\n }\n\n if ('name' in field && field.name === 'url') {\n linkURLField = field\n }\n }\n\n const defaultLinkType = linkTypeField\n ? 'defaultValue' in linkTypeField && typeof linkTypeField.defaultValue === 'string'\n ? linkTypeField.defaultValue\n : 'custom'\n : undefined\n\n const defaultLinkURL = linkURLField\n ? 'defaultValue' in linkURLField && typeof linkURLField.defaultValue === 'string'\n ? linkURLField.defaultValue\n : 'https://'\n : undefined\n\n return {\n ClientFeature: '@payloadcms/richtext-lexical/client#LinkFeatureClient',\n clientFeatureProps: {\n defaultLinkType,\n defaultLinkURL,\n disableAutoLinks: props.disableAutoLinks,\n disabledCollections: props.disabledCollections,\n enabledCollections: props.enabledCollections,\n } as ClientProps,\n generateSchemaMap: () => {\n if (!sanitizedFields || !Array.isArray(sanitizedFields) || sanitizedFields.length === 0) {\n return null\n }\n\n const schemaMap: FieldSchemaMap = new Map()\n schemaMap.set('fields', {\n fields: sanitizedFields,\n })\n\n return schemaMap\n },\n i18n,\n markdownTransformers: [\n createLinkMarkdownTransformer({ internalDocToHref: props.internalDocToHref }),\n ],\n nodes: [\n props?.disableAutoLinks === true\n ? null\n : createNode({\n jsonSchema: createAutoLinkNodeJSONSchema(sanitizedFieldsWithoutText),\n node: AutoLinkNode,\n // Since AutoLinkNodes are just internal links, they need no hooks or graphQL population promises\n validations: [linkValidation(props, sanitizedFieldsWithoutText)],\n }),\n createNode({\n getSubFields: () => {\n return sanitizedFieldsWithoutText\n },\n getSubFieldsData: ({ node }) => {\n return node?.fields\n },\n graphQLPopulationPromises: [linkPopulationPromiseHOC(props)],\n jsonSchema: createLinkNodeJSONSchema(sanitizedFieldsWithoutText),\n node: LinkNode,\n validations: [linkValidation(props, sanitizedFieldsWithoutText)],\n }),\n ].filter(Boolean) as Array<NodeWithHooks>,\n sanitizedServerFeatureProps: props,\n }\n },\n key: 'link',\n})\n"],"mappings":"AASA,SAASA,cAAc,QAAQ;AAK/B,SAASC,mBAAmB,QAAQ;AACpC,SAASC,UAAU,QAAQ;AAC3B,SAASC,6BAA6B,QAAQ;AAC9C,SAASC,YAAY,QAAQ;AAC7B,SAASC,QAAQ,QAAQ;AACzB,SAASC,wBAAwB,QAAQ;AACzC,SAASC,IAAI,QAAQ;AACrB,SACEC,4BAA4B,EAC5BC,wBAAwB,QAEnB;AACP,SAASC,oBAAoB,QAAQ;AACrC,SAASC,cAAc,QAAQ;AA8D/B,OAAO,MAAMC,WAAA,GAAcX,mBAAA,CAIzB;EACAY,OAAA,EAAS,MAAAA,CAAO;IAAEC,MAAA,EAAQC,OAAO;IAAEC,MAAM;IAAEC,iBAAiB;IAAEC;EAAK,CAAE;IACnE,IAAI,CAACA,KAAA,EAAO;MACVA,KAAA,GAAQ,CAAC;IACX;IACA,MAAMC,kBAAA,GAAqBJ,OAAA,CAAQK,WAAW,CAACC,GAAG,CAAEC,CAAA,IAAMA,CAAA,CAAEC,IAAI,KAAK,EAAE;IAEvE,MAAMC,kBAAA,GAAqBd,oBAAA,CACzBQ,KAAA,CAAMO,MAAM,GAAGP,KAAA,CAAMO,MAAM,GAAG,MAC9BV,OAAA,EACAG,KAAA,CAAMQ,kBAAkB,EACxBR,KAAA,CAAMS,mBAAmB,EACzBT,KAAA,CAAMU,QAAQ;IAGhB,MAAMC,eAAA,GAAkB,MAAM7B,cAAA,CAAe;MAC3Cc,MAAA,EAAQC,OAAA;MACRU,MAAA,EAAQD,kBAAA;MACRP,iBAAA;MACAa,+BAAA,EAAiCd,MAAA;MACjCG;IACF;IACAD,KAAA,CAAMO,MA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;MACAzC,IAAA;MACA4C,oBAAA,EAAsB,CACpBhD,6BAAA,CAA8B;QAAEiD,iBAAA,EAAmBlC,KAAA,CAAMkC;MAAkB,GAC5E;MACDC,KAAA,EAAO,CACLnC,KAAA,EAAOyB,gBAAA,KAAqB,OACxB,OACAzC,UAAA,CAAW;QACToD,UAAA,EAAY9C,4BAAA,CAA6BuB,0BAAA;QACzCwB,IAAA,EAAMnD,YAAA;QACN;QACAoD,WAAA,EAAa,CAAC7C,cAAA,CAAeO,KAAA,EAAOa,0BAAA;MACtC,IACJ7B,UAAA,CAAW;QACTuD,YAAA,EAAcA,CAAA;UACZ,OAAO1B,0BAAA;QACT;QACA2B,gBAAA,EAAkBA,CAAC;UAAEH;QAAI,CAAE;UACzB,OAAOA,IAAA,EAAM9B,MAAA;QACf;QACAkC,yBAAA,EAA2B,CAACrD,wBAAA,CAAyBY,KAAA,EAAO;QAC5DoC,UAAA,EAAY7C,wBAAA,CAAyBsB,0BAAA;QACrCwB,IAAA,EAAMlD,QAAA;QACNmD,WAAA,EAAa,CAAC7C,cAAA,CAAeO,KAAA,EAAOa,0BAAA;MACtC,GACD,CAACC,MAAM,CAAC4B,OAAA;MACTC,2BAAA,EAA6B3C;IAC/B;EACF;EACA4C,GAAA,EAAK;AACP","ignoreList":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { SerializedLexicalNode } from 'lexical';
|
|
2
|
+
import type { DefaultDocumentIDType, Field } from 'payload';
|
|
3
|
+
import type { SerializedLexicalElementBase } from '../../../types/nodeTypes.js';
|
|
4
|
+
import type { JSONSchemaFn } from '../../typesServer.js';
|
|
5
|
+
export type LinkFields = {
|
|
6
|
+
/** Custom fields added via `LinkFeature`'s `fields` prop. */
|
|
7
|
+
[k: string]: unknown;
|
|
8
|
+
doc?: {
|
|
9
|
+
relationTo: string;
|
|
10
|
+
/** Document ID, or the full doc when populated by the afterRead hook. */
|
|
11
|
+
value: {
|
|
12
|
+
[k: string]: unknown;
|
|
13
|
+
id: DefaultDocumentIDType;
|
|
14
|
+
} | DefaultDocumentIDType;
|
|
15
|
+
} | null;
|
|
16
|
+
linkType: 'custom' | 'internal';
|
|
17
|
+
newTab: boolean;
|
|
18
|
+
url?: string;
|
|
19
|
+
};
|
|
20
|
+
export interface SerializedLinkNode<TChildren extends SerializedLexicalNode = SerializedLexicalNode, TFields = LinkFields> extends SerializedLexicalElementBase<TChildren> {
|
|
21
|
+
fields: TFields;
|
|
22
|
+
/** @todo make required in 4.0 and type AutoLinkNode differently */
|
|
23
|
+
id?: string;
|
|
24
|
+
type: 'link';
|
|
25
|
+
}
|
|
26
|
+
export interface SerializedAutoLinkNode<TChildren extends SerializedLexicalNode = SerializedLexicalNode, TFields = LinkFields> extends SerializedLexicalElementBase<TChildren> {
|
|
27
|
+
fields: TFields;
|
|
28
|
+
type: 'autolink';
|
|
29
|
+
}
|
|
30
|
+
export declare const createLinkNodeJSONSchema: (sanitizedFieldsWithoutText: Field[]) => JSONSchemaFn;
|
|
31
|
+
export declare const createAutoLinkNodeJSONSchema: (sanitizedFieldsWithoutText: Field[]) => JSONSchemaFn;
|
|
32
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/features/link/server/schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AACpD,OAAO,KAAK,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAK3D,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAA;AAC/E,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAExE,MAAM,MAAM,UAAU,GAAG;IACvB,6DAA6D;IAC7D,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACpB,GAAG,CAAC,EAAE;QACJ,UAAU,EAAE,MAAM,CAAA;QAClB,yEAAyE;QACzE,KAAK,EAAE;YAAE,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;YAAC,EAAE,EAAE,qBAAqB,CAAA;SAAE,GAAG,qBAAqB,CAAA;KACnF,GAAG,IAAI,CAAA;IACR,QAAQ,EAAE,QAAQ,GAAG,UAAU,CAAA;IAC/B,MAAM,EAAE,OAAO,CAAA;IACf,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,CAAA;AAED,MAAM,WAAW,kBAAkB,CACjC,SAAS,SAAS,qBAAqB,GAAG,qBAAqB,EAC/D,OAAO,GAAG,UAAU,CACpB,SAAQ,4BAA4B,CAAC,SAAS,CAAC;IAC/C,MAAM,EAAE,OAAO,CAAA;IACf,mEAAmE;IACnE,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,sBAAsB,CACrC,SAAS,SAAS,qBAAqB,GAAG,qBAAqB,EAC/D,OAAO,GAAG,UAAU,CACpB,SAAQ,4BAA4B,CAAC,SAAS,CAAC;IAC/C,MAAM,EAAE,OAAO,CAAA;IACf,IAAI,EAAE,UAAU,CAAA;CACjB;AAqHD,eAAO,MAAM,wBAAwB,GAClC,4BAA4B,KAAK,EAAE,KAAG,YActC,CAAA;AAEH,eAAO,MAAM,4BAA4B,GACtC,4BAA4B,KAAK,EAAE,KAAG,YAatC,CAAA"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { createHash } from 'crypto';
|
|
2
|
+
import { fieldsToJSONSchema, flattenAllFields } from 'payload';
|
|
3
|
+
/**
|
|
4
|
+
* MUST stay byte-for-byte in sync with the runtime `LinkFields`, `SerializedLinkNode`,
|
|
5
|
+
* and `SerializedAutoLinkNode` declared above.
|
|
6
|
+
*/
|
|
7
|
+
const LINK_NODES_TS = `export interface LexicalLinkFields {
|
|
8
|
+
[k: string]: unknown;
|
|
9
|
+
doc?: {
|
|
10
|
+
relationTo: string;
|
|
11
|
+
value: Config['db']['defaultIDType'] | { [k: string]: unknown; id: Config['db']['defaultIDType'] };
|
|
12
|
+
} | null;
|
|
13
|
+
linkType: 'custom' | 'internal';
|
|
14
|
+
newTab: boolean;
|
|
15
|
+
url?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface SerializedLinkNode<TChildren, TFields = LexicalLinkFields> extends SerializedLexicalElementBase<TChildren> {
|
|
18
|
+
type: 'link';
|
|
19
|
+
fields: TFields;
|
|
20
|
+
id?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface SerializedAutoLinkNode<TChildren, TFields = LexicalLinkFields> extends SerializedLexicalElementBase<TChildren> {
|
|
23
|
+
type: 'autolink';
|
|
24
|
+
fields: TFields;
|
|
25
|
+
}`;
|
|
26
|
+
const buildLinkFieldsJSONSchema = (sanitizedFieldsWithoutText, {
|
|
27
|
+
collectionIDFieldTypes,
|
|
28
|
+
config,
|
|
29
|
+
i18n,
|
|
30
|
+
interfaceNameDefinitions,
|
|
31
|
+
typeStringDefinitions
|
|
32
|
+
}) => {
|
|
33
|
+
const flattenedExtraFields = flattenAllFields({
|
|
34
|
+
fields: sanitizedFieldsWithoutText
|
|
35
|
+
});
|
|
36
|
+
const userFieldsSchema = flattenedExtraFields.length > 0 && config ? fieldsToJSONSchema({
|
|
37
|
+
collectionIDFieldTypes,
|
|
38
|
+
config,
|
|
39
|
+
fields: flattenedExtraFields,
|
|
40
|
+
i18n,
|
|
41
|
+
interfaceNameDefinitions,
|
|
42
|
+
typeStringDefinitions
|
|
43
|
+
}) : {
|
|
44
|
+
properties: {},
|
|
45
|
+
required: []
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
type: 'object',
|
|
49
|
+
additionalProperties: false,
|
|
50
|
+
properties: {
|
|
51
|
+
...userFieldsSchema.properties,
|
|
52
|
+
doc: {
|
|
53
|
+
oneOf: [{
|
|
54
|
+
type: 'object',
|
|
55
|
+
additionalProperties: false,
|
|
56
|
+
properties: {
|
|
57
|
+
relationTo: {
|
|
58
|
+
type: 'string'
|
|
59
|
+
},
|
|
60
|
+
value: {
|
|
61
|
+
oneOf: [{
|
|
62
|
+
type: 'string'
|
|
63
|
+
}, {
|
|
64
|
+
type: 'number'
|
|
65
|
+
},
|
|
66
|
+
// Populated form (afterRead inflates `value` into the doc).
|
|
67
|
+
{
|
|
68
|
+
type: 'object',
|
|
69
|
+
additionalProperties: true,
|
|
70
|
+
properties: {
|
|
71
|
+
id: {
|
|
72
|
+
type: ['string', 'number']
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
required: ['id']
|
|
76
|
+
}]
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
required: ['relationTo', 'value']
|
|
80
|
+
}, {
|
|
81
|
+
type: 'null'
|
|
82
|
+
}]
|
|
83
|
+
},
|
|
84
|
+
linkType: {
|
|
85
|
+
type: 'string',
|
|
86
|
+
enum: ['custom', 'internal']
|
|
87
|
+
},
|
|
88
|
+
newTab: {
|
|
89
|
+
type: 'boolean'
|
|
90
|
+
},
|
|
91
|
+
url: {
|
|
92
|
+
type: 'string'
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
// `linkType`/`newTab` are already in `userFieldsSchema.required`; use Set to dedupe,
|
|
96
|
+
// so `required` stays unique (draft 2020-12 enforces `uniqueItems`).
|
|
97
|
+
required: [...new Set(['linkType', 'newTab', ...userFieldsSchema.required])]
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
/** Fields auto-attached by `LinkFeature` (see `transformExtraFields`). */
|
|
101
|
+
const STANDARD_LINK_FIELD_NAMES = new Set(['doc', 'linkType', 'newTab', 'url']);
|
|
102
|
+
const hashLinkFields = schema => createHash('sha256').update(JSON.stringify(schema)).digest('hex').slice(0, 8).toUpperCase();
|
|
103
|
+
/**
|
|
104
|
+
* With custom link fields, emit a `LexicalLinkFields_<hash>` interface (hashed by its own content)
|
|
105
|
+
* so the link node picks up their real shape. Without any, reuse the default `LexicalLinkFields` for
|
|
106
|
+
* cross-alias assignability.
|
|
107
|
+
*/
|
|
108
|
+
const resolveLinkFieldsRef = (sanitizedFieldsWithoutText, args) => {
|
|
109
|
+
const fieldsSchema = buildLinkFieldsJSONSchema(sanitizedFieldsWithoutText, args);
|
|
110
|
+
const hasUserExtras = sanitizedFieldsWithoutText.some(field => 'name' in field && !STANDARD_LINK_FIELD_NAMES.has(field.name));
|
|
111
|
+
if (!hasUserExtras) {
|
|
112
|
+
return {
|
|
113
|
+
fieldsRef: fieldsSchema,
|
|
114
|
+
fieldsTypeName: 'LexicalLinkFields'
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
const fieldsTypeName = `LexicalLinkFields_${hashLinkFields(fieldsSchema)}`;
|
|
118
|
+
args.interfaceNameDefinitions.set(fieldsTypeName, fieldsSchema);
|
|
119
|
+
return {
|
|
120
|
+
fieldsRef: {
|
|
121
|
+
$ref: `#/$defs/${fieldsTypeName}`
|
|
122
|
+
},
|
|
123
|
+
fieldsTypeName
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
export const createLinkNodeJSONSchema = sanitizedFieldsWithoutText => args => {
|
|
127
|
+
const {
|
|
128
|
+
elementNodeSchema,
|
|
129
|
+
nodeUnionName,
|
|
130
|
+
typeStringDefinitions
|
|
131
|
+
} = args;
|
|
132
|
+
typeStringDefinitions.add(LINK_NODES_TS);
|
|
133
|
+
const {
|
|
134
|
+
fieldsRef,
|
|
135
|
+
fieldsTypeName
|
|
136
|
+
} = resolveLinkFieldsRef(sanitizedFieldsWithoutText, args);
|
|
137
|
+
return elementNodeSchema({
|
|
138
|
+
nodeType: 'link',
|
|
139
|
+
properties: {
|
|
140
|
+
id: {
|
|
141
|
+
type: 'string'
|
|
142
|
+
},
|
|
143
|
+
fields: fieldsRef
|
|
144
|
+
},
|
|
145
|
+
required: ['fields'],
|
|
146
|
+
tsType: `SerializedLinkNode<${nodeUnionName}, ${fieldsTypeName}>`
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
export const createAutoLinkNodeJSONSchema = sanitizedFieldsWithoutText => args => {
|
|
150
|
+
const {
|
|
151
|
+
elementNodeSchema,
|
|
152
|
+
nodeUnionName,
|
|
153
|
+
typeStringDefinitions
|
|
154
|
+
} = args;
|
|
155
|
+
typeStringDefinitions.add(LINK_NODES_TS);
|
|
156
|
+
const {
|
|
157
|
+
fieldsRef,
|
|
158
|
+
fieldsTypeName
|
|
159
|
+
} = resolveLinkFieldsRef(sanitizedFieldsWithoutText, args);
|
|
160
|
+
return elementNodeSchema({
|
|
161
|
+
nodeType: 'autolink',
|
|
162
|
+
properties: {
|
|
163
|
+
fields: fieldsRef
|
|
164
|
+
},
|
|
165
|
+
required: ['fields'],
|
|
166
|
+
tsType: `SerializedAutoLinkNode<${nodeUnionName}, ${fieldsTypeName}>`
|
|
167
|
+
});
|
|
168
|
+
};
|
|
169
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","names":["createHash","fieldsToJSONSchema","flattenAllFields","LINK_NODES_TS","buildLinkFieldsJSONSchema","sanitizedFieldsWithoutText","collectionIDFieldTypes","config","i18n","interfaceNameDefinitions","typeStringDefinitions","flattenedExtraFields","fields","userFieldsSchema","length","properties","required","type","additionalProperties","doc","oneOf","relationTo","value","id","linkType","enum","newTab","url","Set","STANDARD_LINK_FIELD_NAMES","hashLinkFields","schema","update","JSON","stringify","digest","slice","toUpperCase","resolveLinkFieldsRef","args","fieldsSchema","hasUserExtras","some","field","has","name","fieldsRef","fieldsTypeName","set","$ref","createLinkNodeJSONSchema","elementNodeSchema","nodeUnionName","add","nodeType","tsType","createAutoLinkNodeJSONSchema"],"sources":["../../../../src/features/link/server/schema.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema'\nimport type { SerializedLexicalNode } from 'lexical'\nimport type { DefaultDocumentIDType, Field } from 'payload'\n\nimport { createHash } from 'crypto'\nimport { fieldsToJSONSchema, flattenAllFields } from 'payload'\n\nimport type { SerializedLexicalElementBase } from '../../../types/nodeTypes.js'\nimport type { JSONSchemaArgs, JSONSchemaFn } from '../../typesServer.js'\n\nexport type LinkFields = {\n /** Custom fields added via `LinkFeature`'s `fields` prop. */\n [k: string]: unknown\n doc?: {\n relationTo: string\n /** Document ID, or the full doc when populated by the afterRead hook. */\n value: { [k: string]: unknown; id: DefaultDocumentIDType } | DefaultDocumentIDType\n } | null\n linkType: 'custom' | 'internal'\n newTab: boolean\n url?: string\n}\n\nexport interface SerializedLinkNode<\n TChildren extends SerializedLexicalNode = SerializedLexicalNode,\n TFields = LinkFields,\n> extends SerializedLexicalElementBase<TChildren> {\n fields: TFields\n /** @todo make required in 4.0 and type AutoLinkNode differently */\n id?: string\n type: 'link'\n}\n\nexport interface SerializedAutoLinkNode<\n TChildren extends SerializedLexicalNode = SerializedLexicalNode,\n TFields = LinkFields,\n> extends SerializedLexicalElementBase<TChildren> {\n fields: TFields\n type: 'autolink'\n}\n\n/**\n * MUST stay byte-for-byte in sync with the runtime `LinkFields`, `SerializedLinkNode`,\n * and `SerializedAutoLinkNode` declared above.\n */\nconst LINK_NODES_TS = `export interface LexicalLinkFields {\n [k: string]: unknown;\n doc?: {\n relationTo: string;\n value: Config['db']['defaultIDType'] | { [k: string]: unknown; id: Config['db']['defaultIDType'] };\n } | null;\n linkType: 'custom' | 'internal';\n newTab: boolean;\n url?: string;\n}\nexport interface SerializedLinkNode<TChildren, TFields = LexicalLinkFields> extends SerializedLexicalElementBase<TChildren> {\n type: 'link';\n fields: TFields;\n id?: string;\n}\nexport interface SerializedAutoLinkNode<TChildren, TFields = LexicalLinkFields> extends SerializedLexicalElementBase<TChildren> {\n type: 'autolink';\n fields: TFields;\n}`\n\nconst buildLinkFieldsJSONSchema = (\n sanitizedFieldsWithoutText: Field[],\n {\n collectionIDFieldTypes,\n config,\n i18n,\n interfaceNameDefinitions,\n typeStringDefinitions,\n }: JSONSchemaArgs,\n): JSONSchema4 => {\n const flattenedExtraFields = flattenAllFields({ fields: sanitizedFieldsWithoutText })\n const userFieldsSchema =\n flattenedExtraFields.length > 0 && config\n ? fieldsToJSONSchema({\n collectionIDFieldTypes,\n config,\n fields: flattenedExtraFields,\n i18n,\n interfaceNameDefinitions,\n typeStringDefinitions,\n })\n : { properties: {}, required: [] }\n\n return {\n type: 'object',\n additionalProperties: false,\n properties: {\n ...userFieldsSchema.properties,\n doc: {\n oneOf: [\n {\n type: 'object',\n additionalProperties: false,\n properties: {\n relationTo: { type: 'string' },\n value: {\n oneOf: [\n { type: 'string' },\n { type: 'number' },\n // Populated form (afterRead inflates `value` into the doc).\n {\n type: 'object',\n additionalProperties: true,\n properties: { id: { type: ['string', 'number'] } },\n required: ['id'],\n },\n ],\n },\n },\n required: ['relationTo', 'value'],\n },\n { type: 'null' },\n ],\n },\n linkType: { type: 'string', enum: ['custom', 'internal'] },\n newTab: { type: 'boolean' },\n url: { type: 'string' },\n },\n // `linkType`/`newTab` are already in `userFieldsSchema.required`; use Set to dedupe,\n // so `required` stays unique (draft 2020-12 enforces `uniqueItems`).\n required: [...new Set(['linkType', 'newTab', ...userFieldsSchema.required])],\n }\n}\n\n/** Fields auto-attached by `LinkFeature` (see `transformExtraFields`). */\nconst STANDARD_LINK_FIELD_NAMES = new Set(['doc', 'linkType', 'newTab', 'url'])\n\nconst hashLinkFields = (schema: JSONSchema4): string =>\n createHash('sha256').update(JSON.stringify(schema)).digest('hex').slice(0, 8).toUpperCase()\n\n/**\n * With custom link fields, emit a `LexicalLinkFields_<hash>` interface (hashed by its own content)\n * so the link node picks up their real shape. Without any, reuse the default `LexicalLinkFields` for\n * cross-alias assignability.\n */\nconst resolveLinkFieldsRef = (\n sanitizedFieldsWithoutText: Field[],\n args: JSONSchemaArgs,\n): { fieldsRef: JSONSchema4; fieldsTypeName: string } => {\n const fieldsSchema = buildLinkFieldsJSONSchema(sanitizedFieldsWithoutText, args)\n const hasUserExtras = sanitizedFieldsWithoutText.some(\n (field) => 'name' in field && !STANDARD_LINK_FIELD_NAMES.has(field.name),\n )\n if (!hasUserExtras) {\n return { fieldsRef: fieldsSchema, fieldsTypeName: 'LexicalLinkFields' }\n }\n const fieldsTypeName = `LexicalLinkFields_${hashLinkFields(fieldsSchema)}`\n args.interfaceNameDefinitions.set(fieldsTypeName, fieldsSchema)\n return { fieldsRef: { $ref: `#/$defs/${fieldsTypeName}` }, fieldsTypeName }\n}\n\nexport const createLinkNodeJSONSchema =\n (sanitizedFieldsWithoutText: Field[]): JSONSchemaFn =>\n (args) => {\n const { elementNodeSchema, nodeUnionName, typeStringDefinitions } = args\n typeStringDefinitions.add(LINK_NODES_TS)\n const { fieldsRef, fieldsTypeName } = resolveLinkFieldsRef(sanitizedFieldsWithoutText, args)\n return elementNodeSchema({\n nodeType: 'link',\n properties: {\n id: { type: 'string' },\n fields: fieldsRef,\n },\n required: ['fields'],\n tsType: `SerializedLinkNode<${nodeUnionName}, ${fieldsTypeName}>`,\n })\n }\n\nexport const createAutoLinkNodeJSONSchema =\n (sanitizedFieldsWithoutText: Field[]): JSONSchemaFn =>\n (args) => {\n const { elementNodeSchema, nodeUnionName, typeStringDefinitions } = args\n typeStringDefinitions.add(LINK_NODES_TS)\n const { fieldsRef, fieldsTypeName } = resolveLinkFieldsRef(sanitizedFieldsWithoutText, args)\n return elementNodeSchema({\n nodeType: 'autolink',\n properties: {\n fields: fieldsRef,\n },\n required: ['fields'],\n tsType: `SerializedAutoLinkNode<${nodeUnionName}, ${fieldsTypeName}>`,\n })\n }\n"],"mappings":"AAIA,SAASA,UAAU,QAAQ;AAC3B,SAASC,kBAAkB,EAAEC,gBAAgB,QAAQ;AAoCrD;;;;AAIA,MAAMC,aAAA,GAAgB;;;;;;;;;;;;;;;;;;EAkBpB;AAEF,MAAMC,yBAAA,GAA4BA,CAChCC,0BAAA,EACA;EACEC,sBAAsB;EACtBC,MAAM;EACNC,IAAI;EACJC,wBAAwB;EACxBC;AAAqB,CACN;EAEjB,MAAMC,oBAAA,GAAuBT,gBAAA,CAAiB;IAAEU,MAAA,EAAQP;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A,KAAkBL,cAAA;EAClD;AACF;AAEF,OAAO,MAAMS,4BAAA,GACVnD,0BAAA,IACAkC,IAAA;EACC,MAAM;IAAEY,iBAAiB;IAAEC,aAAa;IAAE1C;EAAqB,CAAE,GAAG6B,IAAA;EACpE7B,qBAAA,CAAsB2C,GAAG,CAAClD,aAAA;EAC1B,MAAM;IAAE2C,SAAS;IAAEC;EAAc,CAAE,GAAGT,oBAAA,CAAqBjC,0BAAA,EAA4BkC,IAAA;EACvF,OAAOY,iBAAA,CAAkB;IACvBG,QAAA,EAAU;IACVvC,UAAA,EAAY;MACVH,MAAA,EAAQkC;IACV;IACA9B,QAAA,EAAU,CAAC,SAAS;IACpBuC,MAAA,EAAQ,0BAA0BH,aAAA,KAAkBL,cAAA;EACtD;AACF","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Field } from 'payload';
|
|
2
2
|
import type { NodeValidation } from '../../typesServer.js';
|
|
3
|
-
import type { SerializedAutoLinkNode, SerializedLinkNode } from '../nodes/types.js';
|
|
4
3
|
import type { LinkFeatureServerProps } from './index.js';
|
|
4
|
+
import type { SerializedAutoLinkNode, SerializedLinkNode } from './schema.js';
|
|
5
5
|
export declare const linkValidation: (props: LinkFeatureServerProps, sanitizedFieldsWithoutText: Field[]) => NodeValidation<SerializedAutoLinkNode | SerializedLinkNode>;
|
|
6
6
|
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../../src/features/link/server/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAIpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,sBAAsB,EAAE,
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../../src/features/link/server/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAIpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AACxD,OAAO,KAAK,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAE7E,eAAO,MAAM,cAAc,GACzB,OAAO,sBAAsB,EAC7B,4BAA4B,KAAK,EAAE,KAClC,cAAc,CAAC,sBAAsB,GAAG,kBAAkB,CA4C5D,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","names":["fieldSchemasToFormState","linkValidation","props","sanitizedFieldsWithoutText","node","validation","options","id","collectionSlug","data","operation","preferences","req","result","fields","documentData","fieldSchemaMap","undefined","initialBlockData","permissions","renderAllFields","schemaPath","errorPathsSet","Set","fieldKey","fieldState","errorPaths","length","errorPath","add","Array","from","join"],"sources":["../../../../src/features/link/server/validate.ts"],"sourcesContent":["import type { Field } from 'payload'\n\nimport { fieldSchemasToFormState } from '@payloadcms/ui/forms/fieldSchemasToFormState'\n\nimport type { NodeValidation } from '../../typesServer.js'\nimport type {
|
|
1
|
+
{"version":3,"file":"validate.js","names":["fieldSchemasToFormState","linkValidation","props","sanitizedFieldsWithoutText","node","validation","options","id","collectionSlug","data","operation","preferences","req","result","fields","documentData","fieldSchemaMap","undefined","initialBlockData","permissions","renderAllFields","schemaPath","errorPathsSet","Set","fieldKey","fieldState","errorPaths","length","errorPath","add","Array","from","join"],"sources":["../../../../src/features/link/server/validate.ts"],"sourcesContent":["import type { Field } from 'payload'\n\nimport { fieldSchemasToFormState } from '@payloadcms/ui/forms/fieldSchemasToFormState'\n\nimport type { NodeValidation } from '../../typesServer.js'\nimport type { LinkFeatureServerProps } from './index.js'\nimport type { SerializedAutoLinkNode, SerializedLinkNode } from './schema.js'\n\nexport const linkValidation = (\n props: LinkFeatureServerProps,\n sanitizedFieldsWithoutText: Field[],\n): NodeValidation<SerializedAutoLinkNode | SerializedLinkNode> => {\n return async ({\n node,\n validation: {\n options: { id, collectionSlug, data, operation, preferences, req },\n },\n }) => {\n /**\n * Run fieldSchemasToFormState as that properly validates link fields and link sub-fields\n */\n\n const result = await fieldSchemasToFormState({\n id,\n collectionSlug,\n data: node.fields,\n documentData: data,\n fields: sanitizedFieldsWithoutText, // Sanitized in feature.server.ts\n fieldSchemaMap: undefined,\n initialBlockData: node.fields,\n operation: operation === 'create' || operation === 'update' ? operation : 'update',\n permissions: {},\n preferences,\n renderAllFields: false,\n req,\n schemaPath: '',\n })\n\n const errorPathsSet = new Set<string>()\n for (const fieldKey in result) {\n const fieldState = result[fieldKey]\n if (fieldState?.errorPaths?.length) {\n for (const errorPath of fieldState.errorPaths) {\n errorPathsSet.add(errorPath)\n }\n }\n }\n const errorPaths = Array.from(errorPathsSet)\n\n if (errorPaths.length) {\n return 'The following fields are invalid: ' + errorPaths.join(', ')\n }\n\n return true\n }\n}\n"],"mappings":"AAEA,SAASA,uBAAuB,QAAQ;AAMxC,OAAO,MAAMC,cAAA,GAAiBA,CAC5BC,KAAA,EACAC,0BAAA;EAEA,OAAO,OAAO;IACZC,IAAI;IACJC,UAAA,EAAY;MACVC,OAAA,EAAS;QAAEC,EAAE;QAAEC,cAAc;QAAEC,IAAI;QAAEC,SAAS;QAAEC,WAAW;QAAEC;MAAG;IAAE;EACnE,CACF;IACC;;;IAIA,MAAMC,MAAA,GAAS,MAAMb,uBAAA,CAAwB;MAC3CO,EAAA;MACAC,cAAA;MACAC,IAAA,EAAML,IAAA,CAAKU,MAAM;MACjBC,YAAA,EAAcN,IAAA;MACdK,MAAA,EAAQX,0BAAA;MACRa,cAAA,EAAgBC,SAAA;MAChBC,gBAAA,EAAkBd,IAAA,CAAKU,MAAM;MAC7BJ,SAAA,EAAWA,SAAA,KAAc,YAAYA,SAAA,KAAc,WAAWA,SAAA,GAAY;MAC1ES,WAAA,EAAa,CAAC;MACdR,WAAA;MACAS,eAAA,EAAiB;MACjBR,GAAA;MACAS,UAAA,EAAY;IACd;IAEA,MAAMC,aAAA,GAAgB,IAAIC,GAAA;IAC1B,KAAK,MAAMC,QAAA,IAAYX,MAAA,EAAQ;MAC7B,MAAMY,UAAA,GAAaZ,MAAM,CAACW,QAAA,CAAS;MACnC,IAAIC,UAAA,EAAYC,UAAA,EAAYC,MAAA,EAAQ;QAClC,KAAK,MAAMC,SAAA,IAAaH,UAAA,CAAWC,UAAU,EAAE;UAC7CJ,aAAA,CAAcO,GAAG,CAACD,SAAA;QACpB;MACF;IACF;IACA,MAAMF,UAAA,GAAaI,KAAA,CAAMC,IAAI,CAACT,aAAA;IAE9B,IAAII,UAAA,CAAWC,MAAM,EAAE;MACrB,OAAO,uCAAuCD,UAAA,CAAWM,IAAI,CAAC;IAChE;IAEA,OAAO;EACT;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/lists/checklist/server/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/lists/checklist/server/index.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,gBAAgB,kGAqB3B,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ListItemNode, ListNode } from '@lexical/list';
|
|
2
2
|
import { createServerFeature } from '../../../../utilities/createServerFeature.js';
|
|
3
3
|
import { createNode } from '../../../typeUtilities.js';
|
|
4
|
+
import { listItemNodeJSONSchema, listNodeJSONSchema } from '../../shared/schema.js';
|
|
4
5
|
import { shouldRegisterListBaseNodes } from '../../shared/shouldRegisterListBaseNodes.js';
|
|
5
6
|
import { CHECK_LIST } from '../markdownTransformers.js';
|
|
6
7
|
import { i18n } from './i18n.js';
|
|
@@ -13,8 +14,10 @@ export const ChecklistFeature = createServerFeature({
|
|
|
13
14
|
i18n,
|
|
14
15
|
markdownTransformers: [CHECK_LIST],
|
|
15
16
|
nodes: shouldRegisterListBaseNodes('checklist', featureProviderMap) ? [createNode({
|
|
17
|
+
jsonSchema: listNodeJSONSchema,
|
|
16
18
|
node: ListNode
|
|
17
19
|
}), createNode({
|
|
20
|
+
jsonSchema: listItemNodeJSONSchema,
|
|
18
21
|
node: ListItemNode
|
|
19
22
|
})] : []
|
|
20
23
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["ListItemNode","ListNode","createServerFeature","createNode","shouldRegisterListBaseNodes","CHECK_LIST","i18n","ChecklistFeature","feature","featureProviderMap","ClientFeature","markdownTransformers","nodes","node","key"],"sources":["../../../../../src/features/lists/checklist/server/index.ts"],"sourcesContent":["import { ListItemNode, ListNode } from '@lexical/list'\n\nimport { createServerFeature } from '../../../../utilities/createServerFeature.js'\nimport { createNode } from '../../../typeUtilities.js'\nimport { shouldRegisterListBaseNodes } from '../../shared/shouldRegisterListBaseNodes.js'\nimport { CHECK_LIST } from '../markdownTransformers.js'\nimport { i18n } from './i18n.js'\n\nexport const ChecklistFeature = createServerFeature({\n feature: ({ featureProviderMap }) => {\n return {\n ClientFeature: '@payloadcms/richtext-lexical/client#ChecklistFeatureClient',\n i18n,\n markdownTransformers: [CHECK_LIST],\n nodes: shouldRegisterListBaseNodes('checklist', featureProviderMap)\n ? [\n createNode({\n node: ListNode,\n }),\n createNode({\n node: ListItemNode,\n }),\n ]\n : [],\n }\n },\n key: 'checklist',\n})\n"],"mappings":"AAAA,SAASA,YAAY,EAAEC,QAAQ,QAAQ;AAEvC,SAASC,mBAAmB,QAAQ;AACpC,SAASC,UAAU,QAAQ;AAC3B,SAASC,2BAA2B,QAAQ;AAC5C,SAASC,UAAU,QAAQ;AAC3B,SAASC,IAAI,QAAQ;AAErB,OAAO,MAAMC,gBAAA,
|
|
1
|
+
{"version":3,"file":"index.js","names":["ListItemNode","ListNode","createServerFeature","createNode","listItemNodeJSONSchema","listNodeJSONSchema","shouldRegisterListBaseNodes","CHECK_LIST","i18n","ChecklistFeature","feature","featureProviderMap","ClientFeature","markdownTransformers","nodes","jsonSchema","node","key"],"sources":["../../../../../src/features/lists/checklist/server/index.ts"],"sourcesContent":["import { ListItemNode, ListNode } from '@lexical/list'\n\nimport { createServerFeature } from '../../../../utilities/createServerFeature.js'\nimport { createNode } from '../../../typeUtilities.js'\nimport { listItemNodeJSONSchema, listNodeJSONSchema } from '../../shared/schema.js'\nimport { shouldRegisterListBaseNodes } from '../../shared/shouldRegisterListBaseNodes.js'\nimport { CHECK_LIST } from '../markdownTransformers.js'\nimport { i18n } from './i18n.js'\n\nexport const ChecklistFeature = createServerFeature({\n feature: ({ featureProviderMap }) => {\n return {\n ClientFeature: '@payloadcms/richtext-lexical/client#ChecklistFeatureClient',\n i18n,\n markdownTransformers: [CHECK_LIST],\n nodes: shouldRegisterListBaseNodes('checklist', featureProviderMap)\n ? [\n createNode({\n jsonSchema: listNodeJSONSchema,\n node: ListNode,\n }),\n createNode({\n jsonSchema: listItemNodeJSONSchema,\n node: ListItemNode,\n }),\n ]\n : [],\n }\n },\n key: 'checklist',\n})\n"],"mappings":"AAAA,SAASA,YAAY,EAAEC,QAAQ,QAAQ;AAEvC,SAASC,mBAAmB,QAAQ;AACpC,SAASC,UAAU,QAAQ;AAC3B,SAASC,sBAAsB,EAAEC,kBAAkB,QAAQ;AAC3D,SAASC,2BAA2B,QAAQ;AAC5C,SAASC,UAAU,QAAQ;AAC3B,SAASC,IAAI,QAAQ;AAErB,OAAO,MAAMC,gBAAA,GAAmBP,mBAAA,CAAoB;EAClDQ,OAAA,EAASA,CAAC;IAAEC;EAAkB,CAAE;IAC9B,OAAO;MACLC,aAAA,EAAe;MACfJ,IAAA;MACAK,oBAAA,EAAsB,CAACN,UAAA,CAAW;MAClCO,KAAA,EAAOR,2BAAA,CAA4B,aAAaK,kBAAA,IAC5C,CACER,UAAA,CAAW;QACTY,UAAA,EAAYV,kBAAA;QACZW,IAAA,EAAMf;MACR,IACAE,UAAA,CAAW;QACTY,UAAA,EAAYX,sBAAA;QACZY,IAAA,EAAMhB;MACR,GACD,GACD;IACN;EACF;EACAiB,GAAA,EAAK;AACP","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/lists/orderedList/server/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/lists/orderedList/server/index.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,kBAAkB,kGAqB7B,CAAA"}
|