@mattisvensson/strapi-plugin-webatlas 0.3.0 → 0.4.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 (82) hide show
  1. package/dist/_chunks/{EmptyBox-7D4LrvdH.mjs → EmptyBox-BM4IscSk.mjs} +2 -6
  2. package/dist/_chunks/{EmptyBox-DT6D5gcf.js → EmptyBox-T8t29l25.js} +1 -5
  3. package/dist/_chunks/FullLoader-Cmsf8xS6.js +11 -0
  4. package/dist/_chunks/FullLoader-CrPED_dY.mjs +12 -0
  5. package/dist/_chunks/{de-C8PE3n3B.mjs → de-Dn24NwJf.mjs} +11 -1
  6. package/dist/_chunks/{de-4tL_cJTC.js → de-RiCps8UH.js} +11 -1
  7. package/dist/_chunks/{en-CR1YZvJo.mjs → en-D9Lxaugc.mjs} +11 -1
  8. package/dist/_chunks/{en-Bg4z3fR7.js → en-JLW5S3ZC.js} +11 -1
  9. package/dist/_chunks/index-B3JakJZB.mjs +126 -0
  10. package/dist/_chunks/index-BpvDMe8t.js +126 -0
  11. package/dist/_chunks/index-C1rj8TbT.js +281 -0
  12. package/dist/_chunks/{index-B0XE_zRP.js → index-CKHmlZdc.js} +1381 -363
  13. package/dist/_chunks/index-Cce7AGi-.mjs +281 -0
  14. package/dist/_chunks/{index-B85fJxGa.js → index-ChDbwEb-.js} +43 -61
  15. package/dist/_chunks/{index-C7B8QHDT.mjs → index-DJ-Du5aY.mjs} +1375 -357
  16. package/dist/_chunks/{index-CCiDvLAC.mjs → index-DUxYbDKG.mjs} +43 -61
  17. package/dist/admin/index.js +1 -1
  18. package/dist/admin/index.mjs +1 -1
  19. package/dist/admin/src/components/UI/FullLoader.d.ts +3 -0
  20. package/dist/admin/src/components/UI/index.d.ts +2 -1
  21. package/dist/admin/src/components/modals/Delete.d.ts +3 -3
  22. package/dist/admin/src/components/modals/NavEdit.d.ts +2 -2
  23. package/dist/admin/src/components/modals/externalItem/index.d.ts +10 -4
  24. package/dist/admin/src/components/modals/internalItem/internalItemCreate.d.ts +1 -1
  25. package/dist/admin/src/components/modals/wrapperItem/index.d.ts +11 -5
  26. package/dist/admin/src/hooks/useApi.d.ts +6 -5
  27. package/dist/admin/src/hooks/useNavigations.d.ts +2 -0
  28. package/dist/admin/src/hooks/usePluginConfig.d.ts +3 -3
  29. package/dist/admin/src/pages/Navigation/PageWrapper.d.ts +7 -0
  30. package/dist/admin/src/pages/Navigation/index.d.ts +1 -1
  31. package/dist/admin/src/pages/Routes/PageWrapper.d.ts +4 -0
  32. package/dist/admin/src/pages/Routes/TableHeader.d.ts +1 -0
  33. package/dist/admin/src/pages/Routes/TableRow.d.ts +4 -0
  34. package/dist/admin/src/pages/Settings/ContentTypeAccordion.d.ts +7 -0
  35. package/dist/admin/src/pages/Settings/PageWrapper.d.ts +8 -0
  36. package/dist/admin/src/utils/createTempNavItemObject.d.ts +25 -0
  37. package/dist/admin/src/utils/index.d.ts +2 -1
  38. package/dist/server/index.js +228 -177
  39. package/dist/server/index.mjs +228 -177
  40. package/dist/server/src/controllers/admin.d.ts +1 -4
  41. package/dist/server/src/controllers/index.d.ts +1 -4
  42. package/dist/server/src/index.d.ts +2 -8
  43. package/dist/server/src/services/admin.d.ts +2 -5
  44. package/dist/server/src/services/index.d.ts +1 -4
  45. package/dist/server/src/utils/navItemHandler.d.ts +5 -0
  46. package/dist/server/src/utils/routeHandler.d.ts +3 -0
  47. package/package.json +1 -1
  48. package/dist/_chunks/EmptyBox-7D4LrvdH.mjs.map +0 -1
  49. package/dist/_chunks/EmptyBox-DT6D5gcf.js.map +0 -1
  50. package/dist/_chunks/_baseConvert-B84_vf8X.js +0 -864
  51. package/dist/_chunks/_baseConvert-B84_vf8X.js.map +0 -1
  52. package/dist/_chunks/_baseConvert-C2SW1VHq.mjs +0 -865
  53. package/dist/_chunks/_baseConvert-C2SW1VHq.mjs.map +0 -1
  54. package/dist/_chunks/de-4tL_cJTC.js.map +0 -1
  55. package/dist/_chunks/de-C8PE3n3B.mjs.map +0 -1
  56. package/dist/_chunks/en-Bg4z3fR7.js.map +0 -1
  57. package/dist/_chunks/en-CR1YZvJo.mjs.map +0 -1
  58. package/dist/_chunks/index-B2Tiv3EK.mjs +0 -92
  59. package/dist/_chunks/index-B48CGofU.mjs +0 -17170
  60. package/dist/_chunks/index-B48CGofU.mjs.map +0 -1
  61. package/dist/_chunks/index-BbM9Sn1t.js +0 -17195
  62. package/dist/_chunks/index-BocSkZOu.mjs +0 -17176
  63. package/dist/_chunks/index-CXzNr2cH.mjs +0 -93
  64. package/dist/_chunks/index-CXzNr2cH.mjs.map +0 -1
  65. package/dist/_chunks/index-Cd6y6nuf.js +0 -93
  66. package/dist/_chunks/index-Cd6y6nuf.js.map +0 -1
  67. package/dist/_chunks/index-Cf9ZIBLd.js +0 -4195
  68. package/dist/_chunks/index-Cf9ZIBLd.js.map +0 -1
  69. package/dist/_chunks/index-D981K4TK.mjs +0 -4179
  70. package/dist/_chunks/index-D981K4TK.mjs.map +0 -1
  71. package/dist/_chunks/index-DGb8ESH-.js +0 -92
  72. package/dist/_chunks/index-DYiJBXKE.js +0 -10131
  73. package/dist/_chunks/index-DYiJBXKE.js.map +0 -1
  74. package/dist/_chunks/index-DjZ3ZaVB.js +0 -17189
  75. package/dist/_chunks/index-DjZ3ZaVB.js.map +0 -1
  76. package/dist/_chunks/index-DkhJl5mF.mjs +0 -10131
  77. package/dist/_chunks/index-DkhJl5mF.mjs.map +0 -1
  78. package/dist/admin/index.js.map +0 -1
  79. package/dist/admin/index.mjs.map +0 -1
  80. package/dist/admin/src/pages/Navigation/Header.d.ts +0 -6
  81. package/dist/server/index.js.map +0 -1
  82. package/dist/server/index.mjs.map +0 -1
