@sanity/embeddings-index-ui 2.0.1 → 2.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
@@ -1,120 +1,547 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true
5
- });
6
- var sanity = require('sanity');
7
- var jsxRuntime = require('react/jsx-runtime');
8
- var ui = require('@sanity/ui');
9
- var icons = require('@sanity/icons');
10
- var require$$0 = require('react');
11
- var desk = require('sanity/desk');
12
- var router = require('sanity/router');
1
+ "use strict";
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"), require$$0 = require("react"), router = require("sanity/router"), desk = require("sanity/desk");
13
4
  function _interopDefaultCompat(e) {
14
- return e && typeof e === 'object' && 'default' in e ? e : {
15
- default: e
16
- };
5
+ return e && typeof e == "object" && "default" in e ? e : { default: e };
17
6
  }
18
- var require$$0__default = /*#__PURE__*/_interopDefaultCompat(require$$0);
19
- function publicId(id) {
20
- return id.replace("drafts.", "");
7
+ var require$$0__default = /* @__PURE__ */ _interopDefaultCompat(require$$0);
8
+ function queryIndex(queryConfig, client) {
9
+ const { query, indexName, maxResults, filter } = queryConfig, projectId = client.config().projectId, dataset = client.config().dataset, queryString = query?.trim();
10
+ return client.request({
11
+ method: "POST",
12
+ url: `/embeddings-index/query/${dataset}/${indexName}?projectId=${projectId}`,
13
+ body: {
14
+ query: queryString,
15
+ maxResults,
16
+ filter
17
+ }
18
+ });
21
19
  }
22
- function useApiClient() {
23
- const client = sanity.useClient({
24
- apiVersion: "vX"
20
+ function getIndexes(client) {
21
+ const projectId = client.config().projectId, dataset = client.config().dataset;
22
+ return client.request({
23
+ method: "GET",
24
+ url: `/embeddings-index/${dataset}?projectId=${projectId}`
25
+ });
26
+ }
27
+ function deleteIndex(indexName, client) {
28
+ const projectId = client.config().projectId, dataset = client.config().dataset;
29
+ return client.request({
30
+ method: "DELETE",
31
+ url: `/embeddings-index/${dataset}/${indexName}?projectId=${projectId}`
25
32
  });
33
+ }
34
+ function useApiClient() {
35
+ const client = sanity.useClient({ apiVersion: "vX" });
26
36
  return require$$0.useMemo(() => {
27
37
  const customHost = localStorage.getItem("embeddings-index-host");
28
- if (customHost) {
29
- return client.withConfig({
30
- apiHost: customHost,
31
- useProjectHostname: false,
32
- withCredentials: false
33
- });
34
- }
35
- return client;
38
+ return customHost ? client.withConfig({
39
+ apiHost: customHost,
40
+ useProjectHostname: !1,
41
+ withCredentials: !1
42
+ }) : client;
36
43
  }, [client]);
37
44
  }
38
45
  const FeatureEnabledContext = require$$0.createContext("loading");
39
46
  function useIsFeatureEnabled() {
40
- const client = useApiClient();
41
- const [status, setStatus] = require$$0.useState("loading");
42
- require$$0.useEffect(() => {
47
+ const client = useApiClient(), [status, setStatus] = require$$0.useState("loading");
48
+ return require$$0.useEffect(() => {
43
49
  client.request({
44
50
  method: "GET",
45
51
  url: "/embeddings-index/status"
46
- }).then(response => {
52
+ }).then((response) => {
47
53
  setStatus(response.enabled ? "enabled" : "disabled");
48
- }).catch(err => {
49
- console.error(err);
50
- setStatus("error");
54
+ }).catch((err) => {
55
+ console.error(err), setStatus("error");
51
56
  });
52
- }, [client]);
53
- return status;
57
+ }, [client]), status;
54
58
  }
55
59
  function FeatureEnabledProvider(props) {
56
60
  const status = useIsFeatureEnabled();
57
- return /* @__PURE__ */jsxRuntime.jsx(FeatureEnabledContext.Provider, {
58
- value: status,
59
- children: props.children
60
- });
61
+ return /* @__PURE__ */ jsxRuntime.jsx(FeatureEnabledContext.Provider, { value: status, children: props.children });
61
62
  }
62
63
  function useIsFeatureEnabledContext() {
63
64
  return require$$0.useContext(FeatureEnabledContext);
64
65
  }
65
66
  function FeatureDisabledNotice(props) {
66
- var _a;
67
67
  const projectId = sanity.useProjectId();
68
- return /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
69
- tone: "primary",
70
- border: true,
71
- padding: 4,
72
- children: /* @__PURE__ */jsxRuntime.jsxs(ui.Text, {
73
- size: 1,
74
- children: ["\u{1F48E} Unlock semantic search with the Embeddings Index API \u2014 available on Team, Business, and Enterprise plans.", " ", /* @__PURE__ */jsxRuntime.jsx("a", {
75
- href: "https://www.sanity.io/manage/project/".concat(projectId, "/plan").concat((_a = props.urlSuffix) != null ? _a : ""),
76
- children: "Upgrade now \u2192"
77
- })]
78
- })
79
- });
68
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { tone: "primary", border: !0, padding: 4, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: 1, children: [
69
+ "\u{1F48E} Unlock semantic search with the Embeddings Index API \u2014 available on Team, Business, and Enterprise plans.",
70
+ " ",
71
+ /* @__PURE__ */ jsxRuntime.jsx("a", { href: `https://www.sanity.io/manage/project/${projectId}/plan${props.urlSuffix ?? ""}`, children: "Upgrade now \u2192" })
72
+ ] }) });
80
73
  }
81
74
  function FeatureError() {
82
- return /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
83
- padding: 4,
84
- border: true,
85
- tone: "critical",
86
- children: "An error occurred. See console for details."
87
- });
75
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { padding: 4, border: !0, tone: "critical", children: "An error occurred. See console for details." });
76
+ }
77
+ function isType(schemaType, typeName) {
78
+ return schemaType.name === typeName ? !0 : schemaType.type ? isType(schemaType.type, typeName) : !1;
79
+ }
80
+ const defaultProjection = "{...}";
81
+ function useDefaultIndex(schema, dataset) {
82
+ const defaultFilter = require$$0.useMemo(
83
+ () => `_type in [${schema.getTypeNames().map((n) => schema.get(n)).filter(
84
+ (schemaType) => !!(schemaType && isType(schemaType, "document"))
85
+ ).filter(
86
+ (documentType) => !documentType.name.startsWith("sanity.") && !documentType.name.startsWith("assist.") && documentType.name !== "document"
87
+ ).map((documentType) => `"${documentType.name}"`).join(`,
88
+ `)}]`,
89
+ [schema]
90
+ );
91
+ return require$$0.useMemo(
92
+ () => ({
93
+ dataset,
94
+ projection: defaultProjection,
95
+ filter: defaultFilter
96
+ }),
97
+ [defaultFilter, dataset]
98
+ );
99
+ }
100
+ function IndexFormInput(props) {
101
+ const { label, description, index, prop, onChange, readOnly, placeholder, type } = props, handleChange = require$$0.useCallback(
102
+ (propValue) => onChange((current) => ({ ...current, [prop]: propValue })),
103
+ [onChange, prop]
104
+ );
105
+ return /* @__PURE__ */ jsxRuntime.jsx(
106
+ FormInput,
107
+ {
108
+ label,
109
+ description,
110
+ onChange: handleChange,
111
+ value: index[prop] ?? "",
112
+ readOnly,
113
+ placeholder,
114
+ type
115
+ }
116
+ );
117
+ }
118
+ function FormInput(props) {
119
+ const { label, description, onChange, value, readOnly, placeholder, type = "text" } = props, id = require$$0.useId(), handleChange = require$$0.useCallback(
120
+ (e) => onChange(e.currentTarget.value),
121
+ [onChange]
122
+ );
123
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 3, children: [
124
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { muted: !0, htmlFor: id, children: /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: id, children: label }) }),
125
+ description && /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: 1, muted: !0, children: description }) }),
126
+ type === "text" ? /* @__PURE__ */ jsxRuntime.jsx(
127
+ ui.TextInput,
128
+ {
129
+ id,
130
+ value,
131
+ onChange: handleChange,
132
+ readOnly,
133
+ placeholder
134
+ }
135
+ ) : /* @__PURE__ */ jsxRuntime.jsx(
136
+ ui.TextArea,
137
+ {
138
+ id,
139
+ value,
140
+ rows: 3,
141
+ onChange: handleChange,
142
+ readOnly,
143
+ placeholder,
144
+ style: { resize: "vertical" }
145
+ }
146
+ )
147
+ ] });
148
+ }
149
+ function EditIndexDialog(props) {
150
+ const { open, onClose, onSubmit } = props, id = require$$0.useId(), ref = require$$0.useRef(null);
151
+ require$$0.useEffect(() => {
152
+ open && setTimeout(() => ref.current?.querySelector("input")?.focus());
153
+ }, [ref, open]);
154
+ const handleSubmit = require$$0.useCallback(
155
+ (index) => {
156
+ onSubmit(index), onClose();
157
+ },
158
+ [onSubmit, onClose]
159
+ );
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
+ }
162
+ function IndexEditor(props) {
163
+ const { readOnly, index: selectedIndex, onSubmit } = props, client = useApiClient(), schema = sanity.useSchema(), defaultIndex = useDefaultIndex(schema, client.config().dataset ?? ""), [errors, setErrors] = require$$0.useState(), [loading, setLoading] = require$$0.useState(), [index, setIndex] = require$$0.useState(() => ({
164
+ ...defaultIndex,
165
+ ...selectedIndex
166
+ }));
167
+ require$$0.useEffect(() => setIndex(selectedIndex ?? { ...defaultIndex }), [selectedIndex, defaultIndex]);
168
+ const handleSubmit = require$$0.useCallback(
169
+ (e) => {
170
+ if (e.preventDefault(), readOnly)
171
+ return;
172
+ const validationErrors = [];
173
+ if (index.indexName ? index.indexName.match(/^[a-zA-Z0-9-_]+$/g) || validationErrors.push("Index name can only contain the letters a-z, numbers - and _") : validationErrors.push("Index name is required"), index.dataset || validationErrors.push("Dataset is required"), index.filter || validationErrors.push("Filter is required"), index.projection || validationErrors.push("Projection is required"), validationErrors.length) {
174
+ setErrors(validationErrors);
175
+ return;
176
+ }
177
+ const { projectId } = client.config();
178
+ setLoading(!0), client.request({
179
+ method: "POST",
180
+ url: `/embeddings-index/${index.dataset}?projectId=${projectId}`,
181
+ body: {
182
+ indexName: index.indexName,
183
+ projection: index.projection,
184
+ filter: index.filter
185
+ }
186
+ }).then((response) => {
187
+ onSubmit && onSubmit(response.index);
188
+ }).catch((err) => {
189
+ console.error(err), setErrors([err.message]);
190
+ }).finally(() => {
191
+ setLoading(!1);
192
+ });
193
+ },
194
+ [index, readOnly, onSubmit, client]
195
+ );
196
+ return /* @__PURE__ */ jsxRuntime.jsx("form", { onSubmit: handleSubmit, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 4, children: [
197
+ errors?.length ? /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { tone: "critical", border: !0, padding: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: /* @__PURE__ */ jsxRuntime.jsx("ul", { style: { marginLeft: -10 }, children: errors?.map((error, i) => /* @__PURE__ */ jsxRuntime.jsx("li", { children: error }, `${error}-${i}`)) }) }) }) : null,
198
+ /* @__PURE__ */ jsxRuntime.jsx(
199
+ IndexFormInput,
200
+ {
201
+ label: "Index name",
202
+ placeholder: "Name of index without spaces...",
203
+ index,
204
+ prop: "indexName",
205
+ onChange: setIndex,
206
+ readOnly
207
+ }
208
+ ),
209
+ /* @__PURE__ */ jsxRuntime.jsx(IndexFormInput, { label: "Dataset", index, prop: "dataset", onChange: setIndex, readOnly: !0 }),
210
+ /* @__PURE__ */ jsxRuntime.jsx(
211
+ IndexFormInput,
212
+ {
213
+ label: "Filter",
214
+ description: "Must be a valid GROQ filter",
215
+ placeholder: defaultIndex.filter,
216
+ index,
217
+ prop: "filter",
218
+ onChange: setIndex,
219
+ readOnly,
220
+ type: "textarea"
221
+ }
222
+ ),
223
+ /* @__PURE__ */ jsxRuntime.jsx(
224
+ IndexFormInput,
225
+ {
226
+ label: "Projection",
227
+ description: "Must be a valid GROQ projection, starting { and ending with }",
228
+ placeholder: defaultIndex.projection,
229
+ index,
230
+ prop: "projection",
231
+ onChange: setIndex,
232
+ readOnly,
233
+ type: "textarea"
234
+ }
235
+ ),
236
+ onSubmit && /* @__PURE__ */ jsxRuntime.jsx(
237
+ ui.Button,
238
+ {
239
+ type: "submit",
240
+ text: "Create index",
241
+ icon: loading ? /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { style: { marginTop: 5 }, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Spinner, {}) }) : icons.AddIcon,
242
+ disabled: readOnly || loading,
243
+ tone: "primary"
244
+ }
245
+ )
246
+ ] }) });
88
247
  }
89
-
90
- /******************************************************************************
91
- Copyright (c) Microsoft Corporation.
92
-
93
- Permission to use, copy, modify, and/or distribute this software for any
94
- purpose with or without fee is hereby granted.
95
-
96
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
97
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
98
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
99
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
100
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
101
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
102
- PERFORMANCE OF THIS SOFTWARE.
103
- ***************************************************************************** */
104
- /* global Reflect, Promise, SuppressedError, Symbol */
105
-
106
- var extendStatics = function (d, b) {
107
- extendStatics = Object.setPrototypeOf || {
108
- __proto__: []
109
- } instanceof Array && function (d, b) {
110
- d.__proto__ = b;
111
- } || function (d, b) {
112
- for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
248
+ /**
249
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
250
+ *
251
+ * This source code is licensed under the MIT license found in the
252
+ * LICENSE file in the root directory of this source tree.
253
+ *
254
+ * @lightSyntaxTransform
255
+ * @noflow
256
+ * @nolint
257
+ * @preventMunge
258
+ * @preserve-invariant-messages
259
+ */
260
+ var dist, hasRequiredDist;
261
+ function requireDist() {
262
+ if (hasRequiredDist) return dist;
263
+ hasRequiredDist = 1;
264
+ var __create = Object.create, __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __getOwnPropNames = Object.getOwnPropertyNames, __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty, __export = (target, all) => {
265
+ for (var name in all)
266
+ __defProp(target, name, { get: all[name], enumerable: !0 });
267
+ }, __copyProps = (to, from2, except, desc) => {
268
+ if (from2 && typeof from2 == "object" || typeof from2 == "function")
269
+ for (let key of __getOwnPropNames(from2))
270
+ !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from2[key], enumerable: !(desc = __getOwnPropDesc(from2, key)) || desc.enumerable });
271
+ return to;
272
+ }, __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
273
+ // If the importer is in node compatibility mode or this is not an ESM
274
+ // file that has been converted to a CommonJS file using a Babel-
275
+ // compatible transform (i.e. "__esModule" has not been set), then set
276
+ // "default" to the CommonJS "module.exports" for node compatibility.
277
+ !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
278
+ mod
279
+ )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod), index_exports = {};
280
+ __export(index_exports, {
281
+ $dispatcherGuard: () => $dispatcherGuard,
282
+ $makeReadOnly: () => $makeReadOnly,
283
+ $reset: () => $reset,
284
+ $structuralCheck: () => $structuralCheck,
285
+ c: () => c,
286
+ clearRenderCounterRegistry: () => clearRenderCounterRegistry,
287
+ renderCounterRegistry: () => renderCounterRegistry,
288
+ useRenderCounter: () => useRenderCounter
289
+ }), dist = __toCommonJS(index_exports);
290
+ var React = __toESM(require$$0__default.default), { useRef, useEffect, isValidElement } = React, _a, ReactSecretInternals = (
291
+ //@ts-ignore
292
+ (_a = React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE) != null ? _a : React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
293
+ ), $empty = Symbol.for("react.memo_cache_sentinel"), _a2, c = (
294
+ // @ts-expect-error
295
+ typeof ((_a2 = React.__COMPILER_RUNTIME) == null ? void 0 : _a2.c) == "function" ? (
296
+ // @ts-expect-error
297
+ React.__COMPILER_RUNTIME.c
298
+ ) : function(size) {
299
+ return React.useMemo(() => {
300
+ const $ = new Array(size);
301
+ for (let ii = 0; ii < size; ii++)
302
+ $[ii] = $empty;
303
+ return $[$empty] = !0, $;
304
+ }, []);
305
+ }
306
+ ), LazyGuardDispatcher = {};
307
+ [
308
+ "readContext",
309
+ "useCallback",
310
+ "useContext",
311
+ "useEffect",
312
+ "useImperativeHandle",
313
+ "useInsertionEffect",
314
+ "useLayoutEffect",
315
+ "useMemo",
316
+ "useReducer",
317
+ "useRef",
318
+ "useState",
319
+ "useDebugValue",
320
+ "useDeferredValue",
321
+ "useTransition",
322
+ "useMutableSource",
323
+ "useSyncExternalStore",
324
+ "useId",
325
+ "unstable_isNewReconciler",
326
+ "getCacheSignal",
327
+ "getCacheForType",
328
+ "useCacheRefresh"
329
+ ].forEach((name) => {
330
+ LazyGuardDispatcher[name] = () => {
331
+ throw new Error(
332
+ `[React] Unexpected React hook call (${name}) from a React compiled function. Check that all hooks are called directly and named according to convention ('use[A-Z]') `
333
+ );
334
+ };
335
+ });
336
+ var originalDispatcher = null;
337
+ LazyGuardDispatcher.useMemoCache = (count) => {
338
+ if (originalDispatcher == null)
339
+ throw new Error(
340
+ "React Compiler internal invariant violation: unexpected null dispatcher"
341
+ );
342
+ return originalDispatcher.useMemoCache(count);
113
343
  };
114
- return extendStatics(d, b);
344
+ function setCurrent(newDispatcher) {
345
+ return ReactSecretInternals.ReactCurrentDispatcher.current = newDispatcher, ReactSecretInternals.ReactCurrentDispatcher.current;
346
+ }
347
+ var guardFrames = [];
348
+ function $dispatcherGuard(kind) {
349
+ const curr = ReactSecretInternals.ReactCurrentDispatcher.current;
350
+ if (kind === 0) {
351
+ if (guardFrames.push(curr), guardFrames.length === 1 && (originalDispatcher = curr), curr === LazyGuardDispatcher)
352
+ throw new Error(
353
+ "[React] Unexpected call to custom hook or component from a React compiled function. Check that (1) all hooks are called directly and named according to convention ('use[A-Z]') and (2) components are returned as JSX instead of being directly invoked."
354
+ );
355
+ setCurrent(LazyGuardDispatcher);
356
+ } else if (kind === 1) {
357
+ const lastFrame = guardFrames.pop();
358
+ if (lastFrame == null)
359
+ throw new Error(
360
+ "React Compiler internal error: unexpected null in guard stack"
361
+ );
362
+ guardFrames.length === 0 && (originalDispatcher = null), setCurrent(lastFrame);
363
+ } else if (kind === 2)
364
+ guardFrames.push(curr), setCurrent(originalDispatcher);
365
+ else if (kind === 3) {
366
+ const lastFrame = guardFrames.pop();
367
+ if (lastFrame == null)
368
+ throw new Error(
369
+ "React Compiler internal error: unexpected null in guard stack"
370
+ );
371
+ setCurrent(lastFrame);
372
+ } else
373
+ throw new Error("React Compiler internal error: unreachable block" + kind);
374
+ }
375
+ function $reset($) {
376
+ for (let ii = 0; ii < $.length; ii++)
377
+ $[ii] = $empty;
378
+ }
379
+ function $makeReadOnly() {
380
+ throw new Error("TODO: implement $makeReadOnly in react-compiler-runtime");
381
+ }
382
+ var renderCounterRegistry = /* @__PURE__ */ new Map();
383
+ function clearRenderCounterRegistry() {
384
+ for (const counters of renderCounterRegistry.values())
385
+ counters.forEach((counter) => {
386
+ counter.count = 0;
387
+ });
388
+ }
389
+ function registerRenderCounter(name, val) {
390
+ let counters = renderCounterRegistry.get(name);
391
+ counters == null && (counters = /* @__PURE__ */ new Set(), renderCounterRegistry.set(name, counters)), counters.add(val);
392
+ }
393
+ function removeRenderCounter(name, val) {
394
+ const counters = renderCounterRegistry.get(name);
395
+ counters?.delete(val);
396
+ }
397
+ function useRenderCounter(name) {
398
+ const val = useRef(null);
399
+ val.current != null && (val.current.count += 1), useEffect(() => {
400
+ if (val.current == null) {
401
+ const counter = { count: 0 };
402
+ registerRenderCounter(name, counter), val.current = counter;
403
+ }
404
+ return () => {
405
+ val.current !== null && removeRenderCounter(name, val.current);
406
+ };
407
+ });
408
+ }
409
+ var seenErrors = /* @__PURE__ */ new Set();
410
+ function $structuralCheck(oldValue, newValue, variableName, fnName, kind, loc) {
411
+ function error(l, r, path, depth) {
412
+ const str = `${fnName}:${loc} [${kind}] ${variableName}${path} changed from ${l} to ${r} at depth ${depth}`;
413
+ seenErrors.has(str) || (seenErrors.add(str), console.error(str));
414
+ }
415
+ const depthLimit = 2;
416
+ function recur(oldValue2, newValue2, path, depth) {
417
+ if (!(depth > depthLimit)) {
418
+ if (oldValue2 === newValue2)
419
+ return;
420
+ if (typeof oldValue2 != typeof newValue2)
421
+ error(`type ${typeof oldValue2}`, `type ${typeof newValue2}`, path, depth);
422
+ else if (typeof oldValue2 == "object") {
423
+ const oldArray = Array.isArray(oldValue2), newArray = Array.isArray(newValue2);
424
+ if (oldValue2 === null && newValue2 !== null)
425
+ error("null", `type ${typeof newValue2}`, path, depth);
426
+ else if (newValue2 === null)
427
+ error(`type ${typeof oldValue2}`, "null", path, depth);
428
+ else if (oldValue2 instanceof Map)
429
+ if (!(newValue2 instanceof Map))
430
+ error("Map instance", "other value", path, depth);
431
+ else if (oldValue2.size !== newValue2.size)
432
+ error(
433
+ `Map instance with size ${oldValue2.size}`,
434
+ `Map instance with size ${newValue2.size}`,
435
+ path,
436
+ depth
437
+ );
438
+ else
439
+ for (const [k, v] of oldValue2)
440
+ newValue2.has(k) ? recur(v, newValue2.get(k), `${path}.get(${k})`, depth + 1) : error(
441
+ `Map instance with key ${k}`,
442
+ `Map instance without key ${k}`,
443
+ path,
444
+ depth
445
+ );
446
+ else if (newValue2 instanceof Map)
447
+ error("other value", "Map instance", path, depth);
448
+ else if (oldValue2 instanceof Set)
449
+ if (!(newValue2 instanceof Set))
450
+ error("Set instance", "other value", path, depth);
451
+ else if (oldValue2.size !== newValue2.size)
452
+ error(
453
+ `Set instance with size ${oldValue2.size}`,
454
+ `Set instance with size ${newValue2.size}`,
455
+ path,
456
+ depth
457
+ );
458
+ else
459
+ for (const v of newValue2)
460
+ oldValue2.has(v) || error(
461
+ `Set instance without element ${v}`,
462
+ `Set instance with element ${v}`,
463
+ path,
464
+ depth
465
+ );
466
+ else if (newValue2 instanceof Set)
467
+ error("other value", "Set instance", path, depth);
468
+ else if (oldArray || newArray)
469
+ if (oldArray !== newArray)
470
+ error(
471
+ `type ${oldArray ? "array" : "object"}`,
472
+ `type ${newArray ? "array" : "object"}`,
473
+ path,
474
+ depth
475
+ );
476
+ else if (oldValue2.length !== newValue2.length)
477
+ error(
478
+ `array with length ${oldValue2.length}`,
479
+ `array with length ${newValue2.length}`,
480
+ path,
481
+ depth
482
+ );
483
+ else
484
+ for (let ii = 0; ii < oldValue2.length; ii++)
485
+ recur(oldValue2[ii], newValue2[ii], `${path}[${ii}]`, depth + 1);
486
+ else if (isValidElement(oldValue2) || isValidElement(newValue2))
487
+ isValidElement(oldValue2) !== isValidElement(newValue2) ? error(
488
+ `type ${isValidElement(oldValue2) ? "React element" : "object"}`,
489
+ `type ${isValidElement(newValue2) ? "React element" : "object"}`,
490
+ path,
491
+ depth
492
+ ) : oldValue2.type !== newValue2.type ? error(
493
+ `React element of type ${oldValue2.type}`,
494
+ `React element of type ${newValue2.type}`,
495
+ path,
496
+ depth
497
+ ) : recur(
498
+ oldValue2.props,
499
+ newValue2.props,
500
+ `[props of ${path}]`,
501
+ depth + 1
502
+ );
503
+ else {
504
+ for (const key in newValue2)
505
+ key in oldValue2 || error(
506
+ `object without key ${key}`,
507
+ `object with key ${key}`,
508
+ path,
509
+ depth
510
+ );
511
+ for (const key in oldValue2)
512
+ key in newValue2 ? recur(oldValue2[key], newValue2[key], `${path}.${key}`, depth + 1) : error(
513
+ `object with key ${key}`,
514
+ `object without key ${key}`,
515
+ path,
516
+ depth
517
+ );
518
+ }
519
+ } else {
520
+ if (typeof oldValue2 == "function")
521
+ return;
522
+ isNaN(oldValue2) || isNaN(newValue2) ? isNaN(oldValue2) !== isNaN(newValue2) && error(
523
+ `${isNaN(oldValue2) ? "NaN" : "non-NaN value"}`,
524
+ `${isNaN(newValue2) ? "NaN" : "non-NaN value"}`,
525
+ path,
526
+ depth
527
+ ) : oldValue2 !== newValue2 && error(oldValue2, newValue2, path, depth);
528
+ }
529
+ }
530
+ }
531
+ recur(oldValue, newValue, "", 0);
532
+ }
533
+ return dist;
534
+ }
535
+ var distExports = requireDist(), extendStatics = function(d, b) {
536
+ return extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b2) {
537
+ d2.__proto__ = b2;
538
+ } || function(d2, b2) {
539
+ for (var p in b2) Object.prototype.hasOwnProperty.call(b2, p) && (d2[p] = b2[p]);
540
+ }, extendStatics(d, b);
115
541
  };
