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