@strapi/i18n 0.0.0-experimental.dd3311938ac827f1fa8560c8840a9a394f5896c0 → 0.0.0-experimental.ddb35414098c2a2816cae28a6abd5be1c4d8a58a

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 (156) hide show
  1. package/LICENSE +18 -3
  2. package/dist/admin/chunks/SettingsPage-B6ikxVOg.js +820 -0
  3. package/dist/admin/chunks/SettingsPage-B6ikxVOg.js.map +1 -0
  4. package/dist/admin/chunks/SettingsPage-Kg4GAThm.js +797 -0
  5. package/dist/admin/chunks/SettingsPage-Kg4GAThm.js.map +1 -0
  6. package/dist/admin/chunks/de-Cm8mYdaO.js +64 -0
  7. package/dist/admin/chunks/de-Cm8mYdaO.js.map +1 -0
  8. package/dist/admin/chunks/de-nEMWvIiY.js +66 -0
  9. package/dist/admin/chunks/de-nEMWvIiY.js.map +1 -0
  10. package/dist/admin/chunks/dk-BeUFOegB.js +64 -0
  11. package/dist/admin/chunks/dk-BeUFOegB.js.map +1 -0
  12. package/dist/admin/chunks/dk-CYATLPVe.js +66 -0
  13. package/dist/admin/chunks/dk-CYATLPVe.js.map +1 -0
  14. package/dist/admin/chunks/en-CG5cUCbD.js +81 -0
  15. package/dist/admin/chunks/en-CG5cUCbD.js.map +1 -0
  16. package/dist/admin/chunks/en-eWSaCeOb.js +79 -0
  17. package/dist/admin/chunks/en-eWSaCeOb.js.map +1 -0
  18. package/dist/admin/chunks/es-CWsogTGm.js +66 -0
  19. package/dist/admin/chunks/es-CWsogTGm.js.map +1 -0
  20. package/dist/admin/chunks/es-DqF_IdAc.js +64 -0
  21. package/dist/admin/chunks/es-DqF_IdAc.js.map +1 -0
  22. package/dist/admin/chunks/fr-CC7UFcYd.js +66 -0
  23. package/dist/admin/chunks/fr-CC7UFcYd.js.map +1 -0
  24. package/dist/admin/chunks/fr-CyARbZ3c.js +64 -0
  25. package/dist/admin/chunks/fr-CyARbZ3c.js.map +1 -0
  26. package/dist/admin/chunks/index-Dch-2xao.js +2035 -0
  27. package/dist/admin/chunks/index-Dch-2xao.js.map +1 -0
  28. package/dist/admin/chunks/index-DyvbIjH9.js +2006 -0
  29. package/dist/admin/chunks/index-DyvbIjH9.js.map +1 -0
  30. package/dist/admin/chunks/ko-Ax4NSedM.js +63 -0
  31. package/dist/admin/chunks/ko-Ax4NSedM.js.map +1 -0
  32. package/dist/admin/chunks/ko-XwGmfhoq.js +65 -0
  33. package/dist/admin/chunks/ko-XwGmfhoq.js.map +1 -0
  34. package/dist/admin/chunks/pl-B-aqvMqL.js +64 -0
  35. package/dist/admin/chunks/pl-B-aqvMqL.js.map +1 -0
  36. package/dist/admin/chunks/pl-B_vzY_ZB.js +66 -0
  37. package/dist/admin/chunks/pl-B_vzY_ZB.js.map +1 -0
  38. package/dist/admin/chunks/ru-VkPjQ-Sk.js +66 -0
  39. package/dist/admin/chunks/ru-VkPjQ-Sk.js.map +1 -0
  40. package/dist/admin/chunks/ru-WzHcJV1f.js +68 -0
  41. package/dist/admin/chunks/ru-WzHcJV1f.js.map +1 -0
  42. package/dist/admin/chunks/tr-CcWp6u3w.js +66 -0
  43. package/dist/admin/chunks/tr-CcWp6u3w.js.map +1 -0
  44. package/dist/admin/chunks/tr-DcTR88c9.js +64 -0
  45. package/dist/admin/chunks/tr-DcTR88c9.js.map +1 -0
  46. package/dist/admin/chunks/zh-C9So4SGq.js +66 -0
  47. package/dist/admin/chunks/zh-C9So4SGq.js.map +1 -0
  48. package/dist/admin/chunks/zh-Hans-DnU2bhri.js +57 -0
  49. package/dist/admin/chunks/zh-Hans-DnU2bhri.js.map +1 -0
  50. package/dist/admin/chunks/zh-Hans-L3wsRegj.js +55 -0
  51. package/dist/admin/chunks/zh-Hans-L3wsRegj.js.map +1 -0
  52. package/dist/admin/chunks/zh-RZyMiPIs.js +64 -0
  53. package/dist/admin/chunks/zh-RZyMiPIs.js.map +1 -0
  54. package/dist/admin/index.js +20 -4
  55. package/dist/admin/index.js.map +1 -1
  56. package/dist/admin/index.mjs +15 -6
  57. package/dist/admin/index.mjs.map +1 -1
  58. package/dist/admin/src/components/BulkLocaleActionModal.d.ts +2 -1
  59. package/dist/admin/src/components/CMHeaderActions.d.ts +30 -4
  60. package/dist/admin/src/components/CreateLocale.d.ts +6 -6
  61. package/dist/admin/src/components/EditLocale.d.ts +5 -4
  62. package/dist/admin/src/components/LocaleListCell.d.ts +4 -4
  63. package/dist/admin/src/components/tests/CreateLocale.test.d.ts +1 -0
  64. package/dist/admin/src/components/tests/DeleteLocale.test.d.ts +1 -0
  65. package/dist/admin/src/components/tests/EditLocale.test.d.ts +1 -0
  66. package/dist/admin/src/components/tests/LocaleListCell.test.d.ts +1 -0
  67. package/dist/admin/src/contentReleasesHooks/releaseDetailsView.d.ts +10 -6
  68. package/dist/admin/src/pages/tests/SettingsPage.test.d.ts +1 -0
  69. package/dist/admin/src/utils/clean.d.ts +4 -0
  70. package/dist/admin/src/utils/schemas.d.ts +1 -0
  71. package/dist/admin/tests/server.d.ts +1 -0
  72. package/dist/admin/tests/utils.d.ts +6 -0
  73. package/dist/server/index.js +3658 -3458
  74. package/dist/server/index.js.map +1 -1
  75. package/dist/server/index.mjs +3640 -3441
  76. package/dist/server/index.mjs.map +1 -1
  77. package/dist/server/src/bootstrap.d.ts +1 -4
  78. package/dist/server/src/bootstrap.d.ts.map +1 -1
  79. package/dist/server/src/index.d.ts +21 -13
  80. package/dist/server/src/index.d.ts.map +1 -1
  81. package/dist/server/src/register.d.ts.map +1 -1
  82. package/dist/server/src/services/index.d.ts +20 -10
  83. package/dist/server/src/services/index.d.ts.map +1 -1
  84. package/dist/server/src/services/localizations.d.ts +1 -1
  85. package/dist/server/src/services/localizations.d.ts.map +1 -1
  86. package/dist/server/src/services/permissions/actions.d.ts +14 -2
  87. package/dist/server/src/services/permissions/actions.d.ts.map +1 -1
  88. package/dist/server/src/services/permissions.d.ts +14 -2
  89. package/dist/server/src/services/permissions.d.ts.map +1 -1
  90. package/dist/server/src/services/sanitize/index.d.ts +11 -0
  91. package/dist/server/src/services/sanitize/index.d.ts.map +1 -0
  92. package/dist/server/src/utils/index.d.ts +2 -2
  93. package/dist/server/src/utils/index.d.ts.map +1 -1
  94. package/dist/shared/contracts/content-manager.d.ts +1 -1
  95. package/dist/shared/contracts/shared.d.ts +1 -1
  96. package/package.json +18 -16
  97. package/dist/_chunks/SettingsPage-BWlXRGN7.mjs +0 -567
  98. package/dist/_chunks/SettingsPage-BWlXRGN7.mjs.map +0 -1
  99. package/dist/_chunks/SettingsPage-DjWupAff.js +0 -587
  100. package/dist/_chunks/SettingsPage-DjWupAff.js.map +0 -1
  101. package/dist/_chunks/de-9eCAqqrB.mjs +0 -66
  102. package/dist/_chunks/de-9eCAqqrB.mjs.map +0 -1
  103. package/dist/_chunks/de-DtWiGdHl.js +0 -66
  104. package/dist/_chunks/de-DtWiGdHl.js.map +0 -1
  105. package/dist/_chunks/dk-2qBjxt-P.mjs +0 -66
  106. package/dist/_chunks/dk-2qBjxt-P.mjs.map +0 -1
  107. package/dist/_chunks/dk-D8C-casx.js +0 -66
  108. package/dist/_chunks/dk-D8C-casx.js.map +0 -1
  109. package/dist/_chunks/en-18tWw4P6.mjs +0 -72
  110. package/dist/_chunks/en-18tWw4P6.mjs.map +0 -1
  111. package/dist/_chunks/en-Kv6y9zPQ.js +0 -72
  112. package/dist/_chunks/en-Kv6y9zPQ.js.map +0 -1
  113. package/dist/_chunks/es-DS-XFGSw.js +0 -66
  114. package/dist/_chunks/es-DS-XFGSw.js.map +0 -1
  115. package/dist/_chunks/es-DlmMVaBG.mjs +0 -66
  116. package/dist/_chunks/es-DlmMVaBG.mjs.map +0 -1
  117. package/dist/_chunks/fr-3S6ke71d.mjs +0 -66
  118. package/dist/_chunks/fr-3S6ke71d.mjs.map +0 -1
  119. package/dist/_chunks/fr-BTjekDpq.js +0 -66
  120. package/dist/_chunks/fr-BTjekDpq.js.map +0 -1
  121. package/dist/_chunks/index-D--YX2ZY.js +0 -1410
  122. package/dist/_chunks/index-D--YX2ZY.js.map +0 -1
  123. package/dist/_chunks/index-DVTdCB4M.mjs +0 -1388
  124. package/dist/_chunks/index-DVTdCB4M.mjs.map +0 -1
  125. package/dist/_chunks/ko-DmcGUBQ3.js +0 -65
  126. package/dist/_chunks/ko-DmcGUBQ3.js.map +0 -1
  127. package/dist/_chunks/ko-qTjQ8IMw.mjs +0 -65
  128. package/dist/_chunks/ko-qTjQ8IMw.mjs.map +0 -1
  129. package/dist/_chunks/pl-B67TSHqT.mjs +0 -66
  130. package/dist/_chunks/pl-B67TSHqT.mjs.map +0 -1
  131. package/dist/_chunks/pl-Cn5RYonZ.js +0 -66
  132. package/dist/_chunks/pl-Cn5RYonZ.js.map +0 -1
  133. package/dist/_chunks/ru-BMBgVL3s.js +0 -68
  134. package/dist/_chunks/ru-BMBgVL3s.js.map +0 -1
  135. package/dist/_chunks/ru-hagMa57T.mjs +0 -68
  136. package/dist/_chunks/ru-hagMa57T.mjs.map +0 -1
  137. package/dist/_chunks/tr-CarUU76c.js +0 -66
  138. package/dist/_chunks/tr-CarUU76c.js.map +0 -1
  139. package/dist/_chunks/tr-Dw_jmkG-.mjs +0 -66
  140. package/dist/_chunks/tr-Dw_jmkG-.mjs.map +0 -1
  141. package/dist/_chunks/zh-57YM4amO.mjs +0 -66
  142. package/dist/_chunks/zh-57YM4amO.mjs.map +0 -1
  143. package/dist/_chunks/zh-CukOviB0.js +0 -66
  144. package/dist/_chunks/zh-CukOviB0.js.map +0 -1
  145. package/dist/_chunks/zh-Hans-DSHIXAa3.js +0 -57
  146. package/dist/_chunks/zh-Hans-DSHIXAa3.js.map +0 -1
  147. package/dist/_chunks/zh-Hans-Dyc-aR-h.mjs +0 -57
  148. package/dist/_chunks/zh-Hans-Dyc-aR-h.mjs.map +0 -1
  149. package/dist/admin/src/components/Initializer.d.ts +0 -5
  150. package/dist/server/src/migrations/content-type/disable/index.d.ts +0 -3
  151. package/dist/server/src/migrations/content-type/disable/index.d.ts.map +0 -1
  152. package/dist/server/src/migrations/content-type/enable/index.d.ts +0 -3
  153. package/dist/server/src/migrations/content-type/enable/index.d.ts.map +0 -1
  154. package/dist/server/src/services/entity-service-decorator.d.ts +0 -29
  155. package/dist/server/src/services/entity-service-decorator.d.ts.map +0 -1
  156. package/strapi-server.js +0 -3
