@mattisvensson/strapi-plugin-webatlas 0.5.0 → 0.6.0

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 (39) 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-Ctq2vsD5.mjs → index-B5u3q4DO.mjs} +5 -5
  10. package/dist/_chunks/{index-Ciae_OgQ.js → index-Bxhu-TNT.js} +6 -6
  11. package/dist/_chunks/{index-Ciae_OgQ.js.map → index-Bxhu-TNT.js.map} +1 -1
  12. package/dist/_chunks/{index-CJtLrSxU.js → index-C1HfYOU_.js} +5 -5
  13. package/dist/_chunks/{index-CNfpGKSw.mjs → index-CDqKPoLF.mjs} +74 -36
  14. package/dist/_chunks/{index-C5ejmUpN.mjs.map → index-CDqKPoLF.mjs.map} +1 -1
  15. package/dist/_chunks/{index-BOvKFOKk.js → index-CcwGhk4b.js} +73 -36
  16. package/dist/_chunks/{index-BAN8PGGJ.js → index-Cw8m9qME.js} +2 -2
  17. package/dist/_chunks/{index-BAN8PGGJ.js.map → index-Cw8m9qME.js.map} +1 -1
  18. package/dist/_chunks/{index-DtFIVZxq.mjs → index-DKWn1eh9.mjs} +2 -2
  19. package/dist/_chunks/{index-DtFIVZxq.mjs.map → index-DKWn1eh9.mjs.map} +1 -1
  20. package/dist/_chunks/{index-LAGFB7iO.mjs → index-DLfJwkbe.mjs} +1 -1
  21. package/dist/_chunks/{index-CEt9P4TS.mjs → index-DShP5BtK.mjs} +2 -2
  22. package/dist/_chunks/{index-CEt9P4TS.mjs.map → index-DShP5BtK.mjs.map} +1 -1
  23. package/dist/_chunks/{index-BxnHHgGC.js → index-DWcVnOi0.js} +74 -37
  24. package/dist/_chunks/{index-BxnHHgGC.js.map → index-DWcVnOi0.js.map} +1 -1
  25. package/dist/_chunks/{index-DTz7wDR7.mjs → index-Dl3NwmwH.mjs} +1 -1
  26. package/dist/_chunks/{index-CuJP8Fy7.mjs → index-DohcUdej.mjs} +6 -6
  27. package/dist/_chunks/{index-CuJP8Fy7.mjs.map → index-DohcUdej.mjs.map} +1 -1
  28. package/dist/_chunks/{index-D4tWVnt1.js → index-Dryo1JuH.js} +2 -2
  29. package/dist/_chunks/{index-D4tWVnt1.js.map → index-Dryo1JuH.js.map} +1 -1
  30. package/dist/_chunks/{index-BfgRvDzx.js → index-Dy2LLMda.js} +1 -1
  31. package/dist/_chunks/{index-C5ejmUpN.mjs → index-Upva9LaE.mjs} +73 -37
  32. package/dist/_chunks/{index-CJNR2c7_.js → index-xhAxCOze.js} +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
@@ -7,7 +7,7 @@ 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-Ciae_OgQ.js");
10
+ const index = require("./index-Bxhu-TNT.js");
11
11
  const admin = require("@strapi/strapi/admin");
12
12
  const FullLoader = require("./FullLoader-Cmsf8xS6.js");
13
13
  const EmptyBox = require("./EmptyBox-T8t29l25.js");
@@ -10570,11 +10570,10 @@ function getProjection(items, activeId, overId, dragOffset) {
10570
10570
  const activeItem = items[activeItemIndex];
10571
10571
  const newItems = sortable.arrayMove(items, activeItemIndex, overItemIndex);
10572
10572
  const previousItem = newItems[overItemIndex - 1];
10573
- const nextItem = newItems[overItemIndex + 1];
10574
10573
  const dragDepth = getDragDepth(dragOffset, indentationWidth);
10575
10574
  const projectedDepth = activeItem && typeof activeItem.depth === "number" ? activeItem.depth + dragDepth : 0;
10576
- const maxDepth = getMaxDepth({ previousItem });
10577
- const minDepth = getMinDepth({ nextItem });
10575
+ let maxDepth = getMaxDepth({ previousItem });
10576
+ let minDepth = 0;
10578
10577
  let depth = projectedDepth;
10579
10578
  if (projectedDepth >= maxDepth) {
10580
10579
  depth = maxDepth;
@@ -10589,12 +10588,6 @@ function getMaxDepth({ previousItem }) {
10589
10588
  }
10590
10589
  return 0;
10591
10590
  }
10592
- function getMinDepth({ nextItem }) {
10593
- if (nextItem && typeof nextItem.depth === "number") {
10594
- return nextItem.depth;
10595
- }
10596
- return 0;
10597
- }
10598
10591
  function getDragDepth(offset, indentationWidth2) {
10599
10592
  return Math.round(offset / indentationWidth2);
10600
10593
  }
@@ -10610,7 +10603,7 @@ function RouteIcon({ type, color = "neutral800" }) {
10610
10603
  return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { width: "16px", height: "16px" });
10611
10604
  }
