@strapi/content-manager 5.41.1 → 5.42.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.
Files changed (39) hide show
  1. package/dist/admin/components/ConfigurationForm/Fields.js +21 -13
  2. package/dist/admin/components/ConfigurationForm/Fields.js.map +1 -1
  3. package/dist/admin/components/ConfigurationForm/Fields.mjs +21 -13
  4. package/dist/admin/components/ConfigurationForm/Fields.mjs.map +1 -1
  5. package/dist/admin/hooks/useContentManagerInitData.js +35 -17
  6. package/dist/admin/hooks/useContentManagerInitData.js.map +1 -1
  7. package/dist/admin/hooks/useContentManagerInitData.mjs +36 -18
  8. package/dist/admin/hooks/useContentManagerInitData.mjs.map +1 -1
  9. package/dist/admin/hooks/useDocument.js +4 -1
  10. package/dist/admin/hooks/useDocument.js.map +1 -1
  11. package/dist/admin/hooks/useDocument.mjs +4 -1
  12. package/dist/admin/hooks/useDocument.mjs.map +1 -1
  13. package/dist/admin/hooks/useDocumentLayout.js +17 -1
  14. package/dist/admin/hooks/useDocumentLayout.js.map +1 -1
  15. package/dist/admin/hooks/useDocumentLayout.mjs +17 -1
  16. package/dist/admin/hooks/useDocumentLayout.mjs.map +1 -1
  17. package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.js +13 -1
  18. package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.js.map +1 -1
  19. package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.mjs +13 -1
  20. package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.mjs.map +1 -1
  21. package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/Editor.js +17 -4
  22. package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/Editor.js.map +1 -1
  23. package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/Editor.mjs +17 -4
  24. package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/Editor.mjs.map +1 -1
  25. package/dist/admin/pages/EditView/utils/data.js +1 -1
  26. package/dist/admin/pages/EditView/utils/data.js.map +1 -1
  27. package/dist/admin/pages/EditView/utils/data.mjs +1 -1
  28. package/dist/admin/pages/EditView/utils/data.mjs.map +1 -1
  29. package/dist/admin/pages/ListView/ListViewPage.js +8 -4
  30. package/dist/admin/pages/ListView/ListViewPage.js.map +1 -1
  31. package/dist/admin/pages/ListView/ListViewPage.mjs +8 -4
  32. package/dist/admin/pages/ListView/ListViewPage.mjs.map +1 -1
  33. package/dist/admin/src/hooks/useDocument.d.ts +5 -0
  34. package/dist/admin/src/hooks/useDocumentLayout.d.ts +19 -0
  35. package/dist/admin/translations/pl.json.js +184 -34
  36. package/dist/admin/translations/pl.json.js.map +1 -1
  37. package/dist/admin/translations/pl.json.mjs +184 -34
  38. package/dist/admin/translations/pl.json.mjs.map +1 -1
  39. package/package.json +6 -6
@@ -79,7 +79,10 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
79
79
  }
80
80
  // When it's a singleType without a mainField, use the contentType displayName
81
81
  if (schema?.kind === 'singleType' && schema.info.displayName) {
82
- return schema.info.displayName;
82
+ return formatMessage({
83
+ id: schema.info.displayName,
84
+ defaultMessage: schema.info.displayName
85
+ });
83
86
  }
84
87
  // Otherwise, use a fallback
