@strapi/i18n 0.0.0-next.d6ed4fcf2c833656b8c91a90909c1e77c79379e5 → 0.0.0-next.e61eff51f9834ffdef16bdc236aecab5f837723b

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