@strapi/i18n 0.0.0-experimental.1610404a03d98b65f497f9adda35815021b8fd76 → 0.0.0-experimental.16cb0821de17dd12078d915e3a10249158807e5e

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