@payloadcms/ui 3.0.0-beta.133 → 3.0.0-beta.134

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.
@@ -3,8 +3,12 @@ import { getTranslation } from '@payloadcms/translations';
3
3
  import { createClientField, deepCopyObjectSimple, MissingEditorProp } from 'payload';
4
4
  import { fieldAffectsData } from 'payload/shared';
5
5
  import { RenderServerComponent } from '../../elements/RenderServerComponent/index.js';
6
- import { FieldDescription } from '../../fields/FieldDescription/index.js';
6
+ // eslint-disable-next-line payload/no-imports-from-exports-dir -- need this to reference already existing bundle. Otherwise, bundle size increases., payload/no-imports-from-exports-dir
7
+ import { FieldDescription } from '../../exports/client/index.js';
8
+ const defaultUIFieldComponentKeys = ['Cell', 'Description', 'Field', 'Filter'];
7
9
  export const renderField = ({
10
+ id,
11
+ collectionSlug,
8
12
  data,
9
13
  fieldConfig,
10
14
  fieldSchemaMap,
@@ -16,6 +20,7 @@ export const renderField = ({
16
20
  parentSchemaPath,
17
21
  path,
18
22
  permissions: incomingPermissions,
23
+ preferences,
19
24
  req,
20
25
  schemaPath,
21
26
  siblingData
@@ -44,6 +49,7 @@ export const renderField = ({
44
49
  clientProps.parentSchemaPath = parentSchemaPath;
45
50
  }
46
51
  const serverProps = {
52
+ id,
47
53
  clientField,
48
54
  data,
49
55
  field: fieldConfig,
@@ -51,9 +57,13 @@ export const renderField = ({
51
57
  permissions,
52
58
  // TODO: Should we pass explicit values? initialValue, value, valid
53
59
  // value and initialValue should be typed
60
+ collectionSlug,
54
61
  formState,
55
62
  i18n: req.i18n,
63
+ operation,
56
64
  payload: req.payload,
65
+ preferences,
66
+ req,
57
67
  siblingData,
58
68
  user: req.user
59
69
  };
@@ -121,6 +131,25 @@ export const renderField = ({
121
131
  });
122
132
  break;
123
133
  }
134
+ case 'ui':
135
+ {
136
+ if (fieldConfig?.admin?.components) {
137
+ // Render any extra, untyped components
138
+ for (const key in fieldConfig.admin.components) {
139
+ if (key in defaultUIFieldComponentKeys) {
140
+ continue;
141
+ }
142
+ const Component = fieldConfig.admin.components[key];
143
+ fieldState.customComponents[key] = /*#__PURE__*/_jsx(RenderServerComponent, {
144
+ clientProps: clientProps,
145
+ Component: Component,
146
+ importMap: req.payload.importMap,
147
+ serverProps: serverProps
148
+ }, `field.admin.components.${key}`);
149
+ }
150
+ }
151
+ break;
152
+ }
124
153
  default:
125
154
  {
126
155
  break;
@@ -1 +1 @@
1
- {"version":3,"file":"renderField.js","names":["getTranslation","createClientField","deepCopyObjectSimple","MissingEditorProp","fieldAffectsData","RenderServerComponent","FieldDescription","renderField","data","fieldConfig","fieldSchemaMap","fieldState","formState","indexPath","operation","parentPath","parentSchemaPath","path","permissions","incomingPermissions","req","schemaPath","siblingData","clientField","defaultIDType","payload","config","db","field","i18n","name","clientProps","customComponents","readOnly","includes","type","serverProps","user","rows","forEach","row","rowIndex","admin","components","RowLabels","_jsx","Component","RowLabel","importMap","rowLabel","labels","singular","String","padStart","rowNumber","editor","Error","FieldComponent","Field","Fallback","undefined","Description","description","t","AfterInput","afterInput","BeforeInput","beforeInput","Label"],"sources":["../../../src/forms/fieldSchemasToFormState/renderField.tsx"],"sourcesContent":["import type {\n ClientComponentProps,\n ClientField,\n FieldPaths,\n PayloadComponent,\n SanitizedFieldPermissions,\n ServerComponentProps,\n} from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { createClientField, deepCopyObjectSimple, MissingEditorProp } from 'payload'\nimport { fieldAffectsData } from 'payload/shared'\n\nimport type { RenderFieldMethod } from './types.js'\n\nimport { RenderServerComponent } from '../../elements/RenderServerComponent/index.js'\nimport { FieldDescription } from '../../fields/FieldDescription/index.js'\n\nexport const renderField: RenderFieldMethod = ({\n data,\n fieldConfig,\n fieldSchemaMap,\n fieldState,\n formState,\n indexPath,\n operation,\n parentPath,\n parentSchemaPath,\n path,\n permissions: incomingPermissions,\n req,\n schemaPath,\n siblingData,\n}) => {\n // TODO (ALESSIO): why are we passing the fieldConfig twice?\n // and especially, why are we deepCopyObject -here- instead of inside the createClientField func,\n // so no one screws this up in the future?\n const clientField = createClientField({\n clientField: deepCopyObjectSimple(fieldConfig) as ClientField,\n defaultIDType: req.payload.config.db.defaultIDType,\n field: fieldConfig,\n i18n: req.i18n,\n })\n\n const permissions =\n incomingPermissions === true\n ? true\n : fieldAffectsData(fieldConfig)\n ? incomingPermissions?.[fieldConfig.name]\n : ({} as SanitizedFieldPermissions)\n\n const clientProps: ClientComponentProps & Partial<FieldPaths> = {\n customComponents: fieldState?.customComponents || {},\n field: clientField,\n path,\n readOnly: permissions !== true && !permissions?.[operation],\n schemaPath,\n }\n\n // fields with subfields\n if (['array', 'blocks', 'collapsible', 'group', 'row', 'tabs'].includes(fieldConfig.type)) {\n clientProps.indexPath = indexPath\n clientProps.parentPath = parentPath\n clientProps.parentSchemaPath = parentSchemaPath\n }\n\n const serverProps: ServerComponentProps = {\n clientField,\n data,\n field: fieldConfig,\n fieldSchemaMap,\n permissions,\n // TODO: Should we pass explicit values? initialValue, value, valid\n // value and initialValue should be typed\n formState,\n i18n: req.i18n,\n payload: req.payload,\n siblingData,\n user: req.user,\n }\n\n if (!fieldState?.customComponents) {\n fieldState.customComponents = {}\n }\n\n switch (fieldConfig.type) {\n // TODO: handle block row labels as well in a similar fashion\n case 'array': {\n fieldState?.rows?.forEach((row, rowIndex) => {\n if (fieldConfig.admin?.components && 'RowLabel' in fieldConfig.admin.components) {\n if (!fieldState.customComponents.RowLabels) {\n fieldState.customComponents.RowLabels = []\n }\n\n fieldState.customComponents.RowLabels[rowIndex] = (\n <RenderServerComponent\n clientProps={clientProps}\n Component={fieldConfig.admin.components.RowLabel}\n importMap={req.payload.importMap}\n serverProps={{\n ...serverProps,\n rowLabel: `${getTranslation(fieldConfig.labels.singular, req.i18n)} ${String(\n rowIndex + 1,\n ).padStart(2, '0')}`,\n rowNumber: rowIndex + 1,\n }}\n />\n )\n }\n })\n\n break\n }\n\n case 'richText': {\n if (!fieldConfig?.editor) {\n throw new MissingEditorProp(fieldConfig) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n\n if (typeof fieldConfig?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n if (!fieldConfig.admin) {\n fieldConfig.admin = {}\n }\n\n if (!fieldConfig.admin.components) {\n fieldConfig.admin.components = {}\n }\n\n /**\n * We have to deep copy all the props we send to the client (= FieldComponent.clientProps).\n * That way, every editor's field / cell props we send to the client have their own object references.\n *\n * If we send the same object reference to the client twice (e.g. through some configurations where 2 or more fields\n * reference the same editor object, like the root editor), the admin panel may hang indefinitely. This has been happening since\n * a newer Next.js update that made it break when sending the same object reference to the client twice.\n *\n * We can use deepCopyObjectSimple as client props should be JSON-serializable.\n */\n const FieldComponent: PayloadComponent = fieldConfig.editor.FieldComponent\n if (typeof FieldComponent === 'object' && FieldComponent.clientProps) {\n FieldComponent.clientProps = deepCopyObjectSimple(FieldComponent.clientProps)\n }\n\n fieldState.customComponents.Field = (\n <RenderServerComponent\n clientProps={clientProps}\n Component={FieldComponent}\n Fallback={undefined}\n importMap={req.payload.importMap}\n serverProps={serverProps}\n />\n )\n\n break\n }\n\n default: {\n break\n }\n }\n\n if (fieldConfig.admin) {\n if ('description' in fieldConfig.admin) {\n // @TODO move this to client, only render if it is a function\n fieldState.customComponents.Description = (\n <FieldDescription\n description={\n typeof fieldConfig.admin?.description === 'string' ||\n typeof fieldConfig.admin?.description === 'object'\n ? fieldConfig.admin.description\n : typeof fieldConfig.admin?.description === 'function'\n ? fieldConfig.admin?.description({ t: req.i18n.t })\n : ''\n }\n path={path}\n />\n )\n }\n\n if (fieldConfig.admin?.components) {\n if ('afterInput' in fieldConfig.admin.components) {\n fieldState.customComponents.AfterInput = (\n <RenderServerComponent\n clientProps={clientProps}\n Component={fieldConfig.admin.components.afterInput}\n importMap={req.payload.importMap}\n key=\"field.admin.components.afterInput\"\n serverProps={serverProps}\n />\n )\n }\n\n if ('beforeInput' in fieldConfig.admin.components) {\n fieldState.customComponents.BeforeInput = (\n <RenderServerComponent\n clientProps={clientProps}\n Component={fieldConfig.admin.components.beforeInput}\n importMap={req.payload.importMap}\n key=\"field.admin.components.beforeInput\"\n serverProps={serverProps}\n />\n )\n }\n\n if ('Description' in fieldConfig.admin.components) {\n fieldState.customComponents.Description = (\n <RenderServerComponent\n clientProps={clientProps}\n Component={fieldConfig.admin.components.Description}\n importMap={req.payload.importMap}\n key=\"field.admin.components.Description\"\n serverProps={serverProps}\n />\n )\n }\n\n if ('Error' in fieldConfig.admin.components) {\n fieldState.customComponents.Error = (\n <RenderServerComponent\n clientProps={clientProps}\n Component={fieldConfig.admin.components.Error}\n importMap={req.payload.importMap}\n key=\"field.admin.components.Error\"\n serverProps={serverProps}\n />\n )\n }\n\n if ('Label' in fieldConfig.admin.components) {\n fieldState.customComponents.Label = (\n <RenderServerComponent\n clientProps={clientProps}\n Component={fieldConfig.admin.components.Label}\n importMap={req.payload.importMap}\n key=\"field.admin.components.Label\"\n serverProps={serverProps}\n />\n )\n }\n\n if ('Field' in fieldConfig.admin.components) {\n fieldState.customComponents.Field = (\n <RenderServerComponent\n clientProps={clientProps}\n Component={fieldConfig.admin.components.Field}\n importMap={req.payload.importMap}\n key=\"field.admin.components.Field\"\n serverProps={serverProps}\n />\n )\n }\n }\n }\n}\n"],"mappings":";AASA,SAASA,cAAc,QAAQ;AAC/B,SAASC,iBAAiB,EAAEC,oBAAoB,EAAEC,iBAAiB,QAAQ;AAC3E,SAASC,gBAAgB,QAAQ;AAIjC,SAASC,qBAAqB,QAAQ;AACtC,SAASC,gBAAgB,QAAQ;AAEjC,OAAO,MAAMC,WAAA,GAAiCA,CAAC;EAC7CC,IAAI;EACJC,WAAW;EACXC,cAAc;EACdC,UAAU;EACVC,SAAS;EACTC,SAAS;EACTC,SAAS;EACTC,UAAU;EACVC,gBAAgB;EAChBC,IAAI;EACJC,WAAA,EAAaC,mBAAmB;EAChCC,GAAG;EACHC,UAAU;EACVC;AAA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oC,KAAK,gBAC/BvB,IAAA,CAACxC,qBAAA;UACC0B,WAAA,EAAaA,WAAA;UACbe,SAAA,EAAWrC,WAAA,CAAYiC,KAAK,CAACC,UAAU,CAACyB,KAAK;UAC7CpB,SAAA,EAAW5B,GAAA,CAAIK,OAAO,CAACuB,SAAS;UAEhCZ,WAAA,EAAaA;WADT;MAIV;MAEA,IAAI,WAAW3B,WAAA,CAAYiC,KAAK,CAACC,UAAU,EAAE;QAC3ChC,UAAA,CAAWqB,gBAAgB,CAAC0B,KAAK,gBAC/Bb,IAAA,CAACxC,qBAAA;UACC0B,WAAA,EAAaA,WAAA;UACbe,SAAA,EAAWrC,WAAA,CAAYiC,KAAK,CAACC,UAAU,CAACe,KAAK;UAC7CV,SAAA,EAAW5B,GAAA,CAAIK,OAAO,CAACuB,SAAS;UAEhCZ,WAAA,EAAaA;WADT;MAIV;IACF;EACF;AACF","ignoreList":[]}
1
+ {"version":3,"file":"renderField.js","names":["getTranslation","createClientField","deepCopyObjectSimple","MissingEditorProp","fieldAffectsData","RenderServerComponent","FieldDescription","defaultUIFieldComponentKeys","renderField","id","collectionSlug","data","fieldConfig","fieldSchemaMap","fieldState","formState","indexPath","operation","parentPath","parentSchemaPath","path","permissions","incomingPermissions","preferences","req","schemaPath","siblingData","clientField","defaultIDType","payload","config","db","field","i18n","name","clientProps","customComponents","readOnly","includes","type","serverProps","user","rows","forEach","row","rowIndex","admin","components","RowLabels","_jsx","Component","RowLabel","importMap","rowLabel","labels","singular","String","padStart","rowNumber","editor","Error","FieldComponent","Field","Fallback","undefined","key","Description","description","t","AfterInput","afterInput","BeforeInput","beforeInput","Label"],"sources":["../../../src/forms/fieldSchemasToFormState/renderField.tsx"],"sourcesContent":["import type {\n ClientComponentProps,\n ClientField,\n FieldPaths,\n PayloadComponent,\n SanitizedFieldPermissions,\n ServerComponentProps,\n} from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { createClientField, deepCopyObjectSimple, MissingEditorProp } from 'payload'\nimport { fieldAffectsData } from 'payload/shared'\n\nimport type { RenderFieldMethod } from './types.js'\n\nimport { RenderServerComponent } from '../../elements/RenderServerComponent/index.js'\n// eslint-disable-next-line payload/no-imports-from-exports-dir -- need this to reference already existing bundle. Otherwise, bundle size increases., payload/no-imports-from-exports-dir\nimport { FieldDescription } from '../../exports/client/index.js'\n\nconst defaultUIFieldComponentKeys: Array<'Cell' | 'Description' | 'Field' | 'Filter'> = [\n 'Cell',\n 'Description',\n 'Field',\n 'Filter',\n]\n\nexport const renderField: RenderFieldMethod = ({\n id,\n collectionSlug,\n data,\n fieldConfig,\n fieldSchemaMap,\n fieldState,\n formState,\n indexPath,\n operation,\n parentPath,\n parentSchemaPath,\n path,\n permissions: incomingPermissions,\n preferences,\n req,\n schemaPath,\n siblingData,\n}) => {\n // TODO (ALESSIO): why are we passing the fieldConfig twice?\n // and especially, why are we deepCopyObject -here- instead of inside the createClientField func,\n // so no one screws this up in the future?\n const clientField = createClientField({\n clientField: deepCopyObjectSimple(fieldConfig) as ClientField,\n defaultIDType: req.payload.config.db.defaultIDType,\n field: fieldConfig,\n i18n: req.i18n,\n })\n\n const permissions =\n incomingPermissions === true\n ? true\n : fieldAffectsData(fieldConfig)\n ? incomingPermissions?.[fieldConfig.name]\n : ({} as SanitizedFieldPermissions)\n\n const clientProps: ClientComponentProps & Partial<FieldPaths> = {\n customComponents: fieldState?.customComponents || {},\n field: clientField,\n path,\n readOnly: permissions !== true && !permissions?.[operation],\n schemaPath,\n }\n\n // fields with subfields\n if (['array', 'blocks', 'collapsible', 'group', 'row', 'tabs'].includes(fieldConfig.type)) {\n clientProps.indexPath = indexPath\n clientProps.parentPath = parentPath\n clientProps.parentSchemaPath = parentSchemaPath\n }\n\n const serverProps: ServerComponentProps = {\n id,\n clientField,\n data,\n field: fieldConfig,\n fieldSchemaMap,\n permissions,\n // TODO: Should we pass explicit values? initialValue, value, valid\n // value and initialValue should be typed\n collectionSlug,\n formState,\n i18n: req.i18n,\n operation,\n payload: req.payload,\n preferences,\n req,\n siblingData,\n user: req.user,\n }\n\n if (!fieldState?.customComponents) {\n fieldState.customComponents = {}\n }\n\n switch (fieldConfig.type) {\n // TODO: handle block row labels as well in a similar fashion\n case 'array': {\n fieldState?.rows?.forEach((row, rowIndex) => {\n if (fieldConfig.admin?.components && 'RowLabel' in fieldConfig.admin.components) {\n if (!fieldState.customComponents.RowLabels) {\n fieldState.customComponents.RowLabels = []\n }\n\n fieldState.customComponents.RowLabels[rowIndex] = (\n <RenderServerComponent\n clientProps={clientProps}\n Component={fieldConfig.admin.components.RowLabel}\n importMap={req.payload.importMap}\n serverProps={{\n ...serverProps,\n rowLabel: `${getTranslation(fieldConfig.labels.singular, req.i18n)} ${String(\n rowIndex + 1,\n ).padStart(2, '0')}`,\n rowNumber: rowIndex + 1,\n }}\n />\n )\n }\n })\n\n break\n }\n\n case 'richText': {\n if (!fieldConfig?.editor) {\n throw new MissingEditorProp(fieldConfig) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor\n }\n\n if (typeof fieldConfig?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n if (!fieldConfig.admin) {\n fieldConfig.admin = {}\n }\n\n if (!fieldConfig.admin.components) {\n fieldConfig.admin.components = {}\n }\n\n /**\n * We have to deep copy all the props we send to the client (= FieldComponent.clientProps).\n * That way, every editor's field / cell props we send to the client have their own object references.\n *\n * If we send the same object reference to the client twice (e.g. through some configurations where 2 or more fields\n * reference the same editor object, like the root editor), the admin panel may hang indefinitely. This has been happening since\n * a newer Next.js update that made it break when sending the same object reference to the client twice.\n *\n * We can use deepCopyObjectSimple as client props should be JSON-serializable.\n */\n const FieldComponent: PayloadComponent = fieldConfig.editor.FieldComponent\n if (typeof FieldComponent === 'object' && FieldComponent.clientProps) {\n FieldComponent.clientProps = deepCopyObjectSimple(FieldComponent.clientProps)\n }\n\n fieldState.customComponents.Field = (\n <RenderServerComponent\n clientProps={clientProps}\n Component={FieldComponent}\n Fallback={undefined}\n importMap={req.payload.importMap}\n serverProps={serverProps}\n />\n )\n\n break\n }\n\n case 'ui': {\n if (fieldConfig?.admin?.components) {\n // Render any extra, untyped components\n for (const key in fieldConfig.admin.components) {\n if (key in defaultUIFieldComponentKeys) {\n continue\n }\n const Component = fieldConfig.admin.components[key]\n fieldState.customComponents[key] = (\n <RenderServerComponent\n clientProps={clientProps}\n Component={Component}\n importMap={req.payload.importMap}\n key={`field.admin.components.${key}`}\n serverProps={serverProps}\n />\n )\n }\n }\n break\n }\n\n default: {\n break\n }\n }\n\n if (fieldConfig.admin) {\n if ('description' in fieldConfig.admin) {\n // @TODO move this to client, only render if it is a function\n fieldState.customComponents.Description = (\n <FieldDescription\n description={\n typeof fieldConfig.admin?.description === 'string' ||\n typeof fieldConfig.admin?.description === 'object'\n ? fieldConfig.admin.description\n : typeof fieldConfig.admin?.description === 'function'\n ? fieldConfig.admin?.description({ t: req.i18n.t })\n : ''\n }\n path={path}\n />\n )\n }\n\n if (fieldConfig.admin?.components) {\n if ('afterInput' in fieldConfig.admin.components) {\n fieldState.customComponents.AfterInput = (\n <RenderServerComponent\n clientProps={clientProps}\n Component={fieldConfig.admin.components.afterInput}\n importMap={req.payload.importMap}\n key=\"field.admin.components.afterInput\"\n serverProps={serverProps}\n />\n )\n }\n\n if ('beforeInput' in fieldConfig.admin.components) {\n fieldState.customComponents.BeforeInput = (\n <RenderServerComponent\n clientProps={clientProps}\n Component={fieldConfig.admin.components.beforeInput}\n importMap={req.payload.importMap}\n key=\"field.admin.components.beforeInput\"\n serverProps={serverProps}\n />\n )\n }\n\n if ('Description' in fieldConfig.admin.components) {\n fieldState.customComponents.Description = (\n <RenderServerComponent\n clientProps={clientProps}\n Component={fieldConfig.admin.components.Description}\n importMap={req.payload.importMap}\n key=\"field.admin.components.Description\"\n serverProps={serverProps}\n />\n )\n }\n\n if ('Error' in fieldConfig.admin.components) {\n fieldState.customComponents.Error = (\n <RenderServerComponent\n clientProps={clientProps}\n Component={fieldConfig.admin.components.Error}\n importMap={req.payload.importMap}\n key=\"field.admin.components.Error\"\n serverProps={serverProps}\n />\n )\n }\n\n if ('Label' in fieldConfig.admin.components) {\n fieldState.customComponents.Label = (\n <RenderServerComponent\n clientProps={clientProps}\n Component={fieldConfig.admin.components.Label}\n importMap={req.payload.importMap}\n key=\"field.admin.components.Label\"\n serverProps={serverProps}\n />\n )\n }\n\n if ('Field' in fieldConfig.admin.components) {\n fieldState.customComponents.Field = (\n <RenderServerComponent\n clientProps={clientProps}\n Component={fieldConfig.admin.components.Field}\n importMap={req.payload.importMap}\n key=\"field.admin.components.Field\"\n serverProps={serverProps}\n />\n )\n }\n }\n }\n}\n"],"mappings":";AASA,SAASA,cAAc,QAAQ;AAC/B,SAASC,iBAAiB,EAAEC,oBAAoB,EAAEC,iBAAiB,QAAQ;AAC3E,SAASC,gBAAgB,QAAQ;AAIjC,SAASC,qBAAqB,QAAQ;AACtC;AACA,SAASC,gBAAgB,QAAQ;AAEjC,MAAMC,2BAAA,GAAkF,CACtF,QACA,eACA,SACA,SACD;AAED,OAAO,MAAMC,WAAA,GAAiCA,CAAC;EAC7CC,EAAE;EACFC,cAAc;EACdC,IAAI;EACJC,WAAW;EACXC,cAAc;EACdC,UAAU;EACVC,SAAS;EACTC,SAAS;EACTC,SAAS;EACTC,UAAU;EACVC,gBAAgB;EAChBC,IAAI;EACJC,WAAA,EAAaC,mBAAmB;EAChCC,WAAW;EACXC,GAAG;EACHC,UAAU;EACVC;AAAW,CACZ;EACC;EACA;EACA;EACA,MAAMC,WAAA,GAAc1B,iBAAA,CAAkB;IACpC0B,WAAA,EAAazB,oBAAA,CAAqBU,WAAA;IAClCgB,aAAA,EAAeJ,GAAA,CAAIK,OAAO,CAACC,MAAM,CAACC,EAAE,CAACH,aAAa;IAClDI,KAAA,EAAOpB,WAAA;IACPqB,IAAA,EAAMT,GAAA,CAAIS;EACZ;EAEA,MAAMZ,WAAA,GACJC,mBAAA,KAAwB,OACpB,OACAlB,gBAAA,CAA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B,KAAK,gBAC/BX,IAAA,CAAC5C,qBAAA;UACC8B,WAAA,EAAaA,WAAA;UACbe,SAAA,EAAWtC,WAAA,CAAYkC,KAAK,CAACC,UAAU,CAACa,KAAK;UAC7CR,SAAA,EAAW5B,GAAA,CAAIK,OAAO,CAACuB,SAAS;UAEhCZ,WAAA,EAAaA;WADT;MAIV;MAEA,IAAI,WAAW5B,WAAA,CAAYkC,KAAK,CAACC,UAAU,EAAE;QAC3CjC,UAAA,CAAWsB,gBAAgB,CAACqC,KAAK,gBAC/BxB,IAAA,CAAC5C,qBAAA;UACC8B,WAAA,EAAaA,WAAA;UACbe,SAAA,EAAWtC,WAAA,CAAYkC,KAAK,CAACC,UAAU,CAAC0B,KAAK;UAC7CrB,SAAA,EAAW5B,GAAA,CAAIK,OAAO,CAACuB,SAAS;UAEhCZ,WAAA,EAAaA;WADT;MAIV;MAEA,IAAI,WAAW5B,WAAA,CAAYkC,KAAK,CAACC,UAAU,EAAE;QAC3CjC,UAAA,CAAWsB,gBAAgB,CAAC0B,KAAK,gBAC/Bb,IAAA,CAAC5C,qBAAA;UACC8B,WAAA,EAAaA,WAAA;UACbe,SAAA,EAAWtC,WAAA,CAAYkC,KAAK,CAACC,UAAU,CAACe,KAAK;UAC7CV,SAAA,EAAW5B,GAAA,CAAIK,OAAO,CAACuB,SAAS;UAEhCZ,WAAA,EAAaA;WADT;MAIV;IACF;EACF;AACF","ignoreList":[]}
@@ -1,10 +1,12 @@
1
- import type { Data, Field, FieldSchemaMap, FieldState, FormState, Operation, PayloadRequest, SanitizedFieldPermissions } from 'payload';
1
+ import type { Data, DocumentPreferences, Field, FieldSchemaMap, FieldState, FormState, Operation, PayloadRequest, SanitizedFieldPermissions } from 'payload';
2
2
  export type RenderFieldArgs = {
3
+ collectionSlug: string;
3
4
  data: Data;
4
5
  fieldConfig: Field;
5
6
  fieldSchemaMap: FieldSchemaMap;
6
7
  fieldState: FieldState;
7
8
  formState: FormState;
9
+ id?: number | string;
8
10
  indexPath: string;
9
11
  operation: Operation;
10
12
  parentPath: string;
@@ -13,6 +15,7 @@ export type RenderFieldArgs = {
13
15
  permissions: {
14
16
  [fieldName: string]: SanitizedFieldPermissions;
15
17
  } | null | SanitizedFieldPermissions;
18
+ preferences: DocumentPreferences;
16
19
  previousFieldState: FieldState;
17
20
  req: PayloadRequest;
18
21
  schemaPath: string;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/forms/fieldSchemasToFormState/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EACJ,KAAK,EACL,cAAc,EACd,UAAU,EACV,SAAS,EACT,SAAS,EACT,cAAc,EACd,yBAAyB,EAC1B,MAAM,SAAS,CAAA;AAEhB,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,IAAI,CAAA;IACV,WAAW,EAAE,KAAK,CAAA;IAClB,cAAc,EAAE,cAAc,CAAA;IAC9B,UAAU,EAAE,UAAU,CAAA;IACtB,SAAS,EAAE,SAAS,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,SAAS,CAAA;IACpB,UAAU,EAAE,MAAM,CAAA;IAClB,gBAAgB,EAAE,MAAM,CAAA;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EACP;QACE,CAAC,SAAS,EAAE,MAAM,GAAG,yBAAyB,CAAA;KAC/C,GACD,IAAI,GACJ,yBAAyB,CAAA;IAC7B,kBAAkB,EAAE,UAAU,CAAA;IAC9B,GAAG,EAAE,cAAc,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,IAAI,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/forms/fieldSchemasToFormState/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EACJ,mBAAmB,EACnB,KAAK,EACL,cAAc,EACd,UAAU,EACV,SAAS,EACT,SAAS,EACT,cAAc,EACd,yBAAyB,EAC1B,MAAM,SAAS,CAAA;AAEhB,MAAM,MAAM,eAAe,GAAG;IAC5B,cAAc,EAAE,MAAM,CAAA;IACtB,IAAI,EAAE,IAAI,CAAA;IACV,WAAW,EAAE,KAAK,CAAA;IAClB,cAAc,EAAE,cAAc,CAAA;IAC9B,UAAU,EAAE,UAAU,CAAA;IACtB,SAAS,EAAE,SAAS,CAAA;IACpB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,SAAS,CAAA;IACpB,UAAU,EAAE,MAAM,CAAA;IAClB,gBAAgB,EAAE,MAAM,CAAA;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EACP;QACE,CAAC,SAAS,EAAE,MAAM,GAAG,yBAAyB,CAAA;KAC/C,GACD,IAAI,GACJ,yBAAyB,CAAA;IAC7B,WAAW,EAAE,mBAAmB,CAAA;IAChC,kBAAkB,EAAE,UAAU,CAAA;IAC9B,GAAG,EAAE,cAAc,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,IAAI,CAAA;CAClB,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../../src/forms/fieldSchemasToFormState/types.ts"],"sourcesContent":["import type {\n Data,\n Field,\n FieldSchemaMap,\n FieldState,\n FormState,\n Operation,\n PayloadRequest,\n SanitizedFieldPermissions,\n} from 'payload'\n\nexport type RenderFieldArgs = {\n data: Data\n fieldConfig: Field\n fieldSchemaMap: FieldSchemaMap\n fieldState: FieldState\n formState: FormState\n indexPath: string\n operation: Operation\n parentPath: string\n parentSchemaPath: string\n path: string\n permissions:\n | {\n [fieldName: string]: SanitizedFieldPermissions\n }\n | null\n | SanitizedFieldPermissions\n previousFieldState: FieldState\n req: PayloadRequest\n schemaPath: string\n siblingData: Data\n}\n\nexport type RenderFieldMethod = (args: RenderFieldArgs) => void\n"],"mappings":"AAkCA","ignoreList":[]}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../../src/forms/fieldSchemasToFormState/types.ts"],"sourcesContent":["import type {\n Data,\n DocumentPreferences,\n Field,\n FieldSchemaMap,\n FieldState,\n FormState,\n Operation,\n PayloadRequest,\n SanitizedFieldPermissions,\n} from 'payload'\n\nexport type RenderFieldArgs = {\n collectionSlug: string\n data: Data\n fieldConfig: Field\n fieldSchemaMap: FieldSchemaMap\n fieldState: FieldState\n formState: FormState\n id?: number | string\n indexPath: string\n operation: Operation\n parentPath: string\n parentSchemaPath: string\n path: string\n permissions:\n | {\n [fieldName: string]: SanitizedFieldPermissions\n }\n | null\n | SanitizedFieldPermissions\n preferences: DocumentPreferences\n previousFieldState: FieldState\n req: PayloadRequest\n schemaPath: string\n siblingData: Data\n}\n\nexport type RenderFieldMethod = (args: RenderFieldArgs) => void\n"],"mappings":"AAsCA","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import { dequal } from 'dequal';
1
+ import { dequal } from 'dequal'; // TODO: Can we change this to dequal/lite ? If not, please add comment explaining why
2
2
  import { createClientConfig, formatErrors } from 'payload';
3
3
  import { renderFilters, renderTable } from './renderTable.js';
4
4
  let cachedClientConfig = global._payload_clientConfig;
@@ -1 +1 @@
1
- {"version":3,"file":"buildTableState.js","names":["dequal","createClientConfig","formatErrors","renderFilters","renderTable","cachedClientConfig","global","_payload_clientConfig","getClientConfig","args","config","i18n","process","env","NODE_ENV","buildTableStateHandler","req","res","buildTableState","err","payload","logger","error","msg","message","collectionSlug","columns","docs","docsFromArgs","enableRowSelections","query","renderRowTypes","user","tableAppearance","incomingUserSlug","collection","adminUserSlug","admin","adminAccessFunction","collections","access","canAccessAdmin","Error","hasUsers","find","depth","limit","pagination","length","clientConfig","collectionConfig","clientCollectionConfig","slug","preferencesKey","preferencesResult","where","and","key","equals","id","then","value","newPrefs","mergedPrefs","preferencesArgs","data","update","create","fields","parseInt","undefined","page","sort","columnState","Table","columnPreferences","useAsTitle","renderedFilters","importMap","preferences","state"],"sources":["../../src/utilities/buildTableState.ts"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type {\n BuildTableStateArgs,\n ClientCollectionConfig,\n ClientConfig,\n ErrorResult,\n PaginatedDocs,\n SanitizedCollectionConfig,\n SanitizedConfig,\n} from 'payload'\n\nimport { dequal } from 'dequal'\nimport { createClientConfig, formatErrors } from 'payload'\n\nimport type { Column } from '../elements/Table/index.js'\nimport type { ListPreferences } from '../elements/TableColumns/index.js'\n\nimport { renderFilters, renderTable } from './renderTable.js'\n\nlet cachedClientConfig = global._payload_clientConfig\n\nif (!cachedClientConfig) {\n cachedClientConfig = global._payload_clientConfig = null\n}\n\nexport const getClientConfig = (args: {\n config: SanitizedConfig\n i18n: I18nClient\n}): ClientConfig => {\n const { config, i18n } = args\n\n if (cachedClientConfig && process.env.NODE_ENV !== 'development') {\n return cachedClientConfig\n }\n\n cachedClientConfig = createClientConfig({\n config,\n i18n,\n })\n\n return cachedClientConfig\n}\n\ntype BuildTableStateSuccessResult = {\n clientConfig?: ClientConfig\n data: PaginatedDocs\n errors?: never\n preferences: ListPreferences\n renderedFilters: Map<string, React.ReactNode>\n state: Column[]\n Table: React.ReactNode\n}\n\ntype BuildTableStateErrorResult = {\n data?: any\n renderedFilters?: never\n state?: never\n Table?: never\n} & (\n | {\n message: string\n }\n | ErrorResult\n)\n\nexport type BuildTableStateResult = BuildTableStateErrorResult | BuildTableStateSuccessResult\n\nexport const buildTableStateHandler = async (\n args: BuildTableStateArgs,\n): Promise<BuildTableStateResult> => {\n const { req } = args\n\n try {\n const res = await buildTableState(args)\n return res\n } catch (err) {\n req.payload.logger.error({ err, msg: `There was an error building form state` })\n\n if (err.message === 'Could not find field schema for given path') {\n return {\n message: err.message,\n }\n }\n\n if (err.message === 'Unauthorized') {\n return null\n }\n\n return formatErrors(err)\n }\n}\n\nexport const buildTableState = async (\n args: BuildTableStateArgs,\n): Promise<BuildTableStateSuccessResult> => {\n const {\n collectionSlug,\n columns,\n docs: docsFromArgs,\n enableRowSelections,\n query,\n renderRowTypes,\n req,\n req: {\n i18n,\n payload,\n payload: { config },\n user,\n },\n tableAppearance,\n } = args\n\n const incomingUserSlug = user?.collection\n\n const adminUserSlug = config.admin.user\n\n // If we have a user slug, test it against the functions\n if (incomingUserSlug) {\n const adminAccessFunction = payload.collections[incomingUserSlug].config.access?.admin\n\n // Run the admin access function from the config if it exists\n if (adminAccessFunction) {\n const canAccessAdmin = await adminAccessFunction({ req })\n\n if (!canAccessAdmin) {\n throw new Error('Unauthorized')\n }\n // Match the user collection to the global admin config\n } else if (adminUserSlug !== incomingUserSlug) {\n throw new Error('Unauthorized')\n }\n } else {\n const hasUsers = await payload.find({\n collection: adminUserSlug,\n depth: 0,\n limit: 1,\n pagination: false,\n })\n\n // If there are users, we should not allow access because of /create-first-user\n if (hasUsers.docs.length) {\n throw new Error('Unauthorized')\n }\n }\n\n const clientConfig = getClientConfig({\n config,\n i18n,\n })\n\n let collectionConfig: SanitizedCollectionConfig\n let clientCollectionConfig: ClientCollectionConfig\n\n if (req.payload.collections[collectionSlug]) {\n collectionConfig = req.payload.collections[collectionSlug].config\n clientCollectionConfig = clientConfig.collections.find(\n (collection) => collection.slug === collectionSlug,\n )\n }\n\n // get prefs, then set update them using the columns that we just received\n const preferencesKey = `${collectionSlug}-list`\n\n const preferencesResult = await payload\n .find({\n collection: 'payload-preferences',\n depth: 0,\n limit: 1,\n pagination: false,\n where: {\n and: [\n {\n key: {\n equals: preferencesKey,\n },\n },\n {\n 'user.relationTo': {\n equals: user.collection,\n },\n },\n {\n 'user.value': {\n equals: user.id,\n },\n },\n ],\n },\n })\n .then((res) => res.docs[0] ?? { id: null, value: {} })\n\n let newPrefs = preferencesResult.value\n\n if (!preferencesResult.id || !dequal(columns, preferencesResult?.columns)) {\n const mergedPrefs = {\n ...(preferencesResult || {}),\n columns,\n }\n const preferencesArgs = {\n collection: 'payload-preferences',\n data: {\n key: preferencesKey,\n user: {\n collection: user.collection,\n value: user.id,\n },\n value: mergedPrefs,\n },\n depth: 0,\n req,\n }\n\n if (preferencesResult.id) {\n newPrefs = await payload\n .update({\n ...preferencesArgs,\n id: preferencesResult.id,\n })\n ?.then((res) => res.value as ListPreferences)\n } else {\n newPrefs = await payload.create(preferencesArgs)?.then((res) => res.value as ListPreferences)\n }\n }\n\n const fields = collectionConfig.fields\n\n let docs = docsFromArgs\n let data: PaginatedDocs\n\n // lookup docs, if desired, i.e. within `join` field which initialize with `depth: 0`\n\n if (!docs || query) {\n data = await payload.find({\n collection: collectionSlug,\n depth: 0,\n limit: query?.limit ? parseInt(query.limit, 10) : undefined,\n page: query?.page ? parseInt(query.page, 10) : undefined,\n sort: query?.sort,\n where: query?.where,\n })\n\n docs = data.docs\n }\n\n const { columnState, Table } = renderTable({\n collectionConfig: clientCollectionConfig,\n columnPreferences: undefined, // TODO, might not be needed\n columns,\n docs,\n enableRowSelections,\n fields,\n i18n: req.i18n,\n payload,\n renderRowTypes,\n tableAppearance,\n useAsTitle: collectionConfig.admin.useAsTitle,\n })\n\n const renderedFilters = renderFilters(fields, req.payload.importMap)\n\n return {\n data,\n preferences: newPrefs,\n renderedFilters,\n state: columnState,\n Table,\n }\n}\n"],"mappings":"AAWA,SAASA,MAAM,QAAQ;AACvB,SAASC,kBAAkB,EAAEC,YAAY,QAAQ;AAKjD,SAASC,aAAa,EAAEC,WAAW,QAAQ;AAE3C,IAAIC,kBAAA,GAAqBC,MAAA,CAAOC,qBAAqB;AAErD,IAAI,CAACF,kBAAA,EAAoB;EACvBA,kBAAA,GAAqBC,MAAA,CAAOC,qBAAqB,GAAG;AACtD;AAEA,OAAO,MAAMC,eAAA,GAAmBC,IAAA;EAI9B,MAAM;IAAEC,MAAM;IAAEC;EAAI,CAA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AAA,EAAO;IAClBmC,IAAA,GAAO,MAAM7C,OAAA,CAAQwB,IAAI,CAAC;MACxBT,UAAA,EAAYV,cAAA;MACZoB,KAAA,EAAO;MACPC,KAAA,EAAOhB,KAAA,EAAOgB,KAAA,GAAQuB,QAAA,CAASvC,KAAA,CAAMgB,KAAK,EAAE,MAAMwB,SAAA;MAClDC,IAAA,EAAMzC,KAAA,EAAOyC,IAAA,GAAOF,QAAA,CAASvC,KAAA,CAAMyC,IAAI,EAAE,MAAMD,SAAA;MAC/CE,IAAA,EAAM1C,KAAA,EAAO0C,IAAA;MACbjB,KAAA,EAAOzB,KAAA,EAAOyB;IAChB;IAEA5B,IAAA,GAAOsC,IAAA,CAAKtC,IAAI;EAClB;EAEA,MAAM;IAAE8C,WAAW;IAAEC;EAAK,CAAE,GAAGtE,WAAA,CAAY;IACzC8C,gBAAA,EAAkBC,sBAAA;IAClBwB,iBAAA,EAAmBL,SAAA;IACnB5C,OAAA;IACAC,IAAA;IACAE,mBAAA;IACAuC,MAAA;IACAzD,IAAA,EAAMK,GAAA,CAAIL,IAAI;IACdS,OAAA;IACAW,cAAA;IACAE,eAAA;IACA2C,UAAA,EAAY1B,gBAAA,CAAiBb,KAAK,CAACuC;EACrC;EAEA,MAAMC,eAAA,GAAkB1E,aAAA,CAAciE,MAAA,EAAQpD,GAAA,CAAII,OAAO,CAAC0D,SAAS;EAEnE,OAAO;IACLb,IAAA;IACAc,WAAA,EAAajB,QAAA;IACbe,eAAA;IACAG,KAAA,EAAOP,WAAA;IACPC;EACF;AACF","ignoreList":[]}
1
+ {"version":3,"file":"buildTableState.js","names":["dequal","createClientConfig","formatErrors","renderFilters","renderTable","cachedClientConfig","global","_payload_clientConfig","getClientConfig","args","config","i18n","process","env","NODE_ENV","buildTableStateHandler","req","res","buildTableState","err","payload","logger","error","msg","message","collectionSlug","columns","docs","docsFromArgs","enableRowSelections","query","renderRowTypes","user","tableAppearance","incomingUserSlug","collection","adminUserSlug","admin","adminAccessFunction","collections","access","canAccessAdmin","Error","hasUsers","find","depth","limit","pagination","length","clientConfig","collectionConfig","clientCollectionConfig","slug","preferencesKey","preferencesResult","where","and","key","equals","id","then","value","newPrefs","mergedPrefs","preferencesArgs","data","update","create","fields","parseInt","undefined","page","sort","columnState","Table","columnPreferences","useAsTitle","renderedFilters","importMap","preferences","state"],"sources":["../../src/utilities/buildTableState.ts"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type {\n BuildTableStateArgs,\n ClientCollectionConfig,\n ClientConfig,\n ErrorResult,\n PaginatedDocs,\n SanitizedCollectionConfig,\n SanitizedConfig,\n} from 'payload'\n\nimport { dequal } from 'dequal' // TODO: Can we change this to dequal/lite ? If not, please add comment explaining why\nimport { createClientConfig, formatErrors } from 'payload'\n\nimport type { Column } from '../elements/Table/index.js'\nimport type { ListPreferences } from '../elements/TableColumns/index.js'\n\nimport { renderFilters, renderTable } from './renderTable.js'\n\nlet cachedClientConfig = global._payload_clientConfig\n\nif (!cachedClientConfig) {\n cachedClientConfig = global._payload_clientConfig = null\n}\n\nexport const getClientConfig = (args: {\n config: SanitizedConfig\n i18n: I18nClient\n}): ClientConfig => {\n const { config, i18n } = args\n\n if (cachedClientConfig && process.env.NODE_ENV !== 'development') {\n return cachedClientConfig\n }\n\n cachedClientConfig = createClientConfig({\n config,\n i18n,\n })\n\n return cachedClientConfig\n}\n\ntype BuildTableStateSuccessResult = {\n clientConfig?: ClientConfig\n data: PaginatedDocs\n errors?: never\n preferences: ListPreferences\n renderedFilters: Map<string, React.ReactNode>\n state: Column[]\n Table: React.ReactNode\n}\n\ntype BuildTableStateErrorResult = {\n data?: any\n renderedFilters?: never\n state?: never\n Table?: never\n} & (\n | {\n message: string\n }\n | ErrorResult\n)\n\nexport type BuildTableStateResult = BuildTableStateErrorResult | BuildTableStateSuccessResult\n\nexport const buildTableStateHandler = async (\n args: BuildTableStateArgs,\n): Promise<BuildTableStateResult> => {\n const { req } = args\n\n try {\n const res = await buildTableState(args)\n return res\n } catch (err) {\n req.payload.logger.error({ err, msg: `There was an error building form state` })\n\n if (err.message === 'Could not find field schema for given path') {\n return {\n message: err.message,\n }\n }\n\n if (err.message === 'Unauthorized') {\n return null\n }\n\n return formatErrors(err)\n }\n}\n\nexport const buildTableState = async (\n args: BuildTableStateArgs,\n): Promise<BuildTableStateSuccessResult> => {\n const {\n collectionSlug,\n columns,\n docs: docsFromArgs,\n enableRowSelections,\n query,\n renderRowTypes,\n req,\n req: {\n i18n,\n payload,\n payload: { config },\n user,\n },\n tableAppearance,\n } = args\n\n const incomingUserSlug = user?.collection\n\n const adminUserSlug = config.admin.user\n\n // If we have a user slug, test it against the functions\n if (incomingUserSlug) {\n const adminAccessFunction = payload.collections[incomingUserSlug].config.access?.admin\n\n // Run the admin access function from the config if it exists\n if (adminAccessFunction) {\n const canAccessAdmin = await adminAccessFunction({ req })\n\n if (!canAccessAdmin) {\n throw new Error('Unauthorized')\n }\n // Match the user collection to the global admin config\n } else if (adminUserSlug !== incomingUserSlug) {\n throw new Error('Unauthorized')\n }\n } else {\n const hasUsers = await payload.find({\n collection: adminUserSlug,\n depth: 0,\n limit: 1,\n pagination: false,\n })\n\n // If there are users, we should not allow access because of /create-first-user\n if (hasUsers.docs.length) {\n throw new Error('Unauthorized')\n }\n }\n\n const clientConfig = getClientConfig({\n config,\n i18n,\n })\n\n let collectionConfig: SanitizedCollectionConfig\n let clientCollectionConfig: ClientCollectionConfig\n\n if (req.payload.collections[collectionSlug]) {\n collectionConfig = req.payload.collections[collectionSlug].config\n clientCollectionConfig = clientConfig.collections.find(\n (collection) => collection.slug === collectionSlug,\n )\n }\n\n // get prefs, then set update them using the columns that we just received\n const preferencesKey = `${collectionSlug}-list`\n\n const preferencesResult = await payload\n .find({\n collection: 'payload-preferences',\n depth: 0,\n limit: 1,\n pagination: false,\n where: {\n and: [\n {\n key: {\n equals: preferencesKey,\n },\n },\n {\n 'user.relationTo': {\n equals: user.collection,\n },\n },\n {\n 'user.value': {\n equals: user.id,\n },\n },\n ],\n },\n })\n .then((res) => res.docs[0] ?? { id: null, value: {} })\n\n let newPrefs = preferencesResult.value\n\n if (!preferencesResult.id || !dequal(columns, preferencesResult?.columns)) {\n const mergedPrefs = {\n ...(preferencesResult || {}),\n columns,\n }\n const preferencesArgs = {\n collection: 'payload-preferences',\n data: {\n key: preferencesKey,\n user: {\n collection: user.collection,\n value: user.id,\n },\n value: mergedPrefs,\n },\n depth: 0,\n req,\n }\n\n if (preferencesResult.id) {\n newPrefs = await payload\n .update({\n ...preferencesArgs,\n id: preferencesResult.id,\n })\n ?.then((res) => res.value as ListPreferences)\n } else {\n newPrefs = await payload.create(preferencesArgs)?.then((res) => res.value as ListPreferences)\n }\n }\n\n const fields = collectionConfig.fields\n\n let docs = docsFromArgs\n let data: PaginatedDocs\n\n // lookup docs, if desired, i.e. within `join` field which initialize with `depth: 0`\n\n if (!docs || query) {\n data = await payload.find({\n collection: collectionSlug,\n depth: 0,\n limit: query?.limit ? parseInt(query.limit, 10) : undefined,\n page: query?.page ? parseInt(query.page, 10) : undefined,\n sort: query?.sort,\n where: query?.where,\n })\n\n docs = data.docs\n }\n\n const { columnState, Table } = renderTable({\n collectionConfig: clientCollectionConfig,\n columnPreferences: undefined, // TODO, might not be needed\n columns,\n docs,\n enableRowSelections,\n fields,\n i18n: req.i18n,\n payload,\n renderRowTypes,\n tableAppearance,\n useAsTitle: collectionConfig.admin.useAsTitle,\n })\n\n const renderedFilters = renderFilters(fields, req.payload.importMap)\n\n return {\n data,\n preferences: newPrefs,\n renderedFilters,\n state: columnState,\n Table,\n }\n}\n"],"mappings":"AAWA,SAASA,MAAM,QAAQ,SAAQ,CAAC;AAChC,SAASC,kBAAkB,EAAEC,YAAY,QAAQ;AAKjD,SAASC,aAAa,EAAEC,WAAW,QAAQ;AAE3C,IAAIC,kBAAA,GAAqBC,MAAA,CAAOC,qBAAqB;AAErD,IAAI,CAACF,kBAAA,EAAoB;EACvBA,kBAAA,GAAqBC,MAAA,CAAOC,qB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MAAM;EAEtC,IAAIzC,IAAA,GAAOC,YAAA;EACX,IAAIqC,IAAA;EAEJ;EAEA,IAAI,CAACtC,IAAA,IAAQG,KAAA,EAAO;IAClBmC,IAAA,GAAO,MAAM7C,OAAA,CAAQwB,IAAI,CAAC;MACxBT,UAAA,EAAYV,cAAA;MACZoB,KAAA,EAAO;MACPC,KAAA,EAAOhB,KAAA,EAAOgB,KAAA,GAAQuB,QAAA,CAASvC,KAAA,CAAMgB,KAAK,EAAE,MAAMwB,SAAA;MAClDC,IAAA,EAAMzC,KAAA,EAAOyC,IAAA,GAAOF,QAAA,CAASvC,KAAA,CAAMyC,IAAI,EAAE,MAAMD,SAAA;MAC/CE,IAAA,EAAM1C,KAAA,EAAO0C,IAAA;MACbjB,KAAA,EAAOzB,KAAA,EAAOyB;IAChB;IAEA5B,IAAA,GAAOsC,IAAA,CAAKtC,IAAI;EAClB;EAEA,MAAM;IAAE8C,WAAW;IAAEC;EAAK,CAAE,GAAGtE,WAAA,CAAY;IACzC8C,gBAAA,EAAkBC,sBAAA;IAClBwB,iBAAA,EAAmBL,SAAA;IACnB5C,OAAA;IACAC,IAAA;IACAE,mBAAA;IACAuC,MAAA;IACAzD,IAAA,EAAMK,GAAA,CAAIL,IAAI;IACdS,OAAA;IACAW,cAAA;IACAE,eAAA;IACA2C,UAAA,EAAY1B,gBAAA,CAAiBb,KAAK,CAACuC;EACrC;EAEA,MAAMC,eAAA,GAAkB1E,aAAA,CAAciE,MAAA,EAAQpD,GAAA,CAAII,OAAO,CAAC0D,SAAS;EAEnE,OAAO;IACLb,IAAA;IACAc,WAAA,EAAajB,QAAA;IACbe,eAAA;IACAG,KAAA,EAAOP,WAAA;IACPC;EACF;AACF","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/ui",
3
- "version": "3.0.0-beta.133",
3
+ "version": "3.0.0-beta.134",
4
4
  "homepage": "https://payloadcms.com",
5
5
  "repository": {
6
6
  "type": "git",
@@ -64,6 +64,16 @@
64
64
  "types": "./dist/fields/*/index.d.ts",
65
65
  "default": "./dist/fields/*/index.js"
66
66
  },
67
+ "./forms/fieldSchemasToFormState": {
68
+ "import": "./dist/forms/fieldSchemasToFormState/index.js",
69
+ "types": "./dist/forms/fieldSchemasToFormState/index.d.ts",
70
+ "default": "./dist/forms/fieldSchemasToFormState/index.js"
71
+ },
72
+ "./forms/renderField": {
73
+ "import": "./dist/forms/fieldSchemasToFormState/renderField.js",
74
+ "types": "./dist/forms/fieldSchemasToFormState/renderField.d.ts",
75
+ "default": "./dist/forms/fieldSchemasToFormState/renderField.js"
76
+ },
67
77
  "./forms/*": {
68
78
  "import": "./dist/forms/*/index.js",
69
79
  "types": "./dist/forms/*/index.d.ts",
@@ -123,7 +133,7 @@
123
133
  "ts-essentials": "10.0.3",
124
134
  "use-context-selector": "2.0.0",
125
135
  "uuid": "10.0.0",
126
- "@payloadcms/translations": "3.0.0-beta.133"
136
+ "@payloadcms/translations": "3.0.0-beta.134"
127
137
  },
128
138
  "devDependencies": {
129
139
  "@babel/cli": "^7.24.5",
@@ -141,14 +151,14 @@
141
151
  "esbuild": "0.23.1",
142
152
  "esbuild-sass-plugin": "3.3.1",
143
153
  "eslint-plugin-react-compiler": "19.0.0-beta-a7bf2bd-20241110",
144
- "payload": "3.0.0-beta.133",
154
+ "payload": "3.0.0-beta.134",
145
155
  "@payloadcms/eslint-config": "3.0.0-beta.112"
146
156
  },
147
157
  "peerDependencies": {
148
158
  "next": "^15.0.0",
149
159
  "react": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
150
160
  "react-dom": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
151
- "payload": "3.0.0-beta.133"
161
+ "payload": "3.0.0-beta.134"
152
162
  },
153
163
  "engines": {
154
164
  "node": "^18.20.2 || >=20.9.0"