@@ -20,7 +20,7 @@ function transformToUrl(input) {
20
20
  input = input.replace(/-+/g, "-");
21
21
  return input;
22
22
  }
23
- const version = "0.3.0";
23
+ const version = "0.3.1";
24
24
  const keywords = [];
25
25
  const type = "commonjs";
26
26
  const exports$1 = {
@@ -239,9 +239,11 @@ const bootstrap = async ({ strapi: strapi2 }) => {
239
239
  });
240
240
  strapi2.db?.lifecycles.subscribe({
241
241
  models: config2.selectedContentTypes.map((type2) => type2.uid),
242
- async beforeCreate() {
242
+ async beforeCreate(event) {
243
243
  const validContentTypes = config2.selectedContentTypes.filter((type2) => strapi2.contentTypes[type2.uid]);
244
244
  await pluginStore.set({ key: "config", value: { selectedContentTypes: validContentTypes } });
245
+ if (!event.params.data.webatlas_path) return;
246
+ event.params.data.webatlas_path = transformToUrl(event.params.data.webatlas_path);
245
247
  },
246
248
  async afterCreate(event) {
247
249
  const ctSettings = config2.selectedContentTypes.find((type2) => type2.uid === event.model.uid);
@@ -1126,16 +1128,6 @@ const admin$2 = () => ({
1126
1128
  return ctx.throw(500, e);
1127
1129
  }
1128
1130
  },
1129
- async createExternalRoute(ctx) {
1130
- try {
1131
- const { data } = ctx.request.body;
1132
- return await getAdminService().createExternalRoute(
1133
- data
1134
- );
1135
- } catch (e) {
1136
- return ctx.throw(500, e);
1137
- }
1138
- },
1139
1131
  async getRelatedRoute(ctx) {
1140
1132
  try {
1141
1133
  const { documentId } = ctx.query;
@@ -1171,38 +1163,20 @@ const admin$2 = () => ({
1171
1163
  return ctx.throw(500, e);
1172
1164
  }
1173
1165
  },
1174
- async deleteNavigation(ctx) {
1166
+ async updateNavigationItemStructure(ctx) {
1175
1167
  try {
1176
- const { documentId } = ctx.query;
1177
- if (!documentId) return ctx.throw(400, "Navigation documentId is required");
1178
- return await getAdminService().deleteNavigation(documentId);
1168
+ const { navigationId, navigationItems } = ctx.request.body;
1169
+ if (!navigationId || !navigationItems) return ctx.throw(400, "NavigationId and Navigation items are required");
1170
+ return await getAdminService().updateNavigationItemStructure(navigationId, navigationItems);
1179
1171
  } catch (e) {
1180
1172
  return ctx.throw(500, e);
1181
1173
  }
1182
1174
  },
1183
- async createNavItem(ctx) {
1184
- try {
1185
- const { data } = ctx.request.body;
1186
- return await getAdminService().createNavItem(data);
1187
- } catch (e) {
1188
- return ctx.throw(500, e);
1189
- }
1190
- },
1191
- async updateNavItem(ctx) {
1192
- try {
1193
- const { documentId } = ctx.query;
1194
- if (!documentId) return ctx.throw(400, "NavItem documentId is required");
1195
- const { data } = ctx.request.body;
1196
- return await getAdminService().updateNavItem(documentId, data);
1197
- } catch (e) {
1198
- return ctx.throw(500, e);
1199
- }
1200
- },
1201
- async deleteNavItem(ctx) {
1175
+ async deleteNavigation(ctx) {
1202
1176
  try {
1203
1177
  const { documentId } = ctx.query;
1204
- if (!documentId) return ctx.throw(400, "NavItem documentId is required");
1205
- return await getAdminService().deleteNavItem(documentId);
1178
+ if (!documentId) return ctx.throw(400, "Navigation documentId is required");
1179
+ return await getAdminService().deleteNavigation(documentId);
1206
1180
  } catch (e) {
1207
1181
  return ctx.throw(500, e);
1208
1182
  }
@@ -1286,15 +1260,6 @@ const admin$1 = {
1286
1260
  auth: false
1287
1261
  }
1288
1262
  },
1289
- {
1290
- method: "POST",
1291
- path: "/route/external",
1292
- handler: "admin.createExternalRoute",
1293
- config: {
1294
- policies: [],
1295
- auth: false
1296
- }
1297
- },
1298
1263
  {
1299
1264
  method: "GET",
1300
1265
  path: "/route/related",
@@ -1331,28 +1296,10 @@ const admin$1 = {
1331
1296
  auth: false
1332
1297
  }
1333
1298
  },
1334
- {
1335
- method: "DELETE",
1336
- path: "/navigation",
1337
- handler: "admin.deleteNavigation",
1338
- config: {
1339
- policies: [],
1340
- auth: false
1341
- }
1342
- },
1343
- {
1344
- method: "POST",
1345
- path: "/navitem",
1346
- handler: "admin.createNavItem",
1347
- config: {
1348
- policies: [],
1349
- auth: false
1350
- }
1351
- },
1352
1299
  {
1353
1300
  method: "PUT",
1354
- path: "/navitem",
1355
- handler: "admin.updateNavItem",
1301
+ path: "/navigation/items",
1302
+ handler: "admin.updateNavigationItemStructure",
1356
1303
  config: {
1357
1304
  policies: [],
1358
1305
  auth: false
@@ -1360,8 +1307,8 @@ const admin$1 = {
1360
1307
  },
1361
1308
  {
1362
1309
  method: "DELETE",
1363
- path: "/navitem",
1364
- handler: "admin.deleteNavItem",
1310
+ path: "/navigation",
1311
+ handler: "admin.deleteNavigation",
1365
1312
  config: {
1366
1313
  policies: [],
1367
1314
  auth: false
@@ -1414,49 +1361,54 @@ function buildStructuredNavigation(navigation2, variant = "nested") {
1414
1361
  const rootItems = [];
1415
1362
  if (!navigation2.items || navigation2.items?.length === 0) return navigation2;
1416
1363
  navigation2.items.forEach((item) => {
1417
- itemsById.set(item.id, { ...item, items: [] });
1364
+ itemsById.set(item.documentId, { ...item, items: [] });
1418
1365
  });
1419
- if (variant === "nested") {
1420
- navigation2.items.forEach((item) => {
1421
- const newItem = itemsById.get(item.id);
1422
- if (!newItem) return null;
1423
- if (item.parent) {
1424
- const parentItem = itemsById.get(item.parent.id);
1425
- parentItem && parentItem.items.push(newItem);
1426
- } else {
1427
- rootItems.push(newItem);
1428
- }
1429
- });
1430
- sortItems(rootItems);
1431
- return { ...navigation2, items: rootItems };
1432
- } else if (variant === "flat") {
1433
- let itemsToProcess = [...navigation2.items];
1434
- let itemsProcessed = /* @__PURE__ */ new Set();
1435
- while (itemsToProcess.length > 0) {
1436
- const remainingItems = [];
1437
- itemsToProcess.forEach((item) => {
1438
- const newItem = itemsById.get(item.id);
1366
+ try {
1367
+ if (variant === "nested") {
1368
+ navigation2.items.forEach((item) => {
1369
+ const newItem = itemsById.get(item.documentId);
1439
1370
  if (!newItem) return null;
1440
1371
  if (item.parent) {
1441
- const parentItem = itemsById.get(item.parent.id);
1442
- if (!parentItem || !itemsProcessed.has(item.parent.id)) {
1443
- remainingItems.push(item);
1444
- return;
1445
- }
1446
- newItem.depth = parentItem.depth !== void 0 ? parentItem.depth + 1 : 0;
1447
- parentItem.items.push(newItem);
1372
+ const parentItem = itemsById.get(item.parent.documentId);
1373
+ parentItem && parentItem.items.push(newItem);
1448
1374
  } else {
1449
- newItem.depth = 0;
1450
1375
  rootItems.push(newItem);
1451
1376
  }
1452
- itemsById.set(item.id, newItem);
1453
- itemsProcessed.add(item.id);
1454
1377
  });
1455
- itemsToProcess = remainingItems;
1378
+ sortItems(rootItems);
1379
+ return { ...navigation2, items: rootItems };
1380
+ } else if (variant === "flat") {
1381
+ let itemsToProcess = [...navigation2.items];
1382
+ let itemsProcessed = /* @__PURE__ */ new Set();
1383
+ while (itemsToProcess.length > 0) {
1384
+ const remainingItems = [];
1385
+ itemsToProcess.forEach((item) => {
1386
+ const newItem = itemsById.get(item.documentId);
1387
+ if (!newItem) return null;
1388
+ if (item.parent) {
1389
+ const parentItem = itemsById.get(item.parent.documentId);
1390
+ if (!parentItem || !itemsProcessed.has(item.parent.documentId)) {
1391
+ remainingItems.push(item);
1392
+ return;
1393
+ }
1394
+ newItem.depth = parentItem.depth !== void 0 ? parentItem.depth + 1 : 0;
1395
+ parentItem.items.push(newItem);
1396
+ } else {
1397
+ newItem.depth = 0;
1398
+ rootItems.push(newItem);
1399
+ }
1400
+ itemsById.set(item.documentId, newItem);
1401
+ itemsProcessed.add(item.documentId);
1402
+ });
1403
+ itemsToProcess = remainingItems;
1404
+ }
1405
+ const sortedItems = sortItems(rootItems);
1406
+ const flattenedItems = flattenItems(sortedItems);
1407
+ return { ...navigation2, items: flattenedItems };
1456
1408
  }
1457
- const sortedItems = sortItems(rootItems);
1458
- const flattenedItems = flattenItems(sortedItems);
1459
- return { ...navigation2, items: flattenedItems };
1409
+ } catch (error) {
1410
+ console.error(error);
1411
+ throw error;
1460
1412
  }
1461
1413
  }
1462
1414
  const flattenItems = (items, result = []) => {
@@ -5522,6 +5474,80 @@ function removeWaFields(obj) {
5522
5474
  delete obj["webatlas_override"];
5523
5475
  return obj;
5524
5476
  }
5477
+ async function createNavItem(data) {
5478
+ try {
5479
+ if (!data.route || !data.navigation) return null;
5480
+ const parent = data.parent ? await strapi.documents(waNavItem).findOne({
5481
+ documentId: data.parent,
5482
+ populate: ["route"]
5483
+ }) : null;
5484
+ const route2 = data.route ? await strapi.documents(waRoute).findOne({
5485
+ documentId: data.route
5486
+ }) : null;
5487
+ let fullPath = route2.slug;
5488
+ if (route2.internal && !route2.isOverride && parent?.route.internal) fullPath = getFullPath(parent?.route?.fullPath, route2.slug);
5489
+ await strapi.documents(waRoute).update({
5490
+ documentId: data.route,
5491
+ data: {
5492
+ fullPath
5493
+ }
5494
+ });
5495
+ const entity = await strapi.documents(waNavItem).create({
5496
+ data: {
5497
+ navigation: data.navigation,
5498
+ route: data.route || null,
5499
+ parent: data.parent || null
5500
+ }
5501
+ });
5502
+ return entity;
5503
+ } catch (e) {
5504
+ console.log(e);
5505
+ }
5506
+ }
5507
+ async function updateNavItem(documentId, data) {
5508
+ try {
5509
+ const updateData = {};
5510
+ if (data.navigation !== void 0 && data.navigation !== null && data.navigation !== "") updateData.navigation = data.navigation;
5511
+ if (data.route !== void 0 && data.route !== null && data.route !== "") updateData.route = data.route;
5512
+ if (data.parent !== void 0) updateData.parent = data.parent;
5513
+ if (data.order !== void 0 && typeof data.order === "number") updateData.order = data.order;
5514
+ return await strapi.documents(waNavItem).update({
5515
+ documentId,
5516
+ data: updateData
5517
+ });
5518
+ } catch (e) {
5519
+ console.log(e);
5520
+ }
5521
+ }
5522
+ async function deleteNavItem(documentId) {
5523
+ try {
5524
+ await strapi.documents(waNavItem).delete({
5525
+ documentId
5526
+ });
5527
+ return true;
5528
+ } catch (e) {
5529
+ console.log(e);
5530
+ }
5531
+ }
5532
+ async function createExternalRoute(data) {
5533
+ try {
5534
+ return await strapi.documents(waRoute).create({
5535
+ data: {
5536
+ title: data.title,
5537
+ slug: data.fullPath,
5538
+ fullPath: data.fullPath,
5539
+ relatedContentType: "",
5540
+ relatedId: 0,
5541
+ relatedDocumentId: "",
5542
+ uidPath: "",
5543
+ internal: false,
5544
+ wrapper: data.wrapper
5545
+ }
5546
+ });
5547
+ } catch (e) {
5548
+ console.log(e);
5549
+ }
5550
+ }
5525
5551
  const admin = ({ strapi: strapi2 }) => ({
5526
5552
  async updateConfig(newConfig) {
5527
5553
  if (!newConfig || !newConfig.selectedContentTypes) return;
@@ -5585,25 +5611,6 @@ const admin = ({ strapi: strapi2 }) => ({
5585
5611
  console.log(e);
5586
5612
  }
5587
5613
  },
5588
- async createExternalRoute(data) {
5589
- try {
5590
- return await strapi2.documents(waRoute).create({
5591
- data: {
5592
- title: data.title,
5593
- slug: data.fullPath,
5594
- fullPath: data.fullPath,
5595
- relatedContentType: "",
5596
- relatedId: 0,
5597
- relatedDocumentId: "",
5598
- uidPath: "",
5599
- internal: false,
5600
- wrapper: data.wrapper
5601
- }
5602
- });
5603
- } catch (e) {
5604
- console.log(e);
5605
- }
5606
- },
5607
5614
  async getRelatedRoute(documentId) {
5608
5615
  try {
5609
5616
  return await strapi2.db?.query(waRoute).findOne({
@@ -5623,14 +5630,17 @@ const admin = ({ strapi: strapi2 }) => ({
5623
5630
  documentId,
5624
5631
  populate: ["items", "items.route", "items.parent"]
5625
5632
  });
5633
+ if (!navigation2) throw new Error("Navigation not found");
5634
+ if (variant)
5635
+ navigation2 = buildStructuredNavigation(navigation2, variant);
5626
5636
  } else {
5627
5637
  navigation2 = await strapi2.documents(waNavigation).findMany({
5628
5638
  populate: ["items", "items.route", "items.parent"]
5629
5639
  });
5630
- }
5631
- if (!navigation2) throw new Error("Navigation not found");
5632
- if (variant) {
5633
- navigation2 = buildStructuredNavigation(navigation2, variant);
5640
+ if (!navigation2) throw new Error("Navigation not found");
5641
+ if (variant) {
5642
+ navigation2 = navigation2.map((nav) => buildStructuredNavigation(nav, variant));
5643
+ }
5634
5644
  }
5635
5645
  return navigation2;
5636
5646
  } catch (e) {
@@ -5684,60 +5694,102 @@ const admin = ({ strapi: strapi2 }) => ({
5684
5694
  console.log(e);
5685
5695
  }
5686
5696
  },
5687
- async createNavItem(data) {
5688
- try {
5689
- if (!data.route || !data.navigation) return false;
5690
- const parent = data.parent ? await strapi2.documents(waNavItem).findOne({
5691
- documentId: data.parent,
5692
- populate: ["route"]
5693
- }) : null;
5694
- const route2 = data.route ? await strapi2.documents(waRoute).findOne({
5695
- documentId: data.route
5696
- }) : null;
5697
- let fullPath = route2.slug;
5698
- if (route2.internal && !route2.isOverride && parent?.route.internal) fullPath = getFullPath(parent?.route?.fullPath, route2.slug);
5699
- await strapi2.documents(waRoute).update({
5700
- documentId: data.route,
5701
- data: {
5702
- fullPath
5697
+ async updateNavigationItemStructure(navigationId, navigationItems) {
5698
+ if (!navigationId || !navigationItems) return;
5699
+ let error = false;
5700
+ let groupIndices = [];
5701
+ let parentIds = [];
5702
+ const newNavItemsMap = /* @__PURE__ */ new Map();
5703
+ for (const [index2, item] of navigationItems.entries()) {
5704
+ if (item.deleted) {
5705
+ try {
5706
+ item.documentId && await deleteNavItem(item.documentId);
5707
+ } catch (error2) {
5708
+ error2 = true;
5709
+ console.error("Error deleting navigation item ", error2);
5703
5710
  }
5704
- });
5705
- const entity = await strapi2.documents(waNavItem).create({
5706
- data: {
5707
- navigation: data.navigation,
5708
- route: data.route || null,
5709
- parent: data.parent || null
5711
+ continue;
5712
+ }
5713
+ if (item.parent?.documentId.startsWith("temp-")) {
5714
+ const newItem = newNavItemsMap.get(item.parent.documentId);
5715
+ item.isNew.parent = newItem?.documentId;
5716
+ }
5717
+ if (item.update && !item.isNew) {
5718
+ try {
5719
+ await this.updateRoute(item.route.documentId, {
5720
+ title: item.update.title || item.route.title,
5721
+ slug: item.update.slug || item.route.slug,
5722
+ fullPath: item.update.fullPath || item.route.fullPath,
5723
+ isOverride: item.update.isOverride !== void 0 ? item.update.isOverride : item.route.isOverride
5724
+ });
5725
+ } catch (error2) {
5726
+ error2 = true;
5727
+ console.error("Error updating route ", error2);
5710
5728
  }
5711
- });
5712
- return entity;
5713
- } catch (e) {
5714
- console.log(e);
5715
- }
5716
- },
5717
- async updateNavItem(documentId, data) {
5718
- try {
5719
- return await strapi2.documents(waNavItem).update({
5720
- documentId,
5721
- data: {
5722
- navigation: data.navigation || null,
5723
- route: data.route || null,
5724
- parent: data.parent || null,
5725
- order: data.order || 0
5729
+ }
5730
+ const previousItem = navigationItems[index2 - 1];
5731
+ if (typeof item.depth !== "number") {
5732
+ return;
5733
+ }
5734
+ if (item.depth === 0) {
5735
+ if (groupIndices[0] !== void 0) {
5736
+ groupIndices[0] = groupIndices[0] + 1;
5737
+ } else {
5738
+ groupIndices[0] = 0;
5726
5739
  }
5727
- });
5728
- } catch (e) {
5729
- console.log(e);
5730
- }
5731
- },
5732
- async deleteNavItem(documentId) {
5733
- try {
5734
- await strapi2.documents(waNavItem).delete({
5735
- documentId
5736
- });
5737
- return true;
5738
- } catch (e) {
5739
- console.log(e);
5740
+ parentIds = [];
5741
+ } else if (typeof previousItem.depth === "number" && item.depth === previousItem.depth + 1) {
5742
+ parentIds.push(previousItem.documentId);
5743
+ groupIndices[item.depth] = 0;
5744
+ } else if (typeof previousItem.depth === "number" && item.depth <= previousItem.depth) {
5745
+ const diff = previousItem.depth - item.depth;
5746
+ for (let i = 0; i < diff; i++) {
5747
+ parentIds.pop();
5748
+ groupIndices.pop();
5749
+ }
5750
+ groupIndices[item.depth] = (groupIndices[item.depth] || 0) + 1;
5751
+ }
5752
+ try {
5753
+ if (item.isNew) {
5754
+ if (item.isNew.route) {
5755
+ await createNavItem({
5756
+ route: item.isNew.route,
5757
+ parent: item.isNew.parent,
5758
+ navigation: item.isNew.navigation,
5759
+ order: groupIndices[item.depth]
5760
+ });
5761
+ } else {
5762
+ const newRoute = await createExternalRoute({
5763
+ title: item.route.title,
5764
+ slug: item.route.slug,
5765
+ fullPath: item.route.fullPath,
5766
+ wrapper: item.route.wrapper,
5767
+ internal: item.route.internal
5768
+ // isOverride: item.route.isOverride,
5769
+ // active: item.route.active,
5770
+ });
5771
+ const newNavItem = await createNavItem({
5772
+ route: newRoute.documentId,
5773
+ navigation: navigationId,
5774
+ parent: item.isNew.parent,
5775
+ order: groupIndices[item.depth]
5776
+ });
5777
+ if (newNavItem) newNavItemsMap.set(item.documentId, newNavItem);
5778
+ }
5779
+ } else {
5780
+ await updateNavItem(item.documentId, {
5781
+ navigation: void 0,
5782
+ route: void 0,
5783
+ order: groupIndices[item.depth] || 0,
5784
+ parent: parentIds.at(-1) || null
5785
+ });
5786
+ }
5787
+ } catch (errorMsg) {
5788
+ error = true;
5789
+ console.error("Error updating navigation item ", errorMsg);
5790
+ }
5740
5791
  }
5792
+ return !error;
5741
5793
  },
5742
5794
  async checkUniquePath(initialPath, targetRouteDocumentId = null) {
5743
5795
  try {
@@ -5853,4 +5905,3 @@ const index = {
5853
5905
  middlewares
5854
5906
  };
5855
5907
  module.exports = index;
5856
- //# sourceMappingURL=index.js.map