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