gt-sanity 1.0.2 → 1.0.4

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.
package/dist/index.mjs CHANGED
@@ -12,8 +12,8 @@ import merge from "lodash.merge";
12
12
  import { extractWithPath, arrayToJSONMatchPath } from "@sanity/mutator";
13
13
  import { JSONPath } from "jsonpath-plus";
14
14
  import JSONPointer from "jsonpointer";
15
- import { CheckmarkCircleIcon, DownloadIcon, LinkIcon, PublishIcon } from "@sanity/icons";
16
- import { Link, route } from "sanity/router";
15
+ import { CheckmarkCircleIcon, DownloadIcon, LinkIcon, PublishIcon, TranslateIcon } from "@sanity/icons";
16
+ import { useRouter, Link, route } from "sanity/router";
17
17
  const useClient = () => useClient$1({ apiVersion: "2025-09-15" });
18
18
  function useSecrets(id) {
19
19
  const [loading, setLoading] = useState(!0), [secrets, setSecrets] = useState(null), client = useClient();
@@ -1436,170 +1436,167 @@ const getLocales = async (secrets) => pluginConfig.getLocales().map((locale) =>
1436
1436
  }
1437
1437
  }, [secrets, documents, locales]), handleImportDocument = useCallback(
1438
1438
  async (documentId, localeId) => {
1439
- if (secrets)
1440
- try {
1441
- const key = `${documentId}:${localeId}`, status = translationStatuses.get(key);
1442
- if (!status?.isReady || !status.translationId) {
1443
- toast.push({
1444
- title: `Translation not ready for ${documentId} (${localeId})`,
1445
- status: "warning",
1439
+ if (!secrets) return;
1440
+ const key = `${documentId}:${localeId}`, status = translationStatuses.get(key);
1441
+ if (!status?.isReady || !status.translationId) {
1442
+ toast.push({
1443
+ title: `Translation not ready for ${documentId} (${localeId})`,
1444
+ status: "warning",
1445
+ closable: !0
1446
+ });
1447
+ return;
1448
+ }
1449
+ const document2 = documents.find(
1450
+ (doc) => (doc._id?.replace("drafts.", "") || doc._id) === documentId
1451
+ );
1452
+ if (!document2) {
1453
+ toast.push({
1454
+ title: `Document ${documentId} not found`,
1455
+ status: "error",
1456
+ closable: !0
1457
+ });
1458
+ return;
1459
+ }
1460
+ try {
1461
+ const downloadedFiles = await downloadTranslations(
1462
+ [
1463
+ {
1464
+ documentId,
1465
+ versionId: document2._rev,
1466
+ translationId: status.translationId,
1467
+ locale: localeId
1468
+ }
1469
+ ],
1470
+ secrets
1471
+ );
1472
+ if (downloadedFiles.length > 0)
1473
+ try {
1474
+ const docInfo = {
1475
+ documentId,
1476
+ versionId: document2._rev
1477
+ };
1478
+ await importDocument(
1479
+ docInfo,
1480
+ localeId,
1481
+ downloadedFiles[0].data,
1482
+ translationContext,
1483
+ !1
1484
+ ), setDownloadStatus((prev2) => ({
1485
+ ...prev2,
1486
+ downloaded: /* @__PURE__ */ new Set([...prev2.downloaded, key])
1487
+ })), setImportedTranslations((prev2) => /* @__PURE__ */ new Set([...prev2, key])), toast.push({
1488
+ title: `Successfully imported translation for ${documentId} (${localeId})`,
1489
+ status: "success",
1446
1490
  closable: !0
1447
1491
  });
1448
- return;
1449
- }
1450
- const document2 = documents.find(
1451
- (doc) => (doc._id?.replace("drafts.", "") || doc._id) === documentId
1452
- );
1453
- if (!document2) {
1454
- toast.push({
1455
- title: `Document ${documentId} not found`,
1492
+ } catch (importError) {
1493
+ console.error("Failed to import translation:", importError), toast.push({
1494
+ title: `Failed to import translation for ${documentId} (${localeId})`,
1456
1495
  status: "error",
1457
1496
  closable: !0
1458
1497
  });
1459
- return;
1460
1498
  }
1461
- const downloadedFiles = await downloadTranslations(
1462
- [
1463
- {
1464
- documentId,
1465
- versionId: document2._rev,
1466
- translationId: status.translationId,
1467
- locale: localeId
1468
- }
1469
- ],
1470
- secrets
1471
- );
1472
- if (downloadedFiles.length > 0)
1473
- try {
1474
- const docInfo = {
1475
- documentId,
1476
- versionId: document2._rev
1477
- };
1478
- await importDocument(
1479
- docInfo,
1480
- localeId,
1481
- downloadedFiles[0].data,
1482
- translationContext,
1483
- !1
1484
- ), setDownloadStatus((prev2) => ({
1485
- ...prev2,
1486
- downloaded: /* @__PURE__ */ new Set([...prev2.downloaded, key])
1487
- })), setImportedTranslations((prev2) => /* @__PURE__ */ new Set([...prev2, key])), toast.push({
1488
- title: `Successfully imported translation for ${documentId} (${localeId})`,
1489
- status: "success",
1490
- closable: !0
1491
- });
1492
- } catch (importError) {
1493
- console.error("Failed to import translation:", importError), toast.push({
1494
- title: `Failed to import translation for ${documentId} (${localeId})`,
1495
- status: "error",
1496
- closable: !0
1497
- });
1498
- }
1499
- else
1500
- toast.push({
1501
- title: `No translation content received for ${documentId}`,
1502
- status: "warning",
1503
- closable: !0
1504
- });
1505
- } catch (error) {
1506
- console.error("Error importing translation:", error), toast.push({
1507
- title: `Error importing translation for ${documentId}`,
1508
- status: "error",
1499
+ else
1500
+ toast.push({
1501
+ title: `No translation content received for ${documentId}`,
1502
+ status: "warning",
1509
1503
  closable: !0
1510
1504
  });
1511
- }
1512
- },
1513
- [secrets, documents, translationContext]
1514
- ), handlePatchDocumentReferences = useCallback(async () => {
1515
- if (!(!secrets || documents.length === 0)) {
1516
- setIsBusy(!0);
1517
- try {
1518
- const availableLocaleIds = locales.filter((locale) => locale.enabled !== !1).map((locale) => locale.localeId), patchTasks = [];
1519
- for (const doc of documents)
1520
- for (const localeId of availableLocaleIds)
1521
- patchTasks.push({ doc, localeId });
1522
- setImportProgress({
1523
- current: 0,
1524
- total: patchTasks.length,
1525
- isImporting: !0
1526
- });
1527
- const result = await processBatch(
1528
- patchTasks,
1529
- async ({ doc, localeId }) => {
1530
- const sourceLocale = pluginConfig.getSourceLocale();
1531
- if (localeId === sourceLocale)
1532
- return { patched: !1, doc, localeId, skipped: !0 };
1533
- const translatedDoc = await findTranslatedDocumentForLocale(
1534
- doc._id,
1535
- localeId,
1536
- client
1537
- );
1538
- if (!translatedDoc)
1539
- return { patched: !1, doc, localeId, noTranslation: !0 };
1540
- const resolvedDoc = await resolveRefs(
1541
- translatedDoc,
1542
- localeId,
1543
- client
1544
- );
1545
- if (resolvedDoc !== translatedDoc) {
1546
- const mutation = {
1547
- patch: {
1548
- id: translatedDoc._id,
1549
- set: resolvedDoc
1550
- }
1551
- };
1552
- return await client.mutate([mutation]), { patched: !0, doc: translatedDoc, localeId };
1553
- }
1554
- return { patched: !1, doc: translatedDoc, localeId };
1555
- },
1556
- {
1557
- onProgress: (current, total) => {
1558
- setImportProgress({
1559
- current,
1560
- total,
1561
- isImporting: !0
1562
- });
1563
- },
1564
- onItemFailure: ({ doc, localeId }, error) => {
1565
- console.error(
1566
- `Failed to patch references for ${doc._id} (${localeId}):`,
1567
- error
1568
- );
1569
- }
1570
- }
1571
- ), patchedCount = result.successfulItems.filter(
1572
- (item) => item.patched
1573
- ).length;
1574
- toast.push({
1575
- title: `Patched references in ${patchedCount} documents${result.failureCount > 0 ? `, ${result.failureCount} failed` : ""}`,
1576
- status: patchedCount > 0 || result.failureCount === 0 ? "success" : "error",
1577
- closable: !0
1578
- });
1579
1505
  } catch (error) {
1580
- console.error("Error patching document references:", error), toast.push({
1581
- title: "Error patching document references",
1506
+ console.error("Error importing translation:", error), toast.push({
1507
+ title: `Error importing translation for ${documentId}`,
1582
1508
  status: "error",
1583
1509
  closable: !0
1584
1510
  });
1585
- } finally {
1586
- setIsBusy(!1), setImportProgress({ current: 0, total: 0, isImporting: !1 });
1587
1511
  }
1512
+ },
1513
+ [secrets, documents, translationContext, translationStatuses]
1514
+ ), handlePatchDocumentReferences = useCallback(async () => {
1515
+ if (!secrets || documents.length === 0) return 0;
1516
+ setIsBusy(!0);
1517
+ try {
1518
+ const availableLocaleIds = locales.filter((locale) => locale.enabled !== !1).map((locale) => locale.localeId), patchTasks = [];
1519
+ for (const doc of documents)
1520
+ for (const localeId of availableLocaleIds)
1521
+ patchTasks.push({ doc, localeId });
1522
+ setImportProgress({
1523
+ current: 0,
1524
+ total: patchTasks.length,
1525
+ isImporting: !0
1526
+ });
1527
+ const result = await processBatch(
1528
+ patchTasks,
1529
+ async ({ doc, localeId }) => {
1530
+ const sourceLocale = pluginConfig.getSourceLocale();
1531
+ if (localeId === sourceLocale)
1532
+ return { patched: !1, doc, localeId, skipped: !0 };
1533
+ const translatedDoc = await findTranslatedDocumentForLocale(
1534
+ doc._id,
1535
+ localeId,
1536
+ client
1537
+ );
1538
+ if (!translatedDoc)
1539
+ return { patched: !1, doc, localeId, noTranslation: !0 };
1540
+ const resolvedDoc = await resolveRefs(
1541
+ translatedDoc,
1542
+ localeId,
1543
+ client
1544
+ );
1545
+ if (resolvedDoc !== translatedDoc) {
1546
+ const mutation = {
1547
+ patch: {
1548
+ id: translatedDoc._id,
1549
+ set: resolvedDoc
1550
+ }
1551
+ };
1552
+ return await client.mutate([mutation]), { patched: !0, doc: translatedDoc, localeId };
1553
+ }
1554
+ return { patched: !1, doc: translatedDoc, localeId };
1555
+ },
1556
+ {
1557
+ onProgress: (current, total) => {
1558
+ setImportProgress({
1559
+ current,
1560
+ total,
1561
+ isImporting: !0
1562
+ });
1563
+ },
1564
+ onItemFailure: ({ doc, localeId }, error) => {
1565
+ console.error(
1566
+ `Failed to patch references for ${doc._id} (${localeId}):`,
1567
+ error
1568
+ );
1569
+ }
1570
+ }
1571
+ ), patchedCount = result.successfulItems.filter(
1572
+ (item) => item.patched
1573
+ ).length;
1574
+ return toast.push({
1575
+ title: `Patched references in ${patchedCount} documents${result.failureCount > 0 ? `, ${result.failureCount} failed` : ""}`,
1576
+ status: patchedCount > 0 || result.failureCount === 0 ? "success" : "error",
1577
+ closable: !0
1578
+ }), patchedCount;
1579
+ } catch (error) {
1580
+ return console.error("Error patching document references:", error), toast.push({
1581
+ title: "Error patching document references",
1582
+ status: "error",
1583
+ closable: !0
1584
+ }), 0;
1585
+ } finally {
1586
+ setIsBusy(!1), setImportProgress({ current: 0, total: 0, isImporting: !1 });
1588
1587
  }
1589
1588
  }, [secrets, documents, locales, client]), handlePublishAllTranslations = useCallback(async () => {
1590
- if (!(!secrets || documents.length === 0)) {
1591
- setIsBusy(!0);
1592
- try {
1593
- const sourceLocale = pluginConfig.getSourceLocale(), publishedDocumentIds = documents.filter((doc) => !doc._id.startsWith("drafts.")).map((doc) => doc._id);
1594
- if (publishedDocumentIds.length === 0) {
1595
- toast.push({
1596
- title: "No published source documents found to publish translations for",
1597
- status: "warning",
1598
- closable: !0
1599
- });
1600
- return;
1601
- }
1602
- const translationMetadata = await client.fetch(`*[
1589
+ if (!secrets || documents.length === 0) return 0;
1590
+ setIsBusy(!0);
1591
+ try {
1592
+ const sourceLocale = pluginConfig.getSourceLocale(), publishedDocumentIds = documents.filter((doc) => !doc._id.startsWith("drafts.")).map((doc) => doc._id);
1593
+ if (publishedDocumentIds.length === 0)
1594
+ return toast.push({
1595
+ title: "No published source documents found to publish translations for",
1596
+ status: "warning",
1597
+ closable: !0
1598
+ }), 0;
1599
+ const translationMetadata = await client.fetch(`*[
1603
1600
  _type == 'translation.metadata' &&
1604
1601
  translations[_key == $sourceLocale][0].value._ref in $publishedDocumentIds
1605
1602
  ] {
@@ -1609,39 +1606,36 @@ const getLocales = async (secrets) => pluginConfig.getLocales().map((locale) =>
1609
1606
  'docId': value._ref
1610
1607
  }
1611
1608
  }`, {
1612
- sourceLocale,
1613
- publishedDocumentIds
1614
- }), translationDocIds = [];
1615
- if (translationMetadata.forEach((metadata) => {
1616
- metadata.translationDocs?.forEach((translation) => {
1617
- translation.docId && translationDocIds.push(translation.docId);
1618
- });
1619
- }), translationDocIds.length === 0) {
1620
- toast.push({
1621
- title: "No translation documents found to publish",
1622
- status: "warning",
1623
- closable: !0
1624
- });
1625
- return;
1626
- }
1627
- const translatedDocumentIds = await publishTranslations(
1628
- translationDocIds,
1629
- client
1630
- );
1631
- toast.push({
1632
- title: `Published ${translatedDocumentIds.length} translation documents`,
1633
- status: "success",
1634
- closable: !0
1609
+ sourceLocale,
1610
+ publishedDocumentIds
1611
+ }), translationDocIds = [];
1612
+ if (translationMetadata.forEach((metadata) => {
1613
+ metadata.translationDocs?.forEach((translation) => {
1614
+ translation.docId && translationDocIds.push(translation.docId);
1635
1615
  });
1636
- } catch (error) {
1637
- console.error("Error publishing translations:", error), toast.push({
1638
- title: "Error publishing translations",
1639
- status: "error",
1616
+ }), translationDocIds.length === 0)
1617
+ return toast.push({
1618
+ title: "No translation documents found to publish",
1619
+ status: "warning",
1640
1620
  closable: !0
1641
- });
1642
- } finally {
1643
- setIsBusy(!1);
1644
- }
1621
+ }), 0;
1622
+ const translatedDocumentIds = await publishTranslations(
1623
+ translationDocIds,
1624
+ client
1625
+ );
1626
+ return toast.push({
1627
+ title: `Published ${translatedDocumentIds.length} translation documents`,
1628
+ status: "success",
1629
+ closable: !0
1630
+ }), translatedDocumentIds.length;
1631
+ } catch (error) {
1632
+ return console.error("Error publishing translations:", error), toast.push({
1633
+ title: "Error publishing translations",
1634
+ status: "error",
1635
+ closable: !0
1636
+ }), 0;
1637
+ } finally {
1638
+ setIsBusy(!1);
1645
1639
  }
1646
1640
  }, [secrets, documents, client]);
1647
1641
  useEffect(() => {
@@ -2949,8 +2943,9 @@ const WrapText = dt(Box)`
2949
2943
  isRefreshing,
2950
2944
  importedTranslations,
2951
2945
  setLocales,
2952
- handlePatchDocumentReferences
2953
- } = useTranslations(), [autoImport, setAutoImport] = useState(!1), [isImporting, setIsImporting] = useState(!1), [autoRefresh, setAutoRefresh] = useState(!0), document2 = documents[0], currentDocumentLanguage = useMemo(() => {
2946
+ handlePatchDocumentReferences,
2947
+ handlePublishAllTranslations
2948
+ } = useTranslations(), [autoImport, setAutoImport] = useState(!1), [isImporting, setIsImporting] = useState(!1), [autoRefresh, setAutoRefresh] = useState(!0), [autoPatchReferences, setAutoPatchReferences] = useState(!0), [autoPublish, setAutoPublish] = useState(!0), [isPublishing, setIsPublishing] = useState(!1), toast = useToast(), document2 = documents[0], currentDocumentLanguage = useMemo(() => {
2954
2949
  if (!document2) return null;
2955
2950
  const languageField = pluginConfig.getLanguageField();
2956
2951
  return document2[languageField] || pluginConfig.getSourceLocale();
@@ -2959,57 +2954,48 @@ const WrapText = dt(Box)`
2959
2954
  return locales.filter(
2960
2955
  (locale) => locale.enabled !== !1 && locale.localeId !== sourceLocale
2961
2956
  );
2962
- }, [locales]), documentId = useMemo(() => document2 ? document2._id?.replace("drafts.", "") || document2._id : null, [document2]), checkAndImportCompletedTranslations = useCallback(async () => {
2963
- if (!autoImport || isImporting || !documentId) return;
2964
- const completedTranslations = availableLocales.filter((locale) => {
2965
- const key = `${documentId}:${locale.localeId}`, status = translationStatuses.get(key);
2966
- return (status?.progress || 0) >= 100 && status?.isReady && !importedTranslations.has(key);
2967
- });
2968
- if (completedTranslations.length !== 0) {
2969
- setIsImporting(!0);
2970
- try {
2971
- for (const locale of completedTranslations)
2972
- await handleImportDocument(documentId, locale.localeId);
2973
- } finally {
2974
- setIsImporting(!1);
2975
- }
2976
- }
2977
- }, [
2978
- autoImport,
2979
- isImporting,
2980
- documentId,
2981
- availableLocales,
2982
- translationStatuses,
2983
- importedTranslations,
2984
- handleImportDocument
2985
- ]), handleImportAll = useCallback(async () => {
2986
- if (!(isImporting || !documentId)) {
2987
- setIsImporting(!0);
2988
- try {
2989
- const readyTranslations = availableLocales.filter((locale) => {
2990
- const key = `${documentId}:${locale.localeId}`;
2991
- return translationStatuses.get(key)?.isReady && !importedTranslations.has(key);
2992
- });
2993
- for (const locale of readyTranslations)
2994
- await handleImportDocument(documentId, locale.localeId);
2995
- } finally {
2996
- setIsImporting(!1);
2957
+ }, [locales]), documentId = useMemo(() => document2 ? document2._id?.replace("drafts.", "") || document2._id : null, [document2]), handleImportTranslations = useCallback(
2958
+ async (options = {}) => {
2959
+ const { autoOnly = !1 } = options;
2960
+ if (isImporting || !documentId || autoOnly && !autoImport) return;
2961
+ const readyTranslations = availableLocales.filter((locale) => {
2962
+ const key = `${documentId}:${locale.localeId}`;
2963
+ return translationStatuses.get(key)?.isReady && !importedTranslations.has(key);
2964
+ });
2965
+ if (readyTranslations.length !== 0) {
2966
+ setIsImporting(!0);
2967
+ try {
2968
+ await Promise.all(
2969
+ readyTranslations.map(
2970
+ (locale) => handleImportDocument(documentId, locale.localeId)
2971
+ )
2972
+ ), autoPatchReferences && await handlePatchDocumentReferences(), autoPublish && await handlePublishAllTranslations();
2973
+ } finally {
2974
+ setIsImporting(!1);
2975
+ }
2997
2976
  }
2998
- }
2999
- }, [
3000
- isImporting,
3001
- documentId,
3002
- availableLocales,
3003
- translationStatuses,
3004
- importedTranslations,
3005
- handleImportDocument
3006
- ]);
2977
+ },
2978
+ [
2979
+ autoImport,
2980
+ isImporting,
2981
+ documentId,
2982
+ availableLocales,
2983
+ translationStatuses,
2984
+ importedTranslations,
2985
+ handleImportDocument,
2986
+ autoPatchReferences,
2987
+ handlePatchDocumentReferences,
2988
+ autoPublish,
2989
+ handlePublishAllTranslations,
2990
+ toast
2991
+ ]
2992
+ );
3007
2993
  useEffect(() => {
3008
- checkAndImportCompletedTranslations();
3009
- }, [checkAndImportCompletedTranslations]), useEffect(() => {
2994
+ handleImportTranslations({ autoOnly: !0 });
2995
+ }, [handleImportTranslations]), useEffect(() => {
3010
2996
  if (!autoRefresh || !documentId || availableLocales.length === 0) return;
3011
2997
  const interval = setInterval(async () => {
3012
- await handleRefreshAll(), await checkAndImportCompletedTranslations();
2998
+ await handleRefreshAll(), await handleImportTranslations({ autoOnly: !0 });
3013
2999
  }, 1e4);
3014
3000
  return () => clearInterval(interval);
3015
3001
  }, [
@@ -3017,9 +3003,9 @@ const WrapText = dt(Box)`
3017
3003
  documentId,
3018
3004
  availableLocales.length,
3019
3005
  handleRefreshAll,
3020
- checkAndImportCompletedTranslations
3006
+ handleImportTranslations
3021
3007
  ]), useEffect(() => {
3022
- (async () => (await handleRefreshAll(), await checkAndImportCompletedTranslations()))();
3008
+ (async () => (await handleRefreshAll(), await handleImportTranslations({ autoOnly: !0 })))();
3023
3009
  }, []);
3024
3010
  const toggleLocale = useCallback(
3025
3011
  (localeId, shouldEnable) => {
@@ -3127,59 +3113,116 @@ const WrapText = dt(Box)`
3127
3113
  Button,
3128
3114
  {
3129
3115
  mode: "ghost",
3130
- onClick: handleImportAll,
3116
+ tone: "primary",
3117
+ onClick: () => handleImportTranslations(),
3131
3118
  text: isImporting ? "Importing..." : "Import All",
3132
3119
  icon: DownloadIcon,
3133
3120
  disabled: isImporting || availableLocales.every((locale) => {
3134
3121
  const key = `${documentId}:${locale.localeId}`;
3135
3122
  return !translationStatuses.get(key)?.isReady || importedTranslations.has(key);
3136
- })
3123
+ }),
3124
+ style: { minWidth: "180px" }
3137
3125
  }
3138
3126
  ),
3139
- /* @__PURE__ */ jsxs(Text, { size: 1, muted: !0, children: [
3140
- "Imported",
3141
- " ",
3142
- availableLocales.filter((locale) => {
3143
- const key = `${documentId}:${locale.localeId}`;
3144
- return importedTranslations.has(key);
3145
- }).length,
3146
- "/",
3147
- availableLocales.filter((locale) => {
3148
- const key = `${documentId}:${locale.localeId}`;
3149
- return translationStatuses.get(key)?.isReady;
3150
- }).length
3127
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, align: "center", children: [
3128
+ /* @__PURE__ */ jsx(
3129
+ Switch,
3130
+ {
3131
+ checked: autoImport,
3132
+ onChange: () => setAutoImport(!autoImport),
3133
+ disabled: isImporting
3134
+ }
3135
+ ),
3136
+ /* @__PURE__ */ jsx(Text, { size: 1, children: "Auto-import when complete" })
3151
3137
  ] })
3152
3138
  ] }),
3153
- /* @__PURE__ */ jsxs(Flex, { gap: 2, align: "center", style: { whiteSpace: "nowrap" }, children: [
3154
- /* @__PURE__ */ jsx(Text, { size: 1, children: "Auto-import when complete" }),
3139
+ /* @__PURE__ */ jsxs(Text, { size: 1, muted: !0, children: [
3140
+ "Imported",
3141
+ " ",
3142
+ availableLocales.filter((locale) => {
3143
+ const key = `${documentId}:${locale.localeId}`;
3144
+ return importedTranslations.has(key);
3145
+ }).length,
3146
+ "/",
3147
+ availableLocales.filter((locale) => {
3148
+ const key = `${documentId}:${locale.localeId}`;
3149
+ return translationStatuses.get(key)?.isReady;
3150
+ }).length
3151
+ ] })
3152
+ ] }),
3153
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, align: "center", justify: "flex-start", children: [
3154
+ /* @__PURE__ */ jsx(
3155
+ Tooltip,
3156
+ {
3157
+ placement: "top",
3158
+ content: `Replaces references to ${pluginConfig.getSourceLocale()} documents in this document with the corresponding translated document reference`,
3159
+ children: /* @__PURE__ */ jsx(
3160
+ Button,
3161
+ {
3162
+ mode: "ghost",
3163
+ tone: "caution",
3164
+ onClick: async () => {
3165
+ await handlePatchDocumentReferences();
3166
+ },
3167
+ text: isBusy ? "Patching..." : "Patch References",
3168
+ icon: isBusy ? null : LinkIcon,
3169
+ disabled: isBusy || isImporting,
3170
+ style: { minWidth: "180px" }
3171
+ }
3172
+ )
3173
+ }
3174
+ ),
3175
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, align: "center", children: [
3155
3176
  /* @__PURE__ */ jsx(
3156
3177
  Switch,
3157
3178
  {
3158
- checked: autoImport,
3159
- onChange: () => setAutoImport(!autoImport),
3160
- disabled: isImporting
3179
+ checked: autoPatchReferences,
3180
+ onChange: () => setAutoPatchReferences(!autoPatchReferences),
3181
+ disabled: isImporting || isBusy
3161
3182
  }
3162
- )
3183
+ ),
3184
+ /* @__PURE__ */ jsx(Text, { size: 1, children: "Auto-patch after import" })
3163
3185
  ] })
3164
3186
  ] }),
3165
- /* @__PURE__ */ jsx(Flex, { justify: "flex-start", children: /* @__PURE__ */ jsx(
3166
- Tooltip,
3167
- {
3168
- placement: "top",
3169
- content: `Replaces references to ${pluginConfig.getSourceLocale()} documents in this document with the corresponding translated document reference`,
3170
- children: /* @__PURE__ */ jsx(
3171
- Button,
3187
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, align: "center", justify: "flex-start", children: [
3188
+ /* @__PURE__ */ jsx(
3189
+ Tooltip,
3190
+ {
3191
+ placement: "top",
3192
+ content: "Publishes all translations (if the source document is published)",
3193
+ children: /* @__PURE__ */ jsx(
3194
+ Button,
3195
+ {
3196
+ mode: "ghost",
3197
+ tone: "positive",
3198
+ onClick: async () => {
3199
+ setIsPublishing(!0);
3200
+ try {
3201
+ await handlePublishAllTranslations();
3202
+ } finally {
3203
+ setIsPublishing(!1);
3204
+ }
3205
+ },
3206
+ text: isPublishing ? "Publishing..." : "Publish Translations",
3207
+ icon: isPublishing ? null : PublishIcon,
3208
+ disabled: isBusy || isPublishing || isImporting,
3209
+ style: { minWidth: "180px" }
3210
+ }
3211
+ )
3212
+ }
3213
+ ),
3214
+ /* @__PURE__ */ jsxs(Flex, { gap: 2, align: "center", children: [
3215
+ /* @__PURE__ */ jsx(
3216
+ Switch,
3172
3217
  {
3173
- mode: "ghost",
3174
- tone: "caution",
3175
- onClick: handlePatchDocumentReferences,
3176
- text: isBusy ? "Patching..." : "Patch Document References",
3177
- icon: isBusy ? null : LinkIcon,
3178
- disabled: isBusy
3218
+ checked: autoPublish,
3219
+ onChange: () => setAutoPublish(!autoPublish),
3220
+ disabled: isPublishing || isImporting || isBusy
3179
3221
  }
3180
- )
3181
- }
3182
- ) })
3222
+ ),
3223
+ /* @__PURE__ */ jsx(Text, { size: 1, children: "Auto-publish after import" })
3224
+ ] })
3225
+ ] })
3183
3226
  ] })
3184
3227
  ] })
3185
3228
  ] }) : /* @__PURE__ */ jsx(Card, { padding: 4, tone: "neutral", border: !0, children: /* @__PURE__ */ jsxs(Text, { size: 1, muted: !0, children: [
@@ -3191,6 +3234,21 @@ const WrapText = dt(Box)`
3191
3234
  }, TranslationTab = (props) => {
3192
3235
  const { displayed } = props.document;
3193
3236
  return /* @__PURE__ */ jsx(BaseTranslationWrapper, { showContainer: !1, children: /* @__PURE__ */ jsx(TranslationsProvider, { singleDocument: displayed, children: /* @__PURE__ */ jsx(TranslationView, {}) }) });
3237
+ }, translateAction = (props) => {
3238
+ const router = useRouter();
3239
+ return {
3240
+ label: "Translate",
3241
+ icon: TranslateIcon,
3242
+ tone: "primary",
3243
+ onHandle: () => {
3244
+ const { id, type } = props;
3245
+ router.navigateIntent("edit", {
3246
+ id,
3247
+ type,
3248
+ view: "general-translation"
3249
+ });
3250
+ }
3251
+ };
3194
3252
  }, TranslationsTable = () => {
3195
3253
  const {
3196
3254
  documents,
@@ -3620,7 +3678,17 @@ const WrapText = dt(Box)`
3620
3678
  component: TranslationsTool,
3621
3679
  router: route.create("/*")
3622
3680
  }
3623
- ]
3681
+ ],
3682
+ document: {
3683
+ views: [
3684
+ {
3685
+ id: "general-translation",
3686
+ title: "Translations",
3687
+ component: TranslationTab
3688
+ }
3689
+ ],
3690
+ actions: (prev2) => [...prev2, translateAction]
3691
+ }
3624
3692
  })
3625
3693
  );
3626
3694
  export {
@@ -3633,6 +3701,7 @@ export {
3633
3701
  defaultStopTypes,
3634
3702
  detachGTData,
3635
3703
  findLatestDraft,
3636
- gtPlugin
3704
+ gtPlugin,
3705
+ translateAction
3637
3706
  };
3638
3707
  //# sourceMappingURL=index.mjs.map