@strapi/i18n 0.0.0-experimental.e14656d3b8681880212c13260b9a2b340c182f2d → 0.0.0-experimental.e350eaa6073e65190102b4b798c32c287053cc02

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 (47) hide show
  1. package/dist/_chunks/{SettingsPage-CbEn7zF5.mjs → SettingsPage-BAx9nmep.mjs} +4 -4
  2. package/dist/_chunks/SettingsPage-BAx9nmep.mjs.map +1 -0
  3. package/dist/_chunks/{SettingsPage-C0l7c5fn.js → SettingsPage-BTgjb2KS.js} +5 -6
  4. package/dist/_chunks/SettingsPage-BTgjb2KS.js.map +1 -0
  5. package/dist/_chunks/{en-BsOU9o5z.js → en-BKBz3tro.js} +10 -3
  6. package/dist/_chunks/en-BKBz3tro.js.map +1 -0
  7. package/dist/_chunks/{en-CM6Pjfyv.mjs → en-DlXfy6Gy.mjs} +10 -3
  8. package/dist/_chunks/en-DlXfy6Gy.mjs.map +1 -0
  9. package/dist/_chunks/{index-C0i3v7QQ.js → index-3yyF237r.js} +400 -145
  10. package/dist/_chunks/index-3yyF237r.js.map +1 -0
  11. package/dist/_chunks/{index-CkrCiZyq.mjs → index-B0NijiBB.mjs} +406 -150
  12. package/dist/_chunks/index-B0NijiBB.mjs.map +1 -0
  13. package/dist/admin/index.js +1 -1
  14. package/dist/admin/index.mjs +1 -1
  15. package/dist/admin/src/components/BulkLocaleActionModal.d.ts +2 -1
  16. package/dist/admin/src/components/CMHeaderActions.d.ts +29 -3
  17. package/dist/admin/src/components/CreateLocale.d.ts +6 -6
  18. package/dist/admin/src/utils/clean.d.ts +4 -0
  19. package/dist/server/index.js +398 -487
  20. package/dist/server/index.js.map +1 -1
  21. package/dist/server/index.mjs +399 -487
  22. package/dist/server/index.mjs.map +1 -1
  23. package/dist/server/src/bootstrap.d.ts +1 -4
  24. package/dist/server/src/bootstrap.d.ts.map +1 -1
  25. package/dist/server/src/index.d.ts +7 -11
  26. package/dist/server/src/index.d.ts.map +1 -1
  27. package/dist/server/src/register.d.ts.map +1 -1
  28. package/dist/server/src/services/index.d.ts +6 -8
  29. package/dist/server/src/services/index.d.ts.map +1 -1
  30. package/dist/server/src/services/sanitize/index.d.ts +11 -0
  31. package/dist/server/src/services/sanitize/index.d.ts.map +1 -0
  32. package/dist/server/src/utils/index.d.ts +2 -2
  33. package/dist/server/src/utils/index.d.ts.map +1 -1
  34. package/package.json +13 -13
  35. package/dist/_chunks/SettingsPage-C0l7c5fn.js.map +0 -1
  36. package/dist/_chunks/SettingsPage-CbEn7zF5.mjs.map +0 -1
  37. package/dist/_chunks/en-BsOU9o5z.js.map +0 -1
  38. package/dist/_chunks/en-CM6Pjfyv.mjs.map +0 -1
  39. package/dist/_chunks/index-C0i3v7QQ.js.map +0 -1
  40. package/dist/_chunks/index-CkrCiZyq.mjs.map +0 -1
  41. package/dist/server/src/migrations/content-type/disable/index.d.ts +0 -3
  42. package/dist/server/src/migrations/content-type/disable/index.d.ts.map +0 -1
  43. package/dist/server/src/migrations/content-type/enable/index.d.ts +0 -3
  44. package/dist/server/src/migrations/content-type/enable/index.d.ts.map +0 -1
  45. package/dist/server/src/services/entity-service-decorator.d.ts +0 -29
  46. package/dist/server/src/services/entity-service-decorator.d.ts.map +0 -1
  47. package/strapi-server.js +0 -3
@@ -15,8 +15,7 @@ const qs = require("qs");
15
15
  const omit = require("lodash/omit");
