@strapi/content-manager 5.12.3 → 5.12.4
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/content-manager.js.map +1 -1
- package/dist/admin/content-manager.mjs.map +1 -1
- package/dist/admin/history/pages/History.js +1 -9
- package/dist/admin/history/pages/History.js.map +1 -1
- package/dist/admin/history/pages/History.mjs +1 -9
- package/dist/admin/history/pages/History.mjs.map +1 -1
- package/dist/admin/hooks/useDocumentActions.js +8 -1
- package/dist/admin/hooks/useDocumentActions.js.map +1 -1
- package/dist/admin/hooks/useDocumentActions.mjs +8 -1
- package/dist/admin/hooks/useDocumentActions.mjs.map +1 -1
- package/dist/admin/hooks/useDocumentContext.js +57 -0
- package/dist/admin/hooks/useDocumentContext.js.map +1 -0
- package/dist/admin/hooks/useDocumentContext.mjs +36 -0
- package/dist/admin/hooks/useDocumentContext.mjs.map +1 -0
- package/dist/admin/pages/EditView/EditViewPage.js +85 -93
- package/dist/admin/pages/EditView/EditViewPage.js.map +1 -1
- package/dist/admin/pages/EditView/EditViewPage.mjs +86 -94
- package/dist/admin/pages/EditView/EditViewPage.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/DocumentActions.js +28 -32
- package/dist/admin/pages/EditView/components/DocumentActions.js.map +1 -1
- package/dist/admin/pages/EditView/components/DocumentActions.mjs +32 -36
- package/dist/admin/pages/EditView/components/DocumentActions.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Input.js +2 -2
- package/dist/admin/pages/EditView/components/FormInputs/Component/Input.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Input.mjs +2 -2
- package/dist/admin/pages/EditView/components/FormInputs/Component/Input.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.js +2 -2
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.mjs +2 -2
- package/dist/admin/pages/EditView/components/FormInputs/Component/NonRepeatable.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.js +2 -2
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.mjs +2 -2
- package/dist/admin/pages/EditView/components/FormInputs/Component/Repeatable.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.js +5 -16
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.mjs +5 -16
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.js +2 -3
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.mjs +2 -3
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.js +432 -344
- package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.mjs +432 -346
- package/dist/admin/pages/EditView/components/FormInputs/Relations/RelationModal.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.js +55 -37
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.mjs +57 -39
- package/dist/admin/pages/EditView/components/FormInputs/Relations/Relations.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/UID.js +7 -7
- package/dist/admin/pages/EditView/components/FormInputs/UID.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/UID.mjs +7 -7
- package/dist/admin/pages/EditView/components/FormInputs/UID.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/InputRenderer.js +3 -10
- package/dist/admin/pages/EditView/components/InputRenderer.js.map +1 -1
- package/dist/admin/pages/EditView/components/InputRenderer.mjs +3 -10
- package/dist/admin/pages/EditView/components/InputRenderer.mjs.map +1 -1
- package/dist/admin/preview/components/PreviewHeader.js +2 -5
- package/dist/admin/preview/components/PreviewHeader.js.map +1 -1
- package/dist/admin/preview/components/PreviewHeader.mjs +2 -5
- package/dist/admin/preview/components/PreviewHeader.mjs.map +1 -1
- package/dist/admin/preview/pages/Preview.js +94 -102
- package/dist/admin/preview/pages/Preview.js.map +1 -1
- package/dist/admin/preview/pages/Preview.mjs +94 -102
- package/dist/admin/preview/pages/Preview.mjs.map +1 -1
- package/dist/admin/src/content-manager.d.ts +0 -3
- package/dist/admin/src/features/DocumentRBAC.d.ts +1 -1
- package/dist/admin/src/history/pages/History.d.ts +1 -1
- package/dist/admin/src/hooks/useDocumentContext.d.ts +30 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/ComponentContext.d.ts +1 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/DynamicZone/Field.d.ts +1 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/Relations/RelationModal.d.ts +50 -5
- package/dist/admin/src/pages/EditView/components/FormInputs/Relations/Relations.d.ts +1 -0
- package/dist/admin/src/pages/EditView/components/InputRenderer.d.ts +1 -1
- package/dist/admin/src/preview/pages/Preview.d.ts +2 -1
- package/package.json +8 -8
- package/dist/admin/features/DocumentContext.js +0 -71
- package/dist/admin/features/DocumentContext.js.map +0 -1
- package/dist/admin/features/DocumentContext.mjs +0 -49
- package/dist/admin/features/DocumentContext.mjs.map +0 -1
- package/dist/admin/src/features/DocumentContext.d.ts +0 -53
@@ -7,7 +7,6 @@ import { useIntl } from 'react-intl';
|
|
7
7
|
import { useParams, useLocation } from 'react-router-dom';
|
8
8
|
import { styled } from 'styled-components';
|
9
9
|
import { COLLECTION_TYPES } from '../../constants/collections.mjs';
|
10
|
-
import { DocumentContextProvider } from '../../features/DocumentContext.mjs';
|
11
10
|
import { DocumentRBAC } from '../../features/DocumentRBAC.mjs';
|
12
11
|
import { useDocument } from '../../hooks/useDocument.mjs';
|
13
12
|
import { useDocumentLayout } from '../../hooks/useDocumentLayout.mjs';
|
@@ -102,109 +101,102 @@ const PreviewPage = ()=>{
|
|
102
101
|
contentType: documentTitle
|
103
102
|
})
|
104
103
|
}),
|
105
|
-
/*#__PURE__*/ jsx(
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
104
|
+
/*#__PURE__*/ jsx(PreviewProvider, {
|
105
|
+
url: previewUrl,
|
106
|
+
document: documentResponse.document,
|
107
|
+
title: documentTitle,
|
108
|
+
meta: documentResponse.meta,
|
109
|
+
schema: documentResponse.schema,
|
110
|
+
layout: documentLayoutResponse.edit,
|
111
111
|
onPreview: onPreview,
|
112
|
-
children: /*#__PURE__*/ jsx(
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
paddingLeft: isSideEditorOpen ? 6 : 0,
|
157
|
-
paddingRight: isSideEditorOpen ? 6 : 0,
|
158
|
-
transition: "all 0.2s ease-in-out",
|
159
|
-
children: /*#__PURE__*/ jsx(FormLayout, {
|
160
|
-
layout: documentLayoutResponse.edit.layout,
|
161
|
-
document: documentResponse,
|
162
|
-
hasBackground: false
|
163
|
-
})
|
164
|
-
}),
|
165
|
-
/*#__PURE__*/ jsxs(Box, {
|
166
|
-
position: "relative",
|
167
|
-
flex: 1,
|
168
|
-
height: "100%",
|
169
|
-
overflow: "hidden",
|
170
|
-
children: [
|
171
|
-
/*#__PURE__*/ jsx(Box, {
|
172
|
-
"data-testid": "preview-iframe",
|
173
|
-
ref: iframeRef,
|
174
|
-
src: previewUrl,
|
175
|
-
title: formatMessage({
|
176
|
-
id: 'content-manager.preview.panel.title',
|
177
|
-
defaultMessage: 'Preview'
|
178
|
-
}),
|
179
|
-
width: "100%",
|
180
|
-
height: "100%",
|
181
|
-
borderWidth: 0,
|
182
|
-
tag: "iframe"
|
183
|
-
}, previewUrl),
|
184
|
-
hasAdvancedPreview && /*#__PURE__*/ jsx(IconButton, {
|
185
|
-
variant: "tertiary",
|
186
|
-
label: formatMessage(isSideEditorOpen ? {
|
187
|
-
id: 'content-manager.preview.content.close-editor',
|
188
|
-
defaultMessage: 'Close editor'
|
189
|
-
} : {
|
190
|
-
id: 'content-manager.preview.content.open-editor',
|
191
|
-
defaultMessage: 'Open editor'
|
192
|
-
}),
|
193
|
-
onClick: ()=>setIsSideEditorOpen((prev)=>!prev),
|
194
|
-
position: "absolute",
|
195
|
-
top: 2,
|
196
|
-
left: 2,
|
197
|
-
children: /*#__PURE__*/ jsx(AnimatedArrow, {
|
198
|
-
isSideEditorOpen: isSideEditorOpen
|
199
|
-
})
|
200
|
-
})
|
201
|
-
]
|
112
|
+
children: /*#__PURE__*/ jsx(Form, {
|
113
|
+
method: "PUT",
|
114
|
+
disabled: query.status === 'published' && documentResponse && documentResponse.document.status !== 'draft',
|
115
|
+
initialValues: documentResponse.getInitialFormValues(),
|
116
|
+
initialErrors: location?.state?.forceValidation ? validateSync(initialValues, {}) : {},
|
117
|
+
height: "100%",
|
118
|
+
validate: (values, options)=>{
|
119
|
+
const yupSchema = createYupSchema(documentResponse.schema?.attributes, documentResponse.components, {
|
120
|
+
status: documentResponse.document?.status,
|
121
|
+
...options
|
122
|
+
});
|
123
|
+
return yupSchema.validate(values, {
|
124
|
+
abortEarly: false
|
125
|
+
});
|
126
|
+
},
|
127
|
+
children: ({ resetForm })=>/*#__PURE__*/ jsxs(Flex, {
|
128
|
+
direction: "column",
|
129
|
+
height: "100%",
|
130
|
+
alignItems: "stretch",
|
131
|
+
children: [
|
132
|
+
/*#__PURE__*/ jsx(Blocker, {
|
133
|
+
onProceed: resetForm
|
134
|
+
}),
|
135
|
+
/*#__PURE__*/ jsx(PreviewHeader, {}),
|
136
|
+
/*#__PURE__*/ jsxs(Flex, {
|
137
|
+
flex: 1,
|
138
|
+
overflow: "auto",
|
139
|
+
alignItems: "stretch",
|
140
|
+
children: [
|
141
|
+
hasAdvancedPreview && /*#__PURE__*/ jsx(Box, {
|
142
|
+
overflow: "auto",
|
143
|
+
width: isSideEditorOpen ? '50%' : 0,
|
144
|
+
borderWidth: "0 1px 0 0",
|
145
|
+
borderColor: "neutral150",
|
146
|
+
paddingTop: 6,
|
147
|
+
paddingBottom: 6,
|
148
|
+
// Remove horizontal padding when the editor is closed or it won't fully disappear
|
149
|
+
paddingLeft: isSideEditorOpen ? 6 : 0,
|
150
|
+
paddingRight: isSideEditorOpen ? 6 : 0,
|
151
|
+
transition: "all 0.2s ease-in-out",
|
152
|
+
children: /*#__PURE__*/ jsx(FormLayout, {
|
153
|
+
layout: documentLayoutResponse.edit.layout,
|
154
|
+
document: documentResponse,
|
155
|
+
hasBackground: false
|
202
156
|
})
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
157
|
+
}),
|
158
|
+
/*#__PURE__*/ jsxs(Box, {
|
159
|
+
position: "relative",
|
160
|
+
flex: 1,
|
161
|
+
height: "100%",
|
162
|
+
overflow: "hidden",
|
163
|
+
children: [
|
164
|
+
/*#__PURE__*/ jsx(Box, {
|
165
|
+
"data-testid": "preview-iframe",
|
166
|
+
ref: iframeRef,
|
167
|
+
src: previewUrl,
|
168
|
+
title: formatMessage({
|
169
|
+
id: 'content-manager.preview.panel.title',
|
170
|
+
defaultMessage: 'Preview'
|
171
|
+
}),
|
172
|
+
width: "100%",
|
173
|
+
height: "100%",
|
174
|
+
borderWidth: 0,
|
175
|
+
tag: "iframe"
|
176
|
+
}, previewUrl),
|
177
|
+
hasAdvancedPreview && /*#__PURE__*/ jsx(IconButton, {
|
178
|
+
variant: "tertiary",
|
179
|
+
label: formatMessage(isSideEditorOpen ? {
|
180
|
+
id: 'content-manager.preview.content.close-editor',
|
181
|
+
defaultMessage: 'Close editor'
|
182
|
+
} : {
|
183
|
+
id: 'content-manager.preview.content.open-editor',
|
184
|
+
defaultMessage: 'Open editor'
|
185
|
+
}),
|
186
|
+
onClick: ()=>setIsSideEditorOpen((prev)=>!prev),
|
187
|
+
position: "absolute",
|
188
|
+
top: 2,
|
189
|
+
left: 2,
|
190
|
+
children: /*#__PURE__*/ jsx(AnimatedArrow, {
|
191
|
+
isSideEditorOpen: isSideEditorOpen
|
192
|
+
})
|
193
|
+
})
|
194
|
+
]
|
195
|
+
})
|
196
|
+
]
|
197
|
+
})
|
198
|
+
]
|
199
|
+
})
|
208
200
|
})
|
209
201
|
})
|
210
202
|
]
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Preview.mjs","sources":["../../../../admin/src/preview/pages/Preview.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n Page,\n useQueryParams,\n useRBAC,\n createContext,\n Form as FormContext,\n Blocker,\n} from '@strapi/admin/strapi-admin';\nimport { Box, Flex, FocusTrap, IconButton, Portal } from '@strapi/design-system';\nimport { ArrowLineLeft } from '@strapi/icons';\nimport { useIntl } from 'react-intl';\nimport { useLocation, useParams } from 'react-router-dom';\nimport { styled } from 'styled-components';\n\nimport { GetPreviewUrl } from '../../../../shared/contracts/preview';\nimport { COLLECTION_TYPES } from '../../constants/collections';\nimport { DocumentContextProvider } from '../../features/DocumentContext';\nimport { DocumentRBAC } from '../../features/DocumentRBAC';\nimport { type UseDocument, useDocument } from '../../hooks/useDocument';\nimport { type EditLayout, useDocumentLayout } from '../../hooks/useDocumentLayout';\nimport { FormLayout } from '../../pages/EditView/components/FormLayout';\nimport { buildValidParams } from '../../utils/api';\nimport { createYupSchema } from '../../utils/validation';\nimport { PreviewHeader } from '../components/PreviewHeader';\nimport { useGetPreviewUrlQuery } from '../services/preview';\n\nimport type { UID } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * PreviewProvider\n * -----------------------------------------------------------------------------------------------*/\n\ninterface PreviewContextValue {\n url: string;\n title: string;\n document: NonNullable<ReturnType<UseDocument>['document']>;\n meta: NonNullable<ReturnType<UseDocument>['meta']>;\n schema: NonNullable<ReturnType<UseDocument>['schema']>;\n layout: EditLayout;\n}\n\nconst [PreviewProvider, usePreviewContext] = createContext<PreviewContextValue>('PreviewPage');\n\n/* -------------------------------------------------------------------------------------------------\n * PreviewPage\n * -----------------------------------------------------------------------------------------------*/\n\nconst AnimatedArrow = styled(ArrowLineLeft)<{ isSideEditorOpen: boolean }>`\n will-change: transform;\n rotate: ${(props) => (props.isSideEditorOpen ? '0deg' : '180deg')};\n transition: rotate 0.2s ease-in-out;\n`;\n\nconst PreviewPage = () => {\n const location = useLocation();\n const { formatMessage } = useIntl();\n\n const iframeRef = React.useRef<HTMLIFrameElement>(null);\n const [isSideEditorOpen, setIsSideEditorOpen] = React.useState(true);\n\n // Read all the necessary data from the URL to find the right preview URL\n const {\n slug: model,\n id: documentId,\n collectionType,\n } = useParams<{\n slug: UID.ContentType;\n id: string;\n collectionType: string;\n }>();\n const [{ query }] = useQueryParams<{\n plugins?: Record<string, unknown>;\n status?: string;\n }>();\n\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 (!model) {\n throw new Error('Could not find model in url params');\n }\n\n // Only collection types must have a documentId\n if (collectionType === COLLECTION_TYPES && !documentId) {\n throw new Error('Could not find documentId in url params');\n }\n\n const previewUrlResponse = useGetPreviewUrlQuery({\n params: {\n contentType: model,\n },\n query: {\n documentId,\n locale: params.locale,\n status: params.status as GetPreviewUrl.Request['query']['status'],\n },\n });\n const documentResponse = useDocument({\n model,\n collectionType,\n documentId,\n params,\n });\n const documentLayoutResponse = useDocumentLayout(model);\n\n const isLoading =\n previewUrlResponse.isLoading || documentLayoutResponse.isLoading || documentResponse.isLoading;\n if (isLoading && !documentResponse.document?.documentId) {\n return <Page.Loading />;\n }\n\n const initialValues = documentResponse.getInitialFormValues();\n\n if (\n previewUrlResponse.error ||\n documentLayoutResponse.error ||\n !documentResponse.document ||\n !documentResponse.meta ||\n !documentResponse.schema ||\n !initialValues\n ) {\n return <Page.Error />;\n }\n\n if (!previewUrlResponse.data?.data?.url) {\n return <Page.NoData />;\n }\n\n const documentTitle = documentResponse.getTitle(documentLayoutResponse.edit.settings.mainField);\n\n const validateSync = (values: Record<string, unknown>, options: Record<string, string>) => {\n const yupSchema = createYupSchema(\n documentResponse.schema?.attributes,\n documentResponse.components,\n {\n status: documentResponse.document?.status,\n ...options,\n }\n );\n\n return yupSchema.validateSync(values, { abortEarly: false });\n };\n\n const previewUrl = previewUrlResponse.data.data.url;\n\n const onPreview = () => {\n iframeRef?.current?.contentWindow?.postMessage(\n { type: 'strapiUpdate' },\n // The iframe origin is safe to use since it must be provided through the allowedOrigins config\n new URL(iframeRef.current.src).origin\n );\n };\n\n const hasAdvancedPreview = window.strapi.features.isEnabled('cms-advanced-preview');\n\n return (\n <>\n <Page.Title>\n {formatMessage(\n {\n id: 'content-manager.preview.page-title',\n defaultMessage: '{contentType} preview',\n },\n {\n contentType: documentTitle,\n }\n )}\n </Page.Title>\n <DocumentContextProvider\n initialDocument={{\n documentId: documentId || '',\n model,\n collectionType,\n }}\n onPreview={onPreview}\n >\n <PreviewProvider\n url={previewUrl}\n document={documentResponse.document}\n title={documentTitle}\n meta={documentResponse.meta}\n schema={documentResponse.schema}\n layout={documentLayoutResponse.edit}\n >\n <FormContext\n method=\"PUT\"\n disabled={\n query.status === 'published' &&\n documentResponse &&\n documentResponse.document.status === 'published'\n }\n initialValues={documentResponse.getInitialFormValues()}\n initialErrors={location?.state?.forceValidation ? validateSync(initialValues, {}) : {}}\n height=\"100%\"\n validate={(values: Record<string, unknown>, options: Record<string, string>) => {\n const yupSchema = createYupSchema(\n documentResponse.schema?.attributes,\n documentResponse.components,\n {\n status: documentResponse.document?.status,\n ...options,\n }\n );\n\n return yupSchema.validate(values, { abortEarly: false });\n }}\n >\n {({ resetForm }) => (\n <Flex direction=\"column\" height=\"100%\" alignItems=\"stretch\">\n <Blocker onProceed={resetForm} />\n <PreviewHeader />\n <Flex flex={1} overflow=\"auto\" alignItems=\"stretch\">\n {hasAdvancedPreview && (\n <Box\n overflow=\"auto\"\n width={isSideEditorOpen ? '50%' : 0}\n borderWidth=\"0 1px 0 0\"\n borderColor=\"neutral150\"\n paddingTop={6}\n paddingBottom={6}\n // Remove horizontal padding when the editor is closed or it won't fully disappear\n paddingLeft={isSideEditorOpen ? 6 : 0}\n paddingRight={isSideEditorOpen ? 6 : 0}\n transition=\"all 0.2s ease-in-out\"\n >\n <FormLayout\n layout={documentLayoutResponse.edit.layout}\n document={documentResponse}\n hasBackground={false}\n />\n </Box>\n )}\n\n <Box position=\"relative\" flex={1} height=\"100%\" overflow=\"hidden\">\n <Box\n data-testid=\"preview-iframe\"\n ref={iframeRef}\n src={previewUrl}\n /**\n * For some reason, changing an iframe's src tag causes the browser to add a new item in the\n * history stack. This is an issue for us as it means clicking the back button will not let us\n * go back to the edit view. To fix it, we need to trick the browser into thinking this is a\n * different iframe when the preview URL changes. So we set a key prop to force React\n * to mount a different node when the src changes.\n */\n key={previewUrl}\n title={formatMessage({\n id: 'content-manager.preview.panel.title',\n defaultMessage: 'Preview',\n })}\n width=\"100%\"\n height=\"100%\"\n borderWidth={0}\n tag=\"iframe\"\n />\n {hasAdvancedPreview && (\n <IconButton\n variant=\"tertiary\"\n label={formatMessage(\n isSideEditorOpen\n ? {\n id: 'content-manager.preview.content.close-editor',\n defaultMessage: 'Close editor',\n }\n : {\n id: 'content-manager.preview.content.open-editor',\n defaultMessage: 'Open editor',\n }\n )}\n onClick={() => setIsSideEditorOpen((prev) => !prev)}\n position=\"absolute\"\n top={2}\n left={2}\n >\n <AnimatedArrow isSideEditorOpen={isSideEditorOpen} />\n </IconButton>\n )}\n </Box>\n </Flex>\n </Flex>\n )}\n </FormContext>\n </PreviewProvider>\n </DocumentContextProvider>\n </>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * ProtectedPreviewPage\n * -----------------------------------------------------------------------------------------------*/\n\nconst ProtectedPreviewPageImpl = () => {\n const { slug: model } = useParams<{\n slug: string;\n }>();\n const {\n permissions = [],\n isLoading,\n error,\n } = useRBAC([\n { action: 'plugin::content-manager.explorer.read', subject: model },\n { action: 'plugin::content-manager.explorer.update', subject: model },\n { action: 'plugin::content-manager.explorer.publish', subject: model },\n ]);\n\n if (isLoading) {\n return <Page.Loading />;\n }\n\n if (error || !model) {\n return (\n <Box\n height=\"100vh\"\n width=\"100vw\"\n position=\"fixed\"\n top={0}\n left={0}\n zIndex={2}\n background=\"neutral0\"\n >\n <Page.Error />\n </Box>\n );\n }\n\n return (\n <Box\n height=\"100vh\"\n width=\"100vw\"\n position=\"fixed\"\n top={0}\n left={0}\n zIndex={2}\n background=\"neutral0\"\n >\n <Page.Protect\n permissions={permissions.filter((permission) =>\n permission.action.includes('explorer.read')\n )}\n >\n <DocumentRBAC permissions={permissions}>\n <PreviewPage />\n </DocumentRBAC>\n </Page.Protect>\n </Box>\n );\n};\n\nconst ProtectedPreviewPage = () => {\n return (\n <Portal>\n <FocusTrap>\n <ProtectedPreviewPageImpl />\n </FocusTrap>\n </Portal>\n );\n};\n\nexport { ProtectedPreviewPage, usePreviewContext };\n"],"names":["PreviewProvider","usePreviewContext","createContext","AnimatedArrow","styled","ArrowLineLeft","props","isSideEditorOpen","PreviewPage","location","useLocation","formatMessage","useIntl","iframeRef","React","useRef","setIsSideEditorOpen","useState","slug","model","id","documentId","collectionType","useParams","query","useQueryParams","params","useMemo","buildValidParams","Error","COLLECTION_TYPES","previewUrlResponse","useGetPreviewUrlQuery","contentType","locale","status","documentResponse","useDocument","documentLayoutResponse","useDocumentLayout","isLoading","document","_jsx","Page","Loading","initialValues","getInitialFormValues","error","meta","schema","data","url","NoData","documentTitle","getTitle","edit","settings","mainField","validateSync","values","options","yupSchema","createYupSchema","attributes","components","abortEarly","previewUrl","onPreview","current","contentWindow","postMessage","type","URL","src","origin","hasAdvancedPreview","window","strapi","features","isEnabled","_jsxs","_Fragment","Title","defaultMessage","DocumentContextProvider","initialDocument","title","layout","FormContext","method","disabled","initialErrors","state","forceValidation","height","validate","resetForm","Flex","direction","alignItems","Blocker","onProceed","PreviewHeader","flex","overflow","Box","width","borderWidth","borderColor","paddingTop","paddingBottom","paddingLeft","paddingRight","transition","FormLayout","hasBackground","position","data-testid","ref","tag","IconButton","variant","label","onClick","prev","top","left","ProtectedPreviewPageImpl","permissions","useRBAC","action","subject","zIndex","background","Protect","filter","permission","includes","DocumentRBAC","ProtectedPreviewPage","Portal","FocusTrap"],"mappings":";;;;;;;;;;;;;;;;;;;AA2CA,MAAM,CAACA,eAAAA,EAAiBC,iBAAkB,CAAA,GAAGC,aAAmC,CAAA,aAAA;AAEhF;;AAEkG,qGAElG,MAAMC,aAAAA,GAAgBC,MAAOC,CAAAA,aAAAA,CAA6C;;AAEhE,UAAA,EAAE,CAACC,KAAWA,GAAAA,KAAAA,CAAMC,gBAAgB,GAAG,SAAS,QAAU,CAAA;;AAEpE,CAAC;AAED,MAAMC,WAAc,GAAA,IAAA;AAClB,IAAA,MAAMC,QAAWC,GAAAA,WAAAA,EAAAA;IACjB,MAAM,EAAEC,aAAa,EAAE,GAAGC,OAAAA,EAAAA;IAE1B,MAAMC,SAAAA,GAAYC,KAAMC,CAAAA,MAAM,CAAoB,IAAA,CAAA;AAClD,IAAA,MAAM,CAACR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AM,CAACO,QAAQ,CAAC,eAAA,CAAA,CAAA;AAG7B,YAAA,QAAA,gBAAA/F,GAACgG,CAAAA,YAAAA,EAAAA;gBAAaV,WAAaA,EAAAA,WAAAA;AACzB,gBAAA,QAAA,gBAAAtF,GAAClC,CAAAA,WAAAA,EAAAA,EAAAA;;;;AAKX,CAAA;AAEA,MAAMmI,oBAAuB,GAAA,IAAA;AAC3B,IAAA,qBACEjG,GAACkG,CAAAA,MAAAA,EAAAA;AACC,QAAA,QAAA,gBAAAlG,GAACmG,CAAAA,SAAAA,EAAAA;AACC,YAAA,QAAA,gBAAAnG,GAACqF,CAAAA,wBAAAA,EAAAA,EAAAA;;;AAIT;;;;"}
|
1
|
+
{"version":3,"file":"Preview.mjs","sources":["../../../../admin/src/preview/pages/Preview.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n Page,\n useQueryParams,\n useRBAC,\n createContext,\n Form as FormContext,\n Blocker,\n} from '@strapi/admin/strapi-admin';\nimport { Box, Flex, FocusTrap, IconButton, Portal } from '@strapi/design-system';\nimport { ArrowLineLeft } from '@strapi/icons';\nimport { useIntl } from 'react-intl';\nimport { useLocation, useParams } from 'react-router-dom';\nimport { styled } from 'styled-components';\n\nimport { GetPreviewUrl } from '../../../../shared/contracts/preview';\nimport { COLLECTION_TYPES } from '../../constants/collections';\nimport { DocumentRBAC } from '../../features/DocumentRBAC';\nimport { type UseDocument, useDocument } from '../../hooks/useDocument';\nimport { type EditLayout, useDocumentLayout } from '../../hooks/useDocumentLayout';\nimport { FormLayout } from '../../pages/EditView/components/FormLayout';\nimport { buildValidParams } from '../../utils/api';\nimport { createYupSchema } from '../../utils/validation';\nimport { PreviewHeader } from '../components/PreviewHeader';\nimport { useGetPreviewUrlQuery } from '../services/preview';\n\nimport type { UID } from '@strapi/types';\n\n/* -------------------------------------------------------------------------------------------------\n * PreviewProvider\n * -----------------------------------------------------------------------------------------------*/\n\ninterface PreviewContextValue {\n url: string;\n title: string;\n document: NonNullable<ReturnType<UseDocument>['document']>;\n meta: NonNullable<ReturnType<UseDocument>['meta']>;\n schema: NonNullable<ReturnType<UseDocument>['schema']>;\n layout: EditLayout;\n onPreview: () => void;\n}\n\nconst [PreviewProvider, usePreviewContext] = createContext<PreviewContextValue>('PreviewPage');\n\n/* -------------------------------------------------------------------------------------------------\n * PreviewPage\n * -----------------------------------------------------------------------------------------------*/\n\nconst AnimatedArrow = styled(ArrowLineLeft)<{ isSideEditorOpen: boolean }>`\n will-change: transform;\n rotate: ${(props) => (props.isSideEditorOpen ? '0deg' : '180deg')};\n transition: rotate 0.2s ease-in-out;\n`;\n\nconst PreviewPage = () => {\n const location = useLocation();\n const { formatMessage } = useIntl();\n\n const iframeRef = React.useRef<HTMLIFrameElement>(null);\n const [isSideEditorOpen, setIsSideEditorOpen] = React.useState(true);\n\n // Read all the necessary data from the URL to find the right preview URL\n const {\n slug: model,\n id: documentId,\n collectionType,\n } = useParams<{\n slug: UID.ContentType;\n id: string;\n collectionType: string;\n }>();\n const [{ query }] = useQueryParams<{\n plugins?: Record<string, unknown>;\n status?: string;\n }>();\n\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 (!model) {\n throw new Error('Could not find model in url params');\n }\n\n // Only collection types must have a documentId\n if (collectionType === COLLECTION_TYPES && !documentId) {\n throw new Error('Could not find documentId in url params');\n }\n\n const previewUrlResponse = useGetPreviewUrlQuery({\n params: {\n contentType: model,\n },\n query: {\n documentId,\n locale: params.locale,\n status: params.status as GetPreviewUrl.Request['query']['status'],\n },\n });\n const documentResponse = useDocument({\n model,\n collectionType,\n documentId,\n params,\n });\n const documentLayoutResponse = useDocumentLayout(model);\n\n const isLoading =\n previewUrlResponse.isLoading || documentLayoutResponse.isLoading || documentResponse.isLoading;\n if (isLoading && !documentResponse.document?.documentId) {\n return <Page.Loading />;\n }\n\n const initialValues = documentResponse.getInitialFormValues();\n\n if (\n previewUrlResponse.error ||\n documentLayoutResponse.error ||\n !documentResponse.document ||\n !documentResponse.meta ||\n !documentResponse.schema ||\n !initialValues\n ) {\n return <Page.Error />;\n }\n\n if (!previewUrlResponse.data?.data?.url) {\n return <Page.NoData />;\n }\n\n const documentTitle = documentResponse.getTitle(documentLayoutResponse.edit.settings.mainField);\n\n const validateSync = (values: Record<string, unknown>, options: Record<string, string>) => {\n const yupSchema = createYupSchema(\n documentResponse.schema?.attributes,\n documentResponse.components,\n {\n status: documentResponse.document?.status,\n ...options,\n }\n );\n\n return yupSchema.validateSync(values, { abortEarly: false });\n };\n\n const previewUrl = previewUrlResponse.data.data.url;\n\n const onPreview = () => {\n iframeRef?.current?.contentWindow?.postMessage(\n { type: 'strapiUpdate' },\n // The iframe origin is safe to use since it must be provided through the allowedOrigins config\n new URL(iframeRef.current.src).origin\n );\n };\n\n const hasAdvancedPreview = window.strapi.features.isEnabled('cms-advanced-preview');\n\n return (\n <>\n <Page.Title>\n {formatMessage(\n {\n id: 'content-manager.preview.page-title',\n defaultMessage: '{contentType} preview',\n },\n {\n contentType: documentTitle,\n }\n )}\n </Page.Title>\n <PreviewProvider\n url={previewUrl}\n document={documentResponse.document}\n title={documentTitle}\n meta={documentResponse.meta}\n schema={documentResponse.schema}\n layout={documentLayoutResponse.edit}\n onPreview={onPreview}\n >\n <FormContext\n method=\"PUT\"\n disabled={\n query.status === 'published' &&\n documentResponse &&\n documentResponse.document.status !== 'draft'\n }\n initialValues={documentResponse.getInitialFormValues()}\n initialErrors={location?.state?.forceValidation ? validateSync(initialValues, {}) : {}}\n height=\"100%\"\n validate={(values: Record<string, unknown>, options: Record<string, string>) => {\n const yupSchema = createYupSchema(\n documentResponse.schema?.attributes,\n documentResponse.components,\n {\n status: documentResponse.document?.status,\n ...options,\n }\n );\n\n return yupSchema.validate(values, { abortEarly: false });\n }}\n >\n {({ resetForm }) => (\n <Flex direction=\"column\" height=\"100%\" alignItems=\"stretch\">\n <Blocker onProceed={resetForm} />\n <PreviewHeader />\n <Flex flex={1} overflow=\"auto\" alignItems=\"stretch\">\n {hasAdvancedPreview && (\n <Box\n overflow=\"auto\"\n width={isSideEditorOpen ? '50%' : 0}\n borderWidth=\"0 1px 0 0\"\n borderColor=\"neutral150\"\n paddingTop={6}\n paddingBottom={6}\n // Remove horizontal padding when the editor is closed or it won't fully disappear\n paddingLeft={isSideEditorOpen ? 6 : 0}\n paddingRight={isSideEditorOpen ? 6 : 0}\n transition=\"all 0.2s ease-in-out\"\n >\n <FormLayout\n layout={documentLayoutResponse.edit.layout}\n document={documentResponse}\n hasBackground={false}\n />\n </Box>\n )}\n\n <Box position=\"relative\" flex={1} height=\"100%\" overflow=\"hidden\">\n <Box\n data-testid=\"preview-iframe\"\n ref={iframeRef}\n src={previewUrl}\n /**\n * For some reason, changing an iframe's src tag causes the browser to add a new item in the\n * history stack. This is an issue for us as it means clicking the back button will not let us\n * go back to the edit view. To fix it, we need to trick the browser into thinking this is a\n * different iframe when the preview URL changes. So we set a key prop to force React\n * to mount a different node when the src changes.\n */\n key={previewUrl}\n title={formatMessage({\n id: 'content-manager.preview.panel.title',\n defaultMessage: 'Preview',\n })}\n width=\"100%\"\n height=\"100%\"\n borderWidth={0}\n tag=\"iframe\"\n />\n {hasAdvancedPreview && (\n <IconButton\n variant=\"tertiary\"\n label={formatMessage(\n isSideEditorOpen\n ? {\n id: 'content-manager.preview.content.close-editor',\n defaultMessage: 'Close editor',\n }\n : {\n id: 'content-manager.preview.content.open-editor',\n defaultMessage: 'Open editor',\n }\n )}\n onClick={() => setIsSideEditorOpen((prev) => !prev)}\n position=\"absolute\"\n top={2}\n left={2}\n >\n <AnimatedArrow isSideEditorOpen={isSideEditorOpen} />\n </IconButton>\n )}\n </Box>\n </Flex>\n </Flex>\n )}\n </FormContext>\n </PreviewProvider>\n </>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * ProtectedPreviewPage\n * -----------------------------------------------------------------------------------------------*/\n\nconst ProtectedPreviewPageImpl = () => {\n const { slug: model } = useParams<{\n slug: string;\n }>();\n const {\n permissions = [],\n isLoading,\n error,\n } = useRBAC([\n { action: 'plugin::content-manager.explorer.read', subject: model },\n { action: 'plugin::content-manager.explorer.update', subject: model },\n { action: 'plugin::content-manager.explorer.publish', subject: model },\n ]);\n\n if (isLoading) {\n return <Page.Loading />;\n }\n\n if (error || !model) {\n return (\n <Box\n height=\"100vh\"\n width=\"100vw\"\n position=\"fixed\"\n top={0}\n left={0}\n zIndex={2}\n background=\"neutral0\"\n >\n <Page.Error />\n </Box>\n );\n }\n\n return (\n <Box\n height=\"100vh\"\n width=\"100vw\"\n position=\"fixed\"\n top={0}\n left={0}\n zIndex={2}\n background=\"neutral0\"\n >\n <Page.Protect\n permissions={permissions.filter((permission) =>\n permission.action.includes('explorer.read')\n )}\n >\n <DocumentRBAC permissions={permissions}>\n <PreviewPage />\n </DocumentRBAC>\n </Page.Protect>\n </Box>\n );\n};\n\nconst ProtectedPreviewPage = () => {\n return (\n <Portal>\n <FocusTrap>\n <ProtectedPreviewPageImpl />\n </FocusTrap>\n </Portal>\n );\n};\n\nexport { ProtectedPreviewPage, usePreviewContext };\n"],"names":["PreviewProvider","usePreviewContext","createContext","AnimatedArrow","styled","ArrowLineLeft","props","isSideEditorOpen","PreviewPage","location","useLocation","formatMessage","useIntl","iframeRef","React","useRef","setIsSideEditorOpen","useState","slug","model","id","documentId","collectionType","useParams","query","useQueryParams","params","useMemo","buildValidParams","Error","COLLECTION_TYPES","previewUrlResponse","useGetPreviewUrlQuery","contentType","locale","status","documentResponse","useDocument","documentLayoutResponse","useDocumentLayout","isLoading","document","_jsx","Page","Loading","initialValues","getInitialFormValues","error","meta","schema","data","url","NoData","documentTitle","getTitle","edit","settings","mainField","validateSync","values","options","yupSchema","createYupSchema","attributes","components","abortEarly","previewUrl","onPreview","current","contentWindow","postMessage","type","URL","src","origin","hasAdvancedPreview","window","strapi","features","isEnabled","_jsxs","_Fragment","Title","defaultMessage","title","layout","FormContext","method","disabled","initialErrors","state","forceValidation","height","validate","resetForm","Flex","direction","alignItems","Blocker","onProceed","PreviewHeader","flex","overflow","Box","width","borderWidth","borderColor","paddingTop","paddingBottom","paddingLeft","paddingRight","transition","FormLayout","hasBackground","position","data-testid","ref","tag","IconButton","variant","label","onClick","prev","top","left","ProtectedPreviewPageImpl","permissions","useRBAC","action","subject","zIndex","background","Protect","filter","permission","includes","DocumentRBAC","ProtectedPreviewPage","Portal","FocusTrap"],"mappings":";;;;;;;;;;;;;;;;;;AA2CA,MAAM,CAACA,eAAAA,EAAiBC,iBAAkB,CAAA,GAAGC,aAAmC,CAAA,aAAA;AAEhF;;AAEkG,qGAElG,MAAMC,aAAAA,GAAgBC,MAAOC,CAAAA,aAAAA,CAA6C;;AAEhE,UAAA,EAAE,CAACC,KAAWA,GAAAA,KAAAA,CAAMC,gBAAgB,GAAG,SAAS,QAAU,CAAA;;AAEpE,CAAC;AAED,MAAMC,WAAc,GAAA,IAAA;AAClB,IAAA,MAAMC,QAAWC,GAAAA,WAAAA,EAAAA;IACjB,MAAM,EAAEC,aAAa,EAAE,GAAGC,OAAAA,EAAAA;IAE1B,MAAMC,SAAAA,GAAYC,KAAMC,CAAAA,MAAM,CAAoB,IAAA,CAAA;AAClD,IAAA,MAAM,CAACR,gBAAkBS,EAAAA,mBAAAA,CAAoB,GAAGF,KAAAA,CAAMG,QAAQ,CAAC,IAAA,CAAA;;IAG/D,MAAM,EACJC,MAAMC,KAAK,EACXC,IAAIC,UAAU,EACdC,cAAc,EACf,GAAGC,SAAAA,EAAAA;AAKJ,IAAA,MAAM,CAAC,EAAEC,KAAK,EAAE,CAAC,GAAGC,cAAAA,EAAAA;AAKpB,IAAA,MAAMC,SAASZ,KAAMa,CAAAA,OAAO,CAAC,IAAMC,iBAAiBJ,KAAQ,CAAA,EAAA;AAACA,QAAAA;AAAM,KAAA,CAAA;AAEnE,IAAA,IAAI,CAACF,cAAgB,EAAA;AACnB,QAAA,MAAM,IAAIO,KAAM,CAAA,6CAAA,CAAA;AAClB;AAEA,I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CAAAA,GAAAA,EAAAA;YACCX,MAAO,EAAA,OAAA;YACPY,KAAM,EAAA,OAAA;YACNU,QAAS,EAAA,OAAA;YACTS,GAAK,EAAA,CAAA;YACLC,IAAM,EAAA,CAAA;YACNM,MAAQ,EAAA,CAAA;YACRC,UAAW,EAAA,UAAA;oCAEXzF,GAAA,CAACC,KAAKd,KAAK,EAAA,EAAA;;AAGjB;AAEA,IAAA,qBACEa,GAAC6D,CAAAA,GAAAA,EAAAA;QACCX,MAAO,EAAA,OAAA;QACPY,KAAM,EAAA,OAAA;QACNU,QAAS,EAAA,OAAA;QACTS,GAAK,EAAA,CAAA;QACLC,IAAM,EAAA,CAAA;QACNM,MAAQ,EAAA,CAAA;QACRC,UAAW,EAAA,UAAA;gCAEXzF,GAAA,CAACC,KAAKyF,OAAO,EAAA;YACXN,WAAaA,EAAAA,WAAAA,CAAYO,MAAM,CAAC,CAACC,aAC/BA,UAAWN,CAAAA,MAAM,CAACO,QAAQ,CAAC,eAAA,CAAA,CAAA;AAG7B,YAAA,QAAA,gBAAA7F,GAAC8F,CAAAA,YAAAA,EAAAA;gBAAaV,WAAaA,EAAAA,WAAAA;AACzB,gBAAA,QAAA,gBAAApF,GAAClC,CAAAA,WAAAA,EAAAA,EAAAA;;;;AAKX,CAAA;AAEA,MAAMiI,oBAAuB,GAAA,IAAA;AAC3B,IAAA,qBACE/F,GAACgG,CAAAA,MAAAA,EAAAA;AACC,QAAA,QAAA,gBAAAhG,GAACiG,CAAAA,SAAAA,EAAAA;AACC,YAAA,QAAA,gBAAAjG,GAACmF,CAAAA,wBAAAA,EAAAA,EAAAA;;;AAIT;;;;"}
|
@@ -57,9 +57,6 @@ interface PanelComponent extends DescriptionComponent<PanelComponentProps, Panel
|
|
57
57
|
type?: 'actions' | 'releases';
|
58
58
|
}
|
59
59
|
interface DocumentActionProps extends EditViewContext {
|
60
|
-
onPreview?: () => void;
|
61
|
-
fromPreview?: boolean;
|
62
|
-
fromRelationModal?: boolean;
|
63
60
|
}
|
64
61
|
interface DocumentActionComponent extends DescriptionComponent<DocumentActionProps, DocumentActionDescription> {
|
65
62
|
type?: 'clone' | 'configure-the-view' | 'delete' | 'discard' | 'edit' | 'edit-the-model' | 'history' | 'publish' | 'unpublish' | 'update';
|
@@ -19,7 +19,7 @@ interface DocumentRBACContextValue {
|
|
19
19
|
canUserAction: (fieldName: string, fieldsUserCanAction: string[], fieldType: Schema.Attribute.Kind) => boolean;
|
20
20
|
isLoading: boolean;
|
21
21
|
}
|
22
|
-
declare const useDocumentRBAC: <Selected>(consumerName: string, selector: (value: DocumentRBACContextValue) => Selected) => Selected;
|
22
|
+
declare const useDocumentRBAC: <Selected, ShouldThrow extends boolean = true>(consumerName: string, selector: (value: DocumentRBACContextValue) => Selected, shouldThrowOnMissingContext?: ShouldThrow | undefined) => ShouldThrow extends true ? Selected : Selected | undefined;
|
23
23
|
interface DocumentRBACProps {
|
24
24
|
children: React.ReactNode;
|
25
25
|
permissions: Permission[] | null;
|
@@ -21,7 +21,7 @@ declare const HistoryProvider: {
|
|
21
21
|
children: React.ReactNode;
|
22
22
|
}): import("react/jsx-runtime").JSX.Element;
|
23
23
|
displayName: string;
|
24
|
-
}, useHistoryContext: <Selected>(consumerName: string, selector: (value: HistoryContextValue) => Selected) => Selected;
|
24
|
+
}, useHistoryContext: <Selected, ShouldThrow extends boolean = true>(consumerName: string, selector: (value: HistoryContextValue) => Selected, shouldThrowOnMissingContext?: ShouldThrow | undefined) => ShouldThrow extends true ? Selected : Selected | undefined;
|
25
25
|
declare const ProtectedHistoryPage: () => import("react/jsx-runtime").JSX.Element;
|
26
26
|
export { ProtectedHistoryPage, HistoryProvider, useHistoryContext };
|
27
27
|
export type { HistoryContextValue };
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { type UseDocument } from '../hooks/useDocument';
|
2
|
+
interface DocumentMeta {
|
3
|
+
/**
|
4
|
+
* The equivalent of the ":id" url param value
|
5
|
+
* i.e. gus5a67jcboa3o2zjnz39mb1
|
6
|
+
*/
|
7
|
+
documentId: string;
|
8
|
+
/**
|
9
|
+
* The equivalent of the url ":slug" param value
|
10
|
+
* i.e. api::articles.article
|
11
|
+
*/
|
12
|
+
model: string;
|
13
|
+
/**
|
14
|
+
* The equivalent of the url ":collectionType" param value
|
15
|
+
* i.e. collection-types or single-types
|
16
|
+
*/
|
17
|
+
collectionType: string;
|
18
|
+
/**
|
19
|
+
* Query params object
|
20
|
+
* i.e. { locale: 'fr' }
|
21
|
+
*/
|
22
|
+
params?: Record<string, string | string[] | null>;
|
23
|
+
}
|
24
|
+
interface DocumentContextValue {
|
25
|
+
currentDocumentMeta: DocumentMeta;
|
26
|
+
currentDocument: ReturnType<UseDocument>;
|
27
|
+
}
|
28
|
+
declare function useDocumentContext(consumerName: string): DocumentContextValue;
|
29
|
+
export { useDocumentContext };
|
30
|
+
export type { DocumentMeta };
|
@@ -38,5 +38,5 @@ declare const ComponentProvider: {
|
|
38
38
|
children: import("react").ReactNode;
|
39
39
|
}): import("react/jsx-runtime").JSX.Element;
|
40
40
|
displayName: string;
|
41
|
-
}, useComponent: <Selected>(consumerName: string, selector: (value: ComponentContextValue) => Selected) => Selected;
|
41
|
+
}, useComponent: <Selected, ShouldThrow extends boolean = true>(consumerName: string, selector: (value: ComponentContextValue) => Selected, shouldThrowOnMissingContext?: ShouldThrow | undefined) => ShouldThrow extends true ? Selected : Selected | undefined;
|
42
42
|
export { ComponentProvider, useComponent };
|
@@ -6,7 +6,7 @@ import type { InputRendererProps } from '../../InputRenderer';
|
|
6
6
|
interface DynamicZoneContextValue {
|
7
7
|
isInDynamicZone: boolean;
|
8
8
|
}
|
9
|
-
declare const useDynamicZone: <Selected>(consumerName: string, selector: (value: DynamicZoneContextValue) => Selected) => Selected;
|
9
|
+
declare const useDynamicZone: <Selected, ShouldThrow extends boolean = true>(consumerName: string, selector: (value: DynamicZoneContextValue) => Selected, shouldThrowOnMissingContext?: ShouldThrow | undefined) => ShouldThrow extends true ? Selected : Selected | undefined;
|
10
10
|
interface DynamicZoneProps extends Omit<Extract<EditFieldLayout, {
|
11
11
|
type: 'dynamiczone';
|
12
12
|
}>, 'size' | 'hint'>, Pick<InputProps, 'hint'>, Pick<DynamicZoneLabelProps, 'labelAction'> {
|
@@ -1,8 +1,53 @@
|
|
1
|
-
import
|
1
|
+
import * as React from 'react';
|
2
|
+
import { type UseDocument } from '../../../../../hooks/useDocument';
|
3
|
+
import { type DocumentMeta } from '../../../../../hooks/useDocumentContext';
|
4
|
+
export declare function getCollectionType(url: string): string | undefined;
|
5
|
+
interface State {
|
6
|
+
documentHistory: DocumentMeta[];
|
7
|
+
confirmDialogIntent: null | 'close' | 'back' | 'navigate' | DocumentMeta;
|
8
|
+
isModalOpen: boolean;
|
9
|
+
hasUnsavedChanges: boolean;
|
10
|
+
}
|
11
|
+
type Action = {
|
12
|
+
type: 'GO_TO_RELATION';
|
13
|
+
payload: {
|
14
|
+
document: DocumentMeta;
|
15
|
+
shouldBypassConfirmation: boolean;
|
16
|
+
};
|
17
|
+
} | {
|
18
|
+
type: 'GO_BACK';
|
19
|
+
payload: {
|
20
|
+
shouldBypassConfirmation: boolean;
|
21
|
+
};
|
22
|
+
} | {
|
23
|
+
type: 'GO_FULL_PAGE';
|
24
|
+
} | {
|
25
|
+
type: 'CANCEL_CONFIRM_DIALOG';
|
26
|
+
} | {
|
27
|
+
type: 'CLOSE_MODAL';
|
28
|
+
payload: {
|
29
|
+
shouldBypassConfirmation: boolean;
|
30
|
+
};
|
31
|
+
} | {
|
32
|
+
type: 'SET_HAS_UNSAVED_CHANGES';
|
33
|
+
payload: {
|
34
|
+
hasUnsavedChanges: boolean;
|
35
|
+
};
|
36
|
+
};
|
37
|
+
declare function reducer(state: State, action: Action): State;
|
38
|
+
interface RelationModalContextValue {
|
39
|
+
state: State;
|
40
|
+
dispatch: React.Dispatch<Action>;
|
41
|
+
rootDocumentMeta: DocumentMeta;
|
42
|
+
currentDocumentMeta: DocumentMeta;
|
43
|
+
currentDocument: ReturnType<UseDocument>;
|
44
|
+
onPreview?: () => void;
|
45
|
+
}
|
46
|
+
declare const useRelationModal: <Selected, ShouldThrow extends boolean = true>(consumerName: string, selector: (value: RelationModalContextValue) => Selected, shouldThrowOnMissingContext?: ShouldThrow | undefined) => ShouldThrow extends true ? Selected : Selected | undefined;
|
2
47
|
interface RelationModalProps {
|
3
|
-
|
48
|
+
children: React.ReactNode;
|
4
49
|
relation: DocumentMeta;
|
5
50
|
}
|
6
|
-
|
7
|
-
|
8
|
-
export {
|
51
|
+
declare const RelationModal: React.MemoExoticComponent<({ relation, children }: RelationModalProps) => import("react/jsx-runtime").JSX.Element>;
|
52
|
+
export { RelationModal, reducer, useRelationModal };
|
53
|
+
export type { State, Action };
|
@@ -22,6 +22,7 @@ interface Relation extends Pick<RelationResult, 'documentId' | 'id' | 'locale' |
|
|
22
22
|
id: RelationResult['id'];
|
23
23
|
locale?: RelationResult['locale'];
|
24
24
|
position: RelationPosition;
|
25
|
+
isTemporary?: boolean;
|
25
26
|
};
|
26
27
|
}
|
27
28
|
interface RelationsFieldProps extends Omit<Extract<EditFieldLayout, {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import * as React from 'react';
|
2
|
-
import { UseDocument } from '../../../hooks/useDocument';
|
2
|
+
import { type UseDocument } from '../../../hooks/useDocument';
|
3
3
|
import type { EditFieldLayout } from '../../../hooks/useDocumentLayout';
|
4
4
|
import type { Schema } from '@strapi/types';
|
5
5
|
import type { DistributiveOmit } from 'react-redux';
|
@@ -7,7 +7,8 @@ interface PreviewContextValue {
|
|
7
7
|
meta: NonNullable<ReturnType<UseDocument>['meta']>;
|
8
8
|
schema: NonNullable<ReturnType<UseDocument>['schema']>;
|
9
9
|
layout: EditLayout;
|
10
|
+
onPreview: () => void;
|
10
11
|
}
|
11
|
-
declare const usePreviewContext: <Selected>(consumerName: string, selector: (value: PreviewContextValue) => Selected) => Selected;
|
12
|
+
declare const usePreviewContext: <Selected, ShouldThrow extends boolean = true>(consumerName: string, selector: (value: PreviewContextValue) => Selected, shouldThrowOnMissingContext?: ShouldThrow | undefined) => ShouldThrow extends true ? Selected : Selected | undefined;
|
12
13
|
declare const ProtectedPreviewPage: () => import("react/jsx-runtime").JSX.Element;
|
13
14
|
export { ProtectedPreviewPage, usePreviewContext };
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@strapi/content-manager",
|
3
|
-
"version": "5.12.
|
3
|
+
"version": "5.12.4",
|
4
4
|
"description": "A powerful UI to easily manage your data.",
|
5
5
|
"repository": {
|
6
6
|
"type": "git",
|
@@ -64,10 +64,10 @@
|
|
64
64
|
"@radix-ui/react-toolbar": "1.0.4",
|
65
65
|
"@reduxjs/toolkit": "1.9.7",
|
66
66
|
"@sindresorhus/slugify": "1.1.0",
|
67
|
-
"@strapi/design-system": "2.0.0-rc.
|
68
|
-
"@strapi/icons": "2.0.0-rc.
|
69
|
-
"@strapi/types": "5.12.
|
70
|
-
"@strapi/utils": "5.12.
|
67
|
+
"@strapi/design-system": "2.0.0-rc.21",
|
68
|
+
"@strapi/icons": "2.0.0-rc.21",
|
69
|
+
"@strapi/types": "5.12.4",
|
70
|
+
"@strapi/utils": "5.12.4",
|
71
71
|
"codemirror5": "npm:codemirror@^5.65.11",
|
72
72
|
"date-fns": "2.30.0",
|
73
73
|
"fractional-indexing": "3.2.0",
|
@@ -75,7 +75,7 @@
|
|
75
75
|
"immer": "9.0.21",
|
76
76
|
"koa": "2.15.4",
|
77
77
|
"lodash": "4.17.21",
|
78
|
-
"markdown-it": "^
|
78
|
+
"markdown-it": "^13.0.2",
|
79
79
|
"markdown-it-abbr": "^1.0.4",
|
80
80
|
"markdown-it-container": "^3.0.0",
|
81
81
|
"markdown-it-deflist": "^2.1.0",
|
@@ -102,8 +102,8 @@
|
|
102
102
|
"yup": "0.32.9"
|
103
103
|
},
|
104
104
|
"devDependencies": {
|
105
|
-
"@strapi/admin": "5.12.
|
106
|
-
"@strapi/database": "5.12.
|
105
|
+
"@strapi/admin": "5.12.4",
|
106
|
+
"@strapi/database": "5.12.4",
|
107
107
|
"@testing-library/react": "15.0.7",
|
108
108
|
"@types/jest": "29.5.2",
|
109
109
|
"@types/lodash": "^4.14.191",
|
@@ -1,71 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
var jsxRuntime = require('react/jsx-runtime');
|
4
|
-
var React = require('react');
|
5
|
-
var strapiAdmin = require('@strapi/admin/strapi-admin');
|
6
|
-
var useDocument = require('../hooks/useDocument.js');
|
7
|
-
var api = require('../utils/api.js');
|
8
|
-
|
9
|
-
function _interopNamespaceDefault(e) {
|
10
|
-
var n = Object.create(null);
|
11
|
-
if (e) {
|
12
|
-
Object.keys(e).forEach(function (k) {
|
13
|
-
if (k !== 'default') {
|
14
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
15
|
-
Object.defineProperty(n, k, d.get ? d : {
|
16
|
-
enumerable: true,
|
17
|
-
get: function () { return e[k]; }
|
18
|
-
});
|
19
|
-
}
|
20
|
-
});
|
21
|
-
}
|
22
|
-
n.default = e;
|
23
|
-
return Object.freeze(n);
|
24
|
-
}
|
25
|
-
|
26
|
-
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
27
|
-
|
28
|
-
const [DocumentProvider, useDocumentContext] = strapiAdmin.createContext('DocumentContext');
|
29
|
-
/**
|
30
|
-
* TODO: Document in contributor docs, Add unit test
|
31
|
-
*
|
32
|
-
* This context provider and its associated hook are used to access a document at its root level
|
33
|
-
* and expose a function to change the current document being viewed to one of the root level docuemnt's relations.
|
34
|
-
*
|
35
|
-
* The useDocumentContext hook exposes:
|
36
|
-
* - meta: information about the currentDocument,
|
37
|
-
* - document: the actual document,
|
38
|
-
* - changeDocument: a function to change the current document to one of its relations.
|
39
|
-
* - rootDocumentMeta: information about the root level document (current page)
|
40
|
-
*/ const DocumentContextProvider = ({ children, initialDocument, onPreview })=>{
|
41
|
-
/**
|
42
|
-
* Initialize with the "root" document and expose a setter method to change to
|
43
|
-
* one of the root level document's relations.
|
44
|
-
*/ const [currentDocumentMeta, changeDocument] = React__namespace.useState(initialDocument);
|
45
|
-
const params = React__namespace.useMemo(()=>api.buildValidParams(currentDocumentMeta.params ?? {}), [
|
46
|
-
currentDocumentMeta.params
|
47
|
-
]);
|
48
|
-
const document = useDocument.useDocument({
|
49
|
-
...currentDocumentMeta,
|
50
|
-
params
|
51
|
-
});
|
52
|
-
const [documentHistory, setDocumentHistory] = React__namespace.useState([]);
|
53
|
-
return /*#__PURE__*/ jsxRuntime.jsx(DocumentProvider, {
|
54
|
-
changeDocument: changeDocument,
|
55
|
-
document: document,
|
56
|
-
rootDocumentMeta: {
|
57
|
-
documentId: initialDocument.documentId,
|
58
|
-
model: initialDocument.model,
|
59
|
-
collectionType: initialDocument.collectionType
|
60
|
-
},
|
61
|
-
meta: currentDocumentMeta,
|
62
|
-
documentHistory: documentHistory,
|
63
|
-
setDocumentHistory: setDocumentHistory,
|
64
|
-
onPreview: onPreview,
|
65
|
-
children: children
|
66
|
-
});
|
67
|
-
};
|
68
|
-
|
69
|
-
exports.DocumentContextProvider = DocumentContextProvider;
|
70
|
-
exports.useDocumentContext = useDocumentContext;
|
71
|
-
//# sourceMappingURL=DocumentContext.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"DocumentContext.js","sources":["../../../admin/src/features/DocumentContext.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { createContext } from '@strapi/admin/strapi-admin';\n\nimport { useDocument, type UseDocument } from '../hooks/useDocument';\nimport { buildValidParams } from '../utils/api';\n\ninterface DocumentMeta {\n /**\n * The equivalent of the \":id\" url param value\n * i.e. gus5a67jcboa3o2zjnz39mb1\n */\n documentId: string;\n /**\n * The equivalent of the url \":slug\" param value\n * i.e. api::articles.article\n */\n model: string;\n /**\n * The equivalent of the url \":collectionType\" param value\n * i.e. collection-types or single-types\n */\n collectionType: string;\n /**\n * Query params object\n * i.e. { locale: 'fr' }\n */\n params?: Record<string, string | string[] | null>;\n}\n\ninterface DocumentContextValue {\n rootDocumentMeta: DocumentMeta;\n document: ReturnType<UseDocument>;\n meta: DocumentMeta;\n changeDocument: (newRelation: DocumentMeta) => void;\n documentHistory: DocumentMeta[];\n setDocumentHistory: React.Dispatch<React.SetStateAction<DocumentMeta[]>>;\n onPreview?: () => void;\n}\n\nconst [DocumentProvider, useDocumentContext] =\n createContext<DocumentContextValue>('DocumentContext');\n\n/**\n * TODO: Document in contributor docs, Add unit test\n *\n * This context provider and its associated hook are used to access a document at its root level\n * and expose a function to change the current document being viewed to one of the root level docuemnt's relations.\n *\n * The useDocumentContext hook exposes:\n * - meta: information about the currentDocument,\n * - document: the actual document,\n * - changeDocument: a function to change the current document to one of its relations.\n * - rootDocumentMeta: information about the root level document (current page)\n */\nconst DocumentContextProvider = ({\n children,\n initialDocument,\n onPreview,\n}: {\n children: React.ReactNode | React.ReactNode[];\n initialDocument: DocumentMeta;\n onPreview?: () => void;\n}) => {\n /**\n * Initialize with the \"root\" document and expose a setter method to change to\n * one of the root level document's relations.\n */\n const [currentDocumentMeta, changeDocument] = React.useState<DocumentMeta>(initialDocument);\n const params = React.useMemo(\n () => buildValidParams(currentDocumentMeta.params ?? {}),\n [currentDocumentMeta.params]\n );\n const document = useDocument({ ...currentDocumentMeta, params });\n\n const [documentHistory, setDocumentHistory] = React.useState<DocumentMeta[]>([]);\n\n return (\n <DocumentProvider\n changeDocument={changeDocument}\n document={document}\n rootDocumentMeta={{\n documentId: initialDocument.documentId,\n model: initialDocument.model,\n collectionType: initialDocument.collectionType,\n }}\n meta={currentDocumentMeta}\n documentHistory={documentHistory}\n setDocumentHistory={setDocumentHistory}\n onPreview={onPreview}\n >\n {children}\n </DocumentProvider>\n );\n};\n\nexport { useDocumentContext, DocumentContextProvider };\nexport type { DocumentMeta };\n"],"names":["DocumentProvider","useDocumentContext","createContext","DocumentContextProvider","children","initialDocument","onPreview","currentDocumentMeta","changeDocument","React","useState","params","useMemo","buildValidParams","document","useDocument","documentHistory","setDocumentHistory","_jsx","rootDocumentMeta","documentId","model","collectionType","meta"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,MAAM,CAACA,gBAAAA,EAAkBC,kBAAmB,CAAA,GAC1CC,yBAAoC,CAAA,iBAAA;AAEtC;;;;;;;;;;;IAYA,MAAMC,0BAA0B,CAAC,EAC/BC,QAAQ,EACRC,eAAe,EACfC,SAAS,EAKV,GAAA;AACC;;;AAGC,MACD,MAAM,CAACC,mBAAAA,EAAqBC,eAAe,GAAGC,gBAAAA,CAAMC,QAAQ,CAAeL,eAAAA,CAAAA;IAC3E,MAAMM,MAAAA,GAASF,gBAAMG,CAAAA,OAAO,CAC1B,IAAMC,qBAAiBN,mBAAoBI,CAAAA,MAAM,IAAI,EACrD,CAAA,EAAA;AAACJ,QAAAA,mBAAAA,CAAoBI;AAAO,KAAA,CAAA;AAE9B,IAAA,MAAMG,WAAWC,uBAAY,CAAA;AAAE,QAAA,GAAGR,mBAAmB;AAAEI,QAAAA;AAAO,KAAA,CAAA;AAE9D,IAAA,MAAM,CAACK,eAAiBC,EAAAA,kBAAAA,CAAmB,GAAGR,gBAAMC,CAAAA,QAAQ,CAAiB,EAAE,CAAA;AAE/E,IAAA,qBACEQ,cAAClB,CAAAA,gBAAAA,EAAAA;QACCQ,cAAgBA,EAAAA,cAAAA;QAChBM,QAAUA,EAAAA,QAAAA;QACVK,gBAAkB,EAAA;AAChBC,YAAAA,UAAAA,EAAYf,gBAAgBe,UAAU;AACtCC,YAAAA,KAAAA,EAAOhB,gBAAgBgB,KAAK;AAC5BC,YAAAA,cAAAA,EAAgBjB,gBAAgBiB;AAClC,SAAA;QACAC,IAAMhB,EAAAA,mBAAAA;QACNS,eAAiBA,EAAAA,eAAAA;QACjBC,kBAAoBA,EAAAA,kBAAAA;QACpBX,SAAWA,EAAAA,SAAAA;AAEVF,QAAAA,QAAAA,EAAAA;;AAGP;;;;;"}
|