@sanity/document-internationalization 6.2.37 → 6.2.39

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/actions/DeleteTranslationAction.tsx","../src/actions/DuplicateWithTranslationsAction.tsx","../src/types.ts","../src/components/DocumentInternationalizationContext.tsx","../src/components/DocumentInternationalizationMenu.tsx","../src/plugin.tsx"],"mappings":";;;iBAmCE,2BAAA,OAAO,sBACN;;;;;;;;;cA6FU,0BAAuB,OAAW,wBAAsB;iBC5ElB,qCACjD,IACA,MAEA,cACC,sBAAsB;;;;;iBAqMvB,gCAAA,OAAO,sBACN;;;;;KClPS;EACV,IAAI,KAAK;EACT;;KAGU,qBAAqB,eAAe,QAAQ,iBAAiB,QAAQ;KAErE;EACV,gBAAgB;EAChB,aAAa;EACb;EACA;EACA;EACA,QAAQ;;KAGE;EACV,oBAAoB;EACpB;EACA;EACA;EACA;EACA,iBAAiB;EACjB;EACA;EACA,aAAa,MAAM,uBAAuB;EAC1C,4CAA4C,KAAK;;;;;;EAMjD;;;;EAIA,+BAA+B,KAC7B;;;;EAMF;;KAMU,sBAAsB,SAAS,KAAK;EAC9C,oBAAoB;EACpB,+BAA+B,KAC7B;;KAKQ,uBAAuB,2BAA2B;EAC5D;EACA,OAAO;;KAGG;EACV;EACA;EACA,cAAc;;KAGJ,mBAAmB;EAC7B;EACA,cAAc;;KAGJ;EACV,YAAY;EACZ;;UAIe;EACf;;IAEE;;;;YAKQ,qBAAqB;YACrB,qBAAqB;YACrB,uBAAuB;YACvB,qCAAqC;YACrC,oBAAoB;YACpB,wBAAwB;YACxB,oBAAoB;YACpB,wBAAwB;YACxB,qBAAqB;YACrB,sBAAsB;YACtB,sBAAsB;YACtB,6BAA6B;YAC7B,oBAAoB;YACpB,sBAAsB;YACtB,oBAAoB;YACpB,mBAAmB;YACnB,qBAAqB;;iBC5GjB,0CAA0C;iBCQ1C,iCACd,OAAO,wCACN,MAAM,IAAI;cCJA,+CAA4B,OAAA"}
1
+ {"version":3,"file":"index.d.ts","names":["InternationalizedArrayPluginConfig"],"sources":["../src/actions/DeleteTranslationAction.tsx","../src/actions/DuplicateWithTranslationsAction.tsx","../src/types.ts","../src/components/DocumentInternationalizationContext.tsx","../src/components/DocumentInternationalizationMenu.tsx","../src/plugin.tsx"],"mappings":";;;iBAmCE,2BAAA,OAAO,sBACN;;;;;;;;;cA6FU,0BAAuB,OAAW,wBAAsB;iBC5ElB,qCACjD,IACA,MAEA,cACC,sBAAsB;;;;;iBAqMvB,gCAAA,OAAO,sBACN;;;;;KClPS;EACV,IAAI,KAAK;EACT;;KAGU,qBAAqB,eAAe,QAAQ,iBAAiB,QAAQ;KAErE;EACV,gBAAgB;EAChB,aAAa;EACb;EACA;EACA;EACA,QAAQ;;KAGE;EACV,oBAAoB;EACpB;EACA;EACA;EACA;EACA,iBAAiB;EACjB;EACA;EACA,aAAa,MAAM,uBAAuB;EAC1C,4CAA4C,KAAK;;;;;;EAMjD;;;;EAIA,+BAA+B,KAC7BA;;;;EAMF;;KAMU,sBAAsB,SAAS,KAAK;EAC9C,oBAAoB;EACpB,+BAA+B,KAC7BA;;KAKQ,uBAAuB,2BAA2B;EAC5D;EACA,OAAO;;KAGG;EACV;EACA;EACA,cAAc;;KAGJ,mBAAmB;EAC7B;EACA,cAAc;;KAGJ;EACV,YAAY;EACZ;;UAIe;EACf;;IAEE;;;;YAKQ,qBAAqB;YACrB,qBAAqB;YACrB,uBAAuB;YACvB,qCAAqC;YACrC,oBAAoB;YACpB,wBAAwB;YACxB,oBAAoB;YACpB,wBAAwB;YACxB,qBAAqB;YACrB,sBAAsB;YACtB,sBAAsB;YACtB,6BAA6B;YAC7B,oBAAoB;YACpB,sBAAsB;YACtB,oBAAoB;YACpB,mBAAmB;YACnB,qBAAqB;;iBC5GjB,0CAA0C;iBCQ1C,iCACd,OAAO,wCACN,MAAM,IAAI;cCJA,+CAA4B,OAAA"}
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { c } from "react/compiler-runtime";
3
3
  import { TrashIcon } from "@sanity/icons/Trash";