116
542
  function __extends(d, b) {
117
- if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
543
+ if (typeof b != "function" && b !== null)
544
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
118
545
  extendStatics(d, b);
119
546
  function __() {
120
547
  this.constructor = d;
@@ -123,11 +550,11 @@ function __extends(d, b) {
123
550
  }
124
551
  function __awaiter(thisArg, _arguments, P, generator) {
125
552
  function adopt(value) {
126
- return value instanceof P ? value : new P(function (resolve) {
553
+ return value instanceof P ? value : new P(function(resolve) {
127
554
  resolve(value);
128
555
  });
129
556
  }
130
- return new (P || (P = Promise))(function (resolve, reject) {
557
+ return new (P || (P = Promise))(function(resolve, reject) {
131
558
  function fulfilled(value) {
132
559
  try {
133
560
  step(generator.next(value));
@@ -137,7 +564,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
137
564
  }
138
565
  function rejected(value) {
139
566
  try {
140
- step(generator["throw"](value));
567
+ step(generator.throw(value));
141
568
  } catch (e) {
142
569
  reject(e);
143
570
  }
@@ -149,58 +576,37 @@ function __awaiter(thisArg, _arguments, P, generator) {
149
576
  });
150
577
  }
151
578
  function __generator(thisArg, body) {
152
- var _ = {
153
- label: 0,
154
- sent: function () {
155
- if (t[0] & 1) throw t[1];
156
- return t[1];
157
- },
158
- trys: [],
159
- ops: []
160
- },
161
- f,
162
- y,
163
- t,
164
- g;
165
- return g = {
166
- next: verb(0),
167
- "throw": verb(1),
168
- "return": verb(2)
169
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
579
+ var _ = { label: 0, sent: function() {
580
+ if (t[0] & 1) throw t[1];
581
+ return t[1];
582
+ }, trys: [], ops: [] }, f, y, t, g;
583
+ return g = { next: verb(0), throw: verb(1), return: verb(2) }, typeof Symbol == "function" && (g[Symbol.iterator] = function() {
170
584
  return this;
171
585
  }), g;
172
586
  function verb(n) {
173
- return function (v) {
587
+ return function(v) {
174
588
  return step([n, v]);
175
589
  };
176
590
  }
177
591
  function step(op) {
178
592
  if (f) throw new TypeError("Generator is already executing.");
179
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
180
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
181
- if (y = 0, t) op = [op[0] & 2, t.value];
182
- switch (op[0]) {
593
+ for (; g && (g = 0, op[0] && (_ = 0)), _; ) try {
594
+ if (f = 1, y && (t = op[0] & 2 ? y.return : op[0] ? y.throw || ((t = y.return) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
595
+ switch (y = 0, t && (op = [op[0] & 2, t.value]), op[0]) {
183
596
  case 0:
184
597
  case 1:
185
598
  t = op;
186
599
  break;
187
600
  case 4:
188
- _.label++;
189
- return {
190
- value: op[1],
191
- done: false
192
- };
601
+ return _.label++, { value: op[1], done: !1 };
193
602
  case 5:
194
- _.label++;
195
- y = op[1];
196
- op = [0];
603
+ _.label++, y = op[1], op = [0];
197
604
  continue;
198
605
  case 7:
199
- op = _.ops.pop();
200
- _.trys.pop();
606
+ op = _.ops.pop(), _.trys.pop();
201
607
  continue;
202
608
  default:
203
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
609
+ if (t = _.trys, !(t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
204
610
  _ = 0;
205
611
  continue;
206
612
  }
@@ -209,97 +615,73 @@ function __generator(thisArg, body) {
209
615
  break;
210
616
  }
211
617
  if (op[0] === 6 && _.label < t[1]) {
212
- _.label = t[1];
213
- t = op;
618
+ _.label = t[1], t = op;
214
619
  break;
215
620
  }
216
621
  if (t && _.label < t[2]) {
217
- _.label = t[2];
218
- _.ops.push(op);
622
+ _.label = t[2], _.ops.push(op);
219
623
  break;
220
624
  }
221
- if (t[2]) _.ops.pop();
222
- _.trys.pop();
625
+ t[2] && _.ops.pop(), _.trys.pop();
223
626
  continue;
224
627
  }
225
628
  op = body.call(thisArg, _);
226
629
  } catch (e) {
227
- op = [6, e];
228
- y = 0;
630
+ op = [6, e], y = 0;
229
631
  } finally {
230
632
  f = t = 0;
231
633
  }
232
634
  if (op[0] & 5) throw op[1];
233
- return {
234
- value: op[0] ? op[1] : void 0,
235
- done: true
236
- };
635
+ return { value: op[0] ? op[1] : void 0, done: !0 };
237
636
  }
238
637
  }
239
638
  function __values(o) {
240
- var s = typeof Symbol === "function" && Symbol.iterator,
241
- m = s && o[s],
242
- i = 0;
639
+ var s = typeof Symbol == "function" && Symbol.iterator, m = s && o[s], i = 0;
243
640
  if (m) return m.call(o);
244
- if (o && typeof o.length === "number") return {
245
- next: function () {
246
- if (o && i >= o.length) o = void 0;
247
- return {
248
- value: o && o[i++],
249
- done: !o
250
- };
641
+ if (o && typeof o.length == "number") return {
642
+ next: function() {
643
+ return o && i >= o.length && (o = void 0), { value: o && o[i++], done: !o };
251
644
  }
252
645
  };
253
646
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
254
647
  }
255
648
  function __read(o, n) {
256
- var m = typeof Symbol === "function" && o[Symbol.iterator];
649
+ var m = typeof Symbol == "function" && o[Symbol.iterator];
257
650
  if (!m) return o;
258
- var i = m.call(o),
259
- r,
260
- ar = [],
261
- e;
651
+ var i = m.call(o), r, ar = [], e;
262
652
  try {
263
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
653
+ for (; (n === void 0 || n-- > 0) && !(r = i.next()).done; ) ar.push(r.value);
264
654
  } catch (error) {
265
- e = {
266
- error: error
267
- };
655
+ e = { error };
268
656
  } finally {
269
657
  try {
270
- if (r && !r.done && (m = i["return"])) m.call(i);
658
+ r && !r.done && (m = i.return) && m.call(i);
271
659
  } finally {
272
660
  if (e) throw e.error;
273
661
  }
274
662
  }
275
663
  return ar;
276
664
  }
277
- function __spreadArray(to, from, pack) {
278
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
279
- if (ar || !(i in from)) {
280
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
281
- ar[i] = from[i];
282
- }
283
- }
284
- return to.concat(ar || Array.prototype.slice.call(from));
665
+ function __spreadArray(to, from2, pack) {
666
+ if (pack || arguments.length === 2) for (var i = 0, l = from2.length, ar; i < l; i++)
667
+ (ar || !(i in from2)) && (ar || (ar = Array.prototype.slice.call(from2, 0, i)), ar[i] = from2[i]);
668
+ return to.concat(ar || Array.prototype.slice.call(from2));
285
669
  }
286
670
  function __await(v) {
287
671
  return this instanceof __await ? (this.v = v, this) : new __await(v);
288
672
  }
289
673
  function __asyncGenerator(thisArg, _arguments, generator) {
290
674
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
291
- var g = generator.apply(thisArg, _arguments || []),
292
- i,
293
- q = [];
294
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () {
675
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
676
+ return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
295
677
  return this;
296
678
  }, i;
297
679
  function verb(n) {
298
- if (g[n]) i[n] = function (v) {
299
- return new Promise(function (a, b) {
680
+ g[n] && (i[n] = function(v) {
681
+ return new Promise(function(a, b) {
300
682
  q.push([n, v, a, b]) > 1 || resume(n, v);
301
683
  });
302
- };
684
+ });
303
685
  }
304
686
  function resume(n, v) {
305
687
  try {
@@ -318,57 +700,44 @@ function __asyncGenerator(thisArg, _arguments, generator) {
318
700
  resume("throw", value);
319
701
  }
320
702
  function settle(f, v) {
321
- if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]);
703
+ f(v), q.shift(), q.length && resume(q[0][0], q[0][1]);
322
704
  }
323
705
  }
324
706
  function __asyncValues(o) {
325
707
  if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
326
- var m = o[Symbol.asyncIterator],
327
- i;
328
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () {
708
+ var m = o[Symbol.asyncIterator], i;
709
+ return m ? m.call(o) : (o = typeof __values == "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function() {
329
710
  return this;
330
711
  }, i);
331
712
  function verb(n) {
332
- i[n] = o[n] && function (v) {
333
- return new Promise(function (resolve, reject) {
713
+ i[n] = o[n] && function(v) {
714
+ return new Promise(function(resolve, reject) {
334
715
  v = o[n](v), settle(resolve, reject, v.done, v.value);
335
716
  });
336
717
  };
337
718
  }
338
719
  function settle(resolve, reject, d, v) {
339
- Promise.resolve(v).then(function (v) {
340
- resolve({
341
- value: v,
342
- done: d
343
- });
720
+ Promise.resolve(v).then(function(v2) {
721
+ resolve({ value: v2, done: d });
344
722
  }, reject);
345
723
  }
346
724
  }
347
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
348
- var e = new Error(message);
349
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
350
- };
351
725
  function isFunction(value) {
352
- return typeof value === 'function';
726
+ return typeof value == "function";
353
727
  }
354
728
  function createErrorClass(createImpl) {
355
- var _super = function (instance) {
356
- Error.call(instance);
357
- instance.stack = new Error().stack;
358
- };
359
- var ctorFunc = createImpl(_super);
360
- ctorFunc.prototype = Object.create(Error.prototype);
361
- ctorFunc.prototype.constructor = ctorFunc;
362
- return ctorFunc;
363
- }
364
- var UnsubscriptionError = createErrorClass(function (_super) {
365
- return function UnsubscriptionErrorImpl(errors) {
366
- _super(this);
367
- this.message = errors ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function (err, i) {
729
+ var _super = function(instance) {
730
+ Error.call(instance), instance.stack = new Error().stack;
731
+ }, ctorFunc = createImpl(_super);
732
+ return ctorFunc.prototype = Object.create(Error.prototype), ctorFunc.prototype.constructor = ctorFunc, ctorFunc;
733
+ }
734
+ var UnsubscriptionError = createErrorClass(function(_super) {
735
+ return function(errors) {
736
+ _super(this), this.message = errors ? errors.length + ` errors occurred during unsubscription:
737
+ ` + errors.map(function(err, i) {
368
738
  return i + 1 + ") " + err.toString();
369
- }).join('\n ') : '';
370
- this.name = 'UnsubscriptionError';
371
- this.errors = errors;
739
+ }).join(`
740
+ `) : "", this.name = "UnsubscriptionError", this.errors = errors;
372
741
  };
373
742
  });
374
743
  function arrRemove(arr, item) {
@@ -377,50 +746,40 @@ function arrRemove(arr, item) {
377
746
  0 <= index && arr.splice(index, 1);
378
747
  }
379
748
  }
380
- var Subscription = function () {
381
- function Subscription(initialTeardown) {
382
- this.initialTeardown = initialTeardown;
383
- this.closed = false;
384
- this._parentage = null;
385
- this._finalizers = null;
749
+ var Subscription = function() {
750
+ function Subscription2(initialTeardown) {
751
+ this.initialTeardown = initialTeardown, this.closed = !1, this._parentage = null, this._finalizers = null;
386
752
  }
387
- Subscription.prototype.unsubscribe = function () {
388
- var e_1, _a, e_2, _b;
389
- var errors;
753
+ return Subscription2.prototype.unsubscribe = function() {
754
+ var e_1, _a, e_2, _b, errors;
390
755
  if (!this.closed) {
391
- this.closed = true;
756
+ this.closed = !0;
392
757
  var _parentage = this._parentage;
393
- if (_parentage) {
394
- this._parentage = null;
395
- if (Array.isArray(_parentage)) {
758
+ if (_parentage)
759
+ if (this._parentage = null, Array.isArray(_parentage))
396
760
  try {
397
761
  for (var _parentage_1 = __values(_parentage), _parentage_1_1 = _parentage_1.next(); !_parentage_1_1.done; _parentage_1_1 = _parentage_1.next()) {
398
762
  var parent_1 = _parentage_1_1.value;
399
763
  parent_1.remove(this);
400
764
  }
401
765
  } catch (e_1_1) {
402
- e_1 = {
403
- error: e_1_1
404
- };
766
+ e_1 = { error: e_1_1 };
405
767
  } finally {
406
768
  try {
407
- if (_parentage_1_1 && !_parentage_1_1.done && (_a = _parentage_1.return)) _a.call(_parentage_1);
769
+ _parentage_1_1 && !_parentage_1_1.done && (_a = _parentage_1.return) && _a.call(_parentage_1);
408
770
  } finally {
409
771
  if (e_1) throw e_1.error;
410
772
  }
411
773
  }
412
- } else {
774
+ else
413
775
  _parentage.remove(this);
414
- }
415
- }
416
776
  var initialFinalizer = this.initialTeardown;
417
- if (isFunction(initialFinalizer)) {
777
+ if (isFunction(initialFinalizer))
418
778
  try {
419
779
  initialFinalizer();
420
780
  } catch (e) {
421
781
  errors = e instanceof UnsubscriptionError ? e.errors : [e];
422
782
  }
423
- }
424
783
  var _finalizers = this._finalizers;
425
784
  if (_finalizers) {
426
785
  this._finalizers = null;
@@ -430,330 +789,207 @@ var Subscription = function () {
430
789
  try {
431
790
  execFinalizer(finalizer);
432
791
  } catch (err) {
433
- errors = errors !== null && errors !== void 0 ? errors : [];
434
- if (err instanceof UnsubscriptionError) {
435
- errors = __spreadArray(__spreadArray([], __read(errors)), __read(err.errors));
436
- } else {
437
- errors.push(err);
438
- }
792
+ errors = errors ?? [], err instanceof UnsubscriptionError ? errors = __spreadArray(__spreadArray([], __read(errors)), __read(err.errors)) : errors.push(err);
439
793
  }
440
794
  }
441
795
  } catch (e_2_1) {
442
- e_2 = {
443
- error: e_2_1
444
- };
796
+ e_2 = { error: e_2_1 };
445
797
  } finally {
446
798
  try {
447
- if (_finalizers_1_1 && !_finalizers_1_1.done && (_b = _finalizers_1.return)) _b.call(_finalizers_1);
799
+ _finalizers_1_1 && !_finalizers_1_1.done && (_b = _finalizers_1.return) && _b.call(_finalizers_1);
448
800
  } finally {
449
801
  if (e_2) throw e_2.error;
450
802
  }
451
803
  }
452
804
  }
453
- if (errors) {
805
+ if (errors)
454
806
  throw new UnsubscriptionError(errors);
455
- }
456
807
  }
457
- };
458
- Subscription.prototype.add = function (teardown) {
808
+ }, Subscription2.prototype.add = function(teardown) {
459
809
  var _a;
460
- if (teardown && teardown !== this) {
461
- if (this.closed) {
810
+ if (teardown && teardown !== this)
811
+ if (this.closed)
462
812
  execFinalizer(teardown);
463
- } else {
464
- if (teardown instanceof Subscription) {
465
- if (teardown.closed || teardown._hasParent(this)) {
813
+ else {
814
+ if (teardown instanceof Subscription2) {
815
+ if (teardown.closed || teardown._hasParent(this))
466
816
  return;
467
- }
468
817
  teardown._addParent(this);
469
818
  }
470
819
  (this._finalizers = (_a = this._finalizers) !== null && _a !== void 0 ? _a : []).push(teardown);
471
820
  }
472
- }
473
- };
474
- Subscription.prototype._hasParent = function (parent) {
821
+ }, Subscription2.prototype._hasParent = function(parent) {
475
822
  var _parentage = this._parentage;
476
823
  return _parentage === parent || Array.isArray(_parentage) && _parentage.includes(parent);
477
- };
478
- Subscription.prototype._addParent = function (parent) {
824
+ }, Subscription2.prototype._addParent = function(parent) {
479
825
  var _parentage = this._parentage;
480
826
  this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;
481
- };
482
- Subscription.prototype._removeParent = function (parent) {
827
+ }, Subscription2.prototype._removeParent = function(parent) {
483
828
  var _parentage = this._parentage;
484
- if (_parentage === parent) {
485
- this._parentage = null;
486
- } else if (Array.isArray(_parentage)) {
487
- arrRemove(_parentage, parent);
488
- }
489
- };
490
- Subscription.prototype.remove = function (teardown) {
829
+ _parentage === parent ? this._parentage = null : Array.isArray(_parentage) && arrRemove(_parentage, parent);
830
+ }, Subscription2.prototype.remove = function(teardown) {
491
831
  var _finalizers = this._finalizers;
492
- _finalizers && arrRemove(_finalizers, teardown);
493
- if (teardown instanceof Subscription) {
494
- teardown._removeParent(this);
495
- }
496
- };
497
- Subscription.EMPTY = function () {
498
- var empty = new Subscription();
499
- empty.closed = true;
500
- return empty;
501
- }();
502
- return Subscription;
503
- }();
504
- var EMPTY_SUBSCRIPTION = Subscription.EMPTY;
832
+ _finalizers && arrRemove(_finalizers, teardown), teardown instanceof Subscription2 && teardown._removeParent(this);
833
+ }, Subscription2.EMPTY = function() {
834
+ var empty = new Subscription2();
835
+ return empty.closed = !0, empty;
836
+ }(), Subscription2;
837
+ }(), EMPTY_SUBSCRIPTION = Subscription.EMPTY;
505
838
  function isSubscription(value) {
506
- return value instanceof Subscription || value && 'closed' in value && isFunction(value.remove) && isFunction(value.add) && isFunction(value.unsubscribe);
839
+ return value instanceof Subscription || value && "closed" in value && isFunction(value.remove) && isFunction(value.add) && isFunction(value.unsubscribe);
507
840
  }
508
841
  function execFinalizer(finalizer) {
509
- if (isFunction(finalizer)) {
510
- finalizer();
511
- } else {
512
- finalizer.unsubscribe();
513
- }
842
+ isFunction(finalizer) ? finalizer() : finalizer.unsubscribe();
514
843
  }
515
844
  var config = {
516
- onUnhandledError: null,
517
- onStoppedNotification: null,
518
- Promise: undefined,
519
- useDeprecatedSynchronousErrorHandling: false,
520
- useDeprecatedNextContext: false
521
- };
522
- var timeoutProvider = {
523
- setTimeout: function (handler, timeout) {
524
- var args = [];
525
- for (var _i = 2; _i < arguments.length; _i++) {
845
+ Promise: void 0
846
+ }, timeoutProvider = {
847
+ setTimeout: function(handler, timeout) {
848
+ for (var args = [], _i = 2; _i < arguments.length; _i++)
526
849
  args[_i - 2] = arguments[_i];
527
- }
528
850
  return setTimeout.apply(void 0, __spreadArray([handler, timeout], __read(args)));
529
851
  },
530
- clearTimeout: function (handle) {
852
+ clearTimeout: function(handle) {
531
853
  return clearTimeout(handle);
532
854
  },
533
- delegate: undefined
855
+ delegate: void 0
534
856
  };
535
857
  function reportUnhandledError(err) {
536
- timeoutProvider.setTimeout(function () {
537
- {
538
- throw err;
539
- }
858
+ timeoutProvider.setTimeout(function() {
859
+ throw err;
540
860
  });
541
861
  }
542
- function noop() {}
862
+ function noop() {
863
+ }
543
864
  function errorContext(cb) {
544
- {
545
- cb();
546
- }
865
+ cb();
547
866
  }
548
- var Subscriber = function (_super) {
549
- __extends(Subscriber, _super);
550
- function Subscriber(destination) {
867
+ var Subscriber = function(_super) {
868
+ __extends(Subscriber2, _super);
869
+ function Subscriber2(destination) {
551
870
  var _this = _super.call(this) || this;
552
- _this.isStopped = false;
553
- if (destination) {
554
- _this.destination = destination;
555
- if (isSubscription(destination)) {
556
- destination.add(_this);
557
- }
558
- } else {
559
- _this.destination = EMPTY_OBSERVER;
560
- }
561
- return _this;
871
+ return _this.isStopped = !1, destination ? (_this.destination = destination, isSubscription(destination) && destination.add(_this)) : _this.destination = EMPTY_OBSERVER, _this;
562
872
  }
563
- Subscriber.create = function (next, error, complete) {
873
+ return Subscriber2.create = function(next, error, complete) {
564
874
  return new SafeSubscriber(next, error, complete);
565
- };
566
- Subscriber.prototype.next = function (value) {
567
- if (this.isStopped) ;else {
568
- this._next(value);
569
- }
570
- };
571
- Subscriber.prototype.error = function (err) {
572
- if (this.isStopped) ;else {
573
- this.isStopped = true;
574
- this._error(err);
575
- }
576
- };
577
- Subscriber.prototype.complete = function () {
578
- if (this.isStopped) ;else {
579
- this.isStopped = true;
580
- this._complete();
581
- }
582
- };
583
- Subscriber.prototype.unsubscribe = function () {
584
- if (!this.closed) {
585
- this.isStopped = true;
586
- _super.prototype.unsubscribe.call(this);
587
- this.destination = null;
588
- }
589
- };
590
- Subscriber.prototype._next = function (value) {
875
+ }, Subscriber2.prototype.next = function(value) {
876
+ this.isStopped || this._next(value);
877
+ }, Subscriber2.prototype.error = function(err) {
878
+ this.isStopped || (this.isStopped = !0, this._error(err));
879
+ }, Subscriber2.prototype.complete = function() {
880
+ this.isStopped || (this.isStopped = !0, this._complete());
881
+ }, Subscriber2.prototype.unsubscribe = function() {
882
+ this.closed || (this.isStopped = !0, _super.prototype.unsubscribe.call(this), this.destination = null);
883
+ }, Subscriber2.prototype._next = function(value) {
591
884
  this.destination.next(value);
592
- };
593
- Subscriber.prototype._error = function (err) {
885
+ }, Subscriber2.prototype._error = function(err) {
594
886
  try {
595
887
  this.destination.error(err);
596
888
  } finally {
597
889
  this.unsubscribe();
598
890
  }
599
- };
600
- Subscriber.prototype._complete = function () {
891
+ }, Subscriber2.prototype._complete = function() {
601
892
  try {
602
893
  this.destination.complete();
603
894
  } finally {
604
895
  this.unsubscribe();
605
896
  }
606
- };
607
- return Subscriber;
608
- }(Subscription);
609
- var _bind = Function.prototype.bind;
610
- function bind(fn, thisArg) {
611
- return _bind.call(fn, thisArg);
612
- }
613
- var ConsumerObserver = function () {
614
- function ConsumerObserver(partialObserver) {
897
+ }, Subscriber2;
898
+ }(Subscription), ConsumerObserver = function() {
899
+ function ConsumerObserver2(partialObserver) {
615
900
  this.partialObserver = partialObserver;
616
901
  }
617
- ConsumerObserver.prototype.next = function (value) {
902
+ return ConsumerObserver2.prototype.next = function(value) {
618
903
  var partialObserver = this.partialObserver;
619
- if (partialObserver.next) {
904
+ if (partialObserver.next)
620
905
  try {
621
906
  partialObserver.next(value);
622
907
  } catch (error) {
623
908
  handleUnhandledError(error);
624
909
  }
625
- }
626
- };
627
- ConsumerObserver.prototype.error = function (err) {
910
+ }, ConsumerObserver2.prototype.error = function(err) {
628
911
  var partialObserver = this.partialObserver;
629
- if (partialObserver.error) {
912
+ if (partialObserver.error)
630
913
  try {
631
914
  partialObserver.error(err);
632
915
  } catch (error) {
633
916
  handleUnhandledError(error);
634
917
  }
635
- } else {
918
+ else
636
919
  handleUnhandledError(err);
637
- }
638
- };
639
- ConsumerObserver.prototype.complete = function () {
920
+ }, ConsumerObserver2.prototype.complete = function() {
640
921
  var partialObserver = this.partialObserver;
641
- if (partialObserver.complete) {
922
+ if (partialObserver.complete)
642
923
  try {
643
924
  partialObserver.complete();
644
925
  } catch (error) {
645
926
  handleUnhandledError(error);
646
927
  }
647
- }
648
- };
649
- return ConsumerObserver;
650
- }();
651
- var SafeSubscriber = function (_super) {
652
- __extends(SafeSubscriber, _super);
653
- function SafeSubscriber(observerOrNext, error, complete) {
654
- var _this = _super.call(this) || this;
655
- var partialObserver;
656
- if (isFunction(observerOrNext) || !observerOrNext) {
657
- partialObserver = {
658
- next: observerOrNext !== null && observerOrNext !== void 0 ? observerOrNext : undefined,
659
- error: error !== null && error !== void 0 ? error : undefined,
660
- complete: complete !== null && complete !== void 0 ? complete : undefined
661
- };
662
- } else {
663
- var context_1;
664
- if (_this && config.useDeprecatedNextContext) {
665
- context_1 = Object.create(observerOrNext);
666
- context_1.unsubscribe = function () {
667
- return _this.unsubscribe();
668
- };
669
- partialObserver = {
670
- next: observerOrNext.next && bind(observerOrNext.next, context_1),
671
- error: observerOrNext.error && bind(observerOrNext.error, context_1),
672
- complete: observerOrNext.complete && bind(observerOrNext.complete, context_1)
673
- };
674
- } else {
675
- partialObserver = observerOrNext;
676
- }
677
- }
678
- _this.destination = new ConsumerObserver(partialObserver);
679
- return _this;
928
+ }, ConsumerObserver2;
929
+ }(), SafeSubscriber = function(_super) {
930
+ __extends(SafeSubscriber2, _super);
931
+ function SafeSubscriber2(observerOrNext, error, complete) {
932
+ var _this = _super.call(this) || this, partialObserver;
933
+ return isFunction(observerOrNext) || !observerOrNext ? partialObserver = {
934
+ next: observerOrNext ?? void 0,
935
+ error: error ?? void 0,
936
+ complete: complete ?? void 0
937
+ } : partialObserver = observerOrNext, _this.destination = new ConsumerObserver(partialObserver), _this;
680
938
  }
681
- return SafeSubscriber;
939
+ return SafeSubscriber2;
682
940
  }(Subscriber);
683
941
  function handleUnhandledError(error) {
684
- {
685
- reportUnhandledError(error);
686
- }
942
+ reportUnhandledError(error);
687
943
  }
688
944
  function defaultErrorHandler(err) {
689
945
  throw err;
690
946
  }
691
947
  var EMPTY_OBSERVER = {
692
- closed: true,
948
+ closed: !0,
693
949
  next: noop,
694
950
  error: defaultErrorHandler,
695
951
  complete: noop
696
- };
697
- var observable = function () {
698
- return typeof Symbol === 'function' && Symbol.observable || '@@observable';
952
+ }, observable = function() {
953
+ return typeof Symbol == "function" && Symbol.observable || "@@observable";
699
954
  }();
700
955
  function identity(x) {
701
956
  return x;
702
957
  }
703
958
  function pipeFromArray(fns) {
704
- if (fns.length === 0) {
705
- return identity;
706
- }
707
- if (fns.length === 1) {
708
- return fns[0];
709
- }
710
- return function piped(input) {
711
- return fns.reduce(function (prev, fn) {
959
+ return fns.length === 0 ? identity : fns.length === 1 ? fns[0] : function(input) {
960
+ return fns.reduce(function(prev, fn) {
712
961
  return fn(prev);
713
962
  }, input);
714
963
  };
715
964
  }
716
- var Observable = function () {
717
- function Observable(subscribe) {
718
- if (subscribe) {
719
- this._subscribe = subscribe;
720
- }
965
+ var Observable = function() {
966
+ function Observable2(subscribe) {
967
+ subscribe && (this._subscribe = subscribe);
721
968
  }
722
- Observable.prototype.lift = function (operator) {
723
- var observable = new Observable();
724
- observable.source = this;
725
- observable.operator = operator;
726
- return observable;
727
- };
728
- Observable.prototype.subscribe = function (observerOrNext, error, complete) {
729
- var _this = this;
730
- var subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete);
731
- errorContext(function () {
732
- var _a = _this,
733
- operator = _a.operator,
734
- source = _a.source;
969
+ return Observable2.prototype.lift = function(operator) {
970
+ var observable2 = new Observable2();
971
+ return observable2.source = this, observable2.operator = operator, observable2;
972
+ }, Observable2.prototype.subscribe = function(observerOrNext, error, complete) {
973
+ var _this = this, subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete);
974
+ return errorContext(function() {
975
+ var _a = _this, operator = _a.operator, source = _a.source;
735
976
  subscriber.add(operator ? operator.call(subscriber, source) : source ? _this._subscribe(subscriber) : _this._trySubscribe(subscriber));
736
- });
737
- return subscriber;
738
- };
739
- Observable.prototype._trySubscribe = function (sink) {
977
+ }), subscriber;
978
+ }, Observable2.prototype._trySubscribe = function(sink) {
740
979
  try {
741
980
  return this._subscribe(sink);
742
981
  } catch (err) {
743
982
  sink.error(err);
744
983
  }
745
- };
746
- Observable.prototype.forEach = function (next, promiseCtor) {
984
+ }, Observable2.prototype.forEach = function(next, promiseCtor) {
747
985
  var _this = this;
748
- promiseCtor = getPromiseCtor(promiseCtor);
749
- return new promiseCtor(function (resolve, reject) {
986
+ return promiseCtor = getPromiseCtor(promiseCtor), new promiseCtor(function(resolve, reject) {
750
987
  var subscriber = new SafeSubscriber({
751
- next: function (value) {
988
+ next: function(value) {
752
989
  try {
753
990
  next(value);
754
991
  } catch (err) {
755
- reject(err);
756
- subscriber.unsubscribe();
992
+ reject(err), subscriber.unsubscribe();
757
993
  }
758
994
  },
759
995
  error: reject,
@@ -761,43 +997,34 @@ var Observable = function () {
761
997
  });
762
998
  _this.subscribe(subscriber);
763
999
  });
764
- };
765
- Observable.prototype._subscribe = function (subscriber) {
1000
+ }, Observable2.prototype._subscribe = function(subscriber) {
766
1001
  var _a;
767
1002
  return (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber);
768
- };
769
- Observable.prototype[observable] = function () {
1003
+ }, Observable2.prototype[observable] = function() {
770
1004
  return this;
771
- };
772
- Observable.prototype.pipe = function () {
773
- var operations = [];
774
- for (var _i = 0; _i < arguments.length; _i++) {
1005
+ }, Observable2.prototype.pipe = function() {
1006
+ for (var operations = [], _i = 0; _i < arguments.length; _i++)
775
1007
  operations[_i] = arguments[_i];
776
- }
777
1008
  return pipeFromArray(operations)(this);
778
- };
779
- Observable.prototype.toPromise = function (promiseCtor) {
1009
+ }, Observable2.prototype.toPromise = function(promiseCtor) {
780
1010
  var _this = this;
781
- promiseCtor = getPromiseCtor(promiseCtor);
782
- return new promiseCtor(function (resolve, reject) {
1011
+ return promiseCtor = getPromiseCtor(promiseCtor), new promiseCtor(function(resolve, reject) {
783
1012
  var value;
784
- _this.subscribe(function (x) {
1013
+ _this.subscribe(function(x) {
785
1014
  return value = x;
786
- }, function (err) {
1015
+ }, function(err) {
787
1016
  return reject(err);
788
- }, function () {
1017
+ }, function() {
789
1018
  return resolve(value);
790
1019
  });
791
1020
  });
792
- };
793
- Observable.create = function (subscribe) {
794
- return new Observable(subscribe);
795
- };
796
- return Observable;
1021
+ }, Observable2.create = function(subscribe) {
1022
+ return new Observable2(subscribe);
1023
+ }, Observable2;
797
1024
  }();
798
1025
  function getPromiseCtor(promiseCtor) {
799
1026
  var _a;
800
- return (_a = promiseCtor !== null && promiseCtor !== void 0 ? promiseCtor : config.Promise) !== null && _a !== void 0 ? _a : Promise;
1027
+ return (_a = promiseCtor ?? config.Promise) !== null && _a !== void 0 ? _a : Promise;
801
1028
  }
802
1029
  function isObserver(value) {
803
1030
  return value && isFunction(value.next) && isFunction(value.error) && isFunction(value.complete);
@@ -806,48 +1033,43 @@ function isSubscriber(value) {
806
1033
  return value && value instanceof Subscriber || isObserver(value) && isSubscription(value);
807
1034
  }
808
1035
  function hasLift(source) {
809
- return isFunction(source === null || source === void 0 ? void 0 : source.lift);
1036
+ return isFunction(source?.lift);
810
1037
  }
811
1038
  function operate(init) {
812
- return function (source) {
813
- if (hasLift(source)) {
814
- return source.lift(function (liftedSource) {
1039
+ return function(source) {
1040
+ if (hasLift(source))
1041
+ return source.lift(function(liftedSource) {
815
1042
  try {
816
1043
  return init(liftedSource, this);
817
1044
  } catch (err) {
818
1045
  this.error(err);
819
1046
  }
820
1047
  });
821
- }
822
- throw new TypeError('Unable to lift unknown Observable type');
1048
+ throw new TypeError("Unable to lift unknown Observable type");
823
1049
  };
824
1050
  }
825
1051
  function createOperatorSubscriber(destination, onNext, onComplete, onError, onFinalize) {
826
1052
  return new OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize);
827
1053
  }
828
- var OperatorSubscriber = function (_super) {
829
- __extends(OperatorSubscriber, _super);
830
- function OperatorSubscriber(destination, onNext, onComplete, onError, onFinalize, shouldUnsubscribe) {
1054
+ var OperatorSubscriber = function(_super) {
1055
+ __extends(OperatorSubscriber2, _super);
1056
+ function OperatorSubscriber2(destination, onNext, onComplete, onError, onFinalize, shouldUnsubscribe) {
831
1057
  var _this = _super.call(this, destination) || this;
832
- _this.onFinalize = onFinalize;
833
- _this.shouldUnsubscribe = shouldUnsubscribe;
834
- _this._next = onNext ? function (value) {
1058
+ return _this.onFinalize = onFinalize, _this.shouldUnsubscribe = shouldUnsubscribe, _this._next = onNext ? function(value) {
835
1059
  try {
836
1060
  onNext(value);
837
1061
  } catch (err) {
838
1062
  destination.error(err);
839
1063
  }
840
- } : _super.prototype._next;
841
- _this._error = onError ? function (err) {
1064
+ } : _super.prototype._next, _this._error = onError ? function(err) {
842
1065
  try {
843
1066
  onError(err);
844
- } catch (err) {
845
- destination.error(err);
1067
+ } catch (err2) {
1068
+ destination.error(err2);
846
1069
  } finally {
847
1070
  this.unsubscribe();
848
1071
  }
849
- } : _super.prototype._error;
850
- _this._complete = onComplete ? function () {
1072
+ } : _super.prototype._error, _this._complete = onComplete ? function() {
851
1073
  try {
852
1074
  onComplete();
853
1075
  } catch (err) {
@@ -855,305 +1077,319 @@ var OperatorSubscriber = function (_super) {
855
1077
  } finally {
856
1078
  this.unsubscribe();
857
1079
  }
858
- } : _super.prototype._complete;
859
- return _this;
1080
+ } : _super.prototype._complete, _this;
860
1081
  }
861
- OperatorSubscriber.prototype.unsubscribe = function () {
1082
+ return OperatorSubscriber2.prototype.unsubscribe = function() {
862
1083
  var _a;
863
1084
  if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
864
1085
  var closed_1 = this.closed;
865
- _super.prototype.unsubscribe.call(this);
866
- !closed_1 && ((_a = this.onFinalize) === null || _a === void 0 ? void 0 : _a.call(this));
1086
+ _super.prototype.unsubscribe.call(this), !closed_1 && ((_a = this.onFinalize) === null || _a === void 0 || _a.call(this));
867
1087
  }
1088
+ }, OperatorSubscriber2;
1089
+ }(Subscriber), ObjectUnsubscribedError = createErrorClass(function(_super) {
1090
+ return function() {
1091
+ _super(this), this.name = "ObjectUnsubscribedError", this.message = "object unsubscribed";
868
1092
  };
869
- return OperatorSubscriber;
870
- }(Subscriber);
871
- var ObjectUnsubscribedError = createErrorClass(function (_super) {
872
- return function ObjectUnsubscribedErrorImpl() {
873
- _super(this);
874
- this.name = 'ObjectUnsubscribedError';
875
- this.message = 'object unsubscribed';
876
- };
877
- });
878
- var Subject = function (_super) {
879
- __extends(Subject, _super);
880
- function Subject() {
1093
+ }), Subject = function(_super) {
1094
+ __extends(Subject2, _super);
1095
+ function Subject2() {
881
1096
  var _this = _super.call(this) || this;
882
- _this.closed = false;
883
- _this.currentObservers = null;
884
- _this.observers = [];
885
- _this.isStopped = false;
886
- _this.hasError = false;
887
- _this.thrownError = null;
888
- return _this;
1097
+ return _this.closed = !1, _this.currentObservers = null, _this.observers = [], _this.isStopped = !1, _this.hasError = !1, _this.thrownError = null, _this;
889
1098
  }
890
- Subject.prototype.lift = function (operator) {
1099
+ return Subject2.prototype.lift = function(operator) {
891
1100
  var subject = new AnonymousSubject(this, this);
892
- subject.operator = operator;
893
- return subject;
894
- };
895
- Subject.prototype._throwIfClosed = function () {
896
- if (this.closed) {
1101
+ return subject.operator = operator, subject;
1102
+ }, Subject2.prototype._throwIfClosed = function() {
1103
+ if (this.closed)
897
1104
  throw new ObjectUnsubscribedError();
898
- }
899
- };
900
- Subject.prototype.next = function (value) {
1105
+ }, Subject2.prototype.next = function(value) {
901
1106
  var _this = this;
902
- errorContext(function () {
1107
+ errorContext(function() {
903
1108
  var e_1, _a;
904
- _this._throwIfClosed();
905
- if (!_this.isStopped) {
906
- if (!_this.currentObservers) {
907
- _this.currentObservers = Array.from(_this.observers);
908
- }
1109
+ if (_this._throwIfClosed(), !_this.isStopped) {
1110
+ _this.currentObservers || (_this.currentObservers = Array.from(_this.observers));
909
1111
  try {
910
1112
  for (var _b = __values(_this.currentObservers), _c = _b.next(); !_c.done; _c = _b.next()) {
911
1113
  var observer = _c.value;
912
1114
  observer.next(value);
913
1115
  }
914
1116
  } catch (e_1_1) {
915
- e_1 = {
916
- error: e_1_1
917
- };
1117
+ e_1 = { error: e_1_1 };
918
1118
  } finally {
919
1119
  try {
920
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1120
+ _c && !_c.done && (_a = _b.return) && _a.call(_b);
921
1121
  } finally {
922
1122
  if (e_1) throw e_1.error;
923
1123
  }
924
1124
  }
925
1125
  }
926
1126
  });
927
- };
928
- Subject.prototype.error = function (err) {
1127
+ }, Subject2.prototype.error = function(err) {
929
1128
  var _this = this;
930
- errorContext(function () {
931
- _this._throwIfClosed();
932
- if (!_this.isStopped) {
933
- _this.hasError = _this.isStopped = true;
934
- _this.thrownError = err;
935
- var observers = _this.observers;
936
- while (observers.length) {
1129
+ errorContext(function() {
1130
+ if (_this._throwIfClosed(), !_this.isStopped) {
1131
+ _this.hasError = _this.isStopped = !0, _this.thrownError = err;
1132
+ for (var observers = _this.observers; observers.length; )
937
1133
  observers.shift().error(err);
938
- }
939
1134
  }
940
1135
  });
941
- };
942
- Subject.prototype.complete = function () {
1136
+ }, Subject2.prototype.complete = function() {
943
1137
  var _this = this;
944
- errorContext(function () {
945
- _this._throwIfClosed();
946
- if (!_this.isStopped) {
947
- _this.isStopped = true;
948
- var observers = _this.observers;
949
- while (observers.length) {
1138
+ errorContext(function() {
1139
+ if (_this._throwIfClosed(), !_this.isStopped) {
1140
+ _this.isStopped = !0;
1141
+ for (var observers = _this.observers; observers.length; )
950
1142
  observers.shift().complete();
951
- }
952
1143
  }
953
1144
  });
954
- };
955
- Subject.prototype.unsubscribe = function () {
956
- this.isStopped = this.closed = true;
957
- this.observers = this.currentObservers = null;
958
- };
959
- Object.defineProperty(Subject.prototype, "observed", {
960
- get: function () {
1145
+ }, Subject2.prototype.unsubscribe = function() {
1146
+ this.isStopped = this.closed = !0, this.observers = this.currentObservers = null;
1147
+ }, Object.defineProperty(Subject2.prototype, "observed", {
1148
+ get: function() {
961
1149
  var _a;
962
1150
  return ((_a = this.observers) === null || _a === void 0 ? void 0 : _a.length) > 0;
963
1151
  },
964
- enumerable: false,
965
- configurable: true
966
- });
967
- Subject.prototype._trySubscribe = function (subscriber) {
968
- this._throwIfClosed();
969
- return _super.prototype._trySubscribe.call(this, subscriber);
970
- };
971
- Subject.prototype._subscribe = function (subscriber) {
972
- this._throwIfClosed();
973
- this._checkFinalizedStatuses(subscriber);
974
- return this._innerSubscribe(subscriber);
975
- };
976
- Subject.prototype._innerSubscribe = function (subscriber) {
977
- var _this = this;
978
- var _a = this,
979
- hasError = _a.hasError,
980
- isStopped = _a.isStopped,
981
- observers = _a.observers;
982
- if (hasError || isStopped) {
983
- return EMPTY_SUBSCRIPTION;
984
- }
985
- this.currentObservers = null;
986
- observers.push(subscriber);
987
- return new Subscription(function () {
988
- _this.currentObservers = null;
989
- arrRemove(observers, subscriber);
990
- });
991
- };
992
- Subject.prototype._checkFinalizedStatuses = function (subscriber) {
993
- var _a = this,
994
- hasError = _a.hasError,
995
- thrownError = _a.thrownError,
996
- isStopped = _a.isStopped;
997
- if (hasError) {
998
- subscriber.error(thrownError);
999
- } else if (isStopped) {
1000
- subscriber.complete();
1001
- }
1002
- };
1003
- Subject.prototype.asObservable = function () {
1004
- var observable = new Observable();
1005
- observable.source = this;
1006
- return observable;
1007
- };
1008
- Subject.create = function (destination, source) {
1152
+ enumerable: !1,
1153
+ configurable: !0
1154
+ }), Subject2.prototype._trySubscribe = function(subscriber) {
1155
+ return this._throwIfClosed(), _super.prototype._trySubscribe.call(this, subscriber);
1156
+ }, Subject2.prototype._subscribe = function(subscriber) {
1157
+ return this._throwIfClosed(), this._checkFinalizedStatuses(subscriber), this._innerSubscribe(subscriber);
1158
+ }, Subject2.prototype._innerSubscribe = function(subscriber) {
1159
+ var _this = this, _a = this, hasError = _a.hasError, isStopped = _a.isStopped, observers = _a.observers;
1160
+ return hasError || isStopped ? EMPTY_SUBSCRIPTION : (this.currentObservers = null, observers.push(subscriber), new Subscription(function() {
1161
+ _this.currentObservers = null, arrRemove(observers, subscriber);
1162
+ }));
1163
+ }, Subject2.prototype._checkFinalizedStatuses = function(subscriber) {
1164
+ var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, isStopped = _a.isStopped;
1165
+ hasError ? subscriber.error(thrownError) : isStopped && subscriber.complete();
1166
+ }, Subject2.prototype.asObservable = function() {
1167
+ var observable2 = new Observable();
1168
+ return observable2.source = this, observable2;
1169
+ }, Subject2.create = function(destination, source) {
1009
1170
  return new AnonymousSubject(destination, source);
1010
- };
1011
- return Subject;
1012
- }(Observable);
1013
- var AnonymousSubject = function (_super) {
1014
- __extends(AnonymousSubject, _super);
1015
- function AnonymousSubject(destination, source) {
1171
+ }, Subject2;
1172
+ }(Observable), AnonymousSubject = function(_super) {
1173
+ __extends(AnonymousSubject2, _super);
1174
+ function AnonymousSubject2(destination, source) {
1016
1175
  var _this = _super.call(this) || this;
1017
- _this.destination = destination;
1018
- _this.source = source;
1019
- return _this;
1176
+ return _this.destination = destination, _this.source = source, _this;
1020
1177
  }
1021
- AnonymousSubject.prototype.next = function (value) {
1178
+ return AnonymousSubject2.prototype.next = function(value) {
1022
1179
  var _a, _b;
1023
- (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.next) === null || _b === void 0 ? void 0 : _b.call(_a, value);
1024
- };
1025
- AnonymousSubject.prototype.error = function (err) {
1180
+ (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.next) === null || _b === void 0 || _b.call(_a, value);
1181
+ }, AnonymousSubject2.prototype.error = function(err) {
1026
1182
  var _a, _b;
1027
- (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.call(_a, err);
1028
- };
1029
- AnonymousSubject.prototype.complete = function () {
1183
+ (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 || _b.call(_a, err);
1184
+ }, AnonymousSubject2.prototype.complete = function() {
1030
1185
  var _a, _b;
1031
- (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.complete) === null || _b === void 0 ? void 0 : _b.call(_a);
1032
- };
1033
- AnonymousSubject.prototype._subscribe = function (subscriber) {
1186
+ (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.complete) === null || _b === void 0 || _b.call(_a);
1187
+ }, AnonymousSubject2.prototype._subscribe = function(subscriber) {
1034
1188
  var _a, _b;
1035
1189
  return (_b = (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber)) !== null && _b !== void 0 ? _b : EMPTY_SUBSCRIPTION;
1036
- };
1037
- return AnonymousSubject;
1038
- }(Subject);
1039
- var dateTimestampProvider = {
1040
- now: function () {
1041
- return (dateTimestampProvider.delegate || Date).now();
1190
+ }, AnonymousSubject2;
1191
+ }(Subject), dateTimestampProvider = {
1192
+ now: function() {
1193
+ return Date.now();
1194
+ }
1195
+ }, Action = function(_super) {
1196
+ __extends(Action2, _super);
1197
+ function Action2(scheduler, work) {
1198
+ return _super.call(this) || this;
1199
+ }
1200
+ return Action2.prototype.schedule = function(state, delay) {
1201
+ return this;
1202
+ }, Action2;
1203
+ }(Subscription), intervalProvider = {
1204
+ setInterval: function(handler, timeout) {
1205
+ for (var args = [], _i = 2; _i < arguments.length; _i++)
1206
+ args[_i - 2] = arguments[_i];
1207
+ return setInterval.apply(void 0, __spreadArray([handler, timeout], __read(args)));
1042
1208
  },
1043
- delegate: undefined
1044
- };
1045
- var ReplaySubject = function (_super) {
1046
- __extends(ReplaySubject, _super);
1047
- function ReplaySubject(_bufferSize, _windowTime, _timestampProvider) {
1048
- if (_bufferSize === void 0) {
1049
- _bufferSize = Infinity;
1050
- }
1051
- if (_windowTime === void 0) {
1052
- _windowTime = Infinity;
1053
- }
1054
- if (_timestampProvider === void 0) {
1055
- _timestampProvider = dateTimestampProvider;
1056
- }
1057
- var _this = _super.call(this) || this;
1058
- _this._bufferSize = _bufferSize;
1059
- _this._windowTime = _windowTime;
1060
- _this._timestampProvider = _timestampProvider;
1061
- _this._buffer = [];
1062
- _this._infiniteTimeWindow = true;
1063
- _this._infiniteTimeWindow = _windowTime === Infinity;
1064
- _this._bufferSize = Math.max(1, _bufferSize);
1065
- _this._windowTime = Math.max(1, _windowTime);
1066
- return _this;
1209
+ clearInterval: function(handle) {
1210
+ return clearInterval(handle);
1211
+ },
1212
+ delegate: void 0
1213
+ }, AsyncAction = function(_super) {
1214
+ __extends(AsyncAction2, _super);
1215
+ function AsyncAction2(scheduler, work) {
1216
+ var _this = _super.call(this, scheduler, work) || this;
1217
+ return _this.scheduler = scheduler, _this.work = work, _this.pending = !1, _this;
1067
1218
  }
1068
- ReplaySubject.prototype.next = function (value) {
1069
- var _a = this,
1070
- isStopped = _a.isStopped,
1071
- _buffer = _a._buffer,
1072
- _infiniteTimeWindow = _a._infiniteTimeWindow,
1073
- _timestampProvider = _a._timestampProvider,
1074
- _windowTime = _a._windowTime;
1075
- if (!isStopped) {
1076
- _buffer.push(value);
1077
- !_infiniteTimeWindow && _buffer.push(_timestampProvider.now() + _windowTime);
1078
- }
1079
- this._trimBuffer();
1080
- _super.prototype.next.call(this, value);
1081
- };
1082
- ReplaySubject.prototype._subscribe = function (subscriber) {
1083
- this._throwIfClosed();
1084
- this._trimBuffer();
1085
- var subscription = this._innerSubscribe(subscriber);
1086
- var _a = this,
1087
- _infiniteTimeWindow = _a._infiniteTimeWindow,
1088
- _buffer = _a._buffer;
1089
- var copy = _buffer.slice();
1090
- for (var i = 0; i < copy.length && !subscriber.closed; i += _infiniteTimeWindow ? 1 : 2) {
1091
- subscriber.next(copy[i]);
1092
- }
1093
- this._checkFinalizedStatuses(subscriber);
1094
- return subscription;
1095
- };
1096
- ReplaySubject.prototype._trimBuffer = function () {
1097
- var _a = this,
1098
- _bufferSize = _a._bufferSize,
1099
- _timestampProvider = _a._timestampProvider,
1100
- _buffer = _a._buffer,
1101
- _infiniteTimeWindow = _a._infiniteTimeWindow;
1102
- var adjustedBufferSize = (_infiniteTimeWindow ? 1 : 2) * _bufferSize;
1103
- _bufferSize < Infinity && adjustedBufferSize < _buffer.length && _buffer.splice(0, _buffer.length - adjustedBufferSize);
1104
- if (!_infiniteTimeWindow) {
1105
- var now = _timestampProvider.now();
1106
- var last = 0;
1107
- for (var i = 1; i < _buffer.length && _buffer[i] <= now; i += 2) {
1108
- last = i;
1109
- }
1110
- last && _buffer.splice(0, last + 1);
1219
+ return AsyncAction2.prototype.schedule = function(state, delay) {
1220
+ var _a;
1221
+ if (delay === void 0 && (delay = 0), this.closed)
1222
+ return this;
1223
+ this.state = state;
1224
+ var id = this.id, scheduler = this.scheduler;
1225
+ return id != null && (this.id = this.recycleAsyncId(scheduler, id, delay)), this.pending = !0, this.delay = delay, this.id = (_a = this.id) !== null && _a !== void 0 ? _a : this.requestAsyncId(scheduler, this.id, delay), this;
1226
+ }, AsyncAction2.prototype.requestAsyncId = function(scheduler, _id, delay) {
1227
+ return delay === void 0 && (delay = 0), intervalProvider.setInterval(scheduler.flush.bind(scheduler, this), delay);
1228
+ }, AsyncAction2.prototype.recycleAsyncId = function(_scheduler, id, delay) {
1229
+ if (delay === void 0 && (delay = 0), delay != null && this.delay === delay && this.pending === !1)
1230
+ return id;
1231
+ id != null && intervalProvider.clearInterval(id);
1232
+ }, AsyncAction2.prototype.execute = function(state, delay) {
1233
+ if (this.closed)
1234
+ return new Error("executing a cancelled action");
1235
+ this.pending = !1;
1236
+ var error = this._execute(state, delay);
1237
+ if (error)
1238
+ return error;
1239
+ this.pending === !1 && this.id != null && (this.id = this.recycleAsyncId(this.scheduler, this.id, null));
1240
+ }, AsyncAction2.prototype._execute = function(state, _delay) {
1241
+ var errored = !1, errorValue;
1242
+ try {
1243
+ this.work(state);
1244
+ } catch (e) {
1245
+ errored = !0, errorValue = e || new Error("Scheduled action threw falsy error");
1111
1246
  }
1112
- };
1113
- return ReplaySubject;
1114
- }(Subject);
1115
- var isArrayLike = function (x) {
1116
- return x && typeof x.length === 'number' && typeof x !== 'function';
1117
- };
1118
- function isPromise(value) {
1119
- return isFunction(value === null || value === void 0 ? void 0 : value.then);
1247
+ if (errored)
1248
+ return this.unsubscribe(), errorValue;
1249
+ }, AsyncAction2.prototype.unsubscribe = function() {
1250
+ if (!this.closed) {
1251
+ var _a = this, id = _a.id, scheduler = _a.scheduler, actions = scheduler.actions;
1252
+ this.work = this.state = this.scheduler = null, this.pending = !1, arrRemove(actions, this), id != null && (this.id = this.recycleAsyncId(scheduler, id, null)), this.delay = null, _super.prototype.unsubscribe.call(this);
1253
+ }
1254
+ }, AsyncAction2;
1255
+ }(Action), nextHandle = 1, resolved, activeHandles = {};
1256
+ function findAndClearHandle(handle) {
1257
+ return handle in activeHandles ? (delete activeHandles[handle], !0) : !1;
1258
+ }
1259
+ var Immediate = {
1260
+ setImmediate: function(cb) {
1261
+ var handle = nextHandle++;
1262
+ return activeHandles[handle] = !0, resolved || (resolved = Promise.resolve()), resolved.then(function() {
1263
+ return findAndClearHandle(handle) && cb();
1264
+ }), handle;
1265
+ },
1266
+ clearImmediate: function(handle) {
1267
+ findAndClearHandle(handle);
1268
+ }
1269
+ }, setImmediate = Immediate.setImmediate, clearImmediate = Immediate.clearImmediate, immediateProvider = {
1270
+ setImmediate: function() {
1271
+ for (var args = [], _i = 0; _i < arguments.length; _i++)
1272
+ args[_i] = arguments[_i];
1273
+ var delegate = immediateProvider.delegate;
1274
+ return (delegate?.setImmediate || setImmediate).apply(void 0, __spreadArray([], __read(args)));
1275
+ },
1276
+ clearImmediate: function(handle) {
1277
+ return clearImmediate(handle);
1278
+ },
1279
+ delegate: void 0
1280
+ }, AsapAction = function(_super) {
1281
+ __extends(AsapAction2, _super);
1282
+ function AsapAction2(scheduler, work) {
1283
+ var _this = _super.call(this, scheduler, work) || this;
1284
+ return _this.scheduler = scheduler, _this.work = work, _this;
1285
+ }
1286
+ return AsapAction2.prototype.requestAsyncId = function(scheduler, id, delay) {
1287
+ return delay === void 0 && (delay = 0), delay !== null && delay > 0 ? _super.prototype.requestAsyncId.call(this, scheduler, id, delay) : (scheduler.actions.push(this), scheduler._scheduled || (scheduler._scheduled = immediateProvider.setImmediate(scheduler.flush.bind(scheduler, void 0))));
1288
+ }, AsapAction2.prototype.recycleAsyncId = function(scheduler, id, delay) {
1289
+ var _a;
1290
+ if (delay === void 0 && (delay = 0), delay != null ? delay > 0 : this.delay > 0)
1291
+ return _super.prototype.recycleAsyncId.call(this, scheduler, id, delay);
1292
+ var actions = scheduler.actions;
1293
+ id != null && ((_a = actions[actions.length - 1]) === null || _a === void 0 ? void 0 : _a.id) !== id && (immediateProvider.clearImmediate(id), scheduler._scheduled === id && (scheduler._scheduled = void 0));
1294
+ }, AsapAction2;
1295
+ }(AsyncAction), Scheduler = function() {
1296
+ function Scheduler2(schedulerActionCtor, now) {
1297
+ now === void 0 && (now = Scheduler2.now), this.schedulerActionCtor = schedulerActionCtor, this.now = now;
1298
+ }
1299
+ return Scheduler2.prototype.schedule = function(work, delay, state) {
1300
+ return delay === void 0 && (delay = 0), new this.schedulerActionCtor(this, work).schedule(state, delay);
1301
+ }, Scheduler2.now = dateTimestampProvider.now, Scheduler2;
1302
+ }(), AsyncScheduler = function(_super) {
1303
+ __extends(AsyncScheduler2, _super);
1304
+ function AsyncScheduler2(SchedulerAction, now) {
1305
+ now === void 0 && (now = Scheduler.now);
1306
+ var _this = _super.call(this, SchedulerAction, now) || this;
1307
+ return _this.actions = [], _this._active = !1, _this;
1308
+ }
1309
+ return AsyncScheduler2.prototype.flush = function(action) {
1310
+ var actions = this.actions;
1311
+ if (this._active) {
1312
+ actions.push(action);
1313
+ return;
1314
+ }
1315
+ var error;
1316
+ this._active = !0;
1317
+ do
1318
+ if (error = action.execute(action.state, action.delay))
1319
+ break;
1320
+ while (action = actions.shift());
1321
+ if (this._active = !1, error) {
1322
+ for (; action = actions.shift(); )
1323
+ action.unsubscribe();
1324
+ throw error;
1325
+ }
1326
+ }, AsyncScheduler2;
1327
+ }(Scheduler), AsapScheduler = function(_super) {
1328
+ __extends(AsapScheduler2, _super);
1329
+ function AsapScheduler2() {
1330
+ return _super !== null && _super.apply(this, arguments) || this;
1331
+ }
1332
+ return AsapScheduler2.prototype.flush = function(action) {
1333
+ this._active = !0;
1334
+ var flushId = this._scheduled;
1335
+ this._scheduled = void 0;
1336
+ var actions = this.actions, error;
1337
+ action = action || actions.shift();
1338
+ do
1339
+ if (error = action.execute(action.state, action.delay))
1340
+ break;
1341
+ while ((action = actions[0]) && action.id === flushId && actions.shift());
1342
+ if (this._active = !1, error) {
1343
+ for (; (action = actions[0]) && action.id === flushId && actions.shift(); )
1344
+ action.unsubscribe();
1345
+ throw error;
1346
+ }
1347
+ }, AsapScheduler2;
1348
+ }(AsyncScheduler), asapScheduler = new AsapScheduler(AsapAction), asyncScheduler = new AsyncScheduler(AsyncAction), async = asyncScheduler;
1349
+ function isScheduler(value) {
1350
+ return value && isFunction(value.schedule);
1351
+ }
1352
+ function last(arr) {
1353
+ return arr[arr.length - 1];
1354
+ }
1355
+ function popScheduler(args) {
1356
+ return isScheduler(last(args)) ? args.pop() : void 0;
1357
+ }
1358
+ var isArrayLike = function(x) {
1359
+ return x && typeof x.length == "number" && typeof x != "function";
1360
+ };
1361
+ function isPromise(value) {
1362
+ return isFunction(value?.then);
1120
1363
  }
1121
1364
  function isInteropObservable(input) {
1122
1365
  return isFunction(input[observable]);
1123
1366
  }
1124
1367
  function isAsyncIterable(obj) {
1125
- return Symbol.asyncIterator && isFunction(obj === null || obj === void 0 ? void 0 : obj[Symbol.asyncIterator]);
1368
+ return Symbol.asyncIterator && isFunction(obj?.[Symbol.asyncIterator]);
1126
1369
  }
1127
1370
  function createInvalidObservableTypeError(input) {
1128
- return new TypeError("You provided " + (input !== null && typeof input === 'object' ? 'an invalid object' : "'" + input + "'") + " where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.");
1371
+ return new TypeError("You provided " + (input !== null && typeof input == "object" ? "an invalid object" : "'" + input + "'") + " where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.");
1129
1372
  }
1130
1373
  function getSymbolIterator() {
1131
- if (typeof Symbol !== 'function' || !Symbol.iterator) {
1132
- return '@@iterator';
1133
- }
1134
- return Symbol.iterator;
1374
+ return typeof Symbol != "function" || !Symbol.iterator ? "@@iterator" : Symbol.iterator;
1135
1375
  }
1136
1376
  var iterator = getSymbolIterator();
1137
1377
  function isIterable(input) {
1138
- return isFunction(input === null || input === void 0 ? void 0 : input[iterator]);
1378
+ return isFunction(input?.[iterator]);
1139
1379
  }
1140
1380
  function readableStreamLikeToAsyncGenerator(readableStream) {
1141
- return __asyncGenerator(this, arguments, function readableStreamLikeToAsyncGenerator_1() {
1381
+ return __asyncGenerator(this, arguments, function() {
1142
1382
  var reader, _a, value, done;
1143
- return __generator(this, function (_b) {
1383
+ return __generator(this, function(_b) {
1144
1384
  switch (_b.label) {
1145
1385
  case 0:
1146
- reader = readableStream.getReader();
1147
- _b.label = 1;
1386
+ reader = readableStream.getReader(), _b.label = 1;
1148
1387
  case 1:
1149
- _b.trys.push([1,, 9, 10]);
1150
- _b.label = 2;
1388
+ _b.trys.push([1, , 9, 10]), _b.label = 2;
1151
1389
  case 2:
1152
1390
  return [4, __await(reader.read())];
1153
1391
  case 3:
1154
- _a = _b.sent(), value = _a.value, done = _a.done;
1155
- if (!done) return [3, 5];
1156
- return [4, __await(void 0)];
1392
+ return _a = _b.sent(), value = _a.value, done = _a.done, done ? [4, __await(void 0)] : [3, 5];
1157
1393
  case 4:
1158
1394
  return [2, _b.sent()];
1159
1395
  case 5:
@@ -1161,13 +1397,11 @@ function readableStreamLikeToAsyncGenerator(readableStream) {
1161
1397
  case 6:
1162
1398
  return [4, _b.sent()];
1163
1399
  case 7:
1164
- _b.sent();
1165
- return [3, 2];
1400
+ return _b.sent(), [3, 2];
1166
1401
  case 8:
1167
1402
  return [3, 10];
1168
1403
  case 9:
1169
- reader.releaseLock();
1170
- return [7];
1404
+ return reader.releaseLock(), [7];
1171
1405
  case 10:
1172
1406
  return [2];
1173
1407
  }
@@ -1175,81 +1409,65 @@ function readableStreamLikeToAsyncGenerator(readableStream) {
1175
1409
  });
1176
1410
  }
1177
1411
  function isReadableStreamLike(obj) {
1178
- return isFunction(obj === null || obj === void 0 ? void 0 : obj.getReader);
1412
+ return isFunction(obj?.getReader);
1179
1413
  }
1180
1414
  function innerFrom(input) {
1181
- if (input instanceof Observable) {
1415
+ if (input instanceof Observable)
1182
1416
  return input;
1183
- }
1184
1417
  if (input != null) {
1185
- if (isInteropObservable(input)) {
1418
+ if (isInteropObservable(input))
1186
1419
  return fromInteropObservable(input);
1187
- }
1188
- if (isArrayLike(input)) {
1420
+ if (isArrayLike(input))
1189
1421
  return fromArrayLike(input);
1190
- }
1191
- if (isPromise(input)) {
1422
+ if (isPromise(input))
1192
1423
  return fromPromise(input);
1193
- }
1194
- if (isAsyncIterable(input)) {
1424
+ if (isAsyncIterable(input))
1195
1425
  return fromAsyncIterable(input);
1196
- }
1197
- if (isIterable(input)) {
1426
+ if (isIterable(input))
1198
1427
  return fromIterable(input);
1199
- }
1200
- if (isReadableStreamLike(input)) {
1428
+ if (isReadableStreamLike(input))
1201
1429
  return fromReadableStreamLike(input);
1202
- }
1203
1430
  }
1204
1431
  throw createInvalidObservableTypeError(input);
1205
1432
  }
1206
1433
  function fromInteropObservable(obj) {
1207
- return new Observable(function (subscriber) {
1434
+ return new Observable(function(subscriber) {
1208
1435
  var obs = obj[observable]();
1209
- if (isFunction(obs.subscribe)) {
1436
+ if (isFunction(obs.subscribe))
1210
1437
  return obs.subscribe(subscriber);
1211
- }
1212
- throw new TypeError('Provided object does not correctly implement Symbol.observable');
1438
+ throw new TypeError("Provided object does not correctly implement Symbol.observable");
1213
1439
  });
1214
1440
  }
1215
1441
  function fromArrayLike(array) {
1216
- return new Observable(function (subscriber) {
1217
- for (var i = 0; i < array.length && !subscriber.closed; i++) {
1442
+ return new Observable(function(subscriber) {
1443
+ for (var i = 0; i < array.length && !subscriber.closed; i++)
1218
1444
  subscriber.next(array[i]);
1219
- }
1220
1445
  subscriber.complete();
1221
1446
  });
1222
1447
  }
1223
1448
  function fromPromise(promise) {
1224
- return new Observable(function (subscriber) {
1225
- promise.then(function (value) {
1226
- if (!subscriber.closed) {
1227
- subscriber.next(value);
1228
- subscriber.complete();
1229
- }
1230
- }, function (err) {
1449
+ return new Observable(function(subscriber) {
1450
+ promise.then(function(value) {
1451
+ subscriber.closed || (subscriber.next(value), subscriber.complete());
1452
+ }, function(err) {
1231
1453
  return subscriber.error(err);
1232
1454
  }).then(null, reportUnhandledError);
1233
1455
  });
1234
1456
  }
1235
1457
  function fromIterable(iterable) {
1236
- return new Observable(function (subscriber) {
1458
+ return new Observable(function(subscriber) {
1237
1459
  var e_1, _a;
1238
1460
  try {
1239
1461
  for (var iterable_1 = __values(iterable), iterable_1_1 = iterable_1.next(); !iterable_1_1.done; iterable_1_1 = iterable_1.next()) {
1240
1462
  var value = iterable_1_1.value;
1241
- subscriber.next(value);
1242
- if (subscriber.closed) {
1463
+ if (subscriber.next(value), subscriber.closed)
1243
1464
  return;
1244
- }
1245
1465
  }
1246
1466
  } catch (e_1_1) {
1247
- e_1 = {
1248
- error: e_1_1
1249
- };
1467
+ e_1 = { error: e_1_1 };
1250
1468
  } finally {
1251
1469
  try {
1252
- if (iterable_1_1 && !iterable_1_1.done && (_a = iterable_1.return)) _a.call(iterable_1);
1470
+ iterable_1_1 && !iterable_1_1.done && (_a = iterable_1.return) && _a.call(iterable_1);
1253
1471
  } finally {
1254
1472
  if (e_1) throw e_1.error;
1255
1473
  }
@@ -1258,8 +1476,8 @@ function fromIterable(iterable) {
1258
1476
  });
1259
1477
  }
1260
1478
  function fromAsyncIterable(asyncIterable) {
1261
- return new Observable(function (subscriber) {
1262
- process$1(asyncIterable, subscriber).catch(function (err) {
1479
+ return new Observable(function(subscriber) {
1480
+ process(asyncIterable, subscriber).catch(function(err) {
1263
1481
  return subscriber.error(err);
1264
1482
  });
1265
1483
  });
@@ -1267,44 +1485,31 @@ function fromAsyncIterable(asyncIterable) {
1267
1485
  function fromReadableStreamLike(readableStream) {
1268
1486
  return fromAsyncIterable(readableStreamLikeToAsyncGenerator(readableStream));
1269
1487
  }
1270
- function process$1(asyncIterable, subscriber) {
1271
- var asyncIterable_1, asyncIterable_1_1;
1272
- var e_2, _a;
1273
- return __awaiter(this, void 0, void 0, function () {
1488
+ function process(asyncIterable, subscriber) {
1489
+ var asyncIterable_1, asyncIterable_1_1, e_2, _a;
1490
+ return __awaiter(this, void 0, void 0, function() {
1274
1491
  var value, e_2_1;
1275
- return __generator(this, function (_b) {
1492
+ return __generator(this, function(_b) {
1276
1493
  switch (_b.label) {
1277
1494
  case 0:
1278
- _b.trys.push([0, 5, 6, 11]);
1279
- asyncIterable_1 = __asyncValues(asyncIterable);
1280
- _b.label = 1;
1495
+ _b.trys.push([0, 5, 6, 11]), asyncIterable_1 = __asyncValues(asyncIterable), _b.label = 1;
1281
1496
  case 1:
1282
1497
  return [4, asyncIterable_1.next()];
1283
1498
  case 2:
1284
- if (!(asyncIterable_1_1 = _b.sent(), !asyncIterable_1_1.done)) return [3, 4];
1285
- value = asyncIterable_1_1.value;
1286
- subscriber.next(value);
1287
- if (subscriber.closed) {
1499
+ if (asyncIterable_1_1 = _b.sent(), !!asyncIterable_1_1.done) return [3, 4];
1500
+ if (value = asyncIterable_1_1.value, subscriber.next(value), subscriber.closed)
1288
1501
  return [2];
1289
- }
1290
1502
  _b.label = 3;
1291
1503
  case 3:
1292
1504
  return [3, 1];
1293
1505
  case 4:
1294
1506
  return [3, 11];
1295
1507
  case 5:
1296
- e_2_1 = _b.sent();
1297
- e_2 = {
1298
- error: e_2_1
1299
- };
1300
- return [3, 11];
1508
+ return e_2_1 = _b.sent(), e_2 = { error: e_2_1 }, [3, 11];
1301
1509
  case 6:
1302
- _b.trys.push([6,, 9, 10]);
1303
- if (!(asyncIterable_1_1 && !asyncIterable_1_1.done && (_a = asyncIterable_1.return))) return [3, 8];
1304
- return [4, _a.call(asyncIterable_1)];
1510
+ return _b.trys.push([6, , 9, 10]), asyncIterable_1_1 && !asyncIterable_1_1.done && (_a = asyncIterable_1.return) ? [4, _a.call(asyncIterable_1)] : [3, 8];
1305
1511
  case 7:
1306
- _b.sent();
1307
- _b.label = 8;
1512
+ _b.sent(), _b.label = 8;
1308
1513
  case 8:
1309
1514
  return [3, 10];
1310
1515
  case 9:
@@ -1313,653 +1518,383 @@ function process$1(asyncIterable, subscriber) {
1313
1518
  case 10:
1314
1519
  return [7];
1315
1520
  case 11:
1316
- subscriber.complete();
1317
- return [2];
1521
+ return subscriber.complete(), [2];
1318
1522
  }
1319
1523
  });
1320
1524
  });
1321
1525
  }
1322
- function share(options) {
1323
- if (options === void 0) {
1324
- options = {};
1325
- }
1326
- var _a = options.connector,
1327
- connector = _a === void 0 ? function () {
1328
- return new Subject();
1329
- } : _a,
1330
- _b = options.resetOnError,
1331
- resetOnError = _b === void 0 ? true : _b,
1332
- _c = options.resetOnComplete,
1333
- resetOnComplete = _c === void 0 ? true : _c,
1334
- _d = options.resetOnRefCountZero,
1335
- resetOnRefCountZero = _d === void 0 ? true : _d;
1336
- return function (wrapperSource) {
1337
- var connection;
1338
- var resetConnection;
1339
- var subject;
1340
- var refCount = 0;
1341
- var hasCompleted = false;
1342
- var hasErrored = false;
1343
- var cancelReset = function () {
1344
- resetConnection === null || resetConnection === void 0 ? void 0 : resetConnection.unsubscribe();
1345
- resetConnection = undefined;
1346
- };
1347
- var reset = function () {
1348
- cancelReset();
1349
- connection = subject = undefined;
1350
- hasCompleted = hasErrored = false;
1526
+ function executeSchedule(parentSubscription, scheduler, work, delay, repeat) {
1527
+ delay === void 0 && (delay = 0), repeat === void 0 && (repeat = !1);
1528
+ var scheduleSubscription = scheduler.schedule(function() {
1529
+ work(), repeat ? parentSubscription.add(this.schedule(null, delay)) : this.unsubscribe();
1530
+ }, delay);
1531
+ if (parentSubscription.add(scheduleSubscription), !repeat)
1532
+ return scheduleSubscription;
1533
+ }
1534
+ function observeOn(scheduler, delay) {
1535
+ return delay === void 0 && (delay = 0), operate(function(source, subscriber) {
1536
+ source.subscribe(createOperatorSubscriber(subscriber, function(value) {
1537
+ return executeSchedule(subscriber, scheduler, function() {
1538
+ return subscriber.next(value);
1539
+ }, delay);
1540
+ }, function() {
1541
+ return executeSchedule(subscriber, scheduler, function() {
1542
+ return subscriber.complete();
1543
+ }, delay);
1544
+ }, function(err) {
1545
+ return executeSchedule(subscriber, scheduler, function() {
1546
+ return subscriber.error(err);
1547
+ }, delay);
1548
+ }));
1549
+ });
1550
+ }
1551
+ function subscribeOn(scheduler, delay) {
1552
+ return delay === void 0 && (delay = 0), operate(function(source, subscriber) {
1553
+ subscriber.add(scheduler.schedule(function() {
1554
+ return source.subscribe(subscriber);
1555
+ }, delay));
1556
+ });
1557
+ }
1558
+ function scheduleObservable(input, scheduler) {
1559
+ return innerFrom(input).pipe(subscribeOn(scheduler), observeOn(scheduler));
1560
+ }
1561
+ function schedulePromise(input, scheduler) {
1562
+ return innerFrom(input).pipe(subscribeOn(scheduler), observeOn(scheduler));
1563
+ }
1564
+ function scheduleArray(input, scheduler) {
1565
+ return new Observable(function(subscriber) {
1566
+ var i = 0;
1567
+ return scheduler.schedule(function() {
1568
+ i === input.length ? subscriber.complete() : (subscriber.next(input[i++]), subscriber.closed || this.schedule());
1569
+ });
1570
+ });
1571
+ }
1572
+ function scheduleIterable(input, scheduler) {
1573
+ return new Observable(function(subscriber) {
1574
+ var iterator$1;
1575
+ return executeSchedule(subscriber, scheduler, function() {
1576
+ iterator$1 = input[iterator](), executeSchedule(subscriber, scheduler, function() {
1577
+ var _a, value, done;
1578
+ try {
1579
+ _a = iterator$1.next(), value = _a.value, done = _a.done;
1580
+ } catch (err) {
1581
+ subscriber.error(err);
1582
+ return;
1583
+ }
1584
+ done ? subscriber.complete() : subscriber.next(value);
1585
+ }, 0, !0);
1586
+ }), function() {
1587
+ return isFunction(iterator$1?.return) && iterator$1.return();
1351
1588
  };
1352
- var resetAndUnsubscribe = function () {
1589
+ });
1590
+ }
1591
+ function scheduleAsyncIterable(input, scheduler) {
1592
+ if (!input)
1593
+ throw new Error("Iterable cannot be null");
1594
+ return new Observable(function(subscriber) {
1595
+ executeSchedule(subscriber, scheduler, function() {
1596
+ var iterator2 = input[Symbol.asyncIterator]();
1597
+ executeSchedule(subscriber, scheduler, function() {
1598
+ iterator2.next().then(function(result) {
1599
+ result.done ? subscriber.complete() : subscriber.next(result.value);
1600
+ });
1601
+ }, 0, !0);
1602
+ });
1603
+ });
1604
+ }
1605
+ function scheduleReadableStreamLike(input, scheduler) {
1606
+ return scheduleAsyncIterable(readableStreamLikeToAsyncGenerator(input), scheduler);
1607
+ }
1608
+ function scheduled(input, scheduler) {
1609
+ if (input != null) {
1610
+ if (isInteropObservable(input))
1611
+ return scheduleObservable(input, scheduler);
1612
+ if (isArrayLike(input))
1613
+ return scheduleArray(input, scheduler);
1614
+ if (isPromise(input))
1615
+ return schedulePromise(input, scheduler);
1616
+ if (isAsyncIterable(input))
1617
+ return scheduleAsyncIterable(input, scheduler);
1618
+ if (isIterable(input))
1619
+ return scheduleIterable(input, scheduler);
1620
+ if (isReadableStreamLike(input))
1621
+ return scheduleReadableStreamLike(input, scheduler);
1622
+ }
1623
+ throw createInvalidObservableTypeError(input);
1624
+ }
1625
+ function from(input, scheduler) {
1626
+ return scheduler ? scheduled(input, scheduler) : innerFrom(input);
1627
+ }
1628
+ function of() {
1629
+ for (var args = [], _i = 0; _i < arguments.length; _i++)
1630
+ args[_i] = arguments[_i];
1631
+ var scheduler = popScheduler(args);
1632
+ return from(args, scheduler);
1633
+ }
1634
+ function isValidDate(value) {
1635
+ return value instanceof Date && !isNaN(value);
1636
+ }
1637
+ function map(project, thisArg) {
1638
+ return operate(function(source, subscriber) {
1639
+ var index = 0;
1640
+ source.subscribe(createOperatorSubscriber(subscriber, function(value) {
1641
+ subscriber.next(project.call(thisArg, value, index++));
1642
+ }));
1643
+ });
1644
+ }
1645
+ function timer(dueTime, intervalOrScheduler, scheduler) {
1646
+ scheduler === void 0 && (scheduler = async);
1647
+ var intervalDuration = -1;
1648
+ return intervalOrScheduler != null && (isScheduler(intervalOrScheduler) ? scheduler = intervalOrScheduler : intervalDuration = intervalOrScheduler), new Observable(function(subscriber) {
1649
+ var due = isValidDate(dueTime) ? 0 - scheduler.now() : dueTime;
1650
+ due < 0 && (due = 0);
1651
+ var n = 0;
1652
+ return scheduler.schedule(function() {
1653
+ subscriber.closed || (subscriber.next(n++), 0 <= intervalDuration ? this.schedule(void 0, intervalDuration) : subscriber.complete());
1654
+ }, due);
1655
+ });
1656
+ }
1657
+ function catchError(selector) {
1658
+ return operate(function(source, subscriber) {
1659
+ var innerSub = null, syncUnsub = !1, handledResult;
1660
+ innerSub = source.subscribe(createOperatorSubscriber(subscriber, void 0, void 0, function(err) {
1661
+ handledResult = innerFrom(selector(err, catchError(selector)(source))), innerSub ? (innerSub.unsubscribe(), innerSub = null, handledResult.subscribe(subscriber)) : syncUnsub = !0;
1662
+ })), syncUnsub && (innerSub.unsubscribe(), innerSub = null, handledResult.subscribe(subscriber));
1663
+ });
1664
+ }
1665
+ function finalize(callback) {
1666
+ return operate(function(source, subscriber) {
1667
+ try {
1668
+ source.subscribe(subscriber);
1669
+ } finally {
1670
+ subscriber.add(callback);
1671
+ }
1672
+ });
1673
+ }
1674
+ function share(options) {
1675
+ options === void 0 && (options = {});
1676
+ var _a = options.connector, connector = _a === void 0 ? function() {
1677
+ return new Subject();
1678
+ } : _a, _b = options.resetOnError, resetOnError = _b === void 0 ? !0 : _b, _c = options.resetOnComplete, resetOnComplete = _c === void 0 ? !0 : _c, _d = options.resetOnRefCountZero, resetOnRefCountZero = _d === void 0 ? !0 : _d;
1679
+ return function(wrapperSource) {
1680
+ var connection, resetConnection, subject, refCount = 0, hasCompleted = !1, hasErrored = !1, cancelReset = function() {
1681
+ resetConnection?.unsubscribe(), resetConnection = void 0;
1682
+ }, reset = function() {
1683
+ cancelReset(), connection = subject = void 0, hasCompleted = hasErrored = !1;
1684
+ }, resetAndUnsubscribe = function() {
1353
1685
  var conn = connection;
1354
- reset();
1355
- conn === null || conn === void 0 ? void 0 : conn.unsubscribe();
1686
+ reset(), conn?.unsubscribe();
1356
1687
  };
1357
- return operate(function (source, subscriber) {
1358
- refCount++;
1359
- if (!hasErrored && !hasCompleted) {
1360
- cancelReset();
1361
- }
1362
- var dest = subject = subject !== null && subject !== void 0 ? subject : connector();
1363
- subscriber.add(function () {
1364
- refCount--;
1365
- if (refCount === 0 && !hasErrored && !hasCompleted) {
1366
- resetConnection = handleReset(resetAndUnsubscribe, resetOnRefCountZero);
1688
+ return operate(function(source, subscriber) {
1689
+ refCount++, !hasErrored && !hasCompleted && cancelReset();
1690
+ var dest = subject = subject ?? connector();
1691
+ subscriber.add(function() {
1692
+ refCount--, refCount === 0 && !hasErrored && !hasCompleted && (resetConnection = handleReset(resetAndUnsubscribe, resetOnRefCountZero));
1693
+ }), dest.subscribe(subscriber), !connection && refCount > 0 && (connection = new SafeSubscriber({
1694
+ next: function(value) {
1695
+ return dest.next(value);
1696
+ },
1697
+ error: function(err) {
1698
+ hasErrored = !0, cancelReset(), resetConnection = handleReset(reset, resetOnError, err), dest.error(err);
1699
+ },
1700
+ complete: function() {
1701
+ hasCompleted = !0, cancelReset(), resetConnection = handleReset(reset, resetOnComplete), dest.complete();
1367
1702
  }
1368
- });
1369
- dest.subscribe(subscriber);
1370
- if (!connection && refCount > 0) {
1371
- connection = new SafeSubscriber({
1372
- next: function (value) {
1373
- return dest.next(value);
1374
- },
1375
- error: function (err) {
1376
- hasErrored = true;
1377
- cancelReset();
1378
- resetConnection = handleReset(reset, resetOnError, err);
1379
- dest.error(err);
1380
- },
1381
- complete: function () {
1382
- hasCompleted = true;
1383
- cancelReset();
1384
- resetConnection = handleReset(reset, resetOnComplete);
1385
- dest.complete();
1386
- }
1387
- });
1388
- innerFrom(source).subscribe(connection);
1389
- }
1703
+ }), innerFrom(source).subscribe(connection));
1390
1704
  })(wrapperSource);
1391
1705
  };
1392
1706
  }
1393
1707
  function handleReset(reset, on) {
1394
- var args = [];
1395
- for (var _i = 2; _i < arguments.length; _i++) {
1708
+ for (var args = [], _i = 2; _i < arguments.length; _i++)
1396
1709
  args[_i - 2] = arguments[_i];
1397
- }
1398
- if (on === true) {
1710
+ if (on === !0) {
1399
1711
  reset();
1400
1712
  return;
1401
1713
  }
1402
- if (on === false) {
1403
- return;
1404
- }
1405
- var onSubscriber = new SafeSubscriber({
1406
- next: function () {
1407
- onSubscriber.unsubscribe();
1408
- reset();
1409
- }
1410
- });
1411
- return innerFrom(on.apply(void 0, __spreadArray([], __read(args)))).subscribe(onSubscriber);
1412
- }
1413
- function shareReplay(configOrBufferSize, windowTime, scheduler) {
1414
- var _a, _b, _c;
1415
- var bufferSize;
1416
- var refCount = false;
1417
- if (configOrBufferSize && typeof configOrBufferSize === 'object') {
1418
- _a = configOrBufferSize.bufferSize, bufferSize = _a === void 0 ? Infinity : _a, _b = configOrBufferSize.windowTime, windowTime = _b === void 0 ? Infinity : _b, _c = configOrBufferSize.refCount, refCount = _c === void 0 ? false : _c, scheduler = configOrBufferSize.scheduler;
1419
- } else {
1420
- bufferSize = configOrBufferSize !== null && configOrBufferSize !== void 0 ? configOrBufferSize : Infinity;
1714
+ if (on !== !1) {
1715
+ var onSubscriber = new SafeSubscriber({
1716
+ next: function() {
1717
+ onSubscriber.unsubscribe(), reset();
1718
+ }
1719
+ });
1720
+ return innerFrom(on.apply(void 0, __spreadArray([], __read(args)))).subscribe(onSubscriber);
1421
1721
  }
1422
- return share({
1423
- connector: function () {
1424
- return new ReplaySubject(bufferSize, windowTime, scheduler);
1425
- },
1426
- resetOnError: true,
1427
- resetOnComplete: false,
1428
- resetOnRefCountZero: refCount
1429
- });
1430
1722
  }
1431
1723
  function tap(observerOrNext, error, complete) {
1432
- var tapObserver = isFunction(observerOrNext) || error || complete ? {
1433
- next: observerOrNext,
1434
- error: error,
1435
- complete: complete
1436
- } : observerOrNext;
1437
- return tapObserver ? operate(function (source, subscriber) {
1724
+ var tapObserver = isFunction(observerOrNext) || error || complete ? { next: observerOrNext, error, complete } : observerOrNext;
1725
+ return tapObserver ? operate(function(source, subscriber) {
1438
1726
  var _a;
1439
- (_a = tapObserver.subscribe) === null || _a === void 0 ? void 0 : _a.call(tapObserver);
1440
- var isUnsub = true;
1441
- source.subscribe(createOperatorSubscriber(subscriber, function (value) {
1442
- var _a;
1443
- (_a = tapObserver.next) === null || _a === void 0 ? void 0 : _a.call(tapObserver, value);
1444
- subscriber.next(value);
1445
- }, function () {
1446
- var _a;
1447
- isUnsub = false;
1448
- (_a = tapObserver.complete) === null || _a === void 0 ? void 0 : _a.call(tapObserver);
1449
- subscriber.complete();
1450
- }, function (err) {
1451
- var _a;
1452
- isUnsub = false;
1453
- (_a = tapObserver.error) === null || _a === void 0 ? void 0 : _a.call(tapObserver, err);
1454
- subscriber.error(err);
1455
- }, function () {
1456
- var _a, _b;
1457
- if (isUnsub) {
1458
- (_a = tapObserver.unsubscribe) === null || _a === void 0 ? void 0 : _a.call(tapObserver);
1459
- }
1460
- (_b = tapObserver.finalize) === null || _b === void 0 ? void 0 : _b.call(tapObserver);
1727
+ (_a = tapObserver.subscribe) === null || _a === void 0 || _a.call(tapObserver);
1728
+ var isUnsub = !0;
1729
+ source.subscribe(createOperatorSubscriber(subscriber, function(value) {
1730
+ var _a2;
1731
+ (_a2 = tapObserver.next) === null || _a2 === void 0 || _a2.call(tapObserver, value), subscriber.next(value);
1732
+ }, function() {
1733
+ var _a2;
1734
+ isUnsub = !1, (_a2 = tapObserver.complete) === null || _a2 === void 0 || _a2.call(tapObserver), subscriber.complete();
1735
+ }, function(err) {
1736
+ var _a2;
1737
+ isUnsub = !1, (_a2 = tapObserver.error) === null || _a2 === void 0 || _a2.call(tapObserver, err), subscriber.error(err);
1738
+ }, function() {
1739
+ var _a2, _b;
1740
+ isUnsub && ((_a2 = tapObserver.unsubscribe) === null || _a2 === void 0 || _a2.call(tapObserver)), (_b = tapObserver.finalize) === null || _b === void 0 || _b.call(tapObserver);
1461
1741
  }));
1462
1742
  }) : identity;
1463
1743
  }
1464
- var shim = {
1465
- exports: {}
1466
- };
1467
- var useSyncExternalStoreShim_production_min = {};
1468
-
1469
- /**
1470
- * @license React
1471
- * use-sync-external-store-shim.production.min.js
1472
- *
1473
- * Copyright (c) Facebook, Inc. and its affiliates.
1474
- *
1475
- * This source code is licensed under the MIT license found in the
1476
- * LICENSE file in the root directory of this source tree.
1477
- */
1478
-
1479
- var hasRequiredUseSyncExternalStoreShim_production_min;
1480
- function requireUseSyncExternalStoreShim_production_min() {
1481
- if (hasRequiredUseSyncExternalStoreShim_production_min) return useSyncExternalStoreShim_production_min;
1482
- hasRequiredUseSyncExternalStoreShim_production_min = 1;
1483
- var e = require$$0__default.default;
1484
- function h(a, b) {
1485
- return a === b && (0 !== a || 1 / a === 1 / b) || a !== a && b !== b;
1486
- }
1487
- var k = "function" === typeof Object.is ? Object.is : h,
1488
- l = e.useState,
1489
- m = e.useEffect,
1490
- n = e.useLayoutEffect,
1491
- p = e.useDebugValue;
1492
- function q(a, b) {
1493
- var d = b(),
1494
- f = l({
1495
- inst: {
1496
- value: d,
1497
- getSnapshot: b
1498
- }
1499
- }),
1500
- c = f[0].inst,
1501
- g = f[1];
1502
- n(function () {
1503
- c.value = d;
1504
- c.getSnapshot = b;
1505
- r(c) && g({
1506
- inst: c
1507
- });
1508
- }, [a, d, b]);
1509
- m(function () {
1510
- r(c) && g({
1511
- inst: c
1512
- });
1513
- return a(function () {
1514
- r(c) && g({
1515
- inst: c
1516
- });
1517
- });
1518
- }, [a]);
1519
- p(d);
1520
- return d;
1521
- }
1522
- function r(a) {
1523
- var b = a.getSnapshot;
1524
- a = a.value;
1525
- try {
1526
- var d = b();
1527
- return !k(a, d);
1528
- } catch (f) {
1529
- return !0;
1530
- }
1531
- }
1532
- function t(a, b) {
1533
- return b();
1534
- }
1535
- var u = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? t : q;
1536
- useSyncExternalStoreShim_production_min.useSyncExternalStore = void 0 !== e.useSyncExternalStore ? e.useSyncExternalStore : u;
1537
- return useSyncExternalStoreShim_production_min;
1538
- }
1539
- var useSyncExternalStoreShim_development = {};
1540
-
1541
- /**
1542
- * @license React
1543
- * use-sync-external-store-shim.development.js
1544
- *
1545
- * Copyright (c) Facebook, Inc. and its affiliates.
1546
- *
1547
- * This source code is licensed under the MIT license found in the
1548
- * LICENSE file in the root directory of this source tree.
1549
- */
1550
-
1551
- var hasRequiredUseSyncExternalStoreShim_development;
1552
- function requireUseSyncExternalStoreShim_development() {
1553
- if (hasRequiredUseSyncExternalStoreShim_development) return useSyncExternalStoreShim_development;
1554
- hasRequiredUseSyncExternalStoreShim_development = 1;
1555
- if (process.env.NODE_ENV !== "production") {
1556
- (function () {
1557
- /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
1558
- if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart === 'function') {
1559
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
1560
- }
1561
- var React = require$$0__default.default;
1562
- var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
1563
- function error(format) {
1564
- {
1565
- {
1566
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
1567
- args[_key2 - 1] = arguments[_key2];
1568
- }
1569
- printWarning('error', format, args);
1570
- }
1571
- }
1572
- }
1573
- function printWarning(level, format, args) {
1574
- // When changing this logic, you might want to also
1575
- // update consoleWithStackDev.www.js as well.
1576
- {
1577
- var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
1578
- var stack = ReactDebugCurrentFrame.getStackAddendum();
1579
- if (stack !== '') {
1580
- format += '%s';
1581
- args = args.concat([stack]);
1582
- } // eslint-disable-next-line react-internal/safe-string-coercion
1583
-
1584
- var argsWithFormat = args.map(function (item) {
1585
- return String(item);
1586
- }); // Careful: RN currently depends on this prefix
1587
-
1588
- argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
1589
- // breaks IE9: https://github.com/facebook/react/issues/13610
1590
- // eslint-disable-next-line react-internal/no-production-logging
1591
-
1592
- Function.prototype.apply.call(console[level], console, argsWithFormat);
1593
- }
1594
- }
1595
-
1596
- /**
1597
- * inlined Object.is polyfill to avoid requiring consumers ship their own
1598
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
1599
- */
1600
- function is(x, y) {
1601
- return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
1602
- ;
1603
- }
1604
- var objectIs = typeof Object.is === 'function' ? Object.is : is;
1605
-
1606
- // dispatch for CommonJS interop named imports.
1607
-
1608
- var useState = React.useState,
1609
- useEffect = React.useEffect,
1610
- useLayoutEffect = React.useLayoutEffect,
1611
- useDebugValue = React.useDebugValue;
1612
- var didWarnOld18Alpha = false;
1613
- var didWarnUncachedGetSnapshot = false; // Disclaimer: This shim breaks many of the rules of React, and only works
1614
- // because of a very particular set of implementation details and assumptions
1615
- // -- change any one of them and it will break. The most important assumption
1616
- // is that updates are always synchronous, because concurrent rendering is
1617
- // only available in versions of React that also have a built-in
1618
- // useSyncExternalStore API. And we only use this shim when the built-in API
1619
- // does not exist.
1620
- //
1621
- // Do not assume that the clever hacks used by this hook also work in general.
1622
- // The point of this shim is to replace the need for hacks by other libraries.
1623
-
1624
- function useSyncExternalStore(subscribe, getSnapshot,
1625
- // Note: The shim does not use getServerSnapshot, because pre-18 versions of
1626
- // React do not expose a way to check if we're hydrating. So users of the shim
1627
- // will need to track that themselves and return the correct value
1628
- // from `getSnapshot`.
1629
- getServerSnapshot) {
1630
- {
1631
- if (!didWarnOld18Alpha) {
1632
- if (React.startTransition !== undefined) {
1633
- didWarnOld18Alpha = true;
1634
- error('You are using an outdated, pre-release alpha of React 18 that ' + 'does not support useSyncExternalStore. The ' + 'use-sync-external-store shim will not work correctly. Upgrade ' + 'to a newer pre-release.');
1635
- }
1636
- }
1637
- } // Read the current snapshot from the store on every render. Again, this
1638
- // breaks the rules of React, and only works here because of specific
1639
- // implementation details, most importantly that updates are
1640
- // always synchronous.
1641
-
1642
- var value = getSnapshot();
1643
- {
1644
- if (!didWarnUncachedGetSnapshot) {
1645
- var cachedValue = getSnapshot();
1646
- if (!objectIs(value, cachedValue)) {
1647
- error('The result of getSnapshot should be cached to avoid an infinite loop');
1648
- didWarnUncachedGetSnapshot = true;
1649
- }
1650
- }
1651
- } // Because updates are synchronous, we don't queue them. Instead we force a
1652
- // re-render whenever the subscribed state changes by updating an some
1653
- // arbitrary useState hook. Then, during render, we call getSnapshot to read
1654
- // the current value.
1655
- //
1656
- // Because we don't actually use the state returned by the useState hook, we
1657
- // can save a bit of memory by storing other stuff in that slot.
1658
- //
1659
- // To implement the early bailout, we need to track some things on a mutable
1660
- // object. Usually, we would put that in a useRef hook, but we can stash it in
1661
- // our useState hook instead.
1662
- //
1663
- // To force a re-render, we call forceUpdate({inst}). That works because the
1664
- // new object always fails an equality check.
1665
-
1666
- var _useState = useState({
1667
- inst: {
1668
- value: value,
1669
- getSnapshot: getSnapshot
1670
- }
1671
- }),
1672
- inst = _useState[0].inst,
1673
- forceUpdate = _useState[1]; // Track the latest getSnapshot function with a ref. This needs to be updated
1674
- // in the layout phase so we can access it during the tearing check that
1675
- // happens on subscribe.
1676
-
1677
- useLayoutEffect(function () {
1678
- inst.value = value;
1679
- inst.getSnapshot = getSnapshot; // Whenever getSnapshot or subscribe changes, we need to check in the
1680
- // commit phase if there was an interleaved mutation. In concurrent mode
1681
- // this can happen all the time, but even in synchronous mode, an earlier
1682
- // effect may have mutated the store.
1683
-
1684
- if (checkIfSnapshotChanged(inst)) {
1685
- // Force a re-render.
1686
- forceUpdate({
1687
- inst: inst
1688
- });
1689
- }
1690
- }, [subscribe, value, getSnapshot]);
1691
- useEffect(function () {
1692
- // Check for changes right before subscribing. Subsequent changes will be
1693
- // detected in the subscription handler.
1694
- if (checkIfSnapshotChanged(inst)) {
1695
- // Force a re-render.
1696
- forceUpdate({
1697
- inst: inst
1698
- });
1699
- }
1700
- var handleStoreChange = function () {
1701
- // TODO: Because there is no cross-renderer API for batching updates, it's
1702
- // up to the consumer of this library to wrap their subscription event
1703
- // with unstable_batchedUpdates. Should we try to detect when this isn't
1704
- // the case and print a warning in development?
1705
- // The store changed. Check if the snapshot changed since the last time we
1706
- // read from the store.
1707
- if (checkIfSnapshotChanged(inst)) {
1708
- // Force a re-render.
1709
- forceUpdate({
1710
- inst: inst
1711
- });
1712
- }
1713
- }; // Subscribe to the store and return a clean-up function.
1714
-
1715
- return subscribe(handleStoreChange);
1716
- }, [subscribe]);
1717
- useDebugValue(value);
1718
- return value;
1719
- }
1720
- function checkIfSnapshotChanged(inst) {
1721
- var latestGetSnapshot = inst.getSnapshot;
1722
- var prevValue = inst.value;
1723
- try {
1724
- var nextValue = latestGetSnapshot();
1725
- return !objectIs(prevValue, nextValue);
1726
- } catch (error) {
1727
- return true;
1728
- }
1729
- }
1730
- function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {
1731
- // Note: The shim does not use getServerSnapshot, because pre-18 versions of
1732
- // React do not expose a way to check if we're hydrating. So users of the shim
1733
- // will need to track that themselves and return the correct value
1734
- // from `getSnapshot`.
1735
- return getSnapshot();
1736
- }
1737
- var canUseDOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined');
1738
- var isServerEnvironment = !canUseDOM;
1739
- var shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore;
1740
- var useSyncExternalStore$2 = React.useSyncExternalStore !== undefined ? React.useSyncExternalStore : shim;
1741
- useSyncExternalStoreShim_development.useSyncExternalStore = useSyncExternalStore$2;
1742
- /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
1743
- if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop === 'function') {
1744
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
1745
- }
1746
- })();
1747
- }
1748
- return useSyncExternalStoreShim_development;
1749
- }
1750
- if (process.env.NODE_ENV === 'production') {
1751
- shim.exports = requireUseSyncExternalStoreShim_production_min();
1752
- } else {
1753
- shim.exports = requireUseSyncExternalStoreShim_development();
1754
- }
1755
- var shimExports = shim.exports;
1756
1744
  function getValue(value) {
1757
- return typeof value === 'function' ? value() : value;
1758
- }
1759
- var cache = new WeakMap();
1760
- function getOrCreateStore(inputObservable, initialValue) {
1761
- if (!cache.has(inputObservable)) {
1762
- var entry_1 = {
1763
- currentValue: initialValue
1764
- };
1765
- entry_1.observable = inputObservable.pipe(shareReplay({
1766
- refCount: true,
1767
- bufferSize: 1
1768
- }), tap(function (value) {
1769
- return entry_1.currentValue = value;
1770
- }));
1771
- // Eagerly subscribe to sync set `entry.currentValue` to what the observable returns
1772
- entry_1.subscription = entry_1.observable.subscribe();
1773
- cache.set(inputObservable, entry_1);
1774
- }
1775
- return cache.get(inputObservable);
1776
- }
1777
- function useObservable(observable, initialValue) {
1778
- var _a = require$$0.useMemo(function () {
1779
- var store = getOrCreateStore(observable, getValue(initialValue));
1780
- if (store.subscription.closed) {
1781
- store.subscription = store.observable.subscribe();
1745
+ return typeof value == "function" ? value() : value;
1746
+ }
1747
+ const cache = /* @__PURE__ */ new WeakMap();
1748
+ function useObservable(observable2, initialValue) {
1749
+ const $ = distExports.c(9);
1750
+ let t0;
1751
+ if (!cache.has(observable2)) {
1752
+ const state = {
1753
+ didEmit: !1
1754
+ }, entry = {
1755
+ state,
1756
+ observable: observable2.pipe(map(_temp$1), catchError(_temp2), tap((t12) => {
1757
+ const {
1758
+ snapshot,
1759
+ error: error_0
1760
+ } = t12;
1761
+ state.didEmit = !0, state.snapshot = snapshot, state.error = error_0;
1762
+ }), map(_temp3), finalize(() => cache.delete(observable2)), share({
1763
+ resetOnRefCountZero: _temp4
1764
+ })),
1765
+ getSnapshot: (initialValue_0) => {
1766
+ if (state.error)
1767
+ throw state.error;
1768
+ return state.didEmit ? state.snapshot : getValue(initialValue_0);
1782
1769
  }
1783
- return [function getSnapshot() {
1784
- // @TODO: perf opt opportunity: we could do `store.subscription.unsubscribe()` here to clear up some memory, as this subscription is only needed to provide a sync initialValue.
1785
- return store.currentValue;
1786
- }, function subscribe(callback) {
1787
- // @TODO: perf opt opportunity: we could do `store.subscription.unsubscribe()` here as we only need 1 subscription active to keep the observer alive
1788
- var sub = store.observable.subscribe(callback);
1789
- return function () {
1790
- sub.unsubscribe();
1791
- };
1792
- }];
1793
- }, [observable]),
1794
- getSnapshot = _a[0],
1795
- subscribe = _a[1];
1796
- var shouldRestoreSubscriptionRef = require$$0.useRef(false);
1797
- require$$0.useEffect(function () {
1798
- var store = getOrCreateStore(observable, getValue(initialValue));
1799
- if (shouldRestoreSubscriptionRef.current) {
1800
- if (store.subscription.closed) {
1801
- store.subscription = store.observable.subscribe();
1802
- }
1803
- shouldRestoreSubscriptionRef.current = false;
1804
- }
1805
- return function () {
1806
- // React StrictMode will call effects as `setup + teardown + setup` thus we can't trust this callback as "react is about to unmount"
1807
- // Tracking this ref lets us set the subscription back up on the next `setup` call if needed, and if it really did unmounted then all is well
1808
- shouldRestoreSubscriptionRef.current = !store.subscription.closed;
1809
- store.subscription.unsubscribe();
1810
1770
  };
1811
- }, [observable]);
1812
- return shimExports.useSyncExternalStore(subscribe, getSnapshot);
1813
- }
1814
- function useMemoObservable(observableOrFactory, deps, initialValue) {
1815
- return useObservable(require$$0.useMemo(function () {
1816
- return getValue(observableOrFactory);
1817
- }, deps), initialValue);
1818
- }
1819
- function DocumentPreview(_ref) {
1820
- let {
1821
- documentId,
1822
- style,
1823
- schemaTypeName,
1824
- ...buttonProps
1825
- } = _ref;
1826
- const schema = sanity.useSchema();
1827
- const schemaType = schemaTypeName ? schema.get(schemaTypeName) : void 0;
1828
- if (!schemaTypeName) {
1829
- return /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
1830
- style: {
1831
- minHeight: "36px"
1832
- },
1833
- children: /* @__PURE__ */jsxRuntime.jsx(sanity.DefaultPreview, {
1834
- withShadow: false,
1835
- withBorder: false,
1836
- title: "Loading...",
1837
- schemaType,
1838
- isPlaceholder: true
1839
- })
1840
- });
1771
+ entry.observable.subscribe().unsubscribe(), cache.set(observable2, entry);
1841
1772
  }
1842
- if (!schemaType) {
1843
- return /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
1844
- children: /* @__PURE__ */jsxRuntime.jsx(sanity.DefaultPreview, {
1845
- withShadow: false,
1846
- withBorder: false,
1847
- media: () => /* @__PURE__ */jsxRuntime.jsx(icons.ErrorOutlineIcon, {}),
1848
- title: /* @__PURE__ */jsxRuntime.jsxs(jsxRuntime.Fragment, {
1849
- children: ["Unknown type ", /* @__PURE__ */jsxRuntime.jsx("code", {
1850
- children: schemaTypeName != null ? schemaTypeName : "N/A"
1851
- }), " for ", documentId]
1852
- })
1853
- })
1854
- });
1855
- }
1856
- return /* @__PURE__ */jsxRuntime.jsx(DocumentPreviewInner, {
1857
- documentId,
1858
- schemaTypeName,
1859
- schemaType,
1860
- style,
1861
- ...buttonProps
1773
+ let t1;
1774
+ $[0] !== observable2 ? (t1 = cache.get(observable2), $[0] = observable2, $[1] = t1) : t1 = $[1], t0 = t1;
1775
+ const instance = t0;
1776
+ let t2;
1777
+ $[2] !== instance.observable ? (t2 = (onStoreChange) => {
1778
+ const subscription_0 = instance.observable.subscribe(onStoreChange);
1779
+ return () => {
1780
+ subscription_0.unsubscribe();
1781
+ };
1782
+ }, $[2] = instance.observable, $[3] = t2) : t2 = $[3];
1783
+ const subscribe = t2;
1784
+ let t3;
1785
+ $[4] !== initialValue || $[5] !== instance ? (t3 = () => instance.getSnapshot(initialValue), $[4] = initialValue, $[5] = instance, $[6] = t3) : t3 = $[6];
1786
+ let t4;
1787
+ return $[7] !== initialValue ? (t4 = typeof initialValue > "u" ? void 0 : () => getValue(initialValue), $[7] = initialValue, $[8] = t4) : t4 = $[8], require$$0.useSyncExternalStore(subscribe, t3, t4);
1788
+ }
1789
+ function _temp4() {
1790
+ return timer(0, asapScheduler);
1791
+ }
1792
+ function _temp3(value_0) {
1793
+ }
1794
+ function _temp2(error) {
1795
+ return of({
1796
+ snapshot: void 0,
1797
+ error
1862
1798
  });
1863
1799
  }
1864
- function DocumentPreviewInner(_ref2) {
1865
- let {
1866
- documentId,
1867
- schemaType,
1868
- style,
1869
- button
1870
- } = _ref2;
1871
- const documentPreviewStore = sanity.useDocumentPreviewStore();
1872
- const {
1873
- draft,
1874
- published,
1875
- isLoading
1876
- } = useMemoObservable(() => sanity.getPreviewStateObservable(documentPreviewStore, schemaType, documentId, ""), [documentId, documentPreviewStore, schemaType]);
1877
- const sanityDocument = require$$0.useMemo(() => {
1878
- return {
1879
- _id: documentId,
1880
- _type: schemaType == null ? void 0 : schemaType.name
1881
- };
1882
- }, [documentId, schemaType == null ? void 0 : schemaType.name]);
1883
- const {
1884
- onClick: onIntentClick,
1885
- href
1886
- } = router.useIntentLink({
1800
+ function _temp$1(value) {
1801
+ return {
1802
+ snapshot: value,
1803
+ error: void 0
1804
+ };
1805
+ }
1806
+ function DocumentPreview({
1807
+ documentId,
1808
+ style,
1809
+ schemaTypeName,
1810
+ ...buttonProps
1811
+ }) {
1812
+ const schema = sanity.useSchema(), schemaType = schemaTypeName ? schema.get(schemaTypeName) : void 0;
1813
+ return schemaTypeName ? schemaType ? /* @__PURE__ */ jsxRuntime.jsx(
1814
+ DocumentPreviewInner,
1815
+ {
1816
+ documentId,
1817
+ schemaTypeName,
1818
+ schemaType,
1819
+ style,
1820
+ ...buttonProps
1821
+ }
1822
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { children: /* @__PURE__ */ jsxRuntime.jsx(
1823
+ sanity.DefaultPreview,
1824
+ {
1825
+ withShadow: !1,
1826
+ withBorder: !1,
1827
+ media: () => /* @__PURE__ */ jsxRuntime.jsx(icons.ErrorOutlineIcon, {}),
1828
+ title: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
1829
+ "Unknown type ",
1830
+ /* @__PURE__ */ jsxRuntime.jsx("code", { children: schemaTypeName ?? "N/A" }),
1831
+ " for ",
1832
+ documentId
1833
+ ] })
1834
+ }
1835
+ ) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { style: { minHeight: "36px" }, children: /* @__PURE__ */ jsxRuntime.jsx(
1836
+ sanity.DefaultPreview,
1837
+ {
1838
+ withShadow: !1,
1839
+ withBorder: !1,
1840
+ title: "Loading...",
1841
+ schemaType,
1842
+ isPlaceholder: !0
1843
+ }
1844
+ ) });
1845
+ }
1846
+ function DocumentPreviewInner({
1847
+ documentId,
1848
+ schemaType,
1849
+ style,
1850
+ button
1851
+ }) {
1852
+ const documentPreviewStore = sanity.useDocumentPreviewStore(), previewStateObservable = require$$0.useMemo(
1853
+ () => sanity.getPreviewStateObservable(documentPreviewStore, schemaType, documentId),
1854
+ [documentId, documentPreviewStore, schemaType]
1855
+ ), {
1856
+ snapshot,
1857
+ original,
1858
+ isLoading: previewIsLoading
1859
+ } = useObservable(previewStateObservable, {
1860
+ snapshot: null,
1861
+ isLoading: !0,
1862
+ original: null
1863
+ }), sanityDocument = require$$0.useMemo(() => ({
1864
+ _id: documentId,
1865
+ _type: schemaType?.name
1866
+ }), [documentId, schemaType?.name]), { onClick: onIntentClick, href } = router.useIntentLink({
1887
1867
  intent: "edit",
1888
1868
  params: {
1889
1869
  id: documentId,
1890
- type: schemaType == null ? void 0 : schemaType.name
1870
+ type: schemaType?.name
1891
1871
  }
1892
- });
1893
- const preview = /* @__PURE__ */jsxRuntime.jsx(sanity.SanityDefaultPreview, {
1894
- ...sanity.getPreviewValueWithFallback({
1895
- draft,
1896
- published,
1897
- value: sanityDocument
1898
- }),
1899
- isPlaceholder: isLoading != null ? isLoading : true,
1900
- layout: "default",
1901
- icon: schemaType == null ? void 0 : schemaType.icon
1902
- });
1903
- if (button) {
1904
- return /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
1872
+ }), preview = /* @__PURE__ */ jsxRuntime.jsx(
1873
+ sanity.SanityDefaultPreview,
1874
+ {
1875
+ ...sanity.getPreviewValueWithFallback({
1876
+ snapshot,
1877
+ original,
1878
+ fallback: sanityDocument
1879
+ }),
1880
+ isPlaceholder: previewIsLoading ?? !0,
1881
+ layout: "default",
1882
+ icon: schemaType?.icon
1883
+ }
1884
+ );
1885
+ return button ? /* @__PURE__ */ jsxRuntime.jsx(
1886
+ ui.Button,
1887
+ {
1905
1888
  as: "a",
1906
1889
  href,
1907
1890
  onClick: onIntentClick,
1908
1891
  mode: "ghost",
1909
- style: {
1910
- width: "100%",
1911
- ...style
1912
- },
1892
+ style: { width: "100%", ...style },
1913
1893
  children: preview
1914
- });
1915
- }
1916
- return /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
1917
- style: {
1918
- width: "100%"
1919
- },
1920
- children: preview
1921
- });
1922
- }
1923
- function queryIndex(queryConfig, client) {
1924
- const {
1925
- query,
1926
- indexName,
1927
- maxResults,
1928
- filter
1929
- } = queryConfig;
1930
- const projectId = client.config().projectId;
1931
- const dataset = client.config().dataset;
1932
- const queryString = query == null ? void 0 : query.trim();
1933
- return client.request({
1934
- method: "POST",
1935
- url: "/embeddings-index/query/".concat(dataset, "/").concat(indexName, "?projectId=").concat(projectId),
1936
- body: {
1937
- query: queryString,
1938
- maxResults,
1939
- filter
1940
1894
  }
1941
- });
1942
- }
1943
- function getIndexes(client) {
1944
- const projectId = client.config().projectId;
1945
- const dataset = client.config().dataset;
1946
- return client.request({
1947
- method: "GET",
1948
- url: "/embeddings-index/".concat(dataset, "?projectId=").concat(projectId)
1949
- });
1950
- }
1951
- function deleteIndex(indexName, client) {
1952
- const projectId = client.config().projectId;
1953
- const dataset = client.config().dataset;
1954
- return client.request({
1955
- method: "DELETE",
1956
- url: "/embeddings-index/".concat(dataset, "/").concat(indexName, "?projectId=").concat(projectId)
1957
- });
1895
+ ) : /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { style: { width: "100%" }, children: preview });
1958
1896
  }
1959
- const NO_RESULTS_VALUE = "";
1960
- const NO_OPTIONS = [];
1961
- const NO_FILTER = () => true;
1962
- const SemanticSearchAutocomplete = require$$0.forwardRef(function SemanticSearchAutocomplete2(props, ref) {
1897
+ const NO_RESULTS_VALUE = "", NO_OPTIONS = [], NO_FILTER = () => !0, SemanticSearchAutocomplete = require$$0.forwardRef(function(props, ref) {
1963
1898
  const {
1964
1899
  indexConfig,
1965
1900
  filterResult,
@@ -1969,943 +1904,445 @@ const SemanticSearchAutocomplete = require$$0.forwardRef(function SemanticSearch
1969
1904
  onBlur,
1970
1905
  onSelect,
1971
1906
  typeFilter
1972
- } = props;
1973
- const id = require$$0.useId();
1974
- const [query, setQuery] = require$$0.useState("");
1975
- const queryRef = require$$0.useRef(query);
1976
- const debouncedQuery = useDebouncedValue(query, 300);
1977
- const prevDebouncedQuery = require$$0.useRef(debouncedQuery);
1978
- const [searching, setSearching] = require$$0.useState(false);
1979
- const [options, setOptions] = require$$0.useState(NO_OPTIONS);
1980
- const client = useApiClient();
1981
- const runIndexQuery = require$$0.useCallback(queryString => {
1982
- var _a;
1983
- setSearching(true);
1984
- const indexName = indexConfig == null ? void 0 : indexConfig.indexName;
1985
- const maxResults = indexConfig == null ? void 0 : indexConfig.maxResults;
1986
- if (!indexName) {
1987
- throw new Error("Reference option embeddingsIndex.indexName is required, but was missing");
1988
- }
1989
- queryIndex({
1990
- query: queryString.trim().length ? queryString : (_a = getEmptySearchValue()) != null ? _a : "",
1991
- indexName,
1992
- maxResults,
1993
- filter: {
1994
- type: typeFilter
1995
- }
1996
- }, client).then(result => {
1997
- if (queryRef.current === queryString) {
1998
- setSearching(false);
1999
- setOptions([]);
2000
- const resultOptions = result.filter(hit => filterResult ? filterResult(hit) : true).map(r => sanity.typed({
2001
- result: r,
2002
- value: r.value.documentId
2003
- }));
2004
- if (resultOptions.length) {
2005
- setOptions(resultOptions);
2006
- } else {
2007
- setOptions([{
2008
- value: NO_RESULTS_VALUE
2009
- }]);
1907
+ } = props, id = require$$0.useId(), [query, setQuery] = require$$0.useState(""), queryRef = require$$0.useRef(query), debouncedQuery = useDebouncedValue(query, 300), prevDebouncedQuery = require$$0.useRef(debouncedQuery), [searching, setSearching] = require$$0.useState(!1), [options, setOptions] = require$$0.useState(NO_OPTIONS), client = useApiClient(), runIndexQuery = require$$0.useCallback(
1908
+ (queryString) => {
1909
+ setSearching(!0);
1910
+ const indexName = indexConfig?.indexName, maxResults = indexConfig?.maxResults;
1911
+ if (!indexName)
1912
+ throw new Error("Reference option embeddingsIndex.indexName is required, but was missing");
1913
+ queryIndex(
1914
+ {
1915
+ query: queryString.trim().length ? queryString : getEmptySearchValue() ?? "",
1916
+ indexName,
1917
+ maxResults,
1918
+ filter: {
1919
+ type: typeFilter
1920
+ }
1921
+ },
1922
+ client
1923
+ ).then((result) => {
1924
+ if (queryRef.current === queryString) {
1925
+ setSearching(!1), setOptions([]), setOptions([]);
1926
+ const resultOptions = result.filter((hit) => filterResult ? filterResult(hit) : !0).map((r) => sanity.typed({ result: r, value: r.value.documentId }));
1927
+ resultOptions.length ? setOptions(resultOptions) : setOptions([{ value: NO_RESULTS_VALUE }]);
2010
1928
  }
2011
- }
2012
- }).catch(e => {
2013
- if (queryRef.current === queryString) {
2014
- setSearching(false);
2015
- }
2016
- throw e;
2017
- });
2018
- }, [client, indexConfig, getEmptySearchValue, filterResult, typeFilter]);
1929
+ }).catch((e) => {
1930
+ throw queryRef.current === queryString && setSearching(!1), e;
1931
+ });
1932
+ },
1933
+ [client, indexConfig, getEmptySearchValue, filterResult, typeFilter]
1934
+ );
2019
1935
  require$$0.useEffect(() => {
2020
- if (prevDebouncedQuery.current !== debouncedQuery) {
2021
- runIndexQuery(debouncedQuery);
2022
- }
2023
- prevDebouncedQuery.current = debouncedQuery;
1936
+ prevDebouncedQuery.current !== debouncedQuery && runIndexQuery(debouncedQuery), prevDebouncedQuery.current = debouncedQuery;
2024
1937
  }, [debouncedQuery, runIndexQuery]);
2025
- const openButtonConfig = require$$0.useMemo(() => ({
2026
- onClick: () => runIndexQuery(queryRef.current)
2027
- }), [runIndexQuery, queryRef]);
2028
- const handleQueryChange = require$$0.useCallback(newValue => {
2029
- const newQuery = newValue != null ? newValue : "";
2030
- queryRef.current = newQuery;
2031
- setQuery(newQuery);
2032
- }, [setQuery]);
2033
- const handleChange = require$$0.useCallback(value => {
2034
- if (value === NO_RESULTS_VALUE) {
2035
- setOptions(NO_OPTIONS);
2036
- return;
2037
- }
2038
- const option = options.filter(r => "result" in r).find(r => r.result.value.documentId === value);
2039
- if (option && onSelect) {
2040
- onSelect(option.result);
1938
+ const openButtonConfig = require$$0.useMemo(
1939
+ () => ({ onClick: () => runIndexQuery(queryRef.current) }),
1940
+ [runIndexQuery, queryRef]
1941
+ ), handleQueryChange = require$$0.useCallback(
1942
+ (newValue) => {
1943
+ const newQuery = newValue ?? "";
1944
+ queryRef.current = newQuery, setQuery(newQuery);
1945
+ },
1946
+ [setQuery]
1947
+ ), handleChange = require$$0.useCallback(
1948
+ (value) => {
1949
+ if (value === NO_RESULTS_VALUE) {
1950
+ setOptions(NO_OPTIONS);
1951
+ return;
1952
+ }
1953
+ const option = options.filter((r) => "result" in r).find((r) => r.result.value.documentId === value);
1954
+ option && onSelect && onSelect(option.result);
1955
+ },
1956
+ [onSelect, options]
1957
+ );
1958
+ return /* @__PURE__ */ jsxRuntime.jsx(
1959
+ ui.Autocomplete,
1960
+ {
1961
+ id,
1962
+ ref,
1963
+ "data-testid": "semantic-autocomplete",
1964
+ placeholder: "Type to search...",
1965
+ openButton: openButtonConfig,
1966
+ onFocus,
1967
+ onChange: handleChange,
1968
+ loading: searching,
1969
+ onBlur,
1970
+ readOnly,
1971
+ filterOption: NO_FILTER,
1972
+ onQueryChange: handleQueryChange,
1973
+ options,
1974
+ renderOption: AutocompleteOption
2041
1975
  }
2042
- }, [onSelect, options]);
2043
- return /* @__PURE__ */jsxRuntime.jsx(ui.Autocomplete, {
2044
- id,
2045
- ref,
2046
- "data-testid": "semantic-autocomplete",
2047
- placeholder: "Type to search...",
2048
- openButton: openButtonConfig,
2049
- onFocus,
2050
- onChange: handleChange,
2051
- loading: searching,
2052
- onBlur,
2053
- readOnly,
2054
- filterOption: NO_FILTER,
2055
- onQueryChange: handleQueryChange,
2056
- options,
2057
- renderOption: AutocompleteOption
2058
- });
1976
+ );
2059
1977
  });
2060
1978
  function AutocompleteOption(props) {
2061
1979
  if ("result" in props) {
2062
1980
  const value = props.result.value;
2063
- return /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
2064
- mode: "bleed",
2065
- padding: 1,
2066
- style: {
2067
- width: "100%"
2068
- },
2069
- children: /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
2070
- gap: 2,
2071
- align: "center",
2072
- children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2073
- flex: 1,
2074
- children: /* @__PURE__ */jsxRuntime.jsx(DocumentPreview, {
2075
- documentId: value.documentId,
2076
- schemaTypeName: value.type
2077
- })
2078
- }), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2079
- padding: 2,
2080
- children: /* @__PURE__ */jsxRuntime.jsxs(ui.Text, {
2081
- size: 1,
2082
- muted: true,
2083
- title: "Relevance",
2084
- children: [Math.floor(props.result.score * 100), "%"]
2085
- })
2086
- })]
2087
- })
2088
- });
1981
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Button, { mode: "bleed", padding: 1, style: { width: "100%" }, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 2, align: "center", children: [
1982
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, children: /* @__PURE__ */ jsxRuntime.jsx(DocumentPreview, { documentId: value.documentId, schemaTypeName: value.type }) }),
1983
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { padding: 2, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { size: 1, muted: !0, title: "Relevance", children: [
1984
+ Math.floor(props.result.score * 100),
1985
+ "%"
1986
+ ] }) })
1987
+ ] }) });
2089
1988
  }
2090
- return /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
2091
- mode: "bleed",
2092
- padding: 1,
2093
- style: {
2094
- width: "100%"
2095
- },
2096
- disabled: true,
2097
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Flex, {
2098
- gap: 2,
2099
- align: "center",
2100
- children: "No results."
2101
- })
2102
- });
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." }) });
2103
1990
  }
2104
1991
  function useDebouncedValue(value, ms) {
2105
1992
  const [debouncedValue, setDebouncedValue] = require$$0.useState(value);
2106
- require$$0.useEffect(() => {
1993
+ return require$$0.useEffect(() => {
2107
1994
  const timeoutId = setTimeout(() => {
2108
1995
  setDebouncedValue(value);
2109
1996
  }, ms);
2110
1997
  return () => clearTimeout(timeoutId);
2111
- }, [value, ms]);
2112
- return debouncedValue;
2113
- }
2114
- function useEmeddingsConfig(embeddingsIndexConfig, defaultConfig) {
2115
- return require$$0.useMemo(() => {
2116
- if (embeddingsIndexConfig === true || !embeddingsIndexConfig) {
2117
- if (!(defaultConfig == null ? void 0 : defaultConfig.indexName)) {
2118
- throw new Error("Default embeddingsIndex config is missing. When options.embeddingsIndex: true, embeddingsIndexReferenceInput plugin config is required.");
2119
- }
2120
- return defaultConfig;
2121
- }
2122
- const finalConfig = {
2123
- ...defaultConfig,
2124
- ...embeddingsIndexConfig
2125
- };
2126
- if (!(finalConfig == null ? void 0 : finalConfig.indexName)) {
2127
- throw new Error("indexName is missing. Either set it in options.embeddingsIndex or configure defaults using plugin config.");
2128
- }
2129
- return finalConfig;
2130
- }, [defaultConfig, embeddingsIndexConfig]);
2131
- }
2132
- function SemanticSearchReferenceInput(props) {
2133
- var _a, _b;
2134
- const embeddingsIndexConfig = (_b = (_a = props.schemaType) == null ? void 0 : _a.options) == null ? void 0 : _b.embeddingsIndex;
2135
- const config = useEmeddingsConfig(embeddingsIndexConfig, props.defaultConfig);
2136
- const defaultEnabled = config.searchMode === "embeddings";
2137
- const featureState = useIsFeatureEnabledContext();
2138
- const [semantic, setSemantic] = require$$0.useState(defaultEnabled);
2139
- const toggleSemantic = require$$0.useCallback(() => setSemantic(current => !current), []);
2140
- return /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
2141
- gap: 2,
2142
- flex: 1,
2143
- style: {
2144
- width: "100%"
2145
- },
2146
- children: [semantic && featureState == "loading" ? /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2147
- padding: 2,
2148
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Spinner, {})
2149
- }) : null, semantic && featureState == "disabled" ? /* @__PURE__ */jsxRuntime.jsx(FeatureDisabledNotice, {
2150
- urlSuffix: "?ref=embeddings-ref"
2151
- }) : null, semantic && featureState === "error" ? /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2152
- padding: 4,
2153
- children: /* @__PURE__ */jsxRuntime.jsx(FeatureError, {})
2154
- }) : null, /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2155
- flex: 1,
2156
- style: {
2157
- maxHeight: 36,
2158
- overflow: "hidden"
2159
- },
2160
- children: semantic && featureState == "enabled" ? /* @__PURE__ */jsxRuntime.jsx(SemanticSearchInput, {
2161
- ...props,
2162
- indexConfig: config
2163
- }) : props.renderDefault(props)
2164
- }), /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
2165
- icon: semantic ? icons.EarthGlobeIcon : icons.LinkIcon,
2166
- onClick: toggleSemantic,
2167
- mode: "bleed",
2168
- title: semantic ? "Switch to standard reference search" : "Switch to semantic reference search"
2169
- })]
2170
- });
2171
- }
2172
- function SemanticSearchInput(props) {
2173
- const {
2174
- indexConfig,
2175
- onPathFocus,
2176
- onChange,
2177
- readOnly,
2178
- schemaType,
2179
- value
2180
- } = props;
2181
- const {
2182
- value: currentDocument
2183
- } = desk.useDocumentPane();
2184
- const docRef = require$$0.useRef(currentDocument);
2185
- const autocompleteRef = require$$0.useRef(null);
2186
- require$$0.useEffect(() => {
2187
- docRef.current = currentDocument;
2188
- }, [currentDocument]);
2189
- require$$0.useEffect(() => {
2190
- var _a;
2191
- if (value == null ? void 0 : value._ref) {
2192
- (_a = autocompleteRef.current) == null ? void 0 : _a.focus();
2193
- }
2194
- }, []);
2195
- const handleFocus = require$$0.useCallback(() => onPathFocus(["_ref"]), [onPathFocus]);
2196
- const handleBlur = require$$0.useCallback(() => onPathFocus([]), [onPathFocus]);
2197
- const handleChange = require$$0.useCallback(result => {
2198
- if (!result) {
2199
- onChange(sanity.unset());
2200
- onPathFocus([]);
2201
- return;
2202
- }
2203
- const patches = [sanity.setIfMissing({}), sanity.set(schemaType.name, ["_type"]), sanity.set(publicId(result.value.documentId), ["_ref"]), sanity.unset(["_weak"]), sanity.unset(["_strengthenOnPublish"])];
2204
- onChange(patches);
2205
- onPathFocus([]);
2206
- }, [onChange, onPathFocus, schemaType.name]);
2207
- const filterResult = require$$0.useCallback(r => r.value.documentId !== publicId(docRef.current._id), [docRef]);
2208
- const getEmptySearchValue = require$$0.useCallback(() => JSON.stringify(docRef.current), [docRef]);
2209
- const typeFilter = require$$0.useMemo(() => schemaType.to.map(refType => refType.name), [schemaType]);
2210
- return /* @__PURE__ */jsxRuntime.jsx(SemanticSearchAutocomplete, {
2211
- ref: autocompleteRef,
2212
- typeFilter,
2213
- indexConfig,
2214
- onSelect: handleChange,
2215
- onFocus: handleFocus,
2216
- onBlur: handleBlur,
2217
- getEmptySearchValue,
2218
- filterResult,
2219
- readOnly
2220
- });
2221
- }
2222
- function isType(schemaType, typeName) {
2223
- if (schemaType.name === typeName) {
2224
- return true;
2225
- }
2226
- if (!schemaType.type) {
2227
- return false;
2228
- }
2229
- return isType(schemaType.type, typeName);
2230
- }
2231
- const embeddingsIndexReferenceInput = sanity.definePlugin(defaultConfig => {
2232
- const config = typeof defaultConfig === "object" ? defaultConfig : void 0;
2233
- return {
2234
- name: "@sanity/embeddings-index-reference-input",
2235
- studio: {
2236
- components: {
2237
- layout: props => {
2238
- return /* @__PURE__ */jsxRuntime.jsx(FeatureEnabledProvider, {
2239
- children: props.renderDefault(props)
2240
- });
2241
- }
2242
- }
2243
- },
2244
- form: {
2245
- components: {
2246
- input: props => {
2247
- var _a, _b;
2248
- const embeddingsIndexConfig = (_b = (_a = props.schemaType) == null ? void 0 : _a.options) == null ? void 0 : _b.embeddingsIndex;
2249
- if (sanity.isObjectInputProps(props) && isType(props.schemaType, "reference") && (embeddingsIndexConfig === true || (embeddingsIndexConfig == null ? void 0 : embeddingsIndexConfig.indexName))) {
2250
- return /* @__PURE__ */jsxRuntime.jsx(SemanticSearchReferenceInput, {
2251
- ...props,
2252
- defaultConfig: config
2253
- });
2254
- }
2255
- return props.renderDefault(props);
2256
- }
2257
- }
2258
- }
2259
- };
2260
- });
2261
- const defaultProjection = "{...}";
2262
- function useDefaultIndex(schema, dataset) {
2263
- 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]);
2264
- return require$$0.useMemo(() => ({
2265
- dataset,
2266
- projection: defaultProjection,
2267
- filter: defaultFilter
2268
- }), [defaultFilter, dataset]);
2269
- }
2270
- function IndexFormInput(props) {
2271
- var _a;
2272
- const {
2273
- label,
2274
- description,
2275
- index,
2276
- prop,
2277
- onChange,
2278
- readOnly,
2279
- placeholder,
2280
- type
2281
- } = props;
2282
- const handleChange = require$$0.useCallback(propValue => onChange(current => ({
2283
- ...current,
2284
- [prop]: propValue
2285
- })), [onChange, prop]);
2286
- return /* @__PURE__ */jsxRuntime.jsx(FormInput, {
2287
- label,
2288
- description,
2289
- onChange: handleChange,
2290
- value: (_a = index[prop]) != null ? _a : "",
2291
- readOnly,
2292
- placeholder,
2293
- type
2294
- });
2295
- }
2296
- function FormInput(props) {
2297
- const {
2298
- label,
2299
- description,
2300
- onChange,
2301
- value,
2302
- readOnly,
2303
- placeholder,
2304
- type = "text"
2305
- } = props;
2306
- const id = require$$0.useId();
2307
- const handleChange = require$$0.useCallback(e => onChange(e.currentTarget.value), [onChange]);
2308
- return /* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
2309
- space: 3,
2310
- children: [/* @__PURE__ */jsxRuntime.jsx(ui.Label, {
2311
- muted: true,
2312
- htmlFor: id,
2313
- children: /* @__PURE__ */jsxRuntime.jsx("label", {
2314
- htmlFor: id,
2315
- children: label
2316
- })
2317
- }), description && /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2318
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
2319
- size: 1,
2320
- muted: true,
2321
- children: description
2322
- })
2323
- }), type === "text" ? /* @__PURE__ */jsxRuntime.jsx(ui.TextInput, {
2324
- id,
2325
- value,
2326
- onChange: handleChange,
2327
- readOnly,
2328
- placeholder
2329
- }) : /* @__PURE__ */jsxRuntime.jsx(ui.TextArea, {
2330
- id,
2331
- value,
2332
- rows: 3,
2333
- onChange: handleChange,
2334
- readOnly,
2335
- placeholder,
2336
- style: {
2337
- resize: "vertical"
2338
- }
2339
- })]
2340
- });
2341
- }
2342
- function EditIndexDialog(props) {
2343
- const {
2344
- open,
2345
- onClose,
2346
- onSubmit
2347
- } = props;
2348
- const id = require$$0.useId();
2349
- const ref = require$$0.useRef(null);
2350
- require$$0.useEffect(() => {
2351
- if (!open) {
2352
- return;
2353
- }
2354
- setTimeout(() => {
2355
- var _a, _b;
2356
- return (_b = (_a = ref.current) == null ? void 0 : _a.querySelector("input")) == null ? void 0 : _b.focus();
2357
- });
2358
- }, [ref, open]);
2359
- const handleSubmit = require$$0.useCallback(index => {
2360
- onSubmit(index);
2361
- onClose();
2362
- }, [onSubmit, onClose]);
2363
- return open ? /* @__PURE__ */jsxRuntime.jsx(ui.Dialog, {
2364
- id,
2365
- width: 1,
2366
- ref,
2367
- onClose,
2368
- header: "Create embeddings index",
2369
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Stack, {
2370
- padding: 4,
2371
- space: 5,
2372
- children: /* @__PURE__ */jsxRuntime.jsx(IndexEditor, {
2373
- readOnly: false,
2374
- onSubmit: handleSubmit
2375
- })
2376
- })
2377
- }) : null;
2378
- }
2379
- function IndexEditor(props) {
2380
- var _a;
2381
- const {
2382
- readOnly,
2383
- index: selectedIndex,
2384
- onSubmit
2385
- } = props;
2386
- const client = useApiClient();
2387
- const schema = sanity.useSchema();
2388
- const defaultIndex = useDefaultIndex(schema, (_a = client.config().dataset) != null ? _a : "");
2389
- const [errors, setErrors] = require$$0.useState();
2390
- const [loading, setLoading] = require$$0.useState();
2391
- const [index, setIndex] = require$$0.useState(() => ({
2392
- ...defaultIndex,
2393
- ...selectedIndex
2394
- }));
2395
- require$$0.useEffect(() => setIndex(selectedIndex != null ? selectedIndex : {
2396
- ...defaultIndex
2397
- }), [selectedIndex, defaultIndex]);
2398
- const handleSubmit = require$$0.useCallback(e => {
2399
- e.preventDefault();
2400
- if (readOnly) {
2401
- return;
2402
- }
2403
- const validationErrors = [];
2404
- if (!index.indexName) {
2405
- validationErrors.push("Index name is required");
2406
- } else if (!index.indexName.match(/^[a-zA-Z0-9-_]+$/g)) {
2407
- validationErrors.push("Index name can only contain the letters a-z, numbers - and _");
2408
- }
2409
- if (!index.dataset) {
2410
- validationErrors.push("Dataset is required");
2411
- }
2412
- if (!index.filter) {
2413
- validationErrors.push("Filter is required");
2414
- }
2415
- if (!index.projection) {
2416
- validationErrors.push("Projection is required");
2417
- }
2418
- if (validationErrors.length) {
2419
- setErrors(validationErrors);
2420
- return;
2421
- }
2422
- const {
2423
- projectId
2424
- } = client.config();
2425
- setLoading(true);
2426
- client.request({
2427
- method: "POST",
2428
- url: "/embeddings-index/".concat(index.dataset, "?projectId=").concat(projectId),
2429
- body: {
2430
- indexName: index.indexName,
2431
- projection: index.projection,
2432
- filter: index.filter
2433
- }
2434
- }).then(response => {
2435
- if (onSubmit) {
2436
- onSubmit(response.index);
2437
- }
2438
- }).catch(err => {
2439
- console.error(err);
2440
- setErrors([err.message]);
2441
- }).finally(() => {
2442
- setLoading(false);
2443
- });
2444
- }, [index, readOnly, onSubmit, client]);
2445
- return /* @__PURE__ */jsxRuntime.jsx("form", {
2446
- onSubmit: handleSubmit,
2447
- children: /* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
2448
- space: 4,
2449
- children: [(errors == null ? void 0 : errors.length) ? /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
2450
- tone: "critical",
2451
- border: true,
2452
- padding: 2,
2453
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
2454
- children: /* @__PURE__ */jsxRuntime.jsx("ul", {
2455
- style: {
2456
- marginLeft: -10
2457
- },
2458
- children: errors == null ? void 0 : errors.map((error, i) => /* @__PURE__ */jsxRuntime.jsx("li", {
2459
- children: error
2460
- }, "".concat(error, "-").concat(i)))
2461
- })
2462
- })
2463
- }) : null, /* @__PURE__ */jsxRuntime.jsx(IndexFormInput, {
2464
- label: "Index name",
2465
- placeholder: "Name of index without spaces...",
2466
- index,
2467
- prop: "indexName",
2468
- onChange: setIndex,
2469
- readOnly
2470
- }), /* @__PURE__ */jsxRuntime.jsx(IndexFormInput, {
2471
- label: "Dataset",
2472
- index,
2473
- prop: "dataset",
2474
- onChange: setIndex,
2475
- readOnly: true
2476
- }), /* @__PURE__ */jsxRuntime.jsx(IndexFormInput, {
2477
- label: "Filter",
2478
- description: "Must be a valid GROQ filter",
2479
- placeholder: defaultIndex.filter,
2480
- index,
2481
- prop: "filter",
2482
- onChange: setIndex,
2483
- readOnly,
2484
- type: "textarea"
2485
- }), /* @__PURE__ */jsxRuntime.jsx(IndexFormInput, {
2486
- label: "Projection",
2487
- description: "Must be a valid GROQ projection, starting { and ending with }",
2488
- placeholder: defaultIndex.projection,
2489
- index,
2490
- prop: "projection",
2491
- onChange: setIndex,
2492
- readOnly,
2493
- type: "textarea"
2494
- }), onSubmit && /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
2495
- type: "submit",
2496
- text: "Create index",
2497
- icon: loading ? /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2498
- style: {
2499
- marginTop: 5
2500
- },
2501
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Spinner, {})
2502
- }) : icons.AddIcon,
2503
- disabled: readOnly || loading,
2504
- tone: "primary"
2505
- })]
2506
- })
2507
- });
2508
- }
2509
- function IndexList(props) {
2510
- const {
2511
- loading,
2512
- selectedIndex,
2513
- indexes,
2514
- onIndexSelected
2515
- } = props;
2516
- return /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
2517
- tone: "default",
2518
- style: {
2519
- opacity: loading ? 0.5 : 1
2520
- },
2521
- children: /* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
2522
- space: 2,
2523
- children: [/* @__PURE__ */jsxRuntime.jsx(ui.Card, {
2524
- borderBottom: true,
2525
- flex: 1,
2526
- paddingBottom: 2,
2527
- padding: 3,
2528
- children: /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
2529
- children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2530
- flex: 1,
2531
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Label, {
2532
- muted: true,
2533
- children: "Index name"
2534
- })
2535
- }), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2536
- flex: 1,
2537
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Label, {
2538
- muted: true,
2539
- children: "Dataset"
2540
- })
2541
- }), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2542
- flex: 1,
2543
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Label, {
2544
- muted: true,
2545
- children: "Status"
2546
- })
2547
- }), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2548
- flex: 1,
2549
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Label, {
2550
- muted: true,
2551
- children: "Progress"
2552
- })
2553
- })]
2554
- })
2555
- }), indexes.length ? /* @__PURE__ */jsxRuntime.jsx(ui.Stack, {
2556
- space: 2,
2557
- style: {
2558
- maxHeight: 200,
2559
- overflow: "auto"
2560
- },
2561
- children: indexes.map(index => /* @__PURE__ */jsxRuntime.jsx(IndexRow, {
2562
- selectedIndex,
2563
- index,
2564
- onIndexSelected
2565
- }, index.indexName))
2566
- }) : /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
2567
- muted: true,
2568
- children: "No indexes found."
2569
- })]
2570
- })
2571
- });
2572
- }
2573
- function IndexRow(props) {
2574
- const {
2575
- selectedIndex,
2576
- index,
2577
- onIndexSelected
2578
- } = props;
2579
- const onSelect = require$$0.useCallback(() => onIndexSelected(index), [onIndexSelected, index]);
2580
- return /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
2581
- tone: (selectedIndex == null ? void 0 : selectedIndex.indexName) === index.indexName ? "primary" : "default",
2582
- mode: (selectedIndex == null ? void 0 : selectedIndex.indexName) === index.indexName ? "default" : "ghost",
2583
- onClick: onSelect,
2584
- padding: 3,
2585
- children: /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
2586
- children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2587
- flex: 1,
2588
- children: /* @__PURE__ */jsxRuntime.jsx("strong", {
2589
- children: index.indexName
2590
- })
2591
- }), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2592
- flex: 1,
2593
- children: index.dataset
2594
- }), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2595
- flex: 1,
2596
- children: index.status
2597
- }), /* @__PURE__ */jsxRuntime.jsxs(ui.Box, {
2598
- flex: 1,
2599
- children: [index.startDocumentCount ? Math.floor((index.startDocumentCount - index.remainingDocumentCount) / index.startDocumentCount * 100) : "?", "%"]
2600
- })]
2601
- })
2602
- }, index.indexName);
1998
+ }, [value, ms]), debouncedValue;
2603
1999
  }
2604
2000
  function QueryIndex(props) {
2605
- const {
2606
- indexName
2607
- } = props;
2608
- const getEmpty = require$$0.useCallback(() => "anything", []);
2609
- const indexConfig = require$$0.useMemo(() => ({
2610
- indexName,
2611
- maxResults: 8
2612
- }), [indexName]);
2613
- const {
2614
- resolveIntentLink,
2615
- navigateUrl
2616
- } = router.useRouter();
2617
- const onSelect = require$$0.useCallback(hit => {
2618
- navigateUrl({
2619
- path: resolveIntentLink("edit", {
2620
- id: hit.value.documentId,
2621
- type: hit.value.type
2622
- })
2623
- });
2624
- }, [resolveIntentLink, navigateUrl]);
2625
- return /* @__PURE__ */jsxRuntime.jsx(SemanticSearchAutocomplete, {
2626
- getEmptySearchValue: getEmpty,
2627
- indexConfig,
2628
- onSelect
2629
- });
2630
- }
2631
- function IndexInfo(_ref3) {
2632
- let {
2633
- selectedIndex,
2634
- onDeleteIndex
2635
- } = _ref3;
2636
- var _a;
2637
- const handleDelete = require$$0.useCallback(() => onDeleteIndex(selectedIndex), [selectedIndex, onDeleteIndex]);
2638
- return /* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
2639
- space: 4,
2640
- flex: 1,
2641
- children: [/* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
2642
- align: "center",
2643
- flex: 1,
2644
- gap: 2,
2645
- children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2646
- flex: 1,
2647
- children: /* @__PURE__ */jsxRuntime.jsxs(ui.Heading, {
2648
- children: ["Index: ", (_a = selectedIndex == null ? void 0 : selectedIndex.indexName) != null ? _a : "Untitled"]
2649
- })
2650
- }), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2651
- children: /* @__PURE__ */jsxRuntime.jsx(ui.MenuButton, {
2652
- button: /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
2653
- title: "Open index actions",
2654
- icon: icons.EllipsisVerticalIcon,
2655
- padding: 2,
2656
- mode: "ghost"
2657
- }),
2658
- id: "button-".concat(selectedIndex.indexName),
2659
- menu: /* @__PURE__ */jsxRuntime.jsx(ui.Menu, {
2660
- children: /* @__PURE__ */jsxRuntime.jsx(ui.MenuItem, {
2001
+ const { indexName } = props, getEmpty = require$$0.useCallback(() => "anything", []), indexConfig = require$$0.useMemo(
2002
+ () => ({ indexName, maxResults: 8 }),
2003
+ [indexName]
2004
+ ), { resolveIntentLink, navigateUrl } = router.useRouter(), onSelect = require$$0.useCallback(
2005
+ (hit) => {
2006
+ navigateUrl({
2007
+ path: resolveIntentLink("edit", { id: hit.value.documentId, type: hit.value.type })
2008
+ });
2009
+ },
2010
+ [resolveIntentLink, navigateUrl]
2011
+ );
2012
+ return /* @__PURE__ */ jsxRuntime.jsx(
2013
+ SemanticSearchAutocomplete,
2014
+ {
2015
+ getEmptySearchValue: getEmpty,
2016
+ indexConfig,
2017
+ onSelect
2018
+ }
2019
+ );
2020
+ }
2021
+ function IndexInfo({ selectedIndex, onDeleteIndex }) {
2022
+ const handleDelete = require$$0.useCallback(
2023
+ () => onDeleteIndex(selectedIndex),
2024
+ [selectedIndex, onDeleteIndex]
2025
+ );
2026
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 4, flex: 1, children: [
2027
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { align: "center", flex: 1, gap: 2, children: [
2028
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Heading, { children: [
2029
+ "Index: ",
2030
+ selectedIndex?.indexName ?? "Untitled"
2031
+ ] }) }),
2032
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { children: /* @__PURE__ */ jsxRuntime.jsx(
2033
+ ui.MenuButton,
2034
+ {
2035
+ button: /* @__PURE__ */ jsxRuntime.jsx(
2036
+ ui.Button,
2037
+ {
2038
+ title: "Open index actions",
2039
+ icon: icons.EllipsisVerticalIcon,
2040
+ padding: 2,
2041
+ mode: "ghost"
2042
+ }
2043
+ ),
2044
+ id: `button-${selectedIndex.indexName}`,
2045
+ menu: /* @__PURE__ */ jsxRuntime.jsx(ui.Menu, { children: /* @__PURE__ */ jsxRuntime.jsx(
2046
+ ui.MenuItem,
2047
+ {
2661
2048
  text: "Delete index",
2662
2049
  icon: icons.TrashIcon,
2663
2050
  tone: "critical",
2664
2051
  onClick: handleDelete
2665
- })
2666
- }),
2667
- popover: {
2668
- placement: "right"
2669
- }
2670
- })
2671
- })]
2672
- }), /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
2673
- gap: 6,
2674
- children: [/* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
2675
- space: 4,
2676
- flex: 1,
2677
- style: {
2678
- maxWidth: 600
2679
- },
2680
- children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2681
- children: /* @__PURE__ */jsxRuntime.jsx(IndexEditor, {
2682
- index: selectedIndex,
2683
- readOnly: true
2684
- })
2685
- }), /* @__PURE__ */jsxRuntime.jsx(IndexStatus, {
2686
- selectedIndex
2687
- })]
2688
- }), /* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
2689
- space: 3,
2690
- flex: 1,
2691
- children: [/* @__PURE__ */jsxRuntime.jsx(ui.Label, {
2692
- muted: true,
2693
- children: "Query index"
2694
- }), /* @__PURE__ */jsxRuntime.jsx(QueryIndex, {
2695
- indexName: selectedIndex.indexName
2696
- }, selectedIndex.indexName)]
2697
- })]
2698
- })]
2699
- });
2052
+ }
2053
+ ) }),
2054
+ popover: { placement: "right" }
2055
+ }
2056
+ ) })
2057
+ ] }),
2058
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 6, children: [
2059
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 4, flex: 1, style: { maxWidth: 600 }, children: [
2060
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { children: /* @__PURE__ */ jsxRuntime.jsx(IndexEditor, { index: selectedIndex, readOnly: !0 }) }),
2061
+ /* @__PURE__ */ jsxRuntime.jsx(IndexStatus, { selectedIndex })
2062
+ ] }),
2063
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 3, flex: 1, children: [
2064
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { muted: !0, children: "Query index" }),
2065
+ /* @__PURE__ */ jsxRuntime.jsx(QueryIndex, { indexName: selectedIndex.indexName }, selectedIndex.indexName)
2066
+ ] })
2067
+ ] })
2068
+ ] });
2069
+ }
2070
+ function IndexStatus({ selectedIndex }) {
2071
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 4, flex: 1, children: [
2072
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 2, align: "center", children: [
2073
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: 1, muted: !0, children: "Status" }) }),
2074
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { space: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: selectedIndex.status }) })
2075
+ ] }),
2076
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 5, align: "center", children: [
2077
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: 1, muted: !0, children: "Indexing progress" }) }),
2078
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { space: 2, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Text, { children: [
2079
+ selectedIndex.startDocumentCount - selectedIndex.remainingDocumentCount,
2080
+ " /",
2081
+ " ",
2082
+ selectedIndex.startDocumentCount
2083
+ ] }) })
2084
+ ] }),
2085
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 5, align: "center", children: [
2086
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { size: 1, muted: !0, children: "Failed documents" }) }),
2087
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { space: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { children: selectedIndex.failedDocumentCount }) })
2088
+ ] })
2089
+ ] });
2700
2090
  }
