@payloadcms/ui 3.0.0-beta.32 → 3.0.0-beta.34
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/assets/index.d.ts +4 -4
- package/dist/assets/index.d.ts.map +1 -1
- package/dist/assets/index.js +4 -4
- package/dist/assets/index.js.map +1 -1
- package/dist/elements/Banner/index.js +1 -1
- package/dist/elements/Banner/index.js.map +1 -1
- package/dist/elements/Pill/index.js +1 -1
- package/dist/elements/Pill/index.js.map +1 -1
- package/dist/elements/ReactSelect/ClearIndicator/index.d.ts.map +1 -1
- package/dist/elements/ReactSelect/ClearIndicator/index.js +10 -2
- package/dist/elements/ReactSelect/ClearIndicator/index.js.map +1 -1
- package/dist/elements/ReactSelect/ClearIndicator/index.scss +4 -0
- package/dist/elements/ReactSelect/DropdownIndicator/index.d.ts +8 -0
- package/dist/elements/ReactSelect/DropdownIndicator/index.d.ts.map +1 -0
- package/dist/elements/ReactSelect/DropdownIndicator/index.js +19 -0
- package/dist/elements/ReactSelect/DropdownIndicator/index.js.map +1 -0
- package/dist/elements/ReactSelect/DropdownIndicator/index.scss +16 -0
- package/dist/elements/ReactSelect/MultiValue/index.d.ts.map +1 -1
- package/dist/elements/ReactSelect/MultiValue/index.js +3 -3
- package/dist/elements/ReactSelect/MultiValue/index.js.map +1 -1
- package/dist/elements/ReactSelect/MultiValueLabel/index.scss +4 -0
- package/dist/elements/ReactSelect/MultiValueRemove/index.d.ts.map +1 -1
- package/dist/elements/ReactSelect/MultiValueRemove/index.js +6 -0
- package/dist/elements/ReactSelect/MultiValueRemove/index.js.map +1 -1
- package/dist/elements/ReactSelect/index.js +3 -3
- package/dist/elements/ReactSelect/index.js.map +1 -1
- package/dist/elements/ReactSelect/index.scss +1 -1
- package/dist/elements/StepNav/index.d.ts.map +1 -1
- package/dist/elements/StepNav/index.js +13 -3
- package/dist/elements/StepNav/index.js.map +1 -1
- package/dist/elements/StepNav/index.scss +11 -0
- package/dist/fields/Relationship/index.js +1 -1
- package/dist/fields/Relationship/index.js.map +1 -1
- package/dist/fields/Relationship/select-components/MultiValueLabel/index.d.ts.map +1 -1
- package/dist/fields/Relationship/select-components/MultiValueLabel/index.js +8 -1
- package/dist/fields/Relationship/select-components/MultiValueLabel/index.js.map +1 -1
- package/dist/fields/Relationship/select-components/MultiValueLabel/index.scss +4 -0
- package/dist/fields/Relationship/select-components/SingleValue/index.d.ts.map +1 -1
- package/dist/fields/Relationship/select-components/SingleValue/index.js +5 -0
- package/dist/fields/Relationship/select-components/SingleValue/index.js.map +1 -1
- package/dist/fields/Relationship/select-components/SingleValue/index.scss +2 -2
- package/dist/forms/Form/index.js.map +1 -1
- package/dist/forms/Submit/index.d.ts.map +1 -1
- package/dist/forms/Submit/index.js.map +1 -1
- package/dist/graphics/Icon/index.d.ts +3 -1
- package/dist/graphics/Icon/index.d.ts.map +1 -1
- package/dist/graphics/Icon/index.js +10 -36
- package/dist/graphics/Icon/index.js.map +1 -1
- package/dist/icons/Edit/index.d.ts +3 -1
- package/dist/icons/Edit/index.d.ts.map +1 -1
- package/dist/icons/Edit/index.js +5 -2
- package/dist/icons/Edit/index.js.map +1 -1
- package/dist/providers/ComponentMap/buildComponentMap/collections.d.ts.map +1 -1
- package/dist/providers/ComponentMap/buildComponentMap/collections.js +3 -2
- package/dist/providers/ComponentMap/buildComponentMap/collections.js.map +1 -1
- package/dist/providers/ComponentMap/buildComponentMap/globals.d.ts.map +1 -1
- package/dist/providers/ComponentMap/buildComponentMap/globals.js +2 -1
- package/dist/providers/ComponentMap/buildComponentMap/globals.js.map +1 -1
- package/dist/providers/DocumentInfo/index.d.ts.map +1 -1
- package/dist/providers/DocumentInfo/index.js +40 -27
- package/dist/providers/DocumentInfo/index.js.map +1 -1
- package/dist/utilities/hasSavePermission.d.ts +8 -0
- package/dist/utilities/hasSavePermission.d.ts.map +1 -0
- package/dist/utilities/hasSavePermission.js +12 -0
- package/dist/utilities/hasSavePermission.js.map +1 -0
- package/dist/utilities/isEditing.d.ts +6 -0
- package/dist/utilities/isEditing.d.ts.map +1 -0
- package/dist/utilities/isEditing.js +3 -0
- package/dist/utilities/isEditing.js.map +1 -0
- package/package.json +10 -10
- /package/dist/assets/{og-image.png → static-og-image.png} +0 -0
package/dist/icons/Edit/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
export const Edit = ()=>/*#__PURE__*/ React.createElement("svg", {
|
|
3
|
-
className:
|
|
2
|
+
export const Edit = ({ className })=>/*#__PURE__*/ React.createElement("svg", {
|
|
3
|
+
className: [
|
|
4
|
+
className,
|
|
5
|
+
'icon icon--edit'
|
|
6
|
+
].filter(Boolean).join(' '),
|
|
4
7
|
viewBox: "0 0 25 25",
|
|
5
8
|
xmlns: "http://www.w3.org/2000/svg"
|
|
6
9
|
}, /*#__PURE__*/ React.createElement("polygon", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/icons/Edit/index.tsx"],"sourcesContent":["import React from 'react'\n\nimport './index.scss'\n\nexport const Edit: React.FC = () => (\n <svg
|
|
1
|
+
{"version":3,"sources":["../../../src/icons/Edit/index.tsx"],"sourcesContent":["import React from 'react'\n\nimport './index.scss'\n\nexport const Edit: React.FC<{ className?: string }> = ({ className }) => (\n <svg\n className={[className, 'icon icon--edit'].filter(Boolean).join(' ')}\n viewBox=\"0 0 25 25\"\n xmlns=\"http://www.w3.org/2000/svg\"\n >\n <polygon\n className=\"fill\"\n points=\"16.92 16.86 8.25 16.86 8.25 8.21 12.54 8.21 12.54 6.63 6.68 6.63 6.68 18.43 18.5 18.43 18.5 12.53 16.92 12.53 16.92 16.86\"\n />\n <polygon\n className=\"fill\"\n points=\"16.31 7.33 17.42 8.44 12.66 13.2 11.51 13.24 11.55 12.09 16.31 7.33\"\n />\n <rect\n className=\"fill\"\n height=\"1.15\"\n transform=\"translate(10.16 -10.48) rotate(45)\"\n width=\"1.58\"\n x=\"16.94\"\n y=\"6.44\"\n />\n </svg>\n)\n"],"names":["React","Edit","className","svg","filter","Boolean","join","viewBox","xmlns","polygon","points","rect","height","transform","width","x","y"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,WAAW,QAAO;AAIzB,OAAO,MAAMC,OAAyC,CAAC,EAAEC,SAAS,EAAE,iBAClE,oBAACC;QACCD,WAAW;YAACA;YAAW;SAAkB,CAACE,MAAM,CAACC,SAASC,IAAI,CAAC;QAC/DC,SAAQ;QACRC,OAAM;qBAEN,oBAACC;QACCP,WAAU;QACVQ,QAAO;sBAET,oBAACD;QACCP,WAAU;QACVQ,QAAO;sBAET,oBAACC;QACCT,WAAU;QACVU,QAAO;QACPC,WAAU;QACVC,OAAM;QACNC,GAAE;QACFC,GAAE;QAGP"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collections.d.ts","sourceRoot":"","sources":["../../../../src/providers/ComponentMap/buildComponentMap/collections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,yBAAyB,EACzB,eAAe,EAChB,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"collections.d.ts","sourceRoot":"","sources":["../../../../src/providers/ComponentMap/buildComponentMap/collections.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,yBAAyB,EACzB,eAAe,EAChB,MAAM,eAAe,CAAA;AAGtB,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,YAAY,CAAA;AACjE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAMxD,eAAO,MAAM,cAAc,SAAU;IACnC,eAAe,EAAE,MAAM,EAAE,CAAC,aAAa,CAAC,CAAA;IACxC,eAAe,EAAE,MAAM,EAAE,CAAC,cAAc,CAAC,CAAA;IACzC,mBAAmB,EAAE,+BAA+B,CAAA;IACpD,WAAW,EAAE,yBAAyB,EAAE,CAAA;IACxC,MAAM,EAAE,eAAe,CAAA;IACvB,IAAI,EAAE,UAAU,CAAA;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,KAAG;IACF,CAAC,GAAG,EAAE,yBAAyB,CAAC,MAAM,CAAC,GAAG,sBAAsB,CAAA;CAkKjE,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isReactComponentOrFunction } from 'payload/utilities';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import { ViewDescription } from '../../../elements/ViewDescription/index.js';
|
|
3
4
|
import { mapActions } from './actions.js';
|
|
@@ -15,8 +16,8 @@ export const mapCollections = (args)=>{
|
|
|
15
16
|
}
|
|
16
17
|
const editViewFromConfig = collectionConfig?.admin?.components?.views?.Edit;
|
|
17
18
|
const listViewFromConfig = collectionConfig?.admin?.components?.views?.List;
|
|
18
|
-
const CustomEditView = typeof editViewFromConfig === 'function' ? editViewFromConfig : typeof editViewFromConfig === 'object' &&
|
|
19
|
-
const CustomListView = typeof listViewFromConfig === 'function' ? listViewFromConfig : typeof listViewFromConfig === 'object' &&
|
|
19
|
+
const CustomEditView = typeof editViewFromConfig === 'function' ? editViewFromConfig : typeof editViewFromConfig === 'object' && isReactComponentOrFunction(editViewFromConfig.Default) ? editViewFromConfig.Default : typeof editViewFromConfig?.Default === 'object' && 'Component' in editViewFromConfig.Default && isReactComponentOrFunction(editViewFromConfig.Default.Component) ? editViewFromConfig.Default.Component : undefined;
|
|
20
|
+
const CustomListView = typeof listViewFromConfig === 'function' ? listViewFromConfig : typeof listViewFromConfig === 'object' && isReactComponentOrFunction(listViewFromConfig.Component) ? listViewFromConfig.Component : undefined;
|
|
20
21
|
const Edit = CustomEditView || DefaultEditView;
|
|
21
22
|
const List = CustomListView || DefaultListView;
|
|
22
23
|
const SaveButtonComponent = collectionConfig?.admin?.components?.edit?.SaveButton;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/providers/ComponentMap/buildComponentMap/collections.tsx"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type {\n AdminViewProps,\n EditViewProps,\n SanitizedCollectionConfig,\n SanitizedConfig,\n} from 'payload/types'\n\nimport React from 'react'\n\nimport type { ViewDescriptionProps } from '../../../elements/ViewDescription/index.js'\nimport type { WithServerSidePropsPrePopulated } from './index.js'\nimport type { CollectionComponentMap } from './types.js'\n\nimport { ViewDescription } from '../../../elements/ViewDescription/index.js'\nimport { mapActions } from './actions.js'\nimport { mapFields } from './fields.js'\n\nexport const mapCollections = (args: {\n DefaultEditView: React.FC<EditViewProps>\n DefaultListView: React.FC<AdminViewProps>\n WithServerSideProps: WithServerSidePropsPrePopulated\n collections: SanitizedCollectionConfig[]\n config: SanitizedConfig\n i18n: I18nClient\n readOnly?: boolean\n}): {\n [key: SanitizedCollectionConfig['slug']]: CollectionComponentMap\n} => {\n const {\n DefaultEditView,\n DefaultListView,\n WithServerSideProps,\n collections,\n config,\n i18n,\n i18n: { t },\n readOnly: readOnlyOverride,\n } = args\n\n return collections.reduce((acc, collectionConfig) => {\n const { slug, fields } = collectionConfig\n\n const internalCollections = ['payload-preferences', 'payload-migrations']\n\n if (internalCollections.includes(slug)) {\n return acc\n }\n\n const editViewFromConfig = collectionConfig?.admin?.components?.views?.Edit\n\n const listViewFromConfig = collectionConfig?.admin?.components?.views?.List\n\n const CustomEditView =\n typeof editViewFromConfig === 'function'\n ? editViewFromConfig\n : typeof editViewFromConfig === 'object' && typeof editViewFromConfig.Default === 'function'\n ? editViewFromConfig.Default\n : typeof editViewFromConfig?.Default === 'object' &&\n 'Component' in editViewFromConfig.Default &&\n typeof editViewFromConfig.Default.Component === 'function'\n ? (editViewFromConfig.Default.Component as React.FC<EditViewProps>)\n : undefined\n\n const CustomListView =\n typeof listViewFromConfig === 'function'\n ? listViewFromConfig\n : typeof listViewFromConfig === 'object' &&\n typeof listViewFromConfig.Component === 'function'\n ? listViewFromConfig.Component\n : undefined\n\n const Edit = (CustomEditView as React.FC<EditViewProps>) || DefaultEditView\n\n const List = CustomListView || DefaultListView\n\n const SaveButtonComponent = collectionConfig?.admin?.components?.edit?.SaveButton\n\n const SaveButton = SaveButtonComponent ? (\n <WithServerSideProps Component={SaveButtonComponent} />\n ) : undefined\n\n const SaveDraftButtonComponent = collectionConfig?.admin?.components?.edit?.SaveDraftButton\n\n const SaveDraftButton = SaveDraftButtonComponent ? (\n <WithServerSideProps Component={SaveDraftButtonComponent} />\n ) : undefined\n\n const PreviewButtonComponent = collectionConfig?.admin?.components?.edit?.PreviewButton\n\n const PreviewButton = PreviewButtonComponent ? (\n <WithServerSideProps Component={PreviewButtonComponent} />\n ) : undefined\n\n const PublishButtonComponent = collectionConfig?.admin?.components?.edit?.PublishButton\n\n const PublishButton = PublishButtonComponent ? (\n <WithServerSideProps Component={PublishButtonComponent} />\n ) : undefined\n\n const beforeList = collectionConfig?.admin?.components?.BeforeList\n\n const BeforeList =\n (beforeList &&\n Array.isArray(beforeList) &&\n beforeList?.map((Component) => <WithServerSideProps Component={Component} />)) ||\n null\n\n const beforeListTable = collectionConfig?.admin?.components?.BeforeListTable\n\n const BeforeListTable =\n (beforeListTable &&\n Array.isArray(beforeListTable) &&\n beforeListTable?.map((Component) => <WithServerSideProps Component={Component} />)) ||\n null\n\n const afterList = collectionConfig?.admin?.components?.AfterList\n\n const AfterList =\n (afterList &&\n Array.isArray(afterList) &&\n afterList?.map((Component) => <WithServerSideProps Component={Component} />)) ||\n null\n\n const afterListTable = collectionConfig?.admin?.components?.AfterListTable\n\n const AfterListTable =\n (afterListTable &&\n Array.isArray(afterListTable) &&\n afterListTable?.map((Component) => <WithServerSideProps Component={Component} />)) ||\n null\n\n let description = undefined\n if (collectionConfig.admin && 'description' in collectionConfig.admin) {\n if (\n typeof collectionConfig.admin?.description === 'string' ||\n typeof collectionConfig.admin?.description === 'object'\n ) {\n description = collectionConfig.admin.description\n } else if (typeof collectionConfig.admin?.description === 'function') {\n description = collectionConfig.admin?.description({ t })\n }\n }\n\n const descriptionProps: ViewDescriptionProps = {\n description,\n }\n\n const DescriptionComponent =\n collectionConfig.admin?.components?.edit?.Description ||\n (description ? ViewDescription : undefined)\n\n const Description =\n DescriptionComponent !== undefined ? (\n <WithServerSideProps Component={DescriptionComponent} {...(descriptionProps || {})} />\n ) : undefined\n\n const componentMap: CollectionComponentMap = {\n AfterList,\n AfterListTable,\n BeforeList,\n BeforeListTable,\n Description,\n Edit: <Edit collectionSlug={collectionConfig.slug} />,\n List: <List collectionSlug={collectionConfig.slug} />,\n PreviewButton,\n PublishButton,\n SaveButton,\n SaveDraftButton,\n actionsMap: mapActions({\n WithServerSideProps,\n collectionConfig,\n }),\n fieldMap: mapFields({\n WithServerSideProps,\n config,\n fieldSchema: fields,\n i18n,\n readOnly: readOnlyOverride,\n }),\n isPreviewEnabled: !!collectionConfig?.admin?.preview,\n }\n\n return {\n ...acc,\n [slug]: componentMap,\n }\n }, {})\n}\n"],"names":["React","ViewDescription","mapActions","mapFields","mapCollections","args","DefaultEditView","DefaultListView","WithServerSideProps","collections","config","i18n","t","readOnly","readOnlyOverride","reduce","acc","collectionConfig","slug","fields","internalCollections","includes","editViewFromConfig","admin","components","views","Edit","listViewFromConfig","List","CustomEditView","Default","Component","undefined","CustomListView","SaveButtonComponent","edit","SaveButton","SaveDraftButtonComponent","SaveDraftButton","PreviewButtonComponent","PreviewButton","PublishButtonComponent","PublishButton","beforeList","BeforeList","Array","isArray","map","beforeListTable","BeforeListTable","afterList","AfterList","afterListTable","AfterListTable","description","descriptionProps","DescriptionComponent","Description","componentMap","collectionSlug","actionsMap","fieldMap","fieldSchema","isPreviewEnabled","preview"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,iBAAiBM,KAAK,EAAE+B,gBAAgB,YAC/C,OAAOrC,iBAAiBM,KAAK,EAAE+B,gBAAgB,UAC/C;gBACAA,cAAcrC,iBAAiBM,KAAK,CAAC+B,WAAW;YAClD,OAAO,IAAI,OAAOrC,iBAAiBM,KAAK,EAAE+B,gBAAgB,YAAY;gBACpEA,cAAcrC,iBAAiBM,KAAK,EAAE+B,YAAY;oBAAE1C;gBAAE;YACxD;QACF;QAEA,MAAM2C,mBAAyC;YAC7CD;QACF;QAEA,MAAME,uBACJvC,iBAAiBM,KAAK,EAAEC,YAAYW,MAAMsB,eACzCH,CAAAA,cAAcrD,kBAAkB+B,SAAQ;QAE3C,MAAMyB,cACJD,yBAAyBxB,0BACvB,oBAACxB;YAAoBuB,WAAWyB;YAAuB,GAAID,oBAAoB,CAAC,CAAC;aAC/EvB;QAEN,MAAM0B,eAAuC;YAC3CP;YACAE;YACAT;YACAK;YACAQ;YACA/B,oBAAM,oBAACA;gBAAKiC,gBAAgB1C,iBAAiBC,IAAI;;YACjDU,oBAAM,oBAACA;gBAAK+B,gBAAgB1C,iBAAiBC,IAAI;;YACjDsB;YACAE;YACAN;YACAE;YACAsB,YAAY1D,WAAW;gBACrBM;gBACAS;YACF;YACA4C,UAAU1D,UAAU;gBAClBK;gBACAE;gBACAoD,aAAa3C;gBACbR;gBACAE,UAAUC;YACZ;YACAiD,kBAAkB,CAAC,CAAC9C,kBAAkBM,OAAOyC;QAC/C;QAEA,OAAO;YACL,GAAGhD,GAAG;YACN,CAACE,KAAK,EAAEwC;QACV;IACF,GAAG,CAAC;AACN,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/providers/ComponentMap/buildComponentMap/collections.tsx"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type {\n AdminViewProps,\n EditViewProps,\n SanitizedCollectionConfig,\n SanitizedConfig,\n} from 'payload/types'\n\nimport { isReactComponentOrFunction } from 'payload/utilities'\nimport React from 'react'\n\nimport type { ViewDescriptionProps } from '../../../elements/ViewDescription/index.js'\nimport type { WithServerSidePropsPrePopulated } from './index.js'\nimport type { CollectionComponentMap } from './types.js'\n\nimport { ViewDescription } from '../../../elements/ViewDescription/index.js'\nimport { mapActions } from './actions.js'\nimport { mapFields } from './fields.js'\n\nexport const mapCollections = (args: {\n DefaultEditView: React.FC<EditViewProps>\n DefaultListView: React.FC<AdminViewProps>\n WithServerSideProps: WithServerSidePropsPrePopulated\n collections: SanitizedCollectionConfig[]\n config: SanitizedConfig\n i18n: I18nClient\n readOnly?: boolean\n}): {\n [key: SanitizedCollectionConfig['slug']]: CollectionComponentMap\n} => {\n const {\n DefaultEditView,\n DefaultListView,\n WithServerSideProps,\n collections,\n config,\n i18n,\n i18n: { t },\n readOnly: readOnlyOverride,\n } = args\n\n return collections.reduce((acc, collectionConfig) => {\n const { slug, fields } = collectionConfig\n\n const internalCollections = ['payload-preferences', 'payload-migrations']\n\n if (internalCollections.includes(slug)) {\n return acc\n }\n\n const editViewFromConfig = collectionConfig?.admin?.components?.views?.Edit\n\n const listViewFromConfig = collectionConfig?.admin?.components?.views?.List\n\n const CustomEditView =\n typeof editViewFromConfig === 'function'\n ? editViewFromConfig\n : typeof editViewFromConfig === 'object' &&\n isReactComponentOrFunction(editViewFromConfig.Default)\n ? editViewFromConfig.Default\n : typeof editViewFromConfig?.Default === 'object' &&\n 'Component' in editViewFromConfig.Default &&\n isReactComponentOrFunction(editViewFromConfig.Default.Component)\n ? (editViewFromConfig.Default.Component as React.FC<EditViewProps>)\n : undefined\n\n const CustomListView =\n typeof listViewFromConfig === 'function'\n ? listViewFromConfig\n : typeof listViewFromConfig === 'object' &&\n isReactComponentOrFunction(listViewFromConfig.Component)\n ? listViewFromConfig.Component\n : undefined\n\n const Edit = (CustomEditView as React.FC<EditViewProps>) || DefaultEditView\n\n const List = CustomListView || DefaultListView\n\n const SaveButtonComponent = collectionConfig?.admin?.components?.edit?.SaveButton\n\n const SaveButton = SaveButtonComponent ? (\n <WithServerSideProps Component={SaveButtonComponent} />\n ) : undefined\n\n const SaveDraftButtonComponent = collectionConfig?.admin?.components?.edit?.SaveDraftButton\n\n const SaveDraftButton = SaveDraftButtonComponent ? (\n <WithServerSideProps Component={SaveDraftButtonComponent} />\n ) : undefined\n\n const PreviewButtonComponent = collectionConfig?.admin?.components?.edit?.PreviewButton\n\n const PreviewButton = PreviewButtonComponent ? (\n <WithServerSideProps Component={PreviewButtonComponent} />\n ) : undefined\n\n const PublishButtonComponent = collectionConfig?.admin?.components?.edit?.PublishButton\n\n const PublishButton = PublishButtonComponent ? (\n <WithServerSideProps Component={PublishButtonComponent} />\n ) : undefined\n\n const beforeList = collectionConfig?.admin?.components?.BeforeList\n\n const BeforeList =\n (beforeList &&\n Array.isArray(beforeList) &&\n beforeList?.map((Component) => <WithServerSideProps Component={Component} />)) ||\n null\n\n const beforeListTable = collectionConfig?.admin?.components?.BeforeListTable\n\n const BeforeListTable =\n (beforeListTable &&\n Array.isArray(beforeListTable) &&\n beforeListTable?.map((Component) => <WithServerSideProps Component={Component} />)) ||\n null\n\n const afterList = collectionConfig?.admin?.components?.AfterList\n\n const AfterList =\n (afterList &&\n Array.isArray(afterList) &&\n afterList?.map((Component) => <WithServerSideProps Component={Component} />)) ||\n null\n\n const afterListTable = collectionConfig?.admin?.components?.AfterListTable\n\n const AfterListTable =\n (afterListTable &&\n Array.isArray(afterListTable) &&\n afterListTable?.map((Component) => <WithServerSideProps Component={Component} />)) ||\n null\n\n let description = undefined\n if (collectionConfig.admin && 'description' in collectionConfig.admin) {\n if (\n typeof collectionConfig.admin?.description === 'string' ||\n typeof collectionConfig.admin?.description === 'object'\n ) {\n description = collectionConfig.admin.description\n } else if (typeof collectionConfig.admin?.description === 'function') {\n description = collectionConfig.admin?.description({ t })\n }\n }\n\n const descriptionProps: ViewDescriptionProps = {\n description,\n }\n\n const DescriptionComponent =\n collectionConfig.admin?.components?.edit?.Description ||\n (description ? ViewDescription : undefined)\n\n const Description =\n DescriptionComponent !== undefined ? (\n <WithServerSideProps Component={DescriptionComponent} {...(descriptionProps || {})} />\n ) : undefined\n\n const componentMap: CollectionComponentMap = {\n AfterList,\n AfterListTable,\n BeforeList,\n BeforeListTable,\n Description,\n Edit: <Edit collectionSlug={collectionConfig.slug} />,\n List: <List collectionSlug={collectionConfig.slug} />,\n PreviewButton,\n PublishButton,\n SaveButton,\n SaveDraftButton,\n actionsMap: mapActions({\n WithServerSideProps,\n collectionConfig,\n }),\n fieldMap: mapFields({\n WithServerSideProps,\n config,\n fieldSchema: fields,\n i18n,\n readOnly: readOnlyOverride,\n }),\n isPreviewEnabled: !!collectionConfig?.admin?.preview,\n }\n\n return {\n ...acc,\n [slug]: componentMap,\n }\n }, {})\n}\n"],"names":["isReactComponentOrFunction","React","ViewDescription","mapActions","mapFields","mapCollections","args","DefaultEditView","DefaultListView","WithServerSideProps","collections","config","i18n","t","readOnly","readOnlyOverride","reduce","acc","collectionConfig","slug","fields","internalCollections","includes","editViewFromConfig","admin","components","views","Edit","listViewFromConfig","List","CustomEditView","Default","Component","undefined","CustomListView","SaveButtonComponent","edit","SaveButton","SaveDraftButtonComponent","SaveDraftButton","PreviewButtonComponent","PreviewButton","PublishButtonComponent","PublishButton","beforeList","BeforeList","Array","isArray","map","beforeListTable","BeforeListTable","afterList","AfterList","afterListTable","AfterListTable","description","descriptionProps","DescriptionComponent","Description","componentMap","collectionSlug","actionsMap","fieldMap","fieldSchema","isPreviewEnabled","preview"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAQA,SAASA,0BAA0B,QAAQ,oBAAmB;AAC9D,OAAOC,WAAW,QAAO;AAMzB,SAASC,eAAe,QAAQ,6CAA4C;AAC5E,SAASC,UAAU,QAAQ,eAAc;AACzC,SAASC,SAAS,QAAQ,cAAa;AAEvC,OAAO,MAAMC,iBAAiB,CA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AK,EAAE+B,YAAY;oBAAE1C;gBAAE;YACxD;QACF;QAEA,MAAM2C,mBAAyC;YAC7CD;QACF;QAEA,MAAME,uBACJvC,iBAAiBM,KAAK,EAAEC,YAAYW,MAAMsB,eACzCH,CAAAA,cAAcrD,kBAAkB+B,SAAQ;QAE3C,MAAMyB,cACJD,yBAAyBxB,0BACvB,oBAACxB;YAAoBuB,WAAWyB;YAAuB,GAAID,oBAAoB,CAAC,CAAC;aAC/EvB;QAEN,MAAM0B,eAAuC;YAC3CP;YACAE;YACAT;YACAK;YACAQ;YACA/B,oBAAM,oBAACA;gBAAKiC,gBAAgB1C,iBAAiBC,IAAI;;YACjDU,oBAAM,oBAACA;gBAAK+B,gBAAgB1C,iBAAiBC,IAAI;;YACjDsB;YACAE;YACAN;YACAE;YACAsB,YAAY1D,WAAW;gBACrBM;gBACAS;YACF;YACA4C,UAAU1D,UAAU;gBAClBK;gBACAE;gBACAoD,aAAa3C;gBACbR;gBACAE,UAAUC;YACZ;YACAiD,kBAAkB,CAAC,CAAC9C,kBAAkBM,OAAOyC;QAC/C;QAEA,OAAO;YACL,GAAGhD,GAAG;YACN,CAACE,KAAK,EAAEwC;QACV;IACF,GAAG,CAAC;AACN,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"globals.d.ts","sourceRoot":"","sources":["../../../../src/providers/ComponentMap/buildComponentMap/globals.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"globals.d.ts","sourceRoot":"","sources":["../../../../src/providers/ComponentMap/buildComponentMap/globals.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAG1F,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,YAAY,CAAA;AACjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAMpD,eAAO,MAAM,UAAU,cAEpB;IACD,IAAI,EAAE;QACJ,eAAe,EAAE,MAAM,EAAE,CAAC,aAAa,CAAC,CAAA;QACxC,mBAAmB,EAAE,+BAA+B,CAAA;QACpD,MAAM,EAAE,eAAe,CAAA;QACvB,OAAO,EAAE,qBAAqB,EAAE,CAAA;QAChC,IAAI,EAAE,UAAU,CAAA;QAChB,QAAQ,CAAC,EAAE,OAAO,CAAA;KACnB,CAAA;CACF,KAAG;IACF,CAAC,GAAG,EAAE,qBAAqB,CAAC,MAAM,CAAC,GAAG,kBAAkB,CAAA;CAyGzD,CAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isReactComponentOrFunction } from 'payload/utilities';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import { ViewDescription } from '../../../elements/ViewDescription/index.js';
|
|
3
4
|
import { mapActions } from './actions.js';
|
|
@@ -23,7 +24,7 @@ export const mapGlobals = ({ args })=>{
|
|
|
23
24
|
const PublishButtonComponent = PublishButton ? /*#__PURE__*/ React.createElement(WithServerSideProps, {
|
|
24
25
|
Component: PublishButton
|
|
25
26
|
}) : undefined;
|
|
26
|
-
const CustomEditView = typeof editViewFromConfig === 'function' ? editViewFromConfig : typeof editViewFromConfig === 'object' &&
|
|
27
|
+
const CustomEditView = typeof editViewFromConfig === 'function' ? editViewFromConfig : typeof editViewFromConfig === 'object' && isReactComponentOrFunction(editViewFromConfig.Default) ? editViewFromConfig.Default : typeof editViewFromConfig?.Default === 'object' && 'Component' in editViewFromConfig.Default && isReactComponentOrFunction(editViewFromConfig.Default.Component) ? editViewFromConfig.Default.Component : undefined;
|
|
27
28
|
const Edit = CustomEditView || DefaultEditView;
|
|
28
29
|
let description = undefined;
|
|
29
30
|
if (globalConfig.admin && 'description' in globalConfig.admin) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/providers/ComponentMap/buildComponentMap/globals.tsx"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type { EditViewProps, SanitizedConfig, SanitizedGlobalConfig } from 'payload/types'\n\nimport React from 'react'\n\nimport type { ViewDescriptionProps } from '../../../elements/ViewDescription/index.js'\nimport type { WithServerSidePropsPrePopulated } from './index.js'\nimport type { GlobalComponentMap } from './types.js'\n\nimport { ViewDescription } from '../../../elements/ViewDescription/index.js'\nimport { mapActions } from './actions.js'\nimport { mapFields } from './fields.js'\n\nexport const mapGlobals = ({\n args,\n}: {\n args: {\n DefaultEditView: React.FC<EditViewProps>\n WithServerSideProps: WithServerSidePropsPrePopulated\n config: SanitizedConfig\n globals: SanitizedGlobalConfig[]\n i18n: I18nClient\n readOnly?: boolean\n }\n}): {\n [key: SanitizedGlobalConfig['slug']]: GlobalComponentMap\n} => {\n const {\n DefaultEditView,\n WithServerSideProps,\n config,\n globals,\n i18n,\n i18n: { t },\n readOnly: readOnlyOverride,\n } = args\n\n return globals.reduce((acc, globalConfig) => {\n const { slug, fields } = globalConfig\n\n const editViewFromConfig = globalConfig?.admin?.components?.views?.Edit\n\n const SaveButton = globalConfig?.admin?.components?.elements?.SaveButton\n\n const SaveButtonComponent = SaveButton ? (\n <WithServerSideProps Component={SaveButton} />\n ) : undefined\n\n const SaveDraftButton = globalConfig?.admin?.components?.elements?.SaveDraftButton\n\n const SaveDraftButtonComponent = SaveDraftButton ? (\n <WithServerSideProps Component={SaveDraftButton} />\n ) : undefined\n\n const PreviewButton = globalConfig?.admin?.components?.elements?.PreviewButton\n\n const PreviewButtonComponent = PreviewButton ? (\n <WithServerSideProps Component={PreviewButton} />\n ) : undefined\n\n const PublishButton = globalConfig?.admin?.components?.elements?.PublishButton\n\n const PublishButtonComponent = PublishButton ? (\n <WithServerSideProps Component={PublishButton} />\n ) : undefined\n\n const CustomEditView =\n typeof editViewFromConfig === 'function'\n ? editViewFromConfig\n : typeof editViewFromConfig === 'object'
|
|
1
|
+
{"version":3,"sources":["../../../../src/providers/ComponentMap/buildComponentMap/globals.tsx"],"sourcesContent":["import type { I18nClient } from '@payloadcms/translations'\nimport type { EditViewProps, SanitizedConfig, SanitizedGlobalConfig } from 'payload/types'\n\nimport { isReactComponentOrFunction } from 'payload/utilities'\nimport React from 'react'\n\nimport type { ViewDescriptionProps } from '../../../elements/ViewDescription/index.js'\nimport type { WithServerSidePropsPrePopulated } from './index.js'\nimport type { GlobalComponentMap } from './types.js'\n\nimport { ViewDescription } from '../../../elements/ViewDescription/index.js'\nimport { mapActions } from './actions.js'\nimport { mapFields } from './fields.js'\n\nexport const mapGlobals = ({\n args,\n}: {\n args: {\n DefaultEditView: React.FC<EditViewProps>\n WithServerSideProps: WithServerSidePropsPrePopulated\n config: SanitizedConfig\n globals: SanitizedGlobalConfig[]\n i18n: I18nClient\n readOnly?: boolean\n }\n}): {\n [key: SanitizedGlobalConfig['slug']]: GlobalComponentMap\n} => {\n const {\n DefaultEditView,\n WithServerSideProps,\n config,\n globals,\n i18n,\n i18n: { t },\n readOnly: readOnlyOverride,\n } = args\n\n return globals.reduce((acc, globalConfig) => {\n const { slug, fields } = globalConfig\n\n const editViewFromConfig = globalConfig?.admin?.components?.views?.Edit\n\n const SaveButton = globalConfig?.admin?.components?.elements?.SaveButton\n\n const SaveButtonComponent = SaveButton ? (\n <WithServerSideProps Component={SaveButton} />\n ) : undefined\n\n const SaveDraftButton = globalConfig?.admin?.components?.elements?.SaveDraftButton\n\n const SaveDraftButtonComponent = SaveDraftButton ? (\n <WithServerSideProps Component={SaveDraftButton} />\n ) : undefined\n\n const PreviewButton = globalConfig?.admin?.components?.elements?.PreviewButton\n\n const PreviewButtonComponent = PreviewButton ? (\n <WithServerSideProps Component={PreviewButton} />\n ) : undefined\n\n const PublishButton = globalConfig?.admin?.components?.elements?.PublishButton\n\n const PublishButtonComponent = PublishButton ? (\n <WithServerSideProps Component={PublishButton} />\n ) : undefined\n\n const CustomEditView =\n typeof editViewFromConfig === 'function'\n ? editViewFromConfig\n : typeof editViewFromConfig === 'object' &&\n isReactComponentOrFunction(editViewFromConfig.Default)\n ? editViewFromConfig.Default\n : typeof editViewFromConfig?.Default === 'object' &&\n 'Component' in editViewFromConfig.Default &&\n isReactComponentOrFunction(editViewFromConfig.Default.Component)\n ? editViewFromConfig.Default.Component\n : undefined\n\n const Edit = (CustomEditView as React.FC<EditViewProps>) || DefaultEditView\n\n let description = undefined\n if (globalConfig.admin && 'description' in globalConfig.admin) {\n if (\n typeof globalConfig.admin?.description === 'string' ||\n typeof globalConfig.admin?.description === 'object'\n ) {\n description = globalConfig.admin.description\n } else if (typeof globalConfig.admin?.description === 'function') {\n description = globalConfig.admin?.description({ t })\n }\n }\n\n const descriptionProps: ViewDescriptionProps = {\n description,\n }\n const DescriptionComponent =\n globalConfig.admin?.components?.elements?.Description ||\n (description ? ViewDescription : undefined)\n\n const Description =\n DescriptionComponent !== undefined ? (\n <WithServerSideProps Component={DescriptionComponent} {...(descriptionProps || {})} />\n ) : undefined\n\n const componentMap: GlobalComponentMap = {\n Description,\n Edit: <Edit globalSlug={globalConfig.slug} />,\n PreviewButton: PreviewButtonComponent,\n PublishButton: PublishButtonComponent,\n SaveButton: SaveButtonComponent,\n SaveDraftButton: SaveDraftButtonComponent,\n actionsMap: mapActions({\n WithServerSideProps,\n globalConfig,\n }),\n fieldMap: mapFields({\n WithServerSideProps,\n config,\n fieldSchema: fields,\n i18n,\n readOnly: readOnlyOverride,\n }),\n isPreviewEnabled: !!globalConfig?.admin?.preview,\n }\n\n return {\n ...acc,\n [slug]: componentMap,\n }\n }, {})\n}\n"],"names":["isReactComponentOrFunction","React","ViewDescription","mapActions","mapFields","mapGlobals","args","DefaultEditView","WithServerSideProps","config","globals","i18n","t","readOnly","readOnlyOverride","reduce","acc","globalConfig","slug","fields","editViewFromConfig","admin","components","views","Edit","SaveButton","elements","SaveButtonComponent","Component","undefined","SaveDraftButton","SaveDraftButtonComponent","PreviewButton","PreviewButtonComponent","PublishButton","PublishButtonComponent","CustomEditView","Default","description","descriptionProps","DescriptionComponent","Description","componentMap","globalSlug","actionsMap","fieldMap","fieldSchema","isPreviewEnabled","preview"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,0BAA0B,QAAQ,oBAAmB;AAC9D,OAAOC,WAAW,QAAO;AAMzB,SAASC,eAAe,QAAQ,6CAA4C;AAC5E,SAASC,UAAU,QAAQ,eAAc;AACzC,SAASC,SAAS,QAAQ,cAAa;AAEvC,OAAO,MAAMC,aAAa,CAAC,EACzBC,IAAI,EAUL;IAGC,MAAM,EACJC,eAAe,EACfC,mBAAmB,EACnBC,MAAM,EACNC,OAAO,EACPC,IAAI,EACJA,MAAM,EAAEC,CAAC,EAAE,EACXC,UAAUC,gBAAgB,EAC3B,GAAGR;IAEJ,OAAOI,QAAQK,MAAM,CAAC,CAACC,KAAKC;QAC1B,MAAM,EAAEC,IAAI,EAAEC,MAAM,EAAE,GAAGF;QAEzB,MAAMG,qBAAqBH,cAAcI,OAAOC,YAAYC,OAAOC;QAEnE,MAAMC,aAAaR,cAAcI,OAAOC,YAAYI,UAAUD;QAE9D,MAAME,sBAAsBF,2BAC1B,oBAACjB;YAAoBoB,WAAWH;aAC9BI;QAEJ,MAAMC,kBAAkBb,cAAcI,OAAOC,YAAYI,UAAUI;QAEnE,MAAMC,2BAA2BD,gCAC/B,oBAACtB;YAAoBoB,WAAWE;aAC9BD;QAEJ,MAAMG,gBAAgBf,cAAcI,OAAOC,YAAYI,UAAUM;QAEjE,MAAMC,yBAAyBD,8BAC7B,oBAACxB;YAAoBoB,WAAWI;aAC9BH;QAEJ,MAAMK,gBAAgBjB,cAAcI,OAAOC,YAA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AAa3B;gBACbR;gBACAE,UAAUC;YACZ;YACAiC,kBAAkB,CAAC,CAAC9B,cAAcI,OAAO2B;QAC3C;QAEA,OAAO;YACL,GAAGhC,GAAG;YACN,CAACE,KAAK,EAAEwB;QACV;IACF,GAAG,CAAC;AACN,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/DocumentInfo/index.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAsE,MAAM,OAAO,CAAA;AAE1F,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/DocumentInfo/index.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAsE,MAAM,OAAO,CAAA;AAE1F,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAgBxE,mBAAmB,YAAY,CAAA;AAE/B,eAAO,MAAM,eAAe,QAAO,mBAA0C,CAAA;AAE7E,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CACzC,iBAAiB,GAAG;IAClB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B,CA6aF,CAAA"}
|
|
@@ -5,6 +5,8 @@ import React, { createContext, useCallback, useContext, useEffect, useState } fr
|
|
|
5
5
|
import { LoadingOverlay } from '../../elements/Loading/index.js';
|
|
6
6
|
import { formatDocTitle } from '../../utilities/formatDocTitle.js';
|
|
7
7
|
import { getFormState } from '../../utilities/getFormState.js';
|
|
8
|
+
import { hasSavePermission as getHasSavePermission } from '../../utilities/hasSavePermission.js';
|
|
9
|
+
import { isEditing as getIsEditing } from '../../utilities/isEditing.js';
|
|
8
10
|
import { reduceFieldsToValues } from '../../utilities/reduceFieldsToValues.js';
|
|
9
11
|
import { useAuth } from '../Auth/index.js';
|
|
10
12
|
import { useConfig } from '../Config/index.js';
|
|
@@ -36,21 +38,23 @@ export const DocumentInfoProvider = ({ children, ...props })=>{
|
|
|
36
38
|
const versionsConfig = docConfig?.versions;
|
|
37
39
|
const baseURL = `${serverURL}${api}`;
|
|
38
40
|
let slug;
|
|
39
|
-
let pluralType;
|
|
40
41
|
let preferencesKey;
|
|
41
42
|
if (globalSlug) {
|
|
42
43
|
slug = globalSlug;
|
|
43
|
-
pluralType = 'globals';
|
|
44
44
|
preferencesKey = `global-${slug}`;
|
|
45
45
|
}
|
|
46
46
|
if (collectionSlug) {
|
|
47
47
|
slug = collectionSlug;
|
|
48
|
-
pluralType = 'collections';
|
|
49
48
|
if (id) {
|
|
50
49
|
preferencesKey = `collection-${slug}-${id}`;
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
|
-
const
|
|
52
|
+
const isEditing = getIsEditing({
|
|
53
|
+
id,
|
|
54
|
+
collectionSlug,
|
|
55
|
+
globalSlug
|
|
56
|
+
});
|
|
57
|
+
const operation = isEditing ? 'update' : 'create';
|
|
54
58
|
const shouldFetchVersions = Boolean(versionsConfig && docPermissions?.readVersions?.permission);
|
|
55
59
|
const getVersions = useCallback(async ()=>{
|
|
56
60
|
let versionFetchURL;
|
|
@@ -169,40 +173,49 @@ export const DocumentInfoProvider = ({ children, ...props })=>{
|
|
|
169
173
|
shouldFetchVersions
|
|
170
174
|
]);
|
|
171
175
|
const getDocPermissions = React.useCallback(async ()=>{
|
|
172
|
-
let docAccessURL;
|
|
173
176
|
const params = {
|
|
174
177
|
locale: locale || undefined
|
|
175
178
|
};
|
|
176
|
-
if (
|
|
177
|
-
docAccessURL = `/globals/${
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
179
|
+
if (isEditing) {
|
|
180
|
+
const docAccessURL = collectionSlug ? `/${collectionSlug}/access/${id}` : globalSlug ? `/globals/${globalSlug}/access` : null;
|
|
181
|
+
if (docAccessURL) {
|
|
182
|
+
const res = await fetch(`${serverURL}${api}${docAccessURL}?${qs.stringify(params)}`, {
|
|
183
|
+
credentials: 'include',
|
|
184
|
+
headers: {
|
|
185
|
+
'Accept-Language': i18n.language
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
const json = await res.json();
|
|
189
|
+
setDocPermissions(json);
|
|
190
|
+
setHasSavePermission(getHasSavePermission({
|
|
191
|
+
collectionSlug,
|
|
192
|
+
docPermissions: json,
|
|
193
|
+
globalSlug,
|
|
194
|
+
isEditing
|
|
195
|
+
}));
|
|
196
|
+
}
|
|
191
197
|
} else {
|
|
192
|
-
//
|
|
193
|
-
//
|
|
194
|
-
|
|
195
|
-
|
|
198
|
+
// when creating new documents, there is no permissions saved for this document yet
|
|
199
|
+
// use the generic entity permissions instead
|
|
200
|
+
const newDocPermissions = collectionSlug ? permissions?.collections?.[collectionSlug] : permissions?.globals?.[globalSlug];
|
|
201
|
+
setDocPermissions(newDocPermissions);
|
|
202
|
+
setHasSavePermission(getHasSavePermission({
|
|
203
|
+
collectionSlug,
|
|
204
|
+
docPermissions: newDocPermissions,
|
|
205
|
+
globalSlug,
|
|
206
|
+
isEditing
|
|
207
|
+
}));
|
|
196
208
|
}
|
|
197
209
|
}, [
|
|
198
210
|
serverURL,
|
|
199
211
|
api,
|
|
200
|
-
pluralType,
|
|
201
|
-
slug,
|
|
202
212
|
id,
|
|
203
213
|
permissions,
|
|
204
214
|
i18n.language,
|
|
205
|
-
locale
|
|
215
|
+
locale,
|
|
216
|
+
collectionSlug,
|
|
217
|
+
globalSlug,
|
|
218
|
+
isEditing
|
|
206
219
|
]);
|
|
207
220
|
const getDocPreferences = useCallback(()=>{
|
|
208
221
|
return getPreference(preferencesKey);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/providers/DocumentInfo/index.tsx"],"sourcesContent":["'use client'\nimport type { PaginatedDocs, TypeWithVersion } from 'payload/database'\nimport type { Data, FormState, TypeWithTimestamps } from 'payload/types'\nimport type { DocumentPermissions, DocumentPreferences, TypeWithID, Where } from 'payload/types'\n\nimport { notFound } from 'next/navigation.js'\nimport qs from 'qs'\nimport React, { createContext, useCallback, useContext, useEffect, useState } from 'react'\n\nimport type { DocumentInfoContext, DocumentInfoProps } from './types.js'\n\nimport { LoadingOverlay } from '../../elements/Loading/index.js'\nimport { formatDocTitle } from '../../utilities/formatDocTitle.js'\nimport { getFormState } from '../../utilities/getFormState.js'\nimport { reduceFieldsToValues } from '../../utilities/reduceFieldsToValues.js'\nimport { useAuth } from '../Auth/index.js'\nimport { useConfig } from '../Config/index.js'\nimport { useLocale } from '../Locale/index.js'\nimport { usePreferences } from '../Preferences/index.js'\nimport { useTranslation } from '../Translation/index.js'\n\nconst Context = createContext({} as DocumentInfoContext)\n\nexport type * from './types.js'\n\nexport const useDocumentInfo = (): DocumentInfoContext => useContext(Context)\n\nexport const DocumentInfoProvider: React.FC<\n DocumentInfoProps & {\n children: React.ReactNode\n }\n> = ({ children, ...props }) => {\n const { id, collectionSlug, globalSlug, onLoadError, onSave: onSaveFromProps } = props\n const [isLoading, setIsLoading] = useState(false)\n const [isError, setIsError] = useState(false)\n const [documentTitle, setDocumentTitle] = useState('')\n const [initialData, setInitialData] = useState<Data>()\n const [initialState, setInitialState] = useState<FormState>()\n const [publishedDoc, setPublishedDoc] = useState<TypeWithID & TypeWithTimestamps>(null)\n const [versions, setVersions] = useState<PaginatedDocs<TypeWithVersion<any>>>(null)\n const [docPermissions, setDocPermissions] = useState<DocumentPermissions>(null)\n const [hasSavePermission, setHasSavePermission] = useState<boolean>(null)\n const [unpublishedVersions, setUnpublishedVersions] =\n useState<PaginatedDocs<TypeWithVersion<any>>>(null)\n\n const { getPreference, setPreference } = usePreferences()\n const { i18n } = useTranslation()\n const { permissions } = useAuth()\n const { code: locale } = useLocale()\n\n const {\n admin: { dateFormat },\n collections,\n globals,\n routes: { api },\n serverURL,\n } = useConfig()\n\n const collectionConfig = collections.find((c) => c.slug === collectionSlug)\n const globalConfig = globals.find((g) => g.slug === globalSlug)\n const docConfig = collectionConfig || globalConfig\n const versionsConfig = docConfig?.versions\n\n const baseURL = `${serverURL}${api}`\n let slug: string\n let pluralType: 'collections' | 'globals'\n let preferencesKey: string\n\n if (globalSlug) {\n slug = globalSlug\n pluralType = 'globals'\n preferencesKey = `global-${slug}`\n }\n\n if (collectionSlug) {\n slug = collectionSlug\n pluralType = 'collections'\n\n if (id) {\n preferencesKey = `collection-${slug}-${id}`\n }\n }\n\n const operation = collectionSlug && !id ? 'create' : 'update'\n const shouldFetchVersions = Boolean(versionsConfig && docPermissions?.readVersions?.permission)\n\n const getVersions = useCallback(async () => {\n let versionFetchURL\n let publishedFetchURL\n let unpublishedVersionJSON = null\n let versionJSON = null\n let shouldFetch = true\n\n const versionParams = {\n depth: 0,\n where: {\n and: [],\n },\n }\n\n const publishedVersionParams: { depth: number; locale: string; where: Where } = {\n depth: 0,\n locale: locale || undefined,\n where: {\n and: [\n {\n or: [\n {\n _status: {\n equals: 'published',\n },\n },\n {\n _status: {\n exists: false,\n },\n },\n ],\n },\n ],\n },\n }\n\n if (globalSlug) {\n versionFetchURL = `${baseURL}/globals/${globalSlug}/versions`\n publishedFetchURL = `${baseURL}/globals/${globalSlug}?${qs.stringify(publishedVersionParams)}`\n }\n\n if (collectionSlug) {\n versionFetchURL = `${baseURL}/${collectionSlug}/versions`\n\n publishedVersionParams.where.and.push({\n id: {\n equals: id,\n },\n })\n\n publishedFetchURL = `${baseURL}/${collectionSlug}?${qs.stringify(publishedVersionParams)}`\n\n if (!id) {\n shouldFetch = false\n }\n\n versionParams.where.and.push({\n parent: {\n equals: id,\n },\n })\n }\n\n if (shouldFetch) {\n let publishedJSON\n\n if (versionsConfig?.drafts) {\n publishedJSON = await fetch(publishedFetchURL, {\n credentials: 'include',\n headers: {\n 'Accept-Language': i18n.language,\n },\n }).then((res) => res.json())\n\n if (collectionSlug) {\n publishedJSON = publishedJSON?.docs?.[0]\n }\n }\n\n if (shouldFetchVersions) {\n versionJSON = await fetch(`${versionFetchURL}?${qs.stringify(versionParams)}`, {\n credentials: 'include',\n headers: {\n 'Accept-Language': i18n.language,\n },\n }).then((res) => res.json())\n\n if (publishedJSON?.updatedAt) {\n const newerVersionParams = {\n ...versionParams,\n where: {\n ...versionParams.where,\n and: [\n ...versionParams.where.and,\n {\n updatedAt: {\n greater_than: publishedJSON?.updatedAt,\n },\n },\n ],\n },\n }\n\n // Get any newer versions available\n const newerVersionRes = await fetch(\n `${versionFetchURL}?${qs.stringify(newerVersionParams)}`,\n {\n credentials: 'include',\n headers: {\n 'Accept-Language': i18n.language,\n },\n },\n )\n\n if (newerVersionRes.status === 200) {\n unpublishedVersionJSON = await newerVersionRes.json()\n }\n }\n }\n\n setPublishedDoc(publishedJSON)\n setVersions(versionJSON)\n setUnpublishedVersions(unpublishedVersionJSON)\n }\n }, [i18n, globalSlug, collectionSlug, id, baseURL, locale, versionsConfig, shouldFetchVersions])\n\n const getDocPermissions = React.useCallback(async () => {\n let docAccessURL: string\n const params = {\n locale: locale || undefined,\n }\n if (pluralType === 'globals') {\n docAccessURL = `/globals/${slug}/access`\n } else if (pluralType === 'collections' && id) {\n docAccessURL = `/${slug}/access/${id}`\n }\n\n if (docAccessURL) {\n const res = await fetch(`${serverURL}${api}${docAccessURL}?${qs.stringify(params)}`, {\n credentials: 'include',\n headers: {\n 'Accept-Language': i18n.language,\n },\n })\n const json = await res.json()\n\n setDocPermissions(json)\n setHasSavePermission(json?.update?.permission)\n } else {\n // fallback to permissions from the entity type\n // (i.e. create has no id)\n setDocPermissions(permissions?.[pluralType]?.[slug])\n setHasSavePermission(permissions?.[pluralType]?.[slug]?.update?.permission)\n }\n }, [serverURL, api, pluralType, slug, id, permissions, i18n.language, locale])\n\n const getDocPreferences = useCallback(() => {\n return getPreference<DocumentPreferences>(preferencesKey)\n }, [getPreference, preferencesKey])\n\n const setDocFieldPreferences = useCallback<DocumentInfoContext['setDocFieldPreferences']>(\n async (path, fieldPreferences) => {\n const allPreferences = await getDocPreferences()\n\n if (preferencesKey) {\n try {\n await setPreference(preferencesKey, {\n ...allPreferences,\n fields: {\n ...(allPreferences?.fields || {}),\n [path]: {\n ...allPreferences?.fields?.[path],\n ...fieldPreferences,\n },\n },\n })\n } catch (e) {\n console.error(e) // eslint-disable-line no-console\n }\n }\n },\n [setPreference, preferencesKey, getDocPreferences],\n )\n\n const onSave = React.useCallback<DocumentInfoContext['onSave']>(\n async (json) => {\n if (typeof onSaveFromProps === 'function') {\n void onSaveFromProps(json)\n }\n\n const docPreferences = await getDocPreferences()\n\n const newState = await getFormState({\n apiRoute: api,\n body: {\n id,\n collectionSlug,\n data: json.doc,\n docPreferences,\n globalSlug,\n locale,\n operation,\n schemaPath: collectionSlug || globalSlug,\n },\n serverURL,\n })\n\n setInitialState(newState)\n setInitialData(json.doc)\n },\n [\n api,\n collectionSlug,\n getDocPreferences,\n globalSlug,\n id,\n operation,\n locale,\n onSaveFromProps,\n serverURL,\n ],\n )\n\n useEffect(() => {\n const abortController = new AbortController()\n\n const getInitialState = async () => {\n setIsError(false)\n setIsLoading(true)\n\n try {\n const result = await getFormState({\n apiRoute: api,\n body: {\n id,\n collectionSlug,\n globalSlug,\n locale,\n operation,\n schemaPath: collectionSlug || globalSlug,\n },\n onError: onLoadError,\n serverURL,\n signal: abortController.signal,\n })\n\n setInitialData(reduceFieldsToValues(result, true))\n setInitialState(result)\n } catch (err) {\n if (!abortController.signal.aborted) {\n if (typeof onLoadError === 'function') {\n void onLoadError()\n }\n setIsError(true)\n setIsLoading(false)\n }\n }\n\n setIsLoading(false)\n }\n\n void getInitialState()\n\n return () => {\n abortController.abort()\n }\n }, [\n api,\n operation,\n collectionSlug,\n serverURL,\n id,\n getPreference,\n globalSlug,\n locale,\n onLoadError,\n ])\n\n useEffect(() => {\n void getVersions()\n }, [getVersions])\n\n useEffect(() => {\n setDocumentTitle(\n formatDocTitle({\n collectionConfig,\n data: { ...initialData, id },\n dateFormat,\n fallback: id?.toString(),\n globalConfig,\n i18n,\n }),\n )\n }, [collectionConfig, initialData, dateFormat, i18n, id, globalConfig])\n\n useEffect(() => {\n const loadDocPermissions = async () => {\n const docPermissions: DocumentPermissions = props.docPermissions\n const hasSavePermission: boolean = props.hasSavePermission\n\n if (!docPermissions || hasSavePermission === undefined || hasSavePermission === null) {\n await getDocPermissions()\n } else {\n setDocPermissions(docPermissions)\n setHasSavePermission(hasSavePermission)\n }\n }\n\n if (collectionSlug || globalSlug) {\n void loadDocPermissions()\n }\n }, [\n getDocPermissions,\n props.docPermissions,\n props.hasSavePermission,\n setDocPermissions,\n collectionSlug,\n globalSlug,\n ])\n\n if (isError) notFound()\n\n if (!initialState || isLoading) {\n return <LoadingOverlay />\n }\n\n const value: DocumentInfoContext = {\n ...props,\n docConfig,\n docPermissions,\n getDocPermissions,\n getDocPreferences,\n getVersions,\n hasSavePermission,\n initialData,\n initialState,\n onSave,\n publishedDoc,\n setDocFieldPreferences,\n setDocumentTitle,\n title: documentTitle,\n unpublishedVersions,\n versions,\n }\n\n return <Context.Provider value={value}>{children}</Context.Provider>\n}\n"],"names":["notFound","qs","React","createContext","useCallback","useContext","useEffect","useState","LoadingOverlay","formatDocTitle","getFormState","reduceFieldsToValues","useAuth","useConfig","useLocale","usePreferences","useTranslation","Context","useDocumentInfo","DocumentInfoProvider","children","props","id","collectionSlug","globalSlug","onLoadError","onSave","onSaveFromProps","isLoading","setIsLoading","isError","setIsError","documentTitle","setDocumentTitle","initialData","setInitialData","initialState","setInitialState","publishedDoc","setPublishedDoc","versions","setVersions","docPermissions","setDocPermissions","hasSavePermission","setHasSavePermission","unpublishedVersions","setUnpublishedVersions","getPreference","setPreference","i18n","permissions","code","locale","admin","dateFormat","collections","globals","routes","api","serverURL","collectionConfig","find","c","slug","globalConfig","g","docConfig","versionsConfig","baseURL","pluralType","preferencesKey","operation","shouldFetchVersions","Boolean","readVersions","permission","getVersions","versionFetchURL","publishedFetchURL","unpublishedVersionJSON","versionJSON","shouldFetch","versionParams","depth","where","and","publishedVersionParams","undefined","or","_status","equals","exists","stringify","push","parent","publishedJSON","drafts","fetch","credentials","headers","language","then","res","json","docs","updatedAt","newerVersionParams","greater_than","newerVersionRes","status","getDocPermissions","docAccessURL","params","update","getDocPreferences","setDocFieldPreferences","path","fieldPreferences","allPreferences","fields","e","console","error","docPreferences","newState","apiRoute","body","data","doc","schemaPath","abortController","AbortController","getInitialState","result","onError","signal","err","aborted","abort","fallback","toString","loadDocPermissions","value","title","Provider"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAKA,SAASA,QAAQ,QAAQ,qBAAoB;AAC7C,OAAOC,QAAQ,KAAI;AACnB,OAAOC,SAASC,aAAa,EAAEC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAI1F,SAASC,cAAc,QAAQ,kCAAiC;AAChE,SAASC,cAAc,QAAQ,oCAAmC;AAClE,SAASC,YAAY,QAAQ,kCAAiC;AAC9D,SAASC,oBAAoB,QAAQ,0CAAyC;AAC9E,SAASC,OAAO,QAAQ,mBAAkB;AAC1C,SAASC,SAAS,QAAQ,qBAAoB;AAC9C,SAASC,S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S9B;IAEb,IAAI,CAACoC,gBAAgBR,WAAW;QAC9B,qBAAO,oBAACpB;IACV;IAEA,MAAMuI,QAA6B;QACjC,GAAG1H,KAAK;QACR8C;QACAzB;QACAqE;QACAI;QACAtC;QACAjC;QACAV;QACAE;QACAV;QACAY;QACA8E;QACAnF;QACA+G,OAAOhH;QACPc;QACAN;IACF;IAEA,qBAAO,oBAACvB,QAAQgI,QAAQ;QAACF,OAAOA;OAAQ3H;AAC1C,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/providers/DocumentInfo/index.tsx"],"sourcesContent":["'use client'\nimport type { PaginatedDocs, TypeWithVersion } from 'payload/database'\nimport type { Data, FormState, TypeWithTimestamps } from 'payload/types'\nimport type { DocumentPermissions, DocumentPreferences, TypeWithID, Where } from 'payload/types'\n\nimport { notFound } from 'next/navigation.js'\nimport qs from 'qs'\nimport React, { createContext, useCallback, useContext, useEffect, useState } from 'react'\n\nimport type { DocumentInfoContext, DocumentInfoProps } from './types.js'\n\nimport { LoadingOverlay } from '../../elements/Loading/index.js'\nimport { formatDocTitle } from '../../utilities/formatDocTitle.js'\nimport { getFormState } from '../../utilities/getFormState.js'\nimport { hasSavePermission as getHasSavePermission } from '../../utilities/hasSavePermission.js'\nimport { isEditing as getIsEditing } from '../../utilities/isEditing.js'\nimport { reduceFieldsToValues } from '../../utilities/reduceFieldsToValues.js'\nimport { useAuth } from '../Auth/index.js'\nimport { useConfig } from '../Config/index.js'\nimport { useLocale } from '../Locale/index.js'\nimport { usePreferences } from '../Preferences/index.js'\nimport { useTranslation } from '../Translation/index.js'\n\nconst Context = createContext({} as DocumentInfoContext)\n\nexport type * from './types.js'\n\nexport const useDocumentInfo = (): DocumentInfoContext => useContext(Context)\n\nexport const DocumentInfoProvider: React.FC<\n DocumentInfoProps & {\n children: React.ReactNode\n }\n> = ({ children, ...props }) => {\n const { id, collectionSlug, globalSlug, onLoadError, onSave: onSaveFromProps } = props\n const [isLoading, setIsLoading] = useState(false)\n const [isError, setIsError] = useState(false)\n const [documentTitle, setDocumentTitle] = useState('')\n const [initialData, setInitialData] = useState<Data>()\n const [initialState, setInitialState] = useState<FormState>()\n const [publishedDoc, setPublishedDoc] = useState<TypeWithID & TypeWithTimestamps>(null)\n const [versions, setVersions] = useState<PaginatedDocs<TypeWithVersion<any>>>(null)\n const [docPermissions, setDocPermissions] = useState<DocumentPermissions>(null)\n const [hasSavePermission, setHasSavePermission] = useState<boolean>(null)\n const [unpublishedVersions, setUnpublishedVersions] =\n useState<PaginatedDocs<TypeWithVersion<any>>>(null)\n\n const { getPreference, setPreference } = usePreferences()\n const { i18n } = useTranslation()\n const { permissions } = useAuth()\n const { code: locale } = useLocale()\n\n const {\n admin: { dateFormat },\n collections,\n globals,\n routes: { api },\n serverURL,\n } = useConfig()\n\n const collectionConfig = collections.find((c) => c.slug === collectionSlug)\n const globalConfig = globals.find((g) => g.slug === globalSlug)\n const docConfig = collectionConfig || globalConfig\n const versionsConfig = docConfig?.versions\n\n const baseURL = `${serverURL}${api}`\n let slug: string\n let preferencesKey: string\n\n if (globalSlug) {\n slug = globalSlug\n preferencesKey = `global-${slug}`\n }\n\n if (collectionSlug) {\n slug = collectionSlug\n\n if (id) {\n preferencesKey = `collection-${slug}-${id}`\n }\n }\n\n const isEditing = getIsEditing({ id, collectionSlug, globalSlug })\n const operation = isEditing ? 'update' : 'create'\n const shouldFetchVersions = Boolean(versionsConfig && docPermissions?.readVersions?.permission)\n\n const getVersions = useCallback(async () => {\n let versionFetchURL\n let publishedFetchURL\n let unpublishedVersionJSON = null\n let versionJSON = null\n let shouldFetch = true\n\n const versionParams = {\n depth: 0,\n where: {\n and: [],\n },\n }\n\n const publishedVersionParams: { depth: number; locale: string; where: Where } = {\n depth: 0,\n locale: locale || undefined,\n where: {\n and: [\n {\n or: [\n {\n _status: {\n equals: 'published',\n },\n },\n {\n _status: {\n exists: false,\n },\n },\n ],\n },\n ],\n },\n }\n\n if (globalSlug) {\n versionFetchURL = `${baseURL}/globals/${globalSlug}/versions`\n publishedFetchURL = `${baseURL}/globals/${globalSlug}?${qs.stringify(publishedVersionParams)}`\n }\n\n if (collectionSlug) {\n versionFetchURL = `${baseURL}/${collectionSlug}/versions`\n\n publishedVersionParams.where.and.push({\n id: {\n equals: id,\n },\n })\n\n publishedFetchURL = `${baseURL}/${collectionSlug}?${qs.stringify(publishedVersionParams)}`\n\n if (!id) {\n shouldFetch = false\n }\n\n versionParams.where.and.push({\n parent: {\n equals: id,\n },\n })\n }\n\n if (shouldFetch) {\n let publishedJSON\n\n if (versionsConfig?.drafts) {\n publishedJSON = await fetch(publishedFetchURL, {\n credentials: 'include',\n headers: {\n 'Accept-Language': i18n.language,\n },\n }).then((res) => res.json())\n\n if (collectionSlug) {\n publishedJSON = publishedJSON?.docs?.[0]\n }\n }\n\n if (shouldFetchVersions) {\n versionJSON = await fetch(`${versionFetchURL}?${qs.stringify(versionParams)}`, {\n credentials: 'include',\n headers: {\n 'Accept-Language': i18n.language,\n },\n }).then((res) => res.json())\n\n if (publishedJSON?.updatedAt) {\n const newerVersionParams = {\n ...versionParams,\n where: {\n ...versionParams.where,\n and: [\n ...versionParams.where.and,\n {\n updatedAt: {\n greater_than: publishedJSON?.updatedAt,\n },\n },\n ],\n },\n }\n\n // Get any newer versions available\n const newerVersionRes = await fetch(\n `${versionFetchURL}?${qs.stringify(newerVersionParams)}`,\n {\n credentials: 'include',\n headers: {\n 'Accept-Language': i18n.language,\n },\n },\n )\n\n if (newerVersionRes.status === 200) {\n unpublishedVersionJSON = await newerVersionRes.json()\n }\n }\n }\n\n setPublishedDoc(publishedJSON)\n setVersions(versionJSON)\n setUnpublishedVersions(unpublishedVersionJSON)\n }\n }, [i18n, globalSlug, collectionSlug, id, baseURL, locale, versionsConfig, shouldFetchVersions])\n\n const getDocPermissions = React.useCallback(async () => {\n const params = {\n locale: locale || undefined,\n }\n\n if (isEditing) {\n const docAccessURL = collectionSlug\n ? `/${collectionSlug}/access/${id}`\n : globalSlug\n ? `/globals/${globalSlug}/access`\n : null\n\n if (docAccessURL) {\n const res = await fetch(`${serverURL}${api}${docAccessURL}?${qs.stringify(params)}`, {\n credentials: 'include',\n headers: {\n 'Accept-Language': i18n.language,\n },\n })\n\n const json: DocumentPermissions = await res.json()\n\n setDocPermissions(json)\n\n setHasSavePermission(\n getHasSavePermission({ collectionSlug, docPermissions: json, globalSlug, isEditing }),\n )\n }\n } else {\n // when creating new documents, there is no permissions saved for this document yet\n // use the generic entity permissions instead\n const newDocPermissions = collectionSlug\n ? permissions?.collections?.[collectionSlug]\n : permissions?.globals?.[globalSlug]\n\n setDocPermissions(newDocPermissions)\n\n setHasSavePermission(\n getHasSavePermission({\n collectionSlug,\n docPermissions: newDocPermissions,\n globalSlug,\n isEditing,\n }),\n )\n }\n }, [\n serverURL,\n api,\n id,\n permissions,\n i18n.language,\n locale,\n collectionSlug,\n globalSlug,\n isEditing,\n ])\n\n const getDocPreferences = useCallback(() => {\n return getPreference<DocumentPreferences>(preferencesKey)\n }, [getPreference, preferencesKey])\n\n const setDocFieldPreferences = useCallback<DocumentInfoContext['setDocFieldPreferences']>(\n async (path, fieldPreferences) => {\n const allPreferences = await getDocPreferences()\n\n if (preferencesKey) {\n try {\n await setPreference(preferencesKey, {\n ...allPreferences,\n fields: {\n ...(allPreferences?.fields || {}),\n [path]: {\n ...allPreferences?.fields?.[path],\n ...fieldPreferences,\n },\n },\n })\n } catch (e) {\n console.error(e) // eslint-disable-line no-console\n }\n }\n },\n [setPreference, preferencesKey, getDocPreferences],\n )\n\n const onSave = React.useCallback<DocumentInfoContext['onSave']>(\n async (json) => {\n if (typeof onSaveFromProps === 'function') {\n void onSaveFromProps(json)\n }\n\n const docPreferences = await getDocPreferences()\n\n const newState = await getFormState({\n apiRoute: api,\n body: {\n id,\n collectionSlug,\n data: json.doc,\n docPreferences,\n globalSlug,\n locale,\n operation,\n schemaPath: collectionSlug || globalSlug,\n },\n serverURL,\n })\n\n setInitialState(newState)\n setInitialData(json.doc)\n },\n [\n api,\n collectionSlug,\n getDocPreferences,\n globalSlug,\n id,\n operation,\n locale,\n onSaveFromProps,\n serverURL,\n ],\n )\n\n useEffect(() => {\n const abortController = new AbortController()\n\n const getInitialState = async () => {\n setIsError(false)\n setIsLoading(true)\n\n try {\n const result = await getFormState({\n apiRoute: api,\n body: {\n id,\n collectionSlug,\n globalSlug,\n locale,\n operation,\n schemaPath: collectionSlug || globalSlug,\n },\n onError: onLoadError,\n serverURL,\n signal: abortController.signal,\n })\n\n setInitialData(reduceFieldsToValues(result, true))\n setInitialState(result)\n } catch (err) {\n if (!abortController.signal.aborted) {\n if (typeof onLoadError === 'function') {\n void onLoadError()\n }\n setIsError(true)\n setIsLoading(false)\n }\n }\n\n setIsLoading(false)\n }\n\n void getInitialState()\n\n return () => {\n abortController.abort()\n }\n }, [\n api,\n operation,\n collectionSlug,\n serverURL,\n id,\n getPreference,\n globalSlug,\n locale,\n onLoadError,\n ])\n\n useEffect(() => {\n void getVersions()\n }, [getVersions])\n\n useEffect(() => {\n setDocumentTitle(\n formatDocTitle({\n collectionConfig,\n data: { ...initialData, id },\n dateFormat,\n fallback: id?.toString(),\n globalConfig,\n i18n,\n }),\n )\n }, [collectionConfig, initialData, dateFormat, i18n, id, globalConfig])\n\n useEffect(() => {\n const loadDocPermissions = async () => {\n const docPermissions: DocumentPermissions = props.docPermissions\n const hasSavePermission: boolean = props.hasSavePermission\n\n if (!docPermissions || hasSavePermission === undefined || hasSavePermission === null) {\n await getDocPermissions()\n } else {\n setDocPermissions(docPermissions)\n setHasSavePermission(hasSavePermission)\n }\n }\n\n if (collectionSlug || globalSlug) {\n void loadDocPermissions()\n }\n }, [\n getDocPermissions,\n props.docPermissions,\n props.hasSavePermission,\n setDocPermissions,\n collectionSlug,\n globalSlug,\n ])\n\n if (isError) notFound()\n\n if (!initialState || isLoading) {\n return <LoadingOverlay />\n }\n\n const value: DocumentInfoContext = {\n ...props,\n docConfig,\n docPermissions,\n getDocPermissions,\n getDocPreferences,\n getVersions,\n hasSavePermission,\n initialData,\n initialState,\n onSave,\n publishedDoc,\n setDocFieldPreferences,\n setDocumentTitle,\n title: documentTitle,\n unpublishedVersions,\n versions,\n }\n\n return <Context.Provider value={value}>{children}</Context.Provider>\n}\n"],"names":["notFound","qs","React","createContext","useCallback","useContext","useEffect","useState","LoadingOverlay","formatDocTitle","getFormState","hasSavePermission","getHasSavePermission","isEditing","getIsEditing","reduceFieldsToValues","useAuth","useConfig","useLocale","usePreferences","useTranslation","Context","useDocumentInfo","DocumentInfoProvider","children","props","id","collectionSlug","globalSlug","onLoadError","onSave","onSaveFromProps","isLoading","setIsLoading","isError","setIsError","documentTitle","setDocumentTitle","initialData","setInitialData","initialState","setInitialState","publishedDoc","setPublishedDoc","versions","setVersions","docPermissions","setDocPermissions","setHasSavePermission","unpublishedVersions","setUnpublishedVersions","getPreference","setPreference","i18n","permissions","code","locale","admin","dateFormat","collections","globals","routes","api","serverURL","collectionConfig","find","c","slug","globalConfig","g","docConfig","versionsConfig","baseURL","preferencesKey","operation","shouldFetchVersions","Boolean","readVersions","permission","getVersions","versionFetchURL","publishedFetchURL","unpublishedVersionJSON","versionJSON","shouldFetch","versionParams","depth","where","and","publishedVersionParams","undefined","or","_status","equals","exists","stringify","push","parent","publishedJSON","drafts","fetch","credentials","headers","language","then","res","json","docs","updatedAt","newerVersionParams","greater_than","newerVersionRes","status","getDocPermissions","params","docAccessURL","newDocPermissions","getDocPreferences","setDocFieldPreferences","path","fieldPreferences","allPreferences","fields","e","console","error","docPreferences","newState","apiRoute","body","data","doc","schemaPath","abortController","AbortController","getInitialState","result","onError","signal","err","aborted","abort","fallback","toString","loadDocPermissions","value","title","Provider"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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F,aAAa;gBACf;YACF;YAEAA,aAAa;QACf;QAEA,KAAKsG;QAEL,OAAO;YACLF,gBAAgBQ,KAAK;QACvB;IACF,GAAG;QACD/E;QACAY;QACA/C;QACAoC;QACArC;QACAyB;QACAvB;QACA4B;QACA3B;KACD;IAEDvB,UAAU;QACR,KAAKyE;IACP,GAAG;QAACA;KAAY;IAEhBzE,UAAU;QACR+B,iBACE5B,eAAe;YACbuD;YACAkE,MAAM;gBAAE,GAAG5F,WAAW;gBAAEZ;YAAG;YAC3BgC;YACAoF,UAAUpH,IAAIqH;YACd3E;YACAf;QACF;IAEJ,GAAG;QAACW;QAAkB1B;QAAaoB;QAAYL;QAAM3B;QAAI0C;KAAa;IAEtE9D,UAAU;QACR,MAAM0I,qBAAqB;YACzB,MAAMlG,iBAAsCrB,MAAMqB,cAAc;YAChE,MAAMnC,oBAA6Bc,MAAMd,iBAAiB;YAE1D,IAAI,CAACmC,kBAAkBnC,sBAAsB+E,aAAa/E,sBAAsB,MAAM;gBACpF,MAAMsG;YACR,OAAO;gBACLlE,kBAAkBD;gBAClBE,qBAAqBrC;YACvB;QACF;QAEA,IAAIgB,kBAAkBC,YAAY;YAChC,KAAKoH;QACP;IACF,GAAG;QACD/B;QACAxF,MAAMqB,cAAc;QACpBrB,MAAMd,iBAAiB;QACvBoC;QACApB;QACAC;KACD;IAED,IAAIM,SAASlC;IAEb,IAAI,CAACwC,gBAAgBR,WAAW;QAC9B,qBAAO,oBAACxB;IACV;IAEA,MAAMyI,QAA6B;QACjC,GAAGxH,KAAK;QACR6C;QACAxB;QACAmE;QACAI;QACAtC;QACApE;QACA2B;QACAE;QACAV;QACAY;QACA4E;QACAjF;QACA6G,OAAO9G;QACPa;QACAL;IACF;IAEA,qBAAO,oBAACvB,QAAQ8H,QAAQ;QAACF,OAAOA;OAAQzH;AAC1C,EAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DocumentPermissions } from 'payload/auth';
|
|
2
|
+
export declare const hasSavePermission: (args: {
|
|
3
|
+
collectionSlug?: string;
|
|
4
|
+
docPermissions: DocumentPermissions;
|
|
5
|
+
globalSlug?: string;
|
|
6
|
+
isEditing: boolean;
|
|
7
|
+
}) => boolean;
|
|
8
|
+
//# sourceMappingURL=hasSavePermission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hasSavePermission.d.ts","sourceRoot":"","sources":["../../src/utilities/hasSavePermission.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAwB,mBAAmB,EAAoB,MAAM,cAAc,CAAA;AAE/F,eAAO,MAAM,iBAAiB,SAAU;IAItC,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,cAAc,EAAE,mBAAmB,CAAA;IAInC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,OAAO,CAAA;CACnB,YAeA,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const hasSavePermission = (args)=>{
|
|
2
|
+
const { collectionSlug, docPermissions, globalSlug, isEditing } = args;
|
|
3
|
+
if (collectionSlug) {
|
|
4
|
+
return Boolean(isEditing && docPermissions?.update?.permission || !isEditing && docPermissions?.create?.permission);
|
|
5
|
+
}
|
|
6
|
+
if (globalSlug) {
|
|
7
|
+
return Boolean(docPermissions?.update?.permission);
|
|
8
|
+
}
|
|
9
|
+
return false;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=hasSavePermission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/hasSavePermission.ts"],"sourcesContent":["import type { CollectionPermission, DocumentPermissions, GlobalPermission } from 'payload/auth'\n\nexport const hasSavePermission = (args: {\n /*\n * Pass either `collectionSlug` or `globalSlug`\n */\n collectionSlug?: string\n docPermissions: DocumentPermissions\n /*\n * Pass either `collectionSlug` or `globalSlug`\n */\n globalSlug?: string\n isEditing: boolean\n}) => {\n const { collectionSlug, docPermissions, globalSlug, isEditing } = args\n\n if (collectionSlug) {\n return Boolean(\n (isEditing && docPermissions?.update?.permission) ||\n (!isEditing && (docPermissions as CollectionPermission)?.create?.permission),\n )\n }\n\n if (globalSlug) {\n return Boolean((docPermissions as GlobalPermission)?.update?.permission)\n }\n\n return false\n}\n"],"names":["hasSavePermission","args","collectionSlug","docPermissions","globalSlug","isEditing","Boolean","update","permission","create"],"rangeMappings":";;;;;;;;;","mappings":"AAEA,OAAO,MAAMA,oBAAoB,CAACC;IAYhC,MAAM,EAAEC,cAAc,EAAEC,cAAc,EAAEC,UAAU,EAAEC,SAAS,EAAE,GAAGJ;IAElE,IAAIC,gBAAgB;QAClB,OAAOI,QACL,AAACD,aAAaF,gBAAgBI,QAAQC,cACnC,CAACH,aAAcF,gBAAyCM,QAAQD;IAEvE;IAEA,IAAIJ,YAAY;QACd,OAAOE,QAASH,gBAAqCI,QAAQC;IAC/D;IAEA,OAAO;AACT,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isEditing.d.ts","sourceRoot":"","sources":["../../src/utilities/isEditing.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,wCAInB;IACD,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CACrB,KAAG,OAA0D,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/isEditing.ts"],"sourcesContent":["export const isEditing = ({\n id,\n collectionSlug,\n globalSlug,\n}: {\n collectionSlug?: string\n globalSlug?: string\n id?: number | string\n}): boolean => Boolean(globalSlug || (collectionSlug && !!id))\n"],"names":["isEditing","id","collectionSlug","globalSlug","Boolean"],"rangeMappings":"","mappings":"AAAA,OAAO,MAAMA,YAAY,CAAC,EACxBC,EAAE,EACFC,cAAc,EACdC,UAAU,EAKX,GAAcC,QAAQD,cAAeD,kBAAkB,CAAC,CAACD,IAAI"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/ui",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.34",
|
|
4
4
|
"homepage": "https://payloadcms.com",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -110,17 +110,17 @@
|
|
|
110
110
|
"react-datepicker": "6.2.0",
|
|
111
111
|
"react-image-crop": "10.1.8",
|
|
112
112
|
"react-select": "5.7.4",
|
|
113
|
-
"react-toastify": "10.0.
|
|
113
|
+
"react-toastify": "10.0.5",
|
|
114
114
|
"use-context-selector": "1.4.1",
|
|
115
115
|
"uuid": "9.0.1",
|
|
116
|
-
"@payloadcms/translations": "3.0.0-beta.
|
|
116
|
+
"@payloadcms/translations": "3.0.0-beta.34"
|
|
117
117
|
},
|
|
118
118
|
"devDependencies": {
|
|
119
119
|
"@types/body-scroll-lock": "^3.1.0",
|
|
120
120
|
"@types/qs": "6.9.7",
|
|
121
|
-
"@types/react": "18.2
|
|
121
|
+
"@types/react": "18.3.2",
|
|
122
122
|
"@types/react-datepicker": "4.11.2",
|
|
123
|
-
"@types/react-dom": "18.
|
|
123
|
+
"@types/react-dom": "18.3.0",
|
|
124
124
|
"@types/uuid": "8.3.4",
|
|
125
125
|
"css-loader": "^6.10.0",
|
|
126
126
|
"css-minimizer-webpack-plugin": "^6.0.0",
|
|
@@ -134,13 +134,13 @@
|
|
|
134
134
|
"webpack": "^5.78.0",
|
|
135
135
|
"webpack-cli": "^5.1.4",
|
|
136
136
|
"@payloadcms/eslint-config": "1.1.1",
|
|
137
|
-
"payload": "3.0.0-beta.
|
|
137
|
+
"payload": "3.0.0-beta.34"
|
|
138
138
|
},
|
|
139
139
|
"peerDependencies": {
|
|
140
|
-
"next": "^14.3.0-canary.
|
|
141
|
-
"react": "^18.0.0",
|
|
142
|
-
"react-dom": "^18.0.0",
|
|
143
|
-
"payload": "3.0.0-beta.
|
|
140
|
+
"next": "^14.3.0-canary.68",
|
|
141
|
+
"react": "^18.2.0 || ^19.0.0",
|
|
142
|
+
"react-dom": "^18.2.0 || ^19.0.0",
|
|
143
|
+
"payload": "3.0.0-beta.34"
|
|
144
144
|
},
|
|
145
145
|
"engines": {
|
|
146
146
|
"node": ">=18.20.2"
|
|
File without changes
|