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

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