@mattisvensson/strapi-plugin-webatlas 0.3.1 → 0.4.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 (56) 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-9db80XRS.mjs +126 -0
  10. package/dist/_chunks/{index-CwHhwtOU.mjs → index-B4pe6Yuh.mjs} +1375 -357
  11. package/dist/_chunks/{index-CKoxbSC0.js → index-CSYue_D0.js} +42 -60
  12. package/dist/_chunks/index-CVj7qbwh.mjs +281 -0
  13. package/dist/_chunks/index-CiY-8z8F.js +126 -0
  14. package/dist/_chunks/{index-BAqGJ3TM.js → index-Clikpy91.js} +1381 -363
  15. package/dist/_chunks/{index-BBL_eQ0G.mjs → index-CtJ_9-RB.mjs} +42 -60
  16. package/dist/_chunks/index-IHvD3566.js +281 -0
  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 +225 -176
  39. package/dist/server/index.mjs +225 -176
  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/_baseConvert-B84_vf8X.js +0 -864
  49. package/dist/_chunks/_baseConvert-C2SW1VHq.mjs +0 -865
  50. package/dist/_chunks/index-BOq-WidK.mjs +0 -17176
  51. package/dist/_chunks/index-C4ou6MTp.js +0 -17195
  52. package/dist/_chunks/index-DZmhgSeq.mjs +0 -92
  53. package/dist/_chunks/index-DsTyLL2l.js +0 -92
  54. package/dist/admin/src/pages/Navigation/Header.d.ts +0 -6
  55. package/dist/server/index.js.map +0 -1
  56. package/dist/server/index.mjs.map +0 -1