16
16
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
17
17
  function _interopNamespace(e) {
18
- if (e && e.__esModule)
19
- return e;
18
+ if (e && e.__esModule) return e;
20
19
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
21
20
  if (e) {
22
21
  for (const k in e) {
@@ -37,13 +36,20 @@ const yup__namespace = /* @__PURE__ */ _interopNamespace(yup);
37
36
  const React__namespace = /* @__PURE__ */ _interopNamespace(React);
38
37
  const qs__namespace = /* @__PURE__ */ _interopNamespace(qs);
39
38
  const omit__default = /* @__PURE__ */ _interopDefault(omit);
40
- const __variableDynamicImportRuntimeHelper = (glob, path) => {
39
+ const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
41
40
  const v = glob[path];
42
41
  if (v) {
43
42
  return typeof v === "function" ? v() : Promise.resolve(v);
44
43
  }
45
44
  return new Promise((_, reject) => {
46
- (typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(reject.bind(null, new Error("Unknown variable dynamic import: " + path)));
45
+ (typeof queueMicrotask === "function" ? queueMicrotask : setTimeout)(
46
+ reject.bind(
47
+ null,
48
+ new Error(
49
+ "Unknown variable dynamic import: " + path + (path.split("/").length !== segs ? ". Note that variables only represent file names one level deep." : "")
50
+ )
51
+ )
52
+ );
47
53
  });
48
54
  };
49
55
  const pluginId = "i18n";
@@ -241,10 +247,94 @@ const relationsApi = i18nApi.injectEndpoints({
241
247
  })
242
248
  });
243
249
  const { useGetManyDraftRelationCountQuery } = relationsApi;
250
+ const cleanData = (data, schema, components) => {
251
+ const cleanedData = removeFields(data, [
252
+ "createdAt",
253
+ "createdBy",
254
+ "updatedAt",
255
+ "updatedBy",
256
+ "id",
257
+ "documentId",
258
+ "publishedAt",
259
+ "strapi_stage",
260
+ "strapi_assignee",
261
+ "locale",
262
+ "status"
263
+ ]);
264
+ const cleanedDataWithoutPasswordAndRelation = recursiveRemoveFieldTypes(
265
+ cleanedData,
266
+ schema,
267
+ components,
268
+ ["relation", "password"]
269
+ );
270
+ return cleanedDataWithoutPasswordAndRelation;
271
+ };
272
+ const removeFields = (data, fields) => {
273
+ return Object.keys(data).reduce((acc, current) => {
274
+ if (fields.includes(current)) {
275
+ return acc;
276
+ }
277
+ acc[current] = data[current];
278
+ return acc;
279
+ }, {});
280
+ };
281
+ const recursiveRemoveFieldTypes = (data, schema, components, fields) => {
282
+ return Object.keys(data).reduce((acc, current) => {
283
+ const attribute = schema.attributes[current] ?? { type: void 0 };
284
+ if (fields.includes(attribute.type)) {
285
+ return acc;
286
+ }
287
+ if (attribute.type === "dynamiczone") {
288
+ acc[current] = data[current].map((componentValue, index2) => {
289
+ const { id: _, ...rest } = recursiveRemoveFieldTypes(
290
+ componentValue,
291
+ components[componentValue.__component],
292
+ components,
293
+ fields
294
+ );
295
+ return {
296
+ ...rest,
297
+ __temp_key__: index2 + 1
298
+ };
299
+ });
300
+ } else if (attribute.type === "component") {
301
+ const { repeatable, component } = attribute;
302
+ if (repeatable) {
303
+ acc[current] = (data[current] ?? []).map((compoData, index2) => {
304
+ const { id: _, ...rest } = recursiveRemoveFieldTypes(
305
+ compoData,
306
+ components[component],
307
+ components,
308
+ fields
309
+ );
310
+ return {
311
+ ...rest,
312
+ __temp_key__: index2 + 1
313
+ };
314
+ });
315
+ } else {
316
+ const { id: _, ...rest } = recursiveRemoveFieldTypes(
317
+ data[current] ?? {},
318
+ components[component],
319
+ components,
320
+ fields
321
+ );
322
+ acc[current] = rest;
323
+ }
324
+ } else {
325
+ acc[current] = data[current];
326
+ }
327
+ return acc;
328
+ }, {});
329
+ };
244
330
  const isErrorMessageDescriptor = (object) => {
245
331
  return typeof object === "object" && object !== null && "id" in object && "defaultMessage" in object;
246
332
  };
247
- const EntryValidationText = ({ status = "draft", validationErrors }) => {
333
+ const EntryValidationText = ({
334
+ status = "draft",
335
+ validationErrors,
336
+ action
337
+ }) => {
248
338
  const { formatMessage } = reactIntl.useIntl();
249
339
  const getErrorStr = (key, value) => {
250
340
  if (typeof value === "string") {
@@ -278,30 +368,63 @@ const EntryValidationText = ({ status = "draft", validationErrors }) => {
278
368
  ) })
279
369
  ] });
280
370
  }
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
- }
371
+ const getStatusMessage = () => {
372
+ if (action === "bulk-publish") {
373
+ if (status === "published") {
374
+ return {
375
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.CheckCircle, { fill: "success600" }),
376
+ text: formatMessage({
377
+ id: "content-manager.bulk-publish.already-published",
378
+ defaultMessage: "Already Published"
379
+ }),
380
+ textColor: "success600",
381
+ fontWeight: "bold"
382
+ };
383
+ } else if (status === "modified") {
384
+ return {
385
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.ArrowsCounterClockwise, { fill: "alternative600" }),
386
+ text: formatMessage({
387
+ id: "app.utils.ready-to-publish-changes",
388
+ defaultMessage: "Ready to publish changes"
389
+ })
390
+ };
391
+ } else {
392
+ return {
393
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.CheckCircle, { fill: "success600" }),
394
+ text: formatMessage({
395
+ id: "app.utils.ready-to-publish",
396
+ defaultMessage: "Ready to publish"
397
+ })
398
+ };
399
+ }
400
+ } else {
401
+ if (status === "draft") {
402
+ return {
403
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.CheckCircle, { fill: "success600" }),
404
+ text: formatMessage({
405
+ id: "content-manager.bulk-unpublish.already-unpublished",
406
+ defaultMessage: "Already Unpublished"
407
+ }),
408
+ textColor: "success600",
409
+ fontWeight: "bold"
410
+ };
411
+ } else {
412
+ return {
413
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.CheckCircle, { fill: "success600" }),
414
+ text: formatMessage({
415
+ id: "app.utils.ready-to-unpublish-changes",
416
+ defaultMessage: "Ready to unpublish"
417
+ }),
418
+ textColor: "success600",
419
+ fontWeight: "bold"
420
+ };
421
+ }
422
+ }
423
+ };
424
+ const { icon, text, textColor = "success600", fontWeight = "normal" } = getStatusMessage();
299
425
  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
