@strapi/i18n 5.8.1 → 5.10.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 (126) hide show
  1. package/dist/admin/chunks/SettingsPage-B6ikxVOg.js +820 -0
  2. package/dist/admin/chunks/SettingsPage-B6ikxVOg.js.map +1 -0
  3. package/dist/admin/chunks/SettingsPage-DydtYvMJ.mjs +797 -0
  4. package/dist/admin/chunks/SettingsPage-DydtYvMJ.mjs.map +1 -0
  5. package/dist/admin/chunks/de-Cm8mYdaO.mjs +64 -0
  6. package/dist/admin/chunks/de-Cm8mYdaO.mjs.map +1 -0
  7. package/dist/admin/chunks/de-nEMWvIiY.js +66 -0
  8. package/dist/admin/chunks/de-nEMWvIiY.js.map +1 -0
  9. package/dist/admin/chunks/dk-BeUFOegB.mjs +64 -0
  10. package/dist/admin/chunks/dk-BeUFOegB.mjs.map +1 -0
  11. package/dist/admin/chunks/dk-CYATLPVe.js +66 -0
  12. package/dist/admin/chunks/dk-CYATLPVe.js.map +1 -0
  13. package/dist/admin/chunks/en-CG5cUCbD.js +81 -0
  14. package/dist/admin/chunks/en-CG5cUCbD.js.map +1 -0
  15. package/dist/admin/chunks/en-eWSaCeOb.mjs +79 -0
  16. package/dist/admin/chunks/en-eWSaCeOb.mjs.map +1 -0
  17. package/dist/admin/chunks/es-CWsogTGm.js +66 -0
  18. package/dist/admin/chunks/es-CWsogTGm.js.map +1 -0
  19. package/dist/admin/chunks/es-DqF_IdAc.mjs +64 -0
  20. package/dist/admin/chunks/es-DqF_IdAc.mjs.map +1 -0
  21. package/dist/admin/chunks/fr-CC7UFcYd.js +66 -0
  22. package/dist/admin/chunks/fr-CC7UFcYd.js.map +1 -0
  23. package/dist/admin/chunks/fr-CyARbZ3c.mjs +64 -0
  24. package/dist/admin/chunks/fr-CyARbZ3c.mjs.map +1 -0
  25. package/dist/admin/chunks/index-Dch-2xao.js +2035 -0
  26. package/dist/admin/chunks/index-Dch-2xao.js.map +1 -0
  27. package/dist/admin/chunks/index-k3BHSNs0.mjs +2006 -0
  28. package/dist/admin/chunks/index-k3BHSNs0.mjs.map +1 -0
  29. package/dist/admin/chunks/ko-Ax4NSedM.mjs +63 -0
  30. package/dist/admin/chunks/ko-Ax4NSedM.mjs.map +1 -0
  31. package/dist/admin/chunks/ko-XwGmfhoq.js +65 -0
  32. package/dist/admin/chunks/ko-XwGmfhoq.js.map +1 -0
  33. package/dist/admin/chunks/pl-B-aqvMqL.mjs +64 -0
  34. package/dist/admin/chunks/pl-B-aqvMqL.mjs.map +1 -0
  35. package/dist/admin/chunks/pl-B_vzY_ZB.js +66 -0
  36. package/dist/admin/chunks/pl-B_vzY_ZB.js.map +1 -0
  37. package/dist/admin/chunks/ru-VkPjQ-Sk.mjs +66 -0
  38. package/dist/admin/chunks/ru-VkPjQ-Sk.mjs.map +1 -0
  39. package/dist/admin/chunks/ru-WzHcJV1f.js +68 -0
  40. package/dist/admin/chunks/ru-WzHcJV1f.js.map +1 -0
  41. package/dist/admin/chunks/tr-CcWp6u3w.js +66 -0
  42. package/dist/admin/chunks/tr-CcWp6u3w.js.map +1 -0
  43. package/dist/admin/chunks/tr-DcTR88c9.mjs +64 -0
  44. package/dist/admin/chunks/tr-DcTR88c9.mjs.map +1 -0
  45. package/dist/admin/chunks/zh-C9So4SGq.js +66 -0
  46. package/dist/admin/chunks/zh-C9So4SGq.js.map +1 -0
  47. package/dist/admin/chunks/zh-Hans-DnU2bhri.js +57 -0
  48. package/dist/admin/chunks/zh-Hans-DnU2bhri.js.map +1 -0
  49. package/dist/admin/chunks/zh-Hans-L3wsRegj.mjs +55 -0
  50. package/dist/admin/chunks/zh-Hans-L3wsRegj.mjs.map +1 -0
  51. package/dist/admin/chunks/zh-RZyMiPIs.mjs +64 -0
  52. package/dist/admin/chunks/zh-RZyMiPIs.mjs.map +1 -0
  53. package/dist/admin/index.js +20 -4
  54. package/dist/admin/index.js.map +1 -1
  55. package/dist/admin/index.mjs +15 -6
  56. package/dist/admin/index.mjs.map +1 -1
  57. package/dist/admin/src/components/CMHeaderActions.d.ts +1 -1
  58. package/dist/admin/src/components/tests/CreateLocale.test.d.ts +1 -0
  59. package/dist/admin/src/components/tests/DeleteLocale.test.d.ts +1 -0
  60. package/dist/admin/src/components/tests/EditLocale.test.d.ts +1 -0
  61. package/dist/admin/src/components/tests/LocaleListCell.test.d.ts +1 -0
  62. package/dist/admin/src/contentReleasesHooks/releaseDetailsView.d.ts +1 -1
  63. package/dist/admin/src/pages/tests/SettingsPage.test.d.ts +1 -0
  64. package/dist/admin/tests/server.d.ts +1 -0
  65. package/dist/admin/tests/utils.d.ts +6 -0
  66. package/dist/server/index.js +3650 -3390
  67. package/dist/server/index.js.map +1 -1
  68. package/dist/server/index.mjs +3632 -3374
  69. package/dist/server/index.mjs.map +1 -1
  70. package/dist/server/src/services/localizations.d.ts +1 -1
  71. package/dist/server/src/services/localizations.d.ts.map +1 -1
  72. package/dist/shared/contracts/content-manager.d.ts +1 -1
  73. package/dist/shared/contracts/shared.d.ts +1 -1
  74. package/package.json +14 -11
  75. package/dist/_chunks/SettingsPage-B-KzAqT3.mjs +0 -554
  76. package/dist/_chunks/SettingsPage-B-KzAqT3.mjs.map +0 -1
  77. package/dist/_chunks/SettingsPage-hyOi94O9.js +0 -573
  78. package/dist/_chunks/SettingsPage-hyOi94O9.js.map +0 -1
  79. package/dist/_chunks/de-BOhNX_-5.js +0 -65
  80. package/dist/_chunks/de-BOhNX_-5.js.map +0 -1
  81. package/dist/_chunks/de-D80IRBP9.mjs +0 -65
  82. package/dist/_chunks/de-D80IRBP9.mjs.map +0 -1
  83. package/dist/_chunks/dk-CJ6Zzz78.mjs +0 -65
  84. package/dist/_chunks/dk-CJ6Zzz78.mjs.map +0 -1
  85. package/dist/_chunks/dk-cjXm0p3m.js +0 -65
  86. package/dist/_chunks/dk-cjXm0p3m.js.map +0 -1
  87. package/dist/_chunks/en-BTyF7WVW.mjs +0 -80
  88. package/dist/_chunks/en-BTyF7WVW.mjs.map +0 -1
  89. package/dist/_chunks/en-UlC0jh2t.js +0 -80
  90. package/dist/_chunks/en-UlC0jh2t.js.map +0 -1
  91. package/dist/_chunks/es-V8WnPN7w.mjs +0 -65
  92. package/dist/_chunks/es-V8WnPN7w.mjs.map +0 -1
  93. package/dist/_chunks/es-hr9b_HLp.js +0 -65
  94. package/dist/_chunks/es-hr9b_HLp.js.map +0 -1
  95. package/dist/_chunks/fr-BFmBbE0H.js +0 -65
  96. package/dist/_chunks/fr-BFmBbE0H.js.map +0 -1
  97. package/dist/_chunks/fr-F94noFiV.mjs +0 -65
  98. package/dist/_chunks/fr-F94noFiV.mjs.map +0 -1
  99. package/dist/_chunks/index-BcYj5jo9.mjs +0 -1589
  100. package/dist/_chunks/index-BcYj5jo9.mjs.map +0 -1
  101. package/dist/_chunks/index-C8NzsAKp.js +0 -1610
  102. package/dist/_chunks/index-C8NzsAKp.js.map +0 -1
  103. package/dist/_chunks/ko-C40pNQ9b.js +0 -64
  104. package/dist/_chunks/ko-C40pNQ9b.js.map +0 -1
  105. package/dist/_chunks/ko-CF-P3Car.mjs +0 -64
  106. package/dist/_chunks/ko-CF-P3Car.mjs.map +0 -1
  107. package/dist/_chunks/pl-Dxr9RUmD.mjs +0 -65
  108. package/dist/_chunks/pl-Dxr9RUmD.mjs.map +0 -1
  109. package/dist/_chunks/pl-JtWBy-JQ.js +0 -65
  110. package/dist/_chunks/pl-JtWBy-JQ.js.map +0 -1
  111. package/dist/_chunks/ru-B-4sVwXN.mjs +0 -67
  112. package/dist/_chunks/ru-B-4sVwXN.mjs.map +0 -1
  113. package/dist/_chunks/ru-COSWt3Nu.js +0 -67
  114. package/dist/_chunks/ru-COSWt3Nu.js.map +0 -1
  115. package/dist/_chunks/tr-BVj1O5ch.js +0 -65
  116. package/dist/_chunks/tr-BVj1O5ch.js.map +0 -1
  117. package/dist/_chunks/tr-Ccu6Yj11.mjs +0 -65
  118. package/dist/_chunks/tr-Ccu6Yj11.mjs.map +0 -1
  119. package/dist/_chunks/zh-BIz395Ms.mjs +0 -65
  120. package/dist/_chunks/zh-BIz395Ms.mjs.map +0 -1
  121. package/dist/_chunks/zh-Hans-Bfo6_TCM.mjs +0 -56
  122. package/dist/_chunks/zh-Hans-Bfo6_TCM.mjs.map +0 -1
  123. package/dist/_chunks/zh-Hans-DIEm_EMC.js +0 -56
  124. package/dist/_chunks/zh-Hans-DIEm_EMC.js.map +0 -1
  125. package/dist/_chunks/zh-wkBPBkhc.js +0 -65
  126. package/dist/_chunks/zh-wkBPBkhc.js.map +0 -1