2701
- function IndexStatus(_ref4) {
2702
- let {
2703
- selectedIndex
2704
- } = _ref4;
2705
- return /* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
2706
- space: 4,
2707
- flex: 1,
2708
- children: [/* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
2709
- gap: 2,
2710
- align: "center",
2711
- children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2712
- flex: 1,
2713
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Label, {
2714
- size: 1,
2715
- muted: true,
2716
- children: "Status"
2717
- })
2718
- }), /* @__PURE__ */jsxRuntime.jsx(ui.Stack, {
2719
- space: 2,
2720
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
2721
- children: selectedIndex.status
2722
- })
2723
- })]
2724
- }), /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
2725
- gap: 5,
2726
- align: "center",
2727
- children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2728
- flex: 1,
2729
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Label, {
2730
- size: 1,
2731
- muted: true,
2732
- children: "Indexing progress"
2733
- })
2734
- }), /* @__PURE__ */jsxRuntime.jsx(ui.Stack, {
2735
- space: 2,
2736
- children: /* @__PURE__ */jsxRuntime.jsxs(ui.Text, {
2737
- children: [selectedIndex.startDocumentCount - selectedIndex.remainingDocumentCount, " /", " ", selectedIndex.startDocumentCount]
2738
- })
2739
- })]
2740
- }), /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
2741
- gap: 5,
2742
- align: "center",
2743
- children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2744
- flex: 1,
2745
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Label, {
2746
- size: 1,
2747
- muted: true,
2748
- children: "Failed documents"
2749
- })
2750
- }), /* @__PURE__ */jsxRuntime.jsx(ui.Stack, {
2751
- space: 2,
2752
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Text, {
2753
- children: selectedIndex.failedDocumentCount
2754
- })
2755
- })]
2756
- })]
2757
- });
2091
+ function IndexList(props) {
2092
+ const { loading, selectedIndex, indexes, onIndexSelected } = props;
2093
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { tone: "default", style: { opacity: loading ? 0.5 : 1 }, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 2, children: [
2094
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { borderBottom: !0, flex: 1, paddingBottom: 2, padding: 3, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { children: [
2095
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { muted: !0, children: "Index name" }) }),
2096
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { muted: !0, children: "Dataset" }) }),
2097
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { muted: !0, children: "Status" }) }),
2098
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Label, { muted: !0, children: "Progress" }) })
2099
+ ] }) }),
2100
+ indexes.length ? /* @__PURE__ */ jsxRuntime.jsx(ui.Stack, { space: 2, style: { maxHeight: 200, overflow: "auto" }, children: indexes.map((index) => /* @__PURE__ */ jsxRuntime.jsx(
2101
+ IndexRow,
2102
+ {
2103
+ selectedIndex,
2104
+ index,
2105
+ onIndexSelected
2106
+ },
2107
+ index.indexName
2108
+ )) }) : /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { muted: !0, children: "No indexes found." })
2109
+ ] }) });
2110
+ }
2111
+ function IndexRow(props) {
2112
+ const { selectedIndex, index, onIndexSelected } = props, onSelect = require$$0.useCallback(() => onIndexSelected(index), [onIndexSelected, index]);
2113
+ return /* @__PURE__ */ jsxRuntime.jsx(
2114
+ ui.Button,
2115
+ {
2116
+ tone: selectedIndex?.indexName === index.indexName ? "primary" : "default",
2117
+ mode: selectedIndex?.indexName === index.indexName ? "default" : "ghost",
2118
+ onClick: onSelect,
2119
+ padding: 3,
2120
+ children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { children: [
2121
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, children: /* @__PURE__ */ jsxRuntime.jsx("strong", { children: index.indexName }) }),
2122
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, children: index.dataset }),
2123
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, children: index.status }),
2124
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Box, { flex: 1, children: [
2125
+ index.startDocumentCount ? Math.floor(
2126
+ (index.startDocumentCount - index.remainingDocumentCount) / index.startDocumentCount * 100
2127
+ ) : "?",
2128
+ "%"
2129
+ ] })
2130
+ ] })
2131
+ },
2132
+ index.indexName
2133
+ );
2758
2134
  }
