@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.js CHANGED
@@ -1961,7 +1961,7 @@ const SemanticSearchAutocomplete = require$$0.forwardRef(function SemanticSearch
1961
1961
  readOnly,
1962
1962
  onFocus,
1963
1963
  onBlur,
1964
- onChange,
1964
+ onSelect,
1965
1965
  typeFilter
1966
1966
  } = props;
1967
1967
  const id = require$$0.useId();
@@ -2029,8 +2029,11 @@ const SemanticSearchAutocomplete = require$$0.forwardRef(function SemanticSearch
2029
2029
  setOptions(NO_OPTIONS);
2030
2030
  return;
2031
2031
  }
2032
- onChange == null ? void 0 : onChange(value);
2033
- }, [onChange]);
2032
+ const option = options.filter(r => "result" in r).find(r => r.result.value.documentId === value);
2033
+ if (option && onSelect) {
2034
+ onSelect(option.result);
2035
+ }
2036
+ }, [onSelect, options]);
2034
2037
  return /* @__PURE__ */jsxRuntime.jsx(ui.Autocomplete, {
2035
2038
  id,
2036
2039
  ref,
@@ -2180,13 +2183,13 @@ function SemanticSearchInput(props) {
2180
2183
  }, []);
2181
2184
  const handleFocus = require$$0.useCallback(() => onPathFocus(["_ref"]), [onPathFocus]);
2182
2185
  const handleBlur = require$$0.useCallback(() => onPathFocus([]), [onPathFocus]);
2183
- const handleChange = require$$0.useCallback(nextId => {
2184
- if (!nextId) {
2186
+ const handleChange = require$$0.useCallback(result => {
2187
+ if (!result) {
2185
2188
  onChange(sanity.unset());
2186
2189
  onPathFocus([]);
2187
2190
  return;
2188
2191
  }
2189
- const patches = [sanity.setIfMissing({}), sanity.set(schemaType.name, ["_type"]), sanity.set(publicId(nextId), ["_ref"]), sanity.unset(["_weak"]), sanity.unset(["_strengthenOnPublish"])];
2192
+ const patches = [sanity.setIfMissing({}), sanity.set(schemaType.name, ["_type"]), sanity.set(publicId(result.value.documentId), ["_ref"]), sanity.unset(["_weak"]), sanity.unset(["_strengthenOnPublish"])];
2190
2193
  onChange(patches);
2191
2194
  onPathFocus([]);
2192
2195
  }, [onChange, onPathFocus, schemaType.name]);
@@ -2197,7 +2200,7 @@ function SemanticSearchInput(props) {
2197
2200
  ref: autocompleteRef,
2198
2201
  typeFilter,
2199
2202
  indexConfig,
2200
- onChange: handleChange,
2203
+ onSelect: handleChange,
2201
2204
  onFocus: handleFocus,
2202
2205
  onBlur: handleBlur,
2203
2206
  getEmptySearchValue,
@@ -2596,9 +2599,22 @@ function QueryIndex(props) {
2596
2599
  indexName,
2597
2600
  maxResults: 8
2598
2601
  }), [indexName]);
2602
+ const {
2603
+ resolveIntentLink,
2604
+ navigateUrl
2605
+ } = router.useRouter();
2606
+ const onSelect = require$$0.useCallback(hit => {
2607
+ navigateUrl({
2608
+ path: resolveIntentLink("edit", {
2609
+ id: hit.value.documentId,
2610
+ type: hit.value.type
2611
+ })
2612
+ });
2613
+ }, [resolveIntentLink, navigateUrl]);
2599
2614
  return /* @__PURE__ */jsxRuntime.jsx(SemanticSearchAutocomplete, {
2600
2615
  getEmptySearchValue: getEmpty,
2601
- indexConfig
2616
+ indexConfig,
2617
+ onSelect
2602
2618
  });
2603
2619
  }
2604
2620
  function IndexInfo(_ref3) {