@sanity/assist 1.0.10 → 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/dist/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12;
4
- function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
5
3
  Object.defineProperty(exports, '__esModule', {
6
4
  value: true
7
5
  });
@@ -71,7 +69,7 @@ const listenQuery = function (client, query) {
71
69
  const events$ = listen(client, listenerQuery, params, options).pipe(operators.mergeMap((ev, i) => {
72
70
  const isFirst = i === 0;
73
71
  if (isFirst && !isWelcomeEvent(ev)) {
74
- return rxjs.throwError(new Error(ev.type === "reconnect" ? "Could not establish EventSource connection" : "Received unexpected type of first event \"".concat(ev.type, "\"")));
72
+ return rxjs.throwError(new Error(ev.type === "reconnect" ? "Could not establish EventSource connection" : 'Received unexpected type of first event "'.concat(ev.type, '"')));
75
73
  }
76
74
  return rxjs.of(ev);
77
75
  }), operators.share());
@@ -697,8 +695,14 @@ function getInstructionTitle(instruction) {
697
695
  var _a;
698
696
  return (_a = instruction == null ? void 0 : instruction.title) != null ? _a : "Untitled";
699
697
  }
700
- const rotate = styled.keyframes(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n 0% {\n transform: rotate(0);\n }\n 100% {\n transform: rotate(360deg);\n }\n"])));
701
- const SyncSpinningIcon = styled__default.default(icons.SyncIcon)(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n animation: ", " 1s linear infinite;\n"])), rotate);
698
+ var __freeze$5 = Object.freeze;
699
+ var __defProp$5 = Object.defineProperty;
700
+ var __template$5 = (cooked, raw) => __freeze$5(__defProp$5(cooked, "raw", {
701
+ value: __freeze$5(raw || cooked.slice())
702
+ }));
703
+ var _a$5, _b$3;
704
+ const rotate = styled.keyframes(_a$5 || (_a$5 = __template$5(["\n 0% {\n transform: rotate(0);\n }\n 100% {\n transform: rotate(360deg);\n }\n"])));
705
+ const SyncSpinningIcon = styled__default.default(icons.SyncIcon)(_b$3 || (_b$3 = __template$5(["\n animation: ", " 1s linear infinite;\n"])), rotate);
702
706
  const TASK_CONFIG = {
703
707
  aborted: {
704
708
  title: "Canceled",
@@ -736,25 +740,25 @@ function InstructionTaskHistoryButton(props) {
736
740
  return;
737
741
  }
738
742
  const statusDocId = assistTasksStatusId(documentId);
739
- const basePath = "".concat(sanity.typed("tasks"), "[_key==\"").concat(taskKey, "\"]");
743
+ const basePath = "".concat(sanity.typed("tasks"), '[_key=="').concat(taskKey, '"]');
740
744
  client.patch(statusDocId).set({
741
745
  ["".concat(basePath, ".").concat(sanity.typed("ended"))]: /* @__PURE__ */new Date().toISOString(),
742
746
  ["".concat(basePath, ".").concat(sanity.typed("reason"))]: sanity.typed("aborted")
743
747
  }).commit().catch(console.error);
744
748
  }, [client, documentId]);
745
749
  const titledTasks = react.useMemo(() => {
746
- var _a;
747
- const t = (_a = tasks == null ? void 0 : tasks.filter(task => task.started && /* @__PURE__ */new Date().getTime() - new Date(task.started).getTime() < maxHistoryVisibilityMs).map(task => {
750
+ var _a2;
751
+ const t = (_a2 = tasks == null ? void 0 : tasks.filter(task => task.started && /* @__PURE__ */new Date().getTime() - new Date(task.started).getTime() < maxHistoryVisibilityMs).map(task => {
748
752
  const instruction = instructions == null ? void 0 : instructions.find(i => i._key === task.instructionKey);
749
753
  return {
750
754
  ...task,
751
755
  title: showTitles ? getInstructionTitle(instruction) : void 0,
752
756
  cancel: () => cancelRun(task._key)
753
757
  };
754
- })) != null ? _a : [];
758
+ })) != null ? _a2 : [];
755
759
  t.sort((a, b) => {
756
- var _a2, _b;
757
- return new Date((_a2 = b.started) != null ? _a2 : "").getTime() - new Date((_b = a.started) != null ? _b : "").getTime();
760
+ var _a3, _b2;
761
+ return new Date((_a3 = b.started) != null ? _a3 : "").getTime() - new Date((_b2 = a.started) != null ? _b2 : "").getTime();
758
762
  });
759
763
  return t;
760
764
  }, [tasks, instructions, cancelRun, showTitles]);
@@ -839,7 +843,7 @@ function TaskList(props) {
839
843
  });
840
844
  }
841
845
  function TaskItem(props) {
842
- var _a;
846
+ var _a2;
843
847
  const {
844
848
  task
845
849
  } = props;
@@ -877,7 +881,7 @@ function TaskItem(props) {
877
881
  muted: true,
878
882
  size: 1,
879
883
  children: /* @__PURE__ */jsxRuntime.jsx(TimeAgo, {
880
- date: (_a = task.ended) != null ? _a : task.started
884
+ date: (_a2 = task.ended) != null ? _a2 : task.started
881
885
  })
882
886
  })]