85
88
  return formatMessage({
@@ -1 +1 @@
1
- {"version":3,"file":"useDocument.js","sources":["../../../admin/src/hooks/useDocument.ts"],"sourcesContent":["/**\n * This hook doesn't use a context provider because we fetch directly from the server,\n * this sounds expensive but actually, it's really not. Because we have redux-toolkit-query\n * being a cache layer so if nothing invalidates the cache, we don't fetch again.\n */\n\nimport * as React from 'react';\n\nimport {\n useNotification,\n useAPIErrorHandler,\n useQueryParams,\n FormErrors,\n getYupValidationErrors,\n useForm,\n} from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useParams } from 'react-router-dom';\nimport { ValidationError } from 'yup';\n\nimport { SINGLE_TYPES } from '../constants/collections';\nimport { type AnyData, transformDocument } from '../pages/EditView/utils/data';\nimport { createDefaultForm } from '../pages/EditView/utils/forms';\nimport { useGetDocumentQuery } from '../services/documents';\nimport { buildValidParams } from '../utils/api';\nimport { createYupSchema } from '../utils/validation';\n\nimport { useContentTypeSchema, ComponentsDictionary } from './useContentTypeSchema';\nimport { useDocumentLayout } from './useDocumentLayout';\n\nimport type { FindOne } from '../../../shared/contracts/collection-types';\nimport type { ContentType } from '../../../shared/contracts/content-types';\nimport type { Modules } from '@strapi/types';\n\ninterface UseDocumentArgs {\n collectionType: string;\n model: string;\n documentId?: string;\n params?: object;\n}\n\ntype UseDocumentOpts = Parameters<typeof useGetDocumentQuery>[1];\n\ntype Document = FindOne.Response['data'];\n\ntype Schema = ContentType;\n\ntype UseDocument = (\n args: UseDocumentArgs,\n opts?: UseDocumentOpts\n) => {\n /**\n * These are the schemas of the components used in the content type, organised\n * by their uid.\n */\n components: ComponentsDictionary;\n document?: Document;\n meta?: FindOne.Response['meta'];\n isLoading: boolean;\n /**\n * This is the schema of the content type, it is not the same as the layout.\n */\n schema?: Schema;\n schemas?: Schema[];\n hasError?: boolean;\n refetch: () => void;\n validate: (document: Document) => null | FormErrors;\n /**\n * Get the document's title\n */\n getTitle: (mainField: string) => string;\n /**\n * Get the initial form values for the document\n */\n getInitialFormValues: (isCreatingDocument?: boolean) => AnyData | undefined;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDocument\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @alpha\n * @public\n * @description Returns a document based on the model, collection type & id passed as arguments.\n * Also extracts its schema from the redux cache to be used for creating a validation schema.\n * @example\n * ```tsx\n * const { id, model, collectionType } = useParams<{ id: string; model: string; collectionType: string }>();\n *\n * if(!model || !collectionType) return null;\n *\n * const { document, isLoading, validate } = useDocument({ documentId: id, model, collectionType, params: { locale: 'en-GB' } })\n * const { update } = useDocumentActions()\n *\n * const onSubmit = async (document: Document) => {\n * const errors = validate(document);\n *\n * if(errors) {\n * // handle errors\n * }\n *\n * await update({ collectionType, model, id }, document)\n * }\n * ```\n *\n */\nconst useDocument: UseDocument = (args, opts) => {\n const { toggleNotification } = useNotification();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n const { formatMessage } = useIntl();\n\n const {\n currentData: data,\n isLoading: isLoadingDocument,\n isFetching: isFetchingDocument,\n error,\n refetch,\n } = useGetDocumentQuery(args, {\n ...opts,\n skip: (!args.documentId && args.collectionType !== SINGLE_TYPES) || opts?.skip,\n });\n const document = data?.data;\n const meta = data?.meta;\n\n const {\n components,\n schema,\n schemas,\n isLoading: isLoadingSchema,\n } = useContentTypeSchema(args.model);\n const isSingleType = schema?.kind === 'singleType';\n\n const getTitle = React.useCallback(\n (mainField: string) => {\n // Always use mainField if it's not an id\n if (mainField !== 'id' && document?.[mainField]) {\n return document[mainField];\n }\n\n // When it's a singleType without a mainField, use the contentType displayName\n if (schema?.kind === 'singleType' && schema.info.displayName) {\n return schema.info.displayName;\n }\n\n // Otherwise, use a fallback\n return formatMessage({\n id: 'content-manager.containers.untitled',\n defaultMessage: 'Untitled',\n });\n },\n [document, formatMessage, schema]\n );\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [toggleNotification, error, formatAPIError, args.collectionType]);\n\n const validationSchema = React.useMemo(() => {\n if (!schema) {\n return null;\n }\n\n return createYupSchema(schema.attributes, components);\n }, [schema, components]);\n\n const validate = React.useCallback(\n (document: Modules.Documents.AnyDocument): FormErrors | null => {\n if (!validationSchema) {\n throw new Error(\n 'There is no validation schema generated, this is likely due to the schema not being loaded yet.'\n );\n }\n\n try {\n validationSchema.validateSync(document, { abortEarly: false, strict: true });\n return null;\n } catch (error) {\n if (error instanceof ValidationError) {\n return getYupValidationErrors(error);\n }\n\n throw error;\n }\n },\n [validationSchema]\n );\n\n /**\n * Here we prepare the form for editing, we need to:\n * - remove prohibited fields from the document (passwords | ADD YOURS WHEN THERES A NEW ONE)\n * - swap out count objects on relations for empty arrays\n * - set __temp_key__ on array objects for drag & drop\n *\n * We also prepare the form for new documents, so we need to:\n * - set default values on fields\n */\n const getInitialFormValues = React.useCallback(\n (isCreatingDocument: boolean = false) => {\n if ((!document && !isCreatingDocument && !isSingleType) || !schema) {\n return undefined;\n }\n\n /**\n * Check that we have an ID so we know the\n * document has been created in some way.\n */\n const form = document?.id ? document : createDefaultForm(schema, components);\n\n return transformDocument(schema, components)(form);\n },\n [document, isSingleType, schema, components]\n );\n\n const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;\n const hasError = !!error;\n\n return React.useMemo(\n () =>\n ({\n components,\n document,\n meta,\n isLoading,\n hasError,\n schema,\n schemas,\n validate,\n getTitle,\n getInitialFormValues,\n refetch,\n }) satisfies ReturnType<UseDocument>,\n [\n components,\n document,\n meta,\n isLoading,\n hasError,\n schema,\n schemas,\n validate,\n getTitle,\n getInitialFormValues,\n refetch,\n ]\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDoc\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal this hook uses the router to extract the model, collection type & id from the url.\n * therefore, it shouldn't be used outside of the content-manager because it won't work as intended.\n */\nconst useDoc = () => {\n const { id, slug, collectionType, origin } = useParams<{\n id: string;\n origin: string;\n slug: string;\n collectionType: string;\n }>();\n const [{ query }] = useQueryParams();\n const params = React.useMemo(() => buildValidParams(query), [query]);\n\n if (!collectionType) {\n throw new Error('Could not find collectionType in url params');\n }\n\n if (!slug) {\n throw new Error('Could not find model in url params');\n }\n\n const document = useDocument(\n { documentId: origin || id, model: slug, collectionType, params },\n {\n skip: id === 'create' || (!origin && !id && collectionType !== SINGLE_TYPES),\n }\n );\n\n const returnId = origin || (id === 'create' ? undefined : id);\n\n return {\n collectionType,\n model: slug,\n id: returnId,\n ...document,\n };\n};\n\n/**\n * @public\n * @experimental\n * Content manager context hooks for plugin development.\n * Make sure to use this hook inside the content manager.\n */\nconst useContentManagerContext = () => {\n const {\n collectionType,\n model,\n id,\n components,\n isLoading: isLoadingDoc,\n schema,\n schemas,\n } = useDoc();\n\n const layout = useDocumentLayout(model);\n\n const form = useForm<unknown>('useContentManagerContext', (state) => state);\n\n const isSingleType = collectionType === SINGLE_TYPES;\n const slug = model;\n const isCreatingEntry = id === 'create';\n\n const {} = useContentTypeSchema();\n\n const isLoading = isLoadingDoc || layout.isLoading;\n const error = layout.error;\n\n return {\n error,\n isLoading,\n\n // Base metadata\n model,\n collectionType,\n id,\n slug,\n isCreatingEntry,\n isSingleType,\n hasDraftAndPublish: schema?.options?.draftAndPublish ?? false,\n\n // All schema infos\n components,\n contentType: schema,\n contentTypes: schemas,\n\n // Form state\n form,\n\n // layout infos\n layout,\n };\n};\n\nexport { useDocument, useDoc, useContentManagerContext };\nexport type { UseDocument, UseDocumentArgs, Document, Schema, ComponentsDictionary };\n"],"names":["useDocument","args","opts","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","formatMessage","useIntl","currentData","data","isLoading","isLoadingDocument","isFetching","isFetchingDocument","error","refetch","useGetDocumentQuery","skip","documentId","collectionType","SINGLE_TYPES","document","meta","components","schema","schemas","isLoadingSchema","useContentTypeSchema","model","isSingleType","kind","getTitle","React","useCallback","mainField","info","displayName","id","defaultMessage","useEffect","type","message","validationSchema","useMemo","createYupSchema","attributes","validate","Error","validateSync","abortEarly","strict","ValidationError","getYupValidationErrors","getInitialFormValues","isCreatingDocument","undefined","form","createDefaultForm","transformDocument","hasError","useDoc","slug","origin","useParams","query","useQueryParams","params","buildValidParams","returnId","useContentManagerContext","isLoadingDoc","layout","useDocumentLayout","useForm","state","isCreatingEntry","hasDraftAndPublish","options","draftAndPublish","contentType","contentTypes"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EA;;;;;;;;;;;;;;;;;;;;;;;;;;;IA8BA,MAAMA,WAAAA,GAA2B,CAACC,IAAAA,EAAMC,IAAAA,GAAAA;IACtC,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,2BAAAA,EAAAA;AAC/B,IAAA,MAA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AM,EACNC,OAAO,EACR,GAAGmC,MAAAA,EAAAA;AAEJ,IAAA,MAAMW,SAASC,mCAAAA,CAAkB5C,KAAAA,CAAAA;AAEjC,IAAA,MAAM4B,IAAAA,GAAOiB,mBAAAA,CAAiB,0BAAA,EAA4B,CAACC,KAAAA,GAAUA,KAAAA,CAAAA;AAErE,IAAA,MAAM7C,eAAeV,cAAAA,KAAmBC,wBAAAA;AACxC,IAAA,MAAMyC,IAAAA,GAAOjC,KAAAA;AACb,IAAA,MAAM+C,kBAAkBtC,EAAAA,KAAO,QAAA;AAE/B,IAAWV,yCAAAA;IAEX,MAAMjB,SAAAA,GAAY4D,YAAAA,IAAgBC,MAAAA,CAAO7D,SAAS;IAClD,MAAMI,KAAAA,GAAQyD,OAAOzD,KAAK;IAE1B,OAAO;AACLA,QAAAA,KAAAA;AACAJ,QAAAA,SAAAA;;AAGAkB,QAAAA,KAAAA;AACAT,QAAAA,cAAAA;AACAkB,QAAAA,EAAAA;AACAwB,QAAAA,IAAAA;AACAc,QAAAA,eAAAA;AACA9C,QAAAA,YAAAA;QACA+C,kBAAAA,EAAoBpD,MAAAA,EAAQqD,SAASC,eAAAA,IAAmB,KAAA;;AAGxDvD,QAAAA,UAAAA;QACAwD,WAAAA,EAAavD,MAAAA;QACbwD,YAAAA,EAAcvD,OAAAA;;AAGd+B,QAAAA,IAAAA;;AAGAe,QAAAA;AACF,KAAA;AACF;;;;;;"}
1
+ {"version":3,"file":"useDocument.js","sources":["../../../admin/src/hooks/useDocument.ts"],"sourcesContent":["/**\n * This hook doesn't use a context provider because we fetch directly from the server,\n * this sounds expensive but actually, it's really not. Because we have redux-toolkit-query\n * being a cache layer so if nothing invalidates the cache, we don't fetch again.\n */\n\nimport * as React from 'react';\n\nimport {\n useNotification,\n useAPIErrorHandler,\n useQueryParams,\n FormErrors,\n getYupValidationErrors,\n useForm,\n} from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useParams } from 'react-router-dom';\nimport { ValidationError } from 'yup';\n\nimport { SINGLE_TYPES } from '../constants/collections';\nimport { type AnyData, transformDocument } from '../pages/EditView/utils/data';\nimport { createDefaultForm } from '../pages/EditView/utils/forms';\nimport { useGetDocumentQuery } from '../services/documents';\nimport { buildValidParams } from '../utils/api';\nimport { createYupSchema } from '../utils/validation';\n\nimport { useContentTypeSchema, ComponentsDictionary } from './useContentTypeSchema';\nimport { useDocumentLayout } from './useDocumentLayout';\n\nimport type { FindOne } from '../../../shared/contracts/collection-types';\nimport type { ContentType } from '../../../shared/contracts/content-types';\nimport type { Modules } from '@strapi/types';\n\ninterface UseDocumentArgs {\n collectionType: string;\n model: string;\n documentId?: string;\n params?: object;\n}\n\ntype UseDocumentOpts = Parameters<typeof useGetDocumentQuery>[1];\n\ntype Document = FindOne.Response['data'];\n\ntype Schema = ContentType;\n\ntype UseDocument = (\n args: UseDocumentArgs,\n opts?: UseDocumentOpts\n) => {\n /**\n * These are the schemas of the components used in the content type, organised\n * by their uid.\n */\n components: ComponentsDictionary;\n document?: Document;\n meta?: FindOne.Response['meta'];\n isLoading: boolean;\n /**\n * This is the schema of the content type, it is not the same as the layout.\n */\n schema?: Schema;\n schemas?: Schema[];\n hasError?: boolean;\n refetch: () => void;\n validate: (document: Document) => null | FormErrors;\n /**\n * Get the document's title\n */\n getTitle: (mainField: string) => string;\n /**\n * Get the initial form values for the document\n */\n getInitialFormValues: (isCreatingDocument?: boolean) => AnyData | undefined;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDocument\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @alpha\n * @public\n * @description Returns a document based on the model, collection type & id passed as arguments.\n * Also extracts its schema from the redux cache to be used for creating a validation schema.\n * @example\n * ```tsx\n * const { id, model, collectionType } = useParams<{ id: string; model: string; collectionType: string }>();\n *\n * if(!model || !collectionType) return null;\n *\n * const { document, isLoading, validate } = useDocument({ documentId: id, model, collectionType, params: { locale: 'en-GB' } })\n * const { update } = useDocumentActions()\n *\n * const onSubmit = async (document: Document) => {\n * const errors = validate(document);\n *\n * if(errors) {\n * // handle errors\n * }\n *\n * await update({ collectionType, model, id }, document)\n * }\n * ```\n *\n */\nconst useDocument: UseDocument = (args, opts) => {\n const { toggleNotification } = useNotification();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n const { formatMessage } = useIntl();\n\n const {\n currentData: data,\n isLoading: isLoadingDocument,\n isFetching: isFetchingDocument,\n error,\n refetch,\n } = useGetDocumentQuery(args, {\n ...opts,\n skip: (!args.documentId && args.collectionType !== SINGLE_TYPES) || opts?.skip,\n });\n const document = data?.data;\n const meta = data?.meta;\n\n const {\n components,\n schema,\n schemas,\n isLoading: isLoadingSchema,\n } = useContentTypeSchema(args.model);\n const isSingleType = schema?.kind === 'singleType';\n\n const getTitle = React.useCallback(\n (mainField: string) => {\n // Always use mainField if it's not an id\n if (mainField !== 'id' && document?.[mainField]) {\n return document[mainField];\n }\n\n // When it's a singleType without a mainField, use the contentType displayName\n if (schema?.kind === 'singleType' && schema.info.displayName) {\n return formatMessage({\n id: schema.info.displayName,\n defaultMessage: schema.info.displayName,\n });\n }\n\n // Otherwise, use a fallback\n return formatMessage({\n id: 'content-manager.containers.untitled',\n defaultMessage: 'Untitled',\n });\n },\n [document, formatMessage, schema]\n );\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [toggleNotification, error, formatAPIError, args.collectionType]);\n\n const validationSchema = React.useMemo(() => {\n if (!schema) {\n return null;\n }\n\n return createYupSchema(schema.attributes, components);\n }, [schema, components]);\n\n const validate = React.useCallback(\n (document: Modules.Documents.AnyDocument): FormErrors | null => {\n if (!validationSchema) {\n throw new Error(\n 'There is no validation schema generated, this is likely due to the schema not being loaded yet.'\n );\n }\n\n try {\n validationSchema.validateSync(document, { abortEarly: false, strict: true });\n return null;\n } catch (error) {\n if (error instanceof ValidationError) {\n return getYupValidationErrors(error);\n }\n\n throw error;\n }\n },\n [validationSchema]\n );\n\n /**\n * Here we prepare the form for editing, we need to:\n * - remove prohibited fields from the document (passwords | ADD YOURS WHEN THERES A NEW ONE)\n * - swap out count objects on relations for empty arrays\n * - set __temp_key__ on array objects for drag & drop\n *\n * We also prepare the form for new documents, so we need to:\n * - set default values on fields\n */\n const getInitialFormValues = React.useCallback(\n (isCreatingDocument: boolean = false) => {\n if ((!document && !isCreatingDocument && !isSingleType) || !schema) {\n return undefined;\n }\n\n /**\n * Check that we have an ID so we know the\n * document has been created in some way.\n */\n const form = document?.id ? document : createDefaultForm(schema, components);\n\n return transformDocument(schema, components)(form);\n },\n [document, isSingleType, schema, components]\n );\n\n const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;\n const hasError = !!error;\n\n return React.useMemo(\n () =>\n ({\n components,\n document,\n meta,\n isLoading,\n hasError,\n schema,\n schemas,\n validate,\n getTitle,\n getInitialFormValues,\n refetch,\n }) satisfies ReturnType<UseDocument>,\n [\n components,\n document,\n meta,\n isLoading,\n hasError,\n schema,\n schemas,\n validate,\n getTitle,\n getInitialFormValues,\n refetch,\n ]\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDoc\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal this hook uses the router to extract the model, collection type & id from the url.\n * therefore, it shouldn't be used outside of the content-manager because it won't work as intended.\n */\nconst useDoc = () => {\n const { id, slug, collectionType, origin } = useParams<{\n id: string;\n origin: string;\n slug: string;\n collectionType: string;\n }>();\n const [{ query }] = useQueryParams();\n const params = React.useMemo(() => buildValidParams(query), [query]);\n\n if (!collectionType) {\n throw new Error('Could not find collectionType in url params');\n }\n\n if (!slug) {\n throw new Error('Could not find model in url params');\n }\n\n const document = useDocument(\n { documentId: origin || id, model: slug, collectionType, params },\n {\n skip: id === 'create' || (!origin && !id && collectionType !== SINGLE_TYPES),\n }\n );\n\n const returnId = origin || (id === 'create' ? undefined : id);\n\n return {\n collectionType,\n model: slug,\n id: returnId,\n ...document,\n };\n};\n\n/**\n * @public\n * @experimental\n * Content manager context hooks for plugin development.\n * Make sure to use this hook inside the content manager.\n */\nconst useContentManagerContext = () => {\n const {\n collectionType,\n model,\n id,\n components,\n isLoading: isLoadingDoc,\n schema,\n schemas,\n } = useDoc();\n\n const layout = useDocumentLayout(model);\n\n const form = useForm<unknown>('useContentManagerContext', (state) => state);\n\n const isSingleType = collectionType === SINGLE_TYPES;\n const slug = model;\n const isCreatingEntry = id === 'create';\n\n const {} = useContentTypeSchema();\n\n const isLoading = isLoadingDoc || layout.isLoading;\n const error = layout.error;\n\n return {\n error,\n isLoading,\n\n // Base metadata\n model,\n collectionType,\n id,\n slug,\n isCreatingEntry,\n isSingleType,\n hasDraftAndPublish: schema?.options?.draftAndPublish ?? false,\n\n // All schema infos\n components,\n contentType: schema,\n contentTypes: schemas,\n\n // Form state\n form,\n\n // layout infos\n layout,\n };\n};\n\nexport { useDocument, useDoc, useContentManagerContext };\nexport type { UseDocument, UseDocumentArgs, Document, Schema, ComponentsDictionary };\n"],"names":["useDocument","args","opts","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","formatMessage","useIntl","currentData","data","isLoading","isLoadingDocument","isFetching","isFetchingDocument","error","refetch","useGetDocumentQuery","skip","documentId","collectionType","SINGLE_TYPES","document","meta","components","schema","schemas","isLoadingSchema","useContentTypeSchema","model","isSingleType","kind","getTitle","React","useCallback","mainField","info","displayName","id","defaultMessage","useEffect","type","message","validationSchema","useMemo","createYupSchema","attributes","validate","Error","validateSync","abortEarly","strict","ValidationError","getYupValidationErrors","getInitialFormValues","isCreatingDocument","undefined","form","createDefaultForm","transformDocument","hasError","useDoc","slug","origin","useParams","query","useQueryParams","params","buildValidParams","returnId","useContentManagerContext","isLoadingDoc","layout","useDocumentLayout","useForm","state","isCreatingEntry","hasDraftAndPublish","options","draftAndPublish","contentType","contentTypes"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EA;;;;;;;;;;;;;;;;;;;;;;;;;;;IA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QACAS,KAAAA,EAAOiC,IAAAA;QACPxB,EAAAA,EAAI+B,QAAAA;AACJ,QAAA,GAAG/C;AACL,KAAA;AACF;AAEA;;;;;AAKC,UACKgD,wBAAAA,GAA2B,IAAA;AAC/B,IAAA,MAAM,EACJlD,cAAc,EACdS,KAAK,EACLS,EAAE,EACFd,UAAU,EACVb,SAAAA,EAAW4D,YAAY,EACvB9C,MAAM,EACNC,OAAO,EACR,GAAGmC,MAAAA,EAAAA;AAEJ,IAAA,MAAMW,SAASC,mCAAAA,CAAkB5C,KAAAA,CAAAA;AAEjC,IAAA,MAAM4B,IAAAA,GAAOiB,mBAAAA,CAAiB,0BAAA,EAA4B,CAACC,KAAAA,GAAUA,KAAAA,CAAAA;AAErE,IAAA,MAAM7C,eAAeV,cAAAA,KAAmBC,wBAAAA;AACxC,IAAA,MAAMyC,IAAAA,GAAOjC,KAAAA;AACb,IAAA,MAAM+C,kBAAkBtC,EAAAA,KAAO,QAAA;AAE/B,IAAWV,yCAAAA;IAEX,MAAMjB,SAAAA,GAAY4D,YAAAA,IAAgBC,MAAAA,CAAO7D,SAAS;IAClD,MAAMI,KAAAA,GAAQyD,OAAOzD,KAAK;IAE1B,OAAO;AACLA,QAAAA,KAAAA;AACAJ,QAAAA,SAAAA;;AAGAkB,QAAAA,KAAAA;AACAT,QAAAA,cAAAA;AACAkB,QAAAA,EAAAA;AACAwB,QAAAA,IAAAA;AACAc,QAAAA,eAAAA;AACA9C,QAAAA,YAAAA;QACA+C,kBAAAA,EAAoBpD,MAAAA,EAAQqD,SAASC,eAAAA,IAAmB,KAAA;;AAGxDvD,QAAAA,UAAAA;QACAwD,WAAAA,EAAavD,MAAAA;QACbwD,YAAAA,EAAcvD,OAAAA;;AAGd+B,QAAAA,IAAAA;;AAGAe,QAAAA;AACF,KAAA;AACF;;;;;;"}
@@ -58,7 +58,10 @@ import { useDocumentLayout } from './useDocumentLayout.mjs';
58
58
  }
59
59
  // When it's a singleType without a mainField, use the contentType displayName
60
60
  if (schema?.kind === 'singleType' && schema.info.displayName) {
61
- return schema.info.displayName;
61
+ return formatMessage({
62
+ id: schema.info.displayName,
63
+ defaultMessage: schema.info.displayName
64
+ });
62
65
  }
63
66
  // Otherwise, use a fallback
64
67
  return formatMessage({
@@ -1 +1 @@
1
- {"version":3,"file":"useDocument.mjs","sources":["../../../admin/src/hooks/useDocument.ts"],"sourcesContent":["/**\n * This hook doesn't use a context provider because we fetch directly from the server,\n * this sounds expensive but actually, it's really not. Because we have redux-toolkit-query\n * being a cache layer so if nothing invalidates the cache, we don't fetch again.\n */\n\nimport * as React from 'react';\n\nimport {\n useNotification,\n useAPIErrorHandler,\n useQueryParams,\n FormErrors,\n getYupValidationErrors,\n useForm,\n} from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useParams } from 'react-router-dom';\nimport { ValidationError } from 'yup';\n\nimport { SINGLE_TYPES } from '../constants/collections';\nimport { type AnyData, transformDocument } from '../pages/EditView/utils/data';\nimport { createDefaultForm } from '../pages/EditView/utils/forms';\nimport { useGetDocumentQuery } from '../services/documents';\nimport { buildValidParams } from '../utils/api';\nimport { createYupSchema } from '../utils/validation';\n\nimport { useContentTypeSchema, ComponentsDictionary } from './useContentTypeSchema';\nimport { useDocumentLayout } from './useDocumentLayout';\n\nimport type { FindOne } from '../../../shared/contracts/collection-types';\nimport type { ContentType } from '../../../shared/contracts/content-types';\nimport type { Modules } from '@strapi/types';\n\ninterface UseDocumentArgs {\n collectionType: string;\n model: string;\n documentId?: string;\n params?: object;\n}\n\ntype UseDocumentOpts = Parameters<typeof useGetDocumentQuery>[1];\n\ntype Document = FindOne.Response['data'];\n\ntype Schema = ContentType;\n\ntype UseDocument = (\n args: UseDocumentArgs,\n opts?: UseDocumentOpts\n) => {\n /**\n * These are the schemas of the components used in the content type, organised\n * by their uid.\n */\n components: ComponentsDictionary;\n document?: Document;\n meta?: FindOne.Response['meta'];\n isLoading: boolean;\n /**\n * This is the schema of the content type, it is not the same as the layout.\n */\n schema?: Schema;\n schemas?: Schema[];\n hasError?: boolean;\n refetch: () => void;\n validate: (document: Document) => null | FormErrors;\n /**\n * Get the document's title\n */\n getTitle: (mainField: string) => string;\n /**\n * Get the initial form values for the document\n */\n getInitialFormValues: (isCreatingDocument?: boolean) => AnyData | undefined;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDocument\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @alpha\n * @public\n * @description Returns a document based on the model, collection type & id passed as arguments.\n * Also extracts its schema from the redux cache to be used for creating a validation schema.\n * @example\n * ```tsx\n * const { id, model, collectionType } = useParams<{ id: string; model: string; collectionType: string }>();\n *\n * if(!model || !collectionType) return null;\n *\n * const { document, isLoading, validate } = useDocument({ documentId: id, model, collectionType, params: { locale: 'en-GB' } })\n * const { update } = useDocumentActions()\n *\n * const onSubmit = async (document: Document) => {\n * const errors = validate(document);\n *\n * if(errors) {\n * // handle errors\n * }\n *\n * await update({ collectionType, model, id }, document)\n * }\n * ```\n *\n */\nconst useDocument: UseDocument = (args, opts) => {\n const { toggleNotification } = useNotification();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n const { formatMessage } = useIntl();\n\n const {\n currentData: data,\n isLoading: isLoadingDocument,\n isFetching: isFetchingDocument,\n error,\n refetch,\n } = useGetDocumentQuery(args, {\n ...opts,\n skip: (!args.documentId && args.collectionType !== SINGLE_TYPES) || opts?.skip,\n });\n const document = data?.data;\n const meta = data?.meta;\n\n const {\n components,\n schema,\n schemas,\n isLoading: isLoadingSchema,\n } = useContentTypeSchema(args.model);\n const isSingleType = schema?.kind === 'singleType';\n\n const getTitle = React.useCallback(\n (mainField: string) => {\n // Always use mainField if it's not an id\n if (mainField !== 'id' && document?.[mainField]) {\n return document[mainField];\n }\n\n // When it's a singleType without a mainField, use the contentType displayName\n if (schema?.kind === 'singleType' && schema.info.displayName) {\n return schema.info.displayName;\n }\n\n // Otherwise, use a fallback\n return formatMessage({\n id: 'content-manager.containers.untitled',\n defaultMessage: 'Untitled',\n });\n },\n [document, formatMessage, schema]\n );\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [toggleNotification, error, formatAPIError, args.collectionType]);\n\n const validationSchema = React.useMemo(() => {\n if (!schema) {\n return null;\n }\n\n return createYupSchema(schema.attributes, components);\n }, [schema, components]);\n\n const validate = React.useCallback(\n (document: Modules.Documents.AnyDocument): FormErrors | null => {\n if (!validationSchema) {\n throw new Error(\n 'There is no validation schema generated, this is likely due to the schema not being loaded yet.'\n );\n }\n\n try {\n validationSchema.validateSync(document, { abortEarly: false, strict: true });\n return null;\n } catch (error) {\n if (error instanceof ValidationError) {\n return getYupValidationErrors(error);\n }\n\n throw error;\n }\n },\n [validationSchema]\n );\n\n /**\n * Here we prepare the form for editing, we need to:\n * - remove prohibited fields from the document (passwords | ADD YOURS WHEN THERES A NEW ONE)\n * - swap out count objects on relations for empty arrays\n * - set __temp_key__ on array objects for drag & drop\n *\n * We also prepare the form for new documents, so we need to:\n * - set default values on fields\n */\n const getInitialFormValues = React.useCallback(\n (isCreatingDocument: boolean = false) => {\n if ((!document && !isCreatingDocument && !isSingleType) || !schema) {\n return undefined;\n }\n\n /**\n * Check that we have an ID so we know the\n * document has been created in some way.\n */\n const form = document?.id ? document : createDefaultForm(schema, components);\n\n return transformDocument(schema, components)(form);\n },\n [document, isSingleType, schema, components]\n );\n\n const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;\n const hasError = !!error;\n\n return React.useMemo(\n () =>\n ({\n components,\n document,\n meta,\n isLoading,\n hasError,\n schema,\n schemas,\n validate,\n getTitle,\n getInitialFormValues,\n refetch,\n }) satisfies ReturnType<UseDocument>,\n [\n components,\n document,\n meta,\n isLoading,\n hasError,\n schema,\n schemas,\n validate,\n getTitle,\n getInitialFormValues,\n refetch,\n ]\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDoc\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal this hook uses the router to extract the model, collection type & id from the url.\n * therefore, it shouldn't be used outside of the content-manager because it won't work as intended.\n */\nconst useDoc = () => {\n const { id, slug, collectionType, origin } = useParams<{\n id: string;\n origin: string;\n slug: string;\n collectionType: string;\n }>();\n const [{ query }] = useQueryParams();\n const params = React.useMemo(() => buildValidParams(query), [query]);\n\n if (!collectionType) {\n throw new Error('Could not find collectionType in url params');\n }\n\n if (!slug) {\n throw new Error('Could not find model in url params');\n }\n\n const document = useDocument(\n { documentId: origin || id, model: slug, collectionType, params },\n {\n skip: id === 'create' || (!origin && !id && collectionType !== SINGLE_TYPES),\n }\n );\n\n const returnId = origin || (id === 'create' ? undefined : id);\n\n return {\n collectionType,\n model: slug,\n id: returnId,\n ...document,\n };\n};\n\n/**\n * @public\n * @experimental\n * Content manager context hooks for plugin development.\n * Make sure to use this hook inside the content manager.\n */\nconst useContentManagerContext = () => {\n const {\n collectionType,\n model,\n id,\n components,\n isLoading: isLoadingDoc,\n schema,\n schemas,\n } = useDoc();\n\n const layout = useDocumentLayout(model);\n\n const form = useForm<unknown>('useContentManagerContext', (state) => state);\n\n const isSingleType = collectionType === SINGLE_TYPES;\n const slug = model;\n const isCreatingEntry = id === 'create';\n\n const {} = useContentTypeSchema();\n\n const isLoading = isLoadingDoc || layout.isLoading;\n const error = layout.error;\n\n return {\n error,\n isLoading,\n\n // Base metadata\n model,\n collectionType,\n id,\n slug,\n isCreatingEntry,\n isSingleType,\n hasDraftAndPublish: schema?.options?.draftAndPublish ?? false,\n\n // All schema infos\n components,\n contentType: schema,\n contentTypes: schemas,\n\n // Form state\n form,\n\n // layout infos\n layout,\n };\n};\n\nexport { useDocument, useDoc, useContentManagerContext };\nexport type { UseDocument, UseDocumentArgs, Document, Schema, ComponentsDictionary };\n"],"names":["useDocument","args","opts","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","formatMessage","useIntl","currentData","data","isLoading","isLoadingDocument","isFetching","isFetchingDocument","error","refetch","useGetDocumentQuery","skip","documentId","collectionType","SINGLE_TYPES","document","meta","components","schema","schemas","isLoadingSchema","useContentTypeSchema","model","isSingleType","kind","getTitle","React","useCallback","mainField","info","displayName","id","defaultMessage","useEffect","type","message","validationSchema","useMemo","createYupSchema","attributes","validate","Error","validateSync","abortEarly","strict","ValidationError","getYupValidationErrors","getInitialFormValues","isCreatingDocument","undefined","form","createDefaultForm","transformDocument","hasError","useDoc","slug","origin","useParams","query","useQueryParams","params","buildValidParams","returnId","useContentManagerContext","isLoadingDoc","layout","useDocumentLayout","useForm","state","isCreatingEntry","hasDraftAndPublish","options","draftAndPublish","contentType","contentTypes"],"mappings":";;;;;;;;;;;;;;AA6EA;;;;;;;;;;;;;;;;;;;;;;;;;;;IA8BA,MAAMA,WAAAA,GAA2B,CAACC,IAAAA,EAAMC,IAAAA,GAAAA;IACtC,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,eAAAA,EAAAA;AAC/B,IAAA,MAAM,EAAEC,uBAAAA,EAAyBC,cAAc,EAAE,GAAGC,kBAAAA,EAAAA;IACpD,MAAM,EAAEC,aAAa,EAAE,GAAGC,OAAAA,EAAAA;AAE1B,IAAA,MAAM,EACJC,WAAAA,EAAaC,IAAI,EACjBC,SAAAA,EAAWC,iBAAiB,EAC5BC,UAAAA,EAAYC,kBAAkB,EAC9BC,KAAK,EACLC,OAAO,EACR,GAAGC,oBAAoBjB,IAAAA,EAAM;AAC5B,QAAA,GAAGC,IAAI;QACPiB,IAAAA,EAAO,CAAClB,IAAAA,CAAKmB,UAAU,IAAInB,IAAAA,CAAKoB,cAAc,KAAKC,YAAAA,IAAiBpB,IAAAA,EAAMiB;AAC5E,KAAA,CAAA;AACA,IAAA,MAAMI,WAAWZ,IAAAA,EAAMA,IAAAA;AACvB,IAAA,MAAMa,OAAOb,IAAAA,EAAMa,IAAAA;AAEnB,IAAA,MAAM,EACJC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPf,SAAAA,EAAWgB,eAAe,EAC3B,GAA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AAA,YAAAA;QACA+C,kBAAAA,EAAoBpD,MAAAA,EAAQqD,SAASC,eAAAA,IAAmB,KAAA;;AAGxDvD,QAAAA,UAAAA;QACAwD,WAAAA,EAAavD,MAAAA;QACbwD,YAAAA,EAAcvD,OAAAA;;AAGd+B,QAAAA,IAAAA;;AAGAe,QAAAA;AACF,KAAA;AACF;;;;"}
1
+ {"version":3,"file":"useDocument.mjs","sources":["../../../admin/src/hooks/useDocument.ts"],"sourcesContent":["/**\n * This hook doesn't use a context provider because we fetch directly from the server,\n * this sounds expensive but actually, it's really not. Because we have redux-toolkit-query\n * being a cache layer so if nothing invalidates the cache, we don't fetch again.\n */\n\nimport * as React from 'react';\n\nimport {\n useNotification,\n useAPIErrorHandler,\n useQueryParams,\n FormErrors,\n getYupValidationErrors,\n useForm,\n} from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useParams } from 'react-router-dom';\nimport { ValidationError } from 'yup';\n\nimport { SINGLE_TYPES } from '../constants/collections';\nimport { type AnyData, transformDocument } from '../pages/EditView/utils/data';\nimport { createDefaultForm } from '../pages/EditView/utils/forms';\nimport { useGetDocumentQuery } from '../services/documents';\nimport { buildValidParams } from '../utils/api';\nimport { createYupSchema } from '../utils/validation';\n\nimport { useContentTypeSchema, ComponentsDictionary } from './useContentTypeSchema';\nimport { useDocumentLayout } from './useDocumentLayout';\n\nimport type { FindOne } from '../../../shared/contracts/collection-types';\nimport type { ContentType } from '../../../shared/contracts/content-types';\nimport type { Modules } from '@strapi/types';\n\ninterface UseDocumentArgs {\n collectionType: string;\n model: string;\n documentId?: string;\n params?: object;\n}\n\ntype UseDocumentOpts = Parameters<typeof useGetDocumentQuery>[1];\n\ntype Document = FindOne.Response['data'];\n\ntype Schema = ContentType;\n\ntype UseDocument = (\n args: UseDocumentArgs,\n opts?: UseDocumentOpts\n) => {\n /**\n * These are the schemas of the components used in the content type, organised\n * by their uid.\n */\n components: ComponentsDictionary;\n document?: Document;\n meta?: FindOne.Response['meta'];\n isLoading: boolean;\n /**\n * This is the schema of the content type, it is not the same as the layout.\n */\n schema?: Schema;\n schemas?: Schema[];\n hasError?: boolean;\n refetch: () => void;\n validate: (document: Document) => null | FormErrors;\n /**\n * Get the document's title\n */\n getTitle: (mainField: string) => string;\n /**\n * Get the initial form values for the document\n */\n getInitialFormValues: (isCreatingDocument?: boolean) => AnyData | undefined;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDocument\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @alpha\n * @public\n * @description Returns a document based on the model, collection type & id passed as arguments.\n * Also extracts its schema from the redux cache to be used for creating a validation schema.\n * @example\n * ```tsx\n * const { id, model, collectionType } = useParams<{ id: string; model: string; collectionType: string }>();\n *\n * if(!model || !collectionType) return null;\n *\n * const { document, isLoading, validate } = useDocument({ documentId: id, model, collectionType, params: { locale: 'en-GB' } })\n * const { update } = useDocumentActions()\n *\n * const onSubmit = async (document: Document) => {\n * const errors = validate(document);\n *\n * if(errors) {\n * // handle errors\n * }\n *\n * await update({ collectionType, model, id }, document)\n * }\n * ```\n *\n */\nconst useDocument: UseDocument = (args, opts) => {\n const { toggleNotification } = useNotification();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n const { formatMessage } = useIntl();\n\n const {\n currentData: data,\n isLoading: isLoadingDocument,\n isFetching: isFetchingDocument,\n error,\n refetch,\n } = useGetDocumentQuery(args, {\n ...opts,\n skip: (!args.documentId && args.collectionType !== SINGLE_TYPES) || opts?.skip,\n });\n const document = data?.data;\n const meta = data?.meta;\n\n const {\n components,\n schema,\n schemas,\n isLoading: isLoadingSchema,\n } = useContentTypeSchema(args.model);\n const isSingleType = schema?.kind === 'singleType';\n\n const getTitle = React.useCallback(\n (mainField: string) => {\n // Always use mainField if it's not an id\n if (mainField !== 'id' && document?.[mainField]) {\n return document[mainField];\n }\n\n // When it's a singleType without a mainField, use the contentType displayName\n if (schema?.kind === 'singleType' && schema.info.displayName) {\n return formatMessage({\n id: schema.info.displayName,\n defaultMessage: schema.info.displayName,\n });\n }\n\n // Otherwise, use a fallback\n return formatMessage({\n id: 'content-manager.containers.untitled',\n defaultMessage: 'Untitled',\n });\n },\n [document, formatMessage, schema]\n );\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [toggleNotification, error, formatAPIError, args.collectionType]);\n\n const validationSchema = React.useMemo(() => {\n if (!schema) {\n return null;\n }\n\n return createYupSchema(schema.attributes, components);\n }, [schema, components]);\n\n const validate = React.useCallback(\n (document: Modules.Documents.AnyDocument): FormErrors | null => {\n if (!validationSchema) {\n throw new Error(\n 'There is no validation schema generated, this is likely due to the schema not being loaded yet.'\n );\n }\n\n try {\n validationSchema.validateSync(document, { abortEarly: false, strict: true });\n return null;\n } catch (error) {\n if (error instanceof ValidationError) {\n return getYupValidationErrors(error);\n }\n\n throw error;\n }\n },\n [validationSchema]\n );\n\n /**\n * Here we prepare the form for editing, we need to:\n * - remove prohibited fields from the document (passwords | ADD YOURS WHEN THERES A NEW ONE)\n * - swap out count objects on relations for empty arrays\n * - set __temp_key__ on array objects for drag & drop\n *\n * We also prepare the form for new documents, so we need to:\n * - set default values on fields\n */\n const getInitialFormValues = React.useCallback(\n (isCreatingDocument: boolean = false) => {\n if ((!document && !isCreatingDocument && !isSingleType) || !schema) {\n return undefined;\n }\n\n /**\n * Check that we have an ID so we know the\n * document has been created in some way.\n */\n const form = document?.id ? document : createDefaultForm(schema, components);\n\n return transformDocument(schema, components)(form);\n },\n [document, isSingleType, schema, components]\n );\n\n const isLoading = isLoadingDocument || isFetchingDocument || isLoadingSchema;\n const hasError = !!error;\n\n return React.useMemo(\n () =>\n ({\n components,\n document,\n meta,\n isLoading,\n hasError,\n schema,\n schemas,\n validate,\n getTitle,\n getInitialFormValues,\n refetch,\n }) satisfies ReturnType<UseDocument>,\n [\n components,\n document,\n meta,\n isLoading,\n hasError,\n schema,\n schemas,\n validate,\n getTitle,\n getInitialFormValues,\n refetch,\n ]\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDoc\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal this hook uses the router to extract the model, collection type & id from the url.\n * therefore, it shouldn't be used outside of the content-manager because it won't work as intended.\n */\nconst useDoc = () => {\n const { id, slug, collectionType, origin } = useParams<{\n id: string;\n origin: string;\n slug: string;\n collectionType: string;\n }>();\n const [{ query }] = useQueryParams();\n const params = React.useMemo(() => buildValidParams(query), [query]);\n\n if (!collectionType) {\n throw new Error('Could not find collectionType in url params');\n }\n\n if (!slug) {\n throw new Error('Could not find model in url params');\n }\n\n const document = useDocument(\n { documentId: origin || id, model: slug, collectionType, params },\n {\n skip: id === 'create' || (!origin && !id && collectionType !== SINGLE_TYPES),\n }\n );\n\n const returnId = origin || (id === 'create' ? undefined : id);\n\n return {\n collectionType,\n model: slug,\n id: returnId,\n ...document,\n };\n};\n\n/**\n * @public\n * @experimental\n * Content manager context hooks for plugin development.\n * Make sure to use this hook inside the content manager.\n */\nconst useContentManagerContext = () => {\n const {\n collectionType,\n model,\n id,\n components,\n isLoading: isLoadingDoc,\n schema,\n schemas,\n } = useDoc();\n\n const layout = useDocumentLayout(model);\n\n const form = useForm<unknown>('useContentManagerContext', (state) => state);\n\n const isSingleType = collectionType === SINGLE_TYPES;\n const slug = model;\n const isCreatingEntry = id === 'create';\n\n const {} = useContentTypeSchema();\n\n const isLoading = isLoadingDoc || layout.isLoading;\n const error = layout.error;\n\n return {\n error,\n isLoading,\n\n // Base metadata\n model,\n collectionType,\n id,\n slug,\n isCreatingEntry,\n isSingleType,\n hasDraftAndPublish: schema?.options?.draftAndPublish ?? false,\n\n // All schema infos\n components,\n contentType: schema,\n contentTypes: schemas,\n\n // Form state\n form,\n\n // layout infos\n layout,\n };\n};\n\nexport { useDocument, useDoc, useContentManagerContext };\nexport type { UseDocument, UseDocumentArgs, Document, Schema, ComponentsDictionary };\n"],"names":["useDocument","args","opts","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","formatMessage","useIntl","currentData","data","isLoading","isLoadingDocument","isFetching","isFetchingDocument","error","refetch","useGetDocumentQuery","skip","documentId","collectionType","SINGLE_TYPES","document","meta","components","schema","schemas","isLoadingSchema","useContentTypeSchema","model","isSingleType","kind","getTitle","React","useCallback","mainField","info","displayName","id","defaultMessage","useEffect","type","message","validationSchema","useMemo","createYupSchema","attributes","validate","Error","validateSync","abortEarly","strict","ValidationError","getYupValidationErrors","getInitialFormValues","isCreatingDocument","undefined","form","createDefaultForm","transformDocument","hasError","useDoc","slug","origin","useParams","query","useQueryParams","params","buildValidParams","returnId","useContentManagerContext","isLoadingDoc","layout","useDocumentLayout","useForm","state","isCreatingEntry","hasDraftAndPublish","options","draftAndPublish","contentType","contentTypes"],"mappings":";;;;;;;;;;;;;;AA6EA;;;;;;;;;;;;;;;;;;;;;;;;;;;IA8BA,MAAMA,WAAAA,GAA2B,CAACC,IAAAA,EAAMC,IAAAA,GAAAA;IACtC,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,eAAAA,EAAAA;AAC/B,IAAA,MAAM,EAAEC,uBAAAA,EAAyBC,cAAc,EAAE,GAAGC,kBAAAA,EAAAA;IACpD,MAAM,EAAEC,aAAa,EAAE,GAAGC,OAAAA,EAAAA;AAE1B,IAAA,MAAM,EACJC,WAAAA,EAAaC,IAAI,EACjBC,SAAAA,EAAWC,iBAAiB,EAC5BC,UAAAA,EAAYC,kBAAkB,EAC9BC,KAAK,EACLC,OAAO,EACR,GAAGC,oBAAoBjB,IAAAA,EAAM;AAC5B,QAAA,GAAGC,IAAI;QACPiB,IAAAA,EAAO,CAAClB,IAAAA,CAAKmB,UAAU,IAAInB,IAAAA,CAAKoB,cAAc,KAAKC,YAAAA,IAAiBpB,IAAAA,EAAMiB;AAC5E,KAAA,CAAA;AACA,IAAA,MAAMI,WAAWZ,IAAAA,EAAMA,IAAAA;AACvB,IAAA,MAAMa,OAAOb,IAAAA,EAAMa,IAAAA;AAE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KAAAA,GAAQyD,OAAOzD,KAAK;IAE1B,OAAO;AACLA,QAAAA,KAAAA;AACAJ,QAAAA,SAAAA;;AAGAkB,QAAAA,KAAAA;AACAT,QAAAA,cAAAA;AACAkB,QAAAA,EAAAA;AACAwB,QAAAA,IAAAA;AACAc,QAAAA,eAAAA;AACA9C,QAAAA,YAAAA;QACA+C,kBAAAA,EAAoBpD,MAAAA,EAAQqD,SAASC,eAAAA,IAAmB,KAAA;;AAGxDvD,QAAAA,UAAAA;QACAwD,WAAAA,EAAavD,MAAAA;QACbwD,YAAAA,EAAcvD,OAAAA;;AAGd+B,QAAAA,IAAAA;;AAGAe,QAAAA;AACF,KAAA;AACF;;;;"}
@@ -126,11 +126,27 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
126
126
  query,
127
127
  runHookWaterfall
128
128
  ]);
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
+ ]);
129
144
  return {
130
145
  error,
131
146
  isLoading,
132
147
  edit,
133
- list: listLayout
148
+ list: listLayout,
149
+ listViewConversionContext
134
150
  };
135
151
  };
136
152
  /* -------------------------------------------------------------------------------------------------
@@ -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\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\n/* -------------------------------------------------------------------------------------------------\n * useDocumentLayout\n * -----------------------------------------------------------------------------------------------*/\n\nconst DEFAULT_SETTINGS = {\n bulkable: false,\n filterable: false,\n searchable: false,\n pagination: false,\n defaultSortBy: '',\n defaultSortOrder: 'asc',\n mainField: 'id',\n pageSize: 10,\n relationOpenMode: 'modal' as const,\n};\n\n/**\n * @alpha\n * @description This hook is used to get the layouts for either the edit view or list view of a specific content-type\n * including the layouts for the components used in the content-type. It also runs the mutation hook waterfall so the data\n * is consistent wherever it is used. It's a light wrapper around the `useDocument` hook, but provides the `skip` option a document\n * is not fetched, however, it does fetch the schemas & components if they do not already exist in the cache.\n *\n * If the fetch fails, it will display a notification to the user.\n *\n * @example\n * ```tsx\n * const { model } = useParams<{ model: string }>();\n * const { edit: { schema: layout } } = useDocumentLayout(model);\n *\n * return layout.map(panel => panel.map(row => row.map(field => <Field.Root {...field} />)))\n * ```\n *\n */\nconst useDocumentLayout: UseDocumentLayout = (model) => {\n const { schema, components } = useDocument({ model, collectionType: '' }, { skip: true });\n const [{ query }] = useQueryParams();\n const runHookWaterfall = useStrapiApp('useDocumentLayout', (state) => state.runHookWaterfall);\n const { toggleNotification } = useNotification();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();\n\n const {\n data,\n isLoading: isLoadingConfigs,\n error,\n isFetching: isFetchingConfigs,\n } = useGetContentTypeConfigurationQuery(model);\n\n const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [error, formatAPIError, toggleNotification]);\n\n const editLayout = React.useMemo(\n () =>\n data && !isLoading\n ? formatEditLayout(data, { schemas, schema, components })\n : ({\n layout: [],\n components: {},\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as EditLayout),\n [data, isLoading, schemas, schema, components]\n );\n\n const listLayout = React.useMemo(() => {\n return data && !isLoading\n ? formatListLayout(data, { schemas, schema, components })\n : ({\n layout: [],\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as ListLayout);\n }, [data, isLoading, schemas, schema, components]);\n\n const { layout: edit } = React.useMemo(\n () =>\n runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {\n layout: editLayout,\n query,\n }),\n [editLayout, query, runHookWaterfall]\n );\n\n return {\n error,\n isLoading,\n edit,\n list: listLayout,\n } satisfies ReturnType<UseDocumentLayout>;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDocLayout\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal this hook uses the internal useDoc hook, as such it shouldn't be used outside of the\n * content-manager because it won't work as intended.\n */\nconst useDocLayout = () => {\n const { model } = useDoc();\n return useDocumentLayout(model);\n};\n\n/* -------------------------------------------------------------------------------------------------\n * formatEditLayout\n * -----------------------------------------------------------------------------------------------*/\ntype LayoutData = FindContentTypeConfiguration.Response['data'];\n\n/**\n * @internal\n * @description takes the configuration data, the schema & the components used in the schema and formats the edit view\n * versions of the schema & components. This is then used to render the edit view of the content-type.\n */\nconst formatEditLayout = (\n data: LayoutData,\n {\n schemas,\n schema,\n components,\n }: { schemas: Schema[]; schema?: Schema; components: ComponentsDictionary }\n): EditLayout => {\n let currentPanelIndex = 0;\n /**\n * The fields arranged by the panels, new panels are made for dynamic zones only.\n */\n const panelledEditAttributes = convertEditLayoutToFieldLayouts(\n data.contentType.layouts.edit,\n schema?.attributes,\n data.contentType.metadatas,\n { configurations: data.components, schemas: components },\n schemas\n ).reduce<Array<EditFieldLayout[][]>>((panels, row) => {\n if (row.some((field) => field.type === 'dynamiczone')) {\n panels.push([row]);\n currentPanelIndex += 2;\n } else {\n if (!panels[currentPanelIndex]) {\n panels.push([row]);\n } else {\n panels[currentPanelIndex].push(row);\n }\n }\n\n return panels;\n }, []);\n\n const componentEditAttributes = Object.entries(data.components).reduce<EditLayout['components']>(\n (acc, [uid, configuration]) => {\n acc[uid] = {\n layout: convertEditLayoutToFieldLayouts(\n configuration.layouts.edit,\n components[uid].attributes,\n configuration.metadatas,\n { configurations: data.components, schemas: components }\n ),\n settings: {\n ...configuration.settings,\n icon: components[uid].info.icon,\n displayName: components[uid].info.displayName,\n },\n };\n return acc;\n },\n {}\n );\n\n const editMetadatas = Object.entries(data.contentType.metadatas).reduce<EditLayout['metadatas']>(\n (acc, [attribute, metadata]) => {\n return {\n ...acc,\n [attribute]: metadata.edit,\n };\n },\n {}\n );\n\n return {\n layout: panelledEditAttributes,\n components: componentEditAttributes,\n metadatas: editMetadatas,\n settings: {\n ...data.contentType.settings,\n displayName: schema?.info.displayName,\n },\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n ...data.contentType.options,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * convertEditLayoutToFieldLayouts\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the edit layout from either a content-type or a component\n * and formats it into a generic object that can be used to correctly render\n * the form fields.\n */\nconst convertEditLayoutToFieldLayouts = (\n rows: LayoutData['contentType']['layouts']['edit'],\n attributes: Schema['attributes'] = {},\n metadatas: Metadatas,\n components?: {\n configurations: Record<string, ComponentConfiguration>;\n schemas: ComponentsDictionary;\n },\n schemas: Schema[] = []\n) => {\n return rows.map((row) =>\n row\n .map((field) => {\n const attribute = attributes[field.name];\n\n if (!attribute) {\n return null;\n }\n\n const { edit: metadata } = metadatas[field.name];\n\n const settings: Partial<Settings> =\n attribute.type === 'component' && components\n ? components.configurations[attribute.component].settings\n : {};\n\n return {\n attribute,\n disabled: !metadata.editable,\n hint: metadata.description,\n label: metadata.label ?? '',\n name: field.name,\n // @ts-expect-error – mainField does exist on the metadata for a relation.\n mainField: getMainField(attribute, metadata.mainField || settings.mainField, {\n schemas,\n components: components?.schemas ?? {},\n }),\n placeholder: metadata.placeholder ?? '',\n required: attribute.required ?? false,\n size: field.size,\n unique: 'unique' in attribute ? attribute.unique : false,\n visible: metadata.visible ?? true,\n type: attribute.type,\n };\n })\n .filter((field) => field !== null)\n ) as EditFieldLayout[][];\n};\n\n/* -------------------------------------------------------------------------------------------------\n * formatListLayout\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the complete configuration data, the schema & the components used in the schema and\n * formats a list view layout for the content-type. This is much simpler than the edit view layout as there\n * are less options to consider.\n */\nconst formatListLayout = (\n data: LayoutData,\n {\n schemas,\n schema,\n components,\n }: { schemas: Schema[]; schema?: Schema; components: ComponentsDictionary }\n): ListLayout => {\n const listMetadatas = Object.entries(data.contentType.metadatas).reduce<ListLayout['metadatas']>(\n (acc, [attribute, metadata]) => {\n return {\n ...acc,\n [attribute]: metadata.list,\n };\n },\n {}\n );\n /**\n * The fields arranged by the panels, new panels are made for dynamic zones only.\n */\n const listAttributes = convertListLayoutToFieldLayouts(\n data.contentType.layouts.list,\n schema?.attributes,\n listMetadatas,\n { configurations: data.components, schemas: components },\n schemas\n );\n\n return {\n layout: listAttributes,\n settings: { ...data.contentType.settings, displayName: schema?.info.displayName },\n metadatas: listMetadatas,\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n ...data.contentType.options,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * convertListLayoutToFieldLayouts\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the columns from the list view configuration and formats them into a generic object\n * combinining metadata and attribute data.\n *\n * @note We do use this to reformat the list of strings when updating the displayed headers for the list view.\n */\nconst convertListLayoutToFieldLayouts = (\n columns: LayoutData['contentType']['layouts']['list'],\n attributes: Schema['attributes'] = {},\n metadatas: ListLayout['metadatas'],\n components?: {\n configurations: Record<string, ComponentConfiguration>;\n schemas: ComponentsDictionary;\n },\n schemas: Schema[] = []\n) => {\n return columns\n .map((name) => {\n const attribute = attributes[name];\n\n if (!attribute) {\n return null;\n }\n\n const metadata = metadatas[name];\n\n const settings: Partial<Settings> =\n attribute.type === 'component' && components\n ? components.configurations[attribute.component].settings\n : {};\n\n return {\n attribute,\n label: metadata.label ?? '',\n mainField: getMainField(attribute, metadata.mainField || settings.mainField, {\n schemas,\n components: components?.schemas ?? {},\n }),\n name: name,\n searchable: metadata.searchable ?? true,\n sortable: metadata.sortable ?? true,\n } satisfies ListFieldLayout;\n })\n .filter((field) => field !== null) as ListFieldLayout[];\n};\n\nexport {\n useDocLayout,\n useDocumentLayout,\n convertListLayoutToFieldLayouts,\n convertEditLayoutToFieldLayouts,\n DEFAULT_SETTINGS,\n};\nexport type { EditLayout, EditFieldLayout, ListLayout, ListFieldLayout, UseDocumentLayout };\n"],"names":["DEFAULT_SETTINGS","bulkable","filterable","searchable","pagination","defaultSortBy","defaultSortOrder","mainField","pageSize","relationOpenMode","useDocumentLayout","model","schema","components","useDocument","collectionType","skip","query","useQueryParams","runHookWaterfall","useStrapiApp","state","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","isLoading","isLoadingSchemas","schemas","useContentTypeSchema","data","isLoadingConfigs","error","isFetching","isFetchingConfigs","useGetContentTypeConfigurationQuery","React","useEffect","type","message","editLayout","useMemo","formatEditLayout","layout","metadatas","options","settings","listLayout","formatListLayout","edit","HOOKS","MUTATE_EDIT_VIEW_LAYOUT","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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwGA;;AAEkG,2GAE5FA,gBAAAA,GAAmB;IACvBC,QAAAA,EAAU,KAAA;IACVC,UAAAA,EAAY,KAAA;IACZC,UAAAA,EAAY,KAA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BAAAA,OAAAA;gBACAhB,UAAAA,EAAYA,UAAAA,EAAYgB,WAAW;AACrC,aAAA,CAAA;YACAuD,IAAAA,EAAMA,IAAAA;YACNjF,UAAAA,EAAY6E,QAAAA,CAAS7E,UAAU,IAAI,IAAA;YACnCmG,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 data,\n isLoading: isLoadingConfigs,\n error,\n isFetching: isFetchingConfigs,\n } = useGetContentTypeConfigurationQuery(model);\n\n const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [error, formatAPIError, toggleNotification]);\n\n const editLayout = React.useMemo(\n () =>\n data && !isLoading\n ? formatEditLayout(data, { schemas, schema, components })\n : ({\n layout: [],\n components: {},\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as EditLayout),\n [data, isLoading, schemas, schema, components]\n );\n\n const listLayout = React.useMemo(() => {\n return data && !isLoading\n ? formatListLayout(data, { schemas, schema, components })\n : ({\n layout: [],\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as ListLayout);\n }, [data, isLoading, schemas, schema, components]);\n\n const { layout: edit } = React.useMemo(\n () =>\n runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {\n layout: editLayout,\n query,\n }),\n [editLayout, query, runHookWaterfall]\n );\n\n const listViewConversionContext = React.useMemo((): ListViewConversionContext | null => {\n if (!data || isLoading) {\n return null;\n }\n\n return {\n componentConfigurations: data.components,\n componentSchemas: components,\n contentTypeSchemas: schemas,\n };\n }, [data, isLoading, components, schemas]);\n\n return {\n error,\n isLoading,\n edit,\n list: listLayout,\n listViewConversionContext,\n } satisfies ReturnType<UseDocumentLayout>;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDocLayout\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal this hook uses the internal useDoc hook, as such it shouldn't be used outside of the\n * content-manager because it won't work as intended.\n */\nconst useDocLayout = () => {\n const { model } = useDoc();\n return useDocumentLayout(model);\n};\n\n/* -------------------------------------------------------------------------------------------------\n * formatEditLayout\n * -----------------------------------------------------------------------------------------------*/\ntype LayoutData = FindContentTypeConfiguration.Response['data'];\n\n/**\n * @internal\n * @description takes the configuration data, the schema & the components used in the schema and formats the edit view\n * versions of the schema & components. This is then used to render the edit view of the content-type.\n */\nconst formatEditLayout = (\n data: LayoutData,\n {\n schemas,\n schema,\n components,\n }: { schemas: Schema[]; schema?: Schema; components: ComponentsDictionary }\n): EditLayout => {\n let currentPanelIndex = 0;\n /**\n * The fields arranged by the panels, new panels are made for dynamic zones only.\n */\n const panelledEditAttributes = convertEditLayoutToFieldLayouts(\n data.contentType.layouts.edit,\n schema?.attributes,\n data.contentType.metadatas,\n { configurations: data.components, schemas: components },\n schemas\n ).reduce<Array<EditFieldLayout[][]>>((panels, row) => {\n if (row.some((field) => field.type === 'dynamiczone')) {\n panels.push([row]);\n currentPanelIndex += 2;\n } else {\n if (!panels[currentPanelIndex]) {\n panels.push([row]);\n } else {\n panels[currentPanelIndex].push(row);\n }\n }\n\n return panels;\n }, []);\n\n const componentEditAttributes = Object.entries(data.components).reduce<EditLayout['components']>(\n (acc, [uid, configuration]) => {\n acc[uid] = {\n layout: convertEditLayoutToFieldLayouts(\n configuration.layouts.edit,\n components[uid].attributes,\n configuration.metadatas,\n { configurations: data.components, schemas: components }\n ),\n settings: {\n ...configuration.settings,\n icon: components[uid].info.icon,\n displayName: components[uid].info.displayName,\n },\n };\n return acc;\n },\n {}\n );\n\n const editMetadatas = Object.entries(data.contentType.metadatas).reduce<EditLayout['metadatas']>(\n (acc, [attribute, metadata]) => {\n return {\n ...acc,\n [attribute]: metadata.edit,\n };\n },\n {}\n );\n\n return {\n layout: panelledEditAttributes,\n components: componentEditAttributes,\n metadatas: editMetadatas,\n settings: {\n ...data.contentType.settings,\n displayName: schema?.info.displayName,\n },\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n ...data.contentType.options,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * convertEditLayoutToFieldLayouts\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the edit layout from either a content-type or a component\n * and formats it into a generic object that can be used to correctly render\n * the form fields.\n */\nconst convertEditLayoutToFieldLayouts = (\n rows: LayoutData['contentType']['layouts']['edit'],\n attributes: Schema['attributes'] = {},\n metadatas: Metadatas,\n components?: {\n configurations: Record<string, ComponentConfiguration>;\n schemas: ComponentsDictionary;\n },\n schemas: Schema[] = []\n) => {\n return rows.map((row) =>\n row\n .map((field) => {\n const attribute = attributes[field.name];\n\n if (!attribute) {\n return null;\n }\n\n const { edit: metadata } = metadatas[field.name];\n\n const settings: Partial<Settings> =\n attribute.type === 'component' && components\n ? components.configurations[attribute.component].settings\n : {};\n\n return {\n attribute,\n disabled: !metadata.editable,\n hint: metadata.description,\n label: metadata.label ?? '',\n name: field.name,\n // @ts-expect-error – mainField does exist on the metadata for a relation.\n mainField: getMainField(attribute, metadata.mainField || settings.mainField, {\n schemas,\n components: components?.schemas ?? {},\n }),\n placeholder: metadata.placeholder ?? '',\n required: attribute.required ?? false,\n size: field.size,\n unique: 'unique' in attribute ? attribute.unique : false,\n visible: metadata.visible ?? true,\n type: attribute.type,\n };\n })\n .filter((field) => field !== null)\n ) as EditFieldLayout[][];\n};\n\n/* -------------------------------------------------------------------------------------------------\n * formatListLayout\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the complete configuration data, the schema & the components used in the schema and\n * formats a list view layout for the content-type. This is much simpler than the edit view layout as there\n * are less options to consider.\n */\nconst formatListLayout = (\n data: LayoutData,\n {\n schemas,\n schema,\n components,\n }: { schemas: Schema[]; schema?: Schema; components: ComponentsDictionary }\n): ListLayout => {\n const listMetadatas = Object.entries(data.contentType.metadatas).reduce<ListLayout['metadatas']>(\n (acc, [attribute, metadata]) => {\n return {\n ...acc,\n [attribute]: metadata.list,\n };\n },\n {}\n );\n /**\n * The fields arranged by the panels, new panels are made for dynamic zones only.\n */\n const listAttributes = convertListLayoutToFieldLayouts(\n data.contentType.layouts.list,\n schema?.attributes,\n listMetadatas,\n { configurations: data.components, schemas: components },\n schemas\n );\n\n return {\n layout: listAttributes,\n settings: { ...data.contentType.settings, displayName: schema?.info.displayName },\n metadatas: listMetadatas,\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n ...data.contentType.options,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * convertListLayoutToFieldLayouts\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the columns from the list view configuration and formats them into a generic object\n * combinining metadata and attribute data.\n *\n * @note We do use this to reformat the list of strings when updating the displayed headers for the list view.\n */\nconst convertListLayoutToFieldLayouts = (\n columns: LayoutData['contentType']['layouts']['list'],\n attributes: Schema['attributes'] = {},\n metadatas: ListLayout['metadatas'],\n components?: {\n configurations: Record<string, ComponentConfiguration>;\n schemas: ComponentsDictionary;\n },\n schemas: Schema[] = []\n) => {\n return columns\n .map((name) => {\n const attribute = attributes[name];\n\n if (!attribute) {\n return null;\n }\n\n const metadata = metadatas[name];\n\n const settings: Partial<Settings> =\n attribute.type === 'component' && components\n ? components.configurations[attribute.component].settings\n : {};\n\n return {\n attribute,\n label: metadata.label ?? '',\n mainField: getMainField(attribute, metadata.mainField || settings.mainField, {\n schemas,\n components: components?.schemas ?? {},\n }),\n name: name,\n searchable: metadata.searchable ?? true,\n sortable: metadata.sortable ?? true,\n } satisfies ListFieldLayout;\n })\n .filter((field) => field !== null) as ListFieldLayout[];\n};\n\nexport {\n useDocLayout,\n useDocumentLayout,\n convertListLayoutToFieldLayouts,\n convertEditLayoutToFieldLayouts,\n DEFAULT_SETTINGS,\n};\nexport type { EditLayout, EditFieldLayout, ListLayout, ListFieldLayout, UseDocumentLayout };\n"],"names":["DEFAULT_SETTINGS","bulkable","filterable","searchable","pagination","defaultSortBy","defaultSortOrder","mainField","pageSize","relationOpenMode","useDocumentLayout","model","schema","components","useDocument","collectionType","skip","query","useQueryParams","runHookWaterfall","useStrapiApp","state","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","isLoading","isLoadingSchemas","schemas","useContentTypeSchema","data","isLoadingConfigs","error","isFetching","isFetchingConfigs","useGetContentTypeConfigurationQuery","React","useEffect","type","message","editLayout","useMemo","formatEditLayout","layout","metadatas","options","settings","listLayout","formatListLayout","edit","HOOKS","MUTATE_EDIT_VIEW_LAYOUT","listViewConversionContext","componentConfigurations","componentSchemas","contentTypeSchemas","list","useDocLayout","useDoc","currentPanelIndex","panelledEditAttributes","convertEditLayoutToFieldLayouts","contentType","layouts","attributes","configurations","reduce","panels","row","some","field","push","componentEditAttributes","Object","entries","acc","uid","configuration","icon","info","displayName","editMetadatas","attribute","metadata","pluginOptions","rows","map","name","component","disabled","editable","hint","description","label","getMainField","placeholder","required","size","unique","visible","filter","listMetadatas","listAttributes","convertListLayoutToFieldLayouts","columns","sortable"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuHA;;AAEkG,2GAE5FA,gBAAAA,GAAmB;IACvBC,QAAAA,EAAU,KAAA;IACVC,UAAAA,EAAY,KAAA;IACZC,UAAAA,EAAY,KAAA;IACZC,UAAAA,EAAY,KAAA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,SAAS,CAAC2C,IAAAA,CAAK;AAEhC,QAAA,MAAMzC,QAAAA,GACJoC,SAAAA,CAAU5C,IAAI,KAAK,eAAe1B,UAAAA,GAC9BA,UAAAA,CAAWqD,cAAc,CAACiB,UAAUM,SAAS,CAAC,CAAC1C,QAAQ,GACvD,EAAC;QAEP,OAAO;AACLoC,YAAAA,SAAAA;YACAW,KAAAA,EAAOV,QAAAA,CAASU,KAAK,IAAI,EAAA;AACzBvF,YAAAA,SAAAA,EAAWwF,wBAAaZ,SAAAA,EAAWC,QAAAA,CAAS7E,SAAS,IAAIwC,QAAAA,CAASxC,SAAS,EAAE;AAC3EsB,gBAAAA,OAAAA;gBACAhB,UAAAA,EAAYA,UAAAA,EAAYgB,WAAW;AACrC,aAAA,CAAA;YACA2D,IAAAA,EAAMA,IAAAA;YACNrF,UAAAA,EAAYiF,QAAAA,CAASjF,UAAU,IAAI,IAAA;YACnCuG,QAAAA,EAAUtB,QAAAA,CAASsB,QAAQ,IAAI;AACjC,SAAA;AACF,IAAA,CAAA,CAAA,CACCL,MAAM,CAAC,CAAC9B,KAAAA,GAAUA,KAAAA,KAAU,IAAA,CAAA;AACjC;;;;;;;;"}
@@ -105,11 +105,27 @@ import { useDocument, useDoc } from './useDocument.mjs';
105
105
  query,
106
106
  runHookWaterfall
107
107
  ]);
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
+ ]);
108
123
  return {
109
124
  error,
110
125
  isLoading,
111
126
  edit,
112
- list: listLayout
127
+ list: listLayout,
128
+ listViewConversionContext
113
129
  };
114
130
  };
115
131
  /* -------------------------------------------------------------------------------------------------
@@ -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\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\n/* -------------------------------------------------------------------------------------------------\n * useDocumentLayout\n * -----------------------------------------------------------------------------------------------*/\n\nconst DEFAULT_SETTINGS = {\n bulkable: false,\n filterable: false,\n searchable: false,\n pagination: false,\n defaultSortBy: '',\n defaultSortOrder: 'asc',\n mainField: 'id',\n pageSize: 10,\n relationOpenMode: 'modal' as const,\n};\n\n/**\n * @alpha\n * @description This hook is used to get the layouts for either the edit view or list view of a specific content-type\n * including the layouts for the components used in the content-type. It also runs the mutation hook waterfall so the data\n * is consistent wherever it is used. It's a light wrapper around the `useDocument` hook, but provides the `skip` option a document\n * is not fetched, however, it does fetch the schemas & components if they do not already exist in the cache.\n *\n * If the fetch fails, it will display a notification to the user.\n *\n * @example\n * ```tsx\n * const { model } = useParams<{ model: string }>();\n * const { edit: { schema: layout } } = useDocumentLayout(model);\n *\n * return layout.map(panel => panel.map(row => row.map(field => <Field.Root {...field} />)))\n * ```\n *\n */\nconst useDocumentLayout: UseDocumentLayout = (model) => {\n const { schema, components } = useDocument({ model, collectionType: '' }, { skip: true });\n const [{ query }] = useQueryParams();\n const runHookWaterfall = useStrapiApp('useDocumentLayout', (state) => state.runHookWaterfall);\n const { toggleNotification } = useNotification();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();\n\n const {\n data,\n isLoading: isLoadingConfigs,\n error,\n isFetching: isFetchingConfigs,\n } = useGetContentTypeConfigurationQuery(model);\n\n const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [error, formatAPIError, toggleNotification]);\n\n const editLayout = React.useMemo(\n () =>\n data && !isLoading\n ? formatEditLayout(data, { schemas, schema, components })\n : ({\n layout: [],\n components: {},\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as EditLayout),\n [data, isLoading, schemas, schema, components]\n );\n\n const listLayout = React.useMemo(() => {\n return data && !isLoading\n ? formatListLayout(data, { schemas, schema, components })\n : ({\n layout: [],\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as ListLayout);\n }, [data, isLoading, schemas, schema, components]);\n\n const { layout: edit } = React.useMemo(\n () =>\n runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {\n layout: editLayout,\n query,\n }),\n [editLayout, query, runHookWaterfall]\n );\n\n return {\n error,\n isLoading,\n edit,\n list: listLayout,\n } satisfies ReturnType<UseDocumentLayout>;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDocLayout\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal this hook uses the internal useDoc hook, as such it shouldn't be used outside of the\n * content-manager because it won't work as intended.\n */\nconst useDocLayout = () => {\n const { model } = useDoc();\n return useDocumentLayout(model);\n};\n\n/* -------------------------------------------------------------------------------------------------\n * formatEditLayout\n * -----------------------------------------------------------------------------------------------*/\ntype LayoutData = FindContentTypeConfiguration.Response['data'];\n\n/**\n * @internal\n * @description takes the configuration data, the schema & the components used in the schema and formats the edit view\n * versions of the schema & components. This is then used to render the edit view of the content-type.\n */\nconst formatEditLayout = (\n data: LayoutData,\n {\n schemas,\n schema,\n components,\n }: { schemas: Schema[]; schema?: Schema; components: ComponentsDictionary }\n): EditLayout => {\n let currentPanelIndex = 0;\n /**\n * The fields arranged by the panels, new panels are made for dynamic zones only.\n */\n const panelledEditAttributes = convertEditLayoutToFieldLayouts(\n data.contentType.layouts.edit,\n schema?.attributes,\n data.contentType.metadatas,\n { configurations: data.components, schemas: components },\n schemas\n ).reduce<Array<EditFieldLayout[][]>>((panels, row) => {\n if (row.some((field) => field.type === 'dynamiczone')) {\n panels.push([row]);\n currentPanelIndex += 2;\n } else {\n if (!panels[currentPanelIndex]) {\n panels.push([row]);\n } else {\n panels[currentPanelIndex].push(row);\n }\n }\n\n return panels;\n }, []);\n\n const componentEditAttributes = Object.entries(data.components).reduce<EditLayout['components']>(\n (acc, [uid, configuration]) => {\n acc[uid] = {\n layout: convertEditLayoutToFieldLayouts(\n configuration.layouts.edit,\n components[uid].attributes,\n configuration.metadatas,\n { configurations: data.components, schemas: components }\n ),\n settings: {\n ...configuration.settings,\n icon: components[uid].info.icon,\n displayName: components[uid].info.displayName,\n },\n };\n return acc;\n },\n {}\n );\n\n const editMetadatas = Object.entries(data.contentType.metadatas).reduce<EditLayout['metadatas']>(\n (acc, [attribute, metadata]) => {\n return {\n ...acc,\n [attribute]: metadata.edit,\n };\n },\n {}\n );\n\n return {\n layout: panelledEditAttributes,\n components: componentEditAttributes,\n metadatas: editMetadatas,\n settings: {\n ...data.contentType.settings,\n displayName: schema?.info.displayName,\n },\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n ...data.contentType.options,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * convertEditLayoutToFieldLayouts\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the edit layout from either a content-type or a component\n * and formats it into a generic object that can be used to correctly render\n * the form fields.\n */\nconst convertEditLayoutToFieldLayouts = (\n rows: LayoutData['contentType']['layouts']['edit'],\n attributes: Schema['attributes'] = {},\n metadatas: Metadatas,\n components?: {\n configurations: Record<string, ComponentConfiguration>;\n schemas: ComponentsDictionary;\n },\n schemas: Schema[] = []\n) => {\n return rows.map((row) =>\n row\n .map((field) => {\n const attribute = attributes[field.name];\n\n if (!attribute) {\n return null;\n }\n\n const { edit: metadata } = metadatas[field.name];\n\n const settings: Partial<Settings> =\n attribute.type === 'component' && components\n ? components.configurations[attribute.component].settings\n : {};\n\n return {\n attribute,\n disabled: !metadata.editable,\n hint: metadata.description,\n label: metadata.label ?? '',\n name: field.name,\n // @ts-expect-error – mainField does exist on the metadata for a relation.\n mainField: getMainField(attribute, metadata.mainField || settings.mainField, {\n schemas,\n components: components?.schemas ?? {},\n }),\n placeholder: metadata.placeholder ?? '',\n required: attribute.required ?? false,\n size: field.size,\n unique: 'unique' in attribute ? attribute.unique : false,\n visible: metadata.visible ?? true,\n type: attribute.type,\n };\n })\n .filter((field) => field !== null)\n ) as EditFieldLayout[][];\n};\n\n/* -------------------------------------------------------------------------------------------------\n * formatListLayout\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the complete configuration data, the schema & the components used in the schema and\n * formats a list view layout for the content-type. This is much simpler than the edit view layout as there\n * are less options to consider.\n */\nconst formatListLayout = (\n data: LayoutData,\n {\n schemas,\n schema,\n components,\n }: { schemas: Schema[]; schema?: Schema; components: ComponentsDictionary }\n): ListLayout => {\n const listMetadatas = Object.entries(data.contentType.metadatas).reduce<ListLayout['metadatas']>(\n (acc, [attribute, metadata]) => {\n return {\n ...acc,\n [attribute]: metadata.list,\n };\n },\n {}\n );\n /**\n * The fields arranged by the panels, new panels are made for dynamic zones only.\n */\n const listAttributes = convertListLayoutToFieldLayouts(\n data.contentType.layouts.list,\n schema?.attributes,\n listMetadatas,\n { configurations: data.components, schemas: components },\n schemas\n );\n\n return {\n layout: listAttributes,\n settings: { ...data.contentType.settings, displayName: schema?.info.displayName },\n metadatas: listMetadatas,\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n ...data.contentType.options,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * convertListLayoutToFieldLayouts\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the columns from the list view configuration and formats them into a generic object\n * combinining metadata and attribute data.\n *\n * @note We do use this to reformat the list of strings when updating the displayed headers for the list view.\n */\nconst convertListLayoutToFieldLayouts = (\n columns: LayoutData['contentType']['layouts']['list'],\n attributes: Schema['attributes'] = {},\n metadatas: ListLayout['metadatas'],\n components?: {\n configurations: Record<string, ComponentConfiguration>;\n schemas: ComponentsDictionary;\n },\n schemas: Schema[] = []\n) => {\n return columns\n .map((name) => {\n const attribute = attributes[name];\n\n if (!attribute) {\n return null;\n }\n\n const metadata = metadatas[name];\n\n const settings: Partial<Settings> =\n attribute.type === 'component' && components\n ? components.configurations[attribute.component].settings\n : {};\n\n return {\n attribute,\n label: metadata.label ?? '',\n mainField: getMainField(attribute, metadata.mainField || settings.mainField, {\n schemas,\n components: components?.schemas ?? {},\n }),\n name: name,\n searchable: metadata.searchable ?? true,\n sortable: metadata.sortable ?? true,\n } satisfies ListFieldLayout;\n })\n .filter((field) => field !== null) as ListFieldLayout[];\n};\n\nexport {\n useDocLayout,\n useDocumentLayout,\n convertListLayoutToFieldLayouts,\n convertEditLayoutToFieldLayouts,\n DEFAULT_SETTINGS,\n};\nexport type { EditLayout, EditFieldLayout, ListLayout, ListFieldLayout, UseDocumentLayout };\n"],"names":["DEFAULT_SETTINGS","bulkable","filterable","searchable","pagination","defaultSortBy","defaultSortOrder","mainField","pageSize","relationOpenMode","useDocumentLayout","model","schema","components","useDocument","collectionType","skip","query","useQueryParams","runHookWaterfall","useStrapiApp","state","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","isLoading","isLoadingSchemas","schemas","useContentTypeSchema","data","isLoadingConfigs","error","isFetching","isFetchingConfigs","useGetContentTypeConfigurationQuery","React","useEffect","type","message","editLayout","useMemo","formatEditLayout","layout","metadatas","options","settings","listLayout","formatListLayout","edit","HOOKS","MUTATE_EDIT_VIEW_LAYOUT","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":";;;;;;;;AAwGA;;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,EAAE,CAAC,GAAGC,cAAAA,EAAAA;AACpB,IAAA,MAAMC,mBAAmBC,YAAAA,CAAa,mBAAA,EAAqB,CAACC,KAAAA,GAAUA,MAAMF,gBAAgB,CAAA;IAC5F,MAAM,EAAEG,kBAAkB,EAAE,GAAGC,eAAAA,EAAAA;AAC/B,IAAA,MAAM,EAAEC,uBAAAA,EAAyBC,cAAc,EAAE,GAAGC,kBAAAA,EAAAA;AACpD,IAAA,MAAM,EAAEC,SAAAA,EAAWC,gBAAgB,EAAEC,OAAO,EAAE,GAAGC,oBAAAA,EAAAA;AAEjD,IAAA,MAAM,EACJC,IAAI,EACJJ,SAAAA,EAAWK,gBAAgB,EAC3BC,KAAK,EACLC,UAAAA,EAAYC,iBAAiB,EAC9B,GAAGC,mCAAAA,CAAoCzB,KAAAA,CAAAA;IAExC,MAAMgB,SAAAA,GAA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,UAAUM,SAAS,CAAC,CAACtC,QAAQ,GACvD,EAAC;QAEP,OAAO;AACLgC,YAAAA,SAAAA;YACAW,KAAAA,EAAOV,QAAAA,CAASU,KAAK,IAAI,EAAA;AACzBnF,YAAAA,SAAAA,EAAWoF,aAAaZ,SAAAA,EAAWC,QAAAA,CAASzE,SAAS,IAAIwC,QAAAA,CAASxC,SAAS,EAAE;AAC3EsB,gBAAAA,OAAAA;gBACAhB,UAAAA,EAAYA,UAAAA,EAAYgB,WAAW;AACrC,aAAA,CAAA;YACAuD,IAAAA,EAAMA,IAAAA;YACNjF,UAAAA,EAAY6E,QAAAA,CAAS7E,UAAU,IAAI,IAAA;YACnCmG,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 data,\n isLoading: isLoadingConfigs,\n error,\n isFetching: isFetchingConfigs,\n } = useGetContentTypeConfigurationQuery(model);\n\n const isLoading = isLoadingSchemas || isFetchingConfigs || isLoadingConfigs;\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [error, formatAPIError, toggleNotification]);\n\n const editLayout = React.useMemo(\n () =>\n data && !isLoading\n ? formatEditLayout(data, { schemas, schema, components })\n : ({\n layout: [],\n components: {},\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as EditLayout),\n [data, isLoading, schemas, schema, components]\n );\n\n const listLayout = React.useMemo(() => {\n return data && !isLoading\n ? formatListLayout(data, { schemas, schema, components })\n : ({\n layout: [],\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as ListLayout);\n }, [data, isLoading, schemas, schema, components]);\n\n const { layout: edit } = React.useMemo(\n () =>\n runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {\n layout: editLayout,\n query,\n }),\n [editLayout, query, runHookWaterfall]\n );\n\n const listViewConversionContext = React.useMemo((): ListViewConversionContext | null => {\n if (!data || isLoading) {\n return null;\n }\n\n return {\n componentConfigurations: data.components,\n componentSchemas: components,\n contentTypeSchemas: schemas,\n };\n }, [data, isLoading, components, schemas]);\n\n return {\n error,\n isLoading,\n edit,\n list: listLayout,\n listViewConversionContext,\n } satisfies ReturnType<UseDocumentLayout>;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDocLayout\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal this hook uses the internal useDoc hook, as such it shouldn't be used outside of the\n * content-manager because it won't work as intended.\n */\nconst useDocLayout = () => {\n const { model } = useDoc();\n return useDocumentLayout(model);\n};\n\n/* -------------------------------------------------------------------------------------------------\n * formatEditLayout\n * -----------------------------------------------------------------------------------------------*/\ntype LayoutData = FindContentTypeConfiguration.Response['data'];\n\n/**\n * @internal\n * @description takes the configuration data, the schema & the components used in the schema and formats the edit view\n * versions of the schema & components. This is then used to render the edit view of the content-type.\n */\nconst formatEditLayout = (\n data: LayoutData,\n {\n schemas,\n schema,\n components,\n }: { schemas: Schema[]; schema?: Schema; components: ComponentsDictionary }\n): EditLayout => {\n let currentPanelIndex = 0;\n /**\n * The fields arranged by the panels, new panels are made for dynamic zones only.\n */\n const panelledEditAttributes = convertEditLayoutToFieldLayouts(\n data.contentType.layouts.edit,\n schema?.attributes,\n data.contentType.metadatas,\n { configurations: data.components, schemas: components },\n schemas\n ).reduce<Array<EditFieldLayout[][]>>((panels, row) => {\n if (row.some((field) => field.type === 'dynamiczone')) {\n panels.push([row]);\n currentPanelIndex += 2;\n } else {\n if (!panels[currentPanelIndex]) {\n panels.push([row]);\n } else {\n panels[currentPanelIndex].push(row);\n }\n }\n\n return panels;\n }, []);\n\n const componentEditAttributes = Object.entries(data.components).reduce<EditLayout['components']>(\n (acc, [uid, configuration]) => {\n acc[uid] = {\n layout: convertEditLayoutToFieldLayouts(\n configuration.layouts.edit,\n components[uid].attributes,\n configuration.metadatas,\n { configurations: data.components, schemas: components }\n ),\n settings: {\n ...configuration.settings,\n icon: components[uid].info.icon,\n displayName: components[uid].info.displayName,\n },\n };\n return acc;\n },\n {}\n );\n\n const editMetadatas = Object.entries(data.contentType.metadatas).reduce<EditLayout['metadatas']>(\n (acc, [attribute, metadata]) => {\n return {\n ...acc,\n [attribute]: metadata.edit,\n };\n },\n {}\n );\n\n return {\n layout: panelledEditAttributes,\n components: componentEditAttributes,\n metadatas: editMetadatas,\n settings: {\n ...data.contentType.settings,\n displayName: schema?.info.displayName,\n },\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n ...data.contentType.options,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * convertEditLayoutToFieldLayouts\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the edit layout from either a content-type or a component\n * and formats it into a generic object that can be used to correctly render\n * the form fields.\n */\nconst convertEditLayoutToFieldLayouts = (\n rows: LayoutData['contentType']['layouts']['edit'],\n attributes: Schema['attributes'] = {},\n metadatas: Metadatas,\n components?: {\n configurations: Record<string, ComponentConfiguration>;\n schemas: ComponentsDictionary;\n },\n schemas: Schema[] = []\n) => {\n return rows.map((row) =>\n row\n .map((field) => {\n const attribute = attributes[field.name];\n\n if (!attribute) {\n return null;\n }\n\n const { edit: metadata } = metadatas[field.name];\n\n const settings: Partial<Settings> =\n attribute.type === 'component' && components\n ? components.configurations[attribute.component].settings\n : {};\n\n return {\n attribute,\n disabled: !metadata.editable,\n hint: metadata.description,\n label: metadata.label ?? '',\n name: field.name,\n // @ts-expect-error – mainField does exist on the metadata for a relation.\n mainField: getMainField(attribute, metadata.mainField || settings.mainField, {\n schemas,\n components: components?.schemas ?? {},\n }),\n placeholder: metadata.placeholder ?? '',\n required: attribute.required ?? false,\n size: field.size,\n unique: 'unique' in attribute ? attribute.unique : false,\n visible: metadata.visible ?? true,\n type: attribute.type,\n };\n })\n .filter((field) => field !== null)\n ) as EditFieldLayout[][];\n};\n\n/* -------------------------------------------------------------------------------------------------\n * formatListLayout\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the complete configuration data, the schema & the components used in the schema and\n * formats a list view layout for the content-type. This is much simpler than the edit view layout as there\n * are less options to consider.\n */\nconst formatListLayout = (\n data: LayoutData,\n {\n schemas,\n schema,\n components,\n }: { schemas: Schema[]; schema?: Schema; components: ComponentsDictionary }\n): ListLayout => {\n const listMetadatas = Object.entries(data.contentType.metadatas).reduce<ListLayout['metadatas']>(\n (acc, [attribute, metadata]) => {\n return {\n ...acc,\n [attribute]: metadata.list,\n };\n },\n {}\n );\n /**\n * The fields arranged by the panels, new panels are made for dynamic zones only.\n */\n const listAttributes = convertListLayoutToFieldLayouts(\n data.contentType.layouts.list,\n schema?.attributes,\n listMetadatas,\n { configurations: data.components, schemas: components },\n schemas\n );\n\n return {\n layout: listAttributes,\n settings: { ...data.contentType.settings, displayName: schema?.info.displayName },\n metadatas: listMetadatas,\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n ...data.contentType.options,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * convertListLayoutToFieldLayouts\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the columns from the list view configuration and formats them into a generic object\n * combinining metadata and attribute data.\n *\n * @note We do use this to reformat the list of strings when updating the displayed headers for the list view.\n */\nconst convertListLayoutToFieldLayouts = (\n columns: LayoutData['contentType']['layouts']['list'],\n attributes: Schema['attributes'] = {},\n metadatas: ListLayout['metadatas'],\n components?: {\n configurations: Record<string, ComponentConfiguration>;\n schemas: ComponentsDictionary;\n },\n schemas: Schema[] = []\n) => {\n return columns\n .map((name) => {\n const attribute = attributes[name];\n\n if (!attribute) {\n return null;\n }\n\n const metadata = metadatas[name];\n\n const settings: Partial<Settings> =\n attribute.type === 'component' && components\n ? components.configurations[attribute.component].settings\n : {};\n\n return {\n attribute,\n label: metadata.label ?? '',\n mainField: getMainField(attribute, metadata.mainField || settings.mainField, {\n schemas,\n components: components?.schemas ?? {},\n }),\n name: name,\n searchable: metadata.searchable ?? true,\n sortable: metadata.sortable ?? true,\n } satisfies ListFieldLayout;\n })\n .filter((field) => field !== null) as ListFieldLayout[];\n};\n\nexport {\n useDocLayout,\n useDocumentLayout,\n convertListLayoutToFieldLayouts,\n convertEditLayoutToFieldLayouts,\n DEFAULT_SETTINGS,\n};\nexport type { EditLayout, EditFieldLayout, ListLayout, ListFieldLayout, UseDocumentLayout };\n"],"names":["DEFAULT_SETTINGS","bulkable","filterable","searchable","pagination","defaultSortBy","defaultSortOrder","mainField","pageSize","relationOpenMode","useDocumentLayout","model","schema","components","useDocument","collectionType","skip","query","useQueryParams","runHookWaterfall","useStrapiApp","state","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","isLoading","isLoadingSchemas","schemas","useContentTypeSchema","data","isLoadingConfigs","error","isFetching","isFetchingConfigs","useGetContentTypeConfigurationQuery","React","useEffect","type","message","editLayout","useMemo","formatEditLayout","layout","metadatas","options","settings","listLayout","formatListLayout","edit","HOOKS","MUTATE_EDIT_VIEW_LAYOUT","listViewConversionContext","componentConfigurations","componentSchemas","contentTypeSchemas","list","useDocLayout","useDoc","currentPanelIndex","panelledEditAttributes","convertEditLayoutToFieldLayouts","contentType","layouts","attributes","configurations","reduce","panels","row","some","field","push","componentEditAttributes","Object","entries","acc","uid","configuration","icon","info","displayName","editMetadatas","attribute","metadata","pluginOptions","rows","map","name","component","disabled","editable","hint","description","label","getMainField","placeholder","required","size","unique","visible","filter","listMetadatas","listAttributes","convertListLayoutToFieldLayouts","columns","sortable"],"mappings":";;;;;;;;AAuHA;;AAEkG,2GAE5FA,gBAAAA,GAAmB;IACvBC,QAAAA,EAAU,KAAA;IACVC,UAAAA,EAAY,KAAA;IACZC,UAAAA,EAAY,KAAA;IACZC,UAAAA,EAAY,KAAA;IACZC,aAAAA,EAAe,EAAA;IACfC,gBAAAA,EAAkB,KAAA;IAClBC,SAAAA,EAAW,IAAA;IACXC,QAAAA,EAAU,EAAA;IACVC,gBAAAA,EAAkB;AACpB;AAEA;;;;;;;;;;;;;;;;;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,EAAE,CAAC,GAAGC,cAAAA,EAAAA;AACpB,IAAA,MAAMC,mBAAmBC,YAAAA,CAAa,mBAAA,EAAqB,CAACC,KAAAA,GAAUA,MAAMF,gBAAgB,CAAA;IAC5F,MAAM,EAAEG,kBAAkB,EAAE,GAAGC,eAAAA,EAAAA;AAC/B,IAAA,MAAM,EAAEC,uBAAAA,EAAyBC,cAAc,EAAE,GAAGC,kBAAAA,EAAAA;AACpD,IAAA,MAAM,EAAEC,SAAAA,EAAWC,gBAAgB,EAAEC,OAAO,EAAE,GAAGC,oBAAAA,EAAAA;AAEjD,IAAA,MAAM,EACJC,IAAI,EACJJ,SAAAA,EAAWK,gBAAgB,EAC3BC,KAAK,EACLC,UAAAA,EAAYC,iBAAiB,EAC9B,GAAGC,mCAAAA,CAAoCzB,KAAAA,CAAAA;IAExC,MAAMgB,SAAAA,GAAYC,oBAAoBO,iBAAAA,IAAqBH,gBAAAA;AAE3DK,IAAAA,KAAAA,CAAMC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A;IAEtB,OAAO4E,OAAAA,CACJlB,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,GAAWvC,SAAS,CAAC2C,IAAAA,CAAK;AAEhC,QAAA,MAAMzC,QAAAA,GACJoC,SAAAA,CAAU5C,IAAI,KAAK,eAAe1B,UAAAA,GAC9BA,UAAAA,CAAWqD,cAAc,CAACiB,UAAUM,SAAS,CAAC,CAAC1C,QAAQ,GACvD,EAAC;QAEP,OAAO;AACLoC,YAAAA,SAAAA;YACAW,KAAAA,EAAOV,QAAAA,CAASU,KAAK,IAAI,EAAA;AACzBvF,YAAAA,SAAAA,EAAWwF,aAAaZ,SAAAA,EAAWC,QAAAA,CAAS7E,SAAS,IAAIwC,QAAAA,CAASxC,SAAS,EAAE;AAC3EsB,gBAAAA,OAAAA;gBACAhB,UAAAA,EAAYA,UAAAA,EAAYgB,WAAW;AACrC,aAAA,CAAA;YACA2D,IAAAA,EAAMA,IAAAA;YACNrF,UAAAA,EAAYiF,QAAAA,CAASjF,UAAU,IAAI,IAAA;YACnCuG,QAAAA,EAAUtB,QAAAA,CAASsB,QAAQ,IAAI;AACjC,SAAA;AACF,IAAA,CAAA,CAAA,CACCL,MAAM,CAAC,CAAC9B,KAAAA,GAAUA,KAAAA,KAAU,IAAA,CAAA;AACjC;;;;"}
@@ -184,11 +184,23 @@ const EMPTY_RELATION_RESULTS = [];
184
184
  ...serverData
185
185
  ]);
186
186
  /**
187
+ * Connect items (e.g. from fill-from-locale) may lack href/label. Ensure they have them
188
+ * so ListItem's getCollectionType(href) and display work correctly.
189
+ */ const connectItems = (field.value?.connect ?? []).map((rel)=>{
190
+ const urlLocaleParam = rel.locale ? `?plugins[i18n][locale]=${rel.locale}` : '';
191
+ if (rel.href) return rel;
192
+ return {
193
+ ...rel,
194
+ label: rel.label ?? relations$1.getRelationLabel(rel, props.mainField),
195
+ href: `../${collections.COLLECTION_TYPES}/${targetModel}/${rel.documentId}${urlLocaleParam}`
196
+ };
197
+ });
198
+ /**
187
199
  * THIS IS CRUCIAL. If you don't sort by the __temp_key__ which comes from fractional indexing
188
200
  * then the list will be in the wrong order.
189
201
  */ return [
190
202
  ...transformedRels,
191
- ...field.value?.connect ?? []
203
+ ...connectItems
192
204
  ].sort((a, b)=>{
193
205
  if (a.__temp_key__ < b.__temp_key__) return -1;
194
206
  if (a.__temp_key__ > b.__temp_key__) return 1;