2759
2135
  function EmbeddingsIndexTool() {
2760
2136
  const featureState = useIsFeatureEnabled();
2761
- return /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
2762
- flex: 1,
2763
- children: /* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
2764
- justify: "center",
2765
- flex: 1,
2766
- children: [featureState === "error" ? /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2767
- padding: 4,
2768
- children: /* @__PURE__ */jsxRuntime.jsx(FeatureError, {})
2769
- }) : null, featureState === "disabled" ? /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2770
- padding: 4,
2771
- children: /* @__PURE__ */jsxRuntime.jsx(FeatureDisabledNotice, {
2772
- urlSuffix: "?ref=embeddings-tab"
2773
- })
2774
- }) : null, featureState === "loading" ? /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2775
- padding: 6,
2776
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Spinner, {
2777
- size: 4
2778
- })
2779
- }) : null, featureState === "enabled" ? /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
2780
- flex: 1,
2781
- style: {
2782
- maxWidth: 1200
2783
- },
2784
- padding: 5,
2785
- children: /* @__PURE__ */jsxRuntime.jsx(Indexes, {})
2786
- }) : null]
2787
- })
2788
- });
2137
+ return /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { flex: 1, children: /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { justify: "center", flex: 1, children: [
2138
+ featureState === "error" ? /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { padding: 4, children: /* @__PURE__ */ jsxRuntime.jsx(FeatureError, {}) }) : null,
2139
+ featureState === "disabled" ? /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { padding: 4, children: /* @__PURE__ */ jsxRuntime.jsx(FeatureDisabledNotice, { urlSuffix: "?ref=embeddings-tab" }) }) : null,
2140
+ featureState === "loading" ? /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { padding: 6, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Spinner, { size: 4 }) }) : null,
2141
+ featureState === "enabled" ? /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { flex: 1, style: { maxWidth: 1200 }, padding: 5, children: /* @__PURE__ */ jsxRuntime.jsx(Indexes, {}) }) : null
2142
+ ] }) });
2789
2143
  }
