@sanity/assist 1.0.11 → 1.0.12
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 +1 -1
- package/dist/index.esm.js +78 -43
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +78 -43
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/assistInspector/AssistInspector.tsx +7 -4
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ In your Studio project folder, install the following plugin dependency:
|
|
|
40
40
|
npm install @sanity/assist sanity@latest
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
This plugin requires `sanity` version `3.
|
|
43
|
+
This plugin requires `sanity` version `3.14.5` or greater.
|
|
44
44
|
|
|
45
45
|
## Setup
|
|
46
46
|
|
package/dist/index.esm.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12;
|
|
2
|
-
function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
|
3
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
4
2
|
import { useClient, typed, useSchema, useDocumentStore, useDocumentPresence, createPatchChannel, FormBuilder, fromMutationPatches, pathToString, isObjectSchemaType, useEditState, useCurrentUser, useValidationStatus, StatusButton, FormFieldHeaderText, PatchEvent, unset, PresenceOverlay, VirtualizerScrollInstanceProvider, stringToPath, isKeySegment, useColorSchemeValue, isArraySchemaType, useFormCallbacks, set, FormCallbacksProvider, FormInput, setIfMissing, insert, ObjectInputMember, defineType, defineField, defineArrayMember, getPublishedId, definePlugin } from 'sanity';
|
|
5
3
|
import { Card, Stack, Box, Button, Spinner, Flex, Label, focusFirstDescendant, Text, useClickOutside, Popover, useLayer, useGlobalKeyDown, useToast, Dialog, Tooltip, TextArea, Container, Badge, useTheme, rgba, ThemeProvider, ErrorBoundary, Switch, MenuButton, Menu, MenuItem, Breadcrumbs, Autocomplete } from '@sanity/ui';
|
|
@@ -58,7 +56,7 @@ const listenQuery = function (client, query) {
|
|
|
58
56
|
const events$ = listen(client, listenerQuery, params, options).pipe(mergeMap((ev, i) => {
|
|
59
57
|
const isFirst = i === 0;
|
|
60
58
|
if (isFirst && !isWelcomeEvent(ev)) {
|
|
61
|
-
return throwError(new Error(ev.type === "reconnect" ? "Could not establish EventSource connection" :
|
|
59
|
+
return throwError(new Error(ev.type === "reconnect" ? "Could not establish EventSource connection" : 'Received unexpected type of first event "'.concat(ev.type, '"')));
|
|
62
60
|
}
|
|
63
61
|
return of(ev);
|
|
64
62
|
}), share());
|
|
@@ -684,8 +682,14 @@ function getInstructionTitle(instruction) {
|
|
|
684
682
|
var _a;
|
|
685
683
|
return (_a = instruction == null ? void 0 : instruction.title) != null ? _a : "Untitled";
|
|
686
684
|
}
|
|
687
|
-
|
|
688
|
-
|
|
685
|
+
var __freeze$5 = Object.freeze;
|
|
686
|
+
var __defProp$5 = Object.defineProperty;
|
|
687
|
+
var __template$5 = (cooked, raw) => __freeze$5(__defProp$5(cooked, "raw", {
|
|
688
|
+
value: __freeze$5(raw || cooked.slice())
|
|
689
|
+
}));
|
|
690
|
+
var _a$5, _b$3;
|
|
691
|
+
const rotate = keyframes(_a$5 || (_a$5 = __template$5(["\n 0% {\n transform: rotate(0);\n }\n 100% {\n transform: rotate(360deg);\n }\n"])));
|
|
692
|
+
const SyncSpinningIcon = styled(SyncIcon)(_b$3 || (_b$3 = __template$5(["\n animation: ", " 1s linear infinite;\n"])), rotate);
|
|
689
693
|
const TASK_CONFIG = {
|
|
690
694
|
aborted: {
|
|
691
695
|
title: "Canceled",
|
|
@@ -723,25 +727,25 @@ function InstructionTaskHistoryButton(props) {
|
|
|
723
727
|
return;
|
|
724
728
|
}
|
|
725
729
|
const statusDocId = assistTasksStatusId(documentId);
|
|
726
|
-
const basePath = "".concat(typed("tasks"),
|
|
730
|
+
const basePath = "".concat(typed("tasks"), '[_key=="').concat(taskKey, '"]');
|
|
727
731
|
client.patch(statusDocId).set({
|
|
728
732
|
["".concat(basePath, ".").concat(typed("ended"))]: /* @__PURE__ */new Date().toISOString(),
|
|
729
733
|
["".concat(basePath, ".").concat(typed("reason"))]: typed("aborted")
|
|
730
734
|
}).commit().catch(console.error);
|
|
731
735
|
}, [client, documentId]);
|
|
732
736
|
const titledTasks = useMemo(() => {
|
|
733
|
-
var
|
|
734
|
-
const t = (
|
|
737
|
+
var _a2;
|
|
738
|
+
const t = (_a2 = tasks == null ? void 0 : tasks.filter(task => task.started && /* @__PURE__ */new Date().getTime() - new Date(task.started).getTime() < maxHistoryVisibilityMs).map(task => {
|
|
735
739
|
const instruction = instructions == null ? void 0 : instructions.find(i => i._key === task.instructionKey);
|
|
736
740
|
return {
|
|
737
741
|
...task,
|
|
738
742
|
title: showTitles ? getInstructionTitle(instruction) : void 0,
|
|
739
743
|
cancel: () => cancelRun(task._key)
|
|
740
744
|
};
|
|
741
|
-
})) != null ?
|
|
745
|
+
})) != null ? _a2 : [];
|
|
742
746
|
t.sort((a, b) => {
|
|
743
|
-
var
|
|
744
|
-
return new Date((
|
|
747
|
+
var _a3, _b2;
|
|
748
|
+
return new Date((_a3 = b.started) != null ? _a3 : "").getTime() - new Date((_b2 = a.started) != null ? _b2 : "").getTime();
|
|
745
749
|
});
|
|
746
750
|
return t;
|
|
747
751
|
}, [tasks, instructions, cancelRun, showTitles]);
|
|
@@ -826,7 +830,7 @@ function TaskList(props) {
|
|
|
826
830
|
});
|
|
827
831
|
}
|
|
828
832
|
function TaskItem(props) {
|
|
829
|
-
var
|
|
833
|
+
var _a2;
|
|
830
834
|
const {
|
|
831
835
|
task
|
|
832
836
|
} = props;
|
|
@@ -864,7 +868,7 @@ function TaskItem(props) {
|
|
|
864
868
|
muted: true,
|
|
865
869
|
size: 1,
|
|
866
870
|
children: /* @__PURE__ */jsx(TimeAgo, {
|
|
867
|
-
date: (
|
|
871
|
+
date: (_a2 = task.ended) != null ? _a2 : task.started
|
|
868
872
|
})
|
|
869
873
|
})]
|
|
870
874
|
})]
|
|
@@ -1316,8 +1320,14 @@ function useOnboardingFeature(featureKey) {
|
|
|
1316
1320
|
dismissOnboarding
|
|
1317
1321
|
};
|
|
1318
1322
|
}
|
|
1319
|
-
|
|
1320
|
-
|
|
1323
|
+
var __freeze$4 = Object.freeze;
|
|
1324
|
+
var __defProp$4 = Object.defineProperty;
|
|
1325
|
+
var __template$4 = (cooked, raw) => __freeze$4(__defProp$4(cooked, "raw", {
|
|
1326
|
+
value: __freeze$4(raw || cooked.slice())
|
|
1327
|
+
}));
|
|
1328
|
+
var _a$4, _b$2;
|
|
1329
|
+
const CardWithShadowBelow = styled(Card)(_a$4 || (_a$4 = __template$4(["\n position: relative;\n\n &:after {\n content: '';\n display: block;\n position: absolute;\n left: 0;\n right: 0;\n bottom: -1px;\n border-bottom: 1px solid var(--card-border-color);\n opacity: 0.5;\n z-index: 100;\n }\n"])));
|
|
1330
|
+
const CardWithShadowAbove = styled(Card)(_b$2 || (_b$2 = __template$4(["\n position: relative;\n\n &:after {\n content: '';\n display: block;\n position: absolute;\n left: 0;\n right: 0;\n top: -1px;\n border-top: 1px solid var(--card-border-color);\n opacity: 0.5;\n z-index: 100;\n }\n"])));
|
|
1321
1331
|
function AssistInspectorWrapper(props) {
|
|
1322
1332
|
const context = useAiAssistanceConfig();
|
|
1323
1333
|
if (context.statusLoading) {
|
|
@@ -1436,11 +1446,11 @@ function AssistInspectorWrapper(props) {
|
|
|
1436
1446
|
});
|
|
1437
1447
|
}
|
|
1438
1448
|
function AssistInspector(props) {
|
|
1439
|
-
var
|
|
1449
|
+
var _a2, _b2;
|
|
1440
1450
|
const {
|
|
1441
1451
|
params
|
|
1442
1452
|
} = useAiPaneRouter();
|
|
1443
|
-
const
|
|
1453
|
+
const boundary = useRef(null);
|
|
1444
1454
|
const pathKey = params == null ? void 0 : params[fieldPathParam];
|
|
1445
1455
|
const instructionKey = params == null ? void 0 : params[instructionParam];
|
|
1446
1456
|
const documentPane = useDocumentPane();
|
|
@@ -1468,28 +1478,28 @@ function AssistInspector(props) {
|
|
|
1468
1478
|
documentId,
|
|
1469
1479
|
schemaType
|
|
1470
1480
|
});
|
|
1471
|
-
const assistField = (
|
|
1472
|
-
const instruction = (
|
|
1481
|
+
const assistField = (_a2 = assistDocument == null ? void 0 : assistDocument.fields) == null ? void 0 : _a2.find(f => f.path === pathKey);
|
|
1482
|
+
const instruction = (_b2 = assistField == null ? void 0 : assistField.instructions) == null ? void 0 : _b2.find(i => i._key === instructionKey);
|
|
1473
1483
|
const tasks = useMemo(() => {
|
|
1474
|
-
var
|
|
1475
|
-
return (
|
|
1484
|
+
var _a3;
|
|
1485
|
+
return (_a3 = assistDocument == null ? void 0 : assistDocument.tasks) == null ? void 0 : _a3.filter(i => !instructionKey || i.instructionKey === instructionKey);
|
|
1476
1486
|
}, [assistDocument == null ? void 0 : assistDocument.tasks, instructionKey]);
|
|
1477
1487
|
const instructions = useMemo(() => {
|
|
1478
|
-
var
|
|
1479
|
-
return (
|
|
1480
|
-
var
|
|
1481
|
-
return (
|
|
1488
|
+
var _a3;
|
|
1489
|
+
return (_a3 = assistDocument == null ? void 0 : assistDocument.fields) == null ? void 0 : _a3.flatMap(f => {
|
|
1490
|
+
var _a4;
|
|
1491
|
+
return (_a4 = f.instructions) != null ? _a4 : [];
|
|
1482
1492
|
});
|
|
1483
1493
|
}, [assistDocument == null ? void 0 : assistDocument.fields]);
|
|
1484
1494
|
const promptValue = instruction == null ? void 0 : instruction.prompt;
|
|
1485
1495
|
const isEmptyPrompt = useMemo(() => {
|
|
1486
|
-
var
|
|
1496
|
+
var _a3, _b3;
|
|
1487
1497
|
if (!(promptValue == null ? void 0 : promptValue.length)) {
|
|
1488
1498
|
return true;
|
|
1489
1499
|
}
|
|
1490
1500
|
const firstBlock = promptValue[0];
|
|
1491
1501
|
const children = firstBlock == null ? void 0 : firstBlock.children;
|
|
1492
|
-
return promptValue.length == 1 && (children == null ? void 0 : children.length) === 1 && !((
|
|
1502
|
+
return promptValue.length == 1 && (children == null ? void 0 : children.length) === 1 && !((_b3 = (_a3 = children == null ? void 0 : children[0]) == null ? void 0 : _a3.text) == null ? void 0 : _b3.length);
|
|
1493
1503
|
}, [promptValue]);
|
|
1494
1504
|
const paneNode = useMemo(() => ({
|
|
1495
1505
|
type: "document",
|
|
@@ -1526,7 +1536,7 @@ function AssistInspector(props) {
|
|
|
1526
1536
|
});
|
|
1527
1537
|
}
|
|
1528
1538
|
return /* @__PURE__ */jsxs(Flex, {
|
|
1529
|
-
ref:
|
|
1539
|
+
ref: boundary,
|
|
1530
1540
|
direction: "column",
|
|
1531
1541
|
height: "fill",
|
|
1532
1542
|
overflow: "hidden",
|
|
@@ -1552,7 +1562,8 @@ function AssistInspector(props) {
|
|
|
1552
1562
|
children: /* @__PURE__ */jsx(Box, {
|
|
1553
1563
|
padding: 4,
|
|
1554
1564
|
children: selectedField && /* @__PURE__ */jsx(VirtualizerScrollInstanceProvider, {
|
|
1555
|
-
scrollElement: boundary,
|
|
1565
|
+
scrollElement: boundary.current,
|
|
1566
|
+
containerElement: boundary,
|
|
1556
1567
|
children: /* @__PURE__ */jsx(DocumentPaneProvider, {
|
|
1557
1568
|
paneKey: documentPane.paneKey,
|
|
1558
1569
|
index: documentPane.index,
|
|
@@ -1745,8 +1756,14 @@ function aiPresence(presence, path, title) {
|
|
|
1745
1756
|
lastActiveAt: (_a = presence == null ? void 0 : presence.started) != null ? _a : /* @__PURE__ */new Date().toISOString()
|
|
1746
1757
|
};
|
|
1747
1758
|
}
|
|
1748
|
-
|
|
1749
|
-
|
|
1759
|
+
var __freeze$3 = Object.freeze;
|
|
1760
|
+
var __defProp$3 = Object.defineProperty;
|
|
1761
|
+
var __template$3 = (cooked, raw) => __freeze$3(__defProp$3(cooked, "raw", {
|
|
1762
|
+
value: __freeze$3(raw || cooked.slice())
|
|
1763
|
+
}));
|
|
1764
|
+
var _a$3, _b$1;
|
|
1765
|
+
const fadeIn = keyframes(_a$3 || (_a$3 = __template$3(["\n 0% {\n opacity: 0;\n transform: scale(0.75);\n }\n 40% {\n opacity: 0;\n transform: scale(0.75);\n }\n 100% {\n opacity: 1;\n transform: scale(1);\n }\n"])));
|
|
1766
|
+
const FadeInDiv = styled.div(_b$1 || (_b$1 = __template$3(["\n animation-name: ", ";\n animation-timing-function: ease-in-out;\n"])), fadeIn);
|
|
1750
1767
|
function FadeInContent(_ref7) {
|
|
1751
1768
|
let {
|
|
1752
1769
|
children,
|
|
@@ -1805,10 +1822,16 @@ const purple = {
|
|
|
1805
1822
|
hex: "#211229"
|
|
1806
1823
|
}
|
|
1807
1824
|
};
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1825
|
+
var __freeze$2 = Object.freeze;
|
|
1826
|
+
var __defProp$2 = Object.defineProperty;
|
|
1827
|
+
var __template$2 = (cooked, raw) => __freeze$2(__defProp$2(cooked, "raw", {
|
|
1828
|
+
value: __freeze$2(raw || cooked.slice())
|
|
1829
|
+
}));
|
|
1830
|
+
var _a$2, _b, _c, _d;
|
|
1831
|
+
const Root = styled.span(_a$2 || (_a$2 = __template$2(["\n display: block;\n width: 25px;\n height: 25px;\n position: relative;\n"])));
|
|
1832
|
+
const dash = keyframes(_b || (_b = __template$2(["\n 0% {\n transform: rotate(0);\n }\n 100% {\n transform: rotate(43deg);\n }\n"])));
|
|
1833
|
+
const Outline = styled.svg(_c || (_c = __template$2(["\n display: block;\n position: absolute;\n top: 0;\n left: 0;\n\n & > circle {\n stroke: var(--ai-avatar-stroke-color);\n stroke-width: 1.5px;\n stroke-linecap: round;\n transform-origin: center;\n animation: ", " 500ms ease-in-out infinite;\n transition: stroke-dasharray 200ms ease-in-out;\n\n stroke-dasharray: 2.34px 0;\n\n [data-state='active'] > & {\n stroke-dasharray: 2px 2.34px;\n }\n }\n"])), dash);
|
|
1834
|
+
const IconDisc = styled.span(_d || (_d = __template$2(["\n background: var(--ai-avatar-disc-color);\n color: white;\n width: 21px;\n height: 21px;\n display: flex;\n align-items: center;\n justify-content: center;\n border-radius: 10.5px;\n position: absolute;\n top: 2px;\n left: 2px;\n"])));
|
|
1812
1835
|
function AssistAvatar(props) {
|
|
1813
1836
|
const {
|
|
1814
1837
|
state = "present"
|
|
@@ -2526,7 +2549,7 @@ function AlphaMigration() {
|
|
|
2526
2549
|
});
|
|
2527
2550
|
useEffect(() => {
|
|
2528
2551
|
let canUpdate = true;
|
|
2529
|
-
client.fetch(
|
|
2552
|
+
client.fetch('\n {\n "assistDocs": *[_type=="'.concat(legacyAssistDocumentTypeName, '"],\n "staleStatusDocIds": *[_type=="').concat(legacyAssistStatusDocumentTypeName, '"]._id,\n "contextDocs": *[_type=="').concat(legacyContextDocumentTypeName, '"],\n }\n ')).then(result => {
|
|
2530
2553
|
var _a, _b, _c;
|
|
2531
2554
|
if (!canUpdate || !result) {
|
|
2532
2555
|
return;
|
|
@@ -2648,7 +2671,7 @@ async function convertDocs(client, docs, updateProgress) {
|
|
|
2648
2671
|
const progressCount = Math.min(docs.length, i + chunkSize);
|
|
2649
2672
|
const chunk = docs.slice(i, progressCount);
|
|
2650
2673
|
const trans = client.transaction();
|
|
2651
|
-
const contextDocs = await client.fetch(
|
|
2674
|
+
const contextDocs = await client.fetch('*[_type=="'.concat(contextDocumentTypeName, '" && _alphaId != null]{_id, _alphaId}'));
|
|
2652
2675
|
chunk.forEach(oldDoc => {
|
|
2653
2676
|
var _a;
|
|
2654
2677
|
const documentType = oldDoc._id.replace(new RegExp("^(".concat(legacyAssistDocumentIdPrefix, "|").concat(assistDocumentIdPrefix, ")")), "");
|
|
@@ -2756,7 +2779,13 @@ function AssistLayout(props) {
|
|
|
2756
2779
|
})]
|
|
2757
2780
|
});
|
|
2758
2781
|
}
|
|
2759
|
-
|
|
2782
|
+
var __freeze$1 = Object.freeze;
|
|
2783
|
+
var __defProp$1 = Object.defineProperty;
|
|
2784
|
+
var __template$1 = (cooked, raw) => __freeze$1(__defProp$1(cooked, "raw", {
|
|
2785
|
+
value: __freeze$1(raw || cooked.slice())
|
|
2786
|
+
}));
|
|
2787
|
+
var _a$1;
|
|
2788
|
+
const WrapPreCard = styled(Card)(_a$1 || (_a$1 = __template$1(["\n & pre {\n white-space: pre-wrap !important;\n }\n"])));
|
|
2760
2789
|
function SafeValueInput(props) {
|
|
2761
2790
|
return /* @__PURE__ */jsx(ErrorWrapper, {
|
|
2762
2791
|
onChange: props.onChange,
|
|
@@ -3468,7 +3497,7 @@ function HideReferenceChangedBannerInput(props) {
|
|
|
3468
3497
|
const style = document.createElement("style");
|
|
3469
3498
|
const parentId = "id-".concat(Math.random()).replace(".", "-");
|
|
3470
3499
|
parent.id = parentId;
|
|
3471
|
-
style.innerText = "\n #".concat(parentId,
|
|
3500
|
+
style.innerText = "\n #".concat(parentId, ' [data-testid="reference-changed-banner"] { display: none; }\n ');
|
|
3472
3501
|
parent.prepend(style);
|
|
3473
3502
|
}, [ref]);
|
|
3474
3503
|
return /* @__PURE__ */jsx(Box, {
|
|
@@ -3559,7 +3588,13 @@ function randomKey(length) {
|
|
|
3559
3588
|
const table = getByteHexTable();
|
|
3560
3589
|
return whatwgRNG(length).reduce((str, n) => str + table[n], "").slice(0, length);
|
|
3561
3590
|
}
|
|
3562
|
-
|
|
3591
|
+
var __freeze = Object.freeze;
|
|
3592
|
+
var __defProp = Object.defineProperty;
|
|
3593
|
+
var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", {
|
|
3594
|
+
value: __freeze(raw || cooked.slice())
|
|
3595
|
+
}));
|
|
3596
|
+
var _a;
|
|
3597
|
+
const PteMods = styled(Box)(_a || (_a = __template(["\n & [data-testid='pt-editor__toolbar-card'] > div > div:last-child {\n display: none;\n }\n & [data-testid='pt-editor'] {\n min-height: 300px;\n }\n & [data-testid='pt-editor'] .pt-inline-object * {\n max-width: 400px;\n }\n"])));
|
|
3563
3598
|
function PromptInput(props) {
|
|
3564
3599
|
useOnlyInlineBlocks(props);
|
|
3565
3600
|
return /* @__PURE__ */jsx(PteMods, {
|
|
@@ -3568,9 +3603,9 @@ function PromptInput(props) {
|
|
|
3568
3603
|
}
|
|
3569
3604
|
function useOnlyInlineBlocks(props) {
|
|
3570
3605
|
useEffect(() => {
|
|
3571
|
-
var
|
|
3606
|
+
var _a2;
|
|
3572
3607
|
let needsFix = false;
|
|
3573
|
-
const val = ((
|
|
3608
|
+
const val = ((_a2 = props.value) != null ? _a2 : []).map(block => {
|
|
3574
3609
|
if (block._type === "block") {
|
|
3575
3610
|
return block;
|
|
3576
3611
|
}
|
|
@@ -3625,7 +3660,7 @@ const fieldReference = defineType({
|
|
|
3625
3660
|
const refs = getFieldRefsWithDocument(schema);
|
|
3626
3661
|
const fieldRef = refs.find(r => r.key === value);
|
|
3627
3662
|
if (!fieldRef) {
|
|
3628
|
-
return
|
|
3663
|
+
return 'Field with path "'.concat(value, '" does not exist in the schema.');
|
|
3629
3664
|
}
|
|
3630
3665
|
return true;
|
|
3631
3666
|
} catch (e) {
|