node_modules ignore

This commit is contained in:
oier committed 2025-05-08 23:43:47 +02:00
1 parent e19d52f172
commit 4574544c9f
65041 files changed
+10593536

No files matched your search

@@ -0,0 +1,286 @@
'use strict';
var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var strapiAdmin = require('@strapi/admin/strapi-admin');
var designSystem = require('@strapi/design-system');
var Icons = require('@strapi/icons');
var reactIntl = require('react-intl');
var reactRouterDom = require('react-router-dom');
var styledComponents = require('styled-components');
var collections = require('../../constants/collections.js');
var DocumentRBAC = require('../../features/DocumentRBAC.js');
var useDocument = require('../../hooks/useDocument.js');
var useDocumentLayout = require('../../hooks/useDocumentLayout.js');
var FormLayout = require('../../pages/EditView/components/FormLayout.js');
var api = require('../../utils/api.js');
var validation = require('../../utils/validation.js');
var PreviewHeader = require('../components/PreviewHeader.js');
var preview = require('../services/preview.js');
function _interopNamespaceDefault(e) {
var n = Object.create(null);
if (e) {
Object.keys(e).forEach(function (k) {
if (k !== 'default') {
var d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: function () { return e[k]; }
});
}
});
}
n.default = e;
return Object.freeze(n);
}
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
const [PreviewProvider, usePreviewContext] = strapiAdmin.createContext('PreviewPage');
/* -------------------------------------------------------------------------------------------------
* PreviewPage
* -----------------------------------------------------------------------------------------------*/ const AnimatedArrow = styledComponents.styled(Icons.ArrowLineLeft)`
will-change: transform;
rotate: ${(props)=>props.isSideEditorOpen ? '0deg' : '180deg'};
transition: rotate 0.2s ease-in-out;
`;
const PreviewPage = ()=>{
const location = reactRouterDom.useLocation();
const { formatMessage } = reactIntl.useIntl();
const iframeRef = React__namespace.useRef(null);
const [isSideEditorOpen, setIsSideEditorOpen] = React__namespace.useState(true);
// Read all the necessary data from the URL to find the right preview URL
const { slug: model, id: documentId, collectionType } = reactRouterDom.useParams();
const [{ query }] = strapiAdmin.useQueryParams();
const params = React__namespace.useMemo(()=>api.buildValidParams(query), [
query
]);
if (!collectionType) {
throw new Error('Could not find collectionType in url params');
}
if (!model) {
throw new Error('Could not find model in url params');
}
// Only collection types must have a documentId
if (collectionType === collections.COLLECTION_TYPES && !documentId) {
throw new Error('Could not find documentId in url params');
}
const previewUrlResponse = preview.useGetPreviewUrlQuery({
params: {
contentType: model
},
query: {
documentId,
locale: params.locale,
status: params.status
}
});
const documentResponse = useDocument.useDocument({
model,
collectionType,
documentId,
params
});
const documentLayoutResponse = useDocumentLayout.useDocumentLayout(model);
const isLoading = previewUrlResponse.isLoading || documentLayoutResponse.isLoading || documentResponse.isLoading;
if (isLoading && !documentResponse.document?.documentId) {
return /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Page.Loading, {});
}
const initialValues = documentResponse.getInitialFormValues();
if (previewUrlResponse.error || documentLayoutResponse.error || !documentResponse.document || !documentResponse.meta || !documentResponse.schema || !initialValues) {
return /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Page.Error, {});
}
if (!previewUrlResponse.data?.data?.url) {
return /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Page.NoData, {});
}
const documentTitle = documentResponse.getTitle(documentLayoutResponse.edit.settings.mainField);
const validateSync = (values, options)=>{
const yupSchema = validation.createYupSchema(documentResponse.schema?.attributes, documentResponse.components, {
status: documentResponse.document?.status,
...options
});
return yupSchema.validateSync(values, {
abortEarly: false
});
};
const previewUrl = previewUrlResponse.data.data.url;
const onPreview = ()=>{
iframeRef?.current?.contentWindow?.postMessage({
type: 'strapiUpdate'
}, // The iframe origin is safe to use since it must be provided through the allowedOrigins config
new URL(iframeRef.current.src).origin);
};
const hasAdvancedPreview = window.strapi.features.isEnabled('cms-advanced-preview');
return /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
children: [
/*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Page.Title, {
children: formatMessage({
id: 'content-manager.preview.page-title',
defaultMessage: '{contentType} preview'
}, {
contentType: documentTitle
})
}),
/*#__PURE__*/ jsxRuntime.jsx(PreviewProvider, {
url: previewUrl,
document: documentResponse.document,
title: documentTitle,
meta: documentResponse.meta,
schema: documentResponse.schema,
layout: documentLayoutResponse.edit,
onPreview: onPreview,
children: /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Form, {
method: "PUT",
disabled: query.status === 'published' && documentResponse && documentResponse.document.status !== 'draft',
initialValues: documentResponse.getInitialFormValues(),
initialErrors: location?.state?.forceValidation ? validateSync(initialValues, {}) : {},
height: "100%",
validate: (values, options)=>{
const yupSchema = validation.createYupSchema(documentResponse.schema?.attributes, documentResponse.components, {
status: documentResponse.document?.status,
...options
});
return yupSchema.validate(values, {
abortEarly: false
});
},
children: ({ resetForm })=>/*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
direction: "column",
height: "100%",
alignItems: "stretch",
children: [
/*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Blocker, {
onProceed: resetForm
}),
/*#__PURE__*/ jsxRuntime.jsx(PreviewHeader.PreviewHeader, {}),
/*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
flex: 1,
overflow: "auto",
alignItems: "stretch",
children: [
hasAdvancedPreview && /*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
overflow: "auto",
width: isSideEditorOpen ? '50%' : 0,
borderWidth: "0 1px 0 0",
borderColor: "neutral150",
paddingTop: 6,
paddingBottom: 6,
// Remove horizontal padding when the editor is closed or it won't fully disappear
paddingLeft: isSideEditorOpen ? 6 : 0,
paddingRight: isSideEditorOpen ? 6 : 0,
transition: "all 0.2s ease-in-out",
children: /*#__PURE__*/ jsxRuntime.jsx(FormLayout.FormLayout, {
layout: documentLayoutResponse.edit.layout,
document: documentResponse,
hasBackground: false
})
}),
/*#__PURE__*/ jsxRuntime.jsxs(designSystem.Box, {
position: "relative",
flex: 1,
height: "100%",
overflow: "hidden",
children: [
/*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
"data-testid": "preview-iframe",
ref: iframeRef,
src: previewUrl,
title: formatMessage({
id: 'content-manager.preview.panel.title',
defaultMessage: 'Preview'
}),
width: "100%",
height: "100%",
borderWidth: 0,
tag: "iframe"
}, previewUrl),
hasAdvancedPreview && /*#__PURE__*/ jsxRuntime.jsx(designSystem.IconButton, {
variant: "tertiary",
label: formatMessage(isSideEditorOpen ? {
id: 'content-manager.preview.content.close-editor',
defaultMessage: 'Close editor'
} : {
id: 'content-manager.preview.content.open-editor',
defaultMessage: 'Open editor'
}),
onClick: ()=>setIsSideEditorOpen((prev)=>!prev),
position: "absolute",
top: 2,
left: 2,
children: /*#__PURE__*/ jsxRuntime.jsx(AnimatedArrow, {
isSideEditorOpen: isSideEditorOpen
})
})
]
})
]
})
]
})
})
})
]
});
};
/* -------------------------------------------------------------------------------------------------
* ProtectedPreviewPage
* -----------------------------------------------------------------------------------------------*/ const ProtectedPreviewPageImpl = ()=>{
const { slug: model } = reactRouterDom.useParams();
const { permissions = [], isLoading, error } = strapiAdmin.useRBAC([
{
action: 'plugin::content-manager.explorer.read',
subject: model
},
{
action: 'plugin::content-manager.explorer.update',
subject: model
},
{
action: 'plugin::content-manager.explorer.publish',
subject: model
}
]);
if (isLoading) {
return /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Page.Loading, {});
}
if (error || !model) {
return /*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
height: "100vh",
width: "100vw",
position: "fixed",
top: 0,
left: 0,
zIndex: 2,
background: "neutral0",
children: /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Page.Error, {})
});
}
return /*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
height: "100vh",
width: "100vw",
position: "fixed",
top: 0,
left: 0,
zIndex: 2,
background: "neutral0",
children: /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Page.Protect, {
permissions: permissions.filter((permission)=>permission.action.includes('explorer.read')),
children: /*#__PURE__*/ jsxRuntime.jsx(DocumentRBAC.DocumentRBAC, {
permissions: permissions,
children: /*#__PURE__*/ jsxRuntime.jsx(PreviewPage, {})
})
})
});
};
const ProtectedPreviewPage = ()=>{
return /*#__PURE__*/ jsxRuntime.jsx(designSystem.Portal, {
children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.FocusTrap, {
children: /*#__PURE__*/ jsxRuntime.jsx(ProtectedPreviewPageImpl, {})
})
});
};
exports.ProtectedPreviewPage = ProtectedPreviewPage;
exports.usePreviewContext = usePreviewContext;
//# sourceMappingURL=Preview.js.map
@@ -0,0 +1 @@
{"version":3,"file":"Preview.js","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 onPLine truncated
@@ -0,0 +1,264 @@
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
import * as React from 'react';
import { createContext, useRBAC, Page, useQueryParams, Form, Blocker } from '@strapi/admin/strapi-admin';
import { Portal, FocusTrap, Box, Flex, IconButton } from '@strapi/design-system';
import { ArrowLineLeft } from '@strapi/icons';
import { useIntl } from 'react-intl';
import { useParams, useLocation } from 'react-router-dom';
import { styled } from 'styled-components';
import { COLLECTION_TYPES } from '../../constants/collections.mjs';
import { DocumentRBAC } from '../../features/DocumentRBAC.mjs';
import { useDocument } from '../../hooks/useDocument.mjs';
import { useDocumentLayout } from '../../hooks/useDocumentLayout.mjs';
import { FormLayout } from '../../pages/EditView/components/FormLayout.mjs';
import { buildValidParams } from '../../utils/api.mjs';
import { createYupSchema } from '../../utils/validation.mjs';
import { PreviewHeader } from '../components/PreviewHeader.mjs';
import { useGetPreviewUrlQuery } from '../services/preview.mjs';
const [PreviewProvider, usePreviewContext] = createContext('PreviewPage');
/* -------------------------------------------------------------------------------------------------
* PreviewPage
* -----------------------------------------------------------------------------------------------*/ const AnimatedArrow = styled(ArrowLineLeft)`
will-change: transform;
rotate: ${(props)=>props.isSideEditorOpen ? '0deg' : '180deg'};
transition: rotate 0.2s ease-in-out;
`;
const PreviewPage = ()=>{
const location = useLocation();
const { formatMessage } = useIntl();
const iframeRef = React.useRef(null);
const [isSideEditorOpen, setIsSideEditorOpen] = React.useState(true);
// Read all the necessary data from the URL to find the right preview URL
const { slug: model, id: documentId, collectionType } = useParams();
const [{ query }] = useQueryParams();
const params = React.useMemo(()=>buildValidParams(query), [
query
]);
if (!collectionType) {
throw new Error('Could not find collectionType in url params');
}
if (!model) {
throw new Error('Could not find model in url params');
}
// Only collection types must have a documentId
if (collectionType === COLLECTION_TYPES && !documentId) {
throw new Error('Could not find documentId in url params');
}
const previewUrlResponse = useGetPreviewUrlQuery({
params: {
contentType: model
},
query: {
documentId,
locale: params.locale,
status: params.status
}
});
const documentResponse = useDocument({
model,
collectionType,
documentId,
params
});
const documentLayoutResponse = useDocumentLayout(model);
const isLoading = previewUrlResponse.isLoading || documentLayoutResponse.isLoading || documentResponse.isLoading;
if (isLoading && !documentResponse.document?.documentId) {
return /*#__PURE__*/ jsx(Page.Loading, {});
}
const initialValues = documentResponse.getInitialFormValues();
if (previewUrlResponse.error || documentLayoutResponse.error || !documentResponse.document || !documentResponse.meta || !documentResponse.schema || !initialValues) {
return /*#__PURE__*/ jsx(Page.Error, {});
}
if (!previewUrlResponse.data?.data?.url) {
return /*#__PURE__*/ jsx(Page.NoData, {});
}
const documentTitle = documentResponse.getTitle(documentLayoutResponse.edit.settings.mainField);
const validateSync = (values, options)=>{
const yupSchema = createYupSchema(documentResponse.schema?.attributes, documentResponse.components, {
status: documentResponse.document?.status,
...options
});
return yupSchema.validateSync(values, {
abortEarly: false
});
};
const previewUrl = previewUrlResponse.data.data.url;
const onPreview = ()=>{
iframeRef?.current?.contentWindow?.postMessage({
type: 'strapiUpdate'
}, // The iframe origin is safe to use since it must be provided through the allowedOrigins config
new URL(iframeRef.current.src).origin);
};
const hasAdvancedPreview = window.strapi.features.isEnabled('cms-advanced-preview');
return /*#__PURE__*/ jsxs(Fragment, {
children: [
/*#__PURE__*/ jsx(Page.Title, {
children: formatMessage({
id: 'content-manager.preview.page-title',
defaultMessage: '{contentType} preview'
}, {
contentType: documentTitle
})
}),
/*#__PURE__*/ jsx(PreviewProvider, {
url: previewUrl,
document: documentResponse.document,
title: documentTitle,
meta: documentResponse.meta,
schema: documentResponse.schema,
layout: documentLayoutResponse.edit,
onPreview: onPreview,
children: /*#__PURE__*/ jsx(Form, {
method: "PUT",
disabled: query.status === 'published' && documentResponse && documentResponse.document.status !== 'draft',
initialValues: documentResponse.getInitialFormValues(),
initialErrors: location?.state?.forceValidation ? validateSync(initialValues, {}) : {},
height: "100%",
validate: (values, options)=>{
const yupSchema = createYupSchema(documentResponse.schema?.attributes, documentResponse.components, {
status: documentResponse.document?.status,
...options
});
return yupSchema.validate(values, {
abortEarly: false
});
},
children: ({ resetForm })=>/*#__PURE__*/ jsxs(Flex, {
direction: "column",
height: "100%",
alignItems: "stretch",
children: [
/*#__PURE__*/ jsx(Blocker, {
onProceed: resetForm
}),
/*#__PURE__*/ jsx(PreviewHeader, {}),
/*#__PURE__*/ jsxs(Flex, {
flex: 1,
overflow: "auto",
alignItems: "stretch",
children: [
hasAdvancedPreview && /*#__PURE__*/ jsx(Box, {
overflow: "auto",
width: isSideEditorOpen ? '50%' : 0,
borderWidth: "0 1px 0 0",
borderColor: "neutral150",
paddingTop: 6,
paddingBottom: 6,
// Remove horizontal padding when the editor is closed or it won't fully disappear
paddingLeft: isSideEditorOpen ? 6 : 0,
paddingRight: isSideEditorOpen ? 6 : 0,
transition: "all 0.2s ease-in-out",
children: /*#__PURE__*/ jsx(FormLayout, {
layout: documentLayoutResponse.edit.layout,
document: documentResponse,
hasBackground: false
})
}),
/*#__PURE__*/ jsxs(Box, {
position: "relative",
flex: 1,
height: "100%",
overflow: "hidden",
children: [
/*#__PURE__*/ jsx(Box, {
"data-testid": "preview-iframe",
ref: iframeRef,
src: previewUrl,
title: formatMessage({
id: 'content-manager.preview.panel.title',
defaultMessage: 'Preview'
}),
width: "100%",
height: "100%",
borderWidth: 0,
tag: "iframe"
}, previewUrl),
hasAdvancedPreview && /*#__PURE__*/ jsx(IconButton, {
variant: "tertiary",
label: formatMessage(isSideEditorOpen ? {
id: 'content-manager.preview.content.close-editor',
defaultMessage: 'Close editor'
} : {
id: 'content-manager.preview.content.open-editor',
defaultMessage: 'Open editor'
}),
onClick: ()=>setIsSideEditorOpen((prev)=>!prev),
position: "absolute",
top: 2,
left: 2,
children: /*#__PURE__*/ jsx(AnimatedArrow, {
isSideEditorOpen: isSideEditorOpen
})
})
]
})
]
})
]
})
})
})
]
});
};
/* -------------------------------------------------------------------------------------------------
* ProtectedPreviewPage
* -----------------------------------------------------------------------------------------------*/ const ProtectedPreviewPageImpl = ()=>{
const { slug: model } = useParams();
const { permissions = [], isLoading, error } = useRBAC([
{
action: 'plugin::content-manager.explorer.read',
subject: model
},
{
action: 'plugin::content-manager.explorer.update',
subject: model
},
{
action: 'plugin::content-manager.explorer.publish',
subject: model
}
]);
if (isLoading) {
return /*#__PURE__*/ jsx(Page.Loading, {});
}
if (error || !model) {
return /*#__PURE__*/ jsx(Box, {
height: "100vh",
width: "100vw",
position: "fixed",
top: 0,
left: 0,
zIndex: 2,
background: "neutral0",
children: /*#__PURE__*/ jsx(Page.Error, {})
});
}
return /*#__PURE__*/ jsx(Box, {
height: "100vh",
width: "100vw",
position: "fixed",
top: 0,
left: 0,
zIndex: 2,
background: "neutral0",
children: /*#__PURE__*/ jsx(Page.Protect, {
permissions: permissions.filter((permission)=>permission.action.includes('explorer.read')),
children: /*#__PURE__*/ jsx(DocumentRBAC, {
permissions: permissions,
children: /*#__PURE__*/ jsx(PreviewPage, {})
})
})
});
};
const ProtectedPreviewPage = ()=>{
return /*#__PURE__*/ jsx(Portal, {
children: /*#__PURE__*/ jsx(FocusTrap, {
children: /*#__PURE__*/ jsx(ProtectedPreviewPageImpl, {})
})
});
};
export { ProtectedPreviewPage, usePreviewContext };
//# sourceMappingURL=Preview.mjs.map
@@ -0,0 +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 onLine truncated