2790
2144
  const NO_INDEXES = [];
2791
2145
  function Indexes() {
2792
- const client = useApiClient();
2793
- const [indexes, setIndexes] = require$$0.useState(NO_INDEXES);
2794
- const [loading, setLoading] = require$$0.useState(false);
2795
- const [error, setError] = require$$0.useState(false);
2796
- const [createIndexOpen, setCreateIndexOpen] = require$$0.useState(false);
2797
- const [selectedIndex, setSelectedIndex] = require$$0.useState(void 0);
2798
- const onCreateIndexClose = require$$0.useCallback(() => setCreateIndexOpen(false), []);
2146
+ const client = useApiClient(), [indexes, setIndexes] = require$$0.useState(NO_INDEXES), [loading, setLoading] = require$$0.useState(!1), [error, setError] = require$$0.useState(!1), [createIndexOpen, setCreateIndexOpen] = require$$0.useState(!1), [selectedIndex, setSelectedIndex] = require$$0.useState(void 0), onCreateIndexClose = require$$0.useCallback(() => setCreateIndexOpen(!1), []);
2799
2147
  require$$0.useEffect(() => {
2800
- setSelectedIndex(indexes.find(i => i.indexName === (selectedIndex == null ? void 0 : selectedIndex.indexName)));
2148
+ setSelectedIndex(indexes.find((i) => i.indexName === selectedIndex?.indexName));
2801
2149
  }, [indexes, selectedIndex]);
2802
2150
  const updateIndexes = require$$0.useCallback(() => {
2803
- setLoading(true);
2804
- setError(false);
2805
- getIndexes(client).then(response => {
2806
- setLoading(false);
2807
- setIndexes(response);
2808
- }).catch(e => {
2809
- console.error(e);
2810
- setError(true);
2151
+ setLoading(!0), setError(!1), getIndexes(client).then((response) => {
2152
+ setLoading(!1), setIndexes(response);
2153
+ }).catch((e) => {
2154
+ console.error(e), setError(!0);
2811
2155
  }).finally(() => {
2812
- setLoading(false);
2156
+ setLoading(!1);
2813
2157
  });
2814
- }, [client]);
2815
- const deleteNamedIndex = require$$0.useCallback(index => {
2816
- if (
2817
- // eslint-disable-next-line no-alert
2818
- !confirm("Are you sure you want to delete ".concat(index.indexName, " for dataset ").concat(index.dataset, "?"))) {
2819
- return;
2820
- }
2821
- setLoading(true);
2822
- setError(false);
2823
- deleteIndex(index.indexName, client).then(() => {
2824
- setTimeout(() => updateIndexes());
2825
- }).catch(e => {
2826
- console.error(e);
2827
- setError(true);
2828
- }).finally(() => {
2829
- setLoading(false);
2830
- });
2831
- }, [client, updateIndexes]);
2832
- const onSelectIndex = require$$0.useCallback(index => {
2833
- setSelectedIndex(index);
2834
- updateIndexes();
2835
- }, [setSelectedIndex, updateIndexes]);
2158
+ }, [client]), deleteNamedIndex = require$$0.useCallback(
2159
+ (index) => {
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
+ setTimeout(() => updateIndexes());
2162
+ }).catch((e) => {
2163
+ console.error(e), setError(!0);
2164
+ }).finally(() => {
2165
+ setLoading(!1);
2166
+ }));
2167
+ },
2168
+ [client, updateIndexes]
2169
+ ), onSelectIndex = require$$0.useCallback(
2170
+ (index) => {
2171
+ setSelectedIndex(index), updateIndexes();
2172
+ },
2173
+ [setSelectedIndex, updateIndexes]
2174
+ );
2836
2175
  require$$0.useEffect(() => {
2837
2176
  updateIndexes();
2838
2177
  }, [updateIndexes]);
