@sanity/assist 6.1.13 → 6.1.15
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/README.md +210 -48
- package/dist/index.js +69 -8
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -2,9 +2,11 @@ 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
|
-
import { addSeconds
|
|
7
|
+
import { addSeconds } from "date-fns/addSeconds";
|
|
8
|
+
import { isAfter } from "date-fns/isAfter";
|
|
9
|
+
import { minutesToMilliseconds } from "date-fns/minutesToMilliseconds";
|
|
8
10
|
import { BlockContentIcon } from "@sanity/icons/BlockContent";
|
|
9
11
|
import { BlockquoteIcon } from "@sanity/icons/Blockquote";
|
|
10
12
|
import { DocumentIcon } from "@sanity/icons/Document";
|
|
@@ -27,6 +29,8 @@ import { ClockIcon } from "@sanity/icons/Clock";
|
|
|
27
29
|
import { CloseCircleIcon } from "@sanity/icons/CloseCircle";
|
|
28
30
|
import { ErrorOutlineIcon } from "@sanity/icons/ErrorOutline";
|
|
29
31
|
import { SyncIcon } from "@sanity/icons/Sync";
|
|
32
|
+
import { formatDistanceToNow } from "date-fns/formatDistanceToNow";
|
|
33
|
+
import isEqual from "react-fast-compare";
|
|
30
34
|
import get from "lodash-es/get.js";
|
|
31
35
|
import { Icon, icons } from "@sanity/icons";
|
|
32
36
|
import { ControlsIcon } from "@sanity/icons/Controls";
|
|
@@ -38,7 +42,6 @@ import { ThListIcon } from "@sanity/icons/ThList";
|
|
|
38
42
|
import { ArrowLeftIcon } from "@sanity/icons/ArrowLeft";
|
|
39
43
|
import { DocumentTextIcon } from "@sanity/icons/DocumentText";
|
|
40
44
|
import { TokenIcon } from "@sanity/icons/Token";
|
|
41
|
-
import isEqual from "react-fast-compare";
|
|
42
45
|
import { defer, delay, merge, of, partition, switchMap, throwError } from "rxjs";
|
|
43
46
|
import { exhaustMapToWithTrailing } from "rxjs-exhaustmap-with-trailing";
|
|
44
47
|
function hasOverflowScroll(el) {
|
|
@@ -2089,12 +2092,36 @@ function TaskItem(props) {
|
|
|
2089
2092
|
children: t13
|
|
2090
2093
|
}), $[29] = t0, $[30] = t13, $[31] = t14) : t14 = $[31], t14;
|
|
2091
2094
|
}
|
|
2092
|
-
|
|
2095
|
+
/**
|
|
2096
|
+
* The AI Assist inspector renders a nested document form for the instruction
|
|
2097
|
+
* document, but it reuses the host document's pane router. Sanity's document
|
|
2098
|
+
* pane mirrors the router `path` param to programmatic focus, and focus drives
|
|
2099
|
+
* the selected field group. So when the nested form writes `path`, the host
|
|
2100
|
+
* document re-focuses and its field group selection resets (SAPP-3970).
|
|
2101
|
+
*
|
|
2102
|
+
* This keeps the nested form's `path` navigation local, while still forwarding
|
|
2103
|
+
* every other param (e.g. the selected `instruction`) to the host router and
|
|
2104
|
+
* preserving the host document's own `path`.
|
|
2105
|
+
*/
|
|
2106
|
+
function isolatePathParams(nextParams, hostParams) {
|
|
2107
|
+
let { path: nextLocalPath, ...restNext } = nextParams, { path: hostPath, ...restHost } = hostParams;
|
|
2108
|
+
return isEqual(restNext, restHost) ? {
|
|
2109
|
+
nextLocalPath,
|
|
2110
|
+
forwardParams: null
|
|
2111
|
+
} : {
|
|
2112
|
+
nextLocalPath,
|
|
2113
|
+
forwardParams: {
|
|
2114
|
+
...restNext,
|
|
2115
|
+
path: hostPath
|
|
2116
|
+
}
|
|
2117
|
+
};
|
|
2118
|
+
}
|
|
2119
|
+
const EMPTY_PANE_PARAMS = {}, CardWithShadowBelow = styled(Card).withConfig({
|
|
2093
2120
|
displayName: "CardWithShadowBelow",
|
|
2094
|
-
componentId: "sc-
|
|
2121
|
+
componentId: "sc-1m9tjp-0"
|
|
2095
2122
|
})`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
2123
|
displayName: "CardWithShadowAbove",
|
|
2097
|
-
componentId: "sc-
|
|
2124
|
+
componentId: "sc-1m9tjp-1"
|
|
2098
2125
|
})`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
2126
|
function AssistInspectorWrapper(props) {
|
|
2100
2127
|
let $ = c(43), context = useAiAssistanceConfig();
|
|
@@ -2342,13 +2369,13 @@ function AssistInspector(props) {
|
|
|
2342
2369
|
containerElement: boundary,
|
|
2343
2370
|
children: /* @__PURE__ */ jsx(PerspectiveProvider, {
|
|
2344
2371
|
selectedPerspectiveName: void 0,
|
|
2345
|
-
children: /* @__PURE__ */ jsx(DocumentPaneProvider, {
|
|
2372
|
+
children: /* @__PURE__ */ jsx(IsolatedPathPaneRouterProvider, { children: /* @__PURE__ */ jsx(DocumentPaneProvider, {
|
|
2346
2373
|
paneKey: documentPane.paneKey,
|
|
2347
2374
|
index: documentPane.index,
|
|
2348
2375
|
itemId: "ai",
|
|
2349
2376
|
pane: paneNode,
|
|
2350
2377
|
children: /* @__PURE__ */ jsx(DocumentForm, {})
|
|
2351
|
-
})
|
|
2378
|
+
}) })
|
|
2352
2379
|
})
|
|
2353
2380
|
})
|
|
2354
2381
|
})
|
|
@@ -2405,6 +2432,40 @@ function AssistInspector(props) {
|
|
|
2405
2432
|
]
|
|
2406
2433
|
});
|
|
2407
2434
|
}
|
|
2435
|
+
/**
|
|
2436
|
+
* The instruction editor below renders a nested document form that reuses the
|
|
2437
|
+
* host document's pane router. Sanity's document pane mirrors the router `path`
|
|
2438
|
+
* param to programmatic focus, and focus drives the selected field group. So
|
|
2439
|
+
* without isolation, navigating the instruction form overwrites the host `path`
|
|
2440
|
+
* and resets the host document's field group selection (SAPP-3970).
|
|
2441
|
+
*
|
|
2442
|
+
* This provider keeps the nested form's `path` navigation in local state while
|
|
2443
|
+
* still forwarding every other param (e.g. the selected instruction) to the
|
|
2444
|
+
* host pane router.
|
|
2445
|
+
*/
|
|
2446
|
+
function IsolatedPathPaneRouterProvider(props) {
|
|
2447
|
+
let $ = c(13), parentRouter = usePaneRouter(), parentParams = parentRouter.params ?? EMPTY_PANE_PARAMS, parentSetParams = parentRouter.setParams, [localPath, setLocalPath] = useState(void 0), t0;
|
|
2448
|
+
$[0] !== parentParams || $[1] !== parentSetParams ? (t0 = (nextParams, stickyParams) => {
|
|
2449
|
+
let { nextLocalPath, forwardParams } = isolatePathParams(nextParams, parentParams);
|
|
2450
|
+
setLocalPath(nextLocalPath), forwardParams && parentSetParams(forwardParams, stickyParams);
|
|
2451
|
+
}, $[0] = parentParams, $[1] = parentSetParams, $[2] = t0) : t0 = $[2];
|
|
2452
|
+
let setParams = t0, t1;
|
|
2453
|
+
$[3] !== localPath || $[4] !== parentParams ? (t1 = {
|
|
2454
|
+
...parentParams,
|
|
2455
|
+
path: localPath
|
|
2456
|
+
}, $[3] = localPath, $[4] = parentParams, $[5] = t1) : t1 = $[5];
|
|
2457
|
+
let t2;
|
|
2458
|
+
$[6] !== parentRouter || $[7] !== setParams || $[8] !== t1 ? (t2 = {
|
|
2459
|
+
...parentRouter,
|
|
2460
|
+
params: t1,
|
|
2461
|
+
setParams
|
|
2462
|
+
}, $[6] = parentRouter, $[7] = setParams, $[8] = t1, $[9] = t2) : t2 = $[9];
|
|
2463
|
+
let value = t2, t3;
|
|
2464
|
+
return $[10] !== props.children || $[11] !== value ? (t3 = /* @__PURE__ */ jsx(PaneRouterContext.Provider, {
|
|
2465
|
+
value,
|
|
2466
|
+
children: props.children
|
|
2467
|
+
}), $[10] = props.children, $[11] = value, $[12] = t3) : t3 = $[12], t3;
|
|
2468
|
+
}
|
|
2408
2469
|
function AiInspectorHeader(props) {
|
|
2409
2470
|
let $ = c(16), { onClose, field, fieldTitle } = props, { showOnboarding, dismissOnboarding } = useOnboardingFeature("sanityStudio:assist:inspector:onboarding:dismissed"), t0;
|
|
2410
2471
|
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = { marginTop: "-4px" }, $[0] = t0) : t0 = $[0];
|