@strapi/i18n 0.0.0-experimental.d834c9e658d1fb037e6da1105150593521c667cc → 0.0.0-experimental.da0467de7eccc163e893e9b332505a79a5d52ec7

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