@valbuild/react 0.13.4 → 0.15.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 (63) hide show
  1. package/README.md +11 -0
  2. package/dist/{ValProvider-07551558.esm.js → ValProvider-2eb6c2f2.esm.js} +3 -33
  3. package/dist/ValProvider-74eef393.cjs.js +7 -0
  4. package/dist/{ValProvider-d8fe7dc4.cjs.prod.js → ValProvider-74eef393.cjs.prod.js} +6 -37
  5. package/dist/{ValProvider-11be7088.browser.esm.js → ValProvider-c677e164.browser.esm.js} +3 -33
  6. package/dist/{ValProvider-50aa4ba8.worker.esm.js → ValProvider-cb5a2161.worker.esm.js} +1 -31
  7. package/dist/{ValProvider-7b9d888e.cjs.dev.js → ValProvider-f647e355.cjs.dev.js} +6 -37
  8. package/dist/{ValUI-5e993a19.cjs.prod.js → ValUI-0c2671a7.cjs.prod.js} +12 -28
  9. package/dist/{ValUI-ac6ae690.cjs.dev.js → ValUI-334ef1d0.cjs.dev.js} +12 -28
  10. package/dist/{ValUI-4844450a.browser.esm.js → ValUI-bb1d1ed6.browser.esm.js} +11 -27
  11. package/dist/{ValUI-599818da.esm.js → ValUI-bf82178a.esm.js} +11 -27
  12. package/dist/declarations/src/ValProvider.d.ts +2 -2
  13. package/dist/declarations/src/ValRichText.d.ts +5 -0
  14. package/dist/declarations/src/ValStore.d.ts +1 -1
  15. package/dist/declarations/src/index.d.ts +3 -2
  16. package/dist/declarations/src/jsx-runtime.d.ts +1 -1
  17. package/dist/declarations/src/stega/autoTagJSX.d.ts +1 -0
  18. package/dist/declarations/src/stega/fetchVal.d.ts +3 -0
  19. package/dist/declarations/src/stega/hooks/useVal.d.ts +3 -0
  20. package/dist/declarations/src/stega/index.d.ts +4 -0
  21. package/dist/declarations/src/stega/stegaEncode.d.ts +24 -0
  22. package/dist/defineProperty-12b5bd29.esm.js +32 -0
  23. package/dist/defineProperty-36ed93cd.cjs.prod.js +35 -0
  24. package/dist/defineProperty-a4bf59bc.worker.esm.js +32 -0
  25. package/dist/defineProperty-c82a49b0.cjs.dev.js +35 -0
  26. package/dist/defineProperty-f319cb47.browser.esm.js +32 -0
  27. package/dist/objectSpread2-30cc2856.browser.esm.js +25 -0
  28. package/dist/objectSpread2-61fbd9a9.cjs.dev.js +27 -0
  29. package/dist/objectSpread2-7b752a35.cjs.prod.js +27 -0
  30. package/dist/objectSpread2-d5a1fe1c.esm.js +25 -0
  31. package/dist/valbuild-react.browser.esm.js +138 -2
  32. package/dist/valbuild-react.cjs.dev.js +142 -1
  33. package/dist/valbuild-react.cjs.prod.js +142 -1
  34. package/dist/valbuild-react.esm.js +138 -2
  35. package/dist/valbuild-react.worker.esm.js +138 -2
  36. package/jsx-dev-runtime/dist/valbuild-react-jsx-dev-runtime.browser.esm.js +2 -2
  37. package/jsx-dev-runtime/dist/valbuild-react-jsx-dev-runtime.cjs.dev.js +5 -5
  38. package/jsx-dev-runtime/dist/valbuild-react-jsx-dev-runtime.cjs.prod.js +5 -5
  39. package/jsx-dev-runtime/dist/valbuild-react-jsx-dev-runtime.esm.js +2 -2
  40. package/jsx-dev-runtime/dist/valbuild-react-jsx-dev-runtime.worker.esm.js +2 -2
  41. package/package.json +15 -5
  42. package/src/ShadowRoot.tsx +8 -4
  43. package/src/ValRichText.tsx +177 -0
  44. package/src/index.ts +2 -3
  45. package/src/stega/autoTagJSX.ts +80 -0
  46. package/src/stega/fetchVal.ts +16 -0
  47. package/src/stega/hooks/useVal.ts +14 -0
  48. package/src/stega/index.ts +5 -0
  49. package/src/stega/stegaEncode.ts +84 -0
  50. package/stega/README.md +3 -0
  51. package/stega/dist/valbuild-react-stega.browser.esm.js +127 -0
  52. package/stega/dist/valbuild-react-stega.cjs.d.ts +2 -0
  53. package/stega/dist/valbuild-react-stega.cjs.d.ts.map +1 -0
  54. package/stega/dist/valbuild-react-stega.cjs.dev.js +139 -0
  55. package/stega/dist/valbuild-react-stega.cjs.js +7 -0
  56. package/stega/dist/valbuild-react-stega.cjs.prod.js +139 -0
  57. package/stega/dist/valbuild-react-stega.esm.js +127 -0
  58. package/stega/dist/valbuild-react-stega.worker.esm.js +148 -0
  59. package/stega/package.json +7 -0
  60. package/dist/ValProvider-d8fe7dc4.cjs.js +0 -7
  61. package/dist/declarations/src/AuthStatus.d.ts +0 -6
  62. package/dist/declarations/src/ShadowRoot.d.ts +0 -4
  63. package/dist/declarations/src/ValUI.d.ts +0 -8
