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