- }) })
426
+ icon,
427
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor, fontWeight, children: text })
305
428
  ] });
306
429
  };
307
430
  const BoldChunk = (chunks) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { fontWeight: "bold", children: chunks });
@@ -309,7 +432,8 @@ const BulkLocaleActionModal = ({
309
432
  headers,
310
433
  rows,
311
434
  localesMetadata,
312
- validationErrors = {}
435
+ validationErrors = {},
436
+ action
313
437
  }) => {
314
438
  const { formatMessage } = reactIntl.useIntl();
315
439
  const selectedRows = strapiAdmin.useTable(
@@ -322,22 +446,24 @@ const BulkLocaleActionModal = ({
322
446
  return acc;
323
447
  }, {});
324
448
  const localesWithErrors = Object.keys(validationErrors);
325
- const alreadyPublishedCount = selectedRows.filter(
449
+ const publishedCount = selectedRows.filter(
326
450
  ({ locale }) => currentStatusByLocale[locale] === "published"
327
451
  ).length;
328
- const readyToPublishCount = selectedRows.filter(
452
+ const draftCount = selectedRows.filter(
329
453
  ({ locale }) => (currentStatusByLocale[locale] === "draft" || currentStatusByLocale[locale] === "modified") && !localesWithErrors.includes(locale)
330
454
  ).length;
331
455
  const withErrorsCount = localesWithErrors.length;
456
+ const messageId = action === "bulk-publish" ? "content-manager.containers.list.selectedEntriesModal.selectedCount.publish" : "content-manager.containers.list.selectedEntriesModal.selectedCount.unpublish";
457
+ const defaultMessage = action === "bulk-publish" ? "<b>{publishedCount}</b> {publishedCount, plural, =0 {entries} one {entry} other {entries}} already published. <b>{draftCount}</b> {draftCount, plural, =0 {entries} one {entry} other {entries}} ready to publish. <b>{withErrorsCount}</b> {withErrorsCount, plural, =0 {entries} one {entry} other {entries}} waiting for action." : "<b>{draftCount}</b> {draftCount, plural, =0 {entries} one {entry} other {entries}} already unpublished. <b>{publishedCount}</b> {publishedCount, plural, =0 {entries} one {entry} other {entries}} ready to unpublish.";
332
458
  return formatMessage(
333
459
  {
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."
460
+ id: messageId,
461
+ defaultMessage
336
462
  },
337
463
  {
338
464
  withErrorsCount,
339
- readyToPublishCount,
340
- alreadyPublishedCount,
465
+ draftCount,
466
+ publishedCount,
341
467
  b: BoldChunk
342
468
  }
343
469
  );
@@ -363,13 +489,12 @@ const BulkLocaleActionModal = ({
363
489
  paddingRight: "6px",
364
490
  paddingTop: "2px",
365
491
  paddingBottom: "2px",
366
- showBullet: false,
367
492
  size: "S",
368
493
  variant: statusVariant,
369
494
  children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "span", variant: "pi", fontWeight: "bold", children: capitalize(status) })
370
495
  }
371
496
  ) }) }),
372
- /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(EntryValidationText, { validationErrors: error, status }) }),
497
+ /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(EntryValidationText, { validationErrors: error, status, action }) }),
373
498
  /* @__PURE__ */ jsxRuntime.jsx(strapiAdmin.Table.Cell, { children: /* @__PURE__ */ jsxRuntime.jsx(
374
499
  designSystem.IconButton,
375
500
  {
@@ -395,6 +520,47 @@ const BulkLocaleActionModal = ({
395
520
  ] }) })
396
521
  ] });
397
522
  };
