@sanity/assist 6.1.17 → 6.1.18
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.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -21
- package/dist/index.js.map +1 -1
- package/package.json +14 -14
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import "@sanity/ui/styles.css";
|
|
1
2
|
import { CurrentUser, DocumentFieldActionDivider, DocumentFieldActionGroup, DocumentFieldActionItem, ObjectSchemaType, Path, SanityClient, SanityDocumentLike, SchemaType } from "sanity";
|
|
2
3
|
import { SanityClient as SanityClient$1 } from "@sanity/client";
|
|
3
4
|
import { AgentActionPath } from "@sanity/client/stega";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/assistTypes.ts","../src/fieldActions/customFieldActions.tsx","../src/translate/types.ts","../src/types.ts","../src/plugin.tsx","../src/schemas/serialize/SchemTypeTool.tsx","../src/schemas/typeDefExtensions.ts","../src/translate/paths.ts","../src/fieldActions/useUserInput.ts","../src/helpers/typeUtils.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/assistTypes.ts","../src/fieldActions/customFieldActions.tsx","../src/translate/types.ts","../src/types.ts","../src/plugin.tsx","../src/schemas/serialize/SchemTypeTool.tsx","../src/schemas/typeDefExtensions.ts","../src/translate/paths.ts","../src/fieldActions/useUserInput.ts","../src/helpers/typeUtils.ts"],"mappings":";;;;;UAEiB;;;;;;;;;;;;;;;;;;EAkBf,kBAAkB,SAAS,0BAA0B;;;;;;;;;;;;;;;;EAiBrD;;;;;;;;;;;;;EAcA;;UAGe;EACf,MAAM;EACN,iBAAiB;;UAGF;;;;;;;;;;EAUf;;;;;;;;;;;EAYA;;UCvDe;EACf,MAAM;EACN;EACA;;UAGe;;;;;EAKf;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AAW,iBAAiB;KACnE,kBAAkB,KAC5B,yBAAyB;EAEtB;;UA0DY;EACf,cAAc;EACd;EAEA;;UAGe;EACf,cAAc;EACd;EAEA;EAEA;;UCpMe;EACf,YAAY;;;;EAKZ,SAAS;EAET;IACE;;;;IAIA,mBAAmB,OAAO,4BAA4B;;;;;EAMxD,qBAAqB,eAAe,mBAAiB;;;;EAKrD,YAAY,eAAe;;cAGhB,yBAAM,cAAA;iBCvCH,kCAAc,IAAA;UCXb;EACf;;IAEE;;;;;IAMA;;;;YAKQ,qBAAqB;YACrB,qBAAqB;YACrB,uBAAuB;YACvB,qCAAqC;YACrC,oBAAoB;YACpB,wBAAwB;YACxB,wBAAwB;YACxB,oBAAoB;YACpB,wBAAwB;YACxB;IACR,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAmCT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAgCA;QAGM;;;;;;;QAOA;;;;YAIA,sBAAsB;YACtB,sBAAsB;YACtB;IACR;;MAEE;;;;;MAMA;;;YAGM,oBAAoB;YACpB,sBAAsB;YACtB,oBAAoB;YACpB,mBAAmB;YACnB,qBAAqB;;cCUpB,wBAAwB;KCrIzB,gBAAgB;;;;EAI1B;;;;EAIA,QAAQ;MACJ,QAAQ;;;;UAKG;;;;EAIf;;;;EAIA;;;;EAIA;;KAGU;;;;EAIV,OAAO;;;;EAKP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+Dc,gBAAgB;;;;;;;iBC3FhB,OAAO,YAAY,YAAY"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import "@sanity/ui/styles.css";
|
|
1
2
|
import { FormBuilder, FormCallbacksProvider, FormFieldHeaderText, FormInput, MemberFieldError, ObjectInputMember, PatchEvent, PerspectiveProvider, PresenceOverlay, StatusButton, VirtualizerScrollInstanceProvider, createPatchChannel, defineArrayMember, defineField, definePlugin, defineType, fromMutationPatches, getDraftId, getPublishedId, getVersionFromId, getVersionId, insert, isArrayOfObjectsSchemaType, isArraySchemaType, isDocumentSchemaType, isKeySegment, isObjectSchemaType, isRecord, isVersionId, pathToString, set, setIfMissing, stringToPath, typed, unset, useClient, useColorSchemeValue, useCurrentUser, useDocumentPresence, useDocumentStore, useEditState, useFormCallbacks, usePerspective, useSchema, useSyncState, useWorkspaceSchemaId } from "sanity";
|
|
2
3
|
import { c } from "react/compiler-runtime";
|
|
3
|
-
import {
|
|
4
|
+
import { Box, Button, Card, Checkbox, Container, Dialog, ErrorBoundary, Flex, Label, Radio, Spinner, Stack, Switch, Text, TextArea, ThemeProvider, focusFirstDescendant, rgba, useClickOutsideEvent, useGlobalKeyDown, useLayer, useTheme } from "@sanity/ui";
|
|
4
5
|
import { createContext, isValidElement, useCallback, useContext, useEffect, useEffectEvent, useId, useMemo, useReducer, useRef, useState } from "react";
|
|
5
6
|
import { DocumentInspectorHeader, DocumentPaneProvider, PaneRouterContext, useDocumentPane, usePaneRouter } from "sanity/structure";
|
|
6
7
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
import { useToast } from "@sanity/ui/toast";
|
|
7
9
|
import { addSeconds } from "date-fns/addSeconds";
|
|
8
10
|
import { isAfter } from "date-fns/isAfter";
|
|
9
11
|
import { minutesToMilliseconds } from "date-fns/minutesToMilliseconds";
|
|
@@ -16,6 +18,7 @@ import { OlistIcon } from "@sanity/icons/Olist";
|
|
|
16
18
|
import { StringIcon } from "@sanity/icons/String";
|
|
17
19
|
import { extractWithPath } from "@sanity/mutator";
|
|
18
20
|
import { PlayIcon } from "@sanity/icons/Play";
|
|
21
|
+
import { Tooltip } from "@sanity/ui/tooltip";
|
|
19
22
|
import { keyframes, styled } from "styled-components";
|
|
20
23
|
import { purple } from "@sanity/color";
|
|
21
24
|
import { SparklesIcon } from "@sanity/icons/Sparkles";
|
|
@@ -24,16 +27,20 @@ import { CloseIcon } from "@sanity/icons/Close";
|
|
|
24
27
|
import { RetryIcon } from "@sanity/icons/Retry";
|
|
25
28
|
import { catchError, distinctUntilChanged, filter, mergeMap, share, take, tap } from "rxjs/operators";
|
|
26
29
|
import { SearchIcon } from "@sanity/icons/Search";
|
|
30
|
+
import { Autocomplete } from "@sanity/ui/autocomplete";
|
|
31
|
+
import { Breadcrumbs } from "@sanity/ui/breadcrumbs";
|
|
27
32
|
import { CheckmarkCircleIcon } from "@sanity/icons/CheckmarkCircle";
|
|
28
33
|
import { ClockIcon } from "@sanity/icons/Clock";
|
|
29
34
|
import { CloseCircleIcon } from "@sanity/icons/CloseCircle";
|
|
30
35
|
import { ErrorOutlineIcon } from "@sanity/icons/ErrorOutline";
|
|
31
36
|
import { SyncIcon } from "@sanity/icons/Sync";
|
|
37
|
+
import { Popover } from "@sanity/ui/popover";
|
|
32
38
|
import { formatDistanceToNow } from "date-fns/formatDistanceToNow";
|
|
33
39
|
import isEqual from "react-fast-compare";
|
|
34
40
|
import get from "lodash-es/get.js";
|
|
35
41
|
import { Icon, icons } from "@sanity/icons";
|
|
36
42
|
import { ControlsIcon } from "@sanity/icons/Controls";
|
|
43
|
+
import { Menu, MenuButton, MenuItem } from "@sanity/ui/menu";
|
|
37
44
|
import { TranslateIcon } from "@sanity/icons/Translate";
|
|
38
45
|
import { LockIcon } from "@sanity/icons/Lock";
|
|
39
46
|
import { CodeIcon } from "@sanity/icons/Code";
|
|
@@ -65,7 +72,7 @@ function useRegionRects() {
|
|
|
65
72
|
if (!el) return;
|
|
66
73
|
let scrollParents = [], parent = el.parentElement;
|
|
67
74
|
for (; parent && parent !== document.body;) hasOverflowScroll(parent) && scrollParents.push(parent), parent = parent.parentElement;
|
|
68
|
-
let handleResize = function() {
|
|
75
|
+
let handleResize = function handleResize() {
|
|
69
76
|
let boundsRect = scrollParents[0]?.getBoundingClientRect() || {
|
|
70
77
|
x: 0,
|
|
71
78
|
y: 0,
|
|
@@ -83,7 +90,7 @@ function useRegionRects() {
|
|
|
83
90
|
w: domRect.width,
|
|
84
91
|
h: domRect.height
|
|
85
92
|
});
|
|
86
|
-
}, handleScroll = function() {
|
|
93
|
+
}, handleScroll = function handleScroll() {
|
|
87
94
|
let scrollX = window.scrollX, scrollY = window.scrollY;
|
|
88
95
|
for (let scrollParent_0 of scrollParents) scrollX += scrollParent_0.scrollLeft, scrollY += scrollParent_0.scrollTop;
|
|
89
96
|
let scrollParent_1 = scrollParents[0];
|
|
@@ -664,7 +671,7 @@ function useTranslate(apiClient) {
|
|
|
664
671
|
let $ = c(8), [loading, setLoading] = useState(!1), user = useCurrentUser(), types = useSerializedTypes(), toast = useToast(), t0;
|
|
665
672
|
$[0] !== apiClient || $[1] !== toast || $[2] !== types || $[3] !== user?.id ? (t0 = (t1) => {
|
|
666
673
|
let { documentId, languagePath, styleguide, translatePath, fieldLanguageMap, conditionalMembers } = t1;
|
|
667
|
-
return setLoading(!0), async function() {
|
|
674
|
+
return setLoading(!0), async function run() {
|
|
668
675
|
return apiClient.request({
|
|
669
676
|
method: "POST",
|
|
670
677
|
url: `/assist/tasks/translate/${apiClient.config().dataset}?projectId=${apiClient.config().projectId}`,
|
|
@@ -1652,7 +1659,8 @@ function extractConditionalPaths(node, maxDepth) {
|
|
|
1652
1659
|
conditionalState(member.field),
|
|
1653
1660
|
...innerFields
|
|
1654
1661
|
];
|
|
1655
|
-
}
|
|
1662
|
+
}
|
|
1663
|
+
if (schemaType.jsonType === "array") {
|
|
1656
1664
|
let array = member.field, arrayPaths = [], isObjectsArray = array.members.some((m) => m.kind === "item" && isObjectSchemaType(m.item.schemaType));
|
|
1657
1665
|
if (!array.readOnly) for (let arrayMember of array.members) {
|
|
1658
1666
|
if (arrayMember.kind === "error") continue;
|
|
@@ -1670,7 +1678,8 @@ function extractConditionalPaths(node, maxDepth) {
|
|
|
1670
1678
|
];
|
|
1671
1679
|
}
|
|
1672
1680
|
return [...acc, conditionalState(member.field)];
|
|
1673
|
-
}
|
|
1681
|
+
}
|
|
1682
|
+
if (member.kind === "fieldSet") {
|
|
1674
1683
|
let conditionalFieldset = !!node.schemaType?.fieldsets?.some((f) => !f.single && f.name === member.fieldSet.name && typeof f.hidden == "function"), innerFields = extractConditionalPaths(member.fieldSet, maxDepth).map((f) => ({
|
|
1675
1684
|
...f,
|
|
1676
1685
|
conditional: conditionalFieldset || f.conditional
|
|
@@ -1913,7 +1922,7 @@ function TimeAgo(t0) {
|
|
|
1913
1922
|
}
|
|
1914
1923
|
const rotate = keyframes`0%{transform:rotate(0);}100%{transform:rotate(360deg);}`, SyncSpinningIcon = styled(SyncIcon).withConfig({
|
|
1915
1924
|
displayName: "SyncSpinningIcon",
|
|
1916
|
-
componentId: "sc-
|
|
1925
|
+
componentId: "sc-mtdfu7-0"
|
|
1917
1926
|
})`animation:${rotate} 1s linear infinite;`, TASK_CONFIG = {
|
|
1918
1927
|
aborted: {
|
|
1919
1928
|
title: "Canceled",
|
|
@@ -1959,15 +1968,17 @@ function InstructionTaskHistoryButton(props) {
|
|
|
1959
1968
|
instructions,
|
|
1960
1969
|
cancelRun,
|
|
1961
1970
|
showTitles
|
|
1962
|
-
]), isRunning = useMemo(() => titledTasks.some((r) => !r.ended), [titledTasks]), hasErrors = useMemo(() => titledTasks.some((r_0) => r_0.reason === "error" || r_0.reason === "timeout"), [titledTasks]), [open, setOpen] = useState(!1), toggleOpen = useCallback(() => setOpen((v) => !v), []), [button, setButton] = useState(null), [popover, setPopover] = useState(null)
|
|
1963
|
-
return useClickOutside(useCallback(() => {
|
|
1971
|
+
]), isRunning = useMemo(() => titledTasks.some((r) => !r.ended), [titledTasks]), hasErrors = useMemo(() => titledTasks.some((r_0) => r_0.reason === "error" || r_0.reason === "timeout"), [titledTasks]), [open, setOpen] = useState(!1), toggleOpen = useCallback(() => setOpen((v) => !v), []), [button, setButton] = useState(null), [popover, setPopover] = useState(null), handleClickOutside = useCallback(() => {
|
|
1964
1972
|
setOpen(!1);
|
|
1965
|
-
}, [])
|
|
1973
|
+
}, []);
|
|
1974
|
+
useClickOutsideEvent(handleClickOutside, () => [button, popover]);
|
|
1975
|
+
let handleEscape = useCallback(() => {
|
|
1976
|
+
setOpen(!1), button?.focus();
|
|
1977
|
+
}, [button]);
|
|
1978
|
+
return /* @__PURE__ */ jsx(Popover, {
|
|
1966
1979
|
constrainSize: !0,
|
|
1967
1980
|
content: /* @__PURE__ */ jsx(TaskList, {
|
|
1968
|
-
onEscape:
|
|
1969
|
-
setOpen(!1), button?.focus();
|
|
1970
|
-
}, [button]),
|
|
1981
|
+
onEscape: handleEscape,
|
|
1971
1982
|
tasks: titledTasks
|
|
1972
1983
|
}),
|
|
1973
1984
|
open: open && !!titledTasks?.length,
|
|
@@ -2731,7 +2742,8 @@ function extractPaths(doc, schemaType, path, maxDepth) {
|
|
|
2731
2742
|
thisFieldWithPath,
|
|
2732
2743
|
...innerFields
|
|
2733
2744
|
];
|
|
2734
|
-
}
|
|
2745
|
+
}
|
|
2746
|
+
if (fieldSchema.jsonType === "array" && fieldSchema.of.length && fieldSchema.of.some((item) => "fields" in item) && path.length + 1 < maxDepth) {
|
|
2735
2747
|
let { value: arrayValue } = extractWithPath(pathToString(fieldPath), doc)[0] ?? {}, arrayPaths = [];
|
|
2736
2748
|
if (arrayValue?.length) for (let item of arrayValue) {
|
|
2737
2749
|
let itemPath = [...fieldPath, { _key: item._key }], itemSchema = fieldSchema.of.find((t) => t.name === item._type);
|
|
@@ -3176,7 +3188,7 @@ function useFieldRefGetters(schema) {
|
|
|
3176
3188
|
let $ = c(5), t0;
|
|
3177
3189
|
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = createFieldRefCache(), $[0] = t0) : t0 = $[0];
|
|
3178
3190
|
let getForSchemaType = t0, t1;
|
|
3179
|
-
$[1] === schema ? t1 = $[2] : (t1 = function(documentType) {
|
|
3191
|
+
$[1] === schema ? t1 = $[2] : (t1 = function getRefsForType(documentType) {
|
|
3180
3192
|
let schemaType = schema.get(documentType);
|
|
3181
3193
|
if (!schemaType) throw Error(`Schema type "${documentType}" not found`);
|
|
3182
3194
|
return getForSchemaType(schemaType);
|
|
@@ -3760,7 +3772,7 @@ function instructionItem(props) {
|
|
|
3760
3772
|
});
|
|
3761
3773
|
}
|
|
3762
3774
|
function createAssistDocumentPresence(documentId) {
|
|
3763
|
-
return function() {
|
|
3775
|
+
return function AssistDocumentPresenceWrapper() {
|
|
3764
3776
|
return documentId ? /* @__PURE__ */ jsx(AssistDocumentPresence, {}) : null;
|
|
3765
3777
|
};
|
|
3766
3778
|
}
|
|
@@ -4678,7 +4690,7 @@ const contextDocumentSchema = defineType({
|
|
|
4678
4690
|
title: "Context",
|
|
4679
4691
|
description: "The referenced context will be inserted into the instruction",
|
|
4680
4692
|
validation: (rule) => rule.required(),
|
|
4681
|
-
components: { input: function(props) {
|
|
4693
|
+
components: { input: function Fix(props) {
|
|
4682
4694
|
return /* @__PURE__ */ jsx(Box, {
|
|
4683
4695
|
style: { maxWidth: 300 },
|
|
4684
4696
|
children: props.renderDefault(props)
|
|
@@ -5009,7 +5021,7 @@ const schemaTypes = [
|
|
|
5009
5021
|
},
|
|
5010
5022
|
components: { unstable_layout: AssistDocumentLayout }
|
|
5011
5023
|
},
|
|
5012
|
-
studio: { components: { layout: function(props) {
|
|
5024
|
+
studio: { components: { layout: function Layout(props) {
|
|
5013
5025
|
return /* @__PURE__ */ jsx(AssistLayout, {
|
|
5014
5026
|
...props,
|
|
5015
5027
|
config: configWithDefaults
|
|
@@ -5051,8 +5063,8 @@ function isWelcomeEvent(event) {
|
|
|
5051
5063
|
}
|
|
5052
5064
|
/** @internal */
|
|
5053
5065
|
const listenQuery = (client, query, params = {}, options = {}) => {
|
|
5054
|
-
let fetchQuery = typeof query == "string" ? query : query.fetch, listenerQuery = typeof query == "string" ? query : query.listen, fetchOnce$ = fetch(client, fetchQuery, params, options),
|
|
5055
|
-
return merge(welcome$.pipe(take(1)), mutationAndReconnect$.pipe(filter(
|
|
5066
|
+
let fetchQuery = typeof query == "string" ? query : query.fetch, listenerQuery = typeof query == "string" ? query : query.listen, fetchOnce$ = fetch(client, fetchQuery, params, options), events$ = listen(client, listenerQuery, params, options).pipe(mergeMap((ev, i) => i === 0 && !isWelcomeEvent(ev) ? throwError(/* @__PURE__ */ Error(ev.type === "reconnect" ? "Could not establish EventSource connection" : `Received unexpected type of first event "${ev.type}"`)) : of(ev)), share()), [welcome$, mutationAndReconnect$] = partition(events$, isWelcomeEvent), isRelevantEvent = (event) => !options.transitions || event.type !== "mutation" || options.transitions.includes(event.transition);
|
|
5067
|
+
return merge(welcome$.pipe(take(1)), mutationAndReconnect$.pipe(filter(isRelevantEvent), switchMap((event) => merge(of(event), of(event).pipe(delay(options.throttleTime || 1e3)))))).pipe(exhaustMapToWithTrailing(fetchOnce$));
|
|
5056
5068
|
}, DEFAULT_PARAMS = {}, DEFAULT_OPTIONS = { apiVersion: "v2022-05-09" };
|
|
5057
5069
|
function useListeningQuery(query, t0, t1) {
|
|
5058
5070
|
let $ = c(11), params = t0 === void 0 ? DEFAULT_PARAMS : t0, options = t1 === void 0 ? DEFAULT_OPTIONS : t1, [loading, setLoading] = useState(!0), [error, setError] = useState(!1), [data, setData] = useState(null), subscription = useRef(null), t2;
|
|
@@ -5085,7 +5097,7 @@ function SchemaTypeTool() {
|
|
|
5085
5097
|
$[4] !== client || $[5] !== types ? (t3 = () => {
|
|
5086
5098
|
setSaving(!0);
|
|
5087
5099
|
let canSave = !0;
|
|
5088
|
-
return (async function() {
|
|
5100
|
+
return (async function store() {
|
|
5089
5101
|
setSyncTitle(`Syncing 0/${types.length}`);
|
|
5090
5102
|
let transaction = client.transaction();
|
|
5091
5103
|
for (let i = 0; i < types.length && canSave; i++) {
|