@sanity/embeddings-index-ui 2.1.0 → 3.0.0
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 +53 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var icons = require("@sanity/icons"), sanity = require("sanity"), jsxRuntime = require("react/jsx-runtime"), ui = require("@sanity/ui"),
|
|
3
|
+
var icons = require("@sanity/icons"), sanity = require("sanity"), jsxRuntime = require("react/jsx-runtime"), ui = require("@sanity/ui"), React = require("react"), router = require("sanity/router"), desk = require("sanity/desk");
|
|
4
4
|
function _interopDefaultCompat(e) {
|
|
5
5
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
6
|
}
|
|
7
|
-
var
|
|
7
|
+
var React__default = /* @__PURE__ */ _interopDefaultCompat(React);
|
|
8
8
|
function queryIndex(queryConfig, client) {
|
|
9
9
|
const { query, indexName, maxResults, filter } = queryConfig, projectId = client.config().projectId, dataset = client.config().dataset, queryString = query?.trim();
|
|
10
10
|
return client.request({
|
|
@@ -33,7 +33,7 @@ function deleteIndex(indexName, client) {
|
|
|
33
33
|
}
|
|
34
34
|
function useApiClient() {
|
|
35
35
|
const client = sanity.useClient({ apiVersion: "vX" });
|
|
36
|
-
return
|
|
36
|
+
return React.useMemo(() => {
|
|
37
37
|
const customHost = localStorage.getItem("embeddings-index-host");
|
|
38
38
|
return customHost ? client.withConfig({
|
|
39
39
|
apiHost: customHost,
|
|
@@ -42,10 +42,10 @@ function useApiClient() {
|
|
|
42
42
|
}) : client;
|
|
43
43
|
}, [client]);
|
|
44
44
|
}
|
|
45
|
-
const FeatureEnabledContext =
|
|
45
|
+
const FeatureEnabledContext = React.createContext("loading");
|
|
46
46
|
function useIsFeatureEnabled() {
|
|
47
|
-
const client = useApiClient(), [status, setStatus] =
|
|
48
|
-
return
|
|
47
|
+
const client = useApiClient(), [status, setStatus] = React.useState("loading");
|
|
48
|
+
return React.useEffect(() => {
|
|
49
49
|
client.request({
|
|
50
50
|
method: "GET",
|
|
51
51
|
url: "/embeddings-index/status"
|
|
@@ -61,7 +61,7 @@ function FeatureEnabledProvider(props) {
|
|
|
61
61
|
return /* @__PURE__ */ jsxRuntime.jsx(FeatureEnabledContext.Provider, { value: status, children: props.children });
|
|
62
62
|
}
|
|
63
63
|
function useIsFeatureEnabledContext() {
|
|
64
|
-
return
|
|
64
|
+
return React.useContext(FeatureEnabledContext);
|
|
65
65
|
}
|
|
66
66
|
function FeatureDisabledNotice(props) {
|
|
67
67
|
const projectId = sanity.useProjectId();
|
|
@@ -79,7 +79,7 @@ function isType(schemaType, typeName) {
|
|
|
79
79
|
}
|
|
80
80
|
const defaultProjection = "{...}";
|
|
81
81
|
function useDefaultIndex(schema, dataset) {
|
|
82
|
-
const defaultFilter =
|
|
82
|
+
const defaultFilter = React.useMemo(
|
|
83
83
|
() => `_type in [${schema.getTypeNames().map((n) => schema.get(n)).filter(
|
|
84
84
|
(schemaType) => !!(schemaType && isType(schemaType, "document"))
|
|
85
85
|
).filter(
|
|
@@ -88,7 +88,7 @@ function useDefaultIndex(schema, dataset) {
|
|
|
88
88
|
`)}]`,
|
|
89
89
|
[schema]
|
|
90
90
|
);
|
|
91
|
-
return
|
|
91
|
+
return React.useMemo(
|
|
92
92
|
() => ({
|
|
93
93
|
dataset,
|
|
94
94
|
projection: defaultProjection,
|
|
@@ -98,7 +98,7 @@ function useDefaultIndex(schema, dataset) {
|
|
|
98
98
|
);
|
|
99
99
|
}
|
|
100
100
|
function IndexFormInput(props) {
|
|
101
|
-
const { label, description, index, prop, onChange, readOnly, placeholder, type } = props, handleChange =
|
|
101
|
+
const { label, description, index, prop, onChange, readOnly, placeholder, type } = props, handleChange = React.useCallback(
|
|
102
102
|
(propValue) => onChange((current) => ({ ...current, [prop]: propValue })),
|
|
103
103
|
[onChange, prop]
|
|
104
104
|
);
|
|
@@ -116,7 +116,7 @@ function IndexFormInput(props) {
|
|
|
116
116
|
);
|
|
117
117
|
}
|
|
118
118
|
function FormInput(props) {
|
|
119
|
-
const { label, description, onChange, value, readOnly, placeholder, type = "text" } = props, id =
|
|
119
|
+
const { label, description, onChange, value, readOnly, placeholder, type = "text" } = props, id = React.useId(), handleChange = React.useCallback(
|
|
120
120
|
(e) => onChange(e.currentTarget.value),
|
|
121
121
|
[onChange]
|
|
122
122
|
);
|
|
@@ -147,11 +147,11 @@ function FormInput(props) {
|
|
|
147
147
|
] });
|
|
148
148
|
}
|
|
149
149
|
function EditIndexDialog(props) {
|
|
150
|
-
const { open, onClose, onSubmit } = props, id =
|
|
151
|
-
|
|
150
|
+
const { open, onClose, onSubmit } = props, id = React.useId(), ref = React.useRef(null);
|
|
151
|
+
React.useEffect(() => {
|
|
152
152
|
open && setTimeout(() => ref.current?.querySelector("input")?.focus());
|
|
153
153
|
}, [ref, open]);
|
|
154
|
-
const handleSubmit =
|
|
154
|
+
const handleSubmit = React.useCallback(
|
|
155
155
|
(index) => {
|
|
156
156
|
onSubmit(index), onClose();
|
|
157
157
|
},
|
|
@@ -160,12 +160,12 @@ function EditIndexDialog(props) {
|
|
|
160
160
|
return open ? /* @__PURE__ */ jsxRuntime.jsx(ui.Dialog, { id, width: 1, ref, onClose, header: "Create embeddings index", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { padding: 4, space: 5, children: /* @__PURE__ */ jsxRuntime.jsx(IndexEditor, { readOnly: !1, onSubmit: handleSubmit }) }) }) : null;
|
|
161
161
|
}
|
|
162
162
|
function IndexEditor(props) {
|
|
163
|
-
const { readOnly, index: selectedIndex, onSubmit } = props, client = useApiClient(), schema = sanity.useSchema(), defaultIndex = useDefaultIndex(schema, client.config().dataset ?? ""), [errors, setErrors] =
|
|
163
|
+
const { readOnly, index: selectedIndex, onSubmit } = props, client = useApiClient(), schema = sanity.useSchema(), defaultIndex = useDefaultIndex(schema, client.config().dataset ?? ""), [errors, setErrors] = React.useState(), [loading, setLoading] = React.useState(), [index, setIndex] = React.useState(() => ({
|
|
164
164
|
...defaultIndex,
|
|
165
165
|
...selectedIndex
|
|
166
166
|
}));
|
|
167
|
-
|
|
168
|
-
const handleSubmit =
|
|
167
|
+
React.useEffect(() => setIndex(selectedIndex ?? { ...defaultIndex }), [selectedIndex, defaultIndex]);
|
|
168
|
+
const handleSubmit = React.useCallback(
|
|
169
169
|
(e) => {
|
|
170
170
|
if (e.preventDefault(), readOnly)
|
|
171
171
|
return;
|
|
@@ -287,16 +287,16 @@ function requireDist() {
|
|
|
287
287
|
renderCounterRegistry: () => renderCounterRegistry,
|
|
288
288
|
useRenderCounter: () => useRenderCounter
|
|
289
289
|
}), dist = __toCommonJS(index_exports);
|
|
290
|
-
var
|
|
290
|
+
var React2 = __toESM(React__default.default), { useRef, useEffect, isValidElement } = React2, _a, ReactSecretInternals = (
|
|
291
291
|
//@ts-ignore
|
|
292
|
-
(_a =
|
|
292
|
+
(_a = React2.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE) != null ? _a : React2.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
|
|
293
293
|
), $empty = Symbol.for("react.memo_cache_sentinel"), _a2, c = (
|
|
294
294
|
// @ts-expect-error
|
|
295
|
-
typeof ((_a2 =
|
|
295
|
+
typeof ((_a2 = React2.__COMPILER_RUNTIME) == null ? void 0 : _a2.c) == "function" ? (
|
|
296
296
|
// @ts-expect-error
|
|
297
|
-
|
|
297
|
+
React2.__COMPILER_RUNTIME.c
|
|
298
298
|
) : function(size) {
|
|
299
|
-
return
|
|
299
|
+
return React2.useMemo(() => {
|
|
300
300
|
const $ = new Array(size);
|
|
301
301
|
for (let ii = 0; ii < size; ii++)
|
|
302
302
|
$[ii] = $empty;
|
|
@@ -1646,7 +1646,7 @@ function timer(dueTime, intervalOrScheduler, scheduler) {
|
|
|
1646
1646
|
scheduler === void 0 && (scheduler = async);
|
|
1647
1647
|
var intervalDuration = -1;
|
|
1648
1648
|
return intervalOrScheduler != null && (isScheduler(intervalOrScheduler) ? scheduler = intervalOrScheduler : intervalDuration = intervalOrScheduler), new Observable(function(subscriber) {
|
|
1649
|
-
var due = isValidDate(dueTime) ?
|
|
1649
|
+
var due = isValidDate(dueTime) ? +dueTime - scheduler.now() : dueTime;
|
|
1650
1650
|
due < 0 && (due = 0);
|
|
1651
1651
|
var n = 0;
|
|
1652
1652
|
return scheduler.schedule(function() {
|
|
@@ -1784,7 +1784,7 @@ function useObservable(observable2, initialValue) {
|
|
|
1784
1784
|
let t3;
|
|
1785
1785
|
$[4] !== initialValue || $[5] !== instance ? (t3 = () => instance.getSnapshot(initialValue), $[4] = initialValue, $[5] = instance, $[6] = t3) : t3 = $[6];
|
|
1786
1786
|
let t4;
|
|
1787
|
-
return $[7] !== initialValue ? (t4 = typeof initialValue > "u" ? void 0 : () => getValue(initialValue), $[7] = initialValue, $[8] = t4) : t4 = $[8],
|
|
1787
|
+
return $[7] !== initialValue ? (t4 = typeof initialValue > "u" ? void 0 : () => getValue(initialValue), $[7] = initialValue, $[8] = t4) : t4 = $[8], React.useSyncExternalStore(subscribe, t3, t4);
|
|
1788
1788
|
}
|
|
1789
1789
|
function _temp4() {
|
|
1790
1790
|
return timer(0, asapScheduler);
|
|
@@ -1849,7 +1849,7 @@ function DocumentPreviewInner({
|
|
|
1849
1849
|
style,
|
|
1850
1850
|
button
|
|
1851
1851
|
}) {
|
|
1852
|
-
const documentPreviewStore = sanity.useDocumentPreviewStore(), previewStateObservable =
|
|
1852
|
+
const documentPreviewStore = sanity.useDocumentPreviewStore(), previewStateObservable = React.useMemo(
|
|
1853
1853
|
() => sanity.getPreviewStateObservable(documentPreviewStore, schemaType, documentId),
|
|
1854
1854
|
[documentId, documentPreviewStore, schemaType]
|
|
1855
1855
|
), {
|
|
@@ -1860,7 +1860,7 @@ function DocumentPreviewInner({
|
|
|
1860
1860
|
snapshot: null,
|
|
1861
1861
|
isLoading: !0,
|
|
1862
1862
|
original: null
|
|
1863
|
-
}), sanityDocument =
|
|
1863
|
+
}), sanityDocument = React.useMemo(() => ({
|
|
1864
1864
|
_id: documentId,
|
|
1865
1865
|
_type: schemaType?.name
|
|
1866
1866
|
}), [documentId, schemaType?.name]), { onClick: onIntentClick, href } = router.useIntentLink({
|
|
@@ -1894,7 +1894,7 @@ function DocumentPreviewInner({
|
|
|
1894
1894
|
}
|
|
1895
1895
|
) : /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { style: { width: "100%" }, children: preview });
|
|
1896
1896
|
}
|
|
1897
|
-
const NO_RESULTS_VALUE = "", NO_OPTIONS = [], NO_FILTER = () => !0, SemanticSearchAutocomplete =
|
|
1897
|
+
const NO_RESULTS_VALUE = "", NO_OPTIONS = [], NO_FILTER = () => !0, SemanticSearchAutocomplete = React.forwardRef(function(props, ref) {
|
|
1898
1898
|
const {
|
|
1899
1899
|
indexConfig,
|
|
1900
1900
|
filterResult,
|
|
@@ -1904,7 +1904,7 @@ const NO_RESULTS_VALUE = "", NO_OPTIONS = [], NO_FILTER = () => !0, SemanticSear
|
|
|
1904
1904
|
onBlur,
|
|
1905
1905
|
onSelect,
|
|
1906
1906
|
typeFilter
|
|
1907
|
-
} = props, id =
|
|
1907
|
+
} = props, id = React.useId(), [query, setQuery] = React.useState(""), queryRef = React.useRef(query), debouncedQuery = useDebouncedValue(query, 300), prevDebouncedQuery = React.useRef(debouncedQuery), [searching, setSearching] = React.useState(!1), [options, setOptions] = React.useState(NO_OPTIONS), client = useApiClient(), runIndexQuery = React.useCallback(
|
|
1908
1908
|
(queryString) => {
|
|
1909
1909
|
setSearching(!0);
|
|
1910
1910
|
const indexName = indexConfig?.indexName, maxResults = indexConfig?.maxResults;
|
|
@@ -1932,19 +1932,19 @@ const NO_RESULTS_VALUE = "", NO_OPTIONS = [], NO_FILTER = () => !0, SemanticSear
|
|
|
1932
1932
|
},
|
|
1933
1933
|
[client, indexConfig, getEmptySearchValue, filterResult, typeFilter]
|
|
1934
1934
|
);
|
|
1935
|
-
|
|
1935
|
+
React.useEffect(() => {
|
|
1936
1936
|
prevDebouncedQuery.current !== debouncedQuery && runIndexQuery(debouncedQuery), prevDebouncedQuery.current = debouncedQuery;
|
|
1937
1937
|
}, [debouncedQuery, runIndexQuery]);
|
|
1938
|
-
const openButtonConfig =
|
|
1938
|
+
const openButtonConfig = React.useMemo(
|
|
1939
1939
|
() => ({ onClick: () => runIndexQuery(queryRef.current) }),
|
|
1940
1940
|
[runIndexQuery, queryRef]
|
|
1941
|
-
), handleQueryChange =
|
|
1941
|
+
), handleQueryChange = React.useCallback(
|
|
1942
1942
|
(newValue) => {
|
|
1943
1943
|
const newQuery = newValue ?? "";
|
|
1944
1944
|
queryRef.current = newQuery, setQuery(newQuery);
|
|
1945
1945
|
},
|
|
1946
1946
|
[setQuery]
|
|
1947
|
-
), handleChange =
|
|
1947
|
+
), handleChange = React.useCallback(
|
|
1948
1948
|
(value) => {
|
|
1949
1949
|
if (value === NO_RESULTS_VALUE) {
|
|
1950
1950
|
setOptions(NO_OPTIONS);
|
|
@@ -1989,8 +1989,8 @@ function AutocompleteOption(props) {
|
|
|
1989
1989
|
return /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { mode: "bleed", padding: 1, style: { width: "100%" }, disabled: !0, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Flex, { gap: 2, align: "center", children: "No results." }) });
|
|
1990
1990
|
}
|
|
1991
1991
|
function useDebouncedValue(value, ms) {
|
|
1992
|
-
const [debouncedValue, setDebouncedValue] =
|
|
1993
|
-
return
|
|
1992
|
+
const [debouncedValue, setDebouncedValue] = React.useState(value);
|
|
1993
|
+
return React.useEffect(() => {
|
|
1994
1994
|
const timeoutId = setTimeout(() => {
|
|
1995
1995
|
setDebouncedValue(value);
|
|
1996
1996
|
}, ms);
|
|
@@ -1998,10 +1998,10 @@ function useDebouncedValue(value, ms) {
|
|
|
1998
1998
|
}, [value, ms]), debouncedValue;
|
|
1999
1999
|
}
|
|
2000
2000
|
function QueryIndex(props) {
|
|
2001
|
-
const { indexName } = props, getEmpty =
|
|
2001
|
+
const { indexName } = props, getEmpty = React.useCallback(() => "anything", []), indexConfig = React.useMemo(
|
|
2002
2002
|
() => ({ indexName, maxResults: 8 }),
|
|
2003
2003
|
[indexName]
|
|
2004
|
-
), { resolveIntentLink, navigateUrl } = router.useRouter(), onSelect =
|
|
2004
|
+
), { resolveIntentLink, navigateUrl } = router.useRouter(), onSelect = React.useCallback(
|
|
2005
2005
|
(hit) => {
|
|
2006
2006
|
navigateUrl({
|
|
2007
2007
|
path: resolveIntentLink("edit", { id: hit.value.documentId, type: hit.value.type })
|
|
@@ -2019,7 +2019,7 @@ function QueryIndex(props) {
|
|
|
2019
2019
|
);
|
|
2020
2020
|
}
|
|
2021
2021
|
function IndexInfo({ selectedIndex, onDeleteIndex }) {
|
|
2022
|
-
const handleDelete =
|
|
2022
|
+
const handleDelete = React.useCallback(
|
|
2023
2023
|
() => onDeleteIndex(selectedIndex),
|
|
2024
2024
|
[selectedIndex, onDeleteIndex]
|
|
2025
2025
|
);
|
|
@@ -2109,7 +2109,7 @@ function IndexList(props) {
|
|
|
2109
2109
|
] }) });
|
|
2110
2110
|
}
|
|
2111
2111
|
function IndexRow(props) {
|
|
2112
|
-
const { selectedIndex, index, onIndexSelected } = props, onSelect =
|
|
2112
|
+
const { selectedIndex, index, onIndexSelected } = props, onSelect = React.useCallback(() => onIndexSelected(index), [onIndexSelected, index]);
|
|
2113
2113
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2114
2114
|
ui.Button,
|
|
2115
2115
|
{
|
|
@@ -2143,11 +2143,11 @@ function EmbeddingsIndexTool() {
|
|
|
2143
2143
|
}
|
|
2144
2144
|
const NO_INDEXES = [];
|
|
2145
2145
|
function Indexes() {
|
|
2146
|
-
const client = useApiClient(), [indexes, setIndexes] =
|
|
2147
|
-
|
|
2146
|
+
const client = useApiClient(), [indexes, setIndexes] = React.useState(NO_INDEXES), [loading, setLoading] = React.useState(!1), [error, setError] = React.useState(!1), [createIndexOpen, setCreateIndexOpen] = React.useState(!1), [selectedIndex, setSelectedIndex] = React.useState(void 0), onCreateIndexClose = React.useCallback(() => setCreateIndexOpen(!1), []);
|
|
2147
|
+
React.useEffect(() => {
|
|
2148
2148
|
setSelectedIndex(indexes.find((i) => i.indexName === selectedIndex?.indexName));
|
|
2149
2149
|
}, [indexes, selectedIndex]);
|
|
2150
|
-
const updateIndexes =
|
|
2150
|
+
const updateIndexes = React.useCallback(() => {
|
|
2151
2151
|
setLoading(!0), setError(!1), getIndexes(client).then((response) => {
|
|
2152
2152
|
setLoading(!1), setIndexes(response);
|
|
2153
2153
|
}).catch((e) => {
|
|
@@ -2155,7 +2155,7 @@ function Indexes() {
|
|
|
2155
2155
|
}).finally(() => {
|
|
2156
2156
|
setLoading(!1);
|
|
2157
2157
|
});
|
|
2158
|
-
}, [client]), deleteNamedIndex =
|
|
2158
|
+
}, [client]), deleteNamedIndex = React.useCallback(
|
|
2159
2159
|
(index) => {
|
|
2160
2160
|
confirm(`Are you sure you want to delete ${index.indexName} for dataset ${index.dataset}?`) && (setLoading(!0), setError(!1), deleteIndex(index.indexName, client).then(() => {
|
|
2161
2161
|
setTimeout(() => updateIndexes());
|
|
@@ -2166,16 +2166,16 @@ function Indexes() {
|
|
|
2166
2166
|
}));
|
|
2167
2167
|
},
|
|
2168
2168
|
[client, updateIndexes]
|
|
2169
|
-
), onSelectIndex =
|
|
2169
|
+
), onSelectIndex = React.useCallback(
|
|
2170
2170
|
(index) => {
|
|
2171
2171
|
setSelectedIndex(index), updateIndexes();
|
|
2172
2172
|
},
|
|
2173
2173
|
[setSelectedIndex, updateIndexes]
|
|
2174
2174
|
);
|
|
2175
|
-
|
|
2175
|
+
React.useEffect(() => {
|
|
2176
2176
|
updateIndexes();
|
|
2177
2177
|
}, [updateIndexes]);
|
|
2178
|
-
const openCreate =
|
|
2178
|
+
const openCreate = React.useCallback(() => setCreateIndexOpen(!0), []), onSubmit = React.useCallback(
|
|
2179
2179
|
(index) => {
|
|
2180
2180
|
setIndexes((current) => [...current, index]), setSelectedIndex(index), updateIndexes();
|
|
2181
2181
|
},
|
|
@@ -2234,7 +2234,7 @@ function publicId(id) {
|
|
|
2234
2234
|
return id.replace("drafts.", "");
|
|
2235
2235
|
}
|
|
2236
2236
|
function useEmeddingsConfig(embeddingsIndexConfig, defaultConfig) {
|
|
2237
|
-
return
|
|
2237
|
+
return React.useMemo(() => {
|
|
2238
2238
|
if (embeddingsIndexConfig === !0 || !embeddingsIndexConfig) {
|
|
2239
2239
|
if (!defaultConfig?.indexName)
|
|
2240
2240
|
throw new Error(
|
|
@@ -2254,7 +2254,7 @@ function useEmeddingsConfig(embeddingsIndexConfig, defaultConfig) {
|
|
|
2254
2254
|
}, [defaultConfig, embeddingsIndexConfig]);
|
|
2255
2255
|
}
|
|
2256
2256
|
function SemanticSearchReferenceInput(props) {
|
|
2257
|
-
const embeddingsIndexConfig = props.schemaType?.options?.embeddingsIndex, config2 = useEmeddingsConfig(embeddingsIndexConfig, props.defaultConfig), defaultEnabled = config2.searchMode === "embeddings", featureState = useIsFeatureEnabledContext(), [semantic, setSemantic] =
|
|
2257
|
+
const embeddingsIndexConfig = props.schemaType?.options?.embeddingsIndex, config2 = useEmeddingsConfig(embeddingsIndexConfig, props.defaultConfig), defaultEnabled = config2.searchMode === "embeddings", featureState = useIsFeatureEnabledContext(), [semantic, setSemantic] = React.useState(defaultEnabled), toggleSemantic = React.useCallback(() => setSemantic((current) => !current), []);
|
|
2258
2258
|
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 2, flex: 1, style: { width: "100%" }, children: [
|
|
2259
2259
|
semantic && featureState == "loading" ? /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { padding: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Spinner, {}) }) : null,
|
|
2260
2260
|
semantic && featureState == "disabled" ? /* @__PURE__ */ jsxRuntime.jsx(FeatureDisabledNotice, { urlSuffix: "?ref=embeddings-ref" }) : null,
|
|
@@ -2272,13 +2272,13 @@ function SemanticSearchReferenceInput(props) {
|
|
|
2272
2272
|
] });
|
|
2273
2273
|
}
|
|
2274
2274
|
function SemanticSearchInput(props) {
|
|
2275
|
-
const { indexConfig, onPathFocus, onChange, readOnly, schemaType, value } = props, { value: currentDocument } = desk.useDocumentPane(), docRef =
|
|
2276
|
-
|
|
2275
|
+
const { indexConfig, onPathFocus, onChange, readOnly, schemaType, value } = props, { value: currentDocument } = desk.useDocumentPane(), docRef = React.useRef(currentDocument), autocompleteRef = React.useRef(null);
|
|
2276
|
+
React.useEffect(() => {
|
|
2277
2277
|
docRef.current = currentDocument;
|
|
2278
|
-
}, [currentDocument]),
|
|
2278
|
+
}, [currentDocument]), React.useEffect(() => {
|
|
2279
2279
|
value?._ref && autocompleteRef.current?.focus();
|
|
2280
2280
|
}, []);
|
|
2281
|
-
const handleFocus =
|
|
2281
|
+
const handleFocus = React.useCallback(() => onPathFocus(["_ref"]), [onPathFocus]), handleBlur = React.useCallback(() => onPathFocus([]), [onPathFocus]), handleChange = React.useCallback(
|
|
2282
2282
|
(result) => {
|
|
2283
2283
|
if (!result) {
|
|
2284
2284
|
onChange(sanity.unset()), onPathFocus([]);
|
|
@@ -2294,10 +2294,10 @@ function SemanticSearchInput(props) {
|
|
|
2294
2294
|
onChange(patches), onPathFocus([]);
|
|
2295
2295
|
},
|
|
2296
2296
|
[onChange, onPathFocus, schemaType.name]
|
|
2297
|
-
), filterResult =
|
|
2297
|
+
), filterResult = React.useCallback(
|
|
2298
2298
|
(r) => r.value.documentId !== publicId(docRef.current._id),
|
|
2299
2299
|
[docRef]
|
|
2300
|
-
), getEmptySearchValue =
|
|
2300
|
+
), getEmptySearchValue = React.useCallback(() => JSON.stringify(docRef.current), [docRef]), typeFilter = React.useMemo(
|
|
2301
2301
|
() => schemaType.to.map((refType) => refType.name),
|
|
2302
2302
|
[schemaType]
|
|
2303
2303
|
);
|