@payloadcms/ui 3.0.0 → 3.0.1-canary.9494866
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/elements/RenderServerComponent/index.d.ts +8 -5
- package/dist/elements/RenderServerComponent/index.d.ts.map +1 -1
- package/dist/elements/RenderServerComponent/index.js +14 -11
- package/dist/elements/RenderServerComponent/index.js.map +1 -1
- package/dist/elements/TableColumns/buildColumnState.d.ts.map +1 -1
- package/dist/elements/TableColumns/buildColumnState.js +6 -20
- package/dist/elements/TableColumns/buildColumnState.js.map +1 -1
- package/dist/elements/WithServerSideProps/index.js +1 -3
- package/dist/elements/WithServerSideProps/index.js.map +1 -1
- package/dist/exports/client/index.js +10 -10
- package/dist/exports/client/index.js.map +4 -4
- package/dist/exports/shared/index.js +2 -2
- package/dist/exports/shared/index.js.map +2 -2
- package/dist/fields/Array/index.d.ts.map +1 -1
- package/dist/fields/Array/index.js +53 -55
- package/dist/fields/Array/index.js.map +1 -1
- package/dist/fields/Blocks/index.d.ts.map +1 -1
- package/dist/fields/Blocks/index.js +53 -55
- package/dist/fields/Blocks/index.js.map +1 -1
- package/dist/fields/Select/Input.d.ts +1 -0
- package/dist/fields/Select/Input.d.ts.map +1 -1
- package/dist/fields/Select/Input.js +44 -42
- package/dist/fields/Select/Input.js.map +1 -1
- package/dist/fields/Select/index.d.ts.map +1 -1
- package/dist/fields/Select/index.js +1 -0
- package/dist/fields/Select/index.js.map +1 -1
- package/dist/forms/Form/index.d.ts.map +1 -1
- package/dist/forms/Form/index.js +2 -0
- package/dist/forms/Form/index.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/renderField.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/renderField.js +42 -50
- package/dist/forms/fieldSchemasToFormState/renderField.js.map +1 -1
- package/dist/utilities/renderTable.js +2 -2
- package/dist/utilities/renderTable.js.map +1 -1
- package/dist/views/List/index.d.ts.map +1 -1
- package/dist/views/List/index.js +25 -5
- package/dist/views/List/index.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import type { ImportMap, PayloadComponent } from 'payload';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
|
|
4
|
-
* Can be used to render both MappedComponents and React Components.
|
|
5
|
-
*/
|
|
6
|
-
export declare const RenderServerComponent: React.FC<{
|
|
3
|
+
type RenderServerComponentFn = (args: {
|
|
7
4
|
readonly clientProps?: object;
|
|
8
5
|
readonly Component?: PayloadComponent | PayloadComponent[] | React.ComponentType | React.ComponentType[];
|
|
9
6
|
readonly Fallback?: React.ComponentType;
|
|
10
7
|
readonly importMap: ImportMap;
|
|
8
|
+
readonly key?: string;
|
|
11
9
|
readonly serverProps?: object;
|
|
12
|
-
}
|
|
10
|
+
}) => React.ReactNode;
|
|
11
|
+
/**
|
|
12
|
+
* Can be used to render both MappedComponents and React Components.
|
|
13
|
+
*/
|
|
14
|
+
export declare const RenderServerComponent: RenderServerComponentFn;
|
|
15
|
+
export {};
|
|
13
16
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/RenderServerComponent/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAG1D,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/RenderServerComponent/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAG1D,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,KAAK,uBAAuB,GAAG,CAAC,IAAI,EAAE;IACpC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;IAC7B,QAAQ,CAAC,SAAS,CAAC,EACf,gBAAgB,GAChB,gBAAgB,EAAE,GAClB,KAAK,CAAC,aAAa,GACnB,KAAK,CAAC,aAAa,EAAE,CAAA;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IACvC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAA;IAC7B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAC9B,KAAK,KAAK,CAAC,SAAS,CAAA;AAErB;;GAEG;AACH,eAAO,MAAM,qBAAqB,EAAE,uBAiEnC,CAAA"}
|
|
@@ -10,15 +10,17 @@ export const RenderServerComponent = ({
|
|
|
10
10
|
Component,
|
|
11
11
|
Fallback,
|
|
12
12
|
importMap,
|
|
13
|
+
key,
|
|
13
14
|
serverProps
|
|
14
15
|
}) => {
|
|
15
16
|
if (Array.isArray(Component)) {
|
|
16
|
-
return Component.map((c, index) =>
|
|
17
|
-
clientProps
|
|
17
|
+
return Component.map((c, index) => RenderServerComponent({
|
|
18
|
+
clientProps,
|
|
18
19
|
Component: c,
|
|
19
|
-
importMap
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
importMap,
|
|
21
|
+
key: index,
|
|
22
|
+
serverProps
|
|
23
|
+
}));
|
|
22
24
|
}
|
|
23
25
|
if (typeof Component === 'function') {
|
|
24
26
|
const isRSC = isReactServerComponentOrFunction(Component);
|
|
@@ -29,7 +31,7 @@ export const RenderServerComponent = ({
|
|
|
29
31
|
});
|
|
30
32
|
return /*#__PURE__*/_jsx(Component, {
|
|
31
33
|
...sanitizedProps
|
|
32
|
-
});
|
|
34
|
+
}, key);
|
|
33
35
|
}
|
|
34
36
|
if (typeof Component === 'string' || isPlainObject(Component)) {
|
|
35
37
|
const ResolvedComponent = getFromImportMap({
|
|
@@ -48,14 +50,15 @@ export const RenderServerComponent = ({
|
|
|
48
50
|
});
|
|
49
51
|
return /*#__PURE__*/_jsx(ResolvedComponent, {
|
|
50
52
|
...sanitizedProps
|
|
51
|
-
});
|
|
53
|
+
}, key);
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
|
-
return Fallback ?
|
|
55
|
-
clientProps
|
|
56
|
+
return Fallback ? RenderServerComponent({
|
|
57
|
+
clientProps,
|
|
56
58
|
Component: Fallback,
|
|
57
|
-
importMap
|
|
58
|
-
|
|
59
|
+
importMap,
|
|
60
|
+
key,
|
|
61
|
+
serverProps
|
|
59
62
|
}) : null;
|
|
60
63
|
};
|
|
61
64
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["getFromImportMap","isPlainObject","isReactServerComponentOrFunction","React","removeUndefined","RenderServerComponent","clientProps","Component","Fallback","importMap","serverProps","Array","isArray","map","c","index","
|
|
1
|
+
{"version":3,"file":"index.js","names":["getFromImportMap","isPlainObject","isReactServerComponentOrFunction","React","removeUndefined","RenderServerComponent","clientProps","Component","Fallback","importMap","key","serverProps","Array","isArray","map","c","index","isRSC","sanitizedProps","_jsx","ResolvedComponent","PayloadComponent","schemaPath"],"sources":["../../../src/elements/RenderServerComponent/index.tsx"],"sourcesContent":["import type { ImportMap, PayloadComponent } from 'payload'\n\nimport { getFromImportMap, isPlainObject, isReactServerComponentOrFunction } from 'payload/shared'\nimport React from 'react'\n\nimport { removeUndefined } from '../../utilities/removeUndefined.js'\n\ntype RenderServerComponentFn = (args: {\n readonly clientProps?: object\n readonly Component?:\n | PayloadComponent\n | PayloadComponent[]\n | React.ComponentType\n | React.ComponentType[]\n readonly Fallback?: React.ComponentType\n readonly importMap: ImportMap\n readonly key?: string\n readonly serverProps?: object\n}) => React.ReactNode\n\n/**\n * Can be used to render both MappedComponents and React Components.\n */\nexport const RenderServerComponent: RenderServerComponentFn = ({\n clientProps = {},\n Component,\n Fallback,\n importMap,\n key,\n serverProps,\n}) => {\n if (Array.isArray(Component)) {\n return Component.map((c, index) =>\n RenderServerComponent({\n clientProps,\n Component: c,\n importMap,\n key: index,\n serverProps,\n }),\n )\n }\n\n if (typeof Component === 'function') {\n const isRSC = isReactServerComponentOrFunction(Component)\n\n // prevent $undefined from being passed through the rsc requests\n const sanitizedProps = removeUndefined({\n ...clientProps,\n ...(isRSC ? serverProps : {}),\n })\n\n return <Component key={key} {...sanitizedProps} />\n }\n\n if (typeof Component === 'string' || isPlainObject(Component)) {\n const ResolvedComponent = getFromImportMap<React.ComponentType>({\n importMap,\n PayloadComponent: Component,\n schemaPath: '',\n })\n\n if (ResolvedComponent) {\n const isRSC = isReactServerComponentOrFunction(ResolvedComponent)\n\n // prevent $undefined from being passed through rsc requests\n const sanitizedProps = removeUndefined({\n ...clientProps,\n ...(isRSC ? serverProps : {}),\n ...(isRSC && typeof Component === 'object' && Component?.serverProps\n ? Component.serverProps\n : {}),\n ...(typeof Component === 'object' && Component?.clientProps ? Component.clientProps : {}),\n })\n\n return <ResolvedComponent key={key} {...sanitizedProps} />\n }\n }\n\n return Fallback\n ? RenderServerComponent({\n clientProps,\n Component: Fallback,\n importMap,\n key,\n serverProps,\n })\n : null\n}\n"],"mappings":";AAEA,SAASA,gBAAgB,EAAEC,aAAa,EAAEC,gCAAgC,QAAQ;AAClF,OAAOC,KAAA,MAAW;AAElB,SAASC,eAAe,QAAQ;AAehC;;;AAGA,OAAO,MAAMC,qBAAA,GAAiDA,CAAC;EAC7DC,WAAA,GAAc,CAAC,CAAC;EAChBC,SAAS;EACTC,QAAQ;EACRC,SAAS;EACTC,GAAG;EACHC;AAAW,CACZ;EACC,IAAIC,KAAA,CAAMC,OAAO,CAACN,SAAA,GAAY;IAC5B,OAAOA,SAAA,CAAUO,GAAG,CAAC,CAACC,CAAA,EAAGC,KAAA,KACvBX,qBAAA,CAAsB;MACpBC,WAAA;MACAC,SAAA,EAAWQ,CAAA;MACXN,SAAA;MACAC,GAAA,EAAKM,KAAA;MACLL;IACF;EAEJ;EAEA,IAAI,OAAOJ,SAAA,KAAc,YAAY;IACnC,MAAMU,KAAA,GAAQf,gCAAA,CAAiCK,SAAA;IAE/C;IACA,MAAMW,cAAA,GAAiBd,eAAA,CAAgB;MACrC,GAAGE,WAAW;MACd,IAAIW,KAAA,GAAQN,WAAA,GAAc,CAAC,CAAC;IAC9B;IAEA,oBAAOQ,IAAA,CAACZ,SAAA;MAAqB,GAAGW;OAATR,GAAA;EACzB;EAEA,IAAI,OAAOH,SAAA,KAAc,YAAYN,aAAA,CAAcM,SAAA,GAAY;IAC7D,MAAMa,iBAAA,GAAoBpB,gBAAA,CAAsC;MAC9DS,SAAA;MACAY,gBAAA,EAAkBd,SAAA;MAClBe,UAAA,EAAY;IACd;IAEA,IAAIF,iBAAA,EAAmB;MACrB,MAAMH,KAAA,GAAQf,gCAAA,CAAiCkB,iBAAA;MAE/C;MACA,MAAMF,cAAA,GAAiBd,eAAA,CAAgB;QACrC,GAAGE,WAAW;QACd,IAAIW,KAAA,GAAQN,WAAA,GAAc,CAAC,CAAC;QAC5B,IAAIM,KAAA,IAAS,OAAOV,SAAA,KAAc,YAAYA,SAAA,EAAWI,WAAA,GACrDJ,SAAA,CAAUI,WAAW,GACrB,CAAC,CAAC;QACN,IAAI,OAAOJ,SAAA,KAAc,YAAYA,SAAA,EAAWD,WAAA,GAAcC,SAAA,CAAUD,WAAW,GAAG,CAAC,CAAC;MAC1F;MAEA,oBAAOa,IAAA,CAACC,iBAAA;QAA6B,GAAGF;SAATR,GAAA;IACjC;EACF;EAEA,OAAOF,QAAA,GACHH,qBAAA,CAAsB;IACpBC,WAAA;IACAC,SAAA,EAAWC,QAAA;IACXC,SAAA;IACAC,GAAA;IACAC;EACF,KACA;AACN","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildColumnState.d.ts","sourceRoot":"","sources":["../../../src/elements/TableColumns/buildColumnState.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,KAAK,EACV,sBAAsB,EACtB,yBAAyB,EAEzB,KAAK,EACL,aAAa,EACb,OAAO,
|
|
1
|
+
{"version":3,"file":"buildColumnState.d.ts","sourceRoot":"","sources":["../../../src/elements/TableColumns/buildColumnState.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,KAAK,EACV,sBAAsB,EACtB,yBAAyB,EAEzB,KAAK,EACL,aAAa,EACb,OAAO,EACP,yBAAyB,EAE1B,MAAM,SAAS,CAAA;AAMhB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAA;AAC3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AAC7D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAa/C,KAAK,IAAI,GAAG;IACV,UAAU,CAAC,EAAE,MAAM,EAAE,CAAA;IACrB,gBAAgB,EAAE,sBAAsB,CAAA;IACxC,iBAAiB,EAAE,iBAAiB,CAAA;IACpC,OAAO,CAAC,EAAE,iBAAiB,CAAA;IAC3B,eAAe,EAAE,yBAAyB,CAAC,iBAAiB,CAAC,CAAA;IAC7D,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IAC3B,mBAAmB,EAAE,OAAO,CAAA;IAC5B,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,MAAM,EAAE,KAAK,EAAE,CAAA;IACf,IAAI,EAAE,UAAU,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;IAChB,eAAe,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAA;IAC1C,UAAU,EAAE,yBAAyB,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,CAAA;CAC7D,CAAA;AAED,eAAO,MAAM,gBAAgB,SAAU,IAAI,KAAG,MAAM,EAyOnD,CAAA"}
|
|
@@ -76,7 +76,7 @@ export const buildColumnState = args => {
|
|
|
76
76
|
}
|
|
77
77
|
const CustomLabelToRender = _field && 'admin' in _field && 'components' in _field.admin && 'Label' in _field.admin.components && _field.admin.components.Label !== undefined // let it return `null`
|
|
78
78
|
? _field.admin.components.Label : undefined;
|
|
79
|
-
const CustomLabel = CustomLabelToRender ?
|
|
79
|
+
const CustomLabel = CustomLabelToRender ? RenderServerComponent({
|
|
80
80
|
Component: CustomLabelToRender,
|
|
81
81
|
importMap: payload.importMap
|
|
82
82
|
}) : undefined;
|
|
@@ -129,32 +129,18 @@ export const buildColumnState = args => {
|
|
|
129
129
|
if (!_field.admin.components) {
|
|
130
130
|
_field.admin.components = {};
|
|
131
131
|
}
|
|
132
|
-
|
|
133
|
-
* We have to deep copy all the props we send to the client (= CellComponent.clientProps).
|
|
134
|
-
* That way, every editor's field / cell props we send to the client have their own object references.
|
|
135
|
-
*
|
|
136
|
-
* If we send the same object reference to the client twice (e.g. through some configurations where 2 or more fields
|
|
137
|
-
* reference the same editor object, like the root editor), the admin panel may hang indefinitely. This has been happening since
|
|
138
|
-
* a newer Next.js update that made it break when sending the same object reference to the client twice.
|
|
139
|
-
*
|
|
140
|
-
* We can use deepCopyObjectSimple as client props should be JSON-serializable.
|
|
141
|
-
*/
|
|
142
|
-
const CellComponent = _field.editor.CellComponent;
|
|
143
|
-
if (typeof CellComponent === 'object' && CellComponent.clientProps) {
|
|
144
|
-
CellComponent.clientProps = deepCopyObjectSimple(CellComponent.clientProps);
|
|
145
|
-
}
|
|
146
|
-
CustomCell = /*#__PURE__*/_jsx(RenderServerComponent, {
|
|
132
|
+
CustomCell = RenderServerComponent({
|
|
147
133
|
clientProps: cellClientProps,
|
|
148
|
-
Component: CellComponent,
|
|
134
|
+
Component: _field.editor.CellComponent,
|
|
149
135
|
importMap: payload.importMap,
|
|
150
|
-
serverProps
|
|
136
|
+
serverProps
|
|
151
137
|
});
|
|
152
138
|
} else {
|
|
153
|
-
CustomCell = _field?.admin && 'components' in _field.admin && _field.admin.components?.Cell ?
|
|
139
|
+
CustomCell = _field?.admin && 'components' in _field.admin && _field.admin.components?.Cell ? RenderServerComponent({
|
|
154
140
|
clientProps: cellClientProps,
|
|
155
141
|
Component: _field?.admin && 'components' in _field.admin && _field.admin.components?.Cell,
|
|
156
142
|
importMap: payload.importMap,
|
|
157
|
-
serverProps
|
|
143
|
+
serverProps
|
|
158
144
|
}) : undefined;
|
|
159
145
|
}
|
|
160
146
|
return /*#__PURE__*/_jsx(RenderCustomComponent, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildColumnState.js","names":["MissingEditorProp","deepCopyObjectSimple","fieldIsPresentationalOnly","React","RenderCustomComponent","RenderDefaultCell","SelectAll","SelectRow","SortColumn","flattenFieldMap","RenderServerComponent","buildColumnState","args","beforeRows","collectionConfig","columnPreferences","columns","customCellProps","docs","enableRowSelections","fields","i18n","payload","sortColumnProps","useAsTitle","clientFields","sortedFieldMap","_sortedFieldMap","idFieldIndex","findIndex","field","name","idField","splice","unshift","useAsTitleFieldIndex","useAsTitleField","sortTo","sortFieldMap","fieldMap","sort","a","b","aIndex","column","accessor","bIndex","activeColumnsIndices","sorted","reduce","acc","index","_field","find","f","columnPreference","preference","active","Array","isArray","length","includes","push","CustomLabelToRender","admin","components","Label","undefined","CustomLabel","_jsx","Component","importMap","fieldAffectsDataSubFields","type","Heading","disable","label","baseCellClientProps","cellData","rowData","serverProps","renderedCells","map","doc","i","isLinkedColumn","cellClientProps","link","CustomCell","editor","Error","CellComponent","clientProps","Cell","CustomComponent","Fallback","columnIndex","_"],"sources":["../../../src/elements/TableColumns/buildColumnState.tsx"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type {\n ClientCollectionConfig,\n DefaultCellComponentProps,\n DefaultServerCellComponentProps,\n Field,\n PaginatedDocs,\n Payload,\n PayloadComponent,\n SanitizedCollectionConfig,\n StaticLabel,\n} from 'payload'\n\nimport { MissingEditorProp } from 'payload'\nimport { deepCopyObjectSimple, fieldIsPresentationalOnly } from 'payload/shared'\nimport React from 'react'\n\nimport type { ColumnPreferences } from '../../providers/ListQuery/index.js'\nimport type { SortColumnProps } from '../SortColumn/index.js'\nimport type { Column } from '../Table/index.js'\n\nimport {\n RenderCustomComponent,\n RenderDefaultCell,\n SelectAll,\n SelectRow,\n SortColumn,\n // eslint-disable-next-line payload/no-imports-from-exports-dir\n} from '../../exports/client/index.js'\nimport { flattenFieldMap } from '../../utilities/flattenFieldMap.js'\nimport { RenderServerComponent } from '../RenderServerComponent/index.js'\n\ntype Args = {\n beforeRows?: Column[]\n collectionConfig: ClientCollectionConfig\n columnPreferences: ColumnPreferences\n columns?: ColumnPreferences\n customCellProps: DefaultCellComponentProps['customCellProps']\n docs: PaginatedDocs['docs']\n enableRowSelections: boolean\n enableRowTypes?: boolean\n fields: Field[]\n i18n: I18nClient\n payload: Payload\n sortColumnProps?: Partial<SortColumnProps>\n useAsTitle: SanitizedCollectionConfig['admin']['useAsTitle']\n}\n\nexport const buildColumnState = (args: Args): Column[] => {\n const {\n beforeRows,\n collectionConfig,\n columnPreferences,\n columns,\n customCellProps,\n docs,\n enableRowSelections,\n fields,\n i18n,\n payload,\n sortColumnProps,\n useAsTitle,\n } = args\n\n const clientFields = collectionConfig.fields\n\n // clientFields contains the fake `id` column\n let sortedFieldMap = flattenFieldMap(clientFields)\n let _sortedFieldMap = flattenFieldMap(fields) // TODO: think of a way to avoid this additional flatten\n\n // place the `ID` field first, if it exists\n // do the same for the `useAsTitle` field with precedence over the `ID` field\n // then sort the rest of the fields based on the `defaultColumns` or `columnPreferences`\n const idFieldIndex = sortedFieldMap?.findIndex((field) => 'name' in field && field.name === 'id')\n\n if (idFieldIndex > -1) {\n const idField = sortedFieldMap.splice(idFieldIndex, 1)[0]\n sortedFieldMap.unshift(idField)\n }\n\n const useAsTitleFieldIndex = useAsTitle\n ? sortedFieldMap.findIndex((field) => 'name' in field && field.name === useAsTitle)\n : -1\n\n if (useAsTitleFieldIndex > -1) {\n const useAsTitleField = sortedFieldMap.splice(useAsTitleFieldIndex, 1)[0]\n sortedFieldMap.unshift(useAsTitleField)\n }\n\n const sortTo = columnPreferences || columns\n\n const sortFieldMap = (fieldMap, sortTo) =>\n fieldMap?.sort((a, b) => {\n const aIndex = sortTo.findIndex((column) => 'name' in a && column.accessor === a.name)\n const bIndex = sortTo.findIndex((column) => 'name' in b && column.accessor === b.name)\n\n if (aIndex === -1 && bIndex === -1) {\n return 0\n }\n\n if (aIndex === -1) {\n return 1\n }\n\n if (bIndex === -1) {\n return -1\n }\n\n return aIndex - bIndex\n })\n\n if (sortTo) {\n // sort the fields to the order of `defaultColumns` or `columnPreferences`\n sortedFieldMap = sortFieldMap(sortedFieldMap, sortTo)\n _sortedFieldMap = sortFieldMap(_sortedFieldMap, sortTo) // TODO: think of a way to avoid this additional sort\n }\n\n const activeColumnsIndices = []\n\n const sorted: Column[] = sortedFieldMap?.reduce((acc, field, index) => {\n const _field = _sortedFieldMap.find(\n (f) => 'name' in field && 'name' in f && f.name === field.name,\n )\n\n const columnPreference = columnPreferences?.find(\n (preference) => field && 'name' in field && preference.accessor === field.name,\n )\n\n let active = false\n\n if (columnPreference) {\n active = columnPreference.active\n } else if (columns && Array.isArray(columns) && columns.length > 0) {\n active = columns.find(\n (column) => field && 'name' in field && column.accessor === field.name,\n )?.active\n } else if (activeColumnsIndices.length < 4) {\n active = true\n }\n\n if (active && !activeColumnsIndices.includes(index)) {\n activeColumnsIndices.push(index)\n }\n\n const CustomLabelToRender =\n _field &&\n 'admin' in _field &&\n 'components' in _field.admin &&\n 'Label' in _field.admin.components &&\n _field.admin.components.Label !== undefined // let it return `null`\n ? _field.admin.components.Label\n : undefined\n\n const CustomLabel = CustomLabelToRender ? (\n <RenderServerComponent Component={CustomLabelToRender} importMap={payload.importMap} />\n ) : undefined\n\n const fieldAffectsDataSubFields =\n field &&\n field.type &&\n (field.type === 'array' || field.type === 'group' || field.type === 'blocks')\n\n const Heading = (\n <SortColumn\n disable={fieldAffectsDataSubFields || fieldIsPresentationalOnly(field) || undefined}\n Label={CustomLabel}\n label={field && 'label' in field ? (field.label as StaticLabel) : undefined}\n name={'name' in field ? field.name : undefined}\n {...(sortColumnProps || {})}\n />\n )\n\n const baseCellClientProps: DefaultCellComponentProps = {\n cellData: undefined,\n collectionConfig: deepCopyObjectSimple(collectionConfig),\n customCellProps,\n field,\n rowData: undefined,\n }\n\n const serverProps: Pick<DefaultServerCellComponentProps, 'field' | 'i18n' | 'payload'> = {\n field: _field,\n i18n,\n payload,\n }\n\n const column: Column = {\n accessor: 'name' in field ? field.name : undefined,\n active,\n CustomLabel,\n field,\n Heading,\n renderedCells: active\n ? docs.map((doc, i) => {\n const isLinkedColumn = index === activeColumnsIndices[0]\n\n const cellClientProps: DefaultCellComponentProps = {\n ...baseCellClientProps,\n cellData: 'name' in field ? doc[field.name] : undefined,\n link: isLinkedColumn,\n rowData: doc,\n }\n\n let CustomCell = null\n\n if (_field?.type === 'richText') {\n if (!_field?.editor) {\n throw new MissingEditorProp(_field) // 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 _field?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n if (!_field.admin) {\n _field.admin = {}\n }\n\n if (!_field.admin.components) {\n _field.admin.components = {}\n }\n\n /**\n * We have to deep copy all the props we send to the client (= CellComponent.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 CellComponent: PayloadComponent = _field.editor.CellComponent\n if (typeof CellComponent === 'object' && CellComponent.clientProps) {\n CellComponent.clientProps = deepCopyObjectSimple(CellComponent.clientProps)\n }\n\n CustomCell = (\n <RenderServerComponent\n clientProps={cellClientProps}\n Component={CellComponent}\n importMap={payload.importMap}\n serverProps={serverProps}\n />\n )\n } else {\n CustomCell =\n _field?.admin && 'components' in _field.admin && _field.admin.components?.Cell ? (\n <RenderServerComponent\n clientProps={cellClientProps}\n Component={\n _field?.admin && 'components' in _field.admin && _field.admin.components?.Cell\n }\n importMap={payload.importMap}\n serverProps={serverProps}\n />\n ) : undefined\n }\n\n return (\n <RenderCustomComponent\n CustomComponent={CustomCell}\n Fallback={\n <RenderDefaultCell\n clientProps={cellClientProps}\n columnIndex={index}\n enableRowSelections={enableRowSelections}\n isLinkedColumn={isLinkedColumn}\n />\n }\n key={`${i}-${index}`}\n />\n )\n })\n : [],\n }\n\n acc.push(column)\n\n return acc\n }, [])\n\n if (enableRowSelections) {\n sorted?.unshift({\n accessor: '_select',\n active: true,\n field: null,\n Heading: <SelectAll />,\n renderedCells: docs.map((_, i) => <SelectRow key={i} rowData={docs[i]} />),\n })\n }\n\n if (beforeRows) {\n sorted.unshift(...beforeRows)\n }\n\n return sorted\n}\n"],"mappings":";AAaA,SAASA,iBAAiB,QAAQ;AAClC,SAASC,oBAAoB,EAAEC,yBAAyB,QAAQ;AAChE,OAAOC,KAAA,MAAW;AAMlB,SACEC,qBAAqB,EACrBC,iBAAiB,EACjBC,SAAS,EACTC,SAAS,EACTC,UAAU,QAEL;AACP,SAASC,eAAe,QAAQ;AAChC,SAASC,qBAAqB,QAAQ;AAkBtC,OAAO,MAAMC,gBAAA,GAAoBC,IAAA;EAC/B,MAAM;IACJC,UAAU;IACVC,gBAAgB;IAChBC,iBAAiB;IACjBC,OAAO;IACPC,eAAe;IACfC,IAAI;IACJC,mBAAmB;IACnBC,MAAM;IACNC,IAAI;IACJC,OAAO;IACPC,eAAe;IACfC;EAAU,CACX,GAAGZ,IAAA;EAEJ,MAAMa,YAAA,GAAeX,gBAAA,CAAiBM,MAAM;EAE5C;EACA,IAAIM,cAAA,GAAiBjB,eAAA,CAAgBgB,YAAA;EACrC,IAAIE,eAAA,GAAkBlB,eAAA,CAAgBW,MAAA,EAAQ;EAAA;EAE9C;EACA;EACA;EACA,MAAMQ,YAAA,GAAeF,cAA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ingEditorProp","deepCopyObjectSimple","fieldIsPresentationalOnly","React","RenderCustomComponent","RenderDefaultCell","SelectAll","SelectRow","SortColumn","flattenFieldMap","RenderServerComponent","buildColumnState","args","beforeRows","collectionConfig","columnPreferences","columns","customCellProps","docs","enableRowSelections","fields","i18n","payload","sortColumnProps","useAsTitle","clientFields","sortedFieldMap","_sortedFieldMap","idFieldIndex","findIndex","field","name","idField","splice","unshift","useAsTitleFieldIndex","useAsTitleField","sortTo","sortFieldMap","fieldMap","sort","a","b","aIndex","column","accessor","bIndex","activeColumnsIndices","sorted","reduce","acc","index","_field","find","f","columnPreference","preference","active","Array","isArray","length","includes","push","CustomLabelToRender","admin","components","Label","undefined","CustomLabel","Component","importMap","fieldAffectsDataSubFields","type","Heading","_jsx","disable","label","baseCellClientProps","cellData","rowData","serverProps","renderedCells","map","doc","i","isLinkedColumn","cellClientProps","link","CustomCell","editor","Error","clientProps","CellComponent","Cell","CustomComponent","Fallback","columnIndex","_"],"sources":["../../../src/elements/TableColumns/buildColumnState.tsx"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type {\n ClientCollectionConfig,\n DefaultCellComponentProps,\n DefaultServerCellComponentProps,\n Field,\n PaginatedDocs,\n Payload,\n SanitizedCollectionConfig,\n StaticLabel,\n} from 'payload'\n\nimport { MissingEditorProp } from 'payload'\nimport { deepCopyObjectSimple, fieldIsPresentationalOnly } from 'payload/shared'\nimport React from 'react'\n\nimport type { ColumnPreferences } from '../../providers/ListQuery/index.js'\nimport type { SortColumnProps } from '../SortColumn/index.js'\nimport type { Column } from '../Table/index.js'\n\nimport {\n RenderCustomComponent,\n RenderDefaultCell,\n SelectAll,\n SelectRow,\n SortColumn,\n // eslint-disable-next-line payload/no-imports-from-exports-dir\n} from '../../exports/client/index.js'\nimport { flattenFieldMap } from '../../utilities/flattenFieldMap.js'\nimport { RenderServerComponent } from '../RenderServerComponent/index.js'\n\ntype Args = {\n beforeRows?: Column[]\n collectionConfig: ClientCollectionConfig\n columnPreferences: ColumnPreferences\n columns?: ColumnPreferences\n customCellProps: DefaultCellComponentProps['customCellProps']\n docs: PaginatedDocs['docs']\n enableRowSelections: boolean\n enableRowTypes?: boolean\n fields: Field[]\n i18n: I18nClient\n payload: Payload\n sortColumnProps?: Partial<SortColumnProps>\n useAsTitle: SanitizedCollectionConfig['admin']['useAsTitle']\n}\n\nexport const buildColumnState = (args: Args): Column[] => {\n const {\n beforeRows,\n collectionConfig,\n columnPreferences,\n columns,\n customCellProps,\n docs,\n enableRowSelections,\n fields,\n i18n,\n payload,\n sortColumnProps,\n useAsTitle,\n } = args\n\n const clientFields = collectionConfig.fields\n\n // clientFields contains the fake `id` column\n let sortedFieldMap = flattenFieldMap(clientFields)\n let _sortedFieldMap = flattenFieldMap(fields) // TODO: think of a way to avoid this additional flatten\n\n // place the `ID` field first, if it exists\n // do the same for the `useAsTitle` field with precedence over the `ID` field\n // then sort the rest of the fields based on the `defaultColumns` or `columnPreferences`\n const idFieldIndex = sortedFieldMap?.findIndex((field) => 'name' in field && field.name === 'id')\n\n if (idFieldIndex > -1) {\n const idField = sortedFieldMap.splice(idFieldIndex, 1)[0]\n sortedFieldMap.unshift(idField)\n }\n\n const useAsTitleFieldIndex = useAsTitle\n ? sortedFieldMap.findIndex((field) => 'name' in field && field.name === useAsTitle)\n : -1\n\n if (useAsTitleFieldIndex > -1) {\n const useAsTitleField = sortedFieldMap.splice(useAsTitleFieldIndex, 1)[0]\n sortedFieldMap.unshift(useAsTitleField)\n }\n\n const sortTo = columnPreferences || columns\n\n const sortFieldMap = (fieldMap, sortTo) =>\n fieldMap?.sort((a, b) => {\n const aIndex = sortTo.findIndex((column) => 'name' in a && column.accessor === a.name)\n const bIndex = sortTo.findIndex((column) => 'name' in b && column.accessor === b.name)\n\n if (aIndex === -1 && bIndex === -1) {\n return 0\n }\n\n if (aIndex === -1) {\n return 1\n }\n\n if (bIndex === -1) {\n return -1\n }\n\n return aIndex - bIndex\n })\n\n if (sortTo) {\n // sort the fields to the order of `defaultColumns` or `columnPreferences`\n sortedFieldMap = sortFieldMap(sortedFieldMap, sortTo)\n _sortedFieldMap = sortFieldMap(_sortedFieldMap, sortTo) // TODO: think of a way to avoid this additional sort\n }\n\n const activeColumnsIndices = []\n\n const sorted: Column[] = sortedFieldMap?.reduce((acc, field, index) => {\n const _field = _sortedFieldMap.find(\n (f) => 'name' in field && 'name' in f && f.name === field.name,\n )\n\n const columnPreference = columnPreferences?.find(\n (preference) => field && 'name' in field && preference.accessor === field.name,\n )\n\n let active = false\n\n if (columnPreference) {\n active = columnPreference.active\n } else if (columns && Array.isArray(columns) && columns.length > 0) {\n active = columns.find(\n (column) => field && 'name' in field && column.accessor === field.name,\n )?.active\n } else if (activeColumnsIndices.length < 4) {\n active = true\n }\n\n if (active && !activeColumnsIndices.includes(index)) {\n activeColumnsIndices.push(index)\n }\n\n const CustomLabelToRender =\n _field &&\n 'admin' in _field &&\n 'components' in _field.admin &&\n 'Label' in _field.admin.components &&\n _field.admin.components.Label !== undefined // let it return `null`\n ? _field.admin.components.Label\n : undefined\n\n const CustomLabel = CustomLabelToRender\n ? RenderServerComponent({ Component: CustomLabelToRender, importMap: payload.importMap })\n : undefined\n\n const fieldAffectsDataSubFields =\n field &&\n field.type &&\n (field.type === 'array' || field.type === 'group' || field.type === 'blocks')\n\n const Heading = (\n <SortColumn\n disable={fieldAffectsDataSubFields || fieldIsPresentationalOnly(field) || undefined}\n Label={CustomLabel}\n label={field && 'label' in field ? (field.label as StaticLabel) : undefined}\n name={'name' in field ? field.name : undefined}\n {...(sortColumnProps || {})}\n />\n )\n\n const baseCellClientProps: DefaultCellComponentProps = {\n cellData: undefined,\n collectionConfig: deepCopyObjectSimple(collectionConfig),\n customCellProps,\n field,\n rowData: undefined,\n }\n\n const serverProps: Pick<DefaultServerCellComponentProps, 'field' | 'i18n' | 'payload'> = {\n field: _field,\n i18n,\n payload,\n }\n\n const column: Column = {\n accessor: 'name' in field ? field.name : undefined,\n active,\n CustomLabel,\n field,\n Heading,\n renderedCells: active\n ? docs.map((doc, i) => {\n const isLinkedColumn = index === activeColumnsIndices[0]\n\n const cellClientProps: DefaultCellComponentProps = {\n ...baseCellClientProps,\n cellData: 'name' in field ? doc[field.name] : undefined,\n link: isLinkedColumn,\n rowData: doc,\n }\n\n let CustomCell = null\n\n if (_field?.type === 'richText') {\n if (!_field?.editor) {\n throw new MissingEditorProp(_field) // 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 _field?.editor === 'function') {\n throw new Error('Attempted to access unsanitized rich text editor.')\n }\n\n if (!_field.admin) {\n _field.admin = {}\n }\n\n if (!_field.admin.components) {\n _field.admin.components = {}\n }\n\n CustomCell = RenderServerComponent({\n clientProps: cellClientProps,\n Component: _field.editor.CellComponent,\n importMap: payload.importMap,\n serverProps,\n })\n } else {\n CustomCell =\n _field?.admin && 'components' in _field.admin && _field.admin.components?.Cell\n ? RenderServerComponent({\n clientProps: cellClientProps,\n Component:\n _field?.admin &&\n 'components' in _field.admin &&\n _field.admin.components?.Cell,\n importMap: payload.importMap,\n serverProps,\n })\n : undefined\n }\n\n return (\n <RenderCustomComponent\n CustomComponent={CustomCell}\n Fallback={\n <RenderDefaultCell\n clientProps={cellClientProps}\n columnIndex={index}\n enableRowSelections={enableRowSelections}\n isLinkedColumn={isLinkedColumn}\n />\n }\n key={`${i}-${index}`}\n />\n )\n })\n : [],\n }\n\n acc.push(column)\n\n return acc\n }, [])\n\n if (enableRowSelections) {\n sorted?.unshift({\n accessor: '_select',\n active: true,\n field: null,\n Heading: <SelectAll />,\n renderedCells: docs.map((_, i) => <SelectRow key={i} rowData={docs[i]} />),\n })\n }\n\n if (beforeRows) {\n sorted.unshift(...beforeRows)\n }\n\n return sorted\n}\n"],"mappings":";AAYA,SAASA,iBAAiB,QAAQ;AAClC,SAASC,oBAAoB,EAAEC,yBAAyB,QAAQ;AAChE,OAAOC,KAAA,MAAW;AAMlB,SACEC,qBAAqB,EACrBC,iBAAiB,EACj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/D,IAAA,CAAKgE,GAAG,CAAC,CAACe,CAAA,EAAGb,CAAA,kBAAMV,IAAA,CAACnE,SAAA;QAAkBwE,OAAA,EAAS7D,IAAI,CAACkE,CAAA;SAAjBA,CAAA;IACpD;EACF;EAEA,IAAIvE,UAAA,EAAY;IACdmC,MAAA,CAAOd,OAAO,IAAIrB,UAAA;EACpB;EAEA,OAAOmC,MAAA;AACT","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["isReactServerComponentOrFunction","React","WithServerSideProps","Component","serverOnlyProps","rest","passedProps","propsWithServerOnlyProps","_jsx"],"sources":["../../../src/elements/WithServerSideProps/index.tsx"],"sourcesContent":["import type { WithServerSidePropsComponent } from 'payload'\n\nimport { isReactServerComponentOrFunction } from 'payload/shared'\nimport React from 'react'\n\nexport const WithServerSideProps: WithServerSidePropsComponent = ({\n Component,\n serverOnlyProps,\n ...rest\n}) => {\n if (Component) {\n const WithServerSideProps: React.FC = (passedProps) => {\n const propsWithServerOnlyProps = {\n ...passedProps,\n ...(isReactServerComponentOrFunction(Component) ? (serverOnlyProps ?? {}) : {}),\n }\n\n return <Component {...propsWithServerOnlyProps} />\n }\n\n return
|
|
1
|
+
{"version":3,"file":"index.js","names":["isReactServerComponentOrFunction","React","WithServerSideProps","Component","serverOnlyProps","rest","passedProps","propsWithServerOnlyProps","_jsx"],"sources":["../../../src/elements/WithServerSideProps/index.tsx"],"sourcesContent":["import type { WithServerSidePropsComponent } from 'payload'\n\nimport { isReactServerComponentOrFunction } from 'payload/shared'\nimport React from 'react'\n\nexport const WithServerSideProps: WithServerSidePropsComponent = ({\n Component,\n serverOnlyProps,\n ...rest\n}) => {\n if (Component) {\n const WithServerSideProps: React.FC = (passedProps) => {\n const propsWithServerOnlyProps = {\n ...passedProps,\n ...(isReactServerComponentOrFunction(Component) ? (serverOnlyProps ?? {}) : {}),\n }\n\n return <Component {...propsWithServerOnlyProps} />\n }\n\n return WithServerSideProps(rest)\n }\n\n return null\n}\n"],"mappings":";AAEA,SAASA,gCAAgC,QAAQ;AACjD,OAAOC,KAAA,MAAW;AAElB,OAAO,MAAMC,mBAAA,GAAoDA,CAAC;EAChEC,SAAS;EACTC,eAAe;EACf,GAAGC;AAAA,CACJ;EACC,IAAIF,SAAA,EAAW;IACb,MAAMD,mBAAA,GAAiCI,WAAA;MACrC,MAAMC,wBAAA,GAA2B;QAC/B,GAAGD,WAAW;QACd,IAAIN,gCAAA,CAAiCG,SAAA,IAAcC,eAAA,IAAmB,CAAC,IAAK,CAAC,CAAC;MAChF;MAEA,oBAAOI,IAAA,CAACL,SAAA;QAAW,GAAGI;;IACxB;IAEA,OAAOL,mBAAA,CAAoBG,IAAA;EAC7B;EAEA,OAAO;AACT","ignoreList":[]}
|