@mattisvensson/strapi-plugin-webatlas 0.8.0 → 0.8.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.
Files changed (84) hide show
  1. package/dist/_chunks/FullLoader-Cmsf8xS6.js +12 -0
  2. package/dist/_chunks/FullLoader-Cmsf8xS6.js.map +1 -0
  3. package/dist/_chunks/FullLoader-CrPED_dY.mjs +1 -0
  4. package/dist/_chunks/FullLoader-CrPED_dY.mjs.map +1 -0
  5. package/dist/_chunks/SettingTitle-BaaQ_99D.mjs +69 -0
  6. package/dist/_chunks/SettingTitle-BaaQ_99D.mjs.map +1 -0
  7. package/dist/_chunks/SettingTitle-D5oNwpzC.js +67 -0
  8. package/dist/_chunks/SettingTitle-DDZxIqee.js +68 -0
  9. package/dist/_chunks/SettingTitle-DDZxIqee.js.map +1 -0
  10. package/dist/_chunks/SettingTitle-IwvX4Kb5.mjs +68 -0
  11. package/dist/_chunks/{de-C1QgkRoj.mjs → de-B9pq-AJZ.mjs} +11 -2
  12. package/dist/_chunks/de-B9pq-AJZ.mjs.map +1 -0
  13. package/dist/_chunks/de-DlQxM8Tg.js +131 -0
  14. package/dist/_chunks/de-DlQxM8Tg.js.map +1 -0
  15. package/dist/_chunks/{en--8p5hbLP.mjs → en-Dmbcf7gp.mjs} +11 -2
  16. package/dist/_chunks/en-Dmbcf7gp.mjs.map +1 -0
  17. package/dist/_chunks/en-DrhxIwOr.js +131 -0
  18. package/dist/_chunks/en-DrhxIwOr.js.map +1 -0
  19. package/dist/_chunks/index--XAogZgv.js +247 -0
  20. package/dist/_chunks/index--XAogZgv.js.map +1 -0
  21. package/dist/_chunks/index-2lVgPz4a.js +128 -0
  22. package/dist/_chunks/index-B1dEY-gs.js +246 -0
  23. package/dist/_chunks/index-B1mbYb2_.js +293 -0
  24. package/dist/_chunks/index-B2tjc_lG.mjs +247 -0
  25. package/dist/_chunks/index-B2tjc_lG.mjs.map +1 -0
  26. package/dist/_chunks/index-BFuwbmZy.js +12241 -0
  27. package/dist/_chunks/{index-DSPh-fHL.mjs → index-D2Meknib.mjs} +11 -9
  28. package/dist/_chunks/index-D2SIGcj3.mjs +12242 -0
  29. package/dist/_chunks/index-D2SIGcj3.mjs.map +1 -0
  30. package/dist/_chunks/index-DH0mFrgH.js +129 -0
  31. package/dist/_chunks/index-DH0mFrgH.js.map +1 -0
  32. package/dist/_chunks/index-DKtlnMlv.js +12242 -0
  33. package/dist/_chunks/index-DKtlnMlv.js.map +1 -0
  34. package/dist/_chunks/index-DOMrViWi.js +4207 -0
  35. package/dist/_chunks/index-DOMrViWi.js.map +1 -0
  36. package/dist/_chunks/index-DXRtXlZW.mjs +129 -0
  37. package/dist/_chunks/index-DXRtXlZW.mjs.map +1 -0
  38. package/dist/_chunks/index-Df365kgY.js +294 -0
  39. package/dist/_chunks/index-Df365kgY.js.map +1 -0
  40. package/dist/_chunks/{index-VcxUbdMO.mjs → index-Dm_GIRd4.mjs} +35 -30
  41. package/dist/_chunks/index-Dt-mlR1F.mjs +4191 -0
  42. package/dist/_chunks/index-Dt-mlR1F.mjs.map +1 -0
  43. package/dist/_chunks/index-QFbHwlyj.mjs +294 -0
  44. package/dist/_chunks/index-QFbHwlyj.mjs.map +1 -0
  45. package/dist/_chunks/{index-7rox7tGX.mjs → index-QU9SZ_H9.mjs} +93 -52
  46. package/dist/_chunks/{index-Z3qq1ab8.mjs → index-_49Fvwqq.mjs} +47 -36
  47. package/dist/_chunks/{index-DGSjLYNl.mjs → index-aAKsnALd.mjs} +1 -1
  48. package/dist/_chunks/index-g8wz2qoC.js +4206 -0
  49. package/dist/admin/index.js +5 -0
  50. package/dist/admin/index.js.map +1 -0
  51. package/dist/admin/index.mjs +2 -1
  52. package/dist/admin/index.mjs.map +1 -0
  53. package/dist/admin/src/components/modals/NavEdit.d.ts +1 -1
  54. package/dist/admin/src/pages/Navigation/RouteItem.d.ts +1 -0
  55. package/dist/admin/src/pages/Settings/ContentBox.d.ts +5 -0
  56. package/dist/admin/src/pages/Settings/PageWrapper.d.ts +2 -1
  57. package/dist/admin/src/pages/Settings/SettingTitle.d.ts +4 -0
  58. package/dist/admin/src/pages/Settings/index.d.ts +4 -0
  59. package/dist/pluginId.d.ts +2 -1
  60. package/dist/server/index.js +63 -45
  61. package/dist/server/index.js.map +1 -0
  62. package/dist/server/index.mjs +63 -45
  63. package/dist/server/index.mjs.map +1 -0
  64. package/dist/server/src/utils/index.d.ts +6 -0
  65. package/dist/server/src/utils/navItemHandler.d.ts +1 -1
  66. package/dist/server/src/utils/reduceDepthOfOrphanedItems.d.ts +2 -0
  67. package/package.json +1 -1
  68. package/dist/_chunks/PageWrapper-B6nLPFak.mjs +0 -55
  69. package/dist/_chunks/PageWrapper-BMzPDWn4.js +0 -0
  70. package/dist/_chunks/PageWrapper-BMzPDWn4.js.map +0 -0
  71. package/dist/_chunks/de-DYxCPOdb.js +0 -0
  72. package/dist/_chunks/de-DYxCPOdb.js.map +0 -0
  73. package/dist/_chunks/en-Be-athEA.js +0 -0
  74. package/dist/_chunks/en-Be-athEA.js.map +0 -0
  75. package/dist/_chunks/index-Bu-uQ9jA.js +0 -0
  76. package/dist/_chunks/index-Bu-uQ9jA.js.map +0 -0
  77. package/dist/_chunks/index-C53yDU_z.js +0 -0
  78. package/dist/_chunks/index-C53yDU_z.js.map +0 -0
  79. package/dist/_chunks/index-CAz59RSr.js +0 -0
  80. package/dist/_chunks/index-CAz59RSr.js.map +0 -0
  81. package/dist/_chunks/index-DKfUSLPc.js +0 -0
  82. package/dist/_chunks/index-DKfUSLPc.js.map +0 -0
  83. package/dist/_chunks/index-DPMhcaxW.js +0 -0
  84. package/dist/_chunks/index-DPMhcaxW.js.map +0 -0