4
4
  import { useToast } from "@sanity/ui/toast";
5
5
  import { createContext, use, useContext, useEffect, useRef, useState } from "react";
6
- import { DEFAULT_STUDIO_CLIENT_OPTIONS, InsufficientPermissionsMessage, PatchEvent, Preview, TextWithTone, defineField, defineLocaleResourceBundle, definePlugin, defineType, getDraftId, getVersionFromId, getVersionId, isDocumentSchemaType, isSanityDocument, isVersionId, pathToString, unset, useClient, useCurrentUser, useDocumentOperation, useDocumentPairPermissions, useDocumentStore, useEditState, usePerspective, useSchema, useTranslation, useValidationStatus, useWorkspace } from "sanity";
6
+ import { DEFAULT_STUDIO_CLIENT_OPTIONS, InsufficientPermissionsMessage, PatchEvent, Preview, TextWithTone, defineField, defineLocaleResourceBundle, definePlugin, defineType, getDraftId, getVersionFromId, getVersionId, isDocumentSchemaType, isSanityDocument, isVersionId, pathToString, unset, useClient, useCurrentUser, useDocumentOperation, useDocumentPairPermissions, useDocumentStore, useEditState, usePerspective, useSchema, useTranslation, useUnstableObserveDocument, useValidationStatus, useWorkspace } from "sanity";
7
7
  import { LANGUAGE_FIELD_NAME, internationalizedArray } from "sanity-plugin-internationalized-array";
8
8
  import { Badge, Box, Button, Card, Dialog, Flex, Grid, Inline, Spinner, Stack, Text, TextInput, useClickOutsideEvent } from "@sanity/ui";
9
9
  import { Feedback, useListeningQuery } from "sanity-plugin-utils";
@@ -121,7 +121,7 @@ function DeleteTranslationDialog(props) {
121
121
  "must be removed"
122
122
  ]
123
123
  }),
124
- translations.map(_temp$5)
124
+ translations.map(_temp$6)
125
125
  ] }) : null, $[18] = translations, $[19] = t9);
126
126
  let t10;
127
127
  $[20] === otherReferences ? t10 = $[21] : (t10 = otherReferences && otherReferences.length > 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [
@@ -169,7 +169,7 @@ function _temp2$3(reference) {
169
169
  type: reference._type
170
170
  }, reference._id);
171
171
  }
