@strapi/i18n 0.0.0-next.7f1333f1967e625c57ab16648c057aea08c9dddb → 0.0.0-next.80103017ad0134c4681c5b742cfd24091a839446

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