10612
10605
  }
10613
- const RouteItem = React.forwardRef(({ item, setParentId, setActionItem, ghost, depth, style, wrapperRef, handleProps }, ref) => {
10606
+ const RouteItem = React.forwardRef(({ item, setParentId, setActionItem, setNavigationItems, ghost, depth, style, wrapperRef, handleProps }, ref) => {
10614
10607
  if (!item || !item.route) return null;
10615
10608
  const { setModalType } = React.useContext(ModalContext);
10616
10609
  const { formatMessage } = reactIntl.useIntl();
@@ -10662,6 +10655,17 @@ const RouteItem = React.forwardRef(({ item, setParentId, setActionItem, ghost, d
10662
10655
  setActionItem(item);
10663
10656
  setModalType("ItemDelete");
10664
10657
  };
10658
+ const handleRestore = () => {
10659
+ setNavigationItems(
10660
+ (navItems) => navItems?.map((navItem) => {
10661
+ if (navItem.documentId === item.documentId) {
10662
+ delete navItem.update;
10663
+ delete navItem.deleted;
10664
+ }
10665
+ return navItem;
10666
+ })
10667
+ );
10668
+ };
10665
10669
  const elStyle = {
10666
10670
  marginLeft: depth !== void 0 ? depth * 48 : 0,
10667
10671
  opacity: ghost || item.deleted ? 0.5 : 1,
@@ -10718,18 +10722,24 @@ const RouteItem = React.forwardRef(({ item, setParentId, setActionItem, ghost, d
10718
10722
  ] }),
10719
10723
  /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "row", gap: 4, children: [
10720
10724
  type === "internal" && item.status && /* @__PURE__ */ jsxRuntime.jsx(designSystem.Status, { variant: itemStatusOptions[item.status].variant, size: "S", children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { fontWeight: "bold", children: itemStatusOptions[item.status].status }) }),
10721
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.SimpleMenu, { label: "Notifications", tag: designSystem.IconButton, icon: /* @__PURE__ */ jsxRuntime.jsx(icons.More, {}), children: [
10722
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.MenuItem, { onClick: () => handleEdit(), children: formatMessage({
10723
- id: index.getTranslation("edit"),
10724
- defaultMessage: "Edit"
10725
- }) }),
10726
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.MenuItem, { onClick: () => handleAddChildren(), children: formatMessage({
10727
- id: index.getTranslation("navigation.page.navItem.addChildren"),
10728
- defaultMessage: "Add children"
10729
- }) }),
10730
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.MenuItem, { onClick: () => handleDelete(), children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "danger600", children: formatMessage({
10731
- id: index.getTranslation("delete"),
10732
- defaultMessage: "Delete"
10725
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.SimpleMenu, { label: "Item actions", tag: designSystem.IconButton, icon: /* @__PURE__ */ jsxRuntime.jsx(icons.More, {}), children: [
10726
+ !item.deleted && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
10727
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.MenuItem, { onClick: () => handleEdit(), children: formatMessage({
10728
+ id: index.getTranslation("edit"),
10729
+ defaultMessage: "Edit"
10730
+ }) }),
10731
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.MenuItem, { onClick: () => handleAddChildren(), children: formatMessage({
10732
+ id: index.getTranslation("navigation.page.navItem.addChildren"),
10733
+ defaultMessage: "Add children"
10734
+ }) }),
10735
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.MenuItem, { onClick: () => handleDelete(), children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "danger600", children: formatMessage({
10736
+ id: index.getTranslation("delete"),
10737
+ defaultMessage: "Delete"
10738
+ }) }) })
10739
+ ] }),
10740
+ (item.deleted || item.update) && /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.MenuItem, { onClick: () => handleRestore(), children: formatMessage({
10741
+ id: index.getTranslation("restore"),
10742
+ defaultMessage: "Restore"
10733
10743
  }) }) })
10734
10744
  ] })
10735
10745
  ] })
@@ -10739,7 +10749,7 @@ const RouteItem = React.forwardRef(({ item, setParentId, setActionItem, ghost, d
10739
10749
  }
10740
10750
  );
10741
10751
  });