172
- function _temp$5(translation) {
172
+ function _temp$6(translation) {
173
173
  return /* @__PURE__ */ jsx(DocumentPreview, {
174
174
  value: translation,
175
175
  type: translation._type
@@ -369,7 +369,7 @@ const documenti18nLocaleNamespace = "document-internationalization", documentInt
369
369
  let dupeId = uuid(), locale = translation[LANGUAGE_FIELD_NAME], docId = translation.value?._ref;
370
370
  if (typeof locale != "string" || locale.trim().length === 0) return Promise.reject(/* @__PURE__ */ Error("Invalid locale for translation"));
371
371
  if (!docId) return Promise.reject(/* @__PURE__ */ Error("Translation document not found"));
372
- let { duplicate: duplicateTranslation } = await firstValueFrom(documentStore.pair.editOperations(docId, type).pipe(filter(_temp$4)));
372
+ let { duplicate: duplicateTranslation } = await firstValueFrom(documentStore.pair.editOperations(docId, type).pipe(filter(_temp$5)));
373
373
  if (duplicateTranslation.disabled) return Promise.reject(/* @__PURE__ */ Error("Cannot duplicate document"));
374
374
  let duplicateTranslationSuccess = firstValueFrom(documentStore.pair.operationEvents(docId, type).pipe(filter(_temp2$2)));
375
375
  duplicateTranslation.execute(dupeId), await duplicateTranslationSuccess, translations.set(locale, dupeId);
@@ -464,7 +464,7 @@ useDuplicateWithTranslationsAction.action = "duplicate", useDuplicateWithTransla
464
464
  */
465
465
  const DuplicateWithTranslationsAction = (props) => useDuplicateWithTranslationsAction(props);
466
466
  DuplicateWithTranslationsAction.action = "duplicate", DuplicateWithTranslationsAction.displayName = "DuplicateWithTranslationsAction";
467
- function _temp$4(op) {
467
+ function _temp$5(op) {
468
468
  return op.duplicate.disabled !== "NOT_READY";
469
469
  }
470
470
  function _temp2$2(e) {
@@ -819,7 +819,7 @@ function DocumentInternationalizationMenu(props) {
819
819
  event.currentTarget.value ? setQuery(event.currentTarget.value) : setQuery("");
820
820
  }, $[0] = t0) : t0 = $[0];
821
821
  let handleQuery = t0, [open, setOpen] = useState(!1), t1;
822
- $[1] === Symbol.for("react.memo_cache_sentinel") ? (t1 = () => setOpen(_temp$3), $[1] = t1) : t1 = $[1];
822
+ $[1] === Symbol.for("react.memo_cache_sentinel") ? (t1 = () => setOpen(_temp$4), $[1] = t1) : t1 = $[1];
823
823
  let handleClick = t1, buttonRef = useRef(null), popoverRef = useRef(null), t2;
824
824
  $[2] === Symbol.for("react.memo_cache_sentinel") ? (t2 = () => setOpen(!1), $[2] = t2) : t2 = $[2];
825
825
  let handleClickOutside = t2, t3;
@@ -923,7 +923,7 @@ function DocumentInternationalizationMenu(props) {
923
923
  function _temp2$1(l_0) {
924
924
  return l_0.id && l_0.title;
925
925
  }
926
- function _temp$3(o) {
926
+ function _temp$4(o) {
927
927
  return !o;
928
928
  }
929
929
  /**
@@ -943,7 +943,7 @@ const useDeleteMetadataAction = (props) => {
943
943
  let client = useClient(t2), t3;
944
944
  $[4] !== client || $[5] !== documentId || $[6] !== toast || $[7] !== translations ? (t3 = () => {
945
945
  let tx = client.transaction();
946
- tx.patch(documentId, _temp$2), translations.length > 0 && translations.forEach((translation) => {
946
+ tx.patch(documentId, _temp$3), translations.length > 0 && translations.forEach((translation) => {
947
947
  tx.delete(translation.value._ref), tx.delete(`drafts.${translation.value._ref}`);
948
948
  }), tx.delete(documentId), tx.delete(`drafts.${documentId}`), tx.commit().then(() => {
949
949
  onClose(), toast.push({
@@ -982,7 +982,7 @@ const useDeleteMetadataAction = (props) => {
982
982
  dialog: t6
983
983
  }, $[14] = t4, $[15] = t6, $[16] = t7) : t7 = $[16], t7;
984
984
  };
985
- function _temp$2(patch) {
985
+ function _temp$3(patch) {
986
986
  return patch.unset([TRANSLATIONS_ARRAY_NAME]);
987
987
  }
988
988
  /**
@@ -1006,7 +1006,7 @@ function DocumentCheck(props) {
1006
1006
  let $ = c(25), { id, onCheckComplete, addInvalidId, removeInvalidId, addDraftId, removeDraftId } = props, editState = useEditState(id, ""), documentType = editState.draft?._type ?? editState.published?._type ?? "", { isValidating, validation: t0 } = useValidationStatus(id, documentType, !1), t1;
1007
1007
  $[0] === t0 ? t1 = $[1] : (t1 = t0 === void 0 ? [] : t0, $[0] = t0, $[1] = t1);
1008
1008
  let validation = t1, schema = useSchema(), t2;
1009
- $[2] !== isValidating || $[3] !== validation ? (t2 = !isValidating && validation.some(_temp$1), $[2] = isValidating, $[3] = validation, $[4] = t2) : t2 = $[4];
1009
+ $[2] !== isValidating || $[3] !== validation ? (t2 = !isValidating && validation.some(_temp$2), $[2] = isValidating, $[3] = validation, $[4] = t2) : t2 = $[4];
1010
1010
  let validationHasErrors = t2, t3, t4;
1011
1011
  if ($[5] !== addDraftId || $[6] !== addInvalidId || $[7] !== editState.draft || $[8] !== id || $[9] !== isValidating || $[10] !== onCheckComplete || $[11] !== removeDraftId || $[12] !== removeInvalidId || $[13] !== validationHasErrors ? (t3 = () => {
1012
1012
  validationHasErrors ? addInvalidId(id) : removeInvalidId(id), editState.draft ? addDraftId(id) : removeDraftId(id), isValidating || onCheckComplete(id);
@@ -1037,7 +1037,7 @@ function DocumentCheck(props) {
1037
1037
  children: t7
1038
1038
  }), $[22] = t6, $[23] = t7, $[24] = t8) : t8 = $[24], t8;
1039
1039
  }
1040
- function _temp$1(item) {
1040
+ function _temp$2(item) {
1041
1041
  return item.level === "error";
1042
1042
  }
1043
1043
  function InfoIcon(props) {
@@ -1130,7 +1130,7 @@ function BulkPublish(props) {
1130
1130
  }, $[9] = t9) : t9 = $[9];
1131
1131
  let removeDraftId = t9, t10;
1132
1132
  $[10] !== client || $[11] !== dataset || $[12] !== projectId || $[13] !== toast || $[14] !== translations ? (t10 = () => {
1133
- let body = translations.map(_temp);
1133
+ let body = translations.map(_temp$1);
1134
1134
  client.request({
1135
1135
  url: `/publish/${projectId}/${dataset}`,
1136
1136
  method: "POST",
@@ -1237,15 +1237,13 @@ function BulkPublish(props) {
1237
1237
  function _temp2(translation_0) {
1238
1238
  return translation_0?.value?._ref;
1239
1239
  }
1240
- function _temp(translation) {
1240
+ function _temp$1(translation) {
1241
1241
  return { documentId: translation.value._ref };
1242
1242
  }
1243
1243
  function ReferencePatcher(props) {
1244
- let $ = c(14), { translation, documentType, metadataId } = props, editState = useEditState(translation.value._ref, documentType), t0;
1245
- $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = { apiVersion: API_VERSION }, $[0] = t0) : t0 = $[0];
1246
- let client = useClient(t0), { onChange } = useDocumentPane(), t1;
1247
- $[1] !== editState || $[2] !== onChange || $[3] !== translation._key || $[4] !== translation.value._ref || $[5] !== translation.value._strengthenOnPublish || $[6] !== translation.value._weak ? (t1 = () => {
1248
- if (translation.value._ref && translation.value._weak && translation.value._strengthenOnPublish && !editState.draft && editState.published && editState.ready) {
1244
+ let $ = c(20), { translation } = props, { document: publishedDocument, loading } = useUnstableObserveDocument(translation.value._ref), { onChange, ready, formState } = useDocumentPane(), t0;
1245
+ $[0] !== formState?.readOnly || $[1] !== loading || $[2] !== onChange || $[3] !== publishedDocument || $[4] !== ready || $[5] !== translation._key || $[6] !== translation.value._ref || $[7] !== translation.value._strengthenOnPublish || $[8] !== translation.value._weak ? (t0 = () => {
1246
+ if (translation.value._ref && translation.value._weak && translation.value._strengthenOnPublish && !loading && publishedDocument && ready && !formState?.readOnly) {
1249
1247
  let referencePathBase = [
1250
1248
  "translations",
1251
1249
  { _key: translation._key },
@@ -1253,32 +1251,32 @@ function ReferencePatcher(props) {
1253
1251
  ];
1254
1252
  onChange(new PatchEvent([unset([...referencePathBase, "_weak"]), unset([...referencePathBase, "_strengthenOnPublish"])]));
1255
1253
  }
1256
- }, $[1] = editState, $[2] = onChange, $[3] = translation._key, $[4] = translation.value._ref, $[5] = translation.value._strengthenOnPublish, $[6] = translation.value._weak, $[7] = t1) : t1 = $[7];
1257
- let t2;
1258
- return $[8] !== client || $[9] !== editState || $[10] !== metadataId || $[11] !== onChange || $[12] !== translation ? (t2 = [
1259
- translation,
1260
- editState,
1261
- metadataId,
1262
- client,
1263
- onChange
1264
- ], $[8] = client, $[9] = editState, $[10] = metadataId, $[11] = onChange, $[12] = translation, $[13] = t2) : t2 = $[13], useEffect(t1, t2), null;
1254
+ }, $[0] = formState?.readOnly, $[1] = loading, $[2] = onChange, $[3] = publishedDocument, $[4] = ready, $[5] = translation._key, $[6] = translation.value._ref, $[7] = translation.value._strengthenOnPublish, $[8] = translation.value._weak, $[9] = t0) : t0 = $[9];
1255
+ let t1 = formState?.readOnly, t2;
1256
+ return $[10] !== loading || $[11] !== onChange || $[12] !== publishedDocument || $[13] !== ready || $[14] !== t1 || $[15] !== translation._key || $[16] !== translation.value._ref || $[17] !== translation.value._strengthenOnPublish || $[18] !== translation.value._weak ? (t2 = [
1257
+ t1,
1258
+ loading,
1259
+ onChange,
1260
+ publishedDocument,
1261
+ ready,
1262
+ translation._key,
1263
+ translation.value._ref,
1264
+ translation.value._strengthenOnPublish,
1265
+ translation.value._weak
1266
+ ], $[10] = loading, $[11] = onChange, $[12] = publishedDocument, $[13] = ready, $[14] = t1, $[15] = translation._key, $[16] = translation.value._ref, $[17] = translation.value._strengthenOnPublish, $[18] = translation.value._weak, $[19] = t2) : t2 = $[19], useEffect(t0, t2), null;
1265
1267
  }
1266
1268
  function OptimisticallyStrengthen(props) {
1267
- let $ = c(9), { translations: t0, metadataId } = props, t1;
1269
+ let $ = c(6), { translations: t0 } = props, t1;
1268
1270
  $[0] === t0 ? t1 = $[1] : (t1 = t0 === void 0 ? [] : t0, $[0] = t0, $[1] = t1);
1269
1271
  let translations = t1;
1270
1272
  if (!translations.length) return null;
1271
1273
  let t2;
1272
- if ($[2] !== metadataId || $[3] !== translations) {
1273
- let t3;
1274
- $[5] === metadataId ? t3 = $[6] : (t3 = (translation) => translation.value._strengthenOnPublish?.type ? /* @__PURE__ */ jsx(ReferencePatcher, {
1275
- translation,
1276
- documentType: translation.value._strengthenOnPublish.type,
1277
- metadataId
1278
- }, translation._key) : null, $[5] = metadataId, $[6] = t3), t2 = translations.map(t3), $[2] = metadataId, $[3] = translations, $[4] = t2;
1279
- } else t2 = $[4];
1274
+ $[2] === translations ? t2 = $[3] : (t2 = translations.map(_temp), $[2] = translations, $[3] = t2);
1280
1275
  let t3;
1281
- return $[7] === t2 ? t3 = $[8] : (t3 = /* @__PURE__ */ jsx(Fragment, { children: t2 }), $[7] = t2, $[8] = t3), t3;
1276
+ return $[4] === t2 ? t3 = $[5] : (t3 = /* @__PURE__ */ jsx(Fragment, { children: t2 }), $[4] = t2, $[5] = t3), t3;
1277
+ }
1278
+ function _temp(translation) {
1279
+ return translation.value._strengthenOnPublish?.type ? /* @__PURE__ */ jsx(ReferencePatcher, { translation }, translation._key) : null;
1282
1280
  }
1283
1281
  /**
1284
1282
  * Creates the `translation.metadata` document schema definition. This schema
@@ -1338,15 +1336,12 @@ const documentInternationalization = definePlugin((config) => {
1338
1336
  i18n: { bundles: [documentInternationalizationUsEnglishLocaleBundle] },
1339
1337
  form: { components: { input: (props) => {
1340
1338
  if (props.id === "root" && props.schemaType.name === METADATA_SCHEMA_NAME && isSanityDocument(props?.value)) {
1341
- let metadataId = props?.value?._id, translations = props?.value?.translations ?? [], weakAndTypedTranslations = translations.filter(({ value }) => value?._weak && value._strengthenOnPublish);
1339
+ let translations = props?.value?.translations ?? [], weakAndTypedTranslations = translations.filter(({ value }) => value?._weak && value._strengthenOnPublish);
1342
1340
  return /* @__PURE__ */ jsxs(Stack, {
1343
1341
  gap: 5,
1344
1342
  children: [
1345
1343
  bulkPublish ? /* @__PURE__ */ jsx(BulkPublish, { translations }) : null,
1346
- weakAndTypedTranslations.length > 0 ? /* @__PURE__ */ jsx(OptimisticallyStrengthen, {
1347
- metadataId,
1348
- translations: weakAndTypedTranslations
1349
- }) : null,
1344
+ weakAndTypedTranslations.length > 0 ? /* @__PURE__ */ jsx(OptimisticallyStrengthen, { translations: weakAndTypedTranslations }) : null,
1350
1345
  props.renderDefault(props)
1351
1346
  ]
1352
1347
  });