@braze/sanity-plugin-ai-translation 0.2.84 → 0.2.86
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 +36 -14
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getPublishedId, pathToString, useClient,
|
|
1
|
+
import { getPublishedId, pathToString, useClient, useWorkspace, validateDocument, defineType, defineField, definePlugin } from "sanity";
|
|
2
2
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { WarningOutlineIcon, ErrorOutlineIcon, CheckmarkIcon, CloseIcon, SyncIcon, PanelRightIcon, SearchIcon, CircleIcon, ArrowRightIcon, ResetIcon, TranslateIcon } from "@sanity/icons";
|
|
4
4
|
import { createContext, useReducer, useRef, useEffect, useContext, useMemo, useState, useCallback } from "react";
|
|
@@ -3409,20 +3409,41 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
3409
3409
|
padding: 2
|
|
3410
3410
|
}
|
|
3411
3411
|
);
|
|
3412
|
-
},
|
|
3413
|
-
const
|
|
3412
|
+
}, DocumentValidator = ({ documentId, documentType, perspective, onResult }) => {
|
|
3413
|
+
const client = useClient({ apiVersion: "vX" }), workspace = useWorkspace(), hasRun = useRef(!1);
|
|
3414
3414
|
return useEffect(() => {
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3415
|
+
hasRun.current || (hasRun.current = !0, (async () => {
|
|
3416
|
+
onResult(documentId, { isValidating: !0, errors: [] });
|
|
3417
|
+
try {
|
|
3418
|
+
const publishedId = getPublishedId(documentId), draftId = `drafts.${publishedId}`;
|
|
3419
|
+
let doc;
|
|
3420
|
+
if (perspective === "published" ? doc = await client.fetch("*[_id == $publishedId][0]", { publishedId }) : doc = await client.fetch(
|
|
3421
|
+
"*[_id in [$draftId, $publishedId]] | order(_id desc) [0]",
|
|
3422
|
+
{ draftId, publishedId }
|
|
3423
|
+
), !doc) {
|
|
3424
|
+
devLog.warn("Document not found for validation", { documentId, perspective }), onResult(documentId, { isValidating: !1, errors: [] });
|
|
3425
|
+
return;
|
|
3426
|
+
}
|
|
3427
|
+
const errors = (await validateDocument({
|
|
3428
|
+
document: doc,
|
|
3429
|
+
workspace,
|
|
3430
|
+
environment: "studio"
|
|
3431
|
+
})).filter((m) => m.level === "error");
|
|
3432
|
+
errors.length > 0 && devLog.debug("Validation errors found", {
|
|
3433
|
+
documentId,
|
|
3434
|
+
perspective,
|
|
3435
|
+
errorCount: errors.length,
|
|
3436
|
+
component: "DocumentValidator"
|
|
3437
|
+
}), onResult(documentId, { isValidating: !1, errors });
|
|
3438
|
+
} catch (error) {
|
|
3439
|
+
devLog.error(
|
|
3440
|
+
"Failed to validate document",
|
|
3441
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
3442
|
+
{ documentId, component: "DocumentValidator" }
|
|
3443
|
+
), onResult(documentId, { isValidating: !1, errors: [] });
|
|
3444
|
+
}
|
|
3445
|
+
})());
|
|
3446
|
+
}, [documentId, documentType, perspective, onResult, client, workspace]), null;
|
|
3426
3447
|
}, PreflightView = () => {
|
|
3427
3448
|
const {
|
|
3428
3449
|
document,
|
|
@@ -3657,6 +3678,7 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
3657
3678
|
{
|
|
3658
3679
|
documentId: doc._id,
|
|
3659
3680
|
documentType: doc._type,
|
|
3681
|
+
perspective: documentSource === "published" ? "published" : "drafts",
|
|
3660
3682
|
onResult: handleValidationResult
|
|
3661
3683
|
},
|
|
3662
3684
|
`${doc._id}-${scanKey}`
|