@braze/sanity-plugin-ai-translation 0.2.84 → 0.2.85
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 +33 -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,39 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
3409
3409
|
padding: 2
|
|
3410
3410
|
}
|
|
3411
3411
|
);
|
|
3412
|
-
},
|
|
3413
|
-
const
|
|
3412
|
+
}, DocumentValidator = ({ documentId, documentType, 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}`, doc = await client.fetch(
|
|
3419
|
+
"*[_id in [$draftId, $publishedId]] | order(_id desc) [0]",
|
|
3420
|
+
{ draftId, publishedId }
|
|
3421
|
+
);
|
|
3422
|
+
if (!doc) {
|
|
3423
|
+
devLog.warn("Document not found for validation", { documentId }), onResult(documentId, { isValidating: !1, errors: [] });
|
|
3424
|
+
return;
|
|
3425
|
+
}
|
|
3426
|
+
const errors = (await validateDocument({
|
|
3427
|
+
document: doc,
|
|
3428
|
+
workspace,
|
|
3429
|
+
environment: "studio"
|
|
3430
|
+
})).filter((m) => m.level === "error");
|
|
3431
|
+
errors.length > 0 && devLog.debug("Validation errors found", {
|
|
3432
|
+
documentId,
|
|
3433
|
+
errorCount: errors.length,
|
|
3434
|
+
component: "DocumentValidator"
|
|
3435
|
+
}), onResult(documentId, { isValidating: !1, errors });
|
|
3436
|
+
} catch (error) {
|
|
3437
|
+
devLog.error(
|
|
3438
|
+
"Failed to validate document",
|
|
3439
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
3440
|
+
{ documentId, component: "DocumentValidator" }
|
|
3441
|
+
), onResult(documentId, { isValidating: !1, errors: [] });
|
|
3442
|
+
}
|
|
3443
|
+
})());
|
|
3444
|
+
}, [documentId, documentType, onResult, client, workspace]), null;
|
|
3426
3445
|
}, PreflightView = () => {
|
|
3427
3446
|
const {
|
|
3428
3447
|
document,
|