@sanity/assist 6.1.13 → 6.1.14

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 CHANGED
@@ -2,7 +2,7 @@ import { FormBuilder, FormCallbacksProvider, FormFieldHeaderText, FormInput, Mem
2
2
  import { c } from "react/compiler-runtime";
3
3
  import { Autocomplete, Box, Breadcrumbs, Button, Card, Checkbox, Container, Dialog, ErrorBoundary, Flex, Label, Menu, MenuButton, MenuItem, Popover, Radio, Spinner, Stack, Switch, Text, TextArea, ThemeProvider, Tooltip, focusFirstDescendant, rgba, useClickOutside, useGlobalKeyDown, useLayer, useTheme, useToast } from "@sanity/ui";
4
4
  import { createContext, isValidElement, useCallback, useContext, useEffect, useEffectEvent, useId, useMemo, useReducer, useRef, useState } from "react";
5
- import { DocumentInspectorHeader, DocumentPaneProvider, useDocumentPane, usePaneRouter } from "sanity/structure";
5
+ import { DocumentInspectorHeader, DocumentPaneProvider, PaneRouterContext, useDocumentPane, usePaneRouter } from "sanity/structure";
6
6
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
7
7
  import { addSeconds, formatDistanceToNow, isAfter, minutesToMilliseconds } from "date-fns";
8
8
  import { BlockContentIcon } from "@sanity/icons/BlockContent";
@@ -27,6 +27,7 @@ import { ClockIcon } from "@sanity/icons/Clock";
27
27
  import { CloseCircleIcon } from "@sanity/icons/CloseCircle";
28
28
  import { ErrorOutlineIcon } from "@sanity/icons/ErrorOutline";
29
29
  import { SyncIcon } from "@sanity/icons/Sync";
30
+ import isEqual from "react-fast-compare";
30
31
  import get from "lodash-es/get.js";
31
32
  import { Icon, icons } from "@sanity/icons";
32
33
  import { ControlsIcon } from "@sanity/icons/Controls";
@@ -38,7 +39,6 @@ import { ThListIcon } from "@sanity/icons/ThList";
38
39
  import { ArrowLeftIcon } from "@sanity/icons/ArrowLeft";
39
40
  import { DocumentTextIcon } from "@sanity/icons/DocumentText";
40
41
  import { TokenIcon } from "@sanity/icons/Token";
41
- import isEqual from "react-fast-compare";
42
42
  import { defer, delay, merge, of, partition, switchMap, throwError } from "rxjs";
43
43
  import { exhaustMapToWithTrailing } from "rxjs-exhaustmap-with-trailing";
44
44
  function hasOverflowScroll(el) {
@@ -2089,12 +2089,36 @@ function TaskItem(props) {
2089
2089
  children: t13
2090
2090
  }), $[29] = t0, $[30] = t13, $[31] = t14) : t14 = $[31], t14;
2091
2091
  }
2092
- const CardWithShadowBelow = styled(Card).withConfig({
2092
+ /**
2093
+ * The AI Assist inspector renders a nested document form for the instruction
2094
+ * document, but it reuses the host document's pane router. Sanity's document
2095
+ * pane mirrors the router `path` param to programmatic focus, and focus drives
2096
+ * the selected field group. So when the nested form writes `path`, the host
2097
+ * document re-focuses and its field group selection resets (SAPP-3970).
2098
+ *
2099
+ * This keeps the nested form's `path` navigation local, while still forwarding
2100
+ * every other param (e.g. the selected `instruction`) to the host router and
2101
+ * preserving the host document's own `path`.
2102
+ */
2103
+ function isolatePathParams(nextParams, hostParams) {
2104
+ let { path: nextLocalPath, ...restNext } = nextParams, { path: hostPath, ...restHost } = hostParams;
2105
+ return isEqual(restNext, restHost) ? {
2106
+ nextLocalPath,
2107
+ forwardParams: null
2108
+ } : {
2109
+ nextLocalPath,
2110
+ forwardParams: {
2111
+ ...restNext,
2112
+ path: hostPath
2113
+ }
2114
+ };
2115
+ }
2116
+ const EMPTY_PANE_PARAMS = {}, CardWithShadowBelow = styled(Card).withConfig({
2093
2117
  displayName: "CardWithShadowBelow",
2094
- componentId: "sc-l9jw93-0"
2118
+ componentId: "sc-1m9tjp-0"
2095
2119
  })`position:relative;&:after{content:'';display:block;position:absolute;left:0;right:0;bottom:-1px;border-bottom:1px solid var(--card-border-color);opacity:0.5;z-index:100;}`, CardWithShadowAbove = styled(Card).withConfig({
2096
2120
  displayName: "CardWithShadowAbove",
2097
- componentId: "sc-l9jw93-1"
2121
+ componentId: "sc-1m9tjp-1"
2098
2122
  })`position:relative;&:after{content:'';display:block;position:absolute;left:0;right:0;top:-1px;border-top:1px solid var(--card-border-color);opacity:0.5;z-index:100;}`;
2099
2123
  function AssistInspectorWrapper(props) {
2100
2124
  let $ = c(43), context = useAiAssistanceConfig();
@@ -2342,13 +2366,13 @@ function AssistInspector(props) {
2342
2366
  containerElement: boundary,
2343
2367
  children: /* @__PURE__ */ jsx(PerspectiveProvider, {
2344
2368
  selectedPerspectiveName: void 0,
2345
- children: /* @__PURE__ */ jsx(DocumentPaneProvider, {
2369
+ children: /* @__PURE__ */ jsx(IsolatedPathPaneRouterProvider, { children: /* @__PURE__ */ jsx(DocumentPaneProvider, {
2346
2370
  paneKey: documentPane.paneKey,
2347
2371
  index: documentPane.index,
2348
2372
  itemId: "ai",
2349
2373
  pane: paneNode,
2350
2374
  children: /* @__PURE__ */ jsx(DocumentForm, {})
2351
- })
2375
+ }) })
2352
2376
  })
2353
2377
  })
2354
2378
  })