2839
- const openCreate = require$$0.useCallback(() => setCreateIndexOpen(true), []);
2840
- const onSubmit = require$$0.useCallback(index => {
2841
- setIndexes(current => [...current, index]);
2842
- setSelectedIndex(index);
2843
- updateIndexes();
2844
- }, [updateIndexes]);
2845
- return /* @__PURE__ */jsxRuntime.jsxs(ui.Stack, {
2846
- space: 4,
2847
- children: [/* @__PURE__ */jsxRuntime.jsxs(ui.Flex, {
2848
- gap: 2,
2849
- align: "center",
2850
- style: {
2851
- height: 30
2852
- },
2853
- children: [/* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2854
- flex: 1,
2855
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Heading, {
2856
- size: 1,
2857
- children: "Embeddings indexes"
2858
- })
2859
- }), /* @__PURE__ */jsxRuntime.jsx(ui.Box, {
2860
- style: {
2861
- justifySelf: "flex-end"
2862
- },
2863
- children: /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
2178
+ const openCreate = require$$0.useCallback(() => setCreateIndexOpen(!0), []), onSubmit = require$$0.useCallback(
2179
+ (index) => {
2180
+ setIndexes((current) => [...current, index]), setSelectedIndex(index), updateIndexes();
2181
+ },
2182
+ [updateIndexes]
2183
+ );
2184
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Stack, { space: 4, children: [
2185
+ /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 2, align: "center", style: { height: 30 }, children: [
2186
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { size: 1, children: "Embeddings indexes" }) }),
2187
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { style: { justifySelf: "flex-end" }, children: /* @__PURE__ */ jsxRuntime.jsx(
2188
+ ui.Button,
2189
+ {
2864
2190
  icon: icons.AddIcon,
2865
2191
  text: "New index",
2866
2192
  tone: "default",
2867
2193
  mode: "ghost",
2868
2194
  onClick: openCreate
2869
- })
2870
- }), /* @__PURE__ */jsxRuntime.jsx(ui.Button, {
2871
- size: 1,
2872
- icon: loading ? /* @__PURE__ */jsxRuntime.jsx(ui.Spinner, {}) : icons.UndoIcon,
2873
- title: "Refresh index list",
2874
- tone: "default",
2875
- mode: "bleed",
2876
- onClick: updateIndexes,
2877
- disabled: loading
2878
- })]
2879
- }), error ? /* @__PURE__ */jsxRuntime.jsx(ui.Card, {
2880
- tone: "critical",
2881
- padding: 2,
2882
- border: true,
2883
- children: "An error occurred. See console for details."
2884
- }) : null, /* @__PURE__ */jsxRuntime.jsx(IndexList, {
2885
- loading,
2886
- indexes,
2887
- selectedIndex,
2888
- onIndexSelected: onSelectIndex
2889
- }), selectedIndex && /* @__PURE__ */jsxRuntime.jsx(IndexInfo, {
2890
- selectedIndex,
2891
- onDeleteIndex: deleteNamedIndex
2892
- }), /* @__PURE__ */jsxRuntime.jsx(EditIndexDialog, {
2893
- open: createIndexOpen,
2894
- onClose: onCreateIndexClose,
2895
- onSubmit
2896
- })]
2897
- });
2195
+ }
2196
+ ) }),
2197
+ /* @__PURE__ */ jsxRuntime.jsx(
2198
+ ui.Button,
2199
+ {
2200
+ size: 1,
2201
+ icon: loading ? /* @__PURE__ */ jsxRuntime.jsx(ui.Spinner, {}) : icons.UndoIcon,
2202
+ title: "Refresh index list",
2203
+ tone: "default",
2204
+ mode: "bleed",
2205
+ onClick: updateIndexes,
2206
+ disabled: loading
2207
+ }
2208
+ )
2209
+ ] }),
2210
+ error ? /* @__PURE__ */ jsxRuntime.jsx(ui.Card, { tone: "critical", padding: 2, border: !0, children: "An error occurred. See console for details." }) : null,
2211
+ /* @__PURE__ */ jsxRuntime.jsx(
2212
+ IndexList,
2213
+ {
2214
+ loading,
2215
+ indexes,
2216
+ selectedIndex,
2217
+ onIndexSelected: onSelectIndex
2218
+ }
2219
+ ),
2220
+ selectedIndex && /* @__PURE__ */ jsxRuntime.jsx(IndexInfo, { selectedIndex, onDeleteIndex: deleteNamedIndex }),
2221
+ /* @__PURE__ */ jsxRuntime.jsx(EditIndexDialog, { open: createIndexOpen, onClose: onCreateIndexClose, onSubmit })
2222
+ ] });
2898
2223
  }
