@sanity/embeddings-index-ui 1.0.0 → 1.0.2
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.d.ts +1 -1
- package/dist/index.esm.js +34 -39
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +33 -38
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/embeddingsApi.ts +1 -1
- package/src/api/embeddingsApiHooks.ts +12 -7
- package/src/embeddingsIndexDashboard/EmbeddingsIndexTool.tsx +2 -7
- package/src/embeddingsIndexDashboard/QueryIndex.tsx +2 -1
- package/src/preview/DocumentPreview.tsx +7 -11
- package/src/referenceInput/SemanticSearchReferenceInput.tsx +6 -17
package/dist/index.js
CHANGED
|
@@ -1751,20 +1751,12 @@ function DocumentPreview(_ref) {
|
|
|
1751
1751
|
let {
|
|
1752
1752
|
documentId,
|
|
1753
1753
|
style,
|
|
1754
|
+
schemaTypeName,
|
|
1754
1755
|
...buttonProps
|
|
1755
1756
|
} = _ref;
|
|
1756
|
-
const client = sanity.useClient({
|
|
1757
|
-
apiVersion: "2023-06-06"
|
|
1758
|
-
});
|
|
1759
|
-
const [type, setType] = require$$0.useState(void 0);
|
|
1760
1757
|
const schema = sanity.useSchema();
|
|
1761
|
-
const schemaType =
|
|
1762
|
-
|
|
1763
|
-
client.fetch("* [_id==$id]._type", {
|
|
1764
|
-
id: documentId
|
|
1765
|
-
}).then(setType);
|
|
1766
|
-
}, [documentId, client]);
|
|
1767
|
-
if (!type) {
|
|
1758
|
+
const schemaType = schemaTypeName ? schema.get(schemaTypeName) : void 0;
|
|
1759
|
+
if (!schemaTypeName) {
|
|
1768
1760
|
return /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
|
|
1769
1761
|
style: {
|
|
1770
1762
|
minHeight: "36px"
|
|
@@ -1786,7 +1778,7 @@ function DocumentPreview(_ref) {
|
|
|
1786
1778
|
media: () => /* @__PURE__ */jsxRuntime.jsx(icons.ErrorOutlineIcon, {}),
|
|
1787
1779
|
title: /* @__PURE__ */jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1788
1780
|
children: ["Unknown type ", /* @__PURE__ */jsxRuntime.jsx("code", {
|
|
1789
|
-
children:
|
|
1781
|
+
children: schemaTypeName != null ? schemaTypeName : "N/A"
|
|
1790
1782
|
}), " for ", documentId]
|
|
1791
1783
|
})
|
|
1792
1784
|
})
|
|
@@ -1794,6 +1786,7 @@ function DocumentPreview(_ref) {
|
|
|
1794
1786
|
}
|
|
1795
1787
|
return /* @__PURE__ */jsxRuntime.jsx(DocumentPreviewInner, {
|
|
1796
1788
|
documentId,
|
|
1789
|
+
schemaTypeName,
|
|
1797
1790
|
schemaType,
|
|
1798
1791
|
style,
|
|
1799
1792
|
...buttonProps
|
|
@@ -1897,6 +1890,22 @@ function deleteIndex(indexName, client) {
|
|
|
1897
1890
|
function publicId(id) {
|
|
1898
1891
|
return id.replace("drafts.", "");
|
|
1899
1892
|
}
|
|
1893
|
+
function useApiClient() {
|
|
1894
|
+
const client = sanity.useClient({
|
|
1895
|
+
apiVersion: "vX"
|
|
1896
|
+
});
|
|
1897
|
+
return require$$0.useMemo(() => {
|
|
1898
|
+
const customHost = localStorage.getItem("embeddings-index-host");
|
|
1899
|
+
if (customHost) {
|
|
1900
|
+
return client.withConfig({
|
|
1901
|
+
apiHost: customHost,
|
|
1902
|
+
useProjectHostname: false,
|
|
1903
|
+
withCredentials: false
|
|
1904
|
+
});
|
|
1905
|
+
}
|
|
1906
|
+
return client;
|
|
1907
|
+
}, [client]);
|
|
1908
|
+
}
|
|
1900
1909
|
const NO_OPTIONS = [];
|
|
1901
1910
|
const NO_FILTER = () => true;
|
|
1902
1911
|
function SemanticSearchReferenceInput(props) {
|
|
@@ -1937,12 +1946,6 @@ function useDebouncedValue(value, ms) {
|
|
|
1937
1946
|
}, [value, ms]);
|
|
1938
1947
|
return debouncedValue;
|
|
1939
1948
|
}
|
|
1940
|
-
function useApiClient$2() {
|
|
1941
|
-
const client = sanity.useClient({
|
|
1942
|
-
apiVersion: "vX"
|
|
1943
|
-
});
|
|
1944
|
-
return require$$0.useMemo(() => client, [client]);
|
|
1945
|
-
}
|
|
1946
1949
|
function SemanticSearchInput(props) {
|
|
1947
1950
|
const {
|
|
1948
1951
|
onPathFocus,
|
|
@@ -1963,7 +1966,7 @@ function SemanticSearchInput(props) {
|
|
|
1963
1966
|
const prevDebouncedQuery = require$$0.useRef(debouncedQuery);
|
|
1964
1967
|
const [searching, setSearching] = require$$0.useState(false);
|
|
1965
1968
|
const [options, setOptions] = require$$0.useState(NO_OPTIONS);
|
|
1966
|
-
const client = useApiClient
|
|
1969
|
+
const client = useApiClient();
|
|
1967
1970
|
require$$0.useEffect(() => {
|
|
1968
1971
|
docRef.current = currentDocument;
|
|
1969
1972
|
}, [currentDocument]);
|
|
@@ -1976,7 +1979,7 @@ function SemanticSearchInput(props) {
|
|
|
1976
1979
|
const handleFocus = require$$0.useCallback(() => onPathFocus(["_ref"]), [onPathFocus]);
|
|
1977
1980
|
const handleBlur = require$$0.useCallback(() => onPathFocus([]), [onPathFocus]);
|
|
1978
1981
|
const runIndexQuery = require$$0.useCallback(queryString => {
|
|
1979
|
-
var _a, _b, _c, _d;
|
|
1982
|
+
var _a, _b, _c, _d, _e;
|
|
1980
1983
|
setSearching(true);
|
|
1981
1984
|
const refSchema = schemaType;
|
|
1982
1985
|
const indexName = (_b = (_a = refSchema.options) == null ? void 0 : _a.embeddingsIndex) == null ? void 0 : _b.indexName;
|
|
@@ -1986,7 +1989,7 @@ function SemanticSearchInput(props) {
|
|
|
1986
1989
|
throw new Error("Reference option embeddingsIndex.indexName is required, but was missing in type ".concat(refSchema.name));
|
|
1987
1990
|
}
|
|
1988
1991
|
queryIndex({
|
|
1989
|
-
query: queryString,
|
|
1992
|
+
query: queryString.trim().length ? queryString : (_e = JSON.stringify(docRef.current)) != null ? _e : "",
|
|
1990
1993
|
indexName,
|
|
1991
1994
|
maxResults,
|
|
1992
1995
|
filter: {
|
|
@@ -2035,7 +2038,7 @@ function SemanticSearchInput(props) {
|
|
|
2035
2038
|
id,
|
|
2036
2039
|
ref: autocompleteRef,
|
|
2037
2040
|
"data-testid": "semantic-autocomplete",
|
|
2038
|
-
placeholder: "Type to search",
|
|
2041
|
+
placeholder: "Type to search...",
|
|
2039
2042
|
openButton: openButtonConfig,
|
|
2040
2043
|
onFocus: handleFocus,
|
|
2041
2044
|
onChange: handleChange,
|
|
@@ -2049,6 +2052,7 @@ function SemanticSearchInput(props) {
|
|
|
2049
2052
|
});
|
|
2050
2053
|
}
|
|
2051
2054
|
function AutocompleteOption(props) {
|
|
2055
|
+
const value = props.result.value;
|
|
2052
2056
|
return /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
|
|
2053
2057
|
mode: "bleed",
|
|
2054
2058
|
padding: 1,
|
|
@@ -2061,7 +2065,8 @@ function AutocompleteOption(props) {
|
|
|
2061
2065
|
children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
2062
2066
|
flex: 1,
|
|
2063
2067
|
children: /* @__PURE__ */jsxRuntime.jsx(DocumentPreview, {
|
|
2064
|
-
documentId:
|
|
2068
|
+
documentId: value.documentId,
|
|
2069
|
+
schemaTypeName: value.type
|
|
2065
2070
|
})
|
|
2066
2071
|
}), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
2067
2072
|
padding: 2,
|
|
@@ -2100,12 +2105,6 @@ const embeddingsIndexReferenceInput = sanity.definePlugin({
|
|
|
2100
2105
|
}
|
|
2101
2106
|
}
|
|
2102
2107
|
});
|
|
2103
|
-
function useApiClient$1(customApiClient) {
|
|
2104
|
-
const client = sanity.useClient({
|
|
2105
|
-
apiVersion: "vX"
|
|
2106
|
-
});
|
|
2107
|
-
return require$$0.useMemo(() => customApiClient ? customApiClient(client) : client, [client, customApiClient]);
|
|
2108
|
-
}
|
|
2109
2108
|
const defaultProjection = "{...}";
|
|
2110
2109
|
function useDefaultIndex(schema, dataset) {
|
|
2111
2110
|
const defaultFilter = require$$0.useMemo(() => "_type in [".concat(schema.getTypeNames().map(n => schema.get(n)).filter(schemaType => Boolean(schemaType && isType(schemaType, "document"))).filter(documentType => !documentType.name.startsWith("sanity.") && !documentType.name.startsWith("assist.") && documentType.name !== "document").map(documentType => '"'.concat(documentType.name, '"')).join(",\n"), "]"), [schema]);
|
|
@@ -2222,7 +2221,7 @@ function IndexEditor(props) {
|
|
|
2222
2221
|
index: selectedIndex,
|
|
2223
2222
|
onSubmit
|
|
2224
2223
|
} = props;
|
|
2225
|
-
const client = useApiClient
|
|
2224
|
+
const client = useApiClient();
|
|
2226
2225
|
const schema = sanity.useSchema();
|
|
2227
2226
|
const defaultIndex = useDefaultIndex(schema, (_a = client.config().dataset) != null ? _a : "");
|
|
2228
2227
|
const [errors, setErrors] = require$$0.useState();
|
|
@@ -2442,7 +2441,7 @@ function QueryIndex(props) {
|
|
|
2442
2441
|
const [query, setQuery] = require$$0.useState("");
|
|
2443
2442
|
const [searching, setSearching] = require$$0.useState(false);
|
|
2444
2443
|
const [results, setResults] = require$$0.useState(NO_RESULTS);
|
|
2445
|
-
const client = useApiClient
|
|
2444
|
+
const client = useApiClient();
|
|
2446
2445
|
const search = require$$0.useCallback(queryString => {
|
|
2447
2446
|
setSearching(true);
|
|
2448
2447
|
return queryIndex({
|
|
@@ -2512,13 +2511,15 @@ function ResultList(props) {
|
|
|
2512
2511
|
});
|
|
2513
2512
|
}
|
|
2514
2513
|
function ResultEntry(props) {
|
|
2514
|
+
const value = props.result.value;
|
|
2515
2515
|
return /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
|
|
2516
2516
|
gap: 4,
|
|
2517
2517
|
align: "center",
|
|
2518
2518
|
children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
2519
2519
|
flex: 1,
|
|
2520
2520
|
children: /* @__PURE__ */jsxRuntime.jsx(DocumentPreview, {
|
|
2521
|
-
documentId:
|
|
2521
|
+
documentId: value.documentId,
|
|
2522
|
+
schemaTypeName: value.type,
|
|
2522
2523
|
button: true
|
|
2523
2524
|
})
|
|
2524
2525
|
}), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
|
|
@@ -2658,12 +2659,6 @@ function IndexStatus(_ref4) {
|
|
|
2658
2659
|
})]
|
|
2659
2660
|
});
|
|
2660
2661
|
}
|
|
2661
|
-
function useApiClient() {
|
|
2662
|
-
const client = sanity.useClient({
|
|
2663
|
-
apiVersion: "vX"
|
|
2664
|
-
});
|
|
2665
|
-
return require$$0.useMemo(() => client, [client]);
|
|
2666
|
-
}
|
|
2667
2662
|
function EmbeddingsIndexTool() {
|
|
2668
2663
|
return /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
|
|
2669
2664
|
children: /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
|