@univerjs/rpc 0.1.0-alpha.1 → 0.1.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1258 @@
1
+ var Ee = Object.defineProperty;
2
+ var xe = (t, r, e) => r in t ? Ee(t, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[r] = e;
3
+ var d = (t, r, e) => (xe(t, typeof r != "symbol" ? r + "" : r, e), e);
4
+ import { DocumentType as ae, ICommandService as M, IUniverInstanceService as ue, RxDisposable as z, OnLifecycle as le, LifecycleStages as fe, CommandType as he, Disposable as Oe, Plugin as pe, PluginType as de } from "@univerjs/core";
5
+ import { createIdentifier as B, Inject as q, Injector as A } from "@wendellhu/redi";
6
+ import { BehaviorSubject as Te, firstValueFrom as Me, Observable as J, isObservable as qe, of as Ae, shareReplay as ye } from "rxjs";
7
+ function h(t) {
8
+ return typeof t == "function";
9
+ }
10
+ function Ue(t) {
11
+ return h(t == null ? void 0 : t.lift);
12
+ }
13
+ function Q(t) {
14
+ return function(r) {
15
+ if (Ue(r))
16
+ return r.lift(function(e) {
17
+ try {
18
+ return t(e, this);
19
+ } catch (n) {
20
+ this.error(n);
21
+ }
22
+ });
23
+ throw new TypeError("Unable to lift unknown Observable type");
24
+ };
25
+ }
26
+ var F = function(t, r) {
27
+ return F = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(e, n) {
28
+ e.__proto__ = n;
29
+ } || function(e, n) {
30
+ for (var s in n)
31
+ Object.prototype.hasOwnProperty.call(n, s) && (e[s] = n[s]);
32
+ }, F(t, r);
33
+ };
34
+ function X(t, r) {
35
+ if (typeof r != "function" && r !== null)
36
+ throw new TypeError("Class extends value " + String(r) + " is not a constructor or null");
37
+ F(t, r);
38
+ function e() {
39
+ this.constructor = t;
40
+ }
41
+ t.prototype = r === null ? Object.create(r) : (e.prototype = r.prototype, new e());
42
+ }
43
+ function je(t, r, e, n) {
44
+ function s(i) {
45
+ return i instanceof e ? i : new e(function(o) {
46
+ o(i);
47
+ });
48
+ }
49
+ return new (e || (e = Promise))(function(i, o) {
50
+ function a(l) {
51
+ try {
52
+ c(n.next(l));
53
+ } catch (v) {
54
+ o(v);
55
+ }
56
+ }
57
+ function u(l) {
58
+ try {
59
+ c(n.throw(l));
60
+ } catch (v) {
61
+ o(v);
62
+ }
63
+ }
64
+ function c(l) {
65
+ l.done ? i(l.value) : s(l.value).then(a, u);
66
+ }
67
+ c((n = n.apply(t, r || [])).next());
68
+ });
69
+ }
70
+ function ve(t, r) {
71
+ var e = { label: 0, sent: function() {
72
+ if (i[0] & 1)
73
+ throw i[1];
74
+ return i[1];
75
+ }, trys: [], ops: [] }, n, s, i, o;
76
+ return o = { next: a(0), throw: a(1), return: a(2) }, typeof Symbol == "function" && (o[Symbol.iterator] = function() {
77
+ return this;
78
+ }), o;
79
+ function a(c) {
80
+ return function(l) {
81
+ return u([c, l]);
82
+ };
83
+ }
84
+ function u(c) {
85
+ if (n)
86
+ throw new TypeError("Generator is already executing.");
87
+ for (; o && (o = 0, c[0] && (e = 0)), e; )
88
+ try {
89
+ if (n = 1, s && (i = c[0] & 2 ? s.return : c[0] ? s.throw || ((i = s.return) && i.call(s), 0) : s.next) && !(i = i.call(s, c[1])).done)
90
+ return i;
91
+ switch (s = 0, i && (c = [c[0] & 2, i.value]), c[0]) {
92
+ case 0:
93
+ case 1:
94
+ i = c;
95
+ break;
96
+ case 4:
97
+ return e.label++, { value: c[1], done: !1 };
98
+ case 5:
99
+ e.label++, s = c[1], c = [0];
100
+ continue;
101
+ case 7:
102
+ c = e.ops.pop(), e.trys.pop();
103
+ continue;
104
+ default:
105
+ if (i = e.trys, !(i = i.length > 0 && i[i.length - 1]) && (c[0] === 6 || c[0] === 2)) {
106
+ e = 0;
107
+ continue;
108
+ }
109
+ if (c[0] === 3 && (!i || c[1] > i[0] && c[1] < i[3])) {
110
+ e.label = c[1];
111
+ break;
112
+ }
113
+ if (c[0] === 6 && e.label < i[1]) {
114
+ e.label = i[1], i = c;
115
+ break;
116
+ }
117
+ if (i && e.label < i[2]) {
118
+ e.label = i[2], e.ops.push(c);
119
+ break;
120
+ }
121
+ i[2] && e.ops.pop(), e.trys.pop();
122
+ continue;
123
+ }
124
+ c = r.call(t, e);
125
+ } catch (l) {
126
+ c = [6, l], s = 0;
127
+ } finally {
128
+ n = i = 0;
129
+ }
130
+ if (c[0] & 5)
131
+ throw c[1];
132
+ return { value: c[0] ? c[1] : void 0, done: !0 };
133
+ }
134
+ }
135
+ function P(t) {
136
+ var r = typeof Symbol == "function" && Symbol.iterator, e = r && t[r], n = 0;
137
+ if (e)
138
+ return e.call(t);
139
+ if (t && typeof t.length == "number")
140
+ return {
141
+ next: function() {
142
+ return t && n >= t.length && (t = void 0), { value: t && t[n++], done: !t };
143
+ }
144
+ };
145
+ throw new TypeError(r ? "Object is not iterable." : "Symbol.iterator is not defined.");
146
+ }
147
+ function C(t, r) {
148
+ var e = typeof Symbol == "function" && t[Symbol.iterator];
149
+ if (!e)
150
+ return t;
151
+ var n = e.call(t), s, i = [], o;
152
+ try {
153
+ for (; (r === void 0 || r-- > 0) && !(s = n.next()).done; )
154
+ i.push(s.value);
155
+ } catch (a) {
156
+ o = { error: a };
157
+ } finally {
158
+ try {
159
+ s && !s.done && (e = n.return) && e.call(n);
160
+ } finally {
161
+ if (o)
162
+ throw o.error;
163
+ }
164
+ }
165
+ return i;
166
+ }
167
+ function E(t, r, e) {
168
+ if (e || arguments.length === 2)
169
+ for (var n = 0, s = r.length, i; n < s; n++)
170
+ (i || !(n in r)) && (i || (i = Array.prototype.slice.call(r, 0, n)), i[n] = r[n]);
171
+ return t.concat(i || Array.prototype.slice.call(r));
172
+ }
173
+ function m(t) {
174
+ return this instanceof m ? (this.v = t, this) : new m(t);
175
+ }
176
+ function $e(t, r, e) {
177
+ if (!Symbol.asyncIterator)
178
+ throw new TypeError("Symbol.asyncIterator is not defined.");
179
+ var n = e.apply(t, r || []), s, i = [];
180
+ return s = {}, o("next"), o("throw"), o("return"), s[Symbol.asyncIterator] = function() {
181
+ return this;
182
+ }, s;
183
+ function o(f) {
184
+ n[f] && (s[f] = function(y) {
185
+ return new Promise(function(_, p) {
186
+ i.push([f, y, _, p]) > 1 || a(f, y);
187
+ });
188
+ });
189
+ }
190
+ function a(f, y) {
191
+ try {
192
+ u(n[f](y));
193
+ } catch (_) {
194
+ v(i[0][3], _);
195
+ }
196
+ }
197
+ function u(f) {
198
+ f.value instanceof m ? Promise.resolve(f.value.v).then(c, l) : v(i[0][2], f);
199
+ }
200
+ function c(f) {
201
+ a("next", f);
202
+ }
203
+ function l(f) {
204
+ a("throw", f);
205
+ }
206
+ function v(f, y) {
207
+ f(y), i.shift(), i.length && a(i[0][0], i[0][1]);
208
+ }
209
+ }
210
+ function De(t) {
211
+ if (!Symbol.asyncIterator)
212
+ throw new TypeError("Symbol.asyncIterator is not defined.");
213
+ var r = t[Symbol.asyncIterator], e;
214
+ return r ? r.call(t) : (t = typeof P == "function" ? P(t) : t[Symbol.iterator](), e = {}, n("next"), n("throw"), n("return"), e[Symbol.asyncIterator] = function() {
215
+ return this;
216
+ }, e);
217
+ function n(i) {
218
+ e[i] = t[i] && function(o) {
219
+ return new Promise(function(a, u) {
220
+ o = t[i](o), s(a, u, o.done, o.value);
221
+ });
222
+ };
223
+ }
224
+ function s(i, o, a, u) {
225
+ Promise.resolve(u).then(function(c) {
226
+ i({ value: c, done: a });
227
+ }, o);
228
+ }
229
+ }
230
+ var Le = function(t) {
231
+ return t && typeof t.length == "number" && typeof t != "function";
232
+ };
233
+ function Fe(t) {
234
+ return h(t == null ? void 0 : t.then);
235
+ }
236
+ function ke(t) {
237
+ var r = function(n) {
238
+ Error.call(n), n.stack = new Error().stack;
239
+ }, e = t(r);
240
+ return e.prototype = Object.create(Error.prototype), e.prototype.constructor = e, e;
241
+ }
242
+ var j = ke(function(t) {
243
+ return function(e) {
244
+ t(this), this.message = e ? e.length + ` errors occurred during unsubscription:
245
+ ` + e.map(function(n, s) {
246
+ return s + 1 + ") " + n.toString();
247
+ }).join(`
248
+ `) : "", this.name = "UnsubscriptionError", this.errors = e;
249
+ };
250
+ });
251
+ function ne(t, r) {
252
+ if (t) {
253
+ var e = t.indexOf(r);
254
+ 0 <= e && t.splice(e, 1);
255
+ }
256
+ }
257
+ var Z = function() {
258
+ function t(r) {
259
+ this.initialTeardown = r, this.closed = !1, this._parentage = null, this._finalizers = null;
260
+ }
261
+ return t.prototype.unsubscribe = function() {
262
+ var r, e, n, s, i;
263
+ if (!this.closed) {
264
+ this.closed = !0;
265
+ var o = this._parentage;
266
+ if (o)
267
+ if (this._parentage = null, Array.isArray(o))
268
+ try {
269
+ for (var a = P(o), u = a.next(); !u.done; u = a.next()) {
270
+ var c = u.value;
271
+ c.remove(this);
272
+ }
273
+ } catch (p) {
274
+ r = { error: p };
275
+ } finally {
276
+ try {
277
+ u && !u.done && (e = a.return) && e.call(a);
278
+ } finally {
279
+ if (r)
280
+ throw r.error;
281
+ }
282
+ }
283
+ else
284
+ o.remove(this);
285
+ var l = this.initialTeardown;
286
+ if (h(l))
287
+ try {
288
+ l();
289
+ } catch (p) {
290
+ i = p instanceof j ? p.errors : [p];
291
+ }
292
+ var v = this._finalizers;
293
+ if (v) {
294
+ this._finalizers = null;
295
+ try {
296
+ for (var f = P(v), y = f.next(); !y.done; y = f.next()) {
297
+ var _ = y.value;
298
+ try {
299
+ ie(_);
300
+ } catch (p) {
301
+ i = i ?? [], p instanceof j ? i = E(E([], C(i)), C(p.errors)) : i.push(p);
302
+ }
303
+ }
304
+ } catch (p) {
305
+ n = { error: p };
306
+ } finally {
307
+ try {
308
+ y && !y.done && (s = f.return) && s.call(f);
309
+ } finally {
310
+ if (n)
311
+ throw n.error;
312
+ }
313
+ }
314
+ }
315
+ if (i)
316
+ throw new j(i);
317
+ }
318
+ }, t.prototype.add = function(r) {
319
+ var e;
320
+ if (r && r !== this)
321
+ if (this.closed)
322
+ ie(r);
323
+ else {
324
+ if (r instanceof t) {
325
+ if (r.closed || r._hasParent(this))
326
+ return;
327
+ r._addParent(this);
328
+ }
329
+ (this._finalizers = (e = this._finalizers) !== null && e !== void 0 ? e : []).push(r);
330
+ }
331
+ }, t.prototype._hasParent = function(r) {
332
+ var e = this._parentage;
333
+ return e === r || Array.isArray(e) && e.includes(r);
334
+ }, t.prototype._addParent = function(r) {
335
+ var e = this._parentage;
336
+ this._parentage = Array.isArray(e) ? (e.push(r), e) : e ? [e, r] : r;
337
+ }, t.prototype._removeParent = function(r) {
338
+ var e = this._parentage;
339
+ e === r ? this._parentage = null : Array.isArray(e) && ne(e, r);
340
+ }, t.prototype.remove = function(r) {
341
+ var e = this._finalizers;
342
+ e && ne(e, r), r instanceof t && r._removeParent(this);
343
+ }, t.EMPTY = function() {
344
+ var r = new t();
345
+ return r.closed = !0, r;
346
+ }(), t;
347
+ }();
348
+ Z.EMPTY;
349
+ function be(t) {
350
+ return t instanceof Z || t && "closed" in t && h(t.remove) && h(t.add) && h(t.unsubscribe);
351
+ }
352
+ function ie(t) {
353
+ h(t) ? t() : t.unsubscribe();
354
+ }
355
+ var me = {
356
+ onUnhandledError: null,
357
+ onStoppedNotification: null,
358
+ Promise: void 0,
359
+ useDeprecatedSynchronousErrorHandling: !1,
360
+ useDeprecatedNextContext: !1
361
+ }, k = {
362
+ setTimeout: function(t, r) {
363
+ for (var e = [], n = 2; n < arguments.length; n++)
364
+ e[n - 2] = arguments[n];
365
+ var s = k.delegate;
366
+ return s != null && s.setTimeout ? s.setTimeout.apply(s, E([t, r], C(e))) : setTimeout.apply(void 0, E([t, r], C(e)));
367
+ },
368
+ clearTimeout: function(t) {
369
+ var r = k.delegate;
370
+ return ((r == null ? void 0 : r.clearTimeout) || clearTimeout)(t);
371
+ },
372
+ delegate: void 0
373
+ };
374
+ function _e(t) {
375
+ k.setTimeout(function() {
376
+ throw t;
377
+ });
378
+ }
379
+ function W() {
380
+ }
381
+ function We(t) {
382
+ t();
383
+ }
384
+ var K = function(t) {
385
+ X(r, t);
386
+ function r(e) {
387
+ var n = t.call(this) || this;
388
+ return n.isStopped = !1, e ? (n.destination = e, be(e) && e.add(n)) : n.destination = Ve, n;
389
+ }
390
+ return r.create = function(e, n, s) {
391
+ return new H(e, n, s);
392
+ }, r.prototype.next = function(e) {
393
+ this.isStopped || this._next(e);
394
+ }, r.prototype.error = function(e) {
395
+ this.isStopped || (this.isStopped = !0, this._error(e));
396
+ }, r.prototype.complete = function() {
397
+ this.isStopped || (this.isStopped = !0, this._complete());
398
+ }, r.prototype.unsubscribe = function() {
399
+ this.closed || (this.isStopped = !0, t.prototype.unsubscribe.call(this), this.destination = null);
400
+ }, r.prototype._next = function(e) {
401
+ this.destination.next(e);
402
+ }, r.prototype._error = function(e) {
403
+ try {
404
+ this.destination.error(e);
405
+ } finally {
406
+ this.unsubscribe();
407
+ }
408
+ }, r.prototype._complete = function() {
409
+ try {
410
+ this.destination.complete();
411
+ } finally {
412
+ this.unsubscribe();
413
+ }
414
+ }, r;
415
+ }(Z), He = Function.prototype.bind;
416
+ function $(t, r) {
417
+ return He.call(t, r);
418
+ }
419
+ var Ge = function() {
420
+ function t(r) {
421
+ this.partialObserver = r;
422
+ }
423
+ return t.prototype.next = function(r) {
424
+ var e = this.partialObserver;
425
+ if (e.next)
426
+ try {
427
+ e.next(r);
428
+ } catch (n) {
429
+ R(n);
430
+ }
431
+ }, t.prototype.error = function(r) {
432
+ var e = this.partialObserver;
433
+ if (e.error)
434
+ try {
435
+ e.error(r);
436
+ } catch (n) {
437
+ R(n);
438
+ }
439
+ else
440
+ R(r);
441
+ }, t.prototype.complete = function() {
442
+ var r = this.partialObserver;
443
+ if (r.complete)
444
+ try {
445
+ r.complete();
446
+ } catch (e) {
447
+ R(e);
448
+ }
449
+ }, t;
450
+ }(), H = function(t) {
451
+ X(r, t);
452
+ function r(e, n, s) {
453
+ var i = t.call(this) || this, o;
454
+ if (h(e) || !e)
455
+ o = {
456
+ next: e ?? void 0,
457
+ error: n ?? void 0,
458
+ complete: s ?? void 0
459
+ };
460
+ else {
461
+ var a;
462
+ i && me.useDeprecatedNextContext ? (a = Object.create(e), a.unsubscribe = function() {
463
+ return i.unsubscribe();
464
+ }, o = {
465
+ next: e.next && $(e.next, a),
466
+ error: e.error && $(e.error, a),
467
+ complete: e.complete && $(e.complete, a)
468
+ }) : o = e;
469
+ }
470
+ return i.destination = new Ge(o), i;
471
+ }
472
+ return r;
473
+ }(K);
474
+ function R(t) {
475
+ _e(t);
476
+ }
477
+ function Ye(t) {
478
+ throw t;
479
+ }
480
+ var Ve = {
481
+ closed: !0,
482
+ next: W,
483
+ error: Ye,
484
+ complete: W
485
+ }, N = function() {
486
+ return typeof Symbol == "function" && Symbol.observable || "@@observable";
487
+ }();
488
+ function ze(t) {
489
+ return t;
490
+ }
491
+ function Be(t) {
492
+ return t.length === 0 ? ze : t.length === 1 ? t[0] : function(e) {
493
+ return t.reduce(function(n, s) {
494
+ return s(n);
495
+ }, e);
496
+ };
497
+ }
498
+ var b = function() {
499
+ function t(r) {
500
+ r && (this._subscribe = r);
501
+ }
502
+ return t.prototype.lift = function(r) {
503
+ var e = new t();
504
+ return e.source = this, e.operator = r, e;
505
+ }, t.prototype.subscribe = function(r, e, n) {
506
+ var s = this, i = Qe(r) ? r : new H(r, e, n);
507
+ return We(function() {
508
+ var o = s, a = o.operator, u = o.source;
509
+ i.add(a ? a.call(i, u) : u ? s._subscribe(i) : s._trySubscribe(i));
510
+ }), i;
511
+ }, t.prototype._trySubscribe = function(r) {
512
+ try {
513
+ return this._subscribe(r);
514
+ } catch (e) {
515
+ r.error(e);
516
+ }
517
+ }, t.prototype.forEach = function(r, e) {
518
+ var n = this;
519
+ return e = se(e), new e(function(s, i) {
520
+ var o = new H({
521
+ next: function(a) {
522
+ try {
523
+ r(a);
524
+ } catch (u) {
525
+ i(u), o.unsubscribe();
526
+ }
527
+ },
528
+ error: i,
529
+ complete: s
530
+ });
531
+ n.subscribe(o);
532
+ });
533
+ }, t.prototype._subscribe = function(r) {
534
+ var e;
535
+ return (e = this.source) === null || e === void 0 ? void 0 : e.subscribe(r);
536
+ }, t.prototype[N] = function() {
537
+ return this;
538
+ }, t.prototype.pipe = function() {
539
+ for (var r = [], e = 0; e < arguments.length; e++)
540
+ r[e] = arguments[e];
541
+ return Be(r)(this);
542
+ }, t.prototype.toPromise = function(r) {
543
+ var e = this;
544
+ return r = se(r), new r(function(n, s) {
545
+ var i;
546
+ e.subscribe(function(o) {
547
+ return i = o;
548
+ }, function(o) {
549
+ return s(o);
550
+ }, function() {
551
+ return n(i);
552
+ });
553
+ });
554
+ }, t.create = function(r) {
555
+ return new t(r);
556
+ }, t;
557
+ }();
558
+ function se(t) {
559
+ var r;
560
+ return (r = t ?? me.Promise) !== null && r !== void 0 ? r : Promise;
561
+ }
562
+ function Je(t) {
563
+ return t && h(t.next) && h(t.error) && h(t.complete);
564
+ }
565
+ function Qe(t) {
566
+ return t && t instanceof K || Je(t) && be(t);
567
+ }
568
+ function Xe(t) {
569
+ return h(t[N]);
570
+ }
571
+ function Ze(t) {
572
+ return Symbol.asyncIterator && h(t == null ? void 0 : t[Symbol.asyncIterator]);
573
+ }
574
+ function Ke(t) {
575
+ return new TypeError("You provided " + (t !== null && typeof t == "object" ? "an invalid object" : "'" + t + "'") + " where a stream was expected. You can provide an Observable, Promise, ReadableStream, Array, AsyncIterable, or Iterable.");
576
+ }
577
+ function Ne() {
578
+ return typeof Symbol != "function" || !Symbol.iterator ? "@@iterator" : Symbol.iterator;
579
+ }
580
+ var et = Ne();
581
+ function tt(t) {
582
+ return h(t == null ? void 0 : t[et]);
583
+ }
584
+ function rt(t) {
585
+ return $e(this, arguments, function() {
586
+ var e, n, s, i;
587
+ return ve(this, function(o) {
588
+ switch (o.label) {
589
+ case 0:
590
+ e = t.getReader(), o.label = 1;
591
+ case 1:
592
+ o.trys.push([1, , 9, 10]), o.label = 2;
593
+ case 2:
594
+ return [4, m(e.read())];
595
+ case 3:
596
+ return n = o.sent(), s = n.value, i = n.done, i ? [4, m(void 0)] : [3, 5];
597
+ case 4:
598
+ return [2, o.sent()];
599
+ case 5:
600
+ return [4, m(s)];
601
+ case 6:
602
+ return [4, o.sent()];
603
+ case 7:
604
+ return o.sent(), [3, 2];
605
+ case 8:
606
+ return [3, 10];
607
+ case 9:
608
+ return e.releaseLock(), [7];
609
+ case 10:
610
+ return [2];
611
+ }
612
+ });
613
+ });
614
+ }
615
+ function nt(t) {
616
+ return h(t == null ? void 0 : t.getReader);
617
+ }
618
+ function it(t) {
619
+ if (t instanceof b)
620
+ return t;
621
+ if (t != null) {
622
+ if (Xe(t))
623
+ return st(t);
624
+ if (Le(t))
625
+ return ot(t);
626
+ if (Fe(t))
627
+ return ct(t);
628
+ if (Ze(t))
629
+ return Se(t);
630
+ if (tt(t))
631
+ return at(t);
632
+ if (nt(t))
633
+ return ut(t);
634
+ }
635
+ throw Ke(t);
636
+ }
637
+ function st(t) {
638
+ return new b(function(r) {
639
+ var e = t[N]();
640
+ if (h(e.subscribe))
641
+ return e.subscribe(r);
642
+ throw new TypeError("Provided object does not correctly implement Symbol.observable");
643
+ });
644
+ }
645
+ function ot(t) {
646
+ return new b(function(r) {
647
+ for (var e = 0; e < t.length && !r.closed; e++)
648
+ r.next(t[e]);
649
+ r.complete();
650
+ });
651
+ }
652
+ function ct(t) {
653
+ return new b(function(r) {
654
+ t.then(function(e) {
655
+ r.closed || (r.next(e), r.complete());
656
+ }, function(e) {
657
+ return r.error(e);
658
+ }).then(null, _e);
659
+ });
660
+ }
661
+ function at(t) {
662
+ return new b(function(r) {
663
+ var e, n;
664
+ try {
665
+ for (var s = P(t), i = s.next(); !i.done; i = s.next()) {
666
+ var o = i.value;
667
+ if (r.next(o), r.closed)
668
+ return;
669
+ }
670
+ } catch (a) {
671
+ e = { error: a };
672
+ } finally {
673
+ try {
674
+ i && !i.done && (n = s.return) && n.call(s);
675
+ } finally {
676
+ if (e)
677
+ throw e.error;
678
+ }
679
+ }
680
+ r.complete();
681
+ });
682
+ }
683
+ function Se(t) {
684
+ return new b(function(r) {
685
+ lt(t, r).catch(function(e) {
686
+ return r.error(e);
687
+ });
688
+ });
689
+ }
690
+ function ut(t) {
691
+ return Se(rt(t));
692
+ }
693
+ function lt(t, r) {
694
+ var e, n, s, i;
695
+ return je(this, void 0, void 0, function() {
696
+ var o, a;
697
+ return ve(this, function(u) {
698
+ switch (u.label) {
699
+ case 0:
700
+ u.trys.push([0, 5, 6, 11]), e = De(t), u.label = 1;
701
+ case 1:
702
+ return [4, e.next()];
703
+ case 2:
704
+ if (n = u.sent(), !!n.done)
705
+ return [3, 4];
706
+ if (o = n.value, r.next(o), r.closed)
707
+ return [2];
708
+ u.label = 3;
709
+ case 3:
710
+ return [3, 1];
711
+ case 4:
712
+ return [3, 11];
713
+ case 5:
714
+ return a = u.sent(), s = { error: a }, [3, 11];
715
+ case 6:
716
+ return u.trys.push([6, , 9, 10]), n && !n.done && (i = e.return) ? [4, i.call(e)] : [3, 8];
717
+ case 7:
718
+ u.sent(), u.label = 8;
719
+ case 8:
720
+ return [3, 10];
721
+ case 9:
722
+ if (s)
723
+ throw s.error;
724
+ return [7];
725
+ case 10:
726
+ return [7];
727
+ case 11:
728
+ return r.complete(), [2];
729
+ }
730
+ });
731
+ });
732
+ }
733
+ function ee(t, r, e, n, s) {
734
+ return new ft(t, r, e, n, s);
735
+ }
736
+ var ft = function(t) {
737
+ X(r, t);
738
+ function r(e, n, s, i, o, a) {
739
+ var u = t.call(this, e) || this;
740
+ return u.onFinalize = o, u.shouldUnsubscribe = a, u._next = n ? function(c) {
741
+ try {
742
+ n(c);
743
+ } catch (l) {
744
+ e.error(l);
745
+ }
746
+ } : t.prototype._next, u._error = i ? function(c) {
747
+ try {
748
+ i(c);
749
+ } catch (l) {
750
+ e.error(l);
751
+ } finally {
752
+ this.unsubscribe();
753
+ }
754
+ } : t.prototype._error, u._complete = s ? function() {
755
+ try {
756
+ s();
757
+ } catch (c) {
758
+ e.error(c);
759
+ } finally {
760
+ this.unsubscribe();
761
+ }
762
+ } : t.prototype._complete, u;
763
+ }
764
+ return r.prototype.unsubscribe = function() {
765
+ var e;
766
+ if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
767
+ var n = this.closed;
768
+ t.prototype.unsubscribe.call(this), !n && ((e = this.onFinalize) === null || e === void 0 || e.call(this));
769
+ }
770
+ }, r;
771
+ }(K), ht = new b(function(t) {
772
+ return t.complete();
773
+ });
774
+ function pt(t) {
775
+ return t <= 0 ? function() {
776
+ return ht;
777
+ } : Q(function(r, e) {
778
+ var n = 0;
779
+ r.subscribe(ee(e, function(s) {
780
+ ++n <= t && (e.next(s), t <= n && e.complete());
781
+ }));
782
+ });
783
+ }
784
+ function dt(t, r) {
785
+ return Q(function(e, n) {
786
+ var s = 0;
787
+ e.subscribe(ee(n, function(i) {
788
+ return t.call(r, i, s++) && n.next(i);
789
+ }));
790
+ });
791
+ }
792
+ function x(t) {
793
+ return Q(function(r, e) {
794
+ it(t).subscribe(ee(e, function() {
795
+ return e.complete();
796
+ }, W)), !e.closed && r.subscribe(e);
797
+ });
798
+ }
799
+ var yt = Object.defineProperty, vt = Object.getOwnPropertyDescriptor, we = (t, r, e, n) => {
800
+ for (var s = n > 1 ? void 0 : n ? vt(r, e) : r, i = t.length - 1, o; i >= 0; i--)
801
+ (o = t[i]) && (s = (n ? o(r, e, s) : o(s)) || s);
802
+ return n && s && yt(r, e, s), s;
803
+ }, G = (t, r) => (e, n) => r(e, n, t);
804
+ const te = "univer.remote-sync-service", O = B(te);
805
+ let Y = class {
806
+ constructor(t) {
807
+ this._commandService = t;
808
+ }
809
+ async syncMutation(t) {
810
+ return this._commandService.syncExecuteCommand(t.mutationInfo.id, t.mutationInfo.params, {
811
+ local: !0,
812
+ fromSync: !0
813
+ });
814
+ }
815
+ };
816
+ Y = we([
817
+ G(0, M)
818
+ ], Y);
819
+ const re = "univer.remote-instance-service", T = B(re);
820
+ let V = class {
821
+ constructor(t, r) {
822
+ this._univerInstanceService = t, this._commandService = r;
823
+ }
824
+ async syncMutation(t) {
825
+ return this._commandService.syncExecuteCommand(t.mutationInfo.id, t.mutationInfo.params, {
826
+ local: !0,
827
+ fromSync: !0
828
+ });
829
+ }
830
+ async createInstance(t) {
831
+ const { type: r, snapshot: e } = t;
832
+ try {
833
+ switch (r) {
834
+ case ae.SHEET:
835
+ return !!this._univerInstanceService.createSheet(e);
836
+ default:
837
+ throw new Error(
838
+ `[RemoteInstanceReplicaService]: cannot create replica for document type: ${r}.`
839
+ );
840
+ }
841
+ } catch (n) {
842
+ throw n instanceof Error ? n : new Error(`${n}`);
843
+ }
844
+ }
845
+ async disposeInstance(t) {
846
+ return this._univerInstanceService.disposeDocument(t.unitID);
847
+ }
848
+ };
849
+ V = we([
850
+ G(0, ue),
851
+ G(1, M)
852
+ ], V);
853
+ function ge(t) {
854
+ const r = t;
855
+ return new class {
856
+ call(e, n) {
857
+ const s = r[e];
858
+ if (typeof s == "function") {
859
+ let i = s.apply(r, [n]);
860
+ return i instanceof Promise || (i = Promise.resolve(i)), i;
861
+ }
862
+ throw new Error(`[RPC]: method not found for ${e}!`);
863
+ }
864
+ subscribe(e, n) {
865
+ const s = r[e];
866
+ if (typeof s == "function") {
867
+ const i = s.apply(r, n);
868
+ return qe(i) ? i : Ae(i);
869
+ }
870
+ throw new Error(`[RPC]: observable method not found for ${e}!`);
871
+ }
872
+ }();
873
+ }
874
+ function Pe(t) {
875
+ return new Proxy({}, {
876
+ get(r, e) {
877
+ return function(...n) {
878
+ return bt(e) ? t.subscribe(e, n[0]) : t.call(e, n[0]);
879
+ };
880
+ }
881
+ });
882
+ }
883
+ function bt(t) {
884
+ return t.endsWith("$");
885
+ }
886
+ class mt extends z {
887
+ constructor(e) {
888
+ super();
889
+ d(this, "_initialized", new Te(!1));
890
+ d(this, "_lastRequestCounter", 0);
891
+ d(this, "_pendingRequests", /* @__PURE__ */ new Map());
892
+ d(this, "_pendingSubscriptions", /* @__PURE__ */ new Map());
893
+ this._protocol = e, this._protocol.onMessage.pipe(x(this.dispose$)).subscribe((n) => this._onResponse(n));
894
+ }
895
+ getChannel(e) {
896
+ const n = this;
897
+ return {
898
+ call(s, i) {
899
+ return n._disposed ? Promise.reject() : n._remoteCall(e, s, i);
900
+ },
901
+ subscribe(s, i) {
902
+ if (n._disposed)
903
+ throw new Error("[ChannelClient]: client is disposed!");
904
+ return n._remoteSubscribe(e, s, i);
905
+ }
906
+ };
907
+ }
908
+ _whenReady() {
909
+ return Me(
910
+ this._initialized.pipe(
911
+ dt((e) => e),
912
+ pt(1)
913
+ )
914
+ );
915
+ }
916
+ async _remoteCall(e, n, s) {
917
+ await this._whenReady();
918
+ const i = ++this._lastRequestCounter, a = { seq: i, type: 100, channelName: e, method: n, args: s }, u = this;
919
+ return new Promise((c, l) => {
920
+ const v = {
921
+ handle(f) {
922
+ switch (f.type) {
923
+ case 100:
924
+ u._pendingRequests.delete(i), c(f.data);
925
+ break;
926
+ case 101:
927
+ u._pendingRequests.delete(i), l(f.data);
928
+ break;
929
+ default:
930
+ throw new Error("[ChannelClient]: unknown response type!");
931
+ }
932
+ }
933
+ };
934
+ this._pendingRequests.set(i, v), this._sendRequest(a);
935
+ });
936
+ }
937
+ _remoteSubscribe(e, n, s) {
938
+ return new J((i) => {
939
+ let o = -1;
940
+ return this._whenReady().then(() => {
941
+ o = ++this._lastRequestCounter;
942
+ const u = { seq: o, type: 101, channelName: e, method: n, args: s }, c = {
943
+ handle(l) {
944
+ switch (l.type) {
945
+ case 200:
946
+ i.next(l.data);
947
+ break;
948
+ case 201:
949
+ i.error(l.data);
950
+ break;
951
+ case 202:
952
+ i.complete();
953
+ break;
954
+ default:
955
+ throw new Error("[ChannelClient]: unknown response type!");
956
+ }
957
+ }
958
+ };
959
+ this._pendingRequests.set(o, c), this._sendRequest(u);
960
+ }), () => {
961
+ if (o === -1)
962
+ return;
963
+ const a = {
964
+ type: 102,
965
+ seq: o,
966
+ channelName: e,
967
+ method: n
968
+ };
969
+ this._sendRequest(a);
970
+ };
971
+ });
972
+ }
973
+ _sendRequest(e) {
974
+ this._protocol.send(e);
975
+ }
976
+ _onResponse(e) {
977
+ var n;
978
+ switch (e.type) {
979
+ case 0:
980
+ this._initialized.next(!0);
981
+ break;
982
+ case 100:
983
+ case 101:
984
+ case 200:
985
+ case 202:
986
+ case 201:
987
+ (n = this._pendingRequests.get(e.seq)) == null || n.handle(e);
988
+ break;
989
+ }
990
+ }
991
+ }
992
+ class _t extends z {
993
+ constructor(e) {
994
+ super();
995
+ d(this, "_channels", /* @__PURE__ */ new Map());
996
+ d(this, "_subscriptions", /* @__PURE__ */ new Map());
997
+ this._protocol = e, this._protocol.onMessage.pipe(x(this.dispose$)).subscribe((n) => this._onRequest(n)), this._sendResponse({
998
+ seq: -1,
999
+ type: 0
1000
+ /* INITIALIZE */
1001
+ });
1002
+ }
1003
+ registerChannel(e, n) {
1004
+ this._channels.set(e, n);
1005
+ }
1006
+ _onRequest(e) {
1007
+ switch (e.type) {
1008
+ case 100:
1009
+ this._onMethodCall(e);
1010
+ break;
1011
+ case 101:
1012
+ this._onSubscribe(e);
1013
+ break;
1014
+ case 102:
1015
+ this._onUnsubscribe(e);
1016
+ break;
1017
+ }
1018
+ }
1019
+ _onMethodCall(e) {
1020
+ const n = this._channels.get(e.channelName);
1021
+ let s;
1022
+ try {
1023
+ if (!n)
1024
+ throw new Error("[ChannelServer]: Channel not found!");
1025
+ s = n.call(e.method, e.args);
1026
+ } catch (i) {
1027
+ s = Promise.reject(i);
1028
+ }
1029
+ s.then((i) => {
1030
+ this._sendResponse({ seq: e.seq, type: 100, data: i });
1031
+ }).catch((i) => {
1032
+ i instanceof Error ? this._sendResponse({ seq: e.seq, type: 101, data: i.message }) : this._sendResponse({ seq: e.seq, type: 101, data: String(i) });
1033
+ });
1034
+ }
1035
+ _onSubscribe(e) {
1036
+ const n = this._channels.get(e.channelName);
1037
+ try {
1038
+ if (!n)
1039
+ throw new Error("[ChannelServer]: Channel not found!");
1040
+ const i = n.subscribe(e.method, e.args).subscribe({
1041
+ next: (o) => {
1042
+ this._sendResponse({ seq: e.seq, type: 200, data: o });
1043
+ },
1044
+ error: (o) => {
1045
+ this._sendResponse({ seq: e.seq, type: 201, data: o.message }), this._sendResponse({
1046
+ seq: e.seq,
1047
+ type: 202
1048
+ /* SUBSCRIBE_COMPLETE */
1049
+ });
1050
+ },
1051
+ complete: () => {
1052
+ this._sendResponse({
1053
+ seq: e.seq,
1054
+ type: 202
1055
+ /* SUBSCRIBE_COMPLETE */
1056
+ });
1057
+ }
1058
+ });
1059
+ this._subscriptions.set(e.seq, i);
1060
+ } catch (s) {
1061
+ s instanceof Error ? this._sendResponse({ seq: e.seq, type: 201, data: s.message }) : this._sendResponse({ seq: e.seq, type: 201, data: String(s) });
1062
+ }
1063
+ }
1064
+ _onUnsubscribe(e) {
1065
+ const n = this._subscriptions.get(e.seq);
1066
+ n && (n.unsubscribe(), this._subscriptions.delete(e.seq));
1067
+ }
1068
+ _sendResponse(e) {
1069
+ this._protocol.send(e);
1070
+ }
1071
+ }
1072
+ const U = B("IRPChannelService");
1073
+ class Re {
1074
+ constructor(r) {
1075
+ d(this, "_client");
1076
+ d(this, "_server");
1077
+ this._client = new mt(r), this._server = new _t(r);
1078
+ }
1079
+ requestChannel(r) {
1080
+ return this._client.getChannel(r);
1081
+ }
1082
+ registerChannel(r, e) {
1083
+ this._server.registerChannel(r, e);
1084
+ }
1085
+ }
1086
+ var St = Object.defineProperty, wt = Object.getOwnPropertyDescriptor, gt = (t, r, e, n) => {
1087
+ for (var s = n > 1 ? void 0 : n ? wt(r, e) : r, i = t.length - 1, o; i >= 0; i--)
1088
+ (o = t[i]) && (s = (n ? o(r, e, s) : o(s)) || s);
1089
+ return n && s && St(r, e, s), s;
1090
+ }, S = (t, r) => (e, n) => r(e, n, t);
1091
+ let w = class extends z {
1092
+ constructor(r, e, n, s, i, o) {
1093
+ super();
1094
+ d(this, "_remoteInstanceService");
1095
+ this._unsyncMutations = r, this._injector = e, this._commandService = n, this._univerInstanceService = s, this._rpcChannelService = i, this._remoteSyncService = o, this._initRPCChannels(), this._init();
1096
+ }
1097
+ _initRPCChannels() {
1098
+ this._rpcChannelService.registerChannel(te, ge(this._remoteSyncService)), this._injector.add([
1099
+ T,
1100
+ {
1101
+ useFactory: () => Pe(this._rpcChannelService.requestChannel(re))
1102
+ }
1103
+ ]), this._remoteInstanceService = this._injector.get(T);
1104
+ }
1105
+ _init() {
1106
+ this._univerInstanceService.sheetAdded$.pipe(x(this.dispose$)).subscribe((r) => {
1107
+ this._remoteInstanceService.createInstance({
1108
+ unitID: r.getUnitId(),
1109
+ type: ae.SHEET,
1110
+ snapshot: r.getSnapshot()
1111
+ });
1112
+ }), this._univerInstanceService.sheetDisposed$.pipe(x(this.dispose$)).subscribe((r) => {
1113
+ this._remoteInstanceService.disposeInstance({
1114
+ unitID: r.getUnitId()
1115
+ });
1116
+ }), this.disposeWithMe(
1117
+ // Mutations executed on the main thread should be synced to the worker thread.
1118
+ this._commandService.onCommandExecuted((r, e) => {
1119
+ r.type === he.MUTATION && !(e != null && e.fromSync) && !this._unsyncMutations.has(r.id) && this._remoteInstanceService.syncMutation({
1120
+ mutationInfo: r
1121
+ });
1122
+ })
1123
+ );
1124
+ }
1125
+ };
1126
+ w = gt([
1127
+ le(fe.Starting, w),
1128
+ S(1, q(A)),
1129
+ S(2, M),
1130
+ S(3, ue),
1131
+ S(4, U),
1132
+ S(5, O)
1133
+ ], w);
1134
+ var Pt = Object.defineProperty, Rt = Object.getOwnPropertyDescriptor, It = (t, r, e, n) => {
1135
+ for (var s = n > 1 ? void 0 : n ? Rt(r, e) : r, i = t.length - 1, o; i >= 0; i--)
1136
+ (o = t[i]) && (s = (n ? o(r, e, s) : o(s)) || s);
1137
+ return n && s && Pt(r, e, s), s;
1138
+ }, I = (t, r) => (e, n) => r(e, n, t);
1139
+ let g = class extends Oe {
1140
+ constructor(r, e, n, s) {
1141
+ super();
1142
+ d(this, "_remoteSyncService");
1143
+ this._injector = r, this._remoteInstanceService = e, this._commandService = n, this._rpcChannelService = s, this._initRPCChannels(), this._init();
1144
+ }
1145
+ _initRPCChannels() {
1146
+ this._rpcChannelService.registerChannel(re, ge(this._remoteInstanceService)), this._injector.add([
1147
+ O,
1148
+ {
1149
+ useFactory: () => Pe(this._rpcChannelService.requestChannel(te))
1150
+ }
1151
+ ]), this._remoteSyncService = this._injector.get(O);
1152
+ }
1153
+ _init() {
1154
+ this.disposeWithMe(
1155
+ // Mutations executed on the main thread should be synced to the worker thread.
1156
+ this._commandService.onCommandExecuted((r, e) => {
1157
+ r.type === he.MUTATION && !(e != null && e.fromSync) && this._remoteSyncService.syncMutation({
1158
+ mutationInfo: r
1159
+ });
1160
+ })
1161
+ );
1162
+ }
1163
+ };
1164
+ g = It([
1165
+ le(fe.Starting, g),
1166
+ I(0, q(A)),
1167
+ I(1, T),
1168
+ I(2, M),
1169
+ I(3, U)
1170
+ ], g);
1171
+ function Ct() {
1172
+ return {
1173
+ send(t) {
1174
+ postMessage(t);
1175
+ },
1176
+ onMessage: new J((t) => {
1177
+ const r = (e) => {
1178
+ t.next(e.data);
1179
+ };
1180
+ return addEventListener("message", r), () => removeEventListener("message", r);
1181
+ }).pipe(ye(1))
1182
+ };
1183
+ }
1184
+ function Et(t) {
1185
+ return {
1186
+ send(r) {
1187
+ t.postMessage(r);
1188
+ },
1189
+ onMessage: new J((r) => {
1190
+ const e = (n) => {
1191
+ r.next(n.data);
1192
+ };
1193
+ return t.addEventListener("message", e), () => t.removeEventListener("message", e);
1194
+ }).pipe(ye(1))
1195
+ };
1196
+ }
1197
+ var xt = Object.defineProperty, Ot = Object.getOwnPropertyDescriptor, Ie = (t, r, e, n) => {
1198
+ for (var s = n > 1 ? void 0 : n ? Ot(r, e) : r, i = t.length - 1, o; i >= 0; i--)
1199
+ (o = t[i]) && (s = (n ? o(r, e, s) : o(s)) || s);
1200
+ return n && s && xt(r, e, s), s;
1201
+ }, Ce = (t, r) => (e, n) => r(e, n, t), D;
1202
+ let oe = (D = class extends pe {
1203
+ constructor(t, r) {
1204
+ super("UNIVER_RPC_MAIN_THREAD_PLUGIN"), this._config = t, this._injector = r;
1205
+ }
1206
+ async onStarting(t) {
1207
+ const r = new Worker(this._config.workerURL), e = Et(r);
1208
+ [
1209
+ [
1210
+ U,
1211
+ {
1212
+ useFactory: () => new Re(e)
1213
+ }
1214
+ ],
1215
+ [
1216
+ w,
1217
+ {
1218
+ useFactory: () => {
1219
+ var s;
1220
+ return t.createInstance(w, ((s = this._config) == null ? void 0 : s.unsyncMutations) ?? /* @__PURE__ */ new Set());
1221
+ }
1222
+ }
1223
+ ],
1224
+ [O, { useClass: Y }]
1225
+ ].forEach((s) => t.add(s));
1226
+ }
1227
+ }, d(D, "type", de.Univer), D);
1228
+ oe = Ie([
1229
+ Ce(1, q(A))
1230
+ ], oe);
1231
+ var L;
1232
+ let ce = (L = class extends pe {
1233
+ constructor(t, r) {
1234
+ super("UNIVER_RPC_WORKER_THREAD_PLUGIN"), this._config = t, this._injector = r;
1235
+ }
1236
+ onStarting(t) {
1237
+ [
1238
+ [g],
1239
+ [
1240
+ U,
1241
+ {
1242
+ useFactory: () => new Re(Ct())
1243
+ }
1244
+ ],
1245
+ [T, { useClass: V }]
1246
+ ].forEach((r) => t.add(r)), t.get(g);
1247
+ }
1248
+ }, d(L, "type", de.Univer), L);
1249
+ ce = Ie([
1250
+ Ce(1, q(A))
1251
+ ], ce);
1252
+ export {
1253
+ mt as ChannelClient,
1254
+ _t as ChannelServer,
1255
+ U as IRPChannelService,
1256
+ oe as UniverRPCMainThreadPlugin,
1257
+ ce as UniverRPCWorkerThreadPlugin
1258
+ };