@braze/sanity-plugin-ai-translation 0.2.81 → 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 {
@@ -3441,7 +3441,7 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
3441
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
3442
  () => references.filter((ref) => selectedReferenceIds.has(ref._id)),
3443
3443
  [references, selectedReferenceIds]
3444
- ), documentsToValidate = useMemo(() => {
3444
+ ), MAX_REFERENCE_VALIDATORS = 20, documentsToValidate = useMemo(() => {
3445
3445
  const docs = [
3446
3446
  {
3447
3447
  _id: document._id,
@@ -3449,15 +3449,16 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
3449
3449
  title: document.title || document.name || document._id
3450
3450
  }
3451
3451
  ];
3452
- if (shouldTranslateReferences)
3453
- for (const ref of references)
3454
- 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
+ }
3455
3459
  return docs;
3456
- }, [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) => {
3457
3461
  setValidationResults((prev) => {
3458
- const existing = prev.get(id);
3459
- if (existing && existing.isValidating === result.isValidating && existing.errors.length === result.errors.length)
3460
- return prev;
3461
3462
  const next = new Map(prev);
3462
3463
  return next.set(id, result), next;
3463
3464
  });
@@ -3674,6 +3675,14 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
3674
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, {}) }),
3675
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" })
3676
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
+ ] }),
3677
3686
  documentsWithErrors.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
3678
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." }),
3679
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) => {