523
+ const statusVariants = {
524
+ draft: "secondary",
525
+ published: "success",
526
+ modified: "alternative"
527
+ };
528
+ const LocaleOption = ({
529
+ isDraftAndPublishEnabled,
530
+ locale,
531
+ status,
532
+ entryExists
533
+ }) => {
534
+ const { formatMessage } = reactIntl.useIntl();
535
+ if (!entryExists) {
536
+ return formatMessage(
537
+ {
538
+ id: getTranslation("CMEditViewLocalePicker.locale.create"),
539
+ defaultMessage: "Create <bold>{locale}</bold> locale"
540
+ },
541
+ {
542
+ bold: (locale2) => /* @__PURE__ */ jsxRuntime.jsx("b", { children: locale2 }),
543
+ locale: locale.name
544
+ }
545
+ );
546
+ }
547
+ return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { width: "100%", gap: 1, justifyContent: "space-between", children: [
548
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { children: locale.name }),
549
+ isDraftAndPublishEnabled ? /* @__PURE__ */ jsxRuntime.jsx(
550
+ designSystem.Status,
551
+ {
552
+ display: "flex",
553
+ paddingLeft: "6px",
554
+ paddingRight: "6px",
555
+ paddingTop: "2px",
556
+ paddingBottom: "2px",
557
+ size: "S",
558
+ variant: statusVariants[status],
559
+ children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { tag: "span", variant: "pi", fontWeight: "bold", children: capitalize(status) })
560
+ }
561
+ ) : null
562
+ ] });
563
+ };
398
564
  const LocalePickerAction = ({
399
565
  document,
400
566
  meta,
@@ -406,7 +572,13 @@ const LocalePickerAction = ({
406
572
  const [{ query: query2 }, setQuery] = strapiAdmin.useQueryParams();
407
573
  const { hasI18n, canCreate, canRead } = useI18n();
408
574
  const { data: locales = [] } = useGetLocalesQuery();
409
- const { schema } = strapiAdmin$1.unstable_useDocument({ model, collectionType, documentId });
575
+ const currentDesiredLocale = query2.plugins?.i18n?.locale;
576
+ const { schema } = strapiAdmin$1.unstable_useDocument({
577
+ model,
578
+ collectionType,
579
+ documentId,
580
+ params: { locale: currentDesiredLocale }
581
+ });
410
582
  const handleSelect = React__namespace.useCallback(
411
583
  (value) => {
412
584
  setQuery({
@@ -424,53 +596,50 @@ const LocalePickerAction = ({
424
596
  if (!Array.isArray(locales) || !hasI18n) {
425
597
  return;
426
598
  }
427
- const currentDesiredLocale = query2.plugins?.i18n?.locale;
428
599
  const doesLocaleExist = locales.find((loc) => loc.code === currentDesiredLocale);
429
600
  const defaultLocale = locales.find((locale) => locale.isDefault);
430
601
  if (!doesLocaleExist && defaultLocale?.code) {
431
602
  handleSelect(defaultLocale.code);
432
603
  }
433
- }, [handleSelect, hasI18n, locales, query2.plugins?.i18n?.locale]);
434
- if (!hasI18n || !Array.isArray(locales) || locales.length === 0) {
435
- return null;
436
- }
437
- const currentLocale = query2.plugins?.i18n?.locale || locales.find((loc) => loc.isDefault)?.code;
604
+ }, [handleSelect, hasI18n, locales, currentDesiredLocale]);
605
+ const currentLocale = Array.isArray(locales) ? locales.find((locale) => locale.code === currentDesiredLocale) : void 0;
438
606
  const allCurrentLocales = [
439
- { status: getDocumentStatus(document, meta), locale: currentLocale },
607
+ { status: getDocumentStatus(document, meta), locale: currentLocale?.code },
440
608
  ...meta?.availableLocales ?? []
441
609
  ];
610
+ if (!hasI18n || !Array.isArray(locales) || locales.length === 0) {
611
+ return null;
612
+ }
613
+ const displayedLocales = locales.filter((locale) => {
614
+ return canRead.includes(locale.code);
615
+ });
442
616
  return {
443
617
  label: formatMessage({
444
618
  id: getTranslation("Settings.locales.modal.locales.label"),
445
619
  defaultMessage: "Locales"
446
620
  }),
447
- options: locales.map((locale) => {
621
+ options: displayedLocales.map((locale) => {
622
+ const entryWithLocaleExists = allCurrentLocales.some((doc) => doc.locale === locale.code);
448
623
  const currentLocaleDoc = allCurrentLocales.find(
449
624
  (doc) => "locale" in doc ? doc.locale === locale.code : false
450
625
  );
451
- const status = currentLocaleDoc?.status ?? "draft";
452
- const permissionsToCheck = currentLocaleDoc ? canCreate : canRead;
453
- const statusVariant = status === "draft" ? "primary" : status === "published" ? "success" : "alternative";
626
+ const permissionsToCheck = currentLocaleDoc ? canRead : canCreate;
454
627
  return {
455
628
  disabled: !permissionsToCheck.includes(locale.code),
456
629
  value: locale.code,
457
- label: locale.name,
458
- startIcon: schema?.options?.draftAndPublish ? /* @__PURE__ */ jsxRuntime.jsx(
459
- designSystem.Status,
630
+ label: /* @__PURE__ */ jsxRuntime.jsx(
631
+ LocaleOption,
460
632
  {
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) })
633
+ isDraftAndPublishEnabled: !!schema?.options?.draftAndPublish,
634
+ locale,
635
+ status: currentLocaleDoc?.status,
636
+ entryExists: entryWithLocaleExists
470
637
  }
471
- ) : null
638
+ ),
639
+ startIcon: !entryWithLocaleExists ? /* @__PURE__ */ jsxRuntime.jsx(icons.Plus, {}) : null
472
640
  };
473
641
  }),
642
+ customizeContent: () => currentLocale?.name,
474
643
  onSelect: handleSelect,
475
644
  value: currentLocale
476
645
  };
@@ -486,6 +655,99 @@ const getDocumentStatus = (document, meta) => {
486
655
  }
487
656
  return docStatus;
488
657
  };
658
+ const FillFromAnotherLocaleAction = ({
659
+ documentId,
660
+ meta,
661
+ model,
662
+ collectionType
663
+ }) => {
664
+ const { formatMessage } = reactIntl.useIntl();
665
+ const [{ query: query2 }] = strapiAdmin.useQueryParams();
666
+ const { hasI18n } = useI18n();
667
+ const currentDesiredLocale = query2.plugins?.i18n?.locale;
668
+ const [localeSelected, setLocaleSelected] = React__namespace.useState(null);
669
+ const setValues = strapiAdmin.useForm("FillFromAnotherLocale", (state) => state.setValues);
670
+ const { getDocument } = strapiAdmin$1.unstable_useDocumentActions();
671
+ const { schema, components } = strapiAdmin$1.unstable_useDocument({
672
+ model,
673
+ documentId,
674
+ collectionType,
675
+ params: { locale: currentDesiredLocale }
676
+ });
677
+ const { data: locales = [] } = useGetLocalesQuery();
678
+ const availableLocales = Array.isArray(locales) ? locales.filter((locale) => meta?.availableLocales.some((l) => l.locale === locale.code)) : [];
679
+ const fillFromLocale = (onClose) => async () => {
680
+ const response = await getDocument({
681
+ collectionType,
682
+ model,
683
+ documentId,
684
+ params: { locale: localeSelected }
685
+ });
686
+ if (!response || !schema) {
687
+ return;
688
+ }
689
+ const { data } = response;
690
+ const cleanedData = cleanData(data, schema, components);
691
+ setValues(cleanedData);
692
+ onClose();
693
+ };
694
+ if (!hasI18n) {
695
+ return null;
696
+ }
697
+ return {
698
+ type: "icon",
699
+ icon: /* @__PURE__ */ jsxRuntime.jsx(icons.Download, {}),
700
+ disabled: availableLocales.length === 0,
701
+ label: formatMessage({
702
+ id: getTranslation("CMEditViewCopyLocale.copy-text"),
703
+ defaultMessage: "Fill in from another locale"
704
+ }),
705
+ dialog: {
706
+ type: "dialog",
707
+ title: formatMessage({
708
+ id: getTranslation("CMEditViewCopyLocale.dialog.title"),
709
+ defaultMessage: "Confirmation"
710
+ }),
711
+ content: ({ onClose }) => /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
712
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Body, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { direction: "column", gap: 3, children: [
713
+ /* @__PURE__ */ jsxRuntime.jsx(icons.WarningCircle, { width: "24px", height: "24px", fill: "danger600" }),
714
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textAlign: "center", children: formatMessage({
715
+ id: getTranslation("CMEditViewCopyLocale.dialog.body"),
716
+ defaultMessage: "Your current content will be erased and filled by the content of the selected locale:"
717
+ }) }),
718
+ /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Field.Root, { width: "100%", children: [
719
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Field.Label, { children: formatMessage({
720
+ id: getTranslation("CMEditViewCopyLocale.dialog.field.label"),
721
+ defaultMessage: "Locale"
722
+ }) }),
723
+ /* @__PURE__ */ jsxRuntime.jsx(
724
+ designSystem.SingleSelect,
725
+ {
726
+ value: localeSelected,
727
+ placeholder: formatMessage({
728
+ id: getTranslation("CMEditViewCopyLocale.dialog.field.placeholder"),
729
+ defaultMessage: "Select one locale..."
730
+ }),
731
+ onChange: (value) => setLocaleSelected(value),
732
+ children: availableLocales.map((locale) => /* @__PURE__ */ jsxRuntime.jsx(designSystem.SingleSelectOption, { value: locale.code, children: locale.name }, locale.code))
733
+ }
734
+ )
735
+ ] })
736
+ ] }) }),
737
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Dialog.Footer, { children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { gap: 2, width: "100%", children: [
738
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { flex: "auto", variant: "tertiary", onClick: onClose, children: formatMessage({
739
+ id: getTranslation("CMEditViewCopyLocale.cancel-text"),
740
+ defaultMessage: "No, cancel"
741
+ }) }),
742
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { flex: "auto", variant: "success", onClick: fillFromLocale(onClose), children: formatMessage({
743
+ id: getTranslation("CMEditViewCopyLocale.submit-text"),
744
+ defaultMessage: "Yes, fill in"
745
+ }) })
746
+ ] }) })
747
+ ] })
748
+ }
749
+ };
750
+ };
489
751
  const DeleteLocaleAction = ({
490
752
  document,
491
753
  documentId,
@@ -497,16 +759,23 @@ const DeleteLocaleAction = ({
497
759
  const { toggleNotification } = strapiAdmin.useNotification();
498
760
  const { delete: deleteAction } = strapiAdmin$1.unstable_useDocumentActions();
499
761
  const { hasI18n, canDelete } = useI18n();
762
+ const [{ query: query2 }] = strapiAdmin.useQueryParams();
763
+ const { data: locales = [] } = useGetLocalesQuery();
764
+ const currentDesiredLocale = query2.plugins?.i18n?.locale;
765
+ const locale = !("error" in locales) && locales.find((loc) => loc.code === currentDesiredLocale);
500
766
  if (!hasI18n) {
501
767
  return null;
502
768
  }
503
769
  return {
504
770
  disabled: document?.locale && !canDelete.includes(document.locale) || !document || !document.id,
505
771
  position: ["header", "table-row"],
506
- label: formatMessage({
507
- id: getTranslation("actions.delete.label"),
508
- defaultMessage: "Delete locale"
509
- }),
772
+ label: formatMessage(
773
+ {
774
+ id: getTranslation("actions.delete.label"),
775
+ defaultMessage: "Delete entry ({locale})"
776
+ },
777
+ { locale: locale && locale.name }
778
+ ),
510
779
  icon: /* @__PURE__ */ jsxRuntime.jsx(StyledTrash, {}),
511
780
  variant: "danger",
512
781
  dialog: {
@@ -523,7 +792,12 @@ const DeleteLocaleAction = ({
523
792
  }) })
524
793
  ] }),
525
794
  onConfirm: async () => {
526
- if (!documentId || !document?.locale) {
795
+ const unableToDelete = (
796
+ // We are unable to delete a collection type without a document ID
797
+ // & unable to delete generally if there is no document locale
798
+ collectionType !== "single-types" && !documentId || !document?.locale
799
+ );
800
+ if (unableToDelete) {
527
801
  console.error(
528
802
  "You're trying to delete a document without an id or locale, this is likely a bug with Strapi. Please open an issue."
529
803
  );
@@ -549,23 +823,24 @@ const DeleteLocaleAction = ({
549
823
  }
550
824
  };
551
825
  };
552
- const BulkLocalePublishAction = ({
826
+ const BulkLocaleAction = ({
553
827
  document: baseDocument,
554
828
  documentId,
555
829
  model,
556
- collectionType
830
+ collectionType,
831
+ action
557
832
  }) => {
558
833
  const baseLocale = baseDocument?.locale ?? null;
559
834
  const [{ query: query$1 }] = strapiAdmin.useQueryParams();
560
835
  const params = React__namespace.useMemo(() => strapiAdmin$1.buildValidParams(query$1), [query$1]);
561
- const isPublishedTab = query$1.status === "published";
836
+ const isOnPublishedTab = query$1.status === "published";
562
837
  const { formatMessage } = reactIntl.useIntl();
563
838
  const { hasI18n, canPublish } = useI18n();
564
839
  const { toggleNotification } = strapiAdmin.useNotification();
565
840
  const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
566
841
  const [selectedRows, setSelectedRows] = React__namespace.useState([]);
567
842
  const [isDraftRelationConfirmationOpen, setIsDraftRelationConfirmationOpen] = React__namespace.useState(false);
568
- const { publishMany: publishManyAction } = strapiAdmin$1.unstable_useDocumentActions();
843
+ const { publishMany: publishManyAction, unpublishMany: unpublishManyAction } = strapiAdmin$1.unstable_useDocumentActions();
569
844
  const {
570
845
  document,
571
846
  meta: documentMeta,
@@ -581,7 +856,7 @@ const BulkLocalePublishAction = ({
581
856
  }
582
857
  },
583
858
  {
584
- skip: !hasI18n
859
+ skip: !hasI18n || !baseLocale
585
860
  }
586
861
  );
587
862
  const { data: localesMetadata = [] } = useGetLocalesQuery(hasI18n ? void 0 : query.skipToken);
@@ -633,12 +908,19 @@ const BulkLocalePublishAction = ({
633
908
  }, {});
634
909
  return [rowsFromMeta, errors];
635
910
  }, [document, documentMeta?.availableLocales, validate]);
636
- const localesToPublish = selectedRows.reduce((acc, selectedRow) => {
637
- if (selectedRow.status !== "published" && !Object.keys(validationErrors).includes(selectedRow.locale)) {
911
+ const isBulkPublish = action === "bulk-publish";
912
+ const localesForAction = selectedRows.reduce((acc, selectedRow) => {
913
+ const isValidLocale = (
914
+ // Validation errors are irrelevant if we are trying to unpublish
915
+ !isBulkPublish || !Object.keys(validationErrors).includes(selectedRow.locale)
916
+ );
917
+ const shouldAddLocale = isBulkPublish ? selectedRow.status !== "published" && isValidLocale : selectedRow.status !== "draft" && isValidLocale;
918
+ if (shouldAddLocale) {
638
919
  acc.push(selectedRow.locale);
639
920
  }
640
921
  return acc;
641
922
  }, []);
923
+ const enableDraftRelationsCount = false;
642
924
  const {
643
925
  data: draftRelationsCount = 0,
644
926
  isLoading: isDraftRelationsLoading,
@@ -647,10 +929,10 @@ const BulkLocalePublishAction = ({
647
929
  {
648
930
  model,
649
931
  documentIds: [documentId],
650
- locale: localesToPublish
932
+ locale: localesForAction
651
933
  },
652
934
  {
653
- skip: !documentId || localesToPublish.length === 0
935
+ skip: !enableDraftRelationsCount
654
936
  }
655
937
  );
656
938
  React__namespace.useEffect(() => {
@@ -676,7 +958,18 @@ const BulkLocalePublishAction = ({
676
958
  documentIds: [documentId],
677
959
  params: {
678
960
  ...params,
679
- locale: localesToPublish
961
+ locale: localesForAction
962
+ }
963
+ });
964
+ setSelectedRows([]);
965
+ };
966
+ const unpublish = async () => {
967
+ await unpublishManyAction({
968
+ model,
969
+ documentIds: [documentId],
970
+ params: {
971
+ ...params,
972
+ locale: localesForAction
680
973
  }
681
974
  });
682
975
  setSelectedRows([]);
@@ -684,14 +977,12 @@ const BulkLocalePublishAction = ({
684
977
  const handleAction = async () => {
685
978
  if (draftRelationsCount > 0) {
686
979
  setIsDraftRelationConfirmationOpen(true);
687
- } else {
980
+ } else if (isBulkPublish) {
688
981
  await publish();
982
+ } else {
983
+ await unpublish();
689
984
  }
690
985
  };
691
- const isUnpublish = document?.status === "published";
692
- if (isUnpublish) {
693
- console.warn(["I18N"], "Bulk locale unpublish modal not implemented");
694
- }
695
986
  if (isDraftRelationConfirmationOpen) {
696
987
  return {
697
988
  label: formatMessage({
@@ -729,18 +1020,18 @@ const BulkLocalePublishAction = ({
729
1020
  const hasPermission = selectedRows.map(({ locale }) => locale).every((locale) => canPublish.includes(locale));
730
1021
  return {
731
1022
  label: formatMessage({
732
- id: getTranslation("CMEditViewBulkLocale.publish-title"),
733
- defaultMessage: "Publish Multiple Locales"
1023
+ id: getTranslation(`CMEditViewBulkLocale.${isBulkPublish ? "publish" : "unpublish"}-title`),
1024
+ defaultMessage: `${isBulkPublish ? "Publish" : "Unpublish"} Multiple Locales`
734
1025
  }),
735
- icon: /* @__PURE__ */ jsxRuntime.jsx(icons.ListPlus, {}),
736
- disabled: isPublishedTab || canPublish.length === 0,
1026
+ variant: isBulkPublish ? "secondary" : "danger",
1027
+ icon: isBulkPublish ? /* @__PURE__ */ jsxRuntime.jsx(icons.ListPlus, {}) : /* @__PURE__ */ jsxRuntime.jsx(icons.Cross, {}),
1028
+ disabled: isOnPublishedTab || canPublish.length === 0,
737
1029
  position: ["panel"],
738
- variant: "secondary",
739
1030
  dialog: {
740
1031
  type: "modal",
741
1032
  title: formatMessage({
742
- id: getTranslation("CMEditViewBulkLocale.publish-title"),
743
- defaultMessage: "Publish Multiple Locales"
1033
+ id: getTranslation(`CMEditViewBulkLocale.${isBulkPublish ? "publish" : "unpublish"}-title`),
1034
+ defaultMessage: `${isBulkPublish ? "Publish" : "Unpublish"} Multiple Locales`
744
1035
  }),
745
1036
  content: () => {
746
1037
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -759,7 +1050,8 @@ const BulkLocalePublishAction = ({
759
1050
  validationErrors,
760
1051
  headers,
761
1052
  rows,
762
- localesMetadata
1053
+ localesMetadata,
1054
+ action: action ?? "bulk-publish"
763
1055
  }
764
1056
  )
765
1057
  }
@@ -769,18 +1061,24 @@ const BulkLocalePublishAction = ({
769
1061
  designSystem.Button,
770
1062
  {
771
1063
  loading: isDraftRelationsLoading,
772
- disabled: !hasPermission || localesToPublish.length === 0,
1064
+ disabled: !hasPermission || localesForAction.length === 0,
773
1065
  variant: "default",
774
1066
  onClick: handleAction,
775
1067
  children: formatMessage({
776
- id: "app.utils.publish",
777
- defaultMessage: "Publish"
1068
+ id: isBulkPublish ? "app.utils.publish" : "app.utils.unpublish",
1069
+ defaultMessage: isBulkPublish ? "Publish" : "Unpublish"
778
1070
  })
779
1071
  }
780
1072
  ) })
781
1073
  }
782
1074
  };
783
1075
  };
1076
+ const BulkLocalePublishAction = (props) => {
1077
+ return BulkLocaleAction({ action: "bulk-publish", ...props });
1078
+ };
1079
+ const BulkLocaleUnpublishAction = (props) => {
1080
+ return BulkLocaleAction({ action: "bulk-unpublish", ...props });
1081
+ };
784
1082
  const StyledTrash = styledComponents.styled(icons.Trash)`
785
1083
  path {
786
1084
  fill: currentColor;
@@ -1000,54 +1298,13 @@ const LocaleListCell = ({
1000
1298
  return locale.name;
1001
1299
  }).toSorted((a, b) => formatter.compare(a, b));
1002
1300
  return /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Popover.Root, { children: [
1003
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Popover.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsx(Button, { type: "button", onClick: (e) => e.stopPropagation(), children: /* @__PURE__ */ jsxRuntime.jsxs(
1004
- ActionWrapper,
1005
- {
1006
- minWidth: "100%",
1007
- alignItems: "center",
1008
- justifyContent: "center",
1009
- height: "3.2rem",
1010
- width: "3.2rem",
1011
- children: [
1012
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral800", ellipsis: true, children: localesForDocument.join(", ") }),
1013
- /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { children: /* @__PURE__ */ jsxRuntime.jsx(icons.CaretDown, {}) })
1014
- ]
1015
- }
1016
- ) }) }),
1301
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Popover.Trigger, { children: /* @__PURE__ */ jsxRuntime.jsx(designSystem.Button, { variant: "ghost", type: "button", onClick: (e) => e.stopPropagation(), children: /* @__PURE__ */ jsxRuntime.jsxs(designSystem.Flex, { minWidth: "100%", alignItems: "center", justifyContent: "center", fontWeight: "regular", children: [
1302
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Typography, { textColor: "neutral800", ellipsis: true, marginRight: 2, children: localesForDocument.join(", ") }),
1303
+ /* @__PURE__ */ jsxRuntime.jsx(designSystem.Flex, { children: /* @__PURE__ */ jsxRuntime.jsx(icons.CaretDown, { width: "1.2rem", height: "1.2rem" }) })
1304
+ ] }) }) }),
1017
1305
  /* @__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)) }) })
1018
1306
  ] });
1019
1307
  };
1020
- const Button = styledComponents.styled.button`
1021
- width: 100%;
1022
-
1023
- svg {
1024
- > g,
1025
- path {
1026
- fill: ${({ theme }) => theme.colors.neutral500};
1027
- }
1028
- }
1029
- &:hover {
1030
- svg {
1031
- > g,
1032
- path {
1033
- fill: ${({ theme }) => theme.colors.neutral600};
1034
- }
1035
- }
1036
- }
1037
- &:active {
1038
- svg {
1039
- > g,
1040
- path {
1041
- fill: ${({ theme }) => theme.colors.neutral400};
1042
- }
1043
- }
1044
- }
1045
- `;
1046
- const ActionWrapper = styledComponents.styled(designSystem.Flex)`
1047
- svg {
1048
- height: 0.4rem;
1049
- }
1050
- `;
1051
1308
  const addColumnToTableHook = ({ displayedHeaders, layout }) => {
1052
1309
  const { options } = layout;
1053
1310
  const isFieldLocalized = doesPluginOptionsHaveI18nLocalized(options) ? options.i18n.localized : false;
@@ -1173,9 +1430,6 @@ const localeMiddleware = (ctx) => (next) => (permissions) => {
1173
1430
  return next(revisedPermissions);
1174
1431
  };
1175
1432
  const prefixPluginTranslations = (trad, pluginId2) => {
1176
- if (!pluginId2) {
1177
- throw new TypeError("pluginId can't be empty");
1178
- }
1179
1433
  return Object.keys(trad).reduce((acc, current) => {
1180
1434
  acc[`${pluginId2}.${current}`] = trad[current];
1181
1435
  return acc;
@@ -1245,11 +1499,11 @@ const index = {
1245
1499
  },
1246
1500
  id: "internationalization",
1247
1501
  to: "internationalization",
1248
- Component: () => Promise.resolve().then(() => require("./SettingsPage-C0l7c5fn.js")).then((mod) => ({ default: mod.ProtectedSettingsPage })),
1502
+ Component: () => Promise.resolve().then(() => require("./SettingsPage-BTgjb2KS.js")).then((mod) => ({ default: mod.ProtectedSettingsPage })),
1249
1503
  permissions: PERMISSIONS.accessMain
1250
1504
  });
1251
1505
  const contentManager = app.getPlugin("content-manager");
1252
- contentManager.apis.addDocumentHeaderAction([LocalePickerAction]);
1506
+ contentManager.apis.addDocumentHeaderAction([LocalePickerAction, FillFromAnotherLocaleAction]);
1253
1507
  contentManager.apis.addDocumentAction((actions) => {
1254
1508
  const indexOfDeleteAction = actions.findIndex((action) => action.type === "delete");
1255
1509
  actions.splice(indexOfDeleteAction, 0, DeleteLocaleAction);
@@ -1257,6 +1511,7 @@ const index = {
1257
1511
  });
1258
1512
  contentManager.apis.addDocumentAction((actions) => {
1259
1513
  actions.splice(2, 0, BulkLocalePublishAction);
1514
+ actions.splice(5, 0, BulkLocaleUnpublishAction);
1260
1515
  return actions;
1261
1516
  });
1262
1517
  contentManager.injectComponent("listView", "actions", {
@@ -1362,7 +1617,7 @@ const index = {
1362
1617
  async registerTrads({ locales }) {
1363
1618
  const importedTrads = await Promise.all(
1364
1619
  locales.map((locale) => {
1365
- 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-BsOU9o5z.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 }) => {
1620
+ 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-BKBz3tro.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`, 3).then(({ default: data }) => {
1366
1621
  return {
1367
1622
  data: prefixPluginTranslations(data, pluginId),
1368
1623
  locale
@@ -1386,4 +1641,4 @@ exports.useDeleteLocaleMutation = useDeleteLocaleMutation;
1386
1641
  exports.useGetDefaultLocalesQuery = useGetDefaultLocalesQuery;
1387
1642
  exports.useGetLocalesQuery = useGetLocalesQuery;
1388
1643
  exports.useUpdateLocaleMutation = useUpdateLocaleMutation;
1389
- //# sourceMappingURL=index-C0i3v7QQ.js.map
1644
+ //# sourceMappingURL=index-3yyF237r.js.map