@@ -0,0 +1,4 @@
1
+ import type { Route } from '../../../../types';
2
+ export default function TableRow({ route }: {
3
+ route: Route;
4
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import type { ContentType, ConfigContentType } from '../../../../types';
3
+ export default function ContentTypeAccordion({ contentType, contentTypeSettings, dispatch }: {
4
+ contentType: ContentType | undefined;
5
+ contentTypeSettings: ConfigContentType;
6
+ dispatch: React.Dispatch<any>;
7
+ }): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ export default function PageWrapper({ settingsState, initialState, save, isSaving, children }: {
3
+ settingsState?: any;
4
+ initialState?: any;
5
+ save?: () => void;
6
+ isSaving?: boolean;
7
+ children: React.ReactNode;
8
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,25 @@
1
+ import type { NestedNavItem, Entity, GroupedEntities } from '../../../types';
2
+ type CreateTempNavItemObjectParams = {
3
+ parentId: string | undefined;
4
+ entityRoute: {
5
+ documentId: string;
6
+ } | null;
7
+ selectedNavigation: {
8
+ documentId: string;
9
+ } | null;
10
+ navItemState: {
11
+ active?: boolean;
12
+ isOverride?: boolean;
13
+ title?: string;
14
+ };
15
+ selectedEntity: Entity | undefined | null;
16
+ selectedContentType: GroupedEntities | undefined | null;
17
+ path?: {
18
+ value: string;
19
+ uidPath: string;
20
+ };
21
+ wrapper?: boolean;
22
+ internal?: boolean;
23
+ };
24
+ export default function createTempNavItemObject({ parentId, entityRoute, selectedNavigation, navItemState, selectedEntity, selectedContentType, path, wrapper, internal, }: CreateTempNavItemObjectParams): NestedNavItem;
25
+ export {};
@@ -4,4 +4,5 @@ import { isNestedNavigation, isNestedNavItem } from "./typeChecks";
4
4
  import getTranslation from "./getTranslation";
5
5
  import countChildren from "./countChildren";
6
6
  import getRouteType from "./getRouteType";
7
- export { debounce, duplicateCheck, isNestedNavigation, isNestedNavItem, getTranslation, countChildren, getRouteType };
7
+ import createTempNavItemObject from "./createTempNavItemObject";
8
+ export { debounce, duplicateCheck, isNestedNavigation, isNestedNavItem, getTranslation, countChildren, getRouteType, createTempNavItemObject };
@@ -20,7 +20,7 @@ function transformToUrl(input) {
20
20
  input = input.replace(/-+/g, "-");
21
21
  return input;
22
22
  }
23
- const version = "0.3.1";
23
+ const version = "0.4.1";
24
24
  const keywords = [];
25
25
  const type = "commonjs";
26
26
  const exports$1 = {
@@ -1128,16 +1128,6 @@ const admin$2 = () => ({
1128
1128
  return ctx.throw(500, e);
1129
1129
  }
1130
1130
  },
1131
- async createExternalRoute(ctx) {
1132
- try {
1133
- const { data } = ctx.request.body;
1134
- return await getAdminService().createExternalRoute(
1135
- data
1136
- );
1137
- } catch (e) {
1138
- return ctx.throw(500, e);
1139
- }
1140
- },
1141
1131
  async getRelatedRoute(ctx) {
1142
1132
  try {
1143
1133
  const { documentId } = ctx.query;
@@ -1173,38 +1163,20 @@ const admin$2 = () => ({
1173
1163
  return ctx.throw(500, e);
1174
1164
  }
1175
1165
  },
1176
- async deleteNavigation(ctx) {
1166
+ async updateNavigationItemStructure(ctx) {
1177
1167
  try {
1178
- const { documentId } = ctx.query;
1179
- if (!documentId) return ctx.throw(400, "Navigation documentId is required");
1180
- 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);
1181
1171
  } catch (e) {
1182
1172
  return ctx.throw(500, e);
1183
1173
  }
1184
1174
  },
1185
- async createNavItem(ctx) {
1186
- try {
1187
- const { data } = ctx.request.body;
1188
- return await getAdminService().createNavItem(data);
1189
- } catch (e) {
1190
- return ctx.throw(500, e);
1191
- }
1192
- },
1193
- async updateNavItem(ctx) {
1194
- try {
1195
- const { documentId } = ctx.query;
1196
- if (!documentId) return ctx.throw(400, "NavItem documentId is required");
1197
- const { data } = ctx.request.body;
1198
- return await getAdminService().updateNavItem(documentId, data);
1199
- } catch (e) {
1200
- return ctx.throw(500, e);
1201
- }
1202
- },
1203
- async deleteNavItem(ctx) {
1175
+ async deleteNavigation(ctx) {
1204
1176
  try {
1205
1177
  const { documentId } = ctx.query;
1206
- if (!documentId) return ctx.throw(400, "NavItem documentId is required");
1207
- return await getAdminService().deleteNavItem(documentId);
1178
+ if (!documentId) return ctx.throw(400, "Navigation documentId is required");
1179
+ return await getAdminService().deleteNavigation(documentId);
1208
1180
  } catch (e) {
1209
1181
  return ctx.throw(500, e);
1210
1182
  }
@@ -1288,15 +1260,6 @@ const admin$1 = {
1288
1260
  auth: false
1289
1261
  }
1290
1262
  },
1291
- {
1292
- method: "POST",
1293
- path: "/route/external",
1294
- handler: "admin.createExternalRoute",
1295
- config: {
1296
- policies: [],
1297
- auth: false
1298
- }
1299
- },
1300
1263
  {
1301
1264
  method: "GET",
1302
1265
  path: "/route/related",
@@ -1333,28 +1296,10 @@ const admin$1 = {
1333
1296
  auth: false
1334
1297
  }
1335
1298
  },
1336
- {
1337
- method: "DELETE",
1338
- path: "/navigation",
1339
- handler: "admin.deleteNavigation",
1340
- config: {
1341
- policies: [],
1342
- auth: false
1343
- }
1344
- },
1345
- {
1346
- method: "POST",
1347
- path: "/navitem",
1348
- handler: "admin.createNavItem",
1349
- config: {
1350
- policies: [],
1351
- auth: false
1352
- }
1353
- },
1354
1299
  {
1355
1300
  method: "PUT",
1356
- path: "/navitem",
1357
- handler: "admin.updateNavItem",
1301
+ path: "/navigation/items",
1302
+ handler: "admin.updateNavigationItemStructure",
1358
1303
  config: {
1359
1304
  policies: [],
1360
1305
  auth: false
@@ -1362,8 +1307,8 @@ const admin$1 = {
1362
1307
  },
1363
1308
  {
1364
1309
  method: "DELETE",
1365
- path: "/navitem",
1366
- handler: "admin.deleteNavItem",
1310
+ path: "/navigation",
1311
+ handler: "admin.deleteNavigation",
1367
1312
  config: {
1368
1313
  policies: [],
1369
1314
  auth: false
@@ -1416,49 +1361,54 @@ function buildStructuredNavigation(navigation2, variant = "nested") {
1416
1361
  const rootItems = [];
1417
1362
  if (!navigation2.items || navigation2.items?.length === 0) return navigation2;
1418
1363
  navigation2.items.forEach((item) => {
1419
- itemsById.set(item.id, { ...item, items: [] });
1364
+ itemsById.set(item.documentId, { ...item, items: [] });
1420
1365
  });
1421
- if (variant === "nested") {
1422
- navigation2.items.forEach((item) => {
1423
- const newItem = itemsById.get(item.id);
1424
- if (!newItem) return null;
1425
- if (item.parent) {
1426
- const parentItem = itemsById.get(item.parent.id);
1427
- parentItem && parentItem.items.push(newItem);
1428
- } else {
1429
- rootItems.push(newItem);
1430
- }
1431
- });
1432
- sortItems(rootItems);
1433
- return { ...navigation2, items: rootItems };
1434
- } else if (variant === "flat") {
1435
- let itemsToProcess = [...navigation2.items];
1436
- let itemsProcessed = /* @__PURE__ */ new Set();
1437
- while (itemsToProcess.length > 0) {
1438
- const remainingItems = [];
1439
- itemsToProcess.forEach((item) => {
1440
- const newItem = itemsById.get(item.id);
1366
+ try {
1367
+ if (variant === "nested") {
1368
+ navigation2.items.forEach((item) => {
1369
+ const newItem = itemsById.get(item.documentId);
1441
1370
  if (!newItem) return null;
1442
1371
  if (item.parent) {
1443
- const parentItem = itemsById.get(item.parent.id);
1444
- if (!parentItem || !itemsProcessed.has(item.parent.id)) {
1445
- remainingItems.push(item);
1446
- return;
1447
- }
1448
- newItem.depth = parentItem.depth !== void 0 ? parentItem.depth + 1 : 0;
1449
- parentItem.items.push(newItem);
1372
+ const parentItem = itemsById.get(item.parent.documentId);
1373
+ parentItem && parentItem.items.push(newItem);
1450
1374
  } else {
1451
- newItem.depth = 0;
1452
1375
  rootItems.push(newItem);
1453
1376
  }
1454
- itemsById.set(item.id, newItem);
1455
- itemsProcessed.add(item.id);
1456
1377
  });
1457
- 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 };
1458
1408
  }
1459
- const sortedItems = sortItems(rootItems);
1460
- const flattenedItems = flattenItems(sortedItems);
1461
- return { ...navigation2, items: flattenedItems };
1409
+ } catch (error) {
1410
+ console.error(error);
1411
+ throw error;
1462
1412
  }
1463
1413
  }
1464
1414
  const flattenItems = (items, result = []) => {
@@ -5524,6 +5474,80 @@ function removeWaFields(obj) {
5524
5474
  delete obj["webatlas_override"];
5525
5475
  return obj;
5526
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
+ }
5527
5551
  const admin = ({ strapi: strapi2 }) => ({
5528
5552
  async updateConfig(newConfig) {
5529
5553
  if (!newConfig || !newConfig.selectedContentTypes) return;
@@ -5587,25 +5611,6 @@ const admin = ({ strapi: strapi2 }) => ({
5587
5611
  console.log(e);
5588
5612
  }
5589
5613
  },
5590
- async createExternalRoute(data) {
5591
- try {
5592
- return await strapi2.documents(waRoute).create({
5593
- data: {
5594
- title: data.title,
5595
- slug: data.fullPath,
5596
- fullPath: data.fullPath,
5597
- relatedContentType: "",
5598
- relatedId: 0,
5599
- relatedDocumentId: "",
5600
- uidPath: "",
5601
- internal: false,
5602
- wrapper: data.wrapper
5603
- }
5604
- });
5605
- } catch (e) {
5606
- console.log(e);
5607
- }
5608
- },
5609
5614
  async getRelatedRoute(documentId) {
5610
5615
  try {
5611
5616
  return await strapi2.db?.query(waRoute).findOne({
@@ -5625,14 +5630,17 @@ const admin = ({ strapi: strapi2 }) => ({
5625
5630
  documentId,
5626
5631
  populate: ["items", "items.route", "items.parent"]
5627
5632
  });
5633
+ if (!navigation2) throw new Error("Navigation not found");
5634
+ if (variant)
5635
+ navigation2 = buildStructuredNavigation(navigation2, variant);
5628
5636
  } else {
5629
5637
  navigation2 = await strapi2.documents(waNavigation).findMany({
5630
5638
  populate: ["items", "items.route", "items.parent"]
5631
5639
  });
5632
- }
5633
- if (!navigation2) throw new Error("Navigation not found");
5634
- if (variant) {
5635
- 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
+ }
5636
5644
  }
5637
5645
  return navigation2;
5638
5646
  } catch (e) {
@@ -5686,60 +5694,102 @@ const admin = ({ strapi: strapi2 }) => ({
5686
5694
  console.log(e);
5687
5695
  }
5688
5696
  },
5689
- async createNavItem(data) {
5690
- try {
5691
- if (!data.route || !data.navigation) return false;
5692
- const parent = data.parent ? await strapi2.documents(waNavItem).findOne({
5693
- documentId: data.parent,
5694
- populate: ["route"]
5695
- }) : null;
5696
- const route2 = data.route ? await strapi2.documents(waRoute).findOne({
5697
- documentId: data.route
5698
- }) : null;
5699
- let fullPath = route2.slug;
5700
- if (route2.internal && !route2.isOverride && parent?.route.internal) fullPath = getFullPath(parent?.route?.fullPath, route2.slug);
5701
- await strapi2.documents(waRoute).update({
5702
- documentId: data.route,
5703
- data: {
5704
- 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);
5705
5710
  }
5706
- });
5707
- const entity = await strapi2.documents(waNavItem).create({
5708
- data: {
5709
- navigation: data.navigation,
5710
- route: data.route || null,
5711
- 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);
5712
5728
  }
5713
- });
5714
- return entity;
5715
- } catch (e) {
5716
- console.log(e);
5717
- }
5718
- },
5719
- async updateNavItem(documentId, data) {
5720
- try {
5721
- return await strapi2.documents(waNavItem).update({
5722
- documentId,
5723
- data: {
5724
- navigation: data.navigation || null,
5725
- route: data.route || null,
5726
- parent: data.parent || null,
5727
- 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;
5728
5739
  }
5729
- });
5730
- } catch (e) {
5731
- console.log(e);
5732
- }
5733
- },
5734
- async deleteNavItem(documentId) {
5735
- try {
5736
- await strapi2.documents(waNavItem).delete({
5737
- documentId
5738
- });
5739
- return true;
5740
- } catch (e) {
5741
- 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
+ }
5742
5791
  }
5792
+ return !error;
5743
5793
  },
5744
5794
  async checkUniquePath(initialPath, targetRouteDocumentId = null) {
5745
5795
  try {
@@ -5855,4 +5905,3 @@ const index = {
5855
5905
  middlewares
5856
5906
  };
5857
5907
  module.exports = index;
5858
- //# sourceMappingURL=index.js.map