gt-sanity 1.1.30 → 2.0.0

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.d.mts CHANGED
@@ -134,9 +134,11 @@ export declare type GTPluginConfig = Omit<
134
134
  'locales'
135
135
  > & {
136
136
  locales: string[];
137
+ defaultLocale?: string;
137
138
  singletons?: string[];
138
139
  singletonMapping?: (sourceDocumentId: string, locale: string) => string;
139
140
  ignoreFields?: IgnoreFields[];
141
+ skipFields?: SkipFields[];
140
142
  languageField?: string;
141
143
  translateDocuments?: TranslateDocumentFilter[];
142
144
  secretsNamespace?: string;
@@ -198,6 +200,14 @@ export declare type SerializedDocument = {
198
200
  content: string;
199
201
  };
200
202
 
203
+ declare type SkipFields = {
204
+ documentId?: string;
205
+ fields?: {
206
+ property: string;
207
+ type?: string;
208
+ }[];
209
+ };
210
+
201
211
  export declare const translateAction: DocumentActionComponent;
202
212
 
203
213
  declare type TranslateDocumentFilter = {
package/dist/index.d.ts CHANGED
@@ -134,9 +134,11 @@ export declare type GTPluginConfig = Omit<
134
134
  'locales'
135
135
  > & {
136
136
  locales: string[];
137
+ defaultLocale?: string;
137
138
  singletons?: string[];
138
139
  singletonMapping?: (sourceDocumentId: string, locale: string) => string;
139
140
  ignoreFields?: IgnoreFields[];
141
+ skipFields?: SkipFields[];
140
142
  languageField?: string;
141
143
  translateDocuments?: TranslateDocumentFilter[];
142
144
  secretsNamespace?: string;
@@ -198,6 +200,14 @@ export declare type SerializedDocument = {
198
200
  content: string;
199
201
  };
200
202
 
203
+ declare type SkipFields = {
204
+ documentId?: string;
205
+ fields?: {
206
+ property: string;
207
+ type?: string;
208
+ }[];
209
+ };
210
+
201
211
  export declare const translateAction: DocumentActionComponent;
202
212
 
203
213
  declare type TranslateDocumentFilter = {
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var jsxRuntime = require("react/jsx-runtime"), ui = require("@sanity/ui"), theme$1 = require("@sanity/ui/theme"), o = require("react"), sanity = require("sanity"), generaltranslation = require("generaltranslation"), internal = require("generaltranslation/internal"), blockTools = require("@portabletext/block-tools"), schema = require("@sanity/schema"), toHtml = require("@portabletext/to-html"), merge = require("lodash.merge"), mutator = require("@sanity/mutator"), jsonpathPlus = require("jsonpath-plus"), JSONPointer = require("jsonpointer"), icons = require("@sanity/icons"), router = require("sanity/router");
3
+ var jsxRuntime = require("react/jsx-runtime"), ui = require("@sanity/ui"), theme$1 = require("@sanity/ui/theme"), o = require("react"), sanity = require("sanity"), generaltranslation = require("generaltranslation"), internal = require("generaltranslation/internal"), blockTools = require("@portabletext/block-tools"), schema = require("@sanity/schema"), toHtml = require("@portabletext/to-html"), merge = require("lodash.merge"), jsonpathPlus = require("jsonpath-plus"), JSONPointer = require("jsonpointer"), mutator = require("@sanity/mutator"), icons = require("@sanity/icons"), router = require("sanity/router");
4
4
  function _interopDefaultCompat(e) {
5
5
  return e && typeof e == "object" && "default" in e ? e : { default: e };
6
6
  }
@@ -35,14 +35,15 @@ class GTConfig {
35
35
  singletons;
36
36
  singletonMapping;
37
37
  ignoreFields;
38
+ skipFields;
38
39
  translateDocuments;
39
40
  additionalStopTypes;
40
41
  additionalSerializers;
41
42
  additionalDeserializers;
42
43
  additionalBlockDeserializers;
43
44
  static instance;
44
- constructor(secretsNamespace, languageField, sourceLocale, locales, singletons, singletonMapping, ignoreFields, translateDocuments, additionalStopTypes = [], additionalSerializers = {}, additionalDeserializers = {}, additionalBlockDeserializers = []) {
45
- this.secretsNamespace = secretsNamespace, this.languageField = languageField, this.sourceLocale = sourceLocale, this.locales = locales, this.singletons = singletons, this.singletonMapping = singletonMapping, this.ignoreFields = ignoreFields, this.translateDocuments = translateDocuments, this.additionalStopTypes = additionalStopTypes, this.additionalSerializers = additionalSerializers, this.additionalDeserializers = additionalDeserializers, this.additionalBlockDeserializers = additionalBlockDeserializers;
45
+ constructor(secretsNamespace, languageField, sourceLocale, locales, singletons, singletonMapping, ignoreFields, skipFields, translateDocuments, additionalStopTypes = [], additionalSerializers = {}, additionalDeserializers = {}, additionalBlockDeserializers = []) {
46
+ this.secretsNamespace = secretsNamespace, this.languageField = languageField, this.sourceLocale = sourceLocale, this.locales = locales, this.singletons = singletons, this.singletonMapping = singletonMapping, this.ignoreFields = ignoreFields, this.skipFields = skipFields, this.translateDocuments = translateDocuments, this.additionalStopTypes = additionalStopTypes, this.additionalSerializers = additionalSerializers, this.additionalDeserializers = additionalDeserializers, this.additionalBlockDeserializers = additionalBlockDeserializers;
46
47
  }
47
48
  static getInstance() {
48
49
  return this.instance || (this.instance = new GTConfig(
@@ -55,13 +56,14 @@ class GTConfig {
55
56
  [],
56
57
  [],
57
58
  [],
59
+ [],
58
60
  {},
59
61
  {},
60
62
  []
61
63
  )), this.instance;
62
64
  }
63
- init(secretsNamespace, languageField, sourceLocale, locales, singletons, singletonMapping, ignoreFields, translateDocuments, additionalStopTypes = [], additionalSerializers = {}, additionalDeserializers = {}, additionalBlockDeserializers = []) {
64
- this.secretsNamespace = secretsNamespace, this.languageField = languageField, this.sourceLocale = sourceLocale, this.locales = locales, this.singletons = singletons, this.singletonMapping = singletonMapping, this.ignoreFields = ignoreFields, this.translateDocuments = translateDocuments, this.additionalStopTypes = additionalStopTypes, this.additionalSerializers = additionalSerializers, this.additionalDeserializers = additionalDeserializers, this.additionalBlockDeserializers = additionalBlockDeserializers;
65
+ init(secretsNamespace, languageField, sourceLocale, locales, singletons, singletonMapping, ignoreFields, skipFields, translateDocuments, additionalStopTypes = [], additionalSerializers = {}, additionalDeserializers = {}, additionalBlockDeserializers = []) {
66
+ this.secretsNamespace = secretsNamespace, this.languageField = languageField, this.sourceLocale = sourceLocale, this.locales = locales, this.singletons = singletons, this.singletonMapping = singletonMapping, this.ignoreFields = ignoreFields, this.skipFields = skipFields, this.translateDocuments = translateDocuments, this.additionalStopTypes = additionalStopTypes, this.additionalSerializers = additionalSerializers, this.additionalDeserializers = additionalDeserializers, this.additionalBlockDeserializers = additionalBlockDeserializers;
65
67
  }
66
68
  getSecretsNamespace() {
67
69
  return this.secretsNamespace;
@@ -84,6 +86,9 @@ class GTConfig {
84
86
  getIgnoreFields() {
85
87
  return this.ignoreFields;
86
88
  }
89
+ getSkipFields() {
90
+ return this.skipFields;
91
+ }
87
92
  getTranslateDocuments() {
88
93
  return this.translateDocuments;
89
94
  }
@@ -464,7 +469,7 @@ const defaultStopTypes = [
464
469
  serializeDocument: (doc, translationLevel = "document", baseLang = "en", stopTypes = defaultStopTypes, serializers = customSerializers) => {
465
470
  const schema2 = getSchema(doc._type);
466
471
  let filteredObj = {};
467
- translationLevel === "field" ? filteredObj = languageObjectFieldFilter(doc, baseLang) : filteredObj = fieldFilter(doc, schema2.fields, stopTypes);
472
+ translationLevel === "field" ? filteredObj = languageObjectFieldFilter(doc, baseLang) : filteredObj = fieldFilter(doc, schema2?.fields ?? [], stopTypes);
468
473
  const serializedFields = {};
469
474
  for (const key in filteredObj) {
470
475
  if (filteredObj.hasOwnProperty(key) === !1) continue;
@@ -587,6 +592,51 @@ const deserializeArray = (arrayHTML, deserializers = customDeserializers, blockD
587
592
  deserializeDocument: deserializeDocument$1,
588
593
  deserializeHTML
589
594
  };
595
+ function forEachMatchingField(documentId, document2, fields, callback) {
596
+ const applicable = fields.filter(
597
+ (field) => field.documentId === documentId || field.documentId === void 0 || field.documentId === null
598
+ );
599
+ for (const entry of applicable)
600
+ if (entry.fields)
601
+ for (const field of entry.fields) {
602
+ const { property, type } = field;
603
+ try {
604
+ const results = jsonpathPlus.JSONPath({
605
+ json: document2,
606
+ path: property,
607
+ resultType: "all",
608
+ flatten: !0,
609
+ wrap: !0
610
+ });
611
+ results && results.length > 0 && results.forEach(
612
+ (result) => {
613
+ type !== void 0 ? typeof result.value == "object" && result.value !== null && result.value._type === type && callback(result) : callback(result);
614
+ }
615
+ );
616
+ } catch (error) {
617
+ console.warn(`Invalid JSONPath: ${property}`, error);
618
+ }
619
+ }
620
+ }
621
+ function deleteMatchingFields(documentId, document2, fields) {
622
+ const arrayRemovals = [];
623
+ forEachMatchingField(documentId, document2, fields, (result) => {
624
+ Array.isArray(result.parent) ? arrayRemovals.push({
625
+ parent: result.parent,
626
+ index: Number(result.parentProperty)
627
+ }) : delete result.parent[result.parentProperty];
628
+ }), arrayRemovals.sort((a, b) => b.index - a.index);
629
+ for (const { parent, index } of arrayRemovals)
630
+ parent.splice(index, 1);
631
+ }
632
+ function applyDocuments(documentId, sourceDocument, targetDocument, ignore, skip = []) {
633
+ const mergedDocument = JSON.parse(JSON.stringify(sourceDocument)), clonedTarget = JSON.parse(JSON.stringify(targetDocument));
634
+ for (const [key, value] of Object.entries(clonedTarget))
635
+ mergedDocument[key] = value;
636
+ return forEachMatchingField(documentId, sourceDocument, ignore, (result) => {
637
+ JSONPointer__default.default.set(mergedDocument, result.pointer, result.value);
638
+ }), deleteMatchingFields(documentId, mergedDocument, skip), mergedDocument;
639
+ }
590
640
  function deserializeDocument(document2) {
591
641
  const deserializers = merge__default.default(
592
642
  { types: {} },
@@ -608,15 +658,27 @@ function serializeDocument(document2, schema2, baseLanguage) {
608
658
  ], serializers = merge__default.default(
609
659
  customSerializers,
610
660
  pluginConfig.getAdditionalSerializers()
661
+ ), docToSerialize = stripIgnoredFields(
662
+ document2,
663
+ pluginConfig.getIgnoreFields()
611
664
  );
612
665
  return BaseDocumentSerializer(schema2).serializeDocument(
613
- document2,
666
+ docToSerialize,
614
667
  "document",
615
668
  baseLanguage,
616
669
  stopTypes,
617
670
  serializers
618
671
  );
619
672
  }
673
+ function stripIgnoredFields(document2, ignoreFields) {
674
+ if (ignoreFields.length === 0) return document2;
675
+ const strippedDoc = JSON.parse(JSON.stringify(document2));
676
+ return deleteMatchingFields(
677
+ document2._id.replace("drafts.", ""),
678
+ strippedDoc,
679
+ ignoreFields
680
+ ), strippedDoc;
681
+ }
620
682
  async function uploadFiles(documents, secrets) {
621
683
  return overrideConfig(secrets), await gt.uploadSourceFiles(
622
684
  documents.map(({ info, serializedDocument }) => ({
@@ -714,43 +776,19 @@ const findLatestDraft = (documentId, client) => {
714
776
  const baseUrl = `/data/history/${client.config().dataset}/documents/${documentId}?revision=${rev}`, url = client.getUrl(baseUrl);
715
777
  return await fetch(url, { credentials: "include" }).then((req) => req.json()).then((req) => req.documents && req.documents.length ? req.documents[0] : null);
716
778
  };
717
- function applyDocuments(documentId, sourceDocument, targetDocument, ignore) {
718
- const ignoreFields = ignore.filter(
719
- (field) => field.documentId === documentId || field.documentId === void 0 || field.documentId === null
720
- ), mergedDocument = { ...sourceDocument };
721
- for (const [key, value] of Object.entries(targetDocument))
722
- mergedDocument[key] = value;
723
- for (const ignoreField of ignoreFields)
724
- if (ignoreField.fields)
725
- for (const field of ignoreField.fields) {
726
- const { property, type } = field;
727
- try {
728
- const sourceResults = jsonpathPlus.JSONPath({
729
- json: sourceDocument,
730
- path: property,
731
- resultType: "all",
732
- flatten: !0,
733
- wrap: !0
734
- });
735
- sourceResults && sourceResults.length > 0 && sourceResults.forEach((result) => {
736
- const sourceValue = result.value;
737
- type !== void 0 ? typeof sourceValue == "object" && sourceValue !== null && sourceValue._type === type && JSONPointer__default.default.set(mergedDocument, result.pointer, sourceValue) : JSONPointer__default.default.set(mergedDocument, result.pointer, sourceValue);
738
- });
739
- } catch (error) {
740
- console.warn(`Invalid JSONPath: ${property}`, error);
741
- }
742
- }
743
- return mergedDocument;
779
+ function randomKey() {
780
+ return Math.random().toString(36).slice(2, 10);
744
781
  }
745
782
  async function createI18nDocAndPatchMetadata(sourceDocument, translatedDoc, localeId, client, translationMetadata, sourceDocumentId, languageField = "language") {
746
783
  translatedDoc[languageField] = localeId;
747
784
  const existingLocaleKey = translationMetadata.translations.find(
748
- (translation) => translation._key === localeId
749
- ), operation = existingLocaleKey ? "replace" : "after", location = existingLocaleKey ? `translations[_key == "${localeId}"]` : "translations[-1]", { _updatedAt, _createdAt, ...rest } = translatedDoc, appliedDocument = applyDocuments(
785
+ (translation) => translation.language === localeId
786
+ ), operation = existingLocaleKey ? "replace" : "after", location = existingLocaleKey ? `translations[language == "${localeId}"]` : "translations[-1]", { _updatedAt, _createdAt, ...rest } = translatedDoc, appliedDocument = applyDocuments(
750
787
  sourceDocumentId,
751
788
  sourceDocument,
752
789
  rest,
753
- pluginConfig.getIgnoreFields()
790
+ pluginConfig.getIgnoreFields(),
791
+ pluginConfig.getSkipFields()
754
792
  ), isSingleton = pluginConfig.getSingletons().includes(sourceDocumentId);
755
793
  let createDocumentPromise;
756
794
  if (isSingleton) {
@@ -771,7 +809,8 @@ async function createI18nDocAndPatchMetadata(sourceDocument, translatedDoc, loca
771
809
  translationMetadata._id,
772
810
  (p) => p.insert(operation, location, [
773
811
  {
774
- _key: localeId,
812
+ _key: randomKey(),
813
+ language: localeId,
775
814
  _type: "internationalizedArrayReferenceValue",
776
815
  value: {
777
816
  _type: "reference",
@@ -789,14 +828,15 @@ const getOrCreateTranslationMetadata = async (documentId, baseDocument, client,
789
828
  const existingMetadata = await client.fetch(
790
829
  `*[
791
830
  _type == 'translation.metadata' &&
792
- translations[_key == $baseLanguage][0].value._ref == $id
831
+ translations[language == $baseLanguage][0].value._ref == $id
793
832
  ][0]`,
794
833
  { baseLanguage, id: documentId.replace("drafts.", "") }
795
834
  );
796
835
  if (existingMetadata)
797
836
  return existingMetadata;
798
837
  const baseLangEntry = {
799
- _key: baseLanguage,
838
+ _key: randomKey(),
839
+ language: baseLanguage,
800
840
  _type: "internationalizedArrayReferenceValue",
801
841
  value: {
802
842
  _type: "reference",
@@ -822,7 +862,7 @@ const getOrCreateTranslationMetadata = async (documentId, baseDocument, client,
822
862
  const metadata = await client.fetch(
823
863
  `*[
824
864
  _type == 'translation.metadata' &&
825
- translations[_key == $baseLanguage][0].value._ref == $id
865
+ translations[language == $baseLanguage][0].value._ref == $id
826
866
  ][0]`,
827
867
  { baseLanguage, id: documentId.replace("drafts.", "") }
828
868
  );
@@ -845,7 +885,8 @@ async function patchI18nDoc(sourceDocumentId, i18nDocId, sourceDocument, mergedD
845
885
  sourceDocumentId,
846
886
  cleanedSourceDocument,
847
887
  cleanedMerge,
848
- pluginConfig.getIgnoreFields()
888
+ pluginConfig.getIgnoreFields(),
889
+ pluginConfig.getSkipFields()
849
890
  );
850
891
  await client.patch(i18nDocId, { set: appliedDocument }).commit();
851
892
  }
@@ -862,7 +903,7 @@ const documentLevelPatch = async (docInfo, translatedFields, localeId, client, l
862
903
  baseDoc,
863
904
  client,
864
905
  baseLanguage
865
- ), i18nDocId = translationMetadata.translations.find((translation) => translation._key === localeId)?.value?._ref;
906
+ ), i18nDocId = translationMetadata.translations.find((translation) => translation.language === localeId)?.value?._ref;
866
907
  i18nDocId && (i18nDoc = await findLatestDraft(i18nDocId, client)), mergeWithTargetLocale && i18nDoc ? baseDoc = i18nDoc : docInfo.documentId && docInfo.versionId && (baseDoc = await findDocumentAtRevision(
867
908
  docInfo.documentId,
868
909
  docInfo.versionId,
@@ -926,9 +967,9 @@ async function resolveTranslatedReferences(references, locale, client) {
926
967
  const refIds = references.map((r) => r.ref._ref), translatedRefs = /* @__PURE__ */ new Map();
927
968
  if (refIds.length === 0)
928
969
  return translatedRefs;
929
- const sourceLocale = pluginConfig.getSourceLocale(), translationPairs = await client.fetch(`*[_type == "translation.metadata" && count(translations[_key == $sourceLocale && value._ref in $refIds]) > 0] {
930
- "originalRef": translations[_key == $sourceLocale][0].value._ref,
931
- "translatedRef": translations[_key == $locale][0].value._ref
970
+ const sourceLocale = pluginConfig.getSourceLocale(), translationPairs = await client.fetch(`*[_type == "translation.metadata" && count(translations[language == $sourceLocale && value._ref in $refIds]) > 0] {
971
+ "originalRef": translations[language == $sourceLocale][0].value._ref,
972
+ "translatedRef": translations[language == $locale][0].value._ref
932
973
  }[defined(originalRef) && defined(translatedRef)]`, { refIds, sourceLocale, locale });
933
974
  for (const { originalRef, translatedRef } of translationPairs)
934
975
  translatedRefs.set(originalRef, translatedRef);
@@ -957,10 +998,10 @@ async function findTranslatedDocumentForLocale(sourceDocumentId, localeId, clien
957
998
  return await client.fetch(`*[
958
999
  _type == "translation.metadata" &&
959
1000
  (
960
- translations[_key == $sourceLocale][0].value._ref == $cleanDocId
1001
+ translations[language == $sourceLocale][0].value._ref == $cleanDocId
961
1002
  ) &&
962
- defined(translations[_key == $localeId])
963
- ][0].translations[_key == $localeId][0].value->`, {
1003
+ defined(translations[language == $localeId])
1004
+ ][0].translations[language == $localeId][0].value->`, {
964
1005
  sourceLocale: pluginConfig.getSourceLocale(),
965
1006
  cleanDocId,
966
1007
  localeId
@@ -1148,10 +1189,10 @@ const getLocales = async (secrets) => pluginConfig.getLocales().map((locale) =>
1148
1189
  (doc) => doc._id?.replace("drafts.", "") || doc._id
1149
1190
  ), existingMetadata = await client.fetch(`*[
1150
1191
  _type == 'translation.metadata' &&
1151
- translations[_key == $sourceLocale][0].value._ref in $documentIds
1192
+ translations[language == $sourceLocale][0].value._ref in $documentIds
1152
1193
  ] {
1153
- 'sourceDocId': translations[_key == $sourceLocale][0].value._ref,
1154
- 'existingTranslations': translations[_key in $localeIds]._key
1194
+ 'sourceDocId': translations[language == $sourceLocale][0].value._ref,
1195
+ 'existingTranslations': translations[language in $localeIds].language
1155
1196
  }`, {
1156
1197
  sourceLocale,
1157
1198
  documentIds,
@@ -1174,10 +1215,13 @@ const getLocales = async (secrets) => pluginConfig.getLocales().map((locale) =>
1174
1215
  setIsBusy(!0);
1175
1216
  try {
1176
1217
  const availableLocaleIds = locales.filter((locale) => locale.enabled !== !1).map((locale) => locale.localeId), transformedDocuments = documents.map((doc) => {
1177
- delete doc[pluginConfig.getLanguageField()];
1178
- const baseLanguage = pluginConfig.getSourceLocale();
1218
+ const { [pluginConfig.getLanguageField()]: _2, ...cleanDoc } = doc, baseLanguage = pluginConfig.getSourceLocale();
1179
1219
  try {
1180
- const serialized = serializeDocument(doc, schema2, baseLanguage);
1220
+ const serialized = serializeDocument(
1221
+ cleanDoc,
1222
+ schema2,
1223
+ baseLanguage
1224
+ );
1181
1225
  return {
1182
1226
  info: {
1183
1227
  documentId: doc._id?.replace("drafts.", "") || doc._id,
@@ -1272,11 +1316,11 @@ const getLocales = async (secrets) => pluginConfig.getLocales().map((locale) =>
1272
1316
  async (documentIds, localeIds, branchId2) => {
1273
1317
  const sourceLocale = pluginConfig.getSourceLocale(), existingMetadata = await client.fetch(`*[
1274
1318
  _type == 'translation.metadata' &&
1275
- translations[_key == $sourceLocale][0].value._ref in $documentIds
1319
+ translations[language == $sourceLocale][0].value._ref in $documentIds
1276
1320
  ] {
1277
1321
  _rev,
1278
- 'sourceDocId': translations[_key == $sourceLocale][0].value._ref,
1279
- 'existingTranslations': translations[_key in $localeIds]._key
1322
+ 'sourceDocId': translations[language == $sourceLocale][0].value._ref,
1323
+ 'existingTranslations': translations[language in $localeIds].language
1280
1324
  }`, {
1281
1325
  sourceLocale,
1282
1326
  documentIds,
@@ -1595,10 +1639,10 @@ const getLocales = async (secrets) => pluginConfig.getLocales().map((locale) =>
1595
1639
  }), 0;
1596
1640
  const translationMetadata = await client.fetch(`*[
1597
1641
  _type == 'translation.metadata' &&
1598
- translations[_key == $sourceLocale][0].value._ref in $publishedDocumentIds
1642
+ translations[language == $sourceLocale][0].value._ref in $publishedDocumentIds
1599
1643
  ] {
1600
- 'sourceDocId': translations[_key == $sourceLocale][0].value._ref,
1601
- 'translationDocs': translations[_key != $sourceLocale && defined(value._ref)]{
1644
+ 'sourceDocId': translations[language == $sourceLocale][0].value._ref,
1645
+ 'translationDocs': translations[language != $sourceLocale && defined(value._ref)]{
1602
1646
  _key,
1603
1647
  'docId': value._ref
1604
1648
  }
@@ -1651,7 +1695,9 @@ const getLocales = async (secrets) => pluginConfig.getLocales().map((locale) =>
1651
1695
  return () => clearInterval(interval);
1652
1696
  }, [autoRefresh, documents.length, secrets, handleRefreshAll]), o.useEffect(() => {
1653
1697
  setImportedTranslations(new Set(downloadStatus.downloaded));
1654
- }, [downloadStatus.downloaded]), secrets && handleGetBranchId(secrets);
1698
+ }, [downloadStatus.downloaded]), o.useEffect(() => {
1699
+ secrets && handleGetBranchId(secrets);
1700
+ }, [secrets, handleGetBranchId]);
1655
1701
  const contextValue = {
1656
1702
  // State
1657
1703
  isBusy,
@@ -2403,7 +2449,7 @@ function B(e) {
2403
2449
  function G(e) {
2404
2450
  return typeof e == "string" && (process.env.NODE_ENV === "production" || e.charAt(0) === e.charAt(0).toLowerCase());
2405
2451
  }
2406
- var L = typeof Symbol == "function" && Symbol.for, Y = L ? Symbol.for("react.memo") : 60115, q = L ? Symbol.for("react.forward_ref") : 60112, W = { childContextTypes: !0, contextType: !0, contextTypes: !0, defaultProps: !0, displayName: !0, getDefaultProps: !0, getDerivedStateFromError: !0, getDerivedStateFromProps: !0, mixins: !0, propTypes: !0, type: !0 }, H = { name: !0, length: !0, prototype: !0, caller: !0, callee: !0, arguments: !0, arity: !0 }, U = { $$typeof: !0, compare: !0, defaultProps: !0, displayName: !0, propTypes: !0, type: !0 }, J = ((V = {})[q] = { $$typeof: !0, render: !0, defaultProps: !0, displayName: !0, propTypes: !0 }, V[Y] = U, V);
2452
+ var L = typeof Symbol == "function" && Symbol.for, Y = L ? /* @__PURE__ */ Symbol.for("react.memo") : 60115, q = L ? /* @__PURE__ */ Symbol.for("react.forward_ref") : 60112, W = { childContextTypes: !0, contextType: !0, contextTypes: !0, defaultProps: !0, displayName: !0, getDefaultProps: !0, getDerivedStateFromError: !0, getDerivedStateFromProps: !0, mixins: !0, propTypes: !0, type: !0 }, H = { name: !0, length: !0, prototype: !0, caller: !0, callee: !0, arguments: !0, arity: !0 }, U = { $$typeof: !0, compare: !0, defaultProps: !0, displayName: !0, propTypes: !0, type: !0 }, J = ((V = {})[q] = { $$typeof: !0, render: !0, defaultProps: !0, displayName: !0, propTypes: !0 }, V[Y] = U, V);
2407
2453
  function X(e) {
2408
2454
  return ("type" in (t = e) && t.type.$$typeof) === Y ? U : "$$typeof" in e ? J[e.$$typeof] : W;
2409
2455
  var t;
@@ -3240,19 +3286,18 @@ const WrapText = dt(ui.Box)`
3240
3286
  const { displayed } = props.document;
3241
3287
  return /* @__PURE__ */ jsxRuntime.jsx(BaseTranslationWrapper, { showContainer: !1, children: /* @__PURE__ */ jsxRuntime.jsx(TranslationsProvider, { singleDocument: displayed, children: /* @__PURE__ */ jsxRuntime.jsx(TranslationView, {}) }) });
3242
3288
  }, translateAction = (props) => {
3243
- const router$1 = router.useRouter();
3289
+ const [dialogOpen, setDialogOpen] = o.useState(!1), document2 = props.draft || props.published;
3244
3290
  return {
3245
3291
  label: "Translate",
3246
3292
  icon: icons.TranslateIcon,
3247
3293
  tone: "primary",
3248
- onHandle: () => {
3249
- const { id, type } = props;
3250
- router$1.navigateIntent("edit", {
3251
- id,
3252
- type,
3253
- view: "general-translation"
3254
- });
3255
- }
3294
+ onHandle: () => setDialogOpen(!0),
3295
+ dialog: dialogOpen ? {
3296
+ type: "dialog",
3297
+ header: "Translations",
3298
+ onClose: () => setDialogOpen(!1),
3299
+ content: /* @__PURE__ */ jsxRuntime.jsx(BaseTranslationWrapper, { showContainer: !1, children: /* @__PURE__ */ jsxRuntime.jsx(TranslationsProvider, { singleDocument: document2, children: /* @__PURE__ */ jsxRuntime.jsx(TranslationView, {}) }) })
3300
+ } : null
3256
3301
  };
3257
3302
  }, TranslationsTable = () => {
3258
3303
  const {
@@ -3643,7 +3688,8 @@ const WrapText = dt(ui.Box)`
3643
3688
  }, TranslationsTool = () => /* @__PURE__ */ jsxRuntime.jsx(BaseTranslationWrapper, { showContainer: !1, children: /* @__PURE__ */ jsxRuntime.jsx(TranslationsProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(TranslationsToolContent, {}) }) }), gtPlugin = sanity.definePlugin(
3644
3689
  ({
3645
3690
  languageField = "language",
3646
- sourceLocale = internal.libraryDefaultLocale,
3691
+ sourceLocale,
3692
+ defaultLocale,
3647
3693
  locales,
3648
3694
  customMapping,
3649
3695
  apiKey,
@@ -3651,52 +3697,50 @@ const WrapText = dt(ui.Box)`
3651
3697
  singletons,
3652
3698
  singletonMapping,
3653
3699
  ignoreFields,
3700
+ skipFields,
3654
3701
  translateDocuments,
3655
3702
  secretsNamespace = SECRETS_NAMESPACE,
3656
3703
  additionalStopTypes = [],
3657
3704
  additionalSerializers = {},
3658
3705
  additionalDeserializers = {},
3659
3706
  additionalBlockDeserializers = []
3660
- }) => (translateDocuments = translateDocuments?.filter((filter2) => !!(filter2.documentId || filter2.type)), pluginConfig.init(
3661
- secretsNamespace,
3662
- languageField,
3663
- sourceLocale,
3664
- locales,
3665
- singletons || [],
3666
- // singletons is a string array of singleton document ids
3667
- singletonMapping || ((sourceDocumentId, locale) => `${sourceDocumentId}-${locale}`),
3668
- ignoreFields || [],
3669
- translateDocuments || [],
3670
- additionalStopTypes,
3671
- additionalSerializers,
3672
- additionalDeserializers,
3673
- additionalBlockDeserializers
3674
- ), gt.setConfig({
3675
- sourceLocale,
3676
- customMapping,
3677
- apiKey,
3678
- projectId
3679
- }), {
3680
- name: "gt-sanity",
3681
- tools: [
3682
- {
3683
- name: "translations",
3684
- title: "Translations",
3685
- component: TranslationsTool,
3686
- router: router.route.create("/*")
3687
- }
3688
- ],
3689
- document: {
3690
- views: [
3707
+ }) => {
3708
+ const resolvedSourceLocale = sourceLocale ?? defaultLocale ?? internal.libraryDefaultLocale;
3709
+ return translateDocuments = translateDocuments?.filter((filter2) => !!(filter2.documentId || filter2.type)), pluginConfig.init(
3710
+ secretsNamespace,
3711
+ languageField,
3712
+ resolvedSourceLocale,
3713
+ locales,
3714
+ singletons || [],
3715
+ // singletons is a string array of singleton document ids
3716
+ singletonMapping || ((sourceDocumentId, locale) => `${sourceDocumentId}-${locale}`),
3717
+ ignoreFields || [],
3718
+ skipFields || [],
3719
+ translateDocuments || [],
3720
+ additionalStopTypes,
3721
+ additionalSerializers,
3722
+ additionalDeserializers,
3723
+ additionalBlockDeserializers
3724
+ ), gt.setConfig({
3725
+ sourceLocale: resolvedSourceLocale,
3726
+ customMapping,
3727
+ apiKey,
3728
+ projectId
3729
+ }), {
3730
+ name: "gt-sanity",
3731
+ tools: [
3691
3732
  {
3692
- id: "general-translation",
3733
+ name: "translations",
3693
3734
  title: "Translations",
3694
- component: TranslationTab
3735
+ component: TranslationsTool,
3736
+ router: router.route.create("/*")
3695
3737
  }
3696
3738
  ],
3697
- actions: (prev2) => [...prev2, translateAction]
3698
- }
3699
- })
3739
+ document: {
3740
+ actions: (prev2) => [...prev2, translateAction]
3741
+ }
3742
+ };
3743
+ }
3700
3744
  );
3701
3745
  exports.BaseDocumentDeserializer = BaseDocumentDeserializer;
3702
3746
  exports.BaseDocumentMerger = BaseDocumentMerger;