@strapi/content-manager 0.0.0-experimental.e14656d3b8681880212c13260b9a2b340c182f2d → 0.0.0-experimental.e350eaa6073e65190102b4b798c32c287053cc02
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/_chunks/CardDragPreview-C0QyJgRA.js.map +1 -1
- package/dist/_chunks/CardDragPreview-DOxamsuj.mjs.map +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-D_M8iBw5.js → ComponentConfigurationPage-BTR_hQow.js} +5 -6
- package/dist/_chunks/{ComponentConfigurationPage-D_M8iBw5.js.map → ComponentConfigurationPage-BTR_hQow.js.map} +1 -1
- package/dist/_chunks/{ComponentConfigurationPage-qemkOlnj.mjs → ComponentConfigurationPage-bLQr82ce.mjs} +4 -4
- package/dist/_chunks/{ComponentConfigurationPage-qemkOlnj.mjs.map → ComponentConfigurationPage-bLQr82ce.mjs.map} +1 -1
- package/dist/_chunks/{ComponentIcon-BXdiCGQp.js → ComponentIcon-CRbtQEUV.js} +2 -3
- package/dist/_chunks/{ComponentIcon-BXdiCGQp.js.map → ComponentIcon-CRbtQEUV.js.map} +1 -1
- package/dist/_chunks/ComponentIcon-u4bIXTFY.mjs.map +1 -1
- package/dist/_chunks/{EditConfigurationPage-CjUrEewK.mjs → EditConfigurationPage-BhRSnUsL.mjs} +4 -4
- package/dist/_chunks/{EditConfigurationPage-CjUrEewK.mjs.map → EditConfigurationPage-BhRSnUsL.mjs.map} +1 -1
- package/dist/_chunks/{EditConfigurationPage-BePwPuHy.js → EditConfigurationPage-z39Wv3E6.js} +5 -6
- package/dist/_chunks/{EditConfigurationPage-BePwPuHy.js.map → EditConfigurationPage-z39Wv3E6.js.map} +1 -1
- package/dist/_chunks/{EditViewPage-De8GyU8P.mjs → EditViewPage-BCjNxNlY.mjs} +50 -10
- package/dist/_chunks/EditViewPage-BCjNxNlY.mjs.map +1 -0
- package/dist/_chunks/{EditViewPage-B-RJeiJD.js → EditViewPage-wujOq90c.js} +50 -11
- package/dist/_chunks/EditViewPage-wujOq90c.js.map +1 -0
- package/dist/_chunks/{Field-dq8Tg1M_.js → Field-B5QXnctJ.js} +238 -153
- package/dist/_chunks/Field-B5QXnctJ.js.map +1 -0
- package/dist/_chunks/{Field-pb2o8uBe.mjs → Field-Byr3mPTl.mjs} +232 -147
- package/dist/_chunks/Field-Byr3mPTl.mjs.map +1 -0
- package/dist/_chunks/FieldTypeIcon-CMlNO8PE.mjs.map +1 -1
- package/dist/_chunks/FieldTypeIcon-Dnwq_IRF.js.map +1 -1
- package/dist/_chunks/{Form-DJn0Dxha.mjs → Form-BZgvE8C8.mjs} +17 -9
- package/dist/_chunks/Form-BZgvE8C8.mjs.map +1 -0
- package/dist/_chunks/{Form-DGIf4jQU.js → Form-D7mexvm3.js} +19 -12
- package/dist/_chunks/Form-D7mexvm3.js.map +1 -0
- package/dist/_chunks/{History-BowL3JKP.mjs → History-CqNgxkqK.mjs} +43 -100
- package/dist/_chunks/History-CqNgxkqK.mjs.map +1 -0
- package/dist/_chunks/{History-Dh2NEHnR.js → History-DYl2A8Z_.js} +42 -100
- package/dist/_chunks/History-DYl2A8Z_.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-BxYCWz9e.js → ListConfigurationPage-BXnu_OoY.js} +7 -7
- package/dist/_chunks/ListConfigurationPage-BXnu_OoY.js.map +1 -0
- package/dist/_chunks/{ListConfigurationPage-BpVOB-hn.mjs → ListConfigurationPage-BbQjzKkQ.mjs} +7 -6
- package/dist/_chunks/ListConfigurationPage-BbQjzKkQ.mjs.map +1 -0
- package/dist/_chunks/{ListViewPage-4XsciqHZ.js → ListViewPage-BtSi8C1l.js} +103 -77
- package/dist/_chunks/ListViewPage-BtSi8C1l.js.map +1 -0
- package/dist/_chunks/{ListViewPage-CXFUjZQC.mjs → ListViewPage-D4ofkbjR.mjs} +99 -72
- package/dist/_chunks/ListViewPage-D4ofkbjR.mjs.map +1 -0
- package/dist/_chunks/{NoContentTypePage-C8OpoHeU.js → NoContentTypePage-CitJeOq4.js} +2 -2
- package/dist/_chunks/{NoContentTypePage-C8OpoHeU.js.map → NoContentTypePage-CitJeOq4.js.map} +1 -1
- package/dist/_chunks/{NoContentTypePage-DuhOTp3x.mjs → NoContentTypePage-DyUx5mXh.mjs} +2 -2
- package/dist/_chunks/{NoContentTypePage-DuhOTp3x.mjs.map → NoContentTypePage-DyUx5mXh.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-DVz3mzDz.mjs → NoPermissionsPage-DhIiyWkk.mjs} +2 -2
- package/dist/_chunks/{NoPermissionsPage-DVz3mzDz.mjs.map → NoPermissionsPage-DhIiyWkk.mjs.map} +1 -1
- package/dist/_chunks/{NoPermissionsPage-y_r7DVA2.js → NoPermissionsPage-DzgWz0M-.js} +2 -2
- package/dist/_chunks/{NoPermissionsPage-y_r7DVA2.js.map → NoPermissionsPage-DzgWz0M-.js.map} +1 -1
- package/dist/_chunks/Preview-BaYGJ0nb.mjs +293 -0
- package/dist/_chunks/Preview-BaYGJ0nb.mjs.map +1 -0
- package/dist/_chunks/Preview-DfNx8Ke-.js +311 -0
- package/dist/_chunks/Preview-DfNx8Ke-.js.map +1 -0
- package/dist/_chunks/{Relations-CVNLrn1Y.mjs → Relations-DM2yUTST.mjs} +75 -41
- package/dist/_chunks/Relations-DM2yUTST.mjs.map +1 -0
- package/dist/_chunks/{Relations-DPFCAa7b.js → Relations-DuKCaXrv.js} +75 -42
- package/dist/_chunks/Relations-DuKCaXrv.js.map +1 -0
- package/dist/_chunks/{en-uOUIxfcQ.js → en-BK8Xyl5I.js} +28 -15
- package/dist/_chunks/{en-uOUIxfcQ.js.map → en-BK8Xyl5I.js.map} +1 -1
- package/dist/_chunks/{en-BrCTWlZv.mjs → en-Dtk_ot79.mjs} +28 -15
- package/dist/_chunks/{en-BrCTWlZv.mjs.map → en-Dtk_ot79.mjs.map} +1 -1
- package/dist/_chunks/{es-EUonQTon.js → es-9K52xZIr.js} +2 -2
- package/dist/_chunks/{ja-CcFe8diO.js.map → es-9K52xZIr.js.map} +1 -1
- package/dist/_chunks/{es-CeXiYflN.mjs → es-D34tqjMw.mjs} +2 -2
- package/dist/_chunks/{es-CeXiYflN.mjs.map → es-D34tqjMw.mjs.map} +1 -1
- package/dist/_chunks/{fr-CD9VFbPM.mjs → fr--pg5jUbt.mjs} +13 -3
- package/dist/_chunks/{fr-CD9VFbPM.mjs.map → fr--pg5jUbt.mjs.map} +1 -1
- package/dist/_chunks/{fr-B7kGGg3E.js → fr-B2Kyv8Z9.js} +13 -3
- package/dist/_chunks/{fr-B7kGGg3E.js.map → fr-B2Kyv8Z9.js.map} +1 -1
- package/dist/_chunks/hooks-BAaaKPS_.js.map +1 -1
- package/dist/_chunks/{index-C3fJE-1-.js → index-BUWEmX8m.js} +1273 -996
- package/dist/_chunks/index-BUWEmX8m.js.map +1 -0
- package/dist/_chunks/{index-DiMrfcfy.mjs → index-DVAIIsOs.mjs} +1276 -999
- package/dist/_chunks/index-DVAIIsOs.mjs.map +1 -0
- package/dist/_chunks/{ja-CcFe8diO.js → ja-7sfIbjxE.js} +2 -2
- package/dist/_chunks/{es-EUonQTon.js.map → ja-7sfIbjxE.js.map} +1 -1
- package/dist/_chunks/{ja-CtsUxOvk.mjs → ja-BHqhDq4V.mjs} +2 -2
- package/dist/_chunks/{ja-CtsUxOvk.mjs.map → ja-BHqhDq4V.mjs.map} +1 -1
- package/dist/_chunks/{layout-ls3gxfpH.mjs → layout-Bxsv5mP7.mjs} +6 -5
- package/dist/_chunks/{layout-ls3gxfpH.mjs.map → layout-Bxsv5mP7.mjs.map} +1 -1
- package/dist/_chunks/{layout-C788OmNr.js → layout-C3fN7Ejz.js} +7 -7
- package/dist/_chunks/{layout-C788OmNr.js.map → layout-C3fN7Ejz.js.map} +1 -1
- package/dist/_chunks/{objects-gigeqt7s.js → objects-BcXOv6_9.js} +2 -4
- package/dist/_chunks/{objects-gigeqt7s.js.map → objects-BcXOv6_9.js.map} +1 -1
- package/dist/_chunks/{objects-mKMAmfec.mjs → objects-D6yBsdmx.mjs} +2 -4
- package/dist/_chunks/{objects-mKMAmfec.mjs.map → objects-D6yBsdmx.mjs.map} +1 -1
- package/dist/_chunks/{relations-DYeotliT.js → relations-BPZKAoEY.js} +6 -7
- package/dist/_chunks/relations-BPZKAoEY.js.map +1 -0
- package/dist/_chunks/{relations-CLcOmGO0.mjs → relations-o3pPhzY4.mjs} +6 -7
- package/dist/_chunks/relations-o3pPhzY4.mjs.map +1 -0
- package/dist/_chunks/{usePrev-B9w_-eYc.js → useDebounce-CtcjDB3L.js} +14 -1
- package/dist/_chunks/useDebounce-CtcjDB3L.js.map +1 -0
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs +29 -0
- package/dist/_chunks/useDebounce-DmuSJIF3.mjs.map +1 -0
- package/dist/_chunks/{useDragAndDrop-J0TUUbR6.js → useDragAndDrop-BMtgCYzL.js} +5 -9
- package/dist/_chunks/{useDragAndDrop-J0TUUbR6.js.map → useDragAndDrop-BMtgCYzL.js.map} +1 -1
- package/dist/_chunks/{useDragAndDrop-DdHgKsqq.mjs → useDragAndDrop-DJ6jqvZN.mjs} +4 -7
- package/dist/_chunks/{useDragAndDrop-DdHgKsqq.mjs.map → useDragAndDrop-DJ6jqvZN.mjs.map} +1 -1
- package/dist/admin/index.js +2 -1
- package/dist/admin/index.js.map +1 -1
- package/dist/admin/index.mjs +4 -3
- package/dist/admin/src/content-manager.d.ts +3 -2
- package/dist/admin/src/exports.d.ts +1 -1
- package/dist/admin/src/hooks/useDocument.d.ts +32 -1
- package/dist/admin/src/pages/EditView/EditViewPage.d.ts +9 -1
- package/dist/admin/src/pages/EditView/components/DocumentActions.d.ts +1 -1
- package/dist/admin/src/pages/EditView/components/DocumentStatus.d.ts +2 -2
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.d.ts +7 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/Blocks/utils/prismLanguages.d.ts +49 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/utils/constants.d.ts +1 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/WysiwygStyles.d.ts +0 -32
- package/dist/admin/src/pages/EditView/components/Header.d.ts +11 -11
- package/dist/admin/src/preview/components/PreviewContent.d.ts +2 -0
- package/dist/admin/src/preview/components/PreviewHeader.d.ts +2 -0
- package/dist/admin/src/preview/components/PreviewSidePanel.d.ts +3 -0
- package/dist/admin/src/preview/index.d.ts +4 -0
- package/dist/admin/src/preview/pages/Preview.d.ts +11 -0
- package/dist/admin/src/preview/routes.d.ts +3 -0
- package/dist/admin/src/preview/services/preview.d.ts +3 -0
- package/dist/admin/src/router.d.ts +1 -1
- package/dist/admin/src/services/documents.d.ts +3 -4
- package/dist/server/index.js +453 -201
- package/dist/server/index.js.map +1 -1
- package/dist/server/index.mjs +453 -200
- package/dist/server/index.mjs.map +1 -1
- package/dist/server/src/bootstrap.d.ts.map +1 -1
- package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
- package/dist/server/src/controllers/index.d.ts.map +1 -1
- package/dist/server/src/controllers/relations.d.ts.map +1 -1
- package/dist/server/src/controllers/utils/metadata.d.ts +15 -1
- package/dist/server/src/controllers/utils/metadata.d.ts.map +1 -1
- package/dist/server/src/history/services/history.d.ts.map +1 -1
- package/dist/server/src/history/services/lifecycles.d.ts.map +1 -1
- package/dist/server/src/history/services/utils.d.ts +3 -3
- package/dist/server/src/history/services/utils.d.ts.map +1 -1
- package/dist/server/src/index.d.ts +4 -4
- package/dist/server/src/preview/controllers/index.d.ts +2 -0
- package/dist/server/src/preview/controllers/index.d.ts.map +1 -0
- package/dist/server/src/preview/controllers/preview.d.ts +13 -0
- package/dist/server/src/preview/controllers/preview.d.ts.map +1 -0
- package/dist/server/src/preview/controllers/validation/preview.d.ts +6 -0
- package/dist/server/src/preview/controllers/validation/preview.d.ts.map +1 -0
- package/dist/server/src/preview/index.d.ts +4 -0
- package/dist/server/src/preview/index.d.ts.map +1 -0
- package/dist/server/src/preview/routes/index.d.ts +8 -0
- package/dist/server/src/preview/routes/index.d.ts.map +1 -0
- package/dist/server/src/preview/routes/preview.d.ts +4 -0
- package/dist/server/src/preview/routes/preview.d.ts.map +1 -0
- package/dist/server/src/preview/services/index.d.ts +16 -0
- package/dist/server/src/preview/services/index.d.ts.map +1 -0
- package/dist/server/src/preview/services/preview-config.d.ts +32 -0
- package/dist/server/src/preview/services/preview-config.d.ts.map +1 -0
- package/dist/server/src/preview/services/preview.d.ts +12 -0
- package/dist/server/src/preview/services/preview.d.ts.map +1 -0
- package/dist/server/src/preview/utils.d.ts +19 -0
- package/dist/server/src/preview/utils.d.ts.map +1 -0
- package/dist/server/src/register.d.ts.map +1 -1
- package/dist/server/src/routes/index.d.ts.map +1 -1
- package/dist/server/src/services/document-manager.d.ts.map +1 -1
- package/dist/server/src/services/document-metadata.d.ts +8 -8
- package/dist/server/src/services/document-metadata.d.ts.map +1 -1
- package/dist/server/src/services/index.d.ts +4 -4
- package/dist/server/src/services/index.d.ts.map +1 -1
- package/dist/server/src/services/utils/configuration/index.d.ts +2 -2
- package/dist/server/src/services/utils/configuration/layouts.d.ts +2 -2
- package/dist/server/src/utils/index.d.ts +2 -0
- package/dist/server/src/utils/index.d.ts.map +1 -1
- package/dist/shared/contracts/collection-types.d.ts +3 -1
- package/dist/shared/contracts/collection-types.d.ts.map +1 -1
- package/dist/shared/contracts/index.d.ts +1 -0
- package/dist/shared/contracts/index.d.ts.map +1 -1
- package/dist/shared/contracts/preview.d.ts +27 -0
- package/dist/shared/contracts/preview.d.ts.map +1 -0
- package/dist/shared/index.js +4 -0
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/index.mjs +4 -0
- package/dist/shared/index.mjs.map +1 -1
- package/package.json +17 -15
- package/dist/_chunks/EditViewPage-B-RJeiJD.js.map +0 -1
- package/dist/_chunks/EditViewPage-De8GyU8P.mjs.map +0 -1
- package/dist/_chunks/Field-dq8Tg1M_.js.map +0 -1
- package/dist/_chunks/Field-pb2o8uBe.mjs.map +0 -1
- package/dist/_chunks/Form-DGIf4jQU.js.map +0 -1
- package/dist/_chunks/Form-DJn0Dxha.mjs.map +0 -1
- package/dist/_chunks/History-BowL3JKP.mjs.map +0 -1
- package/dist/_chunks/History-Dh2NEHnR.js.map +0 -1
- package/dist/_chunks/ListConfigurationPage-BpVOB-hn.mjs.map +0 -1
- package/dist/_chunks/ListConfigurationPage-BxYCWz9e.js.map +0 -1
- package/dist/_chunks/ListViewPage-4XsciqHZ.js.map +0 -1
- package/dist/_chunks/ListViewPage-CXFUjZQC.mjs.map +0 -1
- package/dist/_chunks/Relations-CVNLrn1Y.mjs.map +0 -1
- package/dist/_chunks/Relations-DPFCAa7b.js.map +0 -1
- package/dist/_chunks/index-C3fJE-1-.js.map +0 -1
- package/dist/_chunks/index-DiMrfcfy.mjs.map +0 -1
- package/dist/_chunks/relations-CLcOmGO0.mjs.map +0 -1
- package/dist/_chunks/relations-DYeotliT.js.map +0 -1
- package/dist/_chunks/usePrev-B9w_-eYc.js.map +0 -1
- package/dist/_chunks/usePrev-DH6iah0A.mjs +0 -16
- package/dist/_chunks/usePrev-DH6iah0A.mjs.map +0 -1
- package/strapi-server.js +0 -3
@@ -0,0 +1,311 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
3
|
+
const jsxRuntime = require("react/jsx-runtime");
|
4
|
+
const React = require("react");
|
5
|
+
const strapiAdmin = require("@strapi/admin/strapi-admin");
|
6
|
+
const designSystem = require("@strapi/design-system");
|
7
|
+
const reactIntl = require("react-intl");
|
8
|
+
const reactRouterDom = require("react-router-dom");
|
9
|
+
const index = require("./index-BUWEmX8m.js");
|
10
|
+
const Icons = require("@strapi/icons");
|
11
|
+
const qs = require("qs");
|
12
|
+
const styledComponents = require("styled-components");
|
13
|
+
const EditViewPage = require("./EditViewPage-wujOq90c.js");
|
14
|
+
function _interopNamespace(e) {
|
15
|
+
if (e && e.__esModule) return e;
|
16
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
17
|
+
if (e) {
|
18
|
+
for (const k in e) {
|
19
|
+
if (k !== "default") {
|
20
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
21
|
+
Object.defineProperty(n, k, d.get ? d : {
|
22
|
+
enumerable: true,
|
23
|
+
get: () => e[k]
|
24
|
+
});
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
n.default = e;
|
29
|
+
return Object.freeze(n);
|
30
|
+
}
|
31
|
+
const React__namespace = /* @__PURE__ */ _interopNamespace(React);
|
32
|
+
const PreviewContent = () => {
|
33
|
+
const previewUrl = usePreviewContext("PreviewContent", (state) => state.url);
|
34
|
+
const { formatMessage } = reactIntl.useIntl();
|
35
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
36
|
+
designSystem.Box,
|
37
|
+
{
|
38
|
+
src: previewUrl,
|
39
|
+
title: formatMessage({
|
40
|
+
id: "content-manager.preview.panel.title",
|
41
|
+
defaultMessage: "Preview"
|
42
|
+
}),
|
43
|
+
width: "100%",
|
44
|
+
height: "100%",
|
45
|
+
borderWidth: 0,
|
46
|
+
tag: "iframe"
|
47
|
+
}
|
48
|
+
);
|
49
|
+
};
|
50
|
+
const ClosePreviewButton = () => {
|
51
|
+
const [{ query }] = strapiAdmin.useQueryParams();
|
52
|
+
const { formatMessage } = reactIntl.useIntl();
|
53
|
+
const canGoBack = strapiAdmin.useHistory("BackButton", (state) => state.canGoBack);
|
54
|
+
const goBack = strapiAdmin.useHistory("BackButton", (state) => state.goBack);
|
55
|
+
const history = strapiAdmin.useHistory("BackButton", (state) => state.history);
|
56
|
+
const locationIndex = strapiAdmin.useHistory("BackButton", (state) => state.currentLocationIndex);
|
57
|
+
const historyTo = canGoBack ? history.at(locationIndex - 2) : void 0;
|
58
|
+
const fallback = {
|
59
|
+
pathname: "..",
|
60
|
+
search: qs.stringify(query, { encode: false })
|
61
|
+
};
|
62
|
+
const toWithFallback = historyTo ?? fallback;
|
63
|
+
const handleClick = (e) => {
|
64
|
+
if (canGoBack) {
|
65
|
+
e.preventDefault();
|
66
|
+
goBack();
|
67
|
+
return;
|
68
|
+
}
|
69
|
+
};
|
70
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
71
|
+
designSystem.IconButton,
|
72
|
+
{
|
73
|
+
tag: reactRouterDom.Link,
|
74
|
+
relative: "path",
|
75
|
+
to: toWithFallback,
|
76
|
+
onClick: handleClick,
|
77
|
+
label: formatMessage({
|
78
|
+
id: "content-manager.preview.header.close",
|
79
|
+
defaultMessage: "Close preview"
|
80
|
+
}),
|
81
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(Icons.Cross, {})
|
82
|
+
}
|
83
|
+
);
|
84
|
+
};
|
85
|
+
const Status = () => {
|
86
|
+
const document = usePreviewContext("PreviewHeader", (state) => state.document);
|
87
|
+
const schema = usePreviewContext("PreviewHeader", (state) => state.schema);
|
88
|
+
const meta = usePreviewContext("PreviewHeader", (state) => state.meta);
|
89
|
+
const hasDraftAndPublished = schema?.options?.draftAndPublish ?? false;
|
90
|
+
if (!hasDraftAndPublished) {
|
91
|
+
return null;
|
92
|
+
}
|
93
|
+
const status = EditViewPage.getDocumentStatus(document, meta);
|
94
|
+
return /* @__PURE__ */ jsxRuntime.jsx(index.DocumentStatus, { status, size: "XS" });
|
95
|
+
};
|
96
|
+
const PreviewTabs = () => {
|
97
|
+
const { formatMessage } = reactIntl.useIntl();
|
98
|
+
const [{ query }, setQuery] = strapiAdmin.useQueryParams();
|
99
|
+
const document = usePreviewContext("PreviewHeader", (state) => state.document);
|
100
|
+
const schema = usePreviewContext("PreviewHeader", (state) => state.schema);
|
101
|
+
const meta = usePreviewContext("PreviewHeader", (state) => state.meta);
|
102
|
+
const hasDraftAndPublish = schema?.options?.draftAndPublish ?? false;
|
103
|
+
const documentStatus = EditViewPage.getDocumentStatus(document, meta);
|
104
|
+
const handleTabChange = (status) => {
|
105
|
+
if (status === "published" || status === "draft") {
|
106
|
+
setQuery({ status }, "push", true);
|
107
|
+
}
|
108
|
+
};
|
109
|
+
if (!hasDraftAndPublish) {
|
110
|
+
return null;
|
111
|
+
}
|
112
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tabs.Root, { variant: "simple", value: query.status || "draft", onValueChange: handleTabChange, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
113
|
+
designSystem.Tabs.List,
|
114
|
+
{
|
115
|
+
"aria-label": formatMessage({
|
116
|
+
id: "preview.tabs.label",
|
117
|
+
defaultMessage: "Document status"
|
118
|
+
}),
|
119
|
+
children: [
|
120
|
+
/* @__PURE__ */ jsxRuntime.jsx(StatusTab, { value: "draft", children: formatMessage({
|
121
|
+
id: "content-manager.containers.List.draft",
|
122
|
+
defaultMessage: "draft"
|
123
|
+
}) }),
|
124
|
+
/* @__PURE__ */ jsxRuntime.jsx(StatusTab, { value: "published", disabled: documentStatus === "draft", children: formatMessage({
|
125
|
+
id: "content-manager.containers.List.published",
|
126
|
+
defaultMessage: "published"
|
127
|
+
}) })
|
128
|
+
]
|
129
|
+
}
|
130
|
+
) }) });
|
131
|
+
};
|
132
|
+
const PreviewHeader = () => {
|
133
|
+
const mainField = usePreviewContext("PreviewHeader", (state) => state.mainField);
|
134
|
+
const document = usePreviewContext("PreviewHeader", (state) => state.document);
|
135
|
+
const schema = usePreviewContext("PreviewHeader", (state) => state.schema);
|
136
|
+
let documentTitle = "Untitled";
|
137
|
+
if (mainField !== "id" && document?.[mainField]) {
|
138
|
+
documentTitle = document[mainField];
|
139
|
+
} else if (schema.kind === "singleType" && schema?.info.displayName) {
|
140
|
+
documentTitle = schema.info.displayName;
|
141
|
+
}
|
142
|
+
const { formatMessage } = reactIntl.useIntl();
|
143
|
+
const { toggleNotification } = strapiAdmin.useNotification();
|
144
|
+
const { copy } = strapiAdmin.useClipboard();
|
145
|
+
const handleCopyLink = () => {
|
146
|
+
copy(window.location.href);
|
147
|
+
toggleNotification({
|
148
|
+
message: formatMessage({
|
149
|
+
id: "content-manager.preview.copy.success",
|
150
|
+
defaultMessage: "Copied preview link"
|
151
|
+
}),
|
152
|
+
type: "success"
|
153
|
+
});
|
154
|
+
};
|
155
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
156
|
+
designSystem.Grid.Root,
|
157
|
+
{
|
158
|
+
gap: 3,
|
159
|
+
gridCols: 3,
|
160
|
+
paddingLeft: 2,
|
161
|
+
paddingRight: 2,
|
162
|
+
background: "neutral0",
|
163
|
+
borderColor: "neutral150",
|
164
|
+
tag: "header",
|
165
|
+
children: [
|
166
|
+
/* @__PURE__ */ jsxRuntime.jsxs(designSystem.Grid.Item, { xs: 1, paddingTop: 2, paddingBottom: 2, gap: 3, children: [
|
167
|
+
/* @__PURE__ */ jsxRuntime.jsx(ClosePreviewButton, {}),
|
168
|
+
/* @__PURE__ */ jsxRuntime.jsx(PreviewTitle, { tag: "h1", fontWeight: 600, fontSize: 2, maxWidth: "200px", title: documentTitle, children: documentTitle }),
|
169
|
+
/* @__PURE__ */ jsxRuntime.jsx(Status, {})
|
170
|
+
] }),
|
171
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { xs: 1, marginBottom: "-1px", alignItems: "end", margin: "auto", children: /* @__PURE__ */ jsxRuntime.jsx(PreviewTabs, {}) }),
|
172
|
+
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Grid.Item, { xs: 1, justifyContent: "end", paddingTop: 2, paddingBottom: 2, children: /* @__PURE__ */ jsxRuntime.jsx(
|
173
|
+
designSystem.IconButton,
|
174
|
+
{
|
175
|
+
type: "button",
|
176
|
+
label: formatMessage({
|
177
|
+
id: "preview.copy.label",
|
178
|
+
defaultMessage: "Copy preview link"
|
179
|
+
}),
|
180
|
+
onClick: handleCopyLink,
|
181
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(Icons.Link, {})
|
182
|
+
}
|
183
|
+
) })
|
184
|
+
]
|
185
|
+
}
|
186
|
+
);
|
187
|
+
};
|
188
|
+
const PreviewTitle = styledComponents.styled(designSystem.Typography)`
|
189
|
+
overflow: hidden;
|
190
|
+
text-overflow: ellipsis;
|
191
|
+
white-space: nowrap;
|
192
|
+
`;
|
193
|
+
const StatusTab = styledComponents.styled(designSystem.Tabs.Trigger)`
|
194
|
+
text-transform: uppercase;
|
195
|
+
`;
|
196
|
+
const [PreviewProvider, usePreviewContext] = strapiAdmin.createContext("PreviewPage");
|
197
|
+
const PreviewPage = () => {
|
198
|
+
const { formatMessage } = reactIntl.useIntl();
|
199
|
+
const {
|
200
|
+
slug: model,
|
201
|
+
id: documentId,
|
202
|
+
collectionType
|
203
|
+
} = reactRouterDom.useParams();
|
204
|
+
const [{ query }] = strapiAdmin.useQueryParams();
|
205
|
+
const params = React__namespace.useMemo(() => index.buildValidParams(query), [query]);
|
206
|
+
if (!collectionType) {
|
207
|
+
throw new Error("Could not find collectionType in url params");
|
208
|
+
}
|
209
|
+
if (!model) {
|
210
|
+
throw new Error("Could not find model in url params");
|
211
|
+
}
|
212
|
+
if (collectionType === index.COLLECTION_TYPES && !documentId) {
|
213
|
+
throw new Error("Could not find documentId in url params");
|
214
|
+
}
|
215
|
+
const previewUrlResponse = index.useGetPreviewUrlQuery({
|
216
|
+
params: {
|
217
|
+
contentType: model
|
218
|
+
},
|
219
|
+
query: {
|
220
|
+
documentId,
|
221
|
+
locale: params.locale,
|
222
|
+
status: params.status
|
223
|
+
}
|
224
|
+
});
|
225
|
+
const documentResponse = index.useDocument({
|
226
|
+
model,
|
227
|
+
collectionType,
|
228
|
+
documentId,
|
229
|
+
params
|
230
|
+
});
|
231
|
+
const documentLayoutResponse = index.useDocumentLayout(model);
|
232
|
+
if (documentResponse.isLoading || previewUrlResponse.isLoading || documentLayoutResponse.isLoading) {
|
233
|
+
return /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Page.Loading, {});
|
234
|
+
}
|
235
|
+
if (previewUrlResponse.error || documentLayoutResponse.error || !documentResponse.document || !documentResponse.meta || !documentResponse.schema) {
|
236
|
+
return /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Page.Error, {});
|
237
|
+
}
|
238
|
+
if (!previewUrlResponse.data?.data?.url) {
|
239
|
+
return /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Page.NoData, {});
|
240
|
+
}
|
241
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
242
|
+
/* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Page.Title, { children: formatMessage(
|
243
|
+
{
|
244
|
+
id: "content-manager.preview.page-title",
|
245
|
+
defaultMessage: "{contentType} preview"
|
246
|
+
},
|
247
|
+
{
|
248
|
+
contentType: documentLayoutResponse.edit.settings.displayName
|
249
|
+
}
|
250
|
+
) }),
|
251
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
252
|
+
PreviewProvider,
|
253
|
+
{
|
254
|
+
url: previewUrlResponse.data.data.url,
|
255
|
+
mainField: documentLayoutResponse.edit.settings.mainField,
|
256
|
+
document: documentResponse.document,
|
257
|
+
meta: documentResponse.meta,
|
258
|
+
schema: documentResponse.schema,
|
259
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", height: "100%", alignItems: "stretch", children: [
|
260
|
+
/* @__PURE__ */ jsxRuntime.jsx(PreviewHeader, {}),
|
261
|
+
/* @__PURE__ */ jsxRuntime.jsx(PreviewContent, {})
|
262
|
+
] })
|
263
|
+
}
|
264
|
+
)
|
265
|
+
] });
|
266
|
+
};
|
267
|
+
const ProtectedPreviewPageImpl = () => {
|
268
|
+
const { slug: model } = reactRouterDom.useParams();
|
269
|
+
const {
|
270
|
+
permissions = [],
|
271
|
+
isLoading,
|
272
|
+
error
|
273
|
+
} = strapiAdmin.useRBAC([{ action: "plugin::content-manager.explorer.read", subject: model }]);
|
274
|
+
if (isLoading) {
|
275
|
+
return /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Page.Loading, {});
|
276
|
+
}
|
277
|
+
if (error || !model) {
|
278
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
279
|
+
designSystem.Box,
|
280
|
+
{
|
281
|
+
height: "100vh",
|
282
|
+
width: "100vw",
|
283
|
+
position: "fixed",
|
284
|
+
top: 0,
|
285
|
+
left: 0,
|
286
|
+
zIndex: 2,
|
287
|
+
background: "neutral0",
|
288
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Page.Error, {})
|
289
|
+
}
|
290
|
+
);
|
291
|
+
}
|
292
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
293
|
+
designSystem.Box,
|
294
|
+
{
|
295
|
+
height: "100vh",
|
296
|
+
width: "100vw",
|
297
|
+
position: "fixed",
|
298
|
+
top: 0,
|
299
|
+
left: 0,
|
300
|
+
zIndex: 2,
|
301
|
+
background: "neutral0",
|
302
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Page.Protect, { permissions, children: ({ permissions: permissions2 }) => /* @__PURE__ */ jsxRuntime.jsx(index.DocumentRBAC, { permissions: permissions2, children: /* @__PURE__ */ jsxRuntime.jsx(PreviewPage, {}) }) })
|
303
|
+
}
|
304
|
+
);
|
305
|
+
};
|
306
|
+
const ProtectedPreviewPage = () => {
|
307
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.FocusTrap, { children: /* @__PURE__ */ jsxRuntime.jsx(ProtectedPreviewPageImpl, {}) }) });
|
308
|
+
};
|
309
|
+
exports.ProtectedPreviewPage = ProtectedPreviewPage;
|
310
|
+
exports.usePreviewContext = usePreviewContext;
|
311
|
+
//# sourceMappingURL=Preview-DfNx8Ke-.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"Preview-DfNx8Ke-.js","sources":["../../admin/src/preview/components/PreviewContent.tsx","../../admin/src/preview/components/PreviewHeader.tsx","../../admin/src/preview/pages/Preview.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Box } from '@strapi/design-system';\nimport { useIntl } from 'react-intl';\n\nimport { usePreviewContext } from '../pages/Preview';\n\nconst PreviewContent = () => {\n const previewUrl = usePreviewContext('PreviewContent', (state) => state.url);\n\n const { formatMessage } = useIntl();\n\n return (\n <Box\n src={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 );\n};\n\nexport { PreviewContent };\n","import * as React from 'react';\n\nimport {\n useClipboard,\n useHistory,\n useNotification,\n useQueryParams,\n} from '@strapi/admin/strapi-admin';\nimport { IconButton, Tabs, Typography, Grid } from '@strapi/design-system';\nimport { Cross, Link as LinkIcon } from '@strapi/icons';\nimport { stringify } from 'qs';\nimport { useIntl } from 'react-intl';\nimport { Link, type To } from 'react-router-dom';\nimport { styled } from 'styled-components';\n\nimport { DocumentStatus } from '../../pages/EditView/components/DocumentStatus';\nimport { getDocumentStatus } from '../../pages/EditView/EditViewPage';\nimport { usePreviewContext } from '../pages/Preview';\n\n/* -------------------------------------------------------------------------------------------------\n * ClosePreviewButton\n * -----------------------------------------------------------------------------------------------*/\n\nconst ClosePreviewButton = () => {\n const [{ query }] = useQueryParams<{\n plugins?: Record<string, unknown>;\n }>();\n const { formatMessage } = useIntl();\n\n const canGoBack = useHistory('BackButton', (state) => state.canGoBack);\n const goBack = useHistory('BackButton', (state) => state.goBack);\n const history = useHistory('BackButton', (state) => state.history);\n const locationIndex = useHistory('BackButton', (state) => state.currentLocationIndex);\n\n /**\n * Get the link destination from the history.\n * Rely on a fallback (the parent edit view page) if there's no page to go back .\n */\n const historyTo = canGoBack ? history.at(locationIndex - 2) : undefined;\n const fallback = {\n pathname: '..',\n search: stringify(query, { encode: false }),\n } satisfies To;\n const toWithFallback = historyTo ?? fallback;\n\n const handleClick = (e: React.MouseEvent) => {\n if (canGoBack) {\n // Prevent normal link behavior, go back in the history stack instead\n e.preventDefault();\n goBack();\n return;\n }\n\n // Otherwise rely on native link behavior to go back to the edit view. We don't use navigate()\n // here in order to get the relative=\"path\" functionality from the Link component.\n };\n\n return (\n <IconButton\n tag={Link}\n relative=\"path\"\n to={toWithFallback}\n onClick={handleClick}\n label={formatMessage({\n id: 'content-manager.preview.header.close',\n defaultMessage: 'Close preview',\n })}\n >\n <Cross />\n </IconButton>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * Status\n * -----------------------------------------------------------------------------------------------*/\n\nconst Status = () => {\n // Get status\n const document = usePreviewContext('PreviewHeader', (state) => state.document);\n const schema = usePreviewContext('PreviewHeader', (state) => state.schema);\n const meta = usePreviewContext('PreviewHeader', (state) => state.meta);\n const hasDraftAndPublished = schema?.options?.draftAndPublish ?? false;\n\n if (!hasDraftAndPublished) {\n return null;\n }\n\n const status = getDocumentStatus(document, meta);\n\n return <DocumentStatus status={status} size=\"XS\" />;\n};\n\nconst PreviewTabs = () => {\n const { formatMessage } = useIntl();\n\n // URL query params\n const [{ query }, setQuery] = useQueryParams<{ status: 'draft' | 'published' }>();\n\n // Get status\n const document = usePreviewContext('PreviewHeader', (state) => state.document);\n const schema = usePreviewContext('PreviewHeader', (state) => state.schema);\n const meta = usePreviewContext('PreviewHeader', (state) => state.meta);\n const hasDraftAndPublish = schema?.options?.draftAndPublish ?? false;\n const documentStatus = getDocumentStatus(document, meta);\n\n const handleTabChange = (status: string) => {\n if (status === 'published' || status === 'draft') {\n setQuery({ status }, 'push', true);\n }\n };\n\n if (!hasDraftAndPublish) {\n return null;\n }\n\n return (\n <>\n <Tabs.Root variant=\"simple\" value={query.status || 'draft'} onValueChange={handleTabChange}>\n <Tabs.List\n aria-label={formatMessage({\n id: 'preview.tabs.label',\n defaultMessage: 'Document status',\n })}\n >\n <StatusTab value=\"draft\">\n {formatMessage({\n id: 'content-manager.containers.List.draft',\n defaultMessage: 'draft',\n })}\n </StatusTab>\n <StatusTab value=\"published\" disabled={documentStatus === 'draft'}>\n {formatMessage({\n id: 'content-manager.containers.List.published',\n defaultMessage: 'published',\n })}\n </StatusTab>\n </Tabs.List>\n </Tabs.Root>\n </>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * PreviewHeader\n * -----------------------------------------------------------------------------------------------*/\n\nconst PreviewHeader = () => {\n // Get main field\n const mainField = usePreviewContext('PreviewHeader', (state) => state.mainField);\n const document = usePreviewContext('PreviewHeader', (state) => state.document);\n const schema = usePreviewContext('PreviewHeader', (state) => state.schema);\n\n /**\n * We look to see what the mainField is from the configuration, if it's an id\n * we don't use it because it's a uuid format and not very user friendly.\n * Instead, we display the schema name for single-type documents\n * or \"Untitled\".\n */\n let documentTitle = 'Untitled';\n if (mainField !== 'id' && document?.[mainField]) {\n documentTitle = document[mainField];\n } else if (schema.kind === 'singleType' && schema?.info.displayName) {\n documentTitle = schema.info.displayName;\n }\n\n const { formatMessage } = useIntl();\n const { toggleNotification } = useNotification();\n const { copy } = useClipboard();\n\n const handleCopyLink = () => {\n copy(window.location.href);\n toggleNotification({\n message: formatMessage({\n id: 'content-manager.preview.copy.success',\n defaultMessage: 'Copied preview link',\n }),\n type: 'success',\n });\n };\n\n return (\n <Grid.Root\n gap={3}\n gridCols={3}\n paddingLeft={2}\n paddingRight={2}\n background=\"neutral0\"\n borderColor=\"neutral150\"\n tag=\"header\"\n >\n {/* Title and status */}\n <Grid.Item xs={1} paddingTop={2} paddingBottom={2} gap={3}>\n <ClosePreviewButton />\n <PreviewTitle tag=\"h1\" fontWeight={600} fontSize={2} maxWidth=\"200px\" title={documentTitle}>\n {documentTitle}\n </PreviewTitle>\n <Status />\n </Grid.Item>\n {/* Tabs */}\n <Grid.Item xs={1} marginBottom=\"-1px\" alignItems=\"end\" margin=\"auto\">\n <PreviewTabs />\n </Grid.Item>\n {/* Copy link */}\n <Grid.Item xs={1} justifyContent=\"end\" paddingTop={2} paddingBottom={2}>\n <IconButton\n type=\"button\"\n label={formatMessage({\n id: 'preview.copy.label',\n defaultMessage: 'Copy preview link',\n })}\n onClick={handleCopyLink}\n >\n <LinkIcon />\n </IconButton>\n </Grid.Item>\n </Grid.Root>\n );\n};\n\nconst PreviewTitle = styled(Typography)`\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n`;\n\nconst StatusTab = styled(Tabs.Trigger)`\n text-transform: uppercase;\n`;\n\nexport { PreviewHeader };\n","import * as React from 'react';\n\nimport { Page, useQueryParams, useRBAC, createContext } from '@strapi/admin/strapi-admin';\nimport { Box, Flex, FocusTrap, Portal } from '@strapi/design-system';\nimport { useIntl } from 'react-intl';\nimport { useParams } from 'react-router-dom';\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 { useDocumentLayout } from '../../hooks/useDocumentLayout';\nimport { buildValidParams } from '../../utils/api';\nimport { PreviewContent } from '../components/PreviewContent';\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 mainField: string;\n document: NonNullable<ReturnType<UseDocument>['document']>;\n meta: NonNullable<ReturnType<UseDocument>['meta']>;\n schema: NonNullable<ReturnType<UseDocument>['schema']>;\n}\n\nconst [PreviewProvider, usePreviewContext] = createContext<PreviewContextValue>('PreviewPage');\n\n/* -------------------------------------------------------------------------------------------------\n * PreviewPage\n * -----------------------------------------------------------------------------------------------*/\n\nconst PreviewPage = () => {\n const { formatMessage } = useIntl();\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 }>();\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\n const documentResponse = useDocument({\n model,\n collectionType,\n documentId,\n params,\n });\n\n const documentLayoutResponse = useDocumentLayout(model);\n\n if (\n documentResponse.isLoading ||\n previewUrlResponse.isLoading ||\n documentLayoutResponse.isLoading\n ) {\n return <Page.Loading />;\n }\n\n if (\n previewUrlResponse.error ||\n documentLayoutResponse.error ||\n !documentResponse.document ||\n !documentResponse.meta ||\n !documentResponse.schema\n ) {\n return <Page.Error />;\n }\n\n if (!previewUrlResponse.data?.data?.url) {\n return <Page.NoData />;\n }\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: documentLayoutResponse.edit.settings.displayName,\n }\n )}\n </Page.Title>\n <PreviewProvider\n url={previewUrlResponse.data.data.url}\n mainField={documentLayoutResponse.edit.settings.mainField}\n document={documentResponse.document}\n meta={documentResponse.meta}\n schema={documentResponse.schema}\n >\n <Flex direction=\"column\" height=\"100%\" alignItems={'stretch'}>\n <PreviewHeader />\n <PreviewContent />\n </Flex>\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([{ action: 'plugin::content-manager.explorer.read', subject: model }]);\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 permissions={permissions}>\n {({ permissions }) => (\n <DocumentRBAC permissions={permissions}>\n <PreviewPage />\n </DocumentRBAC>\n )}\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":["useIntl","jsx","Box","useQueryParams","useHistory","stringify","IconButton","Link","Cross","getDocumentStatus","DocumentStatus","Fragment","Tabs","jsxs","useNotification","useClipboard","Grid","LinkIcon","styled","Typography","createContext","useParams","React","buildValidParams","COLLECTION_TYPES","useGetPreviewUrlQuery","useDocument","useDocumentLayout","Page","Flex","useRBAC","permissions","DocumentRBAC","Portal","FocusTrap"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,MAAM,iBAAiB,MAAM;AAC3B,QAAM,aAAa,kBAAkB,kBAAkB,CAAC,UAAU,MAAM,GAAG;AAErE,QAAA,EAAE,cAAc,IAAIA,kBAAQ;AAGhC,SAAAC,2BAAA;AAAA,IAACC,aAAA;AAAA,IAAA;AAAA,MACC,KAAK;AAAA,MACL,OAAO,cAAc;AAAA,QACnB,IAAI;AAAA,QACJ,gBAAgB;AAAA,MAAA,CACjB;AAAA,MACD,OAAM;AAAA,MACN,QAAO;AAAA,MACP,aAAa;AAAA,MACb,KAAI;AAAA,IAAA;AAAA,EACN;AAEJ;ACFA,MAAM,qBAAqB,MAAM;AAC/B,QAAM,CAAC,EAAE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,EAAyB,GAC5B,EACF,CAAA;AAEJ;;;"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { jsxs, jsx } from "react/jsx-runtime";
|
2
2
|
import * as React from "react";
|
3
|
-
import { createContext, useQueryParams, useField, useNotification, useFocusInputField
|
3
|
+
import { createContext, useQueryParams, useForm, useField, useNotification, useFocusInputField } from "@strapi/admin/strapi-admin";
|
4
4
|
import { Flex, TextButton, Field, Combobox, ComboboxOption, Typography, VisuallyHidden, Box, useComposedRefs, IconButton, Tooltip, Link } from "@strapi/design-system";
|
5
5
|
import { ArrowClockwise, Drag, Cross } from "@strapi/icons";
|
6
6
|
import { generateNKeysBetween } from "fractional-indexing";
|
@@ -10,15 +10,40 @@ import { useIntl } from "react-intl";
|
|
10
10
|
import { NavLink } from "react-router-dom";
|
11
11
|
import { FixedSizeList } from "react-window";
|
12
12
|
import { styled } from "styled-components";
|
13
|
-
import { c as useDoc, d as buildValidParams, C as COLLECTION_TYPES, g as getTranslation, D as DocumentStatus } from "./index-
|
14
|
-
import { u as useDragAndDrop, I as ItemTypes, D as DROP_SENSITIVITY } from "./useDragAndDrop-
|
15
|
-
import { u as useGetRelationsQuery, g as getRelationLabel, a as useLazySearchRelationsQuery } from "./relations-
|
13
|
+
import { c as useDoc, d as buildValidParams, C as COLLECTION_TYPES, g as getTranslation, D as DocumentStatus } from "./index-DVAIIsOs.mjs";
|
14
|
+
import { u as useDragAndDrop, I as ItemTypes, D as DROP_SENSITIVITY } from "./useDragAndDrop-DJ6jqvZN.mjs";
|
15
|
+
import { u as useGetRelationsQuery, g as getRelationLabel, a as useLazySearchRelationsQuery } from "./relations-o3pPhzY4.mjs";
|
16
16
|
const [ComponentProvider, useComponent] = createContext("ComponentContext", {
|
17
17
|
id: void 0,
|
18
18
|
level: -1,
|
19
19
|
uid: void 0,
|
20
20
|
type: void 0
|
21
21
|
});
|
22
|
+
function useHandleDisconnect(fieldName, consumerName) {
|
23
|
+
const field = useField(fieldName);
|
24
|
+
const removeFieldRow = useForm(consumerName, (state) => state.removeFieldRow);
|
25
|
+
const addFieldRow = useForm(consumerName, (state) => state.addFieldRow);
|
26
|
+
const handleDisconnect = (relation) => {
|
27
|
+
if (field.value && field.value.connect) {
|
28
|
+
const indexOfRelationInConnectArray = field.value.connect.findIndex(
|
29
|
+
(rel) => rel.id === relation.id
|
30
|
+
);
|
31
|
+
if (indexOfRelationInConnectArray >= 0) {
|
32
|
+
removeFieldRow(`${fieldName}.connect`, indexOfRelationInConnectArray);
|
33
|
+
return;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
addFieldRow(`${fieldName}.disconnect`, {
|
37
|
+
id: relation.id,
|
38
|
+
apiData: {
|
39
|
+
id: relation.id,
|
40
|
+
documentId: relation.documentId,
|
41
|
+
locale: relation.locale
|
42
|
+
}
|
43
|
+
});
|
44
|
+
};
|
45
|
+
return handleDisconnect;
|
46
|
+
}
|
22
47
|
const RELATIONS_TO_DISPLAY = 5;
|
23
48
|
const ONE_WAY_RELATIONS = ["oneWay", "oneToOne", "manyToOne", "oneToManyMorph", "oneToOneMorph"];
|
24
49
|
const RelationsField = React.forwardRef(
|
@@ -31,9 +56,16 @@ const RelationsField = React.forwardRef(
|
|
31
56
|
const params = buildValidParams(query);
|
32
57
|
const isMorph = props.attribute.relation.toLowerCase().includes("morph");
|
33
58
|
const isDisabled = isMorph || disabled;
|
34
|
-
const {
|
59
|
+
const { componentId, componentUID } = useComponent("RelationsField", ({ uid, id: id2 }) => ({
|
60
|
+
componentId: id2,
|
61
|
+
componentUID: uid
|
62
|
+
}));
|
63
|
+
const isSubmitting = useForm("RelationsList", (state) => state.isSubmitting);
|
64
|
+
React.useEffect(() => {
|
65
|
+
setCurrentPage(1);
|
66
|
+
}, [isSubmitting]);
|
35
67
|
const id = componentId ? componentId.toString() : documentId;
|
36
|
-
const model =
|
68
|
+
const model = componentUID ?? documentModel;
|
37
69
|
const [targetField] = props.name.split(".").slice(-1);
|
38
70
|
const { data, isLoading, isFetching } = useGetRelationsQuery(
|
39
71
|
{
|
@@ -86,10 +118,8 @@ const RelationsField = React.forwardRef(
|
|
86
118
|
);
|
87
119
|
const transformedRels = transformations([...data.results]);
|
88
120
|
return [...transformedRels, ...field.value?.connect ?? []].sort((a, b) => {
|
89
|
-
if (a.__temp_key__ < b.__temp_key__)
|
90
|
-
|
91
|
-
if (a.__temp_key__ > b.__temp_key__)
|
92
|
-
return 1;
|
121
|
+
if (a.__temp_key__ < b.__temp_key__) return -1;
|
122
|
+
if (a.__temp_key__ > b.__temp_key__) return 1;
|
93
123
|
return 0;
|
94
124
|
});
|
95
125
|
}, [
|
@@ -99,10 +129,16 @@ const RelationsField = React.forwardRef(
|
|
99
129
|
props.attribute.targetModel,
|
100
130
|
props.mainField
|
101
131
|
]);
|
132
|
+
const handleDisconnect = useHandleDisconnect(props.name, "RelationsField");
|
102
133
|
const handleConnect = (relation) => {
|
103
134
|
const [lastItemInList] = relations.slice(-1);
|
104
135
|
const item = {
|
105
136
|
id: relation.id,
|
137
|
+
apiData: {
|
138
|
+
id: relation.id,
|
139
|
+
documentId: relation.documentId,
|
140
|
+
locale: relation.locale
|
141
|
+
},
|
106
142
|
status: relation.status,
|
107
143
|
/**
|
108
144
|
* If there's a last item, that's the first key we use to generate out next one.
|
@@ -112,9 +148,11 @@ const RelationsField = React.forwardRef(
|
|
112
148
|
[props.mainField?.name ?? "documentId"]: relation[props.mainField?.name ?? "documentId"],
|
113
149
|
label: getRelationLabel(relation, props.mainField),
|
114
150
|
// @ts-expect-error – targetModel does exist on the attribute, but it's not typed.
|
115
|
-
href: `../${COLLECTION_TYPES}/${props.attribute.targetModel}/${relation.documentId}`
|
151
|
+
href: `../${COLLECTION_TYPES}/${props.attribute.targetModel}/${relation.documentId}?${relation.locale ? `plugins[i18n][locale]=${relation.locale}` : ""}`
|
116
152
|
};
|
117
153
|
if (ONE_WAY_RELATIONS.includes(props.attribute.relation)) {
|
154
|
+
field.value?.connect?.forEach(handleDisconnect);
|
155
|
+
relations.forEach(handleDisconnect);
|
118
156
|
field.onChange(`${props.name}.connect`, [item]);
|
119
157
|
} else {
|
120
158
|
field.onChange(`${props.name}.connect`, [...field.value?.connect ?? [], item]);
|
@@ -135,7 +173,7 @@ const RelationsField = React.forwardRef(
|
|
135
173
|
RelationsInput,
|
136
174
|
{
|
137
175
|
disabled: isDisabled,
|
138
|
-
id,
|
176
|
+
id: componentUID ? componentId ? `${componentId}` : "" : documentId,
|
139
177
|
label: `${label} ${relationsCount > 0 ? `(${relationsCount})` : ""}`,
|
140
178
|
model,
|
141
179
|
onChange: handleConnect,
|
@@ -194,7 +232,7 @@ const addLabelAndHref = ({ mainField, href }) => (relations) => relations.map((r
|
|
194
232
|
// Fallback to `id` if there is no `mainField` value, which will overwrite the above `documentId` property with the exact same data.
|
195
233
|
[mainField?.name ?? "documentId"]: relation[mainField?.name ?? "documentId"],
|
196
234
|
label: getRelationLabel(relation, mainField),
|
197
|
-
href: `${href}/${relation.documentId}`
|
235
|
+
href: `${href}/${relation.documentId}?${relation.locale ? `plugins[i18n][locale]=${relation.locale}` : ""}`
|
198
236
|
};
|
199
237
|
});
|
200
238
|
const RelationsInput = ({
|
@@ -289,7 +327,7 @@ const RelationsInput = ({
|
|
289
327
|
{
|
290
328
|
ref: fieldRef,
|
291
329
|
name,
|
292
|
-
autocomplete: "
|
330
|
+
autocomplete: "list",
|
293
331
|
placeholder: placeholder || formatMessage({
|
294
332
|
id: getTranslation("relation.add"),
|
295
333
|
defaultMessage: "Add relation"
|
@@ -347,8 +385,6 @@ const RelationsList = ({
|
|
347
385
|
const [overflow, setOverflow] = React.useState();
|
348
386
|
const [liveText, setLiveText] = React.useState("");
|
349
387
|
const field = useField(name);
|
350
|
-
const removeFieldRow = useForm("RelationsList", (state) => state.removeFieldRow);
|
351
|
-
const addFieldRow = useForm("RelationsList", (state) => state.addFieldRow);
|
352
388
|
React.useEffect(() => {
|
353
389
|
if (data.length <= RELATIONS_TO_DISPLAY) {
|
354
390
|
return setOverflow(void 0);
|
@@ -398,17 +434,25 @@ const RelationsList = ({
|
|
398
434
|
newData.splice(oldIndex, 1);
|
399
435
|
newData.splice(newIndex, 0, { ...currentRow, __temp_key__: newKey });
|
400
436
|
const connectedRelations = newData.reduce((acc, relation, currentIndex, array) => {
|
401
|
-
const relationOnServer = serverData.find(
|
402
|
-
(oldRelation) => oldRelation.documentId === relation.documentId
|
403
|
-
);
|
437
|
+
const relationOnServer = serverData.find((oldRelation) => oldRelation.id === relation.id);
|
404
438
|
const relationInFront = array[currentIndex + 1];
|
405
439
|
if (!relationOnServer || relationOnServer.__temp_key__ !== relation.__temp_key__) {
|
406
440
|
const position = relationInFront ? {
|
407
441
|
before: relationInFront.documentId,
|
408
442
|
locale: relationInFront.locale,
|
409
|
-
status: relationInFront.
|
443
|
+
status: "publishedAt" in relationInFront && relationInFront.publishedAt ? "published" : "draft"
|
410
444
|
} : { end: true };
|
411
|
-
const relationWithPosition = {
|
445
|
+
const relationWithPosition = {
|
446
|
+
...relation,
|
447
|
+
...{
|
448
|
+
apiData: {
|
449
|
+
id: relation.id,
|
450
|
+
documentId: relation.documentId,
|
451
|
+
locale: relation.locale,
|
452
|
+
position
|
453
|
+
}
|
454
|
+
}
|
455
|
+
};
|
412
456
|
return [...acc, relationWithPosition];
|
413
457
|
}
|
414
458
|
return acc;
|
@@ -459,18 +503,7 @@ const RelationsList = ({
|
|
459
503
|
)
|
460
504
|
);
|
461
505
|
};
|
462
|
-
const handleDisconnect = (
|
463
|
-
if (field.value && field.value.connect) {
|
464
|
-
const indexOfRelationInConnectArray = field.value.connect.findIndex(
|
465
|
-
(rel) => rel.id === relation.id
|
466
|
-
);
|
467
|
-
if (indexOfRelationInConnectArray >= 0) {
|
468
|
-
removeFieldRow(`${name}.connect`, indexOfRelationInConnectArray);
|
469
|
-
return;
|
470
|
-
}
|
471
|
-
}
|
472
|
-
addFieldRow(`${name}.disconnect`, { id: relation.id });
|
473
|
-
};
|
506
|
+
const handleDisconnect = useHandleDisconnect(name, "RelationsList");
|
474
507
|
const canReorder = !ONE_WAY_RELATIONS.includes(relationType);
|
475
508
|
const dynamicListHeight = data.length > RELATIONS_TO_DISPLAY ? Math.min(data.length, RELATIONS_TO_DISPLAY) * (RELATION_ITEM_HEIGHT + RELATION_GUTTER) + RELATION_ITEM_HEIGHT / 2 : Math.min(data.length, RELATIONS_TO_DISPLAY) * (RELATION_ITEM_HEIGHT + RELATION_GUTTER);
|
476
509
|
return /* @__PURE__ */ jsxs(ShadowBox, { $overflowDirection: overflow, children: [
|
@@ -551,7 +584,7 @@ const ListItem = ({ data, index, style }) => {
|
|
551
584
|
relations
|
552
585
|
} = data;
|
553
586
|
const { formatMessage } = useIntl();
|
554
|
-
const { href,
|
587
|
+
const { href, id, label, status } = relations[index];
|
555
588
|
const [{ handlerId, isDragging, handleKeyDown }, relationRef, dropRef, dragRef, dragPreviewRef] = useDragAndDrop(
|
556
589
|
canDrag && !disabled,
|
557
590
|
{
|
@@ -560,7 +593,7 @@ const ListItem = ({ data, index, style }) => {
|
|
560
593
|
item: {
|
561
594
|
displayedValue: label,
|
562
595
|
status,
|
563
|
-
id
|
596
|
+
id,
|
564
597
|
index
|
565
598
|
},
|
566
599
|
onMoveItem: handleMoveItem,
|
@@ -620,16 +653,17 @@ const ListItem = ({ data, index, style }) => {
|
|
620
653
|
] })
|
621
654
|
] }),
|
622
655
|
/* @__PURE__ */ jsx(Box, { paddingLeft: 4, children: /* @__PURE__ */ jsx(
|
623
|
-
|
656
|
+
IconButton,
|
624
657
|
{
|
625
|
-
disabled,
|
626
|
-
type: "button",
|
627
658
|
onClick: () => handleDisconnect(relations[index]),
|
628
|
-
|
659
|
+
disabled,
|
660
|
+
label: formatMessage({
|
629
661
|
id: getTranslation("relation.disconnect"),
|
630
662
|
defaultMessage: "Remove"
|
631
663
|
}),
|
632
|
-
|
664
|
+
variant: "ghost",
|
665
|
+
size: "S",
|
666
|
+
children: /* @__PURE__ */ jsx(Cross, {})
|
633
667
|
}
|
634
668
|
) })
|
635
669
|
]
|
@@ -691,4 +725,4 @@ export {
|
|
691
725
|
MemoizedRelationsField as M,
|
692
726
|
useComponent as u
|
693
727
|
};
|
694
|
-
//# sourceMappingURL=Relations-
|
728
|
+
//# sourceMappingURL=Relations-DM2yUTST.mjs.map
|