@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
@@ -19,7 +19,7 @@ function transformToUrl(input) {
19
19
  input = input.replace(/-+/g, "-");
20
20
  return input;
21
21
  }
22
- const version = "0.3.0";
22
+ const version = "0.3.1";
23
23
  const keywords = [];
24
24
  const type = "commonjs";
25
25
  const exports = {
@@ -238,9 +238,11 @@ const bootstrap = async ({ strapi: strapi2 }) => {
238
238
  });
239
239
  strapi2.db?.lifecycles.subscribe({
240
240
  models: config2.selectedContentTypes.map((type2) => type2.uid),
241
- async beforeCreate() {
241
+ async beforeCreate(event) {
242
242
  const validContentTypes = config2.selectedContentTypes.filter((type2) => strapi2.contentTypes[type2.uid]);
243
243
  await pluginStore.set({ key: "config", value: { selectedContentTypes: validContentTypes } });
244
+ if (!event.params.data.webatlas_path) return;
245
+ event.params.data.webatlas_path = transformToUrl(event.params.data.webatlas_path);
244
246
  },
245
247
  async afterCreate(event) {
246
248
  const ctSettings = config2.selectedContentTypes.find((type2) => type2.uid === event.model.uid);
@@ -1125,16 +1127,6 @@ const admin$2 = () => ({
1125
1127
  return ctx.throw(500, e);
1126
1128
  }
1127
1129
  },
1128
- async createExternalRoute(ctx) {
1129
- try {
1130
- const { data } = ctx.request.body;
1131
- return await getAdminService().createExternalRoute(
1132
- data
1133
- );
1134
- } catch (e) {
1135
- return ctx.throw(500, e);
1136
- }
1137
- },
1138
1130
  async getRelatedRoute(ctx) {
1139
1131
  try {
1140
1132
  const { documentId } = ctx.query;
@@ -1170,38 +1162,20 @@ const admin$2 = () => ({
1170
1162
  return ctx.throw(500, e);
1171
1163
  }
1172
1164
  },
1173
- async deleteNavigation(ctx) {
1165
+ async updateNavigationItemStructure(ctx) {
1174
1166
  try {
1175
- const { documentId } = ctx.query;
1176
- if (!documentId) return ctx.throw(400, "Navigation documentId is required");
1177
- return await getAdminService().deleteNavigation(documentId);
1167
+ const { navigationId, navigationItems } = ctx.request.body;
1168
+ if (!navigationId || !navigationItems) return ctx.throw(400, "NavigationId and Navigation items are required");
1169
+ return await getAdminService().updateNavigationItemStructure(navigationId, navigationItems);
1178
1170
  } catch (e) {
1179
1171
  return ctx.throw(500, e);
1180
1172
  }
1181
1173
  },
1182
- async createNavItem(ctx) {
1183
- try {
1184
- const { data } = ctx.request.body;
1185
- return await getAdminService().createNavItem(data);
1186
- } catch (e) {
1187
- return ctx.throw(500, e);
1188
- }
1189
- },
1190
- async updateNavItem(ctx) {
1191
- try {
1192
- const { documentId } = ctx.query;
1193
- if (!documentId) return ctx.throw(400, "NavItem documentId is required");
1194
- const { data } = ctx.request.body;
1195
- return await getAdminService().updateNavItem(documentId, data);
1196
- } catch (e) {
1197
- return ctx.throw(500, e);
1198
- }
1199
- },
1200
- async deleteNavItem(ctx) {
1174
+ async deleteNavigation(ctx) {
1201
1175
  try {
1202
1176
  const { documentId } = ctx.query;
1203
- if (!documentId) return ctx.throw(400, "NavItem documentId is required");
1204
- return await getAdminService().deleteNavItem(documentId);
1177
+ if (!documentId) return ctx.throw(400, "Navigation documentId is required");
1178
+ return await getAdminService().deleteNavigation(documentId);
1205
1179
  } catch (e) {
1206
1180
  return ctx.throw(500, e);
1207
1181
  }
@@ -1285,15 +1259,6 @@ const admin$1 = {
1285
1259
  auth: false
1286
1260
  }
1287
1261
  },
1288
- {
1289
- method: "POST",
1290
- path: "/route/external",
1291
- handler: "admin.createExternalRoute",
1292
- config: {
1293
- policies: [],
1294
- auth: false
1295
- }
1296
- },
1297
1262
  {
1298
1263
  method: "GET",
1299
1264
  path: "/route/related",
@@ -1330,28 +1295,10 @@ const admin$1 = {
1330
1295
  auth: false
1331
1296
  }
1332
1297
  },
1333
- {
1334
- method: "DELETE",
1335
- path: "/navigation",
1336
- handler: "admin.deleteNavigation",
1337
- config: {
1338
- policies: [],
1339
- auth: false
1340
- }
1341
- },
1342
- {
1343
- method: "POST",
1344
- path: "/navitem",
1345
- handler: "admin.createNavItem",
1346
- config: {
1347
- policies: [],
1348
- auth: false
1349
- }
1350
- },
1351
1298
  {
1352
1299
  method: "PUT",
1353
- path: "/navitem",
1354
- handler: "admin.updateNavItem",
1300
+ path: "/navigation/items",
1301
+ handler: "admin.updateNavigationItemStructure",
1355
1302
  config: {
1356
1303
  policies: [],
1357
1304
  auth: false
@@ -1359,8 +1306,8 @@ const admin$1 = {
1359
1306
  },
1360
1307
  {
1361
1308
  method: "DELETE",
1362
- path: "/navitem",
1363
- handler: "admin.deleteNavItem",
1309
+ path: "/navigation",
1310
+ handler: "admin.deleteNavigation",
1364
1311
  config: {
1365
1312
  policies: [],
1366
1313
  auth: false
@@ -1413,49 +1360,54 @@ function buildStructuredNavigation(navigation2, variant = "nested") {
1413
1360
  const rootItems = [];
1414
1361
  if (!navigation2.items || navigation2.items?.length === 0) return navigation2;
1415
1362
  navigation2.items.forEach((item) => {
1416
- itemsById.set(item.id, { ...item, items: [] });
1363
+ itemsById.set(item.documentId, { ...item, items: [] });
1417
1364
  });
1418
- if (variant === "nested") {
1419
- navigation2.items.forEach((item) => {
1420
- const newItem = itemsById.get(item.id);
1421
- if (!newItem) return null;
1422
- if (item.parent) {
1423
- const parentItem = itemsById.get(item.parent.id);
1424
- parentItem && parentItem.items.push(newItem);
1425
- } else {
1426
- rootItems.push(newItem);
1427
- }
1428
- });
1429
- sortItems(rootItems);
1430
- return { ...navigation2, items: rootItems };
1431
- } else if (variant === "flat") {
1432
- let itemsToProcess = [...navigation2.items];
1433
- let itemsProcessed = /* @__PURE__ */ new Set();
1434
- while (itemsToProcess.length > 0) {
1435
- const remainingItems = [];
1436
- itemsToProcess.forEach((item) => {
1437
- const newItem = itemsById.get(item.id);
1365
+ try {
1366
+ if (variant === "nested") {
1367
+ navigation2.items.forEach((item) => {
1368
+ const newItem = itemsById.get(item.documentId);
1438
1369
  if (!newItem) return null;
1439
1370
  if (item.parent) {
1440
- const parentItem = itemsById.get(item.parent.id);
1441
- if (!parentItem || !itemsProcessed.has(item.parent.id)) {
1442
- remainingItems.push(item);
1443
- return;
1444
- }
1445
- newItem.depth = parentItem.depth !== void 0 ? parentItem.depth + 1 : 0;
1446
- parentItem.items.push(newItem);
1371
+ const parentItem = itemsById.get(item.parent.documentId);
1372
+ parentItem && parentItem.items.push(newItem);
1447
1373
  } else {
1448
- newItem.depth = 0;
1449
1374
  rootItems.push(newItem);
1450
1375
  }
1451
- itemsById.set(item.id, newItem);
1452
- itemsProcessed.add(item.id);
1453
1376
  });
1454
- itemsToProcess = remainingItems;
1377
+ sortItems(rootItems);
1378
+ return { ...navigation2, items: rootItems };
1379
+ } else if (variant === "flat") {
1380
+ let itemsToProcess = [...navigation2.items];
1381
+ let itemsProcessed = /* @__PURE__ */ new Set();
1382
+ while (itemsToProcess.length > 0) {
1383
+ const remainingItems = [];
1384
+ itemsToProcess.forEach((item) => {
1385
+ const newItem = itemsById.get(item.documentId);
1386
+ if (!newItem) return null;
1387
+ if (item.parent) {
1388
+ const parentItem = itemsById.get(item.parent.documentId);
1389
+ if (!parentItem || !itemsProcessed.has(item.parent.documentId)) {
1390
+ remainingItems.push(item);
1391
+ return;
1392
+ }
1393
+ newItem.depth = parentItem.depth !== void 0 ? parentItem.depth + 1 : 0;
1394
+ parentItem.items.push(newItem);
1395
+ } else {
1396
+ newItem.depth = 0;
1397
+ rootItems.push(newItem);
1398
+ }
1399
+ itemsById.set(item.documentId, newItem);
1400
+ itemsProcessed.add(item.documentId);
1401
+ });
1402
+ itemsToProcess = remainingItems;
1403
+ }
1404
+ const sortedItems = sortItems(rootItems);
1405
+ const flattenedItems = flattenItems(sortedItems);
1406
+ return { ...navigation2, items: flattenedItems };
1455
1407
  }
1456
- const sortedItems = sortItems(rootItems);
1457
- const flattenedItems = flattenItems(sortedItems);
1458
- return { ...navigation2, items: flattenedItems };
1408
+ } catch (error) {
1409
+ console.error(error);
1410
+ throw error;
1459
1411
  }
1460
1412
  }
1461
1413
  const flattenItems = (items, result = []) => {
@@ -5521,6 +5473,80 @@ function removeWaFields(obj) {
5521
5473
  delete obj["webatlas_override"];
5522
5474
  return obj;
5523
5475
  }
5476
+ async function createNavItem(data) {
5477
+ try {
5478
+ if (!data.route || !data.navigation) return null;
5479
+ const parent = data.parent ? await strapi.documents(waNavItem).findOne({
5480
+ documentId: data.parent,
5481
+ populate: ["route"]
5482
+ }) : null;
5483
+ const route2 = data.route ? await strapi.documents(waRoute).findOne({
5484
+ documentId: data.route
5485
+ }) : null;
5486
+ let fullPath = route2.slug;
5487
+ if (route2.internal && !route2.isOverride && parent?.route.internal) fullPath = getFullPath(parent?.route?.fullPath, route2.slug);
5488
+ await strapi.documents(waRoute).update({
5489
+ documentId: data.route,
5490
+ data: {
5491
+ fullPath
5492
+ }
5493
+ });
5494
+ const entity = await strapi.documents(waNavItem).create({
5495
+ data: {
5496
+ navigation: data.navigation,
5497
+ route: data.route || null,
5498
+ parent: data.parent || null
5499
+ }
5500
+ });
5501
+ return entity;
5502
+ } catch (e) {
5503
+ console.log(e);
5504
+ }
5505
+ }
5506
+ async function updateNavItem(documentId, data) {
5507
+ try {
5508
+ 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
+ if (data.parent !== void 0) updateData.parent = data.parent;
5512
+ if (data.order !== void 0 && typeof data.order === "number") updateData.order = data.order;
5513
+ return await strapi.documents(waNavItem).update({
5514
+ documentId,
5515
+ data: updateData
5516
+ });
5517
+ } catch (e) {
5518
+ console.log(e);
5519
+ }
5520
+ }
5521
+ async function deleteNavItem(documentId) {
5522
+ try {
5523
+ await strapi.documents(waNavItem).delete({
5524
+ documentId
5525
+ });
5526
+ return true;
5527
+ } catch (e) {
5528
+ console.log(e);
5529
+ }
5530
+ }
5531
+ async function createExternalRoute(data) {
5532
+ try {
5533
+ return await strapi.documents(waRoute).create({
5534
+ data: {
5535
+ title: data.title,
5536
+ slug: data.fullPath,
5537
+ fullPath: data.fullPath,
5538
+ relatedContentType: "",
5539
+ relatedId: 0,
5540
+ relatedDocumentId: "",
5541
+ uidPath: "",
5542
+ internal: false,
5543
+ wrapper: data.wrapper
5544
+ }
5545
+ });
5546
+ } catch (e) {
5547
+ console.log(e);
5548
+ }
5549
+ }
5524
5550
  const admin = ({ strapi: strapi2 }) => ({
5525
5551
  async updateConfig(newConfig) {
5526
5552
  if (!newConfig || !newConfig.selectedContentTypes) return;
@@ -5584,25 +5610,6 @@ const admin = ({ strapi: strapi2 }) => ({
5584
5610
  console.log(e);
5585
5611
  }
5586
5612
  },
5587
- async createExternalRoute(data) {
5588
- try {
5589
- return await strapi2.documents(waRoute).create({
5590
- data: {
5591
- title: data.title,
5592
- slug: data.fullPath,
5593
- fullPath: data.fullPath,
5594
- relatedContentType: "",
5595
- relatedId: 0,
5596
- relatedDocumentId: "",
5597
- uidPath: "",
5598
- internal: false,
5599
- wrapper: data.wrapper
5600
- }
5601
- });
5602
- } catch (e) {
5603
- console.log(e);
5604
- }
5605
- },
5606
5613
  async getRelatedRoute(documentId) {
5607
5614
  try {
5608
5615
  return await strapi2.db?.query(waRoute).findOne({
@@ -5622,14 +5629,17 @@ const admin = ({ strapi: strapi2 }) => ({
5622
5629
  documentId,
5623
5630
  populate: ["items", "items.route", "items.parent"]
5624
5631
  });
5632
+ if (!navigation2) throw new Error("Navigation not found");
5633
+ if (variant)
5634
+ navigation2 = buildStructuredNavigation(navigation2, variant);
5625
5635
  } else {
5626
5636
  navigation2 = await strapi2.documents(waNavigation).findMany({
5627
5637
  populate: ["items", "items.route", "items.parent"]
5628
5638
  });
5629
- }
5630
- if (!navigation2) throw new Error("Navigation not found");
5631
- if (variant) {
5632
- navigation2 = buildStructuredNavigation(navigation2, variant);
5639
+ if (!navigation2) throw new Error("Navigation not found");
5640
+ if (variant) {
5641
+ navigation2 = navigation2.map((nav) => buildStructuredNavigation(nav, variant));
5642
+ }
5633
5643
  }
5634
5644
  return navigation2;
5635
5645
  } catch (e) {
@@ -5683,60 +5693,102 @@ const admin = ({ strapi: strapi2 }) => ({
5683
5693
  console.log(e);
5684
5694
  }
5685
5695
  },
5686
- async createNavItem(data) {
5687
- try {
5688
- if (!data.route || !data.navigation) return false;
5689
- const parent = data.parent ? await strapi2.documents(waNavItem).findOne({
5690
- documentId: data.parent,
5691
- populate: ["route"]
5692
- }) : null;
5693
- const route2 = data.route ? await strapi2.documents(waRoute).findOne({
5694
- documentId: data.route
5695
- }) : null;
5696
- let fullPath = route2.slug;
5697
- if (route2.internal && !route2.isOverride && parent?.route.internal) fullPath = getFullPath(parent?.route?.fullPath, route2.slug);
5698
- await strapi2.documents(waRoute).update({
5699
- documentId: data.route,
5700
- data: {
5701
- fullPath
5696
+ async updateNavigationItemStructure(navigationId, navigationItems) {
5697
+ if (!navigationId || !navigationItems) return;
5698
+ let error = false;
5699
+ let groupIndices = [];
5700
+ let parentIds = [];
5701
+ const newNavItemsMap = /* @__PURE__ */ new Map();
5702
+ for (const [index2, item] of navigationItems.entries()) {
5703
+ if (item.deleted) {
5704
+ try {
5705
+ item.documentId && await deleteNavItem(item.documentId);
5706
+ } catch (error2) {
5707
+ error2 = true;
5708
+ console.error("Error deleting navigation item ", error2);
5702
5709
  }
5703
- });
5704
- const entity = await strapi2.documents(waNavItem).create({
5705
- data: {
5706
- navigation: data.navigation,
5707
- route: data.route || null,
5708
- parent: data.parent || null
5710
+ continue;
5711
+ }
5712
+ if (item.parent?.documentId.startsWith("temp-")) {
5713
+ const newItem = newNavItemsMap.get(item.parent.documentId);
5714
+ item.isNew.parent = newItem?.documentId;
5715
+ }
5716
+ if (item.update && !item.isNew) {
5717
+ try {
5718
+ await this.updateRoute(item.route.documentId, {
5719
+ title: item.update.title || item.route.title,
5720
+ slug: item.update.slug || item.route.slug,
5721
+ fullPath: item.update.fullPath || item.route.fullPath,
5722
+ isOverride: item.update.isOverride !== void 0 ? item.update.isOverride : item.route.isOverride
5723
+ });
5724
+ } catch (error2) {
5725
+ error2 = true;
5726
+ console.error("Error updating route ", error2);
5709
5727
  }
5710
- });
5711
- return entity;
5712
- } catch (e) {
5713
- console.log(e);
5714
- }
5715
- },
5716
- async updateNavItem(documentId, data) {
5717
- try {
5718
- return await strapi2.documents(waNavItem).update({
5719
- documentId,
5720
- data: {
5721
- navigation: data.navigation || null,
5722
- route: data.route || null,
5723
- parent: data.parent || null,
5724
- order: data.order || 0
5728
+ }
5729
+ const previousItem = navigationItems[index2 - 1];
5730
+ if (typeof item.depth !== "number") {
5731
+ return;
5732
+ }
5733
+ if (item.depth === 0) {
5734
+ if (groupIndices[0] !== void 0) {
5735
+ groupIndices[0] = groupIndices[0] + 1;
5736
+ } else {
5737
+ groupIndices[0] = 0;
5725
5738
  }
5726
- });
5727
- } catch (e) {
5728
- console.log(e);
5729
- }
5730
- },
5731
- async deleteNavItem(documentId) {
5732
- try {
5733
- await strapi2.documents(waNavItem).delete({
5734
- documentId
5735
- });
5736
- return true;
5737
- } catch (e) {
5738
- console.log(e);
5739
+ parentIds = [];
5740
+ } else if (typeof previousItem.depth === "number" && item.depth === previousItem.depth + 1) {
5741
+ parentIds.push(previousItem.documentId);
5742
+ groupIndices[item.depth] = 0;
5743
+ } else if (typeof previousItem.depth === "number" && item.depth <= previousItem.depth) {
5744
+ const diff = previousItem.depth - item.depth;
5745
+ for (let i = 0; i < diff; i++) {
5746
+ parentIds.pop();
5747
+ groupIndices.pop();
5748
+ }
5749
+ groupIndices[item.depth] = (groupIndices[item.depth] || 0) + 1;
5750
+ }
5751
+ try {
5752
+ if (item.isNew) {
5753
+ if (item.isNew.route) {
5754
+ await createNavItem({
5755
+ route: item.isNew.route,
5756
+ parent: item.isNew.parent,
5757
+ navigation: item.isNew.navigation,
5758
+ order: groupIndices[item.depth]
5759
+ });
5760
+ } else {
5761
+ const newRoute = await createExternalRoute({
5762
+ title: item.route.title,
5763
+ slug: item.route.slug,
5764
+ fullPath: item.route.fullPath,
5765
+ wrapper: item.route.wrapper,
5766
+ internal: item.route.internal
5767
+ // isOverride: item.route.isOverride,
5768
+ // active: item.route.active,
5769
+ });
5770
+ const newNavItem = await createNavItem({
5771
+ route: newRoute.documentId,
5772
+ navigation: navigationId,
5773
+ parent: item.isNew.parent,
5774
+ order: groupIndices[item.depth]
5775
+ });
5776
+ if (newNavItem) newNavItemsMap.set(item.documentId, newNavItem);
5777
+ }
5778
+ } else {
5779
+ await updateNavItem(item.documentId, {
5780
+ navigation: void 0,
5781
+ route: void 0,
5782
+ order: groupIndices[item.depth] || 0,
5783
+ parent: parentIds.at(-1) || null
5784
+ });
5785
+ }
5786
+ } catch (errorMsg) {
5787
+ error = true;
5788
+ console.error("Error updating navigation item ", errorMsg);
5789
+ }
5739
5790
  }
5791
+ return !error;
5740
5792
  },
5741
5793
  async checkUniquePath(initialPath, targetRouteDocumentId = null) {
5742
5794
  try {
@@ -5854,4 +5906,3 @@ const index = {
5854
5906
  export {
5855
5907
  index as default
5856
5908
  };
5857
- //# sourceMappingURL=index.mjs.map
@@ -3,15 +3,12 @@ declare const admin: () => {
3
3
  getConfig(ctx: any): Promise<any>;
4
4
  getRoutes(ctx: any): Promise<any>;
5
5
  updateRoute(ctx: any): Promise<any>;
6
- createExternalRoute(ctx: any): Promise<any>;
7
6
  getRelatedRoute(ctx: any): Promise<any>;
8
7
  getNavigation(ctx: any): Promise<any>;
9
8
  createNavigation(ctx: any): Promise<any>;
10
9
  updateNavigation(ctx: any): Promise<any>;
10
+ updateNavigationItemStructure(ctx: any): Promise<any>;
11
11
  deleteNavigation(ctx: any): Promise<any>;
12
- createNavItem(ctx: any): Promise<any>;
13
- updateNavItem(ctx: any): Promise<any>;
14
- deleteNavItem(ctx: any): Promise<any>;
15
12
  checkUniquePath(ctx: any): Promise<any>;
16
13
  };
17
14
  export default admin;
@@ -4,15 +4,12 @@ declare const _default: {
4
4
  getConfig(ctx: any): Promise<any>;
5
5
  getRoutes(ctx: any): Promise<any>;
6
6
  updateRoute(ctx: any): Promise<any>;
7
- createExternalRoute(ctx: any): Promise<any>;
8
7
  getRelatedRoute(ctx: any): Promise<any>;
9
8
  getNavigation(ctx: any): Promise<any>;
10
9
  createNavigation(ctx: any): Promise<any>;
11
10
  updateNavigation(ctx: any): Promise<any>;
11
+ updateNavigationItemStructure(ctx: any): Promise<any>;
12
12
  deleteNavigation(ctx: any): Promise<any>;
13
- createNavItem(ctx: any): Promise<any>;
14
- updateNavItem(ctx: any): Promise<any>;
15
- deleteNavItem(ctx: any): Promise<any>;
16
13
  checkUniquePath(ctx: any): Promise<any>;
17
14
  };
18
15
  client: ({ strapi }: {
@@ -18,15 +18,12 @@ declare const _default: {
18
18
  getConfig(ctx: any): Promise<any>;
19
19
  getRoutes(ctx: any): Promise<any>;
20
20
  updateRoute(ctx: any): Promise<any>;
21
- createExternalRoute(ctx: any): Promise<any>;
22
21
  getRelatedRoute(ctx: any): Promise<any>;
23
22
  getNavigation(ctx: any): Promise<any>;
24
23
  createNavigation(ctx: any): Promise<any>;
25
24
  updateNavigation(ctx: any): Promise<any>;
25
+ updateNavigationItemStructure(ctx: any): Promise<any>;
26
26
  deleteNavigation(ctx: any): Promise<any>;
27
- createNavItem(ctx: any): Promise<any>;
28
- updateNavItem(ctx: any): Promise<any>;
29
- deleteNavItem(ctx: any): Promise<any>;
30
27
  checkUniquePath(ctx: any): Promise<any>;
31
28
  };
32
29
  client: ({ strapi }: {
@@ -69,15 +66,12 @@ declare const _default: {
69
66
  getConfig(): Promise<any>;
70
67
  getRoutes(): Promise<any>;
71
68
  updateRoute(documentId: string, data: any): Promise<any>;
72
- createExternalRoute(data: any): Promise<any>;
73
69
  getRelatedRoute(documentId: string): Promise<any>;
74
70
  getNavigation(documentId?: string, variant?: import("../../types").StructuredNavigationVariant): Promise<any>;
75
71
  createNavigation(data: any): Promise<any>;
76
72
  updateNavigation(documentId: string, data: import("../../types").NavigationInput): Promise<any>;
77
73
  deleteNavigation(documentId: string): Promise<any>;
78
- createNavItem(data: import("../../types").NavItemSettings): Promise<any>;
79
- updateNavItem(documentId: string, data: import("../../types").NavItemSettings): Promise<any>;
80
- deleteNavItem(documentId: string): Promise<boolean>;
74
+ updateNavigationItemStructure(navigationId: string, navigationItems: import("../../types").NestedNavItem[]): Promise<boolean>;
81
75
  checkUniquePath(initialPath: string, targetRouteDocumentId?: string): Promise<string>;
82
76
  };
83
77
  client: ({ strapi }: {
@@ -1,4 +1,4 @@
1
- import { NavigationInput, NavItemSettings, StructuredNavigationVariant } from "../../../types";
1
+ import type { NavigationInput, NestedNavItem, StructuredNavigationVariant } from "../../../types";
2
2
  declare const _default: ({ strapi }: {
3
3
  strapi: any;
4
4
  }) => {
@@ -6,15 +6,12 @@ declare const _default: ({ strapi }: {
6
6
  getConfig(): Promise<any>;
7
7
  getRoutes(): Promise<any>;
8
8
  updateRoute(documentId: string, data: any): Promise<any>;
9
- createExternalRoute(data: any): Promise<any>;
10
9
  getRelatedRoute(documentId: string): Promise<any>;
11
10
  getNavigation(documentId?: string, variant?: StructuredNavigationVariant): Promise<any>;
12
11
  createNavigation(data: any): Promise<any>;
13
12
  updateNavigation(documentId: string, data: NavigationInput): Promise<any>;
14
13
  deleteNavigation(documentId: string): Promise<any>;
15
- createNavItem(data: NavItemSettings): Promise<any>;
16
- updateNavItem(documentId: string, data: NavItemSettings): Promise<any>;
17
- deleteNavItem(documentId: string): Promise<boolean>;
14
+ updateNavigationItemStructure(navigationId: string, navigationItems: NestedNavItem[]): Promise<boolean>;
18
15
  checkUniquePath(initialPath: string, targetRouteDocumentId?: string | null): Promise<string>;
19
16
  };
20
17
  export default _default;
@@ -6,15 +6,12 @@ declare const _default: {
6
6
  getConfig(): Promise<any>;
7
7
  getRoutes(): Promise<any>;
8
8
  updateRoute(documentId: string, data: any): Promise<any>;
9
- createExternalRoute(data: any): Promise<any>;
10
9
  getRelatedRoute(documentId: string): Promise<any>;
11
10
  getNavigation(documentId?: string, variant?: import("../../../types").StructuredNavigationVariant): Promise<any>;
12
11
  createNavigation(data: any): Promise<any>;
13
12
  updateNavigation(documentId: string, data: import("../../../types").NavigationInput): Promise<any>;
14
13
  deleteNavigation(documentId: string): Promise<any>;
15
- createNavItem(data: import("../../../types").NavItemSettings): Promise<any>;
16
- updateNavItem(documentId: string, data: import("../../../types").NavItemSettings): Promise<any>;
17
- deleteNavItem(documentId: string): Promise<boolean>;
14
+ updateNavigationItemStructure(navigationId: string, navigationItems: import("../../../types").NestedNavItem[]): Promise<boolean>;
18
15
  checkUniquePath(initialPath: string, targetRouteDocumentId?: string): Promise<string>;
19
16
  };
20
17
  client: ({ strapi }: {
@@ -0,0 +1,5 @@
1
+ import type { NavItemSettings, NestedNavItem } from "../../../types";
2
+ declare function createNavItem(data: NavItemSettings): Promise<null | NestedNavItem>;
3
+ declare function updateNavItem(documentId: string, data: NavItemSettings): Promise<import("@strapi/types/dist/modules/documents").AnyDocument>;
4
+ declare function deleteNavItem(documentId: string): Promise<boolean>;
5
+ export { createNavItem, updateNavItem, deleteNavItem };
@@ -0,0 +1,3 @@
1
+ import type { RouteSettings } from "../../../types";
2
+ declare function createExternalRoute(data: RouteSettings): Promise<import("@strapi/types/dist/modules/documents").AnyDocument>;
3
+ export { createExternalRoute };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.3.0",
2
+ "version": "0.4.0",
3
3
  "keywords": [],
4
4
  "type": "commonjs",
5
5
  "exports": {
@@ -1 +0,0 @@
1
- {"version":3,"file":"EmptyBox-7D4LrvdH.mjs","sources":["../../admin/src/components/UI/Center.tsx","../../admin/src/components/UI/EmptyBox.tsx"],"sourcesContent":["import { Flex } from '@strapi/design-system';\n\nexport default function Center({ height = 400, children }: { height?: number, children: React.ReactNode }) {\n\n return (\n <Flex direction=\"column\" minHeight={`${height}px`} justifyContent=\"center\">\n {children}\n </Flex>\n )\n}","import { EmptyDocuments } from '@strapi/icons/symbols';\nimport { Box, Typography } from '@strapi/design-system';\n\ntype EmptyNavProps = {\n msg: string;\n}\n\nexport default function EmptyBox ({ msg }: EmptyNavProps) {\n\n return (\n <>\n <EmptyDocuments width=\"10rem\" height=\"6rem\"/>\n <Box padding={4}>\n <Typography variant=\"beta\" textColor=\"neutral600\">{msg}</Typography>\n </Box>\n </>\n )\n}"],"names":[],"mappings":";;;AAEA,SAAwB,OAAO,EAAE,SAAS,KAAK,YAA4D;AAGvG,SAAA,oBAAC,MAAK,EAAA,WAAU,UAAS,WAAW,GAAG,MAAM,MAAM,gBAAe,UAC/D,SACH,CAAA;AAEJ;ACFwB,SAAA,SAAU,EAAE,OAAsB;AAExD,SAEI,qBAAA,UAAA,EAAA,UAAA;AAAA,IAAA,oBAAC,gBAAe,EAAA,OAAM,SAAQ,QAAO,QAAM;AAAA,IAC3C,oBAAC,KAAI,EAAA,SAAS,GACZ,UAAA,oBAAC,YAAW,EAAA,SAAQ,QAAO,WAAU,cAAc,UAAA,IAAA,CAAI,EACzD,CAAA;AAAA,EAAA,GACF;AAEJ;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"EmptyBox-DT6D5gcf.js","sources":["../../admin/src/components/UI/Center.tsx","../../admin/src/components/UI/EmptyBox.tsx"],"sourcesContent":["import { Flex } from '@strapi/design-system';\n\nexport default function Center({ height = 400, children }: { height?: number, children: React.ReactNode }) {\n\n return (\n <Flex direction=\"column\" minHeight={`${height}px`} justifyContent=\"center\">\n {children}\n </Flex>\n )\n}","import { EmptyDocuments } from '@strapi/icons/symbols';\nimport { Box, Typography } from '@strapi/design-system';\n\ntype EmptyNavProps = {\n msg: string;\n}\n\nexport default function EmptyBox ({ msg }: EmptyNavProps) {\n\n return (\n <>\n <EmptyDocuments width=\"10rem\" height=\"6rem\"/>\n <Box padding={4}>\n <Typography variant=\"beta\" textColor=\"neutral600\">{msg}</Typography>\n </Box>\n </>\n )\n}"],"names":["jsx","Flex","jsxs","Fragment","EmptyDocuments","Box","Typography"],"mappings":";;;;AAEA,SAAwB,OAAO,EAAE,SAAS,KAAK,YAA4D;AAGvG,SAAAA,2BAAA,IAACC,aAAK,MAAA,EAAA,WAAU,UAAS,WAAW,GAAG,MAAM,MAAM,gBAAe,UAC/D,SACH,CAAA;AAEJ;ACFwB,SAAA,SAAU,EAAE,OAAsB;AAExD,SAEIC,2BAAA,KAAAC,qBAAA,EAAA,UAAA;AAAA,IAAAH,2BAAA,IAACI,QAAe,gBAAA,EAAA,OAAM,SAAQ,QAAO,QAAM;AAAA,IAC3CJ,2BAAA,IAACK,aAAI,KAAA,EAAA,SAAS,GACZ,UAAAL,2BAAAA,IAACM,aAAAA,YAAW,EAAA,SAAQ,QAAO,WAAU,cAAc,UAAA,IAAA,CAAI,EACzD,CAAA;AAAA,EAAA,GACF;AAEJ;;;"}