@strapi/i18n 0.0.0-next.959c5589d0d3efa25d7ca014656d9ff48c173399 → 0.0.0-next.9e9a841899e6378b6f48ab8f419e4b0cc62bdf32

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