@sanity/assist 5.0.2 → 5.0.4
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/LICENSE +1 -1
- package/dist/index.cjs +15 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +11 -34
- package/dist/index.js.map +1 -1
- package/package.json +15 -11
- package/src/_lib/usePrevious.ts +1 -1
- package/src/assistDocument/components/AssistDocumentForm.tsx +3 -2
- package/src/assistDocument/hooks/useAssistDocumentContextValue.tsx +2 -4
- package/src/assistInspector/AssistInspector.tsx +11 -15
- package/src/assistInspector/helpers.ts +2 -2
- package/src/components/ImageContext.tsx +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -3,7 +3,7 @@ import {CurrentUser} from 'sanity'
|
|
|
3
3
|
import {DocumentFieldActionDivider} from 'sanity'
|
|
4
4
|
import {DocumentFieldActionGroup} from 'sanity'
|
|
5
5
|
import {DocumentFieldActionItem} from 'sanity'
|
|
6
|
-
import {JSX
|
|
6
|
+
import {JSX} from 'react/jsx-runtime'
|
|
7
7
|
import {ObjectSchemaType} from 'sanity'
|
|
8
8
|
import {Path} from 'sanity'
|
|
9
9
|
import {Plugin as Plugin_2} from 'sanity'
|
|
@@ -558,7 +558,7 @@ declare type PromptTextBlock = Omit<
|
|
|
558
558
|
_type: 'block'
|
|
559
559
|
}
|
|
560
560
|
|
|
561
|
-
export declare function SchemaTypeTool():
|
|
561
|
+
export declare function SchemaTypeTool(): JSX.Element
|
|
562
562
|
|
|
563
563
|
export declare type TranslateStyleguide =
|
|
564
564
|
| string
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {CurrentUser} from 'sanity'
|
|
|
3
3
|
import {DocumentFieldActionDivider} from 'sanity'
|
|
4
4
|
import {DocumentFieldActionGroup} from 'sanity'
|
|
5
5
|
import {DocumentFieldActionItem} from 'sanity'
|
|
6
|
-
import {JSX
|
|
6
|
+
import {JSX} from 'react/jsx-runtime'
|
|
7
7
|
import {ObjectSchemaType} from 'sanity'
|
|
8
8
|
import {Path} from 'sanity'
|
|
9
9
|
import {Plugin as Plugin_2} from 'sanity'
|
|
@@ -558,7 +558,7 @@ declare type PromptTextBlock = Omit<
|
|
|
558
558
|
_type: 'block'
|
|
559
559
|
}
|
|
560
560
|
|
|
561
|
-
export declare function SchemaTypeTool():
|
|
561
|
+
export declare function SchemaTypeTool(): JSX.Element
|
|
562
562
|
|
|
563
563
|
export declare type TranslateStyleguide =
|
|
564
564
|
| string
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { pathToString, getVersionFromId, getPublishedId, isVersionId, useEditState, useCurrentUser, useClient, typed, FormFieldHeaderText, PatchEvent, unset, isObjectSchemaType, stringToPath, isKeySegment, useSchema, getVersionId, getDraftId, useColorSchemeValue, isArraySchemaType, useFormCallbacks, useDocumentStore, useDocumentPresence, createPatchChannel, FormBuilder, fromMutationPatches, StatusButton, PresenceOverlay, VirtualizerScrollInstanceProvider, isDocumentSchemaType, useSyncState, set, useWorkspaceSchemaId, MemberFieldError, FormCallbacksProvider, FormInput, setIfMissing, insert, ObjectInputMember, isArrayOfObjectsSchemaType, defineType, defineField, defineArrayMember, definePlugin } from "sanity";
|
|
2
|
+
import { pathToString, getVersionFromId, getPublishedId, isVersionId, useEditState, useCurrentUser, useClient, typed, FormFieldHeaderText, PatchEvent, unset, isObjectSchemaType, stringToPath, isKeySegment, useSchema, usePerspective, getVersionId, getDraftId, useColorSchemeValue, isArraySchemaType, useFormCallbacks, useDocumentStore, useDocumentPresence, createPatchChannel, FormBuilder, fromMutationPatches, StatusButton, PresenceOverlay, VirtualizerScrollInstanceProvider, PerspectiveProvider, isDocumentSchemaType, useSyncState, set, useWorkspaceSchemaId, MemberFieldError, FormCallbacksProvider, FormInput, setIfMissing, insert, ObjectInputMember, isArrayOfObjectsSchemaType, defineType, defineField, defineArrayMember, definePlugin } from "sanity";
|
|
3
3
|
import { useToast, useLayer, Dialog, Stack, Flex, Tooltip, Text, TextArea, Button, Card, Box, ErrorBoundary, focusFirstDescendant, Spinner, Container, Autocomplete, Breadcrumbs, useClickOutside, Popover, useGlobalKeyDown, useTheme, rgba, Radio, Checkbox, ThemeProvider, MenuButton, Menu, MenuItem, Switch, Label } from "@sanity/ui";
|
|
4
4
|
import { useRef, useState, useEffect, useMemo, createContext, useContext, useCallback, useId, forwardRef, createElement, useReducer } from "react";
|
|
5
5
|
import { useDocumentPane, usePaneRouter, DocumentInspectorHeader, DocumentPaneProvider } from "sanity/structure";
|
|
@@ -7,8 +7,10 @@ import { minutesToMilliseconds, isAfter, addSeconds, formatDistanceToNow } from
|
|
|
7
7
|
import { PlayIcon, DocumentIcon, LinkIcon, ImageIcon, BlockContentIcon, OlistIcon, BlockquoteIcon, StringIcon, SparklesIcon, SearchIcon, SyncIcon, ErrorOutlineIcon, CheckmarkCircleIcon, ClockIcon, CloseCircleIcon, RetryIcon, ArrowRightIcon, CloseIcon, icons, TranslateIcon, LockIcon, ControlsIcon, ArrowLeftIcon, TokenIcon, DocumentTextIcon, ThListIcon, CodeIcon, ComposeIcon } from "@sanity/icons";
|
|
8
8
|
import { extractWithPath } from "@sanity/mutator";
|
|
9
9
|
import { keyframes, styled } from "styled-components";
|
|
10
|
+
import { purple } from "@sanity/color";
|
|
10
11
|
import { tap, mergeMap, share, take, filter, distinctUntilChanged, catchError } from "rxjs/operators";
|
|
11
12
|
import { get } from "lodash-es";
|
|
13
|
+
import getRandomValues from "get-random-values-esm";
|
|
12
14
|
import isEqual from "react-fast-compare";
|
|
13
15
|
import { defer, throwError, of, partition, merge, switchMap, delay } from "rxjs";
|
|
14
16
|
import { exhaustMapToWithTrailing } from "rxjs-exhaustmap-with-trailing";
|
|
@@ -883,11 +885,8 @@ function useAssistDocumentContextValue(documentId, documentType) {
|
|
|
883
885
|
closeInspector,
|
|
884
886
|
inspector,
|
|
885
887
|
onChange: documentOnChange,
|
|
886
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
887
|
-
// @ts-ignore this is a valid option available in `corel` - Remove after corel is merged to next
|
|
888
|
-
selectedReleaseId,
|
|
889
888
|
editState
|
|
890
|
-
} = useDocumentPane(), { draft, published, version } = editState || {}, assistableDocumentId = selectedReleaseId ? getVersionId(documentId, selectedReleaseId) : documentSchemaType.liveEdit ? documentId : getDraftId(documentId), documentIsNew = selectedReleaseId ? !version?._id : !draft?._id && !published?._id, documentIsAssistable = selectedReleaseId ? !!version : isDocAssistable(documentSchemaType, published, draft), { params } = useAiPaneRouter(), selectedPath = params[fieldPathParam], assistDocument = useStudioAssistDocument({
|
|
889
|
+
} = useDocumentPane(), { selectedReleaseId } = usePerspective(), { draft, published, version } = editState || {}, assistableDocumentId = selectedReleaseId ? getVersionId(documentId, selectedReleaseId) : documentSchemaType.liveEdit ? documentId : getDraftId(documentId), documentIsNew = selectedReleaseId ? !version?._id : !draft?._id && !published?._id, documentIsAssistable = selectedReleaseId ? !!version : isDocAssistable(documentSchemaType, published, draft), { params } = useAiPaneRouter(), selectedPath = params[fieldPathParam], assistDocument = useStudioAssistDocument({
|
|
891
890
|
documentId: assistableDocumentId,
|
|
892
891
|
schemaType: documentSchemaType
|
|
893
892
|
}), { syntheticTasks, addSyntheticTask, removeSyntheticTask } = useSyntheticTasks(assistableDocumentId);
|
|
@@ -974,17 +973,7 @@ const fadeIn = keyframes`
|
|
|
974
973
|
durationMs = 250
|
|
975
974
|
}, ref) {
|
|
976
975
|
return /* @__PURE__ */ jsx(FadeInDiv, { ref, style: { animationDuration: `${durationMs}ms` }, children });
|
|
977
|
-
}),
|
|
978
|
-
400: {
|
|
979
|
-
hex: "#b087f7"
|
|
980
|
-
},
|
|
981
|
-
500: {
|
|
982
|
-
hex: "#8f57ef"
|
|
983
|
-
},
|
|
984
|
-
600: {
|
|
985
|
-
hex: "#721fe5"
|
|
986
|
-
}
|
|
987
|
-
}, Root = styled.span`
|
|
976
|
+
}), Root = styled.span`
|
|
988
977
|
display: block;
|
|
989
978
|
width: 25px;
|
|
990
979
|
height: 25px;
|
|
@@ -1788,21 +1777,16 @@ function AssistInspector(props) {
|
|
|
1788
1777
|
{
|
|
1789
1778
|
scrollElement: boundary.current,
|
|
1790
1779
|
containerElement: boundary,
|
|
1791
|
-
children: /* @__PURE__ */ jsx(
|
|
1780
|
+
children: /* @__PURE__ */ jsx(PerspectiveProvider, { selectedPerspectiveName: void 0, children: /* @__PURE__ */ jsx(
|
|
1792
1781
|
DocumentPaneProvider,
|
|
1793
1782
|
{
|
|
1794
1783
|
paneKey: documentPane.paneKey,
|
|
1795
1784
|
index: documentPane.index,
|
|
1796
1785
|
itemId: "ai",
|
|
1797
1786
|
pane: paneNode,
|
|
1798
|
-
forcedVersion: {
|
|
1799
|
-
isReleaseLocked: !1,
|
|
1800
|
-
selectedPerspectiveName: "published",
|
|
1801
|
-
selectedReleaseId: void 0
|
|
1802
|
-
},
|
|
1803
1787
|
children: /* @__PURE__ */ jsx(DocumentForm, {})
|
|
1804
1788
|
}
|
|
1805
|
-
)
|
|
1789
|
+
) })
|
|
1806
1790
|
}
|
|
1807
1791
|
) }) }) }) }),
|
|
1808
1792
|
/* @__PURE__ */ jsx(Box, { flex: "none", padding: 4, children: /* @__PURE__ */ jsxs(Text, { muted: !0, size: 1, children: [
|
|
@@ -2593,7 +2577,7 @@ function AssistLayout(props) {
|
|
|
2593
2577
|
}
|
|
2594
2578
|
const ImageContext = createContext({});
|
|
2595
2579
|
function ImageContextProvider(props) {
|
|
2596
|
-
const { schemaType, path, value, readOnly } = props, assetRef = value?.asset?._ref, { selectedReleaseId } =
|
|
2580
|
+
const { schemaType, path, value, readOnly } = props, assetRef = value?.asset?._ref, { selectedReleaseId } = usePerspective(), [assetRefState, setAssetRefState] = useState(assetRef), { assistableDocumentId, documentSchemaType } = useAssistDocumentContext(), { config, status } = useAiAssistanceConfig(), apiClient = useApiClient(config?.__customApiClient), { generateCaption } = useGenerateCaption(apiClient), { isSyncing } = useSyncState(
|
|
2597
2581
|
getPublishedId(assistableDocumentId),
|
|
2598
2582
|
documentSchemaType.name,
|
|
2599
2583
|
selectedReleaseId
|
|
@@ -2825,12 +2809,6 @@ function PrivateIcon() {
|
|
|
2825
2809
|
}
|
|
2826
2810
|
);
|
|
2827
2811
|
}
|
|
2828
|
-
function getRandomValues(typedArray) {
|
|
2829
|
-
const crypto = typeof window < "u" && "crypto" in window ? window.crypto : globalThis.crypto;
|
|
2830
|
-
if (!crypto || !crypto.getRandomValues)
|
|
2831
|
-
throw new Error("WebCrypto not available in this environment");
|
|
2832
|
-
return crypto.getRandomValues(typedArray);
|
|
2833
|
-
}
|
|
2834
2812
|
function whatwgRNG(length = 16) {
|
|
2835
2813
|
const rnds8 = new Uint8Array(length);
|
|
2836
2814
|
return getRandomValues(rnds8), rnds8;
|
|
@@ -2905,7 +2883,6 @@ function createSafeNode(args) {
|
|
|
2905
2883
|
expanded: !0,
|
|
2906
2884
|
children
|
|
2907
2885
|
} : void 0;
|
|
2908
|
-
case "divider":
|
|
2909
2886
|
default:
|
|
2910
2887
|
return node;
|
|
2911
2888
|
}
|
|
@@ -3199,18 +3176,18 @@ function AssistDocumentFormEditable(props) {
|
|
|
3199
3176
|
() => ({
|
|
3200
3177
|
...formCallbacks,
|
|
3201
3178
|
onPathOpen: (path) => {
|
|
3202
|
-
!instruction2 && path.length === 4 && path[2] === "instructions" ?
|
|
3179
|
+
!instruction2 && path.length === 4 && path[2] === "instructions" ? setParams(
|
|
3203
3180
|
typed({
|
|
3204
3181
|
...params,
|
|
3205
3182
|
[instructionParam]: path[3]?._key
|
|
3206
3183
|
})
|
|
3207
|
-
)
|
|
3184
|
+
) : setTimeout(() => onPathOpen(path), 0);
|
|
3208
3185
|
}
|
|
3209
3186
|
}),
|
|
3210
3187
|
[formCallbacks, onPathOpen, params, setParams, instruction2]
|
|
3211
3188
|
);
|
|
3212
3189
|
useEffect(() => {
|
|
3213
|
-
activePath && !instruction2 && onPathOpen(
|
|
3190
|
+
activePath && !instruction2 && onPathOpen(activePath);
|
|
3214
3191
|
}, [activePath, instruction2, onPathOpen]);
|
|
3215
3192
|
const fieldError = useMemo(() => {
|
|
3216
3193
|
const fieldError2 = props.members.find(
|