@@ -0,0 +1,2035 @@
1
+ 'use strict';
2
+
3
+ var get = require('lodash/get');
4
+ var yup = require('yup');
5
+ var jsxRuntime = require('react/jsx-runtime');
6
+ var React = require('react');
7
+ var designSystem = require('@strapi/design-system');
8
+ var icons = require('@strapi/icons');
9
+ var reactIntl = require('react-intl');
10
+ var styledComponents = require('styled-components');
11
+ var query = require('@reduxjs/toolkit/query');
12
+ var strapiAdmin = require('@strapi/admin/strapi-admin');
13
+ var strapiAdmin$1 = require('@strapi/content-manager/strapi-admin');
14
+ var reactRouterDom = require('react-router-dom');
15
+ var qs = require('qs');
16
+ var omit = require('lodash/omit');
17
+
18
+ function _interopNamespaceDefault(e) {
19
+ var n = Object.create(null);
20
+ if (e) {
21
+ Object.keys(e).forEach(function (k) {
22
+ if (k !== 'default') {
23
+ var d = Object.getOwnPropertyDescriptor(e, k);
24
+ Object.defineProperty(n, k, d.get ? d : {
25
+ enumerable: true,
26
+ get: function () { return e[k]; }
27
+ });
28
+ }
29
+ });
30
+ }
31
+ n.default = e;
32
+ return Object.freeze(n);
33
+ }
34
+
35
+ var yup__namespace = /*#__PURE__*/_interopNamespaceDefault(yup);
36
+ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
37
+ var qs__namespace = /*#__PURE__*/_interopNamespaceDefault(qs);
38
+
39
+ const pluginId = 'i18n';
40
+
41
+ const getTranslation = (id)=>`${pluginId}.${id}`;
42
+
43
+ const TextAlignTypography = styledComponents.styled(designSystem.Typography)`
44
+ text-align: center;
45
+ `;
46
+ const CheckboxConfirmation = ({ description, isCreating = false, intlLabel, name, onChange, value })=>{
47
+ const { formatMessage } = reactIntl.useIntl();
48
+ const [isOpen, setIsOpen] = React__namespace.useState(false);
49
+ const handleChange = (value)=>{
50
+ if (isCreating || value) {
51
+ return onChange({
52
+ target: {
53
+ name,
54
+ value,
55
+ type: 'checkbox'
56
+ }
57
+ });
58
+ }
59
+ if (!value) {
60
+ return setIsOpen(true);
61
+ }
62
+ return null;
63
+ };
64
+ const handleConfirm = ()=>{
65
+ onChange({
66
+ target: {
67
+ name,
68
+ value: false,
69
+ type: 'checkbox'
70
+ }
71
+ });
72
+ };
73
+ const label = intlLabel.id ? formatMessage({
74
+ id: intlLabel.id,
75
+ defaultMessage: intlLabel.defaultMessage
76
+ }, {
77
+ ...intlLabel.values
78
+ }) : name;
79
+ const hint = description ? formatMessage({
80
+ id: description.id,
81
+ defaultMessage: description.defaultMessage
82
+ }, {
83
+ ...description.values
84
+ }) : '';
85
+ return /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Dialog.Root, {
86
+ open: isOpen,
87
+ onOpenChange: setIsOpen,
88
+ children: [
89
+ /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Field.Root, {
90
+ hint: hint,
91
+ name: name,
92
+ children: [
93
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Checkbox, {
94
+ onCheckedChange: handleChange,
95
+ checked: value,
96
+ children: label
97
+ }),
98
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Field.Hint, {})
99
+ ]
100
+ }),
101
+ /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Dialog.Content, {
102
+ children: [
103
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Dialog.Header, {
104
+ children: formatMessage({
105
+ id: getTranslation('CheckboxConfirmation.Modal.title'),
106
+ defaultMessage: 'Disable localization'
107
+ })
108
+ }),
109
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Dialog.Body, {
110
+ icon: /*#__PURE__*/ jsxRuntime.jsx(icons.WarningCircle, {}),
111
+ children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
112
+ direction: "column",
113
+ alignItems: "stretch",
114
+ gap: 2,
115
+ children: [
116
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Flex, {
117
+ justifyContent: "center",
118
+ children: /*#__PURE__*/ jsxRuntime.jsx(TextAlignTypography, {
119
+ children: formatMessage({
120
+ id: getTranslation('CheckboxConfirmation.Modal.content'),
121
+ defaultMessage: 'Disabling localization will engender the deletion of all your content but the one associated to your default locale (if existing).'
122
+ })
123
+ })
124
+ }),
125
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Flex, {
126
+ justifyContent: "center",
127
+ children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
128
+ fontWeight: "semiBold",
129
+ children: formatMessage({
130
+ id: getTranslation('CheckboxConfirmation.Modal.body'),
131
+ defaultMessage: 'Do you want to disable it?'
132
+ })
133
+ })
134
+ })
135
+ ]
136
+ })
137
+ }),
138
+ /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Dialog.Footer, {
139
+ children: [
140
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Dialog.Cancel, {
141
+ children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Button, {
142
+ variant: "tertiary",
143
+ children: formatMessage({
144
+ id: 'components.popUpWarning.button.cancel',
145
+ defaultMessage: 'No, cancel'
146
+ })
147
+ })
148
+ }),
149
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Dialog.Action, {
150
+ children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Button, {
151
+ variant: "danger-light",
152
+ onClick: handleConfirm,
153
+ children: formatMessage({
154
+ id: getTranslation('CheckboxConfirmation.Modal.button-confirm'),
155
+ defaultMessage: 'Yes, disable'
156
+ })
157
+ })
158
+ })
159
+ ]
160
+ })
161
+ ]
162
+ })
163
+ ]
164
+ });
165
+ };
166
+
167
+ const LOCALIZED_FIELDS = [
168
+ 'biginteger',
169
+ 'boolean',
170
+ 'component',
171
+ 'date',
172
+ 'datetime',
173
+ 'decimal',
174
+ 'dynamiczone',
175
+ 'email',
176
+ 'enumeration',
177
+ 'float',
178
+ 'integer',
179
+ 'json',
180
+ 'media',
181
+ 'number',
182
+ 'password',
183
+ 'richtext',
184
+ 'blocks',
185
+ 'string',
186
+ 'text',
187
+ 'time'
188
+ ];
189
+ 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';
190
+
191
+ const capitalize = (str)=>str.charAt(0).toUpperCase() + str.slice(1);
192
+
193
+ /**
194
+ * @alpha
195
+ * @description This hook is used to get the i18n status of a content type.
196
+ * Also returns the CRUDP permission locale properties for the content type
197
+ * so we know which locales the user can perform actions on.
198
+ */ const useI18n = ()=>{
199
+ // Extract the params from the URL to pass to our useDocument hook
200
+ const params = reactRouterDom.useParams();
201
+ const userPermissions = strapiAdmin.useAuth('useI18n', (state)=>state.permissions);
202
+ const actions = React__namespace.useMemo(()=>{
203
+ const permissions = userPermissions.filter((permission)=>permission.subject === params.slug);
204
+ return permissions.reduce((acc, permission)=>{
205
+ const [actionShorthand] = permission.action.split('.').slice(-1);
206
+ return {
207
+ ...acc,
208
+ [`can${capitalize(actionShorthand)}`]: permission.properties?.locales ?? []
209
+ };
210
+ }, {
211
+ canCreate: [],
212
+ canRead: [],
213
+ canUpdate: [],
214
+ canDelete: [],
215
+ canPublish: []
216
+ });
217
+ }, [
218
+ params.slug,
219
+ userPermissions
220
+ ]);
221
+ // TODO: use specific hook to get schema only
222
+ const { schema } = strapiAdmin$1.unstable_useDocument({
223
+ // We can non-null assert these because below we skip the query if they are not present
224
+ collectionType: params.collectionType,
225
+ model: params.slug
226
+ }, {
227
+ skip: true
228
+ });
229
+ if (doesPluginOptionsHaveI18nLocalized(schema?.pluginOptions)) {
230
+ return {
231
+ hasI18n: schema.pluginOptions.i18n.localized,
232
+ ...actions
233
+ };
234
+ }
235
+ return {
236
+ hasI18n: false,
237
+ ...actions
238
+ };
239
+ };
240
+
241
+ const i18nApi = strapiAdmin.adminApi.enhanceEndpoints({
242
+ addTagTypes: [
243
+ 'Locale'
244
+ ]
245
+ });
246
+
247
+ const localesApi = i18nApi.injectEndpoints({
248
+ endpoints: (builder)=>({
249
+ createLocale: builder.mutation({
250
+ query: (data)=>({
251
+ url: '/i18n/locales',
252
+ method: 'POST',
253
+ data
254
+ }),
255
+ invalidatesTags: [
256
+ {
257
+ type: 'Locale',
258
+ id: 'LIST'
259
+ }
260
+ ]
261
+ }),
262
+ deleteLocale: builder.mutation({
263
+ query: (id)=>({
264
+ url: `/i18n/locales/${id}`,
265
+ method: 'DELETE'
266
+ }),
267
+ invalidatesTags: (result, error, id)=>[
268
+ {
269
+ type: 'Locale',
270
+ id
271
+ }
272
+ ]
273
+ }),
274
+ getLocales: builder.query({
275
+ query: ()=>'/i18n/locales',
276
+ providesTags: (res)=>[
277
+ {
278
+ type: 'Locale',
279
+ id: 'LIST'
280
+ },
281
+ ...Array.isArray(res) ? res.map((locale)=>({
282
+ type: 'Locale',
283
+ id: locale.id
284
+ })) : []
285
+ ]
286
+ }),
287
+ getDefaultLocales: builder.query({
288
+ query: ()=>'/i18n/iso-locales'
289
+ }),
290
+ updateLocale: builder.mutation({
291
+ query: ({ id, ...data })=>({
292
+ url: `/i18n/locales/${id}`,
293
+ method: 'PUT',
294
+ data
295
+ }),
296
+ invalidatesTags: (result, error, { id })=>[
297
+ {
298
+ type: 'Locale',
299
+ id
300
+ }
301
+ ]
302
+ })
303
+ })
304
+ });
305
+ const { useCreateLocaleMutation, useDeleteLocaleMutation, useGetLocalesQuery, useGetDefaultLocalesQuery, useUpdateLocaleMutation } = localesApi;
306
+
307
+ const relationsApi = i18nApi.injectEndpoints({
308
+ overrideExisting: true,
309
+ endpoints: (builder)=>({
310
+ getManyDraftRelationCount: builder.query({
311
+ query: ({ model, ...params })=>({
312
+ url: `/content-manager/collection-types/${model}/actions/countManyEntriesDraftRelations`,
313
+ method: 'GET',
314
+ config: {
315
+ params
316
+ }
317
+ }),
318
+ transformResponse: (response)=>response.data
319
+ })
320
+ })
321
+ });
322
+ const { useGetManyDraftRelationCountQuery } = relationsApi;
323
+
324
+ const cleanData = (data, schema, components)=>{
325
+ const cleanedData = removeFields(data, [
326
+ 'createdAt',
327
+ 'createdBy',
328
+ 'updatedAt',
329
+ 'updatedBy',
330
+ 'id',
331
+ 'documentId',
332
+ 'publishedAt',
333
+ 'strapi_stage',
334
+ 'strapi_assignee',
335
+ 'locale',
336
+ 'status'
337
+ ]);
338
+ const cleanedDataWithoutPasswordAndRelation = recursiveRemoveFieldTypes(cleanedData, schema, components, [
339
+ 'relation',
340
+ 'password'
341
+ ]);
342
+ return cleanedDataWithoutPasswordAndRelation;
343
+ };
344
+ const removeFields = (data, fields)=>{
345
+ return Object.keys(data).reduce((acc, current)=>{
346
+ if (fields.includes(current)) {
347
+ return acc;
348
+ }
349
+ acc[current] = data[current];
350
+ return acc;
351
+ }, {});
352
+ };
353
+ const recursiveRemoveFieldTypes = (data, schema, components, fields)=>{
354
+ return Object.keys(data).reduce((acc, current)=>{
355
+ const attribute = schema.attributes[current] ?? {
356
+ type: undefined
357
+ };
358
+ if (fields.includes(attribute.type)) {
359
+ return acc;
360
+ }
361
+ if (attribute.type === 'dynamiczone') {
362
+ acc[current] = data[current].map((componentValue, index)=>{
363
+ const { id: _, ...rest } = recursiveRemoveFieldTypes(componentValue, components[componentValue.__component], components, fields);
364
+ return {
365
+ ...rest,
366
+ __temp_key__: index + 1
367
+ };
368
+ });
369
+ } else if (attribute.type === 'component') {
370
+ const { repeatable, component } = attribute;
371
+ if (repeatable) {
372
+ acc[current] = (data[current] ?? []).map((compoData, index)=>{
373
+ const { id: _, ...rest } = recursiveRemoveFieldTypes(compoData, components[component], components, fields);
374
+ return {
375
+ ...rest,
376
+ __temp_key__: index + 1
377
+ };
378
+ });
379
+ } else {
380
+ const { id: _, ...rest } = recursiveRemoveFieldTypes(data[current] ?? {}, components[component], components, fields);
381
+ acc[current] = rest;
382
+ }
383
+ } else {
384
+ acc[current] = data[current];
385
+ }
386
+ return acc;
387
+ }, {});
388
+ };
389
+
390
+ const isErrorMessageDescriptor = (object)=>{
391
+ return typeof object === 'object' && object !== null && 'id' in object && 'defaultMessage' in object;
392
+ };
393
+ const EntryValidationText = ({ status = 'draft', validationErrors, action })=>{
394
+ const { formatMessage } = reactIntl.useIntl();
395
+ /**
396
+ * TODO: Should this be extracted an made into a factory to recursively get
397
+ * error messages??
398
+ */ const getErrorStr = (key, value)=>{
399
+ if (typeof value === 'string') {
400
+ return `${key}: ${value}`;
401
+ } else if (isErrorMessageDescriptor(value)) {
402
+ return `${key}: ${formatMessage(value)}`;
403
+ } else if (Array.isArray(value)) {
404
+ return value.map((v)=>getErrorStr(key, v)).join(' ');
405
+ } else if (typeof value === 'object' && !Array.isArray(value)) {
406
+ return Object.entries(value).map(([k, v])=>getErrorStr(k, v)).join(' ');
407
+ } else {
408
+ /**
409
+ * unlikely to happen, but we need to return something
410
+ */ return '';
411
+ }
412
+ };
413
+ if (validationErrors) {
414
+ const validationErrorsMessages = Object.entries(validationErrors).map(([key, value])=>{
415
+ return getErrorStr(key, value);
416
+ }).join(' ');
417
+ return /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
418
+ gap: 2,
419
+ children: [
420
+ /*#__PURE__*/ jsxRuntime.jsx(icons.CrossCircle, {
421
+ fill: "danger600"
422
+ }),
423
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Tooltip, {
424
+ label: validationErrorsMessages,
425
+ children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
426
+ maxWidth: '30rem',
427
+ textColor: "danger600",
428
+ variant: "omega",
429
+ fontWeight: "semiBold",
430
+ ellipsis: true,
431
+ children: validationErrorsMessages
432
+ })
433
+ })
434
+ ]
435
+ });
436
+ }
437
+ const getStatusMessage = ()=>{
438
+ if (action === 'bulk-publish') {
439
+ if (status === 'published') {
440
+ return {
441
+ icon: /*#__PURE__*/ jsxRuntime.jsx(icons.CheckCircle, {
442
+ fill: "success600"
443
+ }),
444
+ text: formatMessage({
445
+ id: 'content-manager.bulk-publish.already-published',
446
+ defaultMessage: 'Already Published'
447
+ }),
448
+ textColor: 'success600',
449
+ fontWeight: 'bold'
450
+ };
451
+ } else if (status === 'modified') {
452
+ return {
453
+ icon: /*#__PURE__*/ jsxRuntime.jsx(icons.ArrowsCounterClockwise, {
454
+ fill: "alternative600"
455
+ }),
456
+ text: formatMessage({
457
+ id: 'app.utils.ready-to-publish-changes',
458
+ defaultMessage: 'Ready to publish changes'
459
+ })
460
+ };
461
+ } else {
462
+ return {
463
+ icon: /*#__PURE__*/ jsxRuntime.jsx(icons.CheckCircle, {
464
+ fill: "success600"
465
+ }),
466
+ text: formatMessage({
467
+ id: 'app.utils.ready-to-publish',
468
+ defaultMessage: 'Ready to publish'
469
+ })
470
+ };
471
+ }
472
+ } else {
473
+ if (status === 'draft') {
474
+ return {
475
+ icon: /*#__PURE__*/ jsxRuntime.jsx(icons.CheckCircle, {
476
+ fill: "success600"
477
+ }),
478
+ text: formatMessage({
479
+ id: 'content-manager.bulk-unpublish.already-unpublished',
480
+ defaultMessage: 'Already Unpublished'
481
+ }),
482
+ textColor: 'success600',
483
+ fontWeight: 'bold'
484
+ };
485
+ } else {
486
+ return {
487
+ icon: /*#__PURE__*/ jsxRuntime.jsx(icons.CheckCircle, {
488
+ fill: "success600"
489
+ }),
490
+ text: formatMessage({
491
+ id: 'app.utils.ready-to-unpublish-changes',
492
+ defaultMessage: 'Ready to unpublish'
493
+ }),
494
+ textColor: 'success600',
495
+ fontWeight: 'bold'
496
+ };
497
+ }
498
+ }
499
+ };
500
+ const { icon, text, textColor = 'success600', fontWeight = 'normal' } = getStatusMessage();
501
+ return /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
502
+ gap: 2,
503
+ children: [
504
+ icon,
505
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
506
+ textColor: textColor,
507
+ fontWeight: fontWeight,
508
+ children: text
509
+ })
510
+ ]
511
+ });
512
+ };
513
+ /* -------------------------------------------------------------------------------------------------
514
+ * BoldChunk
515
+ * -----------------------------------------------------------------------------------------------*/ const BoldChunk = (chunks)=>/*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
516
+ fontWeight: "bold",
517
+ children: chunks
518
+ });
519
+ const BulkLocaleActionModal = ({ headers, rows, localesMetadata, validationErrors = {}, action })=>{
520
+ const { formatMessage } = reactIntl.useIntl();
521
+ const selectedRows = strapiAdmin.useTable('BulkLocaleActionModal', (state)=>state.selectedRows);
522
+ const getFormattedCountMessage = ()=>{
523
+ const currentStatusByLocale = rows.reduce((acc, { locale, status })=>{
524
+ acc[locale] = status;
525
+ return acc;
526
+ }, {});
527
+ const localesWithErrors = Object.keys(validationErrors);
528
+ const publishedCount = selectedRows.filter(({ locale })=>currentStatusByLocale[locale] === 'published').length;
529
+ const draftCount = selectedRows.filter(({ locale })=>(currentStatusByLocale[locale] === 'draft' || currentStatusByLocale[locale] === 'modified') && !localesWithErrors.includes(locale)).length;
530
+ const withErrorsCount = localesWithErrors.length;
531
+ const messageId = action === 'bulk-publish' ? 'content-manager.containers.list.selectedEntriesModal.selectedCount.publish' : 'content-manager.containers.list.selectedEntriesModal.selectedCount.unpublish';
532
+ 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.';
533
+ return formatMessage({
534
+ id: messageId,
535
+ defaultMessage
536
+ }, {
537
+ withErrorsCount,
538
+ draftCount,
539
+ publishedCount,
540
+ b: BoldChunk
541
+ });
542
+ };
543
+ return /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Modal.Body, {
544
+ children: [
545
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
546
+ children: getFormattedCountMessage()
547
+ }),
548
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
549
+ marginTop: 5,
550
+ children: /*#__PURE__*/ jsxRuntime.jsxs(strapiAdmin.Table.Content, {
551
+ children: [
552
+ /*#__PURE__*/ jsxRuntime.jsxs(strapiAdmin.Table.Head, {
553
+ children: [
554
+ /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Table.HeaderCheckboxCell, {}),
555
+ headers.map((head)=>/*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Table.HeaderCell, {
556
+ ...head
557
+ }, head.name))
558
+ ]
559
+ }),
560
+ /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Table.Body, {
561
+ children: rows.map(({ locale, status }, index)=>{
562
+ const error = validationErrors?.[locale] ?? null;
563
+ const statusVariant = status === 'draft' ? 'primary' : status === 'published' ? 'success' : 'alternative';
564
+ return /*#__PURE__*/ jsxRuntime.jsxs(strapiAdmin.Table.Row, {
565
+ children: [
566
+ /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Table.CheckboxCell, {
567
+ id: locale,
568
+ "aria-label": `Select ${locale}`
569
+ }),
570
+ /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Table.Cell, {
571
+ children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
572
+ variant: "sigma",
573
+ textColor: "neutral600",
574
+ children: Array.isArray(localesMetadata) ? localesMetadata.find((localeEntry)=>localeEntry.code === locale)?.name : locale
575
+ })
576
+ }),
577
+ /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Table.Cell, {
578
+ children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
579
+ display: "flex",
580
+ children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Status, {
581
+ display: "flex",
582
+ paddingLeft: "6px",
583
+ paddingRight: "6px",
584
+ paddingTop: "2px",
585
+ paddingBottom: "2px",
586
+ size: 'S',
587
+ variant: statusVariant,
588
+ children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
589
+ tag: "span",
590
+ variant: "pi",
591
+ fontWeight: "bold",
592
+ children: capitalize(status)
593
+ })
594
+ })
595
+ })
596
+ }),
597
+ /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Table.Cell, {
598
+ children: /*#__PURE__*/ jsxRuntime.jsx(EntryValidationText, {
599
+ validationErrors: error,
600
+ status: status,
601
+ action: action
602
+ })
603
+ }),
604
+ /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Table.Cell, {
605
+ children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.IconButton, {
606
+ tag: reactRouterDom.Link,
607
+ to: {
608
+ search: qs.stringify({
609
+ plugins: {
610
+ i18n: {
611
+ locale
612
+ }
613
+ }
614
+ })
615
+ },
616
+ label: formatMessage({
617
+ id: getTranslation('Settings.list.actions.edit'),
618
+ defaultMessage: 'Edit {name} locale'
619
+ }, {
620
+ name: locale
621
+ }),
622
+ variant: "ghost",
623
+ children: /*#__PURE__*/ jsxRuntime.jsx(icons.Pencil, {})
624
+ })
625
+ })
626
+ ]
627
+ }, index);
628
+ })
629
+ })
630
+ ]
631
+ })
632
+ })
633
+ ]
634
+ });
635
+ };
636
+
637
+ const statusVariants = {
638
+ draft: 'secondary',
639
+ published: 'success',
640
+ modified: 'alternative'
641
+ };
642
+ const LocaleOption = ({ isDraftAndPublishEnabled, locale, status, entryExists })=>{
643
+ const { formatMessage } = reactIntl.useIntl();
644
+ if (!entryExists) {
645
+ return formatMessage({
646
+ id: getTranslation('CMEditViewLocalePicker.locale.create'),
647
+ defaultMessage: 'Create <bold>{locale}</bold> locale'
648
+ }, {
649
+ bold: (locale)=>/*#__PURE__*/ jsxRuntime.jsx("b", {
650
+ children: locale
651
+ }),
652
+ locale: locale.name
653
+ });
654
+ }
655
+ return /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
656
+ width: "100%",
657
+ gap: 1,
658
+ justifyContent: "space-between",
659
+ children: [
660
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
661
+ children: locale.name
662
+ }),
663
+ isDraftAndPublishEnabled ? /*#__PURE__*/ jsxRuntime.jsx(designSystem.Status, {
664
+ display: "flex",
665
+ paddingLeft: "6px",
666
+ paddingRight: "6px",
667
+ paddingTop: "2px",
668
+ paddingBottom: "2px",
669
+ size: "S",
670
+ variant: statusVariants[status],
671
+ children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
672
+ tag: "span",
673
+ variant: "pi",
674
+ fontWeight: "bold",
675
+ children: capitalize(status)
676
+ })
677
+ }) : null
678
+ ]
679
+ });
680
+ };
681
+ const LocalePickerAction = ({ document, meta, model, collectionType, documentId })=>{
682
+ const { formatMessage } = reactIntl.useIntl();
683
+ const [{ query }, setQuery] = strapiAdmin.useQueryParams();
684
+ const { hasI18n, canCreate, canRead } = useI18n();
685
+ const { data: locales = [] } = useGetLocalesQuery();
686
+ const currentDesiredLocale = query.plugins?.i18n?.locale;
687
+ const { schema } = strapiAdmin$1.unstable_useDocument({
688
+ model,
689
+ collectionType,
690
+ documentId,
691
+ params: {
692
+ locale: currentDesiredLocale
693
+ }
694
+ });
695
+ const handleSelect = React__namespace.useCallback((value)=>{
696
+ setQuery({
697
+ plugins: {
698
+ ...query.plugins,
699
+ i18n: {
700
+ locale: value
701
+ }
702
+ }
703
+ });
704
+ }, [
705
+ query.plugins,
706
+ setQuery
707
+ ]);
708
+ React__namespace.useEffect(()=>{
709
+ if (!Array.isArray(locales) || !hasI18n) {
710
+ return;
711
+ }
712
+ /**
713
+ * Handle the case where the current locale query param doesn't exist
714
+ * in the list of available locales, so we redirect to the default locale.
715
+ */ const doesLocaleExist = locales.find((loc)=>loc.code === currentDesiredLocale);
716
+ const defaultLocale = locales.find((locale)=>locale.isDefault);
717
+ if (!doesLocaleExist && defaultLocale?.code) {
718
+ handleSelect(defaultLocale.code);
719
+ }
720
+ }, [
721
+ handleSelect,
722
+ hasI18n,
723
+ locales,
724
+ currentDesiredLocale
725
+ ]);
726
+ const currentLocale = Array.isArray(locales) ? locales.find((locale)=>locale.code === currentDesiredLocale) : undefined;
727
+ const allCurrentLocales = [
728
+ {
729
+ status: getDocumentStatus(document, meta),
730
+ locale: currentLocale?.code
731
+ },
732
+ ...document?.localizations ?? []
733
+ ];
734
+ if (!hasI18n || !Array.isArray(locales) || locales.length === 0) {
735
+ return null;
736
+ }
737
+ const displayedLocales = locales.filter((locale)=>{
738
+ /**
739
+ * If you can read we allow you to see the locale exists
740
+ * otherwise the locale is hidden.
741
+ */ return canRead.includes(locale.code);
742
+ });
743
+ return {
744
+ label: formatMessage({
745
+ id: getTranslation('Settings.locales.modal.locales.label'),
746
+ defaultMessage: 'Locales'
747
+ }),
748
+ options: displayedLocales.map((locale)=>{
749
+ const entryWithLocaleExists = allCurrentLocales.some((doc)=>doc.locale === locale.code);
750
+ const currentLocaleDoc = allCurrentLocales.find((doc)=>'locale' in doc ? doc.locale === locale.code : false);
751
+ const permissionsToCheck = currentLocaleDoc ? canRead : canCreate;
752
+ return {
753
+ disabled: !permissionsToCheck.includes(locale.code),
754
+ value: locale.code,
755
+ label: /*#__PURE__*/ jsxRuntime.jsx(LocaleOption, {
756
+ isDraftAndPublishEnabled: !!schema?.options?.draftAndPublish,
757
+ locale: locale,
758
+ status: currentLocaleDoc?.status,
759
+ entryExists: entryWithLocaleExists
760
+ }),
761
+ startIcon: !entryWithLocaleExists ? /*#__PURE__*/ jsxRuntime.jsx(icons.Plus, {}) : null
762
+ };
763
+ }),
764
+ customizeContent: ()=>currentLocale?.name,
765
+ onSelect: handleSelect,
766
+ value: currentLocale
767
+ };
768
+ };
769
+ const getDocumentStatus = (document, meta)=>{
770
+ const docStatus = document?.status;
771
+ const statuses = meta?.availableStatus ?? [];
772
+ /**
773
+ * Creating an entry
774
+ */ if (!docStatus) {
775
+ return 'draft';
776
+ }
777
+ /**
778
+ * We're viewing a draft, but the document could have a published version
779
+ */ if (docStatus === 'draft' && statuses.find((doc)=>doc.publishedAt !== null)) {
780
+ return 'published';
781
+ }
782
+ return docStatus;
783
+ };
784
+ /* -------------------------------------------------------------------------------------------------
785
+ * FillFromAnotherLocaleAction
786
+ * -----------------------------------------------------------------------------------------------*/ const FillFromAnotherLocaleAction = ({ documentId, meta, model, collectionType })=>{
787
+ const { formatMessage } = reactIntl.useIntl();
788
+ const [{ query }] = strapiAdmin.useQueryParams();
789
+ const { hasI18n } = useI18n();
790
+ const currentDesiredLocale = query.plugins?.i18n?.locale;
791
+ const [localeSelected, setLocaleSelected] = React__namespace.useState(null);
792
+ const setValues = strapiAdmin.useForm('FillFromAnotherLocale', (state)=>state.setValues);
793
+ const { getDocument } = strapiAdmin$1.unstable_useDocumentActions();
794
+ const { schema, components } = strapiAdmin$1.unstable_useDocument({
795
+ model,
796
+ documentId,
797
+ collectionType,
798
+ params: {
799
+ locale: currentDesiredLocale
800
+ }
801
+ });
802
+ const { data: locales = [] } = useGetLocalesQuery();
803
+ const availableLocales = Array.isArray(locales) ? locales.filter((locale)=>meta?.availableLocales.some((l)=>l.locale === locale.code)) : [];
804
+ const fillFromLocale = (onClose)=>async ()=>{
805
+ const response = await getDocument({
806
+ collectionType,
807
+ model,
808
+ documentId,
809
+ params: {
810
+ locale: localeSelected
811
+ }
812
+ });
813
+ if (!response || !schema) {
814
+ return;
815
+ }
816
+ const { data } = response;
817
+ const cleanedData = cleanData(data, schema, components);
818
+ setValues(cleanedData);
819
+ onClose();
820
+ };
821
+ if (!hasI18n) {
822
+ return null;
823
+ }
824
+ return {
825
+ type: 'icon',
826
+ icon: /*#__PURE__*/ jsxRuntime.jsx(icons.Download, {}),
827
+ disabled: availableLocales.length === 0,
828
+ label: formatMessage({
829
+ id: getTranslation('CMEditViewCopyLocale.copy-text'),
830
+ defaultMessage: 'Fill in from another locale'
831
+ }),
832
+ dialog: {
833
+ type: 'dialog',
834
+ title: formatMessage({
835
+ id: getTranslation('CMEditViewCopyLocale.dialog.title'),
836
+ defaultMessage: 'Confirmation'
837
+ }),
838
+ content: ({ onClose })=>/*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
839
+ children: [
840
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Dialog.Body, {
841
+ children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
842
+ direction: "column",
843
+ gap: 3,
844
+ children: [
845
+ /*#__PURE__*/ jsxRuntime.jsx(icons.WarningCircle, {
846
+ width: "24px",
847
+ height: "24px",
848
+ fill: "danger600"
849
+ }),
850
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
851
+ textAlign: "center",
852
+ children: formatMessage({
853
+ id: getTranslation('CMEditViewCopyLocale.dialog.body'),
854
+ defaultMessage: 'Your current content will be erased and filled by the content of the selected locale:'
855
+ })
856
+ }),
857
+ /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Field.Root, {
858
+ width: "100%",
859
+ children: [
860
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Field.Label, {
861
+ children: formatMessage({
862
+ id: getTranslation('CMEditViewCopyLocale.dialog.field.label'),
863
+ defaultMessage: 'Locale'
864
+ })
865
+ }),
866
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.SingleSelect, {
867
+ value: localeSelected,
868
+ placeholder: formatMessage({
869
+ id: getTranslation('CMEditViewCopyLocale.dialog.field.placeholder'),
870
+ defaultMessage: 'Select one locale...'
871
+ }),
872
+ // @ts-expect-error – the DS will handle numbers, but we're not allowing the API.
873
+ onChange: (value)=>setLocaleSelected(value),
874
+ children: availableLocales.map((locale)=>/*#__PURE__*/ jsxRuntime.jsx(designSystem.SingleSelectOption, {
875
+ value: locale.code,
876
+ children: locale.name
877
+ }, locale.code))
878
+ })
879
+ ]
880
+ })
881
+ ]
882
+ })
883
+ }),
884
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Dialog.Footer, {
885
+ children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
886
+ gap: 2,
887
+ width: "100%",
888
+ children: [
889
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Button, {
890
+ flex: "auto",
891
+ variant: "tertiary",
892
+ onClick: onClose,
893
+ children: formatMessage({
894
+ id: getTranslation('CMEditViewCopyLocale.cancel-text'),
895
+ defaultMessage: 'No, cancel'
896
+ })
897
+ }),
898
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Button, {
899
+ flex: "auto",
900
+ variant: "success",
901
+ onClick: fillFromLocale(onClose),
902
+ children: formatMessage({
903
+ id: getTranslation('CMEditViewCopyLocale.submit-text'),
904
+ defaultMessage: 'Yes, fill in'
905
+ })
906
+ })
907
+ ]
908
+ })
909
+ })
910
+ ]
911
+ })
912
+ }
913
+ };
914
+ };
915
+ /* -------------------------------------------------------------------------------------------------
916
+ * DeleteLocaleAction
917
+ * -----------------------------------------------------------------------------------------------*/ const DeleteLocaleAction = ({ document, documentId, model, collectionType })=>{
918
+ const { formatMessage } = reactIntl.useIntl();
919
+ const navigate = reactRouterDom.useNavigate();
920
+ const { toggleNotification } = strapiAdmin.useNotification();
921
+ const { delete: deleteAction } = strapiAdmin$1.unstable_useDocumentActions();
922
+ const { hasI18n, canDelete } = useI18n();
923
+ // Get the current locale object, using the URL instead of document so it works while creating
924
+ const [{ query }] = strapiAdmin.useQueryParams();
925
+ const { data: locales = [] } = useGetLocalesQuery();
926
+ const currentDesiredLocale = query.plugins?.i18n?.locale;
927
+ const locale = !('error' in locales) && locales.find((loc)=>loc.code === currentDesiredLocale);
928
+ if (!hasI18n) {
929
+ return null;
930
+ }
931
+ return {
932
+ disabled: document?.locale && !canDelete.includes(document.locale) || !document || !document.id,
933
+ position: [
934
+ 'header',
935
+ 'table-row'
936
+ ],
937
+ label: formatMessage({
938
+ id: getTranslation('actions.delete.label'),
939
+ defaultMessage: 'Delete entry ({locale})'
940
+ }, {
941
+ locale: locale && locale.name
942
+ }),
943
+ icon: /*#__PURE__*/ jsxRuntime.jsx(StyledTrash, {}),
944
+ variant: 'danger',
945
+ dialog: {
946
+ type: 'dialog',
947
+ title: formatMessage({
948
+ id: getTranslation('actions.delete.dialog.title'),
949
+ defaultMessage: 'Confirmation'
950
+ }),
951
+ content: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
952
+ direction: "column",
953
+ gap: 2,
954
+ children: [
955
+ /*#__PURE__*/ jsxRuntime.jsx(icons.WarningCircle, {
956
+ width: "24px",
957
+ height: "24px",
958
+ fill: "danger600"
959
+ }),
960
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
961
+ tag: "p",
962
+ variant: "omega",
963
+ textAlign: "center",
964
+ children: formatMessage({
965
+ id: getTranslation('actions.delete.dialog.body'),
966
+ defaultMessage: 'Are you sure?'
967
+ })
968
+ })
969
+ ]
970
+ }),
971
+ onConfirm: async ()=>{
972
+ const unableToDelete = // We are unable to delete a collection type without a document ID
973
+ // & unable to delete generally if there is no document locale
974
+ collectionType !== 'single-types' && !documentId || !document?.locale;
975
+ if (unableToDelete) {
976
+ console.error("You're trying to delete a document without an id or locale, this is likely a bug with Strapi. Please open an issue.");
977
+ toggleNotification({
978
+ message: formatMessage({
979
+ id: getTranslation('actions.delete.error'),
980
+ defaultMessage: 'An error occurred while trying to delete the document locale.'
981
+ }),
982
+ type: 'danger'
983
+ });
984
+ return;
985
+ }
986
+ const res = await deleteAction({
987
+ documentId,
988
+ model,
989
+ collectionType,
990
+ params: {
991
+ locale: document.locale
992
+ }
993
+ });
994
+ if (!('error' in res)) {
995
+ navigate({
996
+ pathname: `../${collectionType}/${model}`
997
+ }, {
998
+ replace: true
999
+ });
1000
+ }
1001
+ }
1002
+ }
1003
+ };
1004
+ };
1005
+ /* -------------------------------------------------------------------------------------------------
1006
+ * BulkLocaleAction
1007
+ *
1008
+ * This component is used to handle bulk publish and unpublish actions on locales.
1009
+ * -----------------------------------------------------------------------------------------------*/ const BulkLocaleAction = ({ document, documentId, model, collectionType, action })=>{
1010
+ const locale = document?.locale ?? null;
1011
+ const [{ query: query$1 }] = strapiAdmin.useQueryParams();
1012
+ const params = React__namespace.useMemo(()=>strapiAdmin$1.buildValidParams(query$1), [
1013
+ query$1
1014
+ ]);
1015
+ const isOnPublishedTab = query$1.status === 'published';
1016
+ const { formatMessage } = reactIntl.useIntl();
1017
+ const { hasI18n, canPublish } = useI18n();
1018
+ const { toggleNotification } = strapiAdmin.useNotification();
1019
+ const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
1020
+ const [selectedRows, setSelectedRows] = React__namespace.useState([]);
1021
+ const [isDraftRelationConfirmationOpen, setIsDraftRelationConfirmationOpen] = React__namespace.useState(false);
1022
+ const { publishMany: publishManyAction, unpublishMany: unpublishManyAction } = strapiAdmin$1.unstable_useDocumentActions();
1023
+ const { schema, validate } = strapiAdmin$1.unstable_useDocument({
1024
+ model,
1025
+ collectionType,
1026
+ documentId,
1027
+ params: {
1028
+ locale
1029
+ }
1030
+ }, {
1031
+ // No need to fetch the document, the data is already available in the `document` prop
1032
+ skip: true
1033
+ });
1034
+ const { data: localesMetadata = [] } = useGetLocalesQuery(hasI18n ? undefined : query.skipToken);
1035
+ const headers = [
1036
+ {
1037
+ label: formatMessage({
1038
+ id: 'global.name',
1039
+ defaultMessage: 'Name'
1040
+ }),
1041
+ name: 'name'
1042
+ },
1043
+ {
1044
+ label: formatMessage({
1045
+ id: getTranslation('CMEditViewBulkLocale.status'),
1046
+ defaultMessage: 'Status'
1047
+ }),
1048
+ name: 'status'
1049
+ },
1050
+ {
1051
+ label: formatMessage({
1052
+ id: getTranslation('CMEditViewBulkLocale.publication-status'),
1053
+ defaultMessage: 'Publication Status'
1054
+ }),
1055
+ name: 'publication-status'
1056
+ }
1057
+ ];
1058
+ // Extract the rows for the bulk locale publish modal and any validation
1059
+ // errors per locale
1060
+ const [rows, validationErrors] = React__namespace.useMemo(()=>{
1061
+ if (!document) {
1062
+ return [
1063
+ [],
1064
+ {}
1065
+ ];
1066
+ }
1067
+ const localizations = document.localizations ?? [];
1068
+ // Build the rows for the bulk locale publish modal by combining the current
1069
+ // document with all the available locales from the document meta
1070
+ const locales = localizations.map((doc)=>{
1071
+ const { locale, status } = doc;
1072
+ return {
1073
+ locale,
1074
+ status
1075
+ };
1076
+ });
1077
+ // Add the current document locale
1078
+ locales.unshift({
1079
+ locale: document.locale,
1080
+ status: document.status
1081
+ });
1082
+ // Build the validation errors for each locale.
1083
+ const allDocuments = [
1084
+ document,
1085
+ ...localizations
1086
+ ];
1087
+ const errors = allDocuments.reduce((errs, document)=>{
1088
+ if (!document) {
1089
+ return errs;
1090
+ }
1091
+ // Validate each locale entry via the useDocument validate function and store any errors in a dictionary
1092
+ const validation = validate(document);
1093
+ if (validation !== null) {
1094
+ errs[document.locale] = validation;
1095
+ }
1096
+ return errs;
1097
+ }, {});
1098
+ return [
1099
+ locales,
1100
+ errors
1101
+ ];
1102
+ }, [
1103
+ document,
1104
+ validate
1105
+ ]);
1106
+ const isBulkPublish = action === 'bulk-publish';
1107
+ const localesForAction = selectedRows.reduce((acc, selectedRow)=>{
1108
+ const isValidLocale = // Validation errors are irrelevant if we are trying to unpublish
1109
+ !isBulkPublish || !Object.keys(validationErrors).includes(selectedRow.locale);
1110
+ const shouldAddLocale = isBulkPublish ? selectedRow.status !== 'published' && isValidLocale : selectedRow.status !== 'draft' && isValidLocale;
1111
+ if (shouldAddLocale) {
1112
+ acc.push(selectedRow.locale);
1113
+ }
1114
+ return acc;
1115
+ }, []);
1116
+ // TODO skipping this for now as there is a bug with the draft relation count that will be worked on separately
1117
+ // see https://www.notion.so/strapi/Count-draft-relations-56901b492efb45ab90d42fe975b32bd8?pvs=4
1118
+ const enableDraftRelationsCount = false;
1119
+ const { data: draftRelationsCount = 0, isLoading: isDraftRelationsLoading, error: isDraftRelationsError } = useGetManyDraftRelationCountQuery({
1120
+ model,
1121
+ documentIds: [
1122
+ documentId
1123
+ ],
1124
+ locale: localesForAction
1125
+ }, {
1126
+ skip: !enableDraftRelationsCount
1127
+ });
1128
+ React__namespace.useEffect(()=>{
1129
+ if (isDraftRelationsError) {
1130
+ toggleNotification({
1131
+ type: 'danger',
1132
+ message: formatAPIError(isDraftRelationsError)
1133
+ });
1134
+ }
1135
+ }, [
1136
+ isDraftRelationsError,
1137
+ toggleNotification,
1138
+ formatAPIError
1139
+ ]);
1140
+ if (!schema?.options?.draftAndPublish) {
1141
+ return null;
1142
+ }
1143
+ if (!hasI18n) {
1144
+ return null;
1145
+ }
1146
+ if (!documentId) {
1147
+ return null;
1148
+ }
1149
+ // This document action can be enabled given that draft and publish and i18n are
1150
+ // enabled and we can publish the current locale.
1151
+ const publish = async ()=>{
1152
+ await publishManyAction({
1153
+ model,
1154
+ documentIds: [
1155
+ documentId
1156
+ ],
1157
+ params: {
1158
+ ...params,
1159
+ locale: localesForAction
1160
+ }
1161
+ });
1162
+ setSelectedRows([]);
1163
+ };
1164
+ const unpublish = async ()=>{
1165
+ await unpublishManyAction({
1166
+ model,
1167
+ documentIds: [
1168
+ documentId
1169
+ ],
1170
+ params: {
1171
+ ...params,
1172
+ locale: localesForAction
1173
+ }
1174
+ });
1175
+ setSelectedRows([]);
1176
+ };
1177
+ const handleAction = async ()=>{
1178
+ if (draftRelationsCount > 0) {
1179
+ setIsDraftRelationConfirmationOpen(true);
1180
+ } else if (isBulkPublish) {
1181
+ await publish();
1182
+ } else {
1183
+ await unpublish();
1184
+ }
1185
+ };
1186
+ if (isDraftRelationConfirmationOpen) {
1187
+ return {
1188
+ label: formatMessage({
1189
+ id: 'app.components.ConfirmDialog.title',
1190
+ defaultMessage: 'Confirmation'
1191
+ }),
1192
+ variant: 'danger',
1193
+ dialog: {
1194
+ onCancel: ()=>{
1195
+ setIsDraftRelationConfirmationOpen(false);
1196
+ },
1197
+ onConfirm: async ()=>{
1198
+ await publish();
1199
+ setIsDraftRelationConfirmationOpen(false);
1200
+ },
1201
+ type: 'dialog',
1202
+ title: formatMessage({
1203
+ id: getTranslation('actions.publish.dialog.title'),
1204
+ defaultMessage: 'Confirmation'
1205
+ }),
1206
+ content: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
1207
+ direction: "column",
1208
+ alignItems: "center",
1209
+ gap: 2,
1210
+ children: [
1211
+ /*#__PURE__*/ jsxRuntime.jsx(icons.WarningCircle, {
1212
+ width: "2.4rem",
1213
+ height: "2.4rem",
1214
+ fill: "danger600"
1215
+ }),
1216
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
1217
+ textAlign: "center",
1218
+ children: formatMessage({
1219
+ id: getTranslation('CMEditViewBulkLocale.draft-relation-warning'),
1220
+ defaultMessage: 'Some locales are related to draft entries. Publishing them could leave broken links in your app.'
1221
+ })
1222
+ }),
1223
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
1224
+ textAlign: "center",
1225
+ children: formatMessage({
1226
+ id: getTranslation('CMEditViewBulkLocale.continue-confirmation'),
1227
+ defaultMessage: 'Are you sure you want to continue?'
1228
+ })
1229
+ })
1230
+ ]
1231
+ })
1232
+ }
1233
+ };
1234
+ }
1235
+ const hasPermission = selectedRows.map(({ locale })=>locale).every((locale)=>canPublish.includes(locale));
1236
+ return {
1237
+ label: formatMessage({
1238
+ id: getTranslation(`CMEditViewBulkLocale.${isBulkPublish ? 'publish' : 'unpublish'}-title`),
1239
+ defaultMessage: `${isBulkPublish ? 'Publish' : 'Unpublish'} Multiple Locales`
1240
+ }),
1241
+ variant: isBulkPublish ? 'secondary' : 'danger',
1242
+ icon: isBulkPublish ? /*#__PURE__*/ jsxRuntime.jsx(icons.ListPlus, {}) : /*#__PURE__*/ jsxRuntime.jsx(icons.Cross, {}),
1243
+ disabled: isOnPublishedTab || canPublish.length === 0,
1244
+ position: [
1245
+ 'panel'
1246
+ ],
1247
+ dialog: {
1248
+ type: 'modal',
1249
+ title: formatMessage({
1250
+ id: getTranslation(`CMEditViewBulkLocale.${isBulkPublish ? 'publish' : 'unpublish'}-title`),
1251
+ defaultMessage: `${isBulkPublish ? 'Publish' : 'Unpublish'} Multiple Locales`
1252
+ }),
1253
+ content: ()=>{
1254
+ return /*#__PURE__*/ jsxRuntime.jsx(strapiAdmin.Table.Root, {
1255
+ headers: headers,
1256
+ rows: rows.map((row)=>({
1257
+ ...row,
1258
+ id: row.locale
1259
+ })),
1260
+ selectedRows: selectedRows,
1261
+ onSelectedRowsChange: (tableSelectedRows)=>setSelectedRows(tableSelectedRows),
1262
+ children: /*#__PURE__*/ jsxRuntime.jsx(BulkLocaleActionModal, {
1263
+ validationErrors: validationErrors,
1264
+ headers: headers,
1265
+ rows: rows,
1266
+ localesMetadata: localesMetadata,
1267
+ action: action ?? 'bulk-publish'
1268
+ })
1269
+ });
1270
+ },
1271
+ footer: ()=>/*#__PURE__*/ jsxRuntime.jsx(designSystem.Modal.Footer, {
1272
+ justifyContent: "flex-end",
1273
+ children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Button, {
1274
+ loading: isDraftRelationsLoading,
1275
+ disabled: !hasPermission || localesForAction.length === 0,
1276
+ variant: "default",
1277
+ onClick: handleAction,
1278
+ children: formatMessage({
1279
+ id: isBulkPublish ? 'app.utils.publish' : 'app.utils.unpublish',
1280
+ defaultMessage: isBulkPublish ? 'Publish' : 'Unpublish'
1281
+ })
1282
+ })
1283
+ })
1284
+ }
1285
+ };
1286
+ };
1287
+ /* -------------------------------------------------------------------------------------------------
1288
+ * BulkLocalePublishAction
1289
+ * -----------------------------------------------------------------------------------------------*/ const BulkLocalePublishAction = (props)=>{
1290
+ return BulkLocaleAction({
1291
+ action: 'bulk-publish',
1292
+ ...props
1293
+ });
1294
+ };
1295
+ /* -------------------------------------------------------------------------------------------------
1296
+ * BulkLocaleUnpublishAction
1297
+ * -----------------------------------------------------------------------------------------------*/ const BulkLocaleUnpublishAction = (props)=>{
1298
+ return BulkLocaleAction({
1299
+ action: 'bulk-unpublish',
1300
+ ...props
1301
+ });
1302
+ };
1303
+ /**
1304
+ * Because the icon system is completely broken, we have to do
1305
+ * this to remove the fill from the cog.
1306
+ */ const StyledTrash = styledComponents.styled(icons.Trash)`
1307
+ path {
1308
+ fill: currentColor;
1309
+ }
1310
+ `;
1311
+
1312
+ const Emphasis = (chunks)=>{
1313
+ return /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
1314
+ fontWeight: "semiBold",
1315
+ textColor: "danger500",
1316
+ children: chunks
1317
+ });
1318
+ };
1319
+ const DeleteModalAdditionalInfo = ()=>{
1320
+ const { hasI18n } = useI18n();
1321
+ const { formatMessage } = reactIntl.useIntl();
1322
+ if (!hasI18n) {
1323
+ return null;
1324
+ }
1325
+ return /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
1326
+ textColor: "danger500",
1327
+ children: formatMessage({
1328
+ id: getTranslation('Settings.list.actions.deleteAdditionalInfos'),
1329
+ defaultMessage: 'This will delete the active locale versions <em>(from Internationalization)</em>'
1330
+ }, {
1331
+ em: Emphasis
1332
+ })
1333
+ });
1334
+ };
1335
+ const PublishModalAdditionalInfo = ()=>{
1336
+ const { hasI18n } = useI18n();
1337
+ const { formatMessage } = reactIntl.useIntl();
1338
+ if (!hasI18n) {
1339
+ return null;
1340
+ }
1341
+ return /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
1342
+ textColor: "danger500",
1343
+ children: formatMessage({
1344
+ id: getTranslation('Settings.list.actions.publishAdditionalInfos'),
1345
+ defaultMessage: 'This will publish the active locale versions <em>(from Internationalization)</em>'
1346
+ }, {
1347
+ em: Emphasis
1348
+ })
1349
+ });
1350
+ };
1351
+ const UnpublishModalAdditionalInfo = ()=>{
1352
+ const { hasI18n } = useI18n();
1353
+ const { formatMessage } = reactIntl.useIntl();
1354
+ if (!hasI18n) {
1355
+ return null;
1356
+ }
1357
+ return /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
1358
+ textColor: "danger500",
1359
+ children: formatMessage({
1360
+ id: getTranslation('Settings.list.actions.unpublishAdditionalInfos'),
1361
+ defaultMessage: 'This will unpublish the active locale versions <em>(from Internationalization)</em>'
1362
+ }, {
1363
+ em: Emphasis
1364
+ })
1365
+ });
1366
+ };
1367
+
1368
+ const LocalePicker = ()=>{
1369
+ const { formatMessage } = reactIntl.useIntl();
1370
+ const [{ query }, setQuery] = strapiAdmin.useQueryParams();
1371
+ const { hasI18n, canRead, canCreate } = useI18n();
1372
+ const { data: locales = [] } = useGetLocalesQuery(undefined, {
1373
+ skip: !hasI18n
1374
+ });
1375
+ const handleChange = React__namespace.useCallback((code, replace = false)=>{
1376
+ setQuery({
1377
+ page: 1,
1378
+ plugins: {
1379
+ ...query.plugins,
1380
+ i18n: {
1381
+ locale: code
1382
+ }
1383
+ }
1384
+ }, 'push', replace);
1385
+ }, [
1386
+ query.plugins,
1387
+ setQuery
1388
+ ]);
1389
+ React__namespace.useEffect(()=>{
1390
+ if (!Array.isArray(locales) || !hasI18n) {
1391
+ return;
1392
+ }
1393
+ /**
1394
+ * Handle the case where the current locale query param doesn't exist
1395
+ * in the list of available locales, so we redirect to the default locale.
1396
+ */ const currentDesiredLocale = query.plugins?.i18n?.locale;
1397
+ const doesLocaleExist = locales.find((loc)=>loc.code === currentDesiredLocale);
1398
+ const defaultLocale = locales.find((locale)=>locale.isDefault);
1399
+ if (!doesLocaleExist && defaultLocale?.code) {
1400
+ handleChange(defaultLocale.code, true);
1401
+ }
1402
+ }, [
1403
+ hasI18n,
1404
+ handleChange,
1405
+ locales,
1406
+ query.plugins?.i18n?.locale
1407
+ ]);
1408
+ if (!hasI18n || !Array.isArray(locales) || locales.length === 0) {
1409
+ return null;
1410
+ }
1411
+ const displayedLocales = locales.filter((locale)=>{
1412
+ /**
1413
+ * If you can create or read we allow you to see the locale exists
1414
+ * this is because in the ListView, you may be able to create a new entry
1415
+ * in a locale you can't read.
1416
+ */ return canCreate.includes(locale.code) || canRead.includes(locale.code);
1417
+ });
1418
+ return /*#__PURE__*/ jsxRuntime.jsx(designSystem.SingleSelect, {
1419
+ size: "S",
1420
+ "aria-label": formatMessage({
1421
+ id: getTranslation('actions.select-locale'),
1422
+ defaultMessage: 'Select locale'
1423
+ }),
1424
+ value: query.plugins?.i18n?.locale || locales.find((locale)=>locale.isDefault)?.code,
1425
+ // @ts-expect-error – This can be removed in V2 of the DS.
1426
+ onChange: handleChange,
1427
+ children: displayedLocales.map((locale)=>/*#__PURE__*/ jsxRuntime.jsx(designSystem.SingleSelectOption, {
1428
+ value: locale.code,
1429
+ children: locale.name
1430
+ }, locale.id))
1431
+ });
1432
+ };
1433
+
1434
+ const PERMISSIONS = {
1435
+ accessMain: [
1436
+ {
1437
+ action: 'plugin::i18n.locale.read',
1438
+ subject: null
1439
+ }
1440
+ ],
1441
+ create: [
1442
+ {
1443
+ action: 'plugin::i18n.locale.create',
1444
+ subject: null
1445
+ }
1446
+ ],
1447
+ delete: [
1448
+ {
1449
+ action: 'plugin::i18n.locale.delete',
1450
+ subject: null
1451
+ }
1452
+ ],
1453
+ update: [
1454
+ {
1455
+ action: 'plugin::i18n.locale.update',
1456
+ subject: null
1457
+ }
1458
+ ],
1459
+ read: [
1460
+ {
1461
+ action: 'plugin::i18n.locale.read',
1462
+ subject: null
1463
+ }
1464
+ ]
1465
+ };
1466
+
1467
+ const mutateEditViewHook = ({ layout })=>{
1468
+ // If i18n isn't explicitly enabled on the content type, then no field can be localized
1469
+ if (!('i18n' in layout.options) || typeof layout.options.i18n === 'object' && layout.options.i18n !== null && 'localized' in layout.options.i18n && !layout.options.i18n.localized) {
1470
+ return {
1471
+ layout
1472
+ };
1473
+ }
1474
+ const components = Object.entries(layout.components).reduce((acc, [key, componentLayout])=>{
1475
+ return {
1476
+ ...acc,
1477
+ [key]: {
1478
+ ...componentLayout,
1479
+ layout: componentLayout.layout.map((row)=>row.map(addLabelActionToField))
1480
+ }
1481
+ };
1482
+ }, {});
1483
+ return {
1484
+ layout: {
1485
+ ...layout,
1486
+ components,
1487
+ layout: layout.layout.map((panel)=>panel.map((row)=>row.map(addLabelActionToField)))
1488
+ }
1489
+ };
1490
+ };
1491
+ const addLabelActionToField = (field)=>{
1492
+ const isFieldLocalized = doesFieldHaveI18nPluginOpt(field.attribute.pluginOptions) ? field.attribute.pluginOptions.i18n.localized : true;
1493
+ const labelActionProps = {
1494
+ title: {
1495
+ id: isFieldLocalized ? getTranslation('Field.localized') : getTranslation('Field.not-localized'),
1496
+ defaultMessage: isFieldLocalized ? 'This value is unique for the selected locale' : 'This value is the same across all locales'
1497
+ },
1498
+ icon: isFieldLocalized ? /*#__PURE__*/ jsxRuntime.jsx(icons.Earth, {}) : null
1499
+ };
1500
+ return {
1501
+ ...field,
1502
+ labelAction: isFieldLocalized ? /*#__PURE__*/ jsxRuntime.jsx(LabelAction, {
1503
+ ...labelActionProps
1504
+ }) : null
1505
+ };
1506
+ };
1507
+ const doesFieldHaveI18nPluginOpt = (pluginOpts)=>{
1508
+ if (!pluginOpts) {
1509
+ return false;
1510
+ }
1511
+ return 'i18n' in pluginOpts && typeof pluginOpts.i18n === 'object' && pluginOpts.i18n !== null && 'localized' in pluginOpts.i18n;
1512
+ };
1513
+ const LabelAction = ({ title, icon })=>{
1514
+ const { formatMessage } = reactIntl.useIntl();
1515
+ return /*#__PURE__*/ jsxRuntime.jsxs(Span, {
1516
+ tag: "span",
1517
+ children: [
1518
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.VisuallyHidden, {
1519
+ tag: "span",
1520
+ children: formatMessage(title)
1521
+ }),
1522
+ /*#__PURE__*/ React__namespace.cloneElement(icon, {
1523
+ 'aria-hidden': true,
1524
+ focusable: false
1525
+ })
1526
+ ]
1527
+ });
1528
+ };
1529
+ const Span = styledComponents.styled(designSystem.Flex)`
1530
+ svg {
1531
+ width: 12px;
1532
+ height: 12px;
1533
+
1534
+ fill: ${({ theme })=>theme.colors.neutral500};
1535
+
1536
+ path {
1537
+ fill: ${({ theme })=>theme.colors.neutral500};
1538
+ }
1539
+ }
1540
+ `;
1541
+
1542
+ const LocaleListCell = ({ locale: currentLocale, localizations })=>{
1543
+ const { locale: language } = reactIntl.useIntl();
1544
+ const { data: locales = [] } = useGetLocalesQuery();
1545
+ const formatter = designSystem.useCollator(language, {
1546
+ sensitivity: 'base'
1547
+ });
1548
+ if (!Array.isArray(locales) || !localizations) {
1549
+ return null;
1550
+ }
1551
+ const availableLocales = localizations.map((loc)=>loc.locale);
1552
+ const localesForDocument = locales.reduce((acc, locale)=>{
1553
+ const createdLocale = [
1554
+ currentLocale,
1555
+ ...availableLocales
1556
+ ].find((loc)=>{
1557
+ return loc === locale.code;
1558
+ });
1559
+ if (createdLocale) {
1560
+ acc.push(locale);
1561
+ }
1562
+ return acc;
1563
+ }, []).map((locale)=>{
1564
+ if (locale.isDefault) {
1565
+ return `${locale.name} (default)`;
1566
+ }
1567
+ return locale.name;
1568
+ }).toSorted((a, b)=>formatter.compare(a, b));
1569
+ return /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Popover.Root, {
1570
+ children: [
1571
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Popover.Trigger, {
1572
+ children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Button, {
1573
+ variant: "ghost",
1574
+ type: "button",
1575
+ onClick: (e)=>e.stopPropagation(),
1576
+ children: /*#__PURE__*/ jsxRuntime.jsxs(designSystem.Flex, {
1577
+ minWidth: "100%",
1578
+ alignItems: "center",
1579
+ justifyContent: "center",
1580
+ fontWeight: "regular",
1581
+ children: [
1582
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
1583
+ textColor: "neutral800",
1584
+ ellipsis: true,
1585
+ marginRight: 2,
1586
+ children: localesForDocument.join(', ')
1587
+ }),
1588
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Flex, {
1589
+ children: /*#__PURE__*/ jsxRuntime.jsx(icons.CaretDown, {
1590
+ width: "1.2rem",
1591
+ height: "1.2rem"
1592
+ })
1593
+ })
1594
+ ]
1595
+ })
1596
+ })
1597
+ }),
1598
+ /*#__PURE__*/ jsxRuntime.jsx(designSystem.Popover.Content, {
1599
+ sideOffset: 16,
1600
+ children: /*#__PURE__*/ jsxRuntime.jsx("ul", {
1601
+ children: localesForDocument.map((name)=>/*#__PURE__*/ jsxRuntime.jsx(designSystem.Box, {
1602
+ padding: 3,
1603
+ tag: "li",
1604
+ children: /*#__PURE__*/ jsxRuntime.jsx(designSystem.Typography, {
1605
+ children: name
1606
+ })
1607
+ }, name))
1608
+ })
1609
+ })
1610
+ ]
1611
+ });
1612
+ };
1613
+
1614
+ const addColumnToTableHook = ({ displayedHeaders, layout })=>{
1615
+ const { options } = layout;
1616
+ const isFieldLocalized = doesPluginOptionsHaveI18nLocalized(options) ? options.i18n.localized : false;
1617
+ if (!isFieldLocalized) {
1618
+ return {
1619
+ displayedHeaders,
1620
+ layout
1621
+ };
1622
+ }
1623
+ return {
1624
+ displayedHeaders: [
1625
+ ...displayedHeaders,
1626
+ {
1627
+ attribute: {
1628
+ type: 'string'
1629
+ },
1630
+ label: {
1631
+ id: getTranslation('list-view.table.header.label'),
1632
+ defaultMessage: 'Available in'
1633
+ },
1634
+ searchable: false,
1635
+ sortable: false,
1636
+ name: 'locales',
1637
+ // @ts-expect-error – ID is seen as number | string; this will change when we move the type over.
1638
+ cellFormatter: (props, _header, meta)=>/*#__PURE__*/ jsxRuntime.jsx(LocaleListCell, {
1639
+ ...props,
1640
+ ...meta
1641
+ })
1642
+ }
1643
+ ],
1644
+ layout
1645
+ };
1646
+ };
1647
+
1648
+ const addLocaleToReleasesHook = ({ displayedHeaders = [] })=>{
1649
+ return {
1650
+ displayedHeaders: [
1651
+ ...displayedHeaders,
1652
+ {
1653
+ label: {
1654
+ id: 'content-releases.page.ReleaseDetails.table.header.label.locale',
1655
+ defaultMessage: 'locale'
1656
+ },
1657
+ name: 'locale'
1658
+ }
1659
+ ],
1660
+ hasI18nEnabled: true
1661
+ };
1662
+ };
1663
+
1664
+ const extendCTBAttributeInitialDataMiddleware = ()=>{
1665
+ return ({ getState })=>(next)=>(action)=>{
1666
+ const enhanceAction = ()=>{
1667
+ // the block here is to catch the error when trying to access the state
1668
+ // of the ctb when the plugin is not mounted
1669
+ try {
1670
+ const store = getState();
1671
+ const hasi18nEnabled = get(store, [
1672
+ 'content-type-builder_dataManagerProvider',
1673
+ 'modifiedData',
1674
+ 'contentType',
1675
+ 'schema',
1676
+ 'pluginOptions',
1677
+ 'i18n',
1678
+ 'localized'
1679
+ ], false);
1680
+ if (hasi18nEnabled) {
1681
+ const pluginOptions = action.options ? {
1682
+ ...action.options.pluginOptions,
1683
+ i18n: {
1684
+ localized: true
1685
+ }
1686
+ } : {
1687
+ i18n: {
1688
+ localized: true
1689
+ }
1690
+ };
1691
+ return next({
1692
+ ...action,
1693
+ options: {
1694
+ pluginOptions
1695
+ }
1696
+ });
1697
+ }
1698
+ return next(action);
1699
+ } catch (err) {
1700
+ return next(action);
1701
+ }
1702
+ };
1703
+ if (action.type === 'ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA' && action.forTarget === 'contentType' && ![
1704
+ 'relation',
1705
+ 'component'
1706
+ ].includes(action.attributeType) && !action.isEditing) {
1707
+ return enhanceAction();
1708
+ }
1709
+ if (action.type === 'ContentTypeBuilder/FormModal/SET_CUSTOM_FIELD_DATA_SCHEMA' && action.forTarget === 'contentType' && !action.isEditing) {
1710
+ return enhanceAction();
1711
+ }
1712
+ 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') {
1713
+ return enhanceAction();
1714
+ }
1715
+ return next(action);
1716
+ };
1717
+ };
1718
+
1719
+ const extendCTBInitialDataMiddleware = ()=>{
1720
+ return ()=>(next)=>(action)=>{
1721
+ if (action.type === 'ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT' && action.modalType === 'contentType') {
1722
+ const i18n = {
1723
+ localized: false
1724
+ };
1725
+ const pluginOptions = action.data.pluginOptions ? {
1726
+ ...action.data.pluginOptions,
1727
+ i18n
1728
+ } : {
1729
+ i18n
1730
+ };
1731
+ const data = {
1732
+ ...action.data,
1733
+ pluginOptions
1734
+ };
1735
+ if (action.actionType === 'create') {
1736
+ return next({
1737
+ ...action,
1738
+ data
1739
+ });
1740
+ }
1741
+ // Override the action if the pluginOption config does not contain i18n
1742
+ // In this case we need to set the proper initialData shape
1743
+ if (!action.data.pluginOptions?.i18n?.localized) {
1744
+ return next({
1745
+ ...action,
1746
+ data
1747
+ });
1748
+ }
1749
+ }
1750
+ // action is not the one we want to override
1751
+ return next(action);
1752
+ };
1753
+ };
1754
+
1755
+ const localeMiddleware = (ctx)=>(next)=>(permissions)=>{
1756
+ const match = reactRouterDom.matchPath('/content-manager/:collectionType/:model?/:id', ctx.pathname);
1757
+ if (!match) {
1758
+ return next(permissions);
1759
+ }
1760
+ const search = qs__namespace.parse(ctx.search);
1761
+ if (typeof search !== 'object') {
1762
+ return next(permissions);
1763
+ }
1764
+ if (!('plugins' in search && typeof search.plugins === 'object')) {
1765
+ return next(permissions);
1766
+ }
1767
+ if (!('i18n' in search.plugins && typeof search.plugins.i18n === 'object' && !Array.isArray(search.plugins.i18n))) {
1768
+ return next(permissions);
1769
+ }
1770
+ const { locale } = search.plugins.i18n;
1771
+ if (typeof locale !== 'string') {
1772
+ return next(permissions);
1773
+ }
1774
+ const revisedPermissions = permissions.filter((permission)=>!permission.properties?.locales || permission.properties.locales.includes(locale));
1775
+ return next(revisedPermissions);
1776
+ };
1777
+
1778
+ const prefixPluginTranslations = (trad, pluginId)=>{
1779
+ return Object.keys(trad).reduce((acc, current)=>{
1780
+ acc[`${pluginId}.${current}`] = trad[current];
1781
+ return acc;
1782
+ }, {});
1783
+ };
1784
+
1785
+ /* -------------------------------------------------------------------------------------------------
1786
+ * mutateCTBContentTypeSchema
1787
+ * -----------------------------------------------------------------------------------------------*/ const mutateCTBContentTypeSchema = (nextSchema, prevSchema)=>{
1788
+ // Don't perform mutations components
1789
+ if (!doesPluginOptionsHaveI18nLocalized(nextSchema.pluginOptions)) {
1790
+ return nextSchema;
1791
+ }
1792
+ const isNextSchemaLocalized = nextSchema.pluginOptions.i18n.localized;
1793
+ const isPrevSchemaLocalized = doesPluginOptionsHaveI18nLocalized(prevSchema?.schema?.pluginOptions) ? prevSchema?.schema?.pluginOptions.i18n.localized : false;
1794
+ // No need to perform modification on the schema, if the i18n feature was not changed
1795
+ // at the ct level
1796
+ if (isNextSchemaLocalized && isPrevSchemaLocalized) {
1797
+ return nextSchema;
1798
+ }
1799
+ if (isNextSchemaLocalized) {
1800
+ const attributes = addLocalisationToFields(nextSchema.attributes);
1801
+ return {
1802
+ ...nextSchema,
1803
+ attributes
1804
+ };
1805
+ }
1806
+ // Remove the i18n object from the pluginOptions
1807
+ if (!isNextSchemaLocalized) {
1808
+ const pluginOptions = omit(nextSchema.pluginOptions, 'i18n');
1809
+ const attributes = disableAttributesLocalisation(nextSchema.attributes);
1810
+ return {
1811
+ ...nextSchema,
1812
+ pluginOptions,
1813
+ attributes
1814
+ };
1815
+ }
1816
+ return nextSchema;
1817
+ };
1818
+ /* -------------------------------------------------------------------------------------------------
1819
+ * addLocalisationToFields
1820
+ * -----------------------------------------------------------------------------------------------*/ const addLocalisationToFields = (attributes)=>Object.keys(attributes).reduce((acc, current)=>{
1821
+ const currentAttribute = attributes[current];
1822
+ if (LOCALIZED_FIELDS.includes(currentAttribute.type)) {
1823
+ const i18n = {
1824
+ localized: true
1825
+ };
1826
+ const pluginOptions = currentAttribute.pluginOptions ? {
1827
+ ...currentAttribute.pluginOptions,
1828
+ i18n
1829
+ } : {
1830
+ i18n
1831
+ };
1832
+ acc[current] = {
1833
+ ...currentAttribute,
1834
+ pluginOptions
1835
+ };
1836
+ return acc;
1837
+ }
1838
+ acc[current] = currentAttribute;
1839
+ return acc;
1840
+ }, {});
1841
+ const disableAttributesLocalisation = (attributes)=>Object.keys(attributes).reduce((acc, current)=>{
1842
+ acc[current] = omit(attributes[current], 'pluginOptions.i18n');
1843
+ return acc;
1844
+ }, {});
1845
+
1846
+ function __variableDynamicImportRuntime1__(path) {
1847
+ switch (path) {
1848
+ case './translations/de.json': return Promise.resolve().then(function () { return require('./de-nEMWvIiY.js'); });
1849
+ case './translations/dk.json': return Promise.resolve().then(function () { return require('./dk-CYATLPVe.js'); });
1850
+ case './translations/en.json': return Promise.resolve().then(function () { return require('./en-CG5cUCbD.js'); });
1851
+ case './translations/es.json': return Promise.resolve().then(function () { return require('./es-CWsogTGm.js'); });
1852
+ case './translations/fr.json': return Promise.resolve().then(function () { return require('./fr-CC7UFcYd.js'); });
1853
+ case './translations/ko.json': return Promise.resolve().then(function () { return require('./ko-XwGmfhoq.js'); });
1854
+ case './translations/pl.json': return Promise.resolve().then(function () { return require('./pl-B_vzY_ZB.js'); });
1855
+ case './translations/ru.json': return Promise.resolve().then(function () { return require('./ru-WzHcJV1f.js'); });
1856
+ case './translations/tr.json': return Promise.resolve().then(function () { return require('./tr-CcWp6u3w.js'); });
1857
+ case './translations/zh-Hans.json': return Promise.resolve().then(function () { return require('./zh-Hans-DnU2bhri.js'); });
1858
+ case './translations/zh.json': return Promise.resolve().then(function () { return require('./zh-C9So4SGq.js'); });
1859
+ default: return new Promise(function(resolve, reject) {
1860
+ (typeof queueMicrotask === 'function' ? queueMicrotask : setTimeout)(
1861
+ reject.bind(null, new Error("Unknown variable dynamic import: " + path))
1862
+ );
1863
+ })
1864
+ }
1865
+ }
1866
+ // eslint-disable-next-line import/no-default-export
1867
+ var index = {
1868
+ register (app) {
1869
+ app.addMiddlewares([
1870
+ extendCTBAttributeInitialDataMiddleware,
1871
+ extendCTBInitialDataMiddleware
1872
+ ]);
1873
+ app.addMiddlewares([
1874
+ ()=>i18nApi.middleware
1875
+ ]);
1876
+ app.addReducers({
1877
+ [i18nApi.reducerPath]: i18nApi.reducer
1878
+ });
1879
+ app.addRBACMiddleware([
1880
+ localeMiddleware
1881
+ ]);
1882
+ app.registerPlugin({
1883
+ id: pluginId,
1884
+ name: pluginId
1885
+ });
1886
+ },
1887
+ bootstrap (app) {
1888
+ // // Hook that adds a column into the CM's LV table
1889
+ app.registerHook('Admin/CM/pages/ListView/inject-column-in-table', addColumnToTableHook);
1890
+ app.registerHook('Admin/CM/pages/EditView/mutate-edit-view-layout', mutateEditViewHook);
1891
+ // Hooks that checks if the locale is present in the release
1892
+ app.registerHook('ContentReleases/pages/ReleaseDetails/add-locale-in-releases', addLocaleToReleasesHook);
1893
+ // Add the settings link
1894
+ app.addSettingsLink('global', {
1895
+ intlLabel: {
1896
+ id: getTranslation('plugin.name'),
1897
+ defaultMessage: 'Internationalization'
1898
+ },
1899
+ id: 'internationalization',
1900
+ to: 'internationalization',
1901
+ Component: ()=>Promise.resolve().then(function () { return require('./SettingsPage-B6ikxVOg.js'); }).then((mod)=>({
1902
+ default: mod.ProtectedSettingsPage
1903
+ })),
1904
+ permissions: PERMISSIONS.accessMain
1905
+ });
1906
+ const contentManager = app.getPlugin('content-manager');
1907
+ contentManager.apis.addDocumentHeaderAction([
1908
+ LocalePickerAction,
1909
+ FillFromAnotherLocaleAction
1910
+ ]);
1911
+ contentManager.apis.addDocumentAction((actions)=>{
1912
+ const indexOfDeleteAction = actions.findIndex((action)=>action.type === 'delete');
1913
+ actions.splice(indexOfDeleteAction, 0, DeleteLocaleAction);
1914
+ return actions;
1915
+ });
1916
+ contentManager.apis.addDocumentAction((actions)=>{
1917
+ // When enabled the bulk locale publish action should be the first action
1918
+ // in 'More Document Actions' and therefore the third action in the array
1919
+ actions.splice(2, 0, BulkLocalePublishAction);
1920
+ actions.splice(5, 0, BulkLocaleUnpublishAction);
1921
+ return actions;
1922
+ });
1923
+ contentManager.injectComponent('listView', 'actions', {
1924
+ name: 'i18n-locale-filter',
1925
+ Component: LocalePicker
1926
+ });
1927
+ contentManager.injectComponent('listView', 'publishModalAdditionalInfos', {
1928
+ name: 'i18n-publish-bullets-in-modal',
1929
+ Component: PublishModalAdditionalInfo
1930
+ });
1931
+ contentManager.injectComponent('listView', 'unpublishModalAdditionalInfos', {
1932
+ name: 'i18n-unpublish-bullets-in-modal',
1933
+ Component: UnpublishModalAdditionalInfo
1934
+ });
1935
+ contentManager.injectComponent('listView', 'deleteModalAdditionalInfos', {
1936
+ name: 'i18n-delete-bullets-in-modal',
1937
+ Component: DeleteModalAdditionalInfo
1938
+ });
1939
+ const ctbPlugin = app.getPlugin('content-type-builder');
1940
+ if (ctbPlugin) {
1941
+ const ctbFormsAPI = ctbPlugin.apis.forms;
1942
+ ctbFormsAPI.addContentTypeSchemaMutation(mutateCTBContentTypeSchema);
1943
+ ctbFormsAPI.components.add({
1944
+ id: 'checkboxConfirmation',
1945
+ component: CheckboxConfirmation
1946
+ });
1947
+ ctbFormsAPI.extendContentType({
1948
+ validator: ()=>({
1949
+ i18n: yup__namespace.object().shape({
1950
+ localized: yup__namespace.bool()
1951
+ })
1952
+ }),
1953
+ form: {
1954
+ advanced () {
1955
+ return [
1956
+ {
1957
+ name: 'pluginOptions.i18n.localized',
1958
+ description: {
1959
+ id: getTranslation('plugin.schema.i18n.localized.description-content-type'),
1960
+ defaultMessage: 'Allows translating an entry into different languages'
1961
+ },
1962
+ type: 'checkboxConfirmation',
1963
+ intlLabel: {
1964
+ id: getTranslation('plugin.schema.i18n.localized.label-content-type'),
1965
+ defaultMessage: 'Localization'
1966
+ }
1967
+ }
1968
+ ];
1969
+ }
1970
+ }
1971
+ });
1972
+ ctbFormsAPI.extendFields(LOCALIZED_FIELDS, {
1973
+ form: {
1974
+ advanced ({ contentTypeSchema, forTarget, type, step }) {
1975
+ if (forTarget !== 'contentType') {
1976
+ return [];
1977
+ }
1978
+ const hasI18nEnabled = get(contentTypeSchema, [
1979
+ 'schema',
1980
+ 'pluginOptions',
1981
+ 'i18n',
1982
+ 'localized'
1983
+ ], false);
1984
+ if (!hasI18nEnabled) {
1985
+ return [];
1986
+ }
1987
+ if (type === 'component' && step === '1') {
1988
+ return [];
1989
+ }
1990
+ return [
1991
+ {
1992
+ name: 'pluginOptions.i18n.localized',
1993
+ description: {
1994
+ id: getTranslation('plugin.schema.i18n.localized.description-field'),
1995
+ defaultMessage: 'The field can have different values in each locale'
1996
+ },
1997
+ type: 'checkbox',
1998
+ intlLabel: {
1999
+ id: getTranslation('plugin.schema.i18n.localized.label-field'),
2000
+ defaultMessage: 'Enable localization for this field'
2001
+ }
2002
+ }
2003
+ ];
2004
+ }
2005
+ }
2006
+ });
2007
+ }
2008
+ },
2009
+ async registerTrads ({ locales }) {
2010
+ const importedTrads = await Promise.all(locales.map((locale)=>{
2011
+ return __variableDynamicImportRuntime1__(`./translations/${locale}.json`).then(({ default: data })=>{
2012
+ return {
2013
+ data: prefixPluginTranslations(data, pluginId),
2014
+ locale
2015
+ };
2016
+ }).catch(()=>{
2017
+ return {
2018
+ data: {},
2019
+ locale
2020
+ };
2021
+ });
2022
+ }));
2023
+ return Promise.resolve(importedTrads);
2024
+ }
2025
+ };
2026
+
2027
+ exports.PERMISSIONS = PERMISSIONS;
2028
+ exports.getTranslation = getTranslation;
2029
+ exports.index = index;
2030
+ exports.useCreateLocaleMutation = useCreateLocaleMutation;
2031
+ exports.useDeleteLocaleMutation = useDeleteLocaleMutation;
2032
+ exports.useGetDefaultLocalesQuery = useGetDefaultLocalesQuery;
2033
+ exports.useGetLocalesQuery = useGetLocalesQuery;
2034
+ exports.useUpdateLocaleMutation = useUpdateLocaleMutation;
2035
+ //# sourceMappingURL=index-Dch-2xao.js.map