@braze/sanity-plugin-ai-translation 0.2.81 → 0.2.83
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 +10 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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 {
|
|
@@ -3453,15 +3453,15 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
3453
3453
|
for (const ref of references)
|
|
3454
3454
|
selectedReferenceIds.has(ref._id) && docs.push(ref);
|
|
3455
3455
|
return docs;
|
|
3456
|
-
}, [document, references, selectedReferenceIds, shouldTranslateReferences]), handleValidationResult = useCallback((id, result) => {
|
|
3456
|
+
}, [document, references, selectedReferenceIds, shouldTranslateReferences]), CONCURRENT_VALIDATORS = 10, handleValidationResult = useCallback((id, result) => {
|
|
3457
3457
|
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
3458
|
const next = new Map(prev);
|
|
3462
3459
|
return next.set(id, result), next;
|
|
3463
3460
|
});
|
|
3464
|
-
}, []),
|
|
3461
|
+
}, []), activeValidators = useMemo(() => documentsToValidate.filter((doc) => {
|
|
3462
|
+
const result = validationResults.get(doc._id);
|
|
3463
|
+
return !result || result.isValidating;
|
|
3464
|
+
}).slice(0, CONCURRENT_VALIDATORS), [documentsToValidate, validationResults]), { hasValidationErrors, someStillValidating, documentsWithErrors } = useMemo(() => {
|
|
3465
3465
|
const allValidated = documentsToValidate.every((doc) => validationResults.has(doc._id)), validating = [...validationResults.values()].some((r) => r.isValidating) || !allValidated, docsWithErrors = [];
|
|
3466
3466
|
for (const doc of documentsToValidate) {
|
|
3467
3467
|
const result = validationResults.get(doc._id);
|
|
@@ -3647,7 +3647,7 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
3647
3647
|
onSkipConflicts: handleSkipConflicts
|
|
3648
3648
|
}
|
|
3649
3649
|
) }) : /* @__PURE__ */ jsxs(Stack, { space: 4, children: [
|
|
3650
|
-
|
|
3650
|
+
activeValidators.map((doc) => /* @__PURE__ */ jsx(
|
|
3651
3651
|
DocumentValidator,
|
|
3652
3652
|
{
|
|
3653
3653
|
documentId: doc._id,
|
|
@@ -3672,7 +3672,7 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
3672
3672
|
/* @__PURE__ */ jsx(Card, { padding: 4, border: !0, radius: 2, tone: hasValidationErrors ? "critical" : void 0, children: /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
|
|
3673
3673
|
/* @__PURE__ */ jsxs(Flex, { align: "center", gap: 2, children: [
|
|
3674
3674
|
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
|
-
/* @__PURE__ */ jsx(Text, { weight: "semibold", children: someStillValidating ?
|
|
3675
|
+
/* @__PURE__ */ jsx(Text, { weight: "semibold", children: someStillValidating ? `Validating documents (${validationResults.size}/${documentsToValidate.length})\u2026` : hasValidationErrors ? `Validation errors in ${documentsWithErrors.length} document${documentsWithErrors.length !== 1 ? "s" : ""}` : "All documents pass validation" })
|
|
3676
3676
|
] }),
|
|
3677
3677
|
documentsWithErrors.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3678
3678
|
/* @__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." }),
|