@@ -19,7 +19,7 @@ function transformToUrl(input) {
19
19
  input = input.replace(/-+/g, "-");
20
20
  return input;
21
21
  }
22
- const version = "0.7.1";
22
+ const version = "0.8.2";
23
23
  const keywords = [];
24
24
  const type = "commonjs";
25
25
  const exports = {
@@ -5495,7 +5495,8 @@ async function createNavItem(data) {
5495
5495
  data: {
5496
5496
  navigation: data.navigation,
5497
5497
  route: data.route || null,
5498
- parent: data.parent || null
5498
+ parent: data.parent || null,
5499
+ order: data.order || 0
5499
5500
  }
5500
5501
  });
5501
5502
  return entity;
@@ -5506,8 +5507,6 @@ async function createNavItem(data) {
5506
5507
  async function updateNavItem(documentId, data) {
5507
5508
  try {
5508
5509
  const updateData = {};
5509
- if (data.navigation !== void 0 && data.navigation !== null && data.navigation !== "") updateData.navigation = data.navigation;
5510
- if (data.route !== void 0 && data.route !== null && data.route !== "") updateData.route = data.route;
5511
5510
  if (data.parent !== void 0) updateData.parent = data.parent;
5512
5511
  if (data.order !== void 0 && typeof data.order === "number") updateData.order = data.order;
5513
5512
  return await strapi.documents(waNavItem).update({
@@ -5528,6 +5527,24 @@ async function deleteNavItem(documentId) {
5528
5527
  console.log(e);
5529
5528
  }
5530
5529
  }
5530
+ function reduceDepthOfOrphanedItems(navigationItems, itemId) {
5531
+ const navigationItemsCopy = JSON.parse(JSON.stringify(navigationItems));
5532
+ const startItemIndex = navigationItemsCopy.findIndex((item) => item.documentId === itemId);
5533
+ if (startItemIndex === -1) return;
5534
+ const startItem = navigationItemsCopy[startItemIndex];
5535
+ for (let i = startItemIndex + 1; i < navigationItemsCopy.length; i++) {
5536
+ const currentItem = navigationItemsCopy[i];
5537
+ if (!currentItem) continue;
5538
+ if (currentItem.depth === 0) break;
5539
+ if (currentItem.depth > startItem.depth) {
5540
+ currentItem.depth = Math.max(0, currentItem.depth - 1);
5541
+ } else {
5542
+ break;
5543
+ }
5544
+ }
5545
+ navigationItemsCopy.splice(startItemIndex, 1);
5546
+ return navigationItemsCopy;
5547
+ }
5531
5548
  async function createExternalRoute(data) {
5532
5549
  try {
5533
5550
  return await strapi.documents(waRoute).create({
@@ -5560,19 +5577,6 @@ const admin = ({ strapi: strapi2 }) => ({
5560
5577
  console.log(err);
5561
5578
  return "Error. Couldn't update config";
5562
5579
  }
5563
- if (newConfigMerged.selectedContentTypes) {
5564
- try {
5565
- const routes2 = await strapi2.documents(waRoute).findMany();
5566
- const invalidRoutes = routes2.filter(
5567
- (route2) => !newConfigMerged.selectedContentTypes.find((type2) => type2.uid === route2.relatedContentType)
5568
- );
5569
- for (const route2 of invalidRoutes) {
5570
- await strapi2.documents(waRoute).delete({ documentId: route2.documentId });
5571
- }
5572
- } catch (err) {
5573
- console.log(err);
5574
- }
5575
- }
5576
5580
  return newConfigMerged;
5577
5581
  },
5578
5582
  async getConfig() {
@@ -5669,14 +5673,13 @@ const admin = ({ strapi: strapi2 }) => ({
5669
5673
  },
5670
5674
  async createNavigation(data) {
5671
5675
  try {
5672
- const navigation2 = await strapi2.documents(waNavigation).create({
5676
+ return await strapi2.documents(waNavigation).create({
5673
5677
  data: {
5674
5678
  name: data.name,
5675
5679
  slug: transformToUrl(data.name),
5676
5680
  visible: data.isActive
5677
5681
  }
5678
5682
  });
5679
- return navigation2;
5680
5683
  } catch (e) {
5681
5684
  console.log(e);
5682
5685
  }
@@ -5717,22 +5720,28 @@ const admin = ({ strapi: strapi2 }) => ({
5717
5720
  async updateNavigationItemStructure(navigationId, navigationItems) {
5718
5721
  if (!navigationId || !navigationItems) return;
5719
5722
  let error = false;
5720
- let groupIndices = [];
5721
- let parentIds = [];
5722
5723
  const newNavItemsMap = /* @__PURE__ */ new Map();
5723
5724
  for (const [index2, item] of navigationItems.entries()) {
5724
5725
  if (item.deleted) {
5725
5726
  try {
5726
5727
  item.documentId && await deleteNavItem(item.documentId);
5728
+ const newItems = reduceDepthOfOrphanedItems(navigationItems, item.documentId);
5729
+ if (!newItems) throw new Error("Failed to reduce depth of orphaned items");
5730
+ navigationItems = newItems;
5727
5731
  } catch (error2) {
5728
5732
  error2 = true;
5729
5733
  console.error("Error deleting navigation item ", error2);
5730
5734
  }
5731
5735
  continue;
5732
5736
  }
5733
- if (item.parent?.documentId.startsWith("temp-")) {
5734
- const newItem = newNavItemsMap.get(item.parent.documentId);
5735
- item.isNew.parent = newItem?.documentId;
5737
+ if (!item.route && item.documentId) {
5738
+ try {
5739
+ console.warn("Navigation item without route found. Deleting it. ", item);
5740
+ await deleteNavItem(item.documentId);
5741
+ } catch (error2) {
5742
+ console.error("Error deleting navigation item without route ", error2);
5743
+ }
5744
+ continue;
5736
5745
  }
5737
5746
  if (item.update && !item.isNew) {
5738
5747
  try {
@@ -5747,9 +5756,12 @@ const admin = ({ strapi: strapi2 }) => ({
5747
5756
  console.error("Error updating route ", error2);
5748
5757
  }
5749
5758
  }
5750
- const previousItem = navigationItems[index2 - 1];
5759
+ }
5760
+ let parentIds = [];
5761
+ let groupIndices = [];
5762
+ for (const [index2, item] of navigationItems.entries()) {
5751
5763
  if (typeof item.depth !== "number") {
5752
- return;
5764
+ continue;
5753
5765
  }
5754
5766
  if (item.depth === 0) {
5755
5767
  if (groupIndices[0] !== void 0) {
@@ -5758,25 +5770,34 @@ const admin = ({ strapi: strapi2 }) => ({
5758
5770
  groupIndices[0] = 0;
5759
5771
  }
5760
5772
  parentIds = [];
5761
- } else if (typeof previousItem.depth === "number" && item.depth === previousItem.depth + 1) {
5762
- parentIds.push(previousItem.documentId);
5763
- groupIndices[item.depth] = 0;
5764
- } else if (typeof previousItem.depth === "number" && item.depth <= previousItem.depth) {
5765
- const diff = previousItem.depth - item.depth;
5766
- for (let i = 0; i < diff; i++) {
5767
- parentIds.pop();
5768
- groupIndices.pop();
5773
+ } else {
5774
+ const previousItem = navigationItems[index2 - 1];
5775
+ if (previousItem && typeof previousItem.depth === "number") {
5776
+ if (item.depth === previousItem.depth + 1) {
5777
+ parentIds.push(previousItem.documentId.startsWith("temp-") ? newNavItemsMap.get(previousItem.documentId)?.documentId || previousItem.documentId : previousItem.documentId);
5778
+ groupIndices[item.depth] = 0;
5779
+ } else if (item.depth <= previousItem.depth) {
5780
+ const diff = previousItem.depth - item.depth;
5781
+ for (let i = 0; i < diff; i++) {
5782
+ parentIds.pop();
5783
+ groupIndices.pop();
5784
+ }
5785
+ groupIndices[item.depth] = (groupIndices[item.depth] || 0) + 1;
5786
+ } else {
5787
+ groupIndices[item.depth] = (groupIndices[item.depth] || 0) + 1;
5788
+ }
5769
5789
  }
5770
- groupIndices[item.depth] = (groupIndices[item.depth] || 0) + 1;
5771
5790
  }
5791
+ const calculatedParent = parentIds.at(-1) || null;
5792
+ const calculatedOrder = groupIndices[item.depth] || 0;
5772
5793
  try {
5773
5794
  if (item.isNew) {
5774
5795
  if (item.isNew.route) {
5775
5796
  await createNavItem({
5776
5797
  route: item.isNew.route,
5777
- parent: item.isNew.parent,
5798
+ parent: calculatedParent,
5778
5799
  navigation: item.isNew.navigation,
5779
- order: groupIndices[item.depth]
5800
+ order: calculatedOrder
5780
5801
  });
5781
5802
  } else {
5782
5803
  const newRoute = await createExternalRoute({
@@ -5785,23 +5806,19 @@ const admin = ({ strapi: strapi2 }) => ({
5785
5806
  fullPath: item.route.fullPath,
5786
5807
  wrapper: item.route.wrapper,
5787
5808
  internal: item.route.internal
5788
- // isOverride: item.route.isOverride,
5789
- // active: item.route.active,
5790
5809
  });
5791
5810
  const newNavItem = await createNavItem({
5792
5811
  route: newRoute.documentId,
5793
5812
  navigation: navigationId,
5794
- parent: item.isNew.parent,
5795
- order: groupIndices[item.depth]
5813
+ parent: calculatedParent,
5814
+ order: calculatedOrder
5796
5815
  });
5797
5816
  if (newNavItem) newNavItemsMap.set(item.documentId, newNavItem);
5798
5817
  }
5799
5818
  } else {
5800
5819
  await updateNavItem(item.documentId, {
5801
- navigation: void 0,
5802
- route: void 0,
5803
- order: groupIndices[item.depth] || 0,
5804
- parent: parentIds.at(-1) || null
5820
+ order: calculatedOrder,
5821
+ parent: calculatedParent
5805
5822
  });
5806
5823
  }
5807
5824
  } catch (errorMsg) {
@@ -5927,3 +5944,4 @@ const index = {
5927
5944
  export {
5928
5945
  index as default
5929
5946
  };
5947
+ //# sourceMappingURL=index.mjs.map