@strapi/content-manager 5.43.0 → 5.45.0
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/admin/components/Widgets.js +1 -1
- package/dist/admin/components/Widgets.js.map +1 -1
- package/dist/admin/components/Widgets.mjs +1 -1
- package/dist/admin/components/Widgets.mjs.map +1 -1
- package/dist/admin/hooks/useDocument.js +3 -2
- package/dist/admin/hooks/useDocument.js.map +1 -1
- package/dist/admin/hooks/useDocument.mjs +3 -2
- package/dist/admin/hooks/useDocument.mjs.map +1 -1
- package/dist/admin/hooks/useDocumentLayout.js +2 -2
- package/dist/admin/hooks/useDocumentLayout.js.map +1 -1
- package/dist/admin/hooks/useDocumentLayout.mjs +2 -2
- package/dist/admin/hooks/useDocumentLayout.mjs.map +1 -1
- package/dist/admin/hooks/usePersistentQueryParams.js +11 -5
- package/dist/admin/hooks/usePersistentQueryParams.js.map +1 -1
- package/dist/admin/hooks/usePersistentQueryParams.mjs +12 -6
- package/dist/admin/hooks/usePersistentQueryParams.mjs.map +1 -1
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs.map +1 -1
- package/dist/admin/pages/EditView/EditViewPage.js +5 -3
- package/dist/admin/pages/EditView/EditViewPage.js.map +1 -1
- package/dist/admin/pages/EditView/EditViewPage.mjs +5 -3
- package/dist/admin/pages/EditView/EditViewPage.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.js +1 -0
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.mjs +1 -0
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.js +1 -0
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.mjs +1 -0
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.js +2 -0
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.mjs +2 -0
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.mjs.map +1 -1
- package/dist/admin/pages/EditView/utils/data.js +8 -0
- package/dist/admin/pages/EditView/utils/data.js.map +1 -1
- package/dist/admin/pages/EditView/utils/data.mjs +8 -0
- package/dist/admin/pages/EditView/utils/data.mjs.map +1 -1
- package/dist/admin/pages/ListView/ListViewPage.js +22 -5
- package/dist/admin/pages/ListView/ListViewPage.js.map +1 -1
- package/dist/admin/pages/ListView/ListViewPage.mjs +22 -5
- package/dist/admin/pages/ListView/ListViewPage.mjs.map +1 -1
- package/dist/admin/src/hooks/useDocument.d.ts +1 -1
- package/dist/admin/src/hooks/usePersistentQueryParams.d.ts +3 -1
- package/dist/admin/src/index.d.ts +2 -1
- package/dist/admin/translations/cs.json.js +242 -8
- package/dist/admin/translations/cs.json.js.map +1 -1
- package/dist/admin/translations/cs.json.mjs +242 -9
- package/dist/admin/translations/cs.json.mjs.map +1 -1
- package/dist/server/controllers/collection-types.js +78 -1
- package/dist/server/controllers/collection-types.js.map +1 -1
- package/dist/server/controllers/collection-types.mjs +78 -1
- package/dist/server/controllers/collection-types.mjs.map +1 -1
- package/dist/server/controllers/validation/dimensions.js +17 -18
- package/dist/server/controllers/validation/dimensions.js.map +1 -1
- package/dist/server/controllers/validation/dimensions.mjs +18 -19
- package/dist/server/controllers/validation/dimensions.mjs.map +1 -1
- package/dist/server/controllers/validation/index.js +25 -23
- package/dist/server/controllers/validation/index.js.map +1 -1
- package/dist/server/controllers/validation/index.mjs +26 -24
- package/dist/server/controllers/validation/index.mjs.map +1 -1
- package/dist/server/controllers/validation/relations.js +21 -24
- package/dist/server/controllers/validation/relations.js.map +1 -1
- package/dist/server/controllers/validation/relations.mjs +22 -25
- package/dist/server/controllers/validation/relations.mjs.map +1 -1
- package/dist/server/history/controllers/validation/history-version.js +4 -24
- package/dist/server/history/controllers/validation/history-version.js.map +1 -1
- package/dist/server/history/controllers/validation/history-version.mjs +5 -6
- package/dist/server/history/controllers/validation/history-version.mjs.map +1 -1
- package/dist/server/history/services/lifecycles.js +1 -1
- package/dist/server/history/services/lifecycles.js.map +1 -1
- package/dist/server/history/services/lifecycles.mjs +1 -1
- package/dist/server/history/services/lifecycles.mjs.map +1 -1
- package/dist/server/homepage/controllers/homepage.js +6 -26
- package/dist/server/homepage/controllers/homepage.js.map +1 -1
- package/dist/server/homepage/controllers/homepage.mjs +7 -8
- package/dist/server/homepage/controllers/homepage.mjs.map +1 -1
- package/dist/server/preview/controllers/validation/preview.js +6 -26
- package/dist/server/preview/controllers/validation/preview.js.map +1 -1
- package/dist/server/preview/controllers/validation/preview.mjs +7 -8
- package/dist/server/preview/controllers/validation/preview.mjs.map +1 -1
- package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/dimensions.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/index.d.ts +16 -15
- package/dist/server/src/controllers/validation/index.d.ts.map +1 -1
- package/dist/server/src/controllers/validation/relations.d.ts +17 -2
- package/dist/server/src/controllers/validation/relations.d.ts.map +1 -1
- package/dist/server/src/history/controllers/validation/history-version.d.ts +3 -1
- package/dist/server/src/history/controllers/validation/history-version.d.ts.map +1 -1
- package/dist/server/src/homepage/controllers/homepage.d.ts.map +1 -1
- package/dist/server/src/preview/controllers/validation/preview.d.ts.map +1 -1
- package/dist/server/src/validation/policies/hasPermissions.d.ts +4 -1
- package/dist/server/src/validation/policies/hasPermissions.d.ts.map +1 -1
- package/dist/server/src/validation/zod.d.ts +34 -0
- package/dist/server/src/validation/zod.d.ts.map +1 -0
- package/dist/server/validation/policies/hasPermissions.js +4 -4
- package/dist/server/validation/policies/hasPermissions.js.map +1 -1
- package/dist/server/validation/policies/hasPermissions.mjs +5 -5
- package/dist/server/validation/policies/hasPermissions.mjs.map +1 -1
- package/dist/server/validation/zod.js +60 -0
- package/dist/server/validation/zod.js.map +1 -0
- package/dist/server/validation/zod.mjs +56 -0
- package/dist/server/validation/zod.mjs.map +1 -0
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDocumentLayout.js","sources":["../../../admin/src/hooks/useDocumentLayout.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { SerializedError } from '@reduxjs/toolkit';\nimport {\n useNotification,\n useStrapiApp,\n useAPIErrorHandler,\n useQueryParams,\n} from '@strapi/admin/strapi-admin';\n\nimport { HOOKS } from '../constants/hooks';\nimport { useGetContentTypeConfigurationQuery } from '../services/contentTypes';\nimport { BaseQueryError } from '../utils/api';\nimport { getMainField } from '../utils/attributes';\n\nimport { useContentTypeSchema } from './useContentTypeSchema';\nimport {\n type ComponentsDictionary,\n type Document,\n type Schema,\n useDoc,\n useDocument,\n} from './useDocument';\n\nimport type { ComponentConfiguration } from '../../../shared/contracts/components';\nimport type {\n Metadatas,\n FindContentTypeConfiguration,\n Settings,\n} from '../../../shared/contracts/content-types';\nimport type { Filters, InputProps, Table } from '@strapi/admin/strapi-admin';\nimport type { Schema as SchemaUtils } from '@strapi/types';\n\ntype LayoutOptions = Schema['options'] & Schema['pluginOptions'] & object;\n\ninterface LayoutSettings extends Settings {\n displayName?: string;\n icon?: never;\n}\n\ninterface ListFieldLayout\n extends Table.Header<Document, ListFieldLayout>,\n Pick<Filters.Filter, 'mainField'> {\n attribute: SchemaUtils.Attribute.AnyAttribute | { type: 'custom' };\n}\n\ninterface ListLayout {\n layout: ListFieldLayout[];\n components?: never;\n metadatas: {\n [K in keyof Metadatas]: Metadatas[K]['list'];\n };\n options: LayoutOptions;\n settings: LayoutSettings;\n}\ninterface EditFieldSharedProps\n extends Omit<InputProps, 'hint' | 'label' | 'type'>,\n Pick<Filters.Filter, 'mainField'> {\n hint?: string;\n label: string;\n size: number;\n unique?: boolean;\n visible?: boolean;\n}\n\n/**\n * Map over all the types in Attribute Types and use that to create a union of new types where the attribute type\n * is under the property attribute and the type is under the property type.\n */\ntype EditFieldLayout = {\n [K in SchemaUtils.Attribute.Kind]: EditFieldSharedProps & {\n attribute: Extract<SchemaUtils.Attribute.AnyAttribute, { type: K }>;\n type: K;\n };\n}[SchemaUtils.Attribute.Kind];\n\ninterface EditLayout {\n layout: Array<Array<EditFieldLayout[]>>;\n components: {\n [uid: string]: {\n layout: Array<EditFieldLayout[]>;\n settings: ComponentConfiguration['settings'] & {\n displayName?: string;\n icon?: string;\n };\n };\n };\n metadatas: {\n [K in keyof Metadatas]: Metadatas[K]['edit'];\n };\n options: LayoutOptions;\n settings: LayoutSettings;\n}\n\n/**\n * Data required to resolve `mainField` when converting list column names to field layouts for\n * component and relation attributes; mirrors the fourth and fifth arguments of `formatListLayout`.\n */\ntype ListViewConversionContext = {\n componentConfigurations: FindContentTypeConfiguration.Response['data']['components'];\n componentSchemas: ComponentsDictionary;\n contentTypeSchemas: Schema[];\n};\n\ntype UseDocumentLayout = (model: string) => {\n error?: BaseQueryError | SerializedError;\n isLoading: boolean;\n /**\n * This is the layout for the edit view,\n */\n edit: EditLayout;\n list: ListLayout;\n /**\n * Populated when configuration is loaded; pass into `convertListLayoutToFieldLayouts` with\n * `list.metadatas` when mapping persisted list column names (e.g. custom displayed headers).\n */\n listViewConversionContext: ListViewConversionContext | null;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDocumentLayout\n * -----------------------------------------------------------------------------------------------*/\n\nconst DEFAULT_SETTINGS = {\n bulkable: false,\n filterable: false,\n searchable: false,\n pagination: false,\n defaultSortBy: '',\n defaultSortOrder: 'asc',\n mainField: 'id',\n pageSize: 10,\n relationOpenMode: 'modal' as const,\n};\n\n/**\n * @alpha\n * @description This hook is used to get the layouts for either the edit view or list view of a specific content-type\n * including the layouts for the components used in the content-type. It also runs the mutation hook waterfall so the data\n * is consistent wherever it is used. It's a light wrapper around the `useDocument` hook, but provides the `skip` option a document\n * is not fetched, however, it does fetch the schemas & components if they do not already exist in the cache.\n *\n * If the fetch fails, it will display a notification to the user.\n *\n * @example\n * ```tsx\n * const { model } = useParams<{ model: string }>();\n * const { edit: { schema: layout } } = useDocumentLayout(model);\n *\n * return layout.map(panel => panel.map(row => row.map(field => <Field.Root {...field} />)))\n * ```\n *\n */\nconst useDocumentLayout: UseDocumentLayout = (model) => {\n const { schema, components } = useDocument({ model, collectionType: '' }, { skip: true });\n const [{ query }] = useQueryParams();\n const runHookWaterfall = useStrapiApp('useDocumentLayout', (state) => state.runHookWaterfall);\n const { toggleNotification } = useNotification();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();\n\n const {\n data,\n isLoading: isLoadingConfigs,\n error,\n isFetching: isFetchingConfigs,\n } = useGetContentTypeConfigurationQuery(model);\n\n const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [error, formatAPIError, toggleNotification]);\n\n const editLayout = React.useMemo(\n () =>\n data && !isLoading\n ? formatEditLayout(data, { schemas, schema, components })\n : ({\n layout: [],\n components: {},\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as EditLayout),\n [data, isLoading, schemas, schema, components]\n );\n\n const listLayout = React.useMemo(() => {\n return data && !isLoading\n ? formatListLayout(data, { schemas, schema, components })\n : ({\n layout: [],\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as ListLayout);\n }, [data, isLoading, schemas, schema, components]);\n\n const { layout: edit } = React.useMemo(\n () =>\n runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {\n layout: editLayout,\n query,\n }),\n [editLayout, query, runHookWaterfall]\n );\n\n const listViewConversionContext = React.useMemo((): ListViewConversionContext | null => {\n if (!data || isLoading) {\n return null;\n }\n\n return {\n componentConfigurations: data.components,\n componentSchemas: components,\n contentTypeSchemas: schemas,\n };\n }, [data, isLoading, components, schemas]);\n\n return {\n error,\n isLoading,\n edit,\n list: listLayout,\n listViewConversionContext,\n } satisfies ReturnType<UseDocumentLayout>;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDocLayout\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal this hook uses the internal useDoc hook, as such it shouldn't be used outside of the\n * content-manager because it won't work as intended.\n */\nconst useDocLayout = () => {\n const { model } = useDoc();\n return useDocumentLayout(model);\n};\n\n/* -------------------------------------------------------------------------------------------------\n * formatEditLayout\n * -----------------------------------------------------------------------------------------------*/\ntype LayoutData = FindContentTypeConfiguration.Response['data'];\n\n/**\n * @internal\n * @description takes the configuration data, the schema & the components used in the schema and formats the edit view\n * versions of the schema & components. This is then used to render the edit view of the content-type.\n */\nconst formatEditLayout = (\n data: LayoutData,\n {\n schemas,\n schema,\n components,\n }: { schemas: Schema[]; schema?: Schema; components: ComponentsDictionary }\n): EditLayout => {\n let currentPanelIndex = 0;\n /**\n * The fields arranged by the panels, new panels are made for dynamic zones only.\n */\n const panelledEditAttributes = convertEditLayoutToFieldLayouts(\n data.contentType.layouts.edit,\n schema?.attributes,\n data.contentType.metadatas,\n { configurations: data.components, schemas: components },\n schemas\n ).reduce<Array<EditFieldLayout[][]>>((panels, row) => {\n if (row.some((field) => field.type === 'dynamiczone')) {\n panels.push([row]);\n currentPanelIndex += 2;\n } else {\n if (!panels[currentPanelIndex]) {\n panels.push([row]);\n } else {\n panels[currentPanelIndex].push(row);\n }\n }\n\n return panels;\n }, []);\n\n const componentEditAttributes = Object.entries(data.components).reduce<EditLayout['components']>(\n (acc, [uid, configuration]) => {\n acc[uid] = {\n layout: convertEditLayoutToFieldLayouts(\n configuration.layouts.edit,\n components[uid].attributes,\n configuration.metadatas,\n { configurations: data.components, schemas: components }\n ),\n settings: {\n ...configuration.settings,\n icon: components[uid].info.icon,\n displayName: components[uid].info.displayName,\n },\n };\n return acc;\n },\n {}\n );\n\n const editMetadatas = Object.entries(data.contentType.metadatas).reduce<EditLayout['metadatas']>(\n (acc, [attribute, metadata]) => {\n return {\n ...acc,\n [attribute]: metadata.edit,\n };\n },\n {}\n );\n\n return {\n layout: panelledEditAttributes,\n components: componentEditAttributes,\n metadatas: editMetadatas,\n settings: {\n ...data.contentType.settings,\n displayName: schema?.info.displayName,\n },\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n ...data.contentType.options,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * convertEditLayoutToFieldLayouts\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the edit layout from either a content-type or a component\n * and formats it into a generic object that can be used to correctly render\n * the form fields.\n */\nconst convertEditLayoutToFieldLayouts = (\n rows: LayoutData['contentType']['layouts']['edit'],\n attributes: Schema['attributes'] = {},\n metadatas: Metadatas,\n components?: {\n configurations: Record<string, ComponentConfiguration>;\n schemas: ComponentsDictionary;\n },\n schemas: Schema[] = []\n) => {\n return rows.map((row) =>\n row\n .map((field) => {\n const attribute = attributes[field.name];\n\n if (!attribute) {\n return null;\n }\n\n const { edit: metadata } = metadatas[field.name];\n\n const settings: Partial<Settings> =\n attribute.type === 'component' && components\n ? components.configurations[attribute.component].settings\n : {};\n\n return {\n attribute,\n disabled: !metadata.editable,\n hint: metadata.description,\n label: metadata.label ?? '',\n name: field.name,\n // @ts-expect-error – mainField does exist on the metadata for a relation.\n mainField: getMainField(attribute, metadata.mainField || settings.mainField, {\n schemas,\n components: components?.schemas ?? {},\n }),\n placeholder: metadata.placeholder ?? '',\n required: attribute.required ?? false,\n size: field.size,\n unique: 'unique' in attribute ? attribute.unique : false,\n visible: metadata.visible ?? true,\n type: attribute.type,\n };\n })\n .filter((field) => field !== null)\n ) as EditFieldLayout[][];\n};\n\n/* -------------------------------------------------------------------------------------------------\n * formatListLayout\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the complete configuration data, the schema & the components used in the schema and\n * formats a list view layout for the content-type. This is much simpler than the edit view layout as there\n * are less options to consider.\n */\nconst formatListLayout = (\n data: LayoutData,\n {\n schemas,\n schema,\n components,\n }: { schemas: Schema[]; schema?: Schema; components: ComponentsDictionary }\n): ListLayout => {\n const listMetadatas = Object.entries(data.contentType.metadatas).reduce<ListLayout['metadatas']>(\n (acc, [attribute, metadata]) => {\n return {\n ...acc,\n [attribute]: metadata.list,\n };\n },\n {}\n );\n /**\n * The fields arranged by the panels, new panels are made for dynamic zones only.\n */\n const listAttributes = convertListLayoutToFieldLayouts(\n data.contentType.layouts.list,\n schema?.attributes,\n listMetadatas,\n { configurations: data.components, schemas: components },\n schemas\n );\n\n return {\n layout: listAttributes,\n settings: { ...data.contentType.settings, displayName: schema?.info.displayName },\n metadatas: listMetadatas,\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n ...data.contentType.options,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * convertListLayoutToFieldLayouts\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the columns from the list view configuration and formats them into a generic object\n * combinining metadata and attribute data.\n *\n * @note We do use this to reformat the list of strings when updating the displayed headers for the list view.\n */\nconst convertListLayoutToFieldLayouts = (\n columns: LayoutData['contentType']['layouts']['list'],\n attributes: Schema['attributes'] = {},\n metadatas: ListLayout['metadatas'],\n components?: {\n configurations: Record<string, ComponentConfiguration>;\n schemas: ComponentsDictionary;\n },\n schemas: Schema[] = []\n) => {\n return columns\n .map((name) => {\n const attribute = attributes[name];\n\n if (!attribute) {\n return null;\n }\n\n const metadata = metadatas[name];\n\n const settings: Partial<Settings> =\n attribute.type === 'component' && components\n ? components.configurations[attribute.component].settings\n : {};\n\n return {\n attribute,\n label: metadata.label ?? '',\n mainField: getMainField(attribute, metadata.mainField || settings.mainField, {\n schemas,\n components: components?.schemas ?? {},\n }),\n name: name,\n searchable: metadata.searchable ?? true,\n sortable: metadata.sortable ?? true,\n } satisfies ListFieldLayout;\n })\n .filter((field) => field !== null) as ListFieldLayout[];\n};\n\nexport {\n useDocLayout,\n useDocumentLayout,\n convertListLayoutToFieldLayouts,\n convertEditLayoutToFieldLayouts,\n DEFAULT_SETTINGS,\n};\nexport type { EditLayout, EditFieldLayout, ListLayout, ListFieldLayout, UseDocumentLayout };\n"],"names":["DEFAULT_SETTINGS","bulkable","filterable","searchable","pagination","defaultSortBy","defaultSortOrder","mainField","pageSize","relationOpenMode","useDocumentLayout","model","schema","components","useDocument","collectionType","skip","query","useQueryParams","runHookWaterfall","useStrapiApp","state","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","isLoading","isLoadingSchemas","schemas","useContentTypeSchema","data","isLoadingConfigs","error","isFetching","isFetchingConfigs","useGetContentTypeConfigurationQuery","React","useEffect","type","message","editLayout","useMemo","formatEditLayout","layout","metadatas","options","settings","listLayout","formatListLayout","edit","HOOKS","MUTATE_EDIT_VIEW_LAYOUT","listViewConversionContext","componentConfigurations","componentSchemas","contentTypeSchemas","list","useDocLayout","useDoc","currentPanelIndex","panelledEditAttributes","convertEditLayoutToFieldLayouts","contentType","layouts","attributes","configurations","reduce","panels","row","some","field","push","componentEditAttributes","Object","entries","acc","uid","configuration","icon","info","displayName","editMetadatas","attribute","metadata","pluginOptions","rows","map","name","component","disabled","editable","hint","description","label","getMainField","placeholder","required","size","unique","visible","filter","listMetadatas","listAttributes","convertListLayoutToFieldLayouts","columns","sortable"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuHA;;AAEkG,2GAE5FA,gBAAAA,GAAmB;IACvBC,QAAAA,EAAU,KAAA;IACVC,UAAAA,EAAY,KAAA;IACZC,UAAAA,EAAY,KAAA;IACZC,UAAAA,EAAY,KAAA;IACZC,aAAAA,EAAe,EAAA;IACfC,gBAAAA,EAAkB,KAAA;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AA,GACJoC,SAAAA,CAAU5C,IAAI,KAAK,eAAe1B,UAAAA,GAC9BA,UAAAA,CAAWqD,cAAc,CAACiB,UAAUM,SAAS,CAAC,CAAC1C,QAAQ,GACvD,EAAC;QAEP,OAAO;AACLoC,YAAAA,SAAAA;YACAW,KAAAA,EAAOV,QAAAA,CAASU,KAAK,IAAI,EAAA;AACzBvF,YAAAA,SAAAA,EAAWwF,wBAAaZ,SAAAA,EAAWC,QAAAA,CAAS7E,SAAS,IAAIwC,QAAAA,CAASxC,SAAS,EAAE;AAC3EsB,gBAAAA,OAAAA;gBACAhB,UAAAA,EAAYA,UAAAA,EAAYgB,WAAW;AACrC,aAAA,CAAA;YACA2D,IAAAA,EAAMA,IAAAA;YACNrF,UAAAA,EAAYiF,QAAAA,CAASjF,UAAU,IAAI,IAAA;YACnCuG,QAAAA,EAAUtB,QAAAA,CAASsB,QAAQ,IAAI;AACjC,SAAA;AACF,IAAA,CAAA,CAAA,CACCL,MAAM,CAAC,CAAC9B,KAAAA,GAAUA,KAAAA,KAAU,IAAA,CAAA;AACjC;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"useDocumentLayout.js","sources":["../../../admin/src/hooks/useDocumentLayout.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { SerializedError } from '@reduxjs/toolkit';\nimport {\n useNotification,\n useStrapiApp,\n useAPIErrorHandler,\n useQueryParams,\n} from '@strapi/admin/strapi-admin';\n\nimport { HOOKS } from '../constants/hooks';\nimport { useGetContentTypeConfigurationQuery } from '../services/contentTypes';\nimport { BaseQueryError } from '../utils/api';\nimport { getMainField } from '../utils/attributes';\n\nimport { useContentTypeSchema } from './useContentTypeSchema';\nimport {\n type ComponentsDictionary,\n type Document,\n type Schema,\n useDoc,\n useDocument,\n} from './useDocument';\n\nimport type { ComponentConfiguration } from '../../../shared/contracts/components';\nimport type {\n Metadatas,\n FindContentTypeConfiguration,\n Settings,\n} from '../../../shared/contracts/content-types';\nimport type { Filters, InputProps, Table } from '@strapi/admin/strapi-admin';\nimport type { Schema as SchemaUtils } from '@strapi/types';\n\ntype LayoutOptions = Schema['options'] & Schema['pluginOptions'] & object;\n\ninterface LayoutSettings extends Settings {\n displayName?: string;\n icon?: never;\n}\n\ninterface ListFieldLayout\n extends Table.Header<Document, ListFieldLayout>,\n Pick<Filters.Filter, 'mainField'> {\n attribute: SchemaUtils.Attribute.AnyAttribute | { type: 'custom' };\n}\n\ninterface ListLayout {\n layout: ListFieldLayout[];\n components?: never;\n metadatas: {\n [K in keyof Metadatas]: Metadatas[K]['list'];\n };\n options: LayoutOptions;\n settings: LayoutSettings;\n}\ninterface EditFieldSharedProps\n extends Omit<InputProps, 'hint' | 'label' | 'type'>,\n Pick<Filters.Filter, 'mainField'> {\n hint?: string;\n label: string;\n size: number;\n unique?: boolean;\n visible?: boolean;\n}\n\n/**\n * Map over all the types in Attribute Types and use that to create a union of new types where the attribute type\n * is under the property attribute and the type is under the property type.\n */\ntype EditFieldLayout = {\n [K in SchemaUtils.Attribute.Kind]: EditFieldSharedProps & {\n attribute: Extract<SchemaUtils.Attribute.AnyAttribute, { type: K }>;\n type: K;\n };\n}[SchemaUtils.Attribute.Kind];\n\ninterface EditLayout {\n layout: Array<Array<EditFieldLayout[]>>;\n components: {\n [uid: string]: {\n layout: Array<EditFieldLayout[]>;\n settings: ComponentConfiguration['settings'] & {\n displayName?: string;\n icon?: string;\n };\n };\n };\n metadatas: {\n [K in keyof Metadatas]: Metadatas[K]['edit'];\n };\n options: LayoutOptions;\n settings: LayoutSettings;\n}\n\n/**\n * Data required to resolve `mainField` when converting list column names to field layouts for\n * component and relation attributes; mirrors the fourth and fifth arguments of `formatListLayout`.\n */\ntype ListViewConversionContext = {\n componentConfigurations: FindContentTypeConfiguration.Response['data']['components'];\n componentSchemas: ComponentsDictionary;\n contentTypeSchemas: Schema[];\n};\n\ntype UseDocumentLayout = (model: string) => {\n error?: BaseQueryError | SerializedError;\n isLoading: boolean;\n /**\n * This is the layout for the edit view,\n */\n edit: EditLayout;\n list: ListLayout;\n /**\n * Populated when configuration is loaded; pass into `convertListLayoutToFieldLayouts` with\n * `list.metadatas` when mapping persisted list column names (e.g. custom displayed headers).\n */\n listViewConversionContext: ListViewConversionContext | null;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDocumentLayout\n * -----------------------------------------------------------------------------------------------*/\n\nconst DEFAULT_SETTINGS = {\n bulkable: false,\n filterable: false,\n searchable: false,\n pagination: false,\n defaultSortBy: '',\n defaultSortOrder: 'asc',\n mainField: 'id',\n pageSize: 10,\n relationOpenMode: 'modal' as const,\n};\n\n/**\n * @alpha\n * @description This hook is used to get the layouts for either the edit view or list view of a specific content-type\n * including the layouts for the components used in the content-type. It also runs the mutation hook waterfall so the data\n * is consistent wherever it is used. It's a light wrapper around the `useDocument` hook, but provides the `skip` option a document\n * is not fetched, however, it does fetch the schemas & components if they do not already exist in the cache.\n *\n * If the fetch fails, it will display a notification to the user.\n *\n * @example\n * ```tsx\n * const { model } = useParams<{ model: string }>();\n * const { edit: { schema: layout } } = useDocumentLayout(model);\n *\n * return layout.map(panel => panel.map(row => row.map(field => <Field.Root {...field} />)))\n * ```\n *\n */\nconst useDocumentLayout: UseDocumentLayout = (model) => {\n const { schema, components } = useDocument({ model, collectionType: '' }, { skip: true });\n const [{ query }] = useQueryParams();\n const runHookWaterfall = useStrapiApp('useDocumentLayout', (state) => state.runHookWaterfall);\n const { toggleNotification } = useNotification();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();\n\n const { data, isLoading: isLoadingConfigs, error } = useGetContentTypeConfigurationQuery(model);\n\n const isLoading = isLoadingSchemas || isLoadingConfigs;\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [error, formatAPIError, toggleNotification]);\n\n const editLayout = React.useMemo(\n () =>\n data && !isLoading\n ? formatEditLayout(data, { schemas, schema, components })\n : ({\n layout: [],\n components: {},\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as EditLayout),\n [data, isLoading, schemas, schema, components]\n );\n\n const listLayout = React.useMemo(() => {\n return data && !isLoading\n ? formatListLayout(data, { schemas, schema, components })\n : ({\n layout: [],\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as ListLayout);\n }, [data, isLoading, schemas, schema, components]);\n\n const { layout: edit } = React.useMemo(\n () =>\n runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {\n layout: editLayout,\n query,\n }),\n [editLayout, query, runHookWaterfall]\n );\n\n const listViewConversionContext = React.useMemo((): ListViewConversionContext | null => {\n if (!data || isLoading) {\n return null;\n }\n\n return {\n componentConfigurations: data.components,\n componentSchemas: components,\n contentTypeSchemas: schemas,\n };\n }, [data, isLoading, components, schemas]);\n\n return {\n error,\n isLoading,\n edit,\n list: listLayout,\n listViewConversionContext,\n } satisfies ReturnType<UseDocumentLayout>;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDocLayout\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal this hook uses the internal useDoc hook, as such it shouldn't be used outside of the\n * content-manager because it won't work as intended.\n */\nconst useDocLayout = () => {\n const { model } = useDoc();\n return useDocumentLayout(model);\n};\n\n/* -------------------------------------------------------------------------------------------------\n * formatEditLayout\n * -----------------------------------------------------------------------------------------------*/\ntype LayoutData = FindContentTypeConfiguration.Response['data'];\n\n/**\n * @internal\n * @description takes the configuration data, the schema & the components used in the schema and formats the edit view\n * versions of the schema & components. This is then used to render the edit view of the content-type.\n */\nconst formatEditLayout = (\n data: LayoutData,\n {\n schemas,\n schema,\n components,\n }: { schemas: Schema[]; schema?: Schema; components: ComponentsDictionary }\n): EditLayout => {\n let currentPanelIndex = 0;\n /**\n * The fields arranged by the panels, new panels are made for dynamic zones only.\n */\n const panelledEditAttributes = convertEditLayoutToFieldLayouts(\n data.contentType.layouts.edit,\n schema?.attributes,\n data.contentType.metadatas,\n { configurations: data.components, schemas: components },\n schemas\n ).reduce<Array<EditFieldLayout[][]>>((panels, row) => {\n if (row.some((field) => field.type === 'dynamiczone')) {\n panels.push([row]);\n currentPanelIndex += 2;\n } else {\n if (!panels[currentPanelIndex]) {\n panels.push([row]);\n } else {\n panels[currentPanelIndex].push(row);\n }\n }\n\n return panels;\n }, []);\n\n const componentEditAttributes = Object.entries(data.components).reduce<EditLayout['components']>(\n (acc, [uid, configuration]) => {\n acc[uid] = {\n layout: convertEditLayoutToFieldLayouts(\n configuration.layouts.edit,\n components[uid].attributes,\n configuration.metadatas,\n { configurations: data.components, schemas: components }\n ),\n settings: {\n ...configuration.settings,\n icon: components[uid].info.icon,\n displayName: components[uid].info.displayName,\n },\n };\n return acc;\n },\n {}\n );\n\n const editMetadatas = Object.entries(data.contentType.metadatas).reduce<EditLayout['metadatas']>(\n (acc, [attribute, metadata]) => {\n return {\n ...acc,\n [attribute]: metadata.edit,\n };\n },\n {}\n );\n\n return {\n layout: panelledEditAttributes,\n components: componentEditAttributes,\n metadatas: editMetadatas,\n settings: {\n ...data.contentType.settings,\n displayName: schema?.info.displayName,\n },\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n ...data.contentType.options,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * convertEditLayoutToFieldLayouts\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the edit layout from either a content-type or a component\n * and formats it into a generic object that can be used to correctly render\n * the form fields.\n */\nconst convertEditLayoutToFieldLayouts = (\n rows: LayoutData['contentType']['layouts']['edit'],\n attributes: Schema['attributes'] = {},\n metadatas: Metadatas,\n components?: {\n configurations: Record<string, ComponentConfiguration>;\n schemas: ComponentsDictionary;\n },\n schemas: Schema[] = []\n) => {\n return rows.map((row) =>\n row\n .map((field) => {\n const attribute = attributes[field.name];\n\n if (!attribute) {\n return null;\n }\n\n const { edit: metadata } = metadatas[field.name];\n\n const settings: Partial<Settings> =\n attribute.type === 'component' && components\n ? components.configurations[attribute.component].settings\n : {};\n\n return {\n attribute,\n disabled: !metadata.editable,\n hint: metadata.description,\n label: metadata.label ?? '',\n name: field.name,\n // @ts-expect-error – mainField does exist on the metadata for a relation.\n mainField: getMainField(attribute, metadata.mainField || settings.mainField, {\n schemas,\n components: components?.schemas ?? {},\n }),\n placeholder: metadata.placeholder ?? '',\n required: attribute.required ?? false,\n size: field.size,\n unique: 'unique' in attribute ? attribute.unique : false,\n visible: metadata.visible ?? true,\n type: attribute.type,\n };\n })\n .filter((field) => field !== null)\n ) as EditFieldLayout[][];\n};\n\n/* -------------------------------------------------------------------------------------------------\n * formatListLayout\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the complete configuration data, the schema & the components used in the schema and\n * formats a list view layout for the content-type. This is much simpler than the edit view layout as there\n * are less options to consider.\n */\nconst formatListLayout = (\n data: LayoutData,\n {\n schemas,\n schema,\n components,\n }: { schemas: Schema[]; schema?: Schema; components: ComponentsDictionary }\n): ListLayout => {\n const listMetadatas = Object.entries(data.contentType.metadatas).reduce<ListLayout['metadatas']>(\n (acc, [attribute, metadata]) => {\n return {\n ...acc,\n [attribute]: metadata.list,\n };\n },\n {}\n );\n /**\n * The fields arranged by the panels, new panels are made for dynamic zones only.\n */\n const listAttributes = convertListLayoutToFieldLayouts(\n data.contentType.layouts.list,\n schema?.attributes,\n listMetadatas,\n { configurations: data.components, schemas: components },\n schemas\n );\n\n return {\n layout: listAttributes,\n settings: { ...data.contentType.settings, displayName: schema?.info.displayName },\n metadatas: listMetadatas,\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n ...data.contentType.options,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * convertListLayoutToFieldLayouts\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the columns from the list view configuration and formats them into a generic object\n * combinining metadata and attribute data.\n *\n * @note We do use this to reformat the list of strings when updating the displayed headers for the list view.\n */\nconst convertListLayoutToFieldLayouts = (\n columns: LayoutData['contentType']['layouts']['list'],\n attributes: Schema['attributes'] = {},\n metadatas: ListLayout['metadatas'],\n components?: {\n configurations: Record<string, ComponentConfiguration>;\n schemas: ComponentsDictionary;\n },\n schemas: Schema[] = []\n) => {\n return columns\n .map((name) => {\n const attribute = attributes[name];\n\n if (!attribute) {\n return null;\n }\n\n const metadata = metadatas[name];\n\n const settings: Partial<Settings> =\n attribute.type === 'component' && components\n ? components.configurations[attribute.component].settings\n : {};\n\n return {\n attribute,\n label: metadata.label ?? '',\n mainField: getMainField(attribute, metadata.mainField || settings.mainField, {\n schemas,\n components: components?.schemas ?? {},\n }),\n name: name,\n searchable: metadata.searchable ?? true,\n sortable: metadata.sortable ?? true,\n } satisfies ListFieldLayout;\n })\n .filter((field) => field !== null) as ListFieldLayout[];\n};\n\nexport {\n useDocLayout,\n useDocumentLayout,\n convertListLayoutToFieldLayouts,\n convertEditLayoutToFieldLayouts,\n DEFAULT_SETTINGS,\n};\nexport type { EditLayout, EditFieldLayout, ListLayout, ListFieldLayout, UseDocumentLayout };\n"],"names":["DEFAULT_SETTINGS","bulkable","filterable","searchable","pagination","defaultSortBy","defaultSortOrder","mainField","pageSize","relationOpenMode","useDocumentLayout","model","schema","components","useDocument","collectionType","skip","query","useQueryParams","runHookWaterfall","useStrapiApp","state","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","isLoading","isLoadingSchemas","schemas","useContentTypeSchema","data","isLoadingConfigs","error","useGetContentTypeConfigurationQuery","React","useEffect","type","message","editLayout","useMemo","formatEditLayout","layout","metadatas","options","settings","listLayout","formatListLayout","edit","HOOKS","MUTATE_EDIT_VIEW_LAYOUT","listViewConversionContext","componentConfigurations","componentSchemas","contentTypeSchemas","list","useDocLayout","useDoc","currentPanelIndex","panelledEditAttributes","convertEditLayoutToFieldLayouts","contentType","layouts","attributes","configurations","reduce","panels","row","some","field","push","componentEditAttributes","Object","entries","acc","uid","configuration","icon","info","displayName","editMetadatas","attribute","metadata","pluginOptions","rows","map","name","component","disabled","editable","hint","description","label","getMainField","placeholder","required","size","unique","visible","filter","listMetadatas","listAttributes","convertListLayoutToFieldLayouts","columns","sortable"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuHA;;AAEkG,2GAE5FA,gBAAAA,GAAmB;IACvBC,QAAAA,EAAU,KAAA;IACVC,UAAAA,EAAY,KAAA;IACZC,UAAAA,EAAY,KAAA;IACZC,UAAAA,EAAY,KAAA;IACZC,aAAAA,EAAe,EAAA;IACfC,gBAAAA,EAAkB,KAAA;IAClBC,SAAAA,EAAW,IAAA;IACXC,QAAAA,EAAU,EAAA;IACVC,gBAAAA,EAAkB;AACpB;AAEA;;;;;;;;;;;;;;;;;IAkBA,MAAMC,oBAAuC,CAACC,KAAAA,GAAAA;AAC5C,IAAA,MAAM,EAAEC,MAAM,EAAEC,UAAU,EAAE,GAAGC,uBAAAA,CAAY;AAAEH,QAAAA,KAAAA;QAAOI,cAAAA,EAAgB;KAAG,EAAG;QAAEC,IAAAA,EAAM;AAAK,KAAA,CAAA;AACvF,IAAA,MAAM,CAAC,EAAEC,KAAK,EAAE,CAAC,GAAGC,0BAAAA,EAAAA;AACpB,IAAA,MAAMC,mBAAmBC,wBAAAA,CAAa,mBAAA,EAAqB,CAACC,KAAAA,GAAUA,MAAMF,gBAAgB,CAAA;IAC5F,MAAM,EAAEG,kBAAkB,EAAE,GAAGC,2BAAAA,EAAAA;AAC/B,IAAA,MAAM,EAAEC,uBAAAA,EAAyBC,cAAc,EAAE,GAAGC,8BAAAA,EAAAA;AACpD,IAAA,MAAM,EAAEC,SAAAA,EAAWC,gBAAgB,EAAEC,OAAO,EAAE,GAAGC,yCAAAA,EAAAA;IAEjD,MAAM,EAAEC,IAAI,EAAEJ,SAAAA,EAAWK,gBAAgB,EAAEC,KAAK,EAAE,GAAGC,gDAAAA,CAAoCvB,KAAAA,CAAAA;AAEzF,IAAA,MAAMgB,YAAYC,gBAAAA,IAAoBI,gBAAAA;AA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B,OAAAA,GAAoB,EAAE,GAAA;IAEtB,OAAO0E,OAAAA,CACJlB,GAAG,CAAC,CAACC,IAAAA,GAAAA;QACJ,MAAML,SAAAA,GAAYlB,YAAU,CAACuB,IAAAA,CAAK;AAElC,QAAA,IAAI,CAACL,SAAAA,EAAW;YACd,OAAO,IAAA;AACT,QAAA;QAEA,MAAMC,QAAAA,GAAWvC,SAAS,CAAC2C,IAAAA,CAAK;AAEhC,QAAA,MAAMzC,QAAAA,GACJoC,SAAAA,CAAU5C,IAAI,KAAK,eAAexB,UAAAA,GAC9BA,UAAAA,CAAWmD,cAAc,CAACiB,UAAUM,SAAS,CAAC,CAAC1C,QAAQ,GACvD,EAAC;QAEP,OAAO;AACLoC,YAAAA,SAAAA;YACAW,KAAAA,EAAOV,QAAAA,CAASU,KAAK,IAAI,EAAA;AACzBrF,YAAAA,SAAAA,EAAWsF,wBAAaZ,SAAAA,EAAWC,QAAAA,CAAS3E,SAAS,IAAIsC,QAAAA,CAAStC,SAAS,EAAE;AAC3EsB,gBAAAA,OAAAA;gBACAhB,UAAAA,EAAYA,UAAAA,EAAYgB,WAAW;AACrC,aAAA,CAAA;YACAyD,IAAAA,EAAMA,IAAAA;YACNnF,UAAAA,EAAY+E,QAAAA,CAAS/E,UAAU,IAAI,IAAA;YACnCqG,QAAAA,EAAUtB,QAAAA,CAASsB,QAAQ,IAAI;AACjC,SAAA;AACF,IAAA,CAAA,CAAA,CACCL,MAAM,CAAC,CAAC9B,KAAAA,GAAUA,KAAAA,KAAU,IAAA,CAAA;AACjC;;;;;;;;"}
|
|
@@ -48,8 +48,8 @@ import { useDocument, useDoc } from './useDocument.mjs';
|
|
|
48
48
|
const { toggleNotification } = useNotification();
|
|
49
49
|
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
|
50
50
|
const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
|
|
51
|
-
const { data, isLoading: isLoadingConfigs, error
|
|
52
|
-
const isLoading = isLoadingSchemas ||
|
|
51
|
+
const { data, isLoading: isLoadingConfigs, error } = useGetContentTypeConfigurationQuery(model);
|
|
52
|
+
const isLoading = isLoadingSchemas || isLoadingConfigs;
|
|
53
53
|
React.useEffect(()=>{
|
|
54
54
|
if (error) {
|
|
55
55
|
toggleNotification({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDocumentLayout.mjs","sources":["../../../admin/src/hooks/useDocumentLayout.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { SerializedError } from '@reduxjs/toolkit';\nimport {\n useNotification,\n useStrapiApp,\n useAPIErrorHandler,\n useQueryParams,\n} from '@strapi/admin/strapi-admin';\n\nimport { HOOKS } from '../constants/hooks';\nimport { useGetContentTypeConfigurationQuery } from '../services/contentTypes';\nimport { BaseQueryError } from '../utils/api';\nimport { getMainField } from '../utils/attributes';\n\nimport { useContentTypeSchema } from './useContentTypeSchema';\nimport {\n type ComponentsDictionary,\n type Document,\n type Schema,\n useDoc,\n useDocument,\n} from './useDocument';\n\nimport type { ComponentConfiguration } from '../../../shared/contracts/components';\nimport type {\n Metadatas,\n FindContentTypeConfiguration,\n Settings,\n} from '../../../shared/contracts/content-types';\nimport type { Filters, InputProps, Table } from '@strapi/admin/strapi-admin';\nimport type { Schema as SchemaUtils } from '@strapi/types';\n\ntype LayoutOptions = Schema['options'] & Schema['pluginOptions'] & object;\n\ninterface LayoutSettings extends Settings {\n displayName?: string;\n icon?: never;\n}\n\ninterface ListFieldLayout\n extends Table.Header<Document, ListFieldLayout>,\n Pick<Filters.Filter, 'mainField'> {\n attribute: SchemaUtils.Attribute.AnyAttribute | { type: 'custom' };\n}\n\ninterface ListLayout {\n layout: ListFieldLayout[];\n components?: never;\n metadatas: {\n [K in keyof Metadatas]: Metadatas[K]['list'];\n };\n options: LayoutOptions;\n settings: LayoutSettings;\n}\ninterface EditFieldSharedProps\n extends Omit<InputProps, 'hint' | 'label' | 'type'>,\n Pick<Filters.Filter, 'mainField'> {\n hint?: string;\n label: string;\n size: number;\n unique?: boolean;\n visible?: boolean;\n}\n\n/**\n * Map over all the types in Attribute Types and use that to create a union of new types where the attribute type\n * is under the property attribute and the type is under the property type.\n */\ntype EditFieldLayout = {\n [K in SchemaUtils.Attribute.Kind]: EditFieldSharedProps & {\n attribute: Extract<SchemaUtils.Attribute.AnyAttribute, { type: K }>;\n type: K;\n };\n}[SchemaUtils.Attribute.Kind];\n\ninterface EditLayout {\n layout: Array<Array<EditFieldLayout[]>>;\n components: {\n [uid: string]: {\n layout: Array<EditFieldLayout[]>;\n settings: ComponentConfiguration['settings'] & {\n displayName?: string;\n icon?: string;\n };\n };\n };\n metadatas: {\n [K in keyof Metadatas]: Metadatas[K]['edit'];\n };\n options: LayoutOptions;\n settings: LayoutSettings;\n}\n\n/**\n * Data required to resolve `mainField` when converting list column names to field layouts for\n * component and relation attributes; mirrors the fourth and fifth arguments of `formatListLayout`.\n */\ntype ListViewConversionContext = {\n componentConfigurations: FindContentTypeConfiguration.Response['data']['components'];\n componentSchemas: ComponentsDictionary;\n contentTypeSchemas: Schema[];\n};\n\ntype UseDocumentLayout = (model: string) => {\n error?: BaseQueryError | SerializedError;\n isLoading: boolean;\n /**\n * This is the layout for the edit view,\n */\n edit: EditLayout;\n list: ListLayout;\n /**\n * Populated when configuration is loaded; pass into `convertListLayoutToFieldLayouts` with\n * `list.metadatas` when mapping persisted list column names (e.g. custom displayed headers).\n */\n listViewConversionContext: ListViewConversionContext | null;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDocumentLayout\n * -----------------------------------------------------------------------------------------------*/\n\nconst DEFAULT_SETTINGS = {\n bulkable: false,\n filterable: false,\n searchable: false,\n pagination: false,\n defaultSortBy: '',\n defaultSortOrder: 'asc',\n mainField: 'id',\n pageSize: 10,\n relationOpenMode: 'modal' as const,\n};\n\n/**\n * @alpha\n * @description This hook is used to get the layouts for either the edit view or list view of a specific content-type\n * including the layouts for the components used in the content-type. It also runs the mutation hook waterfall so the data\n * is consistent wherever it is used. It's a light wrapper around the `useDocument` hook, but provides the `skip` option a document\n * is not fetched, however, it does fetch the schemas & components if they do not already exist in the cache.\n *\n * If the fetch fails, it will display a notification to the user.\n *\n * @example\n * ```tsx\n * const { model } = useParams<{ model: string }>();\n * const { edit: { schema: layout } } = useDocumentLayout(model);\n *\n * return layout.map(panel => panel.map(row => row.map(field => <Field.Root {...field} />)))\n * ```\n *\n */\nconst useDocumentLayout: UseDocumentLayout = (model) => {\n const { schema, components } = useDocument({ model, collectionType: '' }, { skip: true });\n const [{ query }] = useQueryParams();\n const runHookWaterfall = useStrapiApp('useDocumentLayout', (state) => state.runHookWaterfall);\n const { toggleNotification } = useNotification();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();\n\n const {\n data,\n isLoading: isLoadingConfigs,\n error,\n isFetching: isFetchingConfigs,\n } = useGetContentTypeConfigurationQuery(model);\n\n const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [error, formatAPIError, toggleNotification]);\n\n const editLayout = React.useMemo(\n () =>\n data && !isLoading\n ? formatEditLayout(data, { schemas, schema, components })\n : ({\n layout: [],\n components: {},\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as EditLayout),\n [data, isLoading, schemas, schema, components]\n );\n\n const listLayout = React.useMemo(() => {\n return data && !isLoading\n ? formatListLayout(data, { schemas, schema, components })\n : ({\n layout: [],\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as ListLayout);\n }, [data, isLoading, schemas, schema, components]);\n\n const { layout: edit } = React.useMemo(\n () =>\n runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {\n layout: editLayout,\n query,\n }),\n [editLayout, query, runHookWaterfall]\n );\n\n const listViewConversionContext = React.useMemo((): ListViewConversionContext | null => {\n if (!data || isLoading) {\n return null;\n }\n\n return {\n componentConfigurations: data.components,\n componentSchemas: components,\n contentTypeSchemas: schemas,\n };\n }, [data, isLoading, components, schemas]);\n\n return {\n error,\n isLoading,\n edit,\n list: listLayout,\n listViewConversionContext,\n } satisfies ReturnType<UseDocumentLayout>;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDocLayout\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal this hook uses the internal useDoc hook, as such it shouldn't be used outside of the\n * content-manager because it won't work as intended.\n */\nconst useDocLayout = () => {\n const { model } = useDoc();\n return useDocumentLayout(model);\n};\n\n/* -------------------------------------------------------------------------------------------------\n * formatEditLayout\n * -----------------------------------------------------------------------------------------------*/\ntype LayoutData = FindContentTypeConfiguration.Response['data'];\n\n/**\n * @internal\n * @description takes the configuration data, the schema & the components used in the schema and formats the edit view\n * versions of the schema & components. This is then used to render the edit view of the content-type.\n */\nconst formatEditLayout = (\n data: LayoutData,\n {\n schemas,\n schema,\n components,\n }: { schemas: Schema[]; schema?: Schema; components: ComponentsDictionary }\n): EditLayout => {\n let currentPanelIndex = 0;\n /**\n * The fields arranged by the panels, new panels are made for dynamic zones only.\n */\n const panelledEditAttributes = convertEditLayoutToFieldLayouts(\n data.contentType.layouts.edit,\n schema?.attributes,\n data.contentType.metadatas,\n { configurations: data.components, schemas: components },\n schemas\n ).reduce<Array<EditFieldLayout[][]>>((panels, row) => {\n if (row.some((field) => field.type === 'dynamiczone')) {\n panels.push([row]);\n currentPanelIndex += 2;\n } else {\n if (!panels[currentPanelIndex]) {\n panels.push([row]);\n } else {\n panels[currentPanelIndex].push(row);\n }\n }\n\n return panels;\n }, []);\n\n const componentEditAttributes = Object.entries(data.components).reduce<EditLayout['components']>(\n (acc, [uid, configuration]) => {\n acc[uid] = {\n layout: convertEditLayoutToFieldLayouts(\n configuration.layouts.edit,\n components[uid].attributes,\n configuration.metadatas,\n { configurations: data.components, schemas: components }\n ),\n settings: {\n ...configuration.settings,\n icon: components[uid].info.icon,\n displayName: components[uid].info.displayName,\n },\n };\n return acc;\n },\n {}\n );\n\n const editMetadatas = Object.entries(data.contentType.metadatas).reduce<EditLayout['metadatas']>(\n (acc, [attribute, metadata]) => {\n return {\n ...acc,\n [attribute]: metadata.edit,\n };\n },\n {}\n );\n\n return {\n layout: panelledEditAttributes,\n components: componentEditAttributes,\n metadatas: editMetadatas,\n settings: {\n ...data.contentType.settings,\n displayName: schema?.info.displayName,\n },\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n ...data.contentType.options,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * convertEditLayoutToFieldLayouts\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the edit layout from either a content-type or a component\n * and formats it into a generic object that can be used to correctly render\n * the form fields.\n */\nconst convertEditLayoutToFieldLayouts = (\n rows: LayoutData['contentType']['layouts']['edit'],\n attributes: Schema['attributes'] = {},\n metadatas: Metadatas,\n components?: {\n configurations: Record<string, ComponentConfiguration>;\n schemas: ComponentsDictionary;\n },\n schemas: Schema[] = []\n) => {\n return rows.map((row) =>\n row\n .map((field) => {\n const attribute = attributes[field.name];\n\n if (!attribute) {\n return null;\n }\n\n const { edit: metadata } = metadatas[field.name];\n\n const settings: Partial<Settings> =\n attribute.type === 'component' && components\n ? components.configurations[attribute.component].settings\n : {};\n\n return {\n attribute,\n disabled: !metadata.editable,\n hint: metadata.description,\n label: metadata.label ?? '',\n name: field.name,\n // @ts-expect-error – mainField does exist on the metadata for a relation.\n mainField: getMainField(attribute, metadata.mainField || settings.mainField, {\n schemas,\n components: components?.schemas ?? {},\n }),\n placeholder: metadata.placeholder ?? '',\n required: attribute.required ?? false,\n size: field.size,\n unique: 'unique' in attribute ? attribute.unique : false,\n visible: metadata.visible ?? true,\n type: attribute.type,\n };\n })\n .filter((field) => field !== null)\n ) as EditFieldLayout[][];\n};\n\n/* -------------------------------------------------------------------------------------------------\n * formatListLayout\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the complete configuration data, the schema & the components used in the schema and\n * formats a list view layout for the content-type. This is much simpler than the edit view layout as there\n * are less options to consider.\n */\nconst formatListLayout = (\n data: LayoutData,\n {\n schemas,\n schema,\n components,\n }: { schemas: Schema[]; schema?: Schema; components: ComponentsDictionary }\n): ListLayout => {\n const listMetadatas = Object.entries(data.contentType.metadatas).reduce<ListLayout['metadatas']>(\n (acc, [attribute, metadata]) => {\n return {\n ...acc,\n [attribute]: metadata.list,\n };\n },\n {}\n );\n /**\n * The fields arranged by the panels, new panels are made for dynamic zones only.\n */\n const listAttributes = convertListLayoutToFieldLayouts(\n data.contentType.layouts.list,\n schema?.attributes,\n listMetadatas,\n { configurations: data.components, schemas: components },\n schemas\n );\n\n return {\n layout: listAttributes,\n settings: { ...data.contentType.settings, displayName: schema?.info.displayName },\n metadatas: listMetadatas,\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n ...data.contentType.options,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * convertListLayoutToFieldLayouts\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the columns from the list view configuration and formats them into a generic object\n * combinining metadata and attribute data.\n *\n * @note We do use this to reformat the list of strings when updating the displayed headers for the list view.\n */\nconst convertListLayoutToFieldLayouts = (\n columns: LayoutData['contentType']['layouts']['list'],\n attributes: Schema['attributes'] = {},\n metadatas: ListLayout['metadatas'],\n components?: {\n configurations: Record<string, ComponentConfiguration>;\n schemas: ComponentsDictionary;\n },\n schemas: Schema[] = []\n) => {\n return columns\n .map((name) => {\n const attribute = attributes[name];\n\n if (!attribute) {\n return null;\n }\n\n const metadata = metadatas[name];\n\n const settings: Partial<Settings> =\n attribute.type === 'component' && components\n ? components.configurations[attribute.component].settings\n : {};\n\n return {\n attribute,\n label: metadata.label ?? '',\n mainField: getMainField(attribute, metadata.mainField || settings.mainField, {\n schemas,\n components: components?.schemas ?? {},\n }),\n name: name,\n searchable: metadata.searchable ?? true,\n sortable: metadata.sortable ?? true,\n } satisfies ListFieldLayout;\n })\n .filter((field) => field !== null) as ListFieldLayout[];\n};\n\nexport {\n useDocLayout,\n useDocumentLayout,\n convertListLayoutToFieldLayouts,\n convertEditLayoutToFieldLayouts,\n DEFAULT_SETTINGS,\n};\nexport type { EditLayout, EditFieldLayout, ListLayout, ListFieldLayout, UseDocumentLayout };\n"],"names":["DEFAULT_SETTINGS","bulkable","filterable","searchable","pagination","defaultSortBy","defaultSortOrder","mainField","pageSize","relationOpenMode","useDocumentLayout","model","schema","components","useDocument","collectionType","skip","query","useQueryParams","runHookWaterfall","useStrapiApp","state","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","isLoading","isLoadingSchemas","schemas","useContentTypeSchema","data","isLoadingConfigs","error","isFetching","isFetchingConfigs","useGetContentTypeConfigurationQuery","React","useEffect","type","message","editLayout","useMemo","formatEditLayout","layout","metadatas","options","settings","listLayout","formatListLayout","edit","HOOKS","MUTATE_EDIT_VIEW_LAYOUT","listViewConversionContext","componentConfigurations","componentSchemas","contentTypeSchemas","list","useDocLayout","useDoc","currentPanelIndex","panelledEditAttributes","convertEditLayoutToFieldLayouts","contentType","layouts","attributes","configurations","reduce","panels","row","some","field","push","componentEditAttributes","Object","entries","acc","uid","configuration","icon","info","displayName","editMetadatas","attribute","metadata","pluginOptions","rows","map","name","component","disabled","editable","hint","description","label","getMainField","placeholder","required","size","unique","visible","filter","listMetadatas","listAttributes","convertListLayoutToFieldLayouts","columns","sortable"],"mappings":";;;;;;;;AAuHA;;AAEkG,2GAE5FA,gBAAAA,GAAmB;IACvBC,QAAAA,EAAU,KAAA;IACVC,UAAAA,EAAY,KAAA;IACZC,UAAAA,EAAY,KAAA;IACZC,UAAAA,EAAY,KAAA;IACZC,aAAAA,EAAe,EAAA;IACfC,gBAAAA,EAAkB,KAAA;IAClBC,SAAAA,EAAW,IAAA;IACXC,QAAAA,EAAU,EAAA;IACVC,gBAAAA,EAAkB;AACpB;AAEA;;;;;;;;;;;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CAAC1C,QAAQ,GACvD,EAAC;QAEP,OAAO;AACLoC,YAAAA,SAAAA;YACAW,KAAAA,EAAOV,QAAAA,CAASU,KAAK,IAAI,EAAA;AACzBvF,YAAAA,SAAAA,EAAWwF,aAAaZ,SAAAA,EAAWC,QAAAA,CAAS7E,SAAS,IAAIwC,QAAAA,CAASxC,SAAS,EAAE;AAC3EsB,gBAAAA,OAAAA;gBACAhB,UAAAA,EAAYA,UAAAA,EAAYgB,WAAW;AACrC,aAAA,CAAA;YACA2D,IAAAA,EAAMA,IAAAA;YACNrF,UAAAA,EAAYiF,QAAAA,CAASjF,UAAU,IAAI,IAAA;YACnCuG,QAAAA,EAAUtB,QAAAA,CAASsB,QAAQ,IAAI;AACjC,SAAA;AACF,IAAA,CAAA,CAAA,CACCL,MAAM,CAAC,CAAC9B,KAAAA,GAAUA,KAAAA,KAAU,IAAA,CAAA;AACjC;;;;"}
|
|
1
|
+
{"version":3,"file":"useDocumentLayout.mjs","sources":["../../../admin/src/hooks/useDocumentLayout.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { SerializedError } from '@reduxjs/toolkit';\nimport {\n useNotification,\n useStrapiApp,\n useAPIErrorHandler,\n useQueryParams,\n} from '@strapi/admin/strapi-admin';\n\nimport { HOOKS } from '../constants/hooks';\nimport { useGetContentTypeConfigurationQuery } from '../services/contentTypes';\nimport { BaseQueryError } from '../utils/api';\nimport { getMainField } from '../utils/attributes';\n\nimport { useContentTypeSchema } from './useContentTypeSchema';\nimport {\n type ComponentsDictionary,\n type Document,\n type Schema,\n useDoc,\n useDocument,\n} from './useDocument';\n\nimport type { ComponentConfiguration } from '../../../shared/contracts/components';\nimport type {\n Metadatas,\n FindContentTypeConfiguration,\n Settings,\n} from '../../../shared/contracts/content-types';\nimport type { Filters, InputProps, Table } from '@strapi/admin/strapi-admin';\nimport type { Schema as SchemaUtils } from '@strapi/types';\n\ntype LayoutOptions = Schema['options'] & Schema['pluginOptions'] & object;\n\ninterface LayoutSettings extends Settings {\n displayName?: string;\n icon?: never;\n}\n\ninterface ListFieldLayout\n extends Table.Header<Document, ListFieldLayout>,\n Pick<Filters.Filter, 'mainField'> {\n attribute: SchemaUtils.Attribute.AnyAttribute | { type: 'custom' };\n}\n\ninterface ListLayout {\n layout: ListFieldLayout[];\n components?: never;\n metadatas: {\n [K in keyof Metadatas]: Metadatas[K]['list'];\n };\n options: LayoutOptions;\n settings: LayoutSettings;\n}\ninterface EditFieldSharedProps\n extends Omit<InputProps, 'hint' | 'label' | 'type'>,\n Pick<Filters.Filter, 'mainField'> {\n hint?: string;\n label: string;\n size: number;\n unique?: boolean;\n visible?: boolean;\n}\n\n/**\n * Map over all the types in Attribute Types and use that to create a union of new types where the attribute type\n * is under the property attribute and the type is under the property type.\n */\ntype EditFieldLayout = {\n [K in SchemaUtils.Attribute.Kind]: EditFieldSharedProps & {\n attribute: Extract<SchemaUtils.Attribute.AnyAttribute, { type: K }>;\n type: K;\n };\n}[SchemaUtils.Attribute.Kind];\n\ninterface EditLayout {\n layout: Array<Array<EditFieldLayout[]>>;\n components: {\n [uid: string]: {\n layout: Array<EditFieldLayout[]>;\n settings: ComponentConfiguration['settings'] & {\n displayName?: string;\n icon?: string;\n };\n };\n };\n metadatas: {\n [K in keyof Metadatas]: Metadatas[K]['edit'];\n };\n options: LayoutOptions;\n settings: LayoutSettings;\n}\n\n/**\n * Data required to resolve `mainField` when converting list column names to field layouts for\n * component and relation attributes; mirrors the fourth and fifth arguments of `formatListLayout`.\n */\ntype ListViewConversionContext = {\n componentConfigurations: FindContentTypeConfiguration.Response['data']['components'];\n componentSchemas: ComponentsDictionary;\n contentTypeSchemas: Schema[];\n};\n\ntype UseDocumentLayout = (model: string) => {\n error?: BaseQueryError | SerializedError;\n isLoading: boolean;\n /**\n * This is the layout for the edit view,\n */\n edit: EditLayout;\n list: ListLayout;\n /**\n * Populated when configuration is loaded; pass into `convertListLayoutToFieldLayouts` with\n * `list.metadatas` when mapping persisted list column names (e.g. custom displayed headers).\n */\n listViewConversionContext: ListViewConversionContext | null;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDocumentLayout\n * -----------------------------------------------------------------------------------------------*/\n\nconst DEFAULT_SETTINGS = {\n bulkable: false,\n filterable: false,\n searchable: false,\n pagination: false,\n defaultSortBy: '',\n defaultSortOrder: 'asc',\n mainField: 'id',\n pageSize: 10,\n relationOpenMode: 'modal' as const,\n};\n\n/**\n * @alpha\n * @description This hook is used to get the layouts for either the edit view or list view of a specific content-type\n * including the layouts for the components used in the content-type. It also runs the mutation hook waterfall so the data\n * is consistent wherever it is used. It's a light wrapper around the `useDocument` hook, but provides the `skip` option a document\n * is not fetched, however, it does fetch the schemas & components if they do not already exist in the cache.\n *\n * If the fetch fails, it will display a notification to the user.\n *\n * @example\n * ```tsx\n * const { model } = useParams<{ model: string }>();\n * const { edit: { schema: layout } } = useDocumentLayout(model);\n *\n * return layout.map(panel => panel.map(row => row.map(field => <Field.Root {...field} />)))\n * ```\n *\n */\nconst useDocumentLayout: UseDocumentLayout = (model) => {\n const { schema, components } = useDocument({ model, collectionType: '' }, { skip: true });\n const [{ query }] = useQueryParams();\n const runHookWaterfall = useStrapiApp('useDocumentLayout', (state) => state.runHookWaterfall);\n const { toggleNotification } = useNotification();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();\n\n const { data, isLoading: isLoadingConfigs, error } = useGetContentTypeConfigurationQuery(model);\n\n const isLoading = isLoadingSchemas || isLoadingConfigs;\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [error, formatAPIError, toggleNotification]);\n\n const editLayout = React.useMemo(\n () =>\n data && !isLoading\n ? formatEditLayout(data, { schemas, schema, components })\n : ({\n layout: [],\n components: {},\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as EditLayout),\n [data, isLoading, schemas, schema, components]\n );\n\n const listLayout = React.useMemo(() => {\n return data && !isLoading\n ? formatListLayout(data, { schemas, schema, components })\n : ({\n layout: [],\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as ListLayout);\n }, [data, isLoading, schemas, schema, components]);\n\n const { layout: edit } = React.useMemo(\n () =>\n runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {\n layout: editLayout,\n query,\n }),\n [editLayout, query, runHookWaterfall]\n );\n\n const listViewConversionContext = React.useMemo((): ListViewConversionContext | null => {\n if (!data || isLoading) {\n return null;\n }\n\n return {\n componentConfigurations: data.components,\n componentSchemas: components,\n contentTypeSchemas: schemas,\n };\n }, [data, isLoading, components, schemas]);\n\n return {\n error,\n isLoading,\n edit,\n list: listLayout,\n listViewConversionContext,\n } satisfies ReturnType<UseDocumentLayout>;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDocLayout\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal this hook uses the internal useDoc hook, as such it shouldn't be used outside of the\n * content-manager because it won't work as intended.\n */\nconst useDocLayout = () => {\n const { model } = useDoc();\n return useDocumentLayout(model);\n};\n\n/* -------------------------------------------------------------------------------------------------\n * formatEditLayout\n * -----------------------------------------------------------------------------------------------*/\ntype LayoutData = FindContentTypeConfiguration.Response['data'];\n\n/**\n * @internal\n * @description takes the configuration data, the schema & the components used in the schema and formats the edit view\n * versions of the schema & components. This is then used to render the edit view of the content-type.\n */\nconst formatEditLayout = (\n data: LayoutData,\n {\n schemas,\n schema,\n components,\n }: { schemas: Schema[]; schema?: Schema; components: ComponentsDictionary }\n): EditLayout => {\n let currentPanelIndex = 0;\n /**\n * The fields arranged by the panels, new panels are made for dynamic zones only.\n */\n const panelledEditAttributes = convertEditLayoutToFieldLayouts(\n data.contentType.layouts.edit,\n schema?.attributes,\n data.contentType.metadatas,\n { configurations: data.components, schemas: components },\n schemas\n ).reduce<Array<EditFieldLayout[][]>>((panels, row) => {\n if (row.some((field) => field.type === 'dynamiczone')) {\n panels.push([row]);\n currentPanelIndex += 2;\n } else {\n if (!panels[currentPanelIndex]) {\n panels.push([row]);\n } else {\n panels[currentPanelIndex].push(row);\n }\n }\n\n return panels;\n }, []);\n\n const componentEditAttributes = Object.entries(data.components).reduce<EditLayout['components']>(\n (acc, [uid, configuration]) => {\n acc[uid] = {\n layout: convertEditLayoutToFieldLayouts(\n configuration.layouts.edit,\n components[uid].attributes,\n configuration.metadatas,\n { configurations: data.components, schemas: components }\n ),\n settings: {\n ...configuration.settings,\n icon: components[uid].info.icon,\n displayName: components[uid].info.displayName,\n },\n };\n return acc;\n },\n {}\n );\n\n const editMetadatas = Object.entries(data.contentType.metadatas).reduce<EditLayout['metadatas']>(\n (acc, [attribute, metadata]) => {\n return {\n ...acc,\n [attribute]: metadata.edit,\n };\n },\n {}\n );\n\n return {\n layout: panelledEditAttributes,\n components: componentEditAttributes,\n metadatas: editMetadatas,\n settings: {\n ...data.contentType.settings,\n displayName: schema?.info.displayName,\n },\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n ...data.contentType.options,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * convertEditLayoutToFieldLayouts\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the edit layout from either a content-type or a component\n * and formats it into a generic object that can be used to correctly render\n * the form fields.\n */\nconst convertEditLayoutToFieldLayouts = (\n rows: LayoutData['contentType']['layouts']['edit'],\n attributes: Schema['attributes'] = {},\n metadatas: Metadatas,\n components?: {\n configurations: Record<string, ComponentConfiguration>;\n schemas: ComponentsDictionary;\n },\n schemas: Schema[] = []\n) => {\n return rows.map((row) =>\n row\n .map((field) => {\n const attribute = attributes[field.name];\n\n if (!attribute) {\n return null;\n }\n\n const { edit: metadata } = metadatas[field.name];\n\n const settings: Partial<Settings> =\n attribute.type === 'component' && components\n ? components.configurations[attribute.component].settings\n : {};\n\n return {\n attribute,\n disabled: !metadata.editable,\n hint: metadata.description,\n label: metadata.label ?? '',\n name: field.name,\n // @ts-expect-error – mainField does exist on the metadata for a relation.\n mainField: getMainField(attribute, metadata.mainField || settings.mainField, {\n schemas,\n components: components?.schemas ?? {},\n }),\n placeholder: metadata.placeholder ?? '',\n required: attribute.required ?? false,\n size: field.size,\n unique: 'unique' in attribute ? attribute.unique : false,\n visible: metadata.visible ?? true,\n type: attribute.type,\n };\n })\n .filter((field) => field !== null)\n ) as EditFieldLayout[][];\n};\n\n/* -------------------------------------------------------------------------------------------------\n * formatListLayout\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the complete configuration data, the schema & the components used in the schema and\n * formats a list view layout for the content-type. This is much simpler than the edit view layout as there\n * are less options to consider.\n */\nconst formatListLayout = (\n data: LayoutData,\n {\n schemas,\n schema,\n components,\n }: { schemas: Schema[]; schema?: Schema; components: ComponentsDictionary }\n): ListLayout => {\n const listMetadatas = Object.entries(data.contentType.metadatas).reduce<ListLayout['metadatas']>(\n (acc, [attribute, metadata]) => {\n return {\n ...acc,\n [attribute]: metadata.list,\n };\n },\n {}\n );\n /**\n * The fields arranged by the panels, new panels are made for dynamic zones only.\n */\n const listAttributes = convertListLayoutToFieldLayouts(\n data.contentType.layouts.list,\n schema?.attributes,\n listMetadatas,\n { configurations: data.components, schemas: components },\n schemas\n );\n\n return {\n layout: listAttributes,\n settings: { ...data.contentType.settings, displayName: schema?.info.displayName },\n metadatas: listMetadatas,\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n ...data.contentType.options,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * convertListLayoutToFieldLayouts\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the columns from the list view configuration and formats them into a generic object\n * combinining metadata and attribute data.\n *\n * @note We do use this to reformat the list of strings when updating the displayed headers for the list view.\n */\nconst convertListLayoutToFieldLayouts = (\n columns: LayoutData['contentType']['layouts']['list'],\n attributes: Schema['attributes'] = {},\n metadatas: ListLayout['metadatas'],\n components?: {\n configurations: Record<string, ComponentConfiguration>;\n schemas: ComponentsDictionary;\n },\n schemas: Schema[] = []\n) => {\n return columns\n .map((name) => {\n const attribute = attributes[name];\n\n if (!attribute) {\n return null;\n }\n\n const metadata = metadatas[name];\n\n const settings: Partial<Settings> =\n attribute.type === 'component' && components\n ? components.configurations[attribute.component].settings\n : {};\n\n return {\n attribute,\n label: metadata.label ?? '',\n mainField: getMainField(attribute, metadata.mainField || settings.mainField, {\n schemas,\n components: components?.schemas ?? {},\n }),\n name: name,\n searchable: metadata.searchable ?? true,\n sortable: metadata.sortable ?? true,\n } satisfies ListFieldLayout;\n })\n .filter((field) => field !== null) as ListFieldLayout[];\n};\n\nexport {\n useDocLayout,\n useDocumentLayout,\n convertListLayoutToFieldLayouts,\n convertEditLayoutToFieldLayouts,\n DEFAULT_SETTINGS,\n};\nexport type { EditLayout, EditFieldLayout, ListLayout, ListFieldLayout, UseDocumentLayout };\n"],"names":["DEFAULT_SETTINGS","bulkable","filterable","searchable","pagination","defaultSortBy","defaultSortOrder","mainField","pageSize","relationOpenMode","useDocumentLayout","model","schema","components","useDocument","collectionType","skip","query","useQueryParams","runHookWaterfall","useStrapiApp","state","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","isLoading","isLoadingSchemas","schemas","useContentTypeSchema","data","isLoadingConfigs","error","useGetContentTypeConfigurationQuery","React","useEffect","type","message","editLayout","useMemo","formatEditLayout","layout","metadatas","options","settings","listLayout","formatListLayout","edit","HOOKS","MUTATE_EDIT_VIEW_LAYOUT","listViewConversionContext","componentConfigurations","componentSchemas","contentTypeSchemas","list","useDocLayout","useDoc","currentPanelIndex","panelledEditAttributes","convertEditLayoutToFieldLayouts","contentType","layouts","attributes","configurations","reduce","panels","row","some","field","push","componentEditAttributes","Object","entries","acc","uid","configuration","icon","info","displayName","editMetadatas","attribute","metadata","pluginOptions","rows","map","name","component","disabled","editable","hint","description","label","getMainField","placeholder","required","size","unique","visible","filter","listMetadatas","listAttributes","convertListLayoutToFieldLayouts","columns","sortable"],"mappings":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AAA,IAAI,CAACL,SAAAA,EAAW;YACd,OAAO,IAAA;AACT,QAAA;QAEA,MAAMC,QAAAA,GAAWvC,SAAS,CAAC2C,IAAAA,CAAK;AAEhC,QAAA,MAAMzC,QAAAA,GACJoC,SAAAA,CAAU5C,IAAI,KAAK,eAAexB,UAAAA,GAC9BA,UAAAA,CAAWmD,cAAc,CAACiB,UAAUM,SAAS,CAAC,CAAC1C,QAAQ,GACvD,EAAC;QAEP,OAAO;AACLoC,YAAAA,SAAAA;YACAW,KAAAA,EAAOV,QAAAA,CAASU,KAAK,IAAI,EAAA;AACzBrF,YAAAA,SAAAA,EAAWsF,aAAaZ,SAAAA,EAAWC,QAAAA,CAAS3E,SAAS,IAAIsC,QAAAA,CAAStC,SAAS,EAAE;AAC3EsB,gBAAAA,OAAAA;gBACAhB,UAAAA,EAAYA,UAAAA,EAAYgB,WAAW;AACrC,aAAA,CAAA;YACAyD,IAAAA,EAAMA,IAAAA;YACNnF,UAAAA,EAAY+E,QAAAA,CAAS/E,UAAU,IAAI,IAAA;YACnCqG,QAAAA,EAAUtB,QAAAA,CAASsB,QAAQ,IAAI;AACjC,SAAA;AACF,IAAA,CAAA,CAAA,CACCL,MAAM,CAAC,CAAC9B,KAAAA,GAAUA,KAAAA,KAAU,IAAA,CAAA;AACjC;;;;"}
|
|
@@ -27,6 +27,7 @@ const usePersistentPartialQueryParams = (config)=>{
|
|
|
27
27
|
const scope = strapiAdmin.usePersistentStateScope();
|
|
28
28
|
const [{ query }, setQuery] = strapiAdmin.useQueryParams();
|
|
29
29
|
const clonedConfig = JSON.stringify(config);
|
|
30
|
+
const [isHydrated, setIsHydrated] = React.useState(false);
|
|
30
31
|
// load query params from local storge
|
|
31
32
|
React.useEffect(()=>{
|
|
32
33
|
const mergedFilteredQuery = {};
|
|
@@ -44,11 +45,13 @@ const usePersistentPartialQueryParams = (config)=>{
|
|
|
44
45
|
const filteredQuery = filterObjectKeys(parsedSavedParams, paths);
|
|
45
46
|
Object.assign(mergedFilteredQuery, filteredQuery);
|
|
46
47
|
}
|
|
47
|
-
if (Object.keys(mergedFilteredQuery).length
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
if (Object.keys(mergedFilteredQuery).length > 0) {
|
|
49
|
+
setQuery({
|
|
50
|
+
...mergedFilteredQuery,
|
|
51
|
+
...query
|
|
52
|
+
}, 'push', true);
|
|
53
|
+
}
|
|
54
|
+
setIsHydrated(true);
|
|
52
55
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
53
56
|
}, [
|
|
54
57
|
clonedConfig,
|
|
@@ -68,6 +71,9 @@ const usePersistentPartialQueryParams = (config)=>{
|
|
|
68
71
|
clonedConfig,
|
|
69
72
|
scope
|
|
70
73
|
]);
|
|
74
|
+
return {
|
|
75
|
+
isHydrated
|
|
76
|
+
};
|
|
71
77
|
};
|
|
72
78
|
|
|
73
79
|
exports.usePersistentPartialQueryParams = usePersistentPartialQueryParams;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePersistentQueryParams.js","sources":["../../../admin/src/hooks/usePersistentQueryParams.ts"],"sourcesContent":["import { useEffect } from 'react';\n\nimport { usePersistentStateScope, useQueryParams } from '@strapi/admin/strapi-admin';\nimport get from 'lodash/get';\nimport set from 'lodash/set';\n\ntype PropertyPath = Parameters<typeof get>[1];\n\ninterface PersistentQueryConfigEntry {\n paths: PropertyPath[];\n scoped?: boolean;\n}\n\nconst filterObjectKeys = (obj: object, keys: PropertyPath[]) => {\n const result: Record<string, unknown> = {};\n\n for (const path of keys) {\n const value = get(obj, path);\n\n if (value !== undefined) {\n set(result, path, value);\n }\n }\n\n return result;\n};\n\nexport type PersistentQueryConfig = Record<string, PersistentQueryConfigEntry>;\n\nconst normalizeConfigEntry = (\n key: string,\n entry: PersistentQueryConfigEntry,\n scope: string | false | undefined\n) => {\n const { paths } = entry;\n const isScoped = entry.scoped === true && !!scope;\n\n return {\n key: isScoped ? `${key}:${scope}` : key,\n paths,\n };\n};\n\nexport const usePersistentPartialQueryParams = (config: PersistentQueryConfig) => {\n const scope = usePersistentStateScope();\n const [{ query }, setQuery] = useQueryParams();\n const clonedConfig = JSON.stringify(config);\n\n // load query params from local storge\n useEffect(() => {\n const mergedFilteredQuery: Record<string, unknown> = {};\n\n for (const [keyPrefix, entry] of Object.entries(config)) {\n const { key, paths } = normalizeConfigEntry(keyPrefix, entry, scope);\n\n const savedQueryParams = window.localStorage.getItem(key);\n if (!savedQueryParams) continue;\n\n let parsedSavedParams: Record<string, unknown>;\n try {\n parsedSavedParams = JSON.parse(savedQueryParams);\n } catch {\n continue;\n }\n if (Object.keys(parsedSavedParams).length === 0) continue;\n\n const filteredQuery = filterObjectKeys(parsedSavedParams, paths);\n Object.assign(mergedFilteredQuery, filteredQuery);\n }\n\n if (Object.keys(mergedFilteredQuery).length
|
|
1
|
+
{"version":3,"file":"usePersistentQueryParams.js","sources":["../../../admin/src/hooks/usePersistentQueryParams.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { usePersistentStateScope, useQueryParams } from '@strapi/admin/strapi-admin';\nimport get from 'lodash/get';\nimport set from 'lodash/set';\n\ntype PropertyPath = Parameters<typeof get>[1];\n\ninterface PersistentQueryConfigEntry {\n paths: PropertyPath[];\n scoped?: boolean;\n}\n\nconst filterObjectKeys = (obj: object, keys: PropertyPath[]) => {\n const result: Record<string, unknown> = {};\n\n for (const path of keys) {\n const value = get(obj, path);\n\n if (value !== undefined) {\n set(result, path, value);\n }\n }\n\n return result;\n};\n\nexport type PersistentQueryConfig = Record<string, PersistentQueryConfigEntry>;\n\nconst normalizeConfigEntry = (\n key: string,\n entry: PersistentQueryConfigEntry,\n scope: string | false | undefined\n) => {\n const { paths } = entry;\n const isScoped = entry.scoped === true && !!scope;\n\n return {\n key: isScoped ? `${key}:${scope}` : key,\n paths,\n };\n};\n\nexport const usePersistentPartialQueryParams = (config: PersistentQueryConfig) => {\n const scope = usePersistentStateScope();\n const [{ query }, setQuery] = useQueryParams();\n const clonedConfig = JSON.stringify(config);\n const [isHydrated, setIsHydrated] = useState(false);\n\n // load query params from local storge\n useEffect(() => {\n const mergedFilteredQuery: Record<string, unknown> = {};\n\n for (const [keyPrefix, entry] of Object.entries(config)) {\n const { key, paths } = normalizeConfigEntry(keyPrefix, entry, scope);\n\n const savedQueryParams = window.localStorage.getItem(key);\n if (!savedQueryParams) continue;\n\n let parsedSavedParams: Record<string, unknown>;\n try {\n parsedSavedParams = JSON.parse(savedQueryParams);\n } catch {\n continue;\n }\n if (Object.keys(parsedSavedParams).length === 0) continue;\n\n const filteredQuery = filterObjectKeys(parsedSavedParams, paths);\n Object.assign(mergedFilteredQuery, filteredQuery);\n }\n\n if (Object.keys(mergedFilteredQuery).length > 0) {\n setQuery({ ...mergedFilteredQuery, ...query }, 'push', true);\n }\n setIsHydrated(true);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [clonedConfig, scope]);\n\n // update local storage\n useEffect(() => {\n for (const [keyPrefix, entry] of Object.entries(config)) {\n const { key, paths } = normalizeConfigEntry(keyPrefix, entry, scope);\n\n const paramsToPersist = filterObjectKeys(query, paths);\n if (Object.keys(paramsToPersist).length === 0) continue;\n window.localStorage.setItem(key, JSON.stringify(paramsToPersist));\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [query, clonedConfig, scope]);\n\n return { isHydrated };\n};\n"],"names":["filterObjectKeys","obj","keys","result","path","value","get","undefined","set","normalizeConfigEntry","key","entry","scope","paths","isScoped","scoped","usePersistentPartialQueryParams","config","usePersistentStateScope","query","setQuery","useQueryParams","clonedConfig","JSON","stringify","isHydrated","setIsHydrated","useState","useEffect","mergedFilteredQuery","keyPrefix","Object","entries","savedQueryParams","window","localStorage","getItem","parsedSavedParams","parse","length","filteredQuery","assign","paramsToPersist","setItem"],"mappings":";;;;;;;AAaA,MAAMA,gBAAAA,GAAmB,CAACC,GAAAA,EAAaC,IAAAA,GAAAA;AACrC,IAAA,MAAMC,SAAkC,EA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AM,KAAK,CAAA,EAAG;AAC/CL,YAAAA,MAAAA,CAAOC,YAAY,CAACQ,OAAO,CAACjC,GAAAA,EAAKa,IAAAA,CAAKC,SAAS,CAACkB,eAAAA,CAAAA,CAAAA;AAClD,QAAA;;IAEF,CAAA,EAAG;AAACvB,QAAAA,KAAAA;AAAOG,QAAAA,YAAAA;AAAcV,QAAAA;AAAM,KAAA,CAAA;IAE/B,OAAO;AAAEa,QAAAA;AAAW,KAAA;AACtB;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
2
|
import { usePersistentStateScope, useQueryParams } from '@strapi/admin/strapi-admin';
|
|
3
3
|
import get from 'lodash/get';
|
|
4
4
|
import set from 'lodash/set';
|
|
@@ -25,6 +25,7 @@ const usePersistentPartialQueryParams = (config)=>{
|
|
|
25
25
|
const scope = usePersistentStateScope();
|
|
26
26
|
const [{ query }, setQuery] = useQueryParams();
|
|
27
27
|
const clonedConfig = JSON.stringify(config);
|
|
28
|
+
const [isHydrated, setIsHydrated] = useState(false);
|
|
28
29
|
// load query params from local storge
|
|
29
30
|
useEffect(()=>{
|
|
30
31
|
const mergedFilteredQuery = {};
|
|
@@ -42,11 +43,13 @@ const usePersistentPartialQueryParams = (config)=>{
|
|
|
42
43
|
const filteredQuery = filterObjectKeys(parsedSavedParams, paths);
|
|
43
44
|
Object.assign(mergedFilteredQuery, filteredQuery);
|
|
44
45
|
}
|
|
45
|
-
if (Object.keys(mergedFilteredQuery).length
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
if (Object.keys(mergedFilteredQuery).length > 0) {
|
|
47
|
+
setQuery({
|
|
48
|
+
...mergedFilteredQuery,
|
|
49
|
+
...query
|
|
50
|
+
}, 'push', true);
|
|
51
|
+
}
|
|
52
|
+
setIsHydrated(true);
|
|
50
53
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
51
54
|
}, [
|
|
52
55
|
clonedConfig,
|
|
@@ -66,6 +69,9 @@ const usePersistentPartialQueryParams = (config)=>{
|
|
|
66
69
|
clonedConfig,
|
|
67
70
|
scope
|
|
68
71
|
]);
|
|
72
|
+
return {
|
|
73
|
+
isHydrated
|
|
74
|
+
};
|
|
69
75
|
};
|
|
70
76
|
|
|
71
77
|
export { usePersistentPartialQueryParams };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePersistentQueryParams.mjs","sources":["../../../admin/src/hooks/usePersistentQueryParams.ts"],"sourcesContent":["import { useEffect } from 'react';\n\nimport { usePersistentStateScope, useQueryParams } from '@strapi/admin/strapi-admin';\nimport get from 'lodash/get';\nimport set from 'lodash/set';\n\ntype PropertyPath = Parameters<typeof get>[1];\n\ninterface PersistentQueryConfigEntry {\n paths: PropertyPath[];\n scoped?: boolean;\n}\n\nconst filterObjectKeys = (obj: object, keys: PropertyPath[]) => {\n const result: Record<string, unknown> = {};\n\n for (const path of keys) {\n const value = get(obj, path);\n\n if (value !== undefined) {\n set(result, path, value);\n }\n }\n\n return result;\n};\n\nexport type PersistentQueryConfig = Record<string, PersistentQueryConfigEntry>;\n\nconst normalizeConfigEntry = (\n key: string,\n entry: PersistentQueryConfigEntry,\n scope: string | false | undefined\n) => {\n const { paths } = entry;\n const isScoped = entry.scoped === true && !!scope;\n\n return {\n key: isScoped ? `${key}:${scope}` : key,\n paths,\n };\n};\n\nexport const usePersistentPartialQueryParams = (config: PersistentQueryConfig) => {\n const scope = usePersistentStateScope();\n const [{ query }, setQuery] = useQueryParams();\n const clonedConfig = JSON.stringify(config);\n\n // load query params from local storge\n useEffect(() => {\n const mergedFilteredQuery: Record<string, unknown> = {};\n\n for (const [keyPrefix, entry] of Object.entries(config)) {\n const { key, paths } = normalizeConfigEntry(keyPrefix, entry, scope);\n\n const savedQueryParams = window.localStorage.getItem(key);\n if (!savedQueryParams) continue;\n\n let parsedSavedParams: Record<string, unknown>;\n try {\n parsedSavedParams = JSON.parse(savedQueryParams);\n } catch {\n continue;\n }\n if (Object.keys(parsedSavedParams).length === 0) continue;\n\n const filteredQuery = filterObjectKeys(parsedSavedParams, paths);\n Object.assign(mergedFilteredQuery, filteredQuery);\n }\n\n if (Object.keys(mergedFilteredQuery).length
|
|
1
|
+
{"version":3,"file":"usePersistentQueryParams.mjs","sources":["../../../admin/src/hooks/usePersistentQueryParams.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { usePersistentStateScope, useQueryParams } from '@strapi/admin/strapi-admin';\nimport get from 'lodash/get';\nimport set from 'lodash/set';\n\ntype PropertyPath = Parameters<typeof get>[1];\n\ninterface PersistentQueryConfigEntry {\n paths: PropertyPath[];\n scoped?: boolean;\n}\n\nconst filterObjectKeys = (obj: object, keys: PropertyPath[]) => {\n const result: Record<string, unknown> = {};\n\n for (const path of keys) {\n const value = get(obj, path);\n\n if (value !== undefined) {\n set(result, path, value);\n }\n }\n\n return result;\n};\n\nexport type PersistentQueryConfig = Record<string, PersistentQueryConfigEntry>;\n\nconst normalizeConfigEntry = (\n key: string,\n entry: PersistentQueryConfigEntry,\n scope: string | false | undefined\n) => {\n const { paths } = entry;\n const isScoped = entry.scoped === true && !!scope;\n\n return {\n key: isScoped ? `${key}:${scope}` : key,\n paths,\n };\n};\n\nexport const usePersistentPartialQueryParams = (config: PersistentQueryConfig) => {\n const scope = usePersistentStateScope();\n const [{ query }, setQuery] = useQueryParams();\n const clonedConfig = JSON.stringify(config);\n const [isHydrated, setIsHydrated] = useState(false);\n\n // load query params from local storge\n useEffect(() => {\n const mergedFilteredQuery: Record<string, unknown> = {};\n\n for (const [keyPrefix, entry] of Object.entries(config)) {\n const { key, paths } = normalizeConfigEntry(keyPrefix, entry, scope);\n\n const savedQueryParams = window.localStorage.getItem(key);\n if (!savedQueryParams) continue;\n\n let parsedSavedParams: Record<string, unknown>;\n try {\n parsedSavedParams = JSON.parse(savedQueryParams);\n } catch {\n continue;\n }\n if (Object.keys(parsedSavedParams).length === 0) continue;\n\n const filteredQuery = filterObjectKeys(parsedSavedParams, paths);\n Object.assign(mergedFilteredQuery, filteredQuery);\n }\n\n if (Object.keys(mergedFilteredQuery).length > 0) {\n setQuery({ ...mergedFilteredQuery, ...query }, 'push', true);\n }\n setIsHydrated(true);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [clonedConfig, scope]);\n\n // update local storage\n useEffect(() => {\n for (const [keyPrefix, entry] of Object.entries(config)) {\n const { key, paths } = normalizeConfigEntry(keyPrefix, entry, scope);\n\n const paramsToPersist = filterObjectKeys(query, paths);\n if (Object.keys(paramsToPersist).length === 0) continue;\n window.localStorage.setItem(key, JSON.stringify(paramsToPersist));\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [query, clonedConfig, scope]);\n\n return { isHydrated };\n};\n"],"names":["filterObjectKeys","obj","keys","result","path","value","get","undefined","set","normalizeConfigEntry","key","entry","scope","paths","isScoped","scoped","usePersistentPartialQueryParams","config","usePersistentStateScope","query","setQuery","useQueryParams","clonedConfig","JSON","stringify","isHydrated","setIsHydrated","useState","useEffect","mergedFilteredQuery","keyPrefix","Object","entries","savedQueryParams","window","localStorage","getItem","parsedSavedParams","parse","length","filteredQuery","assign","paramsToPersist","setItem"],"mappings":";;;;;AAaA,MAAMA,gBAAAA,GAAmB,CAACC,GAAAA,EAAaC,IAAAA,GAAAA;AACrC,IAAA,MAAMC,SAAkC,EAAC;IAEzC,KAAK,MAAMC,QAAQF,IAAAA,CAAM;QACvB,MAAMG,KAAAA,GAAQC,IAAIL,GAAAA,EAAKG,IAAAA,CAAAA;AAEvB,QAAA,IAAIC,UAAUE,SAAAA,EAAW;AACvBC,YAAAA,GAAAA,CAAIL,QAAQC,IAAAA,EAAMC,KAAAA,CAAAA;AACpB,QAAA;AACF,IAAA;IAEA,OAAOF,MAAAA;AACT,CAAA;AAIA,MAAMM,oBAAAA,GAAuB,CAC3BC,GAAAA,EACAC,KAAAA,EACAC,KAAAA,GAAAA;IAEA,MA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
-
{"version":3,"file":"index.js","sources":["../../admin/src/index.ts"],"sourcesContent":["import { CheckCircle, Feather, Pencil, PuzzlePiece } from '@strapi/icons';\n\nimport { PLUGIN_ID } from './constants/plugin';\nimport { ContentManagerPlugin } from './content-manager';\nimport { historyAdmin } from './history';\nimport { reducer } from './modules/reducers';\nimport { previewAdmin } from './preview';\nimport { routes } from './router';\nimport { prefixPluginTranslations } from './utils/translations';\n\nimport type { WidgetArgs } from '@strapi/admin/strapi-admin';\n\n// NOTE: we have to preload it to ensure chunks will have it available as global\nimport 'prismjs';\n\n// eslint-disable-next-line import/no-default-export\nexport default {\n register(app: any) {\n const cm = new ContentManagerPlugin();\n\n app.addReducers({\n [PLUGIN_ID]: reducer,\n });\n\n app.addMenuLink({\n to: PLUGIN_ID,\n icon: Feather,\n intlLabel: {\n id: `content-manager.plugin.name`,\n defaultMessage: 'Content Manager',\n },\n permissions: [],\n position: 1,\n });\n\n app.router.addRoute({\n path: 'content-manager/*',\n lazy: async () => {\n const { Layout } = await import('./layout');\n\n return {\n Component: Layout,\n };\n },\n children: routes,\n });\n\n app.registerPlugin(cm.config);\n\n app.widgets.register((widgets: WidgetArgs[]) => {\n const lastEditedWidget: WidgetArgs = {\n icon: Pencil,\n title: {\n id: `${PLUGIN_ID}.widget.last-edited.title`,\n defaultMessage: 'Last edited entries',\n },\n component: async () => {\n const { LastEditedWidget } = await import('./components/Widgets');\n return LastEditedWidget;\n },\n pluginId: PLUGIN_ID,\n id: 'last-edited-entries',\n permissions: [{ action: 'plugin::content-manager.explorer.read' }],\n };\n const lastPublishedWidget: WidgetArgs = {\n icon: CheckCircle,\n title: {\n id: `${PLUGIN_ID}.widget.last-published.title`,\n defaultMessage: 'Last published entries',\n },\n component: async () => {\n const { LastPublishedWidget } = await import('./components/Widgets');\n return LastPublishedWidget;\n },\n pluginId: PLUGIN_ID,\n id: 'last-published-entries',\n permissions: [{ action: 'plugin::content-manager.explorer.read' }],\n };\n const entriesWidget: WidgetArgs = {\n icon: PuzzlePiece,\n title: {\n id: `${PLUGIN_ID}.widget.chart-entries.title`,\n defaultMessage: 'Entries',\n },\n component: async () => {\n const { ChartEntriesWidget } = await import('./components/Widgets');\n return ChartEntriesWidget;\n },\n pluginId: PLUGIN_ID,\n id: 'chart-entries',\n permissions: [{ action: 'plugin::content-manager.explorer.read' }],\n };\n\n const profileInfoIndex = widgets.findIndex(\n (widget) => widget.id === 'profile-info' && widget.pluginId === 'admin'\n );\n\n // Insert chart-entries after the profile-info widget\n if (profileInfoIndex !== -1) {\n const newWidgets: WidgetArgs[] = [...widgets];\n newWidgets.splice(profileInfoIndex + 1, 0, entriesWidget);\n return [lastEditedWidget, lastPublishedWidget, ...newWidgets];\n }\n\n // Fallback: add to the end if the target widget aren't found\n return [lastEditedWidget, lastPublishedWidget, ...widgets, entriesWidget];\n });\n },\n bootstrap(app:
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../admin/src/index.ts"],"sourcesContent":["import { CheckCircle, Feather, Pencil, PuzzlePiece } from '@strapi/icons';\n\nimport { PLUGIN_ID } from './constants/plugin';\nimport { ContentManagerPlugin } from './content-manager';\nimport { historyAdmin } from './history';\nimport { reducer } from './modules/reducers';\nimport { previewAdmin } from './preview';\nimport { routes } from './router';\nimport { prefixPluginTranslations } from './utils/translations';\n\nimport type { StrapiApp, WidgetArgs } from '@strapi/admin/strapi-admin';\n\n// NOTE: we have to preload it to ensure chunks will have it available as global\nimport 'prismjs';\n\n// eslint-disable-next-line import/no-default-export\nexport default {\n register(app: any) {\n const cm = new ContentManagerPlugin();\n\n app.addReducers({\n [PLUGIN_ID]: reducer,\n });\n\n app.addMenuLink({\n to: PLUGIN_ID,\n icon: Feather,\n intlLabel: {\n id: `content-manager.plugin.name`,\n defaultMessage: 'Content Manager',\n },\n permissions: [],\n position: 1,\n });\n\n app.router.addRoute({\n path: 'content-manager/*',\n lazy: async () => {\n const { Layout } = await import('./layout');\n\n return {\n Component: Layout,\n };\n },\n children: routes,\n });\n\n app.registerPlugin(cm.config);\n\n app.widgets.register((widgets: WidgetArgs[]) => {\n const lastEditedWidget: WidgetArgs = {\n icon: Pencil,\n title: {\n id: `${PLUGIN_ID}.widget.last-edited.title`,\n defaultMessage: 'Last edited entries',\n },\n component: async () => {\n const { LastEditedWidget } = await import('./components/Widgets');\n return LastEditedWidget;\n },\n pluginId: PLUGIN_ID,\n id: 'last-edited-entries',\n permissions: [{ action: 'plugin::content-manager.explorer.read' }],\n };\n const lastPublishedWidget: WidgetArgs = {\n icon: CheckCircle,\n title: {\n id: `${PLUGIN_ID}.widget.last-published.title`,\n defaultMessage: 'Last published entries',\n },\n component: async () => {\n const { LastPublishedWidget } = await import('./components/Widgets');\n return LastPublishedWidget;\n },\n pluginId: PLUGIN_ID,\n id: 'last-published-entries',\n permissions: [{ action: 'plugin::content-manager.explorer.read' }],\n };\n const entriesWidget: WidgetArgs = {\n icon: PuzzlePiece,\n title: {\n id: `${PLUGIN_ID}.widget.chart-entries.title`,\n defaultMessage: 'Entries',\n },\n component: async () => {\n const { ChartEntriesWidget } = await import('./components/Widgets');\n return ChartEntriesWidget;\n },\n pluginId: PLUGIN_ID,\n id: 'chart-entries',\n permissions: [{ action: 'plugin::content-manager.explorer.read' }],\n };\n\n const profileInfoIndex = widgets.findIndex(\n (widget) => widget.id === 'profile-info' && widget.pluginId === 'admin'\n );\n\n // Insert chart-entries after the profile-info widget\n if (profileInfoIndex !== -1) {\n const newWidgets: WidgetArgs[] = [...widgets];\n newWidgets.splice(profileInfoIndex + 1, 0, entriesWidget);\n return [lastEditedWidget, lastPublishedWidget, ...newWidgets];\n }\n\n // Fallback: add to the end if the target widget aren't found\n return [lastEditedWidget, lastPublishedWidget, ...widgets, entriesWidget];\n });\n },\n bootstrap(app: StrapiApp) {\n if (typeof historyAdmin.bootstrap === 'function') {\n historyAdmin.bootstrap(app);\n }\n if (typeof previewAdmin.bootstrap === 'function') {\n previewAdmin.bootstrap(app);\n }\n },\n async registerTrads({ locales }: { locales: string[] }) {\n const importedTrads = await Promise.all(\n locales.map((locale) => {\n return import(`./translations/${locale}.json`)\n .then(({ default: data }) => {\n return {\n data: prefixPluginTranslations(data, PLUGIN_ID),\n locale,\n };\n })\n .catch(() => {\n return {\n data: {},\n locale,\n };\n });\n })\n );\n\n return Promise.resolve(importedTrads);\n },\n};\n\nexport * from './exports';\n"],"names":["register","app","cm","ContentManagerPlugin","addReducers","PLUGIN_ID","reducer","addMenuLink","to","icon","Feather","intlLabel","id","defaultMessage","permissions","position","router","addRoute","path","lazy","Layout","Component","children","routes","registerPlugin","config","widgets","lastEditedWidget","Pencil","title","component","LastEditedWidget","pluginId","action","lastPublishedWidget","CheckCircle","LastPublishedWidget","entriesWidget","PuzzlePiece","ChartEntriesWidget","profileInfoIndex","findIndex","widget","newWidgets","splice","bootstrap","historyAdmin","previewAdmin","registerTrads","locales","importedTrads","Promise","all","map","locale","then","default","data","prefixPluginTranslations","catch","resolve"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA;AACA,YAAe;AACbA,IAAAA,QAAAA,CAAAA,CAASC,GAAQ,EAAA;AACf,QAAA,MAAMC,KAAK,IAAIC,mCAAAA,EAAAA;AAEfF,QAAAA,GAAAA,CAAIG,WAAW,CAAC;AACd,YAAA,CAACC,mBAAYC;AACf,SAAA,CAAA;AAEAL,QAAAA,GAAAA,CAAIM,WAAW,CAAC;YACdC,EAAAA,EAAIH,gBAAAA;YACJI,IAAAA,EAAMC,aAAAA;YACNC,SAAAA,EAAW;gBACTC,EAAAA,EAAI,CAAC,2BAA2B,CAAC;gBACjCC,cAAAA,EAAgB;AAClB,aAAA;AACAC,YAAAA,WAAAA,EAAa,EAAE;YACfC,QAAAA,EAAU;AACZ,SAAA,CAAA;QAEAd,GAAAA,CAAIe,MAAM,CAACC,QAAQ,CAAC;YAClBC,IAAAA,EAAM,mBAAA;YACNC,IAAAA,EAAM,UAAA;AACJ,gBAAA,MAAM,EA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CAAaD,SAAS,KAAK,UAAA,EAAY;AAChDC,YAAAA,oBAAAA,CAAaD,SAAS,CAAC5C,GAAAA,CAAAA;AACzB,QAAA;AACA,QAAA,IAAI,OAAO8C,oBAAAA,CAAaF,SAAS,KAAK,UAAA,EAAY;AAChDE,YAAAA,oBAAAA,CAAaF,SAAS,CAAC5C,GAAAA,CAAAA;AACzB,QAAA;AACF,IAAA,CAAA;IACA,MAAM+C,aAAAA,CAAAA,CAAc,EAAEC,OAAO,EAAyB,EAAA;QACpD,MAAMC,aAAAA,GAAgB,MAAMC,OAAAA,CAAQC,GAAG,CACrCH,OAAAA,CAAQI,GAAG,CAAC,CAACC,MAAAA,GAAAA;AACX,YAAA,OAAO,iCAAM,CAAC,CAAC,eAAe,EAAEA,MAAAA,CAAO,KAAK,CAAC,CAAA,CAC1CC,IAAI,CAAC,CAAC,EAAEC,OAAAA,EAASC,IAAI,EAAE,GAAA;gBACtB,OAAO;AACLA,oBAAAA,IAAAA,EAAMC,sCAAyBD,IAAAA,EAAMpD,gBAAAA,CAAAA;AACrCiD,oBAAAA;AACF,iBAAA;AACF,YAAA,CAAA,CAAA,CACCK,KAAK,CAAC,IAAA;gBACL,OAAO;AACLF,oBAAAA,IAAAA,EAAM,EAAC;AACPH,oBAAAA;AACF,iBAAA;AACF,YAAA,CAAA,CAAA;AACJ,QAAA,CAAA,CAAA,CAAA;QAGF,OAAOH,OAAAA,CAAQS,OAAO,CAACV,aAAAA,CAAAA;AACzB,IAAA;AACF,CAAA;;;;;;;;;;;;;"}
|
package/dist/admin/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../admin/src/index.ts"],"sourcesContent":["import { CheckCircle, Feather, Pencil, PuzzlePiece } from '@strapi/icons';\n\nimport { PLUGIN_ID } from './constants/plugin';\nimport { ContentManagerPlugin } from './content-manager';\nimport { historyAdmin } from './history';\nimport { reducer } from './modules/reducers';\nimport { previewAdmin } from './preview';\nimport { routes } from './router';\nimport { prefixPluginTranslations } from './utils/translations';\n\nimport type { WidgetArgs } from '@strapi/admin/strapi-admin';\n\n// NOTE: we have to preload it to ensure chunks will have it available as global\nimport 'prismjs';\n\n// eslint-disable-next-line import/no-default-export\nexport default {\n register(app: any) {\n const cm = new ContentManagerPlugin();\n\n app.addReducers({\n [PLUGIN_ID]: reducer,\n });\n\n app.addMenuLink({\n to: PLUGIN_ID,\n icon: Feather,\n intlLabel: {\n id: `content-manager.plugin.name`,\n defaultMessage: 'Content Manager',\n },\n permissions: [],\n position: 1,\n });\n\n app.router.addRoute({\n path: 'content-manager/*',\n lazy: async () => {\n const { Layout } = await import('./layout');\n\n return {\n Component: Layout,\n };\n },\n children: routes,\n });\n\n app.registerPlugin(cm.config);\n\n app.widgets.register((widgets: WidgetArgs[]) => {\n const lastEditedWidget: WidgetArgs = {\n icon: Pencil,\n title: {\n id: `${PLUGIN_ID}.widget.last-edited.title`,\n defaultMessage: 'Last edited entries',\n },\n component: async () => {\n const { LastEditedWidget } = await import('./components/Widgets');\n return LastEditedWidget;\n },\n pluginId: PLUGIN_ID,\n id: 'last-edited-entries',\n permissions: [{ action: 'plugin::content-manager.explorer.read' }],\n };\n const lastPublishedWidget: WidgetArgs = {\n icon: CheckCircle,\n title: {\n id: `${PLUGIN_ID}.widget.last-published.title`,\n defaultMessage: 'Last published entries',\n },\n component: async () => {\n const { LastPublishedWidget } = await import('./components/Widgets');\n return LastPublishedWidget;\n },\n pluginId: PLUGIN_ID,\n id: 'last-published-entries',\n permissions: [{ action: 'plugin::content-manager.explorer.read' }],\n };\n const entriesWidget: WidgetArgs = {\n icon: PuzzlePiece,\n title: {\n id: `${PLUGIN_ID}.widget.chart-entries.title`,\n defaultMessage: 'Entries',\n },\n component: async () => {\n const { ChartEntriesWidget } = await import('./components/Widgets');\n return ChartEntriesWidget;\n },\n pluginId: PLUGIN_ID,\n id: 'chart-entries',\n permissions: [{ action: 'plugin::content-manager.explorer.read' }],\n };\n\n const profileInfoIndex = widgets.findIndex(\n (widget) => widget.id === 'profile-info' && widget.pluginId === 'admin'\n );\n\n // Insert chart-entries after the profile-info widget\n if (profileInfoIndex !== -1) {\n const newWidgets: WidgetArgs[] = [...widgets];\n newWidgets.splice(profileInfoIndex + 1, 0, entriesWidget);\n return [lastEditedWidget, lastPublishedWidget, ...newWidgets];\n }\n\n // Fallback: add to the end if the target widget aren't found\n return [lastEditedWidget, lastPublishedWidget, ...widgets, entriesWidget];\n });\n },\n bootstrap(app:
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../admin/src/index.ts"],"sourcesContent":["import { CheckCircle, Feather, Pencil, PuzzlePiece } from '@strapi/icons';\n\nimport { PLUGIN_ID } from './constants/plugin';\nimport { ContentManagerPlugin } from './content-manager';\nimport { historyAdmin } from './history';\nimport { reducer } from './modules/reducers';\nimport { previewAdmin } from './preview';\nimport { routes } from './router';\nimport { prefixPluginTranslations } from './utils/translations';\n\nimport type { StrapiApp, WidgetArgs } from '@strapi/admin/strapi-admin';\n\n// NOTE: we have to preload it to ensure chunks will have it available as global\nimport 'prismjs';\n\n// eslint-disable-next-line import/no-default-export\nexport default {\n register(app: any) {\n const cm = new ContentManagerPlugin();\n\n app.addReducers({\n [PLUGIN_ID]: reducer,\n });\n\n app.addMenuLink({\n to: PLUGIN_ID,\n icon: Feather,\n intlLabel: {\n id: `content-manager.plugin.name`,\n defaultMessage: 'Content Manager',\n },\n permissions: [],\n position: 1,\n });\n\n app.router.addRoute({\n path: 'content-manager/*',\n lazy: async () => {\n const { Layout } = await import('./layout');\n\n return {\n Component: Layout,\n };\n },\n children: routes,\n });\n\n app.registerPlugin(cm.config);\n\n app.widgets.register((widgets: WidgetArgs[]) => {\n const lastEditedWidget: WidgetArgs = {\n icon: Pencil,\n title: {\n id: `${PLUGIN_ID}.widget.last-edited.title`,\n defaultMessage: 'Last edited entries',\n },\n component: async () => {\n const { LastEditedWidget } = await import('./components/Widgets');\n return LastEditedWidget;\n },\n pluginId: PLUGIN_ID,\n id: 'last-edited-entries',\n permissions: [{ action: 'plugin::content-manager.explorer.read' }],\n };\n const lastPublishedWidget: WidgetArgs = {\n icon: CheckCircle,\n title: {\n id: `${PLUGIN_ID}.widget.last-published.title`,\n defaultMessage: 'Last published entries',\n },\n component: async () => {\n const { LastPublishedWidget } = await import('./components/Widgets');\n return LastPublishedWidget;\n },\n pluginId: PLUGIN_ID,\n id: 'last-published-entries',\n permissions: [{ action: 'plugin::content-manager.explorer.read' }],\n };\n const entriesWidget: WidgetArgs = {\n icon: PuzzlePiece,\n title: {\n id: `${PLUGIN_ID}.widget.chart-entries.title`,\n defaultMessage: 'Entries',\n },\n component: async () => {\n const { ChartEntriesWidget } = await import('./components/Widgets');\n return ChartEntriesWidget;\n },\n pluginId: PLUGIN_ID,\n id: 'chart-entries',\n permissions: [{ action: 'plugin::content-manager.explorer.read' }],\n };\n\n const profileInfoIndex = widgets.findIndex(\n (widget) => widget.id === 'profile-info' && widget.pluginId === 'admin'\n );\n\n // Insert chart-entries after the profile-info widget\n if (profileInfoIndex !== -1) {\n const newWidgets: WidgetArgs[] = [...widgets];\n newWidgets.splice(profileInfoIndex + 1, 0, entriesWidget);\n return [lastEditedWidget, lastPublishedWidget, ...newWidgets];\n }\n\n // Fallback: add to the end if the target widget aren't found\n return [lastEditedWidget, lastPublishedWidget, ...widgets, entriesWidget];\n });\n },\n bootstrap(app: StrapiApp) {\n if (typeof historyAdmin.bootstrap === 'function') {\n historyAdmin.bootstrap(app);\n }\n if (typeof previewAdmin.bootstrap === 'function') {\n previewAdmin.bootstrap(app);\n }\n },\n async registerTrads({ locales }: { locales: string[] }) {\n const importedTrads = await Promise.all(\n locales.map((locale) => {\n return import(`./translations/${locale}.json`)\n .then(({ default: data }) => {\n return {\n data: prefixPluginTranslations(data, PLUGIN_ID),\n locale,\n };\n })\n .catch(() => {\n return {\n data: {},\n locale,\n };\n });\n })\n );\n\n return Promise.resolve(importedTrads);\n },\n};\n\nexport * from './exports';\n"],"names":["register","app","cm","ContentManagerPlugin","addReducers","PLUGIN_ID","reducer","addMenuLink","to","icon","Feather","intlLabel","id","defaultMessage","permissions","position","router","addRoute","path","lazy","Layout","Component","children","routes","registerPlugin","config","widgets","lastEditedWidget","Pencil","title","component","LastEditedWidget","pluginId","action","lastPublishedWidget","CheckCircle","LastPublishedWidget","entriesWidget","PuzzlePiece","ChartEntriesWidget","profileInfoIndex","findIndex","widget","newWidgets","splice","bootstrap","historyAdmin","previewAdmin","registerTrads","locales","importedTrads","Promise","all","map","locale","then","default","data","prefixPluginTranslations","catch","resolve"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA;AACA,YAAe;AACbA,IAAAA,QAAAA,CAAAA,CAASC,GAAQ,EAAA;AACf,QAAA,MAAMC,KAAK,IAAIC,oBAAAA,EAAAA;AAEfF,QAAAA,GAAAA,CAAIG,WAAW,CAAC;AACd,YAAA,CAACC,YAAYC;AACf,SAAA,CAAA;AAEAL,QAAAA,GAAAA,CAAIM,WAAW,CAAC;YACdC,EAAAA,EAAIH,SAAAA;YACJI,IAAAA,EAAMC,OAAAA;YACNC,SAAAA,EAAW;gBACTC,EAAAA,EAAI,CAAC,2BAA2B,CAAC;gBACjCC,cAAAA,EAAgB;AAClB,aAAA;AACAC,YAAAA,WAAAA,EAAa,EAAE;YACfC,QAAAA,EAAU;AACZ,SAAA,CAAA;QAEAd,GAAAA,CAAIe,MAAM,CAACC,QAAQ,CAAC;YAClBC,IAAAA,EAAM,mBAAA;YACNC,IAAAA,EAAM,UAAA;AACJ,gBAAA,MAAM,EAAEC,MAAM,EAAE,GAAG,MAAM,OAAO,cAAA,CAAA;gBAEhC,OAAO;oBACLC,SAAAA,EAAWD;AACb,iBAAA;AACF,YAAA,CAAA;YACAE,QAAAA,EAAUC;AACZ,SAAA,CAAA;QAEAtB,GAAAA,CAAIuB,cAAc,CAACtB,EAAAA,CAAGuB,MAAM,CAAA;AAE5BxB,QAA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,CAAA;IACA,MAAM+C,aAAAA,CAAAA,CAAc,EAAEC,OAAO,EAAyB,EAAA;QACpD,MAAMC,aAAAA,GAAgB,MAAMC,OAAAA,CAAQC,GAAG,CACrCH,OAAAA,CAAQI,GAAG,CAAC,CAACC,MAAAA,GAAAA;AACX,YAAA,OAAO,iCAAM,CAAC,CAAC,eAAe,EAAEA,MAAAA,CAAO,KAAK,CAAC,CAAA,CAC1CC,IAAI,CAAC,CAAC,EAAEC,OAAAA,EAASC,IAAI,EAAE,GAAA;gBACtB,OAAO;AACLA,oBAAAA,IAAAA,EAAMC,yBAAyBD,IAAAA,EAAMpD,SAAAA,CAAAA;AACrCiD,oBAAAA;AACF,iBAAA;AACF,YAAA,CAAA,CAAA,CACCK,KAAK,CAAC,IAAA;gBACL,OAAO;AACLF,oBAAAA,IAAAA,EAAM,EAAC;AACPH,oBAAAA;AACF,iBAAA;AACF,YAAA,CAAA,CAAA;AACJ,QAAA,CAAA,CAAA,CAAA;QAGF,OAAOH,OAAAA,CAAQS,OAAO,CAACV,aAAAA,CAAAA;AACzB,IAAA;AACF,CAAA;;;;"}
|
|
@@ -64,8 +64,10 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
64
64
|
scoped: false
|
|
65
65
|
}
|
|
66
66
|
}), []);
|
|
67
|
-
usePersistentQueryParams.usePersistentPartialQueryParams(persistentQueryConfigs);
|
|
68
|
-
const doc = useDocument.useDoc(
|
|
67
|
+
const { isHydrated } = usePersistentQueryParams.usePersistentPartialQueryParams(persistentQueryConfigs);
|
|
68
|
+
const doc = useDocument.useDoc({
|
|
69
|
+
skip: !isHydrated
|
|
70
|
+
});
|
|
69
71
|
const { document, meta, isLoading: isLoadingDocument, schema, components, collectionType, id, model, hasError, getTitle, getInitialFormValues } = doc;
|
|
70
72
|
const hasDraftAndPublished = schema?.options?.draftAndPublish ?? false;
|
|
71
73
|
useOnce.useOnce(()=>{
|
|
@@ -91,7 +93,7 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
91
93
|
const { isLoading: isLoadingLayout, edit: { layout, settings: { mainField } } } = useDocumentLayout.useDocumentLayout(model);
|
|
92
94
|
const pageTitle = getTitle(mainField);
|
|
93
95
|
const { isLazyLoading } = useLazyComponents.useLazyComponents([]);
|
|
94
|
-
const isLoading = isLoadingActionsRBAC || isLoadingDocument || isLoadingLayout || isLazyLoading;
|
|
96
|
+
const isLoading = !isHydrated || isLoadingActionsRBAC || isLoadingDocument || isLoadingLayout || isLazyLoading;
|
|
95
97
|
const initialValues = getInitialFormValues(isCreatingDocument);
|
|
96
98
|
if (isLoading && !document?.documentId) {
|
|
97
99
|
return /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Page.Loading, {});
|