@mattisvensson/strapi-plugin-webatlas 0.5.0 → 0.6.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 (41) hide show
  1. package/dist/_chunks/{de-D8LMOTFI.js → de-CL1TIZPg.js} +2 -1
  2. package/dist/_chunks/{en-BdfmJUs8.js.map → de-CL1TIZPg.js.map} +1 -1
  3. package/dist/_chunks/{de-BkirTac9.mjs → de-CzVD4dbZ.mjs} +2 -1
  4. package/dist/_chunks/{de-BkirTac9.mjs.map → de-CzVD4dbZ.mjs.map} +1 -1
  5. package/dist/_chunks/{en-BdfmJUs8.js → en-Du-Ap60j.js} +2 -1
  6. package/dist/_chunks/{de-D8LMOTFI.js.map → en-Du-Ap60j.js.map} +1 -1
  7. package/dist/_chunks/{en-DYbDta3m.mjs → en-Nk6QcTdr.mjs} +2 -1
  8. package/dist/_chunks/{en-DYbDta3m.mjs.map → en-Nk6QcTdr.mjs.map} +1 -1
  9. package/dist/_chunks/{index-CJtLrSxU.js → index-B5ji2Qhs.js} +5 -5
  10. package/dist/_chunks/{index-D4tWVnt1.js → index-BEwslndX.js} +2 -2
  11. package/dist/_chunks/{index-D4tWVnt1.js.map → index-BEwslndX.js.map} +1 -1
  12. package/dist/_chunks/{index-BOvKFOKk.js → index-BJHlAfrS.js} +81 -40
  13. package/dist/_chunks/{index-DTz7wDR7.mjs → index-BKds0CRq.mjs} +1 -1
  14. package/dist/_chunks/{index-C5ejmUpN.mjs → index-Bfu5AVqu.mjs} +81 -41
  15. package/dist/_chunks/{index-Ciae_OgQ.js → index-BvqWnL1-.js} +6 -6
  16. package/dist/_chunks/{index-Ciae_OgQ.js.map → index-BvqWnL1-.js.map} +1 -1
  17. package/dist/_chunks/{index-LAGFB7iO.mjs → index-C-4C6ezO.mjs} +1 -1
  18. package/dist/_chunks/{index-CNfpGKSw.mjs → index-C2V-ZFHK.mjs} +82 -40
  19. package/dist/_chunks/index-C2V-ZFHK.mjs.map +1 -0
  20. package/dist/_chunks/{index-BAN8PGGJ.js → index-Cp_UPsle.js} +2 -2
  21. package/dist/_chunks/{index-BAN8PGGJ.js.map → index-Cp_UPsle.js.map} +1 -1
  22. package/dist/_chunks/{index-CJNR2c7_.js → index-D2CkoDhN.js} +1 -1
  23. package/dist/_chunks/{index-BfgRvDzx.js → index-DBVU2KOj.js} +1 -1
  24. package/dist/_chunks/{index-BxnHHgGC.js → index-DCCE7rxt.js} +82 -41
  25. package/dist/_chunks/index-DCCE7rxt.js.map +1 -0
  26. package/dist/_chunks/{index-DtFIVZxq.mjs → index-DYKhGn15.mjs} +2 -2
  27. package/dist/_chunks/{index-DtFIVZxq.mjs.map → index-DYKhGn15.mjs.map} +1 -1
  28. package/dist/_chunks/{index-Ctq2vsD5.mjs → index-DesLqdi-.mjs} +5 -5
  29. package/dist/_chunks/{index-CuJP8Fy7.mjs → index-JVvkmiKE.mjs} +6 -6
  30. package/dist/_chunks/{index-CuJP8Fy7.mjs.map → index-JVvkmiKE.mjs.map} +1 -1
  31. package/dist/_chunks/{index-CEt9P4TS.mjs → index-mUDowsKQ.mjs} +2 -2
  32. package/dist/_chunks/{index-CEt9P4TS.mjs.map → index-mUDowsKQ.mjs.map} +1 -1
  33. package/dist/admin/index.js +1 -1
  34. package/dist/admin/index.mjs +1 -1
  35. package/dist/admin/src/pages/Navigation/RouteItem.d.ts +1 -0
  36. package/dist/admin/src/pages/Navigation/SortableRouteItem.d.ts +1 -1
  37. package/dist/server/index.js +1 -1
  38. package/dist/server/index.mjs +1 -1
  39. package/package.json +1 -1
  40. package/dist/_chunks/index-BxnHHgGC.js.map +0 -1
  41. package/dist/_chunks/index-C5ejmUpN.mjs.map +0 -1
