@mattisvensson/strapi-plugin-webatlas 0.10.1 → 0.11.1

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.
Files changed (50) hide show
  1. package/README.md +16 -9
  2. package/dist/admin/{FullLoader-CrPED_dY.mjs → FullLoader-Btjb2W2p.mjs} +5 -1
  3. package/dist/admin/FullLoader-Btjb2W2p.mjs.map +1 -0
  4. package/dist/admin/{FullLoader-Cmsf8xS6.js → FullLoader-Da2n70bJ.js} +5 -1
  5. package/dist/admin/FullLoader-Da2n70bJ.js.map +1 -0
  6. package/dist/admin/{SettingTitle-uw1S5OmC.js → SettingTitle-B0quw3f8.js} +6 -2
  7. package/dist/admin/SettingTitle-B0quw3f8.js.map +1 -0
  8. package/dist/admin/{SettingTitle-DbsxB1V9.mjs → SettingTitle-HMfQOJnK.mjs} +6 -2
  9. package/dist/admin/SettingTitle-HMfQOJnK.mjs.map +1 -0
  10. package/dist/admin/de-B5pRvs13.mjs +1 -0
  11. package/dist/admin/de-B5pRvs13.mjs.map +1 -0
  12. package/dist/admin/de-CqU1FU8C.js +1 -0
  13. package/dist/admin/de-CqU1FU8C.js.map +1 -0
  14. package/dist/admin/en-BE-zzIv8.mjs +1 -0
  15. package/dist/admin/en-BE-zzIv8.mjs.map +1 -0
  16. package/dist/admin/en-C7I90FwV.js +1 -0
  17. package/dist/admin/en-C7I90FwV.js.map +1 -0
  18. package/dist/admin/{index-BKWY9Ta-.mjs → index-9_HhKDUC.mjs} +32 -58
  19. package/dist/admin/index-9_HhKDUC.mjs.map +1 -0
  20. package/dist/admin/{index-CIr8o1RP.mjs → index-B79ELMEC.mjs} +300 -282
  21. package/dist/admin/index-B79ELMEC.mjs.map +1 -0
  22. package/dist/admin/{index-DkqiqVx2.js → index-BEVoxEAm.js} +32 -58
  23. package/dist/admin/index-BEVoxEAm.js.map +1 -0
  24. package/dist/admin/index-Bmg-ERct.mjs +244 -0
  25. package/dist/admin/index-Bmg-ERct.mjs.map +1 -0
  26. package/dist/admin/{index-BXt-QjKo.js → index-C8YjuuOx.js} +497 -353
  27. package/dist/admin/index-C8YjuuOx.js.map +1 -0
  28. package/dist/admin/{index-DC5WwNdi.js → index-Cx_mktdk.js} +300 -282
  29. package/dist/admin/index-Cx_mktdk.js.map +1 -0
  30. package/dist/admin/{index-CUaBX_v-.mjs → index-Cz_k_jjp.mjs} +42 -30
  31. package/dist/admin/index-Cz_k_jjp.mjs.map +1 -0
  32. package/dist/admin/{index-BYlmJycd.js → index-D2hB1vTw.js} +42 -30
  33. package/dist/admin/index-D2hB1vTw.js.map +1 -0
  34. package/dist/admin/index-YdWxpvOH.js +244 -0
  35. package/dist/admin/index-YdWxpvOH.js.map +1 -0
  36. package/dist/admin/{index-tPrfjOIn.mjs → index-oEJT_mvw.mjs} +497 -353
  37. package/dist/admin/index-oEJT_mvw.mjs.map +1 -0
  38. package/dist/admin/index.js +2 -1
  39. package/dist/admin/index.js.map +1 -0
  40. package/dist/admin/index.mjs +2 -1
  41. package/dist/admin/index.mjs.map +1 -0
  42. package/dist/server/index.js +578 -394
  43. package/dist/server/index.js.map +1 -0
  44. package/dist/server/index.mjs +578 -394
  45. package/dist/server/index.mjs.map +1 -0
  46. package/package.json +108 -108
  47. package/dist/admin/index-B07KlG03.mjs +0 -218
  48. package/dist/admin/index-CGsC8P9P.js +0 -218
  49. package/dist/admin/src/index.d.ts +0 -12
  50. package/dist/server/src/index.d.ts +0 -301
@@ -23,18 +23,25 @@ const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
23
23
  );
24
24
  });
25
25
  };