@@ -2405,6 +2429,40 @@ function AssistInspector(props) {
2405
2429
  ]
2406
2430
  });
2407
2431
  }
2432
+ /**
2433
+ * The instruction editor below renders a nested document form that reuses the
2434
+ * host document's pane router. Sanity's document pane mirrors the router `path`
2435
+ * param to programmatic focus, and focus drives the selected field group. So
2436
+ * without isolation, navigating the instruction form overwrites the host `path`
2437
+ * and resets the host document's field group selection (SAPP-3970).
2438
+ *
2439
+ * This provider keeps the nested form's `path` navigation in local state while
2440
+ * still forwarding every other param (e.g. the selected instruction) to the
2441
+ * host pane router.
2442
+ */
2443
+ function IsolatedPathPaneRouterProvider(props) {
2444
+ let $ = c(13), parentRouter = usePaneRouter(), parentParams = parentRouter.params ?? EMPTY_PANE_PARAMS, parentSetParams = parentRouter.setParams, [localPath, setLocalPath] = useState(void 0), t0;
2445
+ $[0] !== parentParams || $[1] !== parentSetParams ? (t0 = (nextParams, stickyParams) => {
2446
+ let { nextLocalPath, forwardParams } = isolatePathParams(nextParams, parentParams);
2447
+ setLocalPath(nextLocalPath), forwardParams && parentSetParams(forwardParams, stickyParams);
2448
+ }, $[0] = parentParams, $[1] = parentSetParams, $[2] = t0) : t0 = $[2];
2449
+ let setParams = t0, t1;
2450
+ $[3] !== localPath || $[4] !== parentParams ? (t1 = {
2451
+ ...parentParams,
2452
+ path: localPath
2453
+ }, $[3] = localPath, $[4] = parentParams, $[5] = t1) : t1 = $[5];
2454
+ let t2;
2455
+ $[6] !== parentRouter || $[7] !== setParams || $[8] !== t1 ? (t2 = {
2456
+ ...parentRouter,
2457
+ params: t1,
2458
+ setParams
2459
+ }, $[6] = parentRouter, $[7] = setParams, $[8] = t1, $[9] = t2) : t2 = $[9];
2460
+ let value = t2, t3;
2461
+ return $[10] !== props.children || $[11] !== value ? (t3 = /* @__PURE__ */ jsx(PaneRouterContext.Provider, {
2462
+ value,
2463
+ children: props.children
2464
+ }), $[10] = props.children, $[11] = value, $[12] = t3) : t3 = $[12], t3;
2465
+ }
2408
2466
  function AiInspectorHeader(props) {
2409
2467
  let $ = c(16), { onClose, field, fieldTitle } = props, { showOnboarding, dismissOnboarding } = useOnboardingFeature("sanityStudio:assist:inspector:onboarding:dismissed"), t0;
2410
2468
  $[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = { marginTop: "-4px" }, $[0] = t0) : t0 = $[0];