883
887
  })]
@@ -1329,8 +1333,14 @@ function useOnboardingFeature(featureKey) {
1329
1333
  dismissOnboarding
1330
1334
  };
1331
1335
  }
1332
- const CardWithShadowBelow = styled__default.default(ui.Card)(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\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"])));
1333
- const CardWithShadowAbove = styled__default.default(ui.Card)(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\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"])));
1336
+ var __freeze$4 = Object.freeze;
1337
+ var __defProp$4 = Object.defineProperty;
1338
+ var __template$4 = (cooked, raw) => __freeze$4(__defProp$4(cooked, "raw", {
1339
+ value: __freeze$4(raw || cooked.slice())
1340
+ }));
1341
+ var _a$4, _b$2;
1342
+ const CardWithShadowBelow = styled__default.default(ui.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"])));
1343
+ const CardWithShadowAbove = styled__default.default(ui.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"])));
1334
1344
  function AssistInspectorWrapper(props) {
1335
1345
  const context = useAiAssistanceConfig();
1336
1346
  if (context.statusLoading) {
@@ -1449,11 +1459,11 @@ function AssistInspectorWrapper(props) {
1449
1459
  });
1450
1460
  }
1451
1461
  function AssistInspector(props) {
1452
- var _a, _b;
1462
+ var _a2, _b2;
1453
1463
  const {
1454
1464
  params
1455
1465
  } = useAiPaneRouter();
1456
- const [boundary, setBoundary] = react.useState(null);
1466
+ const boundary = react.useRef(null);
1457
1467
  const pathKey = params == null ? void 0 : params[fieldPathParam];
1458
1468
  const instructionKey = params == null ? void 0 : params[instructionParam];
1459
1469
  const documentPane = desk.useDocumentPane();
@@ -1481,28 +1491,28 @@ function AssistInspector(props) {
1481
1491
  documentId,
1482
1492
  schemaType
1483
1493
  });
1484
- const assistField = (_a = assistDocument == null ? void 0 : assistDocument.fields) == null ? void 0 : _a.find(f => f.path === pathKey);
1485
- const instruction = (_b = assistField == null ? void 0 : assistField.instructions) == null ? void 0 : _b.find(i => i._key === instructionKey);
1494
+ const assistField = (_a2 = assistDocument == null ? void 0 : assistDocument.fields) == null ? void 0 : _a2.find(f => f.path === pathKey);
1495
+ const instruction = (_b2 = assistField == null ? void 0 : assistField.instructions) == null ? void 0 : _b2.find(i => i._key === instructionKey);
1486
1496
  const tasks = react.useMemo(() => {
1487
- var _a2;
1488
- return (_a2 = assistDocument == null ? void 0 : assistDocument.tasks) == null ? void 0 : _a2.filter(i => !instructionKey || i.instructionKey === instructionKey);
1497
+ var _a3;
1498
+ return (_a3 = assistDocument == null ? void 0 : assistDocument.tasks) == null ? void 0 : _a3.filter(i => !instructionKey || i.instructionKey === instructionKey);
1489
1499
  }, [assistDocument == null ? void 0 : assistDocument.tasks, instructionKey]);
1490
1500
  const instructions = react.useMemo(() => {
1491
- var _a2;
1492
- return (_a2 = assistDocument == null ? void 0 : assistDocument.fields) == null ? void 0 : _a2.flatMap(f => {
1493
- var _a3;
1494
- return (_a3 = f.instructions) != null ? _a3 : [];
1501
+ var _a3;
1502
+ return (_a3 = assistDocument == null ? void 0 : assistDocument.fields) == null ? void 0 : _a3.flatMap(f => {
1503
+ var _a4;
1504
+ return (_a4 = f.instructions) != null ? _a4 : [];
1495
1505
  });
1496
1506
  }, [assistDocument == null ? void 0 : assistDocument.fields]);
1497
1507
  const promptValue = instruction == null ? void 0 : instruction.prompt;
1498
1508
  const isEmptyPrompt = react.useMemo(() => {
1499
- var _a2, _b2;
1509
+ var _a3, _b3;
1500
1510
  if (!(promptValue == null ? void 0 : promptValue.length)) {
1501
1511
  return true;
1502
1512
  }
1503
1513
  const firstBlock = promptValue[0];
1504
1514
  const children = firstBlock == null ? void 0 : firstBlock.children;
1505
- return promptValue.length == 1 && (children == null ? void 0 : children.length) === 1 && !((_b2 = (_a2 = children == null ? void 0 : children[0]) == null ? void 0 : _a2.text) == null ? void 0 : _b2.length);
1515
+ 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);
1506
1516
  }, [promptValue]);
1507
1517
  const paneNode = react.useMemo(() => ({
1508
1518
  type: "document",
@@ -1539,7 +1549,7 @@ function AssistInspector(props) {
1539
1549
  });
1540
1550
  }
1541
1551
  return /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
1542
- ref: setBoundary,
1552
+ ref: boundary,
1543
1553
  direction: "column",
1544
1554
  height: "fill",
1545
1555
  overflow: "hidden",
@@ -1565,7 +1575,8 @@ function AssistInspector(props) {
1565
1575
  children: /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
1566
1576
  padding: 4,
1567
1577
  children: selectedField && /* @__PURE__ */jsxRuntime.jsx(sanity.VirtualizerScrollInstanceProvider, {
1568
- scrollElement: boundary,
1578
+ scrollElement: boundary.current,
1579
+ containerElement: boundary,
1569
1580
  children: /* @__PURE__ */jsxRuntime.jsx(desk.DocumentPaneProvider, {
1570
1581
  paneKey: documentPane.paneKey,
1571
1582
  index: documentPane.index,
@@ -1758,8 +1769,14 @@ function aiPresence(presence, path, title) {
1758
1769
  lastActiveAt: (_a = presence == null ? void 0 : presence.started) != null ? _a : /* @__PURE__ */new Date().toISOString()
1759
1770
  };
1760
1771
  }
1761
- const fadeIn = styled.keyframes(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\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"])));
1762
- const FadeInDiv = styled__default.default.div(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n animation-name: ", ";\n animation-timing-function: ease-in-out;\n"])), fadeIn);
1772
+ var __freeze$3 = Object.freeze;
1773
+ var __defProp$3 = Object.defineProperty;
1774
+ var __template$3 = (cooked, raw) => __freeze$3(__defProp$3(cooked, "raw", {
1775
+ value: __freeze$3(raw || cooked.slice())
1776
+ }));
1777
+ var _a$3, _b$1;
1778
+ const fadeIn = styled.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"])));
1779
+ const FadeInDiv = styled__default.default.div(_b$1 || (_b$1 = __template$3(["\n animation-name: ", ";\n animation-timing-function: ease-in-out;\n"])), fadeIn);
1763
1780
  function FadeInContent(_ref7) {
1764
1781
  let {
1765
1782
  children,
@@ -1818,10 +1835,16 @@ const purple = {
1818
1835
  hex: "#211229"
1819
1836
  }
1820
1837
  };
1821
- const Root = styled__default.default.span(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n display: block;\n width: 25px;\n height: 25px;\n position: relative;\n"])));
1822
- const dash = styled.keyframes(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n 0% {\n transform: rotate(0);\n }\n 100% {\n transform: rotate(43deg);\n }\n"])));
1823
- const Outline = styled__default.default.svg(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\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);
1824
- const IconDisc = styled__default.default.span(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["\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"])));
1838
+ var __freeze$2 = Object.freeze;
1839
+ var __defProp$2 = Object.defineProperty;
1840
+ var __template$2 = (cooked, raw) => __freeze$2(__defProp$2(cooked, "raw", {
1841
+ value: __freeze$2(raw || cooked.slice())
1842
+ }));
1843
+ var _a$2, _b, _c, _d;
1844
+ const Root = styled__default.default.span(_a$2 || (_a$2 = __template$2(["\n display: block;\n width: 25px;\n height: 25px;\n position: relative;\n"])));
1845
+ const dash = styled.keyframes(_b || (_b = __template$2(["\n 0% {\n transform: rotate(0);\n }\n 100% {\n transform: rotate(43deg);\n }\n"])));
1846
+ const Outline = styled__default.default.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);
1847
+ const IconDisc = styled__default.default.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"])));
1825
1848
  function AssistAvatar(props) {
1826
1849
  const {
1827
1850
  state = "present"
@@ -2539,7 +2562,7 @@ function AlphaMigration() {
2539
2562
  });
2540
2563
  react.useEffect(() => {
2541
2564
  let canUpdate = true;
2542
- client.fetch("\n {\n \"assistDocs\": *[_type==\"".concat(legacyAssistDocumentTypeName, "\"],\n \"staleStatusDocIds\": *[_type==\"").concat(legacyAssistStatusDocumentTypeName, "\"]._id,\n \"contextDocs\": *[_type==\"").concat(legacyContextDocumentTypeName, "\"],\n }\n ")).then(result => {
2565
+ client.fetch('\n {\n "assistDocs": *[_type=="'.concat(legacyAssistDocumentTypeName, '"],\n "staleStatusDocIds": *[_type=="').concat(legacyAssistStatusDocumentTypeName, '"]._id,\n "contextDocs": *[_type=="').concat(legacyContextDocumentTypeName, '"],\n }\n ')).then(result => {
2543
2566
  var _a, _b, _c;
2544
2567
  if (!canUpdate || !result) {
2545
2568
  return;
@@ -2661,7 +2684,7 @@ async function convertDocs(client, docs, updateProgress) {
2661
2684
  const progressCount = Math.min(docs.length, i + chunkSize);
2662
2685
  const chunk = docs.slice(i, progressCount);
2663
2686
  const trans = client.transaction();
2664
- const contextDocs = await client.fetch("*[_type==\"".concat(contextDocumentTypeName, "\" && _alphaId != null]{_id, _alphaId}"));
2687
+ const contextDocs = await client.fetch('*[_type=="'.concat(contextDocumentTypeName, '" && _alphaId != null]{_id, _alphaId}'));
2665
2688
  chunk.forEach(oldDoc => {
2666
2689
  var _a;
2667
2690
  const documentType = oldDoc._id.replace(new RegExp("^(".concat(legacyAssistDocumentIdPrefix, "|").concat(assistDocumentIdPrefix, ")")), "");
@@ -2769,7 +2792,13 @@ function AssistLayout(props) {
2769
2792
  })]
2770
2793
  });
2771
2794
  }
2772
- const WrapPreCard = styled__default.default(ui.Card)(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["\n & pre {\n white-space: pre-wrap !important;\n }\n"])));
2795
+ var __freeze$1 = Object.freeze;
2796
+ var __defProp$1 = Object.defineProperty;
2797
+ var __template$1 = (cooked, raw) => __freeze$1(__defProp$1(cooked, "raw", {
2798
+ value: __freeze$1(raw || cooked.slice())
2799
+ }));
2800
+ var _a$1;
2801
+ const WrapPreCard = styled__default.default(ui.Card)(_a$1 || (_a$1 = __template$1(["\n & pre {\n white-space: pre-wrap !important;\n }\n"])));
2773
2802
  function SafeValueInput(props) {
2774
2803
  return /* @__PURE__ */jsxRuntime.jsx(ErrorWrapper, {
2775
2804
  onChange: props.onChange,
@@ -3481,7 +3510,7 @@ function HideReferenceChangedBannerInput(props) {
3481
3510
  const style = document.createElement("style");
3482
3511
  const parentId = "id-".concat(Math.random()).replace(".", "-");
3483
3512
  parent.id = parentId;
3484
- style.innerText = "\n #".concat(parentId, " [data-testid=\"reference-changed-banner\"] { display: none; }\n ");
3513
+ style.innerText = "\n #".concat(parentId, ' [data-testid="reference-changed-banner"] { display: none; }\n ');
3485
3514
  parent.prepend(style);
3486
3515
  }, [ref]);
3487
3516
  return /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
@@ -3572,7 +3601,13 @@ function randomKey(length) {
3572
3601
  const table = getByteHexTable();
3573
3602
  return whatwgRNG(length).reduce((str, n) => str + table[n], "").slice(0, length);
3574
3603
  }
3575
- const PteMods = styled__default.default(ui.Box)(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["\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"])));
3604
+ var __freeze = Object.freeze;
3605
+ var __defProp = Object.defineProperty;
3606
+ var __template = (cooked, raw) => __freeze(__defProp(cooked, "raw", {
3607
+ value: __freeze(raw || cooked.slice())
3608
+ }));
3609
+ var _a;
3610
+ const PteMods = styled__default.default(ui.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"])));
3576
3611
  function PromptInput(props) {
3577
3612
  useOnlyInlineBlocks(props);
3578
3613
  return /* @__PURE__ */jsxRuntime.jsx(PteMods, {
@@ -3581,9 +3616,9 @@ function PromptInput(props) {
3581
3616
  }
3582
3617
  function useOnlyInlineBlocks(props) {
3583
3618
  react.useEffect(() => {
3584
- var _a;
3619
+ var _a2;
3585
3620
  let needsFix = false;
3586
- const val = ((_a = props.value) != null ? _a : []).map(block => {
3621
+ const val = ((_a2 = props.value) != null ? _a2 : []).map(block => {
3587
3622
  if (block._type === "block") {
3588
3623
  return block;
3589
3624
  }
@@ -3638,7 +3673,7 @@ const fieldReference = sanity.defineType({
3638
3673
  const refs = getFieldRefsWithDocument(schema);
3639
3674
  const fieldRef = refs.find(r => r.key === value);
3640
3675
  if (!fieldRef) {
3641
- return "Field with path \"".concat(value, "\" does not exist in the schema.");
3676
+ return 'Field with path "'.concat(value, '" does not exist in the schema.');
3642
3677
  }
3643
3678
  return true;
3644
3679
  } catch (e) {