26
- function transformToUrl(input) {
26
+ function transformToUrl(input, replaceSlash = true) {
27
27
  const specialCharMap = {
28
- "ü": "ue",
29
- "ä": "ae",
30
- "ö": "oe"
28
+ ü: "ue",
29
+ ä: "ae",
30
+ ö: "oe",
31
+ ß: "ss"
31
32
  };
32
33
  if (!input || typeof input !== "string") return "";
33
34
  input = input.toLowerCase();
34
35
  input = input.replace(/\/+/g, "/");
35
36
  input = input.startsWith("/") ? input.slice(1) : input;
36
37
  input = input.endsWith("/") ? input.slice(0, -1) : input;
37
- input = input.replace(/\//g, "-");
38
+ if (replaceSlash) {
39
+ input = input.replace(/\//g, "-");
40
+ } else {
41
+ input = input.replace(/\/+/g, "/");
42
+ input = input.startsWith("/") ? input.slice(1) : input;
43
+ input = input.endsWith("/") ? input.slice(0, -1) : input;
44
+ }
38
45
  for (const char in specialCharMap) {
39
46
  const regex = new RegExp(char, "g");
40
47
  input = input.replace(regex, specialCharMap[char]);
@@ -45,7 +52,7 @@ function transformToUrl(input) {
45
52
  input = input.replace(/-+/g, "-");
46
53
  return input;
47
54
  }
48
- const version = "0.10.0";
55
+ const version = "0.11.1";
49
56
  const strapi$1 = { "name": "webatlas", "displayName": "Webatlas" };
50
57
  const pluginPkg = {
51
58
  version,
@@ -100,7 +107,9 @@ function useApi() {
100
107
  const entityResults = await Promise.allSettled(
101
108
  contentTypes.map(async (contentType) => {
102
109
  try {
103
- const { data: data2 } = await get(`/content-manager/collection-types/${contentType.uid}?pageSize=9999`);
110
+ const { data: data2 } = await get(
111
+ `/content-manager/collection-types/${contentType.uid}?pageSize=9999`
112
+ );
104
113
  if (!data2 || !data2.results) {
105
114
  return null;
106
115
  }
@@ -134,14 +143,21 @@ function useApi() {
134
143
  return data;
135
144
  };
136
145
  const getProhibitedRouteIds = async (documentId) => {
137
- const { data } = await get(`/${PLUGIN_ID}/route/prohibitedIds/${documentId ? `${documentId}` : ""}`);
146
+ const { data } = await get(
147
+ `/${PLUGIN_ID}/route/prohibitedIds/${documentId ? `${documentId}` : ""}`
148
+ );
138
149
  return data;
139
150
  };
140
- const getNavigation = async ({ documentId, variant } = {}) => {
151
+ const getNavigation = async ({
152
+ documentId,
153
+ variant
154
+ } = {}) => {
141
155
  const query = [];
142
156
  if (documentId) query.push(`documentId=${documentId}`);
143
157
  if (variant) query.push(`variant=${variant}`);
144
- const { data } = await get(`/${PLUGIN_ID}/navigation${query.length > 0 ? `?${query.join("&")}` : ""}`);
158
+ const { data } = await get(
159
+ `/${PLUGIN_ID}/navigation${query.length > 0 ? `?${query.join("&")}` : ""}`
160
+ );
145
161
  return data;
146
162
  };
147
163
  const createNavigation = async (body) => {
@@ -212,7 +228,9 @@ function usePluginConfig() {
212
228
  setLoading(true);
213
229
  setFetchError(null);
214
230
  try {
215
- const { data: { data: contentTypesArray } } = await get("/content-manager/content-types");
231
+ const {
232
+ data: { data: contentTypesArray }
233
+ } = await get("/content-manager/content-types");
216
234
  let { data: config2 } = await get(`/${PLUGIN_ID}/config`);
217
235
  if (!config2 || !config2.selectedContentTypes) {
218
236
  throw new Error(`Couldn't fetch plugin config`);
@@ -221,7 +239,9 @@ function usePluginConfig() {
221
239
  (type) => type.pluginOptions?.webatlas?.enabled === true
222
240
  );
223
241
  const contentTypeUids = new Set(allowedContentTypes.map((type) => type.uid));
224
- const activeContentTypes = config2.selectedContentTypes.filter((type) => contentTypeUids.has(type.uid));
242
+ const activeContentTypes = config2.selectedContentTypes.filter(
243
+ (type) => contentTypeUids.has(type.uid)
244
+ );
225
245
  const displayConfig = {
226
246
  ...config2,
227
247
  selectedContentTypes: activeContentTypes
@@ -264,7 +284,9 @@ async function duplicateCheck({
264
284
  if (!path) throw new Error("URL is required");
265
285
  try {
266
286
  const pathToCheck = withoutTransform ? path : transformToUrl(path);
267
- const { data } = await fetchFunction(`/${PLUGIN_ID}/checkUniquePath?path=${pathToCheck}${routeDocumentId ? `&targetRouteDocumentId=${routeDocumentId}` : ""}`);
287
+ const { data } = await fetchFunction(
288
+ `/${PLUGIN_ID}/checkUniquePath?path=${pathToCheck}${routeDocumentId ? `&targetRouteDocumentId=${routeDocumentId}` : ""}`
289
+ );
268
290
  if (!data.uniquePath) {
269
291
  throw new Error("Network response was not ok");
270
292
  }
@@ -282,45 +304,42 @@ function PathInfo({ validationState, replacement }) {
282
304
  if (validationState === "initial") return;
283
305
  if (validationState === "checking") {
284
306
  setColor("neutral800");
285
- setText(formatMessage({
286
- id: getTranslation("components.pathInfo.checking"),
287
- defaultMessage: "Checking if path is available..."
288
- }));
307
+ setText(
308
+ formatMessage({
309
+ id: getTranslation("components.pathInfo.checking"),
310
+ defaultMessage: "Checking if path is available..."
311
+ })
312
+ );
289
313
  } else if (validationState === "done") {
290
314
  setColor(replacement ? "danger500" : "success500");
291
- setText(replacement ? `${formatMessage({
292
- id: getTranslation("components.pathInfo.notAvailable"),
293
- defaultMessage: "Path is not available. Replaced with"
294
- })} "${replacement}".` : formatMessage({
295
- id: getTranslation("components.pathInfo.available"),
296
- defaultMessage: "Path is available."
297
- }));
315
+ setText(
316
+ replacement ? `${formatMessage({
317
+ id: getTranslation("components.pathInfo.notAvailable"),
318
+ defaultMessage: "Path is not available. Replaced with"
319
+ })} "${replacement}".` : formatMessage({
320
+ id: getTranslation("components.pathInfo.available"),
321
+ defaultMessage: "Path is available."
322
+ })
323
+ );
298
324
  }
299
325
  }, [validationState, replacement, formatMessage]);
300
326
  return /* @__PURE__ */ jsx(Box, { paddingTop: 1, children: /* @__PURE__ */ jsx(Typography, { textColor: color, children: text }) });
301
327
  }
302
328
  function OverrideCheckbox({ isOverride, setIsOverride, disabledCondition }) {
303
329
  const { formatMessage } = useIntl();
304
- return /* @__PURE__ */ jsx(
305
- Flex,
330
+ return /* @__PURE__ */ jsx(Flex, { gap: 2, paddingTop: 2, children: /* @__PURE__ */ jsx(
331
+ Checkbox,
306
332
  {
307
- gap: 2,
308
- paddingTop: 2,
309
- children: /* @__PURE__ */ jsx(
310
- Checkbox,
311
- {
312
- id: "path-override-checkbox",
313
- checked: isOverride,
314
- onCheckedChange: () => setIsOverride(!isOverride),
315
- disabled: disabledCondition,
316
- children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: formatMessage({
317
- id: getTranslation("components.CMEditViewAside.path.overrideCheckbox"),
318
- defaultMessage: "Override automatic path generation"
319
- }) })
320
- }
321
- )
333
+ id: "path-override-checkbox",
334
+ checked: isOverride,
335
+ onCheckedChange: () => setIsOverride(!isOverride),
336
+ disabled: disabledCondition,
337
+ children: /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: formatMessage({
338
+ id: getTranslation("components.CMEditViewAside.path.overrideCheckbox"),
339
+ defaultMessage: "Override automatic path generation"
340
+ }) })
322
341
  }
323
- );
342
+ ) });
324
343
  }
325
344
  function NewPathInfo() {
326
345
  const { formatMessage } = useIntl();
@@ -339,13 +358,7 @@ function UidPathDisplay({ path }) {
339
358
  defaultMessage: "Permanent UID path, cannot be changed"
340
359
  }),
341
360
  children: [
342
- /* @__PURE__ */ jsx(
343
- Field.Input,
344
- {
345
- value: path,
346
- disabled: true
347
- }
348
- ),
361
+ /* @__PURE__ */ jsx(Field.Input, { value: path, disabled: true }),
349
362
  /* @__PURE__ */ jsx(Field.Hint, {})
350
363
  ]
351
364
  }
@@ -3673,10 +3686,15 @@ function PathInput({ path, dispatchPath, isOverride, config }) {
3673
3686
  id: getTranslation("components.CMEditViewAside.path.input.label"),
3674
3687
  defaultMessage: "Path"
3675
3688
  }),
3676
- /* @__PURE__ */ jsx(Tooltip, { description: formatMessage({
3677
- id: getTranslation("components.CMEditViewAside.path.input.tooltip"),
3678
- defaultMessage: "The following characters are valid: A-Z, a-z, 0-9, /, -, _, $, ., +, !, *, ', (, )"
3679
- }) })
3689
+ /* @__PURE__ */ jsx(
3690
+ Tooltip,
3691
+ {
3692
+ description: formatMessage({
3693
+ id: getTranslation("components.CMEditViewAside.path.input.tooltip"),
3694
+ defaultMessage: "The following characters are valid: A-Z, a-z, 0-9, /, -, _, $, ., +, !, *, ', (, )"
3695
+ })
3696
+ }
3697
+ )
3680
3698
  ] }),
3681
3699
  /* @__PURE__ */ jsx(
3682
3700
  Field.Input,
@@ -3685,10 +3703,10 @@ function PathInput({ path, dispatchPath, isOverride, config }) {
3685
3703
  value: displayedPath,
3686
3704
  onChange: (e) => dispatchPath({ type: "SET_OVERRIDEPATH", payload: e.target.value }),
3687
3705
  disabled: !isOverride,
3688
- onBlur: (e) => {
3689
- if (e.target.value === path.prevValue) return;
3690
- dispatchPath({ type: "DEFAULT", payload: e.target.value });
3691
- },
3706
+ onBlur: (e) => dispatchPath({
3707
+ type: "SET_OVERRIDEPATH",
3708
+ payload: transformToUrl(e.target.value, false)
3709
+ }),
3692
3710
  style: { outline: inputBorder }
3693
3711
  }
3694
3712
  ),
@@ -3697,11 +3715,19 @@ function PathInput({ path, dispatchPath, isOverride, config }) {
3697
3715
  }
3698
3716
  );
3699
3717
  }
3700
- function RouteStructure({ routes, selectedParent, setSelectedParent, canonicalPath, prohibitedRouteIds }) {
3718
+ function RouteStructure({
3719
+ routes,
3720
+ selectedParent,
3721
+ setSelectedParent,
3722
+ canonicalPath,
3723
+ prohibitedRouteIds
3724
+ }) {
3701
3725
  const { formatMessage } = useIntl();
3702
- const sortedRoutes = useMemo(() => {
3703
- return [...routes].sort((a, b) => a.title.localeCompare(b.title));
3704
- }, [routes]);
3726
+ const filteredRoutes = useMemo(() => {
3727
+ return [...routes].sort((a, b) => a.title.localeCompare(b.title)).filter(
3728
+ (route) => !prohibitedRouteIds?.includes(route.documentId) || route.documentId === selectedParent?.documentId
3729
+ );
3730
+ }, [routes, prohibitedRouteIds, selectedParent]);
3705
3731
  const handleSelectParent = (value) => {
3706
3732
  const parentRoute = routes.find((route) => route.documentId === value) || null;
3707
3733
  setSelectedParent(parentRoute);
@@ -3712,29 +3738,13 @@ function RouteStructure({ routes, selectedParent, setSelectedParent, canonicalPa
3712
3738
  id: getTranslation("components.CMEditViewAside.path.input.parentSelect.label"),
3713
3739
  defaultMessage: "Place under"
3714
3740
  }) }),
3715
- /* @__PURE__ */ jsxs(
3716
- SingleSelect,
3717
- {
3718
- value: selectedParent?.documentId || "",
3719
- onValueChange: handleSelectParent,
3720
- children: [
3721
- /* @__PURE__ */ jsx(SingleSelectOption, { value: "", children: formatMessage({
3722
- id: getTranslation("components.CMEditViewAside.path.input.parentSelect.rootPath"),
3723
- defaultMessage: "None (root path)"
3724
- }) }),
3725
- sortedRoutes.filter((route) => !prohibitedRouteIds?.includes(route.documentId) || route.documentId === selectedParent?.documentId).map(
3726
- (route) => /* @__PURE__ */ jsx(
3727
- SingleSelectOption,
3728
- {
3729
- value: route.documentId,
3730
- children: route.title
3731
- },
3732
- route.documentId
3733
- )
3734
- )
3735
- ]
3736
- }
3737
- )
3741
+ /* @__PURE__ */ jsxs(SingleSelect, { value: selectedParent?.documentId || "", onValueChange: handleSelectParent, children: [
3742
+ /* @__PURE__ */ jsx(SingleSelectOption, { value: "", children: formatMessage({
3743
+ id: getTranslation("components.CMEditViewAside.path.input.parentSelect.rootPath"),
3744
+ defaultMessage: "None (root path)"
3745
+ }) }),
3746
+ filteredRoutes.map((route) => /* @__PURE__ */ jsx(SingleSelectOption, { value: route.documentId, children: route.title }, route.documentId))
3747
+ ] })
3738
3748
  ] }),
3739
3749
  /* @__PURE__ */ jsxs(Field.Root, { marginTop: 4, children: [
3740
3750
  /* @__PURE__ */ jsxs(Field.Label, { children: [
@@ -3742,26 +3752,25 @@ function RouteStructure({ routes, selectedParent, setSelectedParent, canonicalPa
3742
3752
  id: getTranslation("components.CMEditViewAside.canonicalPath.input.label"),
3743
3753
  defaultMessage: "Canonical Path"
3744
3754
  }),
3745
- /* @__PURE__ */ jsx(Tooltip, { description: formatMessage({
3746
- id: getTranslation("components.CMEditViewAside.canonicalPath.input.tooltip"),
3747
- defaultMessage: "The path determined by your content's natural hierarchy, independent of where it appears in navigation menus."
3748
- }) })
3755
+ /* @__PURE__ */ jsx(
3756
+ Tooltip,
3757
+ {
3758
+ description: formatMessage({
3759
+ id: getTranslation("components.CMEditViewAside.canonicalPath.input.tooltip"),
3760
+ defaultMessage: "The path determined by your content's natural hierarchy, independent of where it appears in navigation menus."
3761
+ })
3762
+ }
3763
+ )
3749
3764
  ] }),
3750
- /* @__PURE__ */ jsx(
3751
- Field.Input,
3752
- {
3753
- id: "canonicalPath-input",
3754
- value: canonicalPath,
3755
- disabled: true
3756
- }
3757
- ),
3765
+ /* @__PURE__ */ jsx(Field.Input, { id: "canonicalPath-input", value: canonicalPath, disabled: true }),
3758
3766
  /* @__PURE__ */ jsx(Field.Hint, {})
3759
3767
  ] })
3760
3768
  ] });
3761
3769
  }
3762
- function getCanonicalPath(selectedParent, sourceFieldValue) {
3763
- const parentPath = selectedParent ? selectedParent.canonicalPath + "/" : "";
3764
- return `${parentPath}${transformToUrl(sourceFieldValue)}`;
3770
+ function buildPath(type, slug, parent) {
3771
+ const parentSlug = type === "canonical" ? parent?.canonicalPath : parent?.path;
3772
+ const parentPath = parentSlug ? `${parentSlug}/` : "";
3773
+ return `${parentPath}${transformToUrl(slug)}`;
3765
3774
  }
3766
3775
  function reducer(state, action) {
3767
3776
  switch (action.type) {
@@ -3792,6 +3801,8 @@ function reducer(state, action) {
3792
3801
  return { ...state, replacement: action.payload };
3793
3802
  case "SET_UIDPATH":
3794
3803
  return { ...state, uidPath: action.payload };
3804
+ case "SET_SLUG":
3805
+ return { ...state, slug: action.payload };
3795
3806
  case "SET_CANONICALPATH":
3796
3807
  return { ...state, canonicalPath: action.payload };
3797
3808
  case "SET_OVERRIDEPATH":
@@ -3806,10 +3817,9 @@ const Panel = ({ config }) => {
3806
3817
  const { getRelatedRoute, getAllRoutes, getProhibitedRouteIds } = useApi();
3807
3818
  const { formatMessage } = useIntl();
3808
3819
  const { get } = useFetchClient();
3809
- const { allowedActions: {
3810
- canUpdate,
3811
- canCreate
3812
- } } = useRBAC([
3820
+ const {
3821
+ allowedActions: { canUpdate, canCreate }
3822
+ } = useRBAC([
3813
3823
  {
3814
3824
  action: "plugin::content-manager.explorer.update",
3815
3825
  subject: model,
@@ -3837,66 +3847,95 @@ const Panel = ({ config }) => {
3837
3847
  replacement: null,
3838
3848
  uidPath: "",
3839
3849
  canonicalPath: "",
3850
+ slug: "",
3840
3851
  overridePath: ""
3841
3852
  });
3842
3853
  const hasUserChangedField = useRef(false);
3854
+ const hasUserInteracted = useRef(false);
3843
3855
  const initialPath = useRef("");
3844
3856
  const prevSourceValueRef = useRef(null);
3845
- const sourceFieldValue = useMemo(() => {
3846
- const key = config?.default;
3847
- if (!key) return "";
3848
- const currentValue = values[key];
3849
- if (!currentValue) return "";
3850
- return currentValue;
3851
- }, [values, config]);
3852
- const debouncedCheckPath = useCallback(debounce(checkPath, 250), []);
3853
- const debouncedCheckCanonicalPath = useCallback(debounce(checkCanonicalPath, 250), []);
3857
+ const sourceFieldValue = values[config?.default] || "";
3858
+ const initialSourceFieldValue = initialValues[config?.default] || "";
3859
+ const latestCheckPathRef = useRef(checkPath);
3860
+ latestCheckPathRef.current = checkPath;
3861
+ const debouncedCheckPath = useRef(
3862
+ debounce((p, id) => latestCheckPathRef.current(p, id), 250)
3863
+ ).current;
3864
+ const latestCheckCanonicalRef = useRef(checkCanonicalPath);
3865
+ latestCheckCanonicalRef.current = checkCanonicalPath;
3866
+ const debouncedCheckCanonicalPath = useRef(
3867
+ debounce((p, id) => latestCheckCanonicalRef.current(p, id), 250)
3868
+ ).current;
3854
3869
  useEffect(() => {
3855
- if (isOverride) onChange("webatlas_path", path.overridePath);
3856
- onChange("webatlas_override", isOverride);
3857
- onChange("webatlas_parent", selectedParent?.documentId || null);
3858
- }, [path.value, path.overridePath, isOverride, selectedParent]);
3859
- const debouncedValueEffect = useMemo(() => debounce((currentValues) => {
3860
- const key = config?.default;
3861
- if (!key) return;
3862
- const currentValue = currentValues[key];
3863
- if (!currentValue) {
3864
- dispatchPath({ type: "NO_URL_CHECK", payload: "" });
3865
- return;
3866
- }
3867
- if (initialLoadComplete && (hasUserChangedField.current || !route) && prevSourceValueRef.current !== currentValue && !isOverride) {
3868
- const path2 = getCanonicalPath(selectedParent, currentValue);
3869
- if (currentValue === initialValues[key]) {
3870
- dispatchPath({ type: "NO_URL_CHECK", payload: path2 });
3871
- } else {
3872
- dispatchPath({ type: "DEFAULT", payload: path2 });
3873
- }
3874
- prevSourceValueRef.current = currentValue;
3870
+ async function fetchAllRoutes() {
3871
+ const allRoutes = await getAllRoutes();
3872
+ setRoutes(allRoutes);
3875
3873
  }
3876
- }, 500), [config?.default, initialValues, isOverride, initialLoadComplete, route, selectedParent]);
3874
+ fetchAllRoutes();
3875
+ }, []);
3877
3876
  useEffect(() => {
3878
- const key = config?.default;
3879
- if (!key) return;
3880
- const currentValue = values[key];
3881
- const initialValue = initialValues[key];
3882
- if (currentValue !== initialValue && currentValue && !isOverride) {
3883
- onChange("webatlas_path", transformToUrl(currentValue));
3877
+ const slug = transformToUrl(sourceFieldValue);
3878
+ const overridePath = transformToUrl(path.overridePath || "", false);
3879
+ const data = {
3880
+ path: isOverride ? overridePath : path.value,
3881
+ isOverride,
3882
+ parentDocumentId: selectedParent?.documentId || null,
3883
+ slug: isOverride ? overridePath : slug
3884
+ };
3885
+ if (hasUserChangedField.current || hasUserInteracted.current) {
3886
+ onChange("webatlas", data);
3884
3887
  }
3888
+ }, [
3889
+ path.value,
3890
+ path.overridePath,
3891
+ isOverride,
3892
+ selectedParent,
3893
+ sourceFieldValue,
3894
+ hasUserChangedField,
3895
+ hasUserInteracted
3896
+ ]);
3897
+ useEffect(() => {
3885
3898
  if (!initialLoadComplete) return;
3886
- if (currentValue !== initialValue) {
3899
+ if (sourceFieldValue !== initialSourceFieldValue) {
3887
3900
  hasUserChangedField.current = true;
3888
3901
  }
3889
- debouncedValueEffect(values);
3890
- }, [values, debouncedValueEffect, initialLoadComplete, selectedParent]);
3902
+ if (!sourceFieldValue) {
3903
+ dispatchPath({ type: "NO_URL_CHECK", payload: "" });
3904
+ return;
3905
+ }
3906
+ if (initialLoadComplete && (hasUserChangedField.current || !route) && prevSourceValueRef.current !== sourceFieldValue && !isOverride) {
3907
+ const newPath = buildPath("path", sourceFieldValue, selectedParent);
3908
+ const type = sourceFieldValue === initialSourceFieldValue ? "NO_URL_CHECK" : "DEFAULT";
3909
+ const slug = transformToUrl(sourceFieldValue);
3910
+ dispatchPath({ type, payload: newPath });
3911
+ dispatchPath({ type: "SET_SLUG", payload: slug });
3912
+ dispatchPath({ type: "SET_OVERRIDEPATH", payload: slug });
3913
+ prevSourceValueRef.current = sourceFieldValue;
3914
+ }
3915
+ const canonicalPath = buildPath("canonical", sourceFieldValue, selectedParent);
3916
+ dispatchPath({ type: "SET_CANONICALPATH", payload: canonicalPath });
3917
+ debouncedCheckCanonicalPath(canonicalPath, route?.documentId || null);
3918
+ }, [
3919
+ sourceFieldValue,
3920
+ initialSourceFieldValue,
3921
+ initialLoadComplete,
3922
+ selectedParent,
3923
+ isOverride,
3924
+ route
3925
+ ]);
3891
3926
  useEffect(() => {
3927
+ if (!initialLoadComplete) return;
3892
3928
  if (path.needsUrlCheck && path.value) {
3893
3929
  if (path.uidPath === path.value || initialPath.current === path.value) return;
3894
3930
  debouncedCheckPath(path.value, route?.documentId || null);
3895
3931
  dispatchPath({ type: "RESET_URL_CHECK_FLAG" });
3932
+ } else {
3933
+ setValidationState("idle");
3934
+ dispatchPath({ type: "SET_REPLACEMENT", payload: null });
3896
3935
  }
3897
- }, [path.needsUrlCheck, path.value, path.uidPath, route]);
3936
+ }, [path.needsUrlCheck, path.value, path.uidPath, route, initialLoadComplete]);
3898
3937
  useEffect(() => {
3899
- async function getTypes() {
3938
+ async function fetchRelatedRute() {
3900
3939
  if (!initialValues.documentId) {
3901
3940
  setInitialLoadComplete(true);
3902
3941
  return;
@@ -3904,15 +3943,20 @@ const Panel = ({ config }) => {
3904
3943
  try {
3905
3944
  const route2 = await getRelatedRoute(initialValues.documentId);
3906
3945
  if (!route2) return;
3907
- initialPath.current = initialValues.webatlas_path || route2.uidPath;
3946
+ initialPath.current = initialValues.webatlas.path || route2.uidPath;
3908
3947
  setRoute(route2);
3909
3948
  setIsOverride(route2.isOverride || false);
3910
- if (route2.isOverride) {
3911
- dispatchPath({ type: "SET_OVERRIDEPATH", payload: route2.path || "" });
3912
- } else {
3913
- dispatchPath({ type: "NO_TRANSFORM_AND_CHECK", payload: route2.path || "" });
3914
- }
3949
+ dispatchPath({ type: "SET_OVERRIDEPATH", payload: route2.path || "" });
3950
+ dispatchPath({
3951
+ type: "NO_TRANSFORM_AND_CHECK",
3952
+ payload: route2.path || ""
3953
+ });
3915
3954
  dispatchPath({ type: "SET_UIDPATH", payload: route2.uidPath || "" });
3955
+ dispatchPath({ type: "SET_SLUG", payload: route2.slug || "" });
3956
+ dispatchPath({
3957
+ type: "SET_CANONICALPATH",
3958
+ payload: route2.canonicalPath || ""
3959
+ });
3916
3960
  const key = config?.default;
3917
3961
  if (key) {
3918
3962
  prevSourceValueRef.current = values[key];
@@ -3923,27 +3967,15 @@ const Panel = ({ config }) => {
3923
3967
  }
3924
3968
  setInitialLoadComplete(true);
3925
3969
  }
3926
- getTypes();
3970
+ fetchRelatedRute();
3927
3971
  }, [config]);
3928
3972
  useEffect(() => {
3929
- if (initialValues.webatlas_parent && routes.length > 0 && !selectedParent) {
3930
- const parentRoute = routes.find((route2) => route2.documentId === initialValues.webatlas_parent);
3931
- if (parentRoute) {
3932
- setSelectedParent(parentRoute);
3933
- const canonicalPath = getCanonicalPath(parentRoute, sourceFieldValue);
3934
- dispatchPath({ type: "DEFAULT", payload: canonicalPath });
3935
- }
3936
- }
3937
- }, [initialValues, routes]);
3938
- useEffect(() => {
3939
- if (initialValues.webatlas_path) dispatchPath({ type: "NO_URL_CHECK", payload: initialValues.webatlas_path });
3940
- if (initialValues.webatlas_override) setIsOverride(initialValues.webatlas_override);
3941
- async function fetchAllRoutes() {
3942
- const allRoutes = await getAllRoutes();
3943
- setRoutes(allRoutes);
3944
- }
3945
- fetchAllRoutes();
3946
- }, []);
3973
+ if (!route || !routes.length) return;
3974
+ const parentRoute = routes.find(
3975
+ (singleRoute) => singleRoute.documentId === route.parent?.documentId
3976
+ );
3977
+ setSelectedParent(parentRoute || null);
3978
+ }, [route, routes]);
3947
3979
  useEffect(() => {
3948
3980
  async function fetchProhibitedRouteIds() {
3949
3981
  const prohibitedIds = await getProhibitedRouteIds(route?.documentId);
@@ -3952,28 +3984,36 @@ const Panel = ({ config }) => {
3952
3984
  fetchProhibitedRouteIds();
3953
3985
  }, [route]);
3954
3986
  useEffect(() => {
3955
- if (!sourceFieldValue) return;
3956
- const canonicalPath = getCanonicalPath(selectedParent, sourceFieldValue);
3957
- !isOverride && dispatchPath({ type: "DEFAULT", payload: canonicalPath });
3958
- dispatchPath({ type: "SET_CANONICALPATH", payload: canonicalPath });
3959
- debouncedCheckCanonicalPath(canonicalPath, route?.documentId || null);
3960
- dispatchPath({ type: "RESET_URL_CHECK_FLAG" });
3987
+ if (!sourceFieldValue || isOverride || !hasUserChangedField.current && !hasUserInteracted.current)
3988
+ return;
3989
+ const newPath = buildPath("path", sourceFieldValue, selectedParent);
3990
+ dispatchPath({ type: "DEFAULT", payload: newPath });
3961
3991
  }, [selectedParent, sourceFieldValue, route, isOverride]);
3962
- async function checkCanonicalPath(path2, documentId) {
3992
+ async function checkCanonicalPath(path2, routeDocumentId) {
3963
3993
  if (!path2) return;
3964
3994
  try {
3965
- const result = await duplicateCheck({ fetchFunction: get, path: path2, routeDocumentId: documentId, withoutTransform: true });
3995
+ const result = await duplicateCheck({
3996
+ fetchFunction: get,
3997
+ path: path2,
3998
+ routeDocumentId,
3999
+ withoutTransform: true
4000
+ });
3966
4001
  dispatchPath({ type: "SET_CANONICALPATH", payload: result });
3967
4002
  } catch (err) {
3968
4003
  strapi.log.error(err);
3969
4004
  }
3970
4005
  }
3971
- async function checkPath(path2, route2) {
4006
+ async function checkPath(path2, routeDocumentId) {
3972
4007
  if (!path2) return;
3973
4008
  setValidationState("checking");
3974
4009
  dispatchPath({ type: "SET_REPLACEMENT", payload: "" });
3975
4010
  try {
3976
- const data = await duplicateCheck({ fetchFunction: get, path: path2, routeDocumentId: route2, withoutTransform: true });
4011
+ const data = await duplicateCheck({
4012
+ fetchFunction: get,
4013
+ path: path2,
4014
+ routeDocumentId,
4015
+ withoutTransform: true
4016
+ });
3977
4017
  if (!data || data === path2) return;
3978
4018
  dispatchPath({ type: "NO_URL_CHECK", payload: data });
3979
4019
  dispatchPath({ type: "SET_REPLACEMENT", payload: data });
@@ -3983,73 +4023,58 @@ const Panel = ({ config }) => {
3983
4023
  setValidationState("done");
3984
4024
  }
3985
4025
  }
3986
- if (!initialLoadComplete) return /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: formatMessage({
3987
- id: getTranslation("loading"),
3988
- defaultMessage: "Loading..."
3989
- }) });
3990
- return /* @__PURE__ */ jsx(
3991
- Box,
3992
- {
3993
- tag: "aside",
3994
- "aria-labelledby": "URL Route",
3995
- width: "100%",
3996
- children: /* @__PURE__ */ jsxs(
3997
- Flex,
4026
+ if (!initialLoadComplete)
4027
+ return /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: formatMessage({
4028
+ id: getTranslation("loading"),
4029
+ defaultMessage: "Loading..."
4030
+ }) });
4031
+ return /* @__PURE__ */ jsx(Box, { tag: "aside", "aria-labelledby": "URL Route", width: "100%", children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 1, children: [
4032
+ !route && /* @__PURE__ */ jsxs(Fragment$1, { children: [
4033
+ /* @__PURE__ */ jsx(NewPathInfo, {}),
4034
+ /* @__PURE__ */ jsx(Divider, { marginTop: 2, marginBottom: 2 })
4035
+ ] }),
4036
+ /* @__PURE__ */ jsx(
4037
+ RouteStructure,
4038
+ {
4039
+ canonicalPath: path.canonicalPath,
4040
+ routes,
4041
+ selectedParent,
4042
+ setSelectedParent: (val) => {
4043
+ hasUserInteracted.current = true;
4044
+ setSelectedParent(val);
4045
+ },
4046
+ prohibitedRouteIds
4047
+ }
4048
+ ),
4049
+ /* @__PURE__ */ jsx(Divider, { marginTop: 2, marginBottom: 2 }),
4050
+ /* @__PURE__ */ jsxs(Box, { children: [
4051
+ /* @__PURE__ */ jsx(
4052
+ PathInput,
3998
4053
  {
3999
- direction: "column",
4000
- alignItems: "stretch",
4001
- gap: 1,
4002
- children: [
4003
- !route && /* @__PURE__ */ jsxs(Fragment$1, { children: [
4004
- /* @__PURE__ */ jsx(NewPathInfo, {}),
4005
- /* @__PURE__ */ jsx(Divider, { marginTop: 2, marginBottom: 2 })
4006
- ] }),
4007
- /* @__PURE__ */ jsx(
4008
- RouteStructure,
4009
- {
4010
- canonicalPath: path.canonicalPath,
4011
- routes,
4012
- selectedParent,
4013
- setSelectedParent,
4014
- prohibitedRouteIds
4015
- }
4016
- ),
4017
- /* @__PURE__ */ jsx(Divider, { marginTop: 2, marginBottom: 2 }),
4018
- /* @__PURE__ */ jsxs(Box, { children: [
4019
- /* @__PURE__ */ jsx(
4020
- PathInput,
4021
- {
4022
- path,
4023
- dispatchPath,
4024
- isOverride,
4025
- config
4026
- }
4027
- ),
4028
- validationState !== "initial" && /* @__PURE__ */ jsx(
4029
- PathInfo,
4030
- {
4031
- validationState,
4032
- replacement: path.replacement
4033
- }
4034
- )
4035
- ] }),
4036
- /* @__PURE__ */ jsx(
4037
- OverrideCheckbox,
4038
- {
4039
- isOverride,
4040
- setIsOverride,
4041
- disabledCondition: !canCreate && !canUpdate
4042
- }
4043
- ),
4044
- path.uidPath && /* @__PURE__ */ jsxs(Fragment$1, { children: [
4045
- /* @__PURE__ */ jsx(Divider, { marginTop: 2, marginBottom: 2 }),
4046
- /* @__PURE__ */ jsx(UidPathDisplay, { path: path.uidPath })
4047
- ] })
4048
- ]
4054
+ path,
4055
+ dispatchPath,
4056
+ isOverride,
4057
+ config
4049
4058
  }
4050
- )
4051
- }
4052
- );
4059
+ ),
4060
+ validationState !== "initial" && /* @__PURE__ */ jsx(PathInfo, { validationState, replacement: path.replacement })
4061
+ ] }),
4062
+ /* @__PURE__ */ jsx(
4063
+ OverrideCheckbox,
4064
+ {
4065
+ isOverride,
4066
+ setIsOverride: (val) => {
4067
+ hasUserInteracted.current = true;
4068
+ setIsOverride(val);
4069
+ },
4070
+ disabledCondition: !canCreate && !canUpdate
4071
+ }
4072
+ ),
4073
+ path.uidPath && /* @__PURE__ */ jsxs(Fragment$1, { children: [
4074
+ /* @__PURE__ */ jsx(Divider, { marginTop: 2, marginBottom: 2 }),
4075
+ /* @__PURE__ */ jsx(UidPathDisplay, { path: path.uidPath })
4076
+ ] })
4077
+ ] }) });
4053
4078
  };
4054
4079
  const pluginPermissions = {
4055
4080
  "cm.aside": [{ action: `plugin::${PLUGIN_ID}.cm.aside`, subject: null }],
@@ -4058,7 +4083,7 @@ const pluginPermissions = {
4058
4083
  "settings.general": [{ action: `plugin::${PLUGIN_ID}.settings.general`, subject: null }],
4059
4084
  "settings.navigation": [{ action: `plugin::${PLUGIN_ID}.settings.navigation`, subject: null }]
4060
4085
  };
4061
- const CMEditViewAside = ({ documentId, model }) => {
4086
+ const CMEditViewAside = ({ documentId, model, activeTab }) => {
4062
4087
  const { contentTypes } = useAllContentTypes();
4063
4088
  const { config } = usePluginConfig();
4064
4089
  const { formatMessage } = useIntl();
@@ -4072,7 +4097,7 @@ const CMEditViewAside = ({ documentId, model }) => {
4072
4097
  setIsAllowedContentType(!!contentType?.pluginOptions?.webatlas?.enabled);
4073
4098
  }, [contentTypes, model]);
4074
4099
  useEffect(() => {
4075
- const isWebatlasLabel = (label) => label.textContent?.startsWith("webatlas_");
4100
+ const isWebatlasLabel = (label) => label.textContent?.startsWith("webatlas");
4076
4101
  const cleanupLabels = () => {
4077
4102
  const labels = document.querySelectorAll("label");
4078
4103
  labels.forEach((label) => {
@@ -4081,7 +4106,9 @@ const CMEditViewAside = ({ documentId, model }) => {
4081
4106
  const parent = container?.parentElement;
4082
4107
  const greatGrandParent = parent?.parentElement?.parentElement;
4083
4108
  if (!container || !parent) return;
4084
- const parentWebatlasCount = Array.from(parent.querySelectorAll("label")).filter(isWebatlasLabel).length;
4109
+ const parentWebatlasCount = Array.from(parent.querySelectorAll("label")).filter(
4110
+ isWebatlasLabel
4111
+ ).length;
4085
4112
  const childrenCount = parent.children.length;
4086
4113
  if (greatGrandParent && greatGrandParent?.querySelectorAll("label").length === Array.from(greatGrandParent.querySelectorAll("label")).filter(isWebatlasLabel).length) {
4087
4114
  greatGrandParent.remove();
@@ -4098,7 +4125,7 @@ const CMEditViewAside = ({ documentId, model }) => {
4098
4125
  return () => clearTimeout(secondTimeoutId);
4099
4126
  }, 100);
4100
4127
  return () => clearTimeout(timeoutId);
4101
- }, [documentId, model]);
4128
+ }, [documentId, model, activeTab]);
4102
4129
  useEffect(() => {
4103
4130
  if (!config) return;
4104
4131
  setIsActiveContentType(false);
@@ -4121,13 +4148,14 @@ const CMEditViewAside = ({ documentId, model }) => {
4121
4148
  strapi.log.error("CMEditViewAside: Plugin is not configured.");
4122
4149
  return null;
4123
4150
  }
4124
- if (isLoading) return {
4125
- title: panelTitle,
4126
- content: /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: formatMessage({
4127
- id: getTranslation("loading"),
4128
- defaultMessage: "Loading..."
4129
- }) })
4130
- };
4151
+ if (isLoading)
4152
+ return {
4153
+ title: panelTitle,
4154
+ content: /* @__PURE__ */ jsx(Typography, { textColor: "neutral600", children: formatMessage({
4155
+ id: getTranslation("loading"),
4156
+ defaultMessage: "Loading..."
4157
+ }) })
4158
+ };
4131
4159
  return {
4132
4160
  title: panelTitle,
4133
4161
  content: /* @__PURE__ */ jsx(Panel, { config: contentTypeConfig })
@@ -4142,10 +4170,8 @@ const index = {
4142
4170
  id: `${PLUGIN_ID}.link.paths`,
4143
4171
  defaultMessage: "Paths"
4144
4172
  },
4145
- Component: () => import("./index-BKWY9Ta-.mjs"),
4146
- permissions: [
4147
- pluginPermissions["page.routes"][0]
4148
- ]
4173
+ Component: () => import("./index-9_HhKDUC.mjs"),
4174
+ permissions: [pluginPermissions["page.routes"][0]]
4149
4175
  });
4150
4176
  app.addMenuLink({
4151
4177
  to: `plugins/${PLUGIN_ID}/navigation`,
@@ -4154,10 +4180,8 @@ const index = {
4154
4180
  id: `${PLUGIN_ID}.link.navigation`,
4155
4181
  defaultMessage: "Navigation"
4156
4182
  },
4157
- Component: () => import("./index-tPrfjOIn.mjs"),
4158
- permissions: [
4159
- pluginPermissions["page.navigation"][0]
4160
- ]
4183
+ Component: () => import("./index-oEJT_mvw.mjs"),
4184
+ permissions: [pluginPermissions["page.navigation"][0]]
4161
4185
  });
4162
4186
  app.addSettingsLink(
4163
4187
  {
@@ -4174,27 +4198,20 @@ const index = {
4174
4198
  },
4175
4199
  id: `${PLUGIN_ID}-general`,
4176
4200
  to: `${PLUGIN_ID}/general`,
4177
- Component: () => import("./index-B07KlG03.mjs"),
4178
- permissions: [
4179
- pluginPermissions["settings.general"][0]
4180
- ]
4181
- }
4182
- );
4183
- app.addSettingsLink(
4184
- PLUGIN_ID,
4185
- {
4186
- intlLabel: {
4187
- id: `${PLUGIN_ID}.settings.navigation`,
4188
- defaultMessage: "Navigation"
4189
- },
4190
- id: `${PLUGIN_ID}-navigation`,
4191
- to: `${PLUGIN_ID}/navigation`,
4192
- Component: () => import("./index-CUaBX_v-.mjs"),
4193
- permissions: [
4194
- pluginPermissions["settings.navigation"][0]
4195
- ]
4201
+ Component: () => import("./index-Bmg-ERct.mjs"),
4202
+ permissions: [pluginPermissions["settings.general"][0]]
4196
4203
  }
4197
4204
  );
4205
+ app.addSettingsLink(PLUGIN_ID, {
4206
+ intlLabel: {
4207
+ id: `${PLUGIN_ID}.settings.navigation`,
4208
+ defaultMessage: "Navigation"
4209
+ },
4210
+ id: `${PLUGIN_ID}-navigation`,
4211
+ to: `${PLUGIN_ID}/navigation`,
4212
+ Component: () => import("./index-Cz_k_jjp.mjs"),
4213
+ permissions: [pluginPermissions["settings.navigation"][0]]
4214
+ });
4198
4215
  app.registerPlugin({
4199
4216
  id: PLUGIN_ID,
4200
4217
  initializer: Initializer,
@@ -4233,3 +4250,4 @@ export {
4233
4250
  pluginPermissions as p,
4234
4251
  useApi as u
4235
4252
  };
4253
+ //# sourceMappingURL=index-B79ELMEC.mjs.map