@valbuild/react 0.20.0 → 0.21.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.
@@ -0,0 +1,622 @@
1
+ import React, { useContext, useMemo, lazy } from 'react';
2
+ import { _ as _unsupportedIterableToArray, a as _slicedToArray } from './slicedToArray-b4fb91fa.esm.js';
3
+ import { _ as _toPropertyKey, a as _defineProperty } from './defineProperty-b209a901.esm.js';
4
+ import { result } from '@valbuild/core/fp';
5
+ import { ValApi } from '@valbuild/core';
6
+ import { jsxs, jsx } from 'react/jsx-runtime';
7
+
8
+ function _createForOfIteratorHelper(o, allowArrayLike) {
9
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
10
+ if (!it) {
11
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
12
+ if (it) o = it;
13
+ var i = 0;
14
+ var F = function () {};
15
+ return {
16
+ s: F,
17
+ n: function () {
18
+ if (i >= o.length) return {
19
+ done: true
20
+ };
21
+ return {
22
+ done: false,
23
+ value: o[i++]
24
+ };
25
+ },
26
+ e: function (e) {
27
+ throw e;
28
+ },
29
+ f: F
30
+ };
31
+ }
32
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
33
+ }
34
+ var normalCompletion = true,
35
+ didErr = false,
36
+ err;
37
+ return {
38
+ s: function () {
39
+ it = it.call(o);
40
+ },
41
+ n: function () {
42
+ var step = it.next();
43
+ normalCompletion = step.done;
44
+ return step;
45
+ },
46
+ e: function (e) {
47
+ didErr = true;
48
+ err = e;
49
+ },
50
+ f: function () {
51
+ try {
52
+ if (!normalCompletion && it.return != null) it.return();
53
+ } finally {
54
+ if (didErr) throw err;
55
+ }
56
+ }
57
+ };
58
+ }
59
+
60
+ function _regeneratorRuntime() {
61
+ _regeneratorRuntime = function () {
62
+ return exports;
63
+ };
64
+ var exports = {},
65
+ Op = Object.prototype,
66
+ hasOwn = Op.hasOwnProperty,
67
+ defineProperty = Object.defineProperty || function (obj, key, desc) {
68
+ obj[key] = desc.value;
69
+ },
70
+ $Symbol = "function" == typeof Symbol ? Symbol : {},
71
+ iteratorSymbol = $Symbol.iterator || "@@iterator",
72
+ asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
73
+ toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
74
+ function define(obj, key, value) {
75
+ return Object.defineProperty(obj, key, {
76
+ value: value,
77
+ enumerable: !0,
78
+ configurable: !0,
79
+ writable: !0
80
+ }), obj[key];
81
+ }
82
+ try {
83
+ define({}, "");
84
+ } catch (err) {
85
+ define = function (obj, key, value) {
86
+ return obj[key] = value;
87
+ };
88
+ }
89
+ function wrap(innerFn, outerFn, self, tryLocsList) {
90
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
91
+ generator = Object.create(protoGenerator.prototype),
92
+ context = new Context(tryLocsList || []);
93
+ return defineProperty(generator, "_invoke", {
94
+ value: makeInvokeMethod(innerFn, self, context)
95
+ }), generator;
96
+ }
97
+ function tryCatch(fn, obj, arg) {
98
+ try {
99
+ return {
100
+ type: "normal",
101
+ arg: fn.call(obj, arg)
102
+ };
103
+ } catch (err) {
104
+ return {
105
+ type: "throw",
106
+ arg: err
107
+ };
108
+ }
109
+ }
110
+ exports.wrap = wrap;
111
+ var ContinueSentinel = {};
112
+ function Generator() {}
113
+ function GeneratorFunction() {}
114
+ function GeneratorFunctionPrototype() {}
115
+ var IteratorPrototype = {};
116
+ define(IteratorPrototype, iteratorSymbol, function () {
117
+ return this;
118
+ });
119
+ var getProto = Object.getPrototypeOf,
120
+ NativeIteratorPrototype = getProto && getProto(getProto(values([])));
121
+ NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
122
+ var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
123
+ function defineIteratorMethods(prototype) {
124
+ ["next", "throw", "return"].forEach(function (method) {
125
+ define(prototype, method, function (arg) {
126
+ return this._invoke(method, arg);
127
+ });
128
+ });
129
+ }
130
+ function AsyncIterator(generator, PromiseImpl) {
131
+ function invoke(method, arg, resolve, reject) {
132
+ var record = tryCatch(generator[method], generator, arg);
133
+ if ("throw" !== record.type) {
134
+ var result = record.arg,
135
+ value = result.value;
136
+ return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
137
+ invoke("next", value, resolve, reject);
138
+ }, function (err) {
139
+ invoke("throw", err, resolve, reject);
140
+ }) : PromiseImpl.resolve(value).then(function (unwrapped) {
141
+ result.value = unwrapped, resolve(result);
142
+ }, function (error) {
143
+ return invoke("throw", error, resolve, reject);
144
+ });
145
+ }
146
+ reject(record.arg);
147
+ }
148
+ var previousPromise;
149
+ defineProperty(this, "_invoke", {
150
+ value: function (method, arg) {
151
+ function callInvokeWithMethodAndArg() {
152
+ return new PromiseImpl(function (resolve, reject) {
153
+ invoke(method, arg, resolve, reject);
154
+ });
155
+ }
156
+ return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
157
+ }
158
+ });
159
+ }
160
+ function makeInvokeMethod(innerFn, self, context) {
161
+ var state = "suspendedStart";
162
+ return function (method, arg) {
163
+ if ("executing" === state) throw new Error("Generator is already running");
164
+ if ("completed" === state) {
165
+ if ("throw" === method) throw arg;
166
+ return doneResult();
167
+ }
168
+ for (context.method = method, context.arg = arg;;) {
169
+ var delegate = context.delegate;
170
+ if (delegate) {
171
+ var delegateResult = maybeInvokeDelegate(delegate, context);
172
+ if (delegateResult) {
173
+ if (delegateResult === ContinueSentinel) continue;
174
+ return delegateResult;
175
+ }
176
+ }
177
+ if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
178
+ if ("suspendedStart" === state) throw state = "completed", context.arg;
179
+ context.dispatchException(context.arg);
180
+ } else "return" === context.method && context.abrupt("return", context.arg);
181
+ state = "executing";
182
+ var record = tryCatch(innerFn, self, context);
183
+ if ("normal" === record.type) {
184
+ if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
185
+ return {
186
+ value: record.arg,
187
+ done: context.done
188
+ };
189
+ }
190
+ "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
191
+ }
192
+ };
193
+ }
194
+ function maybeInvokeDelegate(delegate, context) {
195
+ var methodName = context.method,
196
+ method = delegate.iterator[methodName];
197
+ if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
198
+ var record = tryCatch(method, delegate.iterator, context.arg);
199
+ if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
200
+ var info = record.arg;
201
+ return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
202
+ }
203
+ function pushTryEntry(locs) {
204
+ var entry = {
205
+ tryLoc: locs[0]
206
+ };
207
+ 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
208
+ }
209
+ function resetTryEntry(entry) {
210
+ var record = entry.completion || {};
211
+ record.type = "normal", delete record.arg, entry.completion = record;
212
+ }
213
+ function Context(tryLocsList) {
214
+ this.tryEntries = [{
215
+ tryLoc: "root"
216
+ }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
217
+ }
218
+ function values(iterable) {
219
+ if (iterable) {
220
+ var iteratorMethod = iterable[iteratorSymbol];
221
+ if (iteratorMethod) return iteratorMethod.call(iterable);
222
+ if ("function" == typeof iterable.next) return iterable;
223
+ if (!isNaN(iterable.length)) {
224
+ var i = -1,
225
+ next = function next() {
226
+ for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
227
+ return next.value = undefined, next.done = !0, next;
228
+ };
229
+ return next.next = next;
230
+ }
231
+ }
232
+ return {
233
+ next: doneResult
234
+ };
235
+ }
236
+ function doneResult() {
237
+ return {
238
+ value: undefined,
239
+ done: !0
240
+ };
241
+ }
242
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
243
+ value: GeneratorFunctionPrototype,
244
+ configurable: !0
245
+ }), defineProperty(GeneratorFunctionPrototype, "constructor", {
246
+ value: GeneratorFunction,
247
+ configurable: !0
248
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
249
+ var ctor = "function" == typeof genFun && genFun.constructor;
250
+ return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
251
+ }, exports.mark = function (genFun) {
252
+ return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
253
+ }, exports.awrap = function (arg) {
254
+ return {
255
+ __await: arg
256
+ };
257
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
258
+ return this;
259
+ }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
260
+ void 0 === PromiseImpl && (PromiseImpl = Promise);
261
+ var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
262
+ return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
263
+ return result.done ? result.value : iter.next();
264
+ });
265
+ }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
266
+ return this;
267
+ }), define(Gp, "toString", function () {
268
+ return "[object Generator]";
269
+ }), exports.keys = function (val) {
270
+ var object = Object(val),
271
+ keys = [];
272
+ for (var key in object) keys.push(key);
273
+ return keys.reverse(), function next() {
274
+ for (; keys.length;) {
275
+ var key = keys.pop();
276
+ if (key in object) return next.value = key, next.done = !1, next;
277
+ }
278
+ return next.done = !0, next;
279
+ };
280
+ }, exports.values = values, Context.prototype = {
281
+ constructor: Context,
282
+ reset: function (skipTempReset) {
283
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
284
+ },
285
+ stop: function () {
286
+ this.done = !0;
287
+ var rootRecord = this.tryEntries[0].completion;
288
+ if ("throw" === rootRecord.type) throw rootRecord.arg;
289
+ return this.rval;
290
+ },
291
+ dispatchException: function (exception) {
292
+ if (this.done) throw exception;
293
+ var context = this;
294
+ function handle(loc, caught) {
295
+ return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
296
+ }
297
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
298
+ var entry = this.tryEntries[i],
299
+ record = entry.completion;
300
+ if ("root" === entry.tryLoc) return handle("end");
301
+ if (entry.tryLoc <= this.prev) {
302
+ var hasCatch = hasOwn.call(entry, "catchLoc"),
303
+ hasFinally = hasOwn.call(entry, "finallyLoc");
304
+ if (hasCatch && hasFinally) {
305
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
306
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
307
+ } else if (hasCatch) {
308
+ if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
309
+ } else {
310
+ if (!hasFinally) throw new Error("try statement without catch or finally");
311
+ if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
312
+ }
313
+ }
314
+ }
315
+ },
316
+ abrupt: function (type, arg) {
317
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
318
+ var entry = this.tryEntries[i];
319
+ if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
320
+ var finallyEntry = entry;
321
+ break;
322
+ }
323
+ }
324
+ finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
325
+ var record = finallyEntry ? finallyEntry.completion : {};
326
+ return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
327
+ },
328
+ complete: function (record, afterLoc) {
329
+ if ("throw" === record.type) throw record.arg;
330
+ return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
331
+ },
332
+ finish: function (finallyLoc) {
333
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
334
+ var entry = this.tryEntries[i];
335
+ if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
336
+ }
337
+ },
338
+ catch: function (tryLoc) {
339
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
340
+ var entry = this.tryEntries[i];
341
+ if (entry.tryLoc === tryLoc) {
342
+ var record = entry.completion;
343
+ if ("throw" === record.type) {
344
+ var thrown = record.arg;
345
+ resetTryEntry(entry);
346
+ }
347
+ return thrown;
348
+ }
349
+ }
350
+ throw new Error("illegal catch attempt");
351
+ },
352
+ delegateYield: function (iterable, resultName, nextLoc) {
353
+ return this.delegate = {
354
+ iterator: values(iterable),
355
+ resultName: resultName,
356
+ nextLoc: nextLoc
357
+ }, "next" === this.method && (this.arg = undefined), ContinueSentinel;
358
+ }
359
+ }, exports;
360
+ }
361
+
362
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
363
+ try {
364
+ var info = gen[key](arg);
365
+ var value = info.value;
366
+ } catch (error) {
367
+ reject(error);
368
+ return;
369
+ }
370
+ if (info.done) {
371
+ resolve(value);
372
+ } else {
373
+ Promise.resolve(value).then(_next, _throw);
374
+ }
375
+ }
376
+ function _asyncToGenerator(fn) {
377
+ return function () {
378
+ var self = this,
379
+ args = arguments;
380
+ return new Promise(function (resolve, reject) {
381
+ var gen = fn.apply(self, args);
382
+ function _next(value) {
383
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
384
+ }
385
+ function _throw(err) {
386
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
387
+ }
388
+ _next(undefined);
389
+ });
390
+ };
391
+ }
392
+
393
+ function _classCallCheck(instance, Constructor) {
394
+ if (!(instance instanceof Constructor)) {
395
+ throw new TypeError("Cannot call a class as a function");
396
+ }
397
+ }
398
+
399
+ function _defineProperties(target, props) {
400
+ for (var i = 0; i < props.length; i++) {
401
+ var descriptor = props[i];
402
+ descriptor.enumerable = descriptor.enumerable || false;
403
+ descriptor.configurable = true;
404
+ if ("value" in descriptor) descriptor.writable = true;
405
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
406
+ }
407
+ }
408
+ function _createClass(Constructor, protoProps, staticProps) {
409
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
410
+ if (staticProps) _defineProperties(Constructor, staticProps);
411
+ Object.defineProperty(Constructor, "prototype", {
412
+ writable: false
413
+ });
414
+ return Constructor;
415
+ }
416
+
417
+ var ValStore = /*#__PURE__*/function () {
418
+ // uncertain whether this is the optimal way of returning
419
+
420
+ function ValStore(api) {
421
+ var _this = this;
422
+ _classCallCheck(this, ValStore);
423
+ _defineProperty(this, "subscribe", function (moduleIds) {
424
+ return function (listener) {
425
+ var subscriberId = createSubscriberId(moduleIds);
426
+ if (!_this.listeners[subscriberId]) {
427
+ _this.listeners[subscriberId] = [];
428
+ _this.subscribers.set(subscriberId, {});
429
+ }
430
+ _this.listeners[subscriberId].push(listener);
431
+ return function () {
432
+ _this.listeners[subscriberId].splice(_this.listeners[subscriberId].indexOf(listener), 1);
433
+ };
434
+ };
435
+ });
436
+ _defineProperty(this, "getSnapshot", function (moduleIds) {
437
+ return function () {
438
+ console.log("getSnapshot", moduleIds);
439
+ return _this.get(moduleIds);
440
+ };
441
+ });
442
+ _defineProperty(this, "getServerSnapshot", function (moduleIds) {
443
+ return function () {
444
+ console.log("getServerSnapshot", moduleIds);
445
+ return _this.get(moduleIds);
446
+ };
447
+ });
448
+ _defineProperty(this, "get", function (moduleIds) {
449
+ var subscriberId = createSubscriberId(moduleIds);
450
+ return _this.subscribers.get(subscriberId);
451
+ });
452
+ this.api = api;
453
+ this.subscribers = new Map();
454
+ this.listeners = {};
455
+ }
456
+
457
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
458
+ _createClass(ValStore, [{
459
+ key: "update",
460
+ value: function () {
461
+ var _update = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(moduleIds) {
462
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
463
+ while (1) switch (_context.prev = _context.next) {
464
+ case 0:
465
+ return _context.abrupt("return", this.updateAll());
466
+ case 1:
467
+ case "end":
468
+ return _context.stop();
469
+ }
470
+ }, _callee, this);
471
+ }));
472
+ function update(_x) {
473
+ return _update.apply(this, arguments);
474
+ }
475
+ return update;
476
+ }()
477
+ }, {
478
+ key: "updateAll",
479
+ value: function () {
480
+ var _updateAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
481
+ var data, updatedSubscriberIds, subscriberIds, _loop, _i, _arr, _i2, _Array$from, _Array$from$_i, updatedSubscriberId, moduleIds, subscriberModules;
482
+ return _regeneratorRuntime().wrap(function _callee2$(_context3) {
483
+ while (1) switch (_context3.prev = _context3.next) {
484
+ case 0:
485
+ _context3.next = 2;
486
+ return this.api.getModules({
487
+ patch: true,
488
+ includeSource: true
489
+ });
490
+ case 2:
491
+ data = _context3.sent;
492
+ if (!result.isOk(data)) {
493
+ _context3.next = 16;
494
+ break;
495
+ }
496
+ updatedSubscriberIds = new Map();
497
+ subscriberIds = Array.from(this.subscribers.keys()); // Figure out which modules have been updated and map to updated subscribed id
498
+ _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
499
+ var moduleId, source, updatedSubscriberId;
500
+ return _regeneratorRuntime().wrap(function _loop$(_context2) {
501
+ while (1) switch (_context2.prev = _context2.next) {
502
+ case 0:
503
+ moduleId = _arr[_i];
504
+ source = data.value.modules[moduleId].source;
505
+ if (typeof source !== "undefined") {
506
+ updatedSubscriberId = subscriberIds.find(function (subscriberId) {
507
+ return subscriberId.includes(moduleId);
508
+ } // NOTE: dependent on
509
+ );
510
+
511
+ if (updatedSubscriberId) {
512
+ updatedSubscriberIds.set(updatedSubscriberId, (updatedSubscriberIds.get(updatedSubscriberId) || []).concat(moduleId));
513
+ }
514
+ }
515
+ case 3:
516
+ case "end":
517
+ return _context2.stop();
518
+ }
519
+ }, _loop);
520
+ });
521
+ _i = 0, _arr = Object.keys(data.value.modules);
522
+ case 8:
523
+ if (!(_i < _arr.length)) {
524
+ _context3.next = 13;
525
+ break;
526
+ }
527
+ return _context3.delegateYield(_loop(), "t0", 10);
528
+ case 10:
529
+ _i++;
530
+ _context3.next = 8;
531
+ break;
532
+ case 13:
533
+ // For all updated subscribers: set new module data and emit change
534
+ for (_i2 = 0, _Array$from = Array.from(updatedSubscriberIds.entries()); _i2 < _Array$from.length; _i2++) {
535
+ _Array$from$_i = _slicedToArray(_Array$from[_i2], 2), updatedSubscriberId = _Array$from$_i[0], moduleIds = _Array$from$_i[1];
536
+ subscriberModules = Object.fromEntries(moduleIds.flatMap(function (moduleId) {
537
+ var source = data.value.modules[moduleId].source;
538
+ if (!source) {
539
+ return [];
540
+ }
541
+ return [[moduleId, source]];
542
+ }));
543
+ this.subscribers.set(updatedSubscriberId, subscriberModules);
544
+ this.emitChange(updatedSubscriberId);
545
+ }
546
+ _context3.next = 17;
547
+ break;
548
+ case 16:
549
+ console.error("Val: failed to update modules", data.error.message);
550
+ case 17:
551
+ case "end":
552
+ return _context3.stop();
553
+ }
554
+ }, _callee2, this);
555
+ }));
556
+ function updateAll() {
557
+ return _updateAll.apply(this, arguments);
558
+ }
559
+ return updateAll;
560
+ }()
561
+ }, {
562
+ key: "emitChange",
563
+ value: function emitChange(subscriberId) {
564
+ console.log("emitChange");
565
+ var _iterator = _createForOfIteratorHelper(this.listeners[subscriberId]),
566
+ _step;
567
+ try {
568
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
569
+ var listener = _step.value;
570
+ listener();
571
+ }
572
+ } catch (err) {
573
+ _iterator.e(err);
574
+ } finally {
575
+ _iterator.f();
576
+ }
577
+ }
578
+ }]);
579
+ return ValStore;
580
+ }();
581
+ function createSubscriberId(moduleIds) {
582
+ return moduleIds.slice().sort().join("&");
583
+ }
584
+
585
+ /* eslint-disable @typescript-eslint/no-explicit-any */
586
+ function useValStore() {
587
+ return useContext(ValContext).valStore;
588
+ }
589
+ function useValApi() {
590
+ return useContext(ValContext).valApi;
591
+ }
592
+ var ValContext = /*#__PURE__*/React.createContext({
593
+ get valStore() {
594
+ throw Error("Val context not found. Ensure components are wrapped by ValProvider!");
595
+ },
596
+ get valApi() {
597
+ throw Error("Val context not found. Ensure components are wrapped by ValProvider!");
598
+ }
599
+ });
600
+ var ValUI = typeof window !== "undefined" ? /*#__PURE__*/lazy(function () {
601
+ return import('./ValUI-2db816eb.esm.js');
602
+ }) : null;
603
+ function ValProvider(_ref) {
604
+ var _ref$host = _ref.host,
605
+ host = _ref$host === void 0 ? "/api/val" : _ref$host,
606
+ children = _ref.children;
607
+ var valApi = useMemo(function () {
608
+ return new ValApi(host);
609
+ }, [host]);
610
+ var valStore = useMemo(function () {
611
+ return new ValStore(valApi);
612
+ }, [valApi]);
613
+ return /*#__PURE__*/jsxs(ValContext.Provider, {
614
+ value: {
615
+ valApi: valApi,
616
+ valStore: valStore
617
+ },
618
+ children: [children, ValUI && /*#__PURE__*/jsx(ValUI, {})]
619
+ });
620
+ }
621
+
622
+ export { ValProvider as V, useValApi as a, useValStore as u };