@@ -0,0 +1,177 @@
1
+ import {
2
+ HeadingNode,
3
+ ListItemNode,
4
+ ListNode,
5
+ ParagraphNode,
6
+ RichText,
7
+ SourcePath,
8
+ TextNode,
9
+ } from "@valbuild/core";
10
+ import { createElement } from "react";
11
+ import parse from "style-to-object";
12
+
13
+ export function ValRichText({ children }: { children: RichText }) {
14
+ const root: RichText = children;
15
+ const path = root.valPath;
16
+ return (
17
+ <div data-val-path={path}>
18
+ {root.children.map((child, i) => {
19
+ const childType = child.type;
20
+ const childPath = `${path}.${i}` as SourcePath;
21
+ switch (childType) {
22
+ case "heading":
23
+ return (
24
+ <HeadingNodeComponent
25
+ key={childPath}
26
+ path={childPath}
27
+ node={child}
28
+ />
29
+ );
30
+ case "paragraph":
31
+ return (
32
+ <ParagraphNodeComponent
33
+ key={childPath}
34
+ path={childPath}
35
+ node={child}
36
+ />
37
+ );
38
+ case "list":
39
+ return (
40
+ <ListNodeComponent
41
+ key={childPath}
42
+ path={childPath}
43
+ node={child}
44
+ />
45
+ );
46
+ default:
47
+ throw Error("Unknown root node type: " + childType);
48
+ }
49
+ })}
50
+ </div>
51
+ );
52
+ }
53
+
54
+ function TextNodeComponent({ node }: { node: TextNode }) {
55
+ const styleProps = node.style ? parse(node.style) ?? {} : {};
56
+ // TODO: Ugly! We should do this before serializing instead
57
+ if (styleProps["font-family"]) {
58
+ styleProps["fontFamily"] = styleProps["font-family"];
59
+ delete styleProps["font-family"];
60
+ }
61
+ if (styleProps["font-size"]) {
62
+ styleProps["fontSize"] = styleProps["font-size"];
63
+ delete styleProps["font-size"];
64
+ }
65
+ const bitmask = node.format?.toString(2);
66
+ const bitmaskOffset = bitmask ? bitmask.length - 1 : 0;
67
+ function isBitOne(bit: number) {
68
+ if (!bitmask) {
69
+ return false;
70
+ }
71
+ return (
72
+ bitmask.length >= bitmaskOffset - bit &&
73
+ bitmask[bitmaskOffset - bit] === "1"
74
+ );
75
+ }
76
+ if (isBitOne(0)) {
77
+ styleProps["fontWeight"] = "bold";
78
+ }
79
+ if (isBitOne(1)) {
80
+ styleProps["fontStyle"] = "italic";
81
+ }
82
+ if (isBitOne(2)) {
83
+ if (!styleProps["textDecoration"]) {
84
+ styleProps["textDecoration"] = "line-through";
85
+ } else {
86
+ styleProps["textDecoration"] += " line-through";
87
+ }
88
+ }
89
+ if (isBitOne(3)) {
90
+ if (!styleProps["textDecoration"]) {
91
+ styleProps["textDecoration"] = "underline";
92
+ } else {
93
+ styleProps["textDecoration"] += " underline";
94
+ }
95
+ }
96
+ return <span style={styleProps}>{node.text}</span>;
97
+ }
98
+
99
+ function HeadingNodeComponent({
100
+ node,
101
+ path,
102
+ }: {
103
+ path: SourcePath;
104
+ node: HeadingNode;
105
+ }) {
106
+ return createElement(
107
+ node.tag,
108
+ {},
109
+ node.children.map((child, i) => {
110
+ const childPath = `${path}.${i}` as SourcePath;
111
+ return <TextNodeComponent key={childPath} node={child} />;
112
+ })
113
+ );
114
+ }
115
+
116
+ function ParagraphNodeComponent({
117
+ node,
118
+ path,
119
+ }: {
120
+ path: SourcePath;
121
+ node: ParagraphNode;
122
+ }) {
123
+ return (
124
+ <p>
125
+ {node.children.map((child, i) => {
126
+ const childPath = `${path}.${i}` as SourcePath;
127
+ switch (child.type) {
128
+ case "text":
129
+ return <TextNodeComponent key={childPath} node={child} />;
130
+ default:
131
+ throw Error("Unknown paragraph node type: " + child?.type);
132
+ }
133
+ })}
134
+ </p>
135
+ );
136
+ }
137
+
138
+ function ListNodeComponent({
139
+ node,
140
+ path,
141
+ }: {
142
+ path: SourcePath;
143
+ node: ListNode;
144
+ }) {
145
+ return createElement(
146
+ node.tag,
147
+ {},
148
+ node.children.map((child, i) => {
149
+ const childPath = `${path}.${i}` as SourcePath;
150
+ return (
151
+ <ListItemComponent key={childPath} path={childPath} node={child} />
152
+ );
153
+ })
154
+ );
155
+ }
156
+
157
+ function ListItemComponent({
158
+ node,
159
+ path,
160
+ }: {
161
+ path: SourcePath;
162
+ node: ListItemNode;
163
+ }) {
164
+ return (
165
+ <li>
166
+ {node.children.map((child, i) => {
167
+ const childPath = `${path}.${i}` as SourcePath;
168
+ switch (child.type) {
169
+ case "text":
170
+ return <TextNodeComponent key={childPath} node={child} />;
171
+ default:
172
+ throw Error("Unknown list item node type: " + child?.type);
173
+ }
174
+ })}
175
+ </li>
176
+ );
177
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,4 @@
1
- /* export { useContent } from "./useContent";
2
- export { useText } from "./useText";
3
- export { WithVal } from "./WithVal"; */
1
+ // NOTE: the exports of this file needs to be kept in sync with ValQuickJSRuntime
4
2
  export { ValProvider } from "./ValProvider";
5
3
  export { useVal } from "./hooks/useVal";
4
+ export { ValRichText } from "./ValRichText";
@@ -0,0 +1,80 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import jsxRuntime from "react/jsx-runtime";
3
+ import jsxRuntimeDev from "react/jsx-dev-runtime";
4
+ import React from "react";
5
+ import {
6
+ vercelStegaSplit,
7
+ vercelStegaDecode,
8
+ VERCEL_STEGA_REGEX,
9
+ } from "@vercel/stega";
10
+
11
+ const isIntrinsicElement = (type: any) => {
12
+ // TODO: think this is not correct, but good enough for now?
13
+ return typeof type === "string";
14
+ };
15
+
16
+ const addValPathIfFound = (type: any, props: any) => {
17
+ const valSources: any = [];
18
+
19
+ if (isIntrinsicElement(type) && props && typeof props === "object") {
20
+ for (const [key, value] of Object.entries(props)) {
21
+ if (typeof value === "string" && value.match(VERCEL_STEGA_REGEX)) {
22
+ const encodedBits = vercelStegaDecode(value);
23
+ if (!encodedBits || typeof encodedBits !== "object") continue;
24
+ if (
25
+ "origin" in encodedBits &&
26
+ "data" in encodedBits &&
27
+ typeof encodedBits.data === "object" &&
28
+ encodedBits.data &&
29
+ "valPath" in encodedBits.data
30
+ ) {
31
+ const valPath = encodedBits?.data?.valPath;
32
+ if (valPath) {
33
+ console.log("Found encoded valPath", valPath);
34
+ valSources.push(valPath);
35
+ props[key] = vercelStegaSplit(value).cleaned;
36
+ }
37
+ }
38
+ }
39
+ }
40
+
41
+ if (valSources.length > 0) {
42
+ props["data-val-path"] = valSources.join(",");
43
+ }
44
+ }
45
+ };
46
+
47
+ function WrapJsx<T>(jsx: T): T {
48
+ if (typeof jsx !== "function") return jsx;
49
+
50
+ return function (type: any, props: any, ...rest: any[]) {
51
+ addValPathIfFound(type, props);
52
+ return jsx.call(jsx, type, props, ...rest);
53
+ } as any as T;
54
+ }
55
+
56
+ interface JsxRuntimeModule {
57
+ jsx?(type: any, ...rest: any[]): unknown;
58
+ jsxs?(type: any, ...rest: any[]): unknown;
59
+ jsxDEV?(type: any, ...rest: any[]): unknown;
60
+ }
61
+
62
+ export function autoTagJSX() {
63
+ const JsxPro: JsxRuntimeModule = jsxRuntime;
64
+ const JsxDev: JsxRuntimeModule = jsxRuntimeDev;
65
+
66
+ /**
67
+ * createElement _may_ be called by jsx runtime as a fallback in certain cases,
68
+ * so we need to wrap it regardless.
69
+ *
70
+ * The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't
71
+ * include both, so one of them will be set with `undefined` values.
72
+ */
73
+ React.createElement = WrapJsx(React.createElement);
74
+ JsxDev.jsx && /* */ (JsxDev.jsx = WrapJsx(JsxDev.jsx));
75
+ JsxPro.jsx && /* */ (JsxPro.jsx = WrapJsx(JsxPro.jsx));
76
+ JsxDev.jsxs && /* */ (JsxDev.jsxs = WrapJsx(JsxDev.jsxs));
77
+ JsxPro.jsxs && /* */ (JsxPro.jsxs = WrapJsx(JsxPro.jsxs));
78
+ JsxDev.jsxDEV && /**/ (JsxDev.jsxDEV = WrapJsx(JsxDev.jsxDEV));
79
+ JsxPro.jsxDEV && /**/ (JsxPro.jsxDEV = WrapJsx(JsxPro.jsxDEV));
80
+ }
@@ -0,0 +1,16 @@
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
+ }
@@ -0,0 +1,14 @@
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
+ }
@@ -0,0 +1,5 @@
1
+ // NOTE: the exports of this file needs to be kept in sync with ValQuickJSRuntime
2
+ export { autoTagJSX } from "./autoTagJSX";
3
+ export { fetchVal } from "./fetchVal";
4
+ export { useVal } from "./hooks/useVal";
5
+ export type { ValEncodedString } from "./stegaEncode";
@@ -0,0 +1,84 @@
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
+ }
@@ -0,0 +1,3 @@
1
+ # Val React Stega
2
+
3
+ This package contains Val specific code that utilizes Vercel's steganography lib (stega) to tag strings.
@@ -0,0 +1,127 @@
1
+ import { a as _typeof, _ as _slicedToArray } from '../../dist/slicedToArray-1a246338.browser.esm.js';
2
+ import ReactJSXRuntime__default from 'react/jsx-runtime';
3
+ import jsxRuntimeDev__default from 'react/jsx-dev-runtime';
4
+ import React from 'react';
5
+ import { VERCEL_STEGA_REGEX, vercelStegaDecode, vercelStegaSplit, vercelStegaCombine } from '@vercel/stega';
6
+ import { _ as _objectSpread2 } from '../../dist/objectSpread2-30cc2856.browser.esm.js';
7
+ import { Internal } from '@valbuild/core';
8
+ import { useVal as useVal$1 } from '@valbuild/react';
9
+ import '../../dist/unsupportedIterableToArray-d3087ed5.browser.esm.js';
10
+ import '../../dist/defineProperty-f319cb47.browser.esm.js';
11
+
12
+ var isIntrinsicElement = function isIntrinsicElement(type) {
13
+ // TODO: think this is not correct, but good enough for now?
14
+ return typeof type === "string";
15
+ };
16
+ var addValPathIfFound = function addValPathIfFound(type, props) {
17
+ var valSources = [];
18
+ if (isIntrinsicElement(type) && props && _typeof(props) === "object") {
19
+ for (var _i = 0, _Object$entries = Object.entries(props); _i < _Object$entries.length; _i++) {
20
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
21
+ key = _Object$entries$_i[0],
22
+ value = _Object$entries$_i[1];
23
+ if (typeof value === "string" && value.match(VERCEL_STEGA_REGEX)) {
24
+ var encodedBits = vercelStegaDecode(value);
25
+ if (!encodedBits || _typeof(encodedBits) !== "object") continue;
26
+ if ("origin" in encodedBits && "data" in encodedBits && _typeof(encodedBits.data) === "object" && encodedBits.data && "valPath" in encodedBits.data) {
27
+ var _encodedBits$data;
28
+ var valPath = encodedBits === null || encodedBits === void 0 ? void 0 : (_encodedBits$data = encodedBits.data) === null || _encodedBits$data === void 0 ? void 0 : _encodedBits$data.valPath;
29
+ if (valPath) {
30
+ console.log("Found encoded valPath", valPath);
31
+ valSources.push(valPath);
32
+ props[key] = vercelStegaSplit(value).cleaned;
33
+ }
34
+ }
35
+ }
36
+ }
37
+ if (valSources.length > 0) {
38
+ props["data-val-path"] = valSources.join(",");
39
+ }
40
+ }
41
+ };
42
+ function WrapJsx(jsx) {
43
+ if (typeof jsx !== "function") return jsx;
44
+ return function (type, props) {
45
+ addValPathIfFound(type, props);
46
+ for (var _len = arguments.length, rest = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
47
+ rest[_key - 2] = arguments[_key];
48
+ }
49
+ return jsx.call.apply(jsx, [jsx, type, props].concat(rest));
50
+ };
51
+ }
52
+ function autoTagJSX() {
53
+ var JsxPro = ReactJSXRuntime__default;
54
+ var JsxDev = jsxRuntimeDev__default;
55
+
56
+ /**
57
+ * createElement _may_ be called by jsx runtime as a fallback in certain cases,
58
+ * so we need to wrap it regardless.
59
+ *
60
+ * The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't
61
+ * include both, so one of them will be set with `undefined` values.
62
+ */
63
+ React.createElement = WrapJsx(React.createElement);
64
+ JsxDev.jsx && ( /* */JsxDev.jsx = WrapJsx(JsxDev.jsx));
65
+ JsxPro.jsx && ( /* */JsxPro.jsx = WrapJsx(JsxPro.jsx));
66
+ JsxDev.jsxs && ( /* */JsxDev.jsxs = WrapJsx(JsxDev.jsxs));
67
+ JsxPro.jsxs && ( /* */JsxPro.jsxs = WrapJsx(JsxPro.jsxs));
68
+ JsxDev.jsxDEV && ( /**/JsxDev.jsxDEV = WrapJsx(JsxDev.jsxDEV));
69
+ JsxPro.jsxDEV && ( /**/JsxPro.jsxDEV = WrapJsx(JsxPro.jsxDEV));
70
+ }
71
+
72
+ /**
73
+ * ValEncodedString is a string that is encoded using steganography.
74
+ *
75
+ * This means that there is a hidden / non-visible object embedded in the string.
76
+ * This object includes a path, which is used to automatically tag
77
+ * where the content comes from for contextual editing.
78
+ *
79
+ */
80
+
81
+ function stegaEncodeVal(val) {
82
+ if (_typeof(val.val) === "object") {
83
+ if (Array.isArray(val)) {
84
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
85
+ return val.map(stegaEncodeVal);
86
+ }
87
+ if (_typeof(val.val) === "object" && val.val && "_type" in val.val && val.val["_type"] === "richtext") {
88
+ return _objectSpread2(_objectSpread2({}, val.val), {}, {
89
+ valPath: Internal.getValPath(val)
90
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
91
+ });
92
+ }
93
+
94
+ return Object.fromEntries(Object.entries(val).map(function (_ref) {
95
+ var _ref2 = _slicedToArray(_ref, 2),
96
+ key = _ref2[0],
97
+ value = _ref2[1];
98
+ return [key, stegaEncodeVal(value)];
99
+ }));
100
+ }
101
+ if (typeof val.val === "string") {
102
+ return vercelStegaCombine(val.val, {
103
+ origin: "val.build",
104
+ data: {
105
+ valPath: Internal.getValPath(val)
106
+ }
107
+ }, isDate(val.val) // skip = true if isDate
108
+ );
109
+ }
110
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
111
+ return val.val;
112
+ }
113
+ function isDate(s) {
114
+ return Boolean(Date.parse(s));
115
+ }
116
+
117
+ function fetchVal(selector, locale) {
118
+ return Internal.fetchVal(selector, locale).then(function (val) {
119
+ return stegaEncodeVal(val);
120
+ });
121
+ }
122
+
123
+ function useVal(selector, locale) {
124
+ return stegaEncodeVal(useVal$1(selector, locale));
125
+ }
126
+
127
+ export { autoTagJSX, fetchVal, useVal };
@@ -0,0 +1,2 @@
1
+ export * from "../../dist/declarations/src/stega/index";
2
+ //# sourceMappingURL=valbuild-react-stega.cjs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"valbuild-react-stega.cjs.d.ts","sourceRoot":"","sources":["../../dist/declarations/src/stega/index.d.ts"],"names":[],"mappings":"AAAA"}
@@ -0,0 +1,139 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var slicedToArray = require('../../dist/slicedToArray-b7cf26e0.cjs.dev.js');
6
+ var ReactJSXRuntime = require('react/jsx-runtime');
7
+ var jsxRuntimeDev = require('react/jsx-dev-runtime');
8
+ var React = require('react');
9
+ var stega = require('@vercel/stega');
10
+ var objectSpread2 = require('../../dist/objectSpread2-61fbd9a9.cjs.dev.js');
11
+ var core = require('@valbuild/core');
12
+ var react = require('@valbuild/react');
13
+ require('../../dist/unsupportedIterableToArray-9e97e24a.cjs.dev.js');
14
+ require('../../dist/defineProperty-c82a49b0.cjs.dev.js');
15
+
16
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
17
+
18
+ var ReactJSXRuntime__default = /*#__PURE__*/_interopDefault(ReactJSXRuntime);
19
+ var jsxRuntimeDev__default = /*#__PURE__*/_interopDefault(jsxRuntimeDev);
20
+ var React__default = /*#__PURE__*/_interopDefault(React);
21
+
22
+ var isIntrinsicElement = function isIntrinsicElement(type) {
23
+ // TODO: think this is not correct, but good enough for now?
24
+ return typeof type === "string";
25
+ };
26
+ var addValPathIfFound = function addValPathIfFound(type, props) {
27
+ var valSources = [];
28
+ if (isIntrinsicElement(type) && props && slicedToArray._typeof(props) === "object") {
29
+ for (var _i = 0, _Object$entries = Object.entries(props); _i < _Object$entries.length; _i++) {
30
+ var _Object$entries$_i = slicedToArray._slicedToArray(_Object$entries[_i], 2),
31
+ key = _Object$entries$_i[0],
32
+ value = _Object$entries$_i[1];
33
+ if (typeof value === "string" && value.match(stega.VERCEL_STEGA_REGEX)) {
34
+ var encodedBits = stega.vercelStegaDecode(value);
35
+ if (!encodedBits || slicedToArray._typeof(encodedBits) !== "object") continue;
36
+ if ("origin" in encodedBits && "data" in encodedBits && slicedToArray._typeof(encodedBits.data) === "object" && encodedBits.data && "valPath" in encodedBits.data) {
37
+ var _encodedBits$data;
38
+ var valPath = encodedBits === null || encodedBits === void 0 ? void 0 : (_encodedBits$data = encodedBits.data) === null || _encodedBits$data === void 0 ? void 0 : _encodedBits$data.valPath;
39
+ if (valPath) {
40
+ console.log("Found encoded valPath", valPath);
41
+ valSources.push(valPath);
42
+ props[key] = stega.vercelStegaSplit(value).cleaned;
43
+ }
44
+ }
45
+ }
46
+ }
47
+ if (valSources.length > 0) {
48
+ props["data-val-path"] = valSources.join(",");
49
+ }
50
+ }
51
+ };
52
+ function WrapJsx(jsx) {
53
+ if (typeof jsx !== "function") return jsx;
54
+ return function (type, props) {
55
+ addValPathIfFound(type, props);
56
+ for (var _len = arguments.length, rest = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
57
+ rest[_key - 2] = arguments[_key];
58
+ }
59
+ return jsx.call.apply(jsx, [jsx, type, props].concat(rest));
60
+ };
61
+ }
62
+ function autoTagJSX() {
63
+ var JsxPro = ReactJSXRuntime__default["default"];
64
+ var JsxDev = jsxRuntimeDev__default["default"];
65
+
66
+ /**
67
+ * createElement _may_ be called by jsx runtime as a fallback in certain cases,
68
+ * so we need to wrap it regardless.
69
+ *
70
+ * The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't
71
+ * include both, so one of them will be set with `undefined` values.
72
+ */
73
+ React__default["default"].createElement = WrapJsx(React__default["default"].createElement);
74
+ JsxDev.jsx && ( /* */JsxDev.jsx = WrapJsx(JsxDev.jsx));
75
+ JsxPro.jsx && ( /* */JsxPro.jsx = WrapJsx(JsxPro.jsx));
76
+ JsxDev.jsxs && ( /* */JsxDev.jsxs = WrapJsx(JsxDev.jsxs));
77
+ JsxPro.jsxs && ( /* */JsxPro.jsxs = WrapJsx(JsxPro.jsxs));
78
+ JsxDev.jsxDEV && ( /**/JsxDev.jsxDEV = WrapJsx(JsxDev.jsxDEV));
79
+ JsxPro.jsxDEV && ( /**/JsxPro.jsxDEV = WrapJsx(JsxPro.jsxDEV));
80
+ }
81
+
82
+ /**
83
+ * ValEncodedString is a string that is encoded using steganography.
84
+ *
85
+ * This means that there is a hidden / non-visible object embedded in the string.
86
+ * This object includes a path, which is used to automatically tag
87
+ * where the content comes from for contextual editing.
88
+ *
89
+ */
90
+
91
+ function stegaEncodeVal(val) {
92
+ if (slicedToArray._typeof(val.val) === "object") {
93
+ if (Array.isArray(val)) {
94
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
95
+ return val.map(stegaEncodeVal);
96
+ }
97
+ if (slicedToArray._typeof(val.val) === "object" && val.val && "_type" in val.val && val.val["_type"] === "richtext") {
98
+ return objectSpread2._objectSpread2(objectSpread2._objectSpread2({}, val.val), {}, {
99
+ valPath: core.Internal.getValPath(val)
100
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
101
+ });
102
+ }
103
+
104
+ return Object.fromEntries(Object.entries(val).map(function (_ref) {
105
+ var _ref2 = slicedToArray._slicedToArray(_ref, 2),
106
+ key = _ref2[0],
107
+ value = _ref2[1];
108
+ return [key, stegaEncodeVal(value)];
109
+ }));
110
+ }
111
+ if (typeof val.val === "string") {
112
+ return stega.vercelStegaCombine(val.val, {
113
+ origin: "val.build",
114
+ data: {
115
+ valPath: core.Internal.getValPath(val)
116
+ }
117
+ }, isDate(val.val) // skip = true if isDate
118
+ );
119
+ }
120
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
121
+ return val.val;
122
+ }
123
+ function isDate(s) {
124
+ return Boolean(Date.parse(s));
125
+ }
126
+
127
+ function fetchVal(selector, locale) {
128
+ return core.Internal.fetchVal(selector, locale).then(function (val) {
129
+ return stegaEncodeVal(val);
130
+ });
131
+ }
132
+
133
+ function useVal(selector, locale) {
134
+ return stegaEncodeVal(react.useVal(selector, locale));
135
+ }
136
+
137
+ exports.autoTagJSX = autoTagJSX;
138
+ exports.fetchVal = fetchVal;
139
+ exports.useVal = useVal;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./valbuild-react-stega.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./valbuild-react-stega.cjs.dev.js");
7
+ }