@mattisvensson/strapi-plugin-webatlas 0.11.4 → 0.11.6
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/README.md +5 -0
- package/dist/admin/RoutePicker-C6omysLv.mjs +101 -0
- package/dist/admin/RoutePicker-CZKBOemS.js +101 -0
- package/dist/admin/{SettingTitle-CcNfx_4T.mjs → SettingTitle-Bu_8jLRE.mjs} +1 -1
- package/dist/admin/{SettingTitle-BdiDHFXF.js → SettingTitle-DcQMSkno.js} +1 -1
- package/dist/admin/{index-BdyLsiR4.mjs → index-Bp-XFH1V.mjs} +1 -1
- package/dist/admin/{index-Sj2FxwAu.js → index-CbllvYIN.js} +2 -2
- package/dist/admin/{index-uW7YJoRU.js → index-CoLBgxOP.js} +5 -5
- package/dist/admin/{index-DkEReTkt.mjs → index-DLMGEpc0.mjs} +2 -2
- package/dist/admin/{index-DkfE_arE.mjs → index-DjLi4gIu.mjs} +5 -5
- package/dist/admin/{index-CEBh9c4X.js → index-Dok2SBFT.js} +2 -2
- package/dist/admin/{index-BMTlUOrK.mjs → index-DqA1gNsu.mjs} +2 -2
- package/dist/admin/{index-BX3hiURm.mjs → index-OkabmPb4.mjs} +67 -15
- package/dist/admin/{index-DBG6vBGU.js → index-e8zVLBgW.js} +1 -1
- package/dist/admin/{index-BkPtrXJO.js → index-ik3u6iCE.js} +67 -15
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/server/index.js +245 -118
- package/dist/server/index.mjs +245 -118
- package/dist/server/src/index.d.ts +3 -0
- package/package.json +1 -1
|
@@ -70,7 +70,7 @@ function transformToUrl(input, replaceSlash = true) {
|
|
|
70
70
|
input = input.replace(/-+/g, "-");
|
|
71
71
|
return input;
|
|
72
72
|
}
|
|
73
|
-
const version = "0.11.
|
|
73
|
+
const version = "0.11.5";
|
|
74
74
|
const strapi$1 = { "name": "webatlas", "displayName": "Webatlas" };
|
|
75
75
|
const pluginPkg = {
|
|
76
76
|
version,
|
|
@@ -3681,7 +3681,7 @@ function Tooltip({ description }) {
|
|
|
3681
3681
|
) }) })
|
|
3682
3682
|
] }) });
|
|
3683
3683
|
}
|
|
3684
|
-
function PathInput({ path, dispatchPath, isOverride, config }) {
|
|
3684
|
+
function PathInput({ path, dispatchPath, isOverride, config, hasUserInteracted }) {
|
|
3685
3685
|
const { formatMessage } = reactIntl.useIntl();
|
|
3686
3686
|
const displayedPath = isOverride && path.overridePath !== void 0 ? path.overridePath : path.value ?? "";
|
|
3687
3687
|
const inputBorder = path.replacement === null ? "" : path.replacement ? "1px solid #ee5e52" : "1px solid #5cb176";
|
|
@@ -3719,12 +3719,21 @@ function PathInput({ path, dispatchPath, isOverride, config }) {
|
|
|
3719
3719
|
{
|
|
3720
3720
|
id: "path-input",
|
|
3721
3721
|
value: displayedPath,
|
|
3722
|
-
onChange: (e) =>
|
|
3722
|
+
onChange: (e) => {
|
|
3723
|
+
hasUserInteracted.current = true;
|
|
3724
|
+
dispatchPath({ type: "SET_OVERRIDEPATH", payload: e.target.value });
|
|
3725
|
+
},
|
|
3723
3726
|
disabled: !isOverride,
|
|
3724
|
-
onBlur: (e) =>
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3727
|
+
onBlur: (e) => {
|
|
3728
|
+
dispatchPath({
|
|
3729
|
+
type: "SET_OVERRIDEPATH",
|
|
3730
|
+
payload: transformToUrl(e.target.value, false)
|
|
3731
|
+
});
|
|
3732
|
+
dispatchPath({
|
|
3733
|
+
type: "SET_URL_CHECK_FLAG",
|
|
3734
|
+
payload: true
|
|
3735
|
+
});
|
|
3736
|
+
},
|
|
3728
3737
|
style: { outline: inputBorder }
|
|
3729
3738
|
}
|
|
3730
3739
|
),
|
|
@@ -3813,8 +3822,8 @@ function reducer(state, action) {
|
|
|
3813
3822
|
prevValue: state.value,
|
|
3814
3823
|
needsUrlCheck: false
|
|
3815
3824
|
};
|
|
3816
|
-
case "
|
|
3817
|
-
return { ...state, needsUrlCheck: false };
|
|
3825
|
+
case "SET_URL_CHECK_FLAG":
|
|
3826
|
+
return { ...state, needsUrlCheck: action.payload || false };
|
|
3818
3827
|
case "SET_REPLACEMENT":
|
|
3819
3828
|
return { ...state, replacement: action.payload };
|
|
3820
3829
|
case "SET_UIDPATH":
|
|
@@ -3946,7 +3955,7 @@ const Panel = ({ config }) => {
|
|
|
3946
3955
|
if (path.needsUrlCheck && path.value) {
|
|
3947
3956
|
if (path.uidPath === path.value || initialPath.current === path.value) return;
|
|
3948
3957
|
debouncedCheckPath(path.value, route?.documentId || null);
|
|
3949
|
-
dispatchPath({ type: "
|
|
3958
|
+
dispatchPath({ type: "SET_URL_CHECK_FLAG" });
|
|
3950
3959
|
} else {
|
|
3951
3960
|
setValidationState("idle");
|
|
3952
3961
|
dispatchPath({ type: "SET_REPLACEMENT", payload: null });
|
|
@@ -4073,7 +4082,8 @@ const Panel = ({ config }) => {
|
|
|
4073
4082
|
path,
|
|
4074
4083
|
dispatchPath,
|
|
4075
4084
|
isOverride,
|
|
4076
|
-
config
|
|
4085
|
+
config,
|
|
4086
|
+
hasUserInteracted
|
|
4077
4087
|
}
|
|
4078
4088
|
),
|
|
4079
4089
|
validationState !== "initial" && /* @__PURE__ */ jsxRuntime.jsx(PathInfo, { validationState, replacement: path.replacement })
|
|
@@ -4159,7 +4169,7 @@ const index = {
|
|
|
4159
4169
|
id: `${PLUGIN_ID}.link.paths`,
|
|
4160
4170
|
defaultMessage: "Paths"
|
|
4161
4171
|
},
|
|
4162
|
-
Component: () => Promise.resolve().then(() => require("./index-
|
|
4172
|
+
Component: () => Promise.resolve().then(() => require("./index-e8zVLBgW.js")),
|
|
4163
4173
|
permissions: [pluginPermissions["page.routes"][0]]
|
|
4164
4174
|
});
|
|
4165
4175
|
app.addMenuLink({
|
|
@@ -4169,7 +4179,7 @@ const index = {
|
|
|
4169
4179
|
id: `${PLUGIN_ID}.link.navigation`,
|
|
4170
4180
|
defaultMessage: "Navigation"
|
|
4171
4181
|
},
|
|
4172
|
-
Component: () => Promise.resolve().then(() => require("./index-
|
|
4182
|
+
Component: () => Promise.resolve().then(() => require("./index-CoLBgxOP.js")),
|
|
4173
4183
|
permissions: [pluginPermissions["page.navigation"][0]]
|
|
4174
4184
|
});
|
|
4175
4185
|
app.addSettingsLink(
|
|
@@ -4187,7 +4197,7 @@ const index = {
|
|
|
4187
4197
|
},
|
|
4188
4198
|
id: `${PLUGIN_ID}-general`,
|
|
4189
4199
|
to: `${PLUGIN_ID}/general`,
|
|
4190
|
-
Component: () => Promise.resolve().then(() => require("./index-
|
|
4200
|
+
Component: () => Promise.resolve().then(() => require("./index-Dok2SBFT.js")),
|
|
4191
4201
|
permissions: [pluginPermissions["settings.general"][0]]
|
|
4192
4202
|
}
|
|
4193
4203
|
);
|
|
@@ -4198,9 +4208,51 @@ const index = {
|
|
|
4198
4208
|
},
|
|
4199
4209
|
id: `${PLUGIN_ID}-navigation`,
|
|
4200
4210
|
to: `${PLUGIN_ID}/navigation`,
|
|
4201
|
-
Component: () => Promise.resolve().then(() => require("./index-
|
|
4211
|
+
Component: () => Promise.resolve().then(() => require("./index-CbllvYIN.js")),
|
|
4202
4212
|
permissions: [pluginPermissions["settings.navigation"][0]]
|
|
4203
4213
|
});
|
|
4214
|
+
app.customFields.register({
|
|
4215
|
+
name: "route-picker",
|
|
4216
|
+
pluginId: PLUGIN_ID,
|
|
4217
|
+
type: "string",
|
|
4218
|
+
intlLabel: {
|
|
4219
|
+
id: `${PLUGIN_ID}.route-picker.label`,
|
|
4220
|
+
defaultMessage: "Route Picker"
|
|
4221
|
+
},
|
|
4222
|
+
intlDescription: {
|
|
4223
|
+
id: `${PLUGIN_ID}.route-picker.description`,
|
|
4224
|
+
defaultMessage: "Select a route"
|
|
4225
|
+
},
|
|
4226
|
+
components: {
|
|
4227
|
+
Input: async () => Promise.resolve().then(() => require("./RoutePicker-CZKBOemS.js")).then((module2) => ({
|
|
4228
|
+
default: module2.default
|
|
4229
|
+
}))
|
|
4230
|
+
},
|
|
4231
|
+
options: {
|
|
4232
|
+
advanced: [
|
|
4233
|
+
{
|
|
4234
|
+
sectionTitle: {
|
|
4235
|
+
id: "global.settings",
|
|
4236
|
+
defaultMessage: "Settings"
|
|
4237
|
+
},
|
|
4238
|
+
items: [
|
|
4239
|
+
{
|
|
4240
|
+
name: "required",
|
|
4241
|
+
type: "checkbox",
|
|
4242
|
+
intlLabel: {
|
|
4243
|
+
id: "content-type-builder.form.attribute.item.requiredField",
|
|
4244
|
+
defaultMessage: "Required field"
|
|
4245
|
+
},
|
|
4246
|
+
description: {
|
|
4247
|
+
id: "content-type-builder.form.attribute.item.requiredField.description",
|
|
4248
|
+
defaultMessage: "You won't be able to create an entry if this field is empty"
|
|
4249
|
+
}
|
|
4250
|
+
}
|
|
4251
|
+
]
|
|
4252
|
+
}
|
|
4253
|
+
]
|
|
4254
|
+
}
|
|
4255
|
+
});
|
|
4204
4256
|
app.registerPlugin({
|
|
4205
4257
|
id: PLUGIN_ID,
|
|
4206
4258
|
initializer: Initializer,
|
package/dist/admin/index.js
CHANGED
package/dist/admin/index.mjs
CHANGED
package/dist/server/index.js
CHANGED
|
@@ -4664,6 +4664,205 @@ function calculateParentAndOrder({
|
|
|
4664
4664
|
calculatedOrder
|
|
4665
4665
|
};
|
|
4666
4666
|
}
|
|
4667
|
+
async function enrichWebatlasData(data, contentTypeUid) {
|
|
4668
|
+
if (!data || typeof data !== "object") return data;
|
|
4669
|
+
const collectDocumentIds = (obj, uid) => {
|
|
4670
|
+
if (!obj || typeof obj !== "object") return [];
|
|
4671
|
+
const ids = [];
|
|
4672
|
+
if (obj.documentId) ids.push(obj.documentId);
|
|
4673
|
+
if (!uid) return ids;
|
|
4674
|
+
const ct = strapi.contentTypes[uid];
|
|
4675
|
+
if (!ct?.attributes) return ids;
|
|
4676
|
+
for (const [key, attr] of Object.entries(ct.attributes)) {
|
|
4677
|
+
const attribute = attr;
|
|
4678
|
+
if (attribute.type === "relation" && obj[key]) {
|
|
4679
|
+
const targetUid = attribute.target;
|
|
4680
|
+
if (Array.isArray(obj[key])) {
|
|
4681
|
+
ids.push(...obj[key].flatMap((item) => collectDocumentIds(item, targetUid)));
|
|
4682
|
+
} else {
|
|
4683
|
+
ids.push(...collectDocumentIds(obj[key], targetUid));
|
|
4684
|
+
}
|
|
4685
|
+
}
|
|
4686
|
+
if (attribute.type === "component" && obj[key]) {
|
|
4687
|
+
const componentUid = attribute.component;
|
|
4688
|
+
if (Array.isArray(obj[key])) {
|
|
4689
|
+
ids.push(...obj[key].flatMap((item) => collectDocumentIds(item, componentUid)));
|
|
4690
|
+
} else {
|
|
4691
|
+
ids.push(...collectDocumentIds(obj[key], componentUid));
|
|
4692
|
+
}
|
|
4693
|
+
}
|
|
4694
|
+
if (attribute.type === "dynamiczone" && Array.isArray(obj[key])) {
|
|
4695
|
+
ids.push(
|
|
4696
|
+
...obj[key].flatMap((item) => {
|
|
4697
|
+
if (!item || !item.__component) return [];
|
|
4698
|
+
return collectDocumentIds(item, item.__component);
|
|
4699
|
+
})
|
|
4700
|
+
);
|
|
4701
|
+
}
|
|
4702
|
+
}
|
|
4703
|
+
return ids;
|
|
4704
|
+
};
|
|
4705
|
+
const documentIds = collectDocumentIds(data, contentTypeUid);
|
|
4706
|
+
if (documentIds.length === 0) return data;
|
|
4707
|
+
const uniqueDocumentIds = [...new Set(documentIds)];
|
|
4708
|
+
const routes2 = await strapi.db?.query(waRoute).findMany({
|
|
4709
|
+
where: {
|
|
4710
|
+
relatedDocumentId: { $in: uniqueDocumentIds }
|
|
4711
|
+
},
|
|
4712
|
+
select: ["relatedDocumentId", "relatedContentType", "path", "canonicalPath", "slug", "uidPath"]
|
|
4713
|
+
});
|
|
4714
|
+
const routeMap = new Map(routes2?.map((route2) => [route2.relatedDocumentId, route2]) || []);
|
|
4715
|
+
const enrichEntity2 = (entity, uid) => {
|
|
4716
|
+
if (!entity || typeof entity !== "object") return entity;
|
|
4717
|
+
const ct = uid ? strapi.contentTypes[uid] : null;
|
|
4718
|
+
const isWebatlasEnabled = ct?.pluginOptions?.webatlas?.enabled === true;
|
|
4719
|
+
if (isWebatlasEnabled && entity.documentId && routeMap.has(entity.documentId)) {
|
|
4720
|
+
const route2 = routeMap.get(entity.documentId);
|
|
4721
|
+
entity.webatlas = {
|
|
4722
|
+
path: route2.path || "",
|
|
4723
|
+
canonicalPath: route2.canonicalPath || "",
|
|
4724
|
+
slug: route2.slug || "",
|
|
4725
|
+
uidPath: route2.uidPath || ""
|
|
4726
|
+
};
|
|
4727
|
+
}
|
|
4728
|
+
if (ct?.attributes) {
|
|
4729
|
+
for (const [key, attr] of Object.entries(ct.attributes)) {
|
|
4730
|
+
const attribute = attr;
|
|
4731
|
+
if (attribute.type === "relation" && entity[key]) {
|
|
4732
|
+
const targetUid = attribute.target;
|
|
4733
|
+
if (Array.isArray(entity[key])) {
|
|
4734
|
+
entity[key] = entity[key].map(
|
|
4735
|
+
(item) => item ? enrichEntity2(item, targetUid) : item
|
|
4736
|
+
);
|
|
4737
|
+
} else {
|
|
4738
|
+
entity[key] = enrichEntity2(entity[key], targetUid);
|
|
4739
|
+
}
|
|
4740
|
+
}
|
|
4741
|
+
if (attribute.type === "component" && entity[key]) {
|
|
4742
|
+
const componentUid = attribute.component;
|
|
4743
|
+
if (Array.isArray(entity[key])) {
|
|
4744
|
+
entity[key] = entity[key].map(
|
|
4745
|
+
(item) => item ? enrichEntity2(item, componentUid) : item
|
|
4746
|
+
);
|
|
4747
|
+
} else {
|
|
4748
|
+
entity[key] = enrichEntity2(entity[key], componentUid);
|
|
4749
|
+
}
|
|
4750
|
+
}
|
|
4751
|
+
if (attribute.type === "dynamiczone" && Array.isArray(entity[key])) {
|
|
4752
|
+
entity[key] = entity[key].map((item) => {
|
|
4753
|
+
if (!item || !item.__component) return item;
|
|
4754
|
+
return enrichEntity2(item, item.__component);
|
|
4755
|
+
});
|
|
4756
|
+
}
|
|
4757
|
+
}
|
|
4758
|
+
}
|
|
4759
|
+
return entity;
|
|
4760
|
+
};
|
|
4761
|
+
return enrichEntity2(data, contentTypeUid);
|
|
4762
|
+
}
|
|
4763
|
+
function isExternalUrl(value) {
|
|
4764
|
+
return !/^[a-z0-9]+$/.test(value);
|
|
4765
|
+
}
|
|
4766
|
+
function collectRoutePickerIds(obj, uid) {
|
|
4767
|
+
if (!obj || typeof obj !== "object") return [];
|
|
4768
|
+
const ids = [];
|
|
4769
|
+
if (!uid) return ids;
|
|
4770
|
+
const ct = strapi.contentTypes[uid] || strapi.components?.[uid];
|
|
4771
|
+
if (!ct?.attributes) return ids;
|
|
4772
|
+
for (const [key, attr] of Object.entries(ct.attributes)) {
|
|
4773
|
+
const attribute = attr;
|
|
4774
|
+
if (attribute.customField === "plugin::webatlas.route-picker" && obj[key]) {
|
|
4775
|
+
const value = obj[key];
|
|
4776
|
+
if (typeof value === "string" && !isExternalUrl(value)) {
|
|
4777
|
+
ids.push(value);
|
|
4778
|
+
}
|
|
4779
|
+
}
|
|
4780
|
+
if (attribute.type === "relation" && obj[key]) {
|
|
4781
|
+
const targetUid = attribute.target;
|
|
4782
|
+
if (Array.isArray(obj[key])) {
|
|
4783
|
+
ids.push(...obj[key].flatMap((item) => collectRoutePickerIds(item, targetUid)));
|
|
4784
|
+
} else {
|
|
4785
|
+
ids.push(...collectRoutePickerIds(obj[key], targetUid));
|
|
4786
|
+
}
|
|
4787
|
+
}
|
|
4788
|
+
if (attribute.type === "component" && obj[key]) {
|
|
4789
|
+
const componentUid = attribute.component;
|
|
4790
|
+
if (Array.isArray(obj[key])) {
|
|
4791
|
+
ids.push(...obj[key].flatMap((item) => collectRoutePickerIds(item, componentUid)));
|
|
4792
|
+
} else {
|
|
4793
|
+
ids.push(...collectRoutePickerIds(obj[key], componentUid));
|
|
4794
|
+
}
|
|
4795
|
+
}
|
|
4796
|
+
if (attribute.type === "dynamiczone" && Array.isArray(obj[key])) {
|
|
4797
|
+
ids.push(
|
|
4798
|
+
...obj[key].flatMap((item) => {
|
|
4799
|
+
if (!item || !item.__component) return [];
|
|
4800
|
+
return collectRoutePickerIds(item, item.__component);
|
|
4801
|
+
})
|
|
4802
|
+
);
|
|
4803
|
+
}
|
|
4804
|
+
}
|
|
4805
|
+
return ids;
|
|
4806
|
+
}
|
|
4807
|
+
function enrichEntity(entity, uid, routeMap) {
|
|
4808
|
+
if (!entity || typeof entity !== "object") return entity;
|
|
4809
|
+
const ct = strapi.contentTypes[uid] || strapi.components?.[uid];
|
|
4810
|
+
if (!ct?.attributes) return entity;
|
|
4811
|
+
for (const [key, attr] of Object.entries(ct.attributes)) {
|
|
4812
|
+
const attribute = attr;
|
|
4813
|
+
if (attribute.customField === "plugin::webatlas.route-picker" && entity[key]) {
|
|
4814
|
+
const value = entity[key];
|
|
4815
|
+
if (typeof value === "string" && !isExternalUrl(value)) {
|
|
4816
|
+
const route2 = routeMap.get(value);
|
|
4817
|
+
if (route2) {
|
|
4818
|
+
entity[key] = route2.canonicalPath || route2.path || value;
|
|
4819
|
+
}
|
|
4820
|
+
}
|
|
4821
|
+
}
|
|
4822
|
+
if (attribute.type === "relation" && entity[key]) {
|
|
4823
|
+
const targetUid = attribute.target;
|
|
4824
|
+
if (Array.isArray(entity[key])) {
|
|
4825
|
+
entity[key] = entity[key].map(
|
|
4826
|
+
(item) => item ? enrichEntity(item, targetUid, routeMap) : item
|
|
4827
|
+
);
|
|
4828
|
+
} else {
|
|
4829
|
+
entity[key] = enrichEntity(entity[key], targetUid, routeMap);
|
|
4830
|
+
}
|
|
4831
|
+
}
|
|
4832
|
+
if (attribute.type === "component" && entity[key]) {
|
|
4833
|
+
const componentUid = attribute.component;
|
|
4834
|
+
if (Array.isArray(entity[key])) {
|
|
4835
|
+
entity[key] = entity[key].map(
|
|
4836
|
+
(item) => item ? enrichEntity(item, componentUid, routeMap) : item
|
|
4837
|
+
);
|
|
4838
|
+
} else {
|
|
4839
|
+
entity[key] = enrichEntity(entity[key], componentUid, routeMap);
|
|
4840
|
+
}
|
|
4841
|
+
}
|
|
4842
|
+
if (attribute.type === "dynamiczone" && Array.isArray(entity[key])) {
|
|
4843
|
+
entity[key] = entity[key].map((item) => {
|
|
4844
|
+
if (!item || !item.__component) return item;
|
|
4845
|
+
return enrichEntity(item, item.__component, routeMap);
|
|
4846
|
+
});
|
|
4847
|
+
}
|
|
4848
|
+
}
|
|
4849
|
+
return entity;
|
|
4850
|
+
}
|
|
4851
|
+
async function enrichRoutePickerFields(data, contentTypeUid) {
|
|
4852
|
+
if (!data || typeof data !== "object") return data;
|
|
4853
|
+
const documentIds = collectRoutePickerIds(data, contentTypeUid);
|
|
4854
|
+
if (documentIds.length === 0) return data;
|
|
4855
|
+
const uniqueDocumentIds = [...new Set(documentIds)];
|
|
4856
|
+
const routes2 = await strapi.db?.query(waRoute).findMany({
|
|
4857
|
+
where: {
|
|
4858
|
+
documentId: { $in: uniqueDocumentIds }
|
|
4859
|
+
},
|
|
4860
|
+
select: ["documentId", "path", "canonicalPath"]
|
|
4861
|
+
});
|
|
4862
|
+
const routeMap = new Map(routes2?.map((route2) => [route2.documentId, route2]) || []);
|
|
4863
|
+
const enriched = enrichEntity(data, contentTypeUid, routeMap);
|
|
4864
|
+
return enriched;
|
|
4865
|
+
}
|
|
4667
4866
|
const migration_001_canonical_path = {
|
|
4668
4867
|
version: "001",
|
|
4669
4868
|
description: "Migrate title field to canonicalPath using transformToUrl",
|
|
@@ -4902,7 +5101,7 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
|
|
|
4902
5101
|
const data = context.params.data;
|
|
4903
5102
|
const { webatlas } = data;
|
|
4904
5103
|
const { slug, parentDocumentId, isOverride } = webatlas || {};
|
|
4905
|
-
const transformedSlug = slug ? transformToUrl(slug) : null;
|
|
5104
|
+
const transformedSlug = slug ? transformToUrl(slug, !isOverride) : null;
|
|
4906
5105
|
const result2 = await next();
|
|
4907
5106
|
if (!transformedSlug) return result2;
|
|
4908
5107
|
const existing = await strapi2.db?.query(waRoute).findOne({
|
|
@@ -4975,7 +5174,7 @@ function documentMiddleware(strapi2, enabledContentTypes, config2) {
|
|
|
4975
5174
|
});
|
|
4976
5175
|
}
|
|
4977
5176
|
}
|
|
4978
|
-
const transformedSlug = transformToUrl(slug);
|
|
5177
|
+
const transformedSlug = transformToUrl(slug, !isOverride);
|
|
4979
5178
|
let rawPath = transformedSlug;
|
|
4980
5179
|
if (!isOverride) rawPath = parent ? `${parent.path}/${transformedSlug}` : transformedSlug;
|
|
4981
5180
|
const validatedPath = await duplicateCheck(rawPath, relatedRoute?.documentId ?? null);
|
|
@@ -5086,130 +5285,59 @@ const addWebatlasField = ({ strapi: strapi2 }) => {
|
|
|
5086
5285
|
([uid, ct]) => ct.info?.pluralName === apiEndpoint
|
|
5087
5286
|
);
|
|
5088
5287
|
if (!contentTypeEntry) return;
|
|
5089
|
-
const [contentTypeUid
|
|
5090
|
-
const collectDocumentIds = (data, uid = contentTypeUid) => {
|
|
5091
|
-
if (!data || typeof data !== "object") return [];
|
|
5092
|
-
const ids = [];
|
|
5093
|
-
if (data.documentId) {
|
|
5094
|
-
ids.push(data.documentId);
|
|
5095
|
-
}
|
|
5096
|
-
const ct = strapi2.contentTypes[uid];
|
|
5097
|
-
if (ct?.attributes) {
|
|
5098
|
-
for (const [key, attr] of Object.entries(ct.attributes)) {
|
|
5099
|
-
const attribute = attr;
|
|
5100
|
-
if (attribute.type === "relation" && data[key]) {
|
|
5101
|
-
const targetUid = attribute.target;
|
|
5102
|
-
if (Array.isArray(data[key])) {
|
|
5103
|
-
ids.push(...data[key].flatMap((item) => collectDocumentIds(item, targetUid)));
|
|
5104
|
-
} else {
|
|
5105
|
-
ids.push(...collectDocumentIds(data[key], targetUid));
|
|
5106
|
-
}
|
|
5107
|
-
}
|
|
5108
|
-
if (attribute.type === "component" && data[key]) {
|
|
5109
|
-
const componentUid = attribute.component;
|
|
5110
|
-
if (Array.isArray(data[key])) {
|
|
5111
|
-
ids.push(...data[key].flatMap((item) => collectDocumentIds(item, componentUid)));
|
|
5112
|
-
} else {
|
|
5113
|
-
ids.push(...collectDocumentIds(data[key], componentUid));
|
|
5114
|
-
}
|
|
5115
|
-
}
|
|
5116
|
-
if (attribute.type === "dynamiczone" && Array.isArray(data[key])) {
|
|
5117
|
-
ids.push(
|
|
5118
|
-
...data[key].flatMap((item) => {
|
|
5119
|
-
const componentUid = item.__component;
|
|
5120
|
-
return collectDocumentIds(item, componentUid);
|
|
5121
|
-
})
|
|
5122
|
-
);
|
|
5123
|
-
}
|
|
5124
|
-
}
|
|
5125
|
-
}
|
|
5126
|
-
return ids;
|
|
5127
|
-
};
|
|
5128
|
-
let documentIds = [];
|
|
5288
|
+
const [contentTypeUid] = contentTypeEntry;
|
|
5129
5289
|
if (ctx.body.data) {
|
|
5130
5290
|
if (Array.isArray(ctx.body.data)) {
|
|
5131
|
-
|
|
5291
|
+
ctx.body.data = await Promise.all(
|
|
5292
|
+
ctx.body.data.map((item) => enrichWebatlasData(item, contentTypeUid))
|
|
5293
|
+
);
|
|
5132
5294
|
} else {
|
|
5133
|
-
|
|
5295
|
+
ctx.body.data = await enrichWebatlasData(ctx.body.data, contentTypeUid);
|
|
5134
5296
|
}
|
|
5135
5297
|
} else if (Array.isArray(ctx.body)) {
|
|
5136
|
-
|
|
5298
|
+
ctx.body = await Promise.all(ctx.body.map((item) => enrichWebatlasData(item, contentTypeUid)));
|
|
5137
5299
|
} else if (typeof ctx.body === "object") {
|
|
5138
|
-
|
|
5300
|
+
ctx.body = await enrichWebatlasData(ctx.body, contentTypeUid);
|
|
5139
5301
|
}
|
|
5140
|
-
|
|
5141
|
-
|
|
5142
|
-
|
|
5143
|
-
|
|
5144
|
-
|
|
5145
|
-
|
|
5146
|
-
|
|
5147
|
-
|
|
5148
|
-
|
|
5149
|
-
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
const isWebatlasEnabled = ct?.pluginOptions?.webatlas?.enabled === true;
|
|
5160
|
-
if (isWebatlasEnabled && data.documentId && routeMap.has(data.documentId)) {
|
|
5161
|
-
const route2 = routeMap.get(data.documentId);
|
|
5162
|
-
data.webatlas = {
|
|
5163
|
-
path: route2.path || "",
|
|
5164
|
-
canonicalPath: route2.canonicalPath || "",
|
|
5165
|
-
slug: route2.slug || "",
|
|
5166
|
-
uidPath: route2.uidPath || ""
|
|
5167
|
-
};
|
|
5168
|
-
}
|
|
5169
|
-
if (ct?.attributes) {
|
|
5170
|
-
for (const [key, attr] of Object.entries(ct.attributes)) {
|
|
5171
|
-
const attribute = attr;
|
|
5172
|
-
if (attribute.type === "relation" && data[key]) {
|
|
5173
|
-
const targetUid = attribute.target;
|
|
5174
|
-
if (Array.isArray(data[key])) {
|
|
5175
|
-
data[key] = data[key].map((item) => enrichWebatlasField(item, targetUid));
|
|
5176
|
-
} else {
|
|
5177
|
-
data[key] = enrichWebatlasField(data[key], targetUid);
|
|
5178
|
-
}
|
|
5179
|
-
}
|
|
5180
|
-
if (attribute.type === "component" && data[key]) {
|
|
5181
|
-
const componentUid = attribute.component;
|
|
5182
|
-
if (Array.isArray(data[key])) {
|
|
5183
|
-
data[key] = data[key].map((item) => enrichWebatlasField(item, componentUid));
|
|
5184
|
-
} else {
|
|
5185
|
-
data[key] = enrichWebatlasField(data[key], componentUid);
|
|
5186
|
-
}
|
|
5187
|
-
}
|
|
5188
|
-
if (attribute.type === "dynamiczone" && Array.isArray(data[key])) {
|
|
5189
|
-
data[key] = data[key].map((item) => {
|
|
5190
|
-
const componentUid = item.__component;
|
|
5191
|
-
return enrichWebatlasField(item, componentUid);
|
|
5192
|
-
});
|
|
5193
|
-
}
|
|
5194
|
-
}
|
|
5195
|
-
}
|
|
5196
|
-
return data;
|
|
5197
|
-
};
|
|
5302
|
+
};
|
|
5303
|
+
};
|
|
5304
|
+
const enrichRoutePicker = ({ strapi: strapi2 }) => {
|
|
5305
|
+
return async (ctx, next) => {
|
|
5306
|
+
await next();
|
|
5307
|
+
if (!ctx.request.url.startsWith("/api/")) {
|
|
5308
|
+
return;
|
|
5309
|
+
}
|
|
5310
|
+
if (!ctx.body || ctx.status !== 200) {
|
|
5311
|
+
return;
|
|
5312
|
+
}
|
|
5313
|
+
const urlMatch = ctx.request.url.match(/^\/api\/([^/?]+)/);
|
|
5314
|
+
if (!urlMatch) return;
|
|
5315
|
+
const apiEndpoint = urlMatch[1];
|
|
5316
|
+
const contentTypeEntry = Object.entries(strapi2.contentTypes).find(
|
|
5317
|
+
([uid, ct]) => ct.info?.pluralName === apiEndpoint
|
|
5318
|
+
);
|
|
5319
|
+
if (!contentTypeEntry) return;
|
|
5320
|
+
const [contentTypeUid] = contentTypeEntry;
|
|
5198
5321
|
if (ctx.body.data) {
|
|
5199
5322
|
if (Array.isArray(ctx.body.data)) {
|
|
5200
|
-
ctx.body.data =
|
|
5323
|
+
ctx.body.data = await Promise.all(
|
|
5324
|
+
ctx.body.data.map((item) => enrichRoutePickerFields(item, contentTypeUid))
|
|
5325
|
+
);
|
|
5201
5326
|
} else {
|
|
5202
|
-
ctx.body.data =
|
|
5327
|
+
ctx.body.data = await enrichRoutePickerFields(ctx.body.data, contentTypeUid);
|
|
5203
5328
|
}
|
|
5204
5329
|
} else if (Array.isArray(ctx.body)) {
|
|
5205
|
-
ctx.body =
|
|
5330
|
+
ctx.body = await Promise.all(
|
|
5331
|
+
ctx.body.map((item) => enrichRoutePickerFields(item, contentTypeUid))
|
|
5332
|
+
);
|
|
5206
5333
|
} else if (typeof ctx.body === "object") {
|
|
5207
|
-
ctx.body =
|
|
5334
|
+
ctx.body = await enrichRoutePickerFields(ctx.body, contentTypeUid);
|
|
5208
5335
|
}
|
|
5209
5336
|
};
|
|
5210
5337
|
};
|
|
5211
5338
|
const middlewares = {
|
|
5212
|
-
addWebatlasField
|
|
5339
|
+
addWebatlasField,
|
|
5340
|
+
enrichRoutePicker
|
|
5213
5341
|
};
|
|
5214
5342
|
const bootstrap = async ({ strapi: strapi2 }) => {
|
|
5215
5343
|
try {
|
|
@@ -5223,6 +5351,7 @@ const bootstrap = async ({ strapi: strapi2 }) => {
|
|
|
5223
5351
|
documentMiddleware(strapi2, enabledContentTypes, config2);
|
|
5224
5352
|
webatlasMiddleware(strapi2);
|
|
5225
5353
|
strapi2.server.use(middlewares.addWebatlasField({ strapi: strapi2 }));
|
|
5354
|
+
strapi2.server.use(middlewares.enrichRoutePicker({ strapi: strapi2 }));
|
|
5226
5355
|
} catch (error) {
|
|
5227
5356
|
strapi2.log.error(`Bootstrap failed. ${String(error)}`);
|
|
5228
5357
|
}
|
|
@@ -5230,6 +5359,11 @@ const bootstrap = async ({ strapi: strapi2 }) => {
|
|
|
5230
5359
|
const destroy = ({ strapi: strapi2 }) => {
|
|
5231
5360
|
};
|
|
5232
5361
|
const register = ({ strapi: strapi2 }) => {
|
|
5362
|
+
strapi2.customFields.register({
|
|
5363
|
+
name: "route-picker",
|
|
5364
|
+
plugin: PLUGIN_ID,
|
|
5365
|
+
type: "string"
|
|
5366
|
+
});
|
|
5233
5367
|
};
|
|
5234
5368
|
const config = {
|
|
5235
5369
|
default: {
|
|
@@ -6092,17 +6226,10 @@ const client = ({ strapi: strapi2 }) => ({
|
|
|
6092
6226
|
if (!entity) return null;
|
|
6093
6227
|
let cleanEntity = cleanRootKeys(entity);
|
|
6094
6228
|
cleanEntity = removeWaFields(cleanEntity);
|
|
6095
|
-
|
|
6096
|
-
|
|
6097
|
-
canonicalPath: route2.canonicalPath,
|
|
6098
|
-
slug: route2.slug,
|
|
6099
|
-
uidPath: route2.uidPath
|
|
6100
|
-
};
|
|
6229
|
+
cleanEntity = await enrichWebatlasData(cleanEntity, route2.relatedContentType);
|
|
6230
|
+
cleanEntity = await enrichRoutePickerFields(cleanEntity, contentTypeKey);
|
|
6101
6231
|
return {
|
|
6102
6232
|
contentType: contentType.info.singularName,
|
|
6103
|
-
webatlas: {
|
|
6104
|
-
...webatlasFields
|
|
6105
|
-
},
|
|
6106
6233
|
...cleanEntity
|
|
6107
6234
|
};
|
|
6108
6235
|
} catch (e) {
|