@strapi/i18n 0.0.0-experimental.78b47df46708173ab4833373f694257729db4b9e → 0.0.0-experimental.7b579e6415ea4434ccb2c2aa52a86b67ff2e7a64

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