@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
package/src/ValApi.ts DELETED
@@ -1,65 +0,0 @@
1
- import { SerializedModule } from "@valbuild/core";
2
- import { PatchJSON } from "@valbuild/core/patch";
3
-
4
- export class ValApi {
5
- constructor(readonly host: string) {}
6
-
7
- async getModule(sourcePath: string): Promise<SerializedModule> {
8
- const res = await fetch(`${this.host}/ids${sourcePath}`);
9
- if (res.ok) {
10
- const serializedVal = await res.json(); // TODO: validate
11
- return serializedVal;
12
- } else {
13
- throw Error(
14
- `Failed to get content of module "${sourcePath}". Status: ${
15
- res.status
16
- }. Error: ${await res.text()}`
17
- );
18
- }
19
- }
20
-
21
- async patchModuleContent(
22
- moduleId: string,
23
- patch: PatchJSON
24
- ): Promise<SerializedModule> {
25
- const res = await fetch(`${this.host}/ids${moduleId}`, {
26
- method: "PATCH",
27
- headers: {
28
- "Content-Type": "application/json-patch+json",
29
- },
30
- body: JSON.stringify(patch),
31
- });
32
- if (res.ok) {
33
- return res.json(); // TODO: validate
34
- } else {
35
- throw Error(
36
- `Failed to patch content of module "${moduleId}". Error: ${await res.text()}`
37
- );
38
- }
39
- }
40
-
41
- async commit(): Promise<void> {
42
- const res = await fetch(`${this.host}/commit`, {
43
- method: "POST",
44
- });
45
- if (res.ok) {
46
- return;
47
- } else {
48
- throw Error(`Failed to commit. Error: ${await res.text()}`);
49
- }
50
- }
51
-
52
- getSession() {
53
- return fetch(`${this.host}/session`);
54
- }
55
-
56
- loginUrl() {
57
- return `${this.host}/authorize?redirect_to=${encodeURIComponent(
58
- location.href
59
- )}`;
60
- }
61
-
62
- logout() {
63
- return fetch(`${this.host}/logout`);
64
- }
65
- }
@@ -1,57 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- import { useVal } from "./useVal";
3
- import { initVal, Val } from "@valbuild/core";
4
- import { renderHook } from "@testing-library/react";
5
- import { ValContext } from "../ValProvider";
6
- import { ReactElement } from "react";
7
- import { ValStore } from "../ValStore";
8
- import { ValApi } from "../ValApi";
9
-
10
- const valApi = new ValApi("mock");
11
- const valStore = new ValStore(valApi);
12
-
13
- const Providers = ({ children }: { children: ReactElement }) => (
14
- <ValContext.Provider
15
- value={{
16
- valStore,
17
- valApi,
18
- }}
19
- >
20
- {children}
21
- </ValContext.Provider>
22
- );
23
-
24
- // const { s, val } = initVal();
25
-
26
- describe("useVal", () => {
27
- test.skip("extracts ValString from string", () => {
28
- // const mod = val.content("foo", s.string(), "bar");
29
- // const { result } = renderHook(() => useVal(mod, "en_US"), {
30
- // wrapper: Providers,
31
- // });
32
- // expect(result.current).toStrictEqual<Val<string>>({
33
- // val: "bar",
34
- // valSrc: "foo?en_US?",
35
- // });
36
- });
37
-
38
- test.skip("extracts ValString from ValObject", () => {
39
- // const mod = val.content("baz", s.object({ foo: s.string() }), {
40
- // foo: "bar",
41
- // });
42
- // const { result } = renderHook(() => useVal(mod, "en_US"), {
43
- // wrapper: Providers,
44
- // });
45
- // const vo: Val<{ foo: string }> = result.current;
46
- // expect(vo.foo).toStrictEqual<Val<string>>({
47
- // valSrc: `baz?en_US?."foo"`,
48
- // val: "bar",
49
- // });
50
- // expect(val).toStrictEqual<ValObject<{ foo: string }>>({
51
- // foo: {
52
- // id: "baz.foo",
53
- // val: "bar",
54
- // },
55
- // });
56
- });
57
- });
@@ -1,35 +0,0 @@
1
- import {
2
- SelectorSource,
3
- SelectorOf,
4
- GenericSelector,
5
- Val,
6
- Internal,
7
- } from "@valbuild/core";
8
- import { JsonOfSource } from "@valbuild/core/src/val";
9
-
10
- export function useVal<T extends SelectorSource>(
11
- selector: T,
12
- locale?: string
13
- ): SelectorOf<T> extends GenericSelector<infer S>
14
- ? Val<JsonOfSource<S>>
15
- : never {
16
- // const mod = selectable.getModule();
17
- // const valStore = useValStore();
18
- // const remoteContent = useSyncExternalStore(
19
- // valStore.subscribe(mod.id),
20
- // valStore.getSnapshot(mod.id),
21
- // valStore.getServerSnapshot(mod.id)
22
- // );
23
- // if (remoteContent) {
24
- // return selectable.getVal(remoteContent.source as S, locale);
25
- // }
26
- // const content = mod.content;
27
- // const validationError = content.validate();
28
- // if (validationError) {
29
- // throw new Error(
30
- // `Invalid source value. Errors:\n${validationError.join("\n")}`
31
- // );
32
- // }
33
-
34
- return Internal.getVal(selector, locale);
35
- }
@@ -1,16 +0,0 @@
1
- import { SelectorSource, SelectorOf, GenericSelector } from "@valbuild/core";
2
- import { stegaEncodeVal, StegaOfSource } from "./stegaEncode";
3
- import { Internal } from "@valbuild/core";
4
-
5
- export function fetchVal<T extends SelectorSource>(
6
- selector: T,
7
- locale?: string
8
- ): SelectorOf<T> extends GenericSelector<infer S>
9
- ? Promise<StegaOfSource<S>>
10
- : never {
11
- return Internal.fetchVal(selector, locale).then((val) =>
12
- stegaEncodeVal(val)
13
- ) as SelectorOf<T> extends GenericSelector<infer S>
14
- ? Promise<StegaOfSource<S>>
15
- : never;
16
- }
@@ -1,14 +0,0 @@
1
- import { GenericSelector, SelectorOf, SelectorSource } from "@valbuild/core";
2
- import { useVal as useReactVal } from "@valbuild/react";
3
- import { stegaEncodeVal, StegaOfSource } from "../stegaEncode";
4
-
5
- export function useVal<T extends SelectorSource>(
6
- selector: T,
7
- locale?: string
8
- ): SelectorOf<T> extends GenericSelector<infer S> ? StegaOfSource<S> : never {
9
- return stegaEncodeVal(
10
- useReactVal(selector, locale)
11
- ) as SelectorOf<T> extends GenericSelector<infer S>
12
- ? StegaOfSource<S>
13
- : never;
14
- }
@@ -1,84 +0,0 @@
1
- import { Json, Val, Internal, RichTextSource, RichText } from "@valbuild/core";
2
- import { vercelStegaCombine } from "@vercel/stega";
3
- import { FileSource, RemoteSource, Source, SourceObject } from "@valbuild/core";
4
- import { JsonPrimitive } from "@valbuild/core";
5
- import { SourceArray } from "@valbuild/core";
6
- import { I18nSource } from "@valbuild/core";
7
-
8
- declare const brand: unique symbol;
9
-
10
- /**
11
- * ValEncodedString is a string that is encoded using steganography.
12
- *
13
- * This means that there is a hidden / non-visible object embedded in the string.
14
- * This object includes a path, which is used to automatically tag
15
- * where the content comes from for contextual editing.
16
- *
17
- */
18
- export type ValEncodedString = string & {
19
- [brand]: "ValEncodedString";
20
- };
21
-
22
- export type StegaOfSource<T extends Source> = Json extends T
23
- ? Json
24
- : T extends I18nSource<readonly string[], infer U>
25
- ? StegaOfSource<U>
26
- : T extends RemoteSource<infer U>
27
- ? StegaOfSource<U>
28
- : T extends RichTextSource
29
- ? RichText
30
- : T extends FileSource
31
- ? { url: ValEncodedString }
32
- : T extends SourceObject
33
- ? {
34
- [key in keyof T]: StegaOfSource<T[key]>;
35
- }
36
- : T extends SourceArray
37
- ? StegaOfSource<T[number]>[]
38
- : T extends string
39
- ? ValEncodedString
40
- : T extends JsonPrimitive
41
- ? T
42
- : never;
43
-
44
- export function stegaEncodeVal<T extends Json>(val: Val<T>): T {
45
- if (typeof val.val === "object") {
46
- if (Array.isArray(val)) {
47
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
48
- return val.map(stegaEncodeVal) as any;
49
- }
50
-
51
- if (
52
- typeof val.val === "object" &&
53
- val.val &&
54
- "_type" in val.val &&
55
- val.val["_type"] === "richtext"
56
- ) {
57
- return {
58
- ...val.val,
59
- valPath: Internal.getValPath(val),
60
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
- } as any;
62
- }
63
-
64
- return Object.fromEntries(
65
- Object.entries(val).map(([key, value]) => [key, stegaEncodeVal(value)])
66
- ) as T;
67
- }
68
- if (typeof val.val === "string") {
69
- return vercelStegaCombine(
70
- val.val,
71
- {
72
- origin: "val.build",
73
- data: { valPath: Internal.getValPath(val) },
74
- },
75
- isDate(val.val) // skip = true if isDate
76
- ) as T;
77
- }
78
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
79
- return val.val as any;
80
- }
81
-
82
- function isDate(s: string) {
83
- return Boolean(Date.parse(s));
84
- }