@sanity/embeddings-index-ui 1.1.0 → 1.1.1

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.esm.js CHANGED
@@ -4,7 +4,7 @@ import { Card, Text, Button, Box, Autocomplete, Flex, Spinner, Stack, Label, Tex
4
4
  import { ErrorOutlineIcon, EarthGlobeIcon, LinkIcon, AddIcon, EllipsisVerticalIcon, TrashIcon, UndoIcon } from '@sanity/icons';
5
5
  import require$$0, { createContext, useState, useEffect, useContext, useMemo, useRef, forwardRef, useId, useCallback } from 'react';
6
6
  import { useDocumentPane } from 'sanity/desk';
7
- import { useIntentLink } from 'sanity/router';
7
+ import { useIntentLink, useRouter } from 'sanity/router';
8
8
  function publicId(id) {
9
9
  return id.replace("drafts.", "");
10
10
  }
@@ -1950,7 +1950,7 @@ const SemanticSearchAutocomplete = forwardRef(function SemanticSearchAutocomplet
1950
1950
  readOnly,
1951
1951
  onFocus,
1952
1952
  onBlur,
1953
- onChange,
1953
+ onSelect,
1954
1954
  typeFilter
1955
1955
  } = props;
1956
1956
  const id = useId();
@@ -2018,8 +2018,11 @@ const SemanticSearchAutocomplete = forwardRef(function SemanticSearchAutocomplet
2018
2018
  setOptions(NO_OPTIONS);
2019
2019
  return;
2020
2020
  }
2021
- onChange == null ? void 0 : onChange(value);
2022
- }, [onChange]);
2021
+ const option = options.filter(r => "result" in r).find(r => r.result.value.documentId === value);
2022
+ if (option && onSelect) {
2023
+ onSelect(option.result);
2024
+ }
2025
+ }, [onSelect, options]);
2023
2026
  return /* @__PURE__ */jsx(Autocomplete, {
2024
2027
  id,
2025
2028
  ref,
@@ -2169,13 +2172,13 @@ function SemanticSearchInput(props) {
2169
2172
  }, []);
2170
2173
  const handleFocus = useCallback(() => onPathFocus(["_ref"]), [onPathFocus]);
2171
2174
  const handleBlur = useCallback(() => onPathFocus([]), [onPathFocus]);
2172
- const handleChange = useCallback(nextId => {
2173
- if (!nextId) {
2175
+ const handleChange = useCallback(result => {
2176
+ if (!result) {
2174
2177
  onChange(unset());
2175
2178
  onPathFocus([]);
2176
2179
  return;
2177
2180
  }
2178
- const patches = [setIfMissing({}), set(schemaType.name, ["_type"]), set(publicId(nextId), ["_ref"]), unset(["_weak"]), unset(["_strengthenOnPublish"])];
2181
+ const patches = [setIfMissing({}), set(schemaType.name, ["_type"]), set(publicId(result.value.documentId), ["_ref"]), unset(["_weak"]), unset(["_strengthenOnPublish"])];
2179
2182
  onChange(patches);
2180
2183
  onPathFocus([]);
2181
2184
  }, [onChange, onPathFocus, schemaType.name]);
@@ -2186,7 +2189,7 @@ function SemanticSearchInput(props) {
2186
2189
  ref: autocompleteRef,
2187
2190
  typeFilter,
2188
2191
  indexConfig,
2189
- onChange: handleChange,
2192
+ onSelect: handleChange,
2190
2193
  onFocus: handleFocus,
2191
2194
  onBlur: handleBlur,
2192
2195
  getEmptySearchValue,
@@ -2585,9 +2588,22 @@ function QueryIndex(props) {
2585
2588
  indexName,
2586
2589
  maxResults: 8
2587
2590
  }), [indexName]);
2591
+ const {
2592
+ resolveIntentLink,
2593
+ navigateUrl
2594
+ } = useRouter();
2595
+ const onSelect = useCallback(hit => {
2596
+ navigateUrl({
2597
+ path: resolveIntentLink("edit", {
2598
+ id: hit.value.documentId,
2599
+ type: hit.value.type
2600
+ })
2601
+ });
2602
+ }, [resolveIntentLink, navigateUrl]);
2588
2603
  return /* @__PURE__ */jsx(SemanticSearchAutocomplete, {
2589
2604
  getEmptySearchValue: getEmpty,
2590
- indexConfig
2605
+ indexConfig,
2606
+ onSelect
2591
2607
  });
2592
2608
  }
2593
2609
  function IndexInfo(_ref3) {