@payloadcms/richtext-lexical 3.0.0-beta.127 → 3.0.0-beta.129
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/LICENSE.md +1 -1
- package/dist/cell/rscEntry.d.ts +12 -0
- package/dist/cell/rscEntry.d.ts.map +1 -0
- package/dist/cell/rscEntry.js +82 -0
- package/dist/cell/rscEntry.js.map +1 -0
- package/dist/exports/client/Field-SHUAQNQD.js +2 -0
- package/dist/exports/client/Field-SHUAQNQD.js.map +7 -0
- package/dist/exports/client/RelationshipComponent-IMM4CFBE.js +2 -0
- package/dist/exports/client/RelationshipComponent-IMM4CFBE.js.map +7 -0
- package/dist/exports/client/bundled.css +1 -1
- package/dist/exports/client/{chunk-NEO76RJK.js → chunk-352SHIZR.js} +2 -2
- package/dist/exports/client/chunk-75T7MDBH.js +2 -0
- package/dist/exports/client/chunk-75T7MDBH.js.map +7 -0
- package/dist/exports/client/{chunk-XY4TCSM7.js → chunk-O4IOO4EU.js} +2 -2
- package/dist/exports/client/chunk-OOBB5GCO.js +2 -0
- package/dist/exports/client/chunk-OOBB5GCO.js.map +7 -0
- package/dist/exports/client/chunk-PDAZFJVO.js +2 -0
- package/dist/exports/client/chunk-PDAZFJVO.js.map +7 -0
- package/dist/exports/client/{chunk-32KXGBIQ.js → chunk-ZOYGBIAN.js} +2 -2
- package/dist/exports/client/component-EHTN2BHZ.js +2 -0
- package/dist/exports/client/component-EHTN2BHZ.js.map +7 -0
- package/dist/exports/client/component-YE2TDR5O.js +2 -0
- package/dist/exports/client/component-YE2TDR5O.js.map +7 -0
- package/dist/exports/client/componentInline-N5LJ2LY2.js +2 -0
- package/dist/exports/client/componentInline-N5LJ2LY2.js.map +7 -0
- package/dist/exports/client/index.d.ts +0 -1
- package/dist/exports/client/index.d.ts.map +1 -1
- package/dist/exports/client/index.js +8 -8
- package/dist/exports/client/index.js.map +4 -4
- package/dist/exports/server/rsc.d.ts +3 -0
- package/dist/exports/server/rsc.d.ts.map +1 -0
- package/dist/exports/server/rsc.js +3 -0
- package/dist/exports/server/rsc.js.map +1 -0
- package/dist/features/blocks/client/component/BlockContent.d.ts +1 -0
- package/dist/features/blocks/client/component/BlockContent.d.ts.map +1 -1
- package/dist/features/blocks/client/component/BlockContent.js +15 -15
- package/dist/features/blocks/client/component/BlockContent.js.map +1 -1
- package/dist/features/blocks/client/component/index.d.ts.map +1 -1
- package/dist/features/blocks/client/component/index.js +68 -52
- package/dist/features/blocks/client/component/index.js.map +1 -1
- package/dist/features/blocks/client/componentInline/index.d.ts.map +1 -1
- package/dist/features/blocks/client/componentInline/index.js +14 -19
- package/dist/features/blocks/client/componentInline/index.js.map +1 -1
- package/dist/features/blocks/client/index.d.ts.map +1 -1
- package/dist/features/blocks/client/index.js +26 -24
- package/dist/features/blocks/client/index.js.map +1 -1
- package/dist/features/blocks/client/plugin/index.d.ts.map +1 -1
- package/dist/features/blocks/client/plugin/index.js +83 -75
- package/dist/features/blocks/client/plugin/index.js.map +1 -1
- package/dist/features/blocks/server/index.d.ts.map +1 -1
- package/dist/features/blocks/server/index.js +20 -10
- package/dist/features/blocks/server/index.js.map +1 -1
- package/dist/features/blocks/server/validate.d.ts.map +1 -1
- package/dist/features/blocks/server/validate.js +8 -5
- package/dist/features/blocks/server/validate.js.map +1 -1
- package/dist/features/debug/testRecorder/client/plugin/index.js +25 -14
- package/dist/features/debug/testRecorder/client/plugin/index.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableActionMenuPlugin/index.js +19 -7
- package/dist/features/experimental_table/client/plugins/TableActionMenuPlugin/index.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.js +16 -3
- package/dist/features/experimental_table/client/plugins/TableCellResizerPlugin/index.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.d.ts.map +1 -1
- package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.js +58 -19
- package/dist/features/experimental_table/client/plugins/TableHoverActionsPlugin/index.js.map +1 -1
- package/dist/features/experimental_table/client/plugins/TablePlugin/index.d.ts.map +1 -1
- package/dist/features/experimental_table/client/plugins/TablePlugin/index.js +38 -32
- package/dist/features/experimental_table/client/plugins/TablePlugin/index.js.map +1 -1
- package/dist/features/experimental_table/server/index.d.ts.map +1 -1
- package/dist/features/experimental_table/server/index.js +3 -1
- package/dist/features/experimental_table/server/index.js.map +1 -1
- package/dist/features/format/bold/feature.client.d.ts.map +1 -1
- package/dist/features/format/bold/feature.client.js +2 -1
- package/dist/features/format/bold/feature.client.js.map +1 -1
- package/dist/features/format/inlineCode/feature.client.d.ts.map +1 -1
- package/dist/features/format/inlineCode/feature.client.js +2 -1
- package/dist/features/format/inlineCode/feature.client.js.map +1 -1
- package/dist/features/format/italic/feature.client.d.ts.map +1 -1
- package/dist/features/format/italic/feature.client.js +2 -1
- package/dist/features/format/italic/feature.client.js.map +1 -1
- package/dist/features/format/strikethrough/feature.client.d.ts.map +1 -1
- package/dist/features/format/strikethrough/feature.client.js +2 -1
- package/dist/features/format/strikethrough/feature.client.js.map +1 -1
- package/dist/features/format/subscript/feature.client.d.ts.map +1 -1
- package/dist/features/format/subscript/feature.client.js +2 -1
- package/dist/features/format/subscript/feature.client.js.map +1 -1
- package/dist/features/format/superscript/feature.client.d.ts.map +1 -1
- package/dist/features/format/superscript/feature.client.js +2 -1
- package/dist/features/format/superscript/feature.client.js.map +1 -1
- package/dist/features/format/underline/feature.client.d.ts.map +1 -1
- package/dist/features/format/underline/feature.client.js +2 -1
- package/dist/features/format/underline/feature.client.js.map +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.d.ts.map +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js +52 -15
- package/dist/features/link/client/plugins/floatingLinkEditor/LinkEditor/index.js.map +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/index.js +1 -1
- package/dist/features/link/client/plugins/floatingLinkEditor/index.js.map +1 -1
- package/dist/features/link/server/i18n.d.ts.map +1 -1
- package/dist/features/link/server/i18n.js +64 -32
- package/dist/features/link/server/i18n.js.map +1 -1
- package/dist/features/link/server/index.d.ts.map +1 -1
- package/dist/features/link/server/index.js +3 -1
- package/dist/features/link/server/index.js.map +1 -1
- package/dist/features/link/server/validate.d.ts.map +1 -1
- package/dist/features/link/server/validate.js +8 -5
- package/dist/features/link/server/validate.js.map +1 -1
- package/dist/features/relationship/client/components/RelationshipComponent.d.ts.map +1 -1
- package/dist/features/relationship/client/components/RelationshipComponent.js +6 -4
- package/dist/features/relationship/client/components/RelationshipComponent.js.map +1 -1
- package/dist/features/toolbars/fixed/client/Toolbar/index.d.ts.map +1 -1
- package/dist/features/toolbars/fixed/client/Toolbar/index.js +77 -49
- package/dist/features/toolbars/fixed/client/Toolbar/index.js.map +1 -1
- package/dist/features/toolbars/inline/client/Toolbar/index.js +93 -52
- package/dist/features/toolbars/inline/client/Toolbar/index.js.map +1 -1
- package/dist/features/toolbars/shared/ToolbarButton/index.js +1 -1
- package/dist/features/toolbars/shared/ToolbarButton/index.js.map +1 -1
- package/dist/features/toolbars/shared/ToolbarDropdown/DropDown.js +2 -2
- package/dist/features/toolbars/shared/ToolbarDropdown/DropDown.js.map +1 -1
- package/dist/features/toolbars/shared/ToolbarDropdown/index.d.ts.map +1 -1
- package/dist/features/toolbars/shared/ToolbarDropdown/index.js +25 -22
- package/dist/features/toolbars/shared/ToolbarDropdown/index.js.map +1 -1
- package/dist/features/toolbars/types.d.ts +3 -1
- package/dist/features/toolbars/types.d.ts.map +1 -1
- package/dist/features/toolbars/types.js.map +1 -1
- package/dist/features/typesServer.d.ts +4 -17
- package/dist/features/typesServer.d.ts.map +1 -1
- package/dist/features/typesServer.js.map +1 -1
- package/dist/features/upload/client/component/index.d.ts.map +1 -1
- package/dist/features/upload/client/component/index.js +8 -4
- package/dist/features/upload/client/component/index.js.map +1 -1
- package/dist/features/upload/server/feature.server.d.ts.map +1 -1
- package/dist/features/upload/server/feature.server.js +3 -1
- package/dist/features/upload/server/feature.server.js.map +1 -1
- package/dist/features/upload/server/validate.d.ts.map +1 -1
- package/dist/features/upload/server/validate.js +7 -4
- package/dist/features/upload/server/validate.js.map +1 -1
- package/dist/field/Field.d.ts.map +1 -1
- package/dist/field/Field.js +27 -41
- package/dist/field/Field.js.map +1 -1
- package/dist/field/bundled.css +1 -1
- package/dist/field/index.d.ts.map +1 -1
- package/dist/field/index.js +26 -27
- package/dist/field/index.js.map +1 -1
- package/dist/field/rscEntry.d.ts +9 -0
- package/dist/field/rscEntry.d.ts.map +1 -0
- package/dist/field/rscEntry.js +37 -0
- package/dist/field/rscEntry.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -14
- package/dist/index.js.map +1 -1
- package/dist/lexical/LexicalProvider.d.ts +1 -1
- package/dist/lexical/LexicalProvider.d.ts.map +1 -1
- package/dist/lexical/LexicalProvider.js +2 -2
- package/dist/lexical/LexicalProvider.js.map +1 -1
- package/dist/lexical/config/client/EditorConfigProvider.d.ts +4 -3
- package/dist/lexical/config/client/EditorConfigProvider.d.ts.map +1 -1
- package/dist/lexical/config/client/EditorConfigProvider.js +5 -5
- package/dist/lexical/config/client/EditorConfigProvider.js.map +1 -1
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.d.ts +4 -4
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.d.ts.map +1 -1
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js +14 -5
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/LexicalMenu.js.map +1 -1
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.d.ts +2 -2
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.d.ts.map +1 -1
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.js +5 -5
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/index.js.map +1 -1
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.d.ts +3 -2
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.d.ts.map +1 -1
- package/dist/lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.js.map +1 -1
- package/dist/lexical/plugins/SlashMenu/index.d.ts.map +1 -1
- package/dist/lexical/plugins/SlashMenu/index.js +15 -24
- package/dist/lexical/plugins/SlashMenu/index.js.map +1 -1
- package/dist/lexical/plugins/handles/AddBlockHandlePlugin/index.js +6 -4
- package/dist/lexical/plugins/handles/AddBlockHandlePlugin/index.js.map +1 -1
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.js +6 -4
- package/dist/lexical/plugins/handles/DraggableBlockPlugin/index.js.map +1 -1
- package/dist/lexical/theme/EditorTheme.d.ts.map +1 -1
- package/dist/lexical/theme/EditorTheme.js +0 -2
- package/dist/lexical/theme/EditorTheme.js.map +1 -1
- package/dist/types.d.ts +15 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/fieldsDrawer/Drawer.d.ts +1 -0
- package/dist/utilities/fieldsDrawer/Drawer.d.ts.map +1 -1
- package/dist/utilities/fieldsDrawer/Drawer.js +25 -20
- package/dist/utilities/fieldsDrawer/Drawer.js.map +1 -1
- package/dist/utilities/fieldsDrawer/DrawerContent.d.ts.map +1 -1
- package/dist/utilities/fieldsDrawer/DrawerContent.js +99 -143
- package/dist/utilities/fieldsDrawer/DrawerContent.js.map +1 -1
- package/dist/utilities/fieldsDrawer/useLexicalDrawer.js +1 -1
- package/dist/utilities/fieldsDrawer/useLexicalDrawer.js.map +1 -1
- package/dist/utilities/generateImportMap.d.ts.map +1 -1
- package/dist/utilities/generateImportMap.js +2 -3
- package/dist/utilities/generateImportMap.js.map +1 -1
- package/dist/utilities/generateSchemaMap.d.ts.map +1 -1
- package/dist/utilities/generateSchemaMap.js +13 -10
- package/dist/utilities/generateSchemaMap.js.map +1 -1
- package/dist/utilities/initLexicalFeatures.d.ts +18 -0
- package/dist/utilities/initLexicalFeatures.d.ts.map +1 -0
- package/dist/utilities/initLexicalFeatures.js +95 -0
- package/dist/utilities/initLexicalFeatures.js.map +1 -0
- package/dist/utilities/upgradeLexicalData/upgradeDocumentFieldsRecursively.d.ts.map +1 -1
- package/dist/utilities/upgradeLexicalData/upgradeDocumentFieldsRecursively.js +5 -1
- package/dist/utilities/upgradeLexicalData/upgradeDocumentFieldsRecursively.js.map +1 -1
- package/dist/utilities/useLexicalFeature.d.ts.map +1 -1
- package/dist/utilities/useLexicalFeature.js +12 -4
- package/dist/utilities/useLexicalFeature.js.map +1 -1
- package/dist/validate/index.d.ts.map +1 -1
- package/dist/validate/index.js +1 -1
- package/dist/validate/index.js.map +1 -1
- package/package.json +43 -35
- package/dist/cell/index.d.ts +0 -9
- package/dist/cell/index.d.ts.map +0 -1
- package/dist/cell/index.js +0 -120
- package/dist/cell/index.js.map +0 -1
- package/dist/exports/client/Field-Y47DV2NP.js +0 -2
- package/dist/exports/client/Field-Y47DV2NP.js.map +0 -7
- package/dist/exports/client/RelationshipComponent-LBWKOBGF.js +0 -2
- package/dist/exports/client/RelationshipComponent-LBWKOBGF.js.map +0 -7
- package/dist/exports/client/chunk-7SR2HYD6.js +0 -2
- package/dist/exports/client/chunk-7SR2HYD6.js.map +0 -7
- package/dist/exports/client/chunk-GD6LBQBJ.js +0 -2
- package/dist/exports/client/chunk-GD6LBQBJ.js.map +0 -7
- package/dist/exports/client/chunk-IIWHHN4J.js +0 -2
- package/dist/exports/client/chunk-IIWHHN4J.js.map +0 -7
- package/dist/exports/client/component-4TP4L5EV.js +0 -2
- package/dist/exports/client/component-4TP4L5EV.js.map +0 -7
- package/dist/exports/client/component-XMR5NN36.js +0 -2
- package/dist/exports/client/component-XMR5NN36.js.map +0 -7
- package/dist/exports/client/componentInline-NUDJIIQ4.js +0 -2
- package/dist/exports/client/componentInline-NUDJIIQ4.js.map +0 -7
- package/dist/utilities/generateComponentMap.d.ts +0 -6
- package/dist/utilities/generateComponentMap.d.ts.map +0 -1
- package/dist/utilities/generateComponentMap.js +0 -93
- package/dist/utilities/generateComponentMap.js.map +0 -1
- /package/dist/exports/client/{chunk-NEO76RJK.js.map → chunk-352SHIZR.js.map} +0 -0
- /package/dist/exports/client/{chunk-XY4TCSM7.js.map → chunk-O4IOO4EU.js.map} +0 -0
- /package/dist/exports/client/{chunk-32KXGBIQ.js.map → chunk-ZOYGBIAN.js.map} +0 -0
|
@@ -26,15 +26,17 @@ export const BlocksFeatureClient = createClientFeature(({
|
|
|
26
26
|
key: 'block-' + blockSlug,
|
|
27
27
|
keywords: ['block', 'blocks', blockSlug],
|
|
28
28
|
label: ({
|
|
29
|
+
featureClientSchemaMap,
|
|
29
30
|
i18n,
|
|
30
|
-
|
|
31
|
+
schemaPath
|
|
31
32
|
}) => {
|
|
32
|
-
if (!
|
|
33
|
+
if (!featureClientSchemaMap) {
|
|
33
34
|
return blockSlug;
|
|
34
35
|
}
|
|
35
|
-
const componentMapRenderedBlockPath =
|
|
36
|
-
const
|
|
37
|
-
const
|
|
36
|
+
const componentMapRenderedBlockPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_blocks.${blockSlug}`;
|
|
37
|
+
const clientSchemaMap = featureClientSchemaMap['blocks'];
|
|
38
|
+
const blocksField = clientSchemaMap[componentMapRenderedBlockPath][0];
|
|
39
|
+
const clientBlock = blocksField.blocks[0];
|
|
38
40
|
const blockDisplayName = clientBlock?.labels?.singular ? getTranslation(clientBlock.labels.singular, i18n) : clientBlock?.slug;
|
|
39
41
|
return blockDisplayName;
|
|
40
42
|
},
|
|
@@ -61,15 +63,14 @@ export const BlocksFeatureClient = createClientFeature(({
|
|
|
61
63
|
key: 'inlineBlocks-' + inlineBlockSlug,
|
|
62
64
|
keywords: ['inlineBlock', 'inline block', inlineBlockSlug],
|
|
63
65
|
label: ({
|
|
66
|
+
featureClientSchemaMap,
|
|
64
67
|
i18n,
|
|
65
|
-
|
|
68
|
+
schemaPath
|
|
66
69
|
}) => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
const
|
|
71
|
-
const blocksField = richTextComponentMap.get(componentMapRenderedBlockPath)?.[0];
|
|
72
|
-
const clientBlock = blocksField.blocks.find(_block => _block.slug === inlineBlockSlug);
|
|
70
|
+
const componentMapRenderedBlockPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.${inlineBlockSlug}`;
|
|
71
|
+
const clientSchemaMap = featureClientSchemaMap['blocks'];
|
|
72
|
+
const blocksField = clientSchemaMap[componentMapRenderedBlockPath][0];
|
|
73
|
+
const clientBlock = blocksField.blocks[0];
|
|
73
74
|
const blockDisplayName = clientBlock?.labels?.singular ? getTranslation(clientBlock.labels.singular, i18n) : clientBlock?.slug;
|
|
74
75
|
return blockDisplayName;
|
|
75
76
|
},
|
|
@@ -103,15 +104,14 @@ export const BlocksFeatureClient = createClientFeature(({
|
|
|
103
104
|
isActive: undefined,
|
|
104
105
|
key: 'block-' + blockSlug,
|
|
105
106
|
label: ({
|
|
107
|
+
featureClientSchemaMap,
|
|
106
108
|
i18n,
|
|
107
|
-
|
|
109
|
+
schemaPath
|
|
108
110
|
}) => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
const blocksField = richTextComponentMap.get(componentMapRenderedBlockPath)?.[0];
|
|
114
|
-
const clientBlock = blocksField.blocks.find(_block => _block.slug === blockSlug);
|
|
111
|
+
const componentMapRenderedBlockPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_blocks.${blockSlug}`;
|
|
112
|
+
const clientSchemaMap = featureClientSchemaMap['blocks'];
|
|
113
|
+
const blocksField = clientSchemaMap[componentMapRenderedBlockPath][0];
|
|
114
|
+
const clientBlock = blocksField.blocks[0];
|
|
115
115
|
const blockDisplayName = clientBlock?.labels?.singular ? getTranslation(clientBlock.labels.singular, i18n) : clientBlock?.slug;
|
|
116
116
|
return blockDisplayName;
|
|
117
117
|
},
|
|
@@ -137,15 +137,17 @@ export const BlocksFeatureClient = createClientFeature(({
|
|
|
137
137
|
isActive: undefined,
|
|
138
138
|
key: 'inlineBlock-' + inlineBlockSlug,
|
|
139
139
|
label: ({
|
|
140
|
+
featureClientSchemaMap,
|
|
140
141
|
i18n,
|
|
141
|
-
|
|
142
|
+
schemaPath
|
|
142
143
|
}) => {
|
|
143
|
-
if (!
|
|
144
|
+
if (!featureClientSchemaMap) {
|
|
144
145
|
return inlineBlockSlug;
|
|
145
146
|
}
|
|
146
|
-
const componentMapRenderedBlockPath =
|
|
147
|
-
const
|
|
148
|
-
const
|
|
147
|
+
const componentMapRenderedBlockPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.${inlineBlockSlug}`;
|
|
148
|
+
const clientSchemaMap = featureClientSchemaMap['blocks'];
|
|
149
|
+
const blocksField = clientSchemaMap[componentMapRenderedBlockPath][0];
|
|
150
|
+
const clientBlock = blocksField.blocks[0];
|
|
149
151
|
const blockDisplayName = clientBlock?.labels?.singular ? getTranslation(clientBlock.labels.singular, i18n) : clientBlock?.slug;
|
|
150
152
|
return blockDisplayName;
|
|
151
153
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["getTranslation","BlockIcon","InlineBlocksIcon","createClientFeature","BlockNode","InlineBlockNode","INSERT_BLOCK_COMMAND","OPEN_INLINE_BLOCK_DRAWER_COMMAND","BlocksPlugin","BlocksFeatureClient","props","nodes","plugins","Component","position","sanitizedClientFeatureProps","slashMenu","groups","clientBlockSlugs","length","items","map","blockSlug","Icon","key","keywords","label","i18n","richTextComponentMap","componentMapRenderedBlockPath","blocksField","get","clientBlock","blocks","find","_block","slug","blockDisplayName","labels","singular","onSelect","editor","dispatchCommand","blockName","blockType","t","clientInlineBlockSlugs","inlineBlockSlug","fields","filter","Boolean","toolbarFixed","type","ChildComponent","index","isActive","undefined","order"],"sources":["../../../../src/features/blocks/client/index.tsx"],"sourcesContent":["'use client'\n\nimport type { BlocksFieldClient } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\n\nimport type { SlashMenuItem } from '../../../lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.js'\nimport type { ToolbarGroup, ToolbarGroupItem } from '../../toolbars/types.js'\n\nimport { BlockIcon } from '../../../lexical/ui/icons/Block/index.js'\nimport { InlineBlocksIcon } from '../../../lexical/ui/icons/InlineBlocks/index.js'\nimport { createClientFeature } from '../../../utilities/createClientFeature.js'\nimport { BlockNode } from './nodes/BlocksNode.js'\nimport { InlineBlockNode } from './nodes/InlineBlocksNode.js'\nimport { INSERT_BLOCK_COMMAND, OPEN_INLINE_BLOCK_DRAWER_COMMAND } from './plugin/commands.js'\nimport { BlocksPlugin } from './plugin/index.js'\n\nexport type BlocksFeatureClientProps = {\n clientBlockSlugs: string[]\n clientInlineBlockSlugs: string[]\n}\n// @ts-expect-error - TODO: fix this\nexport const BlocksFeatureClient = createClientFeature<BlocksFeatureClientProps>(({ props }) => ({\n nodes: [BlockNode, InlineBlockNode],\n plugins: [\n {\n Component: BlocksPlugin,\n position: 'normal',\n },\n ],\n sanitizedClientFeatureProps: props,\n slashMenu: {\n groups: [\n props.clientBlockSlugs?.length\n ? {\n items: props.clientBlockSlugs.map((blockSlug) => {\n return {\n Icon: BlockIcon,\n key: 'block-' + blockSlug,\n keywords: ['block', 'blocks', blockSlug],\n label: ({ i18n, richTextComponentMap }) => {\n if (!richTextComponentMap) {\n return blockSlug\n }\n\n const componentMapRenderedBlockPath = `lexical_internal_feature.blocks.fields.lexical_blocks`\n const blocksField: BlocksFieldClient = richTextComponentMap.get(\n componentMapRenderedBlockPath,\n )?.[0]\n\n const clientBlock = blocksField.blocks.find((_block) => _block.slug === blockSlug)\n\n const blockDisplayName = clientBlock?.labels?.singular\n ? getTranslation(clientBlock.labels.singular, i18n)\n : clientBlock?.slug\n\n return blockDisplayName\n },\n onSelect: ({ editor }) => {\n editor.dispatchCommand(INSERT_BLOCK_COMMAND, {\n blockName: '',\n blockType: blockSlug,\n })\n },\n } as SlashMenuItem\n }),\n key: 'blocks',\n label: ({ i18n }) => {\n return i18n.t('lexical:blocks:label')\n },\n }\n : null,\n props.clientInlineBlockSlugs?.length\n ? {\n items: props.clientInlineBlockSlugs.map((inlineBlockSlug) => {\n return {\n Icon: InlineBlocksIcon,\n key: 'inlineBlocks-' + inlineBlockSlug,\n keywords: ['inlineBlock', 'inline block', inlineBlockSlug],\n label: ({ i18n, richTextComponentMap }) => {\n if (!richTextComponentMap) {\n return inlineBlockSlug\n }\n\n const componentMapRenderedBlockPath = `lexical_internal_feature.blocks.fields.lexical_inline_blocks`\n\n const blocksField: BlocksFieldClient = richTextComponentMap.get(\n componentMapRenderedBlockPath,\n )?.[0]\n\n const clientBlock = blocksField.blocks.find(\n (_block) => _block.slug === inlineBlockSlug,\n )\n\n const blockDisplayName = clientBlock?.labels?.singular\n ? getTranslation(clientBlock.labels.singular, i18n)\n : clientBlock?.slug\n\n return blockDisplayName\n },\n onSelect: ({ editor }) => {\n editor.dispatchCommand(OPEN_INLINE_BLOCK_DRAWER_COMMAND, {\n fields: {\n blockName: '',\n blockType: inlineBlockSlug,\n },\n })\n },\n } as SlashMenuItem\n }),\n key: 'inlineBlocks',\n label: ({ i18n }) => {\n return i18n.t('lexical:blocks:inlineBlocks:label')\n },\n }\n : null,\n ].filter(Boolean),\n },\n toolbarFixed: {\n groups: [\n props.clientBlockSlugs?.length\n ? {\n type: 'dropdown',\n ChildComponent: BlockIcon,\n items: props.clientBlockSlugs.map((blockSlug, index) => {\n return {\n ChildComponent: BlockIcon,\n isActive: undefined, // At this point, we would be inside a sub-richtext-editor. And at this point this will be run against the focused sub-editor, not the parent editor which has the actual block. Thus, no point in running this\n key: 'block-' + blockSlug,\n label: ({ i18n, richTextComponentMap }) => {\n if (!richTextComponentMap) {\n return blockSlug\n }\n const componentMapRenderedBlockPath = `lexical_internal_feature.blocks.fields.lexical_blocks`\n const blocksField: BlocksFieldClient = richTextComponentMap.get(\n componentMapRenderedBlockPath,\n )?.[0]\n\n const clientBlock = blocksField.blocks.find((_block) => _block.slug === blockSlug)\n\n const blockDisplayName = clientBlock?.labels?.singular\n ? getTranslation(clientBlock.labels.singular, i18n)\n : clientBlock?.slug\n\n return blockDisplayName\n },\n onSelect: ({ editor }) => {\n editor.dispatchCommand(INSERT_BLOCK_COMMAND, {\n blockName: '',\n blockType: blockSlug,\n })\n },\n order: index,\n } as ToolbarGroupItem\n }),\n key: 'blocks',\n order: 20,\n }\n : null,\n props.clientInlineBlockSlugs?.length\n ? {\n type: 'dropdown',\n ChildComponent: InlineBlocksIcon,\n items: props.clientInlineBlockSlugs.map((inlineBlockSlug, index) => {\n return {\n ChildComponent: InlineBlocksIcon,\n isActive: undefined,\n key: 'inlineBlock-' + inlineBlockSlug,\n label: ({ i18n, richTextComponentMap }) => {\n if (!richTextComponentMap) {\n return inlineBlockSlug\n }\n\n const componentMapRenderedBlockPath = `lexical_internal_feature.blocks.fields.lexical_inline_blocks`\n const blocksField: BlocksFieldClient = richTextComponentMap.get(\n componentMapRenderedBlockPath,\n )?.[0]\n\n const clientBlock = blocksField.blocks.find(\n (_block) => _block.slug === inlineBlockSlug,\n )\n\n const blockDisplayName = clientBlock?.labels?.singular\n ? getTranslation(clientBlock.labels.singular, i18n)\n : clientBlock?.slug\n\n return blockDisplayName\n },\n onSelect: ({ editor }) => {\n editor.dispatchCommand(OPEN_INLINE_BLOCK_DRAWER_COMMAND, {\n fields: {\n blockType: inlineBlockSlug,\n },\n })\n },\n order: index,\n } as ToolbarGroupItem\n }),\n key: 'inlineBlocks',\n order: 25,\n }\n : null,\n ].filter(Boolean) as ToolbarGroup[],\n },\n}))\n"],"mappings":"AAAA;;AAIA,SAASA,cAAc,QAAQ;AAK/B,SAASC,SAAS,QAAQ;AAC1B,SAASC,gBAAgB,QAAQ;AACjC,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B;MACEiC,IAAA,EAAM;MACNC,cAAA,EAAgBnD,gBAAA;MAChBkB,KAAA,EAAOV,KAAA,CAAMoC,sBAAsB,CAACzB,GAAG,CAAC,CAAC0B,eAAA,EAAiBO,KAAA;QACxD,OAAO;UACLD,cAAA,EAAgBnD,gBAAA;UAChBqD,QAAA,EAAUC,SAAA;UACVhC,GAAA,EAAK,iBAAiBuB,eAAA;UACtBrB,KAAA,EAAOA,CAAC;YAAEC,IAAI;YAAEC;UAAoB,CAAE;YACpC,IAAI,CAACA,oBAAA,EAAsB;cACzB,OAAOmB,eAAA;YACT;YAEA,MAAMlB,6BAAA,GAAgC,8DAA8D;YACpG,MAAMC,WAAA,GAAiCF,oBAAA,CAAqBG,GAAG,CAC7DF,6BAAA,IACE,EAAE;YAEN,MAAMG,WAAA,GAAcF,WAAA,CAAYG,MAAM,CAACC,IAAI,CACxCC,MAAA,IAAWA,MAAA,CAAOC,IAAI,KAAKW,eAAA;YAG9B,MAAMV,gBAAA,GAAmBL,WAAA,EAAaM,MAAA,EAAQC,QAAA,GAC1CvC,cAAA,CAAegC,WAAA,CAAYM,MAAM,CAACC,QAAQ,EAAEZ,IAAA,IAC5CK,WAAA,EAAaI,IAAA;YAEjB,OAAOC,gBAAA;UACT;UACAG,QAAA,EAAUA,CAAC;YAAEC;UAAM,CAAE;YACnBA,MAAA,CAAOC,eAAe,CAACnC,gCAAA,EAAkC;cACvDyC,MAAA,EAAQ;gBACNJ,SAAA,EAAWG;cACb;YACF;UACF;UACAU,KAAA,EAAOH;QACT;MACF;MACA9B,GAAA,EAAK;MACLiC,KAAA,EAAO;IACT,IACA,KACL,CAACR,MAAM,CAACC,OAAA;EACX;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["getTranslation","BlockIcon","InlineBlocksIcon","createClientFeature","BlockNode","InlineBlockNode","INSERT_BLOCK_COMMAND","OPEN_INLINE_BLOCK_DRAWER_COMMAND","BlocksPlugin","BlocksFeatureClient","props","nodes","plugins","Component","position","sanitizedClientFeatureProps","slashMenu","groups","clientBlockSlugs","length","items","map","blockSlug","Icon","key","keywords","label","featureClientSchemaMap","i18n","schemaPath","componentMapRenderedBlockPath","clientSchemaMap","blocksField","clientBlock","blocks","blockDisplayName","labels","singular","slug","onSelect","editor","dispatchCommand","blockName","blockType","t","clientInlineBlockSlugs","inlineBlockSlug","fields","filter","Boolean","toolbarFixed","type","ChildComponent","index","isActive","undefined","order"],"sources":["../../../../src/features/blocks/client/index.tsx"],"sourcesContent":["'use client'\n\nimport type { BlocksFieldClient } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\n\nimport type { SlashMenuItem } from '../../../lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.js'\nimport type { ToolbarGroup, ToolbarGroupItem } from '../../toolbars/types.js'\n\nimport { BlockIcon } from '../../../lexical/ui/icons/Block/index.js'\nimport { InlineBlocksIcon } from '../../../lexical/ui/icons/InlineBlocks/index.js'\nimport { createClientFeature } from '../../../utilities/createClientFeature.js'\nimport { BlockNode } from './nodes/BlocksNode.js'\nimport { InlineBlockNode } from './nodes/InlineBlocksNode.js'\nimport { INSERT_BLOCK_COMMAND, OPEN_INLINE_BLOCK_DRAWER_COMMAND } from './plugin/commands.js'\nimport { BlocksPlugin } from './plugin/index.js'\n\nexport type BlocksFeatureClientProps = {\n clientBlockSlugs: string[]\n clientInlineBlockSlugs: string[]\n}\n// @ts-expect-error - TODO: fix this\nexport const BlocksFeatureClient = createClientFeature<BlocksFeatureClientProps>(({ props }) => ({\n nodes: [BlockNode, InlineBlockNode],\n plugins: [\n {\n Component: BlocksPlugin,\n position: 'normal',\n },\n ],\n sanitizedClientFeatureProps: props,\n slashMenu: {\n groups: [\n props.clientBlockSlugs?.length\n ? {\n items: props.clientBlockSlugs.map((blockSlug) => {\n return {\n Icon: BlockIcon,\n key: 'block-' + blockSlug,\n keywords: ['block', 'blocks', blockSlug],\n label: ({ featureClientSchemaMap, i18n, schemaPath }) => {\n if (!featureClientSchemaMap) {\n return blockSlug\n }\n\n const componentMapRenderedBlockPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_blocks.${blockSlug}`\n const clientSchemaMap = featureClientSchemaMap['blocks']\n\n const blocksField: BlocksFieldClient = clientSchemaMap[\n componentMapRenderedBlockPath\n ][0] as BlocksFieldClient\n\n const clientBlock = blocksField.blocks[0]\n\n const blockDisplayName = clientBlock?.labels?.singular\n ? getTranslation(clientBlock.labels.singular, i18n)\n : clientBlock?.slug\n\n return blockDisplayName\n },\n onSelect: ({ editor }) => {\n editor.dispatchCommand(INSERT_BLOCK_COMMAND, {\n blockName: '',\n blockType: blockSlug,\n })\n },\n } as SlashMenuItem\n }),\n key: 'blocks',\n label: ({ i18n }) => {\n return i18n.t('lexical:blocks:label')\n },\n }\n : null,\n props.clientInlineBlockSlugs?.length\n ? {\n items: props.clientInlineBlockSlugs.map((inlineBlockSlug) => {\n return {\n Icon: InlineBlocksIcon,\n key: 'inlineBlocks-' + inlineBlockSlug,\n keywords: ['inlineBlock', 'inline block', inlineBlockSlug],\n label: ({ featureClientSchemaMap, i18n, schemaPath }) => {\n const componentMapRenderedBlockPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.${inlineBlockSlug}`\n const clientSchemaMap = featureClientSchemaMap['blocks']\n\n const blocksField: BlocksFieldClient = clientSchemaMap[\n componentMapRenderedBlockPath\n ][0] as BlocksFieldClient\n\n const clientBlock = blocksField.blocks[0]\n\n const blockDisplayName = clientBlock?.labels?.singular\n ? getTranslation(clientBlock.labels.singular, i18n)\n : clientBlock?.slug\n\n return blockDisplayName\n },\n onSelect: ({ editor }) => {\n editor.dispatchCommand(OPEN_INLINE_BLOCK_DRAWER_COMMAND, {\n fields: {\n blockName: '',\n blockType: inlineBlockSlug,\n },\n })\n },\n } as SlashMenuItem\n }),\n key: 'inlineBlocks',\n label: ({ i18n }) => {\n return i18n.t('lexical:blocks:inlineBlocks:label')\n },\n }\n : null,\n ].filter(Boolean),\n },\n toolbarFixed: {\n groups: [\n props.clientBlockSlugs?.length\n ? {\n type: 'dropdown',\n ChildComponent: BlockIcon,\n items: props.clientBlockSlugs.map((blockSlug, index) => {\n return {\n ChildComponent: BlockIcon,\n isActive: undefined, // At this point, we would be inside a sub-richtext-editor. And at this point this will be run against the focused sub-editor, not the parent editor which has the actual block. Thus, no point in running this\n key: 'block-' + blockSlug,\n label: ({ featureClientSchemaMap, i18n, schemaPath }) => {\n const componentMapRenderedBlockPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_blocks.${blockSlug}`\n const clientSchemaMap = featureClientSchemaMap['blocks']\n\n const blocksField: BlocksFieldClient = clientSchemaMap[\n componentMapRenderedBlockPath\n ][0] as BlocksFieldClient\n\n const clientBlock = blocksField.blocks[0]\n\n const blockDisplayName = clientBlock?.labels?.singular\n ? getTranslation(clientBlock.labels.singular, i18n)\n : clientBlock?.slug\n\n return blockDisplayName\n },\n onSelect: ({ editor }) => {\n editor.dispatchCommand(INSERT_BLOCK_COMMAND, {\n blockName: '',\n blockType: blockSlug,\n })\n },\n order: index,\n } as ToolbarGroupItem\n }),\n key: 'blocks',\n order: 20,\n }\n : null,\n props.clientInlineBlockSlugs?.length\n ? {\n type: 'dropdown',\n ChildComponent: InlineBlocksIcon,\n items: props.clientInlineBlockSlugs.map((inlineBlockSlug, index) => {\n return {\n ChildComponent: InlineBlocksIcon,\n isActive: undefined,\n key: 'inlineBlock-' + inlineBlockSlug,\n label: ({ featureClientSchemaMap, i18n, schemaPath }) => {\n if (!featureClientSchemaMap) {\n return inlineBlockSlug\n }\n\n const componentMapRenderedBlockPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.${inlineBlockSlug}`\n const clientSchemaMap = featureClientSchemaMap['blocks']\n\n const blocksField: BlocksFieldClient = clientSchemaMap[\n componentMapRenderedBlockPath\n ][0] as BlocksFieldClient\n\n const clientBlock = blocksField.blocks[0]\n\n const blockDisplayName = clientBlock?.labels?.singular\n ? getTranslation(clientBlock.labels.singular, i18n)\n : clientBlock?.slug\n\n return blockDisplayName\n },\n onSelect: ({ editor }) => {\n editor.dispatchCommand(OPEN_INLINE_BLOCK_DRAWER_COMMAND, {\n fields: {\n blockType: inlineBlockSlug,\n },\n })\n },\n order: index,\n } as ToolbarGroupItem\n }),\n key: 'inlineBlocks',\n order: 25,\n }\n : null,\n ].filter(Boolean) as ToolbarGroup[],\n },\n}))\n"],"mappings":"AAAA;;AAIA,SAASA,cAAc,QAAQ;AAK/B,SAASC,SAAS,QAAQ;AAC1B,SAASC,gBAAgB,QAAQ;AACjC,SAASC,mBAAmB,QAAQ;AACpC,SAASC,SAAS,QAAQ;AAC1B,SAASC,eAAe,QAAQ;AAChC,SAASC,oBAAoB,EAAEC,gCAAgC,QAAQ;AACvE,SAASC,YAAY,QAAQ;AAM7B;AACA,OAAO,MAAMC,mBAAA,GAAsBN,mBAAA,CAA8C,CAAC;EAAEO;AAAK,CAAE,MAAM;EAC/FC,KAAA,EAAO,CAACP,SAAA,EAAWC,eAAA,CAAgB;EACnCO,OAAA,EAAS,CACP;IACEC,SAAA,EAAWL,YAAA;IACXM,QAAA,EAAU;EACZ,EACD;EACDC,2BAAA,EAA6BL,KAAA;EAC7BM,SAAA,EAAW;IACTC,MAAA,EAAQ,CACNP,KAAA,CAAMQ,gBAAgB,EAAEC,MAAA,GACpB;MACEC,KAAA,EAAOV,KAAA,CAAMQ,gBAAgB,CAACG,GAAG,CAAEC,SAAA;QACjC,OAAO;UACLC,IAAA,EAAMtB,SAAA;UACNuB,GAAA,EAAK,WAAWF,SAAA;UAChBG,QAAA,EAAU,CAAC,SAAS,UAAUH,SAAA,CAAU;UACxCI,KAAA,EAAOA,CAAC;YAAEC,sBAAsB;YAAEC,IAAI;YAAEC;UAAU,CAAE;YAClD,IAAI,CAACF,sBAAA,EAAwB;cAC3B,OAAOL,SAAA;YACT;YAEA,MAAMQ,6BAAA,GAAgC,GAAGD,UAAA,mDAA6DP,SAAA,EAAW;YACjH,MAAMS,eAAA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C,MAAA,EAAQ;gBACNJ,SAAA,EAAWG;cACb;YACF;UACF;UACAU,KAAA,EAAOH;QACT;MACF;MACA7B,GAAA,EAAK;MACLgC,KAAA,EAAO;IACT,IACA,KACL,CAACR,MAAM,CAACC,OAAA;EACX;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/blocks/client/plugin/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/blocks/client/plugin/index.tsx"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAC9D,OAAO,KAAK,EAAe,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC1F,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAa3D,MAAM,MAAM,kBAAkB,GAAG,qBAAqB,CAAA;AAEtD,eAAO,MAAM,YAAY,EAAE,eAAe,CAAC,wBAAwB,CA8JlE,CAAA"}
|
|
@@ -5,7 +5,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
5
5
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js';
|
|
6
6
|
import { $insertNodeToNearestRoot, $wrapNodeInElement, mergeRegister } from '@lexical/utils';
|
|
7
7
|
import { getTranslation } from '@payloadcms/translations';
|
|
8
|
-
import { formatDrawerSlug, useEditDepth,
|
|
8
|
+
import { formatDrawerSlug, useEditDepth, useTranslation } from '@payloadcms/ui';
|
|
9
9
|
import { $createParagraphNode, $getNodeByKey, $getPreviousSelection, $getSelection, $insertNodes, $isParagraphNode, $isRangeSelection, $isRootOrShadowRoot, COMMAND_PRIORITY_EDITOR } from 'lexical';
|
|
10
10
|
import React, { useEffect, useState } from 'react';
|
|
11
11
|
import { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js';
|
|
@@ -15,7 +15,7 @@ import { $createBlockNode, BlockNode } from '../nodes/BlocksNode.js';
|
|
|
15
15
|
import { $createInlineBlockNode, $isInlineBlockNode } from '../nodes/InlineBlocksNode.js';
|
|
16
16
|
import { INSERT_BLOCK_COMMAND, INSERT_INLINE_BLOCK_COMMAND, OPEN_INLINE_BLOCK_DRAWER_COMMAND } from './commands.js';
|
|
17
17
|
export const BlocksPlugin = () => {
|
|
18
|
-
const $ = _c(
|
|
18
|
+
const $ = _c(27);
|
|
19
19
|
const [editor] = useLexicalComposerContext();
|
|
20
20
|
const [blockFields, setBlockFields] = useState(null);
|
|
21
21
|
const [blockType, setBlockType] = useState("");
|
|
@@ -25,35 +25,33 @@ export const BlocksPlugin = () => {
|
|
|
25
25
|
t
|
|
26
26
|
} = useTranslation();
|
|
27
27
|
const {
|
|
28
|
+
fieldProps: t0
|
|
29
|
+
} = useEditorConfigContext();
|
|
30
|
+
const {
|
|
31
|
+
featureClientSchemaMap,
|
|
28
32
|
schemaPath
|
|
29
|
-
} =
|
|
33
|
+
} = t0;
|
|
30
34
|
const {
|
|
31
35
|
uuid
|
|
32
36
|
} = useEditorConfigContext();
|
|
33
37
|
const editDepth = useEditDepth();
|
|
34
|
-
const
|
|
35
|
-
let
|
|
36
|
-
if ($[0] !==
|
|
37
|
-
|
|
38
|
-
slug:
|
|
38
|
+
const t1 = `lexical-inlineBlocks-create-` + uuid;
|
|
39
|
+
let t2;
|
|
40
|
+
if ($[0] !== t1 || $[1] !== editDepth) {
|
|
41
|
+
t2 = formatDrawerSlug({
|
|
42
|
+
slug: t1,
|
|
39
43
|
depth: editDepth
|
|
40
44
|
});
|
|
41
|
-
$[0] =
|
|
45
|
+
$[0] = t1;
|
|
42
46
|
$[1] = editDepth;
|
|
43
|
-
$[2] =
|
|
47
|
+
$[2] = t2;
|
|
44
48
|
} else {
|
|
45
|
-
|
|
49
|
+
t2 = $[2];
|
|
46
50
|
}
|
|
47
|
-
const drawerSlug =
|
|
51
|
+
const drawerSlug = t2;
|
|
48
52
|
const {
|
|
49
53
|
toggleDrawer
|
|
50
|
-
} = useLexicalDrawer(drawerSlug);
|
|
51
|
-
const {
|
|
52
|
-
field: t2
|
|
53
|
-
} = useEditorConfigContext();
|
|
54
|
-
const {
|
|
55
|
-
richTextComponentMap
|
|
56
|
-
} = t2;
|
|
54
|
+
} = useLexicalDrawer(drawerSlug, true);
|
|
57
55
|
let t3;
|
|
58
56
|
let t4;
|
|
59
57
|
if ($[3] !== editor || $[4] !== targetNodeKey || $[5] !== toggleDrawer) {
|
|
@@ -133,65 +131,75 @@ export const BlocksPlugin = () => {
|
|
|
133
131
|
if (!blockFields) {
|
|
134
132
|
return null;
|
|
135
133
|
}
|
|
136
|
-
const schemaFieldsPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks
|
|
137
|
-
const
|
|
134
|
+
const schemaFieldsPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.${blockFields?.blockType}`;
|
|
135
|
+
const clientSchemaMap = featureClientSchemaMap.blocks;
|
|
136
|
+
const blocksField = clientSchemaMap[schemaFieldsPath][0];
|
|
137
|
+
const clientBlock = blocksField.blocks[0];
|
|
138
|
+
if (!blocksField) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
138
141
|
let t5;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
data.blockType = blockType;
|
|
157
|
-
editor.dispatchCommand(INSERT_INLINE_BLOCK_COMMAND, data);
|
|
158
|
-
};
|
|
159
|
-
$[18] = blockType;
|
|
160
|
-
$[19] = editor;
|
|
161
|
-
$[20] = t7;
|
|
162
|
-
} else {
|
|
163
|
-
t7 = $[20];
|
|
164
|
-
}
|
|
165
|
-
t5 = _jsx(FieldsDrawer, {
|
|
166
|
-
data: blockFields,
|
|
167
|
-
drawerSlug,
|
|
168
|
-
drawerTitle: t(`lexical:blocks:inlineBlocks:${blockFields?.id ? "edit" : "create"}`, {
|
|
169
|
-
label: blockDisplayName ?? t("lexical:blocks:inlineBlocks:label")
|
|
170
|
-
}),
|
|
171
|
-
featureKey: "blocks",
|
|
172
|
-
fieldMapOverride: clientBlock?.fields,
|
|
173
|
-
handleDrawerSubmit: t7,
|
|
174
|
-
schemaFieldsPathOverride: schemaFieldsPath,
|
|
175
|
-
schemaPathSuffix: blockFields?.blockType
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
$[8] = richTextComponentMap;
|
|
179
|
-
$[9] = blockFields;
|
|
180
|
-
$[10] = i18n;
|
|
181
|
-
$[11] = t;
|
|
182
|
-
$[12] = blockType;
|
|
183
|
-
$[13] = editor;
|
|
184
|
-
$[14] = drawerSlug;
|
|
185
|
-
$[15] = schemaFieldsPath;
|
|
186
|
-
$[16] = t5;
|
|
187
|
-
$[17] = t6;
|
|
142
|
+
if ($[8] !== clientBlock || $[9] !== i18n) {
|
|
143
|
+
t5 = clientBlock?.labels?.singular ? getTranslation(clientBlock?.labels?.singular, i18n) : clientBlock?.slug;
|
|
144
|
+
$[8] = clientBlock;
|
|
145
|
+
$[9] = i18n;
|
|
146
|
+
$[10] = t5;
|
|
147
|
+
} else {
|
|
148
|
+
t5 = $[10];
|
|
149
|
+
}
|
|
150
|
+
const blockDisplayName = t5;
|
|
151
|
+
const t6 = `lexical:blocks:inlineBlocks:${blockFields?.id ? "edit" : "create"}`;
|
|
152
|
+
let t7;
|
|
153
|
+
if ($[11] !== blockDisplayName || $[12] !== t) {
|
|
154
|
+
t7 = blockDisplayName ?? t("lexical:blocks:inlineBlocks:label");
|
|
155
|
+
$[11] = blockDisplayName;
|
|
156
|
+
$[12] = t;
|
|
157
|
+
$[13] = t7;
|
|
188
158
|
} else {
|
|
189
|
-
|
|
190
|
-
t6 = $[17];
|
|
159
|
+
t7 = $[13];
|
|
191
160
|
}
|
|
192
|
-
|
|
193
|
-
|
|
161
|
+
let t8;
|
|
162
|
+
if ($[14] !== t7 || $[15] !== t || $[16] !== t6 || $[17] !== clientBlock?.fields || $[18] !== blockType || $[19] !== editor || $[20] !== blockFields || $[21] !== drawerSlug || $[22] !== schemaPath) {
|
|
163
|
+
let t9;
|
|
164
|
+
if ($[24] !== blockType || $[25] !== editor) {
|
|
165
|
+
t9 = (_fields, data) => {
|
|
166
|
+
if (!data) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
data.blockType = blockType;
|
|
170
|
+
editor.dispatchCommand(INSERT_INLINE_BLOCK_COMMAND, data);
|
|
171
|
+
};
|
|
172
|
+
$[24] = blockType;
|
|
173
|
+
$[25] = editor;
|
|
174
|
+
$[26] = t9;
|
|
175
|
+
} else {
|
|
176
|
+
t9 = $[26];
|
|
177
|
+
}
|
|
178
|
+
t8 = _jsx(FieldsDrawer, {
|
|
179
|
+
data: blockFields,
|
|
180
|
+
drawerSlug,
|
|
181
|
+
drawerTitle: t(t6, {
|
|
182
|
+
label: t7
|
|
183
|
+
}),
|
|
184
|
+
featureKey: "blocks",
|
|
185
|
+
fieldMapOverride: clientBlock?.fields,
|
|
186
|
+
handleDrawerSubmit: t9,
|
|
187
|
+
schemaPath,
|
|
188
|
+
schemaPathSuffix: `lexical_inline_blocks.${blockFields?.blockType}.fields`
|
|
189
|
+
});
|
|
190
|
+
$[14] = t7;
|
|
191
|
+
$[15] = t;
|
|
192
|
+
$[16] = t6;
|
|
193
|
+
$[17] = clientBlock?.fields;
|
|
194
|
+
$[18] = blockType;
|
|
195
|
+
$[19] = editor;
|
|
196
|
+
$[20] = blockFields;
|
|
197
|
+
$[21] = drawerSlug;
|
|
198
|
+
$[22] = schemaPath;
|
|
199
|
+
$[23] = t8;
|
|
200
|
+
} else {
|
|
201
|
+
t8 = $[23];
|
|
194
202
|
}
|
|
195
|
-
return
|
|
203
|
+
return t8;
|
|
196
204
|
};
|
|
197
205
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","$insertNodeToNearestRoot","$wrapNodeInElement","mergeRegister","getTranslation","formatDrawerSlug","useEditDepth","useFieldProps","useTranslation","$createParagraphNode","$getNodeByKey","$getPreviousSelection","$getSelection","$insertNodes","$isParagraphNode","$isRangeSelection","$isRootOrShadowRoot","COMMAND_PRIORITY_EDITOR","React","useEffect","useState","useEditorConfigContext","FieldsDrawer","useLexicalDrawer","$createBlockNode","BlockNode","$createInlineBlockNode","$isInlineBlockNode","INSERT_BLOCK_COMMAND","INSERT_INLINE_BLOCK_COMMAND","OPEN_INLINE_BLOCK_DRAWER_COMMAND","BlocksPlugin","$","editor","blockFields","setBlockFields","blockType","setBlockType","targetNodeKey","setTargetNodeKey","i18n","t","schemaPath","uuid","editDepth","t0","t1","slug","depth","drawerSlug","toggleDrawer","field","t2","richTextComponentMap","t3","t4","hasNodes","Error","registerCommand","payload","update","selection","blockNode","focus","focusNode","getNode","getTextContentSize","getParentOrThrow","getChildren","filter","node","length","remove","fields","node_0","setFields","inlineBlockNode","selectEnd","t5","fields_0","nodeKey","rangeSelection","getEditorState","read","selection_0","schemaFieldsPath","componentMapRenderedBlockPath","t6","Symbol","for","bb0","blocksField","has","get","clientBlock","blocks","find","block","blockDisplayName","labels","singular","t7","_fields","data","dispatchCommand","_jsx","drawerTitle","id","label","featureKey","fieldMapOverride","handleDrawerSubmit","schemaFieldsPathOverride","schemaPathSuffix"],"sources":["../../../../../src/features/blocks/client/plugin/index.tsx"],"sourcesContent":["'use client'\n\nimport type { BlocksFieldClient } from 'payload'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { $insertNodeToNearestRoot, $wrapNodeInElement, mergeRegister } from '@lexical/utils'\nimport { getTranslation } from '@payloadcms/translations'\nimport {\n formatDrawerSlug,\n useEditDepth,\n useFieldProps,\n useModal,\n useTranslation,\n} from '@payloadcms/ui'\nimport {\n $createParagraphNode,\n $getNodeByKey,\n $getPreviousSelection,\n $getSelection,\n $insertNodes,\n $isParagraphNode,\n $isRangeSelection,\n $isRootOrShadowRoot,\n COMMAND_PRIORITY_EDITOR,\n type RangeSelection,\n} from 'lexical'\nimport React, { useEffect, useState } from 'react'\n\nimport type { PluginComponent } from '../../../typesClient.js'\nimport type { BlockFields, BlockFieldsOptionalID } from '../../server/nodes/BlocksNode.js'\nimport type { BlocksFeatureClientProps } from '../index.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport { FieldsDrawer } from '../../../../utilities/fieldsDrawer/Drawer.js'\nimport { useLexicalDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDrawer.js'\nimport { $createBlockNode, BlockNode } from '../nodes/BlocksNode.js'\nimport { $createInlineBlockNode, $isInlineBlockNode } from '../nodes/InlineBlocksNode.js'\nimport {\n INSERT_BLOCK_COMMAND,\n INSERT_INLINE_BLOCK_COMMAND,\n OPEN_INLINE_BLOCK_DRAWER_COMMAND,\n} from './commands.js'\n\nexport type InsertBlockPayload = BlockFieldsOptionalID\n\nexport const BlocksPlugin: PluginComponent<BlocksFeatureClientProps> = () => {\n const [editor] = useLexicalComposerContext()\n const [blockFields, setBlockFields] = useState<BlockFields | null>(null)\n const [blockType, setBlockType] = useState<string>('' as any)\n const [targetNodeKey, setTargetNodeKey] = useState<null | string>(null)\n const { i18n, t } = useTranslation<string, any>()\n const { schemaPath } = useFieldProps()\n const { uuid } = useEditorConfigContext()\n const editDepth = useEditDepth()\n\n const drawerSlug = formatDrawerSlug({\n slug: `lexical-inlineBlocks-create-` + uuid,\n depth: editDepth,\n })\n\n const { toggleDrawer } = useLexicalDrawer(drawerSlug)\n\n const {\n field: { richTextComponentMap },\n } = useEditorConfigContext()\n\n useEffect(() => {\n if (!editor.hasNodes([BlockNode])) {\n throw new Error('BlocksPlugin: BlocksNode not registered on editor')\n }\n\n return mergeRegister(\n editor.registerCommand<InsertBlockPayload>(\n INSERT_BLOCK_COMMAND,\n (payload: InsertBlockPayload) => {\n editor.update(() => {\n const selection = $getSelection() || $getPreviousSelection()\n\n if ($isRangeSelection(selection)) {\n const blockNode = $createBlockNode(payload)\n // Insert blocks node BEFORE potentially removing focusNode, as $insertNodeToNearestRoot errors if the focusNode doesn't exist\n $insertNodeToNearestRoot(blockNode)\n\n const { focus } = selection\n const focusNode = focus.getNode()\n\n // First, delete currently selected node if it's an empty paragraph and if there are sufficient\n // paragraph nodes (more than 1) left in the parent node, so that we don't \"trap\" the user\n if (\n $isParagraphNode(focusNode) &&\n focusNode.getTextContentSize() === 0 &&\n focusNode\n .getParentOrThrow()\n .getChildren()\n .filter((node) => $isParagraphNode(node)).length > 1\n ) {\n focusNode.remove()\n }\n }\n })\n\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n editor.registerCommand(\n INSERT_INLINE_BLOCK_COMMAND,\n (fields) => {\n if (targetNodeKey) {\n const node = $getNodeByKey(targetNodeKey)\n\n if (!node || !$isInlineBlockNode(node)) {\n return false\n }\n\n node.setFields(fields as BlockFields)\n\n setTargetNodeKey(null)\n return true\n }\n\n const inlineBlockNode = $createInlineBlockNode(fields as BlockFields)\n $insertNodes([inlineBlockNode])\n if ($isRootOrShadowRoot(inlineBlockNode.getParentOrThrow())) {\n $wrapNodeInElement(inlineBlockNode, $createParagraphNode).selectEnd()\n }\n\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n editor.registerCommand(\n OPEN_INLINE_BLOCK_DRAWER_COMMAND,\n ({ fields, nodeKey }) => {\n setBlockFields((fields as BlockFields) ?? null)\n setTargetNodeKey(nodeKey ?? null)\n setBlockType(fields?.blockType ?? ('' as any))\n\n if (nodeKey) {\n toggleDrawer()\n return true\n }\n\n let rangeSelection: null | RangeSelection = null\n\n editor.getEditorState().read(() => {\n const selection = $getSelection()\n if ($isRangeSelection(selection)) {\n rangeSelection = selection\n }\n })\n\n if (rangeSelection) {\n //setLastSelection(rangeSelection)\n toggleDrawer()\n }\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n )\n }, [editor, targetNodeKey, toggleDrawer])\n\n if (!blockFields) {\n return null\n }\n\n const schemaFieldsPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.lexical_inline_blocks.${blockFields?.blockType}`\n\n const componentMapRenderedBlockPath = `lexical_internal_feature.blocks.fields.lexical_inline_blocks`\n const blocksField: BlocksFieldClient = richTextComponentMap?.has(componentMapRenderedBlockPath)\n ? richTextComponentMap.get(componentMapRenderedBlockPath)[0]\n : null\n\n const clientBlock = blocksField\n ? blocksField.blocks.find((block) => block.slug === blockFields?.blockType)\n : null\n\n if (!blocksField) {\n return null\n }\n\n const blockDisplayName = clientBlock?.labels?.singular\n ? getTranslation(clientBlock?.labels?.singular, i18n)\n : clientBlock?.slug\n\n return (\n <FieldsDrawer\n data={blockFields}\n drawerSlug={drawerSlug}\n drawerTitle={t(`lexical:blocks:inlineBlocks:${blockFields?.id ? 'edit' : 'create'}`, {\n label: blockDisplayName ?? t('lexical:blocks:inlineBlocks:label'),\n })}\n featureKey=\"blocks\"\n fieldMapOverride={clientBlock?.fields}\n handleDrawerSubmit={(_fields, data) => {\n if (!data) {\n return\n }\n\n data.blockType = blockType\n\n editor.dispatchCommand(INSERT_INLINE_BLOCK_COMMAND, data)\n }}\n schemaFieldsPathOverride={schemaFieldsPath}\n schemaPathSuffix={blockFields?.blockType}\n />\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAIA,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,wBAAwB,EAAEC,kBAAkB,EAAEC,aAAa,QAAQ;AAC5E,SAASC,cAAc,QAAQ;AAC/B,SACEC,gBAAgB,EAChBC,YAAY,EACZC,aAAa,EAEbC,cAAc,QACT;AACP,SACEC,oBAAoB,EACpBC,aAAa,EACbC,qBAAqB,EACrBC,aAAa,EACbC,YAAY,E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A;QAAAA,EAAA,GAAArE,CAAA;MAAA;MAhBF8C,EAAA,GAAA2B,IAAA,CAAAnF,YAAA;QAAAiF,IAAA,EACQrE,WAAA;QAAAe,UAAA;QAAAyD,WAAA,EAEOjE,CAAA,CAAE,+BAA+BP,WAAA,EAAAyE,EAAA,GAAkB,SAAS,UAAU;UAAAC,KAAA,EAC1EV,gBAAA,IAAoBzD,CAAA,CAAE;QAAA,CAC/B;QAAAoE,UAAA,EACW;QAAAC,gBAAA,EACOhB,WAAA,EAAArB,MAAA;QAAAsC,kBAAA,EACEV,EAQpB;QAAAW,wBAAA,EAC0B3B,gBAAA;QAAA4B,gBAAA,EACR/E,WAAA,EAAAE;MAAA,C;;;;;;;;;;;;;;;;;;;SAlBpB0C,E;CAqBJ","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","useLexicalComposerContext","$insertNodeToNearestRoot","$wrapNodeInElement","mergeRegister","getTranslation","formatDrawerSlug","useEditDepth","useTranslation","$createParagraphNode","$getNodeByKey","$getPreviousSelection","$getSelection","$insertNodes","$isParagraphNode","$isRangeSelection","$isRootOrShadowRoot","COMMAND_PRIORITY_EDITOR","React","useEffect","useState","useEditorConfigContext","FieldsDrawer","useLexicalDrawer","$createBlockNode","BlockNode","$createInlineBlockNode","$isInlineBlockNode","INSERT_BLOCK_COMMAND","INSERT_INLINE_BLOCK_COMMAND","OPEN_INLINE_BLOCK_DRAWER_COMMAND","BlocksPlugin","$","editor","blockFields","setBlockFields","blockType","setBlockType","targetNodeKey","setTargetNodeKey","i18n","t","fieldProps","t0","featureClientSchemaMap","schemaPath","uuid","editDepth","t1","t2","slug","depth","drawerSlug","toggleDrawer","t3","t4","hasNodes","Error","registerCommand","payload","update","selection","blockNode","focus","focusNode","getNode","getTextContentSize","getParentOrThrow","getChildren","filter","node","length","remove","fields","node_0","setFields","inlineBlockNode","selectEnd","t5","fields_0","nodeKey","rangeSelection","getEditorState","read","selection_0","schemaFieldsPath","clientSchemaMap","blocks","blocksField","clientBlock","labels","singular","blockDisplayName","t6","id","t7","t8","t9","_fields","data","dispatchCommand","_jsx","drawerTitle","label","featureKey","fieldMapOverride","handleDrawerSubmit","schemaPathSuffix"],"sources":["../../../../../src/features/blocks/client/plugin/index.tsx"],"sourcesContent":["'use client'\n\nimport type { BlocksFieldClient } from 'payload'\n\nimport { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext.js'\nimport { $insertNodeToNearestRoot, $wrapNodeInElement, mergeRegister } from '@lexical/utils'\nimport { getTranslation } from '@payloadcms/translations'\nimport { formatDrawerSlug, useEditDepth, useTranslation } from '@payloadcms/ui'\nimport {\n $createParagraphNode,\n $getNodeByKey,\n $getPreviousSelection,\n $getSelection,\n $insertNodes,\n $isParagraphNode,\n $isRangeSelection,\n $isRootOrShadowRoot,\n COMMAND_PRIORITY_EDITOR,\n type RangeSelection,\n} from 'lexical'\nimport React, { useEffect, useState } from 'react'\n\nimport type { PluginComponent } from '../../../typesClient.js'\nimport type { BlockFields, BlockFieldsOptionalID } from '../../server/nodes/BlocksNode.js'\nimport type { BlocksFeatureClientProps } from '../index.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport { FieldsDrawer } from '../../../../utilities/fieldsDrawer/Drawer.js'\nimport { useLexicalDrawer } from '../../../../utilities/fieldsDrawer/useLexicalDrawer.js'\nimport { $createBlockNode, BlockNode } from '../nodes/BlocksNode.js'\nimport { $createInlineBlockNode, $isInlineBlockNode } from '../nodes/InlineBlocksNode.js'\nimport {\n INSERT_BLOCK_COMMAND,\n INSERT_INLINE_BLOCK_COMMAND,\n OPEN_INLINE_BLOCK_DRAWER_COMMAND,\n} from './commands.js'\n\nexport type InsertBlockPayload = BlockFieldsOptionalID\n\nexport const BlocksPlugin: PluginComponent<BlocksFeatureClientProps> = () => {\n const [editor] = useLexicalComposerContext()\n const [blockFields, setBlockFields] = useState<BlockFields | null>(null)\n const [blockType, setBlockType] = useState<string>('' as any)\n const [targetNodeKey, setTargetNodeKey] = useState<null | string>(null)\n const { i18n, t } = useTranslation<string, any>()\n const {\n fieldProps: { featureClientSchemaMap, schemaPath },\n } = useEditorConfigContext()\n const { uuid } = useEditorConfigContext()\n const editDepth = useEditDepth()\n\n const drawerSlug = formatDrawerSlug({\n slug: `lexical-inlineBlocks-create-` + uuid,\n depth: editDepth,\n })\n\n const { toggleDrawer } = useLexicalDrawer(drawerSlug, true)\n\n useEffect(() => {\n if (!editor.hasNodes([BlockNode])) {\n throw new Error('BlocksPlugin: BlocksNode not registered on editor')\n }\n\n return mergeRegister(\n editor.registerCommand<InsertBlockPayload>(\n INSERT_BLOCK_COMMAND,\n (payload: InsertBlockPayload) => {\n editor.update(() => {\n const selection = $getSelection() || $getPreviousSelection()\n\n if ($isRangeSelection(selection)) {\n const blockNode = $createBlockNode(payload)\n // Insert blocks node BEFORE potentially removing focusNode, as $insertNodeToNearestRoot errors if the focusNode doesn't exist\n $insertNodeToNearestRoot(blockNode)\n\n const { focus } = selection\n const focusNode = focus.getNode()\n\n // First, delete currently selected node if it's an empty paragraph and if there are sufficient\n // paragraph nodes (more than 1) left in the parent node, so that we don't \"trap\" the user\n if (\n $isParagraphNode(focusNode) &&\n focusNode.getTextContentSize() === 0 &&\n focusNode\n .getParentOrThrow()\n .getChildren()\n .filter((node) => $isParagraphNode(node)).length > 1\n ) {\n focusNode.remove()\n }\n }\n })\n\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n editor.registerCommand(\n INSERT_INLINE_BLOCK_COMMAND,\n (fields) => {\n if (targetNodeKey) {\n const node = $getNodeByKey(targetNodeKey)\n\n if (!node || !$isInlineBlockNode(node)) {\n return false\n }\n\n node.setFields(fields as BlockFields)\n\n setTargetNodeKey(null)\n return true\n }\n\n const inlineBlockNode = $createInlineBlockNode(fields as BlockFields)\n $insertNodes([inlineBlockNode])\n if ($isRootOrShadowRoot(inlineBlockNode.getParentOrThrow())) {\n $wrapNodeInElement(inlineBlockNode, $createParagraphNode).selectEnd()\n }\n\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n editor.registerCommand(\n OPEN_INLINE_BLOCK_DRAWER_COMMAND,\n ({ fields, nodeKey }) => {\n setBlockFields((fields as BlockFields) ?? null)\n setTargetNodeKey(nodeKey ?? null)\n setBlockType(fields?.blockType ?? ('' as any))\n\n if (nodeKey) {\n toggleDrawer()\n return true\n }\n\n let rangeSelection: null | RangeSelection = null\n\n editor.getEditorState().read(() => {\n const selection = $getSelection()\n if ($isRangeSelection(selection)) {\n rangeSelection = selection\n }\n })\n\n if (rangeSelection) {\n //setLastSelection(rangeSelection)\n toggleDrawer()\n }\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n ),\n )\n }, [editor, targetNodeKey, toggleDrawer])\n\n if (!blockFields) {\n return null\n }\n\n const schemaFieldsPath = `${schemaPath}.lexical_internal_feature.blocks.lexical_inline_blocks.${blockFields?.blockType}`\n\n const clientSchemaMap = featureClientSchemaMap['blocks']\n\n const blocksField: BlocksFieldClient = clientSchemaMap[schemaFieldsPath][0] as BlocksFieldClient\n\n const clientBlock = blocksField.blocks[0]\n\n if (!blocksField) {\n return null\n }\n\n const blockDisplayName = clientBlock?.labels?.singular\n ? getTranslation(clientBlock?.labels?.singular, i18n)\n : clientBlock?.slug\n\n return (\n <FieldsDrawer\n data={blockFields}\n drawerSlug={drawerSlug}\n drawerTitle={t(`lexical:blocks:inlineBlocks:${blockFields?.id ? 'edit' : 'create'}`, {\n label: blockDisplayName ?? t('lexical:blocks:inlineBlocks:label'),\n })}\n featureKey=\"blocks\"\n fieldMapOverride={clientBlock?.fields}\n handleDrawerSubmit={(_fields, data) => {\n if (!data) {\n return\n }\n\n data.blockType = blockType\n\n editor.dispatchCommand(INSERT_INLINE_BLOCK_COMMAND, data)\n }}\n schemaPath={schemaPath}\n schemaPathSuffix={`lexical_inline_blocks.${blockFields?.blockType}.fields`}\n />\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;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AS,CAAA,IAAAT,CAAA,SAAA6D,EAAA,IAAA7D,CAAA,SAAAyD,WAAA,EAAAhB,MAAA,IAAAzC,CAAA,SAAAI,SAAA,IAAAJ,CAAA,SAAAC,MAAA,IAAAD,CAAA,SAAAE,WAAA,IAAAF,CAAA,SAAAoB,UAAA,IAAApB,CAAA,SAAAa,UAAA;IAAA,IAAAoD,EAAA;IAAA,IAAAjE,CAAA,SAAAI,SAAA,IAAAJ,CAAA,SAAAC,MAAA;MAIXgE,EAAA,GAAAA,CAAAC,OAAA,EAAAC,IAAA;QAAA,KACbA,IAAA;UAAA;QAAA;QAILA,IAAA,CAAA/D,SAAA,GAAiBA,SAAA;QAEjBH,MAAA,CAAAmE,eAAA,CAAAvE,2BAAA,EAAoDsE,IAAA;MAAA;MACtDnE,CAAA,OAAAI,SAAA;MAAAJ,CAAA,OAAAC,MAAA;MAAAD,CAAA,OAAAiE,EAAA;IAAA;MAAAA,EAAA,GAAAjE,CAAA;IAAA;IAhBFgE,EAAA,GAAAK,IAAA,CAAA/E,YAAA;MAAA6E,IAAA,EACQjE,WAAA;MAAAkB,UAAA;MAAAkD,WAAA,EAEO7D,CAAA,CAAEoD,EAAoE;QAAAU,KAAA,EAC1ER;MAAsB,CAC/B;MAAAS,UAAA,EACW;MAAAC,gBAAA,EACOhB,WAAA,EAAAhB,MAAA;MAAAiC,kBAAA,EACET,EAQpB;MAAApD,UAAA;MAAA8D,gBAAA,EAEkB,yBAAyBzE,WAAA,EAAAE,SAAA;IAA+B,C;;;;;;;;;;;;;;SAlB5E4D,E;CAqBJ","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/features/blocks/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/features/blocks/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAA8C,MAAM,SAAS,CAAA;AAIhF,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AAUlE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,CAAC,EAAE,KAAK,EAAE,CAAA;IAChB,YAAY,CAAC,EAAE,KAAK,EAAE,CAAA;CACvB,CAAA;AAED,eAAO,MAAM,aAAa,gIAmLxB,CAAA"}
|
|
@@ -84,19 +84,29 @@ export const BlocksFeature = createServerFeature({
|
|
|
84
84
|
*/
|
|
85
85
|
const schemaMap = new Map();
|
|
86
86
|
if (props?.blocks?.length) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
for (const block of props.blocks) {
|
|
88
|
+
schemaMap.set(`lexical_blocks.${block.slug}.fields`, {
|
|
89
|
+
fields: block.fields
|
|
90
|
+
});
|
|
91
|
+
schemaMap.set(`lexical_blocks.${block.slug}`, {
|
|
92
|
+
name: `lexical_blocks_${block.slug}`,
|
|
93
|
+
type: 'blocks',
|
|
94
|
+
blocks: [block]
|
|
95
|
+
});
|
|
96
|
+
}
|
|
92
97
|
}
|
|
93
98
|
if (props?.inlineBlocks?.length) {
|
|
94
99
|
// To generate block schemaMap which generates things like the componentMap for admin.Label
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
+
for (const block of props.inlineBlocks) {
|
|
101
|
+
schemaMap.set(`lexical_inline_blocks.${block.slug}.fields`, {
|
|
102
|
+
fields: block.fields
|
|
103
|
+
});
|
|
104
|
+
schemaMap.set(`lexical_inline_blocks.${block.slug}`, {
|
|
105
|
+
name: `lexical_inline_blocks_${block.slug}`,
|
|
106
|
+
type: 'blocks',
|
|
107
|
+
blocks: [block]
|
|
108
|
+
});
|
|
109
|
+
}
|
|
100
110
|
}
|
|
101
111
|
return schemaMap;
|
|
102
112
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["fieldsToJSONSchema","sanitizeFields","createServerFeature","createNode","blockPopulationPromiseHOC","i18n","ServerBlockNode","ServerInlineBlockNode","blockValidationHOC","BlocksFeature","feature","config","_config","isRoot","parentIsLocalized","props","clientProps","clientBlockSlugs","clientInlineBlockSlugs","validRelationships","collections","map","c","slug","sanitized","fields","name","type","blocks","inlineBlocks","requireFieldLevelRichTextEditor","block","ClientFeature","clientFeatureProps","generatedTypes","modifyOutputSchema","collectionIDFieldTypes","currentSchema","field","interfaceNameDefinitions","length","push","generateSchemaMap","schemaMap","Map","set","nodes","getSubFields","node","blockType","find","getSubFieldsData","graphQLPopulationPromises","validations","sanitizedServerFeatureProps","key"],"sources":["../../../../src/features/blocks/server/index.ts"],"sourcesContent":["import type { Block, BlocksField, Config, Field } from 'payload'\n\nimport { fieldsToJSONSchema, sanitizeFields } from 'payload'\n\nimport type { BlocksFeatureClientProps } from '../client/index.js'\n\nimport { createServerFeature } from '../../../utilities/createServerFeature.js'\nimport { createNode } from '../../typeUtilities.js'\nimport { blockPopulationPromiseHOC } from './graphQLPopulationPromise.js'\nimport { i18n } from './i18n.js'\nimport { ServerBlockNode } from './nodes/BlocksNode.js'\nimport { ServerInlineBlockNode } from './nodes/InlineBlocksNode.js'\nimport { blockValidationHOC } from './validate.js'\n\nexport type BlocksFeatureProps = {\n blocks?: Block[]\n inlineBlocks?: Block[]\n}\n\nexport const BlocksFeature = createServerFeature<\n BlocksFeatureProps,\n BlocksFeatureProps,\n BlocksFeatureClientProps\n>({\n feature: async ({ config: _config, isRoot, parentIsLocalized, props }) => {\n // Build clientProps\n const clientProps: BlocksFeatureClientProps = {\n clientBlockSlugs: [],\n clientInlineBlockSlugs: [],\n }\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 props.blocks = (sanitized[0] as BlocksField).blocks\n props.inlineBlocks = (sanitized[1] as BlocksField).blocks\n\n clientProps.clientBlockSlugs = props.blocks.map((block) => block.slug)\n clientProps.clientInlineBlockSlugs = props.inlineBlocks.map((block) => block.slug)\n\n return {\n ClientFeature: '@payloadcms/richtext-lexical/client#BlocksFeatureClient',\n clientFeatureProps: clientProps,\n generatedTypes: {\n modifyOutputSchema: ({\n collectionIDFieldTypes,\n config,\n currentSchema,\n field,\n interfaceNameDefinitions,\n }) => {\n if (!props?.blocks?.length && !props?.inlineBlocks?.length) {\n return currentSchema\n }\n\n const fields: BlocksField[] = []\n\n if (props?.blocks?.length) {\n fields.push({\n name: field?.name + '_lexical_blocks',\n type: 'blocks',\n blocks: props.blocks,\n })\n }\n if (props?.inlineBlocks?.length) {\n fields.push({\n name: field?.name + '_lexical_inline_blocks',\n type: 'blocks',\n blocks: props.inlineBlocks,\n })\n }\n\n if (fields.length) {\n // This is only done so that interfaceNameDefinitions sets those block's interfaceNames.\n // we don't actually use the JSON Schema itself in the generated types yet.\n fieldsToJSONSchema(collectionIDFieldTypes, fields, interfaceNameDefinitions, config)\n }\n\n return currentSchema\n },\n },\n generateSchemaMap: ({ props }) => {\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 = new Map<string, Field[]>()\n\n if (props?.blocks?.length) {\n schemaMap.set('lexical_blocks', [\n {\n name: 'lexical_blocks',\n type: 'blocks',\n blocks: props.blocks,\n },\n ])\n }\n\n if (props?.inlineBlocks?.length) {\n // To generate block schemaMap which generates things like the componentMap for admin.Label\n schemaMap.set('lexical_inline_blocks', [\n {\n name: 'lexical_inline_blocks',\n type: 'blocks',\n blocks: props.inlineBlocks,\n },\n ])\n }\n\n return schemaMap\n },\n i18n,\n nodes: [\n createNode({\n // @ts-expect-error - TODO: fix this\n getSubFields: ({ node }) => {\n if (!node) {\n if (props?.blocks?.length) {\n return [\n {\n name: 'lexical_blocks',\n type: 'blocks',\n blocks: props.blocks,\n },\n ]\n }\n return []\n }\n\n const blockType = node.fields.blockType\n\n const block = props.blocks?.find((block) => block.slug === blockType)\n return block?.fields\n },\n getSubFieldsData: ({ node }) => {\n return node?.fields\n },\n graphQLPopulationPromises: [blockPopulationPromiseHOC(props.blocks)],\n node: ServerBlockNode,\n validations: [blockValidationHOC(props.blocks)],\n }),\n createNode({\n // @ts-expect-error - TODO: fix this\n getSubFields: ({ node }) => {\n if (!node) {\n if (props?.inlineBlocks?.length) {\n return [\n {\n name: 'lexical_inline_blocks',\n type: 'blocks',\n blocks: props.inlineBlocks,\n },\n ]\n }\n return []\n }\n\n const blockType = node.fields.blockType\n\n const block = props.inlineBlocks?.find((block) => block.slug === blockType)\n return block?.fields\n },\n getSubFieldsData: ({ node }) => {\n return node?.fields\n },\n graphQLPopulationPromises: [blockPopulationPromiseHOC(props.inlineBlocks)],\n node: ServerInlineBlockNode,\n validations: [blockValidationHOC(props.inlineBlocks)],\n }),\n ],\n sanitizedServerFeatureProps: props,\n }\n },\n key: 'blocks',\n})\n"],"mappings":"AAEA,SAASA,kBAAkB,EAAEC,cAAc,QAAQ;AAInD,SAASC,mBAAmB,QAAQ;AACpC,SAASC,UAAU,QAAQ;AAC3B,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,IAAI,QAAQ;AACrB,SAASC,eAAe,QAAQ;AAChC,SAASC,qBAAqB,QAAQ;AACtC,SAASC,kBAAkB,QAAQ;AAOnC,OAAO,MAAMC,aAAA,GAAgBP,mBAAA,CAI3B;EACAQ,OAAA,EAAS,MAAAA,CAAO;IAAEC,MAAA,EAAQC,OAAO;IAAEC,MAAM;IAAEC,iBAAiB;IAAEC;EAAK,CAAE;IACnE;IACA,MAAMC,WAAA,GAAwC;MAC5CC,gBAAA,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mB,IAAA,EAAMzC,qBAAA;QACN8C,WAAA,EAAa,CAAC7C,kBAAA,CAAmBO,KAAA,CAAMc,YAAY;MACrD,GACD;MACDyB,2BAAA,EAA6BvC;IAC/B;EACF;EACAwC,GAAA,EAAK;AACP","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["fieldsToJSONSchema","sanitizeFields","createServerFeature","createNode","blockPopulationPromiseHOC","i18n","ServerBlockNode","ServerInlineBlockNode","blockValidationHOC","BlocksFeature","feature","config","_config","isRoot","parentIsLocalized","props","clientProps","clientBlockSlugs","clientInlineBlockSlugs","validRelationships","collections","map","c","slug","sanitized","fields","name","type","blocks","inlineBlocks","requireFieldLevelRichTextEditor","block","ClientFeature","clientFeatureProps","generatedTypes","modifyOutputSchema","collectionIDFieldTypes","currentSchema","field","interfaceNameDefinitions","length","push","generateSchemaMap","schemaMap","Map","set","nodes","getSubFields","node","blockType","find","getSubFieldsData","graphQLPopulationPromises","validations","sanitizedServerFeatureProps","key"],"sources":["../../../../src/features/blocks/server/index.ts"],"sourcesContent":["import type { Block, BlocksField, Config, Field, FieldSchemaMap } from 'payload'\n\nimport { fieldsToJSONSchema, sanitizeFields } from 'payload'\n\nimport type { BlocksFeatureClientProps } from '../client/index.js'\n\nimport { createServerFeature } from '../../../utilities/createServerFeature.js'\nimport { createNode } from '../../typeUtilities.js'\nimport { blockPopulationPromiseHOC } from './graphQLPopulationPromise.js'\nimport { i18n } from './i18n.js'\nimport { ServerBlockNode } from './nodes/BlocksNode.js'\nimport { ServerInlineBlockNode } from './nodes/InlineBlocksNode.js'\nimport { blockValidationHOC } from './validate.js'\n\nexport type BlocksFeatureProps = {\n blocks?: Block[]\n inlineBlocks?: Block[]\n}\n\nexport const BlocksFeature = createServerFeature<\n BlocksFeatureProps,\n BlocksFeatureProps,\n BlocksFeatureClientProps\n>({\n feature: async ({ config: _config, isRoot, parentIsLocalized, props }) => {\n // Build clientProps\n const clientProps: BlocksFeatureClientProps = {\n clientBlockSlugs: [],\n clientInlineBlockSlugs: [],\n }\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 props.blocks = (sanitized[0] as BlocksField).blocks\n props.inlineBlocks = (sanitized[1] as BlocksField).blocks\n\n clientProps.clientBlockSlugs = props.blocks.map((block) => block.slug)\n clientProps.clientInlineBlockSlugs = props.inlineBlocks.map((block) => block.slug)\n\n return {\n ClientFeature: '@payloadcms/richtext-lexical/client#BlocksFeatureClient',\n clientFeatureProps: clientProps,\n generatedTypes: {\n modifyOutputSchema: ({\n collectionIDFieldTypes,\n config,\n currentSchema,\n field,\n interfaceNameDefinitions,\n }) => {\n if (!props?.blocks?.length && !props?.inlineBlocks?.length) {\n return currentSchema\n }\n\n const fields: BlocksField[] = []\n\n if (props?.blocks?.length) {\n fields.push({\n name: field?.name + '_lexical_blocks',\n type: 'blocks',\n blocks: props.blocks,\n })\n }\n if (props?.inlineBlocks?.length) {\n fields.push({\n name: field?.name + '_lexical_inline_blocks',\n type: 'blocks',\n blocks: props.inlineBlocks,\n })\n }\n\n if (fields.length) {\n // This is only done so that interfaceNameDefinitions sets those block's interfaceNames.\n // we don't actually use the JSON Schema itself in the generated types yet.\n fieldsToJSONSchema(collectionIDFieldTypes, fields, interfaceNameDefinitions, config)\n }\n\n return currentSchema\n },\n },\n generateSchemaMap: ({ props }) => {\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 (props?.blocks?.length) {\n for (const block of props.blocks) {\n schemaMap.set(`lexical_blocks.${block.slug}.fields`, {\n fields: block.fields,\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 (props?.inlineBlocks?.length) {\n // To generate block schemaMap which generates things like the componentMap for admin.Label\n for (const block of props.inlineBlocks) {\n schemaMap.set(`lexical_inline_blocks.${block.slug}.fields`, {\n fields: block.fields,\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 nodes: [\n createNode({\n // @ts-expect-error - TODO: fix this\n getSubFields: ({ node }) => {\n if (!node) {\n if (props?.blocks?.length) {\n return [\n {\n name: 'lexical_blocks',\n type: 'blocks',\n blocks: props.blocks,\n },\n ]\n }\n return []\n }\n\n const blockType = node.fields.blockType\n\n const block = props.blocks?.find((block) => block.slug === blockType)\n return block?.fields\n },\n getSubFieldsData: ({ node }) => {\n return node?.fields\n },\n graphQLPopulationPromises: [blockPopulationPromiseHOC(props.blocks)],\n node: ServerBlockNode,\n validations: [blockValidationHOC(props.blocks)],\n }),\n createNode({\n // @ts-expect-error - TODO: fix this\n getSubFields: ({ node }) => {\n if (!node) {\n if (props?.inlineBlocks?.length) {\n return [\n {\n name: 'lexical_inline_blocks',\n type: 'blocks',\n blocks: props.inlineBlocks,\n },\n ]\n }\n return []\n }\n\n const blockType = node.fields.blockType\n\n const block = props.inlineBlocks?.find((block) => block.slug === blockType)\n return block?.fields\n },\n getSubFieldsData: ({ node }) => {\n return node?.fields\n },\n graphQLPopulationPromises: [blockPopulationPromiseHOC(props.inlineBlocks)],\n node: ServerInlineBlockNode,\n validations: [blockValidationHOC(props.inlineBlocks)],\n }),\n ],\n sanitizedServerFeatureProps: props,\n }\n },\n key: 'blocks',\n})\n"],"mappings":"AAEA,SAASA,kBAAkB,EAAEC,cAAc,QAAQ;AAInD,SAASC,mBAAmB,QAA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;QACf;QACA2B,yBAAA,EAA2B,CAAChD,yBAAA,CAA0BW,KAAA,CAAMa,MAAM,EAAE;QACpEoB,IAAA,EAAM1C,eAAA;QACN+C,WAAA,EAAa,CAAC7C,kBAAA,CAAmBO,KAAA,CAAMa,MAAM;MAC/C,IACAzB,UAAA,CAAW;QACT;QACA4C,YAAA,EAAcA,CAAC;UAAEC;QAAI,CAAE;UACrB,IAAI,CAACA,IAAA,EAAM;YACT,IAAIjC,KAAA,EAAOc,YAAA,EAAcW,MAAA,EAAQ;cAC/B,OAAO,CACL;gBACEd,IAAA,EAAM;gBACNC,IAAA,EAAM;gBACNC,MAAA,EAAQb,KAAA,CAAMc;cAChB,EACD;YACH;YACA,OAAO,EAAE;UACX;UAEA,MAAMoB,SAAA,GAAYD,IAAA,CAAKvB,MAAM,CAACwB,SAAS;UAEvC,MAAMlB,KAAA,GAAQhB,KAAA,CAAMc,YAAY,EAAEqB,IAAA,CAAMnB,KAAA,IAAUA,KAAA,CAAMR,IAAI,KAAK0B,SAAA;UACjE,OAAOlB,KAAA,EAAON,MAAA;QAChB;QACA0B,gBAAA,EAAkBA,CAAC;UAAEH;QAAI,CAAE;UACzB,OAAOA,IAAA,EAAMvB,MAAA;QACf;QACA2B,yBAAA,EAA2B,CAAChD,yBAAA,CAA0BW,KAAA,CAAMc,YAAY,EAAE;QAC1EmB,IAAA,EAAMzC,qBAAA;QACN8C,WAAA,EAAa,CAAC7C,kBAAA,CAAmBO,KAAA,CAAMc,YAAY;MACrD,GACD;MACDyB,2BAAA,EAA6BvC;IAC/B;EACF;EACAwC,GAAA,EAAK;AACP","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../../src/features/blocks/server/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAIpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAA;AACpF,OAAO,KAAK,EAAe,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAE7E,eAAO,MAAM,kBAAkB,WACrB,KAAK,EAAE,KACd,cAAc,CAAC,mBAAmB,GAAG,yBAAyB,
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../../src/features/blocks/server/validate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAIpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qCAAqC,CAAA;AACpF,OAAO,KAAK,EAAe,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAE7E,eAAO,MAAM,kBAAkB,WACrB,KAAK,EAAE,KACd,cAAc,CAAC,mBAAmB,GAAG,yBAAyB,CA+ChE,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fieldSchemasToFormState } from '@payloadcms/ui/forms/fieldSchemasToFormState';
|
|
2
2
|
export const blockValidationHOC = blocks => {
|
|
3
3
|
return async ({
|
|
4
4
|
node,
|
|
@@ -21,17 +21,20 @@ export const blockValidationHOC = blocks => {
|
|
|
21
21
|
return 'Block not found';
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
-
* Run
|
|
24
|
+
* Run fieldSchemasToFormState as that properly validates block and block sub-fields
|
|
25
25
|
*/
|
|
26
|
-
const result = await
|
|
26
|
+
const result = await fieldSchemasToFormState({
|
|
27
27
|
id,
|
|
28
28
|
collectionSlug,
|
|
29
29
|
data: blockFieldData,
|
|
30
|
-
|
|
30
|
+
fields: block.fields,
|
|
31
|
+
fieldSchemaMap: undefined,
|
|
31
32
|
operation: operation === 'create' || operation === 'update' ? operation : 'update',
|
|
33
|
+
permissions: {},
|
|
32
34
|
preferences,
|
|
35
|
+
renderAllFields: false,
|
|
33
36
|
req,
|
|
34
|
-
|
|
37
|
+
schemaPath: ''
|
|
35
38
|
});
|
|
36
39
|
let errorPaths = [];
|
|
37
40
|
for (const fieldKey in result) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.js","names":["
|
|
1
|
+
{"version":3,"file":"validate.js","names":["fieldSchemasToFormState","blockValidationHOC","blocks","node","validation","blockFieldData","fields","options","id","collectionSlug","operation","preferences","req","block","find","slug","blockType","result","data","fieldSchemaMap","undefined","permissions","renderAllFields","schemaPath","errorPaths","fieldKey","concat","length","join"],"sources":["../../../../src/features/blocks/server/validate.ts"],"sourcesContent":["import type { Block } from 'payload'\n\nimport { fieldSchemasToFormState } from '@payloadcms/ui/forms/fieldSchemasToFormState'\n\nimport type { NodeValidation } from '../../typesServer.js'\nimport type { SerializedInlineBlockNode } from '../client/nodes/InlineBlocksNode.js'\nimport type { BlockFields, SerializedBlockNode } from './nodes/BlocksNode.js'\n\nexport const blockValidationHOC = (\n blocks: Block[],\n): NodeValidation<SerializedBlockNode | SerializedInlineBlockNode> => {\n return async ({ node, validation }) => {\n const blockFieldData = node.fields ?? ({} as BlockFields)\n\n const {\n options: { id, collectionSlug, operation, preferences, req },\n } = validation\n\n // find block\n const block = blocks.find((block) => block.slug === blockFieldData.blockType)\n\n // validate block\n if (!block) {\n return 'Block not found'\n }\n\n /**\n * Run fieldSchemasToFormState as that properly validates block and block sub-fields\n */\n\n const result = await fieldSchemasToFormState({\n id,\n collectionSlug,\n data: blockFieldData,\n fields: block.fields,\n fieldSchemaMap: undefined,\n operation: operation === 'create' || operation === 'update' ? operation : 'update',\n permissions: {},\n preferences,\n renderAllFields: false,\n req,\n schemaPath: '',\n })\n\n let errorPaths: string[] = []\n for (const fieldKey in result) {\n if (result[fieldKey].errorPaths) {\n errorPaths = errorPaths.concat(result[fieldKey].errorPaths)\n }\n }\n\n if (errorPaths.length) {\n return 'The following fields are invalid: ' + errorPaths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