multi-content-type-relation 2.1.1 → 2.1.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.
- package/dist/_chunks/en-Bk9okOMP.js +0 -1
- package/dist/_chunks/en-Cj4T04Z2.mjs +0 -1
- package/dist/_chunks/fr-KHPiQOFP.mjs +0 -1
- package/dist/_chunks/fr-ZS3aTnjj.js +0 -1
- package/dist/_chunks/index-BtldAbIW.js +0 -1
- package/dist/_chunks/index-CyBD50Lc.js +0 -1
- package/dist/_chunks/index-DGcImy9s.mjs +0 -1
- package/dist/_chunks/index-DdX2rVzB.mjs +0 -1
- package/dist/admin/index.js +0 -1
- package/dist/admin/index.mjs +0 -1
- package/dist/server/index.js +1 -2
- package/dist/server/index.mjs +1 -2
- package/package.json +1 -1
- package/dist/_chunks/en-Bk9okOMP.js.map +0 -1
- package/dist/_chunks/en-Cj4T04Z2.mjs.map +0 -1
- package/dist/_chunks/fr-KHPiQOFP.mjs.map +0 -1
- package/dist/_chunks/fr-ZS3aTnjj.js.map +0 -1
- package/dist/_chunks/index-BHcolZ4N.mjs +0 -334
- package/dist/_chunks/index-BHcolZ4N.mjs.map +0 -1
- package/dist/_chunks/index-BtldAbIW.js.map +0 -1
- package/dist/_chunks/index-CktBIBSM.js +0 -333
- package/dist/_chunks/index-CktBIBSM.js.map +0 -1
- package/dist/_chunks/index-CxWt3llJ.js +0 -3567
- package/dist/_chunks/index-CxWt3llJ.js.map +0 -1
- package/dist/_chunks/index-CyBD50Lc.js.map +0 -1
- package/dist/_chunks/index-D6nv39Fp.mjs +0 -3565
- package/dist/_chunks/index-D6nv39Fp.mjs.map +0 -1
- package/dist/_chunks/index-DGcImy9s.mjs.map +0 -1
- package/dist/_chunks/index-DdX2rVzB.mjs.map +0 -1
- package/dist/admin/index.js.map +0 -1
- package/dist/admin/index.mjs.map +0 -1
- package/dist/server/index.js.map +0 -1
- package/dist/server/index.mjs.map +0 -1
|
@@ -3565,4 +3565,3 @@ const Index = (props) => {
|
|
|
3565
3565
|
return /* @__PURE__ */ jsxRuntime.jsx(designSystem.DesignSystemProvider, { theme, children: /* @__PURE__ */ jsxRuntime.jsx(MainInput, { ...props, attribute }) });
|
|
3566
3566
|
};
|
|
3567
3567
|
exports.default = Index;
|
|
3568
|
-
//# sourceMappingURL=index-CyBD50Lc.js.map
|
package/dist/admin/index.js
CHANGED
package/dist/admin/index.mjs
CHANGED
package/dist/server/index.js
CHANGED
|
@@ -279,7 +279,7 @@ const schema = {
|
|
|
279
279
|
},
|
|
280
280
|
pluginOptions: {
|
|
281
281
|
"content-manager": {
|
|
282
|
-
visible:
|
|
282
|
+
visible: true
|
|
283
283
|
},
|
|
284
284
|
"content-type-builder": {
|
|
285
285
|
visible: false
|
|
@@ -506,4 +506,3 @@ const index = {
|
|
|
506
506
|
middlewares
|
|
507
507
|
};
|
|
508
508
|
module.exports = index;
|
|
509
|
-
//# sourceMappingURL=index.js.map
|
package/dist/server/index.mjs
CHANGED
|
@@ -278,7 +278,7 @@ const schema = {
|
|
|
278
278
|
},
|
|
279
279
|
pluginOptions: {
|
|
280
280
|
"content-manager": {
|
|
281
|
-
visible:
|
|
281
|
+
visible: true
|
|
282
282
|
},
|
|
283
283
|
"content-type-builder": {
|
|
284
284
|
visible: false
|
|
@@ -507,4 +507,3 @@ const index = {
|
|
|
507
507
|
export {
|
|
508
508
|
index as default
|
|
509
509
|
};
|
|
510
|
-
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"en-Bk9okOMP.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"en-Cj4T04Z2.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fr-KHPiQOFP.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fr-ZS3aTnjj.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,334 +0,0 @@
|
|
|
1
|
-
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { PuzzlePiece } from "@strapi/icons";
|
|
3
|
-
import { getFetchClient, unstable_useContentManagerContext } from "@strapi/strapi/admin";
|
|
4
|
-
import { useState, useEffect } from "react";
|
|
5
|
-
import { Box, Loader, Divider, Flex, Typography, CardBadge } from "@strapi/design-system";
|
|
6
|
-
import { useIntl } from "react-intl";
|
|
7
|
-
const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
|
|
8
|
-
const v = glob[path];
|
|
9
|
-
if (v) {
|
|
10
|
-
return typeof v === "function" ? v() : Promise.resolve(v);
|
|
11
|
-
}
|
|
12
|
-
return new Promise((_, reject) => {
|
|
13
|
-
(typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(
|
|
14
|
-
reject.bind(
|
|
15
|
-
null,
|
|
16
|
-
new Error(
|
|
17
|
-
"Unknown variable dynamic import: " + path + (path.split("/").length !== segs ? ". Note that variables only represent file names one level deep." : "")
|
|
18
|
-
)
|
|
19
|
-
)
|
|
20
|
-
);
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
const name$1 = "multi-content-type-relation";
|
|
24
|
-
const strapi = {
|
|
25
|
-
name: "multi-content-type-relation"
|
|
26
|
-
};
|
|
27
|
-
const pluginPkg = {
|
|
28
|
-
name: name$1,
|
|
29
|
-
strapi
|
|
30
|
-
};
|
|
31
|
-
const PluginIcon = () => /* @__PURE__ */ jsx(PuzzlePiece, {});
|
|
32
|
-
const pluginId = pluginPkg.name.replace(
|
|
33
|
-
/^(@[^-,.][\w,-]+\/|strapi-)plugin-/i,
|
|
34
|
-
""
|
|
35
|
-
);
|
|
36
|
-
const fetchMatchingContent = async (keyword, contentTypes, locale) => {
|
|
37
|
-
const { post } = getFetchClient();
|
|
38
|
-
const response = await post(`/${pluginId}/get-content`, {
|
|
39
|
-
contentTypes: contentTypes.split(","),
|
|
40
|
-
keyword,
|
|
41
|
-
locale
|
|
42
|
-
});
|
|
43
|
-
const data = response.data;
|
|
44
|
-
if (!data) throw new Error("No data returned from API");
|
|
45
|
-
const total = data.reduce((accumulator, option) => {
|
|
46
|
-
if (!option.results) return accumulator;
|
|
47
|
-
return accumulator + option.results.length;
|
|
48
|
-
}, 0);
|
|
49
|
-
return {
|
|
50
|
-
data,
|
|
51
|
-
total
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
const formatToStrapiField = (entries) => {
|
|
55
|
-
if (entries.length === 0) return "";
|
|
56
|
-
return JSON.stringify(
|
|
57
|
-
entries.map((entry) => ({
|
|
58
|
-
uid: entry.uid,
|
|
59
|
-
documentId: entry.item.documentId,
|
|
60
|
-
MRCT: true
|
|
61
|
-
})).filter(Boolean)
|
|
62
|
-
);
|
|
63
|
-
};
|
|
64
|
-
const validateCurrentRelations = async (entries) => {
|
|
65
|
-
const { post } = getFetchClient();
|
|
66
|
-
const response = await post(`/${pluginId}/validate-relations`, {
|
|
67
|
-
entries
|
|
68
|
-
});
|
|
69
|
-
return response.data;
|
|
70
|
-
};
|
|
71
|
-
const listContentTypes = async () => {
|
|
72
|
-
try {
|
|
73
|
-
const { get } = getFetchClient();
|
|
74
|
-
const response = await get(`/${pluginId}/list-content-types`);
|
|
75
|
-
return response.data;
|
|
76
|
-
} catch (error) {
|
|
77
|
-
console.error(error);
|
|
78
|
-
return [];
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
const STORAGE_KEY = "mctr::content_types";
|
|
82
|
-
function getContentTypes() {
|
|
83
|
-
const raw = sessionStorage.getItem(STORAGE_KEY);
|
|
84
|
-
return raw ? JSON.parse(raw) : void 0;
|
|
85
|
-
}
|
|
86
|
-
function getContentTypeForUid(uid) {
|
|
87
|
-
const contentTypes = getContentTypes();
|
|
88
|
-
if (!Array.isArray(contentTypes)) return;
|
|
89
|
-
return contentTypes.find((contentType) => contentType.uid === uid);
|
|
90
|
-
}
|
|
91
|
-
function setContentTypes(contentTypes) {
|
|
92
|
-
const stringified = JSON.stringify(contentTypes);
|
|
93
|
-
sessionStorage.setItem(STORAGE_KEY, stringified);
|
|
94
|
-
}
|
|
95
|
-
const useTranslate = () => {
|
|
96
|
-
const { formatMessage } = useIntl();
|
|
97
|
-
const translate = (key, values) => {
|
|
98
|
-
return formatMessage({ id: key }, values);
|
|
99
|
-
};
|
|
100
|
-
return {
|
|
101
|
-
translate
|
|
102
|
-
};
|
|
103
|
-
};
|
|
104
|
-
const SidePanel = () => {
|
|
105
|
-
const { translate } = useTranslate();
|
|
106
|
-
const {
|
|
107
|
-
id: documentId,
|
|
108
|
-
model: uid,
|
|
109
|
-
isSingleType
|
|
110
|
-
} = unstable_useContentManagerContext();
|
|
111
|
-
const [linkedContent, setLinkedContent] = useState([]);
|
|
112
|
-
const [loading, setLoading] = useState(false);
|
|
113
|
-
useEffect(() => {
|
|
114
|
-
const fetchRevertRelations = async () => {
|
|
115
|
-
const { post } = getFetchClient();
|
|
116
|
-
const response = await post(`/${pluginId}/fetch-revert-relations`, {
|
|
117
|
-
documentId,
|
|
118
|
-
uid,
|
|
119
|
-
isSingleType
|
|
120
|
-
});
|
|
121
|
-
setLinkedContent(Array.isArray(response.data) ? response.data.filter(Boolean) : []);
|
|
122
|
-
setLoading(false);
|
|
123
|
-
};
|
|
124
|
-
fetchRevertRelations();
|
|
125
|
-
}, []);
|
|
126
|
-
if (loading)
|
|
127
|
-
return /* @__PURE__ */ jsx(Box, { width: "100%", children: /* @__PURE__ */ jsx(Loader, {}) });
|
|
128
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
129
|
-
/* @__PURE__ */ jsx(Divider, {}),
|
|
130
|
-
/* @__PURE__ */ jsxs(Box, { width: "100%", marginTop: 4, children: [
|
|
131
|
-
/* @__PURE__ */ jsx(Flex, { children: /* @__PURE__ */ jsx(
|
|
132
|
-
Typography,
|
|
133
|
-
{
|
|
134
|
-
variant: "sigma",
|
|
135
|
-
fontWeight: "bold",
|
|
136
|
-
textTransform: "uppercase",
|
|
137
|
-
marginBottom: 1,
|
|
138
|
-
textColor: "neutral600",
|
|
139
|
-
children: translate("sidePanel.linkedContent")
|
|
140
|
-
}
|
|
141
|
-
) }),
|
|
142
|
-
linkedContent.length > 0 ? /* @__PURE__ */ jsx(Flex, { children: /* @__PURE__ */ jsxs(Typography, { variant: "omega", textColor: "neutral600", marginBottom: 3, children: [
|
|
143
|
-
translate("sidePanel.referencedIn"),
|
|
144
|
-
" ",
|
|
145
|
-
linkedContent.length,
|
|
146
|
-
" ",
|
|
147
|
-
translate("sidePanel.otherContents")
|
|
148
|
-
] }) }) : /* @__PURE__ */ jsx(Flex, { children: /* @__PURE__ */ jsx(Typography, { variant: "omega", textColor: "neutral600", marginBottom: 3, children: translate("sidePanel.notReferenced") }) }),
|
|
149
|
-
/* @__PURE__ */ jsx(Box, { marginTop: 2, children: linkedContent.map((content, idx) => /* @__PURE__ */ jsxs(
|
|
150
|
-
Box,
|
|
151
|
-
{
|
|
152
|
-
marginBottom: idx < linkedContent.length - 1 ? 3 : 0,
|
|
153
|
-
children: [
|
|
154
|
-
/* @__PURE__ */ jsxs(
|
|
155
|
-
Flex,
|
|
156
|
-
{
|
|
157
|
-
direction: "row",
|
|
158
|
-
justifyContent: "space-between",
|
|
159
|
-
alignItems: "flex-start",
|
|
160
|
-
paddingY: 2,
|
|
161
|
-
paddingX: 3,
|
|
162
|
-
children: [
|
|
163
|
-
/* @__PURE__ */ jsxs(Box, { children: [
|
|
164
|
-
/* @__PURE__ */ jsx(Box, { children: /* @__PURE__ */ jsx(
|
|
165
|
-
"a",
|
|
166
|
-
{
|
|
167
|
-
href: content.isSingleType ? `/admin/content-manager/single-types/${content.uid}` : `/admin/content-manager/collection-types/${content.uid}/${content.documentId}`,
|
|
168
|
-
target: "_blank",
|
|
169
|
-
style: { textDecoration: "none" },
|
|
170
|
-
children: /* @__PURE__ */ jsx(
|
|
171
|
-
Typography,
|
|
172
|
-
{
|
|
173
|
-
children: content.title ?? content.documentId
|
|
174
|
-
}
|
|
175
|
-
)
|
|
176
|
-
}
|
|
177
|
-
) }),
|
|
178
|
-
/* @__PURE__ */ jsx(Box, { marginTop: 1, children: /* @__PURE__ */ jsxs(
|
|
179
|
-
Typography,
|
|
180
|
-
{
|
|
181
|
-
variant: "pi",
|
|
182
|
-
textColor: "neutral600",
|
|
183
|
-
style: { lineHeight: 1.2 },
|
|
184
|
-
children: [
|
|
185
|
-
translate("sidePanel.field"),
|
|
186
|
-
" ",
|
|
187
|
-
content.field
|
|
188
|
-
]
|
|
189
|
-
}
|
|
190
|
-
) })
|
|
191
|
-
] }),
|
|
192
|
-
/* @__PURE__ */ jsx(Box, { marginLeft: 2, children: /* @__PURE__ */ jsx(CardBadge, { children: content.type }) })
|
|
193
|
-
]
|
|
194
|
-
}
|
|
195
|
-
),
|
|
196
|
-
idx < linkedContent.length - 1 && /* @__PURE__ */ jsx(Box, { marginY: 1, children: /* @__PURE__ */ jsx(Divider, {}) })
|
|
197
|
-
]
|
|
198
|
-
},
|
|
199
|
-
content.documentId
|
|
200
|
-
)) })
|
|
201
|
-
] })
|
|
202
|
-
] });
|
|
203
|
-
};
|
|
204
|
-
const name = pluginPkg.strapi.name;
|
|
205
|
-
const index = {
|
|
206
|
-
async register(app) {
|
|
207
|
-
const contentTypes = await listContentTypes();
|
|
208
|
-
setContentTypes(contentTypes);
|
|
209
|
-
app.customFields.register({
|
|
210
|
-
name,
|
|
211
|
-
pluginId,
|
|
212
|
-
type: "richtext",
|
|
213
|
-
intlLabel: {
|
|
214
|
-
id: "multi-content-type-relation.text-ai.label",
|
|
215
|
-
defaultMessage: "Multi Content Type Relation"
|
|
216
|
-
},
|
|
217
|
-
intlDescription: {
|
|
218
|
-
id: "multi-content-type-relation.text-ai.description",
|
|
219
|
-
defaultMessage: "Write content types separated by commas"
|
|
220
|
-
},
|
|
221
|
-
icon: PluginIcon,
|
|
222
|
-
// don't forget to create/import your icon component
|
|
223
|
-
components: {
|
|
224
|
-
Input: () => import(
|
|
225
|
-
/* webpackChunkName: "input-component" */
|
|
226
|
-
"./index-D6nv39Fp.mjs"
|
|
227
|
-
)
|
|
228
|
-
},
|
|
229
|
-
inputSize: {
|
|
230
|
-
default: 12,
|
|
231
|
-
isResizable: false
|
|
232
|
-
},
|
|
233
|
-
options: {
|
|
234
|
-
base: [
|
|
235
|
-
/*
|
|
236
|
-
Declare settings to be added to the "Base settings" section
|
|
237
|
-
of the field in the Content-Type Builder
|
|
238
|
-
*/
|
|
239
|
-
{
|
|
240
|
-
sectionTitle: {
|
|
241
|
-
id: "multi-content-type-relation.text-ai.length",
|
|
242
|
-
defaultMessage: "Content types"
|
|
243
|
-
},
|
|
244
|
-
items: contentTypes.map((contentType) => {
|
|
245
|
-
const value = contentType.info.singularName;
|
|
246
|
-
return {
|
|
247
|
-
intlLabel: {
|
|
248
|
-
id: `multi-content-type-relation.options.${contentType.uid}`,
|
|
249
|
-
defaultMessage: contentType.info.displayName
|
|
250
|
-
},
|
|
251
|
-
type: "checkbox",
|
|
252
|
-
name: `options.contentTypes.${value}`
|
|
253
|
-
};
|
|
254
|
-
})
|
|
255
|
-
}
|
|
256
|
-
],
|
|
257
|
-
advanced: [
|
|
258
|
-
{
|
|
259
|
-
sectionTitle: {
|
|
260
|
-
id: "global.settings",
|
|
261
|
-
defaultMessage: "Settings"
|
|
262
|
-
},
|
|
263
|
-
items: [
|
|
264
|
-
{
|
|
265
|
-
name: "required",
|
|
266
|
-
type: "checkbox",
|
|
267
|
-
intlLabel: {
|
|
268
|
-
id: "content-type-relation-select.options.advanced.requiredField",
|
|
269
|
-
defaultMessage: "Required field"
|
|
270
|
-
},
|
|
271
|
-
description: {
|
|
272
|
-
id: "content-type-relation-select.options.advanced.requiredField.description",
|
|
273
|
-
defaultMessage: "You won't be able to create an entry if this field is empty"
|
|
274
|
-
}
|
|
275
|
-
},
|
|
276
|
-
{
|
|
277
|
-
name: "options.min",
|
|
278
|
-
type: "number",
|
|
279
|
-
intlLabel: {
|
|
280
|
-
id: "content-type-relation-select.options.advanced.minField",
|
|
281
|
-
defaultMessage: "Minimum values"
|
|
282
|
-
},
|
|
283
|
-
description: {
|
|
284
|
-
id: "content-type-relation-select.options.advanced.minField.description",
|
|
285
|
-
defaultMessage: "Minimum number of entries"
|
|
286
|
-
}
|
|
287
|
-
},
|
|
288
|
-
{
|
|
289
|
-
name: "options.max",
|
|
290
|
-
type: "number",
|
|
291
|
-
intlLabel: {
|
|
292
|
-
id: "content-type-relation-select.options.advanced.maxField",
|
|
293
|
-
defaultMessage: "Maximum values"
|
|
294
|
-
},
|
|
295
|
-
description: {
|
|
296
|
-
id: "content-type-relation-select.options.advanced.maxField.description",
|
|
297
|
-
defaultMessage: "Maximum number of entries"
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
]
|
|
301
|
-
}
|
|
302
|
-
]
|
|
303
|
-
}
|
|
304
|
-
});
|
|
305
|
-
},
|
|
306
|
-
bootstrap(app) {
|
|
307
|
-
app.getPlugin("content-manager").injectComponent("editView", "right-links", {
|
|
308
|
-
name: "side-panel",
|
|
309
|
-
Component: SidePanel
|
|
310
|
-
});
|
|
311
|
-
},
|
|
312
|
-
async registerTrads(app) {
|
|
313
|
-
const { locales } = app;
|
|
314
|
-
const importedTrads = await Promise.all(
|
|
315
|
-
locales.map(async (locale) => {
|
|
316
|
-
const { default: data } = await __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/en.json": () => import("./en-Cj4T04Z2.mjs"), "./translations/fr.json": () => import("./fr-KHPiQOFP.mjs") }), `./translations/${locale}.json`, 3);
|
|
317
|
-
return {
|
|
318
|
-
data,
|
|
319
|
-
locale
|
|
320
|
-
};
|
|
321
|
-
})
|
|
322
|
-
);
|
|
323
|
-
return Promise.resolve(importedTrads);
|
|
324
|
-
}
|
|
325
|
-
};
|
|
326
|
-
export {
|
|
327
|
-
formatToStrapiField as a,
|
|
328
|
-
fetchMatchingContent as f,
|
|
329
|
-
getContentTypeForUid as g,
|
|
330
|
-
index as i,
|
|
331
|
-
useTranslate as u,
|
|
332
|
-
validateCurrentRelations as v
|
|
333
|
-
};
|
|
334
|
-
//# sourceMappingURL=index-BHcolZ4N.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-BHcolZ4N.mjs","sources":["../../admin/src/components/PluginIcon/index.tsx","../../admin/src/pluginId.ts","../../admin/src/helpers/content.ts","../../admin/src/helpers/storage.ts","../../admin/src/hooks/useTranslate.ts","../../admin/src/components/SidePanel/SidePanel.tsx","../../admin/src/index.ts"],"sourcesContent":["import { PuzzlePiece } from '@strapi/icons';\n\nconst PluginIcon = () => <PuzzlePiece />;\n\nexport default PluginIcon;\n","import pluginPkg from '../../package.json';\n\nconst pluginId = pluginPkg.name.replace(\n /^(@[^-,.][\\w,-]+\\/|strapi-)plugin-/i,\n ''\n);\n\nexport default pluginId;\n","import { getFetchClient } from '@strapi/strapi/admin';\n\nimport pluginId from '../pluginId';\nimport {\n FormattedStrapiEntry,\n MatchingContent,\n MatchingContentResponse,\n SelectedEntry,\n} from '../interface';\n\nexport const fetchMatchingContent = async (\n keyword: string,\n contentTypes: string,\n locale: string\n): Promise<MatchingContentResponse> => {\n const { post } = getFetchClient();\n const response = await post(`/${pluginId}/get-content`, {\n contentTypes: contentTypes.split(','),\n keyword,\n locale,\n });\n\n const data = response.data as MatchingContent[];\n\n if (!data) throw new Error('No data returned from API');\n\n const total = data.reduce((accumulator, option) => {\n if (!option.results) return accumulator;\n\n return accumulator + option.results.length;\n }, 0);\n\n return {\n data,\n total,\n };\n};\n\nexport const formatToStrapiField = (entries: SelectedEntry[]) => {\n if (entries.length === 0) return '';\n\n return JSON.stringify(\n entries\n .map((entry) => ({\n uid: entry.uid,\n documentId: entry.item.documentId,\n MRCT: true,\n }))\n .filter(Boolean)\n );\n};\n\nexport const validateCurrentRelations = async (\n entries: FormattedStrapiEntry[]\n) => {\n const { post } = getFetchClient();\n\n const response = await post(`/${pluginId}/validate-relations`, {\n entries,\n });\n\n return response.data as SelectedEntry[];\n};\n\nexport const listContentTypes = async () => {\n try {\n const { get } = getFetchClient();\n const response = await get(`/${pluginId}/list-content-types`);\n\n return response.data;\n } catch (error) {\n console.error(error);\n return [];\n }\n};\n","export type LightContentType = {\n apiName: string;\n attributes: Record<string, Record<string, unknown>>[];\n collectionName: string;\n globalId: string;\n modelName: string;\n modelType: string;\n options?: { draftAndPublish?: boolean };\n uid: string;\n};\n\nconst STORAGE_KEY = 'mctr::content_types';\n\nexport function getContentTypes() {\n const raw = sessionStorage.getItem(STORAGE_KEY);\n\n return raw ? (JSON.parse(raw) as LightContentType[]) : undefined;\n}\n\nexport function getContentTypeForUid(uid: string) {\n const contentTypes = getContentTypes();\n\n if (!Array.isArray(contentTypes)) return;\n\n return contentTypes.find((contentType) => contentType.uid === uid);\n}\n\nexport function setContentTypes(contentTypes: LightContentType[]) {\n const stringified = JSON.stringify(contentTypes);\n\n sessionStorage.setItem(STORAGE_KEY, stringified);\n}\n","import { useIntl } from 'react-intl';\n\nconst useTranslate = () => {\n const { formatMessage } = useIntl();\n\n const translate = (key: string, values?: Record<string, any>) => {\n return formatMessage({ id: key }, values);\n };\n\n return {\n translate\n };\n};\n\nexport default useTranslate;\n","import React, { useEffect, useState } from 'react';\nimport {\n Box,\n Typography,\n Card,\n CardBody,\n Flex,\n Divider\n} from '@strapi/design-system';\nimport { CardTitle, CardContent, CardBadge } from '@strapi/design-system';\nimport { getFetchClient } from '@strapi/strapi/admin';\nimport pluginId from '../../pluginId';\nimport { unstable_useContentManagerContext as useContentManagerContext } from '@strapi/strapi/admin';\nimport { Loader } from '@strapi/design-system';\nimport useTranslate from '../../hooks/useTranslate';\n\ninterface LinkedContent {\n documentId: string;\n title: string;\n type: string;\n uid: string;\n field: string;\n isSingleType: boolean;\n}\n\ninterface SidePanelProps {\n contentType?: string;\n contentId?: string;\n}\n\nconst SidePanel: React.FC<SidePanelProps> = () => {\n const { translate } = useTranslate();\n const {\n id: documentId,\n model: uid,\n isSingleType\n } = useContentManagerContext();\n\n const [linkedContent, setLinkedContent] = useState<LinkedContent[]>([]);\n const [loading, setLoading] = useState(false);\n\n useEffect(() => {\n const fetchRevertRelations = async () => {\n const { post } = getFetchClient();\n\n const response = await post(`/${pluginId}/fetch-revert-relations`, {\n documentId,\n uid,\n isSingleType\n });\n\n setLinkedContent(Array.isArray(response.data) ? response.data.filter(Boolean) : []);\n setLoading(false);\n };\n\n fetchRevertRelations();\n }, []);\n\n if (loading)\n return (\n <Box width=\"100%\">\n <Loader />\n </Box>\n );\n\n return (\n <>\n <Divider />\n <Box width=\"100%\" marginTop={4}>\n <Flex>\n <Typography\n variant=\"sigma\"\n fontWeight=\"bold\"\n textTransform=\"uppercase\"\n marginBottom={1}\n textColor=\"neutral600\"\n >\n {translate('sidePanel.linkedContent')}\n </Typography>\n </Flex>\n\n {linkedContent.length > 0 ? (\n <Flex>\n <Typography variant=\"omega\" textColor=\"neutral600\" marginBottom={3}>\n {translate('sidePanel.referencedIn')} {linkedContent.length}{' '}\n {translate('sidePanel.otherContents')}\n </Typography>\n </Flex>\n ) : (\n <Flex>\n <Typography variant=\"omega\" textColor=\"neutral600\" marginBottom={3}>\n {translate('sidePanel.notReferenced')}\n </Typography>\n </Flex>\n )}\n\n <Box marginTop={2}>\n {linkedContent.map((content, idx) => (\n <Box\n key={content.documentId}\n marginBottom={idx < linkedContent.length - 1 ? 3 : 0}\n >\n <Flex\n direction=\"row\"\n justifyContent=\"space-between\"\n alignItems=\"flex-start\"\n paddingY={2}\n paddingX={3}\n >\n <Box>\n <Box>\n <a\n href={\n content.isSingleType\n ? `/admin/content-manager/single-types/${content.uid}`\n : `/admin/content-manager/collection-types/${content.uid}/${content.documentId}`\n }\n target=\"_blank\"\n style={{ textDecoration: 'none' }}\n >\n <Typography\n >\n {content.title ?? content.documentId}\n </Typography>\n </a>\n </Box>\n <Box marginTop={1}>\n <Typography\n variant=\"pi\"\n textColor=\"neutral600\"\n style={{ lineHeight: 1.2 }}\n >\n {translate('sidePanel.field')} {content.field}\n </Typography>\n </Box>\n </Box>\n <Box marginLeft={2}>\n <CardBadge>{content.type}</CardBadge>\n </Box>\n </Flex>\n {idx < linkedContent.length - 1 && (\n <Box marginY={1}>\n <Divider />\n </Box>\n )}\n </Box>\n ))}\n </Box>\n </Box>\n </>\n );\n};\n\nexport default SidePanel;\n","import React, { ComponentType } from 'react';\n\nimport pluginPkg from '../../package.json';\n\nimport PluginIcon from './components/PluginIcon';\nimport pluginId from './pluginId';\nimport { listContentTypes } from './helpers/content';\nimport { setContentTypes } from './helpers/storage';\nimport SidePanel from './components/SidePanel/SidePanel';\n\nconst name = pluginPkg.strapi.name;\n\nexport default {\n async register(app: any) {\n const contentTypes = await listContentTypes();\n setContentTypes(contentTypes);\n\n app.customFields.register({\n name,\n pluginId,\n type: 'richtext',\n intlLabel: {\n id: 'multi-content-type-relation.text-ai.label',\n defaultMessage: 'Multi Content Type Relation'\n },\n intlDescription: {\n id: 'multi-content-type-relation.text-ai.description',\n defaultMessage: 'Write content types separated by commas'\n },\n icon: PluginIcon, // don't forget to create/import your icon component\n components: {\n Input: () =>\n import(\n /* webpackChunkName: \"input-component\" */ './components/Input'\n ) as unknown as ComponentType\n },\n inputSize: {\n default: 12,\n isResizable: false\n },\n options: {\n base: [\n /*\n Declare settings to be added to the \"Base settings\" section\n of the field in the Content-Type Builder\n */\n {\n sectionTitle: {\n id: 'multi-content-type-relation.text-ai.length',\n defaultMessage: 'Content types'\n },\n items: contentTypes.map((contentType: any) => {\n const value = contentType.info.singularName;\n\n return {\n intlLabel: {\n id: `multi-content-type-relation.options.${contentType.uid}`,\n defaultMessage: contentType.info.displayName\n },\n type: 'checkbox',\n name: `options.contentTypes.${value}`\n };\n })\n }\n ],\n advanced: [\n {\n sectionTitle: {\n id: 'global.settings',\n defaultMessage: 'Settings'\n },\n items: [\n {\n name: 'required',\n type: 'checkbox',\n intlLabel: {\n id: 'content-type-relation-select.options.advanced.requiredField',\n defaultMessage: 'Required field'\n },\n description: {\n id: 'content-type-relation-select.options.advanced.requiredField.description',\n defaultMessage:\n \"You won't be able to create an entry if this field is empty\"\n }\n },\n {\n name: 'options.min',\n type: 'number',\n intlLabel: {\n id: 'content-type-relation-select.options.advanced.minField',\n defaultMessage: 'Minimum values'\n },\n description: {\n id: 'content-type-relation-select.options.advanced.minField.description',\n defaultMessage: 'Minimum number of entries'\n }\n },\n {\n name: 'options.max',\n type: 'number',\n intlLabel: {\n id: 'content-type-relation-select.options.advanced.maxField',\n defaultMessage: 'Maximum values'\n },\n description: {\n id: 'content-type-relation-select.options.advanced.maxField.description',\n defaultMessage: 'Maximum number of entries'\n }\n }\n ]\n }\n ]\n }\n });\n },\n\n bootstrap(app: any) {\n app\n .getPlugin('content-manager')\n .injectComponent('editView', 'right-links', {\n name: 'side-panel',\n Component: SidePanel\n });\n },\n\n async registerTrads(app: any) {\n const { locales } = app;\n\n const importedTrads = await Promise.all(\n (locales as any[]).map(async (locale) => {\n const { default: data } = await import(`./translations/${locale}.json`);\n\n return {\n data,\n locale\n };\n })\n );\n\n return Promise.resolve(importedTrads);\n }\n};\n"],"names":["useContentManagerContext"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,MAAM,aAAa,MAAM,oBAAC,aAAA,EAAY;ACAtC,MAAM,WAAW,UAAU,KAAK;AAAA,EAC9B;AAAA,EACA;AACF;ACKO,MAAM,uBAAuB,OAClC,SACA,cACA,WACqC;AACrC,QAAM,EAAE,KAAA,IAAS,eAAA;AACjB,QAAM,WAAW,MAAM,KAAK,IAAI,QAAQ,gBAAgB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,WAAW;AAAA,IAAA,CACZ;AAAA,EAAA;AAAA,EAGL,MAAM,cAAc,KAAU;AAC5B,UAAM,EAAE,YAAY;AAEpB,UAAM,gBAAgB,MAAM,QAAQ;AAAA,MACjC,QAAkB,IAAI,OAAO,WAAW;AACvC,cAAM,EAAE,SAAS,KAAA,IAAS,MAAM,kMAAA,kBAAA,MAAA,SAAA,CAAA;AAEhC,eAAO;AAAA,UACL;AAAA,UACA;AAAA,QAAA;AAAA,MACF,CACD;AAAA,IAAA;AAGH,WAAO,QAAQ,QAAQ,aAAa;AAAA,EAAA;AAExC;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-BtldAbIW.js","sources":["../../admin/src/components/PluginIcon/index.tsx","../../admin/src/pluginId.ts","../../admin/src/helpers/content.ts","../../admin/src/helpers/storage.ts","../../admin/src/hooks/useTranslate.ts","../../admin/src/components/SidePanel/SidePanel.tsx","../../admin/src/index.ts"],"sourcesContent":["import { PuzzlePiece } from '@strapi/icons';\n\nconst PluginIcon = () => <PuzzlePiece />;\n\nexport default PluginIcon;\n","import pluginPkg from '../../package.json';\n\nconst pluginId = pluginPkg.name.replace(\n /^(@[^-,.][\\w,-]+\\/|strapi-)plugin-/i,\n ''\n);\n\nexport default pluginId;\n","import { getFetchClient } from '@strapi/strapi/admin';\n\nimport pluginId from '../pluginId';\nimport {\n FormattedStrapiEntry,\n MatchingContent,\n MatchingContentResponse,\n SelectedEntry,\n} from '../interface';\n\nexport const fetchMatchingContent = async (\n keyword: string,\n contentTypes: string,\n locale: string\n): Promise<MatchingContentResponse> => {\n const { post } = getFetchClient();\n const response = await post(`/${pluginId}/get-content`, {\n contentTypes: contentTypes.split(','),\n keyword,\n locale,\n });\n\n const data = response.data as MatchingContent[];\n\n if (!data) throw new Error('No data returned from API');\n\n const total = data.reduce((accumulator, option) => {\n if (!option.results) return accumulator;\n\n return accumulator + option.results.length;\n }, 0);\n\n return {\n data,\n total,\n };\n};\n\nexport const formatToStrapiField = (entries: SelectedEntry[]) => {\n if (entries.length === 0) return '';\n\n return JSON.stringify(\n entries\n .map((entry) => ({\n uid: entry.uid,\n documentId: entry.item.documentId,\n MRCT: true,\n }))\n .filter(Boolean)\n );\n};\n\nexport const validateCurrentRelations = async (\n entries: FormattedStrapiEntry[]\n) => {\n const { post } = getFetchClient();\n\n const response = await post(`/${pluginId}/validate-relations`, {\n entries,\n });\n\n return response.data as SelectedEntry[];\n};\n\nexport const listContentTypes = async () => {\n try {\n const { get } = getFetchClient();\n const response = await get(`/${pluginId}/list-content-types`);\n\n return response.data;\n } catch (error) {\n console.error(error);\n return [];\n }\n};\n","export type LightContentType = {\n apiName: string;\n attributes: Record<string, Record<string, unknown>>[];\n collectionName: string;\n globalId: string;\n modelName: string;\n modelType: string;\n options?: { draftAndPublish?: boolean };\n uid: string;\n};\n\nconst STORAGE_KEY = 'mctr::content_types';\n\nexport function getContentTypes() {\n const raw = sessionStorage.getItem(STORAGE_KEY);\n\n return raw ? (JSON.parse(raw) as LightContentType[]) : undefined;\n}\n\nexport function getContentTypeForUid(uid: string) {\n const contentTypes = getContentTypes();\n\n if (!Array.isArray(contentTypes)) return;\n\n return contentTypes.find((contentType) => contentType.uid === uid);\n}\n\nexport function setContentTypes(contentTypes: LightContentType[]) {\n const stringified = JSON.stringify(contentTypes);\n\n sessionStorage.setItem(STORAGE_KEY, stringified);\n}\n","import { useIntl } from 'react-intl';\n\nconst useTranslate = () => {\n const { formatMessage } = useIntl();\n\n const translate = (key: string, values?: Record<string, any>) => {\n return formatMessage({ id: key }, values);\n };\n\n return {\n translate\n };\n};\n\nexport default useTranslate;\n","import React, { useEffect, useState } from 'react';\nimport {\n Box,\n Typography,\n Card,\n CardBody,\n Flex,\n Divider\n} from '@strapi/design-system';\nimport { CardTitle, CardContent, CardBadge } from '@strapi/design-system';\nimport { getFetchClient } from '@strapi/strapi/admin';\nimport pluginId from '../../pluginId';\nimport { unstable_useContentManagerContext as useContentManagerContext } from '@strapi/strapi/admin';\nimport { Loader } from '@strapi/design-system';\nimport useTranslate from '../../hooks/useTranslate';\n\ninterface LinkedContent {\n documentId: string;\n title: string;\n type: string;\n uid: string;\n field: string;\n isSingleType: boolean;\n}\n\ninterface SidePanelProps {\n contentType?: string;\n contentId?: string;\n}\n\nconst SidePanel: React.FC<SidePanelProps> = () => {\n const { translate } = useTranslate();\n const {\n id: documentId,\n model: uid,\n isSingleType\n } = useContentManagerContext();\n\n const [linkedContent, setLinkedContent] = useState<LinkedContent[]>([]);\n const [loading, setLoading] = useState(false);\n\n useEffect(() => {\n const fetchRevertRelations = async () => {\n const { post } = getFetchClient();\n\n const response = await post(`/${pluginId}/fetch-revert-relations`, {\n documentId,\n uid,\n isSingleType\n });\n\n setLinkedContent(Array.isArray(response.data) ? response.data.filter(Boolean) : []);\n setLoading(false);\n };\n\n fetchRevertRelations();\n }, []);\n\n if (loading)\n return (\n <Box width=\"100%\">\n <Loader />\n </Box>\n );\n\n return (\n <>\n <Divider />\n <Box width=\"100%\" marginTop={4}>\n <Flex>\n <Typography\n variant=\"sigma\"\n fontWeight=\"bold\"\n textTransform=\"uppercase\"\n marginBottom={1}\n textColor=\"neutral600\"\n >\n {translate('sidePanel.linkedContent')}\n </Typography>\n </Flex>\n\n {linkedContent.length > 0 ? (\n <Flex>\n <Typography variant=\"omega\" textColor=\"neutral600\" marginBottom={3}>\n {translate('sidePanel.referencedIn')} {linkedContent.length}{' '}\n {translate('sidePanel.otherContents')}\n </Typography>\n </Flex>\n ) : (\n <Flex>\n <Typography variant=\"omega\" textColor=\"neutral600\" marginBottom={3}>\n {translate('sidePanel.notReferenced')}\n </Typography>\n </Flex>\n )}\n\n <Box marginTop={2}>\n {linkedContent.map((content, idx) => (\n <Box\n key={content.documentId}\n marginBottom={idx < linkedContent.length - 1 ? 3 : 0}\n >\n <Flex\n direction=\"row\"\n justifyContent=\"space-between\"\n alignItems=\"flex-start\"\n paddingY={2}\n paddingX={3}\n >\n <Box>\n <Box>\n <a\n href={\n content.isSingleType\n ? `/admin/content-manager/single-types/${content.uid}`\n : `/admin/content-manager/collection-types/${content.uid}/${content.documentId}`\n }\n target=\"_blank\"\n style={{ textDecoration: 'none' }}\n >\n <Typography\n >\n {content.title ?? content.documentId}\n </Typography>\n </a>\n </Box>\n <Box marginTop={1}>\n <Typography\n variant=\"pi\"\n textColor=\"neutral600\"\n style={{ lineHeight: 1.2 }}\n >\n {translate('sidePanel.field')} {content.field}\n </Typography>\n </Box>\n </Box>\n <Box marginLeft={2}>\n <CardBadge>{content.type}</CardBadge>\n </Box>\n </Flex>\n {idx < linkedContent.length - 1 && (\n <Box marginY={1}>\n <Divider />\n </Box>\n )}\n </Box>\n ))}\n </Box>\n </Box>\n </>\n );\n};\n\nexport default SidePanel;\n","import React, { ComponentType } from 'react';\n\nimport pluginPkg from '../../package.json';\n\nimport PluginIcon from './components/PluginIcon';\nimport pluginId from './pluginId';\nimport { listContentTypes } from './helpers/content';\nimport { setContentTypes } from './helpers/storage';\nimport SidePanel from './components/SidePanel/SidePanel';\n\nconst name = pluginPkg.strapi.name;\n\nexport default {\n async register(app: any) {\n const contentTypes = await listContentTypes();\n setContentTypes(contentTypes);\n\n app.customFields.register({\n name,\n pluginId,\n type: 'richtext',\n intlLabel: {\n id: 'multi-content-type-relation.text-ai.label',\n defaultMessage: 'Multi Content Type Relation'\n },\n intlDescription: {\n id: 'multi-content-type-relation.text-ai.description',\n defaultMessage: 'Write content types separated by commas'\n },\n icon: PluginIcon, // don't forget to create/import your icon component\n components: {\n Input: () =>\n import(\n /* webpackChunkName: \"input-component\" */ './components/Input'\n ) as unknown as ComponentType\n },\n inputSize: {\n default: 12,\n isResizable: false\n },\n options: {\n base: [\n /*\n Declare settings to be added to the \"Base settings\" section\n of the field in the Content-Type Builder\n */\n {\n sectionTitle: {\n id: 'multi-content-type-relation.text-ai.length',\n defaultMessage: 'Content types'\n },\n items: contentTypes.map((contentType: any) => {\n const value = contentType.info.singularName;\n\n return {\n intlLabel: {\n id: `multi-content-type-relation.options.${contentType.uid}`,\n defaultMessage: contentType.info.displayName\n },\n type: 'checkbox',\n name: `options.contentTypes.${value}`\n };\n })\n }\n ],\n advanced: [\n {\n sectionTitle: {\n id: 'global.settings',\n defaultMessage: 'Settings'\n },\n items: [\n {\n name: 'required',\n type: 'checkbox',\n intlLabel: {\n id: 'content-type-relation-select.options.advanced.requiredField',\n defaultMessage: 'Required field'\n },\n description: {\n id: 'content-type-relation-select.options.advanced.requiredField.description',\n defaultMessage:\n \"You won't be able to create an entry if this field is empty\"\n }\n },\n {\n name: 'options.min',\n type: 'number',\n intlLabel: {\n id: 'content-type-relation-select.options.advanced.minField',\n defaultMessage: 'Minimum values'\n },\n description: {\n id: 'content-type-relation-select.options.advanced.minField.description',\n defaultMessage: 'Minimum number of entries'\n }\n },\n {\n name: 'options.max',\n type: 'number',\n intlLabel: {\n id: 'content-type-relation-select.options.advanced.maxField',\n defaultMessage: 'Maximum values'\n },\n description: {\n id: 'content-type-relation-select.options.advanced.maxField.description',\n defaultMessage: 'Maximum number of entries'\n }\n }\n ]\n }\n ]\n }\n });\n },\n\n bootstrap(app: any) {\n app\n .getPlugin('content-manager')\n .injectComponent('editView', 'right-links', {\n name: 'side-panel',\n Component: SidePanel\n });\n },\n\n async registerTrads(app: any) {\n const { locales } = app;\n\n const importedTrads = await Promise.all(\n (locales as any[]).map(async (locale) => {\n const { default: data } = await import(`./translations/${locale}.json`);\n\n return {\n data,\n locale\n };\n })\n );\n\n return Promise.resolve(importedTrads);\n }\n};\n"],"names":["jsx","PuzzlePiece","getFetchClient","useIntl","useContentManagerContext","useState","useEffect","Box","Loader","jsxs","Fragment","Divider","Flex","Typography","CardBadge"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,MAAM,aAAa,MAAMA,2BAAAA,IAACC,MAAAA,aAAA,EAAY;ACAtC,MAAM,WAAW,UAAU,KAAK;AAAA,EAC9B;AAAA,EACA;AACF;ACKO,MAAM,uBAAuB,OAClC,SACA,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