@mattisvensson/strapi-plugin-webatlas 0.12.1 → 0.12.2
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/README.md +13 -1
- package/dist/admin/{RoutePicker-IRZiHKFi.mjs → RoutePicker-C6LpgVMi.mjs} +1 -1
- package/dist/admin/{RoutePicker-C3_tzz9U.js → RoutePicker-DvzQH2CX.js} +1 -1
- package/dist/admin/{SettingTitle-0mKlA80i.mjs → SettingTitle-C1_2epDJ.mjs} +1 -1
- package/dist/admin/{SettingTitle-Ib_0AvoZ.js → SettingTitle-DXGCUfum.js} +1 -1
- package/dist/admin/{WarningBox-BZ3BZ5fR.js → WarningBox-BHlYlKQ8.js} +1 -1
- package/dist/admin/{WarningBox-CXEmXfVx.mjs → WarningBox-CfIVF0O-.mjs} +1 -1
- package/dist/admin/{de-DhwCZE_m.js → de-BWUGdpM0.js} +1 -0
- package/dist/admin/{de-BFjenpyN.mjs → de-Dnk_hvMW.mjs} +1 -0
- package/dist/admin/{en-CGCh9ld_.mjs → en-D5EqZSGy.mjs} +1 -0
- package/dist/admin/{en-C-rPCNd2.js → en-DOk8P6X5.js} +1 -0
- package/dist/admin/{index-ByxM39aL.mjs → index-CVrufPeL.mjs} +46 -13
- package/dist/admin/{index-88JTX1Mj.js → index-D7zg69uM.js} +3 -3
- package/dist/admin/{index-BY6JLZrD.mjs → index-DC-2-FsX.mjs} +2 -2
- package/dist/admin/{index-CsKnBzp6.js → index-DHNPW0YT.js} +46 -13
- package/dist/admin/{index-DNBXz42q.js → index-Dp_eCRFS.js} +1 -1
- package/dist/admin/{index-Bym1mXg1.mjs → index-DuSnxRbO.mjs} +3 -3
- package/dist/admin/{index-CNCyng5O.mjs → index-Dx4gvFWK.mjs} +2 -2
- package/dist/admin/{index-CEJBltoJ.js → index-FuvoHpAT.js} +2 -2
- package/dist/admin/{index-BPUJTNed.js → index-RmZ3LQPu.js} +2 -2
- package/dist/admin/{index-PD3gcnXA.mjs → index-Y4uwBSjP.mjs} +1 -1
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/server/index.js +130 -46
- package/dist/server/index.mjs +130 -46
- package/dist/server/src/index.d.ts +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -114,6 +114,18 @@ The RoutePicker custom field allows you to select a route from the existing rout
|
|
|
114
114
|
|
|
115
115
|
Webatlas provides two API endpoints. One to fetch routes and one to fetch navigations.
|
|
116
116
|
|
|
117
|
+
#### Permissions
|
|
118
|
+
|
|
119
|
+
The endpoints are protected like any other Strapi API endpoint. Grant the following permissions either to a role in **Settings → Users & Permissions plugin → Roles** (e.g. `Public`) or to an API token in **Settings → API Tokens**:
|
|
120
|
+
|
|
121
|
+
- Under **Webatlas**, enable `getEntityByPath` and/or `getNavigation`.
|
|
122
|
+
- Enable `findOne` (collection types) or `find` (single types) for every content type with webatlas enabled whose entries should be fetchable via `/api/webatlas/path`. Without this permission, the endpoint responds with `404`.
|
|
123
|
+
- Enable `find` for every content type that is referenced through a relation and should be included when using `populate`. Relations to content types without `find` permission are removed from the response, private fields are never returned.
|
|
124
|
+
|
|
125
|
+
Only enable `find` and `findOne` for content types whose entries are meant to be public, since they also expose the regular `/api/<content-type>` endpoints. Like with the Strapi REST API, anyone who can read a content type can also fetch its drafts by passing `status=draft`.
|
|
126
|
+
|
|
127
|
+
To keep your content types private, leave the `Public` role untouched and grant the permissions to an API token instead. Make sure to allow the `getEntityByPath` and `getNavigation` permissions for the API token.
|
|
128
|
+
|
|
117
129
|
#### Fetch route
|
|
118
130
|
|
|
119
131
|
`GET /api/webatlas/path`
|
|
@@ -122,7 +134,7 @@ Query parameters:
|
|
|
122
134
|
|
|
123
135
|
- `slug` (string, required): The slug/path to fetch the route for. This can either be the generated path from webatlas, the uId path or the canonical path.
|
|
124
136
|
- `populate` (string, optional): Comma-separated list of relations to populate. Use `deep` to populate all relations in any depth.
|
|
125
|
-
- `populateDeepDepth` (string, optional): Depth for deep population
|
|
137
|
+
- `populateDeepDepth` (string, optional): Depth for deep population, between `1` and `10`. Default is `5`.
|
|
126
138
|
- `fields` (string, optional): Comma-separated list of fields to include in the response.
|
|
127
139
|
- `status` (string, optional): `draft` or `published`. Default is `published`. Returns the draft or published version of the entity.
|
|
128
140
|
- `breadcrumb` (string, optional): Pass `false` to omit the breadcrumb from the response. Enabled by default.
|
|
@@ -2,7 +2,7 @@ import { jsxs, jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { forwardRef, useState, useEffect } from "react";
|
|
3
3
|
import { Field, Combobox, ComboboxOption, Box } from "@strapi/design-system";
|
|
4
4
|
import { ExternalLink, Link } from "@strapi/icons";
|
|
5
|
-
import { u as useApi } from "./index-
|
|
5
|
+
import { u as useApi } from "./index-CVrufPeL.mjs";
|
|
6
6
|
import "@strapi/strapi/admin";
|
|
7
7
|
const Input = forwardRef((props, ref) => {
|
|
8
8
|
const { attribute, disabled, placeholder, label, name, onChange, required, value, hint } = props;
|
|
@@ -4,7 +4,7 @@ const jsxRuntime = require("react/jsx-runtime");
|
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const designSystem = require("@strapi/design-system");
|
|
6
6
|
const icons = require("@strapi/icons");
|
|
7
|
-
const index = require("./index-
|
|
7
|
+
const index = require("./index-DHNPW0YT.js");
|
|
8
8
|
require("@strapi/strapi/admin");
|
|
9
9
|
const Input = React.forwardRef((props, ref) => {
|
|
10
10
|
const { attribute, disabled, placeholder, label, name, onChange, required, value, hint } = props;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Button, Flex, Typography, Box } from "@strapi/design-system";
|
|
3
3
|
import { Page, Layouts } from "@strapi/strapi/admin";
|
|
4
|
-
import { f as PLUGIN_NAME, g as getTranslation } from "./index-
|
|
4
|
+
import { f as PLUGIN_NAME, g as getTranslation } from "./index-CVrufPeL.mjs";
|
|
5
5
|
import { useIntl } from "react-intl";
|
|
6
6
|
import { Check } from "@strapi/icons";
|
|
7
7
|
function PageWrapper({
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
const jsxRuntime = require("react/jsx-runtime");
|
|
3
3
|
const designSystem = require("@strapi/design-system");
|
|
4
4
|
const admin = require("@strapi/strapi/admin");
|
|
5
|
-
const index = require("./index-
|
|
5
|
+
const index = require("./index-DHNPW0YT.js");
|
|
6
6
|
const reactIntl = require("react-intl");
|
|
7
7
|
const icons = require("@strapi/icons");
|
|
8
8
|
function PageWrapper({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const React = require("react");
|
|
3
|
-
const index = require("./index-
|
|
3
|
+
const index = require("./index-DHNPW0YT.js");
|
|
4
4
|
const jsxRuntime = require("react/jsx-runtime");
|
|
5
5
|
const designSystem = require("@strapi/design-system");
|
|
6
6
|
const icons = require("@strapi/icons");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState, useEffect } from "react";
|
|
2
|
-
import { u as useApi, i as isAbortError } from "./index-
|
|
2
|
+
import { u as useApi, i as isAbortError } from "./index-CVrufPeL.mjs";
|
|
3
3
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
4
|
import { Badge, Flex, Typography } from "@strapi/design-system";
|
|
5
5
|
import { WarningCircle } from "@strapi/icons";
|
|
@@ -96,6 +96,7 @@ const de = {
|
|
|
96
96
|
"webatlas.components.CMEditViewAside.path.overrideCheckbox": "Automatische Pfad-Generierung überschreiben",
|
|
97
97
|
"webatlas.components.CMEditViewAside.path.uidPath.hint": "Permanenter UID-Pfad, kann nicht geändert werden",
|
|
98
98
|
"webatlas.components.CMEditViewAside.path.newPathInfo": "Ein neuer Pfad wird beim Speichern dieses Eintrags erstellt.",
|
|
99
|
+
"webatlas.components.CMEditViewAside.path.noPathInfo": 'Es wird kein Pfad erstellt, solange das Feld "{field}" leer ist. Füllen Sie es aus oder verwenden Sie die Überschreibungsoption, um einen benutzerdefinierten Pfad festzulegen.',
|
|
99
100
|
"webatlas.components.CMEditViewAside.path.input.noSourceField": "Verwenden Sie die Überschreibungsoption, um einen benutzerdefinierten Pfad festzulegen.",
|
|
100
101
|
"webatlas.components.CMEditViewAside.path.input.parentSelect.label": "Platzieren unter",
|
|
101
102
|
"webatlas.components.CMEditViewAside.path.input.parentSelect.rootPath": "Keine (Stammverzeichnis)",
|
|
@@ -94,6 +94,7 @@ const de = {
|
|
|
94
94
|
"webatlas.components.CMEditViewAside.path.overrideCheckbox": "Automatische Pfad-Generierung überschreiben",
|
|
95
95
|
"webatlas.components.CMEditViewAside.path.uidPath.hint": "Permanenter UID-Pfad, kann nicht geändert werden",
|
|
96
96
|
"webatlas.components.CMEditViewAside.path.newPathInfo": "Ein neuer Pfad wird beim Speichern dieses Eintrags erstellt.",
|
|
97
|
+
"webatlas.components.CMEditViewAside.path.noPathInfo": 'Es wird kein Pfad erstellt, solange das Feld "{field}" leer ist. Füllen Sie es aus oder verwenden Sie die Überschreibungsoption, um einen benutzerdefinierten Pfad festzulegen.',
|
|
97
98
|
"webatlas.components.CMEditViewAside.path.input.noSourceField": "Verwenden Sie die Überschreibungsoption, um einen benutzerdefinierten Pfad festzulegen.",
|
|
98
99
|
"webatlas.components.CMEditViewAside.path.input.parentSelect.label": "Platzieren unter",
|
|
99
100
|
"webatlas.components.CMEditViewAside.path.input.parentSelect.rootPath": "Keine (Stammverzeichnis)",
|
|
@@ -94,6 +94,7 @@ const en = {
|
|
|
94
94
|
"webatlas.components.CMEditViewAside.path.overrideCheckbox": "Override automatic path generation",
|
|
95
95
|
"webatlas.components.CMEditViewAside.path.uidPath.hint": "Permanent UID path, cannot be changed",
|
|
96
96
|
"webatlas.components.CMEditViewAside.path.newPathInfo": "A new path will be created upon saving this entry.",
|
|
97
|
+
"webatlas.components.CMEditViewAside.path.noPathInfo": 'No path will be created while the "{field}" field is empty. Fill it in or use the override option to set a custom path.',
|
|
97
98
|
"webatlas.components.CMEditViewAside.path.input.noSourceField": "Use the override option to set a custom Path.",
|
|
98
99
|
"webatlas.components.CMEditViewAside.path.input.parentSelect.label": "Place under",
|
|
99
100
|
"webatlas.components.CMEditViewAside.path.input.parentSelect.rootPath": "None (root path)",
|
|
@@ -96,6 +96,7 @@ const en = {
|
|
|
96
96
|
"webatlas.components.CMEditViewAside.path.overrideCheckbox": "Override automatic path generation",
|
|
97
97
|
"webatlas.components.CMEditViewAside.path.uidPath.hint": "Permanent UID path, cannot be changed",
|
|
98
98
|
"webatlas.components.CMEditViewAside.path.newPathInfo": "A new path will be created upon saving this entry.",
|
|
99
|
+
"webatlas.components.CMEditViewAside.path.noPathInfo": 'No path will be created while the "{field}" field is empty. Fill it in or use the override option to set a custom path.',
|
|
99
100
|
"webatlas.components.CMEditViewAside.path.input.noSourceField": "Use the override option to set a custom Path.",
|
|
100
101
|
"webatlas.components.CMEditViewAside.path.input.parentSelect.label": "Place under",
|
|
101
102
|
"webatlas.components.CMEditViewAside.path.input.parentSelect.rootPath": "None (root path)",
|
|
@@ -332,8 +332,19 @@ function OverrideCheckbox({ isOverride, setIsOverride, disabledCondition }) {
|
|
|
332
332
|
}
|
|
333
333
|
) });
|
|
334
334
|
}
|
|
335
|
-
function NewPathInfo(
|
|
335
|
+
function NewPathInfo({
|
|
336
|
+
hasSlug,
|
|
337
|
+
routeSourceField
|
|
338
|
+
}) {
|
|
336
339
|
const { formatMessage } = useIntl();
|
|
340
|
+
if (!hasSlug)
|
|
341
|
+
return /* @__PURE__ */ jsx(Typography, { textColor: "danger600", children: formatMessage(
|
|
342
|
+
{
|
|
343
|
+
id: getTranslation("components.CMEditViewAside.path.noPathInfo"),
|
|
344
|
+
defaultMessage: 'No path will be created while the "{field}" field is empty. Fill it in or use the override option to set a custom path.'
|
|
345
|
+
},
|
|
346
|
+
{ field: routeSourceField }
|
|
347
|
+
) });
|
|
337
348
|
return /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: formatMessage({
|
|
338
349
|
id: getTranslation("components.CMEditViewAside.path.newPathInfo"),
|
|
339
350
|
defaultMessage: "A new path will be created upon saving this entry."
|
|
@@ -3827,8 +3838,8 @@ function reducer(state, action) {
|
|
|
3827
3838
|
}
|
|
3828
3839
|
}
|
|
3829
3840
|
const Panel = ({ config }) => {
|
|
3830
|
-
const { form, model } = unstable_useContentManagerContext();
|
|
3831
|
-
const { initialValues, values, onChange } = form;
|
|
3841
|
+
const { form, model, contentType } = unstable_useContentManagerContext();
|
|
3842
|
+
const { initialValues, values, onChange, isSubmitting } = form;
|
|
3832
3843
|
const { getRelatedRoute, getAllRoutes, getProhibitedRouteIds } = useApi();
|
|
3833
3844
|
const { formatMessage } = useIntl();
|
|
3834
3845
|
const { get } = useFetchClient();
|
|
@@ -3866,6 +3877,8 @@ const Panel = ({ config }) => {
|
|
|
3866
3877
|
slug: "",
|
|
3867
3878
|
overridePath: ""
|
|
3868
3879
|
});
|
|
3880
|
+
const [routeRefreshKey, setRouteRefreshKey] = useState(0);
|
|
3881
|
+
const wasSubmitting = useRef(false);
|
|
3869
3882
|
const hasUserChangedField = useRef(false);
|
|
3870
3883
|
const hasUserInteracted = useRef(false);
|
|
3871
3884
|
const initialRouteData = useRef(null);
|
|
@@ -3873,6 +3886,7 @@ const Panel = ({ config }) => {
|
|
|
3873
3886
|
const routeSourceField = config?.routeSourceField;
|
|
3874
3887
|
const sourceFieldValue = routeSourceField ? values[routeSourceField] || "" : "";
|
|
3875
3888
|
const initialSourceFieldValue = routeSourceField ? initialValues[routeSourceField] || "" : "";
|
|
3889
|
+
const isSourceFieldRequired = !!(routeSourceField && contentType?.attributes?.[routeSourceField]?.required);
|
|
3876
3890
|
const latestCheckPathRef = useRef(checkPath);
|
|
3877
3891
|
latestCheckPathRef.current = checkPath;
|
|
3878
3892
|
const debouncedCheckPath = useRef(
|
|
@@ -3899,7 +3913,7 @@ const Panel = ({ config }) => {
|
|
|
3899
3913
|
parentDocumentId: selectedParent?.documentId || null,
|
|
3900
3914
|
slug: isOverride ? overridePath : slug
|
|
3901
3915
|
};
|
|
3902
|
-
if (initialRouteData.current?.isOverride === isOverride && data.path === initialRouteData.current?.path && data.parentDocumentId === (initialRouteData.current?.parent?.documentId ?? null)) {
|
|
3916
|
+
if (initialRouteData.current?.isOverride === isOverride && data.path === initialRouteData.current?.path && data.parentDocumentId === (initialRouteData.current?.parent?.documentId ?? null) && sourceFieldValue.trim() === (initialRouteData.current?.title ?? "")) {
|
|
3903
3917
|
onChange("webatlas", void 0);
|
|
3904
3918
|
return;
|
|
3905
3919
|
}
|
|
@@ -3921,7 +3935,11 @@ const Panel = ({ config }) => {
|
|
|
3921
3935
|
hasUserChangedField.current = true;
|
|
3922
3936
|
}
|
|
3923
3937
|
if (!sourceFieldValue) {
|
|
3924
|
-
dispatchPath({ type: "NO_URL_CHECK", payload: "" });
|
|
3938
|
+
dispatchPath({ type: "NO_URL_CHECK", payload: initialRouteData.current?.path ?? "" });
|
|
3939
|
+
dispatchPath({
|
|
3940
|
+
type: "SET_CANONICALPATH",
|
|
3941
|
+
payload: initialRouteData.current?.canonicalPath ?? ""
|
|
3942
|
+
});
|
|
3925
3943
|
return;
|
|
3926
3944
|
}
|
|
3927
3945
|
if (initialLoadComplete && (hasUserChangedField.current || !route) && prevSourceValueRef.current !== sourceFieldValue && !isOverride) {
|
|
@@ -3999,7 +4017,16 @@ const Panel = ({ config }) => {
|
|
|
3999
4017
|
}
|
|
4000
4018
|
}
|
|
4001
4019
|
fetchRelatedRute();
|
|
4002
|
-
}, [config]);
|
|
4020
|
+
}, [config, routeRefreshKey]);
|
|
4021
|
+
useEffect(() => {
|
|
4022
|
+
if (isSubmitting) {
|
|
4023
|
+
wasSubmitting.current = true;
|
|
4024
|
+
return;
|
|
4025
|
+
}
|
|
4026
|
+
if (!wasSubmitting.current) return;
|
|
4027
|
+
wasSubmitting.current = false;
|
|
4028
|
+
setRouteRefreshKey((key) => key + 1);
|
|
4029
|
+
}, [isSubmitting]);
|
|
4003
4030
|
useEffect(() => {
|
|
4004
4031
|
if (!route || !routes.length) return;
|
|
4005
4032
|
const parentRoute = routes.find(
|
|
@@ -4067,7 +4094,13 @@ const Panel = ({ config }) => {
|
|
|
4067
4094
|
}) });
|
|
4068
4095
|
return /* @__PURE__ */ jsx(Box, { tag: "aside", "aria-labelledby": "URL Route", width: "100%", children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 1, children: [
|
|
4069
4096
|
!route && /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
4070
|
-
/* @__PURE__ */ jsx(
|
|
4097
|
+
/* @__PURE__ */ jsx(
|
|
4098
|
+
NewPathInfo,
|
|
4099
|
+
{
|
|
4100
|
+
hasSlug: !!(isOverride ? path.overridePath : sourceFieldValue.trim()) || !isOverride && isSourceFieldRequired,
|
|
4101
|
+
routeSourceField
|
|
4102
|
+
}
|
|
4103
|
+
),
|
|
4071
4104
|
/* @__PURE__ */ jsx(Divider, { marginTop: 2, marginBottom: 2 })
|
|
4072
4105
|
] }),
|
|
4073
4106
|
/* @__PURE__ */ jsx(
|
|
@@ -4188,7 +4221,7 @@ const index = {
|
|
|
4188
4221
|
id: `${PLUGIN_ID}.link.paths`,
|
|
4189
4222
|
defaultMessage: "Paths"
|
|
4190
4223
|
},
|
|
4191
|
-
Component: () => import("./index-
|
|
4224
|
+
Component: () => import("./index-Y4uwBSjP.mjs"),
|
|
4192
4225
|
permissions: [pluginPermissions["page.routes"][0]]
|
|
4193
4226
|
});
|
|
4194
4227
|
app.addMenuLink({
|
|
@@ -4198,7 +4231,7 @@ const index = {
|
|
|
4198
4231
|
id: `${PLUGIN_ID}.link.navigation`,
|
|
4199
4232
|
defaultMessage: "Navigation"
|
|
4200
4233
|
},
|
|
4201
|
-
Component: () => import("./index-
|
|
4234
|
+
Component: () => import("./index-DC-2-FsX.mjs"),
|
|
4202
4235
|
permissions: [pluginPermissions["page.navigation"][0]]
|
|
4203
4236
|
});
|
|
4204
4237
|
app.addSettingsLink(
|
|
@@ -4216,7 +4249,7 @@ const index = {
|
|
|
4216
4249
|
},
|
|
4217
4250
|
id: `${PLUGIN_ID}-general`,
|
|
4218
4251
|
to: `${PLUGIN_ID}/general`,
|
|
4219
|
-
Component: () => import("./index-
|
|
4252
|
+
Component: () => import("./index-DuSnxRbO.mjs"),
|
|
4220
4253
|
permissions: [pluginPermissions["settings.general"][0]]
|
|
4221
4254
|
}
|
|
4222
4255
|
);
|
|
@@ -4227,7 +4260,7 @@ const index = {
|
|
|
4227
4260
|
},
|
|
4228
4261
|
id: `${PLUGIN_ID}-navigation`,
|
|
4229
4262
|
to: `${PLUGIN_ID}/navigation`,
|
|
4230
|
-
Component: () => import("./index-
|
|
4263
|
+
Component: () => import("./index-Dx4gvFWK.mjs"),
|
|
4231
4264
|
permissions: [pluginPermissions["settings.navigation"][0]]
|
|
4232
4265
|
});
|
|
4233
4266
|
app.customFields.register({
|
|
@@ -4243,7 +4276,7 @@ const index = {
|
|
|
4243
4276
|
defaultMessage: "Select a route"
|
|
4244
4277
|
},
|
|
4245
4278
|
components: {
|
|
4246
|
-
Input: async () => import("./RoutePicker-
|
|
4279
|
+
Input: async () => import("./RoutePicker-C6LpgVMi.mjs").then((module) => ({
|
|
4247
4280
|
default: module.default
|
|
4248
4281
|
}))
|
|
4249
4282
|
},
|
|
@@ -4286,7 +4319,7 @@ const index = {
|
|
|
4286
4319
|
return Promise.all(
|
|
4287
4320
|
locales.map(async (locale) => {
|
|
4288
4321
|
try {
|
|
4289
|
-
const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/de.json": () => import("./de-
|
|
4322
|
+
const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/de.json": () => import("./de-Dnk_hvMW.mjs"), "./translations/en.json": () => import("./en-D5EqZSGy.mjs") }), `./translations/${locale}.json`, 3);
|
|
4290
4323
|
return { data, locale };
|
|
4291
4324
|
} catch {
|
|
4292
4325
|
return { data: {}, locale };
|
|
@@ -4,13 +4,13 @@ const jsxRuntime = require("react/jsx-runtime");
|
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const designSystem = require("@strapi/design-system");
|
|
6
6
|
const admin = require("@strapi/strapi/admin");
|
|
7
|
-
const index = require("./index-
|
|
8
|
-
const WarningBox = require("./WarningBox-
|
|
7
|
+
const index = require("./index-DHNPW0YT.js");
|
|
8
|
+
const WarningBox = require("./WarningBox-BHlYlKQ8.js");
|
|
9
9
|
const FullLoader = require("./FullLoader-C4hXFaLP.js");
|
|
10
10
|
const reactIntl = require("react-intl");
|
|
11
11
|
require("@strapi/icons/symbols");
|
|
12
12
|
const icons = require("@strapi/icons");
|
|
13
|
-
const SettingTitle = require("./SettingTitle-
|
|
13
|
+
const SettingTitle = require("./SettingTitle-DXGCUfum.js");
|
|
14
14
|
function getRouteSourceFields(contentType) {
|
|
15
15
|
if (!contentType?.attributes) return [];
|
|
16
16
|
return Object.entries(contentType.attributes).filter(
|
|
@@ -5,11 +5,11 @@ import { Box, Typography, Dialog, Button, Modal, Flex, SingleSelect, SingleSelec
|
|
|
5
5
|
import { createContext, useRef, useContext, useState, useMemo, useReducer, useCallback, useEffect, forwardRef } from "react";
|
|
6
6
|
import { createPortal } from "react-dom";
|
|
7
7
|
import { useIntl } from "react-intl";
|
|
8
|
-
import { u as useApi, g as getTranslation, i as isAbortError, P as PLUGIN_ID, d as debounce, a as duplicateCheck, T as Tooltip, b as PathInfo, c as usePluginConfig, p as pluginPermissions } from "./index-
|
|
8
|
+
import { u as useApi, g as getTranslation, i as isAbortError, P as PLUGIN_ID, d as debounce, a as duplicateCheck, T as Tooltip, b as PathInfo, c as usePluginConfig, p as pluginPermissions } from "./index-CVrufPeL.mjs";
|
|
9
9
|
import { u as useErrorMessage, C as Center, F as FullLoader } from "./FullLoader-BTZzPY8g.mjs";
|
|
10
10
|
import { useNotification, useFetchClient, Page, Layouts } from "@strapi/strapi/admin";
|
|
11
11
|
import { EmptyDocuments } from "@strapi/icons/symbols";
|
|
12
|
-
import { u as useAllEntities, W as WarningBox } from "./WarningBox-
|
|
12
|
+
import { u as useAllEntities, W as WarningBox } from "./WarningBox-CfIVF0O-.mjs";
|
|
13
13
|
import { MeasuringStrategy, DndContext, DragOverlay, closestCenter } from "@dnd-kit/core";
|
|
14
14
|
import { arrayMove, useSortable, SortableContext, verticalListSortingStrategy } from "@dnd-kit/sortable";
|
|
15
15
|
import { CSS } from "@dnd-kit/utilities";
|
|
@@ -350,8 +350,19 @@ function OverrideCheckbox({ isOverride, setIsOverride, disabledCondition }) {
|
|
|
350
350
|
}
|
|
351
351
|
) });
|
|
352
352
|
}
|
|
353
|
-
function NewPathInfo(
|
|
353
|
+
function NewPathInfo({
|
|
354
|
+
hasSlug,
|
|
355
|
+
routeSourceField
|
|
356
|
+
}) {
|
|
354
357
|
const { formatMessage } = reactIntl.useIntl();
|
|
358
|
+
if (!hasSlug)
|
|
359
|
+
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "danger600", children: formatMessage(
|
|
360
|
+
{
|
|
361
|
+
id: getTranslation("components.CMEditViewAside.path.noPathInfo"),
|
|
362
|
+
defaultMessage: 'No path will be created while the "{field}" field is empty. Fill it in or use the override option to set a custom path.'
|
|
363
|
+
},
|
|
364
|
+
{ field: routeSourceField }
|
|
365
|
+
) });
|
|
355
366
|
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral600", children: formatMessage({
|
|
356
367
|
id: getTranslation("components.CMEditViewAside.path.newPathInfo"),
|
|
357
368
|
defaultMessage: "A new path will be created upon saving this entry."
|
|
@@ -3845,8 +3856,8 @@ function reducer(state, action) {
|
|
|
3845
3856
|
}
|
|
3846
3857
|
}
|
|
3847
3858
|
const Panel = ({ config }) => {
|
|
3848
|
-
const { form, model } = admin.unstable_useContentManagerContext();
|
|
3849
|
-
const { initialValues, values, onChange } = form;
|
|
3859
|
+
const { form, model, contentType } = admin.unstable_useContentManagerContext();
|
|
3860
|
+
const { initialValues, values, onChange, isSubmitting } = form;
|
|
3850
3861
|
const { getRelatedRoute, getAllRoutes, getProhibitedRouteIds } = useApi();
|
|
3851
3862
|
const { formatMessage } = reactIntl.useIntl();
|
|
3852
3863
|
const { get } = admin.useFetchClient();
|
|
@@ -3884,6 +3895,8 @@ const Panel = ({ config }) => {
|
|
|
3884
3895
|
slug: "",
|
|
3885
3896
|
overridePath: ""
|
|
3886
3897
|
});
|
|
3898
|
+
const [routeRefreshKey, setRouteRefreshKey] = React.useState(0);
|
|
3899
|
+
const wasSubmitting = React.useRef(false);
|
|
3887
3900
|
const hasUserChangedField = React.useRef(false);
|
|
3888
3901
|
const hasUserInteracted = React.useRef(false);
|
|
3889
3902
|
const initialRouteData = React.useRef(null);
|
|
@@ -3891,6 +3904,7 @@ const Panel = ({ config }) => {
|
|
|
3891
3904
|
const routeSourceField = config?.routeSourceField;
|
|
3892
3905
|
const sourceFieldValue = routeSourceField ? values[routeSourceField] || "" : "";
|
|
3893
3906
|
const initialSourceFieldValue = routeSourceField ? initialValues[routeSourceField] || "" : "";
|
|
3907
|
+
const isSourceFieldRequired = !!(routeSourceField && contentType?.attributes?.[routeSourceField]?.required);
|
|
3894
3908
|
const latestCheckPathRef = React.useRef(checkPath);
|
|
3895
3909
|
latestCheckPathRef.current = checkPath;
|
|
3896
3910
|
const debouncedCheckPath = React.useRef(
|
|
@@ -3917,7 +3931,7 @@ const Panel = ({ config }) => {
|
|
|
3917
3931
|
parentDocumentId: selectedParent?.documentId || null,
|
|
3918
3932
|
slug: isOverride ? overridePath : slug
|
|
3919
3933
|
};
|
|
3920
|
-
if (initialRouteData.current?.isOverride === isOverride && data.path === initialRouteData.current?.path && data.parentDocumentId === (initialRouteData.current?.parent?.documentId ?? null)) {
|
|
3934
|
+
if (initialRouteData.current?.isOverride === isOverride && data.path === initialRouteData.current?.path && data.parentDocumentId === (initialRouteData.current?.parent?.documentId ?? null) && sourceFieldValue.trim() === (initialRouteData.current?.title ?? "")) {
|
|
3921
3935
|
onChange("webatlas", void 0);
|
|
3922
3936
|
return;
|
|
3923
3937
|
}
|
|
@@ -3939,7 +3953,11 @@ const Panel = ({ config }) => {
|
|
|
3939
3953
|
hasUserChangedField.current = true;
|
|
3940
3954
|
}
|
|
3941
3955
|
if (!sourceFieldValue) {
|
|
3942
|
-
dispatchPath({ type: "NO_URL_CHECK", payload: "" });
|
|
3956
|
+
dispatchPath({ type: "NO_URL_CHECK", payload: initialRouteData.current?.path ?? "" });
|
|
3957
|
+
dispatchPath({
|
|
3958
|
+
type: "SET_CANONICALPATH",
|
|
3959
|
+
payload: initialRouteData.current?.canonicalPath ?? ""
|
|
3960
|
+
});
|
|
3943
3961
|
return;
|
|
3944
3962
|
}
|
|
3945
3963
|
if (initialLoadComplete && (hasUserChangedField.current || !route) && prevSourceValueRef.current !== sourceFieldValue && !isOverride) {
|
|
@@ -4017,7 +4035,16 @@ const Panel = ({ config }) => {
|
|
|
4017
4035
|
}
|
|
4018
4036
|
}
|
|
4019
4037
|
fetchRelatedRute();
|
|
4020
|
-
}, [config]);
|
|
4038
|
+
}, [config, routeRefreshKey]);
|
|
4039
|
+
React.useEffect(() => {
|
|
4040
|
+
if (isSubmitting) {
|
|
4041
|
+
wasSubmitting.current = true;
|
|
4042
|
+
return;
|
|
4043
|
+
}
|
|
4044
|
+
if (!wasSubmitting.current) return;
|
|
4045
|
+
wasSubmitting.current = false;
|
|
4046
|
+
setRouteRefreshKey((key) => key + 1);
|
|
4047
|
+
}, [isSubmitting]);
|
|
4021
4048
|
React.useEffect(() => {
|
|
4022
4049
|
if (!route || !routes.length) return;
|
|
4023
4050
|
const parentRoute = routes.find(
|
|
@@ -4085,7 +4112,13 @@ const Panel = ({ config }) => {
|
|
|
4085
4112
|
}) });
|
|
4086
4113
|
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { tag: "aside", "aria-labelledby": "URL Route", width: "100%", children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 1, children: [
|
|
4087
4114
|
!route && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
4088
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4115
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4116
|
+
NewPathInfo,
|
|
4117
|
+
{
|
|
4118
|
+
hasSlug: !!(isOverride ? path.overridePath : sourceFieldValue.trim()) || !isOverride && isSourceFieldRequired,
|
|
4119
|
+
routeSourceField
|
|
4120
|
+
}
|
|
4121
|
+
),
|
|
4089
4122
|
/* @__PURE__ */ jsxRuntime.jsx(designSystem.Divider, { marginTop: 2, marginBottom: 2 })
|
|
4090
4123
|
] }),
|
|
4091
4124
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -4206,7 +4239,7 @@ const index = {
|
|
|
4206
4239
|
id: `${PLUGIN_ID}.link.paths`,
|
|
4207
4240
|
defaultMessage: "Paths"
|
|
4208
4241
|
},
|
|
4209
|
-
Component: () => Promise.resolve().then(() => require("./index-
|
|
4242
|
+
Component: () => Promise.resolve().then(() => require("./index-Dp_eCRFS.js")),
|
|
4210
4243
|
permissions: [pluginPermissions["page.routes"][0]]
|
|
4211
4244
|
});
|
|
4212
4245
|
app.addMenuLink({
|
|
@@ -4216,7 +4249,7 @@ const index = {
|
|
|
4216
4249
|
id: `${PLUGIN_ID}.link.navigation`,
|
|
4217
4250
|
defaultMessage: "Navigation"
|
|
4218
4251
|
},
|
|
4219
|
-
Component: () => Promise.resolve().then(() => require("./index-
|
|
4252
|
+
Component: () => Promise.resolve().then(() => require("./index-RmZ3LQPu.js")),
|
|
4220
4253
|
permissions: [pluginPermissions["page.navigation"][0]]
|
|
4221
4254
|
});
|
|
4222
4255
|
app.addSettingsLink(
|
|
@@ -4234,7 +4267,7 @@ const index = {
|
|
|
4234
4267
|
},
|
|
4235
4268
|
id: `${PLUGIN_ID}-general`,
|
|
4236
4269
|
to: `${PLUGIN_ID}/general`,
|
|
4237
|
-
Component: () => Promise.resolve().then(() => require("./index-
|
|
4270
|
+
Component: () => Promise.resolve().then(() => require("./index-D7zg69uM.js")),
|
|
4238
4271
|
permissions: [pluginPermissions["settings.general"][0]]
|
|
4239
4272
|
}
|
|
4240
4273
|
);
|
|
@@ -4245,7 +4278,7 @@ const index = {
|
|
|
4245
4278
|
},
|
|
4246
4279
|
id: `${PLUGIN_ID}-navigation`,
|
|
4247
4280
|
to: `${PLUGIN_ID}/navigation`,
|
|
4248
|
-
Component: () => Promise.resolve().then(() => require("./index-
|
|
4281
|
+
Component: () => Promise.resolve().then(() => require("./index-FuvoHpAT.js")),
|
|
4249
4282
|
permissions: [pluginPermissions["settings.navigation"][0]]
|
|
4250
4283
|
});
|
|
4251
4284
|
app.customFields.register({
|
|
@@ -4261,7 +4294,7 @@ const index = {
|
|
|
4261
4294
|
defaultMessage: "Select a route"
|
|
4262
4295
|
},
|
|
4263
4296
|
components: {
|
|
4264
|
-
Input: async () => Promise.resolve().then(() => require("./RoutePicker-
|
|
4297
|
+
Input: async () => Promise.resolve().then(() => require("./RoutePicker-DvzQH2CX.js")).then((module2) => ({
|
|
4265
4298
|
default: module2.default
|
|
4266
4299
|
}))
|
|
4267
4300
|
},
|
|
@@ -4304,7 +4337,7 @@ const index = {
|
|
|
4304
4337
|
return Promise.all(
|
|
4305
4338
|
locales.map(async (locale) => {
|
|
4306
4339
|
try {
|
|
4307
|
-
const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/de.json": () => Promise.resolve().then(() => require("./de-
|
|
4340
|
+
const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/de.json": () => Promise.resolve().then(() => require("./de-BWUGdpM0.js")), "./translations/en.json": () => Promise.resolve().then(() => require("./en-DOk8P6X5.js")) }), `./translations/${locale}.json`, 3);
|
|
4308
4341
|
return { data, locale };
|
|
4309
4342
|
} catch {
|
|
4310
4343
|
return { data: {}, locale };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const jsxRuntime = require("react/jsx-runtime");
|
|
4
4
|
const React = require("react");
|
|
5
|
-
const index = require("./index-
|
|
5
|
+
const index = require("./index-DHNPW0YT.js");
|
|
6
6
|
const FullLoader = require("./FullLoader-C4hXFaLP.js");
|
|
7
7
|
const admin = require("@strapi/strapi/admin");
|
|
8
8
|
const designSystem = require("@strapi/design-system");
|
|
@@ -2,13 +2,13 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { useState, useEffect, useReducer, useRef, useMemo } from "react";
|
|
3
3
|
import { Box, Accordion, Field, SingleSelect, SingleSelectOption, Grid, Typography, Link } from "@strapi/design-system";
|
|
4
4
|
import { useNotification, Page } from "@strapi/strapi/admin";
|
|
5
|
-
import { g as getTranslation, T as Tooltip, c as usePluginConfig, e as useAllContentTypes, p as pluginPermissions, f as PLUGIN_NAME, h as PLUGIN_VERSION } from "./index-
|
|
6
|
-
import { W as WarningBox, u as useAllEntities } from "./WarningBox-
|
|
5
|
+
import { g as getTranslation, T as Tooltip, c as usePluginConfig, e as useAllContentTypes, p as pluginPermissions, f as PLUGIN_NAME, h as PLUGIN_VERSION } from "./index-CVrufPeL.mjs";
|
|
6
|
+
import { W as WarningBox, u as useAllEntities } from "./WarningBox-CfIVF0O-.mjs";
|
|
7
7
|
import { u as useErrorMessage, F as FullLoader } from "./FullLoader-BTZzPY8g.mjs";
|
|
8
8
|
import { useIntl } from "react-intl";
|
|
9
9
|
import "@strapi/icons/symbols";
|
|
10
10
|
import { ExternalLink } from "@strapi/icons";
|
|
11
|
-
import { P as PageWrapper, C as ContentBox, S as SettingTitle } from "./SettingTitle-
|
|
11
|
+
import { P as PageWrapper, C as ContentBox, S as SettingTitle } from "./SettingTitle-C1_2epDJ.mjs";
|
|
12
12
|
function getRouteSourceFields(contentType) {
|
|
13
13
|
if (!contentType?.attributes) return [];
|
|
14
14
|
return Object.entries(contentType.attributes).filter(
|
|
@@ -2,12 +2,12 @@ import { jsx, jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { useReducer, useState, useRef, useEffect } from "react";
|
|
3
3
|
import { Field } from "@strapi/design-system";
|
|
4
4
|
import { useNotification, Page } from "@strapi/strapi/admin";
|
|
5
|
-
import { c as usePluginConfig, g as getTranslation, p as pluginPermissions } from "./index-
|
|
5
|
+
import { c as usePluginConfig, g as getTranslation, p as pluginPermissions } from "./index-CVrufPeL.mjs";
|
|
6
6
|
import { u as useErrorMessage, F as FullLoader } from "./FullLoader-BTZzPY8g.mjs";
|
|
7
7
|
import { useIntl } from "react-intl";
|
|
8
8
|
import "@strapi/icons/symbols";
|
|
9
9
|
import "@strapi/icons";
|
|
10
|
-
import { P as PageWrapper, C as ContentBox, S as SettingTitle } from "./SettingTitle-
|
|
10
|
+
import { P as PageWrapper, C as ContentBox, S as SettingTitle } from "./SettingTitle-C1_2epDJ.mjs";
|
|
11
11
|
function reducer(newConfig, action) {
|
|
12
12
|
switch (action.type) {
|
|
13
13
|
case "SET_MAX_DEPTH":
|
|
@@ -4,12 +4,12 @@ const jsxRuntime = require("react/jsx-runtime");
|
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const designSystem = require("@strapi/design-system");
|
|
6
6
|
const admin = require("@strapi/strapi/admin");
|
|
7
|
-
const index = require("./index-
|
|
7
|
+
const index = require("./index-DHNPW0YT.js");
|
|
8
8
|
const FullLoader = require("./FullLoader-C4hXFaLP.js");
|
|
9
9
|
const reactIntl = require("react-intl");
|
|
10
10
|
require("@strapi/icons/symbols");
|
|
11
11
|
require("@strapi/icons");
|
|
12
|
-
const SettingTitle = require("./SettingTitle-
|
|
12
|
+
const SettingTitle = require("./SettingTitle-DXGCUfum.js");
|
|
13
13
|
function reducer(newConfig, action) {
|
|
14
14
|
switch (action.type) {
|
|
15
15
|
case "SET_MAX_DEPTH":
|
|
@@ -7,11 +7,11 @@ const designSystem = require("@strapi/design-system");
|
|
|
7
7
|
const React = require("react");
|
|
8
8
|
const ReactDOM = require("react-dom");
|
|
9
9
|
const reactIntl = require("react-intl");
|
|
10
|
-
const index = require("./index-
|
|
10
|
+
const index = require("./index-DHNPW0YT.js");
|
|
11
11
|
const FullLoader = require("./FullLoader-C4hXFaLP.js");
|
|
12
12
|
const admin = require("@strapi/strapi/admin");
|
|
13
13
|
const symbols = require("@strapi/icons/symbols");
|
|
14
|
-
const WarningBox = require("./WarningBox-
|
|
14
|
+
const WarningBox = require("./WarningBox-BHlYlKQ8.js");
|
|
15
15
|
const core = require("@dnd-kit/core");
|
|
16
16
|
const sortable = require("@dnd-kit/sortable");
|
|
17
17
|
const utilities = require("@dnd-kit/utilities");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useState, useEffect, useMemo } from "react";
|
|
3
|
-
import { g as getTranslation, u as useApi, d as debounce, p as pluginPermissions, i as isAbortError } from "./index-
|
|
3
|
+
import { g as getTranslation, u as useApi, d as debounce, p as pluginPermissions, i as isAbortError } from "./index-CVrufPeL.mjs";
|
|
4
4
|
import { u as useErrorMessage, F as FullLoader } from "./FullLoader-BTZzPY8g.mjs";
|
|
5
5
|
import { Page, Layouts, useNotification } from "@strapi/strapi/admin";
|
|
6
6
|
import { Grid, Box, Field, Thead, Tr, Th, Typography, VisuallyHidden, Td, Flex, LinkButton, Table, Tbody, EmptyStateLayout } from "@strapi/design-system";
|
package/dist/admin/index.js
CHANGED
package/dist/admin/index.mjs
CHANGED
package/dist/server/index.js
CHANGED
|
@@ -184,6 +184,7 @@ function buildStructuredNavigation(navigation2, variant = "nested") {
|
|
|
184
184
|
itemsById.set(item.documentId, newItem);
|
|
185
185
|
itemsProcessed.add(item.documentId);
|
|
186
186
|
});
|
|
187
|
+
if (remainingItems.length === itemsToProcess.length) break;
|
|
187
188
|
itemsToProcess = remainingItems;
|
|
188
189
|
}
|
|
189
190
|
const sortedItems = sortItems(rootItems);
|
|
@@ -4671,7 +4672,8 @@ async function enrichWebatlasData(data, contentTypeUid) {
|
|
|
4671
4672
|
}
|
|
4672
4673
|
return ids;
|
|
4673
4674
|
};
|
|
4674
|
-
const
|
|
4675
|
+
const items = Array.isArray(data) ? data : [data];
|
|
4676
|
+
const documentIds = items.flatMap((item) => collectDocumentIds(item, contentTypeUid));
|
|
4675
4677
|
if (documentIds.length === 0) return data;
|
|
4676
4678
|
const uniqueDocumentIds = [...new Set(documentIds)];
|
|
4677
4679
|
const routes2 = await strapi.db?.query(waRoute).findMany({
|
|
@@ -4727,7 +4729,7 @@ async function enrichWebatlasData(data, contentTypeUid) {
|
|
|
4727
4729
|
}
|
|
4728
4730
|
return entity;
|
|
4729
4731
|
};
|
|
4730
|
-
return enrichEntity2(data, contentTypeUid);
|
|
4732
|
+
return Array.isArray(data) ? data.map((item) => enrichEntity2(item, contentTypeUid)) : enrichEntity2(data, contentTypeUid);
|
|
4731
4733
|
}
|
|
4732
4734
|
function isExternalUrl(value) {
|
|
4733
4735
|
return !/^[a-z0-9]+$/.test(value);
|
|
@@ -4789,6 +4791,8 @@ function enrichEntity(entity, uid, routeMap) {
|
|
|
4789
4791
|
`Wrapper route detected in route-picker field '${key}'. Wrapper routes cannot be used as page links. Setting to null.`
|
|
4790
4792
|
);
|
|
4791
4793
|
entity[key] = null;
|
|
4794
|
+
} else if (route2.isUnpublished) {
|
|
4795
|
+
entity[key] = null;
|
|
4792
4796
|
} else {
|
|
4793
4797
|
entity[key] = route2.canonicalPath || route2.path || value;
|
|
4794
4798
|
}
|
|
@@ -4824,20 +4828,36 @@ function enrichEntity(entity, uid, routeMap) {
|
|
|
4824
4828
|
}
|
|
4825
4829
|
return entity;
|
|
4826
4830
|
}
|
|
4827
|
-
async function enrichRoutePickerFields(data, contentTypeUid) {
|
|
4831
|
+
async function enrichRoutePickerFields(data, contentTypeUid, status = "published") {
|
|
4828
4832
|
if (!data || typeof data !== "object") return data;
|
|
4829
|
-
const
|
|
4833
|
+
const items = Array.isArray(data) ? data : [data];
|
|
4834
|
+
const documentIds = items.flatMap((item) => collectRoutePickerIds(item, contentTypeUid));
|
|
4830
4835
|
if (documentIds.length === 0) return data;
|
|
4831
4836
|
const uniqueDocumentIds = [...new Set(documentIds)];
|
|
4832
4837
|
const routes2 = await strapi.db?.query(waRoute).findMany({
|
|
4833
4838
|
where: {
|
|
4834
4839
|
documentId: { $in: uniqueDocumentIds }
|
|
4835
4840
|
},
|
|
4836
|
-
select: [
|
|
4841
|
+
select: [
|
|
4842
|
+
"documentId",
|
|
4843
|
+
"path",
|
|
4844
|
+
"canonicalPath",
|
|
4845
|
+
"type",
|
|
4846
|
+
"relatedContentType",
|
|
4847
|
+
"relatedDocumentId"
|
|
4848
|
+
]
|
|
4837
4849
|
});
|
|
4838
|
-
const
|
|
4839
|
-
const
|
|
4840
|
-
|
|
4850
|
+
const publishedDocumentIds = status === "published" ? await getPublishedDocumentIds(routes2 || []) : null;
|
|
4851
|
+
const routeMap = new Map(
|
|
4852
|
+
routes2?.map((route2) => [
|
|
4853
|
+
route2.documentId,
|
|
4854
|
+
{
|
|
4855
|
+
...route2,
|
|
4856
|
+
isUnpublished: publishedDocumentIds && route2.relatedContentType && !publishedDocumentIds.has(route2.relatedDocumentId)
|
|
4857
|
+
}
|
|
4858
|
+
]) || []
|
|
4859
|
+
);
|
|
4860
|
+
return Array.isArray(data) ? data.map((item) => enrichEntity(item, contentTypeUid, routeMap)) : enrichEntity(data, contentTypeUid, routeMap);
|
|
4841
4861
|
}
|
|
4842
4862
|
function isBlacklistedPath(url, routeBlacklist) {
|
|
4843
4863
|
if (!url) return false;
|
|
@@ -4903,18 +4923,67 @@ function toBreadcrumbEntry(route2) {
|
|
|
4903
4923
|
title: route2.title
|
|
4904
4924
|
};
|
|
4905
4925
|
}
|
|
4906
|
-
async function addWebatlasBreadcrumb(data, route2) {
|
|
4926
|
+
async function addWebatlasBreadcrumb(data, route2, status = "published") {
|
|
4907
4927
|
if (!data?.webatlas || !route2) return data;
|
|
4908
4928
|
const segments = route2.canonicalPath?.split("/").filter(Boolean) || [];
|
|
4909
4929
|
const ancestorPaths = segments.slice(0, -1).map((_, i) => segments.slice(0, i + 1).join("/"));
|
|
4910
4930
|
const ancestors = ancestorPaths.length ? await strapi.db.query(waRoute).findMany({
|
|
4911
4931
|
where: { canonicalPath: { $in: ancestorPaths } },
|
|
4912
|
-
select: [
|
|
4932
|
+
select: [
|
|
4933
|
+
"path",
|
|
4934
|
+
"canonicalPath",
|
|
4935
|
+
"slug",
|
|
4936
|
+
"uidPath",
|
|
4937
|
+
"title",
|
|
4938
|
+
"relatedContentType",
|
|
4939
|
+
"relatedDocumentId"
|
|
4940
|
+
]
|
|
4913
4941
|
}) : [];
|
|
4914
|
-
const
|
|
4942
|
+
const publishedDocumentIds = status === "published" ? await getPublishedDocumentIds(ancestors) : null;
|
|
4943
|
+
const isVisible = (ancestor) => !publishedDocumentIds || !ancestor.relatedContentType || publishedDocumentIds.has(ancestor.relatedDocumentId);
|
|
4944
|
+
const orderedAncestors = ancestorPaths.map((path) => ancestors.find((ancestor) => ancestor.canonicalPath === path)).filter((ancestor) => ancestor && isVisible(ancestor));
|
|
4915
4945
|
data.webatlas.breadcrumb = [...orderedAncestors, route2].map(toBreadcrumbEntry);
|
|
4916
4946
|
return data;
|
|
4917
4947
|
}
|
|
4948
|
+
async function removeUnpublishedNavItems(items) {
|
|
4949
|
+
const publishedDocumentIds = await getPublishedDocumentIds(items.map((item) => item.route));
|
|
4950
|
+
const removedItemIds = new Set(
|
|
4951
|
+
items.filter(
|
|
4952
|
+
({ route: route2 }) => route2?.relatedContentType && !publishedDocumentIds.has(route2.relatedDocumentId)
|
|
4953
|
+
).map((item) => item.documentId)
|
|
4954
|
+
);
|
|
4955
|
+
let foundDescendant = removedItemIds.size > 0;
|
|
4956
|
+
while (foundDescendant) {
|
|
4957
|
+
foundDescendant = false;
|
|
4958
|
+
for (const item of items) {
|
|
4959
|
+
if (item.parent && removedItemIds.has(item.parent.documentId) && !removedItemIds.has(item.documentId)) {
|
|
4960
|
+
removedItemIds.add(item.documentId);
|
|
4961
|
+
foundDescendant = true;
|
|
4962
|
+
}
|
|
4963
|
+
}
|
|
4964
|
+
}
|
|
4965
|
+
return items.filter((item) => !removedItemIds.has(item.documentId));
|
|
4966
|
+
}
|
|
4967
|
+
async function getPublishedDocumentIds(routes2) {
|
|
4968
|
+
const documentIdsByUid = /* @__PURE__ */ new Map();
|
|
4969
|
+
for (const route2 of routes2) {
|
|
4970
|
+
if (!route2?.relatedContentType) continue;
|
|
4971
|
+
const documentIds = documentIdsByUid.get(route2.relatedContentType) ?? [];
|
|
4972
|
+
documentIds.push(route2.relatedDocumentId);
|
|
4973
|
+
documentIdsByUid.set(route2.relatedContentType, documentIds);
|
|
4974
|
+
}
|
|
4975
|
+
const publishedDocumentIds = /* @__PURE__ */ new Set();
|
|
4976
|
+
for (const [uid, documentIds] of documentIdsByUid) {
|
|
4977
|
+
if (!strapi.contentTypes[uid]) continue;
|
|
4978
|
+
const entries = await strapi.documents(uid).findMany({
|
|
4979
|
+
filters: { documentId: { $in: documentIds } },
|
|
4980
|
+
fields: ["documentId"],
|
|
4981
|
+
status: "published"
|
|
4982
|
+
});
|
|
4983
|
+
entries.forEach((entry) => publishedDocumentIds.add(entry.documentId));
|
|
4984
|
+
}
|
|
4985
|
+
return publishedDocumentIds;
|
|
4986
|
+
}
|
|
4918
4987
|
const migration_001_canonical_path = {
|
|
4919
4988
|
version: "001",
|
|
4920
4989
|
description: "Migrate title field to canonicalPath using transformToUrl",
|
|
@@ -5177,11 +5246,17 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
|
|
|
5177
5246
|
return next();
|
|
5178
5247
|
}
|
|
5179
5248
|
const ctSettings = config2.selectedContentTypes.find((ct) => ct.uid === context.uid);
|
|
5249
|
+
const requestContext = strapi2.requestContext.get();
|
|
5250
|
+
const isRouteDataAllowed = !requestContext || requestContext.state?.route?.info?.type === "admin";
|
|
5251
|
+
if ((context.action === "create" || context.action === "update") && !isRouteDataAllowed) {
|
|
5252
|
+
delete context.params.data?.webatlas;
|
|
5253
|
+
}
|
|
5180
5254
|
if (context.action === "create") {
|
|
5181
5255
|
const data = context.params.data;
|
|
5182
5256
|
const { webatlas } = data;
|
|
5183
5257
|
const { slug, parentDocumentId, isOverride } = webatlas || {};
|
|
5184
5258
|
const transformedSlug = slug ? transformToUrl(slug, !isOverride) : null;
|
|
5259
|
+
if (!transformedSlug) return next();
|
|
5185
5260
|
let parent = null;
|
|
5186
5261
|
let isValid = false;
|
|
5187
5262
|
if (parentDocumentId) {
|
|
@@ -5210,7 +5285,6 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
|
|
|
5210
5285
|
assertPathAllowed(rawPath, routeBlacklist);
|
|
5211
5286
|
assertPathAllowed(canonicalPath, routeBlacklist);
|
|
5212
5287
|
const result2 = await next();
|
|
5213
|
-
if (!transformedSlug) return result2;
|
|
5214
5288
|
const existing = await strapi2.db?.query(waRoute).findOne({
|
|
5215
5289
|
where: { relatedDocumentId: result2.documentId }
|
|
5216
5290
|
});
|
|
@@ -5383,15 +5457,7 @@ const addWebatlasField = ({ strapi: strapi2 }) => {
|
|
|
5383
5457
|
if (!contentTypeEntry) return;
|
|
5384
5458
|
const [contentTypeUid] = contentTypeEntry;
|
|
5385
5459
|
if (ctx.body.data) {
|
|
5386
|
-
|
|
5387
|
-
ctx.body.data = await Promise.all(
|
|
5388
|
-
ctx.body.data.map((item) => enrichWebatlasData(item, contentTypeUid))
|
|
5389
|
-
);
|
|
5390
|
-
} else {
|
|
5391
|
-
ctx.body.data = await enrichWebatlasData(ctx.body.data, contentTypeUid);
|
|
5392
|
-
}
|
|
5393
|
-
} else if (Array.isArray(ctx.body)) {
|
|
5394
|
-
ctx.body = await Promise.all(ctx.body.map((item) => enrichWebatlasData(item, contentTypeUid)));
|
|
5460
|
+
ctx.body.data = await enrichWebatlasData(ctx.body.data, contentTypeUid);
|
|
5395
5461
|
} else if (typeof ctx.body === "object") {
|
|
5396
5462
|
ctx.body = await enrichWebatlasData(ctx.body, contentTypeUid);
|
|
5397
5463
|
}
|
|
@@ -5414,20 +5480,11 @@ const enrichRoutePicker = ({ strapi: strapi2 }) => {
|
|
|
5414
5480
|
);
|
|
5415
5481
|
if (!contentTypeEntry) return;
|
|
5416
5482
|
const [contentTypeUid] = contentTypeEntry;
|
|
5483
|
+
const status = ctx.query?.status === "draft" ? "draft" : "published";
|
|
5417
5484
|
if (ctx.body.data) {
|
|
5418
|
-
|
|
5419
|
-
ctx.body.data = await Promise.all(
|
|
5420
|
-
ctx.body.data.map((item) => enrichRoutePickerFields(item, contentTypeUid))
|
|
5421
|
-
);
|
|
5422
|
-
} else {
|
|
5423
|
-
ctx.body.data = await enrichRoutePickerFields(ctx.body.data, contentTypeUid);
|
|
5424
|
-
}
|
|
5425
|
-
} else if (Array.isArray(ctx.body)) {
|
|
5426
|
-
ctx.body = await Promise.all(
|
|
5427
|
-
ctx.body.map((item) => enrichRoutePickerFields(item, contentTypeUid))
|
|
5428
|
-
);
|
|
5485
|
+
ctx.body.data = await enrichRoutePickerFields(ctx.body.data, contentTypeUid, status);
|
|
5429
5486
|
} else if (typeof ctx.body === "object") {
|
|
5430
|
-
ctx.body = await enrichRoutePickerFields(ctx.body, contentTypeUid);
|
|
5487
|
+
ctx.body = await enrichRoutePickerFields(ctx.body, contentTypeUid, status);
|
|
5431
5488
|
}
|
|
5432
5489
|
};
|
|
5433
5490
|
};
|
|
@@ -5740,14 +5797,20 @@ const admin$2 = () => ({
|
|
|
5740
5797
|
const client$2 = ({ strapi: strapi2 }) => ({
|
|
5741
5798
|
async getEntityByPath(ctx) {
|
|
5742
5799
|
const { slug, populate, populateDeepDepth, fields, status, breadcrumb } = ctx.query;
|
|
5743
|
-
if (!slug) throw new utils.errors.ValidationError("Slug is required");
|
|
5800
|
+
if (typeof slug !== "string" || !slug) throw new utils.errors.ValidationError("Slug is required");
|
|
5801
|
+
if (status !== void 0 && status !== "draft" && status !== "published")
|
|
5802
|
+
throw new utils.errors.ValidationError('Status must be "draft" or "published"');
|
|
5803
|
+
const depth = populateDeepDepth === void 0 ? 5 : Number(populateDeepDepth);
|
|
5804
|
+
if (!Number.isInteger(depth) || depth < 1 || depth > 10)
|
|
5805
|
+
throw new utils.errors.ValidationError("populateDeepDepth must be a number between 1 and 10");
|
|
5744
5806
|
const entity = await getClientService().getEntityByPath(
|
|
5745
5807
|
slug,
|
|
5746
5808
|
populate,
|
|
5747
|
-
|
|
5809
|
+
depth,
|
|
5748
5810
|
fields,
|
|
5749
5811
|
status,
|
|
5750
|
-
breadcrumb !== "false"
|
|
5812
|
+
breadcrumb !== "false",
|
|
5813
|
+
ctx.state.auth
|
|
5751
5814
|
);
|
|
5752
5815
|
if (!entity) throw new utils.errors.NotFoundError("Entity not found");
|
|
5753
5816
|
return ctx.send(entity);
|
|
@@ -5756,6 +5819,14 @@ const client$2 = ({ strapi: strapi2 }) => ({
|
|
|
5756
5819
|
const { id, name, slug, documentId, variant } = ctx.query;
|
|
5757
5820
|
if (!id && !name && !slug && !documentId)
|
|
5758
5821
|
throw new utils.errors.ValidationError("Navigation id, name, slug or documentId is required");
|
|
5822
|
+
for (const [key, value] of Object.entries({ id, name, slug, documentId })) {
|
|
5823
|
+
if (value !== void 0 && typeof value !== "string")
|
|
5824
|
+
throw new utils.errors.ValidationError(`Navigation ${key} must be a string`);
|
|
5825
|
+
}
|
|
5826
|
+
if (id !== void 0 && !/^\d+$/.test(id))
|
|
5827
|
+
throw new utils.errors.ValidationError("Navigation id must be a number");
|
|
5828
|
+
if (variant !== void 0 && variant !== "nested" && variant !== "flat")
|
|
5829
|
+
throw new utils.errors.ValidationError('Variant must be "nested" or "flat"');
|
|
5759
5830
|
const navigation2 = await getClientService().getNavigation(id, name, slug, documentId, variant);
|
|
5760
5831
|
if (!navigation2) throw new utils.errors.NotFoundError("Navigation not found");
|
|
5761
5832
|
return ctx.send(navigation2);
|
|
@@ -6195,7 +6266,7 @@ const admin = ({ strapi: strapi2 }) => ({
|
|
|
6195
6266
|
}
|
|
6196
6267
|
});
|
|
6197
6268
|
const client = ({ strapi: strapi2 }) => ({
|
|
6198
|
-
async getEntityByPath(slug, populate, populateDeepDepth, fields, status = "published", breadcrumb = true) {
|
|
6269
|
+
async getEntityByPath(slug, populate, populateDeepDepth, fields, status = "published", breadcrumb = true, auth) {
|
|
6199
6270
|
const route2 = await strapi2.documents(waRoute).findFirst({
|
|
6200
6271
|
filters: {
|
|
6201
6272
|
$or: [{ path: slug }, { canonicalPath: slug }, { uidPath: slug }]
|
|
@@ -6206,12 +6277,10 @@ const client = ({ strapi: strapi2 }) => ({
|
|
|
6206
6277
|
if (populate === "deep") {
|
|
6207
6278
|
const modelObject = getFullPopulateObject(
|
|
6208
6279
|
route2.relatedContentType,
|
|
6209
|
-
|
|
6280
|
+
populateDeepDepth,
|
|
6210
6281
|
[]
|
|
6211
6282
|
);
|
|
6212
|
-
|
|
6213
|
-
populateObject = modelObject.populate;
|
|
6214
|
-
}
|
|
6283
|
+
populateObject = typeof modelObject === "object" && "populate" in modelObject ? modelObject.populate : void 0;
|
|
6215
6284
|
}
|
|
6216
6285
|
const contentTypeObject = Object.entries(strapi2.contentTypes).find(
|
|
6217
6286
|
([key, value]) => key === route2.relatedContentType
|
|
@@ -6220,20 +6289,34 @@ const client = ({ strapi: strapi2 }) => ({
|
|
|
6220
6289
|
return null;
|
|
6221
6290
|
}
|
|
6222
6291
|
const [contentTypeKey, contentType] = contentTypeObject;
|
|
6292
|
+
const action = contentType.kind === "singleType" ? "find" : "findOne";
|
|
6293
|
+
try {
|
|
6294
|
+
await strapi2.auth.verify(auth, { scope: [`${contentTypeKey}.${action}`] });
|
|
6295
|
+
} catch {
|
|
6296
|
+
return null;
|
|
6297
|
+
}
|
|
6298
|
+
await strapi2.contentAPI.validate.query(
|
|
6299
|
+
{ populate: populate === "deep" ? void 0 : populate, fields },
|
|
6300
|
+
contentType,
|
|
6301
|
+
{ auth }
|
|
6302
|
+
);
|
|
6303
|
+
const sanitizedQuery = await strapi2.contentAPI.sanitize.query({ fields }, contentType, { auth });
|
|
6304
|
+
const sanitizedPopulate = populateObject ? await strapi2.contentAPI.sanitize.populate(populateObject, contentType, { auth }) : void 0;
|
|
6223
6305
|
const entity = await strapi2.documents(route2.relatedContentType).findOne({
|
|
6224
6306
|
documentId: route2.relatedDocumentId,
|
|
6225
|
-
populate:
|
|
6226
|
-
fields,
|
|
6307
|
+
populate: sanitizedPopulate,
|
|
6308
|
+
fields: sanitizedQuery.fields,
|
|
6227
6309
|
status
|
|
6228
6310
|
});
|
|
6229
6311
|
if (!entity) return null;
|
|
6230
|
-
|
|
6312
|
+
const sanitizedEntity = await strapi2.contentAPI.sanitize.output(entity, contentType, { auth });
|
|
6313
|
+
let cleanEntity = cleanRootKeys(sanitizedEntity);
|
|
6231
6314
|
cleanEntity = removeWaFields(cleanEntity);
|
|
6232
6315
|
cleanEntity = await enrichWebatlasData(cleanEntity, route2.relatedContentType);
|
|
6233
6316
|
if (breadcrumb) {
|
|
6234
|
-
cleanEntity = await addWebatlasBreadcrumb(cleanEntity, route2);
|
|
6317
|
+
cleanEntity = await addWebatlasBreadcrumb(cleanEntity, route2, status);
|
|
6235
6318
|
}
|
|
6236
|
-
cleanEntity = await enrichRoutePickerFields(cleanEntity, contentTypeKey);
|
|
6319
|
+
cleanEntity = await enrichRoutePickerFields(cleanEntity, contentTypeKey, status);
|
|
6237
6320
|
return {
|
|
6238
6321
|
contentType: contentType.info.singularName,
|
|
6239
6322
|
...cleanEntity
|
|
@@ -6286,6 +6369,7 @@ const client = ({ strapi: strapi2 }) => ({
|
|
|
6286
6369
|
}
|
|
6287
6370
|
}
|
|
6288
6371
|
if (!navigation2) return null;
|
|
6372
|
+
if (navigation2.items) navigation2.items = await removeUnpublishedNavItems(navigation2.items);
|
|
6289
6373
|
const structured = buildStructuredNavigation(navigation2, variant);
|
|
6290
6374
|
if (!structured) return null;
|
|
6291
6375
|
const entityNavigation = extractRouteAndItems(structured.items);
|
package/dist/server/index.mjs
CHANGED
|
@@ -182,6 +182,7 @@ function buildStructuredNavigation(navigation2, variant = "nested") {
|
|
|
182
182
|
itemsById.set(item.documentId, newItem);
|
|
183
183
|
itemsProcessed.add(item.documentId);
|
|
184
184
|
});
|
|
185
|
+
if (remainingItems.length === itemsToProcess.length) break;
|
|
185
186
|
itemsToProcess = remainingItems;
|
|
186
187
|
}
|
|
187
188
|
const sortedItems = sortItems(rootItems);
|
|
@@ -4669,7 +4670,8 @@ async function enrichWebatlasData(data, contentTypeUid) {
|
|
|
4669
4670
|
}
|
|
4670
4671
|
return ids;
|
|
4671
4672
|
};
|
|
4672
|
-
const
|
|
4673
|
+
const items = Array.isArray(data) ? data : [data];
|
|
4674
|
+
const documentIds = items.flatMap((item) => collectDocumentIds(item, contentTypeUid));
|
|
4673
4675
|
if (documentIds.length === 0) return data;
|
|
4674
4676
|
const uniqueDocumentIds = [...new Set(documentIds)];
|
|
4675
4677
|
const routes2 = await strapi.db?.query(waRoute).findMany({
|
|
@@ -4725,7 +4727,7 @@ async function enrichWebatlasData(data, contentTypeUid) {
|
|
|
4725
4727
|
}
|
|
4726
4728
|
return entity;
|
|
4727
4729
|
};
|
|
4728
|
-
return enrichEntity2(data, contentTypeUid);
|
|
4730
|
+
return Array.isArray(data) ? data.map((item) => enrichEntity2(item, contentTypeUid)) : enrichEntity2(data, contentTypeUid);
|
|
4729
4731
|
}
|
|
4730
4732
|
function isExternalUrl(value) {
|
|
4731
4733
|
return !/^[a-z0-9]+$/.test(value);
|
|
@@ -4787,6 +4789,8 @@ function enrichEntity(entity, uid, routeMap) {
|
|
|
4787
4789
|
`Wrapper route detected in route-picker field '${key}'. Wrapper routes cannot be used as page links. Setting to null.`
|
|
4788
4790
|
);
|
|
4789
4791
|
entity[key] = null;
|
|
4792
|
+
} else if (route2.isUnpublished) {
|
|
4793
|
+
entity[key] = null;
|
|
4790
4794
|
} else {
|
|
4791
4795
|
entity[key] = route2.canonicalPath || route2.path || value;
|
|
4792
4796
|
}
|
|
@@ -4822,20 +4826,36 @@ function enrichEntity(entity, uid, routeMap) {
|
|
|
4822
4826
|
}
|
|
4823
4827
|
return entity;
|
|
4824
4828
|
}
|
|
4825
|
-
async function enrichRoutePickerFields(data, contentTypeUid) {
|
|
4829
|
+
async function enrichRoutePickerFields(data, contentTypeUid, status = "published") {
|
|
4826
4830
|
if (!data || typeof data !== "object") return data;
|
|
4827
|
-
const
|
|
4831
|
+
const items = Array.isArray(data) ? data : [data];
|
|
4832
|
+
const documentIds = items.flatMap((item) => collectRoutePickerIds(item, contentTypeUid));
|
|
4828
4833
|
if (documentIds.length === 0) return data;
|
|
4829
4834
|
const uniqueDocumentIds = [...new Set(documentIds)];
|
|
4830
4835
|
const routes2 = await strapi.db?.query(waRoute).findMany({
|
|
4831
4836
|
where: {
|
|
4832
4837
|
documentId: { $in: uniqueDocumentIds }
|
|
4833
4838
|
},
|
|
4834
|
-
select: [
|
|
4839
|
+
select: [
|
|
4840
|
+
"documentId",
|
|
4841
|
+
"path",
|
|
4842
|
+
"canonicalPath",
|
|
4843
|
+
"type",
|
|
4844
|
+
"relatedContentType",
|
|
4845
|
+
"relatedDocumentId"
|
|
4846
|
+
]
|
|
4835
4847
|
});
|
|
4836
|
-
const
|
|
4837
|
-
const
|
|
4838
|
-
|
|
4848
|
+
const publishedDocumentIds = status === "published" ? await getPublishedDocumentIds(routes2 || []) : null;
|
|
4849
|
+
const routeMap = new Map(
|
|
4850
|
+
routes2?.map((route2) => [
|
|
4851
|
+
route2.documentId,
|
|
4852
|
+
{
|
|
4853
|
+
...route2,
|
|
4854
|
+
isUnpublished: publishedDocumentIds && route2.relatedContentType && !publishedDocumentIds.has(route2.relatedDocumentId)
|
|
4855
|
+
}
|
|
4856
|
+
]) || []
|
|
4857
|
+
);
|
|
4858
|
+
return Array.isArray(data) ? data.map((item) => enrichEntity(item, contentTypeUid, routeMap)) : enrichEntity(data, contentTypeUid, routeMap);
|
|
4839
4859
|
}
|
|
4840
4860
|
function isBlacklistedPath(url, routeBlacklist) {
|
|
4841
4861
|
if (!url) return false;
|
|
@@ -4901,18 +4921,67 @@ function toBreadcrumbEntry(route2) {
|
|
|
4901
4921
|
title: route2.title
|
|
4902
4922
|
};
|
|
4903
4923
|
}
|
|
4904
|
-
async function addWebatlasBreadcrumb(data, route2) {
|
|
4924
|
+
async function addWebatlasBreadcrumb(data, route2, status = "published") {
|
|
4905
4925
|
if (!data?.webatlas || !route2) return data;
|
|
4906
4926
|
const segments = route2.canonicalPath?.split("/").filter(Boolean) || [];
|
|
4907
4927
|
const ancestorPaths = segments.slice(0, -1).map((_, i) => segments.slice(0, i + 1).join("/"));
|
|
4908
4928
|
const ancestors = ancestorPaths.length ? await strapi.db.query(waRoute).findMany({
|
|
4909
4929
|
where: { canonicalPath: { $in: ancestorPaths } },
|
|
4910
|
-
select: [
|
|
4930
|
+
select: [
|
|
4931
|
+
"path",
|
|
4932
|
+
"canonicalPath",
|
|
4933
|
+
"slug",
|
|
4934
|
+
"uidPath",
|
|
4935
|
+
"title",
|
|
4936
|
+
"relatedContentType",
|
|
4937
|
+
"relatedDocumentId"
|
|
4938
|
+
]
|
|
4911
4939
|
}) : [];
|
|
4912
|
-
const
|
|
4940
|
+
const publishedDocumentIds = status === "published" ? await getPublishedDocumentIds(ancestors) : null;
|
|
4941
|
+
const isVisible = (ancestor) => !publishedDocumentIds || !ancestor.relatedContentType || publishedDocumentIds.has(ancestor.relatedDocumentId);
|
|
4942
|
+
const orderedAncestors = ancestorPaths.map((path) => ancestors.find((ancestor) => ancestor.canonicalPath === path)).filter((ancestor) => ancestor && isVisible(ancestor));
|
|
4913
4943
|
data.webatlas.breadcrumb = [...orderedAncestors, route2].map(toBreadcrumbEntry);
|
|
4914
4944
|
return data;
|
|
4915
4945
|
}
|
|
4946
|
+
async function removeUnpublishedNavItems(items) {
|
|
4947
|
+
const publishedDocumentIds = await getPublishedDocumentIds(items.map((item) => item.route));
|
|
4948
|
+
const removedItemIds = new Set(
|
|
4949
|
+
items.filter(
|
|
4950
|
+
({ route: route2 }) => route2?.relatedContentType && !publishedDocumentIds.has(route2.relatedDocumentId)
|
|
4951
|
+
).map((item) => item.documentId)
|
|
4952
|
+
);
|
|
4953
|
+
let foundDescendant = removedItemIds.size > 0;
|
|
4954
|
+
while (foundDescendant) {
|
|
4955
|
+
foundDescendant = false;
|
|
4956
|
+
for (const item of items) {
|
|
4957
|
+
if (item.parent && removedItemIds.has(item.parent.documentId) && !removedItemIds.has(item.documentId)) {
|
|
4958
|
+
removedItemIds.add(item.documentId);
|
|
4959
|
+
foundDescendant = true;
|
|
4960
|
+
}
|
|
4961
|
+
}
|
|
4962
|
+
}
|
|
4963
|
+
return items.filter((item) => !removedItemIds.has(item.documentId));
|
|
4964
|
+
}
|
|
4965
|
+
async function getPublishedDocumentIds(routes2) {
|
|
4966
|
+
const documentIdsByUid = /* @__PURE__ */ new Map();
|
|
4967
|
+
for (const route2 of routes2) {
|
|
4968
|
+
if (!route2?.relatedContentType) continue;
|
|
4969
|
+
const documentIds = documentIdsByUid.get(route2.relatedContentType) ?? [];
|
|
4970
|
+
documentIds.push(route2.relatedDocumentId);
|
|
4971
|
+
documentIdsByUid.set(route2.relatedContentType, documentIds);
|
|
4972
|
+
}
|
|
4973
|
+
const publishedDocumentIds = /* @__PURE__ */ new Set();
|
|
4974
|
+
for (const [uid, documentIds] of documentIdsByUid) {
|
|
4975
|
+
if (!strapi.contentTypes[uid]) continue;
|
|
4976
|
+
const entries = await strapi.documents(uid).findMany({
|
|
4977
|
+
filters: { documentId: { $in: documentIds } },
|
|
4978
|
+
fields: ["documentId"],
|
|
4979
|
+
status: "published"
|
|
4980
|
+
});
|
|
4981
|
+
entries.forEach((entry) => publishedDocumentIds.add(entry.documentId));
|
|
4982
|
+
}
|
|
4983
|
+
return publishedDocumentIds;
|
|
4984
|
+
}
|
|
4916
4985
|
const migration_001_canonical_path = {
|
|
4917
4986
|
version: "001",
|
|
4918
4987
|
description: "Migrate title field to canonicalPath using transformToUrl",
|
|
@@ -5175,11 +5244,17 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
|
|
|
5175
5244
|
return next();
|
|
5176
5245
|
}
|
|
5177
5246
|
const ctSettings = config2.selectedContentTypes.find((ct) => ct.uid === context.uid);
|
|
5247
|
+
const requestContext = strapi2.requestContext.get();
|
|
5248
|
+
const isRouteDataAllowed = !requestContext || requestContext.state?.route?.info?.type === "admin";
|
|
5249
|
+
if ((context.action === "create" || context.action === "update") && !isRouteDataAllowed) {
|
|
5250
|
+
delete context.params.data?.webatlas;
|
|
5251
|
+
}
|
|
5178
5252
|
if (context.action === "create") {
|
|
5179
5253
|
const data = context.params.data;
|
|
5180
5254
|
const { webatlas } = data;
|
|
5181
5255
|
const { slug, parentDocumentId, isOverride } = webatlas || {};
|
|
5182
5256
|
const transformedSlug = slug ? transformToUrl(slug, !isOverride) : null;
|
|
5257
|
+
if (!transformedSlug) return next();
|
|
5183
5258
|
let parent = null;
|
|
5184
5259
|
let isValid = false;
|
|
5185
5260
|
if (parentDocumentId) {
|
|
@@ -5208,7 +5283,6 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
|
|
|
5208
5283
|
assertPathAllowed(rawPath, routeBlacklist);
|
|
5209
5284
|
assertPathAllowed(canonicalPath, routeBlacklist);
|
|
5210
5285
|
const result2 = await next();
|
|
5211
|
-
if (!transformedSlug) return result2;
|
|
5212
5286
|
const existing = await strapi2.db?.query(waRoute).findOne({
|
|
5213
5287
|
where: { relatedDocumentId: result2.documentId }
|
|
5214
5288
|
});
|
|
@@ -5381,15 +5455,7 @@ const addWebatlasField = ({ strapi: strapi2 }) => {
|
|
|
5381
5455
|
if (!contentTypeEntry) return;
|
|
5382
5456
|
const [contentTypeUid] = contentTypeEntry;
|
|
5383
5457
|
if (ctx.body.data) {
|
|
5384
|
-
|
|
5385
|
-
ctx.body.data = await Promise.all(
|
|
5386
|
-
ctx.body.data.map((item) => enrichWebatlasData(item, contentTypeUid))
|
|
5387
|
-
);
|
|
5388
|
-
} else {
|
|
5389
|
-
ctx.body.data = await enrichWebatlasData(ctx.body.data, contentTypeUid);
|
|
5390
|
-
}
|
|
5391
|
-
} else if (Array.isArray(ctx.body)) {
|
|
5392
|
-
ctx.body = await Promise.all(ctx.body.map((item) => enrichWebatlasData(item, contentTypeUid)));
|
|
5458
|
+
ctx.body.data = await enrichWebatlasData(ctx.body.data, contentTypeUid);
|
|
5393
5459
|
} else if (typeof ctx.body === "object") {
|
|
5394
5460
|
ctx.body = await enrichWebatlasData(ctx.body, contentTypeUid);
|
|
5395
5461
|
}
|
|
@@ -5412,20 +5478,11 @@ const enrichRoutePicker = ({ strapi: strapi2 }) => {
|
|
|
5412
5478
|
);
|
|
5413
5479
|
if (!contentTypeEntry) return;
|
|
5414
5480
|
const [contentTypeUid] = contentTypeEntry;
|
|
5481
|
+
const status = ctx.query?.status === "draft" ? "draft" : "published";
|
|
5415
5482
|
if (ctx.body.data) {
|
|
5416
|
-
|
|
5417
|
-
ctx.body.data = await Promise.all(
|
|
5418
|
-
ctx.body.data.map((item) => enrichRoutePickerFields(item, contentTypeUid))
|
|
5419
|
-
);
|
|
5420
|
-
} else {
|
|
5421
|
-
ctx.body.data = await enrichRoutePickerFields(ctx.body.data, contentTypeUid);
|
|
5422
|
-
}
|
|
5423
|
-
} else if (Array.isArray(ctx.body)) {
|
|
5424
|
-
ctx.body = await Promise.all(
|
|
5425
|
-
ctx.body.map((item) => enrichRoutePickerFields(item, contentTypeUid))
|
|
5426
|
-
);
|
|
5483
|
+
ctx.body.data = await enrichRoutePickerFields(ctx.body.data, contentTypeUid, status);
|
|
5427
5484
|
} else if (typeof ctx.body === "object") {
|
|
5428
|
-
ctx.body = await enrichRoutePickerFields(ctx.body, contentTypeUid);
|
|
5485
|
+
ctx.body = await enrichRoutePickerFields(ctx.body, contentTypeUid, status);
|
|
5429
5486
|
}
|
|
5430
5487
|
};
|
|
5431
5488
|
};
|
|
@@ -5738,14 +5795,20 @@ const admin$2 = () => ({
|
|
|
5738
5795
|
const client$2 = ({ strapi: strapi2 }) => ({
|
|
5739
5796
|
async getEntityByPath(ctx) {
|
|
5740
5797
|
const { slug, populate, populateDeepDepth, fields, status, breadcrumb } = ctx.query;
|
|
5741
|
-
if (!slug) throw new errors.ValidationError("Slug is required");
|
|
5798
|
+
if (typeof slug !== "string" || !slug) throw new errors.ValidationError("Slug is required");
|
|
5799
|
+
if (status !== void 0 && status !== "draft" && status !== "published")
|
|
5800
|
+
throw new errors.ValidationError('Status must be "draft" or "published"');
|
|
5801
|
+
const depth = populateDeepDepth === void 0 ? 5 : Number(populateDeepDepth);
|
|
5802
|
+
if (!Number.isInteger(depth) || depth < 1 || depth > 10)
|
|
5803
|
+
throw new errors.ValidationError("populateDeepDepth must be a number between 1 and 10");
|
|
5742
5804
|
const entity = await getClientService().getEntityByPath(
|
|
5743
5805
|
slug,
|
|
5744
5806
|
populate,
|
|
5745
|
-
|
|
5807
|
+
depth,
|
|
5746
5808
|
fields,
|
|
5747
5809
|
status,
|
|
5748
|
-
breadcrumb !== "false"
|
|
5810
|
+
breadcrumb !== "false",
|
|
5811
|
+
ctx.state.auth
|
|
5749
5812
|
);
|
|
5750
5813
|
if (!entity) throw new errors.NotFoundError("Entity not found");
|
|
5751
5814
|
return ctx.send(entity);
|
|
@@ -5754,6 +5817,14 @@ const client$2 = ({ strapi: strapi2 }) => ({
|
|
|
5754
5817
|
const { id, name, slug, documentId, variant } = ctx.query;
|
|
5755
5818
|
if (!id && !name && !slug && !documentId)
|
|
5756
5819
|
throw new errors.ValidationError("Navigation id, name, slug or documentId is required");
|
|
5820
|
+
for (const [key, value] of Object.entries({ id, name, slug, documentId })) {
|
|
5821
|
+
if (value !== void 0 && typeof value !== "string")
|
|
5822
|
+
throw new errors.ValidationError(`Navigation ${key} must be a string`);
|
|
5823
|
+
}
|
|
5824
|
+
if (id !== void 0 && !/^\d+$/.test(id))
|
|
5825
|
+
throw new errors.ValidationError("Navigation id must be a number");
|
|
5826
|
+
if (variant !== void 0 && variant !== "nested" && variant !== "flat")
|
|
5827
|
+
throw new errors.ValidationError('Variant must be "nested" or "flat"');
|
|
5757
5828
|
const navigation2 = await getClientService().getNavigation(id, name, slug, documentId, variant);
|
|
5758
5829
|
if (!navigation2) throw new errors.NotFoundError("Navigation not found");
|
|
5759
5830
|
return ctx.send(navigation2);
|
|
@@ -6193,7 +6264,7 @@ const admin = ({ strapi: strapi2 }) => ({
|
|
|
6193
6264
|
}
|
|
6194
6265
|
});
|
|
6195
6266
|
const client = ({ strapi: strapi2 }) => ({
|
|
6196
|
-
async getEntityByPath(slug, populate, populateDeepDepth, fields, status = "published", breadcrumb = true) {
|
|
6267
|
+
async getEntityByPath(slug, populate, populateDeepDepth, fields, status = "published", breadcrumb = true, auth) {
|
|
6197
6268
|
const route2 = await strapi2.documents(waRoute).findFirst({
|
|
6198
6269
|
filters: {
|
|
6199
6270
|
$or: [{ path: slug }, { canonicalPath: slug }, { uidPath: slug }]
|
|
@@ -6204,12 +6275,10 @@ const client = ({ strapi: strapi2 }) => ({
|
|
|
6204
6275
|
if (populate === "deep") {
|
|
6205
6276
|
const modelObject = getFullPopulateObject(
|
|
6206
6277
|
route2.relatedContentType,
|
|
6207
|
-
|
|
6278
|
+
populateDeepDepth,
|
|
6208
6279
|
[]
|
|
6209
6280
|
);
|
|
6210
|
-
|
|
6211
|
-
populateObject = modelObject.populate;
|
|
6212
|
-
}
|
|
6281
|
+
populateObject = typeof modelObject === "object" && "populate" in modelObject ? modelObject.populate : void 0;
|
|
6213
6282
|
}
|
|
6214
6283
|
const contentTypeObject = Object.entries(strapi2.contentTypes).find(
|
|
6215
6284
|
([key, value]) => key === route2.relatedContentType
|
|
@@ -6218,20 +6287,34 @@ const client = ({ strapi: strapi2 }) => ({
|
|
|
6218
6287
|
return null;
|
|
6219
6288
|
}
|
|
6220
6289
|
const [contentTypeKey, contentType] = contentTypeObject;
|
|
6290
|
+
const action = contentType.kind === "singleType" ? "find" : "findOne";
|
|
6291
|
+
try {
|
|
6292
|
+
await strapi2.auth.verify(auth, { scope: [`${contentTypeKey}.${action}`] });
|
|
6293
|
+
} catch {
|
|
6294
|
+
return null;
|
|
6295
|
+
}
|
|
6296
|
+
await strapi2.contentAPI.validate.query(
|
|
6297
|
+
{ populate: populate === "deep" ? void 0 : populate, fields },
|
|
6298
|
+
contentType,
|
|
6299
|
+
{ auth }
|
|
6300
|
+
);
|
|
6301
|
+
const sanitizedQuery = await strapi2.contentAPI.sanitize.query({ fields }, contentType, { auth });
|
|
6302
|
+
const sanitizedPopulate = populateObject ? await strapi2.contentAPI.sanitize.populate(populateObject, contentType, { auth }) : void 0;
|
|
6221
6303
|
const entity = await strapi2.documents(route2.relatedContentType).findOne({
|
|
6222
6304
|
documentId: route2.relatedDocumentId,
|
|
6223
|
-
populate:
|
|
6224
|
-
fields,
|
|
6305
|
+
populate: sanitizedPopulate,
|
|
6306
|
+
fields: sanitizedQuery.fields,
|
|
6225
6307
|
status
|
|
6226
6308
|
});
|
|
6227
6309
|
if (!entity) return null;
|
|
6228
|
-
|
|
6310
|
+
const sanitizedEntity = await strapi2.contentAPI.sanitize.output(entity, contentType, { auth });
|
|
6311
|
+
let cleanEntity = cleanRootKeys(sanitizedEntity);
|
|
6229
6312
|
cleanEntity = removeWaFields(cleanEntity);
|
|
6230
6313
|
cleanEntity = await enrichWebatlasData(cleanEntity, route2.relatedContentType);
|
|
6231
6314
|
if (breadcrumb) {
|
|
6232
|
-
cleanEntity = await addWebatlasBreadcrumb(cleanEntity, route2);
|
|
6315
|
+
cleanEntity = await addWebatlasBreadcrumb(cleanEntity, route2, status);
|
|
6233
6316
|
}
|
|
6234
|
-
cleanEntity = await enrichRoutePickerFields(cleanEntity, contentTypeKey);
|
|
6317
|
+
cleanEntity = await enrichRoutePickerFields(cleanEntity, contentTypeKey, status);
|
|
6235
6318
|
return {
|
|
6236
6319
|
contentType: contentType.info.singularName,
|
|
6237
6320
|
...cleanEntity
|
|
@@ -6284,6 +6367,7 @@ const client = ({ strapi: strapi2 }) => ({
|
|
|
6284
6367
|
}
|
|
6285
6368
|
}
|
|
6286
6369
|
if (!navigation2) return null;
|
|
6370
|
+
if (navigation2.items) navigation2.items = await removeUnpublishedNavItems(navigation2.items);
|
|
6287
6371
|
const structured = buildStructuredNavigation(navigation2, variant);
|
|
6288
6372
|
if (!structured) return null;
|
|
6289
6373
|
const entityNavigation = extractRouteAndItems(structured.items);
|
|
@@ -98,7 +98,7 @@ declare const _default: {
|
|
|
98
98
|
client: ({ strapi }: {
|
|
99
99
|
strapi: any;
|
|
100
100
|
}) => {
|
|
101
|
-
getEntityByPath(slug: string, populate: string, populateDeepDepth:
|
|
101
|
+
getEntityByPath(slug: string, populate: string, populateDeepDepth: number, fields: any, status?: "published" | "draft", breadcrumb?: boolean, auth?: any): Promise<any>;
|
|
102
102
|
getNavigation(id: string, name: string, slug: string, documentId: string, variant?: import('../../types').StructuredNavigationVariant): Promise<{
|
|
103
103
|
items: {
|
|
104
104
|
depth: any;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@mattisvensson/strapi-plugin-webatlas",
|
|
3
3
|
"description": "A strapi plugin to manage URL routes and navigations.",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "0.12.
|
|
5
|
+
"version": "0.12.2",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"strapi",
|
|
8
8
|
"plugin",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"watch": "strapi-plugin watch",
|
|
38
38
|
"watch:link": "strapi-plugin watch:link",
|
|
39
39
|
"verify": "strapi-plugin verify",
|
|
40
|
-
"test:ts:front": "tsc -p admin/tsconfig.json",
|
|
41
|
-
"test:ts:back": "tsc -p server/tsconfig.json",
|
|
40
|
+
"test:ts:front": "tsc -p admin/tsconfig.json --noEmit",
|
|
41
|
+
"test:ts:back": "tsc -p server/tsconfig.json --noEmit",
|
|
42
42
|
"test:jest": "ENV_PATH=./playground/.env jest --verbose --runInBand --forceExit",
|
|
43
43
|
"test:cypress": "cypress run",
|
|
44
44
|
"test:cypress:open": "cypress open",
|