@braze/sanity-plugin-ai-translation 0.2.80 → 0.2.82

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.js CHANGED
@@ -3412,7 +3412,7 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
3412
3412
  }
3413
3413
  );
3414
3414
  }, VALIDATION_TIMEOUT_MS = 2e3, DocumentValidator = ({ documentId, documentType, onResult }) => {
3415
- const publishedId = getPublishedId(documentId), { isValidating, validation } = useValidationStatus(publishedId, documentType), hasReceivedRealResult = useRef(!1), hasSettled = useRef(!1), [timedOut, setTimedOut] = useState(!1);
3415
+ const publishedId = getPublishedId(documentId), { isValidating, validation } = useValidationStatus(publishedId, documentType), hasReceivedRealResult = useRef(!1), hasSettled = useRef(!1), lastReported = useRef(null), [timedOut, setTimedOut] = useState(!1);
3416
3416
  return useEffect(() => {
3417
3417
  const timer = setTimeout(() => setTimedOut(!0), VALIDATION_TIMEOUT_MS);
3418
3418
  return () => clearTimeout(timer);
@@ -3420,10 +3420,10 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
3420
3420
  if (hasSettled.current) return;
3421
3421
  (isValidating || validation.length > 0) && (hasReceivedRealResult.current = !0);
3422
3422
  const stillWaitingForFirstResult = !hasReceivedRealResult.current && !timedOut, errors = validation.filter((v) => v.level === "error"), computedIsValidating = isValidating || stillWaitingForFirstResult;
3423
- !computedIsValidating && hasReceivedRealResult.current && (hasSettled.current = !0), onResult(documentId, {
3423
+ !computedIsValidating && hasReceivedRealResult.current && (hasSettled.current = !0), !(lastReported.current && lastReported.current.isValidating === computedIsValidating && lastReported.current.errorCount === errors.length) && (lastReported.current = { isValidating: computedIsValidating, errorCount: errors.length }, onResult(documentId, {
3424
3424
  isValidating: computedIsValidating,
3425
3425
  errors
3426
- });
3426
+ }));
3427
3427
  }, [isValidating, validation, documentId, onResult, timedOut]), null;
3428
3428
  }, PreflightView = () => {
3429
3429
  const {
@@ -3438,7 +3438,10 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
3438
3438
  translationMode,
3439
3439
  releaseConfig,
3440
3440
  documentSource
3441
- } = useTranslationContext(), client = useClient({ apiVersion: "vX" }), [scanKey, setScanKey] = useState(0), [validationResults, setValidationResults] = useState(/* @__PURE__ */ new Map()), [sourceRefsWithDrafts, setSourceRefsWithDrafts] = useState([]), [isSourceDraftCheckLoading, setIsSourceDraftCheckLoading] = useState(!0), [staleDrafts, setStaleDrafts] = useState([]), [isDraftCheckLoading, setIsDraftCheckLoading] = useState(!0), [draftAction, setDraftAction] = useState("none"), [isDraftActionInProgress, setIsDraftActionInProgress] = useState(!1), [conflictContext, setConflictContext] = useState(null), [isCheckingConflicts, setIsCheckingConflicts] = useState(!0), filteredReferences = references.filter((ref) => selectedReferenceIds.has(ref._id)), documentsToValidate = useMemo(() => {
3441
+ } = useTranslationContext(), client = useClient({ apiVersion: "vX" }), [scanKey, setScanKey] = useState(0), [validationResults, setValidationResults] = useState(/* @__PURE__ */ new Map()), [sourceRefsWithDrafts, setSourceRefsWithDrafts] = useState([]), [isSourceDraftCheckLoading, setIsSourceDraftCheckLoading] = useState(!0), [staleDrafts, setStaleDrafts] = useState([]), [isDraftCheckLoading, setIsDraftCheckLoading] = useState(!0), [draftAction, setDraftAction] = useState("none"), [isDraftActionInProgress, setIsDraftActionInProgress] = useState(!1), [conflictContext, setConflictContext] = useState(null), [isCheckingConflicts, setIsCheckingConflicts] = useState(!0), filteredReferences = useMemo(
3442
+ () => references.filter((ref) => selectedReferenceIds.has(ref._id)),
3443
+ [references, selectedReferenceIds]
3444
+ ), MAX_REFERENCE_VALIDATORS = 20, documentsToValidate = useMemo(() => {
3442
3445
  const docs = [
3443
3446
  {
3444
3447
  _id: document._id,
@@ -3446,11 +3449,15 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
3446
3449
  title: document.title || document.name || document._id
3447
3450
  }
3448
3451
  ];
3449
- if (shouldTranslateReferences)
3450
- for (const ref of references)
3451
- selectedReferenceIds.has(ref._id) && docs.push(ref);
3452
+ if (shouldTranslateReferences) {
3453
+ let count = 0;
3454
+ for (const ref of references) {
3455
+ if (count >= MAX_REFERENCE_VALIDATORS) break;
3456
+ selectedReferenceIds.has(ref._id) && (docs.push(ref), count++);
3457
+ }
3458
+ }
3452
3459
  return docs;
3453
- }, [document, references, selectedReferenceIds, shouldTranslateReferences]), handleValidationResult = useCallback((id, result) => {
3460
+ }, [document, references, selectedReferenceIds, shouldTranslateReferences]), skippedValidationCount = shouldTranslateReferences ? Math.max(0, filteredReferences.length - MAX_REFERENCE_VALIDATORS) : 0, handleValidationResult = useCallback((id, result) => {
3454
3461
  setValidationResults((prev) => {
3455
3462
  const next = new Map(prev);
3456
3463
  return next.set(id, result), next;
@@ -3668,6 +3675,14 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
3668
3675
  someStillValidating ? /* @__PURE__ */ jsx(Spinner, { muted: !0 }) : hasValidationErrors ? /* @__PURE__ */ jsx(Text, { size: 2, children: /* @__PURE__ */ jsx(ErrorOutlineIcon, {}) }) : /* @__PURE__ */ jsx(Text, { size: 2, children: /* @__PURE__ */ jsx(CheckmarkIcon, {}) }),
3669
3676
  /* @__PURE__ */ jsx(Text, { weight: "semibold", children: someStillValidating ? "Validating documents\u2026" : hasValidationErrors ? `Validation errors in ${documentsWithErrors.length} document${documentsWithErrors.length !== 1 ? "s" : ""}` : "All documents pass validation" })
3670
3677
  ] }),
3678
+ skippedValidationCount > 0 && !someStillValidating && /* @__PURE__ */ jsxs(Text, { size: 1, muted: !0, children: [
3679
+ skippedValidationCount,
3680
+ " additional reference",
3681
+ skippedValidationCount !== 1 ? "s were" : " was",
3682
+ " not validated (limit: ",
3683
+ MAX_REFERENCE_VALIDATORS,
3684
+ ")."
3685
+ ] }),
3671
3686
  documentsWithErrors.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
3672
3687
  /* @__PURE__ */ jsx(Text, { size: 1, children: "Documents must pass validation before they can be translated. Click a document to open it and fix the errors." }),
3673
3688
  /* @__PURE__ */ jsx(Card, { padding: 3, border: !0, radius: 2, children: /* @__PURE__ */ jsx(Box, { style: { maxHeight: "300px", overflowY: "auto" }, children: /* @__PURE__ */ jsx(Stack, { space: 3, children: documentsWithErrors.map((doc) => {