@@ -5,7 +5,7 @@ import { Dialog, Typography, Button, Modal, Flex, SingleSelect, SingleSelectOpti
5
5
  import { useState, useEffect, createContext, useRef, useContext, useReducer, useCallback, useMemo, 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, d as debounce, a as duplicateCheck, t as transformToUrl, U as URLInfo } from "./index-CuJP8Fy7.mjs";
8
+ import { u as useApi, g as getTranslation, d as debounce, a as duplicateCheck, t as transformToUrl, U as URLInfo } from "./index-DesLqdi-.mjs";
9
9
  import { useFetchClient, useNotification, Page, Layouts } from "@strapi/strapi/admin";
10
10
  import { C as Center, F as FullLoader } from "./FullLoader-CrPED_dY.mjs";
11
11
  import { E as EmptyBox } from "./EmptyBox-BM4IscSk.mjs";
@@ -91,12 +91,12 @@ function Delete({ variant, item, onDelete }) {
91
91
  const { setModalType } = useContext(ModalContext);
92
92
  const { formatMessage } = useIntl();
93
93
  const { deleteNavigation } = useApi();
94
- const navigate = useNavigate();
94
+ useNavigate();
95
95
  const handleDelete = async () => {
96
96
  try {
97
97
  if (variant === "NavDelete") {
98
98
  await deleteNavigation(item.documentId);
99
- navigate("/plugins/webatlas/navigation");
99
+ onDelete(item);
100
100
  } else if (variant === "ItemDelete") {
101
101
  const editedItem = { ...item, deleted: true };
102
102
  onDelete(editedItem);
@@ -10568,11 +10568,10 @@ function getProjection(items, activeId, overId, dragOffset) {
10568
10568
  const activeItem = items[activeItemIndex];
10569
10569
  const newItems = arrayMove(items, activeItemIndex, overItemIndex);
10570
10570
  const previousItem = newItems[overItemIndex - 1];
10571
- const nextItem = newItems[overItemIndex + 1];
10572
10571
  const dragDepth = getDragDepth(dragOffset, indentationWidth);
10573
10572
  const projectedDepth = activeItem && typeof activeItem.depth === "number" ? activeItem.depth + dragDepth : 0;
10574
- const maxDepth = getMaxDepth({ previousItem });
10575
- const minDepth = getMinDepth({ nextItem });
10573
+ let maxDepth = getMaxDepth({ previousItem });
10574
+ let minDepth = 0;
10576
10575
  let depth = projectedDepth;
10577
10576
  if (projectedDepth >= maxDepth) {
10578
10577
  depth = maxDepth;
@@ -10587,12 +10586,6 @@ function getMaxDepth({ previousItem }) {
10587
10586
  }
10588
10587
  return 0;
10589
10588
  }
10590
- function getMinDepth({ nextItem }) {
10591
- if (nextItem && typeof nextItem.depth === "number") {
10592
- return nextItem.depth;
10593
- }
10594
- return 0;
10595
- }
10596
10589
  function getDragDepth(offset, indentationWidth2) {
10597
10590
  return Math.round(offset / indentationWidth2);
10598
10591
  }
@@ -10608,7 +10601,7 @@ function RouteIcon({ type, color = "neutral800" }) {
10608
10601
  return /* @__PURE__ */ jsx(Box, { width: "16px", height: "16px" });
10609
10602
  }
10610
10603
  }
10611
- const RouteItem = forwardRef(({ item, setParentId, setActionItem, ghost, depth, style, wrapperRef, handleProps }, ref) => {
10604
+ const RouteItem = forwardRef(({ item, setParentId, setActionItem, setNavigationItems, ghost, depth, style, wrapperRef, handleProps }, ref) => {
10612
10605
  if (!item || !item.route) return null;
10613
10606
  const { setModalType } = useContext(ModalContext);
10614
10607
  const { formatMessage } = useIntl();
@@ -10660,6 +10653,17 @@ const RouteItem = forwardRef(({ item, setParentId, setActionItem, ghost, depth,
10660
10653
  setActionItem(item);
10661
10654
  setModalType("ItemDelete");
10662
10655
  };
10656
+ const handleRestore = () => {
10657
+ setNavigationItems(
10658
+ (navItems) => navItems?.map((navItem) => {
10659
+ if (navItem.documentId === item.documentId) {
10660
+ delete navItem.update;
10661
+ delete navItem.deleted;
10662
+ }
10663
+ return navItem;
10664
+ })
10665
+ );
10666
+ };
10663
10667
  const elStyle = {
10664
10668
  marginLeft: depth !== void 0 ? depth * 48 : 0,
10665
10669
  opacity: ghost || item.deleted ? 0.5 : 1,
@@ -10716,18 +10720,24 @@ const RouteItem = forwardRef(({ item, setParentId, setActionItem, ghost, depth,
10716
10720
  ] }),
10717
10721
  /* @__PURE__ */ jsxs(Flex, { direction: "row", gap: 4, children: [
10718
10722
  type === "internal" && item.status && /* @__PURE__ */ jsx(Status, { variant: itemStatusOptions[item.status].variant, size: "S", children: /* @__PURE__ */ jsx(Typography, { fontWeight: "bold", children: itemStatusOptions[item.status].status }) }),
10719
- /* @__PURE__ */ jsxs(SimpleMenu, { label: "Notifications", tag: IconButton, icon: /* @__PURE__ */ jsx(More, {}), children: [
10720
- /* @__PURE__ */ jsx(MenuItem, { onClick: () => handleEdit(), children: formatMessage({
10721
- id: getTranslation("edit"),
10722
- defaultMessage: "Edit"
10723
- }) }),
10724
- /* @__PURE__ */ jsx(MenuItem, { onClick: () => handleAddChildren(), children: formatMessage({
10725
- id: getTranslation("navigation.page.navItem.addChildren"),
10726
- defaultMessage: "Add children"
10727
- }) }),
10728
- /* @__PURE__ */ jsx(MenuItem, { onClick: () => handleDelete(), children: /* @__PURE__ */ jsx(Typography, { textColor: "danger600", children: formatMessage({
10729
- id: getTranslation("delete"),
10730
- defaultMessage: "Delete"
10723
+ /* @__PURE__ */ jsxs(SimpleMenu, { label: "Item actions", tag: IconButton, icon: /* @__PURE__ */ jsx(More, {}), children: [
10724
+ !item.deleted && /* @__PURE__ */ jsxs(Fragment, { children: [
10725
+ /* @__PURE__ */ jsx(MenuItem, { onClick: () => handleEdit(), children: formatMessage({
10726
+ id: getTranslation("edit"),
10727
+ defaultMessage: "Edit"
10728
+ }) }),
10729
+ /* @__PURE__ */ jsx(MenuItem, { onClick: () => handleAddChildren(), children: formatMessage({
10730
+ id: getTranslation("navigation.page.navItem.addChildren"),
10731
+ defaultMessage: "Add children"
10732
+ }) }),
10733
+ /* @__PURE__ */ jsx(MenuItem, { onClick: () => handleDelete(), children: /* @__PURE__ */ jsx(Typography, { textColor: "danger600", children: formatMessage({
10734
+ id: getTranslation("delete"),
10735
+ defaultMessage: "Delete"
10736
+ }) }) })
10737
+ ] }),
10738
+ (item.deleted || item.update) && /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(MenuItem, { onClick: () => handleRestore(), children: formatMessage({
10739
+ id: getTranslation("restore"),
10740
+ defaultMessage: "Restore"
10731
10741
  }) }) })
10732
10742
  ] })
10733
10743
  ] })
@@ -10737,7 +10747,7 @@ const RouteItem = forwardRef(({ item, setParentId, setActionItem, ghost, depth,
10737
10747
  }
10738
10748
  );
10739
10749
  });
10740
- function SortableRouteItem({ item, depth, ...props }) {
10750
+ function SortableRouteItem({ item, depth, setNavigationItems, ...props }) {
10741
10751
  if (!item) return null;
10742
10752
  const {
10743
10753
  isDragging,
@@ -10756,6 +10766,7 @@ function SortableRouteItem({ item, depth, ...props }) {
10756
10766
  {
10757
10767
  ref: setDraggableNodeRef,
10758
10768
  wrapperRef: setDroppableNodeRef,
10769
+ setNavigationItems,
10759
10770
  style,
10760
10771
  item,
10761
10772
  disableInteraction: isSorting,
@@ -10799,6 +10810,7 @@ function PageWrapper({ navigations, loading = false, children }) {
10799
10810
  id: getTranslation("navigation.page.selectNavigation"),
10800
10811
  defaultMessage: "Select Navigation"
10801
10812
  }),
10813
+ selected: true,
10802
10814
  onChange: (value) => {
10803
10815
  const navItem = navigations.find((nav) => nav.slug === value);
10804
10816
  navItem && navigate(`/plugins/webatlas/navigation/${navItem.documentId}`);
@@ -11800,6 +11812,7 @@ const Navigation = () => {
11800
11812
  const { getNavigation, updateNavigationItemStructure } = useApi();
11801
11813
  const [isSavingNavigation, setIsSavingNavigation] = useState(false);
11802
11814
  const [loading, setLoading] = useState(true);
11815
+ const cachedNavigations = useRef(null);
11803
11816
  const [projected, setProjected] = useState(null);
11804
11817
  const [activeItem, setActiveItem] = useState();
11805
11818
  const [activeId, setActiveId] = useState(null);
@@ -11843,11 +11856,10 @@ const Navigation = () => {
11843
11856
  }) + ": " + updatedNavigations[0]?.name
11844
11857
  });
11845
11858
  navigate(`/plugins/webatlas/navigation/${updatedNavigations[0]?.documentId}`);
11859
+ return;
11846
11860
  }
11847
- setNavigations(updatedNavigations);
11848
- setSelectedNavigation(selectedNav);
11849
- setNavigationItems(selectedNav?.items || []);
11850
- initialNavigationItemsRef.current = cloneDeep$1(selectedNav?.items) || null;
11861
+ cachedNavigations.current = updatedNavigations;
11862
+ switchNavigation(selectedNav, updatedNavigations);
11851
11863
  } catch (error) {
11852
11864
  console.error("Error fetching navigations: ", error);
11853
11865
  toggleNotification({
@@ -11859,16 +11871,32 @@ const Navigation = () => {
11859
11871
  });
11860
11872
  }
11861
11873
  }
11874
+ function switchNavigation(selectedNav, updatedNavigations) {
11875
+ setNavigations(updatedNavigations);
11876
+ setSelectedNavigation(selectedNav);
11877
+ setNavigationItems(selectedNav.items || []);
11878
+ initialNavigationItemsRef.current = cloneDeep$1(selectedNav.items) || null;
11879
+ }
11862
11880
  useEffect(() => {
11863
11881
  async function fetchNavigations() {
11864
11882
  if (!navigationId) {
11865
- const navigations2 = await getNavigation({ documentId: navigationId, variant: "namesOnly" });
11866
- navigations2 && navigate(`/plugins/webatlas/navigation/${navigations2[0]?.documentId}`);
11867
- } else {
11868
- setLoading(true);
11869
- await loadNavigations();
11870
- setLoading(false);
11883
+ const navs = await getNavigation({ variant: "namesOnly" });
11884
+ if (navs && navs.length > 0) {
11885
+ navigate(`/plugins/webatlas/navigation/${navs[0].documentId}`);
11886
+ }
11887
+ return;
11871
11888
  }
11889
+ if (cachedNavigations.current) {
11890
+ const selectedNav = cachedNavigations.current.find((nav) => nav.documentId === navigationId);
11891
+ if (selectedNav) {
11892
+ switchNavigation(selectedNav, cachedNavigations.current);
11893
+ setLoading(false);
11894
+ return;
11895
+ }
11896
+ }
11897
+ setLoading(true);
11898
+ await loadNavigations();
11899
+ setLoading(false);
11872
11900
  }
11873
11901
  fetchNavigations();
11874
11902
  }, [navigationId]);
@@ -11922,7 +11950,7 @@ const Navigation = () => {
11922
11950
  })
11923
11951
  });
11924
11952
  } finally {
11925
- loadNavigations();
11953
+ await loadNavigations();
11926
11954
  setIsSavingNavigation(false);
11927
11955
  }
11928
11956
  }
@@ -11951,7 +11979,16 @@ const Navigation = () => {
11951
11979
  const activeTreeItem = navigationItems[activeIndex];
11952
11980
  navigationItems[activeIndex] = { ...activeTreeItem, depth };
11953
11981
  const sortedItems = arrayMove(navigationItems, activeIndex, overIndex);
11954
- setNavigationItems(sortedItems);
11982
+ const fixedItems = [...sortedItems];
11983
+ fixedItems[0].depth = 0;
11984
+ for (let i = 1; i < fixedItems.length; i++) {
11985
+ const prev = fixedItems[i - 1].depth ?? 0;
11986
+ let curr = fixedItems[i].depth ?? 0;
11987
+ if (curr < 0) curr = 0;
11988
+ if (curr > prev + 1) curr = prev + 1;
11989
+ fixedItems[i].depth = curr;
11990
+ }
11991
+ setNavigationItems(fixedItems);
11955
11992
  }
11956
11993
  }
11957
11994
  function resetState() {
@@ -12010,6 +12047,7 @@ const Navigation = () => {
12010
12047
  item,
12011
12048
  setParentId,
12012
12049
  setActionItem,
12050
+ setNavigationItems,
12013
12051
  indentationWidth,
12014
12052
  depth: item.id === activeId && projected ? projected.depth : item.depth
12015
12053
  },
@@ -12021,7 +12059,8 @@ const Navigation = () => {
12021
12059
  {
12022
12060
  item: activeItem,
12023
12061
  setParentId,
12024
- setActionItem
12062
+ setActionItem,
12063
+ setNavigationItems
12025
12064
  }
12026
12065
  ) : null }),
12027
12066
  document.body
@@ -12060,7 +12099,9 @@ const Navigation = () => {
12060
12099
  {
12061
12100
  variant: "NavDelete",
12062
12101
  item: actionItem,
12063
- onDelete: () => {
12102
+ onDelete: async () => {
12103
+ cachedNavigations.current = null;
12104
+ navigate("/plugins/webatlas/navigation");
12064
12105
  }
12065
12106
  }
12066
12107
  ),
@@ -12160,4 +12201,3 @@ const App = () => {
12160
12201
  export {
12161
12202
  App as default
12162
12203
  };
12163
- //# sourceMappingURL=index-C5ejmUpN.mjs.map
@@ -41,7 +41,7 @@ const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
41
41
  );
42
42
  });
43
43
  };
44
- const version = "0.5.0";
44
+ const version = "0.6.1";
45
45
  const keywords = [];
46
46
  const type = "commonjs";
47
47
  const exports$1 = {
@@ -4077,7 +4077,7 @@ const index = {
4077
4077
  defaultMessage: "Routes"
4078
4078
  },
4079
4079
  Component: async () => {
4080
- const component = await Promise.resolve().then(() => require("./index-D4tWVnt1.js"));
4080
+ const component = await Promise.resolve().then(() => require("./index-BEwslndX.js"));
4081
4081
  return { default: component.default };
4082
4082
  },
4083
4083
  permissions: [
@@ -4096,7 +4096,7 @@ const index = {
4096
4096
  defaultMessage: "Navigation"
4097
4097
  },
4098
4098
  Component: async () => {
4099
- const component = await Promise.resolve().then(() => require("./index-BxnHHgGC.js"));
4099
+ const component = await Promise.resolve().then(() => require("./index-DCCE7rxt.js"));
4100
4100
  return { default: component.default };
4101
4101
  },
4102
4102
  permissions: [
@@ -4125,7 +4125,7 @@ const index = {
4125
4125
  Component: async () => {
4126
4126
  return await Promise.resolve().then(() => require(
4127
4127
  /* webpackChunkName: "webatlas-settings-page" */
4128
- "./index-BAN8PGGJ.js"
4128
+ "./index-Cp_UPsle.js"
4129
4129
  ));
4130
4130
  },
4131
4131
  permissions: [
@@ -4154,7 +4154,7 @@ const index = {
4154
4154
  return Promise.all(
4155
4155
  locales.map(async (locale) => {
4156
4156
  try {
4157
- const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/de.json": () => Promise.resolve().then(() => require("./de-D8LMOTFI.js")), "./translations/en.json": () => Promise.resolve().then(() => require("./en-BdfmJUs8.js")) }), `./translations/${locale}.json`, 3);
4157
+ const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/de.json": () => Promise.resolve().then(() => require("./de-CL1TIZPg.js")), "./translations/en.json": () => Promise.resolve().then(() => require("./en-Du-Ap60j.js")) }), `./translations/${locale}.json`, 3);
4158
4158
  return { data, locale };
4159
4159
  } catch {
4160
4160
  return { data: {}, locale };
@@ -4174,4 +4174,4 @@ exports.transformToUrl = transformToUrl;
4174
4174
  exports.useAllContentTypes = useAllContentTypes;
4175
4175
  exports.useApi = useApi;
4176
4176
  exports.usePluginConfig = usePluginConfig;
4177
- //# sourceMappingURL=index-Ciae_OgQ.js.map
4177
+ //# sourceMappingURL=index-BvqWnL1-.js.map