@sanity/assist 5.0.3 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 Sanity
3
+ Copyright (c) 2026 Sanity
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dist/index.cjs CHANGED
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: !0 });
3
- var jsxRuntime = require("react/jsx-runtime"), sanity = require("sanity"), ui = require("@sanity/ui"), react = require("react"), structure = require("sanity/structure"), dateFns = require("date-fns"), icons = require("@sanity/icons"), mutator = require("@sanity/mutator"), styledComponents = require("styled-components"), operators = require("rxjs/operators"), get = require("lodash/get.js"), isEqual = require("react-fast-compare"), rxjs = require("rxjs"), rxjsExhaustmapWithTrailing = require("rxjs-exhaustmap-with-trailing");
3
+ var jsxRuntime = require("react/jsx-runtime"), sanity = require("sanity"), ui = require("@sanity/ui"), react = require("react"), structure = require("sanity/structure"), dateFns = require("date-fns"), icons = require("@sanity/icons"), mutator = require("@sanity/mutator"), styledComponents = require("styled-components"), color = require("@sanity/color"), operators = require("rxjs/operators"), get = require("lodash/get.js"), getRandomValues = require("get-random-values-esm"), isEqual = require("react-fast-compare"), rxjs = require("rxjs"), rxjsExhaustmapWithTrailing = require("rxjs-exhaustmap-with-trailing");
4
4
  function _interopDefaultCompat(e) {
5
5
  return e && typeof e == "object" && "default" in e ? e : { default: e };
6
6
  }
