@valbuild/react 0.16.0 → 0.17.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
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var slicedToArray = require('../../dist/slicedToArray-0eb0bcdb.cjs.prod.js');
5
+ var _typeof = require('../../dist/typeof-16c77f45.cjs.prod.js');
6
+ var slicedToArray = require('../../dist/slicedToArray-5bddfa58.cjs.prod.js');
6
7
  var core = require('@valbuild/core');
7
8
  var jsxRuntimeDev = require('react/jsx-dev-runtime');
8
- require('../../dist/unsupportedIterableToArray-afbea1dd.cjs.prod.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);
@@ -1,8 +1,8 @@
1
- import { _ as _slicedToArray, a as _typeof } from '../../dist/slicedToArray-d846e1d2.esm.js';
1
+ import { _ as _typeof } from '../../dist/typeof-5c86a240.esm.js';
2
+ import { a as _slicedToArray } from '../../dist/slicedToArray-b4fb91fa.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-51bb61c2.esm.js';
6
6
 
7
7
  var isIntrinsicElement = function isIntrinsicElement(type) {
8
8
  // TODO: think this is not correct, but good enough for now?
@@ -1,8 +1,8 @@
1
- import { _ as _slicedToArray, a as _typeof } from '../../dist/slicedToArray-9e7d1407.worker.esm.js';
1
+ import { _ as _typeof } from '../../dist/typeof-8854ace1.worker.esm.js';
2
+ import { a as _slicedToArray } from '../../dist/slicedToArray-5a51fd33.worker.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-738344ef.worker.esm.js';
6
6
 
7
7
  var isIntrinsicElement = function isIntrinsicElement(type) {
8
8
  // TODO: think this is not correct, but good enough for now?
@@ -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 ReactJSXRuntime from 'react/jsx-runtime';
4
5
  export * from 'react/jsx-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 ReactJSXRuntime = require('react/jsx-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);
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var slicedToArray = require('../../dist/slicedToArray-0eb0bcdb.cjs.prod.js');
5
+ var _typeof = require('../../dist/typeof-16c77f45.cjs.prod.js');
6
+ var slicedToArray = require('../../dist/slicedToArray-5bddfa58.cjs.prod.js');
6
7
  var core = require('@valbuild/core');
7
8
  var ReactJSXRuntime = require('react/jsx-runtime');
8
- require('../../dist/unsupportedIterableToArray-afbea1dd.cjs.prod.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);
@@ -1,8 +1,8 @@
1
- import { _ as _slicedToArray, a as _typeof } from '../../dist/slicedToArray-d846e1d2.esm.js';
1
+ import { _ as _typeof } from '../../dist/typeof-5c86a240.esm.js';
2
+ import { a as _slicedToArray } from '../../dist/slicedToArray-b4fb91fa.esm.js';
2
3
  import { Internal } from '@valbuild/core';
3
4
  import * as ReactJSXRuntime from 'react/jsx-runtime';
4
5
  export * from 'react/jsx-runtime';
5
- import '../../dist/unsupportedIterableToArray-51bb61c2.esm.js';
6
6
 
7
7
  var isIntrinsicElement = function isIntrinsicElement(type) {
8
8
  // TODO: think this is not correct, but good enough for now?
@@ -1,8 +1,8 @@
1
- import { _ as _slicedToArray, a as _typeof } from '../../dist/slicedToArray-9e7d1407.worker.esm.js';
1
+ import { _ as _typeof } from '../../dist/typeof-8854ace1.worker.esm.js';
2
+ import { a as _slicedToArray } from '../../dist/slicedToArray-5a51fd33.worker.esm.js';
2
3
  import { Internal } from '@valbuild/core';
3
4
  import * as ReactJSXRuntime from 'react/jsx-runtime';
4
5
  export * from 'react/jsx-runtime';
5
- import '../../dist/unsupportedIterableToArray-738344ef.worker.esm.js';
6
6
 
7
7
  var isIntrinsicElement = function isIntrinsicElement(type) {
8
8
  // TODO: think this is not correct, but good enough for now?
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valbuild/react",
3
- "version": "0.16.0",
3
+ "version": "0.17.0",
4
4
  "private": false,
5
5
  "description": "Val - React internal helpers",
6
6
  "sideEffects": false,
@@ -9,8 +9,8 @@
9
9
  "test": "jest"
10
10
  },
11
11
  "dependencies": {
12
- "@valbuild/core": "~0.16.0",
13
- "@valbuild/ui": "~0.15.0",
12
+ "@valbuild/core": "~0.17.0",
13
+ "@valbuild/ui": "~0.17.0",
14
14
  "@vercel/stega": "^0.1.0",
15
15
  "base64-arraybuffer": "^1.0.2",
16
16
  "style-to-object": "^0.4.1"
@@ -1,8 +1,7 @@
1
- "use client";
2
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
3
2
  import React, { lazy, useContext, useMemo } from "react";
4
- import { ValApi } from "./ValApi";
5
3
  import { ValStore } from "./ValStore";
4
+ import { ValApi } from "@valbuild/core";
6
5
 
7
6
  export function useValStore() {
8
7
  return useContext(ValContext).valStore;
@@ -42,7 +41,7 @@ export function ValProvider({ host = "/api/val", children }: ValProviderProps) {
42
41
  return (
43
42
  <ValContext.Provider value={{ valApi, valStore }}>
44
43
  {children}
45
- {ValUI && <ValUI valApi={valApi} valStore={valStore} />}
44
+ {ValUI && <ValUI />}
46
45
  </ValContext.Provider>
47
46
  );
48
47
  }
package/src/ValStore.ts CHANGED
@@ -1,62 +1,112 @@
1
- import { ValModule, SelectorSource } from "@valbuild/core";
2
- import { ValApi } from "./ValApi";
1
+ import { Json, ModuleId, ValApi } from "@valbuild/core";
2
+ import { result } from "@valbuild/core/fp";
3
+
4
+ type SubscriberId = string & {
5
+ readonly _tag: unique symbol;
6
+ };
3
7
 
4
8
  export class ValStore {
5
- private readonly vals: Map<string, ValModule<SelectorSource>>;
6
- private readonly listeners: { [moduleId: string]: (() => void)[] };
9
+ private readonly subscribers: Map<SubscriberId, Record<ModuleId, Json>>; // uncertain whether this is the optimal way of returning
10
+ private readonly listeners: Record<SubscriberId, (() => void)[]>;
7
11
 
8
12
  constructor(private readonly api: ValApi) {
9
- this.vals = new Map();
13
+ this.subscribers = new Map();
10
14
  this.listeners = {};
11
15
  }
12
16
 
13
- async updateAll() {
14
- await Promise.all(
15
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
16
- Object.keys(this.listeners).map(async (moduleId) => {
17
- // this.set(
18
- // moduleId,
19
- // await this.api.getModule(moduleId)
20
- // // ModuleContent.deserialize(await this.api.getModule(moduleId))
21
- // );
22
- })
23
- );
17
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
18
+ async update(moduleIds: ModuleId[]) {
19
+ // TODO: update only the modules that have changed
20
+ return this.updateAll();
24
21
  }
25
22
 
26
- subscribe = (moduleId: string) => (listener: () => void) => {
27
- const listeners = (this.listeners[moduleId] =
28
- moduleId in this.listeners ? this.listeners[moduleId] : []);
29
- listeners.push(listener);
30
- return () => {
31
- listeners.splice(listeners.indexOf(listener), 1);
32
- if (listeners.length === 0) {
33
- delete this.listeners[moduleId];
23
+ async updateAll() {
24
+ const data = await this.api.getModules({
25
+ patch: true,
26
+ includeSource: true,
27
+ });
28
+ if (result.isOk(data)) {
29
+ const updatedSubscriberIds = new Map<SubscriberId, ModuleId[]>();
30
+ const subscriberIds = Array.from(this.subscribers.keys());
31
+
32
+ // Figure out which modules have been updated and map to updated subscribed id
33
+ for (const moduleId of Object.keys(data.value.modules) as ModuleId[]) {
34
+ const source = data.value.modules[moduleId].source;
35
+ if (typeof source !== "undefined") {
36
+ const updatedSubscriberId = subscriberIds.find(
37
+ (subscriberId) => subscriberId.includes(moduleId) // NOTE: dependent on
38
+ );
39
+ if (updatedSubscriberId) {
40
+ updatedSubscriberIds.set(
41
+ updatedSubscriberId,
42
+ (updatedSubscriberIds.get(updatedSubscriberId) || []).concat(
43
+ moduleId
44
+ )
45
+ );
46
+ }
47
+ }
34
48
  }
35
- };
36
- };
37
49
 
38
- set(moduleId: string, val: ValModule<SelectorSource>) {
39
- this.vals.set(moduleId, val);
40
- this.emitChange(moduleId);
50
+ // For all updated subscribers: set new module data and emit change
51
+ for (const [updatedSubscriberId, moduleIds] of Array.from(
52
+ updatedSubscriberIds.entries()
53
+ )) {
54
+ const subscriberModules = Object.fromEntries(
55
+ moduleIds.flatMap((moduleId) => {
56
+ const source = data.value.modules[moduleId].source;
57
+ if (!source) {
58
+ return [];
59
+ }
60
+ return [[moduleId, source]];
61
+ })
62
+ );
63
+ this.subscribers.set(updatedSubscriberId, subscriberModules);
64
+ this.emitChange(updatedSubscriberId);
65
+ }
66
+ } else {
67
+ console.error("Val: failed to update modules", data.error.message);
68
+ }
41
69
  }
42
70
 
43
- get(moduleId: string) {
44
- return this.vals.get(moduleId);
45
- }
71
+ subscribe = (moduleIds: ModuleId[]) => (listener: () => void) => {
72
+ const subscriberId = createSubscriberId(moduleIds);
73
+ if (!this.listeners[subscriberId]) {
74
+ this.listeners[subscriberId] = [];
75
+ this.subscribers.set(subscriberId, {});
76
+ }
77
+ this.listeners[subscriberId].push(listener);
78
+
79
+ return () => {
80
+ this.listeners[subscriberId].splice(
81
+ this.listeners[subscriberId].indexOf(listener),
82
+ 1
83
+ );
84
+ };
85
+ };
46
86
 
47
- emitChange(moduleId: string) {
48
- const listeners = this.listeners[moduleId];
49
- if (typeof listeners === "undefined") return;
50
- for (const listener of listeners) {
87
+ private emitChange(subscriberId: SubscriberId) {
88
+ console.log("emitChange");
89
+ for (const listener of this.listeners[subscriberId]) {
51
90
  listener();
52
91
  }
53
92
  }
54
93
 
55
- getSnapshot = (moduleId: string) => () => {
56
- return this.vals.get(moduleId);
94
+ getSnapshot = (moduleIds: ModuleId[]) => () => {
95
+ console.log("getSnapshot", moduleIds);
96
+ return this.get(moduleIds);
57
97
  };
58
98
 
59
- getServerSnapshot = (moduleId: string) => () => {
60
- return this.vals.get(moduleId);
99
+ getServerSnapshot = (moduleIds: ModuleId[]) => () => {
100
+ console.log("getServerSnapshot", moduleIds);
101
+ return this.get(moduleIds);
61
102
  };
103
+
104
+ get = (moduleIds: ModuleId[]): Record<ModuleId, Json> | undefined => {
105
+ const subscriberId = createSubscriberId(moduleIds);
106
+ return this.subscribers.get(subscriberId);
107
+ };
108
+ }
109
+
110
+ function createSubscriberId(moduleIds: ModuleId[]): SubscriberId {
111
+ return moduleIds.slice().sort().join("&") as SubscriberId;
62
112
  }