@treely/strapi-slices 7.5.0 → 7.5.1
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.
- package/dist/strapi-slices.cjs.development.js +36 -68
- package/dist/strapi-slices.cjs.development.js.map +1 -1
- package/dist/strapi-slices.cjs.production.min.js +1 -1
- package/dist/strapi-slices.cjs.production.min.js.map +1 -1
- package/dist/strapi-slices.esm.js +36 -68
- package/dist/strapi-slices.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/integrations/strapi/getAllSlugsFromStrapi.test.ts +1 -13
- package/src/integrations/strapi/getAvailableLocalesFromStrapi.test.ts +1 -1
- package/src/integrations/strapi/getStrapiCollectionType.test.ts +20 -15
- package/src/integrations/strapi/getStrapiCollectionType.ts +26 -20
|
@@ -22,11 +22,6 @@ import useEmblaCarousel from 'embla-carousel-react';
|
|
|
22
22
|
import AutoScroll from 'embla-carousel-auto-scroll';
|
|
23
23
|
import useSWRInfinite from 'swr/infinite';
|
|
24
24
|
|
|
25
|
-
function _arrayLikeToArray(r, a) {
|
|
26
|
-
(null == a || a > r.length) && (a = r.length);
|
|
27
|
-
for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
|
|
28
|
-
return n;
|
|
29
|
-
}
|
|
30
25
|
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
31
26
|
try {
|
|
32
27
|
var i = n[a](c),
|
|
@@ -52,23 +47,6 @@ function _asyncToGenerator(n) {
|
|
|
52
47
|
});
|
|
53
48
|
};
|
|
54
49
|
}
|
|
55
|
-
function _createForOfIteratorHelperLoose(r, e) {
|
|
56
|
-
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
|
|
57
|
-
if (t) return (t = t.call(r)).next.bind(t);
|
|
58
|
-
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
|
|
59
|
-
t && (r = t);
|
|
60
|
-
var o = 0;
|
|
61
|
-
return function () {
|
|
62
|
-
return o >= r.length ? {
|
|
63
|
-
done: !0
|
|
64
|
-
} : {
|
|
65
|
-
done: !1,
|
|
66
|
-
value: r[o++]
|
|
67
|
-
};
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
71
|
-
}
|
|
72
50
|
function _extends() {
|
|
73
51
|
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
74
52
|
for (var e = 1; e < arguments.length; e++) {
|
|
@@ -391,13 +369,6 @@ function _regeneratorRuntime() {
|
|
|
391
369
|
function _taggedTemplateLiteralLoose(e, t) {
|
|
392
370
|
return t || (t = e.slice(0)), e.raw = t, e;
|
|
393
371
|
}
|
|
394
|
-
function _unsupportedIterableToArray(r, a) {
|
|
395
|
-
if (r) {
|
|
396
|
-
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
397
|
-
var t = {}.toString.call(r).slice(8, -1);
|
|
398
|
-
return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
372
|
|
|
402
373
|
var STRAPI_URI = process.env.NEXT_PUBLIC_STRAPI_URI || 'http://127.0.0.1:1337';
|
|
403
374
|
var STRAPI_DEFAULT_PAGE_SIZE = '100';
|
|
@@ -593,7 +564,7 @@ var getPortfolioProjects = /*#__PURE__*/function () {
|
|
|
593
564
|
|
|
594
565
|
var getStrapiCollectionType = /*#__PURE__*/function () {
|
|
595
566
|
var _ref2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(path, key, _ref) {
|
|
596
|
-
var _ref$locale, locale, _ref$preview, preview, _ref$filters, filters, cache, allLocales,
|
|
567
|
+
var _ref$locale, locale, _ref$preview, preview, _ref$filters, filters, cache, allLocales, promises, responses, results, localizedResponses, fallbackResponses, result;
|
|
597
568
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
598
569
|
while (1) switch (_context.prev = _context.next) {
|
|
599
570
|
case 0:
|
|
@@ -606,45 +577,42 @@ var getStrapiCollectionType = /*#__PURE__*/function () {
|
|
|
606
577
|
if (!allLocales.includes(STRAPI_FALLBACK_LOCALE)) {
|
|
607
578
|
allLocales.push(STRAPI_FALLBACK_LOCALE);
|
|
608
579
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
pLevel: '6',
|
|
619
|
-
loc: loc,
|
|
620
|
-
'pagination[pageSize]': STRAPI_DEFAULT_PAGE_SIZE,
|
|
621
|
-
filters: filters
|
|
622
|
-
};
|
|
623
|
-
if (preview) {
|
|
624
|
-
params.publicationState = 'preview';
|
|
625
|
-
}
|
|
626
|
-
_context.next = 14;
|
|
627
|
-
return strapiClient.get(path, {
|
|
628
|
-
params: params,
|
|
629
|
-
cache: cache
|
|
630
|
-
});
|
|
631
|
-
case 14:
|
|
632
|
-
_yield$strapiClient$g = _context.sent;
|
|
633
|
-
data = _yield$strapiClient$g.data;
|
|
634
|
-
responses.push.apply(responses, data.data);
|
|
635
|
-
case 17:
|
|
636
|
-
_context.next = 8;
|
|
637
|
-
break;
|
|
638
|
-
case 19:
|
|
639
|
-
groupedResponses = responses.reduce(function (acc, response) {
|
|
640
|
-
var keyValue = response.attributes[key];
|
|
641
|
-
if (!acc[keyValue] || response.attributes.locale === locale) {
|
|
642
|
-
acc[keyValue] = response;
|
|
580
|
+
promises = allLocales.map(function (loc) {
|
|
581
|
+
var params = {
|
|
582
|
+
pLevel: '6',
|
|
583
|
+
locale: loc,
|
|
584
|
+
'pagination[pageSize]': STRAPI_DEFAULT_PAGE_SIZE,
|
|
585
|
+
filters: filters
|
|
586
|
+
};
|
|
587
|
+
if (preview) {
|
|
588
|
+
params.publicationState = 'preview';
|
|
643
589
|
}
|
|
644
|
-
return
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
590
|
+
return strapiClient.get(path, {
|
|
591
|
+
params: params,
|
|
592
|
+
cache: cache
|
|
593
|
+
});
|
|
594
|
+
});
|
|
595
|
+
_context.next = 9;
|
|
596
|
+
return Promise.all(promises);
|
|
597
|
+
case 9:
|
|
598
|
+
responses = _context.sent;
|
|
599
|
+
results = responses.flatMap(function (response) {
|
|
600
|
+
return response.data.data;
|
|
601
|
+
});
|
|
602
|
+
localizedResponses = results.filter(function (d) {
|
|
603
|
+
return d.attributes.locale === locale;
|
|
604
|
+
});
|
|
605
|
+
fallbackResponses = results.filter(function (d) {
|
|
606
|
+
return d.attributes.locale === STRAPI_FALLBACK_LOCALE;
|
|
607
|
+
});
|
|
608
|
+
result = fallbackResponses.map(function (fallbackResponse) {
|
|
609
|
+
var localizedResponse = localizedResponses.find(function (localized) {
|
|
610
|
+
return localized.attributes[key] === fallbackResponse.attributes[key];
|
|
611
|
+
});
|
|
612
|
+
return localizedResponse || fallbackResponse;
|
|
613
|
+
});
|
|
614
|
+
return _context.abrupt("return", result);
|
|
615
|
+
case 15:
|
|
648
616
|
case "end":
|
|
649
617
|
return _context.stop();
|
|
650
618
|
}
|