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