@payloadcms/richtext-lexical 4.0.0-internal.cd69eef → 4.0.0-internal.d1cc1d3
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/exports/client/{Field-QGSHF22S.js → Field-IZKDIUJY.js} +2 -2
- package/dist/exports/client/bundled.css +1 -1
- package/dist/exports/client/chunk-43E5QYAA.js +2 -0
- package/dist/exports/client/chunk-43E5QYAA.js.map +7 -0
- package/dist/exports/client/chunk-SSMQFWCQ.js +2 -0
- package/dist/exports/client/chunk-SSMQFWCQ.js.map +7 -0
- package/dist/exports/client/component-D5QLYS7W.js +2 -0
- package/dist/exports/client/component-D5QLYS7W.js.map +7 -0
- package/dist/exports/client/index.d.ts +1 -1
- package/dist/exports/client/index.d.ts.map +1 -1
- package/dist/exports/client/index.js +21 -21
- package/dist/exports/client/index.js.map +4 -4
- package/dist/features/blocks/server/index.js +2 -2
- package/dist/features/blocks/server/index.js.map +1 -1
- package/dist/features/debug/testRecorder/client/plugin/index.css +0 -1
- 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 +1 -1
- package/dist/features/horizontalRule/client/nodes/HorizontalRuleNode.js.map +1 -1
- package/dist/features/horizontalRule/server/nodes/HorizontalRuleNode.d.ts +1 -1
- package/dist/features/horizontalRule/server/nodes/HorizontalRuleNode.d.ts.map +1 -1
- package/dist/features/horizontalRule/server/nodes/HorizontalRuleNode.js +1 -1
- package/dist/features/horizontalRule/server/nodes/HorizontalRuleNode.js.map +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/index.css +0 -1
- package/dist/features/link/nodes/AutoLinkNode.d.ts +1 -1
- package/dist/features/link/nodes/AutoLinkNode.d.ts.map +1 -1
- package/dist/features/link/nodes/AutoLinkNode.js.map +1 -1
- package/dist/features/link/nodes/LinkNode.d.ts +1 -1
- package/dist/features/link/nodes/LinkNode.d.ts.map +1 -1
- package/dist/features/link/nodes/LinkNode.js.map +1 -1
- package/dist/features/link/server/baseFields.d.ts.map +1 -1
- package/dist/features/link/server/baseFields.js +5 -4
- package/dist/features/link/server/baseFields.js.map +1 -1
- package/dist/features/link/server/index.js +2 -2
- package/dist/features/link/server/index.js.map +1 -1
- package/dist/features/relationship/shared/filterEnabledRelationshipCollections.d.ts.map +1 -1
- package/dist/features/relationship/shared/filterEnabledRelationshipCollections.js +3 -2
- package/dist/features/relationship/shared/filterEnabledRelationshipCollections.js.map +1 -1
- package/dist/features/table/client/index.d.ts.map +1 -0
- package/dist/features/table/client/index.js.map +1 -0
- package/dist/features/table/client/plugins/TableActionMenuPlugin/index.d.ts.map +1 -0
- package/dist/features/table/client/plugins/TableActionMenuPlugin/index.js.map +1 -0
- package/dist/features/table/client/plugins/TableCellResizerPlugin/index.d.ts.map +1 -0
- package/dist/features/table/client/plugins/TableCellResizerPlugin/index.js.map +1 -0
- package/dist/features/table/client/plugins/TableHoverActionsPlugin/index.d.ts.map +1 -0
- package/dist/features/table/client/plugins/TableHoverActionsPlugin/index.js.map +1 -0
- package/dist/features/table/client/plugins/TablePlugin/TableGridPopup/index.d.ts.map +1 -0
- package/dist/features/table/client/plugins/TablePlugin/TableGridPopup/index.js.map +1 -0
- package/dist/features/table/client/plugins/TablePlugin/index.d.ts.map +1 -0
- package/dist/features/table/client/plugins/TablePlugin/index.js.map +1 -0
- package/dist/features/table/client/utils/debounce.d.ts.map +1 -0
- package/dist/features/table/client/utils/debounce.js.map +1 -0
- package/dist/features/table/client/utils/useDebounce.d.ts.map +1 -0
- package/dist/features/table/client/utils/useDebounce.js.map +1 -0
- package/dist/features/table/markdownTransformer.d.ts.map +1 -0
- package/dist/features/table/markdownTransformer.js.map +1 -0
- package/dist/features/table/server/index.d.ts +3 -0
- package/dist/features/table/server/index.d.ts.map +1 -0
- package/dist/features/{experimental_table → table}/server/index.js +4 -4
- package/dist/features/table/server/index.js.map +1 -0
- package/dist/features/table/server/schema.d.ts.map +1 -0
- package/dist/features/table/server/schema.js.map +1 -0
- package/dist/features/toolbars/fixed/client/Toolbar/index.css +2 -4
- package/dist/features/toolbars/inline/client/Toolbar/index.css +0 -1
- package/dist/features/toolbars/shared/ToolbarDropdown/index.css +0 -2
- package/dist/features/typesServer.d.ts +1 -1
- package/dist/features/typesServer.d.ts.map +1 -1
- package/dist/features/typesServer.js.map +1 -1
- package/dist/features/upload/client/component/index.js +2 -1
- package/dist/features/upload/client/component/index.js.map +1 -1
- package/dist/features/upload/server/index.js +2 -2
- package/dist/features/upload/server/index.js.map +1 -1
- package/dist/field/bundled.css +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/lexical/LexicalEditor.css +18 -20
- package/dist/lexical/config/server/loader.d.ts +1 -1
- package/dist/lexical/config/server/loader.d.ts.map +1 -1
- package/dist/lexical/config/server/loader.js +2 -2
- package/dist/lexical/config/server/loader.js.map +1 -1
- package/dist/lexical/config/server/sanitize.d.ts +1 -1
- package/dist/lexical/config/server/sanitize.d.ts.map +1 -1
- package/dist/lexical/config/server/sanitize.js +2 -2
- package/dist/lexical/config/server/sanitize.js.map +1 -1
- package/dist/lexical/plugins/InsertParagraphAtEnd/index.css +0 -1
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.d.ts +0 -1
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.d.ts.map +1 -1
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js +1 -20
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js.map +1 -1
- package/dist/lexical/plugins/SlashMenu/index.css +0 -1
- package/dist/lexical/ui/ContentEditable.css +16 -15
- package/dist/lexical-proxy/@lexical-react/ExtensionComponent.d.ts +2 -0
- package/dist/lexical-proxy/@lexical-react/ExtensionComponent.d.ts.map +1 -0
- package/dist/lexical-proxy/@lexical-react/ExtensionComponent.js +2 -0
- package/dist/lexical-proxy/@lexical-react/ExtensionComponent.js.map +1 -0
- package/dist/lexical-proxy/@lexical-react/LexicalExtensionComposer.d.ts +2 -0
- package/dist/lexical-proxy/@lexical-react/LexicalExtensionComposer.d.ts.map +1 -0
- package/dist/lexical-proxy/@lexical-react/LexicalExtensionComposer.js +2 -0
- package/dist/lexical-proxy/@lexical-react/LexicalExtensionComposer.js.map +1 -0
- package/dist/lexical-proxy/@lexical-react/LexicalExtensionEditorComposer.d.ts +2 -0
- package/dist/lexical-proxy/@lexical-react/LexicalExtensionEditorComposer.d.ts.map +1 -0
- package/dist/lexical-proxy/@lexical-react/LexicalExtensionEditorComposer.js +2 -0
- package/dist/lexical-proxy/@lexical-react/LexicalExtensionEditorComposer.js.map +1 -0
- package/dist/lexical-proxy/@lexical-react/LexicalSelectionAlwaysOnDisplay.d.ts +2 -0
- package/dist/lexical-proxy/@lexical-react/LexicalSelectionAlwaysOnDisplay.d.ts.map +1 -0
- package/dist/lexical-proxy/@lexical-react/LexicalSelectionAlwaysOnDisplay.js +2 -0
- package/dist/lexical-proxy/@lexical-react/LexicalSelectionAlwaysOnDisplay.js.map +1 -0
- package/dist/lexical-proxy/@lexical-react/ReactExtension.d.ts +2 -0
- package/dist/lexical-proxy/@lexical-react/ReactExtension.d.ts.map +1 -0
- package/dist/lexical-proxy/@lexical-react/ReactExtension.js +2 -0
- package/dist/lexical-proxy/@lexical-react/ReactExtension.js.map +1 -0
- package/dist/lexical-proxy/@lexical-react/ReactPluginHostExtension.d.ts +2 -0
- package/dist/lexical-proxy/@lexical-react/ReactPluginHostExtension.d.ts.map +1 -0
- package/dist/lexical-proxy/@lexical-react/ReactPluginHostExtension.js +2 -0
- package/dist/lexical-proxy/@lexical-react/ReactPluginHostExtension.js.map +1 -0
- package/dist/lexical-proxy/@lexical-react/ReactProviderExtension.d.ts +2 -0
- package/dist/lexical-proxy/@lexical-react/ReactProviderExtension.d.ts.map +1 -0
- package/dist/lexical-proxy/@lexical-react/ReactProviderExtension.js +2 -0
- package/dist/lexical-proxy/@lexical-react/ReactProviderExtension.js.map +1 -0
- package/dist/lexical-proxy/@lexical-react/TreeViewExtension.d.ts +2 -0
- package/dist/lexical-proxy/@lexical-react/TreeViewExtension.d.ts.map +1 -0
- package/dist/lexical-proxy/@lexical-react/TreeViewExtension.js +2 -0
- package/dist/lexical-proxy/@lexical-react/TreeViewExtension.js.map +1 -0
- package/dist/lexical-proxy/@lexical-react/useExtensionComponent.d.ts +2 -0
- package/dist/lexical-proxy/@lexical-react/useExtensionComponent.d.ts.map +1 -0
- package/dist/lexical-proxy/@lexical-react/useExtensionComponent.js +2 -0
- package/dist/lexical-proxy/@lexical-react/useExtensionComponent.js.map +1 -0
- package/dist/lexical-proxy/@lexical-react/useExtensionSignalValue.d.ts +2 -0
- package/dist/lexical-proxy/@lexical-react/useExtensionSignalValue.d.ts.map +1 -0
- package/dist/lexical-proxy/@lexical-react/useExtensionSignalValue.js +2 -0
- package/dist/lexical-proxy/@lexical-react/useExtensionSignalValue.js.map +1 -0
- package/dist/lexical-proxy/@lexical-react/useLexicalAriaLiveRegion.d.ts +2 -0
- package/dist/lexical-proxy/@lexical-react/useLexicalAriaLiveRegion.d.ts.map +1 -0
- package/dist/lexical-proxy/@lexical-react/useLexicalAriaLiveRegion.js +2 -0
- package/dist/lexical-proxy/@lexical-react/useLexicalAriaLiveRegion.js.map +1 -0
- package/dist/lexical-proxy/@lexical-react/useLexicalFocusManagerRef.d.ts +2 -0
- package/dist/lexical-proxy/@lexical-react/useLexicalFocusManagerRef.d.ts.map +1 -0
- package/dist/lexical-proxy/@lexical-react/useLexicalFocusManagerRef.js +2 -0
- package/dist/lexical-proxy/@lexical-react/useLexicalFocusManagerRef.js.map +1 -0
- package/dist/lexical-proxy/@lexical-react/useLexicalFocusTrapRef.d.ts +2 -0
- package/dist/lexical-proxy/@lexical-react/useLexicalFocusTrapRef.d.ts.map +1 -0
- package/dist/lexical-proxy/@lexical-react/useLexicalFocusTrapRef.js +2 -0
- package/dist/lexical-proxy/@lexical-react/useLexicalFocusTrapRef.js.map +1 -0
- package/dist/lexical-proxy/@lexical-react/useLexicalRovingTabIndexRef.d.ts +2 -0
- package/dist/lexical-proxy/@lexical-react/useLexicalRovingTabIndexRef.d.ts.map +1 -0
- package/dist/lexical-proxy/@lexical-react/useLexicalRovingTabIndexRef.js +2 -0
- package/dist/lexical-proxy/@lexical-react/useLexicalRovingTabIndexRef.js.map +1 -0
- package/dist/lexical-proxy/@lexical-react/useLexicalSlotRef.d.ts +2 -0
- package/dist/lexical-proxy/@lexical-react/useLexicalSlotRef.d.ts.map +1 -0
- package/dist/lexical-proxy/@lexical-react/useLexicalSlotRef.js +2 -0
- package/dist/lexical-proxy/@lexical-react/useLexicalSlotRef.js.map +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/nodeTypes.d.ts +1 -1
- package/dist/types/nodeTypes.d.ts.map +1 -1
- package/dist/types/nodeTypes.js.map +1 -1
- package/dist/utilities/createServerFeature.d.ts +1 -1
- package/dist/utilities/createServerFeature.d.ts.map +1 -1
- package/dist/utilities/createServerFeature.js +2 -2
- package/dist/utilities/createServerFeature.js.map +1 -1
- package/dist/utilities/editorConfigFactory.d.ts +6 -6
- package/dist/utilities/editorConfigFactory.d.ts.map +1 -1
- package/dist/utilities/editorConfigFactory.js +9 -9
- package/dist/utilities/editorConfigFactory.js.map +1 -1
- package/dist/utilities/getDefaultSanitizedEditorConfig.d.ts +2 -2
- package/dist/utilities/getDefaultSanitizedEditorConfig.d.ts.map +1 -1
- package/dist/utilities/getDefaultSanitizedEditorConfig.js +6 -17
- package/dist/utilities/getDefaultSanitizedEditorConfig.js.map +1 -1
- package/package.json +94 -21
- package/dist/exports/client/chunk-UD4DQ4AK.js +0 -2
- package/dist/exports/client/chunk-UD4DQ4AK.js.map +0 -7
- package/dist/exports/client/chunk-X3D4LZS7.js +0 -2
- package/dist/exports/client/chunk-X3D4LZS7.js.map +0 -7
- package/dist/exports/client/component-PHZQBOJE.js +0 -2
- package/dist/exports/client/component-PHZQBOJE.js.map +0 -7
- package/dist/features/experimental_table/client/index.d.ts.map +0 -1
- package/dist/features/experimental_table/client/index.js.map +0 -1
- package/dist/features/experimental_table/client/plugins/TableActionMenuPlugin/index.d.ts.map +0 -1
- package/dist/features/experimental_table/client/plugins/TableActionMenuPlugin/index.js.map +0 -1
- package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.d.ts.map +0 -1
- package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.js.map +0 -1
- package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.d.ts.map +0 -1
- package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.js.map +0 -1
- package/dist/features/experimental_table/client/plugins/TablePlugin/TableGridPopup/index.d.ts.map +0 -1
- package/dist/features/experimental_table/client/plugins/TablePlugin/TableGridPopup/index.js.map +0 -1
- package/dist/features/experimental_table/client/plugins/TablePlugin/index.d.ts.map +0 -1
- package/dist/features/experimental_table/client/plugins/TablePlugin/index.js.map +0 -1
- package/dist/features/experimental_table/client/utils/debounce.d.ts.map +0 -1
- package/dist/features/experimental_table/client/utils/debounce.js.map +0 -1
- package/dist/features/experimental_table/client/utils/useDebounce.d.ts.map +0 -1
- package/dist/features/experimental_table/client/utils/useDebounce.js.map +0 -1
- package/dist/features/experimental_table/markdownTransformer.d.ts.map +0 -1
- package/dist/features/experimental_table/markdownTransformer.js.map +0 -1
- package/dist/features/experimental_table/server/index.d.ts +0 -3
- package/dist/features/experimental_table/server/index.d.ts.map +0 -1
- package/dist/features/experimental_table/server/index.js.map +0 -1
- package/dist/features/experimental_table/server/schema.d.ts.map +0 -1
- package/dist/features/experimental_table/server/schema.js.map +0 -1
- /package/dist/exports/client/{Field-QGSHF22S.js.map → Field-IZKDIUJY.js.map} +0 -0
- /package/dist/features/{experimental_table → table}/client/index.d.ts +0 -0
- /package/dist/features/{experimental_table → table}/client/index.js +0 -0
- /package/dist/features/{experimental_table → table}/client/plugins/TableActionMenuPlugin/index.css +0 -0
- /package/dist/features/{experimental_table → table}/client/plugins/TableActionMenuPlugin/index.d.ts +0 -0
- /package/dist/features/{experimental_table → table}/client/plugins/TableActionMenuPlugin/index.js +0 -0
- /package/dist/features/{experimental_table → table}/client/plugins/TableCellResizerPlugin/index.css +0 -0
- /package/dist/features/{experimental_table → table}/client/plugins/TableCellResizerPlugin/index.d.ts +0 -0
- /package/dist/features/{experimental_table → table}/client/plugins/TableCellResizerPlugin/index.js +0 -0
- /package/dist/features/{experimental_table → table}/client/plugins/TableHoverActionsPlugin/index.d.ts +0 -0
- /package/dist/features/{experimental_table → table}/client/plugins/TableHoverActionsPlugin/index.js +0 -0
- /package/dist/features/{experimental_table → table}/client/plugins/TablePlugin/TableGridPopup/index.css +0 -0
- /package/dist/features/{experimental_table → table}/client/plugins/TablePlugin/TableGridPopup/index.d.ts +0 -0
- /package/dist/features/{experimental_table → table}/client/plugins/TablePlugin/TableGridPopup/index.js +0 -0
- /package/dist/features/{experimental_table → table}/client/plugins/TablePlugin/index.css +0 -0
- /package/dist/features/{experimental_table → table}/client/plugins/TablePlugin/index.d.ts +0 -0
- /package/dist/features/{experimental_table → table}/client/plugins/TablePlugin/index.js +0 -0
- /package/dist/features/{experimental_table → table}/client/utils/debounce.d.ts +0 -0
- /package/dist/features/{experimental_table → table}/client/utils/debounce.js +0 -0
- /package/dist/features/{experimental_table → table}/client/utils/useDebounce.d.ts +0 -0
- /package/dist/features/{experimental_table → table}/client/utils/useDebounce.js +0 -0
- /package/dist/features/{experimental_table → table}/markdownTransformer.d.ts +0 -0
- /package/dist/features/{experimental_table → table}/markdownTransformer.js +0 -0
- /package/dist/features/{experimental_table → table}/server/schema.d.ts +0 -0
- /package/dist/features/{experimental_table → table}/server/schema.js +0 -0
|
@@ -10,14 +10,14 @@ import { ServerInlineBlockNode } from './nodes/InlineBlocksNode.js';
|
|
|
10
10
|
import { createBlockNodeJSONSchema, createInlineBlockNodeJSONSchema } from './schema.js';
|
|
11
11
|
import { blockValidationHOC } from './validate.js';
|
|
12
12
|
export const BlocksFeature = createServerFeature({
|
|
13
|
-
feature:
|
|
13
|
+
feature: ({
|
|
14
14
|
config: _config,
|
|
15
15
|
isRoot,
|
|
16
16
|
parentIsLocalized,
|
|
17
17
|
props: _props
|
|
18
18
|
}) => {
|
|
19
19
|
const validRelationships = _config.collections.map(c => c.slug) || [];
|
|
20
|
-
const sanitized =
|
|
20
|
+
const sanitized = sanitizeFields({
|
|
21
21
|
config: _config,
|
|
22
22
|
fields: [{
|
|
23
23
|
name: 'lexical_blocks',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["sanitizeFields","applyBaseFilterToFields","createServerFeature","createNode","blockPopulationPromiseHOC","i18n","getBlockMarkdownTransformers","ServerBlockNode","ServerInlineBlockNode","createBlockNodeJSONSchema","createInlineBlockNodeJSONSchema","blockValidationHOC","BlocksFeature","feature","config","_config","isRoot","parentIsLocalized","props","_props","validRelationships","collections","map","c","slug","sanitized","fields","name","type","blocks","inlineBlocks","requireFieldLevelRichTextEditor","blockConfigs","_block","block","find","b","Error","push","inlineBlockConfigs","ClientFeature","generateSchemaMap","schemaMap","Map","length","blockFields","admin","components","unshift","Block","BlockLabel","Label","set","markdownTransformers","nodes","jsonSchema","undefined","getSubFields","node","blockType","getSubFieldsData","graphQLPopulationPromises","validations","sanitizedServerFeatureProps","key"],"sources":["../../../../src/features/blocks/server/index.ts"],"sourcesContent":["import type {\n Block,\n BlocksField,\n BlockSlug,\n Config,\n FieldSchemaMap,\n UIFieldClientProps,\n UIFieldServerProps,\n} from 'payload'\n\nimport { sanitizeFields } from 'payload'\n\nimport { applyBaseFilterToFields } from '../../../utilities/applyBaseFilterToFields.js'\nimport { createServerFeature } from '../../../utilities/createServerFeature.js'\nimport { createNode } from '../../typeUtilities.js'\nimport { blockPopulationPromiseHOC } from './graphQLPopulationPromise.js'\nimport { i18n } from './i18n.js'\nimport { getBlockMarkdownTransformers } from './markdown/markdownTransformer.js'\nimport { ServerBlockNode } from './nodes/BlocksNode.js'\nimport { ServerInlineBlockNode } from './nodes/InlineBlocksNode.js'\nimport { createBlockNodeJSONSchema, createInlineBlockNodeJSONSchema } from './schema.js'\nimport { blockValidationHOC } from './validate.js'\n\nexport type {\n BlockFields,\n BlockFieldsOptionalID,\n InlineBlockFields,\n SerializedBlockNode,\n SerializedInlineBlockNode,\n} from './schema.js'\n\nexport type BlocksFeatureProps = {\n blocks?: (Block | BlockSlug)[] | Block[]\n inlineBlocks?: (Block | BlockSlug)[] | Block[]\n}\n\nexport const BlocksFeature = createServerFeature<BlocksFeatureProps, BlocksFeatureProps>({\n feature: async ({ config: _config, isRoot, parentIsLocalized, props: _props }) => {\n const validRelationships = _config.collections.map((c) => c.slug) || []\n\n const sanitized = await sanitizeFields({\n config: _config as unknown as Config,\n fields: [\n {\n name: 'lexical_blocks',\n type: 'blocks',\n blocks: _props.blocks ?? [],\n },\n {\n name: 'lexical_inline_blocks',\n type: 'blocks',\n blocks: _props.inlineBlocks ?? [],\n },\n ],\n parentIsLocalized,\n requireFieldLevelRichTextEditor: isRoot,\n validRelationships,\n })\n\n const blockConfigs: Block[] = []\n for (const _block of (sanitized[0] as BlocksField).blocks) {\n const block =\n typeof _block === 'string' ? _config?.blocks?.find((b) => b.slug === _block) : _block\n if (!block) {\n throw new Error(\n `Block not found for slug: ${typeof _block === 'string' ? _block : _block?.slug}`,\n )\n }\n // Apply baseFilter to relationship fields in the block\n blockConfigs.push({\n ...block,\n fields: applyBaseFilterToFields(block.fields, _config),\n })\n }\n\n const inlineBlockConfigs: Block[] = []\n for (const _block of (sanitized[1] as BlocksField).blocks) {\n const block =\n typeof _block === 'string' ? _config?.blocks?.find((b) => b.slug === _block) : _block\n if (!block) {\n throw new Error(\n `Block not found for slug: ${typeof _block === 'string' ? _block : _block?.slug}`,\n )\n }\n // Apply baseFilter to relationship fields in the block\n inlineBlockConfigs.push({\n ...block,\n fields: applyBaseFilterToFields(block.fields, _config),\n })\n }\n\n return {\n ClientFeature: '@payloadcms/richtext-lexical/client#BlocksFeatureClient',\n generateSchemaMap: ({ config }) => {\n /**\n * Add sub-fields to the schemaMap. E.g. if you have an array field as part of the block, and it runs addRow, it will request these\n * sub-fields from the component map. Thus, we need to put them in the component map here.\n */\n const schemaMap: FieldSchemaMap = new Map()\n\n if (blockConfigs?.length) {\n for (const block of blockConfigs) {\n const blockFields = [...block.fields]\n\n if (block?.admin?.components) {\n blockFields.unshift({\n name: `_components`,\n type: 'ui',\n admin: {\n components: {\n Block: block.admin?.components?.Block,\n BlockLabel: block.admin?.components?.Label,\n },\n },\n })\n }\n schemaMap.set(`lexical_blocks.${block.slug}.fields`, {\n fields: blockFields,\n })\n schemaMap.set(`lexical_blocks.${block.slug}`, {\n name: `lexical_blocks_${block.slug}`,\n type: 'blocks',\n blocks: [block],\n })\n }\n }\n\n if (inlineBlockConfigs?.length) {\n // To generate block schemaMap which generates things like the componentMap for admin.Label\n for (const block of inlineBlockConfigs) {\n const blockFields = [...block.fields]\n\n if (block?.admin?.components) {\n blockFields.unshift({\n name: `_components`,\n type: 'ui',\n admin: {\n components: {\n Block: block.admin?.components?.Block,\n BlockLabel: block.admin?.components?.Label,\n },\n },\n })\n }\n\n schemaMap.set(`lexical_inline_blocks.${block.slug}.fields`, {\n fields: blockFields,\n })\n\n schemaMap.set(`lexical_inline_blocks.${block.slug}`, {\n name: `lexical_inline_blocks_${block.slug}`,\n type: 'blocks',\n blocks: [block],\n })\n }\n }\n\n return schemaMap\n },\n i18n,\n markdownTransformers: getBlockMarkdownTransformers({\n blocks: blockConfigs,\n inlineBlocks: inlineBlockConfigs,\n }),\n\n nodes: [\n createNode({\n jsonSchema: blockConfigs.length ? createBlockNodeJSONSchema(blockConfigs) : undefined,\n // @ts-expect-error - TODO: fix this\n getSubFields: ({ node }) => {\n if (!node) {\n if (!blockConfigs.length) {\n return []\n }\n return [\n {\n name: 'lexical_blocks',\n type: 'blocks',\n blocks: blockConfigs,\n },\n ]\n }\n\n const blockType = node.fields.blockType\n const block = blockConfigs.find((block) => block.slug === blockType)\n return block?.fields\n },\n getSubFieldsData: ({ node }) => {\n return node?.fields\n },\n graphQLPopulationPromises: [blockPopulationPromiseHOC(blockConfigs)],\n node: ServerBlockNode,\n validations: [blockValidationHOC(blockConfigs)],\n }),\n createNode({\n jsonSchema: inlineBlockConfigs.length\n ? createInlineBlockNodeJSONSchema(inlineBlockConfigs)\n : undefined,\n // @ts-expect-error - TODO: fix this\n getSubFields: ({ node }) => {\n if (!node) {\n if (!inlineBlockConfigs.length) {\n return []\n }\n return [\n {\n name: 'lexical_inline_blocks',\n type: 'blocks',\n blocks: inlineBlockConfigs,\n },\n ]\n }\n\n const blockType = node.fields.blockType\n const block = inlineBlockConfigs.find((block) => block.slug === blockType)\n return block?.fields\n },\n getSubFieldsData: ({ node }) => {\n return node?.fields\n },\n graphQLPopulationPromises: [blockPopulationPromiseHOC(inlineBlockConfigs)],\n node: ServerInlineBlockNode,\n validations: [blockValidationHOC(inlineBlockConfigs)],\n }),\n ],\n sanitizedServerFeatureProps: _props,\n }\n },\n key: 'blocks',\n})\n\n/**\n * Props for the client components provided to `admin.components.Block` of lexical blocks.\n */\nexport type LexicalBlockClientProps = UIFieldClientProps\n/**\n * Props for the server components provided to `admin.components.Block` of lexical blocks.\n */\nexport type LexicalBlockServerProps = UIFieldServerProps\n\n/**\n * Props for the client components provided to `admin.components.Label` of lexical blocks.\n */\nexport type LexicalBlockLabelClientProps = UIFieldClientProps\n/**\n * Props for the server components provided to `admin.components.Label` of lexical blocks.\n */\nexport type LexicalBlockLabelServerProps = UIFieldServerProps\n\n/**\n * Props for the client components provided to `admin.components.Block` of lexical inline blocks.\n */\nexport type LexicalInlineBlockClientProps = UIFieldClientProps\n/**\n * Props for the server components provided to `admin.components.Block` of lexical inline blocks.\n */\nexport type LexicalInlineBlockServerProps = UIFieldServerProps\n\n/**\n * Props for the client components provided to `admin.components.Label` of lexical inline blocks.\n */\nexport type LexicalInlineBlockLabelClientProps = UIFieldClientProps\n/**\n * Props for the server components provided to `admin.components.Label` of lexical inline blocks.\n */\nexport type LexicalInlineBlockLabelServerProps = UIFieldServerProps\n"],"mappings":"AAUA,SAASA,cAAc,QAAQ;AAE/B,SAASC,uBAAuB,QAAQ;AACxC,SAASC,mBAAmB,QAAQ;AACpC,SAASC,UAAU,QAAQ;AAC3B,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,IAAI,QAAQ;AACrB,SAASC,4BAA4B,QAAQ;AAC7C,SAASC,eAAe,QAAQ;AAChC,SAASC,qBAAqB,QAAQ;AACtC,SAASC,yBAAyB,EAAEC,+BAA+B,QAAQ;AAC3E,SAASC,kBAAkB,QAAQ;AAenC,OAAO,MAAMC,aAAA,GAAgBV,mBAAA,CAA4D;EACvFW,OAAA,EAAS,MAAAA,CAAO;IAAEC,MAAA,EAAQC,OAAO;IAAEC,MAAM;IAAEC,iBAAiB;IAAEC,KAAA,EAAOC;EAAM,CAAE;IAC3E,MAAMC,kBAAA,GAAqBL,OAAA,CAAQM,WAAW,CAACC,GAAG,CAAEC,CAAA,IAAMA,CAAA,CAAEC,IAAI,KAAK,EAAE;IAEvE,MAAMC,SAAA,GAAY,MAAMzB,cAAA,CAAe;MACrCc,MAAA,EAAQC,OAAA;MACRW,MAAA,EAAQ,CACN;QACEC,IAAA,EAAM;QACNC,IAAA,EAAM;QACNC,MAAA,EAAQV,MAAA,CAAOU,MAAM,IAAI;MAC3B,GACA;QACEF,IAAA,EAAM;QACNC,IAAA,EAAM;QACNC,MAAA,EAAQV,MAAA,CAAOW,YAAY,IAAI;MACjC,EACD;MACDb,iBAAA;MACAc,+BAAA,EAAiCf,MAAA;MACjCI;IACF;IAEA,MAAMY,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AmBK,MAAM,GACjClC,+BAAA,CAAgC6B,kBAAA,IAChCiB,SAAA;QACJ;QACAC,YAAA,EAAcA,CAAC;UAAEC;QAAI,CAAE;UACrB,IAAI,CAACA,IAAA,EAAM;YACT,IAAI,CAACnB,kBAAA,CAAmBK,MAAM,EAAE;cAC9B,OAAO,EAAE;YACX;YACA,OAAO,CACL;cACEjB,IAAA,EAAM;cACNC,IAAA,EAAM;cACNC,MAAA,EAAQU;YACV,EACD;UACH;UAEA,MAAMoB,SAAA,GAAYD,IAAA,CAAKhC,MAAM,CAACiC,SAAS;UACvC,MAAMzB,KAAA,GAAQK,kBAAA,CAAmBJ,IAAI,CAAED,KAAA,IAAUA,KAAA,CAAMV,IAAI,KAAKmC,SAAA;UAChE,OAAOzB,KAAA,EAAOR,MAAA;QAChB;QACAkC,gBAAA,EAAkBA,CAAC;UAAEF;QAAI,CAAE;UACzB,OAAOA,IAAA,EAAMhC,MAAA;QACf;QACAmC,yBAAA,EAA2B,CAACzD,yBAAA,CAA0BmC,kBAAA,EAAoB;QAC1EmB,IAAA,EAAMlD,qBAAA;QACNsD,WAAA,EAAa,CAACnD,kBAAA,CAAmB4B,kBAAA;MACnC,GACD;MACDwB,2BAAA,EAA6B5C;IAC/B;EACF;EACA6C,GAAA,EAAK;AACP","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["sanitizeFields","applyBaseFilterToFields","createServerFeature","createNode","blockPopulationPromiseHOC","i18n","getBlockMarkdownTransformers","ServerBlockNode","ServerInlineBlockNode","createBlockNodeJSONSchema","createInlineBlockNodeJSONSchema","blockValidationHOC","BlocksFeature","feature","config","_config","isRoot","parentIsLocalized","props","_props","validRelationships","collections","map","c","slug","sanitized","fields","name","type","blocks","inlineBlocks","requireFieldLevelRichTextEditor","blockConfigs","_block","block","find","b","Error","push","inlineBlockConfigs","ClientFeature","generateSchemaMap","schemaMap","Map","length","blockFields","admin","components","unshift","Block","BlockLabel","Label","set","markdownTransformers","nodes","jsonSchema","undefined","getSubFields","node","blockType","getSubFieldsData","graphQLPopulationPromises","validations","sanitizedServerFeatureProps","key"],"sources":["../../../../src/features/blocks/server/index.ts"],"sourcesContent":["import type {\n Block,\n BlocksField,\n BlockSlug,\n Config,\n FieldSchemaMap,\n UIFieldClientProps,\n UIFieldServerProps,\n} from 'payload'\n\nimport { sanitizeFields } from 'payload'\n\nimport { applyBaseFilterToFields } from '../../../utilities/applyBaseFilterToFields.js'\nimport { createServerFeature } from '../../../utilities/createServerFeature.js'\nimport { createNode } from '../../typeUtilities.js'\nimport { blockPopulationPromiseHOC } from './graphQLPopulationPromise.js'\nimport { i18n } from './i18n.js'\nimport { getBlockMarkdownTransformers } from './markdown/markdownTransformer.js'\nimport { ServerBlockNode } from './nodes/BlocksNode.js'\nimport { ServerInlineBlockNode } from './nodes/InlineBlocksNode.js'\nimport { createBlockNodeJSONSchema, createInlineBlockNodeJSONSchema } from './schema.js'\nimport { blockValidationHOC } from './validate.js'\n\nexport type {\n BlockFields,\n BlockFieldsOptionalID,\n InlineBlockFields,\n SerializedBlockNode,\n SerializedInlineBlockNode,\n} from './schema.js'\n\nexport type BlocksFeatureProps = {\n blocks?: (Block | BlockSlug)[] | Block[]\n inlineBlocks?: (Block | BlockSlug)[] | Block[]\n}\n\nexport const BlocksFeature = createServerFeature<BlocksFeatureProps, BlocksFeatureProps>({\n feature: ({ config: _config, isRoot, parentIsLocalized, props: _props }) => {\n const validRelationships = _config.collections.map((c) => c.slug) || []\n\n const sanitized = sanitizeFields({\n config: _config as unknown as Config,\n fields: [\n {\n name: 'lexical_blocks',\n type: 'blocks',\n blocks: _props.blocks ?? [],\n },\n {\n name: 'lexical_inline_blocks',\n type: 'blocks',\n blocks: _props.inlineBlocks ?? [],\n },\n ],\n parentIsLocalized,\n requireFieldLevelRichTextEditor: isRoot,\n validRelationships,\n })\n\n const blockConfigs: Block[] = []\n for (const _block of (sanitized[0] as BlocksField).blocks) {\n const block =\n typeof _block === 'string' ? _config?.blocks?.find((b) => b.slug === _block) : _block\n if (!block) {\n throw new Error(\n `Block not found for slug: ${typeof _block === 'string' ? _block : _block?.slug}`,\n )\n }\n // Apply baseFilter to relationship fields in the block\n blockConfigs.push({\n ...block,\n fields: applyBaseFilterToFields(block.fields, _config),\n })\n }\n\n const inlineBlockConfigs: Block[] = []\n for (const _block of (sanitized[1] as BlocksField).blocks) {\n const block =\n typeof _block === 'string' ? _config?.blocks?.find((b) => b.slug === _block) : _block\n if (!block) {\n throw new Error(\n `Block not found for slug: ${typeof _block === 'string' ? _block : _block?.slug}`,\n )\n }\n // Apply baseFilter to relationship fields in the block\n inlineBlockConfigs.push({\n ...block,\n fields: applyBaseFilterToFields(block.fields, _config),\n })\n }\n\n return {\n ClientFeature: '@payloadcms/richtext-lexical/client#BlocksFeatureClient',\n generateSchemaMap: ({ config }) => {\n /**\n * Add sub-fields to the schemaMap. E.g. if you have an array field as part of the block, and it runs addRow, it will request these\n * sub-fields from the component map. Thus, we need to put them in the component map here.\n */\n const schemaMap: FieldSchemaMap = new Map()\n\n if (blockConfigs?.length) {\n for (const block of blockConfigs) {\n const blockFields = [...block.fields]\n\n if (block?.admin?.components) {\n blockFields.unshift({\n name: `_components`,\n type: 'ui',\n admin: {\n components: {\n Block: block.admin?.components?.Block,\n BlockLabel: block.admin?.components?.Label,\n },\n },\n })\n }\n schemaMap.set(`lexical_blocks.${block.slug}.fields`, {\n fields: blockFields,\n })\n schemaMap.set(`lexical_blocks.${block.slug}`, {\n name: `lexical_blocks_${block.slug}`,\n type: 'blocks',\n blocks: [block],\n })\n }\n }\n\n if (inlineBlockConfigs?.length) {\n // To generate block schemaMap which generates things like the componentMap for admin.Label\n for (const block of inlineBlockConfigs) {\n const blockFields = [...block.fields]\n\n if (block?.admin?.components) {\n blockFields.unshift({\n name: `_components`,\n type: 'ui',\n admin: {\n components: {\n Block: block.admin?.components?.Block,\n BlockLabel: block.admin?.components?.Label,\n },\n },\n })\n }\n\n schemaMap.set(`lexical_inline_blocks.${block.slug}.fields`, {\n fields: blockFields,\n })\n\n schemaMap.set(`lexical_inline_blocks.${block.slug}`, {\n name: `lexical_inline_blocks_${block.slug}`,\n type: 'blocks',\n blocks: [block],\n })\n }\n }\n\n return schemaMap\n },\n i18n,\n markdownTransformers: getBlockMarkdownTransformers({\n blocks: blockConfigs,\n inlineBlocks: inlineBlockConfigs,\n }),\n\n nodes: [\n createNode({\n jsonSchema: blockConfigs.length ? createBlockNodeJSONSchema(blockConfigs) : undefined,\n // @ts-expect-error - TODO: fix this\n getSubFields: ({ node }) => {\n if (!node) {\n if (!blockConfigs.length) {\n return []\n }\n return [\n {\n name: 'lexical_blocks',\n type: 'blocks',\n blocks: blockConfigs,\n },\n ]\n }\n\n const blockType = node.fields.blockType\n const block = blockConfigs.find((block) => block.slug === blockType)\n return block?.fields\n },\n getSubFieldsData: ({ node }) => {\n return node?.fields\n },\n graphQLPopulationPromises: [blockPopulationPromiseHOC(blockConfigs)],\n node: ServerBlockNode,\n validations: [blockValidationHOC(blockConfigs)],\n }),\n createNode({\n jsonSchema: inlineBlockConfigs.length\n ? createInlineBlockNodeJSONSchema(inlineBlockConfigs)\n : undefined,\n // @ts-expect-error - TODO: fix this\n getSubFields: ({ node }) => {\n if (!node) {\n if (!inlineBlockConfigs.length) {\n return []\n }\n return [\n {\n name: 'lexical_inline_blocks',\n type: 'blocks',\n blocks: inlineBlockConfigs,\n },\n ]\n }\n\n const blockType = node.fields.blockType\n const block = inlineBlockConfigs.find((block) => block.slug === blockType)\n return block?.fields\n },\n getSubFieldsData: ({ node }) => {\n return node?.fields\n },\n graphQLPopulationPromises: [blockPopulationPromiseHOC(inlineBlockConfigs)],\n node: ServerInlineBlockNode,\n validations: [blockValidationHOC(inlineBlockConfigs)],\n }),\n ],\n sanitizedServerFeatureProps: _props,\n }\n },\n key: 'blocks',\n})\n\n/**\n * Props for the client components provided to `admin.components.Block` of lexical blocks.\n */\nexport type LexicalBlockClientProps = UIFieldClientProps\n/**\n * Props for the server components provided to `admin.components.Block` of lexical blocks.\n */\nexport type LexicalBlockServerProps = UIFieldServerProps\n\n/**\n * Props for the client components provided to `admin.components.Label` of lexical blocks.\n */\nexport type LexicalBlockLabelClientProps = UIFieldClientProps\n/**\n * Props for the server components provided to `admin.components.Label` of lexical blocks.\n */\nexport type LexicalBlockLabelServerProps = UIFieldServerProps\n\n/**\n * Props for the client components provided to `admin.components.Block` of lexical inline blocks.\n */\nexport type LexicalInlineBlockClientProps = UIFieldClientProps\n/**\n * Props for the server components provided to `admin.components.Block` of lexical inline blocks.\n */\nexport type LexicalInlineBlockServerProps = UIFieldServerProps\n\n/**\n * Props for the client components provided to `admin.components.Label` of lexical inline blocks.\n */\nexport type LexicalInlineBlockLabelClientProps = UIFieldClientProps\n/**\n * Props for the server components provided to `admin.components.Label` of lexical inline blocks.\n */\nexport type LexicalInlineBlockLabelServerProps = UIFieldServerProps\n"],"mappings":"AAUA,SAASA,cAAc,QAAQ;AAE/B,SAASC,uBAAuB,QAAQ;AACxC,SAASC,mBAAmB,QAAQ;AACpC,SAASC,UAAU,QAAQ;AAC3B,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,IAAI,QAAQ;AACrB,SAASC,4BAA4B,QAAQ;AAC7C,SAASC,eAAe,QAAQ;AAChC,SAASC,qBAAqB,QAAQ;AACtC,SAASC,yBAAyB,EAAEC,+BAA+B,QAAQ;AAC3E,SAASC,kBAAkB,QAAQ;AAenC,OAAO,MAAMC,aAAA,GAAgBV,mBAAA,CAA4D;EACvFW,OAAA,EAASA,CAAC;IAAEC,MAAA,EAAQC,OAAO;IAAEC,MAAM;IAAEC,iBAAiB;IAAEC,KAAA,EAAOC;EAAM,CAAE;IACrE,MAAMC,kBAAA,GAAqBL,OAAA,CAAQM,WAAW,CAACC,GAAG,CAAEC,CAAA,IAAMA,CAAA,CAAEC,IAAI,KAAK,EAAE;IAEvE,MAAMC,SAAA,GAAYzB,cAAA,CAAe;MAC/Bc,MAAA,EAAQC,OAAA;MACRW,MAAA,EAAQ,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CAAC;UAAEF;QAAI,CAAE;UACzB,OAAOA,IAAA,EAAMhC,MAAA;QACf;QACAmC,yBAAA,EAA2B,CAACzD,yBAAA,CAA0B4B,YAAA,EAAc;QACpE0B,IAAA,EAAMnD,eAAA;QACNuD,WAAA,EAAa,CAACnD,kBAAA,CAAmBqB,YAAA;MACnC,IACA7B,UAAA,CAAW;QACToD,UAAA,EAAYhB,kBAAA,CAAmBK,MAAM,GACjClC,+BAAA,CAAgC6B,kBAAA,IAChCiB,SAAA;QACJ;QACAC,YAAA,EAAcA,CAAC;UAAEC;QAAI,CAAE;UACrB,IAAI,CAACA,IAAA,EAAM;YACT,IAAI,CAACnB,kBAAA,CAAmBK,MAAM,EAAE;cAC9B,OAAO,EAAE;YACX;YACA,OAAO,CACL;cACEjB,IAAA,EAAM;cACNC,IAAA,EAAM;cACNC,MAAA,EAAQU;YACV,EACD;UACH;UAEA,MAAMoB,SAAA,GAAYD,IAAA,CAAKhC,MAAM,CAACiC,SAAS;UACvC,MAAMzB,KAAA,GAAQK,kBAAA,CAAmBJ,IAAI,CAAED,KAAA,IAAUA,KAAA,CAAMV,IAAI,KAAKmC,SAAA;UAChE,OAAOzB,KAAA,EAAOR,MAAA;QAChB;QACAkC,gBAAA,EAAkBA,CAAC;UAAEF;QAAI,CAAE;UACzB,OAAOA,IAAA,EAAMhC,MAAA;QACf;QACAmC,yBAAA,EAA2B,CAACzD,yBAAA,CAA0BmC,kBAAA,EAAoB;QAC1EmB,IAAA,EAAMlD,qBAAA;QACNsD,WAAA,EAAa,CAACnD,kBAAA,CAAmB4B,kBAAA;MACnC,GACD;MACDwB,2BAAA,EAA6B5C;IAC/B;EACF;EACA6C,GAAA,EAAK;AACP","ignoreList":[]}
|
|
@@ -7,7 +7,7 @@ export declare class HorizontalRuleNode extends HorizontalRuleServerNode {
|
|
|
7
7
|
/**
|
|
8
8
|
* The data for this node is stored serialized as JSON. This is the "load function" of that node: it takes the saved data and converts it into a node.
|
|
9
9
|
*/
|
|
10
|
-
static importJSON(
|
|
10
|
+
static importJSON(_serializedNode: Record<string, unknown> & SerializedHorizontalRuleNode): HorizontalRuleNode;
|
|
11
11
|
/**
|
|
12
12
|
* Allows you to render a React component within whatever createDOM returns.
|
|
13
13
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HorizontalRuleNode.d.ts","sourceRoot":"","sources":["../../../../../src/features/horizontalRule/client/nodes/HorizontalRuleNode.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAuB,WAAW,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAKtF,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAA;AAE1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAA;AAEnF,qBAAa,kBAAmB,SAAQ,wBAAwB;IAC9D,OAAgB,KAAK,CAAC,IAAI,EAAE,wBAAwB,GAAG,wBAAwB,CAE9E;IAED,OAAgB,OAAO,IAAI,MAAM,CAEhC;IAED;;OAEG;IACH,OAAgB,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"HorizontalRuleNode.d.ts","sourceRoot":"","sources":["../../../../../src/features/horizontalRule/client/nodes/HorizontalRuleNode.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAuB,WAAW,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAKtF,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAA;AAE1E,OAAO,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAA;AAEnF,qBAAa,kBAAmB,SAAQ,wBAAwB;IAC9D,OAAgB,KAAK,CAAC,IAAI,EAAE,wBAAwB,GAAG,wBAAwB,CAE9E;IAED,OAAgB,OAAO,IAAI,MAAM,CAEhC;IAED;;OAEG;IACH,OAAgB,UAAU,CACxB,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,4BAA4B,GACtE,kBAAkB,CAEpB;IAED;;OAEG;IACM,QAAQ,SAEhB;IAEQ,UAAU,IAAI,qBAAqB,CAE3C;CACF;AAMD,wBAAgB,yBAAyB,IAAI,kBAAkB,CAE9D;AAED,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,GACnC,IAAI,IAAI,kBAAkB,CAE5B"}
|
|
@@ -13,7 +13,7 @@ export class HorizontalRuleNode extends HorizontalRuleServerNode {
|
|
|
13
13
|
/**
|
|
14
14
|
* The data for this node is stored serialized as JSON. This is the "load function" of that node: it takes the saved data and converts it into a node.
|
|
15
15
|
*/
|
|
16
|
-
static importJSON(
|
|
16
|
+
static importJSON(_serializedNode) {
|
|
17
17
|
return $createHorizontalRuleNode();
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HorizontalRuleNode.js","names":["$applyNodeReplacement","React","HorizontalRuleServerNode","HorizontalRuleNode","clone","node","getType","importJSON","
|
|
1
|
+
{"version":3,"file":"HorizontalRuleNode.js","names":["$applyNodeReplacement","React","HorizontalRuleServerNode","HorizontalRuleNode","clone","node","getType","importJSON","_serializedNode","$createHorizontalRuleNode","decorate","exportJSON","$convertHorizontalRuleElement","$isHorizontalRuleNode"],"sources":["../../../../../src/features/horizontalRule/client/nodes/HorizontalRuleNode.tsx"],"sourcesContent":["'use client'\nimport type { DOMConversionOutput, LexicalNode, SerializedLexicalNode } from 'lexical'\n\nimport { $applyNodeReplacement } from 'lexical'\nimport * as React from 'react'\n\nimport type { SerializedHorizontalRuleNode } from '../../server/schema.js'\n\nimport { HorizontalRuleServerNode } from '../../server/nodes/HorizontalRuleNode.js'\n\nexport class HorizontalRuleNode extends HorizontalRuleServerNode {\n static override clone(node: HorizontalRuleServerNode): HorizontalRuleServerNode {\n return super.clone(node)\n }\n\n static override getType(): string {\n return super.getType()\n }\n\n /**\n * The data for this node is stored serialized as JSON. This is the \"load function\" of that node: it takes the saved data and converts it into a node.\n */\n static override importJSON(\n _serializedNode: Record<string, unknown> & SerializedHorizontalRuleNode,\n ): HorizontalRuleNode {\n return $createHorizontalRuleNode()\n }\n\n /**\n * Allows you to render a React component within whatever createDOM returns.\n */\n override decorate() {\n return null\n }\n\n override exportJSON(): SerializedLexicalNode {\n return super.exportJSON()\n }\n}\n\nfunction $convertHorizontalRuleElement(): DOMConversionOutput {\n return { node: $createHorizontalRuleNode() }\n}\n\nexport function $createHorizontalRuleNode(): HorizontalRuleNode {\n return $applyNodeReplacement(new HorizontalRuleNode())\n}\n\nexport function $isHorizontalRuleNode(\n node: LexicalNode | null | undefined,\n): node is HorizontalRuleNode {\n return node instanceof HorizontalRuleNode\n}\n"],"mappings":"AAAA;;AAGA,SAASA,qBAAqB,QAAQ;AACtC,YAAYC,KAAA,MAAW;AAIvB,SAASC,wBAAwB,QAAQ;AAEzC,OAAO,MAAMC,kBAAA,SAA2BD,wBAAA;EACtC,OAAgBE,MAAMC,IAA8B,EAA4B;IAC9E,OAAO,KAAK,CAACD,KAAA,CAAMC,IAAA;EACrB;EAEA,OAAgBC,QAAA,EAAkB;IAChC,OAAO,KAAK,CAACA,OAAA;EACf;EAEA;;;EAGA,OAAgBC,WACdC,eAAuE,EACnD;IACpB,OAAOC,yBAAA;EACT;EAEA;;;EAGAC,QAASA,CAAA,EAAW;IAClB,OAAO;EACT;EAESC,WAAA,EAAoC;IAC3C,OAAO,KAAK,CAACA,UAAA;EACf;AACF;AAEA,SAASC,8BAAA;EACP,OAAO;IAAEP,IAAA,EAAMI,yBAAA;EAA4B;AAC7C;AAEA,OAAO,SAASA,0BAAA;EACd,OAAOT,qBAAA,CAAsB,IAAIG,kBAAA;AACnC;AAEA,OAAO,SAASU,sBACdR,IAAoC;EAEpC,OAAOA,IAAA,YAAgBF,kBAAA;AACzB","ignoreList":[]}
|
|
@@ -22,7 +22,7 @@ export declare class HorizontalRuleServerNode extends DecoratorNode<null | React
|
|
|
22
22
|
/**
|
|
23
23
|
* The data for this node is stored serialized as JSON. This is the "load function" of that node: it takes the saved data and converts it into a node.
|
|
24
24
|
*/
|
|
25
|
-
static importJSON(
|
|
25
|
+
static importJSON(_serializedNode: Record<string, unknown> & SerializedHorizontalRuleNode): HorizontalRuleServerNode;
|
|
26
26
|
/**
|
|
27
27
|
* Determines how the hr element is rendered in the lexical editor. This is only the "initial" / "outer" HTML element.
|
|
28
28
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HorizontalRuleNode.d.ts","sourceRoot":"","sources":["../../../../../src/features/horizontalRule/server/nodes/HorizontalRuleNode.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAEhB,eAAe,EACf,YAAY,EACZ,cAAc,EACd,WAAW,EACX,qBAAqB,EACtB,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAA;AAGnC,OAAO,EAAwC,aAAa,EAAE,MAAM,SAAS,CAAA;AAE7E,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAEhE,eAAO,MAAM,8BAA8B,EAAE,cAAc,CAAC,IAAI,CAE/D,CAAA;AAED;;;;;;GAMG;AACH,qBAAa,wBAAyB,SAAQ,aAAa,CAAC,IAAI,GAAG,KAAK,CAAC,YAAY,CAAC;IACpF,OAAgB,KAAK,CAAC,IAAI,EAAE,wBAAwB,GAAG,wBAAwB,CAE9E;IAED,OAAgB,OAAO,IAAI,MAAM,CAEhC;IAED;;;;OAIG;IACH,OAAgB,SAAS,IAAI,gBAAgB,GAAG,IAAI,CAOnD;IAED;;OAEG;IACH,OAAgB,UAAU,CACxB,
|
|
1
|
+
{"version":3,"file":"HorizontalRuleNode.d.ts","sourceRoot":"","sources":["../../../../../src/features/horizontalRule/server/nodes/HorizontalRuleNode.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAEhB,eAAe,EACf,YAAY,EACZ,cAAc,EACd,WAAW,EACX,qBAAqB,EACtB,MAAM,SAAS,CAAA;AAChB,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAA;AAGnC,OAAO,EAAwC,aAAa,EAAE,MAAM,SAAS,CAAA;AAE7E,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,cAAc,CAAA;AAEhE,eAAO,MAAM,8BAA8B,EAAE,cAAc,CAAC,IAAI,CAE/D,CAAA;AAED;;;;;;GAMG;AACH,qBAAa,wBAAyB,SAAQ,aAAa,CAAC,IAAI,GAAG,KAAK,CAAC,YAAY,CAAC;IACpF,OAAgB,KAAK,CAAC,IAAI,EAAE,wBAAwB,GAAG,wBAAwB,CAE9E;IAED,OAAgB,OAAO,IAAI,MAAM,CAEhC;IAED;;;;OAIG;IACH,OAAgB,SAAS,IAAI,gBAAgB,GAAG,IAAI,CAOnD;IAED;;OAEG;IACH,OAAgB,UAAU,CACxB,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,4BAA4B,GACtE,wBAAwB,CAE1B;IAED;;OAEG;IACM,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,WAAW,CAIpD;IAEQ,QAAQ,IAAI,IAAI,GAAG,KAAK,CAAC,YAAY,CAE7C;IAED;;;;OAIG;IACM,SAAS,IAAI,eAAe,CAEpC;IACD;;OAEG;IACM,UAAU,IAAI,qBAAqB,CAK3C;IAEQ,cAAc,IAAI,MAAM,CAEhC;IAEQ,QAAQ,IAAI,KAAK,CAEzB;IAEQ,SAAS,IAAI,OAAO,CAE5B;CACF;AAMD,wBAAgB,+BAA+B,IAAI,wBAAwB,CAE1E;AAED,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,GACnC,IAAI,IAAI,wBAAwB,CAElC"}
|
|
@@ -31,7 +31,7 @@ export class HorizontalRuleServerNode extends DecoratorNode {
|
|
|
31
31
|
/**
|
|
32
32
|
* The data for this node is stored serialized as JSON. This is the "load function" of that node: it takes the saved data and converts it into a node.
|
|
33
33
|
*/
|
|
34
|
-
static importJSON(
|
|
34
|
+
static importJSON(_serializedNode) {
|
|
35
35
|
return $createHorizontalRuleServerNode();
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HorizontalRuleNode.js","names":["addClassNamesToElement","$applyNodeReplacement","createCommand","DecoratorNode","INSERT_HORIZONTAL_RULE_COMMAND","HorizontalRuleServerNode","clone","node","__key","getType","importDOM","hr","conversion","$convertHorizontalRuleElement","priority","importJSON","
|
|
1
|
+
{"version":3,"file":"HorizontalRuleNode.js","names":["addClassNamesToElement","$applyNodeReplacement","createCommand","DecoratorNode","INSERT_HORIZONTAL_RULE_COMMAND","HorizontalRuleServerNode","clone","node","__key","getType","importDOM","hr","conversion","$convertHorizontalRuleElement","priority","importJSON","_serializedNode","$createHorizontalRuleServerNode","createDOM","config","element","document","createElement","theme","decorate","exportDOM","exportJSON","type","version","getTextContent","isInline","updateDOM","$isHorizontalRuleServerNode"],"sources":["../../../../../src/features/horizontalRule/server/nodes/HorizontalRuleNode.tsx"],"sourcesContent":["import type {\n DOMConversionMap,\n DOMConversionOutput,\n DOMExportOutput,\n EditorConfig,\n LexicalCommand,\n LexicalNode,\n SerializedLexicalNode,\n} from 'lexical'\nimport type * as React from 'react'\n\nimport { addClassNamesToElement } from '@lexical/utils'\nimport { $applyNodeReplacement, createCommand, DecoratorNode } from 'lexical'\n\nimport type { SerializedHorizontalRuleNode } from '../schema.js'\n\nexport const INSERT_HORIZONTAL_RULE_COMMAND: LexicalCommand<void> = createCommand(\n 'INSERT_HORIZONTAL_RULE_COMMAND',\n)\n\n/**\n * This node is a DecoratorNode. DecoratorNodes allow you to render React components in the editor.\n *\n * They need both createDom and decorate functions. createDom => outside of the html. decorate => React Component inside of the html.\n *\n * If we used DecoratorBlockNode instead, we would only need a decorate method\n */\nexport class HorizontalRuleServerNode extends DecoratorNode<null | React.ReactElement> {\n static override clone(node: HorizontalRuleServerNode): HorizontalRuleServerNode {\n return new this(node.__key)\n }\n\n static override getType(): string {\n return 'horizontalrule'\n }\n\n /**\n * Defines what happens if you copy an hr element from another page and paste it into the lexical editor\n *\n * This also determines the behavior of lexical's internal HTML -> Lexical converter\n */\n static override importDOM(): DOMConversionMap | null {\n return {\n hr: () => ({\n conversion: $convertHorizontalRuleElement,\n priority: 0,\n }),\n }\n }\n\n /**\n * The data for this node is stored serialized as JSON. This is the \"load function\" of that node: it takes the saved data and converts it into a node.\n */\n static override importJSON(\n _serializedNode: Record<string, unknown> & SerializedHorizontalRuleNode,\n ): HorizontalRuleServerNode {\n return $createHorizontalRuleServerNode()\n }\n\n /**\n * Determines how the hr element is rendered in the lexical editor. This is only the \"initial\" / \"outer\" HTML element.\n */\n override createDOM(config: EditorConfig): HTMLElement {\n const element = document.createElement('hr')\n addClassNamesToElement(element, config.theme.hr)\n return element\n }\n\n override decorate(): null | React.ReactElement {\n return null\n }\n\n /**\n * Opposite of importDOM, this function defines what happens when you copy an hr element from the lexical editor and paste it into another page.\n *\n * This also determines the behavior of lexical's internal Lexical -> HTML converter\n */\n override exportDOM(): DOMExportOutput {\n return { element: document.createElement('hr') }\n }\n /**\n * Opposite of importJSON. This determines what data is saved in the database / in the lexical editor state.\n */\n override exportJSON(): SerializedLexicalNode {\n return {\n type: 'horizontalrule',\n version: 1,\n }\n }\n\n override getTextContent(): string {\n return '\\n'\n }\n\n override isInline(): false {\n return false\n }\n\n override updateDOM(): boolean {\n return false\n }\n}\n\nfunction $convertHorizontalRuleElement(): DOMConversionOutput {\n return { node: $createHorizontalRuleServerNode() }\n}\n\nexport function $createHorizontalRuleServerNode(): HorizontalRuleServerNode {\n return $applyNodeReplacement(new HorizontalRuleServerNode())\n}\n\nexport function $isHorizontalRuleServerNode(\n node: LexicalNode | null | undefined,\n): node is HorizontalRuleServerNode {\n return node instanceof HorizontalRuleServerNode\n}\n"],"mappings":"AAWA,SAASA,sBAAsB,QAAQ;AACvC,SAASC,qBAAqB,EAAEC,aAAa,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","ignoreList":[]}
|
|
@@ -5,7 +5,7 @@ export declare class AutoLinkNode extends LinkNode {
|
|
|
5
5
|
static clone(node: AutoLinkNode): AutoLinkNode;
|
|
6
6
|
static getType(): string;
|
|
7
7
|
static importDOM(): null;
|
|
8
|
-
static importJSON(serializedNode: SerializedAutoLinkNode): AutoLinkNode;
|
|
8
|
+
static importJSON(serializedNode: Record<string, unknown> & SerializedAutoLinkNode): AutoLinkNode;
|
|
9
9
|
exportJSON(): SerializedAutoLinkNode;
|
|
10
10
|
insertNewAfter(selection: RangeSelection, restoreSelection?: boolean): ElementNode | null;
|
|
11
11
|
updateFromJSON(_serializedNode: LexicalUpdateJSON<SerializedElementNode>): this;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoLinkNode.d.ts","sourceRoot":"","sources":["../../../../src/features/link/nodes/AutoLinkNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACtB,MAAM,SAAS,CAAA;AAIhB,OAAO,KAAK,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAE7E,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAKxC,qBAAa,YAAa,SAAQ,QAAQ;IACxC,OAAgB,KAAK,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,CAEtD;IAED,OAAgB,OAAO,IAAI,MAAM,CAEhC;IAED,OAAgB,SAAS,IAAI,IAAI,CAGhC;IAED,OAAgB,UAAU,
|
|
1
|
+
{"version":3,"file":"AutoLinkNode.d.ts","sourceRoot":"","sources":["../../../../src/features/link/nodes/AutoLinkNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACtB,MAAM,SAAS,CAAA;AAIhB,OAAO,KAAK,EAAE,UAAU,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAE7E,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAKxC,qBAAa,YAAa,SAAQ,QAAQ;IACxC,OAAgB,KAAK,CAAC,IAAI,EAAE,YAAY,GAAG,YAAY,CAEtD;IAED,OAAgB,OAAO,IAAI,MAAM,CAEhC;IAED,OAAgB,SAAS,IAAI,IAAI,CAGhC;IAED,OAAgB,UAAU,CACxB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,sBAAsB,GAC/D,YAAY,CAgBd;IAGD,UAAU,IAAI,sBAAsB,CAWnC;IAEQ,cAAc,CAAC,SAAS,EAAE,cAAc,EAAE,gBAAgB,UAAO,GAAG,WAAW,GAAG,IAAI,CAQ9F;IAEQ,cAAc,CAAC,eAAe,EAAE,iBAAiB,CAAC,qBAAqB,CAAC,GAAG,IAAI,CAGvF;CACF;AAED,wBAAgB,mBAAmB,CAAC,EAAE,MAAM,EAAE,EAAE;IAAE,MAAM,CAAC,EAAE,UAAU,CAAA;CAAE,GAAG,YAAY,CAErF;AACD,wBAAgB,eAAe,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,IAAI,YAAY,CAE1F"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AutoLinkNode.js","names":["$applyNodeReplacement","$isElementNode","LinkNode","AutoLinkNode","clone","node","id","fields","__fields","key","__key","getType","importDOM","importJSON","serializedNode","$createAutoLinkNode","updateFromJSON","version","doc","value","exportJSON","serialized","type","children","direction","format","indent","insertNewAfter","selection","restoreSelection","element","getParentOrThrow","linkNode","append","_serializedNode","setFields","$isAutoLinkNode"],"sources":["../../../../src/features/link/nodes/AutoLinkNode.ts"],"sourcesContent":["import type {\n ElementNode,\n LexicalNode,\n LexicalUpdateJSON,\n RangeSelection,\n SerializedElementNode,\n} from 'lexical'\n\nimport { $applyNodeReplacement, $isElementNode } from 'lexical'\n\nimport type { LinkFields, SerializedAutoLinkNode } from '../server/schema.js'\n\nimport { LinkNode } from './LinkNode.js'\n\n// Custom node type to override `canInsertTextAfter` that will\n// allow typing within the link\n\nexport class AutoLinkNode extends LinkNode {\n static override clone(node: AutoLinkNode): AutoLinkNode {\n return new this({ id: '', fields: node.__fields, key: node.__key })\n }\n\n static override getType(): string {\n return 'autolink'\n }\n\n static override importDOM(): null {\n // TODO: Should link node should handle the import over autolink?\n return null\n }\n\n static override importJSON(serializedNode: SerializedAutoLinkNode): AutoLinkNode {\n const node = $createAutoLinkNode({}).updateFromJSON(serializedNode)\n\n /**\n * @todo remove 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 return node\n }\n\n // @ts-expect-error\n exportJSON(): SerializedAutoLinkNode {\n const serialized = super.exportJSON()\n return {\n type: 'autolink',\n children: serialized.children,\n direction: serialized.direction,\n fields: serialized.fields,\n format: serialized.format,\n indent: serialized.indent,\n version: 2,\n }\n }\n\n override insertNewAfter(selection: RangeSelection, restoreSelection = true): ElementNode | null {\n const element = this.getParentOrThrow().insertNewAfter(selection, restoreSelection)\n if ($isElementNode(element)) {\n const linkNode = $createAutoLinkNode({ fields: this.__fields })\n element.append(linkNode)\n return linkNode\n }\n return null\n }\n\n override updateFromJSON(_serializedNode: LexicalUpdateJSON<SerializedElementNode>): this {\n const serializedNode = _serializedNode as unknown as SerializedAutoLinkNode\n return super.updateFromJSON(serializedNode).setFields(serializedNode.fields)\n }\n}\n\nexport function $createAutoLinkNode({ fields }: { fields?: LinkFields }): AutoLinkNode {\n return $applyNodeReplacement(new AutoLinkNode({ id: '', fields }))\n}\nexport function $isAutoLinkNode(node: LexicalNode | null | undefined): node is AutoLinkNode {\n return node instanceof AutoLinkNode\n}\n"],"mappings":"AAQA,SAASA,qBAAqB,EAAEC,cAAc,QAAQ;AAItD,SAASC,QAAQ,QAAQ;AAEzB;AACA;AAEA,OAAO,MAAMC,YAAA,SAAqBD,QAAA;EAChC,OAAgBE,MAAMC,IAAkB,EAAgB;IACtD,OAAO,IAAI,IAAI,CAAC;MAAEC,EAAA,EAAI;MAAIC,MAAA,EAAQF,IAAA,CAAKG,QAAQ;MAAEC,GAAA,EAAKJ,IAAA,CAAKK;IAAM;EACnE;EAEA,OAAgBC,QAAA,EAAkB;IAChC,OAAO;EACT;EAEA,OAAgBC,UAAA,EAAkB;IAChC;IACA,OAAO;EACT;EAEA,OAAgBC,
|
|
1
|
+
{"version":3,"file":"AutoLinkNode.js","names":["$applyNodeReplacement","$isElementNode","LinkNode","AutoLinkNode","clone","node","id","fields","__fields","key","__key","getType","importDOM","importJSON","serializedNode","$createAutoLinkNode","updateFromJSON","version","doc","value","exportJSON","serialized","type","children","direction","format","indent","insertNewAfter","selection","restoreSelection","element","getParentOrThrow","linkNode","append","_serializedNode","setFields","$isAutoLinkNode"],"sources":["../../../../src/features/link/nodes/AutoLinkNode.ts"],"sourcesContent":["import type {\n ElementNode,\n LexicalNode,\n LexicalUpdateJSON,\n RangeSelection,\n SerializedElementNode,\n} from 'lexical'\n\nimport { $applyNodeReplacement, $isElementNode } from 'lexical'\n\nimport type { LinkFields, SerializedAutoLinkNode } from '../server/schema.js'\n\nimport { LinkNode } from './LinkNode.js'\n\n// Custom node type to override `canInsertTextAfter` that will\n// allow typing within the link\n\nexport class AutoLinkNode extends LinkNode {\n static override clone(node: AutoLinkNode): AutoLinkNode {\n return new this({ id: '', fields: node.__fields, key: node.__key })\n }\n\n static override getType(): string {\n return 'autolink'\n }\n\n static override importDOM(): null {\n // TODO: Should link node should handle the import over autolink?\n return null\n }\n\n static override importJSON(\n serializedNode: Record<string, unknown> & SerializedAutoLinkNode,\n ): AutoLinkNode {\n const node = $createAutoLinkNode({}).updateFromJSON(serializedNode)\n\n /**\n * @todo remove 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 return node\n }\n\n // @ts-expect-error\n exportJSON(): SerializedAutoLinkNode {\n const serialized = super.exportJSON()\n return {\n type: 'autolink',\n children: serialized.children,\n direction: serialized.direction,\n fields: serialized.fields,\n format: serialized.format,\n indent: serialized.indent,\n version: 2,\n }\n }\n\n override insertNewAfter(selection: RangeSelection, restoreSelection = true): ElementNode | null {\n const element = this.getParentOrThrow().insertNewAfter(selection, restoreSelection)\n if ($isElementNode(element)) {\n const linkNode = $createAutoLinkNode({ fields: this.__fields })\n element.append(linkNode)\n return linkNode\n }\n return null\n }\n\n override updateFromJSON(_serializedNode: LexicalUpdateJSON<SerializedElementNode>): this {\n const serializedNode = _serializedNode as unknown as SerializedAutoLinkNode\n return super.updateFromJSON(serializedNode).setFields(serializedNode.fields)\n }\n}\n\nexport function $createAutoLinkNode({ fields }: { fields?: LinkFields }): AutoLinkNode {\n return $applyNodeReplacement(new AutoLinkNode({ id: '', fields }))\n}\nexport function $isAutoLinkNode(node: LexicalNode | null | undefined): node is AutoLinkNode {\n return node instanceof AutoLinkNode\n}\n"],"mappings":"AAQA,SAASA,qBAAqB,EAAEC,cAAc,QAAQ;AAItD,SAASC,QAAQ,QAAQ;AAEzB;AACA;AAEA,OAAO,MAAMC,YAAA,SAAqBD,QAAA;EAChC,OAAgBE,MAAMC,IAAkB,EAAgB;IACtD,OAAO,IAAI,IAAI,CAAC;MAAEC,EAAA,EAAI;MAAIC,MAAA,EAAQF,IAAA,CAAKG,QAAQ;MAAEC,GAAA,EAAKJ,IAAA,CAAKK;IAAM;EACnE;EAEA,OAAgBC,QAAA,EAAkB;IAChC,OAAO;EACT;EAEA,OAAgBC,UAAA,EAAkB;IAChC;IACA,OAAO;EACT;EAEA,OAAgBC,WACdC,cAAgE,EAClD;IACd,MAAMT,IAAA,GAAOU,mBAAA,CAAoB,CAAC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AEA,OAAO,SAASQ,oBAAoB;EAAER;AAAM,CAA2B;EACrE,OAAOP,qBAAA,CAAsB,IAAIG,YAAA,CAAa;IAAEG,EAAA,EAAI;IAAIC;EAAO;AACjE;AACA,OAAO,SAAS6B,gBAAgB/B,IAAoC;EAClE,OAAOA,IAAA,YAAgBF,YAAA;AACzB","ignoreList":[]}
|
|
@@ -14,7 +14,7 @@ export declare class LinkNode extends ElementNode {
|
|
|
14
14
|
static clone(node: LinkNode): LinkNode;
|
|
15
15
|
static getType(): string;
|
|
16
16
|
static importDOM(): DOMConversionMap | null;
|
|
17
|
-
static importJSON(serializedNode: SerializedLinkNode): LinkNode;
|
|
17
|
+
static importJSON(serializedNode: Record<string, unknown> & SerializedLinkNode): LinkNode;
|
|
18
18
|
canBeEmpty(): false;
|
|
19
19
|
canInsertTextAfter(): false;
|
|
20
20
|
canInsertTextBefore(): false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LinkNode.d.ts","sourceRoot":"","sources":["../../../../src/features/link/nodes/LinkNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAEhB,YAAY,EACZ,WAAW,IAAI,eAAe,EAC9B,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,OAAO,EACP,cAAc,EACd,qBAAqB,EACtB,MAAM,SAAS,CAAA;AAIhB,OAAO,EAOL,WAAW,EACZ,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+CAA+C,CAAA;AAChF,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAIzE,oBAAoB;AACpB,qBAAa,QAAS,SAAQ,WAAW;IACvC,QAAQ,EAAE,UAAU,CAAA;IACpB,IAAI,EAAE,MAAM,CAAA;IAEZ,YAAY,EACV,EAAE,EACF,MAGC,EACD,GAAG,GACJ,EAAE;QACD,MAAM,CAAC,EAAE,UAAU,CAAA;QACnB,EA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AE,MAAM,EAAE,UAAU,CAAA;CAAE,GAAG,WAAW,CAAC,GAAG,IAAI,GAAG,IAAI,CA+GxF"}
|
|
@@ -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","_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,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,CAAK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MAAA,CAAOC,SAAS;IACzB,IAAID,MAAA,KAAW,QAAQgB,SAAA,CAAUhB,MAAA,GAAS;MACxC;IACF;EACF;EACA,OAAOA,MAAA;AACT;AAEA,SAASpD,UAAUqE,KAAa,EAAEC,MAAwB,EAAEtF,KAAa;EACvE,IAAIuF,MAAA;EACJ,IAAIC,YAAA,GAAe,GAAGH,KAAA,EAAO;EAC7B,IAAIC,MAAA,KAAW,OAAO;IACpB;IACA,IAAIE,YAAA,CAAaC,QAAQ,CAACzF,KAAA,GAAQ;MAChC,MAAM0F,EAAA,GAAK,IAAIC,MAAA,CAAO3F,KAAA,EAAO;MAC7BwF,YAAA,GAAeA,YAAA,CAAaI,OAAO,CAACF,EAAA,EAAI,IAAIG,IAAI;IAClD;IACAL,YAAA,GAAeA,YAAA,CAAaK,IAAI;IAChCN,MAAA,GAASC,YAAA,CAAarD,MAAM,KAAK,IAAI,GAAGnC,KAAA,EAAO,GAAG,GAAGwF,YAAA,IAAgBxF,KAAA,EAAO;EAC9E,OAAO;IACL,MAAM0F,EAAA,GAAK,IAAIC,MAAA,CAAO3F,KAAA,EAAO;IAC7BuF,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(\n serializedNode: Record<string, unknown> & SerializedLinkNode,\n ): 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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AA,GAASC,YAAA,CAAarD,MAAM,KAAK,IAAI,GAAGnC,KAAA,EAAO,GAAG,GAAGwF,YAAA,IAAgBxF,KAAA,EAAO;EAC9E,OAAO;IACL,MAAM0F,EAAA,GAAK,IAAIC,MAAA,CAAO3F,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.d.ts","sourceRoot":"","sources":["../../../../src/features/link/server/baseFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,kBAAkB,EAElB,eAAe,EAIhB,MAAM,SAAS,CAAA;AAMhB,eAAO,MAAM,aAAa,WAChB,eAAe,uBACF,cAAc,EAAE,wBACf,cAAc,EAAE,aAC3B,MAAM,KAChB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"baseFields.d.ts","sourceRoot":"","sources":["../../../../src/features/link/server/baseFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,kBAAkB,EAElB,eAAe,EAIhB,MAAM,SAAS,CAAA;AAMhB,eAAO,MAAM,aAAa,WAChB,eAAe,uBACF,cAAc,EAAE,wBACf,cAAc,EAAE,aAC3B,MAAM,KAChB,kBAAkB,EAuIpB,CAAA"}
|
|
@@ -15,11 +15,12 @@ export const getBaseFields = (config, enabledCollections, disabledCollections, m
|
|
|
15
15
|
}) => slug);
|
|
16
16
|
} else {
|
|
17
17
|
enabledRelations = config.collections.filter(({
|
|
18
|
-
admin
|
|
19
|
-
enableRichTextLink,
|
|
20
|
-
hidden
|
|
21
|
-
}
|
|
18
|
+
admin
|
|
22
19
|
}) => {
|
|
20
|
+
const {
|
|
21
|
+
enableRichTextLink = true,
|
|
22
|
+
hidden
|
|
23
|
+
} = admin ?? {};
|
|
23
24
|
if (typeof hidden !== 'function' && hidden) {
|
|
24
25
|
return false;
|
|
25
26
|
}
|
|
@@ -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 User,\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
|
|
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 User,\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 }) => {\n const { enableRichTextLink = true, hidden } = admin ?? {}\n\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: User })) {\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;EACv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,GAAA;UACAO,IAAA,EAAM;QACR,OAAO;MAEX,IACA;MACN3B,KAAA,EAAOA,CAAC;QAAEC;MAAC,CAAE,KAAKA,CAAA,CAAE;MACpBd,QAAA;MACAgC,UAAA,EAAY/B,gBAAA;MACZc,QAAA,EAAU;IACZ;EACF;EAEAL,UAAA,CAAWiB,IAAI,CAAC;IACdhB,IAAA,EAAM;IACNC,IAAA,EAAM;IACNC,KAAA,EAAOA,CAAC;MAAEC;IAAC,CAAE,KAAKA,CAAA,CAAE;EACtB;EAEA,OAAOJ,UAAA;AACT","ignoreList":[]}
|
|
@@ -10,7 +10,7 @@ import { createAutoLinkNodeJSONSchema, createLinkNodeJSONSchema } from './schema
|
|
|
10
10
|
import { transformExtraFields } from './transformExtraFields.js';
|
|
11
11
|
import { linkValidation } from './validate.js';
|
|
12
12
|
export const LinkFeature = createServerFeature({
|
|
13
|
-
feature:
|
|
13
|
+
feature: ({
|
|
14
14
|
config: _config,
|
|
15
15
|
isRoot,
|
|
16
16
|
parentIsLocalized,
|
|
@@ -21,7 +21,7 @@ export const LinkFeature = createServerFeature({
|
|
|
21
21
|
}
|
|
22
22
|
const validRelationships = _config.collections.map(c => c.slug) || [];
|
|
23
23
|
const _transformedFields = transformExtraFields(props.fields ? props.fields : null, _config, props.enabledCollections, props.disabledCollections, props.maxDepth);
|
|
24
|
-
const sanitizedFields =
|
|
24
|
+
const sanitizedFields = sanitizeFields({
|
|
25
25
|
config: _config,
|
|
26
26
|
fields: _transformedFields,
|
|
27
27
|
parentIsLocalized,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["sanitizeFields","createServerFeature","createNode","createPayloadLinkTransformer","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 { createPayloadLinkTransformer } 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 createPayloadLinkTransformer({ 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,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;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":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["sanitizeFields","createServerFeature","createNode","createPayloadLinkTransformer","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 { createPayloadLinkTransformer } 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: ({ 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 = 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 createPayloadLinkTransformer({ 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,4BAA4B,QAAQ;AAC7C,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,EAASA,CAAC;IAAEC,MAAA,EAAQC,OAAO;IAAEC,MAAM;IAAEC,iBAAiB;IAAEC;EAAK,CAAE;IAC7D,IAAI,CAACA,KAAA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CAAC4B,OAAA;MACTC,2BAAA,EAA6B3C;IAC/B;EACF;EACA4C,GAAA,EAAK;AACP","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filterEnabledRelationshipCollections.d.ts","sourceRoot":"","sources":["../../../../src/features/relationship/shared/filterEnabledRelationshipCollections.ts"],"names":[],"mappings":"AAAA,KAAK,cAAc,GAAG;IACpB,KAAK,CAAC,EAAE;QACN,0BAA0B,CAAC,EAAE,OAAO,CAAA;KACrC,CAAA;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,2CAA2C,GAAG;IACxD,2DAA2D;IAC3D,mBAAmB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACvC,0DAA0D;IAC1D,kBAAkB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACtC,wFAAwF;IACxF,OAAO,EAAE,OAAO,CAAA;IAChB;;;OAGG;IACH,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CACjC,CAAA;AAED,eAAO,MAAM,oCAAoC,GAAI,WAAW,SAAS,cAAc,eACxE,SAAS,WAAW,EAAE,uEAMhC,2CAA2C,KAC7C,WAAW,
|
|
1
|
+
{"version":3,"file":"filterEnabledRelationshipCollections.d.ts","sourceRoot":"","sources":["../../../../src/features/relationship/shared/filterEnabledRelationshipCollections.ts"],"names":[],"mappings":"AAAA,KAAK,cAAc,GAAG;IACpB,KAAK,CAAC,EAAE;QACN,0BAA0B,CAAC,EAAE,OAAO,CAAA;KACrC,CAAA;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,2CAA2C,GAAG;IACxD,2DAA2D;IAC3D,mBAAmB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACvC,0DAA0D;IAC1D,kBAAkB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IACtC,wFAAwF;IACxF,OAAO,EAAE,OAAO,CAAA;IAChB;;;OAGG;IACH,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CACjC,CAAA;AAED,eAAO,MAAM,oCAAoC,GAAI,WAAW,SAAS,cAAc,eACxE,SAAS,WAAW,EAAE,uEAMhC,2CAA2C,KAC7C,WAAW,EA6Bb,CAAA"}
|
|
@@ -12,14 +12,15 @@ export const filterEnabledRelationshipCollections = (collections, {
|
|
|
12
12
|
admin,
|
|
13
13
|
upload
|
|
14
14
|
} = collection;
|
|
15
|
+
const enableRichTextRelationship = admin?.enableRichTextRelationship ?? true;
|
|
15
16
|
if (visibleSlugs && !visibleSlugs.includes(slug)) {
|
|
16
17
|
return false;
|
|
17
18
|
}
|
|
18
19
|
if (uploads) {
|
|
19
|
-
if (!
|
|
20
|
+
if (!enableRichTextRelationship || !upload) {
|
|
20
21
|
return false;
|
|
21
22
|
}
|
|
22
|
-
} else if (upload || !
|
|
23
|
+
} else if (upload || !enableRichTextRelationship) {
|
|
23
24
|
return false;
|
|
24
25
|
}
|
|
25
26
|
if (whitelistSet && !whitelistSet.has(slug)) {
|