@valbuild/react 0.20.2 → 0.21.1

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