@strapi/i18n 0.0.0-next.f6dca5adf05ef6bed9605a1535999ab0bbbf063e → 0.0.0-next.fc9d26d995624dc886b29f563e1de655d47e6609

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 (127) hide show
  1. package/dist/admin/chunks/SettingsPage-D0K-VSRW.js +797 -0
  2. package/dist/admin/chunks/SettingsPage-D0K-VSRW.js.map +1 -0
  3. package/dist/admin/chunks/SettingsPage-JGkgqjSC.js +820 -0
  4. package/dist/admin/chunks/SettingsPage-JGkgqjSC.js.map +1 -0
  5. package/dist/admin/chunks/de-Cm8mYdaO.js +64 -0
  6. package/dist/admin/chunks/de-Cm8mYdaO.js.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.js +64 -0
  10. package/dist/admin/chunks/dk-BeUFOegB.js.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.js +79 -0
  16. package/dist/admin/chunks/en-eWSaCeOb.js.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.js +64 -0
  20. package/dist/admin/chunks/es-DqF_IdAc.js.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.js +64 -0
  24. package/dist/admin/chunks/fr-CyARbZ3c.js.map +1 -0
  25. package/dist/admin/chunks/index-BrzTFkBd.js +2035 -0
  26. package/dist/admin/chunks/index-BrzTFkBd.js.map +1 -0
  27. package/dist/admin/chunks/index-DGnskYbP.js +2006 -0
  28. package/dist/admin/chunks/index-DGnskYbP.js.map +1 -0
  29. package/dist/admin/chunks/ko-Ax4NSedM.js +63 -0
  30. package/dist/admin/chunks/ko-Ax4NSedM.js.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.js +64 -0
  34. package/dist/admin/chunks/pl-B-aqvMqL.js.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.js +66 -0
  38. package/dist/admin/chunks/ru-VkPjQ-Sk.js.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.js +64 -0
  44. package/dist/admin/chunks/tr-DcTR88c9.js.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.js +55 -0
  50. package/dist/admin/chunks/zh-Hans-L3wsRegj.js.map +1 -0
  51. package/dist/admin/chunks/zh-RZyMiPIs.js +64 -0
  52. package/dist/admin/chunks/zh-RZyMiPIs.js.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/LocaleListCell.d.ts +4 -4
  59. package/dist/admin/src/components/tests/CreateLocale.test.d.ts +1 -0
  60. package/dist/admin/src/components/tests/DeleteLocale.test.d.ts +1 -0
  61. package/dist/admin/src/components/tests/EditLocale.test.d.ts +1 -0
  62. package/dist/admin/src/components/tests/LocaleListCell.test.d.ts +1 -0
  63. package/dist/admin/src/contentReleasesHooks/releaseDetailsView.d.ts +1 -1
  64. package/dist/admin/src/pages/tests/SettingsPage.test.d.ts +1 -0
  65. package/dist/admin/tests/server.d.ts +1 -0
  66. package/dist/admin/tests/utils.d.ts +6 -0
  67. package/dist/server/index.js +3650 -3383
  68. package/dist/server/index.js.map +1 -1
  69. package/dist/server/index.mjs +3632 -3366
  70. package/dist/server/index.mjs.map +1 -1
  71. package/dist/server/src/services/localizations.d.ts +1 -1
  72. package/dist/server/src/services/localizations.d.ts.map +1 -1
  73. package/dist/shared/contracts/content-manager.d.ts +1 -1
  74. package/dist/shared/contracts/shared.d.ts +1 -1
  75. package/package.json +17 -15
  76. package/dist/_chunks/SettingsPage-BHvunuIF.mjs +0 -554
  77. package/dist/_chunks/SettingsPage-BHvunuIF.mjs.map +0 -1
  78. package/dist/_chunks/SettingsPage-Bcj7380u.js +0 -574
  79. package/dist/_chunks/SettingsPage-Bcj7380u.js.map +0 -1
  80. package/dist/_chunks/de-9eCAqqrB.mjs +0 -66
  81. package/dist/_chunks/de-9eCAqqrB.mjs.map +0 -1
  82. package/dist/_chunks/de-DtWiGdHl.js +0 -66
  83. package/dist/_chunks/de-DtWiGdHl.js.map +0 -1
  84. package/dist/_chunks/dk-2qBjxt-P.mjs +0 -66
  85. package/dist/_chunks/dk-2qBjxt-P.mjs.map +0 -1
  86. package/dist/_chunks/dk-D8C-casx.js +0 -66
  87. package/dist/_chunks/dk-D8C-casx.js.map +0 -1
  88. package/dist/_chunks/en-BKBz3tro.js +0 -81
  89. package/dist/_chunks/en-BKBz3tro.js.map +0 -1
  90. package/dist/_chunks/en-DlXfy6Gy.mjs +0 -81
  91. package/dist/_chunks/en-DlXfy6Gy.mjs.map +0 -1
  92. package/dist/_chunks/es-DS-XFGSw.js +0 -66
  93. package/dist/_chunks/es-DS-XFGSw.js.map +0 -1
  94. package/dist/_chunks/es-DlmMVaBG.mjs +0 -66
  95. package/dist/_chunks/es-DlmMVaBG.mjs.map +0 -1
  96. package/dist/_chunks/fr-3S6ke71d.mjs +0 -66
  97. package/dist/_chunks/fr-3S6ke71d.mjs.map +0 -1
  98. package/dist/_chunks/fr-BTjekDpq.js +0 -66
  99. package/dist/_chunks/fr-BTjekDpq.js.map +0 -1
  100. package/dist/_chunks/index-BKZbxhpm.js +0 -1637
  101. package/dist/_chunks/index-BKZbxhpm.js.map +0 -1
  102. package/dist/_chunks/index-DUdrr5PR.mjs +0 -1615
  103. package/dist/_chunks/index-DUdrr5PR.mjs.map +0 -1
  104. package/dist/_chunks/ko-DmcGUBQ3.js +0 -65
  105. package/dist/_chunks/ko-DmcGUBQ3.js.map +0 -1
  106. package/dist/_chunks/ko-qTjQ8IMw.mjs +0 -65
  107. package/dist/_chunks/ko-qTjQ8IMw.mjs.map +0 -1
  108. package/dist/_chunks/pl-B67TSHqT.mjs +0 -66
  109. package/dist/_chunks/pl-B67TSHqT.mjs.map +0 -1
  110. package/dist/_chunks/pl-Cn5RYonZ.js +0 -66
  111. package/dist/_chunks/pl-Cn5RYonZ.js.map +0 -1
  112. package/dist/_chunks/ru-BMBgVL3s.js +0 -68
  113. package/dist/_chunks/ru-BMBgVL3s.js.map +0 -1
  114. package/dist/_chunks/ru-hagMa57T.mjs +0 -68
  115. package/dist/_chunks/ru-hagMa57T.mjs.map +0 -1
  116. package/dist/_chunks/tr-CarUU76c.js +0 -66
  117. package/dist/_chunks/tr-CarUU76c.js.map +0 -1
  118. package/dist/_chunks/tr-Dw_jmkG-.mjs +0 -66
  119. package/dist/_chunks/tr-Dw_jmkG-.mjs.map +0 -1
  120. package/dist/_chunks/zh-57YM4amO.mjs +0 -66
  121. package/dist/_chunks/zh-57YM4amO.mjs.map +0 -1
  122. package/dist/_chunks/zh-CukOviB0.js +0 -66
  123. package/dist/_chunks/zh-CukOviB0.js.map +0 -1
  124. package/dist/_chunks/zh-Hans-DSHIXAa3.js +0 -57
  125. package/dist/_chunks/zh-Hans-DSHIXAa3.js.map +0 -1
  126. package/dist/_chunks/zh-Hans-Dyc-aR-h.mjs +0 -57
  127. package/dist/_chunks/zh-Hans-Dyc-aR-h.mjs.map +0 -1
