@strapi/i18n 0.0.0-experimental.e60ec1829240dae21c1e1d29076681c322288813 → 0.0.0-experimental.eba25ec571b091c6bde1104eb6c753debdf15462

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 (63) hide show
  1. package/LICENSE +18 -3
  2. package/dist/_chunks/{SettingsPage-Djqsdrzs.js → SettingsPage-JyA1zd8f.js} +117 -128
  3. package/dist/_chunks/SettingsPage-JyA1zd8f.js.map +1 -0
  4. package/dist/_chunks/{SettingsPage-CeqfDjsb.mjs → SettingsPage-giNp3Ftr.mjs} +117 -128
  5. package/dist/_chunks/SettingsPage-giNp3Ftr.mjs.map +1 -0
  6. package/dist/_chunks/{en-BuBc6LKZ.js → en-BKBz3tro.js} +14 -2
  7. package/dist/_chunks/en-BKBz3tro.js.map +1 -0
  8. package/dist/_chunks/{en-CnrTsjWS.mjs → en-DlXfy6Gy.mjs} +14 -2
  9. package/dist/_chunks/en-DlXfy6Gy.mjs.map +1 -0
  10. package/dist/_chunks/index-Bt5ork2g.mjs +1616 -0
  11. package/dist/_chunks/index-Bt5ork2g.mjs.map +1 -0
  12. package/dist/_chunks/index-BwAeKsym.js +1638 -0
  13. package/dist/_chunks/index-BwAeKsym.js.map +1 -0
  14. package/dist/admin/index.js +1 -1
  15. package/dist/admin/index.mjs +2 -2
  16. package/dist/admin/src/components/BulkLocaleActionModal.d.ts +16 -0
  17. package/dist/admin/src/components/CMHeaderActions.d.ts +35 -3
  18. package/dist/admin/src/components/CreateLocale.d.ts +6 -6
  19. package/dist/admin/src/components/EditLocale.d.ts +5 -4
  20. package/dist/admin/src/contentReleasesHooks/releaseDetailsView.d.ts +9 -5
  21. package/dist/admin/src/services/api.d.ts +2 -3
  22. package/dist/admin/src/services/locales.d.ts +1 -1
  23. package/dist/admin/src/services/relations.d.ts +7 -0
  24. package/dist/admin/src/utils/baseQuery.d.ts +4 -19
  25. package/dist/admin/src/utils/clean.d.ts +4 -0
  26. package/dist/admin/src/utils/schemas.d.ts +1 -0
  27. package/dist/server/index.js +413 -480
  28. package/dist/server/index.js.map +1 -1
  29. package/dist/server/index.mjs +415 -482
  30. package/dist/server/index.mjs.map +1 -1
  31. package/dist/server/src/bootstrap.d.ts +1 -4
  32. package/dist/server/src/bootstrap.d.ts.map +1 -1
  33. package/dist/server/src/index.d.ts +21 -13
  34. package/dist/server/src/index.d.ts.map +1 -1
  35. package/dist/server/src/register.d.ts.map +1 -1
  36. package/dist/server/src/services/index.d.ts +20 -10
  37. package/dist/server/src/services/index.d.ts.map +1 -1
  38. package/dist/server/src/services/permissions/actions.d.ts +14 -2
  39. package/dist/server/src/services/permissions/actions.d.ts.map +1 -1
  40. package/dist/server/src/services/permissions.d.ts +14 -2
  41. package/dist/server/src/services/permissions.d.ts.map +1 -1
  42. package/dist/server/src/services/sanitize/index.d.ts +11 -0
  43. package/dist/server/src/services/sanitize/index.d.ts.map +1 -0
  44. package/dist/server/src/utils/index.d.ts +2 -2
  45. package/dist/server/src/utils/index.d.ts.map +1 -1
  46. package/dist/shared/contracts/content-manager.d.ts +20 -1
  47. package/package.json +18 -19
  48. package/dist/_chunks/SettingsPage-CeqfDjsb.mjs.map +0 -1
  49. package/dist/_chunks/SettingsPage-Djqsdrzs.js.map +0 -1
  50. package/dist/_chunks/en-BuBc6LKZ.js.map +0 -1
  51. package/dist/_chunks/en-CnrTsjWS.mjs.map +0 -1
  52. package/dist/_chunks/index-BDU1w_fd.mjs +0 -1058
  53. package/dist/_chunks/index-BDU1w_fd.mjs.map +0 -1
  54. package/dist/_chunks/index-DMXJeGjN.js +0 -1082
  55. package/dist/_chunks/index-DMXJeGjN.js.map +0 -1
  56. package/dist/admin/src/components/Initializer.d.ts +0 -5
  57. package/dist/server/src/migrations/content-type/disable/index.d.ts +0 -3
  58. package/dist/server/src/migrations/content-type/disable/index.d.ts.map +0 -1
  59. package/dist/server/src/migrations/content-type/enable/index.d.ts +0 -3
  60. package/dist/server/src/migrations/content-type/enable/index.d.ts.map +0 -1
  61. package/dist/server/src/services/entity-service-decorator.d.ts +0 -29
  62. package/dist/server/src/services/entity-service-decorator.d.ts.map +0 -1
  63. package/strapi-server.js +0 -3
