@braze/sanity-plugin-ai-translation 0.2.82 → 0.2.84
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 +24 -37
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -416,9 +416,7 @@ const isLoggingEnabled = () => process.env.NEXT_PUBLIC_SANITY_STUDIO_AI_TRANSLAT
|
|
|
416
416
|
const refIdSet = new Set(refIds);
|
|
417
417
|
for (const metadataDoc of refMetadataDocs) {
|
|
418
418
|
if (!metadataDoc.translations?.length) continue;
|
|
419
|
-
const matchingRefId = metadataDoc.translations.find(
|
|
420
|
-
(t) => t.value?._ref && refIdSet.has(t.value._ref)
|
|
421
|
-
)?.value._ref;
|
|
419
|
+
const matchingRefId = metadataDoc.translations.find((t) => t.value?._ref && refIdSet.has(t.value._ref))?.value._ref;
|
|
422
420
|
if (matchingRefId)
|
|
423
421
|
for (const lang of selectedTargetLanguages) {
|
|
424
422
|
const targetId = getExistingTranslationId(metadataDoc, lang);
|
|
@@ -3411,14 +3409,14 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
3411
3409
|
padding: 2
|
|
3412
3410
|
}
|
|
3413
3411
|
);
|
|
3414
|
-
}, VALIDATION_TIMEOUT_MS =
|
|
3415
|
-
const publishedId = getPublishedId(documentId), { isValidating, validation } = useValidationStatus(publishedId, documentType), hasReceivedRealResult = useRef(!1), hasSettled = useRef(!1), lastReported = useRef(null), [timedOut, setTimedOut] = useState(!1);
|
|
3412
|
+
}, VALIDATION_TIMEOUT_MS = 1e4, DocumentValidator = ({ documentId, documentType, onResult }) => {
|
|
3413
|
+
const publishedId = getPublishedId(documentId), { isValidating, validation } = useValidationStatus(publishedId, documentType), hasReceivedRealResult = useRef(!1), hasSettled = useRef(!1), lastReported = useRef(null), [timedOut, setTimedOut] = useState(!1), initialValidationRef = useRef(validation);
|
|
3416
3414
|
return useEffect(() => {
|
|
3417
3415
|
const timer = setTimeout(() => setTimedOut(!0), VALIDATION_TIMEOUT_MS);
|
|
3418
3416
|
return () => clearTimeout(timer);
|
|
3419
3417
|
}, []), useEffect(() => {
|
|
3420
3418
|
if (hasSettled.current) return;
|
|
3421
|
-
(isValidating || validation.length > 0) && (hasReceivedRealResult.current = !0);
|
|
3419
|
+
(isValidating || validation.length > 0 || validation !== initialValidationRef.current) && (hasReceivedRealResult.current = !0);
|
|
3422
3420
|
const stillWaitingForFirstResult = !hasReceivedRealResult.current && !timedOut, errors = validation.filter((v) => v.level === "error"), computedIsValidating = isValidating || stillWaitingForFirstResult;
|
|
3423
3421
|
!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
3422
|
isValidating: computedIsValidating,
|
|
@@ -3441,7 +3439,7 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
3441
3439
|
} = 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
3440
|
() => references.filter((ref) => selectedReferenceIds.has(ref._id)),
|
|
3443
3441
|
[references, selectedReferenceIds]
|
|
3444
|
-
),
|
|
3442
|
+
), documentsToValidate = useMemo(() => {
|
|
3445
3443
|
const docs = [
|
|
3446
3444
|
{
|
|
3447
3445
|
_id: document._id,
|
|
@@ -3449,20 +3447,19 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
3449
3447
|
title: document.title || document.name || document._id
|
|
3450
3448
|
}
|
|
3451
3449
|
];
|
|
3452
|
-
if (shouldTranslateReferences)
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
if (count >= MAX_REFERENCE_VALIDATORS) break;
|
|
3456
|
-
selectedReferenceIds.has(ref._id) && (docs.push(ref), count++);
|
|
3457
|
-
}
|
|
3458
|
-
}
|
|
3450
|
+
if (shouldTranslateReferences)
|
|
3451
|
+
for (const ref of references)
|
|
3452
|
+
selectedReferenceIds.has(ref._id) && docs.push(ref);
|
|
3459
3453
|
return docs;
|
|
3460
|
-
}, [document, references, selectedReferenceIds, shouldTranslateReferences]),
|
|
3454
|
+
}, [document, references, selectedReferenceIds, shouldTranslateReferences]), CONCURRENT_VALIDATORS = 10, handleValidationResult = useCallback((id, result) => {
|
|
3461
3455
|
setValidationResults((prev) => {
|
|
3462
3456
|
const next = new Map(prev);
|
|
3463
3457
|
return next.set(id, result), next;
|
|
3464
3458
|
});
|
|
3465
|
-
}, []),
|
|
3459
|
+
}, []), activeValidators = useMemo(() => documentsToValidate.filter((doc) => {
|
|
3460
|
+
const result = validationResults.get(doc._id);
|
|
3461
|
+
return !result || result.isValidating;
|
|
3462
|
+
}).slice(0, CONCURRENT_VALIDATORS), [documentsToValidate, validationResults]), { hasValidationErrors, someStillValidating, documentsWithErrors } = useMemo(() => {
|
|
3466
3463
|
const allValidated = documentsToValidate.every((doc) => validationResults.has(doc._id)), validating = [...validationResults.values()].some((r) => r.isValidating) || !allValidated, docsWithErrors = [];
|
|
3467
3464
|
for (const doc of documentsToValidate) {
|
|
3468
3465
|
const result = validationResults.get(doc._id);
|
|
@@ -3513,7 +3510,14 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
3513
3510
|
} finally {
|
|
3514
3511
|
setIsDraftCheckLoading(!1);
|
|
3515
3512
|
}
|
|
3516
|
-
}, [
|
|
3513
|
+
}, [
|
|
3514
|
+
client,
|
|
3515
|
+
translationMetadata,
|
|
3516
|
+
selectedTargetLanguages,
|
|
3517
|
+
document._id,
|
|
3518
|
+
shouldTranslateReferences,
|
|
3519
|
+
filteredReferences
|
|
3520
|
+
]), runConflictCheck = useCallback(async () => {
|
|
3517
3521
|
if (releaseConfig.mode === "new") {
|
|
3518
3522
|
setIsCheckingConflicts(!1), setConflictContext(null);
|
|
3519
3523
|
return;
|
|
@@ -3648,7 +3652,7 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
3648
3652
|
onSkipConflicts: handleSkipConflicts
|
|
3649
3653
|
}
|
|
3650
3654
|
) }) : /* @__PURE__ */ jsxs(Stack, { space: 4, children: [
|
|
3651
|
-
|
|
3655
|
+
activeValidators.map((doc) => /* @__PURE__ */ jsx(
|
|
3652
3656
|
DocumentValidator,
|
|
3653
3657
|
{
|
|
3654
3658
|
documentId: doc._id,
|
|
@@ -3673,15 +3677,7 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
3673
3677
|
/* @__PURE__ */ jsx(Card, { padding: 4, border: !0, radius: 2, tone: hasValidationErrors ? "critical" : void 0, children: /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
|
|
3674
3678
|
/* @__PURE__ */ jsxs(Flex, { align: "center", gap: 2, children: [
|
|
3675
3679
|
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, {}) }),
|
|
3676
|
-
/* @__PURE__ */ jsx(Text, { weight: "semibold", children: someStillValidating ?
|
|
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
|
-
")."
|
|
3680
|
+
/* @__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" })
|
|
3685
3681
|
] }),
|
|
3686
3682
|
documentsWithErrors.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3687
3683
|
/* @__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." }),
|
|
@@ -3785,16 +3781,7 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
3785
3781
|
/* @__PURE__ */ jsxs(Flex, { justify: "space-between", gap: 2, children: [
|
|
3786
3782
|
/* @__PURE__ */ jsx(Button, { mode: "ghost", text: "Back", onClick: handleBack }),
|
|
3787
3783
|
/* @__PURE__ */ jsxs(Flex, { gap: 2, children: [
|
|
3788
|
-
/* @__PURE__ */ jsx(
|
|
3789
|
-
Button,
|
|
3790
|
-
{
|
|
3791
|
-
mode: "ghost",
|
|
3792
|
-
text: "Rescan",
|
|
3793
|
-
icon: SyncIcon,
|
|
3794
|
-
onClick: handleRescan,
|
|
3795
|
-
disabled: isLoading
|
|
3796
|
-
}
|
|
3797
|
-
),
|
|
3784
|
+
/* @__PURE__ */ jsx(Button, { mode: "ghost", text: "Rescan", icon: SyncIcon, onClick: handleRescan, disabled: isLoading }),
|
|
3798
3785
|
/* @__PURE__ */ jsx(
|
|
3799
3786
|
Button,
|
|
3800
3787
|
{
|