10742
- function SortableRouteItem({ item, depth, ...props }) {
10752
+ function SortableRouteItem({ item, depth, setNavigationItems, ...props }) {
10743
10753
  if (!item) return null;
10744
10754
  const {
10745
10755
  isDragging,
@@ -10758,6 +10768,7 @@ function SortableRouteItem({ item, depth, ...props }) {
10758
10768
  {
10759
10769
  ref: setDraggableNodeRef,
10760
10770
  wrapperRef: setDroppableNodeRef,
10771
+ setNavigationItems,
10761
10772
  style,
10762
10773
  item,
10763
10774
  disableInteraction: isSorting,
@@ -10801,6 +10812,7 @@ function PageWrapper({ navigations, loading = false, children }) {
10801
10812
  id: index.getTranslation("navigation.page.selectNavigation"),
10802
10813
  defaultMessage: "Select Navigation"
10803
10814
  }),
10815
+ selected: true,
10804
10816
  onChange: (value) => {
10805
10817
  const navItem = navigations.find((nav) => nav.slug === value);
10806
10818
  navItem && navigate(`/plugins/webatlas/navigation/${navItem.documentId}`);
@@ -11802,6 +11814,7 @@ const Navigation = () => {
11802
11814
  const { getNavigation, updateNavigationItemStructure } = index.useApi();
11803
11815
  const [isSavingNavigation, setIsSavingNavigation] = React.useState(false);
11804
11816
  const [loading, setLoading] = React.useState(true);
11817
+ const cachedNavigations = React.useRef(null);
11805
11818
  const [projected, setProjected] = React.useState(null);
11806
11819
  const [activeItem, setActiveItem] = React.useState();
11807
11820
  const [activeId, setActiveId] = React.useState(null);
@@ -11845,11 +11858,10 @@ const Navigation = () => {
11845
11858
  }) + ": " + updatedNavigations[0]?.name
11846
11859
  });
11847
11860
  navigate(`/plugins/webatlas/navigation/${updatedNavigations[0]?.documentId}`);
11861
+ return;
11848
11862
  }
11849
- setNavigations(updatedNavigations);
11850
- setSelectedNavigation(selectedNav);
11851
- setNavigationItems(selectedNav?.items || []);
11852
- initialNavigationItemsRef.current = cloneDeep$1(selectedNav?.items) || null;
11863
+ cachedNavigations.current = updatedNavigations;
11864
+ switchNavigation(selectedNav, updatedNavigations);
11853
11865
  } catch (error) {
11854
11866
  console.error("Error fetching navigations: ", error);
11855
11867
  toggleNotification({
@@ -11861,16 +11873,30 @@ const Navigation = () => {
11861
11873
  });
11862
11874
  }
11863
11875
  }
11876
+ function switchNavigation(selectedNav, updatedNavigations) {
11877
+ setNavigations(updatedNavigations);
11878
+ setSelectedNavigation(selectedNav);
11879
+ setNavigationItems(selectedNav.items || []);
11880
+ initialNavigationItemsRef.current = cloneDeep$1(selectedNav.items) || null;
11881
+ }
11864
11882
  React.useEffect(() => {
11865
11883
  async function fetchNavigations() {
11866
11884
  if (!navigationId) {
11867
- const navigations2 = await getNavigation({ documentId: navigationId, variant: "namesOnly" });
11868
- navigations2 && navigate(`/plugins/webatlas/navigation/${navigations2[0]?.documentId}`);
11869
- } else {
11870
- setLoading(true);
11871
- await loadNavigations();
11885
+ const navs = await getNavigation({ variant: "namesOnly" });
11886
+ if (navs && navs.length > 0) {
11887
+ navigate(`/plugins/webatlas/navigation/${navs[0].documentId}`);
11888
+ }
11889
+ return;
11890
+ }
11891
+ if (cachedNavigations.current) {
11892
+ const selectedNav = cachedNavigations.current.find((nav) => nav.documentId === navigationId);
11893
+ selectedNav && switchNavigation(selectedNav, cachedNavigations.current);
11872
11894
  setLoading(false);
11895
+ return;
11873
11896
  }
11897
+ setLoading(true);
11898
+ await loadNavigations();
11899
+ setLoading(false);
11874
11900
  }
11875
11901
  fetchNavigations();
11876
11902
  }, [navigationId]);
@@ -11924,7 +11950,7 @@ const Navigation = () => {
11924
11950
  })
11925
11951
  });
11926
11952
  } finally {
11927
- loadNavigations();
11953
+ await loadNavigations();
11928
11954
  setIsSavingNavigation(false);
11929
11955
  }
11930
11956
  }
@@ -11953,7 +11979,16 @@ const Navigation = () => {
11953
11979
  const activeTreeItem = navigationItems[activeIndex];
11954
11980
  navigationItems[activeIndex] = { ...activeTreeItem, depth };
11955
11981
  const sortedItems = sortable.arrayMove(navigationItems, activeIndex, overIndex);
11956
- 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);
11957
11992
  }
11958
11993
  }
11959
11994
  function resetState() {
@@ -12012,6 +12047,7 @@ const Navigation = () => {
12012
12047
  item,
12013
12048
  setParentId,
12014
12049
  setActionItem,
12050
+ setNavigationItems,
12015
12051
  indentationWidth,
12016
12052
  depth: item.id === activeId && projected ? projected.depth : item.depth
12017
12053
  },
@@ -12023,7 +12059,8 @@ const Navigation = () => {
12023
12059
  {
12024
12060
  item: activeItem,
12025
12061
  setParentId,
12026
- setActionItem
12062
+ setActionItem,
12063
+ setNavigationItems
12027
12064
  }
12028
12065
  ) : null }),
12029
12066
  document.body
@@ -12160,4 +12197,4 @@ const App = () => {
12160
12197
  ] });
12161
12198
  };
12162
12199
  exports.default = App;
12163
- //# sourceMappingURL=index-BxnHHgGC.js.map
12200
+ //# sourceMappingURL=index-DWcVnOi0.js.map