@@ -1,1388 +0,0 @@
1
- import get from "lodash/get";
2
- import * as yup from "yup";
3
- import { jsxs, Fragment, jsx } from "react/jsx-runtime";
4
- import * as React from "react";
5
- import { Typography, Field, Checkbox, Dialog, DialogBody, Flex, DialogFooter, Button as Button$1, 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 { useAuth, adminApi, useTable, Table, useQueryParams, useNotification, useAPIErrorHandler } from "@strapi/admin/strapi-admin";
10
- import { unstable_useDocument, unstable_useDocumentActions, buildValidParams } from "@strapi/content-manager/strapi-admin";
11
- import { useParams, Link, useNavigate, matchPath } from "react-router-dom";
12
- import * as qs from "qs";
13
- import { stringify } from "qs";
14
- import omit from "lodash/omit";
15
- const __variableDynamicImportRuntimeHelper = (glob, path) => {
16
- const v = glob[path];
17
- if (v) {
18
- return typeof v === "function" ? v() : Promise.resolve(v);
19
- }
20
- return new Promise((_, reject) => {
21
- (typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(reject.bind(null, new Error("Unknown variable dynamic import: " + path)));
22
- });
23
- };
24
- const pluginId = "i18n";
25
- const getTranslation = (id) => `${pluginId}.${id}`;
26
- const TextAlignTypography = styled(Typography)`
27
- text-align: center;
28
- `;
29
- const CheckboxConfirmation = ({
30
- description,
31
- isCreating = false,
32
- intlLabel,
33
- name,
34
- onChange,
35
- value
36
- }) => {
37
- const { formatMessage } = useIntl();
38
- const [isOpen, setIsOpen] = React.useState(false);
39
- const handleChange = (value2) => {
40
- if (isCreating || value2) {
41
- return onChange({ target: { name, value: value2, type: "checkbox" } });
42
- }
43
- if (!value2) {
44
- return setIsOpen(true);
45
- }
46
- return null;
47
- };
48
- const handleConfirm = () => {
49
- onChange({ target: { name, value: false, type: "checkbox" } });
50
- setIsOpen(false);
51
- };
52
- const handleToggle = () => setIsOpen((prev) => !prev);
53
- const label = intlLabel.id ? formatMessage(
54
- { id: intlLabel.id, defaultMessage: intlLabel.defaultMessage },
55
- { ...intlLabel.values }
56
- ) : name;
57
- const hint = description ? formatMessage(
58
- { id: description.id, defaultMessage: description.defaultMessage },
59
- { ...description.values }
60
- ) : "";
61
- return /* @__PURE__ */ jsxs(Fragment, { children: [
62
- /* @__PURE__ */ jsxs(Field.Root, { hint, name, children: [
63
- /* @__PURE__ */ jsx(Checkbox, { onValueChange: handleChange, value, type: "checkbox", children: label }),
64
- /* @__PURE__ */ jsx(Field.Hint, {})
65
- ] }),
66
- isOpen && /* @__PURE__ */ jsxs(Dialog, { onClose: handleToggle, title: "Confirmation", isOpen, children: [
67
- /* @__PURE__ */ jsx(DialogBody, { icon: /* @__PURE__ */ jsx(WarningCircle, {}), children: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "stretch", gap: 2, children: [
68
- /* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(TextAlignTypography, { id: "confirm-description", children: formatMessage({
69
- id: getTranslation("CheckboxConfirmation.Modal.content"),
70
- defaultMessage: "Disabling localization will engender the deletion of all your content but the one associated to your default locale (if existing)."
71
- }) }) }),
72
- /* @__PURE__ */ jsx(Flex, { justifyContent: "center", children: /* @__PURE__ */ jsx(Typography, { fontWeight: "semiBold", id: "confirm-description", children: formatMessage({
73
- id: getTranslation("CheckboxConfirmation.Modal.body"),
74
- defaultMessage: "Do you want to disable it?"
75
- }) }) })
76
- ] }) }),
77
- /* @__PURE__ */ jsx(
78
- DialogFooter,
79
- {
80
- startAction: /* @__PURE__ */ jsx(Button$1, { onClick: handleToggle, variant: "tertiary", children: formatMessage({
81
- id: "components.popUpWarning.button.cancel",
82
- defaultMessage: "No, cancel"
83
- }) }),
84
- endAction: /* @__PURE__ */ jsx(Button$1, { variant: "danger-light", onClick: handleConfirm, children: formatMessage({
85
- id: getTranslation("CheckboxConfirmation.Modal.button-confirm"),
86
- defaultMessage: "Yes, disable"
87
- }) })
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: !params.slug || !params.collectionType
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(React.Fragment, { 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
- borderWidth: 0,
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 [isConfirmationOpen, setIsConfirmationOpen] = React.useState(false);
544
- const { publishMany: publishManyAction } = unstable_useDocumentActions();
545
- const {
546
- document,
547
- meta: documentMeta,
548
- schema,
549
- validate
550
- } = unstable_useDocument({
551
- model,
552
- collectionType,
553
- documentId,
554
- params: {
555
- locale: baseLocale
556
- }
557
- });
558
- const { data: localesMetadata = [] } = useGetLocalesQuery();
559
- const headers = [
560
- {
561
- label: formatMessage({
562
- id: "global.name",
563
- defaultMessage: "Name"
564
- }),
565
- name: "name"
566
- },
567
- {
568
- label: formatMessage({
569
- id: getTranslation("CMEditViewBulkLocale.status"),
570
- defaultMessage: "Status"
571
- }),
572
- name: "status"
573
- },
574
- {
575
- label: formatMessage({
576
- id: getTranslation("CMEditViewBulkLocale.publication-status"),
577
- defaultMessage: "Publication Status"
578
- }),
579
- name: "publication-status"
580
- }
581
- ];
582
- const [rows, validationErrors] = React.useMemo(() => {
583
- if (!document || !documentMeta?.availableLocales) {
584
- return [[], {}];
585
- }
586
- const rowsFromMeta = documentMeta?.availableLocales.map((doc) => {
587
- const { locale, status } = doc;
588
- return { locale, status };
589
- });
590
- rowsFromMeta.unshift({
591
- locale: document.locale,
592
- status: document.status
593
- });
594
- const allDocuments = [document, ...documentMeta?.availableLocales ?? []];
595
- const errors = allDocuments.reduce((errs, document2) => {
596
- if (!document2) {
597
- return errs;
598
- }
599
- const validation = validate(document2);
600
- if (validation !== null) {
601
- errs[document2.locale] = validation;
602
- }
603
- return errs;
604
- }, {});
605
- return [rowsFromMeta, errors];
606
- }, [document, documentMeta?.availableLocales, validate]);
607
- const localesToPublish = selectedRows.reduce((acc, selectedRow) => {
608
- if (selectedRow.status !== "published" && !Object.keys(validationErrors).includes(selectedRow.locale)) {
609
- acc.push(selectedRow.locale);
610
- }
611
- return acc;
612
- }, []);
613
- const {
614
- data: draftRelationsCount = 0,
615
- isLoading: isDraftRelationsLoading,
616
- error: isDraftRelationsError
617
- } = useGetManyDraftRelationCountQuery(
618
- {
619
- model,
620
- documentIds: [documentId],
621
- locale: localesToPublish
622
- },
623
- {
624
- skip: !documentId || localesToPublish.length === 0
625
- }
626
- );
627
- React.useEffect(() => {
628
- if (isDraftRelationsError) {
629
- toggleNotification({
630
- type: "danger",
631
- message: formatAPIError(isDraftRelationsError)
632
- });
633
- }
634
- }, [isDraftRelationsError, toggleNotification, formatAPIError]);
635
- if (!schema?.options?.draftAndPublish) {
636
- return null;
637
- }
638
- if (!hasI18n) {
639
- return null;
640
- }
641
- if (!documentId) {
642
- return null;
643
- }
644
- const publish = async () => {
645
- await publishManyAction({
646
- model,
647
- documentIds: [documentId],
648
- params: {
649
- ...params,
650
- locale: localesToPublish
651
- }
652
- });
653
- setSelectedRows([]);
654
- };
655
- const handleAction = async () => {
656
- if (draftRelationsCount > 0) {
657
- setIsConfirmationOpen(true);
658
- } else {
659
- await publish();
660
- }
661
- };
662
- const isUnpublish = document?.status === "published";
663
- if (isUnpublish) {
664
- console.warn(["I18N"], "Bulk locale unpublish modal not implemented");
665
- }
666
- if (isConfirmationOpen) {
667
- return {
668
- label: formatMessage({
669
- id: "app.components.ConfirmDialog.title",
670
- defaultMessage: "Confirmation"
671
- }),
672
- variant: "danger",
673
- dialog: {
674
- onCancel: () => {
675
- setIsConfirmationOpen(false);
676
- },
677
- onConfirm: async () => {
678
- await publish();
679
- setIsConfirmationOpen(false);
680
- },
681
- type: "dialog",
682
- title: formatMessage({
683
- id: getTranslation("actions.publish.dialog.title"),
684
- defaultMessage: "Confirmation"
685
- }),
686
- content: /* @__PURE__ */ jsxs(Flex, { direction: "column", alignItems: "center", gap: 2, children: [
687
- /* @__PURE__ */ jsx(WarningCircle, { width: "2.4rem", height: "2.4rem", fill: "danger600" }),
688
- /* @__PURE__ */ jsx(Typography, { textAlign: "center", children: formatMessage({
689
- id: "content-manager.actions.discard.dialog.body",
690
- defaultMessage: "Are you sure you want to discard the changes? This action is irreversible."
691
- }) })
692
- ] })
693
- }
694
- };
695
- }
696
- return {
697
- label: formatMessage({
698
- id: getTranslation("CMEditViewBulkLocale.publish-title"),
699
- defaultMessage: "Publish Multiple Locales"
700
- }),
701
- icon: /* @__PURE__ */ jsx(ListPlus, {}),
702
- disabled: isPublishedTab || !canPublish,
703
- position: ["panel"],
704
- variant: "secondary",
705
- dialog: {
706
- type: "modal",
707
- title: formatMessage({
708
- id: getTranslation("CMEditViewBulkLocale.publish-title"),
709
- defaultMessage: "Publish Multiple Locales"
710
- }),
711
- content: () => {
712
- return /* @__PURE__ */ jsx(
713
- Table.Root,
714
- {
715
- headers,
716
- rows: rows.map((row) => ({
717
- ...row,
718
- id: row.locale
719
- })),
720
- selectedRows,
721
- onSelectedRowsChange: (tableSelectedRows) => setSelectedRows(tableSelectedRows),
722
- children: /* @__PURE__ */ jsx(
723
- BulkLocaleActionModal,
724
- {
725
- validationErrors,
726
- headers,
727
- rows,
728
- localesMetadata
729
- }
730
- )
731
- }
732
- );
733
- },
734
- footer: () => /* @__PURE__ */ jsx(Flex, { justifyContent: "flex-end", children: /* @__PURE__ */ jsx(
735
- Button$1,
736
- {
737
- loading: isDraftRelationsLoading,
738
- disabled: localesToPublish.length === 0,
739
- variant: "default",
740
- onClick: handleAction,
741
- children: formatMessage({
742
- id: "app.utils.publish",
743
- defaultMessage: "Publish"
744
- })
745
- }
746
- ) })
747
- }
748
- };
749
- };
750
- const StyledTrash = styled(Trash)`
751
- path {
752
- fill: currentColor;
753
- }
754
- `;
755
- const Emphasis = (chunks) => {
756
- return /* @__PURE__ */ jsx(Typography, { fontWeight: "semiBold", textColor: "danger500", children: chunks });
757
- };
758
- const DeleteModalAdditionalInfo = () => {
759
- const { hasI18n } = useI18n();
760
- const { formatMessage } = useIntl();
761
- if (!hasI18n) {
762
- return null;
763
- }
764
- return /* @__PURE__ */ jsx(Typography, { textColor: "danger500", children: formatMessage(
765
- {
766
- id: getTranslation("Settings.list.actions.deleteAdditionalInfos"),
767
- defaultMessage: "This will delete the active locale versions <em>(from Internationalization)</em>"
768
- },
769
- {
770
- em: Emphasis
771
- }
772
- ) });
773
- };
774
- const PublishModalAdditionalInfo = () => {
775
- const { hasI18n } = useI18n();
776
- const { formatMessage } = useIntl();
777
- if (!hasI18n) {
778
- return null;
779
- }
780
- return /* @__PURE__ */ jsx(Typography, { textColor: "danger500", children: formatMessage(
781
- {
782
- id: getTranslation("Settings.list.actions.publishAdditionalInfos"),
783
- defaultMessage: "This will publish the active locale versions <em>(from Internationalization)</em>"
784
- },
785
- {
786
- em: Emphasis
787
- }
788
- ) });
789
- };
790
- const UnpublishModalAdditionalInfo = () => {
791
- const { hasI18n } = useI18n();
792
- const { formatMessage } = useIntl();
793
- if (!hasI18n) {
794
- return null;
795
- }
796
- return /* @__PURE__ */ jsx(Typography, { textColor: "danger500", children: formatMessage(
797
- {
798
- id: getTranslation("Settings.list.actions.unpublishAdditionalInfos"),
799
- defaultMessage: "This will unpublish the active locale versions <em>(from Internationalization)</em>"
800
- },
801
- {
802
- em: Emphasis
803
- }
804
- ) });
805
- };
806
- const Initializer = ({ setPlugin }) => {
807
- const setPluginRef = React.useRef(setPlugin);
808
- React.useEffect(() => {
809
- setPluginRef.current(pluginId);
810
- }, []);
811
- return null;
812
- };
813
- const LocalePicker = () => {
814
- const { formatMessage } = useIntl();
815
- const [{ query }, setQuery] = useQueryParams();
816
- const { hasI18n, canRead, canCreate } = useI18n();
817
- const { data: locales = [] } = useGetLocalesQuery(void 0, {
818
- skip: !hasI18n
819
- });
820
- const handleChange = React.useCallback(
821
- (code, replace = false) => {
822
- setQuery(
823
- {
824
- page: 1,
825
- plugins: { ...query.plugins, i18n: { locale: code } }
826
- },
827
- "push",
828
- replace
829
- );
830
- },
831
- [query.plugins, setQuery]
832
- );
833
- React.useEffect(() => {
834
- if (!Array.isArray(locales) || !hasI18n) {
835
- return;
836
- }
837
- const currentDesiredLocale = query.plugins?.i18n?.locale;
838
- const doesLocaleExist = locales.find((loc) => loc.code === currentDesiredLocale);
839
- const defaultLocale = locales.find((locale) => locale.isDefault);
840
- if (!doesLocaleExist && defaultLocale?.code) {
841
- handleChange(defaultLocale.code, true);
842
- }
843
- }, [hasI18n, handleChange, locales, query.plugins?.i18n?.locale]);
844
- if (!hasI18n || !Array.isArray(locales) || locales.length === 0) {
845
- return null;
846
- }
847
- const displayedLocales = locales.filter((locale) => {
848
- return canCreate.includes(locale.code) || canRead.includes(locale.code);
849
- });
850
- return /* @__PURE__ */ jsx(
851
- SingleSelect,
852
- {
853
- size: "S",
854
- "aria-label": formatMessage({
855
- id: getTranslation("actions.select-locale"),
856
- defaultMessage: "Select locale"
857
- }),
858
- value: query.plugins?.i18n?.locale || locales.find((locale) => locale.isDefault)?.code,
859
- onChange: handleChange,
860
- children: displayedLocales.map((locale) => /* @__PURE__ */ jsx(SingleSelectOption, { value: locale.code, children: locale.name }, locale.id))
861
- }
862
- );
863
- };
864
- const PERMISSIONS = {
865
- accessMain: [{ action: "plugin::i18n.locale.read", subject: null }],
866
- create: [{ action: "plugin::i18n.locale.create", subject: null }],
867
- delete: [{ action: "plugin::i18n.locale.delete", subject: null }],
868
- update: [{ action: "plugin::i18n.locale.update", subject: null }],
869
- read: [{ action: "plugin::i18n.locale.read", subject: null }]
870
- };
871
- const mutateEditViewHook = ({ layout }) => {
872
- if (!("i18n" in layout.options) || typeof layout.options.i18n === "object" && layout.options.i18n !== null && "localized" in layout.options.i18n && !layout.options.i18n.localized) {
873
- return { layout };
874
- }
875
- const components = Object.entries(layout.components).reduce(
876
- (acc, [key, componentLayout]) => {
877
- return {
878
- ...acc,
879
- [key]: {
880
- ...componentLayout,
881
- layout: componentLayout.layout.map((row) => row.map(addLabelActionToField))
882
- }
883
- };
884
- },
885
- {}
886
- );
887
- return {
888
- layout: {
889
- ...layout,
890
- components,
891
- layout: layout.layout.map((panel) => panel.map((row) => row.map(addLabelActionToField)))
892
- }
893
- };
894
- };
895
- const addLabelActionToField = (field) => {
896
- const isFieldLocalized = doesFieldHaveI18nPluginOpt(field.attribute.pluginOptions) ? field.attribute.pluginOptions.i18n.localized : true;
897
- const labelActionProps = {
898
- title: {
899
- id: isFieldLocalized ? getTranslation("Field.localized") : getTranslation("Field.not-localized"),
900
- defaultMessage: isFieldLocalized ? "This value is unique for the selected locale" : "This value is the same across all locales"
901
- },
902
- icon: isFieldLocalized ? /* @__PURE__ */ jsx(Earth, {}) : /* @__PURE__ */ jsx(EarthStriked, {})
903
- };
904
- return {
905
- ...field,
906
- labelAction: /* @__PURE__ */ jsx(LabelAction, { ...labelActionProps })
907
- };
908
- };
909
- const doesFieldHaveI18nPluginOpt = (pluginOpts) => {
910
- if (!pluginOpts) {
911
- return false;
912
- }
913
- return "i18n" in pluginOpts && typeof pluginOpts.i18n === "object" && pluginOpts.i18n !== null && "localized" in pluginOpts.i18n;
914
- };
915
- const LabelAction = ({ title, icon }) => {
916
- const { formatMessage } = useIntl();
917
- return /* @__PURE__ */ jsxs(Span, { tag: "span", children: [
918
- /* @__PURE__ */ jsx(VisuallyHidden, { tag: "span", children: formatMessage(title) }),
919
- React.cloneElement(icon, {
920
- "aria-hidden": true,
921
- focusable: false
922
- // See: https://allyjs.io/tutorials/focusing-in-svg.html#making-svg-elements-focusable
923
- })
924
- ] });
925
- };
926
- const Span = styled(Flex)`
927
- svg {
928
- width: 12px;
929
- height: 12px;
930
-
931
- fill: ${({ theme }) => theme.colors.neutral500};
932
-
933
- path {
934
- fill: ${({ theme }) => theme.colors.neutral500};
935
- }
936
- }
937
- `;
938
- const LocaleListCell = ({
939
- documentId,
940
- locale: currentLocale,
941
- collectionType,
942
- model
943
- }) => {
944
- const { meta, isLoading } = unstable_useDocument({
945
- documentId,
946
- collectionType,
947
- model,
948
- params: {
949
- locale: currentLocale
950
- }
951
- });
952
- const { locale: language } = useIntl();
953
- const [visible, setVisible] = React.useState(false);
954
- const buttonRef = React.useRef(null);
955
- const { data: locales = [] } = useGetLocalesQuery();
956
- const handleTogglePopover = (e) => {
957
- e.stopPropagation();
958
- setVisible((prev) => !prev);
959
- };
960
- const formatter = useCollator(language, {
961
- sensitivity: "base"
962
- });
963
- if (!Array.isArray(locales) || isLoading) {
964
- return null;
965
- }
966
- const availableLocales = meta?.availableLocales.map((doc) => doc.locale) ?? [];
967
- const localesForDocument = locales.reduce((acc, locale) => {
968
- const createdLocale = [currentLocale, ...availableLocales].find((loc) => {
969
- return loc === locale.code;
970
- });
971
- if (createdLocale) {
972
- acc.push(locale);
973
- }
974
- return acc;
975
- }, []).map((locale) => {
976
- if (locale.isDefault) {
977
- return `${locale.name} (default)`;
978
- }
979
- return locale.name;
980
- }).toSorted((a, b) => formatter.compare(a, b));
981
- return /* @__PURE__ */ jsxs(Button, { type: "button", onClick: handleTogglePopover, ref: buttonRef, children: [
982
- /* @__PURE__ */ jsxs(
983
- ActionWrapper,
984
- {
985
- minWidth: "100%",
986
- alignItems: "center",
987
- justifyContent: "center",
988
- height: "3.2rem",
989
- width: "3.2rem",
990
- children: [
991
- /* @__PURE__ */ jsx(Typography, { textColor: "neutral800", ellipsis: true, children: localesForDocument.join(", ") }),
992
- /* @__PURE__ */ jsx(Flex, { children: /* @__PURE__ */ jsx(CaretDown, {}) })
993
- ]
994
- }
995
- ),
996
- visible && /* @__PURE__ */ jsx(
997
- Popover,
998
- {
999
- onDismiss: () => setVisible(false),
1000
- source: buttonRef,
1001
- spacing: 16,
1002
- centered: true,
1003
- children: /* @__PURE__ */ jsx("ul", { children: localesForDocument.map((name) => /* @__PURE__ */ jsx(Box, { padding: 3, tag: "li", children: /* @__PURE__ */ jsx(Typography, { children: name }) }, name)) })
1004
- }
1005
- )
1006
- ] });
1007
- };
1008
- const Button = styled.button`
1009
- width: 100%;
1010
-
1011
- svg {
1012
- > g,
1013
- path {
1014
- fill: ${({ theme }) => theme.colors.neutral500};
1015
- }
1016
- }
1017
- &:hover {
1018
- svg {
1019
- > g,
1020
- path {
1021
- fill: ${({ theme }) => theme.colors.neutral600};
1022
- }
1023
- }
1024
- }
1025
- &:active {
1026
- svg {
1027
- > g,
1028
- path {
1029
- fill: ${({ theme }) => theme.colors.neutral400};
1030
- }
1031
- }
1032
- }
1033
- `;
1034
- const ActionWrapper = styled(Flex)`
1035
- svg {
1036
- height: 0.4rem;
1037
- }
1038
- `;
1039
- const addColumnToTableHook = ({ displayedHeaders, layout }) => {
1040
- const { options } = layout;
1041
- const isFieldLocalized = doesPluginOptionsHaveI18nLocalized(options) ? options.i18n.localized : false;
1042
- if (!isFieldLocalized) {
1043
- return { displayedHeaders, layout };
1044
- }
1045
- return {
1046
- displayedHeaders: [
1047
- ...displayedHeaders,
1048
- {
1049
- attribute: { type: "string" },
1050
- label: {
1051
- id: getTranslation("list-view.table.header.label"),
1052
- defaultMessage: "Available in"
1053
- },
1054
- searchable: false,
1055
- sortable: false,
1056
- name: "locales",
1057
- // @ts-expect-error – ID is seen as number | string; this will change when we move the type over.
1058
- cellFormatter: (props, _header, meta) => /* @__PURE__ */ jsx(LocaleListCell, { ...props, ...meta })
1059
- }
1060
- ],
1061
- layout
1062
- };
1063
- };
1064
- const addLocaleToReleasesHook = ({ displayedHeaders = [] }) => {
1065
- return {
1066
- displayedHeaders: [
1067
- // TODO: Fix when migrating to v5
1068
- // ...displayedHeaders,
1069
- {
1070
- key: "__locale__",
1071
- fieldSchema: { type: "string" },
1072
- metadatas: {
1073
- label: {
1074
- id: "content-releases.page.ReleaseDetails.table.header.label.locale",
1075
- defaultMessage: "locale"
1076
- },
1077
- searchable: false,
1078
- sortable: false
1079
- },
1080
- name: "locale"
1081
- }
1082
- ],
1083
- hasI18nEnabled: true
1084
- };
1085
- };
1086
- const extendCTBAttributeInitialDataMiddleware = () => {
1087
- return ({ getState }) => (next) => (action) => {
1088
- const enhanceAction = () => {
1089
- try {
1090
- const store = getState();
1091
- const hasi18nEnabled = get(
1092
- store,
1093
- [
1094
- "content-type-builder_dataManagerProvider",
1095
- "modifiedData",
1096
- "contentType",
1097
- "schema",
1098
- "pluginOptions",
1099
- "i18n",
1100
- "localized"
1101
- ],
1102
- false
1103
- );
1104
- if (hasi18nEnabled) {
1105
- const pluginOptions = action.options ? { ...action.options.pluginOptions, i18n: { localized: true } } : { i18n: { localized: true } };
1106
- return next({
1107
- ...action,
1108
- options: {
1109
- pluginOptions
1110
- }
1111
- });
1112
- }
1113
- return next(action);
1114
- } catch (err) {
1115
- return next(action);
1116
- }
1117
- };
1118
- if (action.type === "ContentTypeBuilder/FormModal/SET_ATTRIBUTE_DATA_SCHEMA" && action.forTarget === "contentType" && !["relation", "component"].includes(action.attributeType) && !action.isEditing) {
1119
- return enhanceAction();
1120
- }
1121
- if (action.type === "ContentTypeBuilder/FormModal/SET_CUSTOM_FIELD_DATA_SCHEMA" && action.forTarget === "contentType" && !action.isEditing) {
1122
- return enhanceAction();
1123
- }
1124
- 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") {
1125
- return enhanceAction();
1126
- }
1127
- return next(action);
1128
- };
1129
- };
1130
- const extendCTBInitialDataMiddleware = () => {
1131
- return () => (next) => (action) => {
1132
- if (action.type === "ContentTypeBuilder/FormModal/SET_DATA_TO_EDIT" && action.modalType === "contentType") {
1133
- const i18n = { localized: false };
1134
- const pluginOptions = action.data.pluginOptions ? { ...action.data.pluginOptions, i18n } : { i18n };
1135
- const data = { ...action.data, pluginOptions };
1136
- if (action.actionType === "create") {
1137
- return next({ ...action, data });
1138
- }
1139
- if (!action.data.pluginOptions?.i18n?.localized) {
1140
- return next({ ...action, data });
1141
- }
1142
- }
1143
- return next(action);
1144
- };
1145
- };
1146
- const localeMiddleware = (ctx) => (next) => (permissions) => {
1147
- const match = matchPath("/content-manager/:collectionType/:model?/:id", ctx.pathname);
1148
- if (!match) {
1149
- return next(permissions);
1150
- }
1151
- const search = qs.parse(ctx.search);
1152
- if (typeof search !== "object") {
1153
- return next(permissions);
1154
- }
1155
- if (!("plugins" in search && typeof search.plugins === "object")) {
1156
- return next(permissions);
1157
- }
1158
- if (!("i18n" in search.plugins && typeof search.plugins.i18n === "object" && !Array.isArray(search.plugins.i18n))) {
1159
- return next(permissions);
1160
- }
1161
- const { locale } = search.plugins.i18n;
1162
- if (typeof locale !== "string") {
1163
- return next(permissions);
1164
- }
1165
- const revisedPermissions = permissions.filter(
1166
- (permission) => !permission.properties?.locales || permission.properties.locales.includes(locale)
1167
- );
1168
- return next(revisedPermissions);
1169
- };
1170
- const prefixPluginTranslations = (trad, pluginId2) => {
1171
- if (!pluginId2) {
1172
- throw new TypeError("pluginId can't be empty");
1173
- }
1174
- return Object.keys(trad).reduce((acc, current) => {
1175
- acc[`${pluginId2}.${current}`] = trad[current];
1176
- return acc;
1177
- }, {});
1178
- };
1179
- const mutateCTBContentTypeSchema = (nextSchema, prevSchema) => {
1180
- if (!doesPluginOptionsHaveI18nLocalized(nextSchema.pluginOptions)) {
1181
- return nextSchema;
1182
- }
1183
- const isNextSchemaLocalized = nextSchema.pluginOptions.i18n.localized;
1184
- const isPrevSchemaLocalized = doesPluginOptionsHaveI18nLocalized(
1185
- prevSchema?.schema?.pluginOptions
1186
- ) ? prevSchema?.schema?.pluginOptions.i18n.localized : false;
1187
- if (isNextSchemaLocalized && isPrevSchemaLocalized) {
1188
- return nextSchema;
1189
- }
1190
- if (isNextSchemaLocalized) {
1191
- const attributes = addLocalisationToFields(nextSchema.attributes);
1192
- return { ...nextSchema, attributes };
1193
- }
1194
- if (!isNextSchemaLocalized) {
1195
- const pluginOptions = omit(nextSchema.pluginOptions, "i18n");
1196
- const attributes = disableAttributesLocalisation(nextSchema.attributes);
1197
- return { ...nextSchema, pluginOptions, attributes };
1198
- }
1199
- return nextSchema;
1200
- };
1201
- const addLocalisationToFields = (attributes) => Object.keys(attributes).reduce((acc, current) => {
1202
- const currentAttribute = attributes[current];
1203
- if (LOCALIZED_FIELDS.includes(currentAttribute.type)) {
1204
- const i18n = { localized: true };
1205
- const pluginOptions = currentAttribute.pluginOptions ? { ...currentAttribute.pluginOptions, i18n } : { i18n };
1206
- acc[current] = { ...currentAttribute, pluginOptions };
1207
- return acc;
1208
- }
1209
- acc[current] = currentAttribute;
1210
- return acc;
1211
- }, {});
1212
- const disableAttributesLocalisation = (attributes) => Object.keys(attributes).reduce((acc, current) => {
1213
- acc[current] = omit(attributes[current], "pluginOptions.i18n");
1214
- return acc;
1215
- }, {});
1216
- const index = {
1217
- register(app) {
1218
- app.addMiddlewares([extendCTBAttributeInitialDataMiddleware, extendCTBInitialDataMiddleware]);
1219
- app.addMiddlewares([() => i18nApi.middleware]);
1220
- app.addReducers({
1221
- [i18nApi.reducerPath]: i18nApi.reducer
1222
- });
1223
- app.addRBACMiddleware([localeMiddleware]);
1224
- app.registerPlugin({
1225
- id: pluginId,
1226
- initializer: Initializer,
1227
- isReady: false,
1228
- name: pluginId
1229
- });
1230
- },
1231
- bootstrap(app) {
1232
- app.registerHook("Admin/CM/pages/ListView/inject-column-in-table", addColumnToTableHook);
1233
- app.registerHook("Admin/CM/pages/EditView/mutate-edit-view-layout", mutateEditViewHook);
1234
- app.registerHook(
1235
- "ContentReleases/pages/ReleaseDetails/add-locale-in-releases",
1236
- addLocaleToReleasesHook
1237
- );
1238
- app.addSettingsLink("global", {
1239
- intlLabel: {
1240
- id: getTranslation("plugin.name"),
1241
- defaultMessage: "Internationalization"
1242
- },
1243
- id: "internationalization",
1244
- to: "internationalization",
1245
- Component: () => import("./SettingsPage-BWlXRGN7.mjs").then((mod) => ({ default: mod.ProtectedSettingsPage })),
1246
- permissions: PERMISSIONS.accessMain
1247
- });
1248
- const contentManager = app.getPlugin("content-manager");
1249
- contentManager.apis.addDocumentHeaderAction([LocalePickerAction]);
1250
- contentManager.apis.addDocumentAction((actions) => {
1251
- const indexOfDeleteAction = actions.findIndex((action) => action.type === "delete");
1252
- actions.splice(indexOfDeleteAction, 0, DeleteLocaleAction);
1253
- return actions;
1254
- });
1255
- contentManager.apis.addDocumentAction((actions) => {
1256
- actions.splice(2, 0, BulkLocalePublishAction);
1257
- return actions;
1258
- });
1259
- contentManager.injectComponent("listView", "actions", {
1260
- name: "i18n-locale-filter",
1261
- Component: LocalePicker
1262
- });
1263
- contentManager.injectComponent("listView", "publishModalAdditionalInfos", {
1264
- name: "i18n-publish-bullets-in-modal",
1265
- Component: PublishModalAdditionalInfo
1266
- });
1267
- contentManager.injectComponent("listView", "unpublishModalAdditionalInfos", {
1268
- name: "i18n-unpublish-bullets-in-modal",
1269
- Component: UnpublishModalAdditionalInfo
1270
- });
1271
- contentManager.injectComponent("listView", "deleteModalAdditionalInfos", {
1272
- name: "i18n-delete-bullets-in-modal",
1273
- Component: DeleteModalAdditionalInfo
1274
- });
1275
- const ctbPlugin = app.getPlugin("content-type-builder");
1276
- if (ctbPlugin) {
1277
- const ctbFormsAPI = ctbPlugin.apis.forms;
1278
- ctbFormsAPI.addContentTypeSchemaMutation(mutateCTBContentTypeSchema);
1279
- ctbFormsAPI.components.add({ id: "checkboxConfirmation", component: CheckboxConfirmation });
1280
- ctbFormsAPI.extendContentType({
1281
- validator: () => ({
1282
- i18n: yup.object().shape({
1283
- localized: yup.bool()
1284
- })
1285
- }),
1286
- form: {
1287
- advanced() {
1288
- return [
1289
- {
1290
- name: "pluginOptions.i18n.localized",
1291
- description: {
1292
- id: getTranslation("plugin.schema.i18n.localized.description-content-type"),
1293
- defaultMessage: "Allows translating an entry into different languages"
1294
- },
1295
- type: "checkboxConfirmation",
1296
- intlLabel: {
1297
- id: getTranslation("plugin.schema.i18n.localized.label-content-type"),
1298
- defaultMessage: "Localization"
1299
- }
1300
- }
1301
- ];
1302
- }
1303
- }
1304
- });
1305
- ctbFormsAPI.extendFields(LOCALIZED_FIELDS, {
1306
- validator: (args) => ({
1307
- i18n: yup.object().shape({
1308
- localized: yup.bool().test({
1309
- name: "ensure-unique-localization",
1310
- message: getTranslation("plugin.schema.i18n.ensure-unique-localization"),
1311
- test(value) {
1312
- if (value === void 0 || value) {
1313
- return true;
1314
- }
1315
- const unique = get(args, ["3", "modifiedData", "unique"], null);
1316
- if (unique && !value) {
1317
- return false;
1318
- }
1319
- return true;
1320
- }
1321
- })
1322
- })
1323
- }),
1324
- form: {
1325
- advanced({ contentTypeSchema, forTarget, type, step }) {
1326
- if (forTarget !== "contentType") {
1327
- return [];
1328
- }
1329
- const hasI18nEnabled = get(
1330
- contentTypeSchema,
1331
- ["schema", "pluginOptions", "i18n", "localized"],
1332
- false
1333
- );
1334
- if (!hasI18nEnabled) {
1335
- return [];
1336
- }
1337
- if (type === "component" && step === "1") {
1338
- return [];
1339
- }
1340
- return [
1341
- {
1342
- name: "pluginOptions.i18n.localized",
1343
- description: {
1344
- id: getTranslation("plugin.schema.i18n.localized.description-field"),
1345
- defaultMessage: "The field can have different values in each locale"
1346
- },
1347
- type: "checkbox",
1348
- intlLabel: {
1349
- id: getTranslation("plugin.schema.i18n.localized.label-field"),
1350
- defaultMessage: "Enable localization for this field"
1351
- }
1352
- }
1353
- ];
1354
- }
1355
- }
1356
- });
1357
- }
1358
- },
1359
- async registerTrads({ locales }) {
1360
- const importedTrads = await Promise.all(
1361
- locales.map((locale) => {
1362
- 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-18tWw4P6.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 }) => {
1363
- return {
1364
- data: prefixPluginTranslations(data, pluginId),
1365
- locale
1366
- };
1367
- }).catch(() => {
1368
- return {
1369
- data: {},
1370
- locale
1371
- };
1372
- });
1373
- })
1374
- );
1375
- return Promise.resolve(importedTrads);
1376
- }
1377
- };
1378
- export {
1379
- PERMISSIONS as P,
1380
- useGetDefaultLocalesQuery as a,
1381
- useDeleteLocaleMutation as b,
1382
- useUpdateLocaleMutation as c,
1383
- useGetLocalesQuery as d,
1384
- getTranslation as g,
1385
- index as i,
1386
- useCreateLocaleMutation as u
1387
- };
1388
- //# sourceMappingURL=index-DVTdCB4M.mjs.map