@strapi/content-manager 5.45.0 → 5.45.1

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.
@@ -104,7 +104,10 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
104
104
  ...new Set(componentUids)
105
105
  ];
106
106
  const componentsByKey = uniqueComponentUids.reduce((acc, uid)=>{
107
- acc[uid] = allComponents[uid];
107
+ const component = allComponents[uid];
108
+ if (component) {
109
+ acc[uid] = component;
110
+ }
108
111
  return acc;
109
112
  }, {});
110
113
  return componentsByKey;
@@ -1 +1 @@
1
- {"version":3,"file":"useContentTypeSchema.js","sources":["../../../admin/src/hooks/useContentTypeSchema.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { useNotification, useAPIErrorHandler } from '@strapi/admin/strapi-admin';\n\nimport { useGetInitialDataQuery } from '../services/init';\n\nimport type { Component } from '../../../shared/contracts/components';\nimport type { ContentType } from '../../../shared/contracts/content-types';\nimport type { Schema } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * useContentTypeSchema\n * -----------------------------------------------------------------------------------------------*/\ntype ComponentsDictionary = Record<string, Component>;\n\n/**\n * @internal\n * @description Given a model UID, return the schema and the schemas\n * of the associated components within said model's schema. A wrapper\n * implementation around the `useGetInitialDataQuery` with a unique\n * `selectFromResult` function to memoize the calculation.\n *\n * If no model is provided, the hook will return all the schemas.\n */\nconst useContentTypeSchema = (model?: string) => {\n const { toggleNotification } = useNotification();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n\n const { data, error, isLoading, isFetching } = useGetInitialDataQuery(undefined);\n\n const { components, contentType, contentTypes } = React.useMemo(() => {\n const contentType = data?.contentTypes.find((ct) => ct.uid === model);\n\n const componentsByKey = data?.components.reduce<ComponentsDictionary>((acc, component) => {\n acc[component.uid] = component;\n\n return acc;\n }, {});\n\n const components = extractContentTypeComponents(contentType?.attributes, componentsByKey);\n\n return {\n components: Object.keys(components).length === 0 ? undefined : components,\n contentType,\n contentTypes: data?.contentTypes ?? [],\n };\n }, [model, data]);\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [toggleNotification, error, formatAPIError]);\n\n return {\n // This must be memoized to avoid inifiinite re-renders where the empty object is different everytime.\n components: React.useMemo(() => components ?? {}, [components]),\n schema: contentType,\n schemas: contentTypes,\n isLoading: isLoading || isFetching,\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * extractContentTypeComponents\n * -----------------------------------------------------------------------------------------------*/\n/**\n * @internal\n * @description Extracts the components used in a content type's attributes recursively.\n */\nconst extractContentTypeComponents = (\n attributes: ContentType['attributes'] = {},\n allComponents: ComponentsDictionary = {}\n): ComponentsDictionary => {\n const getComponents = (attributes: Schema.Attribute.AnyAttribute[]) => {\n return attributes.reduce<string[]>((acc, attribute) => {\n /**\n * If the attribute is a component or dynamiczone, we need to recursively\n * extract the component UIDs from its attributes.\n */\n if (attribute.type === 'component') {\n const componentAttributes = Object.values(\n allComponents[attribute.component]?.attributes ?? {}\n );\n\n acc.push(attribute.component, ...getComponents(componentAttributes));\n } else if (attribute.type === 'dynamiczone') {\n acc.push(\n ...attribute.components,\n /**\n * Dynamic zones have an array of components, so we flatMap over them\n * performing the same search as above.\n */\n ...attribute.components.flatMap((componentUid) => {\n const componentAttributes = Object.values(\n allComponents[componentUid]?.attributes ?? {}\n );\n\n return getComponents(componentAttributes);\n })\n );\n }\n\n return acc;\n }, []);\n };\n\n const componentUids = getComponents(Object.values(attributes));\n\n const uniqueComponentUids = [...new Set(componentUids)];\n\n const componentsByKey = uniqueComponentUids.reduce<ComponentsDictionary>((acc, uid) => {\n acc[uid] = allComponents[uid];\n\n return acc;\n }, {});\n\n return componentsByKey;\n};\n\nexport { useContentTypeSchema, extractContentTypeComponents };\nexport type { ComponentsDictionary };\n"],"names":["useContentTypeSchema","model","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","data","error","isLoading","isFetching","useGetInitialDataQuery","undefined","components","contentType","contentTypes","React","useMemo","find","ct","uid","componentsByKey","reduce","acc","component","extractContentTypeComponents","attributes","Object","keys","length","useEffect","type","message","schema","schemas","allComponents","getComponents","attribute","componentAttributes","values","push","flatMap","componentUid","componentUids","uniqueComponentUids","Set"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAeA;;;;;;;;IASA,MAAMA,uBAAuB,CAACC,KAAAA,GAAAA;IAC5B,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,2BAAAA,EAAAA;AAC/B,IAAA,MAAM,EAAEC,uBAAAA,EAAyBC,cAAc,EAAE,GAAGC,8BAAAA,EAAAA;IAEpD,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAEC,SAAS,EAAEC,UAAU,EAAE,GAAGC,2BAAAA,CAAuBC,SAAAA,CAAAA;IAEtE,MAAM,EAAEC,UAAU,EAAEC,WAAW,EAAEC,YAAY,EAAE,GAAGC,gBAAAA,CAAMC,OAAO,CAAC,IAAA;QAC9D,MAAMH,WAAAA,GAAcP,MAAMQ,YAAAA,CAAaG,IAAAA,CAAK,CAACC,EAAAA,GAAOA,EAAAA,CAAGC,GAAG,KAAKnB,KAAAA,CAAAA;AAE/D,QAAA,MAAMoB,eAAAA,GAAkBd,IAAAA,EAAMM,UAAAA,CAAWS,MAAAA,CAA6B,CAACC,GAAAA,EAAKC,SAAAA,GAAAA;AAC1ED,YAAAA,GAAG,CAACC,SAAAA,CAAUJ,GAAG,CAAC,GAAGI,SAAAA;YAErB,OAAOD,GAAAA;AACT,QAAA,CAAA,EAAG,EAAC,CAAA;QAEJ,MAAMV,UAAAA,GAAaY,4BAAAA,CAA6BX,WAAAA,EAAaY,UAAAA,EAAYL,eAAAA,CAAAA;QAEzE,OAAO;AACLR,YAAAA,UAAAA,EAAYc,OAAOC,IAAI,CAACf,YAAYgB,MAAM,KAAK,IAAIjB,SAAAA,GAAYC,UAAAA;AAC/DC,YAAAA,WAAAA;YAC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AO,IAAID,SAAAA,CAAUN,IAAI,KAAK,aAAA,EAAe;AAC3CR,gBAAAA,GAAAA,CAAIiB,IAAI,CAAA,GACHH,SAAAA,CAAUxB,UAAU;;;AAItB,cAAA,GACEwB,SAAAA,CAAUxB,UAAU,CAAC4B,OAAO,CAAC,CAACC,YAAAA,GAAAA;oBAC/B,MAAMJ,mBAAAA,GAAsBX,OAAOY,MAAM,CACvCJ,aAAa,CAACO,YAAAA,CAAa,EAAEhB,UAAAA,IAAc,EAAC,CAAA;AAG9C,oBAAA,OAAOU,aAAAA,CAAcE,mBAAAA,CAAAA;AACvB,gBAAA,CAAA,CAAA,CAAA;AAEJ,YAAA;YAEA,OAAOf,GAAAA;AACT,QAAA,CAAA,EAAG,EAAE,CAAA;AACP,IAAA,CAAA;AAEA,IAAA,MAAMoB,aAAAA,GAAgBP,aAAAA,CAAcT,MAAAA,CAAOY,MAAM,CAACb,UAAAA,CAAAA,CAAAA;AAElD,IAAA,MAAMkB,mBAAAA,GAAsB;AAAI,QAAA,GAAA,IAAIC,GAAAA,CAAIF,aAAAA;AAAe,KAAA;AAEvD,IAAA,MAAMtB,eAAAA,GAAkBuB,mBAAAA,CAAoBtB,MAAM,CAAuB,CAACC,GAAAA,EAAKH,GAAAA,GAAAA;AAC7EG,QAAAA,GAAG,CAACH,GAAAA,CAAI,GAAGe,aAAa,CAACf,GAAAA,CAAI;QAE7B,OAAOG,GAAAA;AACT,IAAA,CAAA,EAAG,EAAC,CAAA;IAEJ,OAAOF,eAAAA;AACT;;;;;"}
1
+ {"version":3,"file":"useContentTypeSchema.js","sources":["../../../admin/src/hooks/useContentTypeSchema.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { useNotification, useAPIErrorHandler } from '@strapi/admin/strapi-admin';\n\nimport { useGetInitialDataQuery } from '../services/init';\n\nimport type { Component } from '../../../shared/contracts/components';\nimport type { ContentType } from '../../../shared/contracts/content-types';\nimport type { Schema } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * useContentTypeSchema\n * -----------------------------------------------------------------------------------------------*/\ntype ComponentsDictionary = Record<string, Component>;\n\n/**\n * @internal\n * @description Given a model UID, return the schema and the schemas\n * of the associated components within said model's schema. A wrapper\n * implementation around the `useGetInitialDataQuery` with a unique\n * `selectFromResult` function to memoize the calculation.\n *\n * If no model is provided, the hook will return all the schemas.\n */\nconst useContentTypeSchema = (model?: string) => {\n const { toggleNotification } = useNotification();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n\n const { data, error, isLoading, isFetching } = useGetInitialDataQuery(undefined);\n\n const { components, contentType, contentTypes } = React.useMemo(() => {\n const contentType = data?.contentTypes.find((ct) => ct.uid === model);\n\n const componentsByKey = data?.components.reduce<ComponentsDictionary>((acc, component) => {\n acc[component.uid] = component;\n\n return acc;\n }, {});\n\n const components = extractContentTypeComponents(contentType?.attributes, componentsByKey);\n\n return {\n components: Object.keys(components).length === 0 ? undefined : components,\n contentType,\n contentTypes: data?.contentTypes ?? [],\n };\n }, [model, data]);\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [toggleNotification, error, formatAPIError]);\n\n return {\n // This must be memoized to avoid inifiinite re-renders where the empty object is different everytime.\n components: React.useMemo(() => components ?? {}, [components]),\n schema: contentType,\n schemas: contentTypes,\n isLoading: isLoading || isFetching,\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * extractContentTypeComponents\n * -----------------------------------------------------------------------------------------------*/\n/**\n * @internal\n * @description Extracts the components used in a content type's attributes recursively.\n */\nconst extractContentTypeComponents = (\n attributes: ContentType['attributes'] = {},\n allComponents: ComponentsDictionary = {}\n): ComponentsDictionary => {\n const getComponents = (attributes: Schema.Attribute.AnyAttribute[]) => {\n return attributes.reduce<string[]>((acc, attribute) => {\n /**\n * If the attribute is a component or dynamiczone, we need to recursively\n * extract the component UIDs from its attributes.\n */\n if (attribute.type === 'component') {\n const componentAttributes = Object.values(\n allComponents[attribute.component]?.attributes ?? {}\n );\n\n acc.push(attribute.component, ...getComponents(componentAttributes));\n } else if (attribute.type === 'dynamiczone') {\n acc.push(\n ...attribute.components,\n /**\n * Dynamic zones have an array of components, so we flatMap over them\n * performing the same search as above.\n */\n ...attribute.components.flatMap((componentUid) => {\n const componentAttributes = Object.values(\n allComponents[componentUid]?.attributes ?? {}\n );\n\n return getComponents(componentAttributes);\n })\n );\n }\n\n return acc;\n }, []);\n };\n\n const componentUids = getComponents(Object.values(attributes));\n\n const uniqueComponentUids = [...new Set(componentUids)];\n\n const componentsByKey = uniqueComponentUids.reduce<ComponentsDictionary>((acc, uid) => {\n const component = allComponents[uid];\n if (component) {\n acc[uid] = component;\n }\n\n return acc;\n }, {});\n\n return componentsByKey;\n};\n\nexport { useContentTypeSchema, extractContentTypeComponents };\nexport type { ComponentsDictionary };\n"],"names":["useContentTypeSchema","model","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","data","error","isLoading","isFetching","useGetInitialDataQuery","undefined","components","contentType","contentTypes","React","useMemo","find","ct","uid","componentsByKey","reduce","acc","component","extractContentTypeComponents","attributes","Object","keys","length","useEffect","type","message","schema","schemas","allComponents","getComponents","attribute","componentAttributes","values","push","flatMap","componentUid","componentUids","uniqueComponentUids","Set"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAeA;;;;;;;;IASA,MAAMA,uBAAuB,CAACC,KAAAA,GAAAA;IAC5B,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,2BAAAA,EAAAA;AAC/B,IAAA,MAAM,EAAEC,uBAAAA,EAAyBC,cAAc,EAAE,GAAGC,8BAAAA,EAAAA;IAEpD,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAEC,SAAS,EAAEC,UAAU,EAAE,GAAGC,2BAAAA,CAAuBC,SAAAA,CAAAA;IAEtE,MAAM,EAAEC,UAAU,EAAEC,WAAW,EAAEC,YAAY,EAAE,GAAGC,gBAAAA,CAAMC,OAAO,CAAC,IAAA;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A,IAAIC,GAAAA,CAAIF,aAAAA;AAAe,KAAA;AAEvD,IAAA,MAAMtB,eAAAA,GAAkBuB,mBAAAA,CAAoBtB,MAAM,CAAuB,CAACC,GAAAA,EAAKH,GAAAA,GAAAA;QAC7E,MAAMI,SAAAA,GAAYW,aAAa,CAACf,GAAAA,CAAI;AACpC,QAAA,IAAII,SAAAA,EAAW;YACbD,GAAG,CAACH,IAAI,GAAGI,SAAAA;AACb,QAAA;QAEA,OAAOD,GAAAA;AACT,IAAA,CAAA,EAAG,EAAC,CAAA;IAEJ,OAAOF,eAAAA;AACT;;;;;"}
@@ -83,7 +83,10 @@ import { useGetInitialDataQuery } from '../services/init.mjs';
83
83
  ...new Set(componentUids)
84
84
  ];
85
85
  const componentsByKey = uniqueComponentUids.reduce((acc, uid)=>{
86
- acc[uid] = allComponents[uid];
86
+ const component = allComponents[uid];
87
+ if (component) {
88
+ acc[uid] = component;
89
+ }
87
90
  return acc;
88
91
  }, {});
89
92
  return componentsByKey;
@@ -1 +1 @@
1
- {"version":3,"file":"useContentTypeSchema.mjs","sources":["../../../admin/src/hooks/useContentTypeSchema.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { useNotification, useAPIErrorHandler } from '@strapi/admin/strapi-admin';\n\nimport { useGetInitialDataQuery } from '../services/init';\n\nimport type { Component } from '../../../shared/contracts/components';\nimport type { ContentType } from '../../../shared/contracts/content-types';\nimport type { Schema } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * useContentTypeSchema\n * -----------------------------------------------------------------------------------------------*/\ntype ComponentsDictionary = Record<string, Component>;\n\n/**\n * @internal\n * @description Given a model UID, return the schema and the schemas\n * of the associated components within said model's schema. A wrapper\n * implementation around the `useGetInitialDataQuery` with a unique\n * `selectFromResult` function to memoize the calculation.\n *\n * If no model is provided, the hook will return all the schemas.\n */\nconst useContentTypeSchema = (model?: string) => {\n const { toggleNotification } = useNotification();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n\n const { data, error, isLoading, isFetching } = useGetInitialDataQuery(undefined);\n\n const { components, contentType, contentTypes } = React.useMemo(() => {\n const contentType = data?.contentTypes.find((ct) => ct.uid === model);\n\n const componentsByKey = data?.components.reduce<ComponentsDictionary>((acc, component) => {\n acc[component.uid] = component;\n\n return acc;\n }, {});\n\n const components = extractContentTypeComponents(contentType?.attributes, componentsByKey);\n\n return {\n components: Object.keys(components).length === 0 ? undefined : components,\n contentType,\n contentTypes: data?.contentTypes ?? [],\n };\n }, [model, data]);\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [toggleNotification, error, formatAPIError]);\n\n return {\n // This must be memoized to avoid inifiinite re-renders where the empty object is different everytime.\n components: React.useMemo(() => components ?? {}, [components]),\n schema: contentType,\n schemas: contentTypes,\n isLoading: isLoading || isFetching,\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * extractContentTypeComponents\n * -----------------------------------------------------------------------------------------------*/\n/**\n * @internal\n * @description Extracts the components used in a content type's attributes recursively.\n */\nconst extractContentTypeComponents = (\n attributes: ContentType['attributes'] = {},\n allComponents: ComponentsDictionary = {}\n): ComponentsDictionary => {\n const getComponents = (attributes: Schema.Attribute.AnyAttribute[]) => {\n return attributes.reduce<string[]>((acc, attribute) => {\n /**\n * If the attribute is a component or dynamiczone, we need to recursively\n * extract the component UIDs from its attributes.\n */\n if (attribute.type === 'component') {\n const componentAttributes = Object.values(\n allComponents[attribute.component]?.attributes ?? {}\n );\n\n acc.push(attribute.component, ...getComponents(componentAttributes));\n } else if (attribute.type === 'dynamiczone') {\n acc.push(\n ...attribute.components,\n /**\n * Dynamic zones have an array of components, so we flatMap over them\n * performing the same search as above.\n */\n ...attribute.components.flatMap((componentUid) => {\n const componentAttributes = Object.values(\n allComponents[componentUid]?.attributes ?? {}\n );\n\n return getComponents(componentAttributes);\n })\n );\n }\n\n return acc;\n }, []);\n };\n\n const componentUids = getComponents(Object.values(attributes));\n\n const uniqueComponentUids = [...new Set(componentUids)];\n\n const componentsByKey = uniqueComponentUids.reduce<ComponentsDictionary>((acc, uid) => {\n acc[uid] = allComponents[uid];\n\n return acc;\n }, {});\n\n return componentsByKey;\n};\n\nexport { useContentTypeSchema, extractContentTypeComponents };\nexport type { ComponentsDictionary };\n"],"names":["useContentTypeSchema","model","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","data","error","isLoading","isFetching","useGetInitialDataQuery","undefined","components","contentType","contentTypes","React","useMemo","find","ct","uid","componentsByKey","reduce","acc","component","extractContentTypeComponents","attributes","Object","keys","length","useEffect","type","message","schema","schemas","allComponents","getComponents","attribute","componentAttributes","values","push","flatMap","componentUid","componentUids","uniqueComponentUids","Set"],"mappings":";;;;AAeA;;;;;;;;IASA,MAAMA,uBAAuB,CAACC,KAAAA,GAAAA;IAC5B,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,eAAAA,EAAAA;AAC/B,IAAA,MAAM,EAAEC,uBAAAA,EAAyBC,cAAc,EAAE,GAAGC,kBAAAA,EAAAA;IAEpD,MAAM,EAAEC,IAAI,EAAEC,KAAK,EAAEC,SAAS,EAAEC,UAAU,EAAE,GAAGC,sBAAAA,CAAuBC,SAAAA,CAAAA;IAEtE,MAAM,EAAEC,UAAU,EAAEC,WAAW,EAAEC,YAAY,EAAE,GAAGC,KAAAA,CAAMC,OAAO,CAAC,IAAA;QAC9D,MAAMH,WAAAA,GAAcP,MAAMQ,YAAAA,CAAaG,IAAAA,CAAK,CAACC,EAAAA,GAAOA,EAAAA,CAAGC,GAAG,KAAKnB,KAAAA,CAAAA;AAE/D,QAAA,MAAMoB,eAAAA,GAAkBd,IAAAA,EAAMM,UAAAA,CAAWS,MAAAA,CAA6B,CAACC,GAAAA,EAAKC,SAAAA,GAAAA;AAC1ED,YAAAA,GAAG,CAACC,SAAAA,CAAUJ,GAAG,CAAC,GAAGI,SAAAA;YAErB,OAAOD,GAAAA;AACT,QAAA,CAAA,EAAG,EAAC,CA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TypeSchema.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { useNotification, useAPIErrorHandler } from '@strapi/admin/strapi-admin';\n\nimport { useGetInitialDataQuery } from '../services/init';\n\nimport type { Component } from '../../../shared/contracts/components';\nimport type { ContentType } from '../../../shared/contracts/content-types';\nimport type { Schema } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * useContentTypeSchema\n * -----------------------------------------------------------------------------------------------*/\ntype ComponentsDictionary = Record<string, Component>;\n\n/**\n * @internal\n * @description Given a model UID, return the schema and the schemas\n * of the associated components within said model's schema. A wrapper\n * implementation around the `useGetInitialDataQuery` with a unique\n * `selectFromResult` function to memoize the calculation.\n *\n * If no model is provided, the hook will return all the schemas.\n */\nconst useContentTypeSchema = (model?: string) => {\n const { toggleNotification } = useNotification();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n\n const { data, error, isLoading, isFetching } = useGetInitialDataQuery(undefined);\n\n const { components, contentType, contentTypes } = React.useMemo(() => {\n const contentType = data?.contentTypes.find((ct) => ct.uid === model);\n\n const componentsByKey = data?.components.reduce<ComponentsDictionary>((acc, component) => {\n acc[component.uid] = component;\n\n return acc;\n }, {});\n\n const components = extractContentTypeComponents(contentType?.attributes, componentsByKey);\n\n return {\n components: Object.keys(components).length === 0 ? undefined : components,\n contentType,\n contentTypes: data?.contentTypes ?? [],\n };\n }, [model, data]);\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [toggleNotification, error, formatAPIError]);\n\n return {\n // This must be memoized to avoid inifiinite re-renders where the empty object is different everytime.\n components: React.useMemo(() => components ?? {}, [components]),\n schema: contentType,\n schemas: contentTypes,\n isLoading: isLoading || isFetching,\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * extractContentTypeComponents\n * -----------------------------------------------------------------------------------------------*/\n/**\n * @internal\n * @description Extracts the components used in a content type's attributes recursively.\n */\nconst extractContentTypeComponents = (\n attributes: ContentType['attributes'] = {},\n allComponents: ComponentsDictionary = {}\n): ComponentsDictionary => {\n const getComponents = (attributes: Schema.Attribute.AnyAttribute[]) => {\n return attributes.reduce<string[]>((acc, attribute) => {\n /**\n * If the attribute is a component or dynamiczone, we need to recursively\n * extract the component UIDs from its attributes.\n */\n if (attribute.type === 'component') {\n const componentAttributes = Object.values(\n allComponents[attribute.component]?.attributes ?? {}\n );\n\n acc.push(attribute.component, ...getComponents(componentAttributes));\n } else if (attribute.type === 'dynamiczone') {\n acc.push(\n ...attribute.components,\n /**\n * Dynamic zones have an array of components, so we flatMap over them\n * performing the same search as above.\n */\n ...attribute.components.flatMap((componentUid) => {\n const componentAttributes = Object.values(\n allComponents[componentUid]?.attributes ?? {}\n );\n\n return getComponents(componentAttributes);\n })\n );\n }\n\n return acc;\n }, []);\n };\n\n const componentUids = getComponents(Object.values(attributes));\n\n const uniqueComponentUids = [...new Set(componentUids)];\n\n const componentsByKey = uniqueComponentUids.reduce<ComponentsDictionary>((acc, uid) => {\n const component = allComponents[uid];\n if (component) {\n acc[uid] = component;\n }\n\n return acc;\n }, {});\n\n return componentsByKey;\n};\n\nexport { useContentTypeSchema, extractContentTypeComponents };\nexport type { ComponentsDictionary };\n"],"names":["useContentTypeSchema","model","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","data","error","isLoading","isFetching","useGetInitialDataQuery","undefined","components","contentType","contentTypes","React","useMemo","find","ct","uid","componentsByKey","reduce","acc","component","extractContentTypeComponents","attributes","Object","keys","length","useEffect","type","message","schema","schemas","allComponents","getComponents","attribute","componentAttributes","values","push","flatMap","componentUid","componentUids","uniqueComponentUids","Set"],"mappings":";;;;AAeA;;;;;;;;IASA,MAAMA,uBAAuB,CAACC,KAAAA,GAAAA;IAC5B,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,eAAAA,EAAAA;AAC/B,IAAA,MAAM,EAAEC,uBAAAA,EAAyBC,cAAc,EAAE,GAAGC,kBAAAA,EAAAA;IAEpD,MA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QAAA,CAAA,EAAG,EAAE,CAAA;AACP,IAAA,CAAA;AAEA,IAAA,MAAMoB,aAAAA,GAAgBP,aAAAA,CAAcT,MAAAA,CAAOY,MAAM,CAACb,UAAAA,CAAAA,CAAAA;AAElD,IAAA,MAAMkB,mBAAAA,GAAsB;AAAI,QAAA,GAAA,IAAIC,GAAAA,CAAIF,aAAAA;AAAe,KAAA;AAEvD,IAAA,MAAMtB,eAAAA,GAAkBuB,mBAAAA,CAAoBtB,MAAM,CAAuB,CAACC,GAAAA,EAAKH,GAAAA,GAAAA;QAC7E,MAAMI,SAAAA,GAAYW,aAAa,CAACf,GAAAA,CAAI;AACpC,QAAA,IAAII,SAAAA,EAAW;YACbD,GAAG,CAACH,IAAI,GAAGI,SAAAA;AACb,QAAA;QAEA,OAAOD,GAAAA;AACT,IAAA,CAAA,EAAG,EAAC,CAAA;IAEJ,OAAOF,eAAAA;AACT;;;;"}
@@ -69,8 +69,10 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
69
69
  const { toggleNotification } = strapiAdmin.useNotification();
70
70
  const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
71
71
  const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema.useContentTypeSchema();
72
- const { data, isLoading: isLoadingConfigs, error } = contentTypes.useGetContentTypeConfigurationQuery(model);
73
- const isLoading = isLoadingSchemas || isLoadingConfigs;
72
+ const { currentData: data, isLoading: isLoadingConfigs, error } = contentTypes.useGetContentTypeConfigurationQuery(model);
73
+ const isConfigResolvedForModel = data?.contentType?.uid === model;
74
+ const isLoading = isLoadingSchemas || isLoadingConfigs || !error && !isConfigResolvedForModel;
75
+ const stableLayoutsByModelRef = React__namespace.useRef(new Map());
74
76
  React__namespace.useEffect(()=>{
75
77
  if (error) {
76
78
  toggleNotification({
@@ -83,40 +85,62 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
83
85
  formatAPIError,
84
86
  toggleNotification
85
87
  ]);
86
- const editLayout = React__namespace.useMemo(()=>data && !isLoading ? formatEditLayout(data, {
88
+ const resolvedLayouts = React__namespace.useMemo(()=>{
89
+ if (!data || isLoading) {
90
+ return null;
91
+ }
92
+ const edit = formatEditLayout(data, {
93
+ schemas,
94
+ schema,
95
+ components
96
+ });
97
+ const list = formatListLayout(data, {
87
98
  schemas,
88
99
  schema,
89
100
  components
90
- }) : {
101
+ });
102
+ const listViewConversionContext = {
103
+ componentConfigurations: data.components,
104
+ componentSchemas: components,
105
+ contentTypeSchemas: schemas
106
+ };
107
+ return {
108
+ edit,
109
+ list,
110
+ listViewConversionContext
111
+ };
112
+ }, [
113
+ data,
114
+ isLoading,
115
+ schemas,
116
+ schema,
117
+ components
118
+ ]);
119
+ React__namespace.useEffect(()=>{
120
+ if (resolvedLayouts) {
121
+ stableLayoutsByModelRef.current.set(model, resolvedLayouts);
122
+ }
123
+ }, [
124
+ model,
125
+ resolvedLayouts
126
+ ]);
127
+ const stableLayouts = resolvedLayouts ?? stableLayoutsByModelRef.current.get(model) ?? null;
128
+ const editLayout = React__namespace.useMemo(()=>stableLayouts?.edit ?? {
91
129
  layout: [],
92
130
  components: {},
93
131
  metadatas: {},
94
132
  options: {},
95
133
  settings: DEFAULT_SETTINGS
96
134
  }, [
97
- data,
98
- isLoading,
99
- schemas,
100
- schema,
101
- components
135
+ stableLayouts
102
136
  ]);
103
- const listLayout = React__namespace.useMemo(()=>{
104
- return data && !isLoading ? formatListLayout(data, {
105
- schemas,
106
- schema,
107
- components
108
- }) : {
137
+ const listLayout = React__namespace.useMemo(()=>stableLayouts?.list ?? {
109
138
  layout: [],
110
139
  metadatas: {},
111
140
  options: {},
112
141
  settings: DEFAULT_SETTINGS
113
- };
114
- }, [
115
- data,
116
- isLoading,
117
- schemas,
118
- schema,
119
- components
142
+ }, [
143
+ stableLayouts
120
144
  ]);
121
145
  const { layout: edit } = React__namespace.useMemo(()=>runHookWaterfall(hooks.HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
122
146
  layout: editLayout,
@@ -126,21 +150,7 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
126
150
  query,
127
151
  runHookWaterfall
128
152
  ]);
129
- const listViewConversionContext = React__namespace.useMemo(()=>{
130
- if (!data || isLoading) {
131
- return null;
132
- }
133
- return {
134
- componentConfigurations: data.components,
135
- componentSchemas: components,
136
- contentTypeSchemas: schemas
137
- };
138
- }, [
139
- data,
140
- isLoading,
141
- components,
142
- schemas
143
- ]);
153
+ const listViewConversionContext = stableLayouts?.listViewConversionContext ?? null;
144
154
  return {
145
155
  error,
146
156
  isLoading,
@@ -187,15 +197,20 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
187
197
  return panels;
188
198
  }, []);
189
199
  const componentEditAttributes = Object.entries(data.components).reduce((acc, [uid, configuration])=>{
200
+ const componentSchema = components[uid];
201
+ // Persisted configuration can reference component UIDs absent from `/init`.
202
+ if (!componentSchema) {
203
+ return acc;
204
+ }
190
205
  acc[uid] = {
191
- layout: convertEditLayoutToFieldLayouts(configuration.layouts.edit, components[uid].attributes, configuration.metadatas, {
206
+ layout: convertEditLayoutToFieldLayouts(configuration.layouts.edit, componentSchema.attributes, configuration.metadatas, {
192
207
  configurations: data.components,
193
208
  schemas: components
194
209
  }),
195
210
  settings: {
196
211
  ...configuration.settings,
197
- icon: components[uid].info.icon,
198
- displayName: components[uid].info.displayName
212
+ icon: componentSchema.info.icon,
213
+ displayName: componentSchema.info.displayName
199
214
  }
200
215
  };
201
216
  return acc;
@@ -212,7 +227,7 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
212
227
  metadatas: editMetadatas,
213
228
  settings: {
214
229
  ...data.contentType.settings,
215
- displayName: schema?.info.displayName
230
+ displayName: schema?.info?.displayName
216
231
  },
217
232
  options: {
218
233
  ...schema?.options,
@@ -234,8 +249,12 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
234
249
  if (!attribute) {
235
250
  return null;
236
251
  }
237
- const { edit: metadata } = metadatas[field.name];
238
- const settings = attribute.type === 'component' && components ? components.configurations[attribute.component].settings : {};
252
+ const fieldMetadata = metadatas[field.name];
253
+ if (!fieldMetadata) {
254
+ return null;
255
+ }
256
+ const { edit: metadata } = fieldMetadata;
257
+ const settings = attribute.type === 'component' && components ? components.configurations[attribute.component]?.settings ?? {} : {};
239
258
  return {
240
259
  attribute,
241
260
  disabled: !metadata.editable,
@@ -280,7 +299,7 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
280
299
  layout: listAttributes,
281
300
  settings: {
282
301
  ...data.contentType.settings,
283
- displayName: schema?.info.displayName
302
+ displayName: schema?.info?.displayName
284
303
  },
285
304
  metadatas: listMetadatas,
286
305
  options: {
@@ -305,7 +324,10 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
305
324
  return null;
306
325
  }
307
326
  const metadata = metadatas[name];
308
- const settings = attribute.type === 'component' && components ? components.configurations[attribute.component].settings : {};
327
+ if (!metadata) {
328
+ return null;
329
+ }
330
+ const settings = attribute.type === 'component' && components ? components.configurations[attribute.component]?.settings ?? {} : {};
309
331
  return {
310
332
  attribute,
311
333
  label: metadata.label ?? '',
@@ -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 { 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;AAE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AA,GAAmC,EAAE,EACrCpB,SAAAA,EACA9B,UAAAA,EAIAgB,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;;;;;;;;"}
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 currentData: data,\n isLoading: isLoadingConfigs,\n error,\n } = useGetContentTypeConfigurationQuery(model);\n\n const isConfigResolvedForModel = data?.contentType?.uid === model;\n const isLoading = isLoadingSchemas || isLoadingConfigs || (!error && !isConfigResolvedForModel);\n const stableLayoutsByModelRef = React.useRef(\n new Map<\n string,\n {\n edit: EditLayout;\n list: ListLayout;\n listViewConversionContext: ListViewConversionContext | null;\n }\n >()\n );\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 resolvedLayouts = React.useMemo(() => {\n if (!data || isLoading) {\n return null;\n }\n\n const edit = formatEditLayout(data, { schemas, schema, components });\n const list = formatListLayout(data, { schemas, schema, components });\n const listViewConversionContext: ListViewConversionContext = {\n componentConfigurations: data.components,\n componentSchemas: components,\n contentTypeSchemas: schemas,\n };\n\n return { edit, list, listViewConversionContext };\n }, [data, isLoading, schemas, schema, components]);\n\n React.useEffect(() => {\n if (resolvedLayouts) {\n stableLayoutsByModelRef.current.set(model, resolvedLayouts);\n }\n }, [model, resolvedLayouts]);\n\n const stableLayouts = resolvedLayouts ?? stableLayoutsByModelRef.current.get(model) ?? null;\n\n const editLayout = React.useMemo(\n () =>\n stableLayouts?.edit ??\n ({\n layout: [],\n components: {},\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as EditLayout),\n [stableLayouts]\n );\n\n const listLayout = React.useMemo(\n () =>\n stableLayouts?.list ??\n ({\n layout: [],\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as ListLayout),\n [stableLayouts]\n );\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 = stableLayouts?.listViewConversionContext ?? null;\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 const componentSchema = components[uid];\n\n // Persisted configuration can reference component UIDs absent from `/init`.\n if (!componentSchema) {\n return acc;\n }\n\n acc[uid] = {\n layout: convertEditLayoutToFieldLayouts(\n configuration.layouts.edit,\n componentSchema.attributes,\n configuration.metadatas,\n { configurations: data.components, schemas: components }\n ),\n settings: {\n ...configuration.settings,\n icon: componentSchema.info.icon,\n displayName: componentSchema.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 fieldMetadata = metadatas[field.name];\n if (!fieldMetadata) {\n return null;\n }\n\n const { edit: metadata } = fieldMetadata;\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 if (!metadata) {\n return null;\n }\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","currentData","data","isLoadingConfigs","error","useGetContentTypeConfigurationQuery","isConfigResolvedForModel","contentType","uid","stableLayoutsByModelRef","React","useRef","Map","useEffect","type","message","resolvedLayouts","useMemo","edit","formatEditLayout","list","formatListLayout","listViewConversionContext","componentConfigurations","componentSchemas","contentTypeSchemas","current","set","stableLayouts","get","editLayout","layout","metadatas","options","settings","listLayout","HOOKS","MUTATE_EDIT_VIEW_LAYOUT","useDocLayout","useDoc","currentPanelIndex","panelledEditAttributes","convertEditLayoutToFieldLayouts","layouts","attributes","configurations","reduce","panels","row","some","field","push","componentEditAttributes","Object","entries","acc","configuration","componentSchema","icon","info","displayName","editMetadatas","attribute","metadata","pluginOptions","rows","map","name","fieldMetadata","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,EA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E;AAC3EsB,gBAAAA,OAAAA;gBACAhB,UAAAA,EAAYA,UAAAA,EAAYgB,WAAW;AACrC,aAAA,CAAA;YACAoE,IAAAA,EAAMA,IAAAA;YACN9F,UAAAA,EAAY0F,QAAAA,CAAS1F,UAAU,IAAI,IAAA;YACnCiH,QAAAA,EAAUvB,QAAAA,CAASuB,QAAQ,IAAI;AACjC,SAAA;AACF,IAAA,CAAA,CAAA,CACCL,MAAM,CAAC,CAAC/B,KAAAA,GAAUA,KAAAA,KAAU,IAAA,CAAA;AACjC;;;;;;;;"}
@@ -48,8 +48,10 @@ 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 } = useGetContentTypeConfigurationQuery(model);
52
- const isLoading = isLoadingSchemas || isLoadingConfigs;
51
+ const { currentData: data, isLoading: isLoadingConfigs, error } = useGetContentTypeConfigurationQuery(model);
52
+ const isConfigResolvedForModel = data?.contentType?.uid === model;
53
+ const isLoading = isLoadingSchemas || isLoadingConfigs || !error && !isConfigResolvedForModel;
54
+ const stableLayoutsByModelRef = React.useRef(new Map());
53
55
  React.useEffect(()=>{
54
56
  if (error) {
55
57
  toggleNotification({
@@ -62,40 +64,62 @@ import { useDocument, useDoc } from './useDocument.mjs';
62
64
  formatAPIError,
63
65
  toggleNotification
64
66
  ]);
65
- const editLayout = React.useMemo(()=>data && !isLoading ? formatEditLayout(data, {
67
+ const resolvedLayouts = React.useMemo(()=>{
68
+ if (!data || isLoading) {
69
+ return null;
70
+ }
71
+ const edit = formatEditLayout(data, {
72
+ schemas,
73
+ schema,
74
+ components
75
+ });
76
+ const list = formatListLayout(data, {
66
77
  schemas,
67
78
  schema,
68
79
  components
69
- }) : {
80
+ });
81
+ const listViewConversionContext = {
82
+ componentConfigurations: data.components,
83
+ componentSchemas: components,
84
+ contentTypeSchemas: schemas
85
+ };
86
+ return {
87
+ edit,
88
+ list,
89
+ listViewConversionContext
90
+ };
91
+ }, [
92
+ data,
93
+ isLoading,
94
+ schemas,
95
+ schema,
96
+ components
97
+ ]);
98
+ React.useEffect(()=>{
99
+ if (resolvedLayouts) {
100
+ stableLayoutsByModelRef.current.set(model, resolvedLayouts);
101
+ }
102
+ }, [
103
+ model,
104
+ resolvedLayouts
105
+ ]);
106
+ const stableLayouts = resolvedLayouts ?? stableLayoutsByModelRef.current.get(model) ?? null;
107
+ const editLayout = React.useMemo(()=>stableLayouts?.edit ?? {
70
108
  layout: [],
71
109
  components: {},
72
110
  metadatas: {},
73
111
  options: {},
74
112
  settings: DEFAULT_SETTINGS
75
113
  }, [
76
- data,
77
- isLoading,
78
- schemas,
79
- schema,
80
- components
114
+ stableLayouts
81
115
  ]);
82
- const listLayout = React.useMemo(()=>{
83
- return data && !isLoading ? formatListLayout(data, {
84
- schemas,
85
- schema,
86
- components
87
- }) : {
116
+ const listLayout = React.useMemo(()=>stableLayouts?.list ?? {
88
117
  layout: [],
89
118
  metadatas: {},
90
119
  options: {},
91
120
  settings: DEFAULT_SETTINGS
92
- };
93
- }, [
94
- data,
95
- isLoading,
96
- schemas,
97
- schema,
98
- components
121
+ }, [
122
+ stableLayouts
99
123
  ]);
100
124
  const { layout: edit } = React.useMemo(()=>runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
101
125
  layout: editLayout,
@@ -105,21 +129,7 @@ import { useDocument, useDoc } from './useDocument.mjs';
105
129
  query,
106
130
  runHookWaterfall
107
131
  ]);
108
- const listViewConversionContext = React.useMemo(()=>{
109
- if (!data || isLoading) {
110
- return null;
111
- }
112
- return {
113
- componentConfigurations: data.components,
114
- componentSchemas: components,
115
- contentTypeSchemas: schemas
116
- };
117
- }, [
118
- data,
119
- isLoading,
120
- components,
121
- schemas
122
- ]);
132
+ const listViewConversionContext = stableLayouts?.listViewConversionContext ?? null;
123
133
  return {
124
134
  error,
125
135
  isLoading,
@@ -166,15 +176,20 @@ import { useDocument, useDoc } from './useDocument.mjs';
166
176
  return panels;
167
177
  }, []);
168
178
  const componentEditAttributes = Object.entries(data.components).reduce((acc, [uid, configuration])=>{
179
+ const componentSchema = components[uid];
180
+ // Persisted configuration can reference component UIDs absent from `/init`.
181
+ if (!componentSchema) {
182
+ return acc;
183
+ }
169
184
  acc[uid] = {
170
- layout: convertEditLayoutToFieldLayouts(configuration.layouts.edit, components[uid].attributes, configuration.metadatas, {
185
+ layout: convertEditLayoutToFieldLayouts(configuration.layouts.edit, componentSchema.attributes, configuration.metadatas, {
171
186
  configurations: data.components,
172
187
  schemas: components
173
188
  }),
174
189
  settings: {
175
190
  ...configuration.settings,
176
- icon: components[uid].info.icon,
177
- displayName: components[uid].info.displayName
191
+ icon: componentSchema.info.icon,
192
+ displayName: componentSchema.info.displayName
178
193
  }
179
194
  };
180
195
  return acc;
@@ -191,7 +206,7 @@ import { useDocument, useDoc } from './useDocument.mjs';
191
206
  metadatas: editMetadatas,
192
207
  settings: {
193
208
  ...data.contentType.settings,
194
- displayName: schema?.info.displayName
209
+ displayName: schema?.info?.displayName
195
210
  },
196
211
  options: {
197
212
  ...schema?.options,
@@ -213,8 +228,12 @@ import { useDocument, useDoc } from './useDocument.mjs';
213
228
  if (!attribute) {
214
229
  return null;
215
230
  }
216
- const { edit: metadata } = metadatas[field.name];
217
- const settings = attribute.type === 'component' && components ? components.configurations[attribute.component].settings : {};
231
+ const fieldMetadata = metadatas[field.name];
232
+ if (!fieldMetadata) {
233
+ return null;
234
+ }
235
+ const { edit: metadata } = fieldMetadata;
236
+ const settings = attribute.type === 'component' && components ? components.configurations[attribute.component]?.settings ?? {} : {};
218
237
  return {
219
238
  attribute,
220
239
  disabled: !metadata.editable,
@@ -259,7 +278,7 @@ import { useDocument, useDoc } from './useDocument.mjs';
259
278
  layout: listAttributes,
260
279
  settings: {
261
280
  ...data.contentType.settings,
262
- displayName: schema?.info.displayName
281
+ displayName: schema?.info?.displayName
263
282
  },
264
283
  metadatas: listMetadatas,
265
284
  options: {
@@ -284,7 +303,10 @@ import { useDocument, useDoc } from './useDocument.mjs';
284
303
  return null;
285
304
  }
286
305
  const metadata = metadatas[name];
287
- const settings = attribute.type === 'component' && components ? components.configurations[attribute.component].settings : {};
306
+ if (!metadata) {
307
+ return null;
308
+ }
309
+ const settings = attribute.type === 'component' && components ? components.configurations[attribute.component]?.settings ?? {} : {};
288
310
  return {
289
311
  attribute,
290
312
  label: metadata.label ?? '',
@@ -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 { 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,IA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,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;;;;"}
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 currentData: data,\n isLoading: isLoadingConfigs,\n error,\n } = useGetContentTypeConfigurationQuery(model);\n\n const isConfigResolvedForModel = data?.contentType?.uid === model;\n const isLoading = isLoadingSchemas || isLoadingConfigs || (!error && !isConfigResolvedForModel);\n const stableLayoutsByModelRef = React.useRef(\n new Map<\n string,\n {\n edit: EditLayout;\n list: ListLayout;\n listViewConversionContext: ListViewConversionContext | null;\n }\n >()\n );\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 resolvedLayouts = React.useMemo(() => {\n if (!data || isLoading) {\n return null;\n }\n\n const edit = formatEditLayout(data, { schemas, schema, components });\n const list = formatListLayout(data, { schemas, schema, components });\n const listViewConversionContext: ListViewConversionContext = {\n componentConfigurations: data.components,\n componentSchemas: components,\n contentTypeSchemas: schemas,\n };\n\n return { edit, list, listViewConversionContext };\n }, [data, isLoading, schemas, schema, components]);\n\n React.useEffect(() => {\n if (resolvedLayouts) {\n stableLayoutsByModelRef.current.set(model, resolvedLayouts);\n }\n }, [model, resolvedLayouts]);\n\n const stableLayouts = resolvedLayouts ?? stableLayoutsByModelRef.current.get(model) ?? null;\n\n const editLayout = React.useMemo(\n () =>\n stableLayouts?.edit ??\n ({\n layout: [],\n components: {},\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as EditLayout),\n [stableLayouts]\n );\n\n const listLayout = React.useMemo(\n () =>\n stableLayouts?.list ??\n ({\n layout: [],\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as ListLayout),\n [stableLayouts]\n );\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 = stableLayouts?.listViewConversionContext ?? null;\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 const componentSchema = components[uid];\n\n // Persisted configuration can reference component UIDs absent from `/init`.\n if (!componentSchema) {\n return acc;\n }\n\n acc[uid] = {\n layout: convertEditLayoutToFieldLayouts(\n configuration.layouts.edit,\n componentSchema.attributes,\n configuration.metadatas,\n { configurations: data.components, schemas: components }\n ),\n settings: {\n ...configuration.settings,\n icon: componentSchema.info.icon,\n displayName: componentSchema.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 fieldMetadata = metadatas[field.name];\n if (!fieldMetadata) {\n return null;\n }\n\n const { edit: metadata } = fieldMetadata;\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 if (!metadata) {\n return null;\n }\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","currentData","data","isLoadingConfigs","error","useGetContentTypeConfigurationQuery","isConfigResolvedForModel","contentType","uid","stableLayoutsByModelRef","React","useRef","Map","useEffect","type","message","resolvedLayouts","useMemo","edit","formatEditLayout","list","formatListLayout","listViewConversionContext","componentConfigurations","componentSchemas","contentTypeSchemas","current","set","stableLayouts","get","editLayout","layout","metadatas","options","settings","listLayout","HOOKS","MUTATE_EDIT_VIEW_LAYOUT","useDocLayout","useDoc","currentPanelIndex","panelledEditAttributes","convertEditLayoutToFieldLayouts","layouts","attributes","configurations","reduce","panels","row","some","field","push","componentEditAttributes","Object","entries","acc","configuration","componentSchema","icon","info","displayName","editMetadatas","attribute","metadata","pluginOptions","rows","map","name","fieldMetadata","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,WAAAA,CAAY;AAAEH,QAAAA,KAAAA;QAAOI,cAAAA,EAAgB;KAAG,EAAG;QAAEC,IAAAA,EAAM;AAAK,KAAA,CAAA;AACvF,IAAA,MAAM,CAAC,EAAEC,KAAK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zC,UAAAA,GAAmC,EAAE,EACrCZ,SAAAA,EACAjD,UAAAA,EAIAgB,OAAAA,GAAoB,EAAE,GAAA;IAEtB,OAAOsF,OAAAA,CACJnB,GAAG,CAAC,CAACC,IAAAA,GAAAA;QACJ,MAAML,SAAAA,GAAYlB,UAAU,CAACuB,IAAAA,CAAK;AAElC,QAAA,IAAI,CAACL,SAAAA,EAAW;YACd,OAAO,IAAA;AACT,QAAA;QAEA,MAAMC,QAAAA,GAAW/B,SAAS,CAACmC,IAAAA,CAAK;AAChC,QAAA,IAAI,CAACJ,QAAAA,EAAU;YACb,OAAO,IAAA;AACT,QAAA;AAEA,QAAA,MAAM7B,WACJ4B,SAAAA,CAAUhD,IAAI,KAAK,WAAA,IAAe/B,aAC7BA,UAAAA,CAAW8D,cAAc,CAACiB,SAAAA,CAAUO,SAAS,CAAC,EAAEnC,QAAAA,IAAY,KAC7D,EAAC;QAEP,OAAO;AACL4B,YAAAA,SAAAA;YACAY,KAAAA,EAAOX,QAAAA,CAASW,KAAK,IAAI,EAAA;AACzBjG,YAAAA,SAAAA,EAAWkG,aAAab,SAAAA,EAAWC,QAAAA,CAAStF,SAAS,IAAIyD,QAAAA,CAASzD,SAAS,EAAE;AAC3EsB,gBAAAA,OAAAA;gBACAhB,UAAAA,EAAYA,UAAAA,EAAYgB,WAAW;AACrC,aAAA,CAAA;YACAoE,IAAAA,EAAMA,IAAAA;YACN9F,UAAAA,EAAY0F,QAAAA,CAAS1F,UAAU,IAAI,IAAA;YACnCiH,QAAAA,EAAUvB,QAAAA,CAASuB,QAAQ,IAAI;AACjC,SAAA;AACF,IAAA,CAAA,CAAA,CACCL,MAAM,CAAC,CAAC/B,KAAAA,GAAUA,KAAAA,KAAU,IAAA,CAAA;AACjC;;;;"}
@@ -201,12 +201,16 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
201
201
  schemas: components
202
202
  });
203
203
  const componentEditAttributes = Object.entries(data.components).reduce((acc, [uid, configuration])=>{
204
+ const componentSchema = components[uid];
205
+ if (!componentSchema) {
206
+ return acc;
207
+ }
204
208
  acc[uid] = {
205
- layout: useDocumentLayout.convertEditLayoutToFieldLayouts(configuration.layouts.edit, components[uid].attributes, configuration.metadatas),
209
+ layout: useDocumentLayout.convertEditLayoutToFieldLayouts(configuration.layouts.edit, componentSchema.attributes, configuration.metadatas),
206
210
  settings: {
207
211
  ...configuration.settings,
208
- icon: components[uid].info.icon,
209
- displayName: components[uid].info.displayName
212
+ icon: componentSchema.info.icon,
213
+ displayName: componentSchema.info.displayName
210
214
  }
211
215
  };
212
216
  return acc;
@@ -1 +1 @@
1
- {"version":3,"file":"ComponentConfigurationPage.js","sources":["../../../admin/src/pages/ComponentConfigurationPage.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Page, useNotification, useAPIErrorHandler } from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useParams } from 'react-router-dom';\n\nimport { TEMP_FIELD_NAME } from '../components/ConfigurationForm/Fields';\nimport { ConfigurationForm, ConfigurationFormProps } from '../components/ConfigurationForm/Form';\nimport { ComponentsDictionary, extractContentTypeComponents } from '../hooks/useContentTypeSchema';\nimport {\n DEFAULT_SETTINGS,\n EditLayout,\n convertEditLayoutToFieldLayouts,\n} from '../hooks/useDocumentLayout';\nimport { useTypedSelector } from '../modules/hooks';\nimport {\n useGetComponentConfigurationQuery,\n useUpdateComponentConfigurationMutation,\n} from '../services/components';\nimport { useGetInitialDataQuery } from '../services/init';\nimport { setIn } from '../utils/objects';\n\nimport type { Component, FindComponentConfiguration } from '../../../shared/contracts/components';\nimport type { Metadatas } from '../../../shared/contracts/content-types';\n\n/* -------------------------------------------------------------------------------------------------\n * ComponentConfigurationPage\n * -----------------------------------------------------------------------------------------------*/\n\nconst ComponentConfigurationPage = () => {\n /**\n * useDocumentLayout only works for documents, not components,\n * it feels weird to make that hook work for both when this is SUCH\n * a unique use case and we only do it here, so in short, we essentially\n * just extracted the logic to make an edit view layout and reproduced it here.\n */\n const { slug: model } = useParams<{ slug: string }>();\n const { toggleNotification } = useNotification();\n const { formatMessage } = useIntl();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n\n const {\n components,\n fieldSizes,\n schema,\n error: errorSchema,\n isLoading: isLoadingSchema,\n isFetching: isFetchingSchema,\n } = useGetInitialDataQuery(undefined, {\n selectFromResult: (res) => {\n const schema = res.data?.components.find((ct) => ct.uid === model);\n\n const componentsByKey = res.data?.components.reduce<ComponentsDictionary>(\n (acc, component) => {\n acc[component.uid] = component;\n\n return acc;\n },\n {}\n );\n\n const components = extractContentTypeComponents(schema?.attributes, componentsByKey);\n\n const fieldSizes = Object.entries(res.data?.fieldSizes ?? {}).reduce<\n ConfigurationFormProps['fieldSizes']\n >((acc, [attributeName, { default: size }]) => {\n acc[attributeName] = size;\n\n return acc;\n }, {});\n\n return {\n isFetching: res.isFetching,\n isLoading: res.isLoading,\n error: res.error,\n components,\n schema,\n fieldSizes,\n };\n },\n });\n\n React.useEffect(() => {\n if (errorSchema) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(errorSchema),\n });\n }\n }, [errorSchema, formatAPIError, toggleNotification]);\n\n const {\n data,\n isLoading: isLoadingConfig,\n isFetching: isFetchingConfig,\n error,\n } = useGetComponentConfigurationQuery(model ?? '');\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [error, formatAPIError, toggleNotification]);\n\n /**\n * you **must** check if we're loading or fetching in case the component gets new props\n * but nothing was unmounted, it then becomes a fetch, not a load.\n */\n const isLoading = isLoadingConfig || isLoadingSchema || isFetchingConfig || isFetchingSchema;\n\n const editLayout = React.useMemo(\n () =>\n data && !isLoading\n ? formatEditLayout(data, { schema, components })\n : ({\n layout: [],\n components: {},\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as EditLayout),\n [data, isLoading, schema, components]\n );\n\n const [updateConfiguration] = useUpdateComponentConfigurationMutation();\n const handleSubmit: ConfigurationFormProps['onSubmit'] = async (formData) => {\n try {\n /**\n * We reconstruct the metadatas object by taking the existing list metadatas\n * and re-merging that by attribute name with the current list metadatas, whilst overwriting\n * the data from the form we've built.\n */\n const meta = Object.entries(data?.component.metadatas ?? {}).reduce<Metadatas>(\n (acc, [name, { edit, list }]) => {\n const {\n __temp_key__,\n size: _size,\n name: _name,\n ...editedMetadata\n } = formData.layout.flatMap((row) => row.children).find((field) => field.name === name) ??\n {};\n\n acc[name] = {\n edit: {\n ...edit,\n ...editedMetadata,\n },\n list,\n };\n\n return acc;\n },\n {}\n );\n\n const res = await updateConfiguration({\n layouts: {\n edit: formData.layout.map((row) =>\n row.children.reduce<Array<{ name: string; size: number }>>((acc, { name, size }) => {\n if (name !== TEMP_FIELD_NAME) {\n return [...acc, { name, size }];\n }\n\n return acc;\n }, [])\n ),\n list: data?.component.layouts.list,\n },\n settings: setIn(formData.settings, 'displayName', undefined),\n metadatas: meta,\n uid: model,\n });\n\n if ('data' in res) {\n toggleNotification({\n type: 'success',\n message: formatMessage({ id: 'notification.success.saved', defaultMessage: 'Saved' }),\n });\n } else {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(res.error),\n });\n }\n } catch {\n toggleNotification({\n type: 'danger',\n message: formatMessage({ id: 'notification.error', defaultMessage: 'An error occurred' }),\n });\n }\n };\n\n if (isLoading) {\n return <Page.Loading />;\n }\n\n if (error || errorSchema || !schema) {\n return <Page.Error />;\n }\n\n return (\n <>\n <Page.Title>{`Configure ${editLayout.settings.displayName} Edit View`}</Page.Title>\n <ConfigurationForm\n onSubmit={handleSubmit}\n attributes={schema.attributes}\n fieldSizes={fieldSizes}\n layout={editLayout}\n />\n </>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * Header\n * -----------------------------------------------------------------------------------------------*/\n\nconst formatEditLayout = (\n data: FindComponentConfiguration.Response['data'],\n { schema, components }: { schema?: Component; components: ComponentsDictionary }\n) => {\n const editAttributes = convertEditLayoutToFieldLayouts(\n data.component.layouts.edit,\n schema?.attributes,\n data.component.metadatas,\n { configurations: data.components, schemas: components }\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 ),\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.component.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: [editAttributes],\n components: componentEditAttributes,\n metadatas: editMetadatas,\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n },\n settings: {\n ...data.component.settings,\n displayName: schema?.info.displayName,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * Header\n * -----------------------------------------------------------------------------------------------*/\n\nconst ProtectedComponentConfigurationPage = () => {\n const permissions = useTypedSelector(\n (state) => state.admin_app.permissions.contentManager?.componentsConfigurations\n );\n\n return (\n <Page.Protect permissions={permissions}>\n <ComponentConfigurationPage />\n </Page.Protect>\n );\n};\n\nexport { ComponentConfigurationPage, ProtectedComponentConfigurationPage };\n"],"names":["ComponentConfigurationPage","slug","model","useParams","toggleNotification","useNotification","formatMessage","useIntl","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","components","fieldSizes","schema","error","errorSchema","isLoading","isLoadingSchema","isFetching","isFetchingSchema","useGetInitialDataQuery","undefined","selectFromResult","res","data","find","ct","uid","componentsByKey","reduce","acc","component","extractContentTypeComponents","attributes","Object","entries","attributeName","default","size","React","useEffect","type","message","isLoadingConfig","isFetchingConfig","useGetComponentConfigurationQuery","editLayout","useMemo","formatEditLayout","layout","metadatas","options","settings","DEFAULT_SETTINGS","updateConfiguration","useUpdateComponentConfigurationMutation","handleSubmit","formData","meta","name","edit","list","__temp_key__","_size","_name","editedMetadata","flatMap","row","children","field","layouts","map","TEMP_FIELD_NAME","setIn","id","defaultMessage","_jsx","Page","Loading","Error","_jsxs","_Fragment","Title","displayName","ConfigurationForm","onSubmit","editAttributes","convertEditLayoutToFieldLayouts","configurations","schemas","componentEditAttributes","configuration","icon","info","editMetadatas","attribute","metadata","pluginOptions","ProtectedComponentConfigurationPage","permissions","useTypedSelector","state","admin_app","contentManager","componentsConfigurations","Protect"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA;;AAEkG,2GAE5FA,0BAAAA,GAA6B,IAAA;AACjC;;;;;AAKC,MACD,MAAM,EAAEC,IAAAA,EAAMC,KAAK,EAAE,GAAGC,wBAAAA,EAAAA;IACxB,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,2BAAAA,EAAAA;IAC/B,MAAM,EAAEC,aAAa,EAAE,GAAGC,iBAAAA,EAAAA;AAC1B,IAAA,MAAM,EAAEC,uBAAAA,EAAyBC,cAAc,EAAE,GAAGC,8BAAAA,EAAAA;AAEpD,IAAA,MAAM,cACJC,YAAU,EACVC,UAAU,EACVC,MAAM,EACNC,KAAAA,EAAOC,WAAW,EAClBC,SAAAA,EAAWC,eAAe,EAC1BC,UAAAA,EAAYC,gBAAgB,EAC7B,GAAGC,4BAAuBC,SAAAA,EAAW;AACpCC,QAAAA,gBAAAA,EAAkB,CAACC,GAAAA,GAAAA;YACjB,MAAMV,MAAAA,GAASU,GAAAA,CAAIC,IAAI,EAAEb,UAAAA,CAAWc,KAAK,CAACC,EAAAA,GAAOA,EAAAA,CAAGC,GAAG,KAAKzB,KAAAA,CAAAA;AAE5D,YAAA,MAAM0B,kBAAkBL,GAAAA,CAAIC,IAAI,EAAEb,UAAAA,CAAWkB,MAAAA,CAC3C,CAACC,GAAAA,EAAKC,SAAAA,GAAAA;AACJD,gBAAAA,GAAG,CAACC,SAAAA,CAAUJ,GAAG,CAAC,GAAGI,SAAAA;gBAErB,OAAOD,G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AQsC,OAAO;AAClB,YAAA,GAAGtC,QAAQoF;AACb,SAAA;QACA7C,QAAAA,EAAU;YACR,GAAG5B,IAAAA,CAAKO,SAAS,CAACqB,QAAQ;AAC1B+B,YAAAA,WAAAA,EAAatE,QAAQgF,IAAAA,CAAKV;AAC5B;AACF,KAAA;AACF,CAAA;AAEA;;AAEkG,2GAE5Fe,mCAAAA,GAAsC,IAAA;IAC1C,MAAMC,WAAAA,GAAcC,sBAAAA,CAClB,CAACC,KAAAA,GAAUA,KAAAA,CAAMC,SAAS,CAACH,WAAW,CAACI,cAAc,EAAEC,wBAAAA,CAAAA;IAGzD,qBACE5B,cAAA,CAACC,iBAAK4B,OAAO,EAAA;QAACN,WAAAA,EAAaA,WAAAA;AACzB,QAAA,QAAA,gBAAAvB,cAAA,CAAC5E,0BAAAA,EAAAA,EAAAA;;AAGP;;;;;"}
1
+ {"version":3,"file":"ComponentConfigurationPage.js","sources":["../../../admin/src/pages/ComponentConfigurationPage.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Page, useNotification, useAPIErrorHandler } from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useParams } from 'react-router-dom';\n\nimport { TEMP_FIELD_NAME } from '../components/ConfigurationForm/Fields';\nimport { ConfigurationForm, ConfigurationFormProps } from '../components/ConfigurationForm/Form';\nimport { ComponentsDictionary, extractContentTypeComponents } from '../hooks/useContentTypeSchema';\nimport {\n DEFAULT_SETTINGS,\n EditLayout,\n convertEditLayoutToFieldLayouts,\n} from '../hooks/useDocumentLayout';\nimport { useTypedSelector } from '../modules/hooks';\nimport {\n useGetComponentConfigurationQuery,\n useUpdateComponentConfigurationMutation,\n} from '../services/components';\nimport { useGetInitialDataQuery } from '../services/init';\nimport { setIn } from '../utils/objects';\n\nimport type { Component, FindComponentConfiguration } from '../../../shared/contracts/components';\nimport type { Metadatas } from '../../../shared/contracts/content-types';\n\n/* -------------------------------------------------------------------------------------------------\n * ComponentConfigurationPage\n * -----------------------------------------------------------------------------------------------*/\n\nconst ComponentConfigurationPage = () => {\n /**\n * useDocumentLayout only works for documents, not components,\n * it feels weird to make that hook work for both when this is SUCH\n * a unique use case and we only do it here, so in short, we essentially\n * just extracted the logic to make an edit view layout and reproduced it here.\n */\n const { slug: model } = useParams<{ slug: string }>();\n const { toggleNotification } = useNotification();\n const { formatMessage } = useIntl();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n\n const {\n components,\n fieldSizes,\n schema,\n error: errorSchema,\n isLoading: isLoadingSchema,\n isFetching: isFetchingSchema,\n } = useGetInitialDataQuery(undefined, {\n selectFromResult: (res) => {\n const schema = res.data?.components.find((ct) => ct.uid === model);\n\n const componentsByKey = res.data?.components.reduce<ComponentsDictionary>(\n (acc, component) => {\n acc[component.uid] = component;\n\n return acc;\n },\n {}\n );\n\n const components = extractContentTypeComponents(schema?.attributes, componentsByKey);\n\n const fieldSizes = Object.entries(res.data?.fieldSizes ?? {}).reduce<\n ConfigurationFormProps['fieldSizes']\n >((acc, [attributeName, { default: size }]) => {\n acc[attributeName] = size;\n\n return acc;\n }, {});\n\n return {\n isFetching: res.isFetching,\n isLoading: res.isLoading,\n error: res.error,\n components,\n schema,\n fieldSizes,\n };\n },\n });\n\n React.useEffect(() => {\n if (errorSchema) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(errorSchema),\n });\n }\n }, [errorSchema, formatAPIError, toggleNotification]);\n\n const {\n data,\n isLoading: isLoadingConfig,\n isFetching: isFetchingConfig,\n error,\n } = useGetComponentConfigurationQuery(model ?? '');\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [error, formatAPIError, toggleNotification]);\n\n /**\n * you **must** check if we're loading or fetching in case the component gets new props\n * but nothing was unmounted, it then becomes a fetch, not a load.\n */\n const isLoading = isLoadingConfig || isLoadingSchema || isFetchingConfig || isFetchingSchema;\n\n const editLayout = React.useMemo(\n () =>\n data && !isLoading\n ? formatEditLayout(data, { schema, components })\n : ({\n layout: [],\n components: {},\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as EditLayout),\n [data, isLoading, schema, components]\n );\n\n const [updateConfiguration] = useUpdateComponentConfigurationMutation();\n const handleSubmit: ConfigurationFormProps['onSubmit'] = async (formData) => {\n try {\n /**\n * We reconstruct the metadatas object by taking the existing list metadatas\n * and re-merging that by attribute name with the current list metadatas, whilst overwriting\n * the data from the form we've built.\n */\n const meta = Object.entries(data?.component.metadatas ?? {}).reduce<Metadatas>(\n (acc, [name, { edit, list }]) => {\n const {\n __temp_key__,\n size: _size,\n name: _name,\n ...editedMetadata\n } = formData.layout.flatMap((row) => row.children).find((field) => field.name === name) ??\n {};\n\n acc[name] = {\n edit: {\n ...edit,\n ...editedMetadata,\n },\n list,\n };\n\n return acc;\n },\n {}\n );\n\n const res = await updateConfiguration({\n layouts: {\n edit: formData.layout.map((row) =>\n row.children.reduce<Array<{ name: string; size: number }>>((acc, { name, size }) => {\n if (name !== TEMP_FIELD_NAME) {\n return [...acc, { name, size }];\n }\n\n return acc;\n }, [])\n ),\n list: data?.component.layouts.list,\n },\n settings: setIn(formData.settings, 'displayName', undefined),\n metadatas: meta,\n uid: model,\n });\n\n if ('data' in res) {\n toggleNotification({\n type: 'success',\n message: formatMessage({ id: 'notification.success.saved', defaultMessage: 'Saved' }),\n });\n } else {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(res.error),\n });\n }\n } catch {\n toggleNotification({\n type: 'danger',\n message: formatMessage({ id: 'notification.error', defaultMessage: 'An error occurred' }),\n });\n }\n };\n\n if (isLoading) {\n return <Page.Loading />;\n }\n\n if (error || errorSchema || !schema) {\n return <Page.Error />;\n }\n\n return (\n <>\n <Page.Title>{`Configure ${editLayout.settings.displayName} Edit View`}</Page.Title>\n <ConfigurationForm\n onSubmit={handleSubmit}\n attributes={schema.attributes}\n fieldSizes={fieldSizes}\n layout={editLayout}\n />\n </>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * Header\n * -----------------------------------------------------------------------------------------------*/\n\nconst formatEditLayout = (\n data: FindComponentConfiguration.Response['data'],\n { schema, components }: { schema?: Component; components: ComponentsDictionary }\n) => {\n const editAttributes = convertEditLayoutToFieldLayouts(\n data.component.layouts.edit,\n schema?.attributes,\n data.component.metadatas,\n { configurations: data.components, schemas: components }\n );\n\n const componentEditAttributes = Object.entries(data.components).reduce<EditLayout['components']>(\n (acc, [uid, configuration]) => {\n const componentSchema = components[uid];\n if (!componentSchema) {\n return acc;\n }\n\n acc[uid] = {\n layout: convertEditLayoutToFieldLayouts(\n configuration.layouts.edit,\n componentSchema.attributes,\n configuration.metadatas\n ),\n settings: {\n ...configuration.settings,\n icon: componentSchema.info.icon,\n displayName: componentSchema.info.displayName,\n },\n };\n return acc;\n },\n {}\n );\n\n const editMetadatas = Object.entries(data.component.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: [editAttributes],\n components: componentEditAttributes,\n metadatas: editMetadatas,\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n },\n settings: {\n ...data.component.settings,\n displayName: schema?.info.displayName,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * Header\n * -----------------------------------------------------------------------------------------------*/\n\nconst ProtectedComponentConfigurationPage = () => {\n const permissions = useTypedSelector(\n (state) => state.admin_app.permissions.contentManager?.componentsConfigurations\n );\n\n return (\n <Page.Protect permissions={permissions}>\n <ComponentConfigurationPage />\n </Page.Protect>\n );\n};\n\nexport { ComponentConfigurationPage, ProtectedComponentConfigurationPage };\n"],"names":["ComponentConfigurationPage","slug","model","useParams","toggleNotification","useNotification","formatMessage","useIntl","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","components","fieldSizes","schema","error","errorSchema","isLoading","isLoadingSchema","isFetching","isFetchingSchema","useGetInitialDataQuery","undefined","selectFromResult","res","data","find","ct","uid","componentsByKey","reduce","acc","component","extractContentTypeComponents","attributes","Object","entries","attributeName","default","size","React","useEffect","type","message","isLoadingConfig","isFetchingConfig","useGetComponentConfigurationQuery","editLayout","useMemo","formatEditLayout","layout","metadatas","options","settings","DEFAULT_SETTINGS","updateConfiguration","useUpdateComponentConfigurationMutation","handleSubmit","formData","meta","name","edit","list","__temp_key__","_size","_name","editedMetadata","flatMap","row","children","field","layouts","map","TEMP_FIELD_NAME","setIn","id","defaultMessage","_jsx","Page","Loading","Error","_jsxs","_Fragment","Title","displayName","ConfigurationForm","onSubmit","editAttributes","convertEditLayoutToFieldLayouts","configurations","schemas","componentEditAttributes","configuration","componentSchema","icon","info","editMetadatas","attribute","metadata","pluginOptions","ProtectedComponentConfigurationPage","permissions","useTypedSelector","state","admin_app","contentManager","componentsConfigurations","Protect"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyBA;;AAEkG,2GAE5FA,0BAAAA,GAA6B,IAAA;AACjC;;;;;AAKC,MACD,MAAM,EAAEC,IAAAA,EAAMC,KAAK,EAAE,GAAGC,wBAAAA,EAAAA;IACxB,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,2BAAAA,EAAAA;IAC/B,MAAM,EAAEC,aAAa,EAAE,GAAGC,iBAAAA,EAAAA;AAC1B,IAAA,MAAM,EAAEC,uBAAAA,EAAyBC,cAAc,EAAE,GAAGC,8BAAAA,EAAAA;AAEpD,IAAA,MAAM,cACJC,YAAU,EACVC,UAAU,EACVC,MAAM,EACNC,KAAAA,EAAOC,WAAW,EAClBC,SAAAA,EAAWC,eAAe,EAC1BC,UAAAA,EAAYC,gBAAgB,EAC7B,GAAGC,4BAAuBC,SAAAA,EAAW;AACpCC,QAAAA,gBAAAA,EAAkB,CAACC,GAAAA,GAAAA;YACjB,MAAMV,MAAAA,GAASU,GAAAA,CAAIC,IAAI,EAAEb,UAAAA,CAAWc,KAAK,CAACC,EAAAA,GAAOA,EAAAA,CAAGC,GAAG,KAAKzB,KAAAA,C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,YAAA,GAAGnE,GAAG;YACN,CAACkE,SAAAA,GAAYC,QAAAA,CAASrC;AACxB,SAAA;AACF,IAAA,CAAA,EACA,EAAC,CAAA;IAGH,OAAO;QACLX,MAAAA,EAAQ;AAACqC,YAAAA;AAAe,SAAA;QACxB3E,UAAAA,EAAY+E,uBAAAA;QACZxC,SAAAA,EAAW6C,aAAAA;QACX5C,OAAAA,EAAS;AACP,YAAA,GAAGtC,QAAQsC,OAAO;AAClB,YAAA,GAAGtC,QAAQqF;AACb,SAAA;QACA9C,QAAAA,EAAU;YACR,GAAG5B,IAAAA,CAAKO,SAAS,CAACqB,QAAQ;AAC1B+B,YAAAA,WAAAA,EAAatE,QAAQiF,IAAAA,CAAKX;AAC5B;AACF,KAAA;AACF,CAAA;AAEA;;AAEkG,2GAE5FgB,mCAAAA,GAAsC,IAAA;IAC1C,MAAMC,WAAAA,GAAcC,sBAAAA,CAClB,CAACC,KAAAA,GAAUA,KAAAA,CAAMC,SAAS,CAACH,WAAW,CAACI,cAAc,EAAEC,wBAAAA,CAAAA;IAGzD,qBACE7B,cAAA,CAACC,iBAAK6B,OAAO,EAAA;QAACN,WAAAA,EAAaA,WAAAA;AACzB,QAAA,QAAA,gBAAAxB,cAAA,CAAC5E,0BAAAA,EAAAA,EAAAA;;AAGP;;;;;"}
@@ -180,12 +180,16 @@ import { setIn } from '../utils/objects.mjs';
180
180
  schemas: components
181
181
  });
182
182
  const componentEditAttributes = Object.entries(data.components).reduce((acc, [uid, configuration])=>{
183
+ const componentSchema = components[uid];
184
+ if (!componentSchema) {
185
+ return acc;
186
+ }
183
187
  acc[uid] = {
184
- layout: convertEditLayoutToFieldLayouts(configuration.layouts.edit, components[uid].attributes, configuration.metadatas),
188
+ layout: convertEditLayoutToFieldLayouts(configuration.layouts.edit, componentSchema.attributes, configuration.metadatas),
185
189
  settings: {
186
190
  ...configuration.settings,
187
- icon: components[uid].info.icon,
188
- displayName: components[uid].info.displayName
191
+ icon: componentSchema.info.icon,
192
+ displayName: componentSchema.info.displayName
189
193
  }
190
194
  };
191
195
  return acc;
@@ -1 +1 @@
1
- {"version":3,"file":"ComponentConfigurationPage.mjs","sources":["../../../admin/src/pages/ComponentConfigurationPage.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Page, useNotification, useAPIErrorHandler } from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useParams } from 'react-router-dom';\n\nimport { TEMP_FIELD_NAME } from '../components/ConfigurationForm/Fields';\nimport { ConfigurationForm, ConfigurationFormProps } from '../components/ConfigurationForm/Form';\nimport { ComponentsDictionary, extractContentTypeComponents } from '../hooks/useContentTypeSchema';\nimport {\n DEFAULT_SETTINGS,\n EditLayout,\n convertEditLayoutToFieldLayouts,\n} from '../hooks/useDocumentLayout';\nimport { useTypedSelector } from '../modules/hooks';\nimport {\n useGetComponentConfigurationQuery,\n useUpdateComponentConfigurationMutation,\n} from '../services/components';\nimport { useGetInitialDataQuery } from '../services/init';\nimport { setIn } from '../utils/objects';\n\nimport type { Component, FindComponentConfiguration } from '../../../shared/contracts/components';\nimport type { Metadatas } from '../../../shared/contracts/content-types';\n\n/* -------------------------------------------------------------------------------------------------\n * ComponentConfigurationPage\n * -----------------------------------------------------------------------------------------------*/\n\nconst ComponentConfigurationPage = () => {\n /**\n * useDocumentLayout only works for documents, not components,\n * it feels weird to make that hook work for both when this is SUCH\n * a unique use case and we only do it here, so in short, we essentially\n * just extracted the logic to make an edit view layout and reproduced it here.\n */\n const { slug: model } = useParams<{ slug: string }>();\n const { toggleNotification } = useNotification();\n const { formatMessage } = useIntl();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n\n const {\n components,\n fieldSizes,\n schema,\n error: errorSchema,\n isLoading: isLoadingSchema,\n isFetching: isFetchingSchema,\n } = useGetInitialDataQuery(undefined, {\n selectFromResult: (res) => {\n const schema = res.data?.components.find((ct) => ct.uid === model);\n\n const componentsByKey = res.data?.components.reduce<ComponentsDictionary>(\n (acc, component) => {\n acc[component.uid] = component;\n\n return acc;\n },\n {}\n );\n\n const components = extractContentTypeComponents(schema?.attributes, componentsByKey);\n\n const fieldSizes = Object.entries(res.data?.fieldSizes ?? {}).reduce<\n ConfigurationFormProps['fieldSizes']\n >((acc, [attributeName, { default: size }]) => {\n acc[attributeName] = size;\n\n return acc;\n }, {});\n\n return {\n isFetching: res.isFetching,\n isLoading: res.isLoading,\n error: res.error,\n components,\n schema,\n fieldSizes,\n };\n },\n });\n\n React.useEffect(() => {\n if (errorSchema) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(errorSchema),\n });\n }\n }, [errorSchema, formatAPIError, toggleNotification]);\n\n const {\n data,\n isLoading: isLoadingConfig,\n isFetching: isFetchingConfig,\n error,\n } = useGetComponentConfigurationQuery(model ?? '');\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [error, formatAPIError, toggleNotification]);\n\n /**\n * you **must** check if we're loading or fetching in case the component gets new props\n * but nothing was unmounted, it then becomes a fetch, not a load.\n */\n const isLoading = isLoadingConfig || isLoadingSchema || isFetchingConfig || isFetchingSchema;\n\n const editLayout = React.useMemo(\n () =>\n data && !isLoading\n ? formatEditLayout(data, { schema, components })\n : ({\n layout: [],\n components: {},\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as EditLayout),\n [data, isLoading, schema, components]\n );\n\n const [updateConfiguration] = useUpdateComponentConfigurationMutation();\n const handleSubmit: ConfigurationFormProps['onSubmit'] = async (formData) => {\n try {\n /**\n * We reconstruct the metadatas object by taking the existing list metadatas\n * and re-merging that by attribute name with the current list metadatas, whilst overwriting\n * the data from the form we've built.\n */\n const meta = Object.entries(data?.component.metadatas ?? {}).reduce<Metadatas>(\n (acc, [name, { edit, list }]) => {\n const {\n __temp_key__,\n size: _size,\n name: _name,\n ...editedMetadata\n } = formData.layout.flatMap((row) => row.children).find((field) => field.name === name) ??\n {};\n\n acc[name] = {\n edit: {\n ...edit,\n ...editedMetadata,\n },\n list,\n };\n\n return acc;\n },\n {}\n );\n\n const res = await updateConfiguration({\n layouts: {\n edit: formData.layout.map((row) =>\n row.children.reduce<Array<{ name: string; size: number }>>((acc, { name, size }) => {\n if (name !== TEMP_FIELD_NAME) {\n return [...acc, { name, size }];\n }\n\n return acc;\n }, [])\n ),\n list: data?.component.layouts.list,\n },\n settings: setIn(formData.settings, 'displayName', undefined),\n metadatas: meta,\n uid: model,\n });\n\n if ('data' in res) {\n toggleNotification({\n type: 'success',\n message: formatMessage({ id: 'notification.success.saved', defaultMessage: 'Saved' }),\n });\n } else {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(res.error),\n });\n }\n } catch {\n toggleNotification({\n type: 'danger',\n message: formatMessage({ id: 'notification.error', defaultMessage: 'An error occurred' }),\n });\n }\n };\n\n if (isLoading) {\n return <Page.Loading />;\n }\n\n if (error || errorSchema || !schema) {\n return <Page.Error />;\n }\n\n return (\n <>\n <Page.Title>{`Configure ${editLayout.settings.displayName} Edit View`}</Page.Title>\n <ConfigurationForm\n onSubmit={handleSubmit}\n attributes={schema.attributes}\n fieldSizes={fieldSizes}\n layout={editLayout}\n />\n </>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * Header\n * -----------------------------------------------------------------------------------------------*/\n\nconst formatEditLayout = (\n data: FindComponentConfiguration.Response['data'],\n { schema, components }: { schema?: Component; components: ComponentsDictionary }\n) => {\n const editAttributes = convertEditLayoutToFieldLayouts(\n data.component.layouts.edit,\n schema?.attributes,\n data.component.metadatas,\n { configurations: data.components, schemas: components }\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 ),\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.component.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: [editAttributes],\n components: componentEditAttributes,\n metadatas: editMetadatas,\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n },\n settings: {\n ...data.component.settings,\n displayName: schema?.info.displayName,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * Header\n * -----------------------------------------------------------------------------------------------*/\n\nconst ProtectedComponentConfigurationPage = () => {\n const permissions = useTypedSelector(\n (state) => state.admin_app.permissions.contentManager?.componentsConfigurations\n );\n\n return (\n <Page.Protect permissions={permissions}>\n <ComponentConfigurationPage />\n </Page.Protect>\n );\n};\n\nexport { ComponentConfigurationPage, ProtectedComponentConfigurationPage };\n"],"names":["ComponentConfigurationPage","slug","model","useParams","toggleNotification","useNotification","formatMessage","useIntl","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","components","fieldSizes","schema","error","errorSchema","isLoading","isLoadingSchema","isFetching","isFetchingSchema","useGetInitialDataQuery","undefined","selectFromResult","res","data","find","ct","uid","componentsByKey","reduce","acc","component","extractContentTypeComponents","attributes","Object","entries","attributeName","default","size","React","useEffect","type","message","isLoadingConfig","isFetchingConfig","useGetComponentConfigurationQuery","editLayout","useMemo","formatEditLayout","layout","metadatas","options","settings","DEFAULT_SETTINGS","updateConfiguration","useUpdateComponentConfigurationMutation","handleSubmit","formData","meta","name","edit","list","__temp_key__","_size","_name","editedMetadata","flatMap","row","children","field","layouts","map","TEMP_FIELD_NAME","setIn","id","defaultMessage","_jsx","Page","Loading","Error","_jsxs","_Fragment","Title","displayName","ConfigurationForm","onSubmit","editAttributes","convertEditLayoutToFieldLayouts","configurations","schemas","componentEditAttributes","configuration","icon","info","editMetadatas","attribute","metadata","pluginOptions","ProtectedComponentConfigurationPage","permissions","useTypedSelector","state","admin_app","contentManager","componentsConfigurations","Protect"],"mappings":";;;;;;;;;;;;;;AAyBA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c,EAAEC,wBAAAA,CAAAA;IAGzD,qBACE5B,GAAA,CAACC,KAAK4B,OAAO,EAAA;QAACN,WAAAA,EAAaA,WAAAA;AACzB,QAAA,QAAA,gBAAAvB,GAAA,CAAC5E,0BAAAA,EAAAA,EAAAA;;AAGP;;;;"}
1
+ {"version":3,"file":"ComponentConfigurationPage.mjs","sources":["../../../admin/src/pages/ComponentConfigurationPage.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Page, useNotification, useAPIErrorHandler } from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useParams } from 'react-router-dom';\n\nimport { TEMP_FIELD_NAME } from '../components/ConfigurationForm/Fields';\nimport { ConfigurationForm, ConfigurationFormProps } from '../components/ConfigurationForm/Form';\nimport { ComponentsDictionary, extractContentTypeComponents } from '../hooks/useContentTypeSchema';\nimport {\n DEFAULT_SETTINGS,\n EditLayout,\n convertEditLayoutToFieldLayouts,\n} from '../hooks/useDocumentLayout';\nimport { useTypedSelector } from '../modules/hooks';\nimport {\n useGetComponentConfigurationQuery,\n useUpdateComponentConfigurationMutation,\n} from '../services/components';\nimport { useGetInitialDataQuery } from '../services/init';\nimport { setIn } from '../utils/objects';\n\nimport type { Component, FindComponentConfiguration } from '../../../shared/contracts/components';\nimport type { Metadatas } from '../../../shared/contracts/content-types';\n\n/* -------------------------------------------------------------------------------------------------\n * ComponentConfigurationPage\n * -----------------------------------------------------------------------------------------------*/\n\nconst ComponentConfigurationPage = () => {\n /**\n * useDocumentLayout only works for documents, not components,\n * it feels weird to make that hook work for both when this is SUCH\n * a unique use case and we only do it here, so in short, we essentially\n * just extracted the logic to make an edit view layout and reproduced it here.\n */\n const { slug: model } = useParams<{ slug: string }>();\n const { toggleNotification } = useNotification();\n const { formatMessage } = useIntl();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n\n const {\n components,\n fieldSizes,\n schema,\n error: errorSchema,\n isLoading: isLoadingSchema,\n isFetching: isFetchingSchema,\n } = useGetInitialDataQuery(undefined, {\n selectFromResult: (res) => {\n const schema = res.data?.components.find((ct) => ct.uid === model);\n\n const componentsByKey = res.data?.components.reduce<ComponentsDictionary>(\n (acc, component) => {\n acc[component.uid] = component;\n\n return acc;\n },\n {}\n );\n\n const components = extractContentTypeComponents(schema?.attributes, componentsByKey);\n\n const fieldSizes = Object.entries(res.data?.fieldSizes ?? {}).reduce<\n ConfigurationFormProps['fieldSizes']\n >((acc, [attributeName, { default: size }]) => {\n acc[attributeName] = size;\n\n return acc;\n }, {});\n\n return {\n isFetching: res.isFetching,\n isLoading: res.isLoading,\n error: res.error,\n components,\n schema,\n fieldSizes,\n };\n },\n });\n\n React.useEffect(() => {\n if (errorSchema) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(errorSchema),\n });\n }\n }, [errorSchema, formatAPIError, toggleNotification]);\n\n const {\n data,\n isLoading: isLoadingConfig,\n isFetching: isFetchingConfig,\n error,\n } = useGetComponentConfigurationQuery(model ?? '');\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [error, formatAPIError, toggleNotification]);\n\n /**\n * you **must** check if we're loading or fetching in case the component gets new props\n * but nothing was unmounted, it then becomes a fetch, not a load.\n */\n const isLoading = isLoadingConfig || isLoadingSchema || isFetchingConfig || isFetchingSchema;\n\n const editLayout = React.useMemo(\n () =>\n data && !isLoading\n ? formatEditLayout(data, { schema, components })\n : ({\n layout: [],\n components: {},\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as EditLayout),\n [data, isLoading, schema, components]\n );\n\n const [updateConfiguration] = useUpdateComponentConfigurationMutation();\n const handleSubmit: ConfigurationFormProps['onSubmit'] = async (formData) => {\n try {\n /**\n * We reconstruct the metadatas object by taking the existing list metadatas\n * and re-merging that by attribute name with the current list metadatas, whilst overwriting\n * the data from the form we've built.\n */\n const meta = Object.entries(data?.component.metadatas ?? {}).reduce<Metadatas>(\n (acc, [name, { edit, list }]) => {\n const {\n __temp_key__,\n size: _size,\n name: _name,\n ...editedMetadata\n } = formData.layout.flatMap((row) => row.children).find((field) => field.name === name) ??\n {};\n\n acc[name] = {\n edit: {\n ...edit,\n ...editedMetadata,\n },\n list,\n };\n\n return acc;\n },\n {}\n );\n\n const res = await updateConfiguration({\n layouts: {\n edit: formData.layout.map((row) =>\n row.children.reduce<Array<{ name: string; size: number }>>((acc, { name, size }) => {\n if (name !== TEMP_FIELD_NAME) {\n return [...acc, { name, size }];\n }\n\n return acc;\n }, [])\n ),\n list: data?.component.layouts.list,\n },\n settings: setIn(formData.settings, 'displayName', undefined),\n metadatas: meta,\n uid: model,\n });\n\n if ('data' in res) {\n toggleNotification({\n type: 'success',\n message: formatMessage({ id: 'notification.success.saved', defaultMessage: 'Saved' }),\n });\n } else {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(res.error),\n });\n }\n } catch {\n toggleNotification({\n type: 'danger',\n message: formatMessage({ id: 'notification.error', defaultMessage: 'An error occurred' }),\n });\n }\n };\n\n if (isLoading) {\n return <Page.Loading />;\n }\n\n if (error || errorSchema || !schema) {\n return <Page.Error />;\n }\n\n return (\n <>\n <Page.Title>{`Configure ${editLayout.settings.displayName} Edit View`}</Page.Title>\n <ConfigurationForm\n onSubmit={handleSubmit}\n attributes={schema.attributes}\n fieldSizes={fieldSizes}\n layout={editLayout}\n />\n </>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * Header\n * -----------------------------------------------------------------------------------------------*/\n\nconst formatEditLayout = (\n data: FindComponentConfiguration.Response['data'],\n { schema, components }: { schema?: Component; components: ComponentsDictionary }\n) => {\n const editAttributes = convertEditLayoutToFieldLayouts(\n data.component.layouts.edit,\n schema?.attributes,\n data.component.metadatas,\n { configurations: data.components, schemas: components }\n );\n\n const componentEditAttributes = Object.entries(data.components).reduce<EditLayout['components']>(\n (acc, [uid, configuration]) => {\n const componentSchema = components[uid];\n if (!componentSchema) {\n return acc;\n }\n\n acc[uid] = {\n layout: convertEditLayoutToFieldLayouts(\n configuration.layouts.edit,\n componentSchema.attributes,\n configuration.metadatas\n ),\n settings: {\n ...configuration.settings,\n icon: componentSchema.info.icon,\n displayName: componentSchema.info.displayName,\n },\n };\n return acc;\n },\n {}\n );\n\n const editMetadatas = Object.entries(data.component.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: [editAttributes],\n components: componentEditAttributes,\n metadatas: editMetadatas,\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n },\n settings: {\n ...data.component.settings,\n displayName: schema?.info.displayName,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * Header\n * -----------------------------------------------------------------------------------------------*/\n\nconst ProtectedComponentConfigurationPage = () => {\n const permissions = useTypedSelector(\n (state) => state.admin_app.permissions.contentManager?.componentsConfigurations\n );\n\n return (\n <Page.Protect permissions={permissions}>\n <ComponentConfigurationPage />\n </Page.Protect>\n );\n};\n\nexport { ComponentConfigurationPage, ProtectedComponentConfigurationPage };\n"],"names":["ComponentConfigurationPage","slug","model","useParams","toggleNotification","useNotification","formatMessage","useIntl","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","components","fieldSizes","schema","error","errorSchema","isLoading","isLoadingSchema","isFetching","isFetchingSchema","useGetInitialDataQuery","undefined","selectFromResult","res","data","find","ct","uid","componentsByKey","reduce","acc","component","extractContentTypeComponents","attributes","Object","entries","attributeName","default","size","React","useEffect","type","message","isLoadingConfig","isFetchingConfig","useGetComponentConfigurationQuery","editLayout","useMemo","formatEditLayout","layout","metadatas","options","settings","DEFAULT_SETTINGS","updateConfiguration","useUpdateComponentConfigurationMutation","handleSubmit","formData","meta","name","edit","list","__temp_key__","_size","_name","editedMetadata","flatMap","row","children","field","layouts","map","TEMP_FIELD_NAME","setIn","id","defaultMessage","_jsx","Page","Loading","Error","_jsxs","_Fragment","Title","displayName","ConfigurationForm","onSubmit","editAttributes","convertEditLayoutToFieldLayouts","configurations","schemas","componentEditAttributes","configuration","componentSchema","icon","info","editMetadatas","attribute","metadata","pluginOptions","ProtectedComponentConfigurationPage","permissions","useTypedSelector","state","admin_app","contentManager","componentsConfigurations","Protect"],"mappings":";;;;;;;;;;;;;;AAyBA;;AAEkG,2GAE5FA,0BAAAA,GAA6B,IAAA;AACjC;;;;;AAKC,MACD,MAAM,EAAEC,IAAAA,EAAMC,KAAK,EAAE,GAAGC,SAAAA,EAAAA;IACxB,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,eAAAA,EAAAA;IAC/B,MAAM,EAAEC,aAAa,EAAE,GAAGC,OAAAA,EAAAA;AAC1B,IAAA,MAAM,EAAEC,uBAAAA,EAAyBC,cAAc,EAAE,GAAGC,kBAAAA,EAAAA;AAEpD,IAAA,MAAM,EACJC,UAAU,EACVC,UAAU,EACVC,MAAM,EACNC,KAAAA,EAAOC,WAAW,EAClBC,SAAAA,EAAWC,eAAe,EAC1BC,UAAAA,EAAYC,gBAAgB,EAC7B,GAAGC,uBAAuBC,SAAAA,EAAW;AACpCC,QAAAA,gBAAAA,EAAkB,CAACC,GAAAA,GAAAA;YACjB,MAAMV,MAAAA,GAASU,GAAAA,CAAIC,IAAI,EAAEb,UAAAA,CAAWc,KAAK,CAACC,EAAAA,GAAOA,EAAAA,CAAGC,GAAG,KAAKzB,KAAAA,CAAAA;AAE5D,YAAA,MAAM0B,kBAAkBL,GAAAA,CAAIC,IAAI,EAAEb,UAAAA,CAAWkB,MAAAA,CAC3C,CAACC,GAAAA,EAAKC,SAAAA,GAAAA;AACJD,gBAAAA,GAAG,CAACC,SAAAA,CAAUJ,GAAG,CAAC,GAAGI,SAAAA;gBAErB,OAAOD,GAAAA;AACT,YAAA,CAAA,EACA,EAAC,CAAA;YAGH,MAAMnB,UAAAA,GAAaqB,4BAAAA,CAA6BnB,MAAAA,EAAQoB,UAAAA,EAAYL,eAAAA,CAAAA;YAEpE,MAAMhB,UAAAA,GAAasB,OAAOC,O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1B+B,YAAAA,WAAAA,EAAatE,QAAQiF,IAAAA,CAAKX;AAC5B;AACF,KAAA;AACF,CAAA;AAEA;;AAEkG,2GAE5FgB,mCAAAA,GAAsC,IAAA;IAC1C,MAAMC,WAAAA,GAAcC,gBAAAA,CAClB,CAACC,KAAAA,GAAUA,KAAAA,CAAMC,SAAS,CAACH,WAAW,CAACI,cAAc,EAAEC,wBAAAA,CAAAA;IAGzD,qBACE7B,GAAA,CAACC,KAAK6B,OAAO,EAAA;QAACN,WAAAA,EAAaA,WAAAA;AACzB,QAAA,QAAA,gBAAAxB,GAAA,CAAC5E,0BAAAA,EAAAA,EAAAA;;AAGP;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strapi/content-manager",
3
- "version": "5.45.0",
3
+ "version": "5.45.1",
4
4
  "description": "A powerful UI to easily manage your data.",
5
5
  "homepage": "https://strapi.io",
6
6
  "bugs": {
@@ -74,8 +74,8 @@
74
74
  "@sindresorhus/slugify": "1.1.0",
75
75
  "@strapi/design-system": "2.2.0",
76
76
  "@strapi/icons": "2.2.0",
77
- "@strapi/types": "5.45.0",
78
- "@strapi/utils": "5.45.0",
77
+ "@strapi/types": "5.45.1",
78
+ "@strapi/utils": "5.45.1",
79
79
  "codemirror5": "npm:codemirror@^5.65.11",
80
80
  "date-fns": "2.30.0",
81
81
  "fractional-indexing": "3.2.0",
@@ -109,8 +109,8 @@
109
109
  "yup": "0.32.9"
110
110
  },
111
111
  "devDependencies": {
112
- "@strapi/admin": "5.45.0",
113
- "@strapi/database": "5.45.0",
112
+ "@strapi/admin": "5.45.1",
113
+ "@strapi/database": "5.45.1",
114
114
  "@testing-library/react": "16.3.0",
115
115
  "@types/jest": "29.5.2",
116
116
  "@types/lodash": "^4.14.191",