2899
2224
  const embeddingsIndexTool = {
2900
2225
  name: "embeddings-index",
2901
2226
  title: "Embeddings",
2902
2227
  icon: icons.EarthGlobeIcon,
2903
2228
  component: EmbeddingsIndexTool
2904
- };
2905
- const embeddingsIndexDashboard = sanity.definePlugin({
2229
+ }, embeddingsIndexDashboard = sanity.definePlugin({
2906
2230
  name: "@sanity/embeddings-index-dashboard",
2907
2231
  tools: [embeddingsIndexTool]
2908
2232
  });
2233
+ function publicId(id) {
2234
+ return id.replace("drafts.", "");
2235
+ }
2236
+ function useEmeddingsConfig(embeddingsIndexConfig, defaultConfig) {
2237
+ return require$$0.useMemo(() => {
2238
+ if (embeddingsIndexConfig === !0 || !embeddingsIndexConfig) {
2239
+ if (!defaultConfig?.indexName)
2240
+ throw new Error(
2241
+ "Default embeddingsIndex config is missing. When options.embeddingsIndex: true, embeddingsIndexReferenceInput plugin config is required."
2242
+ );
2243
+ return defaultConfig;
2244
+ }
2245
+ const finalConfig = {
2246
+ ...defaultConfig,
2247
+ ...embeddingsIndexConfig
2248
+ };
2249
+ if (!finalConfig?.indexName)
2250
+ throw new Error(
2251
+ "indexName is missing. Either set it in options.embeddingsIndex or configure defaults using plugin config."
2252
+ );
2253
+ return finalConfig;
2254
+ }, [defaultConfig, embeddingsIndexConfig]);
2255
+ }
2256
+ function SemanticSearchReferenceInput(props) {
2257
+ const embeddingsIndexConfig = props.schemaType?.options?.embeddingsIndex, config2 = useEmeddingsConfig(embeddingsIndexConfig, props.defaultConfig), defaultEnabled = config2.searchMode === "embeddings", featureState = useIsFeatureEnabledContext(), [semantic, setSemantic] = require$$0.useState(defaultEnabled), toggleSemantic = require$$0.useCallback(() => setSemantic((current) => !current), []);
2258
+ return /* @__PURE__ */ jsxRuntime.jsxs(ui.Flex, { gap: 2, flex: 1, style: { width: "100%" }, children: [
2259
+ semantic && featureState == "loading" ? /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { padding: 2, children: /* @__PURE__ */ jsxRuntime.jsx(ui.Spinner, {}) }) : null,
2260
+ semantic && featureState == "disabled" ? /* @__PURE__ */ jsxRuntime.jsx(FeatureDisabledNotice, { urlSuffix: "?ref=embeddings-ref" }) : null,
2261
+ semantic && featureState === "error" ? /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { padding: 4, children: /* @__PURE__ */ jsxRuntime.jsx(FeatureError, {}) }) : null,
2262
+ /* @__PURE__ */ jsxRuntime.jsx(ui.Box, { flex: 1, style: { maxHeight: 36, overflow: "hidden" }, children: semantic && featureState == "enabled" ? /* @__PURE__ */ jsxRuntime.jsx(SemanticSearchInput, { ...props, indexConfig: config2 }) : props.renderDefault(props) }),
2263
+ /* @__PURE__ */ jsxRuntime.jsx(
2264
+ ui.Button,
2265
+ {
2266
+ icon: semantic ? icons.EarthGlobeIcon : icons.LinkIcon,
2267
+ onClick: toggleSemantic,
2268
+ mode: "bleed",
2269
+ title: semantic ? "Switch to standard reference search" : "Switch to semantic reference search"
2270
+ }
2271
+ )
2272
+ ] });
2273
+ }
2274
+ function SemanticSearchInput(props) {
2275
+ const { indexConfig, onPathFocus, onChange, readOnly, schemaType, value } = props, { value: currentDocument } = desk.useDocumentPane(), docRef = require$$0.useRef(currentDocument), autocompleteRef = require$$0.useRef(null);
2276
+ require$$0.useEffect(() => {
2277
+ docRef.current = currentDocument;
2278
+ }, [currentDocument]), require$$0.useEffect(() => {
2279
+ value?._ref && autocompleteRef.current?.focus();
2280
+ }, []);
2281
+ const handleFocus = require$$0.useCallback(() => onPathFocus(["_ref"]), [onPathFocus]), handleBlur = require$$0.useCallback(() => onPathFocus([]), [onPathFocus]), handleChange = require$$0.useCallback(
2282
+ (result) => {
2283
+ if (!result) {
2284
+ onChange(sanity.unset()), onPathFocus([]);
2285
+ return;
2286
+ }
2287
+ const patches = [
2288
+ sanity.setIfMissing({}),
2289
+ sanity.set(schemaType.name, ["_type"]),
2290
+ sanity.set(publicId(result.value.documentId), ["_ref"]),
2291
+ sanity.unset(["_weak"]),
2292
+ sanity.unset(["_strengthenOnPublish"])
2293
+ ];
2294
+ onChange(patches), onPathFocus([]);
2295
+ },
2296
+ [onChange, onPathFocus, schemaType.name]
2297
+ ), filterResult = require$$0.useCallback(
2298
+ (r) => r.value.documentId !== publicId(docRef.current._id),
2299
+ [docRef]
2300
+ ), getEmptySearchValue = require$$0.useCallback(() => JSON.stringify(docRef.current), [docRef]), typeFilter = require$$0.useMemo(
2301
+ () => schemaType.to.map((refType) => refType.name),
2302
+ [schemaType]
2303
+ );
2304
+ return /* @__PURE__ */ jsxRuntime.jsx(
2305
+ SemanticSearchAutocomplete,
2306
+ {
2307
+ ref: autocompleteRef,
2308
+ typeFilter,
2309
+ indexConfig,
2310
+ onSelect: handleChange,
2311
+ onFocus: handleFocus,
2312
+ onBlur: handleBlur,
2313
+ getEmptySearchValue,
2314
+ filterResult,
2315
+ readOnly
2316
+ }
2317
+ );
2318
+ }
2319
+ const embeddingsIndexReferenceInput = sanity.definePlugin(
2320
+ (defaultConfig) => {
2321
+ const config2 = typeof defaultConfig == "object" ? defaultConfig : void 0;
2322
+ return {
2323
+ name: "@sanity/embeddings-index-reference-input",
2324
+ studio: {
2325
+ components: {
2326
+ layout: (props) => /* @__PURE__ */ jsxRuntime.jsx(FeatureEnabledProvider, { children: props.renderDefault(props) })
2327
+ }
2328
+ },
2329
+ form: {
2330
+ components: {
2331
+ input: (props) => {
2332
+ const embeddingsIndexConfig = props.schemaType?.options?.embeddingsIndex;
2333
+ return sanity.isObjectInputProps(props) && isType(props.schemaType, "reference") && (embeddingsIndexConfig === !0 || embeddingsIndexConfig?.indexName) ? /* @__PURE__ */ jsxRuntime.jsx(
2334
+ SemanticSearchReferenceInput,
2335
+ {
2336
+ ...props,
2337
+ defaultConfig: config2
2338
+ }
2339
+ ) : props.renderDefault(props);
2340
+ }
2341
+ }
2342
+ }
2343
+ };
2344
+ }
2345
+ );
2909
2346
  exports.deleteIndex = deleteIndex;
2910
2347
  exports.embeddingsIndexDashboard = embeddingsIndexDashboard;
2911
2348
  exports.embeddingsIndexReferenceInput = embeddingsIndexReferenceInput;