@braze/sanity-plugin-ai-translation 0.2.86 → 0.2.87
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 +13 -92
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getPublishedId, pathToString, useClient, useWorkspace, validateDocument, defineType, defineField, definePlugin } from "sanity";
|
|
2
2
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
3
|
-
import { WarningOutlineIcon, ErrorOutlineIcon, CheckmarkIcon,
|
|
3
|
+
import { WarningOutlineIcon, ErrorOutlineIcon, CheckmarkIcon, SyncIcon, PanelRightIcon, SearchIcon, CircleIcon, ArrowRightIcon, ResetIcon, TranslateIcon } from "@sanity/icons";
|
|
4
4
|
import { createContext, useReducer, useRef, useEffect, useContext, useMemo, useState, useCallback } from "react";
|
|
5
5
|
import defaults from "lodash.defaults";
|
|
6
6
|
import { Card, Stack, Flex, Text, Box, Heading, Button, Spinner, Badge, Inline, Radio, Checkbox, Grid, TextInput, Select, Label, Code, Tooltip } from "@sanity/ui";
|
|
@@ -3457,7 +3457,7 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
3457
3457
|
translationMode,
|
|
3458
3458
|
releaseConfig,
|
|
3459
3459
|
documentSource
|
|
3460
|
-
} = 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"), [
|
|
3460
|
+
} = 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"), [conflictContext, setConflictContext] = useState(null), [isCheckingConflicts, setIsCheckingConflicts] = useState(!0), filteredReferences = useMemo(
|
|
3461
3461
|
() => references.filter((ref) => selectedReferenceIds.has(ref._id)),
|
|
3462
3462
|
[references, selectedReferenceIds]
|
|
3463
3463
|
), documentsToValidate = useMemo(() => {
|
|
@@ -3559,58 +3559,7 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
3559
3559
|
useEffect(() => {
|
|
3560
3560
|
runSourceDraftCheck(), runDraftCheck(), runConflictCheck();
|
|
3561
3561
|
}, [scanKey]);
|
|
3562
|
-
const
|
|
3563
|
-
setIsDraftActionInProgress(!0);
|
|
3564
|
-
try {
|
|
3565
|
-
const draftIds = staleDrafts.map((d) => d.draftId);
|
|
3566
|
-
devLog.info("Discarding stale drafts", { draftIds, component: "PreflightView" });
|
|
3567
|
-
const transaction = client.transaction();
|
|
3568
|
-
for (const id of draftIds)
|
|
3569
|
-
transaction.delete(id);
|
|
3570
|
-
await transaction.commit(), devLog.info("Successfully discarded stale drafts", {
|
|
3571
|
-
count: draftIds.length,
|
|
3572
|
-
component: "PreflightView"
|
|
3573
|
-
}), await runDraftCheck();
|
|
3574
|
-
} catch (error) {
|
|
3575
|
-
devLog.error("Failed to discard drafts", error instanceof Error ? error : new Error(String(error)), {
|
|
3576
|
-
component: "PreflightView"
|
|
3577
|
-
});
|
|
3578
|
-
} finally {
|
|
3579
|
-
setIsDraftActionInProgress(!1);
|
|
3580
|
-
}
|
|
3581
|
-
}, [staleDrafts, client, runDraftCheck]), handlePublishDrafts = useCallback(async () => {
|
|
3582
|
-
setIsDraftActionInProgress(!0);
|
|
3583
|
-
try {
|
|
3584
|
-
devLog.info("Publishing stale drafts", {
|
|
3585
|
-
count: staleDrafts.length,
|
|
3586
|
-
component: "PreflightView"
|
|
3587
|
-
});
|
|
3588
|
-
for (const draft of staleDrafts)
|
|
3589
|
-
await client.request({
|
|
3590
|
-
method: "POST",
|
|
3591
|
-
uri: "/data/actions/mutate",
|
|
3592
|
-
body: {
|
|
3593
|
-
actions: [
|
|
3594
|
-
{
|
|
3595
|
-
actionType: "sanity.action.document.publish",
|
|
3596
|
-
draftId: draft.draftId,
|
|
3597
|
-
publishedId: draft.targetId
|
|
3598
|
-
}
|
|
3599
|
-
]
|
|
3600
|
-
}
|
|
3601
|
-
});
|
|
3602
|
-
devLog.info("Successfully published stale drafts", {
|
|
3603
|
-
count: staleDrafts.length,
|
|
3604
|
-
component: "PreflightView"
|
|
3605
|
-
}), await runDraftCheck();
|
|
3606
|
-
} catch (error) {
|
|
3607
|
-
devLog.error("Failed to publish drafts", error instanceof Error ? error : new Error(String(error)), {
|
|
3608
|
-
component: "PreflightView"
|
|
3609
|
-
});
|
|
3610
|
-
} finally {
|
|
3611
|
-
setIsDraftActionInProgress(!1);
|
|
3612
|
-
}
|
|
3613
|
-
}, [staleDrafts, client, runDraftCheck]), startTranslation = useCallback(
|
|
3562
|
+
const startTranslation = useCallback(
|
|
3614
3563
|
(replaceExisting, overrideReleaseId, skipConflicts) => {
|
|
3615
3564
|
translateDocumentSet({
|
|
3616
3565
|
sourceDocument: document,
|
|
@@ -3750,10 +3699,10 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
3750
3699
|
(isDraftCheckLoading || hasStaleDrafts) && /* @__PURE__ */ jsx(Card, { padding: 4, border: !0, radius: 2, tone: hasStaleDrafts && !draftsDismissed ? "caution" : void 0, children: /* @__PURE__ */ jsxs(Stack, { space: 3, children: [
|
|
3751
3700
|
/* @__PURE__ */ jsxs(Flex, { align: "center", gap: 2, children: [
|
|
3752
3701
|
isDraftCheckLoading ? /* @__PURE__ */ jsx(Spinner, { muted: !0 }) : draftsDismissed ? /* @__PURE__ */ jsx(Text, { size: 2, children: /* @__PURE__ */ jsx(CheckmarkIcon, {}) }) : /* @__PURE__ */ jsx(Text, { size: 2, children: /* @__PURE__ */ jsx(WarningOutlineIcon, {}) }),
|
|
3753
|
-
/* @__PURE__ */ jsx(Text, { weight: "semibold", children: isDraftCheckLoading ? "Checking for stale drafts on target documents\u2026" : draftsDismissed ? "Stale drafts acknowledged" : `${staleDrafts.length}
|
|
3702
|
+
/* @__PURE__ */ jsx(Text, { weight: "semibold", children: isDraftCheckLoading ? "Checking for stale drafts on target documents\u2026" : draftsDismissed ? "Stale drafts acknowledged" : `${staleDrafts.length} draft${staleDrafts.length !== 1 ? "s" : ""} found on existing translated document${staleDrafts.length !== 1 ? "s" : ""}` })
|
|
3754
3703
|
] }),
|
|
3755
3704
|
hasStaleDrafts && !draftsDismissed && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3756
|
-
/* @__PURE__ */ jsx(Text, { size: 1, children: "These
|
|
3705
|
+
/* @__PURE__ */ jsx(Text, { size: 1, children: "These existing translations have unpublished changes that will be out-of-date after this translation is completed. Use the links below to either publish each draft or discard the changes." }),
|
|
3757
3706
|
/* @__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: staleDrafts.map((draft) => /* @__PURE__ */ jsxs(Flex, { align: "center", justify: "space-between", gap: 2, children: [
|
|
3758
3707
|
/* @__PURE__ */ jsxs(Flex, { align: "center", gap: 2, flex: 1, style: { minWidth: 0 }, children: [
|
|
3759
3708
|
/* @__PURE__ */ jsx(Text, { size: 1, children: draft.title || draft.targetId }),
|
|
@@ -3762,42 +3711,14 @@ ${protectedPhrases.join(", ")}`, buildStyleGuideSection = (globalPrompt, localeP
|
|
|
3762
3711
|
] }),
|
|
3763
3712
|
/* @__PURE__ */ jsx(DocumentOpenerButton, { documentId: draft.targetId, documentType: draft._type })
|
|
3764
3713
|
] }, draft.draftId)) }) }) }),
|
|
3765
|
-
/* @__PURE__ */
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
onClick: handleDiscardDrafts,
|
|
3774
|
-
disabled: isDraftActionInProgress
|
|
3775
|
-
}
|
|
3776
|
-
),
|
|
3777
|
-
/* @__PURE__ */ jsx(
|
|
3778
|
-
Button,
|
|
3779
|
-
{
|
|
3780
|
-
mode: "ghost",
|
|
3781
|
-
tone: "caution",
|
|
3782
|
-
text: "Publish All Drafts",
|
|
3783
|
-
onClick: handlePublishDrafts,
|
|
3784
|
-
disabled: isDraftActionInProgress
|
|
3785
|
-
}
|
|
3786
|
-
),
|
|
3787
|
-
/* @__PURE__ */ jsx(
|
|
3788
|
-
Button,
|
|
3789
|
-
{
|
|
3790
|
-
mode: "ghost",
|
|
3791
|
-
text: "Continue Anyway",
|
|
3792
|
-
onClick: () => setDraftAction("continue"),
|
|
3793
|
-
disabled: isDraftActionInProgress
|
|
3794
|
-
}
|
|
3795
|
-
)
|
|
3796
|
-
] }),
|
|
3797
|
-
isDraftActionInProgress && /* @__PURE__ */ jsxs(Flex, { align: "center", gap: 2, children: [
|
|
3798
|
-
/* @__PURE__ */ jsx(Spinner, { muted: !0 }),
|
|
3799
|
-
/* @__PURE__ */ jsx(Text, { size: 1, muted: !0, children: "Processing\u2026" })
|
|
3800
|
-
] })
|
|
3714
|
+
/* @__PURE__ */ jsx(
|
|
3715
|
+
Button,
|
|
3716
|
+
{
|
|
3717
|
+
mode: "ghost",
|
|
3718
|
+
text: "Continue Anyway",
|
|
3719
|
+
onClick: () => setDraftAction("continue")
|
|
3720
|
+
}
|
|
3721
|
+
)
|
|
3801
3722
|
] })
|
|
3802
3723
|
] }) }),
|
|
3803
3724
|
/* @__PURE__ */ jsxs(Flex, { justify: "space-between", gap: 2, children: [
|