@strapi/i18n 0.0.0-experimental.e9122b401c96877b6707775c4f893660eab93ae3 → 0.0.0-experimental.e9144fc8a193f9875a2c0832d689c14001c79f00

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