@payloadcms/richtext-lexical 4.0.0-internal.5f0cd13 → 4.0.0-internal.688c4d0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/assets.d.js +2 -0
- package/dist/@types/assets.d.js.map +1 -0
- package/dist/cell/rscEntry.d.ts.map +1 -1
- package/dist/cell/rscEntry.js +5 -5
- package/dist/cell/rscEntry.js.map +1 -1
- package/dist/exports/client/Field-VYBSMSRY.js +2 -0
- package/dist/exports/client/Field-VYBSMSRY.js.map +7 -0
- package/dist/exports/client/bundled.css +1 -1
- package/dist/exports/client/chunk-5VIL27GI.js +2 -0
- package/dist/exports/client/chunk-5VIL27GI.js.map +7 -0
- package/dist/exports/client/chunk-ESITTE3C.js +2 -0
- package/dist/exports/client/chunk-ESITTE3C.js.map +7 -0
- package/dist/exports/client/chunk-UD4DQ4AK.js +2 -0
- package/dist/exports/client/chunk-UD4DQ4AK.js.map +7 -0
- package/dist/exports/client/{component-HKTAZ77E.js → component-PHZQBOJE.js} +2 -2
- package/dist/exports/client/componentInline-H24N7GUG.js +2 -0
- package/dist/exports/client/index.d.ts +1 -0
- package/dist/exports/client/index.d.ts.map +1 -1
- package/dist/exports/client/index.js +25 -25
- package/dist/exports/client/index.js.map +4 -4
- package/dist/exports/server/rsc.browser.d.ts +11 -0
- package/dist/exports/server/rsc.browser.d.ts.map +1 -0
- package/dist/exports/server/rsc.browser.js +10 -0
- package/dist/exports/server/rsc.browser.js.map +1 -0
- package/dist/features/blocks/client/component/index.d.ts +1 -0
- package/dist/features/blocks/client/component/index.d.ts.map +1 -1
- package/dist/features/blocks/client/component/index.js +16 -8
- package/dist/features/blocks/client/component/index.js.map +1 -1
- package/dist/features/blocks/client/componentInline/index.d.ts +1 -0
- package/dist/features/blocks/client/componentInline/index.d.ts.map +1 -1
- package/dist/features/blocks/client/componentInline/index.js +15 -7
- 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 +4 -2
- package/dist/features/blocks/client/index.js.map +1 -1
- package/dist/features/blocks/premade/CodeBlock/Component/Block.d.ts.map +1 -1
- package/dist/features/blocks/premade/CodeBlock/Component/Block.js +1 -0
- package/dist/features/blocks/premade/CodeBlock/Component/Block.js.map +1 -1
- package/dist/features/blocks/server/index.d.ts.map +1 -1
- package/dist/features/blocks/server/index.js +6 -8
- package/dist/features/blocks/server/index.js.map +1 -1
- package/dist/features/blocks/server/schema.d.ts +5 -5
- package/dist/features/blocks/server/schema.d.ts.map +1 -1
- package/dist/features/blocks/server/schema.js +26 -23
- package/dist/features/blocks/server/schema.js.map +1 -1
- package/dist/features/converters/lexicalToHtml/async/types.d.ts +13 -15
- package/dist/features/converters/lexicalToHtml/async/types.d.ts.map +1 -1
- package/dist/features/converters/lexicalToHtml/async/types.js.map +1 -1
- package/dist/features/converters/lexicalToHtml/sync/types.d.ts +13 -15
- package/dist/features/converters/lexicalToHtml/sync/types.d.ts.map +1 -1
- package/dist/features/converters/lexicalToHtml/sync/types.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/Component/index.d.ts +2 -2
- package/dist/features/converters/lexicalToJSX/Component/index.d.ts.map +1 -1
- package/dist/features/converters/lexicalToJSX/Component/index.js +5 -4
- package/dist/features/converters/lexicalToJSX/Component/index.js.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/types.d.ts +12 -14
- package/dist/features/converters/lexicalToJSX/converter/types.d.ts.map +1 -1
- package/dist/features/converters/lexicalToJSX/converter/types.js.map +1 -1
- package/dist/features/converters/lexicalToPlaintext/sync/types.d.ts +12 -14
- package/dist/features/converters/lexicalToPlaintext/sync/types.d.ts.map +1 -1
- package/dist/features/converters/lexicalToPlaintext/sync/types.js.map +1 -1
- package/dist/features/experimental_table/server/schema.d.ts.map +1 -1
- package/dist/features/experimental_table/server/schema.js +6 -3
- package/dist/features/experimental_table/server/schema.js.map +1 -1
- package/dist/features/link/server/schema.d.ts.map +1 -1
- package/dist/features/link/server/schema.js +10 -7
- package/dist/features/link/server/schema.js.map +1 -1
- package/dist/features/relationship/server/schema.d.ts.map +1 -1
- package/dist/features/relationship/server/schema.js +5 -8
- package/dist/features/relationship/server/schema.js.map +1 -1
- package/dist/features/toolbars/shared/ToolbarDropdown/index.js.map +1 -1
- package/dist/features/upload/client/component/index.css +2 -2
- package/dist/features/upload/server/schema.d.ts +4 -4
- package/dist/features/upload/server/schema.d.ts.map +1 -1
- package/dist/features/upload/server/schema.js +34 -18
- package/dist/features/upload/server/schema.js.map +1 -1
- package/dist/field/bundled.css +1 -1
- package/dist/field/clientEntry.d.ts +29 -0
- package/dist/field/clientEntry.d.ts.map +1 -0
- package/dist/field/clientEntry.js +86 -0
- package/dist/field/clientEntry.js.map +1 -0
- package/dist/field/index.css +13 -12
- package/dist/field/index.js +1 -1
- package/dist/field/index.js.map +1 -1
- package/dist/field/rscEntry.d.ts.map +1 -1
- package/dist/field/rscEntry.js +2 -0
- package/dist/field/rscEntry.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -4
- package/dist/index.js.map +1 -1
- package/dist/lexical/LexicalEditor.d.ts.map +1 -1
- package/dist/lexical/LexicalEditor.js +36 -2
- package/dist/lexical/LexicalEditor.js.map +1 -1
- package/dist/lexical/LexicalProvider.d.ts.map +1 -1
- package/dist/lexical/LexicalProvider.js +22 -7
- package/dist/lexical/LexicalProvider.js.map +1 -1
- package/dist/lexical/config/client/loader.d.ts.map +1 -1
- package/dist/lexical/config/client/loader.js +5 -1
- package/dist/lexical/config/client/loader.js.map +1 -1
- package/dist/lexical/plugins/DecoratorPlugin/index.js.map +1 -1
- package/dist/types/builtInNodes.d.ts.map +1 -1
- package/dist/types/builtInNodes.js +17 -17
- package/dist/types/builtInNodes.js.map +1 -1
- package/dist/types/index.d.ts +16 -16
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/jsonSchemaHelpers.d.ts +2 -0
- package/dist/types/jsonSchemaHelpers.d.ts.map +1 -1
- package/dist/types/jsonSchemaHelpers.js +7 -3
- package/dist/types/jsonSchemaHelpers.js.map +1 -1
- package/dist/types/nodeTypes.d.ts +51 -9
- package/dist/types/nodeTypes.d.ts.map +1 -1
- package/dist/types/nodeTypes.js +3 -3
- package/dist/types/nodeTypes.js.map +1 -1
- package/dist/types/schema.d.ts.map +1 -1
- package/dist/types/schema.js +12 -2
- package/dist/types/schema.js.map +1 -1
- package/dist/utilities/applyBaseFilterToFields.d.ts.map +1 -1
- package/dist/utilities/applyBaseFilterToFields.js +1 -2
- package/dist/utilities/applyBaseFilterToFields.js.map +1 -1
- package/dist/utilities/buildEditorState.d.ts +17 -3
- package/dist/utilities/buildEditorState.d.ts.map +1 -1
- package/dist/utilities/buildEditorState.js +8 -0
- package/dist/utilities/buildEditorState.js.map +1 -1
- package/dist/utilities/buildInitialState.d.ts +2 -1
- package/dist/utilities/buildInitialState.d.ts.map +1 -1
- package/dist/utilities/buildInitialState.js.map +1 -1
- package/dist/utilities/fieldsDrawer/Drawer.d.ts.map +1 -1
- package/dist/utilities/fieldsDrawer/Drawer.js +19 -10
- package/dist/utilities/fieldsDrawer/Drawer.js.map +1 -1
- package/dist/utilities/fieldsDrawer/DrawerContent.d.ts +4 -1
- package/dist/utilities/fieldsDrawer/DrawerContent.d.ts.map +1 -1
- package/dist/utilities/fieldsDrawer/DrawerContent.js +8 -7
- package/dist/utilities/fieldsDrawer/DrawerContent.js.map +1 -1
- package/dist/utilities/fieldsDrawer/index.css +16 -0
- package/dist/utilities/fieldsDrawer/useDrawerSubmit.d.ts +29 -0
- package/dist/utilities/fieldsDrawer/useDrawerSubmit.d.ts.map +1 -0
- package/dist/utilities/fieldsDrawer/useDrawerSubmit.js +97 -0
- package/dist/utilities/fieldsDrawer/useDrawerSubmit.js.map +1 -0
- package/dist/utilities/generateImportMap.d.ts.map +1 -1
- package/dist/utilities/generateImportMap.js +7 -3
- package/dist/utilities/generateImportMap.js.map +1 -1
- package/dist/utilities/upgradeLexicalData/upgradeDocumentFieldsRecursively.js +1 -1
- package/dist/utilities/upgradeLexicalData/upgradeDocumentFieldsRecursively.js.map +1 -1
- package/package.json +9 -8
- package/dist/exports/client/Field-G5Z2HM5Y.js +0 -2
- package/dist/exports/client/Field-G5Z2HM5Y.js.map +0 -7
- package/dist/exports/client/chunk-6QWQ7JV4.js +0 -2
- package/dist/exports/client/chunk-6QWQ7JV4.js.map +0 -7
- package/dist/exports/client/chunk-INBEEENE.js +0 -2
- package/dist/exports/client/chunk-INBEEENE.js.map +0 -7
- package/dist/exports/client/chunk-UAKNDD6R.js +0 -2
- package/dist/exports/client/chunk-UAKNDD6R.js.map +0 -7
- package/dist/exports/client/componentInline-D3A6OW76.js +0 -2
- /package/dist/exports/client/{component-HKTAZ77E.js.map → component-PHZQBOJE.js.map} +0 -0
- /package/dist/exports/client/{componentInline-D3A6OW76.js.map → componentInline-H24N7GUG.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/features/link/server/schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AACpD,OAAO,KAAK,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/features/link/server/schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AACpD,OAAO,KAAK,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAK3D,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,6BAA6B,CAAA;AAC/E,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,sBAAsB,CAAA;AAExE,MAAM,MAAM,UAAU,GAAG;IACvB,6DAA6D;IAC7D,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IACpB,GAAG,CAAC,EAAE;QACJ,UAAU,EAAE,MAAM,CAAA;QAClB,yEAAyE;QACzE,KAAK,EAAE;YAAE,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;YAAC,EAAE,EAAE,qBAAqB,CAAA;SAAE,GAAG,qBAAqB,CAAA;KACnF,GAAG,IAAI,CAAA;IACR,QAAQ,EAAE,QAAQ,GAAG,UAAU,CAAA;IAC/B,MAAM,EAAE,OAAO,CAAA;IACf,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,CAAA;AAED,MAAM,WAAW,kBAAkB,CACjC,SAAS,SAAS,qBAAqB,GAAG,qBAAqB,EAC/D,OAAO,GAAG,UAAU,CACpB,SAAQ,4BAA4B,CAAC,SAAS,CAAC;IAC/C,MAAM,EAAE,OAAO,CAAA;IACf,mEAAmE;IACnE,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,sBAAsB,CACrC,SAAS,SAAS,qBAAqB,GAAG,qBAAqB,EAC/D,OAAO,GAAG,UAAU,CACpB,SAAQ,4BAA4B,CAAC,SAAS,CAAC;IAC/C,MAAM,EAAE,OAAO,CAAA;IACf,IAAI,EAAE,UAAU,CAAA;CACjB;AAqHD,eAAO,MAAM,wBAAwB,GAClC,4BAA4B,KAAK,EAAE,KAAG,YActC,CAAA;AAEH,eAAO,MAAM,4BAA4B,GACtC,4BAA4B,KAAK,EAAE,KAAG,YAatC,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createHash } from 'crypto';
|
|
1
2
|
import { fieldsToJSONSchema, flattenAllFields } from 'payload';
|
|
2
3
|
/**
|
|
3
4
|
* MUST stay byte-for-byte in sync with the runtime `LinkFields`, `SerializedLinkNode`,
|
|
@@ -91,15 +92,18 @@ const buildLinkFieldsJSONSchema = (sanitizedFieldsWithoutText, {
|
|
|
91
92
|
type: 'string'
|
|
92
93
|
}
|
|
93
94
|
},
|
|
94
|
-
|
|
95
|
+
// `linkType`/`newTab` are already in `userFieldsSchema.required`; use Set to dedupe,
|
|
96
|
+
// so `required` stays unique (draft 2020-12 enforces `uniqueItems`).
|
|
97
|
+
required: [...new Set(['linkType', 'newTab', ...userFieldsSchema.required])]
|
|
95
98
|
};
|
|
96
99
|
};
|
|
97
100
|
/** Fields auto-attached by `LinkFeature` (see `transformExtraFields`). */
|
|
98
101
|
const STANDARD_LINK_FIELD_NAMES = new Set(['doc', 'linkType', 'newTab', 'url']);
|
|
102
|
+
const hashLinkFields = schema => createHash('sha256').update(JSON.stringify(schema)).digest('hex').slice(0, 8).toUpperCase();
|
|
99
103
|
/**
|
|
100
|
-
* With custom link fields, emit a
|
|
101
|
-
*
|
|
102
|
-
*
|
|
104
|
+
* With custom link fields, emit a `LexicalLinkFields_<hash>` interface (hashed by its own content)
|
|
105
|
+
* so the link node picks up their real shape. Without any, reuse the default `LexicalLinkFields` for
|
|
106
|
+
* cross-alias assignability.
|
|
103
107
|
*/
|
|
104
108
|
const resolveLinkFieldsRef = (sanitizedFieldsWithoutText, args) => {
|
|
105
109
|
const fieldsSchema = buildLinkFieldsJSONSchema(sanitizedFieldsWithoutText, args);
|
|
@@ -110,12 +114,11 @@ const resolveLinkFieldsRef = (sanitizedFieldsWithoutText, args) => {
|
|
|
110
114
|
fieldsTypeName: 'LexicalLinkFields'
|
|
111
115
|
};
|
|
112
116
|
}
|
|
113
|
-
const
|
|
114
|
-
const fieldsTypeName = `LexicalLinkFields_${editorHash}`;
|
|
117
|
+
const fieldsTypeName = `LexicalLinkFields_${hashLinkFields(fieldsSchema)}`;
|
|
115
118
|
args.interfaceNameDefinitions.set(fieldsTypeName, fieldsSchema);
|
|
116
119
|
return {
|
|
117
120
|
fieldsRef: {
|
|
118
|
-
$ref:
|
|
121
|
+
$ref: `#/$defs/${fieldsTypeName}`
|
|
119
122
|
},
|
|
120
123
|
fieldsTypeName
|
|
121
124
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","names":["fieldsToJSONSchema","flattenAllFields","LINK_NODES_TS","buildLinkFieldsJSONSchema","sanitizedFieldsWithoutText","collectionIDFieldTypes","config","i18n","interfaceNameDefinitions","typeStringDefinitions","flattenedExtraFields","fields","userFieldsSchema","length","properties","required","type","additionalProperties","doc","oneOf","relationTo","value","id","linkType","enum","newTab","url","STANDARD_LINK_FIELD_NAMES","Set","resolveLinkFieldsRef","args","fieldsSchema","hasUserExtras","some","field","has","name","fieldsRef","fieldsTypeName","editorHash","nodeUnionName","replace","set","$ref","createLinkNodeJSONSchema","elementNodeSchema","add","nodeType","tsType","createAutoLinkNodeJSONSchema"],"sources":["../../../../src/features/link/server/schema.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema'\nimport type { SerializedLexicalNode } from 'lexical'\nimport type { DefaultDocumentIDType, Field } from 'payload'\n\nimport { fieldsToJSONSchema, flattenAllFields } from 'payload'\n\nimport type { SerializedLexicalElementBase } from '../../../types/nodeTypes.js'\nimport type { JSONSchemaArgs, JSONSchemaFn } from '../../typesServer.js'\n\nexport type LinkFields = {\n /** Custom fields added via `LinkFeature`'s `fields` prop. */\n [k: string]: unknown\n doc?: {\n relationTo: string\n /** Document ID, or the full doc when populated by the afterRead hook. */\n value: { [k: string]: unknown; id: DefaultDocumentIDType } | DefaultDocumentIDType\n } | null\n linkType: 'custom' | 'internal'\n newTab: boolean\n url?: string\n}\n\nexport interface SerializedLinkNode<\n TChildren extends SerializedLexicalNode = SerializedLexicalNode,\n TFields = LinkFields,\n> extends SerializedLexicalElementBase<TChildren> {\n fields: TFields\n /** @todo make required in 4.0 and type AutoLinkNode differently */\n id?: string\n type: 'link'\n}\n\nexport interface SerializedAutoLinkNode<\n TChildren extends SerializedLexicalNode = SerializedLexicalNode,\n TFields = LinkFields,\n> extends SerializedLexicalElementBase<TChildren> {\n fields: TFields\n type: 'autolink'\n}\n\n/**\n * MUST stay byte-for-byte in sync with the runtime `LinkFields`, `SerializedLinkNode`,\n * and `SerializedAutoLinkNode` declared above.\n */\nconst LINK_NODES_TS = `export interface LexicalLinkFields {\n [k: string]: unknown;\n doc?: {\n relationTo: string;\n value: Config['db']['defaultIDType'] | { [k: string]: unknown; id: Config['db']['defaultIDType'] };\n } | null;\n linkType: 'custom' | 'internal';\n newTab: boolean;\n url?: string;\n}\nexport interface SerializedLinkNode<TChildren, TFields = LexicalLinkFields> extends SerializedLexicalElementBase<TChildren> {\n type: 'link';\n fields: TFields;\n id?: string;\n}\nexport interface SerializedAutoLinkNode<TChildren, TFields = LexicalLinkFields> extends SerializedLexicalElementBase<TChildren> {\n type: 'autolink';\n fields: TFields;\n}`\n\nconst buildLinkFieldsJSONSchema = (\n sanitizedFieldsWithoutText: Field[],\n {\n collectionIDFieldTypes,\n config,\n i18n,\n interfaceNameDefinitions,\n typeStringDefinitions,\n }: JSONSchemaArgs,\n): JSONSchema4 => {\n const flattenedExtraFields = flattenAllFields({ fields: sanitizedFieldsWithoutText })\n const userFieldsSchema =\n flattenedExtraFields.length > 0 && config\n ? fieldsToJSONSchema({\n collectionIDFieldTypes,\n config,\n fields: flattenedExtraFields,\n i18n,\n interfaceNameDefinitions,\n typeStringDefinitions,\n })\n : { properties: {}, required: [] }\n\n return {\n type: 'object',\n additionalProperties: false,\n properties: {\n ...userFieldsSchema.properties,\n doc: {\n oneOf: [\n {\n type: 'object',\n additionalProperties: false,\n properties: {\n relationTo: { type: 'string' },\n value: {\n oneOf: [\n { type: 'string' },\n { type: 'number' },\n // Populated form (afterRead inflates `value` into the doc).\n {\n type: 'object',\n additionalProperties: true,\n properties: { id: { type: ['string', 'number'] } },\n required: ['id'],\n },\n ],\n },\n },\n required: ['relationTo', 'value'],\n },\n { type: 'null' },\n ],\n },\n linkType: { type: 'string', enum: ['custom', 'internal'] },\n newTab: { type: 'boolean' },\n url: { type: 'string' },\n },\n required: ['linkType', 'newTab', ...userFieldsSchema.required],\n }\n}\n\n/** Fields auto-attached by `LinkFeature` (see `transformExtraFields`). */\nconst STANDARD_LINK_FIELD_NAMES = new Set(['doc', 'linkType', 'newTab', 'url'])\n\n/**\n * With custom link fields, emit a per-editor `LexicalLinkFields_<hash>`\n * interface so the link node picks up their real shape. Without any,\n * reuse the default `LexicalLinkFields` for cross-alias assignability.\n */\nconst resolveLinkFieldsRef = (\n sanitizedFieldsWithoutText: Field[],\n args: JSONSchemaArgs,\n): { fieldsRef: JSONSchema4; fieldsTypeName: string } => {\n const fieldsSchema = buildLinkFieldsJSONSchema(sanitizedFieldsWithoutText, args)\n const hasUserExtras = sanitizedFieldsWithoutText.some(\n (field) => 'name' in field && !STANDARD_LINK_FIELD_NAMES.has(field.name),\n )\n if (!hasUserExtras) {\n return { fieldsRef: fieldsSchema, fieldsTypeName: 'LexicalLinkFields' }\n }\n const editorHash = args.nodeUnionName.replace(/^LexicalNodes_/, '')\n const fieldsTypeName = `LexicalLinkFields_${editorHash}`\n args.interfaceNameDefinitions.set(fieldsTypeName, fieldsSchema)\n return { fieldsRef: { $ref: `#/definitions/${fieldsTypeName}` }, fieldsTypeName }\n}\n\nexport const createLinkNodeJSONSchema =\n (sanitizedFieldsWithoutText: Field[]): JSONSchemaFn =>\n (args) => {\n const { elementNodeSchema, nodeUnionName, typeStringDefinitions } = args\n typeStringDefinitions.add(LINK_NODES_TS)\n const { fieldsRef, fieldsTypeName } = resolveLinkFieldsRef(sanitizedFieldsWithoutText, args)\n return elementNodeSchema({\n nodeType: 'link',\n properties: {\n id: { type: 'string' },\n fields: fieldsRef,\n },\n required: ['fields'],\n tsType: `SerializedLinkNode<${nodeUnionName}, ${fieldsTypeName}>`,\n })\n }\n\nexport const createAutoLinkNodeJSONSchema =\n (sanitizedFieldsWithoutText: Field[]): JSONSchemaFn =>\n (args) => {\n const { elementNodeSchema, nodeUnionName, typeStringDefinitions } = args\n typeStringDefinitions.add(LINK_NODES_TS)\n const { fieldsRef, fieldsTypeName } = resolveLinkFieldsRef(sanitizedFieldsWithoutText, args)\n return elementNodeSchema({\n nodeType: 'autolink',\n properties: {\n fields: fieldsRef,\n },\n required: ['fields'],\n tsType: `SerializedAutoLinkNode<${nodeUnionName}, ${fieldsTypeName}>`,\n })\n }\n"],"mappings":"AAIA,SAASA,kBAAkB,EAAEC,gBAAgB,QAAQ;AAoCrD;;;;AAIA,MAAMC,aAAA,GAAgB;;;;;;;;;;;;;;;;;;EAkBpB;AAEF,MAAMC,yBAAA,GAA4BA,CAChCC,0BAAA,EACA;EACEC,sBAAsB;EACtBC,MAAM;EACNC,IAAI;EACJC,wBAAwB;EACxBC;AAAqB,CACN;EAEjB,MAAMC,oBAAA,GAAuBT,gBAAA,CAAiB;IAAEU,MAAA,EAAQP;EAA2B;EACnF,MAAMQ,gBAAA,GACJF,oBAAA,CAAqBG,MAAM,GAAG,KAAKP,MAAA,GAC/BN,kBAAA,CAAmB;IACjBK,sBAAA;IACAC,MAAA;IACAK,MAAA,EAAQD,oBAAA;IACRH,IAAA;IACAC,wBAAA;IACAC;EACF,KACA;IAAEK,UAAA,EAAY,CAAC;IAAGC,QAAA,EAAU;EAAG;EAErC,OAAO;IACLC,IAAA,EAAM;IACNC,oBAAA,EAAsB;IACtBH,UAAA,EAAY;MACV,GAAGF,gBAAA,CAAiBE,UAAU;MAC9BI,GAAA,EAAK;QACHC,KAAA,EAAO,CACL;UACEH,IAAA,EAAM;UACNC,oBAAA,EAAsB;UACtBH,UAAA,EAAY;YACVM,UAAA,EAAY;cAAEJ,IAAA,EAAM;YAAS;YAC7BK,KAAA,EAAO;cACLF,KAAA,EAAO,CACL;gBAAEH,IAAA,EAAM;cAAS,GACjB;gBAAEA,IAAA,EAAM;cAAS;cACjB;cACA;gBACEA,IAAA,EAAM;gBACNC,oBAAA,EAAsB;gBACtBH,UAAA,EAAY;kBAAEQ,EAAA,EAAI;oBAAEN,IAAA,EAAM,CAAC,UAAU;kBAAU;gBAAE;gBACjDD,QAAA,EAAU,CAAC;cACb;YAEJ;UACF;UACAA,QAAA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A;EAC1B,MAAM;IAAEmC,SAAS;IAAEC;EAAc,CAAE,GAAGT,oBAAA,CAAqBzB,0BAAA,EAA4B0B,IAAA;EACvF,OAAOe,iBAAA,CAAkB;IACvBE,QAAA,EAAU;IACVjC,UAAA,EAAY;MACVQ,EAAA,EAAI;QAAEN,IAAA,EAAM;MAAS;MACrBL,MAAA,EAAQ0B;IACV;IACAtB,QAAA,EAAU,CAAC,SAAS;IACpBiC,MAAA,EAAQ,sBAAsBR,aAAA,KAAkBF,cAAA;EAClD;AACF;AAEF,OAAO,MAAMW,4BAAA,GACV7C,0BAAA,IACA0B,IAAA;EACC,MAAM;IAAEe,iBAAiB;IAAEL,aAAa;IAAE/B;EAAqB,CAAE,GAAGqB,IAAA;EACpErB,qBAAA,CAAsBqC,GAAG,CAAC5C,aAAA;EAC1B,MAAM;IAAEmC,SAAS;IAAEC;EAAc,CAAE,GAAGT,oBAAA,CAAqBzB,0BAAA,EAA4B0B,IAAA;EACvF,OAAOe,iBAAA,CAAkB;IACvBE,QAAA,EAAU;IACVjC,UAAA,EAAY;MACVH,MAAA,EAAQ0B;IACV;IACAtB,QAAA,EAAU,CAAC,SAAS;IACpBiC,MAAA,EAAQ,0BAA0BR,aAAA,KAAkBF,cAAA;EACtD;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"schema.js","names":["createHash","fieldsToJSONSchema","flattenAllFields","LINK_NODES_TS","buildLinkFieldsJSONSchema","sanitizedFieldsWithoutText","collectionIDFieldTypes","config","i18n","interfaceNameDefinitions","typeStringDefinitions","flattenedExtraFields","fields","userFieldsSchema","length","properties","required","type","additionalProperties","doc","oneOf","relationTo","value","id","linkType","enum","newTab","url","Set","STANDARD_LINK_FIELD_NAMES","hashLinkFields","schema","update","JSON","stringify","digest","slice","toUpperCase","resolveLinkFieldsRef","args","fieldsSchema","hasUserExtras","some","field","has","name","fieldsRef","fieldsTypeName","set","$ref","createLinkNodeJSONSchema","elementNodeSchema","nodeUnionName","add","nodeType","tsType","createAutoLinkNodeJSONSchema"],"sources":["../../../../src/features/link/server/schema.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema'\nimport type { SerializedLexicalNode } from 'lexical'\nimport type { DefaultDocumentIDType, Field } from 'payload'\n\nimport { createHash } from 'crypto'\nimport { fieldsToJSONSchema, flattenAllFields } from 'payload'\n\nimport type { SerializedLexicalElementBase } from '../../../types/nodeTypes.js'\nimport type { JSONSchemaArgs, JSONSchemaFn } from '../../typesServer.js'\n\nexport type LinkFields = {\n /** Custom fields added via `LinkFeature`'s `fields` prop. */\n [k: string]: unknown\n doc?: {\n relationTo: string\n /** Document ID, or the full doc when populated by the afterRead hook. */\n value: { [k: string]: unknown; id: DefaultDocumentIDType } | DefaultDocumentIDType\n } | null\n linkType: 'custom' | 'internal'\n newTab: boolean\n url?: string\n}\n\nexport interface SerializedLinkNode<\n TChildren extends SerializedLexicalNode = SerializedLexicalNode,\n TFields = LinkFields,\n> extends SerializedLexicalElementBase<TChildren> {\n fields: TFields\n /** @todo make required in 4.0 and type AutoLinkNode differently */\n id?: string\n type: 'link'\n}\n\nexport interface SerializedAutoLinkNode<\n TChildren extends SerializedLexicalNode = SerializedLexicalNode,\n TFields = LinkFields,\n> extends SerializedLexicalElementBase<TChildren> {\n fields: TFields\n type: 'autolink'\n}\n\n/**\n * MUST stay byte-for-byte in sync with the runtime `LinkFields`, `SerializedLinkNode`,\n * and `SerializedAutoLinkNode` declared above.\n */\nconst LINK_NODES_TS = `export interface LexicalLinkFields {\n [k: string]: unknown;\n doc?: {\n relationTo: string;\n value: Config['db']['defaultIDType'] | { [k: string]: unknown; id: Config['db']['defaultIDType'] };\n } | null;\n linkType: 'custom' | 'internal';\n newTab: boolean;\n url?: string;\n}\nexport interface SerializedLinkNode<TChildren, TFields = LexicalLinkFields> extends SerializedLexicalElementBase<TChildren> {\n type: 'link';\n fields: TFields;\n id?: string;\n}\nexport interface SerializedAutoLinkNode<TChildren, TFields = LexicalLinkFields> extends SerializedLexicalElementBase<TChildren> {\n type: 'autolink';\n fields: TFields;\n}`\n\nconst buildLinkFieldsJSONSchema = (\n sanitizedFieldsWithoutText: Field[],\n {\n collectionIDFieldTypes,\n config,\n i18n,\n interfaceNameDefinitions,\n typeStringDefinitions,\n }: JSONSchemaArgs,\n): JSONSchema4 => {\n const flattenedExtraFields = flattenAllFields({ fields: sanitizedFieldsWithoutText })\n const userFieldsSchema =\n flattenedExtraFields.length > 0 && config\n ? fieldsToJSONSchema({\n collectionIDFieldTypes,\n config,\n fields: flattenedExtraFields,\n i18n,\n interfaceNameDefinitions,\n typeStringDefinitions,\n })\n : { properties: {}, required: [] }\n\n return {\n type: 'object',\n additionalProperties: false,\n properties: {\n ...userFieldsSchema.properties,\n doc: {\n oneOf: [\n {\n type: 'object',\n additionalProperties: false,\n properties: {\n relationTo: { type: 'string' },\n value: {\n oneOf: [\n { type: 'string' },\n { type: 'number' },\n // Populated form (afterRead inflates `value` into the doc).\n {\n type: 'object',\n additionalProperties: true,\n properties: { id: { type: ['string', 'number'] } },\n required: ['id'],\n },\n ],\n },\n },\n required: ['relationTo', 'value'],\n },\n { type: 'null' },\n ],\n },\n linkType: { type: 'string', enum: ['custom', 'internal'] },\n newTab: { type: 'boolean' },\n url: { type: 'string' },\n },\n // `linkType`/`newTab` are already in `userFieldsSchema.required`; use Set to dedupe,\n // so `required` stays unique (draft 2020-12 enforces `uniqueItems`).\n required: [...new Set(['linkType', 'newTab', ...userFieldsSchema.required])],\n }\n}\n\n/** Fields auto-attached by `LinkFeature` (see `transformExtraFields`). */\nconst STANDARD_LINK_FIELD_NAMES = new Set(['doc', 'linkType', 'newTab', 'url'])\n\nconst hashLinkFields = (schema: JSONSchema4): string =>\n createHash('sha256').update(JSON.stringify(schema)).digest('hex').slice(0, 8).toUpperCase()\n\n/**\n * With custom link fields, emit a `LexicalLinkFields_<hash>` interface (hashed by its own content)\n * so the link node picks up their real shape. Without any, reuse the default `LexicalLinkFields` for\n * cross-alias assignability.\n */\nconst resolveLinkFieldsRef = (\n sanitizedFieldsWithoutText: Field[],\n args: JSONSchemaArgs,\n): { fieldsRef: JSONSchema4; fieldsTypeName: string } => {\n const fieldsSchema = buildLinkFieldsJSONSchema(sanitizedFieldsWithoutText, args)\n const hasUserExtras = sanitizedFieldsWithoutText.some(\n (field) => 'name' in field && !STANDARD_LINK_FIELD_NAMES.has(field.name),\n )\n if (!hasUserExtras) {\n return { fieldsRef: fieldsSchema, fieldsTypeName: 'LexicalLinkFields' }\n }\n const fieldsTypeName = `LexicalLinkFields_${hashLinkFields(fieldsSchema)}`\n args.interfaceNameDefinitions.set(fieldsTypeName, fieldsSchema)\n return { fieldsRef: { $ref: `#/$defs/${fieldsTypeName}` }, fieldsTypeName }\n}\n\nexport const createLinkNodeJSONSchema =\n (sanitizedFieldsWithoutText: Field[]): JSONSchemaFn =>\n (args) => {\n const { elementNodeSchema, nodeUnionName, typeStringDefinitions } = args\n typeStringDefinitions.add(LINK_NODES_TS)\n const { fieldsRef, fieldsTypeName } = resolveLinkFieldsRef(sanitizedFieldsWithoutText, args)\n return elementNodeSchema({\n nodeType: 'link',\n properties: {\n id: { type: 'string' },\n fields: fieldsRef,\n },\n required: ['fields'],\n tsType: `SerializedLinkNode<${nodeUnionName}, ${fieldsTypeName}>`,\n })\n }\n\nexport const createAutoLinkNodeJSONSchema =\n (sanitizedFieldsWithoutText: Field[]): JSONSchemaFn =>\n (args) => {\n const { elementNodeSchema, nodeUnionName, typeStringDefinitions } = args\n typeStringDefinitions.add(LINK_NODES_TS)\n const { fieldsRef, fieldsTypeName } = resolveLinkFieldsRef(sanitizedFieldsWithoutText, args)\n return elementNodeSchema({\n nodeType: 'autolink',\n properties: {\n fields: fieldsRef,\n },\n required: ['fields'],\n tsType: `SerializedAutoLinkNode<${nodeUnionName}, ${fieldsTypeName}>`,\n })\n }\n"],"mappings":"AAIA,SAASA,UAAU,QAAQ;AAC3B,SAASC,kBAAkB,EAAEC,gBAAgB,QAAQ;AAoCrD;;;;AAIA,MAAM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BjC,0BAAA,EAA4BkC,IAAA;EACvF,OAAOY,iBAAA,CAAkB;IACvBG,QAAA,EAAU;IACVvC,UAAA,EAAY;MACVQ,EAAA,EAAI;QAAEN,IAAA,EAAM;MAAS;MACrBL,MAAA,EAAQkC;IACV;IACA9B,QAAA,EAAU,CAAC,SAAS;IACpBuC,MAAA,EAAQ,sBAAsBH,aAAA,KAAkBL,cAAA;EAClD;AACF;AAEF,OAAO,MAAMS,4BAAA,GACVnD,0BAAA,IACAkC,IAAA;EACC,MAAM;IAAEY,iBAAiB;IAAEC,aAAa;IAAE1C;EAAqB,CAAE,GAAG6B,IAAA;EACpE7B,qBAAA,CAAsB2C,GAAG,CAAClD,aAAA;EAC1B,MAAM;IAAE2C,SAAS;IAAEC;EAAc,CAAE,GAAGT,oBAAA,CAAqBjC,0BAAA,EAA4BkC,IAAA;EACvF,OAAOY,iBAAA,CAAkB;IACvBG,QAAA,EAAU;IACVvC,UAAA,EAAY;MACVH,MAAA,EAAQkC;IACV;IACA9B,QAAA,EAAU,CAAC,SAAS;IACpBuC,MAAA,EAAQ,0BAA0BH,aAAA,KAAkBL,cAAA;EACtD;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/features/relationship/server/schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAE3F,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAA;AACvE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAK1D,MAAM,MAAM,gBAAgB,GAAG;KAC5B,eAAe,IAAI,cAAc,GAAG;QACnC,UAAU,EAAE,eAAe,CAAA;QAC3B,KAAK,EAAE,sBAAsB,CAAC,eAAe,CAAC,GA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MAAM,uBAAuB,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE,oBAAoB,CAAC,CAAC,SAAS;IAC5F,KAAK;CACN,GACG,cAAc,GACd,OAAO,CAAC,cAAc,EAAE,oBAAoB,CAAC,CAAA;AAEjD,MAAM,MAAM,0BAA0B,CAAC,MAAM,SAAS,cAAc,GAAG,uBAAuB,IAAI;KAC/F,KAAK,IAAI,MAAM,GAAG;QACjB,UAAU,EAAE,KAAK,CAAA;QACjB,KAAK,EAAE,sBAAsB,CAAC,KAAK,CAAC,GAAG,MAAM,GAAG,MAAM,CAAA;KACvD;CACF,CAAC,MAAM,CAAC,GAAG;IACV,MAAM,EAAE,oBAAoB,CAAA;IAC5B,IAAI,EAAE,cAAc,CAAA;IACpB,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAcD,eAAO,MAAM,gCAAgC,GAC1C,OAAO,wBAAwB,GAAG,SAAS,KAAG,YAkD9C,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { formatSchema } from '../../../types/jsonSchemaHelpers.js';
|
|
1
|
+
import { formatSchema, versionSchema } from '../../../types/jsonSchemaHelpers.js';
|
|
2
2
|
import { filterEnabledRelationshipCollections } from '../shared/filterEnabledRelationshipCollections.js';
|
|
3
3
|
/** MUST stay byte-for-byte in sync with the runtime `SerializedRelationshipNode` declared above. */
|
|
4
4
|
const SERIALIZED_RELATIONSHIP_NODE_TS = `export type SerializedRelationshipNode<TSlugs extends keyof Config['collections']> = {
|
|
@@ -39,15 +39,14 @@ export const createRelationshipNodeJSONSchema = props => ({
|
|
|
39
39
|
const: slug
|
|
40
40
|
},
|
|
41
41
|
value: {
|
|
42
|
+
description: 'The related document by ID (string or number). Populated to the full document when read at depth > 0.',
|
|
42
43
|
oneOf: [{
|
|
43
44
|
type: idType
|
|
44
45
|
}, {
|
|
45
|
-
$ref:
|
|
46
|
+
$ref: `#/$defs/${slug}`
|
|
46
47
|
}]
|
|
47
48
|
},
|
|
48
|
-
version:
|
|
49
|
-
type: 'integer'
|
|
50
|
-
}
|
|
49
|
+
version: versionSchema
|
|
51
50
|
},
|
|
52
51
|
required: ['format', 'relationTo', 'type', 'value', 'version']
|
|
53
52
|
};
|
|
@@ -62,9 +61,7 @@ export const createRelationshipNodeJSONSchema = props => ({
|
|
|
62
61
|
type: 'string',
|
|
63
62
|
const: 'relationship'
|
|
64
63
|
},
|
|
65
|
-
version:
|
|
66
|
-
type: 'integer'
|
|
67
|
-
}
|
|
64
|
+
version: versionSchema
|
|
68
65
|
},
|
|
69
66
|
required: ['type', 'version']
|
|
70
67
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","names":["formatSchema","filterEnabledRelationshipCollections","SERIALIZED_RELATIONSHIP_NODE_TS","createRelationshipNodeJSONSchema","props","collectionIDFieldTypes","config","typeStringDefinitions","add","enabledCollections","collections","disabledCollections","uploads","variants","map","collection","slug","idType","type","additionalProperties","properties","const","format","relationTo","value","oneOf","$ref","version","required","schema","length","slugUnion","c","join","baseSchema","tsType"],"sources":["../../../../src/features/relationship/server/schema.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema'\nimport type { CollectionSlug, DataFromCollectionSlug, UploadCollectionSlug } from 'payload'\n\nimport type { LexicalElementFormat } from '../../../types/nodeTypes.js'\nimport type { JSONSchemaFn } from '../../typesServer.js'\nimport type { RelationshipFeatureProps } from './index.js'\n\nimport { formatSchema } from '../../../types/jsonSchemaHelpers.js'\nimport { filterEnabledRelationshipCollections } from '../shared/filterEnabledRelationshipCollections.js'\n\nexport type RelationshipData = {\n [TCollectionSlug in CollectionSlug]: {\n relationTo: TCollectionSlug\n value: DataFromCollectionSlug<TCollectionSlug> | number | string\n }\n}[CollectionSlug]\n\n/**\n * Exclude upload collection slugs. This matches runtime behavior, as well as the json schema.\n */\nexport type NonUploadCollectionSlug = [Exclude<CollectionSlug, UploadCollectionSlug>] extends [\n never,\n]\n ? CollectionSlug\n : Exclude<CollectionSlug, UploadCollectionSlug>\n\nexport type SerializedRelationshipNode<TSlugs extends CollectionSlug = NonUploadCollectionSlug> = {\n [TSlug in TSlugs]: {\n relationTo: TSlug\n value: DataFromCollectionSlug<TSlug> | number | string\n }\n}[TSlugs] & {\n format: LexicalElementFormat\n type: 'relationship'\n version: number\n}\n\n/** MUST stay byte-for-byte in sync with the runtime `SerializedRelationshipNode` declared above. */\nconst SERIALIZED_RELATIONSHIP_NODE_TS = `export type SerializedRelationshipNode<TSlugs extends keyof Config['collections']> = {\n type: 'relationship';\n format: LexicalElementFormat;\n version: number;\n} & {\n [TSlug in TSlugs]: {\n relationTo: TSlug;\n value: number | string | Config['collections'][TSlug];\n };\n}[TSlugs];`\n\nexport const createRelationshipNodeJSONSchema =\n (props: RelationshipFeatureProps | undefined): JSONSchemaFn =>\n ({ collectionIDFieldTypes, config, typeStringDefinitions }) => {\n typeStringDefinitions.add(SERIALIZED_RELATIONSHIP_NODE_TS)\n const enabledCollections = config?.collections\n ? filterEnabledRelationshipCollections(config.collections, {\n disabledCollections: props?.disabledCollections,\n enabledCollections: props?.enabledCollections,\n uploads: false,\n })\n : []\n\n const variants: JSONSchema4[] = enabledCollections.map((collection) => {\n const slug = collection.slug\n const idType: 'number' | 'string' = collectionIDFieldTypes[slug] ?? 'string'\n return {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', const: 'relationship' },\n format: formatSchema,\n relationTo: { type: 'string', const: slug },\n value: {\n oneOf: [{ type: idType }, { $ref:
|
|
1
|
+
{"version":3,"file":"schema.js","names":["formatSchema","versionSchema","filterEnabledRelationshipCollections","SERIALIZED_RELATIONSHIP_NODE_TS","createRelationshipNodeJSONSchema","props","collectionIDFieldTypes","config","typeStringDefinitions","add","enabledCollections","collections","disabledCollections","uploads","variants","map","collection","slug","idType","type","additionalProperties","properties","const","format","relationTo","value","description","oneOf","$ref","version","required","schema","length","slugUnion","c","join","baseSchema","tsType"],"sources":["../../../../src/features/relationship/server/schema.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema'\nimport type { CollectionSlug, DataFromCollectionSlug, UploadCollectionSlug } from 'payload'\n\nimport type { LexicalElementFormat } from '../../../types/nodeTypes.js'\nimport type { JSONSchemaFn } from '../../typesServer.js'\nimport type { RelationshipFeatureProps } from './index.js'\n\nimport { formatSchema, versionSchema } from '../../../types/jsonSchemaHelpers.js'\nimport { filterEnabledRelationshipCollections } from '../shared/filterEnabledRelationshipCollections.js'\n\nexport type RelationshipData = {\n [TCollectionSlug in CollectionSlug]: {\n relationTo: TCollectionSlug\n value: DataFromCollectionSlug<TCollectionSlug> | number | string\n }\n}[CollectionSlug]\n\n/**\n * Exclude upload collection slugs. This matches runtime behavior, as well as the json schema.\n */\nexport type NonUploadCollectionSlug = [Exclude<CollectionSlug, UploadCollectionSlug>] extends [\n never,\n]\n ? CollectionSlug\n : Exclude<CollectionSlug, UploadCollectionSlug>\n\nexport type SerializedRelationshipNode<TSlugs extends CollectionSlug = NonUploadCollectionSlug> = {\n [TSlug in TSlugs]: {\n relationTo: TSlug\n value: DataFromCollectionSlug<TSlug> | number | string\n }\n}[TSlugs] & {\n format: LexicalElementFormat\n type: 'relationship'\n version: number\n}\n\n/** MUST stay byte-for-byte in sync with the runtime `SerializedRelationshipNode` declared above. */\nconst SERIALIZED_RELATIONSHIP_NODE_TS = `export type SerializedRelationshipNode<TSlugs extends keyof Config['collections']> = {\n type: 'relationship';\n format: LexicalElementFormat;\n version: number;\n} & {\n [TSlug in TSlugs]: {\n relationTo: TSlug;\n value: number | string | Config['collections'][TSlug];\n };\n}[TSlugs];`\n\nexport const createRelationshipNodeJSONSchema =\n (props: RelationshipFeatureProps | undefined): JSONSchemaFn =>\n ({ collectionIDFieldTypes, config, typeStringDefinitions }) => {\n typeStringDefinitions.add(SERIALIZED_RELATIONSHIP_NODE_TS)\n const enabledCollections = config?.collections\n ? filterEnabledRelationshipCollections(config.collections, {\n disabledCollections: props?.disabledCollections,\n enabledCollections: props?.enabledCollections,\n uploads: false,\n })\n : []\n\n const variants: JSONSchema4[] = enabledCollections.map((collection) => {\n const slug = collection.slug\n const idType: 'number' | 'string' = collectionIDFieldTypes[slug] ?? 'string'\n return {\n type: 'object',\n additionalProperties: false,\n properties: {\n type: { type: 'string', const: 'relationship' },\n format: formatSchema,\n relationTo: { type: 'string', const: slug },\n value: {\n description:\n 'The related document by ID (string or number). Populated to the full document when read at depth > 0.',\n oneOf: [{ type: idType }, { $ref: `#/$defs/${slug}` }],\n },\n version: versionSchema,\n },\n required: ['format', 'relationTo', 'type', 'value', 'version'],\n }\n })\n\n let schema: JSONSchema4\n if (variants.length === 0) {\n schema = {\n type: 'object',\n additionalProperties: true,\n properties: {\n type: { type: 'string', const: 'relationship' },\n version: versionSchema,\n },\n required: ['type', 'version'],\n }\n } else {\n const slugUnion = enabledCollections.map((c) => `'${c.slug}'`).join(' | ')\n const baseSchema: JSONSchema4 = variants.length === 1 ? variants[0]! : { oneOf: variants }\n schema = { ...baseSchema, tsType: `SerializedRelationshipNode<${slugUnion}>` }\n }\n\n return schema\n }\n"],"mappings":"AAOA,SAASA,YAAY,EAAEC,aAAa,QAAQ;AAC5C,SAASC,oCAAoC,QAAQ;AA6BrD;AACA,MAAMC,+BAAA,GAAkC;;;;;;;;;WAS7B;AAEX,OAAO,MAAMC,gCAAA,GACVC,KAAA,IACD,CAAC;EAAEC,sBAAsB;EAAEC,MAAM;EAAEC;AAAqB,CAAE;EACxDA,qBAAA,CAAsBC,GAAG,CAACN,+BAAA;EAC1B,MAAMO,kBAAA,GAAqBH,MAAA,EAAQI,WAAA,GAC/BT,oCAAA,CAAqCK,MAAA,CAAOI,WAAW,EAAE;IACvDC,mBAAA,EAAqBP,KAAA,EAAOO,mBAAA;IAC5BF,kBAAA,EAAoBL,KAAA,EAAOK,kBAAA;IAC3BG,OAAA,EAAS;EACX,KACA,EAAE;EAEN,MAAMC,QAAA,GAA0BJ,kBAAA,CAAmBK,GAAG,CAAEC,UAAA;IACtD,MAAMC,IAAA,GAAOD,U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c","_c","React","useMemo","baseClass","useTranslation","useEditorConfigContext","DropDown","DropDownItem","ToolbarItem","t0","$","active","anchorElem","editor","enabled","iconOnly","item","i18n","fieldProps","t1","featureClientSchemaMap","schemaPath","Component","t2","_jsx","
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","React","useMemo","baseClass","useTranslation","useEditorConfigContext","DropDown","DropDownItem","ToolbarItem","t0","$","active","anchorElem","editor","enabled","iconOnly","item","i18n","fieldProps","t1","featureClientSchemaMap","schemaPath","Component","t2","_jsx","title","key","croppedTitle","label","length","substring","Icon","ChildComponent","undefined","itemKey","tooltip","children","className","MemoToolbarItem","memo","ToolbarDropdown","classNames","group","groupState","itemsContainerClassNames","items","groupKey","renderedItems","map","activeItemKeys","includes","enabledItemKeys","buttonAriaLabel","buttonClassName","filter","Boolean","join","disabled","enabledGroup","dropdownKey"],"sources":["../../../../../src/features/toolbars/shared/ToolbarDropdown/index.tsx"],"sourcesContent":["'use client'\nimport React, { useMemo } from 'react'\n\nconst baseClass = 'toolbar-popup__dropdown'\n\nimport type { LexicalEditor } from 'lexical'\n\nimport { useTranslation } from '@payloadcms/ui'\n\nimport type { ToolbarDropdownGroup, ToolbarGroupItem } from '../../types.js'\nimport type { ToolbarGroupState } from '../useToolbarStates.js'\n\nimport { useEditorConfigContext } from '../../../../lexical/config/client/EditorConfigProvider.js'\nimport './index.css'\nimport { DropDown, DropDownItem } from './DropDown.js'\n\nconst ToolbarItem = ({\n active,\n anchorElem,\n editor,\n enabled,\n iconOnly,\n item,\n}: {\n active?: boolean\n anchorElem: HTMLElement\n editor: LexicalEditor\n enabled?: boolean\n iconOnly?: boolean\n item: ToolbarGroupItem\n}) => {\n const { i18n } = useTranslation<{}, string>()\n const {\n fieldProps: { featureClientSchemaMap, schemaPath },\n } = useEditorConfigContext()\n\n if (item.Component) {\n return (\n item?.Component && (\n <item.Component\n active={active}\n anchorElem={anchorElem}\n editor={editor}\n enabled={enabled}\n item={item}\n key={item.key}\n />\n )\n )\n }\n\n let title = item.key\n let croppedTitle = item.key\n if (item.label) {\n title =\n typeof item.label === 'function'\n ? item.label({ featureClientSchemaMap, i18n, schemaPath })\n : item.label\n }\n if (title.length > 25) {\n croppedTitle = title.substring(0, 25) + '...'\n } else {\n croppedTitle = title\n }\n\n return (\n <DropDownItem\n active={active}\n editor={editor}\n enabled={enabled}\n Icon={item?.ChildComponent ? <item.ChildComponent /> : undefined}\n item={item}\n itemKey={item.key}\n key={item.key}\n tooltip={iconOnly ? title : undefined}\n >\n <span className=\"text\">{croppedTitle}</span>\n </DropDownItem>\n )\n}\n\nconst MemoToolbarItem = React.memo(ToolbarItem)\n\nexport const ToolbarDropdown = ({\n anchorElem,\n classNames,\n editor,\n group,\n groupState,\n Icon,\n itemsContainerClassNames,\n label,\n}: {\n anchorElem: HTMLElement\n classNames?: string[]\n editor: LexicalEditor\n group: ToolbarDropdownGroup\n groupState: ToolbarGroupState\n Icon?: React.FC\n itemsContainerClassNames?: string[]\n label?: string\n}) => {\n const { items, key: groupKey } = group\n\n const renderedItems = useMemo(() => {\n return items?.length\n ? items.map((item) => (\n <MemoToolbarItem\n active={groupState.activeItemKeys.includes(item.key)}\n anchorElem={anchorElem}\n editor={editor}\n enabled={groupState.enabledItemKeys.includes(item.key)}\n iconOnly={group.iconOnly}\n item={item}\n key={item.key}\n />\n ))\n : null\n }, [items, groupState.activeItemKeys, groupState.enabledItemKeys, anchorElem, editor])\n\n return (\n <DropDown\n buttonAriaLabel={`${groupKey} dropdown`}\n buttonClassName={[baseClass, `${baseClass}-${groupKey}`, ...(classNames || [])]\n .filter(Boolean)\n .join(' ')}\n disabled={!groupState.enabledGroup}\n dropdownKey={groupKey}\n Icon={Icon}\n itemsContainerClassNames={[`${baseClass}-items`, ...(itemsContainerClassNames || [])]}\n key={groupKey}\n label={label}\n >\n {renderedItems}\n </DropDown>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AACA,OAAOC,KAAA,IAASC,O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ErFhB,KAAA,EAAOA,KAAA;cAENmB;KAHID,QAAA;AAMX","ignoreList":[]}
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
background: var(--color-bg-menu);
|
|
90
90
|
border-radius: var(--radius-large);
|
|
91
91
|
color: var(--color-text);
|
|
92
|
-
|
|
92
|
+
opacity: 0;
|
|
93
93
|
pointer-events: none;
|
|
94
94
|
white-space: nowrap;
|
|
95
95
|
z-index: 1;
|
|
@@ -151,7 +151,7 @@
|
|
|
151
151
|
.LexicalEditorTheme__upload__divider {
|
|
152
152
|
width: var(--stroke-width-small);
|
|
153
153
|
height: var(--spacer-6);
|
|
154
|
-
background: var(--
|
|
154
|
+
background: var(--color-border);
|
|
155
155
|
flex-shrink: 0;
|
|
156
156
|
}
|
|
157
157
|
|
|
@@ -34,15 +34,15 @@ export type UploadDataImproved<TFields extends JsonObject = JsonObject> = {
|
|
|
34
34
|
value: number | string | TypedUploadCollection[TCollectionSlug];
|
|
35
35
|
};
|
|
36
36
|
}[UploadCollectionSlug];
|
|
37
|
-
export type SerializedUploadNode<TSlugs extends UploadCollectionSlug = UploadCollectionSlug
|
|
37
|
+
export type SerializedUploadNode<TSlugs extends UploadCollectionSlug = UploadCollectionSlug, TFields = {
|
|
38
|
+
[k: string]: unknown;
|
|
39
|
+
}> = {
|
|
38
40
|
[TSlug in TSlugs]: {
|
|
39
41
|
relationTo: TSlug;
|
|
40
42
|
value: DataFromCollectionSlug<TSlug> | number | string;
|
|
41
43
|
};
|
|
42
44
|
}[TSlugs] & {
|
|
43
|
-
fields:
|
|
44
|
-
[k: string]: unknown;
|
|
45
|
-
};
|
|
45
|
+
fields: TFields;
|
|
46
46
|
format: LexicalElementFormat;
|
|
47
47
|
id: string;
|
|
48
48
|
type: 'upload';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../src/features/upload/server/schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,sBAAsB,EAC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G,MAAM,GAAG,qBAAqB,CAAC,eAAe,CAAC,CAAA;KAChE;CACF,CAAC,oBAAoB,CAAC,CAAA;AAEvB,MAAM,MAAM,oBAAoB,CAC9B,MAAM,SAAS,oBAAoB,GAAG,oBAAoB,EAC1D,OAAO,GAAG;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,IAChC;KACD,KAAK,IAAI,MAAM,GAAG;QACjB,UAAU,EAAE,KAAK,CAAA;QACjB,KAAK,EAAE,sBAAsB,CAAC,KAAK,CAAC,GAAG,MAAM,GAAG,MAAM,CAAA;KACvD;CACF,CAAC,MAAM,CAAC,GAAG;IACV,MAAM,EAAE,OAAO,CAAA;IACf,MAAM,EAAE,oBAAoB,CAAA;IAC5B,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,QAAQ,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAmBD,eAAO,MAAM,0BAA0B,GACpC,OAAO,SAAS,GAAG,kBAAkB,KAAG,YA8FxC,CAAA"}
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
+
import { createHash } from 'crypto';
|
|
1
2
|
import { fieldsToJSONSchema, flattenAllFields } from 'payload';
|
|
2
|
-
import { formatSchema } from '../../../types/jsonSchemaHelpers.js';
|
|
3
|
+
import { formatSchema, versionSchema } from '../../../types/jsonSchemaHelpers.js';
|
|
3
4
|
import { filterEnabledRelationshipCollections } from '../../relationship/shared/filterEnabledRelationshipCollections.js';
|
|
4
5
|
/** MUST stay byte-for-byte in sync with the runtime `SerializedUploadNode` declared above. */
|
|
5
|
-
const SERIALIZED_UPLOAD_NODE_TS = `export type SerializedUploadNode<TSlugs extends keyof Config['collections']> = {
|
|
6
|
+
const SERIALIZED_UPLOAD_NODE_TS = `export type SerializedUploadNode<TSlugs extends keyof Config['collections'], TFields = { [k: string]: unknown }> = {
|
|
6
7
|
type: 'upload';
|
|
7
8
|
format: LexicalElementFormat;
|
|
8
9
|
id: string;
|
|
9
10
|
version: number;
|
|
10
|
-
fields:
|
|
11
|
+
fields: TFields;
|
|
11
12
|
} & {
|
|
12
13
|
[TSlug in TSlugs]: {
|
|
13
14
|
relationTo: TSlug;
|
|
14
15
|
value: number | string | Config['collections'][TSlug];
|
|
15
16
|
};
|
|
16
17
|
}[TSlugs];`;
|
|
18
|
+
const hashUploadFields = schema => createHash('sha256').update(JSON.stringify(schema)).digest('hex').slice(0, 8).toUpperCase();
|
|
17
19
|
export const createUploadNodeJSONSchema = props => ({
|
|
18
20
|
collectionIDFieldTypes,
|
|
19
21
|
config,
|
|
@@ -27,6 +29,14 @@ export const createUploadNodeJSONSchema = props => ({
|
|
|
27
29
|
enabledCollections: props?.enabledCollections,
|
|
28
30
|
uploads: true
|
|
29
31
|
}) : [];
|
|
32
|
+
// Configured extra fields are registered as their own interface and referenced here, so the
|
|
33
|
+
// generated TypeScript keeps them - the node-level `tsType` would otherwise erase `fields` to
|
|
34
|
+
// `{ [k: string]: unknown }`. Mirrors how LinkFeature handles custom link fields.
|
|
35
|
+
//
|
|
36
|
+
// Each collection gets its own `SerializedUploadNode<'slug', Fields>` instantiation so the
|
|
37
|
+
// generated union correctly pairs each `relationTo` with its own fields type. A single
|
|
38
|
+
// `SerializedUploadNode<'a' | 'b', AFields | BFields>` would lose that pairing.
|
|
39
|
+
const perCollectionTsTypes = [];
|
|
30
40
|
const collectionVariants = enabledCollections.map(collection => {
|
|
31
41
|
const slug = collection.slug;
|
|
32
42
|
const idType = collectionIDFieldTypes[slug] ?? 'string';
|
|
@@ -45,6 +55,21 @@ export const createUploadNodeJSONSchema = props => ({
|
|
|
45
55
|
properties: {},
|
|
46
56
|
required: []
|
|
47
57
|
};
|
|
58
|
+
let fieldsSchema = {
|
|
59
|
+
type: 'object',
|
|
60
|
+
additionalProperties: false,
|
|
61
|
+
properties: extraFieldsSchema.properties,
|
|
62
|
+
required: extraFieldsSchema.required
|
|
63
|
+
};
|
|
64
|
+
let fieldsTypeName;
|
|
65
|
+
if (flattenedExtra.length > 0) {
|
|
66
|
+
fieldsTypeName = `LexicalUploadFields_${hashUploadFields(fieldsSchema)}`;
|
|
67
|
+
interfaceNameDefinitions.set(fieldsTypeName, fieldsSchema);
|
|
68
|
+
fieldsSchema = {
|
|
69
|
+
$ref: `#/$defs/${fieldsTypeName}`
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
perCollectionTsTypes.push(fieldsTypeName ? `SerializedUploadNode<'${slug}', ${fieldsTypeName}>` : `SerializedUploadNode<'${slug}'>`);
|
|
48
73
|
return {
|
|
49
74
|
type: 'object',
|
|
50
75
|
additionalProperties: false,
|
|
@@ -56,27 +81,21 @@ export const createUploadNodeJSONSchema = props => ({
|
|
|
56
81
|
type: 'string',
|
|
57
82
|
const: 'upload'
|
|
58
83
|
},
|
|
59
|
-
fields:
|
|
60
|
-
type: 'object',
|
|
61
|
-
additionalProperties: false,
|
|
62
|
-
properties: extraFieldsSchema.properties,
|
|
63
|
-
required: extraFieldsSchema.required
|
|
64
|
-
},
|
|
84
|
+
fields: fieldsSchema,
|
|
65
85
|
format: formatSchema,
|
|
66
86
|
relationTo: {
|
|
67
87
|
type: 'string',
|
|
68
88
|
const: slug
|
|
69
89
|
},
|
|
70
90
|
value: {
|
|
91
|
+
description: 'The uploaded file by ID (string or number). Populated to the full upload document when read at depth > 0.',
|
|
71
92
|
oneOf: [{
|
|
72
93
|
type: idType
|
|
73
94
|
}, {
|
|
74
|
-
$ref:
|
|
95
|
+
$ref: `#/$defs/${slug}`
|
|
75
96
|
}]
|
|
76
97
|
},
|
|
77
|
-
version:
|
|
78
|
-
type: 'integer'
|
|
79
|
-
}
|
|
98
|
+
version: versionSchema
|
|
80
99
|
},
|
|
81
100
|
required: ['fields', 'format', 'id', 'relationTo', 'type', 'value', 'version']
|
|
82
101
|
};
|
|
@@ -92,20 +111,17 @@ export const createUploadNodeJSONSchema = props => ({
|
|
|
92
111
|
type: 'string',
|
|
93
112
|
const: 'upload'
|
|
94
113
|
},
|
|
95
|
-
version:
|
|
96
|
-
type: 'integer'
|
|
97
|
-
}
|
|
114
|
+
version: versionSchema
|
|
98
115
|
},
|
|
99
116
|
required: ['type', 'version']
|
|
100
117
|
};
|
|
101
118
|
} else {
|
|
102
|
-
const slugUnion = enabledCollections.map(c => `'${c.slug}'`).join(' | ');
|
|
103
119
|
const baseSchema = collectionVariants.length === 1 ? collectionVariants[0] : {
|
|
104
120
|
oneOf: collectionVariants
|
|
105
121
|
};
|
|
106
122
|
schema = {
|
|
107
123
|
...baseSchema,
|
|
108
|
-
tsType:
|
|
124
|
+
tsType: perCollectionTsTypes.join(' | ')
|
|
109
125
|
};
|
|
110
126
|
}
|
|
111
127
|
return schema;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","names":["fieldsToJSONSchema","flattenAllFields","formatSchema","filterEnabledRelationshipCollections","SERIALIZED_UPLOAD_NODE_TS","createUploadNodeJSONSchema","props","collectionIDFieldTypes","config","i18n","interfaceNameDefinitions","typeStringDefinitions","add","enabledCollections","collections","disabledCollections","uploads","collectionVariants","map","collection","slug","idType","extraFields","fields","flattenedExtra","extraFieldsSchema","length","properties","required","type","additionalProperties","id","const","format","relationTo","value","oneOf","$ref","version","schema","slugUnion","c","join","baseSchema","tsType"],"sources":["../../../../src/features/upload/server/schema.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema'\nimport type {\n DataFromCollectionSlug,\n JsonObject,\n TypedUploadCollection,\n UploadCollectionSlug,\n} from 'payload'\n\nimport { fieldsToJSONSchema, flattenAllFields } from 'payload'\n\nimport type { LexicalElementFormat } from '../../../types/nodeTypes.js'\nimport type { JSONSchemaFn } from '../../typesServer.js'\nimport type { UploadFeatureProps } from './index.js'\n\nimport { formatSchema } from '../../../types/jsonSchemaHelpers.js'\nimport { filterEnabledRelationshipCollections } from '../../relationship/shared/filterEnabledRelationshipCollections.js'\n\nexport type UploadData<TFields extends JsonObject = JsonObject> = {\n [TCollectionSlug in UploadCollectionSlug]: {\n fields: TFields\n /** ID of this upload node — NOT the linked document's ID. */\n id: string\n relationTo: TCollectionSlug\n /** Either the document ID or the full populated document. */\n value: DataFromCollectionSlug<TCollectionSlug> | number | string\n }\n}[UploadCollectionSlug]\n\n/** @internal Adds a pending state to `UploadData`. */\nexport type Internal_UploadData<TFields extends JsonObject = JsonObject> = {\n pending?: {\n /** Bulk upload form ID. */\n formID: string\n /** `src` of the image DOM element. */\n src: string\n }\n} & UploadData<TFields>\n\n/**\n * More precise variant of {@link UploadData}. Replaces `UploadData` in v4.\n * @internal\n * @todo Replace UploadData with UploadDataImproved in 4.0\n */\nexport type UploadDataImproved<TFields extends JsonObject = JsonObject> = {\n [TCollectionSlug in UploadCollectionSlug]: {\n fields: TFields\n id: string\n relationTo: TCollectionSlug\n value: number | string | TypedUploadCollection[TCollectionSlug]\n }\n}[UploadCollectionSlug]\n\nexport type SerializedUploadNode<TSlugs extends UploadCollectionSlug = UploadCollectionSlug> = {\n [TSlug in TSlugs]: {\n relationTo: TSlug\n value: DataFromCollectionSlug<TSlug> | number | string\n }\n}[TSlugs] & {\n fields: { [k: string]: unknown }\n format: LexicalElementFormat\n id: string\n type: 'upload'\n version: number\n}\n\n/** MUST stay byte-for-byte in sync with the runtime `SerializedUploadNode` declared above. */\nconst SERIALIZED_UPLOAD_NODE_TS = `export type SerializedUploadNode<TSlugs extends keyof Config['collections']> = {\n type: 'upload';\n format: LexicalElementFormat;\n id: string;\n version: number;\n fields: { [k: string]: unknown };\n} & {\n [TSlug in TSlugs]: {\n relationTo: TSlug;\n value: number | string | Config['collections'][TSlug];\n };\n}[TSlugs];`\n\nexport const createUploadNodeJSONSchema =\n (props: undefined | UploadFeatureProps): JSONSchemaFn =>\n ({ collectionIDFieldTypes, config, i18n, interfaceNameDefinitions, typeStringDefinitions }) => {\n typeStringDefinitions.add(SERIALIZED_UPLOAD_NODE_TS)\n const enabledCollections = config?.collections\n ? filterEnabledRelationshipCollections(config.collections, {\n disabledCollections: props?.disabledCollections,\n enabledCollections: props?.enabledCollections,\n uploads: true,\n })\n : []\n\n const collectionVariants: JSONSchema4[] = enabledCollections.map((collection) => {\n const slug = collection.slug\n const idType: 'number' | 'string' = collectionIDFieldTypes[slug] ?? 'string'\n const extraFields = props?.collections?.[slug]?.fields ?? []\n const flattenedExtra = flattenAllFields({ fields: extraFields })\n const extraFieldsSchema =\n flattenedExtra.length > 0 && config\n ? fieldsToJSONSchema({\n collectionIDFieldTypes,\n config,\n fields: flattenedExtra,\n i18n,\n interfaceNameDefinitions,\n typeStringDefinitions,\n })\n : { properties: {}, required: [] }\n\n return {\n type: 'object',\n additionalProperties: false,\n properties: {\n id: { type: 'string' },\n type: { type: 'string', const: 'upload' },\n fields: {\n type: 'object',\n additionalProperties: false,\n properties: extraFieldsSchema.properties,\n required: extraFieldsSchema.required,\n },\n format: formatSchema,\n relationTo: { type: 'string', const: slug },\n value: {\n oneOf: [{ type: idType }, { $ref: `#/definitions/${slug}` }],\n },\n version: { type: 'integer' },\n },\n required: ['fields', 'format', 'id', 'relationTo', 'type', 'value', 'version'],\n }\n })\n\n let schema: JSONSchema4\n if (collectionVariants.length === 0) {\n // Fallback when no enabled upload collections.\n schema = {\n type: 'object',\n additionalProperties: true,\n properties: {\n type: { type: 'string', const: 'upload' },\n version: { type: 'integer' },\n },\n required: ['type', 'version'],\n }\n } else {\n const slugUnion = enabledCollections.map((c) => `'${c.slug}'`).join(' | ')\n const baseSchema: JSONSchema4 =\n collectionVariants.length === 1 ? collectionVariants[0]! : { oneOf: collectionVariants }\n schema = { ...baseSchema, tsType: `SerializedUploadNode<${slugUnion}>` }\n }\n\n return schema\n }\n"],"mappings":"AAQA,SAASA,kBAAkB,EAAEC,gBAAgB,QAAQ;AAMrD,SAASC,YAAY,QAAQ;AAC7B,SAASC,oCAAoC,QAAQ;AAkDrD;AACA,MAAMC,yBAAA,GAA4B;;;;;;;;;;;WAWvB;AAEX,OAAO,MAAMC,0BAAA,GACVC,KAAA,IACD,CAAC;EAAEC,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MAAA,EAAQ/B,YAAA;QACRgC,UAAA,EAAY;UAAEL,IAAA,EAAM;UAAUG,KAAA,EAAOZ;QAAK;QAC1Ce,KAAA,EAAO;UACLC,KAAA,EAAO,CAAC;YAAEP,IAAA,EAAMR;UAAO,GAAG;YAAEgB,IAAA,EAAM,iBAAiBjB,IAAA;UAAO;QAC5D;QACAkB,OAAA,EAAS;UAAET,IAAA,EAAM;QAAU;MAC7B;MACAD,QAAA,EAAU,CAAC,UAAU,UAAU,MAAM,cAAc,QAAQ,SAAS;IACtE;EACF;EAEA,IAAIW,MAAA;EACJ,IAAItB,kBAAA,CAAmBS,MAAM,KAAK,GAAG;IACnC;IACAa,MAAA,GAAS;MACPV,IAAA,EAAM;MACNC,oBAAA,EAAsB;MACtBH,UAAA,EAAY;QACVE,IAAA,EAAM;UAAEA,IAAA,EAAM;UAAUG,KAAA,EAAO;QAAS;QACxCM,OAAA,EAAS;UAAET,IAAA,EAAM;QAAU;MAC7B;MACAD,QAAA,EAAU,CAAC,QAAQ;IACrB;EACF,OAAO;IACL,MAAMY,SAAA,GAAY3B,kBAAA,CAAmBK,GAAG,CAAEuB,CAAA,IAAM,IAAIA,CAAA,CAAErB,IAAI,GAAG,EAAEsB,IAAI,CAAC;IACpE,MAAMC,UAAA,GACJ1B,kBAAA,CAAmBS,MAAM,KAAK,IAAIT,kBAAkB,CAAC,EAAE,GAAI;MAAEmB,KAAA,EAAOnB;IAAmB;IACzFsB,MAAA,GAAS;MAAE,GAAGI,UAAU;MAAEC,MAAA,EAAQ,wBAAwBJ,SAAA;IAAa;EACzE;EAEA,OAAOD,MAAA;AACT","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"schema.js","names":["createHash","fieldsToJSONSchema","flattenAllFields","formatSchema","versionSchema","filterEnabledRelationshipCollections","SERIALIZED_UPLOAD_NODE_TS","hashUploadFields","schema","update","JSON","stringify","digest","slice","toUpperCase","createUploadNodeJSONSchema","props","collectionIDFieldTypes","config","i18n","interfaceNameDefinitions","typeStringDefinitions","add","enabledCollections","collections","disabledCollections","uploads","perCollectionTsTypes","collectionVariants","map","collection","slug","idType","extraFields","fields","flattenedExtra","extraFieldsSchema","length","properties","required","fieldsSchema","type","additionalProperties","fieldsTypeName","set","$ref","push","id","const","format","relationTo","value","description","oneOf","version","baseSchema","tsType","join"],"sources":["../../../../src/features/upload/server/schema.ts"],"sourcesContent":["import type { JSONSchema4 } from 'json-schema'\nimport type {\n DataFromCollectionSlug,\n JsonObject,\n TypedUploadCollection,\n UploadCollectionSlug,\n} from 'payload'\n\nimport { createHash } from 'crypto'\nimport { fieldsToJSONSchema, flattenAllFields } from 'payload'\n\nimport type { LexicalElementFormat } from '../../../types/nodeTypes.js'\nimport type { JSONSchemaFn } from '../../typesServer.js'\nimport type { UploadFeatureProps } from './index.js'\n\nimport { formatSchema, versionSchema } from '../../../types/jsonSchemaHelpers.js'\nimport { filterEnabledRelationshipCollections } from '../../relationship/shared/filterEnabledRelationshipCollections.js'\n\nexport type UploadData<TFields extends JsonObject = JsonObject> = {\n [TCollectionSlug in UploadCollectionSlug]: {\n fields: TFields\n /** ID of this upload node — NOT the linked document's ID. */\n id: string\n relationTo: TCollectionSlug\n /** Either the document ID or the full populated document. */\n value: DataFromCollectionSlug<TCollectionSlug> | number | string\n }\n}[UploadCollectionSlug]\n\n/** @internal Adds a pending state to `UploadData`. */\nexport type Internal_UploadData<TFields extends JsonObject = JsonObject> = {\n pending?: {\n /** Bulk upload form ID. */\n formID: string\n /** `src` of the image DOM element. */\n src: string\n }\n} & UploadData<TFields>\n\n/**\n * More precise variant of {@link UploadData}. Replaces `UploadData` in v4.\n * @internal\n * @todo Replace UploadData with UploadDataImproved in 4.0\n */\nexport type UploadDataImproved<TFields extends JsonObject = JsonObject> = {\n [TCollectionSlug in UploadCollectionSlug]: {\n fields: TFields\n id: string\n relationTo: TCollectionSlug\n value: number | string | TypedUploadCollection[TCollectionSlug]\n }\n}[UploadCollectionSlug]\n\nexport type SerializedUploadNode<\n TSlugs extends UploadCollectionSlug = UploadCollectionSlug,\n TFields = { [k: string]: unknown },\n> = {\n [TSlug in TSlugs]: {\n relationTo: TSlug\n value: DataFromCollectionSlug<TSlug> | number | string\n }\n}[TSlugs] & {\n fields: TFields\n format: LexicalElementFormat\n id: string\n type: 'upload'\n version: number\n}\n\n/** MUST stay byte-for-byte in sync with the runtime `SerializedUploadNode` declared above. */\nconst SERIALIZED_UPLOAD_NODE_TS = `export type SerializedUploadNode<TSlugs extends keyof Config['collections'], TFields = { [k: string]: unknown }> = {\n type: 'upload';\n format: LexicalElementFormat;\n id: string;\n version: number;\n fields: TFields;\n} & {\n [TSlug in TSlugs]: {\n relationTo: TSlug;\n value: number | string | Config['collections'][TSlug];\n };\n}[TSlugs];`\n\nconst hashUploadFields = (schema: JSONSchema4): string =>\n createHash('sha256').update(JSON.stringify(schema)).digest('hex').slice(0, 8).toUpperCase()\n\nexport const createUploadNodeJSONSchema =\n (props: undefined | UploadFeatureProps): JSONSchemaFn =>\n ({ collectionIDFieldTypes, config, i18n, interfaceNameDefinitions, typeStringDefinitions }) => {\n typeStringDefinitions.add(SERIALIZED_UPLOAD_NODE_TS)\n const enabledCollections = config?.collections\n ? filterEnabledRelationshipCollections(config.collections, {\n disabledCollections: props?.disabledCollections,\n enabledCollections: props?.enabledCollections,\n uploads: true,\n })\n : []\n\n // Configured extra fields are registered as their own interface and referenced here, so the\n // generated TypeScript keeps them - the node-level `tsType` would otherwise erase `fields` to\n // `{ [k: string]: unknown }`. Mirrors how LinkFeature handles custom link fields.\n //\n // Each collection gets its own `SerializedUploadNode<'slug', Fields>` instantiation so the\n // generated union correctly pairs each `relationTo` with its own fields type. A single\n // `SerializedUploadNode<'a' | 'b', AFields | BFields>` would lose that pairing.\n const perCollectionTsTypes: string[] = []\n const collectionVariants: JSONSchema4[] = enabledCollections.map((collection) => {\n const slug = collection.slug\n const idType: 'number' | 'string' = collectionIDFieldTypes[slug] ?? 'string'\n const extraFields = props?.collections?.[slug]?.fields ?? []\n const flattenedExtra = flattenAllFields({ fields: extraFields })\n const extraFieldsSchema =\n flattenedExtra.length > 0 && config\n ? fieldsToJSONSchema({\n collectionIDFieldTypes,\n config,\n fields: flattenedExtra,\n i18n,\n interfaceNameDefinitions,\n typeStringDefinitions,\n })\n : { properties: {}, required: [] }\n\n let fieldsSchema: JSONSchema4 = {\n type: 'object',\n additionalProperties: false,\n properties: extraFieldsSchema.properties,\n required: extraFieldsSchema.required,\n }\n let fieldsTypeName: string | undefined\n if (flattenedExtra.length > 0) {\n fieldsTypeName = `LexicalUploadFields_${hashUploadFields(fieldsSchema)}`\n interfaceNameDefinitions.set(fieldsTypeName, fieldsSchema)\n fieldsSchema = { $ref: `#/$defs/${fieldsTypeName}` }\n }\n\n perCollectionTsTypes.push(\n fieldsTypeName\n ? `SerializedUploadNode<'${slug}', ${fieldsTypeName}>`\n : `SerializedUploadNode<'${slug}'>`,\n )\n\n return {\n type: 'object',\n additionalProperties: false,\n properties: {\n id: { type: 'string' },\n type: { type: 'string', const: 'upload' },\n fields: fieldsSchema,\n format: formatSchema,\n relationTo: { type: 'string', const: slug },\n value: {\n description:\n 'The uploaded file by ID (string or number). Populated to the full upload document when read at depth > 0.',\n oneOf: [{ type: idType }, { $ref: `#/$defs/${slug}` }],\n },\n version: versionSchema,\n },\n required: ['fields', 'format', 'id', 'relationTo', 'type', 'value', 'version'],\n }\n })\n\n let schema: JSONSchema4\n if (collectionVariants.length === 0) {\n // Fallback when no enabled upload collections.\n schema = {\n type: 'object',\n additionalProperties: true,\n properties: {\n type: { type: 'string', const: 'upload' },\n version: versionSchema,\n },\n required: ['type', 'version'],\n }\n } else {\n const baseSchema: JSONSchema4 =\n collectionVariants.length === 1 ? collectionVariants[0]! : { oneOf: collectionVariants }\n schema = { ...baseSchema, tsType: perCollectionTsTypes.join(' | ') }\n }\n\n return schema\n }\n"],"mappings":"AAQA,SAASA,UAAU,QAAQ;AAC3B,SAASC,kBAAkB,EAAEC,gBAAgB,QAAQ;AAMrD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