@@ -0,0 +1,1638 @@
1
+ "use strict";
2
+ const get = require("lodash/get");
3
+ const yup = require("yup");
4
+ const jsxRuntime = require("react/jsx-runtime");
5
+ const React = require("react");
6
+ const designSystem = require("@strapi/design-system");
7
+ const icons = require("@strapi/icons");
8
+ const reactIntl = require("react-intl");
9
+ const styledComponents = require("styled-components");
10
+ const query = require("@reduxjs/toolkit/query");
11
+ const strapiAdmin = require("@strapi/admin/strapi-admin");
12
+ const strapiAdmin$1 = require("@strapi/content-manager/strapi-admin");
13
+ const reactRouterDom = require("react-router-dom");
14
+ const qs = require("qs");
15
+ const omit = require("lodash/omit");
16
+ const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
17
+ function _interopNamespace(e) {
18
+ if (e && e.__esModule)
19
+ return e;
20
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
21
+ if (e) {
22
+ for (const k in e) {
23
+ if (k !== "default") {
24
+ const d = Object.getOwnPropertyDescriptor(e, k);
25
+ Object.defineProperty(n, k, d.get ? d : {
26
+ enumerable: true,
27
+ get: () => e[k]
28
+ });
29
+ }
30
+ }
31
+ }
32
+ n.default = e;
33
+ return Object.freeze(n);
34
+ }
35
+ const get__default = /* @__PURE__ */ _interopDefault(get);
36
+ const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
37
+ const React__namespace = /* @__PURE__ */ _interopNamespace(React);
38
+ const qs__namespace = /* @__PURE__ */ _interopNamespace(qs);
39
+ const omit__default = /* @__PURE__ */ _interopDefault(omit);
40
+ const __variableDynamicImportRuntimeHelper = (glob, path) => {
41
+ const v = glob[path];
42
+ if (v) {
43
+ return typeof v === "function" ? v() : Promise.resolve(v);
44
+ }
45
+ return new Promise((_, reject) => {
46
+ (typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(reject.bind(null, new Error("Unknown variable dynamic import: " + path)));
47
+ });
48
+ };
49
+ const pluginId = "i18n";
50
+ const getTranslation = (id) => `${pluginId}.${id}`;
51
+ const TextAlignTypography = styledComponents.styled(designSystem.Typography)`
52
+ text-align: center;
53
+ `;
54
+ const CheckboxConfirmation = ({
55
+ description,
56
+ isCreating = false,
57
+ intlLabel,
58
+ name,
59
+ onChange,
60
+ value
61
+ }) => {
62
+ const { formatMessage } = reactIntl.useIntl();
63
+ const [isOpen, setIsOpen] = React__namespace.useState(false);
64
+ const handleChange = (value2) => {
65
+ if (isCreating || value2) {
66
+ return onChange({ target: { name, value: value2, type: "checkbox" } });
67
+ }
68
+ if (!value2) {
69
+ return setIsOpen(true);
70
+ }
71
+ return null;
72
+ };
73
+ const handleConfirm = () => {
74
+ onChange({ target: { name, value: false, type: "checkbox" } });
75
+ };
76
+ const label = intlLabel.id ? formatMessage(
77
+ { id: intlLabel.id, defaultMessage: intlLabel.defaultMessage },
78
+ { ...intlLabel.values }
79
+ ) : name;
80
+ const hint = description ? formatMessage(
81
+ { id: description.id, defaultMessage: description.defaultMessage },
82
+ { ...description.values }
83
+ ) : "";
84
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Root, { open: isOpen, onOpenChange: setIsOpen, children: [
85
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { hint, name, children: [
86
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Checkbox, { onCheckedChange: handleChange, checked: value, children: label }),
87
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Hint, {})
88
+ ] }),
89
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Content, { children: [
90
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Header, { children: formatMessage({
91
+ id: getTranslation("CheckboxConfirmation.Modal.title"),
92
+ defaultMessage: "Disable localization"
93
+ }) }),
94
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Body, { icon: /* @__PURE__ */ jsxRuntime.jsx(icons.WarningCircle, {}), children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
95
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", children: /* @__PURE__ */ jsxRuntime.jsx(TextAlignTypography, { children: formatMessage({
96
+ id: getTranslation("CheckboxConfirmation.Modal.content"),
97
+ defaultMessage: "Disabling localization will engender the deletion of all your content but the one associated to your default locale (if existing)."
98
+ }) }) }),
99
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { justifyContent: "center", children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { fontWeight: "semiBold", children: formatMessage({
100
+ id: getTranslation("CheckboxConfirmation.Modal.body"),
101
+ defaultMessage: "Do you want to disable it?"
102
+ }) }) })
103
+ ] }) }),
104
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Dialog.Footer, { children: [
105
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Cancel, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "tertiary", children: formatMessage({
106
+ id: "components.popUpWarning.button.cancel",
107
+ defaultMessage: "No, cancel"
108
+ }) }) }),
109
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Action, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "danger-light", onClick: handleConfirm, children: formatMessage({
110
+ id: getTranslation("CheckboxConfirmation.Modal.button-confirm"),
111
+ defaultMessage: "Yes, disable"
112
+ }) }) })
113
+ ] })
114
+ ] })
115
+ ] });
116
+ };
117
+ const LOCALIZED_FIELDS = [
118
+ "biginteger",
119
+ "boolean",
120
+ "component",
121
+ "date",
122
+ "datetime",
123
+ "decimal",
124
+ "dynamiczone",
125
+ "email",
126
+ "enumeration",
127
+ "float",
128
+ "integer",
129
+ "json",
130
+ "media",
131
+ "number",
132
+ "password",
133
+ "richtext",
134
+ "blocks",
135
+ "string",
136
+ "text",
137
+ "time"
138
+ ];
139
+ const doesPluginOptionsHaveI18nLocalized = (opts) => typeof opts === "object" && opts !== null && "i18n" in opts && typeof opts.i18n === "object" && opts.i18n !== null && "localized" in opts.i18n && typeof opts.i18n.localized === "boolean";
140
+ const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
141
+ const useI18n = () => {
142
+ const params = reactRouterDom.useParams();
143
+ const userPermissions = strapiAdmin.useAuth("useI18n", (state) => state.permissions);
144
+ const actions = React__namespace.useMemo(() => {
145
+ const permissions = userPermissions.filter((permission) => permission.subject === params.slug);
146
+ return permissions.reduce(
147
+ (acc, permission) => {
148
+ const [actionShorthand] = permission.action.split(".").slice(-1);
149
+ return {
150
+ ...acc,
151
+ [`can${capitalize(actionShorthand)}`]: permission.properties?.locales ?? []
152
+ };
153
+ },
154
+ { canCreate: [], canRead: [], canUpdate: [], canDelete: [], canPublish: [] }
155
+ );
156
+ }, [params.slug, userPermissions]);
157
+ const { schema } = strapiAdmin$1.unstable_useDocument(
158
+ {
159
+ // We can non-null assert these because below we skip the query if they are not present
160
+ collectionType: params.collectionType,
161
+ model: params.slug
162
+ },
163
+ {
164
+ skip: true
165
+ }
166
+ );
167
+ if (doesPluginOptionsHaveI18nLocalized(schema?.pluginOptions)) {
168
+ return {
169
+ hasI18n: schema.pluginOptions.i18n.localized,
170
+ ...actions
171
+ };
172
+ }
173
+ return {
174
+ hasI18n: false,
175
+ ...actions
176
+ };
177
+ };
178
+ const i18nApi = strapiAdmin.adminApi.enhanceEndpoints({
179
+ addTagTypes: ["Locale"]
180
+ });
181
+ const localesApi = i18nApi.injectEndpoints({
182
+ endpoints: (builder) => ({
183
+ createLocale: builder.mutation({
184
+ query: (data) => ({
185
+ url: "/i18n/locales",
186
+ method: "POST",
187
+ data
188
+ }),
189
+ invalidatesTags: [{ type: "Locale", id: "LIST" }]
190
+ }),
191
+ deleteLocale: builder.mutation({
192
+ query: (id) => ({
193
+ url: `/i18n/locales/${id}`,
194
+ method: "DELETE"
195
+ }),
196
+ invalidatesTags: (result, error, id) => [{ type: "Locale", id }]
197
+ }),
198
+ getLocales: builder.query({
199
+ query: () => "/i18n/locales",
200
+ providesTags: (res) => [
201
+ { type: "Locale", id: "LIST" },
202
+ ...Array.isArray(res) ? res.map((locale) => ({
203
+ type: "Locale",
204
+ id: locale.id
205
+ })) : []
206
+ ]
207
+ }),
208
+ getDefaultLocales: builder.query({
209
+ query: () => "/i18n/iso-locales"
210
+ }),
211
+ updateLocale: builder.mutation({
212
+ query: ({ id, ...data }) => ({
213
+ url: `/i18n/locales/${id}`,
214
+ method: "PUT",
215
+ data
216
+ }),
217
+ invalidatesTags: (result, error, { id }) => [{ type: "Locale", id }]
218
+ })
219
+ })
220
+ });
221
+ const {
222
+ useCreateLocaleMutation,
223
+ useDeleteLocaleMutation,
224
+ useGetLocalesQuery,
225
+ useGetDefaultLocalesQuery,
226
+ useUpdateLocaleMutation
227
+ } = localesApi;
228
+ const relationsApi = i18nApi.injectEndpoints({
229
+ overrideExisting: true,
230
+ endpoints: (builder) => ({
231
+ getManyDraftRelationCount: builder.query({
232
+ query: ({ model, ...params }) => ({
233
+ url: `/content-manager/collection-types/${model}/actions/countManyEntriesDraftRelations`,
234
+ method: "GET",
235
+ config: {
236
+ params
237
+ }
238
+ }),
239
+ transformResponse: (response) => response.data
240
+ })
241
+ })
242
+ });
243
+ const { useGetManyDraftRelationCountQuery } = relationsApi;
244
+ const cleanData = (data, schema, components) => {
245
+ const cleanedData = removeFields(data, [
246
+ "createdAt",
247
+ "createdBy",
248
+ "updatedAt",
249
+ "updatedBy",
250
+ "id",
251
+ "documentId",
252
+ "publishedAt",
253
+ "strapi_stage",
254
+ "strapi_assignee",
255
+ "locale",
256
+ "status"
257
+ ]);
258
+ const cleanedDataWithoutPasswordAndRelation = recursiveRemoveFieldTypes(
259
+ cleanedData,
260
+ schema,
261
+ components,
262
+ ["relation", "password"]
263
+ );
264
+ return cleanedDataWithoutPasswordAndRelation;
265
+ };
266
+ const removeFields = (data, fields) => {
267
+ return Object.keys(data).reduce((acc, current) => {
268
+ if (fields.includes(current)) {
269
+ return acc;
270
+ }
271
+ acc[current] = data[current];
272
+ return acc;
273
+ }, {});
274
+ };
275
+ const recursiveRemoveFieldTypes = (data, schema, components, fields) => {
276
+ return Object.keys(data).reduce((acc, current) => {
277
+ const attribute = schema.attributes[current] ?? { type: void 0 };
278
+ if (fields.includes(attribute.type)) {
279
+ return acc;
280
+ }
281
+ if (attribute.type === "dynamiczone") {
282
+ acc[current] = data[current].map((componentValue, index2) => {
283
+ const { id: _, ...rest } = recursiveRemoveFieldTypes(
284
+ componentValue,
285
+ components[componentValue.__component],
286
+ components,
287
+ fields
288
+ );
289
+ return {
290
+ ...rest,
291
+ __temp_key__: index2 + 1
292
+ };
293
+ });
294
+ } else if (attribute.type === "component") {
295
+ const { repeatable, component } = attribute;
296
+ if (repeatable) {
297
+ acc[current] = (data[current] ?? []).map((compoData, index2) => {
298
+ const { id: _, ...rest } = recursiveRemoveFieldTypes(
299
+ compoData,
300
+ components[component],
301
+ components,
302
+ fields
303
+ );
304
+ return {
305
+ ...rest,
306
+ __temp_key__: index2 + 1
307
+ };
308
+ });
309
+ } else {
310
+ const { id: _, ...rest } = recursiveRemoveFieldTypes(
311
+ data[current] ?? {},
312
+ components[component],
313
+ components,
314
+ fields
315
+ );
316
+ acc[current] = rest;
317
+ }
318
+ } else {
319
+ acc[current] = data[current];
320
+ }
321
+ return acc;
322
+ }, {});
323
+ };
324
+ const isErrorMessageDescriptor = (object) => {
325
+ return typeof object === "object" && object !== null && "id" in object && "defaultMessage" in object;
326
+ };
327
+ const EntryValidationText = ({
328
+ status = "draft",
329
+ validationErrors,
330
+ action
331
+ }) => {
332
+ const { formatMessage } = reactIntl.useIntl();
333
+ const getErrorStr = (key, value) => {
334
+ if (typeof value === "string") {
335
+ return `${key}: ${value}`;
336
+ } else if (isErrorMessageDescriptor(value)) {
337
+ return `${key}: ${formatMessage(value)}`;
338
+ } else if (Array.isArray(value)) {
339
+ return value.map((v) => getErrorStr(key, v)).join(" ");
340
+ } else if (typeof value === "object" && !Array.isArray(value)) {
341
+ return Object.entries(value).map(([k, v]) => getErrorStr(k, v)).join(" ");
342
+ } else {
343
+ return "";
344
+ }
345
+ };
346
+ if (validationErrors) {
347
+ const validationErrorsMessages = Object.entries(validationErrors).map(([key, value]) => {
348
+ return getErrorStr(key, value);
349
+ }).join(" ");
350
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
351
+ /* @__PURE__ */ jsxRuntime.jsx(icons.CrossCircle, { fill: "danger600" }),
352
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Tooltip, { label: validationErrorsMessages, children: /* @__PURE__ */ jsxRuntime.jsx(
353
+ designSystem.Typography,
354
+ {
355
+ maxWidth: "30rem",
356
+ textColor: "danger600",
357
+ variant: "omega",
358
+ fontWeight: "semiBold",
359
+ ellipsis: true,
360
+ children: validationErrorsMessages
361
+ }
362
+ ) })
363
+ ] });
364
+ }
365
+ const getStatusMessage = () => {
366
+ if (action === "bulk-publish") {
367
+ if (status === "published") {
368
+ return {
369
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.CheckCircle, { fill: "success600" }),
370
+ text: formatMessage({
371
+ id: "content-manager.bulk-publish.already-published",
372
+ defaultMessage: "Already Published"
373
+ }),
374
+ textColor: "success600",
375
+ fontWeight: "bold"
376
+ };
377
+ } else if (status === "modified") {
378
+ return {
379
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowsCounterClockwise, { fill: "alternative600" }),
380
+ text: formatMessage({
381
+ id: "app.utils.ready-to-publish-changes",
382
+ defaultMessage: "Ready to publish changes"
383
+ })
384
+ };
385
+ } else {
386
+ return {
387
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.CheckCircle, { fill: "success600" }),
388
+ text: formatMessage({
389
+ id: "app.utils.ready-to-publish",
390
+ defaultMessage: "Ready to publish"
391
+ })
392
+ };
393
+ }
394
+ } else {
395
+ if (status === "draft") {
396
+ return {
397
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.CheckCircle, { fill: "success600" }),
398
+ text: formatMessage({
399
+ id: "content-manager.bulk-unpublish.already-unpublished",
400
+ defaultMessage: "Already Unpublished"
401
+ }),
402
+ textColor: "success600",
403
+ fontWeight: "bold"
404
+ };
405
+ } else {
406
+ return {
407
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.CheckCircle, { fill: "success600" }),
408
+ text: formatMessage({
409
+ id: "app.utils.ready-to-unpublish-changes",
410
+ defaultMessage: "Ready to unpublish"
411
+ }),
412
+ textColor: "success600",
413
+ fontWeight: "bold"
414
+ };
415
+ }
416
+ }
417
+ };
418
+ const { icon, text, textColor = "success600", fontWeight = "normal" } = getStatusMessage();
419
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, children: [
420
+ icon,
421
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor, fontWeight, children: text })
422
+ ] });
423
+ };
424
+ const BoldChunk = (chunks) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { fontWeight: "bold", children: chunks });
425
+ const BulkLocaleActionModal = ({
426
+ headers,
427
+ rows,
428
+ localesMetadata,
429
+ validationErrors = {},
430
+ action
431
+ }) => {
432
+ const { formatMessage } = reactIntl.useIntl();
433
+ const selectedRows = strapiAdmin.useTable(
434
+ "BulkLocaleActionModal",
435
+ (state) => state.selectedRows
436
+ );
437
+ const getFormattedCountMessage = () => {
438
+ const currentStatusByLocale = rows.reduce((acc, { locale, status }) => {
439
+ acc[locale] = status;
440
+ return acc;
441
+ }, {});
442
+ const localesWithErrors = Object.keys(validationErrors);
443
+ const publishedCount = selectedRows.filter(
444
+ ({ locale }) => currentStatusByLocale[locale] === "published"
445
+ ).length;
446
+ const draftCount = selectedRows.filter(
447
+ ({ locale }) => (currentStatusByLocale[locale] === "draft" || currentStatusByLocale[locale] === "modified") && !localesWithErrors.includes(locale)
448
+ ).length;
449
+ const withErrorsCount = localesWithErrors.length;
450
+ const messageId = action === "bulk-publish" ? "content-manager.containers.list.selectedEntriesModal.selectedCount.publish" : "content-manager.containers.list.selectedEntriesModal.selectedCount.unpublish";
451
+ const defaultMessage = action === "bulk-publish" ? "<b>{publishedCount}</b> {publishedCount, plural, =0 {entries} one {entry} other {entries}} already published. <b>{draftCount}</b> {draftCount, plural, =0 {entries} one {entry} other {entries}} ready to publish. <b>{withErrorsCount}</b> {withErrorsCount, plural, =0 {entries} one {entry} other {entries}} waiting for action." : "<b>{draftCount}</b> {draftCount, plural, =0 {entries} one {entry} other {entries}} already unpublished. <b>{publishedCount}</b> {publishedCount, plural, =0 {entries} one {entry} other {entries}} ready to unpublish.";
452
+ return formatMessage(
453
+ {
454
+ id: messageId,
455
+ defaultMessage
456
+ },
457
+ {
458
+ withErrorsCount,
459
+ draftCount,
460
+ publishedCount,
461
+ b: BoldChunk
462
+ }
463
+ );
464
+ };
465
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Modal.Body, { children: [
466
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: getFormattedCountMessage() }),
467
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { marginTop: 5, children: /* @__PURE__ */ jsxRuntime.jsxs(strapiAdmin.Table.Content, { children: [
468
+ /* @__PURE__ */ jsxRuntime.jsxs(strapiAdmin.Table.Head, { children: [
469
+ /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.HeaderCheckboxCell, {}),
470
+ headers.map((head) => /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.HeaderCell, { ...head }, head.name))
471
+ ] }),
472
+ /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.Body, { children: rows.map(({ locale, status }, index2) => {
473
+ const error = validationErrors?.[locale] ?? null;
474
+ const statusVariant = status === "draft" ? "primary" : status === "published" ? "success" : "alternative";
475
+ return /* @__PURE__ */ jsxRuntime.jsxs(strapiAdmin.Table.Row, { children: [
476
+ /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.CheckboxCell, { id: locale, "aria-label": `Select ${locale}` }),
477
+ /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { variant: "sigma", textColor: "neutral600", children: Array.isArray(localesMetadata) ? localesMetadata.find((localeEntry) => localeEntry.code === locale)?.name : locale }) }),
478
+ /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { display: "flex", children: /* @__PURE__ */ jsxRuntime.jsx(
479
+ designSystem.Status,
480
+ {
481
+ display: "flex",
482
+ paddingLeft: "6px",
483
+ paddingRight: "6px",
484
+ paddingTop: "2px",
485
+ paddingBottom: "2px",
486
+ size: "S",
487
+ variant: statusVariant,
488
+ children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "span", variant: "pi", fontWeight: "bold", children: capitalize(status) })
489
+ }
490
+ ) }) }),
491
+ /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(EntryValidationText, { validationErrors: error, status, action }) }),
492
+ /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(
493
+ designSystem.IconButton,
494
+ {
495
+ tag: reactRouterDom.Link,
496
+ to: {
497
+ search: qs.stringify({ plugins: { i18n: { locale } } })
498
+ },
499
+ label: formatMessage(
500
+ {
501
+ id: getTranslation("Settings.list.actions.edit"),
502
+ defaultMessage: "Edit {name} locale"
503
+ },
504
+ {
505
+ name: locale
506
+ }
507
+ ),
508
+ variant: "ghost",
509
+ children: /* @__PURE__ */ jsxRuntime.jsx(icons.Pencil, {})
510
+ }
511
+ ) })
512
+ ] }, index2);
513
+ }) })
514
+ ] }) })
515
+ ] });
516
+ };
517
+ const statusVariants = {
518
+ draft: "secondary",
519
+ published: "success",
520
+ modified: "alternative"
521
+ };
522
+ const LocaleOption = ({
523
+ isDraftAndPublishEnabled,
524
+ locale,
525
+ status,
526
+ entryExists
527
+ }) => {
528
+ const { formatMessage } = reactIntl.useIntl();
529
+ if (!entryExists) {
530
+ return formatMessage(
531
+ {
532
+ id: getTranslation("CMEditViewLocalePicker.locale.create"),
533
+ defaultMessage: "Create <bold>{locale}</bold> locale"
534
+ },
535
+ {
536
+ bold: (locale2) => /* @__PURE__ */ jsxRuntime.jsx("b", { children: locale2 }),
537
+ locale: locale.name
538
+ }
539
+ );
540
+ }
541
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { width: "100%", gap: 1, justifyContent: "space-between", children: [
542
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: locale.name }),
543
+ isDraftAndPublishEnabled ? /* @__PURE__ */ jsxRuntime.jsx(
544
+ designSystem.Status,
545
+ {
546
+ display: "flex",
547
+ paddingLeft: "6px",
548
+ paddingRight: "6px",
549
+ paddingTop: "2px",
550
+ paddingBottom: "2px",
551
+ size: "S",
552
+ variant: statusVariants[status],
553
+ children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "span", variant: "pi", fontWeight: "bold", children: capitalize(status) })
554
+ }
555
+ ) : null
556
+ ] });
557
+ };
558
+ const LocalePickerAction = ({
559
+ document,
560
+ meta,
561
+ model,
562
+ collectionType,
563
+ documentId
564
+ }) => {
565
+ const { formatMessage } = reactIntl.useIntl();
566
+ const [{ query: query2 }, setQuery] = strapiAdmin.useQueryParams();
567
+ const { hasI18n, canCreate, canRead } = useI18n();
568
+ const { data: locales = [] } = useGetLocalesQuery();
569
+ const currentDesiredLocale = query2.plugins?.i18n?.locale;
570
+ const { schema } = strapiAdmin$1.unstable_useDocument({
571
+ model,
572
+ collectionType,
573
+ documentId,
574
+ params: { locale: currentDesiredLocale }
575
+ });
576
+ const handleSelect = React__namespace.useCallback(
577
+ (value) => {
578
+ setQuery({
579
+ plugins: {
580
+ ...query2.plugins,
581
+ i18n: {
582
+ locale: value
583
+ }
584
+ }
585
+ });
586
+ },
587
+ [query2.plugins, setQuery]
588
+ );
589
+ React__namespace.useEffect(() => {
590
+ if (!Array.isArray(locales) || !hasI18n) {
591
+ return;
592
+ }
593
+ const doesLocaleExist = locales.find((loc) => loc.code === currentDesiredLocale);
594
+ const defaultLocale = locales.find((locale) => locale.isDefault);
595
+ if (!doesLocaleExist && defaultLocale?.code) {
596
+ handleSelect(defaultLocale.code);
597
+ }
598
+ }, [handleSelect, hasI18n, locales, currentDesiredLocale]);
599
+ const currentLocale = Array.isArray(locales) ? locales.find((locale) => locale.code === currentDesiredLocale) : void 0;
600
+ const allCurrentLocales = [
601
+ { status: getDocumentStatus(document, meta), locale: currentLocale?.code },
602
+ ...meta?.availableLocales ?? []
603
+ ];
604
+ if (!hasI18n || !Array.isArray(locales) || locales.length === 0) {
605
+ return null;
606
+ }
607
+ const displayedLocales = locales.filter((locale) => {
608
+ return canRead.includes(locale.code);
609
+ });
610
+ return {
611
+ label: formatMessage({
612
+ id: getTranslation("Settings.locales.modal.locales.label"),
613
+ defaultMessage: "Locales"
614
+ }),
615
+ options: displayedLocales.map((locale) => {
616
+ const entryWithLocaleExists = allCurrentLocales.some((doc) => doc.locale === locale.code);
617
+ const currentLocaleDoc = allCurrentLocales.find(
618
+ (doc) => "locale" in doc ? doc.locale === locale.code : false
619
+ );
620
+ const permissionsToCheck = currentLocaleDoc ? canRead : canCreate;
621
+ return {
622
+ disabled: !permissionsToCheck.includes(locale.code),
623
+ value: locale.code,
624
+ label: /* @__PURE__ */ jsxRuntime.jsx(
625
+ LocaleOption,
626
+ {
627
+ isDraftAndPublishEnabled: !!schema?.options?.draftAndPublish,
628
+ locale,
629
+ status: currentLocaleDoc?.status,
630
+ entryExists: entryWithLocaleExists
631
+ }
632
+ ),
633
+ startIcon: !entryWithLocaleExists ? /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) : null
634
+ };
635
+ }),
636
+ customizeContent: () => currentLocale?.name,
637
+ onSelect: handleSelect,
638
+ value: currentLocale
639
+ };
640
+ };
641
+ const getDocumentStatus = (document, meta) => {
642
+ const docStatus = document?.status;
643
+ const statuses = meta?.availableStatus ?? [];
644
+ if (!docStatus) {
645
+ return "draft";
646
+ }
647
+ if (docStatus === "draft" && statuses.find((doc) => doc.publishedAt !== null)) {
648
+ return "published";
649
+ }
650
+ return docStatus;
651
+ };
652
+ const FillFromAnotherLocaleAction = ({
653
+ documentId,
654
+ meta,
655
+ model,
656
+ collectionType
657
+ }) => {
658
+ const { formatMessage } = reactIntl.useIntl();
659
+ const [{ query: query2 }] = strapiAdmin.useQueryParams();
660
+ const { hasI18n } = useI18n();
661
+ const currentDesiredLocale = query2.plugins?.i18n?.locale;
662
+ const [localeSelected, setLocaleSelected] = React__namespace.useState(null);
663
+ const setValues = strapiAdmin.useForm("FillFromAnotherLocale", (state) => state.setValues);
664
+ const { getDocument } = strapiAdmin$1.unstable_useDocumentActions();
665
+ const { schema, components } = strapiAdmin$1.unstable_useDocument({
666
+ model,
667
+ documentId,
668
+ collectionType,
669
+ params: { locale: currentDesiredLocale }
670
+ });
671
+ const { data: locales = [] } = useGetLocalesQuery();
672
+ const availableLocales = Array.isArray(locales) ? locales.filter((locale) => meta?.availableLocales.some((l) => l.locale === locale.code)) : [];
673
+ const fillFromLocale = (onClose) => async () => {
674
+ const response = await getDocument({
675
+ collectionType,
676
+ model,
677
+ documentId,
678
+ params: { locale: localeSelected }
679
+ });
680
+ if (!response || !schema) {
681
+ return;
682
+ }
683
+ const { data } = response;
684
+ const cleanedData = cleanData(data, schema, components);
685
+ setValues(cleanedData);
686
+ onClose();
687
+ };
688
+ if (!hasI18n) {
689
+ return null;
690
+ }
691
+ return {
692
+ type: "icon",
693
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Download, {}),
694
+ disabled: availableLocales.length === 0,
695
+ label: formatMessage({
696
+ id: getTranslation("CMEditViewCopyLocale.copy-text"),
697
+ defaultMessage: "Fill in from another locale"
698
+ }),
699
+ dialog: {
700
+ type: "dialog",
701
+ title: formatMessage({
702
+ id: getTranslation("CMEditViewCopyLocale.dialog.title"),
703
+ defaultMessage: "Confirmation"
704
+ }),
705
+ content: ({ onClose }) => /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
706
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 3, children: [
707
+ /* @__PURE__ */ jsxRuntime.jsx(icons.WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
708
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textAlign: "center", children: formatMessage({
709
+ id: getTranslation("CMEditViewCopyLocale.dialog.body"),
710
+ defaultMessage: "Your current content will be erased and filled by the content of the selected locale:"
711
+ }) }),
712
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { width: "100%", children: [
713
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage({
714
+ id: getTranslation("CMEditViewCopyLocale.dialog.field.label"),
715
+ defaultMessage: "Locale"
716
+ }) }),
717
+ /* @__PURE__ */ jsxRuntime.jsx(
718
+ designSystem.SingleSelect,
719
+ {
720
+ value: localeSelected,
721
+ placeholder: formatMessage({
722
+ id: getTranslation("CMEditViewCopyLocale.dialog.field.placeholder"),
723
+ defaultMessage: "Select one locale..."
724
+ }),
725
+ onChange: (value) => setLocaleSelected(value),
726
+ children: availableLocales.map((locale) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: locale.code, children: locale.name }, locale.code))
727
+ }
728
+ )
729
+ ] })
730
+ ] }) }),
731
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, width: "100%", children: [
732
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { flex: "auto", variant: "tertiary", onClick: onClose, children: formatMessage({
733
+ id: getTranslation("CMEditViewCopyLocale.cancel-text"),
734
+ defaultMessage: "No, cancel"
735
+ }) }),
736
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { flex: "auto", variant: "success", onClick: fillFromLocale(onClose), children: formatMessage({
737
+ id: getTranslation("CMEditViewCopyLocale.submit-text"),
738
+ defaultMessage: "Yes, fill in"
739
+ }) })
740
+ ] }) })
741
+ ] })
742
+ }
743
+ };
744
+ };
745
+ const DeleteLocaleAction = ({
746
+ document,
747
+ documentId,
748
+ model,
749
+ collectionType
750
+ }) => {
751
+ const { formatMessage } = reactIntl.useIntl();
752
+ const navigate = reactRouterDom.useNavigate();
753
+ const { toggleNotification } = strapiAdmin.useNotification();
754
+ const { delete: deleteAction } = strapiAdmin$1.unstable_useDocumentActions();
755
+ const { hasI18n, canDelete } = useI18n();
756
+ const [{ query: query2 }] = strapiAdmin.useQueryParams();
757
+ const { data: locales = [] } = useGetLocalesQuery();
758
+ const currentDesiredLocale = query2.plugins?.i18n?.locale;
759
+ const locale = !("error" in locales) && locales.find((loc) => loc.code === currentDesiredLocale);
760
+ if (!hasI18n) {
761
+ return null;
762
+ }
763
+ return {
764
+ disabled: document?.locale && !canDelete.includes(document.locale) || !document || !document.id,
765
+ position: ["header", "table-row"],
766
+ label: formatMessage(
767
+ {
768
+ id: getTranslation("actions.delete.label"),
769
+ defaultMessage: "Delete entry ({locale})"
770
+ },
771
+ { locale: locale && locale.name }
772
+ ),
773
+ icon: /* @__PURE__ */ jsxRuntime.jsx(StyledTrash, {}),
774
+ variant: "danger",
775
+ dialog: {
776
+ type: "dialog",
777
+ title: formatMessage({
778
+ id: getTranslation("actions.delete.dialog.title"),
779
+ defaultMessage: "Confirmation"
780
+ }),
781
+ content: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, children: [
782
+ /* @__PURE__ */ jsxRuntime.jsx(icons.WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
783
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
784
+ id: getTranslation("actions.delete.dialog.body"),
785
+ defaultMessage: "Are you sure?"
786
+ }) })
787
+ ] }),
788
+ onConfirm: async () => {
789
+ const unableToDelete = (
790
+ // We are unable to delete a collection type without a document ID
791
+ // & unable to delete generally if there is no document locale
792
+ collectionType !== "single-types" && !documentId || !document?.locale
793
+ );
794
+ if (unableToDelete) {
795
+ console.error(
796
+ "You're trying to delete a document without an id or locale, this is likely a bug with Strapi. Please open an issue."
797
+ );
798
+ toggleNotification({
799
+ message: formatMessage({
800
+ id: getTranslation("actions.delete.error"),
801
+ defaultMessage: "An error occurred while trying to delete the document locale."
802
+ }),
803
+ type: "danger"
804
+ });
805
+ return;
806
+ }
807
+ const res = await deleteAction({
808
+ documentId,
809
+ model,
810
+ collectionType,
811
+ params: { locale: document.locale }
812
+ });
813
+ if (!("error" in res)) {
814
+ navigate({ pathname: `../${collectionType}/${model}` }, { replace: true });
815
+ }
816
+ }
817
+ }
818
+ };
819
+ };
820
+ const BulkLocaleAction = ({
821
+ document: baseDocument,
822
+ documentId,
823
+ model,
824
+ collectionType,
825
+ action
826
+ }) => {
827
+ const baseLocale = baseDocument?.locale ?? null;
828
+ const [{ query: query$1 }] = strapiAdmin.useQueryParams();
829
+ const params = React__namespace.useMemo(() => strapiAdmin$1.buildValidParams(query$1), [query$1]);
830
+ const isOnPublishedTab = query$1.status === "published";
831
+ const { formatMessage } = reactIntl.useIntl();
832
+ const { hasI18n, canPublish } = useI18n();
833
+ const { toggleNotification } = strapiAdmin.useNotification();
834
+ const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
835
+ const [selectedRows, setSelectedRows] = React__namespace.useState([]);
836
+ const [isDraftRelationConfirmationOpen, setIsDraftRelationConfirmationOpen] = React__namespace.useState(false);
837
+ const { publishMany: publishManyAction, unpublishMany: unpublishManyAction } = strapiAdmin$1.unstable_useDocumentActions();
838
+ const {
839
+ document,
840
+ meta: documentMeta,
841
+ schema,
842
+ validate
843
+ } = strapiAdmin$1.unstable_useDocument(
844
+ {
845
+ model,
846
+ collectionType,
847
+ documentId,
848
+ params: {
849
+ locale: baseLocale
850
+ }
851
+ },
852
+ {
853
+ skip: !hasI18n || !baseLocale
854
+ }
855
+ );
856
+ const { data: localesMetadata = [] } = useGetLocalesQuery(hasI18n ? void 0 : query.skipToken);
857
+ const headers = [
858
+ {
859
+ label: formatMessage({
860
+ id: "global.name",
861
+ defaultMessage: "Name"
862
+ }),
863
+ name: "name"
864
+ },
865
+ {
866
+ label: formatMessage({
867
+ id: getTranslation("CMEditViewBulkLocale.status"),
868
+ defaultMessage: "Status"
869
+ }),
870
+ name: "status"
871
+ },
872
+ {
873
+ label: formatMessage({
874
+ id: getTranslation("CMEditViewBulkLocale.publication-status"),
875
+ defaultMessage: "Publication Status"
876
+ }),
877
+ name: "publication-status"
878
+ }
879
+ ];
880
+ const [rows, validationErrors] = React__namespace.useMemo(() => {
881
+ if (!document || !documentMeta?.availableLocales) {
882
+ return [[], {}];
883
+ }
884
+ const rowsFromMeta = documentMeta?.availableLocales.map((doc) => {
885
+ const { locale, status } = doc;
886
+ return { locale, status };
887
+ });
888
+ rowsFromMeta.unshift({
889
+ locale: document.locale,
890
+ status: document.status
891
+ });
892
+ const allDocuments = [document, ...documentMeta?.availableLocales ?? []];
893
+ const errors = allDocuments.reduce((errs, document2) => {
894
+ if (!document2) {
895
+ return errs;
896
+ }
897
+ const validation = validate(document2);
898
+ if (validation !== null) {
899
+ errs[document2.locale] = validation;
900
+ }
901
+ return errs;
902
+ }, {});
903
+ return [rowsFromMeta, errors];
904
+ }, [document, documentMeta?.availableLocales, validate]);
905
+ const isBulkPublish = action === "bulk-publish";
906
+ const localesForAction = selectedRows.reduce((acc, selectedRow) => {
907
+ const isValidLocale = (
908
+ // Validation errors are irrelevant if we are trying to unpublish
909
+ !isBulkPublish || !Object.keys(validationErrors).includes(selectedRow.locale)
910
+ );
911
+ const shouldAddLocale = isBulkPublish ? selectedRow.status !== "published" && isValidLocale : selectedRow.status !== "draft" && isValidLocale;
912
+ if (shouldAddLocale) {
913
+ acc.push(selectedRow.locale);
914
+ }
915
+ return acc;
916
+ }, []);
917
+ const enableDraftRelationsCount = false;
918
+ const {
919
+ data: draftRelationsCount = 0,
920
+ isLoading: isDraftRelationsLoading,
921
+ error: isDraftRelationsError
922
+ } = useGetManyDraftRelationCountQuery(
923
+ {
924
+ model,
925
+ documentIds: [documentId],
926
+ locale: localesForAction
927
+ },
928
+ {
929
+ skip: !enableDraftRelationsCount
930
+ }
931
+ );
932
+ React__namespace.useEffect(() => {
933
+ if (isDraftRelationsError) {
934
+ toggleNotification({
935
+ type: "danger",
936
+ message: formatAPIError(isDraftRelationsError)
937
+ });
938
+ }
939
+ }, [isDraftRelationsError, toggleNotification, formatAPIError]);
940
+ if (!schema?.options?.draftAndPublish) {
941
+ return null;
942
+ }
943
+ if (!hasI18n) {
944
+ return null;
945
+ }
946
+ if (!documentId) {
947
+ return null;
948
+ }
949
+ const publish = async () => {
950
+ await publishManyAction({
951
+ model,
952
+ documentIds: [documentId],
953
+ params: {
954
+ ...params,
955
+ locale: localesForAction
956
+ }
957
+ });
958
+ setSelectedRows([]);
959
+ };
960
+ const unpublish = async () => {
961
+ await unpublishManyAction({
962
+ model,
963
+ documentIds: [documentId],
964
+ params: {
965
+ ...params,
966
+ locale: localesForAction
967
+ }
968
+ });
969
+ setSelectedRows([]);
970
+ };
971
+ const handleAction = async () => {
972
+ if (draftRelationsCount > 0) {
973
+ setIsDraftRelationConfirmationOpen(true);
974
+ } else if (isBulkPublish) {
975
+ await publish();
976
+ } else {
977
+ await unpublish();
978
+ }
979
+ };
980
+ if (isDraftRelationConfirmationOpen) {
981
+ return {
982
+ label: formatMessage({
983
+ id: "app.components.ConfirmDialog.title",
984
+ defaultMessage: "Confirmation"
985
+ }),
986
+ variant: "danger",
987
+ dialog: {
988
+ onCancel: () => {
989
+ setIsDraftRelationConfirmationOpen(false);
990
+ },
991
+ onConfirm: async () => {
992
+ await publish();
993
+ setIsDraftRelationConfirmationOpen(false);
994
+ },
995
+ type: "dialog",
996
+ title: formatMessage({
997
+ id: getTranslation("actions.publish.dialog.title"),
998
+ defaultMessage: "Confirmation"
999
+ }),
1000
+ content: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "center", gap: 2, children: [
1001
+ /* @__PURE__ */ jsxRuntime.jsx(icons.WarningCircle, { width: "2.4rem", height: "2.4rem", fill: "danger600" }),
1002
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textAlign: "center", children: formatMessage({
1003
+ id: getTranslation("CMEditViewBulkLocale.draft-relation-warning"),
1004
+ defaultMessage: "Some locales are related to draft entries. Publishing them could leave broken links in your app."
1005
+ }) }),
1006
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textAlign: "center", children: formatMessage({
1007
+ id: getTranslation("CMEditViewBulkLocale.continue-confirmation"),
1008
+ defaultMessage: "Are you sure you want to continue?"
1009
+ }) })
1010
+ ] })
1011
+ }
1012
+ };
1013
+ }
1014
+ const hasPermission = selectedRows.map(({ locale }) => locale).every((locale) => canPublish.includes(locale));
1015
+ return {
1016
+ label: formatMessage({
1017
+ id: getTranslation(`CMEditViewBulkLocale.${isBulkPublish ? "publish" : "unpublish"}-title`),
1018
+ defaultMessage: `${isBulkPublish ? "Publish" : "Unpublish"} Multiple Locales`
1019
+ }),
1020
+ variant: isBulkPublish ? "secondary" : "danger",
1021
+ icon: isBulkPublish ? /* @__PURE__ */ jsxRuntime.jsx(icons.ListPlus, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.Cross, {}),
1022
+ disabled: isOnPublishedTab || canPublish.length === 0,
1023
+ position: ["panel"],
1024
+ dialog: {
1025
+ type: "modal",
1026
+ title: formatMessage({
1027
+ id: getTranslation(`CMEditViewBulkLocale.${isBulkPublish ? "publish" : "unpublish"}-title`),
1028
+ defaultMessage: `${isBulkPublish ? "Publish" : "Unpublish"} Multiple Locales`
1029
+ }),
1030
+ content: () => {
1031
+ return /* @__PURE__ */ jsxRuntime.jsx(
1032
+ strapiAdmin.Table.Root,
1033
+ {
1034
+ headers,
1035
+ rows: rows.map((row) => ({
1036
+ ...row,
1037
+ id: row.locale
1038
+ })),
1039
+ selectedRows,
1040
+ onSelectedRowsChange: (tableSelectedRows) => setSelectedRows(tableSelectedRows),
1041
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1042
+ BulkLocaleActionModal,
1043
+ {
1044
+ validationErrors,
1045
+ headers,
1046
+ rows,
1047
+ localesMetadata,
1048
+ action: action ?? "bulk-publish"
1049
+ }
1050
+ )
1051
+ }
1052
+ );
1053
+ },
1054
+ footer: () => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Footer, { justifyContent: "flex-end", children: /* @__PURE__ */ jsxRuntime.jsx(
1055
+ designSystem.Button,
1056
+ {
1057
+ loading: isDraftRelationsLoading,
1058
+ disabled: !hasPermission || localesForAction.length === 0,
1059
+ variant: "default",
1060
+ onClick: handleAction,
1061
+ children: formatMessage({
1062
+ id: isBulkPublish ? "app.utils.publish" : "app.utils.unpublish",
1063
+ defaultMessage: isBulkPublish ? "Publish" : "Unpublish"
1064
+ })
1065
+ }
1066
+ ) })
1067
+ }
1068
+ };
1069
+ };
1070
+ const BulkLocalePublishAction = (props) => {
1071
+ return BulkLocaleAction({ action: "bulk-publish", ...props });
1072
+ };
1073
+ const BulkLocaleUnpublishAction = (props) => {
1074
+ return BulkLocaleAction({ action: "bulk-unpublish", ...props });
1075
+ };
1076
+ const StyledTrash = styledComponents.styled(icons.Trash)`
1077
+ path {
1078
+ fill: currentColor;
1079
+ }
1080
+ `;
1081
+ const Emphasis = (chunks) => {
1082
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { fontWeight: "semiBold", textColor: "danger500", children: chunks });
1083
+ };
1084
+ const DeleteModalAdditionalInfo = () => {
1085
+ const { hasI18n } = useI18n();
1086
+ const { formatMessage } = reactIntl.useIntl();
1087
+ if (!hasI18n) {
1088
+ return null;
1089
+ }
1090
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "danger500", children: formatMessage(
1091
+ {
1092
+ id: getTranslation("Settings.list.actions.deleteAdditionalInfos"),
1093
+ defaultMessage: "This will delete the active locale versions <em>(from Internationalization)</em>"
1094
+ },
1095
+ {
1096
+ em: Emphasis
1097
+ }
1098
+ ) });
1099
+ };
1100
+ const PublishModalAdditionalInfo = () => {
1101
+ const { hasI18n } = useI18n();
1102
+ const { formatMessage } = reactIntl.useIntl();
1103
+ if (!hasI18n) {
1104
+ return null;
1105
+ }
1106
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "danger500", children: formatMessage(
1107
+ {
1108
+ id: getTranslation("Settings.list.actions.publishAdditionalInfos"),
1109
+ defaultMessage: "This will publish the active locale versions <em>(from Internationalization)</em>"
1110
+ },
1111
+ {
1112
+ em: Emphasis
1113
+ }
1114
+ ) });
1115
+ };
1116
+ const UnpublishModalAdditionalInfo = () => {
1117
+ const { hasI18n } = useI18n();
1118
+ const { formatMessage } = reactIntl.useIntl();
1119
+ if (!hasI18n) {
1120
+ return null;
1121
+ }
1122
+ return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "danger500", children: formatMessage(
1123
+ {
1124
+ id: getTranslation("Settings.list.actions.unpublishAdditionalInfos"),
1125
+ defaultMessage: "This will unpublish the active locale versions <em>(from Internationalization)</em>"
1126
+ },
1127
+ {
1128
+ em: Emphasis
1129
+ }
1130
+ ) });
1131
+ };
1132
+ const LocalePicker = () => {
1133
+ const { formatMessage } = reactIntl.useIntl();
1134
+ const [{ query: query2 }, setQuery] = strapiAdmin.useQueryParams();
1135
+ const { hasI18n, canRead, canCreate } = useI18n();
1136
+ const { data: locales = [] } = useGetLocalesQuery(void 0, {
1137
+ skip: !hasI18n
1138
+ });
1139
+ const handleChange = React__namespace.useCallback(
1140
+ (code, replace = false) => {
1141
+ setQuery(
1142
+ {
1143
+ page: 1,
1144
+ plugins: { ...query2.plugins, i18n: { locale: code } }
1145
+ },
1146
+ "push",
1147
+ replace
1148
+ );
1149
+ },
1150
+ [query2.plugins, setQuery]
1151
+ );
1152
+ React__namespace.useEffect(() => {
1153
+ if (!Array.isArray(locales) || !hasI18n) {
1154
+ return;
1155
+ }
1156
+ const currentDesiredLocale = query2.plugins?.i18n?.locale;
1157
+ const doesLocaleExist = locales.find((loc) => loc.code === currentDesiredLocale);
1158
+ const defaultLocale = locales.find((locale) => locale.isDefault);
1159
+ if (!doesLocaleExist && defaultLocale?.code) {
1160
+ handleChange(defaultLocale.code, true);
1161
+ }
1162
+ }, [hasI18n, handleChange, locales, query2.plugins?.i18n?.locale]);
1163
+ if (!hasI18n || !Array.isArray(locales) || locales.length === 0) {
1164
+ return null;
1165
+ }
1166
+ const displayedLocales = locales.filter((locale) => {
1167
+ return canCreate.includes(locale.code) || canRead.includes(locale.code);
1168
+ });
1169
+ return /* @__PURE__ */ jsxRuntime.jsx(
1170
+ designSystem.SingleSelect,
1171
+ {
1172
+ size: "S",
1173
+ "aria-label": formatMessage({
1174
+ id: getTranslation("actions.select-locale"),
1175
+ defaultMessage: "Select locale"
1176
+ }),
1177
+ value: query2.plugins?.i18n?.locale || locales.find((locale) => locale.isDefault)?.code,
1178
+ onChange: handleChange,
1179
+ children: displayedLocales.map((locale) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: locale.code, children: locale.name }, locale.id))
1180
+ }
1181
+ );
1182
+ };
1183
+ const PERMISSIONS = {
1184
+ accessMain: [{ action: "plugin::i18n.locale.read", subject: null }],
1185
+ create: [{ action: "plugin::i18n.locale.create", subject: null }],
1186
+ delete: [{ action: "plugin::i18n.locale.delete", subject: null }],
1187
+ update: [{ action: "plugin::i18n.locale.update", subject: null }],
1188
+ read: [{ action: "plugin::i18n.locale.read", subject: null }]
1189
+ };
1190
+ const mutateEditViewHook = ({ layout }) => {
1191
+ if (!("i18n" in layout.options) || typeof layout.options.i18n === "object" && layout.options.i18n !== null && "localized" in layout.options.i18n && !layout.options.i18n.localized) {
1192
+ return { layout };
1193
+ }
1194
+ const components = Object.entries(layout.components).reduce(
1195
+ (acc, [key, componentLayout]) => {
1196
+ return {
1197
+ ...acc,
1198
+ [key]: {
1199
+ ...componentLayout,
1200
+ layout: componentLayout.layout.map((row) => row.map(addLabelActionToField))
1201
+ }
1202
+ };
1203
+ },
1204
+ {}
1205
+ );
1206
+ return {
1207
+ layout: {
1208
+ ...layout,
1209
+ components,
1210
+ layout: layout.layout.map((panel) => panel.map((row) => row.map(addLabelActionToField)))
1211
+ }
1212
+ };
1213
+ };
1214
+ const addLabelActionToField = (field) => {
1215
+ const isFieldLocalized = doesFieldHaveI18nPluginOpt(field.attribute.pluginOptions) ? field.attribute.pluginOptions.i18n.localized : true;
1216
+ const labelActionProps = {
1217
+ title: {
1218
+ id: isFieldLocalized ? getTranslation("Field.localized") : getTranslation("Field.not-localized"),
1219
+ defaultMessage: isFieldLocalized ? "This value is unique for the selected locale" : "This value is the same across all locales"
1220
+ },
1221
+ icon: isFieldLocalized ? /* @__PURE__ */ jsxRuntime.jsx(icons.Earth, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.EarthStriked, {})
1222
+ };
1223
+ return {
1224
+ ...field,
1225
+ labelAction: /* @__PURE__ */ jsxRuntime.jsx(LabelAction, { ...labelActionProps })
1226
+ };
1227
+ };
1228
+ const doesFieldHaveI18nPluginOpt = (pluginOpts) => {
1229
+ if (!pluginOpts) {
1230
+ return false;
1231
+ }
1232
+ return "i18n" in pluginOpts && typeof pluginOpts.i18n === "object" && pluginOpts.i18n !== null && "localized" in pluginOpts.i18n;
1233
+ };
1234
+ const LabelAction = ({ title, icon }) => {
1235
+ const { formatMessage } = reactIntl.useIntl();
1236
+ return /* @__PURE__ */ jsxRuntime.jsxs(Span, { tag: "span", children: [
1237
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.VisuallyHidden, { tag: "span", children: formatMessage(title) }),
1238
+ React__namespace.cloneElement(icon, {
1239
+ "aria-hidden": true,
1240
+ focusable: false
1241
+ // See: https://allyjs.io/tutorials/focusing-in-svg.html#making-svg-elements-focusable
1242
+ })
1243
+ ] });
1244
+ };
1245
+ const Span = styledComponents.styled(designSystem.Flex)`
1246
+ svg {
1247
+ width: 12px;
1248
+ height: 12px;
1249
+
1250
+ fill: ${({ theme }) => theme.colors.neutral500};
1251
+
1252
+ path {
1253
+ fill: ${({ theme }) => theme.colors.neutral500};
1254
+ }
1255
+ }
1256
+ `;
1257
+ const LocaleListCell = ({
1258
+ documentId,
1259
+ locale: currentLocale,
1260
+ collectionType,
1261
+ model
1262
+ }) => {
1263
+ const { meta, isLoading } = strapiAdmin$1.unstable_useDocument({
1264
+ documentId,
1265
+ collectionType,
1266
+ model,
1267
+ params: {
1268
+ locale: currentLocale
1269
+ }
1270
+ });
1271
+ const { locale: language } = reactIntl.useIntl();
1272
+ const { data: locales = [] } = useGetLocalesQuery();
1273
+ const formatter = designSystem.useCollator(language, {
1274
+ sensitivity: "base"
1275
+ });
1276
+ if (!Array.isArray(locales) || isLoading) {
1277
+ return null;
1278
+ }
1279
+ const availableLocales = meta?.availableLocales.map((doc) => doc.locale) ?? [];
1280
+ const localesForDocument = locales.reduce((acc, locale) => {
1281
+ const createdLocale = [currentLocale, ...availableLocales].find((loc) => {
1282
+ return loc === locale.code;
1283
+ });
1284
+ if (createdLocale) {
1285
+ acc.push(locale);
1286
+ }
1287
+ return acc;
1288
+ }, []).map((locale) => {
1289
+ if (locale.isDefault) {
1290
+ return `${locale.name} (default)`;
1291
+ }
1292
+ return locale.name;
1293
+ }).toSorted((a, b) => formatter.compare(a, b));
1294
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Popover.Root, { children: [
1295
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Popover.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "ghost", type: "button", onClick: (e) => e.stopPropagation(), children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { minWidth: "100%", alignItems: "center", justifyContent: "center", fontWeight: "regular", children: [
1296
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral800", ellipsis: true, marginRight: 2, children: localesForDocument.join(", ") }),
1297
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { children: /* @__PURE__ */ jsxRuntime.jsx(icons.CaretDown, { width: "1.2rem", height: "1.2rem" }) })
1298
+ ] }) }) }),
1299
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Popover.Content, { sideOffset: 16, children: /* @__PURE__ */ jsxRuntime.jsx("ul", { children: localesForDocument.map((name) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Box, { padding: 3, tag: "li", children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: name }) }, name)) }) })
1300
+ ] });
1301
+ };
1302
+ const addColumnToTableHook = ({ displayedHeaders, layout }) => {
1303
+ const { options } = layout;
1304
+ const isFieldLocalized = doesPluginOptionsHaveI18nLocalized(options) ? options.i18n.localized : false;
1305
+ if (!isFieldLocalized) {
1306
+ return { displayedHeaders, layout };
1307
+ }
1308
+ return {
1309
+ displayedHeaders: [
1310
+ ...displayedHeaders,
1311
+ {
1312
+ attribute: { type: "string" },
1313
+ label: {
1314
+ id: getTranslation("list-view.table.header.label"),
1315
+ defaultMessage: "Available in"
1316
+ },
1317
+ searchable: false,
1318
+ sortable: false,
1319
+ name: "locales",
1320
+ // @ts-expect-error – ID is seen as number | string; this will change when we move the type over.
1321
+ cellFormatter: (props, _header, meta) => /* @__PURE__ */ jsxRuntime.jsx(LocaleListCell, { ...props, ...meta })
1322
+ }
1323
+ ],
1324
+ layout
1325
+ };
1326
+ };
1327
+ const addLocaleToReleasesHook = ({ displayedHeaders = [] }) => {
1328
+ return {
1329
+ displayedHeaders: [
1330
+ ...displayedHeaders,
1331
+ {
1332
+ label: {
1333
+ id: "content-releases.page.ReleaseDetails.table.header.label.locale",
1334
+ defaultMessage: "locale"
1335
+ },
1336
+ name: "locale"
1337
+ }
1338
+ ],
1339
+ hasI18nEnabled: true
1340
+ };
1341
+ };
1342
+ const extendCTBAttributeInitialDataMiddleware = () => {
1343
+ return ({ getState }) => (next) => (action) => {
1344
+ const enhanceAction = () => {
1345
+ try {
1346
+ const store = getState();
1347
+ const hasi18nEnabled = get__default.default(
1348
+ store,
1349
+ [
1350
+ "content-type-builder_dataManagerProvider",
1351
+ "modifiedData",
1352
+ "contentType",
1353
+ "schema",
1354
+ "pluginOptions",
1355
+ "i18n",
1356
+ "localized"
1357
+ ],
1358
+ false
1359
+ );
1360
+ if (hasi18nEnabled) {
1361
+ const pluginOptions = action.options ? { ...action.options.pluginOptions, i18n: { localized: true } } : { i18n: { localized: true } };
1362
+ return next({
1363
+ ...action,
1364
+ options: {
1365
+ pluginOptions
1366
+ }
1367
+ });
1368
+ }
1369
+ return next(action);
1370
+ } catch (err) {
1371
+ return next(action);
1372
+ }
1373
+ };
1374
+ if (action.type === "ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA" && action.forTarget === "contentType" && !["relation", "component"].includes(action.attributeType) && !action.isEditing) {
1375
+ return enhanceAction();
1376
+ }
1377
+ if (action.type === "ContentTypeBuilder/FormModal/SET_CUSTOM_FIELD_DATA_SCHEMA" && action.forTarget === "contentType" && !action.isEditing) {
1378
+ return enhanceAction();
1379
+ }
1380
+ if ((action.type === "ContentTypeBuilder/FormModal/RESET_PROPS_AND_SET_FORM_FOR_ADDING_AN_EXISTING_COMPO" || action.type === "ContentTypeBuilder/FormModal/RESET_PROPS_AND_SAVE_CURRENT_DATA") && action.forTarget === "contentType") {
1381
+ return enhanceAction();
1382
+ }
1383
+ return next(action);
1384
+ };
1385
+ };
1386
+ const extendCTBInitialDataMiddleware = () => {
1387
+ return () => (next) => (action) => {
1388
+ if (action.type === "ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT" && action.modalType === "contentType") {
1389
+ const i18n = { localized: false };
1390
+ const pluginOptions = action.data.pluginOptions ? { ...action.data.pluginOptions, i18n } : { i18n };
1391
+ const data = { ...action.data, pluginOptions };
1392
+ if (action.actionType === "create") {
1393
+ return next({ ...action, data });
1394
+ }
1395
+ if (!action.data.pluginOptions?.i18n?.localized) {
1396
+ return next({ ...action, data });
1397
+ }
1398
+ }
1399
+ return next(action);
1400
+ };
1401
+ };
1402
+ const localeMiddleware = (ctx) => (next) => (permissions) => {
1403
+ const match = reactRouterDom.matchPath("/content-manager/:collectionType/:model?/:id", ctx.pathname);
1404
+ if (!match) {
1405
+ return next(permissions);
1406
+ }
1407
+ const search = qs__namespace.parse(ctx.search);
1408
+ if (typeof search !== "object") {
1409
+ return next(permissions);
1410
+ }
1411
+ if (!("plugins" in search && typeof search.plugins === "object")) {
1412
+ return next(permissions);
1413
+ }
1414
+ if (!("i18n" in search.plugins && typeof search.plugins.i18n === "object" && !Array.isArray(search.plugins.i18n))) {
1415
+ return next(permissions);
1416
+ }
1417
+ const { locale } = search.plugins.i18n;
1418
+ if (typeof locale !== "string") {
1419
+ return next(permissions);
1420
+ }
1421
+ const revisedPermissions = permissions.filter(
1422
+ (permission) => !permission.properties?.locales || permission.properties.locales.includes(locale)
1423
+ );
1424
+ return next(revisedPermissions);
1425
+ };
1426
+ const prefixPluginTranslations = (trad, pluginId2) => {
1427
+ return Object.keys(trad).reduce((acc, current) => {
1428
+ acc[`${pluginId2}.${current}`] = trad[current];
1429
+ return acc;
1430
+ }, {});
1431
+ };
1432
+ const mutateCTBContentTypeSchema = (nextSchema, prevSchema) => {
1433
+ if (!doesPluginOptionsHaveI18nLocalized(nextSchema.pluginOptions)) {
1434
+ return nextSchema;
1435
+ }
1436
+ const isNextSchemaLocalized = nextSchema.pluginOptions.i18n.localized;
1437
+ const isPrevSchemaLocalized = doesPluginOptionsHaveI18nLocalized(
1438
+ prevSchema?.schema?.pluginOptions
1439
+ ) ? prevSchema?.schema?.pluginOptions.i18n.localized : false;
1440
+ if (isNextSchemaLocalized && isPrevSchemaLocalized) {
1441
+ return nextSchema;
1442
+ }
1443
+ if (isNextSchemaLocalized) {
1444
+ const attributes = addLocalisationToFields(nextSchema.attributes);
1445
+ return { ...nextSchema, attributes };
1446
+ }
1447
+ if (!isNextSchemaLocalized) {
1448
+ const pluginOptions = omit__default.default(nextSchema.pluginOptions, "i18n");
1449
+ const attributes = disableAttributesLocalisation(nextSchema.attributes);
1450
+ return { ...nextSchema, pluginOptions, attributes };
1451
+ }
1452
+ return nextSchema;
1453
+ };
1454
+ const addLocalisationToFields = (attributes) => Object.keys(attributes).reduce((acc, current) => {
1455
+ const currentAttribute = attributes[current];
1456
+ if (LOCALIZED_FIELDS.includes(currentAttribute.type)) {
1457
+ const i18n = { localized: true };
1458
+ const pluginOptions = currentAttribute.pluginOptions ? { ...currentAttribute.pluginOptions, i18n } : { i18n };
1459
+ acc[current] = { ...currentAttribute, pluginOptions };
1460
+ return acc;
1461
+ }
1462
+ acc[current] = currentAttribute;
1463
+ return acc;
1464
+ }, {});
1465
+ const disableAttributesLocalisation = (attributes) => Object.keys(attributes).reduce((acc, current) => {
1466
+ acc[current] = omit__default.default(attributes[current], "pluginOptions.i18n");
1467
+ return acc;
1468
+ }, {});
1469
+ const index = {
1470
+ register(app) {
1471
+ app.addMiddlewares([extendCTBAttributeInitialDataMiddleware, extendCTBInitialDataMiddleware]);
1472
+ app.addMiddlewares([() => i18nApi.middleware]);
1473
+ app.addReducers({
1474
+ [i18nApi.reducerPath]: i18nApi.reducer
1475
+ });
1476
+ app.addRBACMiddleware([localeMiddleware]);
1477
+ app.registerPlugin({
1478
+ id: pluginId,
1479
+ name: pluginId
1480
+ });
1481
+ },
1482
+ bootstrap(app) {
1483
+ app.registerHook("Admin/CM/pages/ListView/inject-column-in-table", addColumnToTableHook);
1484
+ app.registerHook("Admin/CM/pages/EditView/mutate-edit-view-layout", mutateEditViewHook);
1485
+ app.registerHook(
1486
+ "ContentReleases/pages/ReleaseDetails/add-locale-in-releases",
1487
+ addLocaleToReleasesHook
1488
+ );
1489
+ app.addSettingsLink("global", {
1490
+ intlLabel: {
1491
+ id: getTranslation("plugin.name"),
1492
+ defaultMessage: "Internationalization"
1493
+ },
1494
+ id: "internationalization",
1495
+ to: "internationalization",
1496
+ Component: () => Promise.resolve().then(() => require("./SettingsPage-JyA1zd8f.js")).then((mod) => ({ default: mod.ProtectedSettingsPage })),
1497
+ permissions: PERMISSIONS.accessMain
1498
+ });
1499
+ const contentManager = app.getPlugin("content-manager");
1500
+ contentManager.apis.addDocumentHeaderAction([LocalePickerAction, FillFromAnotherLocaleAction]);
1501
+ contentManager.apis.addDocumentAction((actions) => {
1502
+ const indexOfDeleteAction = actions.findIndex((action) => action.type === "delete");
1503
+ actions.splice(indexOfDeleteAction, 0, DeleteLocaleAction);
1504
+ return actions;
1505
+ });
1506
+ contentManager.apis.addDocumentAction((actions) => {
1507
+ actions.splice(2, 0, BulkLocalePublishAction);
1508
+ actions.splice(5, 0, BulkLocaleUnpublishAction);
1509
+ return actions;
1510
+ });
1511
+ contentManager.injectComponent("listView", "actions", {
1512
+ name: "i18n-locale-filter",
1513
+ Component: LocalePicker
1514
+ });
1515
+ contentManager.injectComponent("listView", "publishModalAdditionalInfos", {
1516
+ name: "i18n-publish-bullets-in-modal",
1517
+ Component: PublishModalAdditionalInfo
1518
+ });
1519
+ contentManager.injectComponent("listView", "unpublishModalAdditionalInfos", {
1520
+ name: "i18n-unpublish-bullets-in-modal",
1521
+ Component: UnpublishModalAdditionalInfo
1522
+ });
1523
+ contentManager.injectComponent("listView", "deleteModalAdditionalInfos", {
1524
+ name: "i18n-delete-bullets-in-modal",
1525
+ Component: DeleteModalAdditionalInfo
1526
+ });
1527
+ const ctbPlugin = app.getPlugin("content-type-builder");
1528
+ if (ctbPlugin) {
1529
+ const ctbFormsAPI = ctbPlugin.apis.forms;
1530
+ ctbFormsAPI.addContentTypeSchemaMutation(mutateCTBContentTypeSchema);
1531
+ ctbFormsAPI.components.add({ id: "checkboxConfirmation", component: CheckboxConfirmation });
1532
+ ctbFormsAPI.extendContentType({
1533
+ validator: () => ({
1534
+ i18n: yup__namespace.object().shape({
1535
+ localized: yup__namespace.bool()
1536
+ })
1537
+ }),
1538
+ form: {
1539
+ advanced() {
1540
+ return [
1541
+ {
1542
+ name: "pluginOptions.i18n.localized",
1543
+ description: {
1544
+ id: getTranslation("plugin.schema.i18n.localized.description-content-type"),
1545
+ defaultMessage: "Allows translating an entry into different languages"
1546
+ },
1547
+ type: "checkboxConfirmation",
1548
+ intlLabel: {
1549
+ id: getTranslation("plugin.schema.i18n.localized.label-content-type"),
1550
+ defaultMessage: "Localization"
1551
+ }
1552
+ }
1553
+ ];
1554
+ }
1555
+ }
1556
+ });
1557
+ ctbFormsAPI.extendFields(LOCALIZED_FIELDS, {
1558
+ validator: (args) => ({
1559
+ i18n: yup__namespace.object().shape({
1560
+ localized: yup__namespace.bool().test({
1561
+ name: "ensure-unique-localization",
1562
+ message: getTranslation("plugin.schema.i18n.ensure-unique-localization"),
1563
+ test(value) {
1564
+ if (value === void 0 || value) {
1565
+ return true;
1566
+ }
1567
+ const unique = get__default.default(args, ["3", "modifiedData", "unique"], null);
1568
+ if (unique && !value) {
1569
+ return false;
1570
+ }
1571
+ return true;
1572
+ }
1573
+ })
1574
+ })
1575
+ }),
1576
+ form: {
1577
+ advanced({ contentTypeSchema, forTarget, type, step }) {
1578
+ if (forTarget !== "contentType") {
1579
+ return [];
1580
+ }
1581
+ const hasI18nEnabled = get__default.default(
1582
+ contentTypeSchema,
1583
+ ["schema", "pluginOptions", "i18n", "localized"],
1584
+ false
1585
+ );
1586
+ if (!hasI18nEnabled) {
1587
+ return [];
1588
+ }
1589
+ if (type === "component" && step === "1") {
1590
+ return [];
1591
+ }
1592
+ return [
1593
+ {
1594
+ name: "pluginOptions.i18n.localized",
1595
+ description: {
1596
+ id: getTranslation("plugin.schema.i18n.localized.description-field"),
1597
+ defaultMessage: "The field can have different values in each locale"
1598
+ },
1599
+ type: "checkbox",
1600
+ intlLabel: {
1601
+ id: getTranslation("plugin.schema.i18n.localized.label-field"),
1602
+ defaultMessage: "Enable localization for this field"
1603
+ }
1604
+ }
1605
+ ];
1606
+ }
1607
+ }
1608
+ });
1609
+ }
1610
+ },
1611
+ async registerTrads({ locales }) {
1612
+ const importedTrads = await Promise.all(
1613
+ locales.map((locale) => {
1614
+ return __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "./translations/de.json": () => Promise.resolve().then(() => require("./de-DtWiGdHl.js")), "./translations/dk.json": () => Promise.resolve().then(() => require("./dk-D8C-casx.js")), "./translations/en.json": () => Promise.resolve().then(() => require("./en-BKBz3tro.js")), "./translations/es.json": () => Promise.resolve().then(() => require("./es-DS-XFGSw.js")), "./translations/fr.json": () => Promise.resolve().then(() => require("./fr-BTjekDpq.js")), "./translations/ko.json": () => Promise.resolve().then(() => require("./ko-DmcGUBQ3.js")), "./translations/pl.json": () => Promise.resolve().then(() => require("./pl-Cn5RYonZ.js")), "./translations/ru.json": () => Promise.resolve().then(() => require("./ru-BMBgVL3s.js")), "./translations/tr.json": () => Promise.resolve().then(() => require("./tr-CarUU76c.js")), "./translations/zh-Hans.json": () => Promise.resolve().then(() => require("./zh-Hans-DSHIXAa3.js")), "./translations/zh.json": () => Promise.resolve().then(() => require("./zh-CukOviB0.js")) }), `./translations/${locale}.json`).then(({ default: data }) => {
1615
+ return {
1616
+ data: prefixPluginTranslations(data, pluginId),
1617
+ locale
1618
+ };
1619
+ }).catch(() => {
1620
+ return {
1621
+ data: {},
1622
+ locale
1623
+ };
1624
+ });
1625
+ })
1626
+ );
1627
+ return Promise.resolve(importedTrads);
1628
+ }
1629
+ };
1630
+ exports.PERMISSIONS = PERMISSIONS;
1631
+ exports.getTranslation = getTranslation;
1632
+ exports.index = index;
1633
+ exports.useCreateLocaleMutation = useCreateLocaleMutation;
1634
+ exports.useDeleteLocaleMutation = useDeleteLocaleMutation;
1635
+ exports.useGetDefaultLocalesQuery = useGetDefaultLocalesQuery;
1636
+ exports.useGetLocalesQuery = useGetLocalesQuery;
1637
+ exports.useUpdateLocaleMutation = useUpdateLocaleMutation;
1638
+ //# sourceMappingURL=index-BwAeKsym.js.map