@strapi/content-manager 0.0.0-experimental.e5d4b412da0d932b61b2fa5012d16513fda6de04 → 0.0.0-experimental.e65c671348c825470427c509f1273497b0b4b828
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/components/LeftMenu.js +13 -15
- package/dist/admin/components/LeftMenu.js.map +1 -1
- package/dist/admin/components/LeftMenu.mjs +14 -16
- package/dist/admin/components/LeftMenu.mjs.map +1 -1
- package/dist/admin/components/Widgets.js +4 -2
- package/dist/admin/components/Widgets.js.map +1 -1
- package/dist/admin/components/Widgets.mjs +4 -2
- package/dist/admin/components/Widgets.mjs.map +1 -1
- package/dist/admin/pages/EditView/EditViewPage.js +3 -11
- package/dist/admin/pages/EditView/EditViewPage.js.map +1 -1
- package/dist/admin/pages/EditView/EditViewPage.mjs +4 -12
- package/dist/admin/pages/EditView/EditViewPage.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/Blocker.js +18 -0
- package/dist/admin/pages/EditView/components/Blocker.js.map +1 -0
- package/dist/admin/pages/EditView/components/Blocker.mjs +16 -0
- package/dist/admin/pages/EditView/components/Blocker.mjs.map +1 -0
- package/dist/admin/pages/EditView/components/InputRenderer.js +20 -7
- package/dist/admin/pages/EditView/components/InputRenderer.js.map +1 -1
- package/dist/admin/pages/EditView/components/InputRenderer.mjs +20 -7
- package/dist/admin/pages/EditView/components/InputRenderer.mjs.map +1 -1
- package/dist/admin/pages/EditView/utils/data.js +27 -8
- package/dist/admin/pages/EditView/utils/data.js.map +1 -1
- package/dist/admin/pages/EditView/utils/data.mjs +27 -8
- package/dist/admin/pages/EditView/utils/data.mjs.map +1 -1
- package/dist/admin/preview/components/InputPopover.js +189 -0
- package/dist/admin/preview/components/InputPopover.js.map +1 -0
- package/dist/admin/preview/components/InputPopover.mjs +167 -0
- package/dist/admin/preview/components/InputPopover.mjs.map +1 -0
- package/dist/admin/preview/components/PreviewHeader.js +0 -1
- package/dist/admin/preview/components/PreviewHeader.js.map +1 -1
- package/dist/admin/preview/components/PreviewHeader.mjs +0 -1
- package/dist/admin/preview/components/PreviewHeader.mjs.map +1 -1
- package/dist/admin/preview/hooks/usePreviewInputManager.js +77 -0
- package/dist/admin/preview/hooks/usePreviewInputManager.js.map +1 -0
- package/dist/admin/preview/hooks/usePreviewInputManager.mjs +56 -0
- package/dist/admin/preview/hooks/usePreviewInputManager.mjs.map +1 -0
- package/dist/admin/preview/pages/Preview.js +122 -119
- package/dist/admin/preview/pages/Preview.js.map +1 -1
- package/dist/admin/preview/pages/Preview.mjs +122 -119
- package/dist/admin/preview/pages/Preview.mjs.map +1 -1
- package/dist/admin/preview/utils/constants.js +36 -1
- package/dist/admin/preview/utils/constants.js.map +1 -1
- package/dist/admin/preview/utils/constants.mjs +35 -2
- package/dist/admin/preview/utils/constants.mjs.map +1 -1
- package/dist/admin/preview/utils/fieldUtils.js +107 -0
- package/dist/admin/preview/utils/fieldUtils.js.map +1 -0
- package/dist/admin/preview/utils/fieldUtils.mjs +102 -0
- package/dist/admin/preview/utils/fieldUtils.mjs.map +1 -0
- package/dist/admin/preview/utils/getSendMessage.js +22 -0
- package/dist/admin/preview/utils/getSendMessage.js.map +1 -0
- package/dist/admin/preview/utils/getSendMessage.mjs +20 -0
- package/dist/admin/preview/utils/getSendMessage.mjs.map +1 -0
- package/dist/admin/preview/utils/previewScript.js +423 -92
- package/dist/admin/preview/utils/previewScript.js.map +1 -1
- package/dist/admin/preview/utils/previewScript.mjs +423 -92
- package/dist/admin/preview/utils/previewScript.mjs.map +1 -1
- package/dist/admin/src/pages/EditView/components/Blocker.d.ts +5 -0
- package/dist/admin/src/pages/EditView/components/InputRenderer.d.ts +1 -1
- package/dist/admin/src/preview/components/InputPopover.d.ts +6 -0
- package/dist/admin/src/preview/hooks/usePreviewInputManager.d.ts +5 -0
- package/dist/admin/src/preview/pages/Preview.d.ts +12 -0
- package/dist/admin/src/preview/utils/constants.d.ts +39 -1
- package/dist/admin/src/preview/utils/fieldUtils.d.ts +22 -0
- package/dist/admin/src/preview/utils/getSendMessage.d.ts +11 -0
- package/dist/admin/src/preview/utils/previewScript.d.ts +7 -1
- package/dist/admin/translations/en.json.js +6 -0
- package/dist/admin/translations/en.json.js.map +1 -1
- package/dist/admin/translations/en.json.mjs +6 -0
- package/dist/admin/translations/en.json.mjs.map +1 -1
- package/dist/admin/translations/es.json.js +1 -0
- package/dist/admin/translations/es.json.js.map +1 -1
- package/dist/admin/translations/es.json.mjs +1 -0
- package/dist/admin/translations/es.json.mjs.map +1 -1
- package/dist/admin/translations/fr.json.js +1 -0
- package/dist/admin/translations/fr.json.js.map +1 -1
- package/dist/admin/translations/fr.json.mjs +1 -0
- package/dist/admin/translations/fr.json.mjs.map +1 -1
- package/dist/server/homepage/services/homepage.js +1 -1
- package/dist/server/homepage/services/homepage.js.map +1 -1
- package/dist/server/homepage/services/homepage.mjs +1 -1
- package/dist/server/homepage/services/homepage.mjs.map +1 -1
- package/dist/server/src/homepage/services/homepage.d.ts.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditViewPage.js","sources":["../../../../admin/src/pages/EditView/EditViewPage.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n Page,\n Blocker,\n Form,\n useForm,\n useRBAC,\n useNotification,\n useQueryParams,\n tours,\n} from '@strapi/admin/strapi-admin';\nimport { Grid, Main, Tabs, Box } from '@strapi/design-system';\nimport { useIntl } from 'react-intl';\nimport { useLocation, useParams } from 'react-router-dom';\nimport { styled } from 'styled-components';\n\nimport { SINGLE_TYPES } from '../../constants/collections';\nimport { PERMISSIONS } from '../../constants/plugin';\nimport { DocumentRBAC, useDocumentRBAC } from '../../features/DocumentRBAC';\nimport { useDoc, type UseDocument } from '../../hooks/useDocument';\nimport { useDocumentLayout } from '../../hooks/useDocumentLayout';\nimport { useLazyComponents } from '../../hooks/useLazyComponents';\nimport { useOnce } from '../../hooks/useOnce';\nimport { getTranslation } from '../../utils/translations';\nimport { createYupSchema } from '../../utils/validation';\n\nimport { FormLayout } from './components/FormLayout';\nimport { Header } from './components/Header';\nimport { Panels } from './components/Panels';\nimport { handleInvisibleAttributes } from './utils/data';\n\n/* -------------------------------------------------------------------------------------------------\n * EditViewPage\n * -----------------------------------------------------------------------------------------------*/\n\n// Needs to be wrapped in a component to have access to the form context via a hook.\n// Using the Form component's render prop instead would cause unnecessary re-renders of Form children\nconst BlockerWrapper = () => {\n const resetForm = useForm('BlockerWrapper', (state) => state.resetForm);\n\n // We reset the form to the published version to avoid errors like – https://strapi-inc.atlassian.net/browse/CONTENT-2284\n return <Blocker onProceed={resetForm} />;\n};\n\nconst EditViewPage = () => {\n const location = useLocation();\n const [\n {\n query: { status },\n },\n setQuery,\n ] = useQueryParams<{ status: 'draft' | 'published' }>({\n status: 'draft',\n });\n const { formatMessage } = useIntl();\n const { toggleNotification } = useNotification();\n\n const doc = useDoc();\n const {\n document,\n meta,\n isLoading: isLoadingDocument,\n schema,\n components,\n collectionType,\n id,\n model,\n hasError,\n getTitle,\n getInitialFormValues,\n } = doc;\n\n const hasDraftAndPublished = schema?.options?.draftAndPublish ?? false;\n\n useOnce(() => {\n /**\n * We only ever want to fire the notification once otherwise\n * whenever the app re-renders it'll pop up regardless of\n * what we do because the state comes from react-router-dom\n */\n if (location?.state && 'error' in location.state) {\n toggleNotification({\n type: 'danger',\n message: location.state.error,\n timeout: 5000,\n });\n }\n });\n\n const isLoadingActionsRBAC = useDocumentRBAC('EditViewPage', (state) => state.isLoading);\n\n const isSingleType = collectionType === SINGLE_TYPES;\n\n /**\n * single-types don't current have an id, but because they're a singleton\n * we can simply use the update operation to continuously update the same\n * document with varying params.\n */\n const isCreatingDocument = !id && !isSingleType;\n\n const {\n isLoading: isLoadingLayout,\n edit: {\n layout,\n settings: { mainField },\n },\n } = useDocumentLayout(model);\n const pageTitle = getTitle(mainField);\n\n const { isLazyLoading } = useLazyComponents([]);\n\n const isLoading = isLoadingActionsRBAC || isLoadingDocument || isLoadingLayout || isLazyLoading;\n\n const initialValues = getInitialFormValues(isCreatingDocument);\n\n if (isLoading && !document?.documentId) {\n return <Page.Loading />;\n }\n\n if (!initialValues || hasError) {\n return <Page.Error />;\n }\n\n const handleTabChange = (status: string) => {\n if (status === 'published' || status === 'draft') {\n setQuery({ status }, 'push', true);\n }\n };\n\n const validateSync = (values: Record<string, unknown>, options: Record<string, string>) => {\n const yupSchema = createYupSchema(schema?.attributes, components, {\n status,\n ...options,\n });\n\n return yupSchema.validateSync(values, { abortEarly: false });\n };\n\n return (\n <Main paddingLeft={10} paddingRight={10}>\n <Page.Title>{pageTitle}</Page.Title>\n {isSingleType && (\n <tours.contentManager.Introduction>\n {/* Invisible Anchor */}\n <Box />\n </tours.contentManager.Introduction>\n )}\n <Form\n disabled={hasDraftAndPublished && status === 'published'}\n initialValues={initialValues}\n method={isCreatingDocument ? 'POST' : 'PUT'}\n validate={(values: Record<string, unknown>, options: Record<string, string>) => {\n // removes hidden fields from the validation\n // this is necessary because the yup schema doesn't know about the visibility conditions\n // and we don't want to validate fields that are not visible\n const { data: cleanedValues, removedAttributes } = handleInvisibleAttributes(values, {\n schema,\n initialValues,\n components,\n });\n\n const yupSchema = createYupSchema(schema?.attributes, components, {\n status,\n removedAttributes,\n ...options,\n });\n\n return yupSchema.validate(cleanedValues, { abortEarly: false });\n }}\n initialErrors={location?.state?.forceValidation ? validateSync(initialValues, {}) : {}}\n >\n <>\n <Header\n isCreating={isCreatingDocument}\n status={hasDraftAndPublished ? getDocumentStatus(document, meta) : undefined}\n title={pageTitle}\n />\n <Tabs.Root variant=\"simple\" value={status} onValueChange={handleTabChange}>\n <Tabs.List\n aria-label={formatMessage({\n id: getTranslation('containers.edit.tabs.label'),\n defaultMessage: 'Document status',\n })}\n >\n {hasDraftAndPublished ? (\n <>\n <StatusTab value=\"draft\">\n {formatMessage({\n id: getTranslation('containers.edit.tabs.draft'),\n defaultMessage: 'draft',\n })}\n </StatusTab>\n <StatusTab\n disabled={!meta || meta.availableStatus.length === 0}\n value=\"published\"\n >\n {formatMessage({\n id: getTranslation('containers.edit.tabs.published'),\n defaultMessage: 'published',\n })}\n </StatusTab>\n </>\n ) : null}\n </Tabs.List>\n <Grid.Root paddingTop={8} gap={4}>\n <Grid.Item col={9} s={12} direction=\"column\" alignItems=\"stretch\">\n <Tabs.Content value=\"draft\">\n <tours.contentManager.Fields>\n <Box />\n </tours.contentManager.Fields>\n <FormLayout layout={layout} document={doc} />\n </Tabs.Content>\n <Tabs.Content value=\"published\">\n <FormLayout layout={layout} document={doc} />\n </Tabs.Content>\n </Grid.Item>\n <Grid.Item col={3} s={12} direction=\"column\" alignItems=\"stretch\">\n <Panels />\n </Grid.Item>\n </Grid.Root>\n </Tabs.Root>\n <BlockerWrapper />\n </>\n </Form>\n </Main>\n );\n};\n\nconst StatusTab = styled(Tabs.Trigger)`\n text-transform: uppercase;\n`;\n\n/**\n * @internal\n * @description Returns the status of the document where its latest state takes priority,\n * this typically will be \"published\" unless a user has edited their draft in which we should\n * display \"modified\".\n */\nconst getDocumentStatus = (\n document: ReturnType<UseDocument>['document'],\n meta: ReturnType<UseDocument>['meta']\n): 'draft' | 'published' | 'modified' => {\n const docStatus = document?.status;\n const statuses = meta?.availableStatus ?? [];\n\n /**\n * Creating an entry\n */\n if (!docStatus) {\n return 'draft';\n }\n\n /**\n * We're viewing a draft, but the document could have a published version\n */\n if (docStatus === 'draft' && statuses.find((doc) => doc.publishedAt !== null)) {\n return 'published';\n }\n\n return docStatus;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * ProtectedEditViewPage\n * -----------------------------------------------------------------------------------------------*/\n\nconst ProtectedEditViewPage = () => {\n const { slug = '' } = useParams<{\n slug: string;\n }>();\n const {\n permissions = [],\n isLoading,\n error,\n } = useRBAC(\n PERMISSIONS.map((action) => ({\n action,\n subject: slug,\n }))\n );\n\n if (isLoading) {\n return <Page.Loading />;\n }\n\n if (error || !slug) {\n return <Page.Error />;\n }\n\n return (\n <Page.Protect permissions={permissions}>\n {({ permissions }) => (\n <DocumentRBAC permissions={permissions}>\n <EditViewPage />\n </DocumentRBAC>\n )}\n </Page.Protect>\n );\n};\n\nexport { EditViewPage, ProtectedEditViewPage, getDocumentStatus };\n"],"names":["BlockerWrapper","resetForm","useForm","state","_jsx","Blocker","onProceed","EditViewPage","location","useLocation","query","status","setQuery","useQueryParams","formatMessage","useIntl","toggleNotification","useNotification","doc","useDoc","document","meta","isLoading","isLoadingDocument","schema","components","collectionType","id","model","hasError","getTitle","getInitialFormValues","hasDraftAndPublished","options","draftAndPublish","useOnce","type","message","error","timeout","isLoadingActionsRBAC","useDocumentRBAC","isSingleType","SINGLE_TYPES","isCreatingDocument","isLoadingLayout","edit","layout","settings","mainField","useDocumentLayout","pageTitle","isLazyLoading","useLazyComponents","initialValues","documentId","Page","Loading","Error","handleTabChange","validateSync","values","yupSchema","createYupSchema","attributes","abortEarly","_jsxs","Main","paddingLeft","paddingRight","Title","tours","contentManager","Introduction","Box","Form","disabled","method","validate","data","cleanedValues","removedAttributes","handleInvisibleAttributes","initialErrors","forceValidation","_Fragment","Header","isCreating","getDocumentStatus","undefined","title","Tabs","Root","variant","value","onValueChange","List","aria-label","getTranslation","defaultMessage","StatusTab","availableStatus","length","Grid","paddingTop","gap","Item","col","s","direction","alignItems","Content","Fields","FormLayout","Panels","styled","Trigger","docStatus","statuses","find","publishedAt","ProtectedEditViewPage","slug","useParams","permissions","useRBAC","PERMISSIONS","map","action","subject","Protect","DocumentRBAC"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAgCA;;AAEkG;AAGlG;AACA,MAAMA,cAAiB,GAAA,IAAA;AACrB,IAAA,MAAMC,YAAYC,mBAAQ,CAAA,gBAAA,EAAkB,CAACC,KAAAA,GAAUA,MAAMF,SAAS,CAAA;;AAGtE,IAAA,qBAAOG,cAACC,CAAAA,mBAAAA,EAAAA;QAAQC,SAAWL,EAAAA;;AAC7B,CAAA;AAEA,MAAMM,YAAe,GAA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AAOH,SAAAA;AACT;AAEA;;AAEkG,2GAE5FI,qBAAwB,GAAA,IAAA;AAC5B,IAAA,MAAM,EAAEC,IAAAA,GAAO,EAAE,EAAE,GAAGC,wBAAAA,EAAAA;AAGtB,IAAA,MAAM,EACJC,WAAAA,GAAc,EAAE,EAChBtG,SAAS,EACTgB,KAAK,EACN,GAAGuF,oBACFC,kBAAYC,CAAAA,GAAG,CAAC,CAACC,UAAY;AAC3BA,YAAAA,MAAAA;YACAC,OAASP,EAAAA;SACX,CAAA,CAAA,CAAA;AAGF,IAAA,IAAIpG,SAAW,EAAA;QACb,qBAAOlB,cAAA,CAACoD,iBAAKC,OAAO,EAAA,EAAA,CAAA;AACtB;IAEA,IAAInB,KAAAA,IAAS,CAACoF,IAAM,EAAA;QAClB,qBAAOtH,cAAA,CAACoD,iBAAKE,KAAK,EAAA,EAAA,CAAA;AACpB;IAEA,qBACEtD,cAAA,CAACoD,iBAAK0E,OAAO,EAAA;QAACN,WAAaA,EAAAA,WAAAA;AACxB,QAAA,QAAA,EAAA,CAAC,EAAEA,WAAW,EAAE,iBACfxH,cAAC+H,CAAAA,yBAAAA,EAAAA;gBAAaP,WAAaA,EAAAA,WAAAA;AACzB,gBAAA,QAAA,gBAAAxH,cAACG,CAAAA,YAAAA,EAAAA,EAAAA;;;AAKX;;;;;;"}
|
|
1
|
+
{"version":3,"file":"EditViewPage.js","sources":["../../../../admin/src/pages/EditView/EditViewPage.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n Page,\n Form,\n useRBAC,\n useNotification,\n useQueryParams,\n tours,\n} from '@strapi/admin/strapi-admin';\nimport { Grid, Main, Tabs, Box } from '@strapi/design-system';\nimport { useIntl } from 'react-intl';\nimport { useLocation, useParams } from 'react-router-dom';\nimport { styled } from 'styled-components';\n\nimport { SINGLE_TYPES } from '../../constants/collections';\nimport { PERMISSIONS } from '../../constants/plugin';\nimport { DocumentRBAC, useDocumentRBAC } from '../../features/DocumentRBAC';\nimport { useDoc, type UseDocument } from '../../hooks/useDocument';\nimport { useDocumentLayout } from '../../hooks/useDocumentLayout';\nimport { useLazyComponents } from '../../hooks/useLazyComponents';\nimport { useOnce } from '../../hooks/useOnce';\nimport { getTranslation } from '../../utils/translations';\nimport { createYupSchema } from '../../utils/validation';\n\nimport { Blocker } from './components/Blocker';\nimport { FormLayout } from './components/FormLayout';\nimport { Header } from './components/Header';\nimport { Panels } from './components/Panels';\nimport { handleInvisibleAttributes } from './utils/data';\n\n/* -------------------------------------------------------------------------------------------------\n * EditViewPage\n * -----------------------------------------------------------------------------------------------*/\n\nconst EditViewPage = () => {\n const location = useLocation();\n const [\n {\n query: { status },\n },\n setQuery,\n ] = useQueryParams<{ status: 'draft' | 'published' }>({\n status: 'draft',\n });\n const { formatMessage } = useIntl();\n const { toggleNotification } = useNotification();\n\n const doc = useDoc();\n const {\n document,\n meta,\n isLoading: isLoadingDocument,\n schema,\n components,\n collectionType,\n id,\n model,\n hasError,\n getTitle,\n getInitialFormValues,\n } = doc;\n\n const hasDraftAndPublished = schema?.options?.draftAndPublish ?? false;\n\n useOnce(() => {\n /**\n * We only ever want to fire the notification once otherwise\n * whenever the app re-renders it'll pop up regardless of\n * what we do because the state comes from react-router-dom\n */\n if (location?.state && 'error' in location.state) {\n toggleNotification({\n type: 'danger',\n message: location.state.error,\n timeout: 5000,\n });\n }\n });\n\n const isLoadingActionsRBAC = useDocumentRBAC('EditViewPage', (state) => state.isLoading);\n\n const isSingleType = collectionType === SINGLE_TYPES;\n\n /**\n * single-types don't current have an id, but because they're a singleton\n * we can simply use the update operation to continuously update the same\n * document with varying params.\n */\n const isCreatingDocument = !id && !isSingleType;\n\n const {\n isLoading: isLoadingLayout,\n edit: {\n layout,\n settings: { mainField },\n },\n } = useDocumentLayout(model);\n const pageTitle = getTitle(mainField);\n\n const { isLazyLoading } = useLazyComponents([]);\n\n const isLoading = isLoadingActionsRBAC || isLoadingDocument || isLoadingLayout || isLazyLoading;\n\n const initialValues = getInitialFormValues(isCreatingDocument);\n\n if (isLoading && !document?.documentId) {\n return <Page.Loading />;\n }\n\n if (!initialValues || hasError) {\n return <Page.Error />;\n }\n\n const handleTabChange = (status: string) => {\n if (status === 'published' || status === 'draft') {\n setQuery({ status }, 'push', true);\n }\n };\n\n const validateSync = (values: Record<string, unknown>, options: Record<string, string>) => {\n const yupSchema = createYupSchema(schema?.attributes, components, {\n status,\n ...options,\n });\n\n return yupSchema.validateSync(values, { abortEarly: false });\n };\n\n return (\n <Main paddingLeft={10} paddingRight={10}>\n <Page.Title>{pageTitle}</Page.Title>\n {isSingleType && (\n <tours.contentManager.Introduction>\n {/* Invisible Anchor */}\n <Box />\n </tours.contentManager.Introduction>\n )}\n <Form\n disabled={hasDraftAndPublished && status === 'published'}\n initialValues={initialValues}\n method={isCreatingDocument ? 'POST' : 'PUT'}\n validate={(values: Record<string, unknown>, options: Record<string, string>) => {\n // removes hidden fields from the validation\n // this is necessary because the yup schema doesn't know about the visibility conditions\n // and we don't want to validate fields that are not visible\n const { data: cleanedValues, removedAttributes } = handleInvisibleAttributes(values, {\n schema,\n initialValues,\n components,\n });\n\n const yupSchema = createYupSchema(schema?.attributes, components, {\n status,\n removedAttributes,\n ...options,\n });\n\n return yupSchema.validate(cleanedValues, { abortEarly: false });\n }}\n initialErrors={location?.state?.forceValidation ? validateSync(initialValues, {}) : {}}\n >\n <>\n <Header\n isCreating={isCreatingDocument}\n status={hasDraftAndPublished ? getDocumentStatus(document, meta) : undefined}\n title={pageTitle}\n />\n <Tabs.Root variant=\"simple\" value={status} onValueChange={handleTabChange}>\n <Tabs.List\n aria-label={formatMessage({\n id: getTranslation('containers.edit.tabs.label'),\n defaultMessage: 'Document status',\n })}\n >\n {hasDraftAndPublished ? (\n <>\n <StatusTab value=\"draft\">\n {formatMessage({\n id: getTranslation('containers.edit.tabs.draft'),\n defaultMessage: 'draft',\n })}\n </StatusTab>\n <StatusTab\n disabled={!meta || meta.availableStatus.length === 0}\n value=\"published\"\n >\n {formatMessage({\n id: getTranslation('containers.edit.tabs.published'),\n defaultMessage: 'published',\n })}\n </StatusTab>\n </>\n ) : null}\n </Tabs.List>\n <Grid.Root paddingTop={8} gap={4}>\n <Grid.Item col={9} s={12} direction=\"column\" alignItems=\"stretch\">\n <Tabs.Content value=\"draft\">\n <tours.contentManager.Fields>\n <Box />\n </tours.contentManager.Fields>\n <FormLayout layout={layout} document={doc} />\n </Tabs.Content>\n <Tabs.Content value=\"published\">\n <FormLayout layout={layout} document={doc} />\n </Tabs.Content>\n </Grid.Item>\n <Grid.Item col={3} s={12} direction=\"column\" alignItems=\"stretch\">\n <Panels />\n </Grid.Item>\n </Grid.Root>\n </Tabs.Root>\n <Blocker />\n </>\n </Form>\n </Main>\n );\n};\n\nconst StatusTab = styled(Tabs.Trigger)`\n text-transform: uppercase;\n`;\n\n/**\n * @internal\n * @description Returns the status of the document where its latest state takes priority,\n * this typically will be \"published\" unless a user has edited their draft in which we should\n * display \"modified\".\n */\nconst getDocumentStatus = (\n document: ReturnType<UseDocument>['document'],\n meta: ReturnType<UseDocument>['meta']\n): 'draft' | 'published' | 'modified' => {\n const docStatus = document?.status;\n const statuses = meta?.availableStatus ?? [];\n\n /**\n * Creating an entry\n */\n if (!docStatus) {\n return 'draft';\n }\n\n /**\n * We're viewing a draft, but the document could have a published version\n */\n if (docStatus === 'draft' && statuses.find((doc) => doc.publishedAt !== null)) {\n return 'published';\n }\n\n return docStatus;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * ProtectedEditViewPage\n * -----------------------------------------------------------------------------------------------*/\n\nconst ProtectedEditViewPage = () => {\n const { slug = '' } = useParams<{\n slug: string;\n }>();\n const {\n permissions = [],\n isLoading,\n error,\n } = useRBAC(\n PERMISSIONS.map((action) => ({\n action,\n subject: slug,\n }))\n );\n\n if (isLoading) {\n return <Page.Loading />;\n }\n\n if (error || !slug) {\n return <Page.Error />;\n }\n\n return (\n <Page.Protect permissions={permissions}>\n {({ permissions }) => (\n <DocumentRBAC permissions={permissions}>\n <EditViewPage />\n </DocumentRBAC>\n )}\n </Page.Protect>\n );\n};\n\nexport { EditViewPage, ProtectedEditViewPage, getDocumentStatus };\n"],"names":["EditViewPage","location","useLocation","query","status","setQuery","useQueryParams","formatMessage","useIntl","toggleNotification","useNotification","doc","useDoc","document","meta","isLoading","isLoadingDocument","schema","components","collectionType","id","model","hasError","getTitle","getInitialFormValues","hasDraftAndPublished","options","draftAndPublish","useOnce","state","type","message","error","timeout","isLoadingActionsRBAC","useDocumentRBAC","isSingleType","SINGLE_TYPES","isCreatingDocument","isLoadingLayout","edit","layout","settings","mainField","useDocumentLayout","pageTitle","isLazyLoading","useLazyComponents","initialValues","documentId","_jsx","Page","Loading","Error","handleTabChange","validateSync","values","yupSchema","createYupSchema","attributes","abortEarly","_jsxs","Main","paddingLeft","paddingRight","Title","tours","contentManager","Introduction","Box","Form","disabled","method","validate","data","cleanedValues","removedAttributes","handleInvisibleAttributes","initialErrors","forceValidation","_Fragment","Header","isCreating","getDocumentStatus","undefined","title","Tabs","Root","variant","value","onValueChange","List","aria-label","getTranslation","defaultMessage","StatusTab","availableStatus","length","Grid","paddingTop","gap","Item","col","s","direction","alignItems","Content","Fields","FormLayout","Panels","Blocker","styled","Trigger","docStatus","statuses","find","publishedAt","ProtectedEditViewPage","slug","useParams","permissions","useRBAC","PERMISSIONS","map","action","subject","Protect","DocumentRBAC"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA+BA;;AAEkG,2GAE5FA,YAAe,GAAA,IAAA;AACnB,IAAA,MAAMC,QAAWC,GAAAA,0BAAAA,EAAAA;IACjB,MAAM,CACJ,EACEC,KAAAA,EAAO,EAAEC,MAAM,EAAE,EAClB,EACDC,QACD,CAAA,GAAGC,0BAAkD,CAAA;QACpDF,MAAQ,EAAA;AACV,KAAA,CAAA;IACA,MAAM,EAAEG,aAAa,EAAE,GAAGC,iBAAAA,EAAAA;IAC1B,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,2BAAAA,EAAAA;AAE/B,IA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P,EAAAA;SACX,CAAA,CAAA,CAAA;AAGF,IAAA,IAAIvG,SAAW,EAAA;QACb,qBAAOmC,cAAA,CAACC,iBAAKC,OAAO,EAAA,EAAA,CAAA;AACtB;IAEA,IAAIpB,KAAAA,IAAS,CAACsF,IAAM,EAAA;QAClB,qBAAOpE,cAAA,CAACC,iBAAKE,KAAK,EAAA,EAAA,CAAA;AACpB;IAEA,qBACEH,cAAA,CAACC,iBAAK2E,OAAO,EAAA;QAACN,WAAaA,EAAAA,WAAAA;AACxB,QAAA,QAAA,EAAA,CAAC,EAAEA,WAAW,EAAE,iBACftE,cAAC6E,CAAAA,yBAAAA,EAAAA;gBAAaP,WAAaA,EAAAA,WAAAA;AACzB,gBAAA,QAAA,gBAAAtE,cAAClD,CAAAA,YAAAA,EAAAA,EAAAA;;;AAKX;;;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import 'react';
|
|
3
|
-
import { useQueryParams, useNotification, Page, tours, Form, useRBAC
|
|
3
|
+
import { useQueryParams, useNotification, Page, tours, Form, useRBAC } from '@strapi/admin/strapi-admin';
|
|
4
4
|
import { Tabs, Main, Box, Grid } from '@strapi/design-system';
|
|
5
5
|
import { useIntl } from 'react-intl';
|
|
6
6
|
import { useLocation, useParams } from 'react-router-dom';
|
|
@@ -14,6 +14,7 @@ import { useLazyComponents } from '../../hooks/useLazyComponents.mjs';
|
|
|
14
14
|
import { useOnce } from '../../hooks/useOnce.mjs';
|
|
15
15
|
import { getTranslation } from '../../utils/translations.mjs';
|
|
16
16
|
import { createYupSchema } from '../../utils/validation.mjs';
|
|
17
|
+
import { Blocker } from './components/Blocker.mjs';
|
|
17
18
|
import { FormLayout } from './components/FormLayout.mjs';
|
|
18
19
|
import { Header } from './components/Header.mjs';
|
|
19
20
|
import { Panels } from './components/Panels.mjs';
|
|
@@ -21,16 +22,7 @@ import { handleInvisibleAttributes } from './utils/data.mjs';
|
|
|
21
22
|
|
|
22
23
|
/* -------------------------------------------------------------------------------------------------
|
|
23
24
|
* EditViewPage
|
|
24
|
-
* -----------------------------------------------------------------------------------------------*/
|
|
25
|
-
// Using the Form component's render prop instead would cause unnecessary re-renders of Form children
|
|
26
|
-
const BlockerWrapper = ()=>{
|
|
27
|
-
const resetForm = useForm('BlockerWrapper', (state)=>state.resetForm);
|
|
28
|
-
// We reset the form to the published version to avoid errors like – https://strapi-inc.atlassian.net/browse/CONTENT-2284
|
|
29
|
-
return /*#__PURE__*/ jsx(Blocker, {
|
|
30
|
-
onProceed: resetForm
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
const EditViewPage = ()=>{
|
|
25
|
+
* -----------------------------------------------------------------------------------------------*/ const EditViewPage = ()=>{
|
|
34
26
|
const location = useLocation();
|
|
35
27
|
const [{ query: { status } }, setQuery] = useQueryParams({
|
|
36
28
|
status: 'draft'
|
|
@@ -199,7 +191,7 @@ const EditViewPage = ()=>{
|
|
|
199
191
|
})
|
|
200
192
|
]
|
|
201
193
|
}),
|
|
202
|
-
/*#__PURE__*/ jsx(
|
|
194
|
+
/*#__PURE__*/ jsx(Blocker, {})
|
|
203
195
|
]
|
|
204
196
|
})
|
|
205
197
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditViewPage.mjs","sources":["../../../../admin/src/pages/EditView/EditViewPage.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n Page,\n Blocker,\n Form,\n useForm,\n useRBAC,\n useNotification,\n useQueryParams,\n tours,\n} from '@strapi/admin/strapi-admin';\nimport { Grid, Main, Tabs, Box } from '@strapi/design-system';\nimport { useIntl } from 'react-intl';\nimport { useLocation, useParams } from 'react-router-dom';\nimport { styled } from 'styled-components';\n\nimport { SINGLE_TYPES } from '../../constants/collections';\nimport { PERMISSIONS } from '../../constants/plugin';\nimport { DocumentRBAC, useDocumentRBAC } from '../../features/DocumentRBAC';\nimport { useDoc, type UseDocument } from '../../hooks/useDocument';\nimport { useDocumentLayout } from '../../hooks/useDocumentLayout';\nimport { useLazyComponents } from '../../hooks/useLazyComponents';\nimport { useOnce } from '../../hooks/useOnce';\nimport { getTranslation } from '../../utils/translations';\nimport { createYupSchema } from '../../utils/validation';\n\nimport { FormLayout } from './components/FormLayout';\nimport { Header } from './components/Header';\nimport { Panels } from './components/Panels';\nimport { handleInvisibleAttributes } from './utils/data';\n\n/* -------------------------------------------------------------------------------------------------\n * EditViewPage\n * -----------------------------------------------------------------------------------------------*/\n\n// Needs to be wrapped in a component to have access to the form context via a hook.\n// Using the Form component's render prop instead would cause unnecessary re-renders of Form children\nconst BlockerWrapper = () => {\n const resetForm = useForm('BlockerWrapper', (state) => state.resetForm);\n\n // We reset the form to the published version to avoid errors like – https://strapi-inc.atlassian.net/browse/CONTENT-2284\n return <Blocker onProceed={resetForm} />;\n};\n\nconst EditViewPage = () => {\n const location = useLocation();\n const [\n {\n query: { status },\n },\n setQuery,\n ] = useQueryParams<{ status: 'draft' | 'published' }>({\n status: 'draft',\n });\n const { formatMessage } = useIntl();\n const { toggleNotification } = useNotification();\n\n const doc = useDoc();\n const {\n document,\n meta,\n isLoading: isLoadingDocument,\n schema,\n components,\n collectionType,\n id,\n model,\n hasError,\n getTitle,\n getInitialFormValues,\n } = doc;\n\n const hasDraftAndPublished = schema?.options?.draftAndPublish ?? false;\n\n useOnce(() => {\n /**\n * We only ever want to fire the notification once otherwise\n * whenever the app re-renders it'll pop up regardless of\n * what we do because the state comes from react-router-dom\n */\n if (location?.state && 'error' in location.state) {\n toggleNotification({\n type: 'danger',\n message: location.state.error,\n timeout: 5000,\n });\n }\n });\n\n const isLoadingActionsRBAC = useDocumentRBAC('EditViewPage', (state) => state.isLoading);\n\n const isSingleType = collectionType === SINGLE_TYPES;\n\n /**\n * single-types don't current have an id, but because they're a singleton\n * we can simply use the update operation to continuously update the same\n * document with varying params.\n */\n const isCreatingDocument = !id && !isSingleType;\n\n const {\n isLoading: isLoadingLayout,\n edit: {\n layout,\n settings: { mainField },\n },\n } = useDocumentLayout(model);\n const pageTitle = getTitle(mainField);\n\n const { isLazyLoading } = useLazyComponents([]);\n\n const isLoading = isLoadingActionsRBAC || isLoadingDocument || isLoadingLayout || isLazyLoading;\n\n const initialValues = getInitialFormValues(isCreatingDocument);\n\n if (isLoading && !document?.documentId) {\n return <Page.Loading />;\n }\n\n if (!initialValues || hasError) {\n return <Page.Error />;\n }\n\n const handleTabChange = (status: string) => {\n if (status === 'published' || status === 'draft') {\n setQuery({ status }, 'push', true);\n }\n };\n\n const validateSync = (values: Record<string, unknown>, options: Record<string, string>) => {\n const yupSchema = createYupSchema(schema?.attributes, components, {\n status,\n ...options,\n });\n\n return yupSchema.validateSync(values, { abortEarly: false });\n };\n\n return (\n <Main paddingLeft={10} paddingRight={10}>\n <Page.Title>{pageTitle}</Page.Title>\n {isSingleType && (\n <tours.contentManager.Introduction>\n {/* Invisible Anchor */}\n <Box />\n </tours.contentManager.Introduction>\n )}\n <Form\n disabled={hasDraftAndPublished && status === 'published'}\n initialValues={initialValues}\n method={isCreatingDocument ? 'POST' : 'PUT'}\n validate={(values: Record<string, unknown>, options: Record<string, string>) => {\n // removes hidden fields from the validation\n // this is necessary because the yup schema doesn't know about the visibility conditions\n // and we don't want to validate fields that are not visible\n const { data: cleanedValues, removedAttributes } = handleInvisibleAttributes(values, {\n schema,\n initialValues,\n components,\n });\n\n const yupSchema = createYupSchema(schema?.attributes, components, {\n status,\n removedAttributes,\n ...options,\n });\n\n return yupSchema.validate(cleanedValues, { abortEarly: false });\n }}\n initialErrors={location?.state?.forceValidation ? validateSync(initialValues, {}) : {}}\n >\n <>\n <Header\n isCreating={isCreatingDocument}\n status={hasDraftAndPublished ? getDocumentStatus(document, meta) : undefined}\n title={pageTitle}\n />\n <Tabs.Root variant=\"simple\" value={status} onValueChange={handleTabChange}>\n <Tabs.List\n aria-label={formatMessage({\n id: getTranslation('containers.edit.tabs.label'),\n defaultMessage: 'Document status',\n })}\n >\n {hasDraftAndPublished ? (\n <>\n <StatusTab value=\"draft\">\n {formatMessage({\n id: getTranslation('containers.edit.tabs.draft'),\n defaultMessage: 'draft',\n })}\n </StatusTab>\n <StatusTab\n disabled={!meta || meta.availableStatus.length === 0}\n value=\"published\"\n >\n {formatMessage({\n id: getTranslation('containers.edit.tabs.published'),\n defaultMessage: 'published',\n })}\n </StatusTab>\n </>\n ) : null}\n </Tabs.List>\n <Grid.Root paddingTop={8} gap={4}>\n <Grid.Item col={9} s={12} direction=\"column\" alignItems=\"stretch\">\n <Tabs.Content value=\"draft\">\n <tours.contentManager.Fields>\n <Box />\n </tours.contentManager.Fields>\n <FormLayout layout={layout} document={doc} />\n </Tabs.Content>\n <Tabs.Content value=\"published\">\n <FormLayout layout={layout} document={doc} />\n </Tabs.Content>\n </Grid.Item>\n <Grid.Item col={3} s={12} direction=\"column\" alignItems=\"stretch\">\n <Panels />\n </Grid.Item>\n </Grid.Root>\n </Tabs.Root>\n <BlockerWrapper />\n </>\n </Form>\n </Main>\n );\n};\n\nconst StatusTab = styled(Tabs.Trigger)`\n text-transform: uppercase;\n`;\n\n/**\n * @internal\n * @description Returns the status of the document where its latest state takes priority,\n * this typically will be \"published\" unless a user has edited their draft in which we should\n * display \"modified\".\n */\nconst getDocumentStatus = (\n document: ReturnType<UseDocument>['document'],\n meta: ReturnType<UseDocument>['meta']\n): 'draft' | 'published' | 'modified' => {\n const docStatus = document?.status;\n const statuses = meta?.availableStatus ?? [];\n\n /**\n * Creating an entry\n */\n if (!docStatus) {\n return 'draft';\n }\n\n /**\n * We're viewing a draft, but the document could have a published version\n */\n if (docStatus === 'draft' && statuses.find((doc) => doc.publishedAt !== null)) {\n return 'published';\n }\n\n return docStatus;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * ProtectedEditViewPage\n * -----------------------------------------------------------------------------------------------*/\n\nconst ProtectedEditViewPage = () => {\n const { slug = '' } = useParams<{\n slug: string;\n }>();\n const {\n permissions = [],\n isLoading,\n error,\n } = useRBAC(\n PERMISSIONS.map((action) => ({\n action,\n subject: slug,\n }))\n );\n\n if (isLoading) {\n return <Page.Loading />;\n }\n\n if (error || !slug) {\n return <Page.Error />;\n }\n\n return (\n <Page.Protect permissions={permissions}>\n {({ permissions }) => (\n <DocumentRBAC permissions={permissions}>\n <EditViewPage />\n </DocumentRBAC>\n )}\n </Page.Protect>\n );\n};\n\nexport { EditViewPage, ProtectedEditViewPage, getDocumentStatus };\n"],"names":["BlockerWrapper","resetForm","useForm","state","_jsx","Blocker","onProceed","EditViewPage","location","useLocation","query","status","setQuery","useQueryParams","formatMessage","useIntl","toggleNotification","useNotification","doc","useDoc","document","meta","isLoading","isLoadingDocument","schema","components","collectionType","id","model","hasError","getTitle","getInitialFormValues","hasDraftAndPublished","options","draftAndPublish","useOnce","type","message","error","timeout","isLoadingActionsRBAC","useDocumentRBAC","isSingleType","SINGLE_TYPES","isCreatingDocument","isLoadingLayout","edit","layout","settings","mainField","useDocumentLayout","pageTitle","isLazyLoading","useLazyComponents","initialValues","documentId","Page","Loading","Error","handleTabChange","validateSync","values","yupSchema","createYupSchema","attributes","abortEarly","_jsxs","Main","paddingLeft","paddingRight","Title","tours","contentManager","Introduction","Box","Form","disabled","method","validate","data","cleanedValues","removedAttributes","handleInvisibleAttributes","initialErrors","forceValidation","_Fragment","Header","isCreating","getDocumentStatus","undefined","title","Tabs","Root","variant","value","onValueChange","List","aria-label","getTranslation","defaultMessage","StatusTab","availableStatus","length","Grid","paddingTop","gap","Item","col","s","direction","alignItems","Content","Fields","FormLayout","Panels","styled","Trigger","docStatus","statuses","find","publishedAt","ProtectedEditViewPage","slug","useParams","permissions","useRBAC","PERMISSIONS","map","action","subject","Protect","DocumentRBAC"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAgCA;;AAEkG;AAGlG;AACA,MAAMA,cAAiB,GAAA,IAAA;AACrB,IAAA,MAAMC,YAAYC,OAAQ,CAAA,gBAAA,EAAkB,CAACC,KAAAA,GAAUA,MAAMF,SAAS,C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AA,CAAIsG,WAAW,KAAK,IAAO,CAAA,EAAA;QAC7E,OAAO,WAAA;AACT;IAEA,OAAOH,SAAAA;AACT;AAEA;;AAEkG,2GAE5FI,qBAAwB,GAAA,IAAA;AAC5B,IAAA,MAAM,EAAEC,IAAAA,GAAO,EAAE,EAAE,GAAGC,SAAAA,EAAAA;AAGtB,IAAA,MAAM,EACJC,WAAAA,GAAc,EAAE,EAChBtG,SAAS,EACTgB,KAAK,EACN,GAAGuF,QACFC,WAAYC,CAAAA,GAAG,CAAC,CAACC,UAAY;AAC3BA,YAAAA,MAAAA;YACAC,OAASP,EAAAA;SACX,CAAA,CAAA,CAAA;AAGF,IAAA,IAAIpG,SAAW,EAAA;QACb,qBAAOlB,GAAA,CAACoD,KAAKC,OAAO,EAAA,EAAA,CAAA;AACtB;IAEA,IAAInB,KAAAA,IAAS,CAACoF,IAAM,EAAA;QAClB,qBAAOtH,GAAA,CAACoD,KAAKE,KAAK,EAAA,EAAA,CAAA;AACpB;IAEA,qBACEtD,GAAA,CAACoD,KAAK0E,OAAO,EAAA;QAACN,WAAaA,EAAAA,WAAAA;AACxB,QAAA,QAAA,EAAA,CAAC,EAAEA,WAAW,EAAE,iBACfxH,GAAC+H,CAAAA,YAAAA,EAAAA;gBAAaP,WAAaA,EAAAA,WAAAA;AACzB,gBAAA,QAAA,gBAAAxH,GAACG,CAAAA,YAAAA,EAAAA,EAAAA;;;AAKX;;;;"}
|
|
1
|
+
{"version":3,"file":"EditViewPage.mjs","sources":["../../../../admin/src/pages/EditView/EditViewPage.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n Page,\n Form,\n useRBAC,\n useNotification,\n useQueryParams,\n tours,\n} from '@strapi/admin/strapi-admin';\nimport { Grid, Main, Tabs, Box } from '@strapi/design-system';\nimport { useIntl } from 'react-intl';\nimport { useLocation, useParams } from 'react-router-dom';\nimport { styled } from 'styled-components';\n\nimport { SINGLE_TYPES } from '../../constants/collections';\nimport { PERMISSIONS } from '../../constants/plugin';\nimport { DocumentRBAC, useDocumentRBAC } from '../../features/DocumentRBAC';\nimport { useDoc, type UseDocument } from '../../hooks/useDocument';\nimport { useDocumentLayout } from '../../hooks/useDocumentLayout';\nimport { useLazyComponents } from '../../hooks/useLazyComponents';\nimport { useOnce } from '../../hooks/useOnce';\nimport { getTranslation } from '../../utils/translations';\nimport { createYupSchema } from '../../utils/validation';\n\nimport { Blocker } from './components/Blocker';\nimport { FormLayout } from './components/FormLayout';\nimport { Header } from './components/Header';\nimport { Panels } from './components/Panels';\nimport { handleInvisibleAttributes } from './utils/data';\n\n/* -------------------------------------------------------------------------------------------------\n * EditViewPage\n * -----------------------------------------------------------------------------------------------*/\n\nconst EditViewPage = () => {\n const location = useLocation();\n const [\n {\n query: { status },\n },\n setQuery,\n ] = useQueryParams<{ status: 'draft' | 'published' }>({\n status: 'draft',\n });\n const { formatMessage } = useIntl();\n const { toggleNotification } = useNotification();\n\n const doc = useDoc();\n const {\n document,\n meta,\n isLoading: isLoadingDocument,\n schema,\n components,\n collectionType,\n id,\n model,\n hasError,\n getTitle,\n getInitialFormValues,\n } = doc;\n\n const hasDraftAndPublished = schema?.options?.draftAndPublish ?? false;\n\n useOnce(() => {\n /**\n * We only ever want to fire the notification once otherwise\n * whenever the app re-renders it'll pop up regardless of\n * what we do because the state comes from react-router-dom\n */\n if (location?.state && 'error' in location.state) {\n toggleNotification({\n type: 'danger',\n message: location.state.error,\n timeout: 5000,\n });\n }\n });\n\n const isLoadingActionsRBAC = useDocumentRBAC('EditViewPage', (state) => state.isLoading);\n\n const isSingleType = collectionType === SINGLE_TYPES;\n\n /**\n * single-types don't current have an id, but because they're a singleton\n * we can simply use the update operation to continuously update the same\n * document with varying params.\n */\n const isCreatingDocument = !id && !isSingleType;\n\n const {\n isLoading: isLoadingLayout,\n edit: {\n layout,\n settings: { mainField },\n },\n } = useDocumentLayout(model);\n const pageTitle = getTitle(mainField);\n\n const { isLazyLoading } = useLazyComponents([]);\n\n const isLoading = isLoadingActionsRBAC || isLoadingDocument || isLoadingLayout || isLazyLoading;\n\n const initialValues = getInitialFormValues(isCreatingDocument);\n\n if (isLoading && !document?.documentId) {\n return <Page.Loading />;\n }\n\n if (!initialValues || hasError) {\n return <Page.Error />;\n }\n\n const handleTabChange = (status: string) => {\n if (status === 'published' || status === 'draft') {\n setQuery({ status }, 'push', true);\n }\n };\n\n const validateSync = (values: Record<string, unknown>, options: Record<string, string>) => {\n const yupSchema = createYupSchema(schema?.attributes, components, {\n status,\n ...options,\n });\n\n return yupSchema.validateSync(values, { abortEarly: false });\n };\n\n return (\n <Main paddingLeft={10} paddingRight={10}>\n <Page.Title>{pageTitle}</Page.Title>\n {isSingleType && (\n <tours.contentManager.Introduction>\n {/* Invisible Anchor */}\n <Box />\n </tours.contentManager.Introduction>\n )}\n <Form\n disabled={hasDraftAndPublished && status === 'published'}\n initialValues={initialValues}\n method={isCreatingDocument ? 'POST' : 'PUT'}\n validate={(values: Record<string, unknown>, options: Record<string, string>) => {\n // removes hidden fields from the validation\n // this is necessary because the yup schema doesn't know about the visibility conditions\n // and we don't want to validate fields that are not visible\n const { data: cleanedValues, removedAttributes } = handleInvisibleAttributes(values, {\n schema,\n initialValues,\n components,\n });\n\n const yupSchema = createYupSchema(schema?.attributes, components, {\n status,\n removedAttributes,\n ...options,\n });\n\n return yupSchema.validate(cleanedValues, { abortEarly: false });\n }}\n initialErrors={location?.state?.forceValidation ? validateSync(initialValues, {}) : {}}\n >\n <>\n <Header\n isCreating={isCreatingDocument}\n status={hasDraftAndPublished ? getDocumentStatus(document, meta) : undefined}\n title={pageTitle}\n />\n <Tabs.Root variant=\"simple\" value={status} onValueChange={handleTabChange}>\n <Tabs.List\n aria-label={formatMessage({\n id: getTranslation('containers.edit.tabs.label'),\n defaultMessage: 'Document status',\n })}\n >\n {hasDraftAndPublished ? (\n <>\n <StatusTab value=\"draft\">\n {formatMessage({\n id: getTranslation('containers.edit.tabs.draft'),\n defaultMessage: 'draft',\n })}\n </StatusTab>\n <StatusTab\n disabled={!meta || meta.availableStatus.length === 0}\n value=\"published\"\n >\n {formatMessage({\n id: getTranslation('containers.edit.tabs.published'),\n defaultMessage: 'published',\n })}\n </StatusTab>\n </>\n ) : null}\n </Tabs.List>\n <Grid.Root paddingTop={8} gap={4}>\n <Grid.Item col={9} s={12} direction=\"column\" alignItems=\"stretch\">\n <Tabs.Content value=\"draft\">\n <tours.contentManager.Fields>\n <Box />\n </tours.contentManager.Fields>\n <FormLayout layout={layout} document={doc} />\n </Tabs.Content>\n <Tabs.Content value=\"published\">\n <FormLayout layout={layout} document={doc} />\n </Tabs.Content>\n </Grid.Item>\n <Grid.Item col={3} s={12} direction=\"column\" alignItems=\"stretch\">\n <Panels />\n </Grid.Item>\n </Grid.Root>\n </Tabs.Root>\n <Blocker />\n </>\n </Form>\n </Main>\n );\n};\n\nconst StatusTab = styled(Tabs.Trigger)`\n text-transform: uppercase;\n`;\n\n/**\n * @internal\n * @description Returns the status of the document where its latest state takes priority,\n * this typically will be \"published\" unless a user has edited their draft in which we should\n * display \"modified\".\n */\nconst getDocumentStatus = (\n document: ReturnType<UseDocument>['document'],\n meta: ReturnType<UseDocument>['meta']\n): 'draft' | 'published' | 'modified' => {\n const docStatus = document?.status;\n const statuses = meta?.availableStatus ?? [];\n\n /**\n * Creating an entry\n */\n if (!docStatus) {\n return 'draft';\n }\n\n /**\n * We're viewing a draft, but the document could have a published version\n */\n if (docStatus === 'draft' && statuses.find((doc) => doc.publishedAt !== null)) {\n return 'published';\n }\n\n return docStatus;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * ProtectedEditViewPage\n * -----------------------------------------------------------------------------------------------*/\n\nconst ProtectedEditViewPage = () => {\n const { slug = '' } = useParams<{\n slug: string;\n }>();\n const {\n permissions = [],\n isLoading,\n error,\n } = useRBAC(\n PERMISSIONS.map((action) => ({\n action,\n subject: slug,\n }))\n );\n\n if (isLoading) {\n return <Page.Loading />;\n }\n\n if (error || !slug) {\n return <Page.Error />;\n }\n\n return (\n <Page.Protect permissions={permissions}>\n {({ permissions }) => (\n <DocumentRBAC permissions={permissions}>\n <EditViewPage />\n </DocumentRBAC>\n )}\n </Page.Protect>\n );\n};\n\nexport { EditViewPage, ProtectedEditViewPage, getDocumentStatus };\n"],"names":["EditViewPage","location","useLocation","query","status","setQuery","useQueryParams","formatMessage","useIntl","toggleNotification","useNotification","doc","useDoc","document","meta","isLoading","isLoadingDocument","schema","components","collectionType","id","model","hasError","getTitle","getInitialFormValues","hasDraftAndPublished","options","draftAndPublish","useOnce","state","type","message","error","timeout","isLoadingActionsRBAC","useDocumentRBAC","isSingleType","SINGLE_TYPES","isCreatingDocument","isLoadingLayout","edit","layout","settings","mainField","useDocumentLayout","pageTitle","isLazyLoading","useLazyComponents","initialValues","documentId","_jsx","Page","Loading","Error","handleTabChange","validateSync","values","yupSchema","createYupSchema","attributes","abortEarly","_jsxs","Main","paddingLeft","paddingRight","Title","tours","contentManager","Introduction","Box","Form","disabled","method","validate","data","cleanedValues","removedAttributes","handleInvisibleAttributes","initialErrors","forceValidation","_Fragment","Header","isCreating","getDocumentStatus","undefined","title","Tabs","Root","variant","value","onValueChange","List","aria-label","getTranslation","defaultMessage","StatusTab","availableStatus","length","Grid","paddingTop","gap","Item","col","s","direction","alignItems","Content","Fields","FormLayout","Panels","Blocker","styled","Trigger","docStatus","statuses","find","publishedAt","ProtectedEditViewPage","slug","useParams","permissions","useRBAC","PERMISSIONS","map","action","subject","Protect","DocumentRBAC"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA+BA;;AAEkG,2GAE5FA,YAAe,GAAA,IAAA;AACnB,IAAA,MAAMC,QAAWC,GAAAA,WAAAA,EAAAA;IACjB,MAAM,CACJ,EACEC,KAAAA,EAAO,EAAEC,MAAM,EAAE,EAClB,EACDC,QACD,CAAA,GAAGC,cAAkD,CAAA;QACpDF,MAAQ,EAAA;AACV,KAAA,CAAA;IACA,MAAM,EAAEG,aAAa,EAAE,GAAGC,OAAAA,EAAAA;IAC1B,M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,MAAAA;YACAC,OAASP,EAAAA;SACX,CAAA,CAAA,CAAA;AAGF,IAAA,IAAIvG,SAAW,EAAA;QACb,qBAAOmC,GAAA,CAACC,KAAKC,OAAO,EAAA,EAAA,CAAA;AACtB;IAEA,IAAIpB,KAAAA,IAAS,CAACsF,IAAM,EAAA;QAClB,qBAAOpE,GAAA,CAACC,KAAKE,KAAK,EAAA,EAAA,CAAA;AACpB;IAEA,qBACEH,GAAA,CAACC,KAAK2E,OAAO,EAAA;QAACN,WAAaA,EAAAA,WAAAA;AACxB,QAAA,QAAA,EAAA,CAAC,EAAEA,WAAW,EAAE,iBACftE,GAAC6E,CAAAA,YAAAA,EAAAA;gBAAaP,WAAaA,EAAAA,WAAAA;AACzB,gBAAA,QAAA,gBAAAtE,GAAClD,CAAAA,YAAAA,EAAAA,EAAAA;;;AAKX;;;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var strapiAdmin = require('@strapi/admin/strapi-admin');
|
|
5
|
+
|
|
6
|
+
// Needs to be wrapped in a component to have access to the form context via a hook.
|
|
7
|
+
/**
|
|
8
|
+
* Prevents users from leaving the page with unsaved form changes
|
|
9
|
+
*/ const Blocker = ()=>{
|
|
10
|
+
const resetForm = strapiAdmin.useForm('Blocker', (state)=>state.resetForm);
|
|
11
|
+
// We reset the form to the published version to avoid errors like – https://strapi-inc.atlassian.net/browse/CONTENT-2284
|
|
12
|
+
return /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Blocker, {
|
|
13
|
+
onProceed: resetForm
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
exports.Blocker = Blocker;
|
|
18
|
+
//# sourceMappingURL=Blocker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Blocker.js","sources":["../../../../../admin/src/pages/EditView/components/Blocker.tsx"],"sourcesContent":["// Needs to be wrapped in a component to have access to the form context via a hook.\n\nimport { Blocker as BaseBlocker, useForm } from '@strapi/admin/strapi-admin';\n\n/**\n * Prevents users from leaving the page with unsaved form changes\n */\nconst Blocker = () => {\n const resetForm = useForm('Blocker', (state) => state.resetForm);\n\n // We reset the form to the published version to avoid errors like – https://strapi-inc.atlassian.net/browse/CONTENT-2284\n return <BaseBlocker onProceed={resetForm} />;\n};\n\nexport { Blocker };\n"],"names":["Blocker","resetForm","useForm","state","_jsx","BaseBlocker","onProceed"],"mappings":";;;;;AAAA;AAIA;;AAEC,UACKA,OAAU,GAAA,IAAA;AACd,IAAA,MAAMC,YAAYC,mBAAQ,CAAA,SAAA,EAAW,CAACC,KAAAA,GAAUA,MAAMF,SAAS,CAAA;;AAG/D,IAAA,qBAAOG,cAACC,CAAAA,mBAAAA,EAAAA;QAAYC,SAAWL,EAAAA;;AACjC;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useForm, Blocker as Blocker$1 } from '@strapi/admin/strapi-admin';
|
|
3
|
+
|
|
4
|
+
// Needs to be wrapped in a component to have access to the form context via a hook.
|
|
5
|
+
/**
|
|
6
|
+
* Prevents users from leaving the page with unsaved form changes
|
|
7
|
+
*/ const Blocker = ()=>{
|
|
8
|
+
const resetForm = useForm('Blocker', (state)=>state.resetForm);
|
|
9
|
+
// We reset the form to the published version to avoid errors like – https://strapi-inc.atlassian.net/browse/CONTENT-2284
|
|
10
|
+
return /*#__PURE__*/ jsx(Blocker$1, {
|
|
11
|
+
onProceed: resetForm
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { Blocker };
|
|
16
|
+
//# sourceMappingURL=Blocker.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Blocker.mjs","sources":["../../../../../admin/src/pages/EditView/components/Blocker.tsx"],"sourcesContent":["// Needs to be wrapped in a component to have access to the form context via a hook.\n\nimport { Blocker as BaseBlocker, useForm } from '@strapi/admin/strapi-admin';\n\n/**\n * Prevents users from leaving the page with unsaved form changes\n */\nconst Blocker = () => {\n const resetForm = useForm('Blocker', (state) => state.resetForm);\n\n // We reset the form to the published version to avoid errors like – https://strapi-inc.atlassian.net/browse/CONTENT-2284\n return <BaseBlocker onProceed={resetForm} />;\n};\n\nexport { Blocker };\n"],"names":["Blocker","resetForm","useForm","state","_jsx","BaseBlocker","onProceed"],"mappings":";;;AAAA;AAIA;;AAEC,UACKA,OAAU,GAAA,IAAA;AACd,IAAA,MAAMC,YAAYC,OAAQ,CAAA,SAAA,EAAW,CAACC,KAAAA,GAAUA,MAAMF,SAAS,CAAA;;AAG/D,IAAA,qBAAOG,GAACC,CAAAA,SAAAA,EAAAA;QAAYC,SAAWL,EAAAA;;AACjC;;;;"}
|
|
@@ -9,6 +9,8 @@ var DocumentRBAC = require('../../../features/DocumentRBAC.js');
|
|
|
9
9
|
var useDocumentContext = require('../../../hooks/useDocumentContext.js');
|
|
10
10
|
var useDocumentLayout = require('../../../hooks/useDocumentLayout.js');
|
|
11
11
|
var useLazyComponents = require('../../../hooks/useLazyComponents.js');
|
|
12
|
+
var InputPopover = require('../../../preview/components/InputPopover.js');
|
|
13
|
+
var usePreviewInputManager = require('../../../preview/hooks/usePreviewInputManager.js');
|
|
12
14
|
var BlocksInput = require('./FormInputs/BlocksInput/BlocksInput.js');
|
|
13
15
|
var Input = require('./FormInputs/Component/Input.js');
|
|
14
16
|
var Field = require('./FormInputs/DynamicZone/Field.js');
|
|
@@ -43,11 +45,13 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
43
45
|
* specifically to be used in the EditView of the content-manager this understands
|
|
44
46
|
* the complete EditFieldLayout and will handle RBAC conditions and rendering CM specific
|
|
45
47
|
* components such as Blocks / Relations.
|
|
46
|
-
*/ const InputRenderer = ({ visible, hint: providedHint, document, ...
|
|
48
|
+
*/ const InputRenderer = ({ visible, hint: providedHint, document, ...inputProps })=>{
|
|
47
49
|
const { currentDocumentMeta } = useDocumentContext.useDocumentContext('DynamicComponent');
|
|
48
50
|
const { edit: { components } } = useDocumentLayout.useDocumentLayout(currentDocumentMeta.model);
|
|
49
51
|
const collectionType = document.schema?.kind === 'collectionType' ? 'collection-types' : 'single-types';
|
|
50
52
|
const isInDynamicZone = Field.useDynamicZone('isInDynamicZone', (state)=>state.isInDynamicZone);
|
|
53
|
+
const isInPreviewPopover = InputPopover.useHasInputPopoverParent();
|
|
54
|
+
const shouldIgnorePermissions = isInDynamicZone || isInPreviewPopover;
|
|
51
55
|
const isFormDisabled = strapiAdmin.useForm('InputRenderer', (state)=>state.disabled);
|
|
52
56
|
const canCreateFields = DocumentRBAC.useDocumentRBAC('InputRenderer', (rbac)=>rbac.canCreateFields);
|
|
53
57
|
const canReadFields = DocumentRBAC.useDocumentRBAC('InputRenderer', (rbac)=>rbac.canReadFields);
|
|
@@ -59,6 +63,12 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
59
63
|
}
|
|
60
64
|
const editableFields = idToCheck ? canUpdateFields : canCreateFields;
|
|
61
65
|
const readableFields = idToCheck ? canReadFields : canCreateFields;
|
|
66
|
+
// Everything preview related
|
|
67
|
+
const previewProps = usePreviewInputManager.usePreviewInputManager(inputProps.name, inputProps.attribute);
|
|
68
|
+
const props = {
|
|
69
|
+
...inputProps,
|
|
70
|
+
...previewProps
|
|
71
|
+
};
|
|
62
72
|
/**
|
|
63
73
|
* Component fields are always readable and editable,
|
|
64
74
|
* however the fields within them may not be.
|
|
@@ -76,29 +86,30 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
76
86
|
}
|
|
77
87
|
/**
|
|
78
88
|
* If the user can't read the field then we don't want to ever render it.
|
|
79
|
-
*/ if (!canUserReadField && !
|
|
89
|
+
*/ if (!canUserReadField && !shouldIgnorePermissions) {
|
|
80
90
|
return /*#__PURE__*/ jsxRuntime.jsx(NotAllowed.NotAllowedInput, {
|
|
81
91
|
hint: hint,
|
|
82
92
|
...props
|
|
83
93
|
});
|
|
84
94
|
}
|
|
85
|
-
const fieldIsDisabled = !canUserEditField && !
|
|
95
|
+
const fieldIsDisabled = !canUserEditField && !shouldIgnorePermissions || props.disabled || isFormDisabled;
|
|
86
96
|
/**
|
|
87
97
|
* Because a custom field has a unique prop but the type could be confused with either
|
|
88
98
|
* the useField hook or the type of the field we need to handle it separately and first.
|
|
89
99
|
*/ if (attributeHasCustomFieldProperty(props.attribute)) {
|
|
90
100
|
const CustomInput = lazyComponentStore[props.attribute.customField];
|
|
91
101
|
if (CustomInput) {
|
|
92
|
-
// @ts-expect-error – TODO: fix this type error in the useLazyComponents hook.
|
|
93
102
|
return /*#__PURE__*/ jsxRuntime.jsx(CustomInput, {
|
|
94
103
|
...props,
|
|
95
104
|
...field,
|
|
105
|
+
// @ts-expect-error – TODO: fix this type error in the useLazyComponents hook.
|
|
96
106
|
hint: hint,
|
|
97
107
|
disabled: fieldIsDisabled
|
|
98
108
|
});
|
|
99
109
|
}
|
|
100
110
|
return /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.InputRenderer, {
|
|
101
111
|
...props,
|
|
112
|
+
...previewProps,
|
|
102
113
|
hint: hint,
|
|
103
114
|
// @ts-expect-error – this workaround lets us display that the custom field is missing.
|
|
104
115
|
type: props.attribute.customField,
|
|
@@ -110,9 +121,9 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
110
121
|
*/ const addedInputTypes = Object.keys(fields);
|
|
111
122
|
if (!attributeHasCustomFieldProperty(props.attribute) && addedInputTypes.includes(props.type)) {
|
|
112
123
|
const CustomInput = fields[props.type];
|
|
113
|
-
// @ts-expect-error – TODO: fix this type error in the useLibrary hook.
|
|
114
124
|
return /*#__PURE__*/ jsxRuntime.jsx(CustomInput, {
|
|
115
125
|
...props,
|
|
126
|
+
// @ts-expect-error – TODO: fix this type error in the useLazyComponents hook.
|
|
116
127
|
hint: hint,
|
|
117
128
|
disabled: fieldIsDisabled
|
|
118
129
|
});
|
|
@@ -134,8 +145,8 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
134
145
|
hint: hint,
|
|
135
146
|
layout: components[props.attribute.component].layout,
|
|
136
147
|
disabled: fieldIsDisabled,
|
|
137
|
-
children: (
|
|
138
|
-
...
|
|
148
|
+
children: (componentInputProps)=>/*#__PURE__*/ jsxRuntime.jsx(InputRenderer, {
|
|
149
|
+
...componentInputProps
|
|
139
150
|
})
|
|
140
151
|
});
|
|
141
152
|
case 'dynamiczone':
|
|
@@ -169,6 +180,7 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
169
180
|
*/ case 'enumeration':
|
|
170
181
|
return /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.InputRenderer, {
|
|
171
182
|
...props,
|
|
183
|
+
...previewProps,
|
|
172
184
|
hint: hint,
|
|
173
185
|
options: props.attribute.enum.map((value)=>({
|
|
174
186
|
value
|
|
@@ -182,6 +194,7 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
182
194
|
const { unique: _unique, mainField: _mainField, ...restProps } = props;
|
|
183
195
|
return /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.InputRenderer, {
|
|
184
196
|
...restProps,
|
|
197
|
+
...previewProps,
|
|
185
198
|
hint: hint,
|
|
186
199
|
// @ts-expect-error – Temp workaround so we don't forget custom-fields don't work!
|
|
187
200
|
type: props.customField ? 'custom-field' : props.type,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InputRenderer.js","sources":["../../../../../admin/src/pages/EditView/components/InputRenderer.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n useStrapiApp,\n useForm,\n InputRenderer as FormInputRenderer,\n useField,\n} from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\n\nimport { SINGLE_TYPES } from '../../../constants/collections';\nimport { useDocumentRBAC } from '../../../features/DocumentRBAC';\nimport { type UseDocument } from '../../../hooks/useDocument';\nimport { useDocumentContext } from '../../../hooks/useDocumentContext';\nimport { useDocumentLayout } from '../../../hooks/useDocumentLayout';\nimport { useLazyComponents } from '../../../hooks/useLazyComponents';\n\nimport { BlocksInput } from './FormInputs/BlocksInput/BlocksInput';\nimport { ComponentInput } from './FormInputs/Component/Input';\nimport { DynamicZone, useDynamicZone } from './FormInputs/DynamicZone/Field';\nimport { NotAllowedInput } from './FormInputs/NotAllowed';\nimport { RelationsInput } from './FormInputs/Relations/Relations';\nimport { UIDInput } from './FormInputs/UID';\nimport { Wysiwyg } from './FormInputs/Wysiwyg/Field';\n\nimport type { EditFieldLayout } from '../../../hooks/useDocumentLayout';\nimport type { Schema } from '@strapi/types';\nimport type { DistributiveOmit } from 'react-redux';\n\ntype InputRendererProps = DistributiveOmit<EditFieldLayout, 'size'> & {\n document: ReturnType<UseDocument>;\n};\n\n/**\n * @internal\n *\n * @description An abstraction around the regular form input renderer designed\n * specifically to be used in the EditView of the content-manager this understands\n * the complete EditFieldLayout and will handle RBAC conditions and rendering CM specific\n * components such as Blocks / Relations.\n */\nconst InputRenderer = ({ visible, hint: providedHint, document, ...props }: InputRendererProps) => {\n const { currentDocumentMeta } = useDocumentContext('DynamicComponent');\n const {\n edit: { components },\n } = useDocumentLayout(currentDocumentMeta.model);\n\n const collectionType =\n document.schema?.kind === 'collectionType' ? 'collection-types' : 'single-types';\n\n const isInDynamicZone = useDynamicZone('isInDynamicZone', (state) => state.isInDynamicZone);\n\n const isFormDisabled = useForm('InputRenderer', (state) => state.disabled);\n const canCreateFields = useDocumentRBAC('InputRenderer', (rbac) => rbac.canCreateFields);\n const canReadFields = useDocumentRBAC('InputRenderer', (rbac) => rbac.canReadFields);\n const canUpdateFields = useDocumentRBAC('InputRenderer', (rbac) => rbac.canUpdateFields);\n const canUserAction = useDocumentRBAC('InputRenderer', (rbac) => rbac.canUserAction);\n\n let idToCheck = document.document?.documentId;\n if (collectionType === SINGLE_TYPES) {\n idToCheck = document?.document?.documentId;\n }\n\n const editableFields = idToCheck ? canUpdateFields : canCreateFields;\n const readableFields = idToCheck ? canReadFields : canCreateFields;\n\n /**\n * Component fields are always readable and editable,\n * however the fields within them may not be.\n */\n const canUserReadField = canUserAction(props.name, readableFields, props.type);\n const canUserEditField = canUserAction(props.name, editableFields, props.type);\n\n const fields = useStrapiApp('InputRenderer', (app) => app.fields);\n const { lazyComponentStore } = useLazyComponents(\n attributeHasCustomFieldProperty(props.attribute) ? [props.attribute.customField] : undefined\n );\n\n const hint = useFieldHint(providedHint, props.attribute);\n\n // We pass field in case of Custom Fields to keep backward compatibility\n const field = useField(props.name);\n\n if (!visible) {\n return null;\n }\n\n /**\n * If the user can't read the field then we don't want to ever render it.\n */\n if (!canUserReadField && !isInDynamicZone) {\n return <NotAllowedInput hint={hint} {...props} />;\n }\n\n const fieldIsDisabled =\n (!canUserEditField && !isInDynamicZone) || props.disabled || isFormDisabled;\n\n /**\n * Because a custom field has a unique prop but the type could be confused with either\n * the useField hook or the type of the field we need to handle it separately and first.\n */\n if (attributeHasCustomFieldProperty(props.attribute)) {\n const CustomInput = lazyComponentStore[props.attribute.customField];\n\n if (CustomInput) {\n // @ts-expect-error – TODO: fix this type error in the useLazyComponents hook.\n return <CustomInput {...props} {...field} hint={hint} disabled={fieldIsDisabled} />;\n }\n\n return (\n <FormInputRenderer\n {...props}\n hint={hint}\n // @ts-expect-error – this workaround lets us display that the custom field is missing.\n type={props.attribute.customField}\n disabled={fieldIsDisabled}\n />\n );\n }\n\n /**\n * This is where we handle ONLY the fields from the `useLibrary` hook.\n */\n const addedInputTypes = Object.keys(fields);\n if (!attributeHasCustomFieldProperty(props.attribute) && addedInputTypes.includes(props.type)) {\n const CustomInput = fields[props.type];\n // @ts-expect-error – TODO: fix this type error in the useLibrary hook.\n return <CustomInput {...props} hint={hint} disabled={fieldIsDisabled} />;\n }\n\n /**\n * These include the content-manager specific fields, failing that we fall back\n * to the more generic form input renderer.\n */\n switch (props.type) {\n case 'blocks':\n return <BlocksInput {...props} hint={hint} type={props.type} disabled={fieldIsDisabled} />;\n case 'component':\n return (\n <ComponentInput\n {...props}\n hint={hint}\n layout={components[props.attribute.component].layout}\n disabled={fieldIsDisabled}\n >\n {(inputProps) => <InputRenderer {...inputProps} />}\n </ComponentInput>\n );\n case 'dynamiczone':\n return <DynamicZone {...props} hint={hint} disabled={fieldIsDisabled} />;\n case 'relation':\n return <RelationsInput {...props} hint={hint} disabled={fieldIsDisabled} />;\n case 'richtext':\n return <Wysiwyg {...props} hint={hint} type={props.type} disabled={fieldIsDisabled} />;\n case 'uid':\n return <UIDInput {...props} hint={hint} type={props.type} disabled={fieldIsDisabled} />;\n /**\n * Enumerations are a special case because they require options.\n */\n case 'enumeration':\n return (\n <FormInputRenderer\n {...props}\n hint={hint}\n options={props.attribute.enum.map((value) => ({ value }))}\n // @ts-expect-error – Temp workaround so we don't forget custom-fields don't work!\n type={props.customField ? 'custom-field' : props.type}\n disabled={fieldIsDisabled}\n />\n );\n default:\n // These props are not needed for the generic form input renderer.\n const { unique: _unique, mainField: _mainField, ...restProps } = props;\n return (\n <FormInputRenderer\n {...restProps}\n hint={hint}\n // @ts-expect-error – Temp workaround so we don't forget custom-fields don't work!\n type={props.customField ? 'custom-field' : props.type}\n disabled={fieldIsDisabled}\n />\n );\n }\n};\n\nconst attributeHasCustomFieldProperty = (\n attribute: Schema.Attribute.AnyAttribute\n): attribute is Schema.Attribute.AnyAttribute & Schema.Attribute.CustomField<string> =>\n 'customField' in attribute && typeof attribute.customField === 'string';\n\nconst useFieldHint = (\n hint: React.ReactNode = undefined,\n attribute: Schema.Attribute.AnyAttribute\n) => {\n const { formatMessage } = useIntl();\n\n const { maximum, minimum } = getMinMax(attribute);\n\n if (!maximum && !minimum) {\n return hint;\n }\n\n const units = !['biginteger', 'integer', 'number', 'dynamiczone', 'component'].includes(\n attribute.type\n )\n ? formatMessage(\n {\n id: 'content-manager.form.Input.hint.character.unit',\n defaultMessage: '{maxValue, plural, one { character} other { characters}}',\n },\n {\n maxValue: Math.max(minimum || 0, maximum || 0),\n }\n )\n : null;\n\n const hasMinAndMax = typeof minimum === 'number' && typeof maximum === 'number';\n\n return formatMessage(\n {\n id: 'content-manager.form.Input.hint.text',\n defaultMessage:\n '{min, select, undefined {} other {min. {min}}}{divider}{max, select, undefined {} other {max. {max}}}{unit}{br}{description}',\n },\n {\n min: minimum,\n max: maximum,\n description: hint,\n unit: units,\n divider: hasMinAndMax\n ? formatMessage({\n id: 'content-manager.form.Input.hint.minMaxDivider',\n defaultMessage: ' / ',\n })\n : null,\n br: <br />,\n }\n );\n};\n\nconst getMinMax = (attribute: Schema.Attribute.AnyAttribute) => {\n if ('min' in attribute || 'max' in attribute) {\n return {\n maximum: !Number.isNaN(Number(attribute.max)) ? Number(attribute.max) : undefined,\n minimum: !Number.isNaN(Number(attribute.min)) ? Number(attribute.min) : undefined,\n };\n } else if ('maxLength' in attribute || 'minLength' in attribute) {\n return { maximum: attribute.maxLength, minimum: attribute.minLength };\n } else {\n return { maximum: undefined, minimum: undefined };\n }\n};\n\nconst MemoizedInputRenderer = React.memo(InputRenderer);\n\nexport type { InputRendererProps };\nexport { MemoizedInputRenderer as InputRenderer, useFieldHint };\n"],"names":["InputRenderer","visible","hint","providedHint","document","props","currentDocumentMeta","useDocumentContext","edit","components","useDocumentLayout","model","collectionType","schema","kind","isInDynamicZone","useDynamicZone","state","isFormDisabled","useForm","disabled","canCreateFields","useDocumentRBAC","rbac","canReadFields","canUpdateFields","canUserAction","idToCheck","documentId","SINGLE_TYPES","editableFields","readableFields","canUserReadField","name","type","canUserEditField","fields","useStrapiApp","app","lazyComponentStore","useLazyComponents","attributeHasCustomFieldProperty","attribute","customField","undefined","useFieldHint","field","useField","_jsx","NotAllowedInput","fieldIsDisabled","CustomInput","FormInputRenderer","addedInputTypes","Object","keys","includes","BlocksInput","ComponentInput","layout","component","inputProps","DynamicZone","RelationsInput","Wysiwyg","UIDInput","options","enum","map","value","unique","_unique","mainField","_mainField","restProps","formatMessage","useIntl","maximum","minimum","getMinMax","units","id","defaultMessage","maxValue","Math","max","hasMinAndMax","min","description","unit","divider","br","Number","isNaN","maxLength","minLength","MemoizedInputRenderer","React","memo"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA;;;;;;;AAOC,IACD,MAAMA,aAAAA,GAAgB,CAAC,EAAEC,OAAO,EAAEC,IAAMC,EAAAA,YAAY,EAAEC,QAAQ,EAAE,GAAGC,KAA2B,EAAA,GAAA;AAC5F,IAAA,MAAM,EAAEC,mBAAmB,EAAE,GAAGC,qCAAmB,CAAA,kBAAA,CAAA;IACnD,MAAM,EACJC,MAAM,EAAEC,UAAU,EAAE,EACrB,GAAGC,mCAAkBJ,CAAAA,mBAAAA,CAAoBK,KAAK,CAAA;AAE/C,IAAA,MAAMC,iBACJR,QAASS,CAAAA,MAAM,EAAEC,IAAAA,KAAS,mBAAmB,kBAAqB,GAAA,cAAA;AAEpE,IAAA,MAAMC,kBAAkBC,oBAAe,CAAA,iBAAA,EAAmB,CAACC,KAAAA,GAAUA,MAAMF,eAAe,CAAA;AAE1F,IAAA,MAAMG,iBAAiBC,mBAAQ,CAAA,eAAA,EAAiB,CAACF,KAAAA,GAAUA,MAAMG,QAAQ,CAAA;AACzE,IAAA,MAAMC,kBAAkBC,4BAAgB,CAAA,eAAA,EAAiB,CAACC,IAAAA,GAASA,KAAKF,eAAe,CAAA;AACvF,IAAA,MAAMG,gBAAgBF,4BAAgB,CAAA,eAAA,EAAiB,CAACC,IAAAA,GAASA,KAAKC,aAAa,CAAA;AACnF,IAAA,MAAMC,kBAAkBH,4BAAgB,CAAA,eAAA,EAAiB,CAACC,IAAAA,GAASA,KAAKE,eAAe,CAAA;AACvF,IAAA,MAAMC,gBAAgBJ,4BAAgB,CAAA,eAAA,EAAiB,CAACC,IAAAA,GAASA,KAAKG,aAAa,CAAA;IAEnF,IAAIC,SAAAA,GAAYvB,QAASA,CAAAA,Q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O;YAAElB,OAASjC,EAAAA,SAAAA;YAAWkC,OAASlC,EAAAA;AAAU,SAAA;AAClD;AACF,CAAA;AAEMoD,MAAAA,qBAAAA,iBAAwBC,gBAAMC,CAAAA,IAAI,CAAClG,aAAAA;;;;;"}
|
|
1
|
+
{"version":3,"file":"InputRenderer.js","sources":["../../../../../admin/src/pages/EditView/components/InputRenderer.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n useStrapiApp,\n useForm,\n InputRenderer as FormInputRenderer,\n useField,\n} from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\n\nimport { SINGLE_TYPES } from '../../../constants/collections';\nimport { useDocumentRBAC } from '../../../features/DocumentRBAC';\nimport { type UseDocument } from '../../../hooks/useDocument';\nimport { useDocumentContext } from '../../../hooks/useDocumentContext';\nimport { useDocumentLayout } from '../../../hooks/useDocumentLayout';\nimport { useLazyComponents } from '../../../hooks/useLazyComponents';\nimport { useHasInputPopoverParent } from '../../../preview/components/InputPopover';\nimport { usePreviewInputManager } from '../../../preview/hooks/usePreviewInputManager';\n\nimport { BlocksInput } from './FormInputs/BlocksInput/BlocksInput';\nimport { ComponentInput } from './FormInputs/Component/Input';\nimport { DynamicZone, useDynamicZone } from './FormInputs/DynamicZone/Field';\nimport { NotAllowedInput } from './FormInputs/NotAllowed';\nimport { RelationsInput } from './FormInputs/Relations/Relations';\nimport { UIDInput } from './FormInputs/UID';\nimport { Wysiwyg } from './FormInputs/Wysiwyg/Field';\n\nimport type { EditFieldLayout } from '../../../hooks/useDocumentLayout';\nimport type { Schema } from '@strapi/types';\nimport type { DistributiveOmit } from 'react-redux';\n\ntype InputRendererProps = DistributiveOmit<EditFieldLayout, 'size'> & {\n document: ReturnType<UseDocument>;\n};\n\n/**\n * @internal\n *\n * @description An abstraction around the regular form input renderer designed\n * specifically to be used in the EditView of the content-manager this understands\n * the complete EditFieldLayout and will handle RBAC conditions and rendering CM specific\n * components such as Blocks / Relations.\n */\nconst InputRenderer = ({\n visible,\n hint: providedHint,\n document,\n ...inputProps\n}: InputRendererProps) => {\n const { currentDocumentMeta } = useDocumentContext('DynamicComponent');\n const {\n edit: { components },\n } = useDocumentLayout(currentDocumentMeta.model);\n\n const collectionType =\n document.schema?.kind === 'collectionType' ? 'collection-types' : 'single-types';\n\n const isInDynamicZone = useDynamicZone('isInDynamicZone', (state) => state.isInDynamicZone);\n const isInPreviewPopover = useHasInputPopoverParent();\n const shouldIgnorePermissions = isInDynamicZone || isInPreviewPopover;\n\n const isFormDisabled = useForm('InputRenderer', (state) => state.disabled);\n const canCreateFields = useDocumentRBAC('InputRenderer', (rbac) => rbac.canCreateFields);\n const canReadFields = useDocumentRBAC('InputRenderer', (rbac) => rbac.canReadFields);\n const canUpdateFields = useDocumentRBAC('InputRenderer', (rbac) => rbac.canUpdateFields);\n const canUserAction = useDocumentRBAC('InputRenderer', (rbac) => rbac.canUserAction);\n\n let idToCheck = document.document?.documentId;\n if (collectionType === SINGLE_TYPES) {\n idToCheck = document?.document?.documentId;\n }\n\n const editableFields = idToCheck ? canUpdateFields : canCreateFields;\n const readableFields = idToCheck ? canReadFields : canCreateFields;\n\n // Everything preview related\n const previewProps = usePreviewInputManager(inputProps.name, inputProps.attribute);\n const props = { ...inputProps, ...previewProps };\n\n /**\n * Component fields are always readable and editable,\n * however the fields within them may not be.\n */\n const canUserReadField = canUserAction(props.name, readableFields, props.type);\n const canUserEditField = canUserAction(props.name, editableFields, props.type);\n\n const fields = useStrapiApp('InputRenderer', (app) => app.fields);\n const { lazyComponentStore } = useLazyComponents(\n attributeHasCustomFieldProperty(props.attribute) ? [props.attribute.customField] : undefined\n );\n\n const hint = useFieldHint(providedHint, props.attribute);\n\n // We pass field in case of Custom Fields to keep backward compatibility\n const field = useField(props.name);\n\n if (!visible) {\n return null;\n }\n\n /**\n * If the user can't read the field then we don't want to ever render it.\n */\n if (!canUserReadField && !shouldIgnorePermissions) {\n return <NotAllowedInput hint={hint} {...props} />;\n }\n\n const fieldIsDisabled =\n (!canUserEditField && !shouldIgnorePermissions) || props.disabled || isFormDisabled;\n\n /**\n * Because a custom field has a unique prop but the type could be confused with either\n * the useField hook or the type of the field we need to handle it separately and first.\n */\n if (attributeHasCustomFieldProperty(props.attribute)) {\n const CustomInput = lazyComponentStore[props.attribute.customField];\n\n if (CustomInput) {\n return (\n <CustomInput\n {...props}\n {...field}\n // @ts-expect-error – TODO: fix this type error in the useLazyComponents hook.\n hint={hint}\n disabled={fieldIsDisabled}\n />\n );\n }\n\n return (\n <FormInputRenderer\n {...props}\n {...previewProps}\n hint={hint}\n // @ts-expect-error – this workaround lets us display that the custom field is missing.\n type={props.attribute.customField}\n disabled={fieldIsDisabled}\n />\n );\n }\n\n /**\n * This is where we handle ONLY the fields from the `useLibrary` hook.\n */\n const addedInputTypes = Object.keys(fields);\n if (!attributeHasCustomFieldProperty(props.attribute) && addedInputTypes.includes(props.type)) {\n const CustomInput = fields[props.type];\n return (\n <CustomInput\n {...props}\n // @ts-expect-error – TODO: fix this type error in the useLazyComponents hook.\n hint={hint}\n disabled={fieldIsDisabled}\n />\n );\n }\n\n /**\n * These include the content-manager specific fields, failing that we fall back\n * to the more generic form input renderer.\n */\n switch (props.type) {\n case 'blocks':\n return <BlocksInput {...props} hint={hint} type={props.type} disabled={fieldIsDisabled} />;\n case 'component':\n return (\n <ComponentInput\n {...props}\n hint={hint}\n layout={components[props.attribute.component].layout}\n disabled={fieldIsDisabled}\n >\n {(componentInputProps) => <InputRenderer {...componentInputProps} />}\n </ComponentInput>\n );\n case 'dynamiczone':\n return <DynamicZone {...props} hint={hint} disabled={fieldIsDisabled} />;\n case 'relation':\n return <RelationsInput {...props} hint={hint} disabled={fieldIsDisabled} />;\n case 'richtext':\n return <Wysiwyg {...props} hint={hint} type={props.type} disabled={fieldIsDisabled} />;\n case 'uid':\n return <UIDInput {...props} hint={hint} type={props.type} disabled={fieldIsDisabled} />;\n /**\n * Enumerations are a special case because they require options.\n */\n case 'enumeration':\n return (\n <FormInputRenderer\n {...props}\n {...previewProps}\n hint={hint}\n options={props.attribute.enum.map((value) => ({ value }))}\n // @ts-expect-error – Temp workaround so we don't forget custom-fields don't work!\n type={props.customField ? 'custom-field' : props.type}\n disabled={fieldIsDisabled}\n />\n );\n default:\n // These props are not needed for the generic form input renderer.\n const { unique: _unique, mainField: _mainField, ...restProps } = props;\n return (\n <FormInputRenderer\n {...restProps}\n {...previewProps}\n hint={hint}\n // @ts-expect-error – Temp workaround so we don't forget custom-fields don't work!\n type={props.customField ? 'custom-field' : props.type}\n disabled={fieldIsDisabled}\n />\n );\n }\n};\n\nconst attributeHasCustomFieldProperty = (\n attribute: Schema.Attribute.AnyAttribute\n): attribute is Schema.Attribute.AnyAttribute & Schema.Attribute.CustomField<string> =>\n 'customField' in attribute && typeof attribute.customField === 'string';\n\nconst useFieldHint = (\n hint: React.ReactNode = undefined,\n attribute: Schema.Attribute.AnyAttribute\n) => {\n const { formatMessage } = useIntl();\n\n const { maximum, minimum } = getMinMax(attribute);\n\n if (!maximum && !minimum) {\n return hint;\n }\n\n const units = !['biginteger', 'integer', 'number', 'dynamiczone', 'component'].includes(\n attribute.type\n )\n ? formatMessage(\n {\n id: 'content-manager.form.Input.hint.character.unit',\n defaultMessage: '{maxValue, plural, one { character} other { characters}}',\n },\n {\n maxValue: Math.max(minimum || 0, maximum || 0),\n }\n )\n : null;\n\n const hasMinAndMax = typeof minimum === 'number' && typeof maximum === 'number';\n\n return formatMessage(\n {\n id: 'content-manager.form.Input.hint.text',\n defaultMessage:\n '{min, select, undefined {} other {min. {min}}}{divider}{max, select, undefined {} other {max. {max}}}{unit}{br}{description}',\n },\n {\n min: minimum,\n max: maximum,\n description: hint,\n unit: units,\n divider: hasMinAndMax\n ? formatMessage({\n id: 'content-manager.form.Input.hint.minMaxDivider',\n defaultMessage: ' / ',\n })\n : null,\n br: <br />,\n }\n );\n};\n\nconst getMinMax = (attribute: Schema.Attribute.AnyAttribute) => {\n if ('min' in attribute || 'max' in attribute) {\n return {\n maximum: !Number.isNaN(Number(attribute.max)) ? Number(attribute.max) : undefined,\n minimum: !Number.isNaN(Number(attribute.min)) ? Number(attribute.min) : undefined,\n };\n } else if ('maxLength' in attribute || 'minLength' in attribute) {\n return { maximum: attribute.maxLength, minimum: attribute.minLength };\n } else {\n return { maximum: undefined, minimum: undefined };\n }\n};\n\nconst MemoizedInputRenderer = React.memo(InputRenderer);\n\nexport type { InputRendererProps };\nexport { MemoizedInputRenderer as InputRenderer, useFieldHint };\n"],"names":["InputRenderer","visible","hint","providedHint","document","inputProps","currentDocumentMeta","useDocumentContext","edit","components","useDocumentLayout","model","collectionType","schema","kind","isInDynamicZone","useDynamicZone","state","isInPreviewPopover","useHasInputPopoverParent","shouldIgnorePermissions","isFormDisabled","useForm","disabled","canCreateFields","useDocumentRBAC","rbac","canReadFields","canUpdateFields","canUserAction","idToCheck","documentId","SINGLE_TYPES","editableFields","readableFields","previewProps","usePreviewInputManager","name","attribute","props","canUserReadField","type","canUserEditField","fields","useStrapiApp","app","lazyComponentStore","useLazyComponents","attributeHasCustomFieldProperty","customField","undefined","useFieldHint","field","useField","_jsx","NotAllowedInput","fieldIsDisabled","CustomInput","FormInputRenderer","addedInputTypes","Object","keys","includes","BlocksInput","ComponentInput","layout","component","componentInputProps","DynamicZone","RelationsInput","Wysiwyg","UIDInput","options","enum","map","value","unique","_unique","mainField","_mainField","restProps","formatMessage","useIntl","maximum","minimum","getMinMax","units","id","defaultMessage","maxValue","Math","max","hasMinAndMax","min","description","unit","divider","br","Number","isNaN","maxLength","minLength","MemoizedInputRenderer","React","memo"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCA;;;;;;;AAOC,IACD,MAAMA,aAAAA,GAAgB,CAAC,EACrBC,OAAO,EACPC,IAAMC,EAAAA,YAAY,EAClBC,QAAQ,EACR,GAAGC,UACgB,EAAA,GAAA;AACnB,IAAA,MAAM,EAAEC,mBAAmB,EAAE,GAAGC,qCAAmB,CAAA,kBAAA,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AA;AAEMoD,MAAAA,qBAAAA,iBAAwBC,gBAAMC,CAAAA,IAAI,CAACxG,aAAAA;;;;;"}
|
|
@@ -7,6 +7,8 @@ import { useDocumentRBAC } from '../../../features/DocumentRBAC.mjs';
|
|
|
7
7
|
import { useDocumentContext } from '../../../hooks/useDocumentContext.mjs';
|
|
8
8
|
import { useDocumentLayout } from '../../../hooks/useDocumentLayout.mjs';
|
|
9
9
|
import { useLazyComponents } from '../../../hooks/useLazyComponents.mjs';
|
|
10
|
+
import { useHasInputPopoverParent } from '../../../preview/components/InputPopover.mjs';
|
|
11
|
+
import { usePreviewInputManager } from '../../../preview/hooks/usePreviewInputManager.mjs';
|
|
10
12
|
import { BlocksInput as MemoizedBlocksInput } from './FormInputs/BlocksInput/BlocksInput.mjs';
|
|
11
13
|
import { ComponentInput as MemoizedComponentInput } from './FormInputs/Component/Input.mjs';
|
|
12
14
|
import { useDynamicZone, DynamicZone } from './FormInputs/DynamicZone/Field.mjs';
|
|
@@ -22,11 +24,13 @@ import { Wysiwyg as MemoizedWysiwyg } from './FormInputs/Wysiwyg/Field.mjs';
|
|
|
22
24
|
* specifically to be used in the EditView of the content-manager this understands
|
|
23
25
|
* the complete EditFieldLayout and will handle RBAC conditions and rendering CM specific
|
|
24
26
|
* components such as Blocks / Relations.
|
|
25
|
-
*/ const InputRenderer = ({ visible, hint: providedHint, document, ...
|
|
27
|
+
*/ const InputRenderer = ({ visible, hint: providedHint, document, ...inputProps })=>{
|
|
26
28
|
const { currentDocumentMeta } = useDocumentContext('DynamicComponent');
|
|
27
29
|
const { edit: { components } } = useDocumentLayout(currentDocumentMeta.model);
|
|
28
30
|
const collectionType = document.schema?.kind === 'collectionType' ? 'collection-types' : 'single-types';
|
|
29
31
|
const isInDynamicZone = useDynamicZone('isInDynamicZone', (state)=>state.isInDynamicZone);
|
|
32
|
+
const isInPreviewPopover = useHasInputPopoverParent();
|
|
33
|
+
const shouldIgnorePermissions = isInDynamicZone || isInPreviewPopover;
|
|
30
34
|
const isFormDisabled = useForm('InputRenderer', (state)=>state.disabled);
|
|
31
35
|
const canCreateFields = useDocumentRBAC('InputRenderer', (rbac)=>rbac.canCreateFields);
|
|
32
36
|
const canReadFields = useDocumentRBAC('InputRenderer', (rbac)=>rbac.canReadFields);
|
|
@@ -38,6 +42,12 @@ import { Wysiwyg as MemoizedWysiwyg } from './FormInputs/Wysiwyg/Field.mjs';
|
|
|
38
42
|
}
|
|
39
43
|
const editableFields = idToCheck ? canUpdateFields : canCreateFields;
|
|
40
44
|
const readableFields = idToCheck ? canReadFields : canCreateFields;
|
|
45
|
+
// Everything preview related
|
|
46
|
+
const previewProps = usePreviewInputManager(inputProps.name, inputProps.attribute);
|
|
47
|
+
const props = {
|
|
48
|
+
...inputProps,
|
|
49
|
+
...previewProps
|
|
50
|
+
};
|
|
41
51
|
/**
|
|
42
52
|
* Component fields are always readable and editable,
|
|
43
53
|
* however the fields within them may not be.
|
|
@@ -55,29 +65,30 @@ import { Wysiwyg as MemoizedWysiwyg } from './FormInputs/Wysiwyg/Field.mjs';
|
|
|
55
65
|
}
|
|
56
66
|
/**
|
|
57
67
|
* If the user can't read the field then we don't want to ever render it.
|
|
58
|
-
*/ if (!canUserReadField && !
|
|
68
|
+
*/ if (!canUserReadField && !shouldIgnorePermissions) {
|
|
59
69
|
return /*#__PURE__*/ jsx(NotAllowedInput, {
|
|
60
70
|
hint: hint,
|
|
61
71
|
...props
|
|
62
72
|
});
|
|
63
73
|
}
|
|
64
|
-
const fieldIsDisabled = !canUserEditField && !
|
|
74
|
+
const fieldIsDisabled = !canUserEditField && !shouldIgnorePermissions || props.disabled || isFormDisabled;
|
|
65
75
|
/**
|
|
66
76
|
* Because a custom field has a unique prop but the type could be confused with either
|
|
67
77
|
* the useField hook or the type of the field we need to handle it separately and first.
|
|
68
78
|
*/ if (attributeHasCustomFieldProperty(props.attribute)) {
|
|
69
79
|
const CustomInput = lazyComponentStore[props.attribute.customField];
|
|
70
80
|
if (CustomInput) {
|
|
71
|
-
// @ts-expect-error – TODO: fix this type error in the useLazyComponents hook.
|
|
72
81
|
return /*#__PURE__*/ jsx(CustomInput, {
|
|
73
82
|
...props,
|
|
74
83
|
...field,
|
|
84
|
+
// @ts-expect-error – TODO: fix this type error in the useLazyComponents hook.
|
|
75
85
|
hint: hint,
|
|
76
86
|
disabled: fieldIsDisabled
|
|
77
87
|
});
|
|
78
88
|
}
|
|
79
89
|
return /*#__PURE__*/ jsx(InputRenderer$1, {
|
|
80
90
|
...props,
|
|
91
|
+
...previewProps,
|
|
81
92
|
hint: hint,
|
|
82
93
|
// @ts-expect-error – this workaround lets us display that the custom field is missing.
|
|
83
94
|
type: props.attribute.customField,
|
|
@@ -89,9 +100,9 @@ import { Wysiwyg as MemoizedWysiwyg } from './FormInputs/Wysiwyg/Field.mjs';
|
|
|
89
100
|
*/ const addedInputTypes = Object.keys(fields);
|
|
90
101
|
if (!attributeHasCustomFieldProperty(props.attribute) && addedInputTypes.includes(props.type)) {
|
|
91
102
|
const CustomInput = fields[props.type];
|
|
92
|
-
// @ts-expect-error – TODO: fix this type error in the useLibrary hook.
|
|
93
103
|
return /*#__PURE__*/ jsx(CustomInput, {
|
|
94
104
|
...props,
|
|
105
|
+
// @ts-expect-error – TODO: fix this type error in the useLazyComponents hook.
|
|
95
106
|
hint: hint,
|
|
96
107
|
disabled: fieldIsDisabled
|
|
97
108
|
});
|
|
@@ -113,8 +124,8 @@ import { Wysiwyg as MemoizedWysiwyg } from './FormInputs/Wysiwyg/Field.mjs';
|
|
|
113
124
|
hint: hint,
|
|
114
125
|
layout: components[props.attribute.component].layout,
|
|
115
126
|
disabled: fieldIsDisabled,
|
|
116
|
-
children: (
|
|
117
|
-
...
|
|
127
|
+
children: (componentInputProps)=>/*#__PURE__*/ jsx(InputRenderer, {
|
|
128
|
+
...componentInputProps
|
|
118
129
|
})
|
|
119
130
|
});
|
|
120
131
|
case 'dynamiczone':
|
|
@@ -148,6 +159,7 @@ import { Wysiwyg as MemoizedWysiwyg } from './FormInputs/Wysiwyg/Field.mjs';
|
|
|
148
159
|
*/ case 'enumeration':
|
|
149
160
|
return /*#__PURE__*/ jsx(InputRenderer$1, {
|
|
150
161
|
...props,
|
|
162
|
+
...previewProps,
|
|
151
163
|
hint: hint,
|
|
152
164
|
options: props.attribute.enum.map((value)=>({
|
|
153
165
|
value
|
|
@@ -161,6 +173,7 @@ import { Wysiwyg as MemoizedWysiwyg } from './FormInputs/Wysiwyg/Field.mjs';
|
|
|
161
173
|
const { unique: _unique, mainField: _mainField, ...restProps } = props;
|
|
162
174
|
return /*#__PURE__*/ jsx(InputRenderer$1, {
|
|
163
175
|
...restProps,
|
|
176
|
+
...previewProps,
|
|
164
177
|
hint: hint,
|
|
165
178
|
// @ts-expect-error – Temp workaround so we don't forget custom-fields don't work!
|
|
166
179
|
type: props.customField ? 'custom-field' : props.type,
|