@@ -1,1637 +0,0 @@
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
- showBullet: false,
487
- size: "S",
488
- variant: statusVariant,
489
- children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "span", variant: "pi", fontWeight: "bold", children: capitalize(status) })
490
- }
491
- ) }) }),
492
- /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(EntryValidationText, { validationErrors: error, status, action }) }),
493
- /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(
494
- designSystem.IconButton,
495
- {
496
- tag: reactRouterDom.Link,
497
- to: {
498
- search: qs.stringify({ plugins: { i18n: { locale } } })
499
- },
500
- label: formatMessage(
501
- {
502
- id: getTranslation("Settings.list.actions.edit"),
503
- defaultMessage: "Edit {name} locale"
504
- },
505
- {
506
- name: locale
507
- }
508
- ),
509
- variant: "ghost",
510
- children: /* @__PURE__ */ jsxRuntime.jsx(icons.Pencil, {})
511
- }
512
- ) })
513
- ] }, index2);
514
- }) })
515
- ] }) })
516
- ] });
517
- };
518
- const statusVariants = {
519
- draft: "secondary",
520
- published: "success",
521
- modified: "alternative"
522
- };
523
- const LocaleOption = ({
524
- isDraftAndPublishEnabled,
525
- locale,
526
- status,
527
- entryExists
528
- }) => {
529
- const { formatMessage } = reactIntl.useIntl();
530
- if (!entryExists) {
531
- return formatMessage(
532
- {
533
- id: getTranslation("CMEditViewLocalePicker.locale.create"),
534
- defaultMessage: "Create <bold>{locale}</bold> locale"
535
- },
536
- {
537
- bold: (locale2) => /* @__PURE__ */ jsxRuntime.jsx("b", { children: locale2 }),
538
- locale: locale.name
539
- }
540
- );
541
- }
542
- return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { width: "100%", gap: 1, justifyContent: "space-between", children: [
543
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: locale.name }),
544
- isDraftAndPublishEnabled ? /* @__PURE__ */ jsxRuntime.jsx(
545
- designSystem.Status,
546
- {
547
- display: "flex",
548
- paddingLeft: "6px",
549
- paddingRight: "6px",
550
- paddingTop: "2px",
551
- paddingBottom: "2px",
552
- showBullet: false,
553
- size: "S",
554
- variant: statusVariants[status],
555
- children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "span", variant: "pi", fontWeight: "bold", children: capitalize(status) })
556
- }
557
- ) : null
558
- ] });
559
- };
560
- const LocalePickerAction = ({
561
- document,
562
- meta,
563
- model,
564
- collectionType,
565
- documentId
566
- }) => {
567
- const { formatMessage } = reactIntl.useIntl();
568
- const [{ query: query2 }, setQuery] = strapiAdmin.useQueryParams();
569
- const { hasI18n, canCreate, canRead } = useI18n();
570
- const { data: locales = [] } = useGetLocalesQuery();
571
- const currentDesiredLocale = query2.plugins?.i18n?.locale;
572
- const { schema } = strapiAdmin$1.unstable_useDocument({
573
- model,
574
- collectionType,
575
- documentId,
576
- params: { locale: currentDesiredLocale }
577
- });
578
- const handleSelect = React__namespace.useCallback(
579
- (value) => {
580
- setQuery({
581
- plugins: {
582
- ...query2.plugins,
583
- i18n: {
584
- locale: value
585
- }
586
- }
587
- });
588
- },
589
- [query2.plugins, setQuery]
590
- );
591
- React__namespace.useEffect(() => {
592
- if (!Array.isArray(locales) || !hasI18n) {
593
- return;
594
- }
595
- const doesLocaleExist = locales.find((loc) => loc.code === currentDesiredLocale);
596
- const defaultLocale = locales.find((locale) => locale.isDefault);
597
- if (!doesLocaleExist && defaultLocale?.code) {
598
- handleSelect(defaultLocale.code);
599
- }
600
- }, [handleSelect, hasI18n, locales, currentDesiredLocale]);
601
- const currentLocale = Array.isArray(locales) ? locales.find((locale) => locale.code === currentDesiredLocale) : void 0;
602
- const allCurrentLocales = [
603
- { status: getDocumentStatus(document, meta), locale: currentLocale?.code },
604
- ...meta?.availableLocales ?? []
605
- ];
606
- if (!hasI18n || !Array.isArray(locales) || locales.length === 0) {
607
- return null;
608
- }
609
- return {
610
- label: formatMessage({
611
- id: getTranslation("Settings.locales.modal.locales.label"),
612
- defaultMessage: "Locales"
613
- }),
614
- options: locales.map((locale) => {
615
- const entryWithLocaleExists = allCurrentLocales.some((doc) => doc.locale === locale.code);
616
- const currentLocaleDoc = allCurrentLocales.find(
617
- (doc) => "locale" in doc ? doc.locale === locale.code : false
618
- );
619
- const permissionsToCheck = currentLocaleDoc ? canRead : canCreate;
620
- return {
621
- disabled: !permissionsToCheck.includes(locale.code),
622
- value: locale.code,
623
- label: /* @__PURE__ */ jsxRuntime.jsx(
624
- LocaleOption,
625
- {
626
- isDraftAndPublishEnabled: !!schema?.options?.draftAndPublish,
627
- locale,
628
- status: currentLocaleDoc?.status,
629
- entryExists: entryWithLocaleExists
630
- }
631
- ),
632
- startIcon: !entryWithLocaleExists ? /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) : null
633
- };
634
- }),
635
- customizeContent: () => currentLocale?.name,
636
- onSelect: handleSelect,
637
- value: currentLocale
638
- };
639
- };
640
- const getDocumentStatus = (document, meta) => {
641
- const docStatus = document?.status;
642
- const statuses = meta?.availableStatus ?? [];
643
- if (!docStatus) {
644
- return "draft";
645
- }
646
- if (docStatus === "draft" && statuses.find((doc) => doc.publishedAt !== null)) {
647
- return "published";
648
- }
649
- return docStatus;
650
- };
651
- const FillFromAnotherLocaleAction = ({
652
- documentId,
653
- meta,
654
- model,
655
- collectionType
656
- }) => {
657
- const { formatMessage } = reactIntl.useIntl();
658
- const [{ query: query2 }] = strapiAdmin.useQueryParams();
659
- const { hasI18n } = useI18n();
660
- const currentDesiredLocale = query2.plugins?.i18n?.locale;
661
- const [localeSelected, setLocaleSelected] = React__namespace.useState(null);
662
- const setValues = strapiAdmin.useForm("FillFromAnotherLocale", (state) => state.setValues);
663
- const { getDocument } = strapiAdmin$1.unstable_useDocumentActions();
664
- const { schema, components } = strapiAdmin$1.unstable_useDocument({
665
- model,
666
- documentId,
667
- collectionType,
668
- params: { locale: currentDesiredLocale }
669
- });
670
- const { data: locales = [] } = useGetLocalesQuery();
671
- const availableLocales = Array.isArray(locales) ? locales.filter((locale) => meta?.availableLocales.some((l) => l.locale === locale.code)) : [];
672
- const fillFromLocale = (onClose) => async () => {
673
- const response = await getDocument({
674
- collectionType,
675
- model,
676
- documentId,
677
- params: { locale: localeSelected }
678
- });
679
- if (!response || !schema) {
680
- return;
681
- }
682
- const { data } = response;
683
- const cleanedData = cleanData(data, schema, components);
684
- setValues(cleanedData);
685
- onClose();
686
- };
687
- if (!hasI18n) {
688
- return null;
689
- }
690
- return {
691
- type: "icon",
692
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Download, {}),
693
- disabled: availableLocales.length === 0,
694
- label: formatMessage({
695
- id: getTranslation("CMEditViewCopyLocale.copy-text"),
696
- defaultMessage: "Fill in from another locale"
697
- }),
698
- dialog: {
699
- type: "dialog",
700
- title: formatMessage({
701
- id: getTranslation("CMEditViewCopyLocale.dialog.title"),
702
- defaultMessage: "Confirmation"
703
- }),
704
- content: ({ onClose }) => /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
705
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 3, children: [
706
- /* @__PURE__ */ jsxRuntime.jsx(icons.WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
707
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textAlign: "center", children: formatMessage({
708
- id: getTranslation("CMEditViewCopyLocale.dialog.body"),
709
- defaultMessage: "Your current content will be erased and filled by the content of the selected locale:"
710
- }) }),
711
- /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { width: "100%", children: [
712
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage({
713
- id: getTranslation("CMEditViewCopyLocale.dialog.field.label"),
714
- defaultMessage: "Locale"
715
- }) }),
716
- /* @__PURE__ */ jsxRuntime.jsx(
717
- designSystem.SingleSelect,
718
- {
719
- value: localeSelected,
720
- placeholder: formatMessage({
721
- id: getTranslation("CMEditViewCopyLocale.dialog.field.placeholder"),
722
- defaultMessage: "Select one locale..."
723
- }),
724
- onChange: (value) => setLocaleSelected(value),
725
- children: availableLocales.map((locale) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: locale.code, children: locale.name }, locale.code))
726
- }
727
- )
728
- ] })
729
- ] }) }),
730
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, width: "100%", children: [
731
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { flex: "auto", variant: "tertiary", onClick: onClose, children: formatMessage({
732
- id: getTranslation("CMEditViewCopyLocale.cancel-text"),
733
- defaultMessage: "No, cancel"
734
- }) }),
735
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { flex: "auto", variant: "success", onClick: fillFromLocale(onClose), children: formatMessage({
736
- id: getTranslation("CMEditViewCopyLocale.submit-text"),
737
- defaultMessage: "Yes, fill in"
738
- }) })
739
- ] }) })
740
- ] })
741
- }
742
- };
743
- };
744
- const DeleteLocaleAction = ({
745
- document,
746
- documentId,
747
- model,
748
- collectionType
749
- }) => {
750
- const { formatMessage } = reactIntl.useIntl();
751
- const navigate = reactRouterDom.useNavigate();
752
- const { toggleNotification } = strapiAdmin.useNotification();
753
- const { delete: deleteAction } = strapiAdmin$1.unstable_useDocumentActions();
754
- const { hasI18n, canDelete } = useI18n();
755
- const [{ query: query2 }] = strapiAdmin.useQueryParams();
756
- const { data: locales = [] } = useGetLocalesQuery();
757
- const currentDesiredLocale = query2.plugins?.i18n?.locale;
758
- const locale = !("error" in locales) && locales.find((loc) => loc.code === currentDesiredLocale);
759
- if (!hasI18n) {
760
- return null;
761
- }
762
- return {
763
- disabled: document?.locale && !canDelete.includes(document.locale) || !document || !document.id,
764
- position: ["header", "table-row"],
765
- label: formatMessage(
766
- {
767
- id: getTranslation("actions.delete.label"),
768
- defaultMessage: "Delete entry ({locale})"
769
- },
770
- { locale: locale && locale.name }
771
- ),
772
- icon: /* @__PURE__ */ jsxRuntime.jsx(StyledTrash, {}),
773
- variant: "danger",
774
- dialog: {
775
- type: "dialog",
776
- title: formatMessage({
777
- id: getTranslation("actions.delete.dialog.title"),
778
- defaultMessage: "Confirmation"
779
- }),
780
- content: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 2, children: [
781
- /* @__PURE__ */ jsxRuntime.jsx(icons.WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
782
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "p", variant: "omega", textAlign: "center", children: formatMessage({
783
- id: getTranslation("actions.delete.dialog.body"),
784
- defaultMessage: "Are you sure?"
785
- }) })
786
- ] }),
787
- onConfirm: async () => {
788
- const unableToDelete = (
789
- // We are unable to delete a collection type without a document ID
790
- // & unable to delete generally if there is no document locale
791
- collectionType !== "single-types" && !documentId || !document?.locale
792
- );
793
- if (unableToDelete) {
794
- console.error(
795
- "You're trying to delete a document without an id or locale, this is likely a bug with Strapi. Please open an issue."
796
- );
797
- toggleNotification({
798
- message: formatMessage({
799
- id: getTranslation("actions.delete.error"),
800
- defaultMessage: "An error occurred while trying to delete the document locale."
801
- }),
802
- type: "danger"
803
- });
804
- return;
805
- }
806
- const res = await deleteAction({
807
- documentId,
808
- model,
809
- collectionType,
810
- params: { locale: document.locale }
811
- });
812
- if (!("error" in res)) {
813
- navigate({ pathname: `../${collectionType}/${model}` }, { replace: true });
814
- }
815
- }
816
- }
817
- };
818
- };
819
- const BulkLocaleAction = ({
820
- document: baseDocument,
821
- documentId,
822
- model,
823
- collectionType,
824
- action
825
- }) => {
826
- const baseLocale = baseDocument?.locale ?? null;
827
- const [{ query: query$1 }] = strapiAdmin.useQueryParams();
828
- const params = React__namespace.useMemo(() => strapiAdmin$1.buildValidParams(query$1), [query$1]);
829
- const isOnPublishedTab = query$1.status === "published";
830
- const { formatMessage } = reactIntl.useIntl();
831
- const { hasI18n, canPublish } = useI18n();
832
- const { toggleNotification } = strapiAdmin.useNotification();
833
- const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
834
- const [selectedRows, setSelectedRows] = React__namespace.useState([]);
835
- const [isDraftRelationConfirmationOpen, setIsDraftRelationConfirmationOpen] = React__namespace.useState(false);
836
- const { publishMany: publishManyAction, unpublishMany: unpublishManyAction } = strapiAdmin$1.unstable_useDocumentActions();
837
- const {
838
- document,
839
- meta: documentMeta,
840
- schema,
841
- validate
842
- } = strapiAdmin$1.unstable_useDocument(
843
- {
844
- model,
845
- collectionType,
846
- documentId,
847
- params: {
848
- locale: baseLocale
849
- }
850
- },
851
- {
852
- skip: !hasI18n || !baseLocale
853
- }
854
- );
855
- const { data: localesMetadata = [] } = useGetLocalesQuery(hasI18n ? void 0 : query.skipToken);
856
- const headers = [
857
- {
858
- label: formatMessage({
859
- id: "global.name",
860
- defaultMessage: "Name"
861
- }),
862
- name: "name"
863
- },
864
- {
865
- label: formatMessage({
866
- id: getTranslation("CMEditViewBulkLocale.status"),
867
- defaultMessage: "Status"
868
- }),
869
- name: "status"
870
- },
871
- {
872
- label: formatMessage({
873
- id: getTranslation("CMEditViewBulkLocale.publication-status"),
874
- defaultMessage: "Publication Status"
875
- }),
876
- name: "publication-status"
877
- }
878
- ];
879
- const [rows, validationErrors] = React__namespace.useMemo(() => {
880
- if (!document || !documentMeta?.availableLocales) {
881
- return [[], {}];
882
- }
883
- const rowsFromMeta = documentMeta?.availableLocales.map((doc) => {
884
- const { locale, status } = doc;
885
- return { locale, status };
886
- });
887
- rowsFromMeta.unshift({
888
- locale: document.locale,
889
- status: document.status
890
- });
891
- const allDocuments = [document, ...documentMeta?.availableLocales ?? []];
892
- const errors = allDocuments.reduce((errs, document2) => {
893
- if (!document2) {
894
- return errs;
895
- }
896
- const validation = validate(document2);
897
- if (validation !== null) {
898
- errs[document2.locale] = validation;
899
- }
900
- return errs;
901
- }, {});
902
- return [rowsFromMeta, errors];
903
- }, [document, documentMeta?.availableLocales, validate]);
904
- const isBulkPublish = action === "bulk-publish";
905
- const localesForAction = selectedRows.reduce((acc, selectedRow) => {
906
- const isValidLocale = (
907
- // Validation errors are irrelevant if we are trying to unpublish
908
- !isBulkPublish || !Object.keys(validationErrors).includes(selectedRow.locale)
909
- );
910
- const shouldAddLocale = isBulkPublish ? selectedRow.status !== "published" && isValidLocale : selectedRow.status !== "draft" && isValidLocale;
911
- if (shouldAddLocale) {
912
- acc.push(selectedRow.locale);
913
- }
914
- return acc;
915
- }, []);
916
- const enableDraftRelationsCount = false;
917
- const {
918
- data: draftRelationsCount = 0,
919
- isLoading: isDraftRelationsLoading,
920
- error: isDraftRelationsError
921
- } = useGetManyDraftRelationCountQuery(
922
- {
923
- model,
924
- documentIds: [documentId],
925
- locale: localesForAction
926
- },
927
- {
928
- skip: !enableDraftRelationsCount
929
- }
930
- );
931
- React__namespace.useEffect(() => {
932
- if (isDraftRelationsError) {
933
- toggleNotification({
934
- type: "danger",
935
- message: formatAPIError(isDraftRelationsError)
936
- });
937
- }
938
- }, [isDraftRelationsError, toggleNotification, formatAPIError]);
939
- if (!schema?.options?.draftAndPublish) {
940
- return null;
941
- }
942
- if (!hasI18n) {
943
- return null;
944
- }
945
- if (!documentId) {
946
- return null;
947
- }
948
- const publish = async () => {
949
- await publishManyAction({
950
- model,
951
- documentIds: [documentId],
952
- params: {
953
- ...params,
954
- locale: localesForAction
955
- }
956
- });
957
- setSelectedRows([]);
958
- };
959
- const unpublish = async () => {
960
- await unpublishManyAction({
961
- model,
962
- documentIds: [documentId],
963
- params: {
964
- ...params,
965
- locale: localesForAction
966
- }
967
- });
968
- setSelectedRows([]);
969
- };
970
- const handleAction = async () => {
971
- if (draftRelationsCount > 0) {
972
- setIsDraftRelationConfirmationOpen(true);
973
- } else if (isBulkPublish) {
974
- await publish();
975
- } else {
976
- await unpublish();
977
- }
978
- };
979
- if (isDraftRelationConfirmationOpen) {
980
- return {
981
- label: formatMessage({
982
- id: "app.components.ConfirmDialog.title",
983
- defaultMessage: "Confirmation"
984
- }),
985
- variant: "danger",
986
- dialog: {
987
- onCancel: () => {
988
- setIsDraftRelationConfirmationOpen(false);
989
- },
990
- onConfirm: async () => {
991
- await publish();
992
- setIsDraftRelationConfirmationOpen(false);
993
- },
994
- type: "dialog",
995
- title: formatMessage({
996
- id: getTranslation("actions.publish.dialog.title"),
997
- defaultMessage: "Confirmation"
998
- }),
999
- content: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", alignItems: "center", gap: 2, children: [
1000
- /* @__PURE__ */ jsxRuntime.jsx(icons.WarningCircle, { width: "2.4rem", height: "2.4rem", fill: "danger600" }),
1001
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textAlign: "center", children: formatMessage({
1002
- id: getTranslation("CMEditViewBulkLocale.draft-relation-warning"),
1003
- defaultMessage: "Some locales are related to draft entries. Publishing them could leave broken links in your app."
1004
- }) }),
1005
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textAlign: "center", children: formatMessage({
1006
- id: getTranslation("CMEditViewBulkLocale.continue-confirmation"),
1007
- defaultMessage: "Are you sure you want to continue?"
1008
- }) })
1009
- ] })
1010
- }
1011
- };
1012
- }
1013
- const hasPermission = selectedRows.map(({ locale }) => locale).every((locale) => canPublish.includes(locale));
1014
- return {
1015
- label: formatMessage({
1016
- id: getTranslation(`CMEditViewBulkLocale.${isBulkPublish ? "publish" : "unpublish"}-title`),
1017
- defaultMessage: `${isBulkPublish ? "Publish" : "Unpublish"} Multiple Locales`
1018
- }),
1019
- variant: isBulkPublish ? "secondary" : "danger",
1020
- icon: isBulkPublish ? /* @__PURE__ */ jsxRuntime.jsx(icons.ListPlus, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.Cross, {}),
1021
- disabled: isOnPublishedTab || canPublish.length === 0,
1022
- position: ["panel"],
1023
- dialog: {
1024
- type: "modal",
1025
- title: formatMessage({
1026
- id: getTranslation(`CMEditViewBulkLocale.${isBulkPublish ? "publish" : "unpublish"}-title`),
1027
- defaultMessage: `${isBulkPublish ? "Publish" : "Unpublish"} Multiple Locales`
1028
- }),
1029
- content: () => {
1030
- return /* @__PURE__ */ jsxRuntime.jsx(
1031
- strapiAdmin.Table.Root,
1032
- {
1033
- headers,
1034
- rows: rows.map((row) => ({
1035
- ...row,
1036
- id: row.locale
1037
- })),
1038
- selectedRows,
1039
- onSelectedRowsChange: (tableSelectedRows) => setSelectedRows(tableSelectedRows),
1040
- children: /* @__PURE__ */ jsxRuntime.jsx(
1041
- BulkLocaleActionModal,
1042
- {
1043
- validationErrors,
1044
- headers,
1045
- rows,
1046
- localesMetadata,
1047
- action: action ?? "bulk-publish"
1048
- }
1049
- )
1050
- }
1051
- );
1052
- },
1053
- footer: () => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Modal.Footer, { justifyContent: "flex-end", children: /* @__PURE__ */ jsxRuntime.jsx(
1054
- designSystem.Button,
1055
- {
1056
- loading: isDraftRelationsLoading,
1057
- disabled: !hasPermission || localesForAction.length === 0,
1058
- variant: "default",
1059
- onClick: handleAction,
1060
- children: formatMessage({
1061
- id: isBulkPublish ? "app.utils.publish" : "app.utils.unpublish",
1062
- defaultMessage: isBulkPublish ? "Publish" : "Unpublish"
1063
- })
1064
- }
1065
- ) })
1066
- }
1067
- };
1068
- };
1069
- const BulkLocalePublishAction = (props) => {
1070
- return BulkLocaleAction({ action: "bulk-publish", ...props });
1071
- };
1072
- const BulkLocaleUnpublishAction = (props) => {
1073
- return BulkLocaleAction({ action: "bulk-unpublish", ...props });
1074
- };
1075
- const StyledTrash = styledComponents.styled(icons.Trash)`
1076
- path {
1077
- fill: currentColor;
1078
- }
1079
- `;
1080
- const Emphasis = (chunks) => {
1081
- return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { fontWeight: "semiBold", textColor: "danger500", children: chunks });
1082
- };
1083
- const DeleteModalAdditionalInfo = () => {
1084
- const { hasI18n } = useI18n();
1085
- const { formatMessage } = reactIntl.useIntl();
1086
- if (!hasI18n) {
1087
- return null;
1088
- }
1089
- return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "danger500", children: formatMessage(
1090
- {
1091
- id: getTranslation("Settings.list.actions.deleteAdditionalInfos"),
1092
- defaultMessage: "This will delete the active locale versions <em>(from Internationalization)</em>"
1093
- },
1094
- {
1095
- em: Emphasis
1096
- }
1097
- ) });
1098
- };
1099
- const PublishModalAdditionalInfo = () => {
1100
- const { hasI18n } = useI18n();
1101
- const { formatMessage } = reactIntl.useIntl();
1102
- if (!hasI18n) {
1103
- return null;
1104
- }
1105
- return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "danger500", children: formatMessage(
1106
- {
1107
- id: getTranslation("Settings.list.actions.publishAdditionalInfos"),
1108
- defaultMessage: "This will publish the active locale versions <em>(from Internationalization)</em>"
1109
- },
1110
- {
1111
- em: Emphasis
1112
- }
1113
- ) });
1114
- };
1115
- const UnpublishModalAdditionalInfo = () => {
1116
- const { hasI18n } = useI18n();
1117
- const { formatMessage } = reactIntl.useIntl();
1118
- if (!hasI18n) {
1119
- return null;
1120
- }
1121
- return /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "danger500", children: formatMessage(
1122
- {
1123
- id: getTranslation("Settings.list.actions.unpublishAdditionalInfos"),
1124
- defaultMessage: "This will unpublish the active locale versions <em>(from Internationalization)</em>"
1125
- },
1126
- {
1127
- em: Emphasis
1128
- }
1129
- ) });
1130
- };
1131
- const LocalePicker = () => {
1132
- const { formatMessage } = reactIntl.useIntl();
1133
- const [{ query: query2 }, setQuery] = strapiAdmin.useQueryParams();
1134
- const { hasI18n, canRead, canCreate } = useI18n();
1135
- const { data: locales = [] } = useGetLocalesQuery(void 0, {
1136
- skip: !hasI18n
1137
- });
1138
- const handleChange = React__namespace.useCallback(
1139
- (code, replace = false) => {
1140
- setQuery(
1141
- {
1142
- page: 1,
1143
- plugins: { ...query2.plugins, i18n: { locale: code } }
1144
- },
1145
- "push",
1146
- replace
1147
- );
1148
- },
1149
- [query2.plugins, setQuery]
1150
- );
1151
- React__namespace.useEffect(() => {
1152
- if (!Array.isArray(locales) || !hasI18n) {
1153
- return;
1154
- }
1155
- const currentDesiredLocale = query2.plugins?.i18n?.locale;
1156
- const doesLocaleExist = locales.find((loc) => loc.code === currentDesiredLocale);
1157
- const defaultLocale = locales.find((locale) => locale.isDefault);
1158
- if (!doesLocaleExist && defaultLocale?.code) {
1159
- handleChange(defaultLocale.code, true);
1160
- }
1161
- }, [hasI18n, handleChange, locales, query2.plugins?.i18n?.locale]);
1162
- if (!hasI18n || !Array.isArray(locales) || locales.length === 0) {
1163
- return null;
1164
- }
1165
- const displayedLocales = locales.filter((locale) => {
1166
- return canCreate.includes(locale.code) || canRead.includes(locale.code);
1167
- });
1168
- return /* @__PURE__ */ jsxRuntime.jsx(
1169
- designSystem.SingleSelect,
1170
- {
1171
- size: "S",
1172
- "aria-label": formatMessage({
1173
- id: getTranslation("actions.select-locale"),
1174
- defaultMessage: "Select locale"
1175
- }),
1176
- value: query2.plugins?.i18n?.locale || locales.find((locale) => locale.isDefault)?.code,
1177
- onChange: handleChange,
1178
- children: displayedLocales.map((locale) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: locale.code, children: locale.name }, locale.id))
1179
- }
1180
- );
1181
- };
1182
- const PERMISSIONS = {
1183
- accessMain: [{ action: "plugin::i18n.locale.read", subject: null }],
1184
- create: [{ action: "plugin::i18n.locale.create", subject: null }],
1185
- delete: [{ action: "plugin::i18n.locale.delete", subject: null }],
1186
- update: [{ action: "plugin::i18n.locale.update", subject: null }],
1187
- read: [{ action: "plugin::i18n.locale.read", subject: null }]
1188
- };
1189
- const mutateEditViewHook = ({ layout }) => {
1190
- if (!("i18n" in layout.options) || typeof layout.options.i18n === "object" && layout.options.i18n !== null && "localized" in layout.options.i18n && !layout.options.i18n.localized) {
1191
- return { layout };
1192
- }
1193
- const components = Object.entries(layout.components).reduce(
1194
- (acc, [key, componentLayout]) => {
1195
- return {
1196
- ...acc,
1197
- [key]: {
1198
- ...componentLayout,
1199
- layout: componentLayout.layout.map((row) => row.map(addLabelActionToField))
1200
- }
1201
- };
1202
- },
1203
- {}
1204
- );
1205
- return {
1206
- layout: {
1207
- ...layout,
1208
- components,
1209
- layout: layout.layout.map((panel) => panel.map((row) => row.map(addLabelActionToField)))
1210
- }
1211
- };
1212
- };
1213
- const addLabelActionToField = (field) => {
1214
- const isFieldLocalized = doesFieldHaveI18nPluginOpt(field.attribute.pluginOptions) ? field.attribute.pluginOptions.i18n.localized : true;
1215
- const labelActionProps = {
1216
- title: {
1217
- id: isFieldLocalized ? getTranslation("Field.localized") : getTranslation("Field.not-localized"),
1218
- defaultMessage: isFieldLocalized ? "This value is unique for the selected locale" : "This value is the same across all locales"
1219
- },
1220
- icon: isFieldLocalized ? /* @__PURE__ */ jsxRuntime.jsx(icons.Earth, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.EarthStriked, {})
1221
- };
1222
- return {
1223
- ...field,
1224
- labelAction: /* @__PURE__ */ jsxRuntime.jsx(LabelAction, { ...labelActionProps })
1225
- };
1226
- };
1227
- const doesFieldHaveI18nPluginOpt = (pluginOpts) => {
1228
- if (!pluginOpts) {
1229
- return false;
1230
- }
1231
- return "i18n" in pluginOpts && typeof pluginOpts.i18n === "object" && pluginOpts.i18n !== null && "localized" in pluginOpts.i18n;
1232
- };
1233
- const LabelAction = ({ title, icon }) => {
1234
- const { formatMessage } = reactIntl.useIntl();
1235
- return /* @__PURE__ */ jsxRuntime.jsxs(Span, { tag: "span", children: [
1236
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.VisuallyHidden, { tag: "span", children: formatMessage(title) }),
1237
- React__namespace.cloneElement(icon, {
1238
- "aria-hidden": true,
1239
- focusable: false
1240
- // See: https://allyjs.io/tutorials/focusing-in-svg.html#making-svg-elements-focusable
1241
- })
1242
- ] });
1243
- };
1244
- const Span = styledComponents.styled(designSystem.Flex)`
1245
- svg {
1246
- width: 12px;
1247
- height: 12px;
1248
-
1249
- fill: ${({ theme }) => theme.colors.neutral500};
1250
-
1251
- path {
1252
- fill: ${({ theme }) => theme.colors.neutral500};
1253
- }
1254
- }
1255
- `;
1256
- const LocaleListCell = ({
1257
- documentId,
1258
- locale: currentLocale,
1259
- collectionType,
1260
- model
1261
- }) => {
1262
- const { meta, isLoading } = strapiAdmin$1.unstable_useDocument({
1263
- documentId,
1264
- collectionType,
1265
- model,
1266
- params: {
1267
- locale: currentLocale
1268
- }
1269
- });
1270
- const { locale: language } = reactIntl.useIntl();
1271
- const { data: locales = [] } = useGetLocalesQuery();
1272
- const formatter = designSystem.useCollator(language, {
1273
- sensitivity: "base"
1274
- });
1275
- if (!Array.isArray(locales) || isLoading) {
1276
- return null;
1277
- }
1278
- const availableLocales = meta?.availableLocales.map((doc) => doc.locale) ?? [];
1279
- const localesForDocument = locales.reduce((acc, locale) => {
1280
- const createdLocale = [currentLocale, ...availableLocales].find((loc) => {
1281
- return loc === locale.code;
1282
- });
1283
- if (createdLocale) {
1284
- acc.push(locale);
1285
- }
1286
- return acc;
1287
- }, []).map((locale) => {
1288
- if (locale.isDefault) {
1289
- return `${locale.name} (default)`;
1290
- }
1291
- return locale.name;
1292
- }).toSorted((a, b) => formatter.compare(a, b));
1293
- return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Popover.Root, { children: [
1294
- /* @__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: [
1295
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral800", ellipsis: true, marginRight: 2, children: localesForDocument.join(", ") }),
1296
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { children: /* @__PURE__ */ jsxRuntime.jsx(icons.CaretDown, { width: "1.2rem", height: "1.2rem" }) })
1297
- ] }) }) }),
1298
- /* @__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)) }) })
1299
- ] });
1300
- };
1301
- const addColumnToTableHook = ({ displayedHeaders, layout }) => {
1302
- const { options } = layout;
1303
- const isFieldLocalized = doesPluginOptionsHaveI18nLocalized(options) ? options.i18n.localized : false;
1304
- if (!isFieldLocalized) {
1305
- return { displayedHeaders, layout };
1306
- }
1307
- return {
1308
- displayedHeaders: [
1309
- ...displayedHeaders,
1310
- {
1311
- attribute: { type: "string" },
1312
- label: {
1313
- id: getTranslation("list-view.table.header.label"),
1314
- defaultMessage: "Available in"
1315
- },
1316
- searchable: false,
1317
- sortable: false,
1318
- name: "locales",
1319
- // @ts-expect-error – ID is seen as number | string; this will change when we move the type over.
1320
- cellFormatter: (props, _header, meta) => /* @__PURE__ */ jsxRuntime.jsx(LocaleListCell, { ...props, ...meta })
1321
- }
1322
- ],
1323
- layout
1324
- };
1325
- };
1326
- const addLocaleToReleasesHook = ({ displayedHeaders = [] }) => {
1327
- return {
1328
- displayedHeaders: [
1329
- ...displayedHeaders,
1330
- {
1331
- label: {
1332
- id: "content-releases.page.ReleaseDetails.table.header.label.locale",
1333
- defaultMessage: "locale"
1334
- },
1335
- name: "locale"
1336
- }
1337
- ],
1338
- hasI18nEnabled: true
1339
- };
1340
- };
1341
- const extendCTBAttributeInitialDataMiddleware = () => {
1342
- return ({ getState }) => (next) => (action) => {
1343
- const enhanceAction = () => {
1344
- try {
1345
- const store = getState();
1346
- const hasi18nEnabled = get__default.default(
1347
- store,
1348
- [
1349
- "content-type-builder_dataManagerProvider",
1350
- "modifiedData",
1351
- "contentType",
1352
- "schema",
1353
- "pluginOptions",
1354
- "i18n",
1355
- "localized"
1356
- ],
1357
- false
1358
- );
1359
- if (hasi18nEnabled) {
1360
- const pluginOptions = action.options ? { ...action.options.pluginOptions, i18n: { localized: true } } : { i18n: { localized: true } };
1361
- return next({
1362
- ...action,
1363
- options: {
1364
- pluginOptions
1365
- }
1366
- });
1367
- }
1368
- return next(action);
1369
- } catch (err) {
1370
- return next(action);
1371
- }
1372
- };
1373
- if (action.type === "ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA" && action.forTarget === "contentType" && !["relation", "component"].includes(action.attributeType) && !action.isEditing) {
1374
- return enhanceAction();
1375
- }
1376
- if (action.type === "ContentTypeBuilder/FormModal/SET_CUSTOM_FIELD_DATA_SCHEMA" && action.forTarget === "contentType" && !action.isEditing) {
1377
- return enhanceAction();
1378
- }
1379
- 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") {
1380
- return enhanceAction();
1381
- }
1382
- return next(action);
1383
- };
1384
- };
1385
- const extendCTBInitialDataMiddleware = () => {
1386
- return () => (next) => (action) => {
1387
- if (action.type === "ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT" && action.modalType === "contentType") {
1388
- const i18n = { localized: false };
1389
- const pluginOptions = action.data.pluginOptions ? { ...action.data.pluginOptions, i18n } : { i18n };
1390
- const data = { ...action.data, pluginOptions };
1391
- if (action.actionType === "create") {
1392
- return next({ ...action, data });
1393
- }
1394
- if (!action.data.pluginOptions?.i18n?.localized) {
1395
- return next({ ...action, data });
1396
- }
1397
- }
1398
- return next(action);
1399
- };
1400
- };
1401
- const localeMiddleware = (ctx) => (next) => (permissions) => {
1402
- const match = reactRouterDom.matchPath("/content-manager/:collectionType/:model?/:id", ctx.pathname);
1403
- if (!match) {
1404
- return next(permissions);
1405
- }
1406
- const search = qs__namespace.parse(ctx.search);
1407
- if (typeof search !== "object") {
1408
- return next(permissions);
1409
- }
1410
- if (!("plugins" in search && typeof search.plugins === "object")) {
1411
- return next(permissions);
1412
- }
1413
- if (!("i18n" in search.plugins && typeof search.plugins.i18n === "object" && !Array.isArray(search.plugins.i18n))) {
1414
- return next(permissions);
1415
- }
1416
- const { locale } = search.plugins.i18n;
1417
- if (typeof locale !== "string") {
1418
- return next(permissions);
1419
- }
1420
- const revisedPermissions = permissions.filter(
1421
- (permission) => !permission.properties?.locales || permission.properties.locales.includes(locale)
1422
- );
1423
- return next(revisedPermissions);
1424
- };
1425
- const prefixPluginTranslations = (trad, pluginId2) => {
1426
- return Object.keys(trad).reduce((acc, current) => {
1427
- acc[`${pluginId2}.${current}`] = trad[current];
1428
- return acc;
1429
- }, {});
1430
- };
1431
- const mutateCTBContentTypeSchema = (nextSchema, prevSchema) => {
1432
- if (!doesPluginOptionsHaveI18nLocalized(nextSchema.pluginOptions)) {
1433
- return nextSchema;
1434
- }
1435
- const isNextSchemaLocalized = nextSchema.pluginOptions.i18n.localized;
1436
- const isPrevSchemaLocalized = doesPluginOptionsHaveI18nLocalized(
1437
- prevSchema?.schema?.pluginOptions
1438
- ) ? prevSchema?.schema?.pluginOptions.i18n.localized : false;
1439
- if (isNextSchemaLocalized && isPrevSchemaLocalized) {
1440
- return nextSchema;
1441
- }
1442
- if (isNextSchemaLocalized) {
1443
- const attributes = addLocalisationToFields(nextSchema.attributes);
1444
- return { ...nextSchema, attributes };
1445
- }
1446
- if (!isNextSchemaLocalized) {
1447
- const pluginOptions = omit__default.default(nextSchema.pluginOptions, "i18n");
1448
- const attributes = disableAttributesLocalisation(nextSchema.attributes);
1449
- return { ...nextSchema, pluginOptions, attributes };
1450
- }
1451
- return nextSchema;
1452
- };
1453
- const addLocalisationToFields = (attributes) => Object.keys(attributes).reduce((acc, current) => {
1454
- const currentAttribute = attributes[current];
1455
- if (LOCALIZED_FIELDS.includes(currentAttribute.type)) {
1456
- const i18n = { localized: true };
1457
- const pluginOptions = currentAttribute.pluginOptions ? { ...currentAttribute.pluginOptions, i18n } : { i18n };
1458
- acc[current] = { ...currentAttribute, pluginOptions };
1459
- return acc;
1460
- }
1461
- acc[current] = currentAttribute;
1462
- return acc;
1463
- }, {});
1464
- const disableAttributesLocalisation = (attributes) => Object.keys(attributes).reduce((acc, current) => {
1465
- acc[current] = omit__default.default(attributes[current], "pluginOptions.i18n");
1466
- return acc;
1467
- }, {});
1468
- const index = {
1469
- register(app) {
1470
- app.addMiddlewares([extendCTBAttributeInitialDataMiddleware, extendCTBInitialDataMiddleware]);
1471
- app.addMiddlewares([() => i18nApi.middleware]);
1472
- app.addReducers({
1473
- [i18nApi.reducerPath]: i18nApi.reducer
1474
- });
1475
- app.addRBACMiddleware([localeMiddleware]);
1476
- app.registerPlugin({
1477
- id: pluginId,
1478
- name: pluginId
1479
- });
1480
- },
1481
- bootstrap(app) {
1482
- app.registerHook("Admin/CM/pages/ListView/inject-column-in-table", addColumnToTableHook);
1483
- app.registerHook("Admin/CM/pages/EditView/mutate-edit-view-layout", mutateEditViewHook);
1484
- app.registerHook(
1485
- "ContentReleases/pages/ReleaseDetails/add-locale-in-releases",
1486
- addLocaleToReleasesHook
1487
- );
1488
- app.addSettingsLink("global", {
1489
- intlLabel: {
1490
- id: getTranslation("plugin.name"),
1491
- defaultMessage: "Internationalization"
1492
- },
1493
- id: "internationalization",
1494
- to: "internationalization",
1495
- Component: () => Promise.resolve().then(() => require("./SettingsPage-Bcj7380u.js")).then((mod) => ({ default: mod.ProtectedSettingsPage })),
1496
- permissions: PERMISSIONS.accessMain
1497
- });
1498
- const contentManager = app.getPlugin("content-manager");
1499
- contentManager.apis.addDocumentHeaderAction([LocalePickerAction, FillFromAnotherLocaleAction]);
1500
- contentManager.apis.addDocumentAction((actions) => {
1501
- const indexOfDeleteAction = actions.findIndex((action) => action.type === "delete");
1502
- actions.splice(indexOfDeleteAction, 0, DeleteLocaleAction);
1503
- return actions;
1504
- });
1505
- contentManager.apis.addDocumentAction((actions) => {
1506
- actions.splice(2, 0, BulkLocalePublishAction);
1507
- actions.splice(5, 0, BulkLocaleUnpublishAction);
1508
- return actions;
1509
- });
1510
- contentManager.injectComponent("listView", "actions", {
1511
- name: "i18n-locale-filter",
1512
- Component: LocalePicker
1513
- });
1514
- contentManager.injectComponent("listView", "publishModalAdditionalInfos", {
1515
- name: "i18n-publish-bullets-in-modal",
1516
- Component: PublishModalAdditionalInfo
1517
- });
1518
- contentManager.injectComponent("listView", "unpublishModalAdditionalInfos", {
1519
- name: "i18n-unpublish-bullets-in-modal",
1520
- Component: UnpublishModalAdditionalInfo
1521
- });
1522
- contentManager.injectComponent("listView", "deleteModalAdditionalInfos", {
1523
- name: "i18n-delete-bullets-in-modal",
1524
- Component: DeleteModalAdditionalInfo
1525
- });
1526
- const ctbPlugin = app.getPlugin("content-type-builder");
1527
- if (ctbPlugin) {
1528
- const ctbFormsAPI = ctbPlugin.apis.forms;
1529
- ctbFormsAPI.addContentTypeSchemaMutation(mutateCTBContentTypeSchema);
1530
- ctbFormsAPI.components.add({ id: "checkboxConfirmation", component: CheckboxConfirmation });
1531
- ctbFormsAPI.extendContentType({
1532
- validator: () => ({
1533
- i18n: yup__namespace.object().shape({
1534
- localized: yup__namespace.bool()
1535
- })
1536
- }),
1537
- form: {
1538
- advanced() {
1539
- return [
1540
- {
1541
- name: "pluginOptions.i18n.localized",
1542
- description: {
1543
- id: getTranslation("plugin.schema.i18n.localized.description-content-type"),
1544
- defaultMessage: "Allows translating an entry into different languages"
1545
- },
1546
- type: "checkboxConfirmation",
1547
- intlLabel: {
1548
- id: getTranslation("plugin.schema.i18n.localized.label-content-type"),
1549
- defaultMessage: "Localization"
1550
- }
1551
- }
1552
- ];
1553
- }
1554
- }
1555
- });
1556
- ctbFormsAPI.extendFields(LOCALIZED_FIELDS, {
1557
- validator: (args) => ({
1558
- i18n: yup__namespace.object().shape({
1559
- localized: yup__namespace.bool().test({
1560
- name: "ensure-unique-localization",
1561
- message: getTranslation("plugin.schema.i18n.ensure-unique-localization"),
1562
- test(value) {
1563
- if (value === void 0 || value) {
1564
- return true;
1565
- }
1566
- const unique = get__default.default(args, ["3", "modifiedData", "unique"], null);
1567
- if (unique && !value) {
1568
- return false;
1569
- }
1570
- return true;
1571
- }
1572
- })
1573
- })
1574
- }),
1575
- form: {
1576
- advanced({ contentTypeSchema, forTarget, type, step }) {
1577
- if (forTarget !== "contentType") {
1578
- return [];
1579
- }
1580
- const hasI18nEnabled = get__default.default(
1581
- contentTypeSchema,
1582
- ["schema", "pluginOptions", "i18n", "localized"],
1583
- false
1584
- );
1585
- if (!hasI18nEnabled) {
1586
- return [];
1587
- }
1588
- if (type === "component" && step === "1") {
1589
- return [];
1590
- }
1591
- return [
1592
- {
1593
- name: "pluginOptions.i18n.localized",
1594
- description: {
1595
- id: getTranslation("plugin.schema.i18n.localized.description-field"),
1596
- defaultMessage: "The field can have different values in each locale"
1597
- },
1598
- type: "checkbox",
1599
- intlLabel: {
1600
- id: getTranslation("plugin.schema.i18n.localized.label-field"),
1601
- defaultMessage: "Enable localization for this field"
1602
- }
1603
- }
1604
- ];
1605
- }
1606
- }
1607
- });
1608
- }
1609
- },
1610
- async registerTrads({ locales }) {
1611
- const importedTrads = await Promise.all(
1612
- locales.map((locale) => {
1613
- 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 }) => {
1614
- return {
1615
- data: prefixPluginTranslations(data, pluginId),
1616
- locale
1617
- };
1618
- }).catch(() => {
1619
- return {
1620
- data: {},
1621
- locale
1622
- };
1623
- });
1624
- })
1625
- );
1626
- return Promise.resolve(importedTrads);
1627
- }
1628
- };
1629
- exports.PERMISSIONS = PERMISSIONS;
1630
- exports.getTranslation = getTranslation;
1631
- exports.index = index;
1632
- exports.useCreateLocaleMutation = useCreateLocaleMutation;
1633
- exports.useDeleteLocaleMutation = useDeleteLocaleMutation;
1634
- exports.useGetDefaultLocalesQuery = useGetDefaultLocalesQuery;
1635
- exports.useGetLocalesQuery = useGetLocalesQuery;
1636
- exports.useUpdateLocaleMutation = useUpdateLocaleMutation;
1637
- //# sourceMappingURL=index-BKZbxhpm.js.map