@payloadcms/richtext-lexical 3.0.0-beta.13 → 3.0.0-beta.15
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/field/features/blockquote/feature.server.d.ts.map +1 -1
- package/dist/field/features/blockquote/feature.server.js +3 -2
- package/dist/field/features/blockquote/feature.server.js.map +1 -1
- package/dist/field/features/blocks/component/index.d.ts.map +1 -1
- package/dist/field/features/blocks/component/index.js +31 -1
- package/dist/field/features/blocks/component/index.js.map +1 -1
- package/dist/field/features/blocks/feature.server.d.ts.map +1 -1
- package/dist/field/features/blocks/feature.server.js +90 -3
- package/dist/field/features/blocks/feature.server.js.map +1 -1
- package/dist/field/features/blocks/populationPromise.d.ts.map +1 -1
- package/dist/field/features/blocks/populationPromise.js +3 -5
- package/dist/field/features/blocks/populationPromise.js.map +1 -1
- package/dist/field/features/blocks/validate.d.ts.map +1 -1
- package/dist/field/features/blocks/validate.js +21 -23
- package/dist/field/features/blocks/validate.js.map +1 -1
- package/dist/field/features/heading/feature.server.d.ts.map +1 -1
- package/dist/field/features/heading/feature.server.js +4 -3
- package/dist/field/features/heading/feature.server.js.map +1 -1
- package/dist/field/features/horizontalrule/feature.server.d.ts.map +1 -1
- package/dist/field/features/horizontalrule/feature.server.js +3 -2
- package/dist/field/features/horizontalrule/feature.server.js.map +1 -1
- package/dist/field/features/link/drawer/baseFields.js +1 -1
- package/dist/field/features/link/drawer/baseFields.js.map +1 -1
- package/dist/field/features/link/feature.server.d.ts.map +1 -1
- package/dist/field/features/link/feature.server.js +15 -6
- package/dist/field/features/link/feature.server.js.map +1 -1
- package/dist/field/features/link/populationPromise.d.ts.map +1 -1
- package/dist/field/features/link/populationPromise.js +28 -26
- package/dist/field/features/link/populationPromise.js.map +1 -1
- package/dist/field/features/lists/checklist/feature.server.d.ts.map +1 -1
- package/dist/field/features/lists/checklist/feature.server.js +5 -4
- package/dist/field/features/lists/checklist/feature.server.js.map +1 -1
- package/dist/field/features/lists/orderedlist/feature.server.d.ts.map +1 -1
- package/dist/field/features/lists/orderedlist/feature.server.js +5 -4
- package/dist/field/features/lists/orderedlist/feature.server.js.map +1 -1
- package/dist/field/features/lists/unorderedlist/feature.server.d.ts.map +1 -1
- package/dist/field/features/lists/unorderedlist/feature.server.js +5 -4
- package/dist/field/features/lists/unorderedlist/feature.server.js.map +1 -1
- package/dist/field/features/migrations/lexicalPluginToLexical/converter/converters/upload/converter.d.ts.map +1 -1
- package/dist/field/features/migrations/lexicalPluginToLexical/converter/converters/upload/converter.js +2 -4
- package/dist/field/features/migrations/lexicalPluginToLexical/converter/converters/upload/converter.js.map +1 -1
- package/dist/field/features/migrations/slateToLexical/converter/converters/relationship/converter.d.ts.map +1 -1
- package/dist/field/features/migrations/slateToLexical/converter/converters/relationship/converter.js +2 -4
- package/dist/field/features/migrations/slateToLexical/converter/converters/relationship/converter.js.map +1 -1
- package/dist/field/features/migrations/slateToLexical/converter/converters/upload/converter.d.ts.map +1 -1
- package/dist/field/features/migrations/slateToLexical/converter/converters/upload/converter.js +2 -4
- package/dist/field/features/migrations/slateToLexical/converter/converters/upload/converter.js.map +1 -1
- package/dist/field/features/relationship/drawer/index.d.ts.map +1 -1
- package/dist/field/features/relationship/drawer/index.js +5 -9
- package/dist/field/features/relationship/drawer/index.js.map +1 -1
- package/dist/field/features/relationship/feature.server.d.ts.map +1 -1
- package/dist/field/features/relationship/feature.server.js +3 -2
- package/dist/field/features/relationship/feature.server.js.map +1 -1
- package/dist/field/features/relationship/nodes/RelationshipNode.d.ts +1 -4
- package/dist/field/features/relationship/nodes/RelationshipNode.d.ts.map +1 -1
- package/dist/field/features/relationship/nodes/RelationshipNode.js +7 -6
- package/dist/field/features/relationship/nodes/RelationshipNode.js.map +1 -1
- package/dist/field/features/relationship/nodes/components/RelationshipComponent.d.ts.map +1 -1
- package/dist/field/features/relationship/nodes/components/RelationshipComponent.js +1 -1
- package/dist/field/features/relationship/nodes/components/RelationshipComponent.js.map +1 -1
- package/dist/field/features/relationship/populationPromise.js +7 -6
- package/dist/field/features/relationship/populationPromise.js.map +1 -1
- package/dist/field/features/typeUtilities.d.ts +8 -0
- package/dist/field/features/typeUtilities.d.ts.map +1 -0
- package/dist/field/features/typeUtilities.js +8 -0
- package/dist/field/features/typeUtilities.js.map +1 -0
- package/dist/field/features/types.d.ts +50 -26
- package/dist/field/features/types.d.ts.map +1 -1
- package/dist/field/features/types.js.map +1 -1
- package/dist/field/features/upload/component/index.js +3 -3
- package/dist/field/features/upload/component/index.js.map +1 -1
- package/dist/field/features/upload/drawer/index.d.ts.map +1 -1
- package/dist/field/features/upload/drawer/index.js +6 -8
- package/dist/field/features/upload/drawer/index.js.map +1 -1
- package/dist/field/features/upload/feature.server.d.ts.map +1 -1
- package/dist/field/features/upload/feature.server.js +8 -4
- package/dist/field/features/upload/feature.server.js.map +1 -1
- package/dist/field/features/upload/nodes/UploadNode.d.ts +1 -11
- package/dist/field/features/upload/nodes/UploadNode.d.ts.map +1 -1
- package/dist/field/features/upload/nodes/UploadNode.js +4 -1
- package/dist/field/features/upload/nodes/UploadNode.js.map +1 -1
- package/dist/field/features/upload/plugin/index.d.ts +2 -2
- package/dist/field/features/upload/plugin/index.d.ts.map +1 -1
- package/dist/field/features/upload/plugin/index.js +1 -3
- package/dist/field/features/upload/plugin/index.js.map +1 -1
- package/dist/field/features/upload/populationPromise.d.ts.map +1 -1
- package/dist/field/features/upload/populationPromise.js +22 -9
- package/dist/field/features/upload/populationPromise.js.map +1 -1
- package/dist/field/features/upload/validate.js +5 -3
- package/dist/field/features/upload/validate.js.map +1 -1
- package/dist/field/lexical/config/server/sanitize.d.ts.map +1 -1
- package/dist/field/lexical/config/server/sanitize.js +20 -6
- package/dist/field/lexical/config/server/sanitize.js.map +1 -1
- package/dist/field/lexical/utils/url.d.ts.map +1 -1
- package/dist/field/lexical/utils/url.js +1 -0
- package/dist/field/lexical/utils/url.js.map +1 -1
- package/dist/forEachNodeRecursively.d.ts +10 -0
- package/dist/forEachNodeRecursively.d.ts.map +1 -0
- package/dist/forEachNodeRecursively.js +24 -0
- package/dist/forEachNodeRecursively.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +103 -23
- package/dist/index.js.map +1 -1
- package/dist/populate/populate.d.ts +1 -1
- package/dist/populate/populate.d.ts.map +1 -1
- package/dist/populate/populate.js.map +1 -1
- package/dist/populate/populateLexicalPopulationPromises.d.ts +12 -0
- package/dist/populate/populateLexicalPopulationPromises.d.ts.map +1 -0
- package/dist/populate/populateLexicalPopulationPromises.js +35 -0
- package/dist/populate/populateLexicalPopulationPromises.js.map +1 -0
- package/dist/populate/recurseNestedFields.d.ts +5 -2
- package/dist/populate/recurseNestedFields.d.ts.map +1 -1
- package/dist/populate/recurseNestedFields.js +3 -5
- package/dist/populate/recurseNestedFields.js.map +1 -1
- package/package.json +9 -9
- package/dist/populate/richTextRelationshipPromise.d.ts +0 -23
- package/dist/populate/richTextRelationshipPromise.d.ts.map +0 -1
- package/dist/populate/richTextRelationshipPromise.js +0 -68
- package/dist/populate/richTextRelationshipPromise.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature.server.d.ts","sourceRoot":"","sources":["../../../../src/field/features/blockquote/feature.server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"feature.server.d.ts","sourceRoot":"","sources":["../../../../src/field/features/blockquote/feature.server.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAA;AAOhE,eAAO,MAAM,iBAAiB,EAAE,6BAA6B,CAAC,SAAS,EAAE,SAAS,CAoCjF,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import lexicalRichTextImport from '@lexical/rich-text';
|
|
2
2
|
const { QuoteNode } = lexicalRichTextImport;
|
|
3
3
|
import { convertLexicalNodesToHTML } from '../converters/html/converter/index.js';
|
|
4
|
+
import { createNode } from '../typeUtilities.js';
|
|
4
5
|
import { BlockQuoteFeatureClientComponent } from './feature.client.js';
|
|
5
6
|
import { MarkdownTransformer } from './markdownTransformer.js';
|
|
6
7
|
export const BlockQuoteFeature = (props)=>{
|
|
@@ -13,7 +14,7 @@ export const BlockQuoteFeature = (props)=>{
|
|
|
13
14
|
MarkdownTransformer
|
|
14
15
|
],
|
|
15
16
|
nodes: [
|
|
16
|
-
{
|
|
17
|
+
createNode({
|
|
17
18
|
converters: {
|
|
18
19
|
html: {
|
|
19
20
|
converter: async ({ converters, node, parent, payload })=>{
|
|
@@ -34,7 +35,7 @@ export const BlockQuoteFeature = (props)=>{
|
|
|
34
35
|
}
|
|
35
36
|
},
|
|
36
37
|
node: QuoteNode
|
|
37
|
-
}
|
|
38
|
+
})
|
|
38
39
|
],
|
|
39
40
|
serverFeatureProps: props
|
|
40
41
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/field/features/blockquote/feature.server.ts"],"sourcesContent":["import lexicalRichTextImport
|
|
1
|
+
{"version":3,"sources":["../../../../src/field/features/blockquote/feature.server.ts"],"sourcesContent":["import lexicalRichTextImport from '@lexical/rich-text'\nconst { QuoteNode } = lexicalRichTextImport\n\nimport type { FeatureProviderProviderServer } from '../types.js'\n\nimport { convertLexicalNodesToHTML } from '../converters/html/converter/index.js'\nimport { createNode } from '../typeUtilities.js'\nimport { BlockQuoteFeatureClientComponent } from './feature.client.js'\nimport { MarkdownTransformer } from './markdownTransformer.js'\n\nexport const BlockQuoteFeature: FeatureProviderProviderServer<undefined, undefined> = (props) => {\n return {\n feature: () => {\n return {\n ClientComponent: BlockQuoteFeatureClientComponent,\n clientFeatureProps: null,\n markdownTransformers: [MarkdownTransformer],\n nodes: [\n createNode({\n converters: {\n html: {\n converter: async ({ converters, node, parent, payload }) => {\n const childrenText = await convertLexicalNodesToHTML({\n converters,\n lexicalNodes: node.children,\n parent: {\n ...node,\n parent,\n },\n payload,\n })\n\n return `<blockquote>${childrenText}</blockquote>`\n },\n nodeTypes: [QuoteNode.getType()],\n },\n },\n node: QuoteNode,\n }),\n ],\n serverFeatureProps: props,\n }\n },\n key: 'blockquote',\n serverFeatureProps: props,\n }\n}\n"],"names":["lexicalRichTextImport","QuoteNode","convertLexicalNodesToHTML","createNode","BlockQuoteFeatureClientComponent","MarkdownTransformer","BlockQuoteFeature","props","feature","ClientComponent","clientFeatureProps","markdownTransformers","nodes","converters","html","converter","node","parent","payload","childrenText","lexicalNodes","children","nodeTypes","getType","serverFeatureProps","key"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,2BAA2B,qBAAoB;AACtD,MAAM,EAAEC,SAAS,EAAE,GAAGD;AAItB,SAASE,yBAAyB,QAAQ,wCAAuC;AACjF,SAASC,UAAU,QAAQ,sBAAqB;AAChD,SAASC,gCAAgC,QAAQ,sBAAqB;AACtE,SAASC,mBAAmB,QAAQ,2BAA0B;AAE9D,OAAO,MAAMC,oBAAyE,CAACC;IACrF,OAAO;QACLC,SAAS;YACP,OAAO;gBACLC,iBAAiBL;gBACjBM,oBAAoB;gBACpBC,sBAAsB;oBAACN;iBAAoB;gBAC3CO,OAAO;oBACLT,WAAW;wBACTU,YAAY;4BACVC,MAAM;gCACJC,WAAW,OAAO,EAAEF,UAAU,EAAEG,IAAI,EAAEC,MAAM,EAAEC,OAAO,EAAE;oCACrD,MAAMC,eAAe,MAAMjB,0BAA0B;wCACnDW;wCACAO,cAAcJ,KAAKK,QAAQ;wCAC3BJ,QAAQ;4CACN,GAAGD,IAAI;4CACPC;wCACF;wCACAC;oCACF;oCAEA,OAAO,CAAC,YAAY,EAAEC,aAAa,aAAa,CAAC;gCACnD;gCACAG,WAAW;oCAACrB,UAAUsB,OAAO;iCAAG;4BAClC;wBACF;wBACAP,MAAMf;oBACR;iBACD;gBACDuB,oBAAoBjB;YACtB;QACF;QACAkB,KAAK;QACLD,oBAAoBjB;IACtB;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/field/features/blocks/component/index.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAoD,MAAM,OAAO,CAAA;AAExE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/field/features/blocks/component/index.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAoD,MAAM,OAAO,CAAA;AAExE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAuBzD,OAAO,cAAc,CAAA;AAGrB,KAAK,KAAK,GAAG;IACX,qBAAqB,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAE1B,QAAQ,EAAE,WAAW,CAAA;IACrB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;OAEG;IACH,mBAAmB,EAAE,WAAW,CAAA;CACjC,CAAA;AAED,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAkJ1C,CAAA"}
|
|
@@ -2,10 +2,16 @@
|
|
|
2
2
|
import { Form } from '@payloadcms/ui/forms/Form';
|
|
3
3
|
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
4
4
|
const baseClass = 'lexical-block';
|
|
5
|
+
import { getTranslation } from '@payloadcms/translations';
|
|
6
|
+
import { Collapsible } from '@payloadcms/ui/elements/Collapsible';
|
|
7
|
+
import { Pill } from '@payloadcms/ui/elements/Pill';
|
|
8
|
+
import { ShimmerEffect } from '@payloadcms/ui/elements/ShimmerEffect';
|
|
9
|
+
import { SectionTitle } from '@payloadcms/ui/fields/Blocks/SectionTitle';
|
|
5
10
|
import { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider';
|
|
6
11
|
import { useFormSubmitted } from '@payloadcms/ui/forms/Form';
|
|
7
12
|
import { useConfig } from '@payloadcms/ui/providers/Config';
|
|
8
13
|
import { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';
|
|
14
|
+
import { useTranslation } from '@payloadcms/ui/providers/Translation';
|
|
9
15
|
import { getFormState } from '@payloadcms/ui/utilities/getFormState';
|
|
10
16
|
import { v4 as uuid } from 'uuid';
|
|
11
17
|
import { useEditorConfigContext } from '../../../lexical/config/client/EditorConfigProvider.js';
|
|
@@ -89,9 +95,17 @@ export const BlockComponent = (props)=>{
|
|
|
89
95
|
id,
|
|
90
96
|
formData.blockName
|
|
91
97
|
]);
|
|
98
|
+
const { i18n } = useTranslation();
|
|
99
|
+
const classNames = [
|
|
100
|
+
`${baseClass}__row`,
|
|
101
|
+
`${baseClass}__row--no-errors`
|
|
102
|
+
].filter(Boolean).join(' ');
|
|
92
103
|
// Memoized Form JSX
|
|
93
104
|
const formContent = useMemo(()=>{
|
|
94
|
-
return reducedBlock && initialState !== false
|
|
105
|
+
return reducedBlock && initialState !== false ? /*#__PURE__*/ React.createElement(Form, {
|
|
106
|
+
beforeSubmit: [
|
|
107
|
+
onChange
|
|
108
|
+
],
|
|
95
109
|
// @ts-expect-error TODO: Fix this
|
|
96
110
|
fields: fieldMap,
|
|
97
111
|
initialState: initialState,
|
|
@@ -109,11 +123,27 @@ export const BlockComponent = (props)=>{
|
|
|
109
123
|
path: `${path}.feature.blocks.${formData.blockType}`,
|
|
110
124
|
reducedBlock: reducedBlock,
|
|
111
125
|
schemaPath: schemaFieldsPath
|
|
126
|
+
})) : /*#__PURE__*/ React.createElement(Collapsible, {
|
|
127
|
+
className: classNames,
|
|
128
|
+
collapsibleStyle: "default",
|
|
129
|
+
header: /*#__PURE__*/ React.createElement("div", {
|
|
130
|
+
className: `${baseClass}__block-header`
|
|
131
|
+
}, /*#__PURE__*/ React.createElement("div", null, /*#__PURE__*/ React.createElement(Pill, {
|
|
132
|
+
className: `${baseClass}__block-pill ${baseClass}__block-pill-${formData?.blockType}`,
|
|
133
|
+
pillStyle: "white"
|
|
134
|
+
}, typeof reducedBlock.labels.singular === 'string' ? getTranslation(reducedBlock.labels.singular, i18n) : '[Singular Label]'), /*#__PURE__*/ React.createElement(SectionTitle, {
|
|
135
|
+
path: "blockName",
|
|
136
|
+
readOnly: parentLexicalRichTextField?.readOnly
|
|
137
|
+
}))),
|
|
138
|
+
key: 0
|
|
139
|
+
}, /*#__PURE__*/ React.createElement(ShimmerEffect, {
|
|
140
|
+
height: "35vh"
|
|
112
141
|
}));
|
|
113
142
|
}, [
|
|
114
143
|
fieldMap,
|
|
115
144
|
parentLexicalRichTextField,
|
|
116
145
|
nodeKey,
|
|
146
|
+
i18n,
|
|
117
147
|
submitted,
|
|
118
148
|
initialState,
|
|
119
149
|
reducedBlock,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/field/features/blocks/component/index.tsx"],"sourcesContent":["'use client'\n\nimport type { FormProps } from '@payloadcms/ui/forms/Form'\n\nimport { Form } from '@payloadcms/ui/forms/Form'\nimport React, { useCallback, useEffect, useMemo, useState } from 'react'\n\nimport { type BlockFields } from '../nodes/BlocksNode.js'\nconst baseClass = 'lexical-block'\n\nimport type { ReducedBlock } from '@payloadcms/ui/utilities/buildComponentMap'\nimport type { FormState } from 'payload/types'\n\nimport { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider'\nimport { useFormSubmitted } from '@payloadcms/ui/forms/Form'\nimport { useConfig } from '@payloadcms/ui/providers/Config'\nimport { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo'\nimport { getFormState } from '@payloadcms/ui/utilities/getFormState'\nimport { v4 as uuid } from 'uuid'\n\nimport type { ClientComponentProps } from '../../types.js'\nimport type { BlocksFeatureClientProps } from '../feature.client.js'\n\nimport { useEditorConfigContext } from '../../../lexical/config/client/EditorConfigProvider.js'\nimport { BlockContent } from './BlockContent.js'\nimport './index.scss'\nimport { removeEmptyArrayValues } from './removeEmptyArrayValues.js'\n\ntype Props = {\n blockFieldWrapperName: string\n children?: React.ReactNode\n\n formData: BlockFields\n nodeKey?: string\n /**\n * This transformedFormData already comes wrapped in blockFieldWrapperName\n */\n transformedFormData: BlockFields\n}\n\nexport const BlockComponent: React.FC<Props> = (props) => {\n const { blockFieldWrapperName, formData, nodeKey } = props\n const config = useConfig()\n const submitted = useFormSubmitted()\n const { id } = useDocumentInfo()\n const { path, schemaPath } = useFieldProps()\n const { editorConfig, field: parentLexicalRichTextField } = useEditorConfigContext()\n\n const [initialState, setInitialState] = useState<FormState | false>(false)\n const {\n field: { richTextComponentMap },\n } = useEditorConfigContext()\n\n const componentMapRenderedFieldsPath = `feature.blocks.fields.${formData?.blockType}`\n const schemaFieldsPath = `${schemaPath}.feature.blocks.${formData?.blockType}`\n\n const reducedBlock: ReducedBlock = (\n editorConfig?.resolvedFeatureMap?.get('blocks')\n ?.clientFeatureProps as ClientComponentProps<BlocksFeatureClientProps>\n )?.reducedBlocks?.find((block) => block.slug === formData?.blockType)\n\n const fieldMap = richTextComponentMap.get(componentMapRenderedFieldsPath)\n // Field Schema\n useEffect(() => {\n const awaitInitialState = async () => {\n const state = await getFormState({\n apiRoute: config.routes.api,\n body: {\n id,\n data: JSON.parse(JSON.stringify(formData)),\n operation: 'update',\n schemaPath: schemaFieldsPath,\n },\n serverURL: config.serverURL,\n }) // Form State\n\n if (state) {\n setInitialState({\n ...removeEmptyArrayValues({ fields: state }),\n blockName: {\n initialValue: '',\n passesCondition: true,\n valid: true,\n value: formData.blockName,\n },\n })\n }\n }\n\n if (formData) {\n void awaitInitialState()\n }\n }, [config.routes.api, config.serverURL, schemaFieldsPath, id])\n\n const onChange: FormProps['onChange'][0] = useCallback(\n async ({ formState: prevFormState }) => {\n const formState = await getFormState({\n apiRoute: config.routes.api,\n body: {\n id,\n formState: prevFormState,\n operation: 'update',\n schemaPath: schemaFieldsPath,\n },\n serverURL: config.serverURL,\n })\n\n return {\n ...formState,\n blockName: {\n initialValue: '',\n passesCondition: true,\n valid: true,\n value: formData.blockName,\n },\n }\n },\n\n [config.routes.api, config.serverURL, schemaFieldsPath, id, formData.blockName],\n )\n\n // Memoized Form JSX\n const formContent = useMemo(() => {\n return (\n reducedBlock &&\n initialState !== false && (\n <Form\n // @ts-expect-error TODO: Fix this\n fields={fieldMap}\n initialState={initialState}\n onChange={[onChange]}\n submitted={submitted}\n uuid={uuid()}\n >\n <BlockContent\n baseClass={baseClass}\n field={parentLexicalRichTextField}\n formData={formData}\n formSchema={Array.isArray(fieldMap) ? fieldMap : []}\n nodeKey={nodeKey}\n path={`${path}.feature.blocks.${formData.blockType}`}\n reducedBlock={reducedBlock}\n schemaPath={schemaFieldsPath}\n />\n </Form>\n )\n )\n }, [\n fieldMap,\n parentLexicalRichTextField,\n nodeKey,\n submitted,\n initialState,\n reducedBlock,\n blockFieldWrapperName,\n onChange,\n schemaFieldsPath,\n path,\n ]) // Adding formData to the dependencies here might break it\n\n return <div className={baseClass}>{formContent}</div>\n}\n"],"names":["Form","React","useCallback","useEffect","useMemo","useState","baseClass","useFieldProps","useFormSubmitted","useConfig","useDocumentInfo","getFormState","v4","uuid","useEditorConfigContext","BlockContent","removeEmptyArrayValues","BlockComponent","props","blockFieldWrapperName","formData","nodeKey","config","submitted","id","path","schemaPath","editorConfig","field","parentLexicalRichTextField","initialState","setInitialState","richTextComponentMap","componentMapRenderedFieldsPath","blockType","schemaFieldsPath","reducedBlock","resolvedFeatureMap","get","clientFeatureProps","reducedBlocks","find","block","slug","fieldMap","awaitInitialState","state","apiRoute","routes","api","body","data","JSON","parse","stringify","operation","serverURL","fields","blockName","initialValue","passesCondition","valid","value","onChange","formState","prevFormState","formContent","formSchema","Array","isArray","div","className"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAIA,SAASA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XV,MAAMA;yBAEN,oBAACE;YACCT,WAAWA;YACXsB,OAAOC;YACPT,UAAUA;YACV+C,YAAYC,MAAMC,OAAO,CAACzB,YAAYA,WAAW,EAAE;YACnDvB,SAASA;YACTI,MAAM,CAAC,EAAEA,KAAK,gBAAgB,EAAEL,SAASc,SAAS,CAAC,CAAC;YACpDE,cAAcA;YACdV,YAAYS;;IAKtB,GAAG;QACDS;QACAf;QACAR;QACAE;QACAO;QACAM;QACAjB;QACA4C;QACA5B;QACAV;KACD,EAAE,0DAA0D;;IAE7D,qBAAO,oBAAC6C;QAAIC,WAAWjE;OAAY4D;AACrC,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/field/features/blocks/component/index.tsx"],"sourcesContent":["'use client'\n\nimport type { FormProps } from '@payloadcms/ui/forms/Form'\n\nimport { Form } from '@payloadcms/ui/forms/Form'\nimport React, { useCallback, useEffect, useMemo, useState } from 'react'\n\nimport { type BlockFields } from '../nodes/BlocksNode.js'\nconst baseClass = 'lexical-block'\nimport type { ReducedBlock } from '@payloadcms/ui/utilities/buildComponentMap'\nimport type { FormState } from 'payload/types'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { Collapsible } from '@payloadcms/ui/elements/Collapsible'\nimport { Pill } from '@payloadcms/ui/elements/Pill'\nimport { ShimmerEffect } from '@payloadcms/ui/elements/ShimmerEffect'\nimport { SectionTitle } from '@payloadcms/ui/fields/Blocks/SectionTitle'\nimport { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider'\nimport { useFormSubmitted } from '@payloadcms/ui/forms/Form'\nimport { useConfig } from '@payloadcms/ui/providers/Config'\nimport { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo'\nimport { useTranslation } from '@payloadcms/ui/providers/Translation'\nimport { getFormState } from '@payloadcms/ui/utilities/getFormState'\nimport { v4 as uuid } from 'uuid'\n\nimport type { ClientComponentProps } from '../../types.js'\nimport type { BlocksFeatureClientProps } from '../feature.client.js'\n\nimport { useEditorConfigContext } from '../../../lexical/config/client/EditorConfigProvider.js'\nimport { BlockContent } from './BlockContent.js'\nimport './index.scss'\nimport { removeEmptyArrayValues } from './removeEmptyArrayValues.js'\n\ntype Props = {\n blockFieldWrapperName: string\n children?: React.ReactNode\n\n formData: BlockFields\n nodeKey?: string\n /**\n * This transformedFormData already comes wrapped in blockFieldWrapperName\n */\n transformedFormData: BlockFields\n}\n\nexport const BlockComponent: React.FC<Props> = (props) => {\n const { blockFieldWrapperName, formData, nodeKey } = props\n const config = useConfig()\n const submitted = useFormSubmitted()\n const { id } = useDocumentInfo()\n const { path, schemaPath } = useFieldProps()\n const { editorConfig, field: parentLexicalRichTextField } = useEditorConfigContext()\n\n const [initialState, setInitialState] = useState<FormState | false>(false)\n const {\n field: { richTextComponentMap },\n } = useEditorConfigContext()\n\n const componentMapRenderedFieldsPath = `feature.blocks.fields.${formData?.blockType}`\n const schemaFieldsPath = `${schemaPath}.feature.blocks.${formData?.blockType}`\n\n const reducedBlock: ReducedBlock = (\n editorConfig?.resolvedFeatureMap?.get('blocks')\n ?.clientFeatureProps as ClientComponentProps<BlocksFeatureClientProps>\n )?.reducedBlocks?.find((block) => block.slug === formData?.blockType)\n\n const fieldMap = richTextComponentMap.get(componentMapRenderedFieldsPath)\n // Field Schema\n useEffect(() => {\n const awaitInitialState = async () => {\n const state = await getFormState({\n apiRoute: config.routes.api,\n body: {\n id,\n data: JSON.parse(JSON.stringify(formData)),\n operation: 'update',\n schemaPath: schemaFieldsPath,\n },\n serverURL: config.serverURL,\n }) // Form State\n\n if (state) {\n setInitialState({\n ...removeEmptyArrayValues({ fields: state }),\n blockName: {\n initialValue: '',\n passesCondition: true,\n valid: true,\n value: formData.blockName,\n },\n })\n }\n }\n\n if (formData) {\n void awaitInitialState()\n }\n }, [config.routes.api, config.serverURL, schemaFieldsPath, id])\n\n const onChange: FormProps['onChange'][0] = useCallback(\n async ({ formState: prevFormState }) => {\n const formState = await getFormState({\n apiRoute: config.routes.api,\n body: {\n id,\n formState: prevFormState,\n operation: 'update',\n schemaPath: schemaFieldsPath,\n },\n serverURL: config.serverURL,\n })\n\n return {\n ...formState,\n blockName: {\n initialValue: '',\n passesCondition: true,\n valid: true,\n value: formData.blockName,\n },\n }\n },\n\n [config.routes.api, config.serverURL, schemaFieldsPath, id, formData.blockName],\n )\n const { i18n } = useTranslation()\n\n const classNames = [`${baseClass}__row`, `${baseClass}__row--no-errors`].filter(Boolean).join(' ')\n\n // Memoized Form JSX\n const formContent = useMemo(() => {\n return reducedBlock && initialState !== false ? (\n <Form\n beforeSubmit={[onChange]}\n // @ts-expect-error TODO: Fix this\n fields={fieldMap}\n initialState={initialState}\n onChange={[onChange]}\n submitted={submitted}\n uuid={uuid()}\n >\n <BlockContent\n baseClass={baseClass}\n field={parentLexicalRichTextField}\n formData={formData}\n formSchema={Array.isArray(fieldMap) ? fieldMap : []}\n nodeKey={nodeKey}\n path={`${path}.feature.blocks.${formData.blockType}`}\n reducedBlock={reducedBlock}\n schemaPath={schemaFieldsPath}\n />\n </Form>\n ) : (\n <Collapsible\n className={classNames}\n collapsibleStyle=\"default\"\n header={\n <div className={`${baseClass}__block-header`}>\n <div>\n <Pill\n className={`${baseClass}__block-pill ${baseClass}__block-pill-${formData?.blockType}`}\n pillStyle=\"white\"\n >\n {typeof reducedBlock.labels.singular === 'string'\n ? getTranslation(reducedBlock.labels.singular, i18n)\n : '[Singular Label]'}\n </Pill>\n <SectionTitle path=\"blockName\" readOnly={parentLexicalRichTextField?.readOnly} />\n </div>\n </div>\n }\n key={0}\n >\n <ShimmerEffect height=\"35vh\" />\n </Collapsible>\n )\n }, [\n fieldMap,\n parentLexicalRichTextField,\n nodeKey,\n i18n,\n submitted,\n initialState,\n reducedBlock,\n blockFieldWrapperName,\n onChange,\n schemaFieldsPath,\n path,\n ]) // Adding formData to the dependencies here might break it\n\n return <div className={baseClass}>{formContent}</div>\n}\n"],"names":["Form","React","useCallback","useEffect","useMemo","useState","baseClass","getTranslation","Collapsible","Pill","ShimmerEffect","SectionTitle","useFieldProps","useFormSubmitted","useConfig","useDocumentInfo","useTranslation","getFormState","v4","uuid","useEditorConfigContext","BlockContent","removeEmptyArrayValues","BlockComponent","props","blockFieldWrapperName","formData","nodeKey","config","submitted","id","path","schemaPath","editorConfig","field","parentLexicalRichTextField","initialState","setInitialState","richTextComponentMap","componentMapRenderedFieldsPath","blockType","schemaFieldsPath","reducedBlock","resolvedFeatureMap","get","clientFeatureProps","reducedBlocks","find","block","slug","fieldMap","awaitInitialState","state","apiRoute","routes","api","body","data","JSON","parse","stringify","operation","serverURL","fields","blockName","initialValue","passesCondition","valid","value","onChange","formState","prevFormState","i18n","classNames","filter","Boolean","join","formContent","beforeSubmit","formSchema","Array","isArray","className","collapsibleStyle","header","div","pillStyle","labels","singular","readOnly","key","height"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAIA,SAASA,IAAI,QAAQ,4BAA2B;AAChD,OAAOC,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AAGxE,MAAMC,YAAY;AAIlB,SAASC,cAAc,QAAQ,2BAA0B;AACzD,SAASC,WAAW,QAAQ,sCAAqC;AACjE,SAASC,IAAI,QAAQ,+BAA8B;AACnD,SAASC,aAAa,QAAQ,wCAAuC;AACrE,SAASC,YAAY,QAAQ,4CAA2C;AACxE,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,gBAAgB,QAAQ,4BAA2B;AAC5D,SAASC,SAAS,QAAQ,kCAAiC;AAC3D,SAASC,eAAe,QAAQ,wCAAuC;AACvE,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,YAAY,QAAQ,wCAAuC;AACpE,SAASC,MA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AAC/B,YAAYA,WAAW,EAAE;YACnDvB,SAASA;YACTI,MAAM,CAAC,EAAEA,KAAK,gBAAgB,EAAEL,SAASc,SAAS,CAAC,CAAC;YACpDE,cAAcA;YACdV,YAAYS;4BAIhB,oBAACjC;YACC0E,WAAWT;YACXU,kBAAiB;YACjBC,sBACE,oBAACC;gBAAIH,WAAW,CAAC,EAAE5E,UAAU,cAAc,CAAC;6BAC1C,oBAAC+E,2BACC,oBAAC5E;gBACCyE,WAAW,CAAC,EAAE5E,UAAU,aAAa,EAAEA,UAAU,aAAa,EAAEoB,UAAUc,UAAU,CAAC;gBACrF8C,WAAU;eAET,OAAO5C,aAAa6C,MAAM,CAACC,QAAQ,KAAK,WACrCjF,eAAemC,aAAa6C,MAAM,CAACC,QAAQ,EAAEhB,QAC7C,mCAEN,oBAAC7D;gBAAaoB,MAAK;gBAAY0D,UAAUtD,4BAA4BsD;;YAI3EC,KAAK;yBAEL,oBAAChF;YAAciF,QAAO;;IAG5B,GAAG;QACDzC;QACAf;QACAR;QACA6C;QACA3C;QACAO;QACAM;QACAjB;QACA4C;QACA5B;QACAV;KACD,EAAE,0DAA0D;;IAE7D,qBAAO,oBAACsD;QAAIH,WAAW5E;OAAYuE;AACrC,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature.server.d.ts","sourceRoot":"","sources":["../../../../src/field/features/blocks/feature.server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAqB,+BAA+B,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"feature.server.d.ts","sourceRoot":"","sources":["../../../../src/field/features/blocks/feature.server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAqB,+BAA+B,EAAE,MAAM,eAAe,CAAA;AAY9F,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAA;AAChE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AASnE,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG;IACjD,MAAM,EAAE,+BAA+B,EAAE,CAAA;CAC1C,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,YAAY,EAAE,CAAA;CACvB,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,6BAA6B,CACvD,kBAAkB,EAClB,wBAAwB,CA+MzB,CAAA"}
|
|
@@ -2,6 +2,7 @@ import { traverseFields } from '@payloadcms/next/utilities';
|
|
|
2
2
|
import { baseBlockFields, sanitizeFields } from 'payload/config';
|
|
3
3
|
import { fieldsToJSONSchema, formatLabels } from 'payload/utilities';
|
|
4
4
|
import { cloneDeep } from '../../lexical/utils/cloneDeep.js';
|
|
5
|
+
import { createNode } from '../typeUtilities.js';
|
|
5
6
|
import { BlocksFeatureClientComponent } from './feature.client.js';
|
|
6
7
|
import { BlockNode } from './nodes/BlocksNode.js';
|
|
7
8
|
import { blockPopulationPromiseHOC } from './populationPromise.js';
|
|
@@ -91,15 +92,101 @@ export const BlocksFeature = (props)=>{
|
|
|
91
92
|
}
|
|
92
93
|
},
|
|
93
94
|
nodes: [
|
|
94
|
-
{
|
|
95
|
-
|
|
95
|
+
createNode({
|
|
96
|
+
/* // TODO: Implement these hooks once docWithLocales / originalSiblingDoc => node matching has been figured out
|
|
97
|
+
hooks: {
|
|
98
|
+
beforeChange: [
|
|
99
|
+
async ({ context, findMany, node, operation, overrideAccess, req }) => {
|
|
100
|
+
const blockType = node.fields.blockType
|
|
101
|
+
|
|
102
|
+
const block = deepCopyObject(
|
|
103
|
+
props.blocks.find((block) => block.slug === blockType),
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
// sanitize blocks
|
|
107
|
+
const validRelationships = req.payload.config.collections.map((c) => c.slug) || []
|
|
108
|
+
|
|
109
|
+
const sanitizedBlock = {
|
|
110
|
+
...block,
|
|
111
|
+
fields: sanitizeFields({
|
|
112
|
+
config: req.payload.config,
|
|
113
|
+
fields: block.fields,
|
|
114
|
+
requireFieldLevelRichTextEditor: true,
|
|
115
|
+
validRelationships,
|
|
116
|
+
}),
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
await beforeChangeTraverseFields({
|
|
121
|
+
id: null,
|
|
122
|
+
collection: null,
|
|
123
|
+
context,
|
|
124
|
+
data: node.fields,
|
|
125
|
+
doc: node.fields,
|
|
126
|
+
fields: sanitizedBlock.fields,
|
|
127
|
+
global: null,
|
|
128
|
+
mergeLocaleActions: [],
|
|
129
|
+
operation:
|
|
130
|
+
operation === 'create' || operation === 'update' ? operation : 'update',
|
|
131
|
+
overrideAccess,
|
|
132
|
+
path: '',
|
|
133
|
+
req,
|
|
134
|
+
siblingData: node.fields,
|
|
135
|
+
siblingDoc: node.fields,
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
return node
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
beforeValidate: [
|
|
143
|
+
async ({ context, findMany, node, operation, overrideAccess, req }) => {
|
|
144
|
+
const blockType = node.fields.blockType
|
|
145
|
+
|
|
146
|
+
const block = deepCopyObject(
|
|
147
|
+
props.blocks.find((block) => block.slug === blockType),
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
// sanitize blocks
|
|
151
|
+
const validRelationships = req.payload.config.collections.map((c) => c.slug) || []
|
|
152
|
+
|
|
153
|
+
const sanitizedBlock = {
|
|
154
|
+
...block,
|
|
155
|
+
fields: sanitizeFields({
|
|
156
|
+
config: req.payload.config,
|
|
157
|
+
fields: block.fields,
|
|
158
|
+
requireFieldLevelRichTextEditor: true,
|
|
159
|
+
validRelationships,
|
|
160
|
+
}),
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
await beforeValidateTraverseFields({
|
|
164
|
+
id: null,
|
|
165
|
+
collection: null,
|
|
166
|
+
context,
|
|
167
|
+
data: node.fields,
|
|
168
|
+
doc: node.fields,
|
|
169
|
+
fields: sanitizedBlock.fields,
|
|
170
|
+
global: null,
|
|
171
|
+
operation:
|
|
172
|
+
operation === 'create' || operation === 'update' ? operation : 'update',
|
|
173
|
+
overrideAccess,
|
|
174
|
+
req,
|
|
175
|
+
siblingData: node.fields,
|
|
176
|
+
siblingDoc: node.fields,
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
return node
|
|
180
|
+
},
|
|
181
|
+
],
|
|
182
|
+
},*/ node: BlockNode,
|
|
96
183
|
populationPromises: [
|
|
97
184
|
blockPopulationPromiseHOC(props)
|
|
98
185
|
],
|
|
99
186
|
validations: [
|
|
100
187
|
blockValidationHOC(props)
|
|
101
188
|
]
|
|
102
|
-
}
|
|
189
|
+
})
|
|
103
190
|
],
|
|
104
191
|
serverFeatureProps: props
|
|
105
192
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/field/features/blocks/feature.server.ts"],"sourcesContent":["import type { Block, BlockField, Field, FieldWithRichTextRequiredEditor } from 'payload/types'\n\nimport { traverseFields } from '@payloadcms/next/utilities'\nimport { baseBlockFields, sanitizeFields } from 'payload/config'\nimport { fieldsToJSONSchema, formatLabels } from 'payload/utilities'\n\nimport type { FeatureProviderProviderServer } from '../types.js'\nimport type { BlocksFeatureClientProps } from './feature.client.js'\n\nimport { cloneDeep } from '../../lexical/utils/cloneDeep.js'\nimport { BlocksFeatureClientComponent } from './feature.client.js'\nimport { BlockNode } from './nodes/BlocksNode.js'\nimport { blockPopulationPromiseHOC } from './populationPromise.js'\nimport { blockValidationHOC } from './validate.js'\n\nexport type LexicalBlock = Omit<Block, 'fields'> & {\n fields: FieldWithRichTextRequiredEditor[]\n}\n\nexport type BlocksFeatureProps = {\n blocks: LexicalBlock[]\n}\n\nexport const BlocksFeature: FeatureProviderProviderServer<\n BlocksFeatureProps,\n BlocksFeatureClientProps\n> = (props) => {\n // Sanitization taken from payload/src/fields/config/sanitize.ts\n\n if (props?.blocks?.length) {\n props.blocks = props.blocks.map((block) => {\n const blockCopy = cloneDeep(block)\n\n return {\n ...blockCopy,\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n fields: blockCopy.fields.concat(baseBlockFields as FieldWithRichTextRequiredEditor[]),\n labels: !blockCopy.labels ? formatLabels(blockCopy.slug) : blockCopy.labels,\n }\n })\n // unSanitizedBlock.fields are sanitized in the React component and not here.\n // That's because we do not have access to the payload config here.\n }\n\n // Build clientProps\n const clientProps: BlocksFeatureClientProps = {\n reducedBlocks: [],\n }\n for (const block of props.blocks) {\n clientProps.reducedBlocks.push({\n slug: block.slug,\n fieldMap: [],\n imageAltText: block.imageAltText,\n imageURL: block.imageURL,\n labels: block.labels,\n })\n }\n\n return {\n feature: () => {\n return {\n ClientComponent: BlocksFeatureClientComponent,\n clientFeatureProps: clientProps,\n generateSchemaMap: ({ config, i18n, props }) => {\n const validRelationships = config.collections.map((c) => c.slug) || []\n\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 for (const block of props.blocks) {\n schemaMap.set(block.slug, block.fields || [])\n\n traverseFields({\n config,\n fields: block.fields,\n i18n,\n schemaMap,\n schemaPath: block.slug,\n validRelationships,\n })\n }\n\n return schemaMap\n },\n generatedTypes: {\n modifyOutputSchema: ({\n collectionIDFieldTypes,\n config,\n currentSchema,\n field,\n interfaceNameDefinitions,\n }) => {\n if (!props?.blocks?.length) {\n return currentSchema\n }\n\n // sanitize blocks\n const validRelationships = config.collections.map((c) => c.slug) || []\n\n const sanitizedBlocks = props.blocks.map((block) => {\n const blockCopy = cloneDeep(block)\n return {\n ...blockCopy,\n fields: sanitizeFields({\n config,\n fields: blockCopy.fields,\n requireFieldLevelRichTextEditor: true,\n validRelationships,\n }),\n }\n })\n\n const blocksField: BlockField = {\n name: field?.name + '_lexical_blocks',\n type: 'blocks',\n blocks: sanitizedBlocks,\n }\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(\n collectionIDFieldTypes,\n [blocksField],\n interfaceNameDefinitions,\n config,\n )\n\n return currentSchema\n },\n },\n nodes: [\n {\n node: BlockNode,\n populationPromises: [blockPopulationPromiseHOC(props)],\n validations: [blockValidationHOC(props)],\n },\n ],\n serverFeatureProps: props,\n }\n },\n key: 'blocks',\n serverFeatureProps: props,\n }\n}\n"],"names":["traverseFields","baseBlockFields","sanitizeFields","fieldsToJSONSchema","formatLabels","cloneDeep","BlocksFeatureClientComponent","BlockNode","blockPopulationPromiseHOC","blockValidationHOC","BlocksFeature","props","blocks","length","map","block","blockCopy","fields","concat","labels","slug","clientProps","reducedBlocks","push","fieldMap","imageAltText","imageURL","feature","ClientComponent","clientFeatureProps","generateSchemaMap","config","i18n","validRelationships","collections","c","schemaMap","Map","set","schemaPath","generatedTypes","modifyOutputSchema","collectionIDFieldTypes","currentSchema","field","interfaceNameDefinitions","sanitizedBlocks","requireFieldLevelRichTextEditor","blocksField","name","type","nodes","node","populationPromises","validations","serverFeatureProps","key"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,cAAc,QAAQ,6BAA4B;AAC3D,SAASC,eAAe,EAAEC,cAAc,QAAQ,iBAAgB;AAChE,SAASC,kBAAkB,EAAEC,YAAY,QAAQ,oBAAmB;AAKpE,SAASC,SAAS,QAAQ,mCAAkC;AAC5D,SAASC,4BAA4B,QAAQ,sBAAqB;AAClE,SAASC,SAAS,QAAQ,wBAAuB;AACjD,SAASC,yBAAyB,QAAQ,yBAAwB;AAClE,SAASC,kBAAkB,QAAQ,gBAAe;AAUlD,OAAO,MAAMC,gBAGT,CAACC;IACH,gEAAgE;IAEhE,IAAIA,OAA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AAM,EACNY,aAAa,EACbC,KAAK,EACLC,wBAAwB,EACzB;wBACC,IAAI,CAAClC,OAAOC,QAAQC,QAAQ;4BAC1B,OAAO8B;wBACT;wBAEA,kBAAkB;wBAClB,MAAMV,qBAAqBF,OAAOG,WAAW,CAACpB,GAAG,CAAC,CAACqB,IAAMA,EAAEf,IAAI,KAAK,EAAE;wBAEtE,MAAM0B,kBAAkBnC,MAAMC,MAAM,CAACE,GAAG,CAAC,CAACC;4BACxC,MAAMC,YAAYX,UAAUU;4BAC5B,OAAO;gCACL,GAAGC,SAAS;gCACZC,QAAQf,eAAe;oCACrB6B;oCACAd,QAAQD,UAAUC,MAAM;oCACxB8B,iCAAiC;oCACjCd;gCACF;4BACF;wBACF;wBAEA,MAAMe,cAA0B;4BAC9BC,MAAML,OAAOK,OAAO;4BACpBC,MAAM;4BACNtC,QAAQkC;wBACV;wBACA,wFAAwF;wBACxF,2EAA2E;wBAC3E3C,mBACEuC,wBACA;4BAACM;yBAAY,EACbH,0BACAd;wBAGF,OAAOY;oBACT;gBACF;gBACAQ,OAAO;oBACL;wBACEC,MAAM7C;wBACN8C,oBAAoB;4BAAC7C,0BAA0BG;yBAAO;wBACtD2C,aAAa;4BAAC7C,mBAAmBE;yBAAO;oBAC1C;iBACD;gBACD4C,oBAAoB5C;YACtB;QACF;QACA6C,KAAK;QACLD,oBAAoB5C;IACtB;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/field/features/blocks/feature.server.ts"],"sourcesContent":["import type { Block, BlockField, Field, FieldWithRichTextRequiredEditor } from 'payload/types'\n\nimport { traverseFields } from '@payloadcms/next/utilities'\nimport { baseBlockFields, sanitizeFields } from 'payload/config'\nimport {\n beforeChangeTraverseFields,\n beforeValidateTraverseFields,\n deepCopyObject,\n fieldsToJSONSchema,\n formatLabels,\n} from 'payload/utilities'\n\nimport type { FeatureProviderProviderServer } from '../types.js'\nimport type { BlocksFeatureClientProps } from './feature.client.js'\n\nimport { cloneDeep } from '../../lexical/utils/cloneDeep.js'\nimport { createNode } from '../typeUtilities.js'\nimport { BlocksFeatureClientComponent } from './feature.client.js'\nimport { BlockNode } from './nodes/BlocksNode.js'\nimport { blockPopulationPromiseHOC } from './populationPromise.js'\nimport { blockValidationHOC } from './validate.js'\n\nexport type LexicalBlock = Omit<Block, 'fields'> & {\n fields: FieldWithRichTextRequiredEditor[]\n}\n\nexport type BlocksFeatureProps = {\n blocks: LexicalBlock[]\n}\n\nexport const BlocksFeature: FeatureProviderProviderServer<\n BlocksFeatureProps,\n BlocksFeatureClientProps\n> = (props) => {\n // Sanitization taken from payload/src/fields/config/sanitize.ts\n\n if (props?.blocks?.length) {\n props.blocks = props.blocks.map((block) => {\n const blockCopy = cloneDeep(block)\n\n return {\n ...blockCopy,\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n fields: blockCopy.fields.concat(baseBlockFields as FieldWithRichTextRequiredEditor[]),\n labels: !blockCopy.labels ? formatLabels(blockCopy.slug) : blockCopy.labels,\n }\n })\n // unSanitizedBlock.fields are sanitized in the React component and not here.\n // That's because we do not have access to the payload config here.\n }\n\n // Build clientProps\n const clientProps: BlocksFeatureClientProps = {\n reducedBlocks: [],\n }\n for (const block of props.blocks) {\n clientProps.reducedBlocks.push({\n slug: block.slug,\n fieldMap: [],\n imageAltText: block.imageAltText,\n imageURL: block.imageURL,\n labels: block.labels,\n })\n }\n\n return {\n feature: () => {\n return {\n ClientComponent: BlocksFeatureClientComponent,\n clientFeatureProps: clientProps,\n generateSchemaMap: ({ config, i18n, props }) => {\n const validRelationships = config.collections.map((c) => c.slug) || []\n\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 for (const block of props.blocks) {\n schemaMap.set(block.slug, block.fields || [])\n\n traverseFields({\n config,\n fields: block.fields,\n i18n,\n schemaMap,\n schemaPath: block.slug,\n validRelationships,\n })\n }\n\n return schemaMap\n },\n generatedTypes: {\n modifyOutputSchema: ({\n collectionIDFieldTypes,\n config,\n currentSchema,\n field,\n interfaceNameDefinitions,\n }) => {\n if (!props?.blocks?.length) {\n return currentSchema\n }\n\n // sanitize blocks\n const validRelationships = config.collections.map((c) => c.slug) || []\n\n const sanitizedBlocks = props.blocks.map((block) => {\n const blockCopy = cloneDeep(block)\n return {\n ...blockCopy,\n fields: sanitizeFields({\n config,\n fields: blockCopy.fields,\n requireFieldLevelRichTextEditor: true,\n validRelationships,\n }),\n }\n })\n\n const blocksField: BlockField = {\n name: field?.name + '_lexical_blocks',\n type: 'blocks',\n blocks: sanitizedBlocks,\n }\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(\n collectionIDFieldTypes,\n [blocksField],\n interfaceNameDefinitions,\n config,\n )\n\n return currentSchema\n },\n },\n nodes: [\n createNode({\n /* // TODO: Implement these hooks once docWithLocales / originalSiblingDoc => node matching has been figured out\n hooks: {\n beforeChange: [\n async ({ context, findMany, node, operation, overrideAccess, req }) => {\n const blockType = node.fields.blockType\n\n const block = deepCopyObject(\n props.blocks.find((block) => block.slug === blockType),\n )\n\n // sanitize blocks\n const validRelationships = req.payload.config.collections.map((c) => c.slug) || []\n\n const sanitizedBlock = {\n ...block,\n fields: sanitizeFields({\n config: req.payload.config,\n fields: block.fields,\n requireFieldLevelRichTextEditor: true,\n validRelationships,\n }),\n }\n\n\n await beforeChangeTraverseFields({\n id: null,\n collection: null,\n context,\n data: node.fields,\n doc: node.fields,\n fields: sanitizedBlock.fields,\n global: null,\n mergeLocaleActions: [],\n operation:\n operation === 'create' || operation === 'update' ? operation : 'update',\n overrideAccess,\n path: '',\n req,\n siblingData: node.fields,\n siblingDoc: node.fields,\n })\n\n\n return node\n },\n ],\n beforeValidate: [\n async ({ context, findMany, node, operation, overrideAccess, req }) => {\n const blockType = node.fields.blockType\n\n const block = deepCopyObject(\n props.blocks.find((block) => block.slug === blockType),\n )\n\n // sanitize blocks\n const validRelationships = req.payload.config.collections.map((c) => c.slug) || []\n\n const sanitizedBlock = {\n ...block,\n fields: sanitizeFields({\n config: req.payload.config,\n fields: block.fields,\n requireFieldLevelRichTextEditor: true,\n validRelationships,\n }),\n }\n\n await beforeValidateTraverseFields({\n id: null,\n collection: null,\n context,\n data: node.fields,\n doc: node.fields,\n fields: sanitizedBlock.fields,\n global: null,\n operation:\n operation === 'create' || operation === 'update' ? operation : 'update',\n overrideAccess,\n req,\n siblingData: node.fields,\n siblingDoc: node.fields,\n })\n\n return node\n },\n ],\n },*/\n node: BlockNode,\n populationPromises: [blockPopulationPromiseHOC(props)],\n validations: [blockValidationHOC(props)],\n }),\n ],\n serverFeatureProps: props,\n }\n },\n key: 'blocks',\n serverFeatureProps: props,\n }\n}\n"],"names":["traverseFields","baseBlockFields","sanitizeFields","fieldsToJSONSchema","formatLabels","cloneDeep","createNode","BlocksFeatureClientComponent","BlockNode","blockPopulationPromiseHOC","blockValidationHOC","BlocksFeature","props","blocks","length","map","block","blockCopy","fields","concat","labels","slug","clientProps","reducedBlocks","push","fieldMap","imageAltText","imageURL","feature","ClientComponent","clientFeatureProps","generateSchemaMap","config","i18n","validRelationships","collections","c","schemaMap","Map","set","schemaPath","generatedTypes","modifyOutputSchema","collectionIDFieldTypes","currentSchema","field","interfaceNameDefinitions","sanitizedBlocks","requireFieldLevelRichTextEditor","blocksField","name","type","nodes","node","populationPromises","validations","serverFeatureProps","key"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,cAAc,QAAQ,6BAA4B;AA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ACtD2C,aAAa;4BAAC7C,mBAAmBE;yBAAO;oBAC1C;iBACD;gBACD4C,oBAAoB5C;YACtB;QACF;QACA6C,KAAK;QACLD,oBAAoB5C;IACtB;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"populationPromise.d.ts","sourceRoot":"","sources":["../../../../src/field/features/blocks/populationPromise.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAIhE,eAAO,MAAM,yBAAyB,UAC7B,kBAAkB,KACxB,kBAAkB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"populationPromise.d.ts","sourceRoot":"","sources":["../../../../src/field/features/blocks/populationPromise.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAIhE,eAAO,MAAM,yBAAyB,UAC7B,kBAAkB,KACxB,kBAAkB,mBAAmB,CAyDvC,CAAA"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { sanitizeFields } from 'payload/config';
|
|
2
2
|
import { recurseNestedFields } from '../../../populate/recurseNestedFields.js';
|
|
3
3
|
export const blockPopulationPromiseHOC = (props)=>{
|
|
4
|
-
const blockPopulationPromise = ({ context, currentDepth, depth, editorPopulationPromises, findMany, flattenLocales, node, overrideAccess, populationPromises, req, showHiddenFields, siblingDoc })=>{
|
|
4
|
+
const blockPopulationPromise = ({ context, currentDepth, depth, editorPopulationPromises, fieldPromises, findMany, flattenLocales, node, overrideAccess, populationPromises, req, showHiddenFields, siblingDoc })=>{
|
|
5
5
|
const blocks = props.blocks;
|
|
6
6
|
const blockFieldData = node.fields;
|
|
7
|
-
const promises = [];
|
|
8
7
|
// Sanitize block's fields here. This is done here and not in the feature, because the payload config is available here
|
|
9
8
|
const payloadConfig = req.payload.config;
|
|
10
9
|
const validRelationships = payloadConfig.collections.map((c)=>c.slug) || [];
|
|
@@ -19,7 +18,7 @@ export const blockPopulationPromiseHOC = (props)=>{
|
|
|
19
18
|
// find block used in this node
|
|
20
19
|
const block = props.blocks.find((block)=>block.slug === blockFieldData.blockType);
|
|
21
20
|
if (!block || !block?.fields?.length || !blockFieldData) {
|
|
22
|
-
return
|
|
21
|
+
return;
|
|
23
22
|
}
|
|
24
23
|
recurseNestedFields({
|
|
25
24
|
context,
|
|
@@ -27,18 +26,17 @@ export const blockPopulationPromiseHOC = (props)=>{
|
|
|
27
26
|
data: blockFieldData,
|
|
28
27
|
depth,
|
|
29
28
|
editorPopulationPromises,
|
|
29
|
+
fieldPromises,
|
|
30
30
|
fields: block.fields,
|
|
31
31
|
findMany,
|
|
32
32
|
flattenLocales,
|
|
33
33
|
overrideAccess,
|
|
34
34
|
populationPromises,
|
|
35
|
-
promises,
|
|
36
35
|
req,
|
|
37
36
|
showHiddenFields,
|
|
38
37
|
// The afterReadPromise gets its data from looking for field.name inside the siblingDoc. Thus, here we cannot pass the whole document's siblingDoc, but only the siblingDoc (sibling fields) of the current field.
|
|
39
38
|
siblingDoc: blockFieldData
|
|
40
39
|
});
|
|
41
|
-
return promises;
|
|
42
40
|
};
|
|
43
41
|
return blockPopulationPromise;
|
|
44
42
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/field/features/blocks/populationPromise.ts"],"sourcesContent":["import type { Block } from 'payload/types'\n\nimport { sanitizeFields } from 'payload/config'\n\nimport type { PopulationPromise } from '../types.js'\nimport type { BlocksFeatureProps } from './feature.server.js'\nimport type { SerializedBlockNode } from './nodes/BlocksNode.js'\n\nimport { recurseNestedFields } from '../../../populate/recurseNestedFields.js'\n\nexport const blockPopulationPromiseHOC = (\n props: BlocksFeatureProps,\n): PopulationPromise<SerializedBlockNode> => {\n const blockPopulationPromise: PopulationPromise<SerializedBlockNode> = ({\n context,\n currentDepth,\n depth,\n editorPopulationPromises,\n findMany,\n flattenLocales,\n node,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc,\n }) => {\n const blocks: Block[] = props.blocks\n const blockFieldData = node.fields\n\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/field/features/blocks/populationPromise.ts"],"sourcesContent":["import type { Block } from 'payload/types'\n\nimport { sanitizeFields } from 'payload/config'\n\nimport type { PopulationPromise } from '../types.js'\nimport type { BlocksFeatureProps } from './feature.server.js'\nimport type { SerializedBlockNode } from './nodes/BlocksNode.js'\n\nimport { recurseNestedFields } from '../../../populate/recurseNestedFields.js'\n\nexport const blockPopulationPromiseHOC = (\n props: BlocksFeatureProps,\n): PopulationPromise<SerializedBlockNode> => {\n const blockPopulationPromise: PopulationPromise<SerializedBlockNode> = ({\n context,\n currentDepth,\n depth,\n editorPopulationPromises,\n fieldPromises,\n findMany,\n flattenLocales,\n node,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n siblingDoc,\n }) => {\n const blocks: Block[] = props.blocks\n const blockFieldData = node.fields\n\n // Sanitize block's fields here. This is done here and not in the feature, because the payload config is available here\n const payloadConfig = req.payload.config\n const validRelationships = payloadConfig.collections.map((c) => c.slug) || []\n blocks.forEach((block) => {\n block.fields = sanitizeFields({\n config: payloadConfig,\n fields: block.fields,\n requireFieldLevelRichTextEditor: true,\n validRelationships,\n })\n })\n\n // find block used in this node\n const block = props.blocks.find((block) => block.slug === blockFieldData.blockType)\n if (!block || !block?.fields?.length || !blockFieldData) {\n return\n }\n\n recurseNestedFields({\n context,\n currentDepth,\n data: blockFieldData,\n depth,\n editorPopulationPromises,\n fieldPromises,\n fields: block.fields,\n findMany,\n flattenLocales,\n overrideAccess,\n populationPromises,\n req,\n showHiddenFields,\n // The afterReadPromise gets its data from looking for field.name inside the siblingDoc. Thus, here we cannot pass the whole document's siblingDoc, but only the siblingDoc (sibling fields) of the current field.\n siblingDoc: blockFieldData,\n })\n }\n\n return blockPopulationPromise\n}\n"],"names":["sanitizeFields","recurseNestedFields","blockPopulationPromiseHOC","props","blockPopulationPromise","context","currentDepth","depth","editorPopulationPromises","fieldPromises","findMany","flattenLocales","node","overrideAccess","populationPromises","req","showHiddenFields","siblingDoc","blocks","blockFieldData","fields","payloadConfig","payload","config","validRelationships","collections","map","c","slug","forEach","block","requireFieldLevelRichTextEditor","find","blockType","length","data"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,SAASA,cAAc,QAAQ,iBAAgB;AAM/C,SAASC,mBAAmB,QAAQ,2CAA0C;AAE9E,OAAO,MAAMC,4BAA4B,CACvCC;IAEA,MAAMC,yBAAiE,CAAC,EACtEC,OAAO,EACPC,YAAY,EACZC,KAAK,EACLC,wBAAwB,EACxBC,aAAa,EACbC,QAAQ,EACRC,cAAc,EACdC,IAAI,EACJC,cAAc,EACdC,kBAAkB,EAClBC,GAAG,EACHC,gBAAgB,EAChBC,UAAU,EACX;QACC,MAAMC,SAAkBf,MAAMe,MAAM;QACpC,MAAMC,iBAAiBP,KAAKQ,MAAM;QAElC,uHAAuH;QACvH,MAAMC,gBAAgBN,IAAIO,OAAO,CAACC,MAAM;QACxC,MAAMC,qBAAqBH,cAAcI,WAAW,CAACC,GAAG,CAAC,CAACC,IAAMA,EAAEC,IAAI,KAAK,EAAE;QAC7EV,OAAOW,OAAO,CAAC,CAACC;YACdA,MAAMV,MAAM,GAAGpB,eAAe;gBAC5BuB,QAAQF;gBACRD,QAAQU,MAAMV,MAAM;gBACpBW,iCAAiC;gBACjCP;YACF;QACF;QAEA,+BAA+B;QAC/B,MAAMM,QAAQ3B,MAAMe,MAAM,CAACc,IAAI,CAAC,CAACF,QAAUA,MAAMF,IAAI,KAAKT,eAAec,SAAS;QAClF,IAAI,CAACH,SAAS,CAACA,OAAOV,QAAQc,UAAU,CAACf,gBAAgB;YACvD;QACF;QAEAlB,oBAAoB;YAClBI;YACAC;YACA6B,MAAMhB;YACNZ;YACAC;YACAC;YACAW,QAAQU,MAAMV,MAAM;YACpBV;YACAC;YACAE;YACAC;YACAC;YACAC;YACA,kNAAkN;YAClNC,YAAYE;QACd;IACF;IAEA,OAAOf;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../../src/field/features/blocks/validate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../../src/field/features/blocks/validate.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAEhE,eAAO,MAAM,kBAAkB,UACtB,kBAAkB,KACxB,eAAe,mBAAmB,CA+DpC,CAAA"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { buildStateFromSchema } from '@payloadcms/ui/forms/buildStateFromSchema';
|
|
1
2
|
import { sanitizeFields } from 'payload/config';
|
|
2
3
|
export const blockValidationHOC = (props)=>{
|
|
3
|
-
|
|
4
|
+
return async ({ node, validation })=>{
|
|
4
5
|
const blockFieldData = node.fields;
|
|
5
6
|
const blocks = props.blocks;
|
|
6
|
-
const { options: { req, req: { payload: { config } } } } = validation;
|
|
7
|
+
const { options: { id, operation, preferences, req, req: { payload: { config } } } } = validation;
|
|
7
8
|
// Sanitize block's fields here. This is done here and not in the feature, because the payload config is available here
|
|
8
9
|
const validRelationships = config.collections.map((c)=>c.slug) || [];
|
|
9
10
|
blocks.forEach((block)=>{
|
|
@@ -20,31 +21,28 @@ export const blockValidationHOC = (props)=>{
|
|
|
20
21
|
if (!block) {
|
|
21
22
|
return 'Block not found';
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
siblingData: validation.options.siblingData
|
|
39
|
-
});
|
|
40
|
-
if (validationResult !== true) {
|
|
41
|
-
return validationResult;
|
|
42
|
-
}
|
|
24
|
+
/**
|
|
25
|
+
* Run buildStateFromSchema as that properly validates block and block sub-fields
|
|
26
|
+
*/ const result = await buildStateFromSchema({
|
|
27
|
+
id,
|
|
28
|
+
data: blockFieldData,
|
|
29
|
+
fieldSchema: block.fields,
|
|
30
|
+
operation: operation === 'create' || operation === 'update' ? operation : 'update',
|
|
31
|
+
preferences,
|
|
32
|
+
req,
|
|
33
|
+
siblingData: blockFieldData
|
|
34
|
+
});
|
|
35
|
+
let errorPaths = [];
|
|
36
|
+
for(const fieldKey in result){
|
|
37
|
+
if (result[fieldKey].errorPaths) {
|
|
38
|
+
errorPaths = errorPaths.concat(result[fieldKey].errorPaths);
|
|
43
39
|
}
|
|
44
40
|
}
|
|
41
|
+
if (errorPaths.length) {
|
|
42
|
+
return 'Block validation failed: ' + errorPaths.join(', ');
|
|
43
|
+
}
|
|
45
44
|
return true;
|
|
46
45
|
};
|
|
47
|
-
return blockValidation;
|
|
48
46
|
};
|
|
49
47
|
|
|
50
48
|
//# sourceMappingURL=validate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/field/features/blocks/validate.ts"],"sourcesContent":["import type { Block } from 'payload/types'\n\nimport { sanitizeFields } from 'payload/config'\n\nimport type { NodeValidation } from '../types.js'\nimport type { BlocksFeatureProps } from './feature.server.js'\nimport type { SerializedBlockNode } from './nodes/BlocksNode.js'\n\nexport const blockValidationHOC = (\n props: BlocksFeatureProps,\n): NodeValidation<SerializedBlockNode> => {\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/field/features/blocks/validate.ts"],"sourcesContent":["import type { Block } from 'payload/types'\n\nimport { buildStateFromSchema } from '@payloadcms/ui/forms/buildStateFromSchema'\nimport { sanitizeFields } from 'payload/config'\n\nimport type { NodeValidation } from '../types.js'\nimport type { BlocksFeatureProps } from './feature.server.js'\nimport type { SerializedBlockNode } from './nodes/BlocksNode.js'\n\nexport const blockValidationHOC = (\n props: BlocksFeatureProps,\n): NodeValidation<SerializedBlockNode> => {\n return async ({ node, validation }) => {\n const blockFieldData = node.fields\n const blocks: Block[] = props.blocks\n\n const {\n options: {\n id,\n operation,\n preferences,\n req,\n req: {\n payload: { config },\n },\n },\n } = validation\n\n // Sanitize block's fields here. This is done here and not in the feature, because the payload config is available here\n const validRelationships = config.collections.map((c) => c.slug) || []\n blocks.forEach((block) => {\n block.fields = sanitizeFields({\n config,\n fields: block.fields,\n requireFieldLevelRichTextEditor: true,\n validRelationships,\n })\n })\n\n // find block\n const block = props.blocks.find((block) => block.slug === blockFieldData.blockType)\n\n // validate block\n if (!block) {\n return 'Block not found'\n }\n\n /**\n * Run buildStateFromSchema as that properly validates block and block sub-fields\n */\n\n const result = await buildStateFromSchema({\n id,\n data: blockFieldData,\n fieldSchema: block.fields,\n operation: operation === 'create' || operation === 'update' ? operation : 'update',\n preferences,\n req,\n siblingData: blockFieldData,\n })\n\n let errorPaths = []\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 'Block validation failed: ' + errorPaths.join(', ')\n }\n\n return true\n }\n}\n"],"names":["buildStateFromSchema","sanitizeFields","blockValidationHOC","props","node","validation","blockFieldData","fields","blocks","options","id","operation","preferences","req","payload","config","validRelationships","collections","map","c","slug","forEach","block","requireFieldLevelRichTextEditor","find","blockType","result","data","fieldSchema","si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UAAU;YAC5D;QACF;QAEA,IAAIA,WAAWG,MAAM,EAAE;YACrB,OAAO,8BAA8BH,WAAWI,IAAI,CAAC;QACvD;QAEA,OAAO;IACT;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature.server.d.ts","sourceRoot":"","sources":["../../../../src/field/features/heading/feature.server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"feature.server.d.ts","sourceRoot":"","sources":["../../../../src/field/features/heading/feature.server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAKxD,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAA;AAOhE,MAAM,MAAM,mBAAmB,GAAG;IAChC,mBAAmB,CAAC,EAAE,cAAc,EAAE,CAAA;CACvC,CAAA;AAED,eAAO,MAAM,cAAc,EAAE,6BAA6B,CACxD,mBAAmB,EACnB,mBAAmB,CA2CpB,CAAA"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import lexicalRichTextImport from '@lexical/rich-text';
|
|
2
2
|
const { HeadingNode } = lexicalRichTextImport;
|
|
3
3
|
import { convertLexicalNodesToHTML } from '../converters/html/converter/index.js';
|
|
4
|
+
import { createNode } from '../typeUtilities.js';
|
|
4
5
|
import { HeadingFeatureClientComponent } from './feature.client.js';
|
|
5
6
|
import { MarkdownTransformer } from './markdownTransformer.js';
|
|
6
7
|
export const HeadingFeature = (props)=>{
|
|
@@ -19,12 +20,12 @@ export const HeadingFeature = (props)=>{
|
|
|
19
20
|
feature: ()=>{
|
|
20
21
|
return {
|
|
21
22
|
ClientComponent: HeadingFeatureClientComponent,
|
|
23
|
+
clientFeatureProps: props,
|
|
22
24
|
markdownTransformers: [
|
|
23
25
|
MarkdownTransformer(enabledHeadingSizes)
|
|
24
26
|
],
|
|
25
27
|
nodes: [
|
|
26
|
-
{
|
|
27
|
-
type: HeadingNode.getType(),
|
|
28
|
+
createNode({
|
|
28
29
|
converters: {
|
|
29
30
|
html: {
|
|
30
31
|
converter: async ({ converters, node, parent, payload })=>{
|
|
@@ -45,7 +46,7 @@ export const HeadingFeature = (props)=>{
|
|
|
45
46
|
}
|
|
46
47
|
},
|
|
47
48
|
node: HeadingNode
|
|
48
|
-
}
|
|
49
|
+
})
|
|
49
50
|
],
|
|
50
51
|
serverFeatureProps: props
|
|
51
52
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/field/features/heading/feature.server.ts"],"sourcesContent":["import type { HeadingTagType
|
|
1
|
+
{"version":3,"sources":["../../../../src/field/features/heading/feature.server.ts"],"sourcesContent":["import type { HeadingTagType } from '@lexical/rich-text'\n\nimport lexicalRichTextImport from '@lexical/rich-text'\nconst { HeadingNode } = lexicalRichTextImport\n\nimport type { FeatureProviderProviderServer } from '../types.js'\n\nimport { convertLexicalNodesToHTML } from '../converters/html/converter/index.js'\nimport { createNode } from '../typeUtilities.js'\nimport { HeadingFeatureClientComponent } from './feature.client.js'\nimport { MarkdownTransformer } from './markdownTransformer.js'\n\nexport type HeadingFeatureProps = {\n enabledHeadingSizes?: HeadingTagType[]\n}\n\nexport const HeadingFeature: FeatureProviderProviderServer<\n HeadingFeatureProps,\n HeadingFeatureProps\n> = (props) => {\n if (!props) {\n props = {}\n }\n\n const { enabledHeadingSizes = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] } = props\n\n return {\n feature: () => {\n return {\n ClientComponent: HeadingFeatureClientComponent,\n clientFeatureProps: props,\n markdownTransformers: [MarkdownTransformer(enabledHeadingSizes)],\n nodes: [\n createNode({\n converters: {\n html: {\n converter: async ({ converters, node, parent, payload }) => {\n const childrenText = await convertLexicalNodesToHTML({\n converters,\n lexicalNodes: node.children,\n parent: {\n ...node,\n parent,\n },\n payload,\n })\n\n return '<' + node?.tag + '>' + childrenText + '</' + node?.tag + '>'\n },\n nodeTypes: [HeadingNode.getType()],\n },\n },\n node: HeadingNode,\n }),\n ],\n serverFeatureProps: props,\n }\n },\n key: 'heading',\n serverFeatureProps: props,\n }\n}\n"],"names":["lexicalRichTextImport","HeadingNode","convertLexicalNodesToHTML","createNode","HeadingFeatureClientComponent","MarkdownTransformer","HeadingFeature","props","enabledHeadingSizes","feature","ClientComponent","clientFeatureProps","markdownTransformers","nodes","converters","html","converter","node","parent","payload","childrenText","lexicalNodes","children","tag","nodeTypes","getType","serverFeatureProps","key"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAOA,2BAA2B,qBAAoB;AACtD,MAAM,EAAEC,WAAW,EAAE,GAAGD;AAIxB,SAASE,yBAAyB,QAAQ,wCAAuC;AACjF,SAASC,UAAU,QAAQ,sBAAqB;AAChD,SAASC,6BAA6B,QAAQ,sBAAqB;AACnE,SAASC,mBAAmB,QAAQ,2BAA0B;AAM9D,OAAO,MAAMC,iBAGT,CAACC;IACH,IAAI,CAACA,OAAO;QACVA,QAAQ,CAAC;IACX;IAEA,MAAM,EAAEC,sBAAsB;QAAC;QAAM;QAAM;QAAM;QAAM;QAAM;KAAK,EAAE,GAAGD;IAEvE,OAAO;QACLE,SAAS;YACP,OAAO;gBACLC,iBAAiBN;gBACjBO,oBAAoBJ;gBACpBK,sBAAsB;oBAACP,oBAAoBG;iBAAqB;gBAChEK,OAAO;oBACLV,WAAW;wBACTW,YAAY;4BACVC,MAAM;gCACJC,WAAW,OAAO,EAAEF,UAAU,EAAEG,IAAI,EAAEC,MAAM,EAAEC,OAAO,EAAE;oCACrD,MAAMC,eAAe,MAAMlB,0BAA0B;wCACnDY;wCACAO,cAAcJ,KAAKK,QAAQ;wCAC3BJ,QAAQ;4CACN,GAAGD,IAAI;4CACPC;wCACF;wCACAC;oCACF;oCAEA,OAAO,MAAMF,MAAMM,MAAM,MAAMH,eAAe,OAAOH,MAAMM,MAAM;gCACnE;gCACAC,WAAW;oCAACvB,YAAYwB,OAAO;iCAAG;4BACpC;wBACF;wBACAR,MAAMhB;oBACR;iBACD;gBACDyB,oBAAoBnB;YACtB;QACF;QACAoB,KAAK;QACLD,oBAAoBnB;IACtB;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"feature.server.d.ts","sourceRoot":"","sources":["../../../../src/field/features/horizontalrule/feature.server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"feature.server.d.ts","sourceRoot":"","sources":["../../../../src/field/features/horizontalrule/feature.server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAA;AAOhE,eAAO,MAAM,qBAAqB,EAAE,6BAA6B,CAAC,SAAS,EAAE,SAAS,CA4BrF,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createNode } from '../typeUtilities.js';
|
|
1
2
|
import { HorizontalRuleFeatureClientComponent } from './feature.client.js';
|
|
2
3
|
import { MarkdownTransformer } from './markdownTransformer.js';
|
|
3
4
|
import { HorizontalRuleNode } from './nodes/HorizontalRuleNode.js';
|
|
@@ -11,7 +12,7 @@ export const HorizontalRuleFeature = (props)=>{
|
|
|
11
12
|
MarkdownTransformer
|
|
12
13
|
],
|
|
13
14
|
nodes: [
|
|
14
|
-
{
|
|
15
|
+
createNode({
|
|
15
16
|
converters: {
|
|
16
17
|
html: {
|
|
17
18
|
converter: ()=>{
|
|
@@ -23,7 +24,7 @@ export const HorizontalRuleFeature = (props)=>{
|
|
|
23
24
|
}
|
|
24
25
|
},
|
|
25
26
|
node: HorizontalRuleNode
|
|
26
|
-
}
|
|
27
|
+
})
|
|
27
28
|
],
|
|
28
29
|
serverFeatureProps: props
|
|
29
30
|
};
|