7
- var get__default = /* @__PURE__ */ _interopDefaultCompat(get), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual);
7
+ var get__default = /* @__PURE__ */ _interopDefaultCompat(get), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual);
8
8
  function hasOverflowScroll(el) {
9
9
  const overflow = getComputedStyle(el).overflow;
10
10
  return overflow.includes("auto") || overflow.includes("hidden") || overflow.includes("scroll");
@@ -876,11 +876,8 @@ function useAssistDocumentContextValue(documentId, documentType) {
876
876
  closeInspector,
877
877
  inspector,
878
878
  onChange: documentOnChange,
879
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
880
- // @ts-ignore this is a valid option available in `corel` - Remove after corel is merged to next
881
- selectedReleaseId,
882
879
  editState
883
- } = structure.useDocumentPane(), { draft, published, version } = editState || {}, assistableDocumentId = selectedReleaseId ? sanity.getVersionId(documentId, selectedReleaseId) : documentSchemaType.liveEdit ? documentId : sanity.getDraftId(documentId), documentIsNew = selectedReleaseId ? !version?._id : !draft?._id && !published?._id, documentIsAssistable = selectedReleaseId ? !!version : isDocAssistable(documentSchemaType, published, draft), { params } = useAiPaneRouter(), selectedPath = params[fieldPathParam], assistDocument = useStudioAssistDocument({
880
+ } = structure.useDocumentPane(), { selectedReleaseId } = sanity.usePerspective(), { draft, published, version } = editState || {}, assistableDocumentId = selectedReleaseId ? sanity.getVersionId(documentId, selectedReleaseId) : documentSchemaType.liveEdit ? documentId : sanity.getDraftId(documentId), documentIsNew = selectedReleaseId ? !version?._id : !draft?._id && !published?._id, documentIsAssistable = selectedReleaseId ? !!version : isDocAssistable(documentSchemaType, published, draft), { params } = useAiPaneRouter(), selectedPath = params[fieldPathParam], assistDocument = useStudioAssistDocument({
884
881
  documentId: assistableDocumentId,
885
882
  schemaType: documentSchemaType
886
883
  }), { syntheticTasks, addSyntheticTask, removeSyntheticTask } = useSyntheticTasks(assistableDocumentId);
@@ -967,17 +964,7 @@ const fadeIn = styledComponents.keyframes`
967
964
  durationMs = 250
968
965
  }, ref) {
969
966
  return /* @__PURE__ */ jsxRuntime.jsx(FadeInDiv, { ref, style: { animationDuration: `${durationMs}ms` }, children });
970
- }), purple = {
971
- 400: {
972
- hex: "#b087f7"
973
- },
974
- 500: {
975
- hex: "#8f57ef"
976
- },
977
- 600: {
978
- hex: "#721fe5"
979
- }
980
- }, Root = styledComponents.styled.span`
967
+ }), Root = styledComponents.styled.span`
981
968
  display: block;
982
969
  width: 25px;
983
970
  height: 25px;
@@ -1024,11 +1011,11 @@ const fadeIn = styledComponents.keyframes`
1024
1011
  `;
1025
1012
  function AssistAvatar(props) {
1026
1013
  const { state = "present" } = props, scheme = sanity.useColorSchemeValue(), style = react.useMemo(() => scheme === "dark" ? {
1027
- "--ai-avatar-stroke-color": purple[400].hex,
1028
- "--ai-avatar-disc-color": purple[600].hex
1014
+ "--ai-avatar-stroke-color": color.purple[400].hex,
1015
+ "--ai-avatar-disc-color": color.purple[600].hex
1029
1016
  } : {
1030
- "--ai-avatar-stroke-color": purple[500].hex,
1031
- "--ai-avatar-disc-color": purple[600].hex
1017
+ "--ai-avatar-stroke-color": color.purple[500].hex,
1018
+ "--ai-avatar-disc-color": color.purple[600].hex
1032
1019
  }, [scheme]);
1033
1020
  return /* @__PURE__ */ jsxRuntime.jsxs(Root, { "data-state": state, style, children: [
1034
1021
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -1781,21 +1768,16 @@ function AssistInspector(props) {
1781
1768
  {
1782
1769
  scrollElement: boundary.current,
1783
1770
  containerElement: boundary,
1784
- children: /* @__PURE__ */ jsxRuntime.jsx(
1771
+ children: /* @__PURE__ */ jsxRuntime.jsx(sanity.PerspectiveProvider, { selectedPerspectiveName: void 0, children: /* @__PURE__ */ jsxRuntime.jsx(
1785
1772
  structure.DocumentPaneProvider,
1786
1773
  {
1787
1774
  paneKey: documentPane.paneKey,
1788
1775
  index: documentPane.index,
1789
1776
  itemId: "ai",
1790
1777
  pane: paneNode,
1791
- forcedVersion: {
1792
- isReleaseLocked: !1,
1793
- selectedPerspectiveName: "published",
1794
- selectedReleaseId: void 0
1795
- },
1796
1778
  children: /* @__PURE__ */ jsxRuntime.jsx(DocumentForm, {})
1797
1779
  }
1798
- )
1780
+ ) })
1799
1781
  }
1800
1782
  ) }) }) }) }),
1801
1783
  /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: "none", padding: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { muted: !0, size: 1, children: [
@@ -2586,7 +2568,7 @@ function AssistLayout(props) {
2586
2568
  }
2587
2569
  const ImageContext = react.createContext({});
2588
2570
  function ImageContextProvider(props) {
2589
- const { schemaType, path, value, readOnly } = props, assetRef = value?.asset?._ref, { selectedReleaseId } = structure.useDocumentPane(), [assetRefState, setAssetRefState] = react.useState(assetRef), { assistableDocumentId, documentSchemaType } = useAssistDocumentContext(), { config, status } = useAiAssistanceConfig(), apiClient = useApiClient(config?.__customApiClient), { generateCaption } = useGenerateCaption(apiClient), { isSyncing } = sanity.useSyncState(
2571
+ const { schemaType, path, value, readOnly } = props, assetRef = value?.asset?._ref, { selectedReleaseId } = sanity.usePerspective(), [assetRefState, setAssetRefState] = react.useState(assetRef), { assistableDocumentId, documentSchemaType } = useAssistDocumentContext(), { config, status } = useAiAssistanceConfig(), apiClient = useApiClient(config?.__customApiClient), { generateCaption } = useGenerateCaption(apiClient), { isSyncing } = sanity.useSyncState(
2590
2572
  sanity.getPublishedId(assistableDocumentId),
2591
2573
  documentSchemaType.name,
2592
2574
  selectedReleaseId
@@ -2818,15 +2800,9 @@ function PrivateIcon() {
2818
2800
  }
2819
2801
  );
2820
2802
  }
2821
- function getRandomValues(typedArray) {
2822
- const crypto = typeof window < "u" && "crypto" in window ? window.crypto : globalThis.crypto;
2823
- if (!crypto || !crypto.getRandomValues)
2824
- throw new Error("WebCrypto not available in this environment");
2825
- return crypto.getRandomValues(typedArray);
2826
- }
2827
2803
  function whatwgRNG(length = 16) {
2828
2804
  const rnds8 = new Uint8Array(length);
2829
- return getRandomValues(rnds8), rnds8;
2805
+ return getRandomValues__default.default(rnds8), rnds8;
2830
2806
  }
2831
2807
  const getByteHexTable = /* @__PURE__ */ (() => {
2832
2808
  let table;
@@ -2898,7 +2874,6 @@ function createSafeNode(args) {
2898
2874
  expanded: !0,
2899
2875
  children
2900
2876
  } : void 0;
2901
- case "divider":
2902
2877
  default:
2903
2878
  return node;
2904
2879
  }
@@ -3192,18 +3167,18 @@ function AssistDocumentFormEditable(props) {
3192
3167
  () => ({
3193
3168
  ...formCallbacks,
3194
3169
  onPathOpen: (path) => {
3195
- !instruction2 && path.length === 4 && path[2] === "instructions" ? (setParams(
3170
+ !instruction2 && path.length === 4 && path[2] === "instructions" ? setParams(
3196
3171
  sanity.typed({
3197
3172
  ...params,
3198
3173
  [instructionParam]: path[3]?._key
3199
3174
  })
3200
- ), onPathOpen([])) : setTimeout(() => onPathOpen(path), 0);
3175
+ ) : setTimeout(() => onPathOpen(path), 0);
3201
3176
  }
3202
3177
  }),
3203
3178
  [formCallbacks, onPathOpen, params, setParams, instruction2]
3204
3179
  );
3205
3180
  react.useEffect(() => {
3206
- activePath && !instruction2 && onPathOpen([]);
3181
+ activePath && !instruction2 && onPathOpen(activePath);
3207
3182
  }, [activePath, instruction2, onPathOpen]);
3208
3183
  const fieldError = react.useMemo(() => {
3209
3184
  const fieldError2 = props.members.find(