@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
@@ -1,2 +1,3 @@
1
- export { ValProvider } from "./ValProvider";
2
- export { useVal } from "./hooks/useVal";
1
+ export { ValProvider } from "./ValProvider.js";
2
+ export { useVal } from "./hooks/useVal.js";
3
+ export { ValRichText } from "./ValRichText.js";
@@ -1 +1 @@
1
- export { ValJSX as JSX } from "./jsx-namespace";
1
+ export { ValJSX as JSX } from "./jsx-namespace.js";
@@ -0,0 +1 @@
1
+ export declare function autoTagJSX(): void;
@@ -0,0 +1,3 @@
1
+ import { SelectorSource, SelectorOf, GenericSelector } from "@valbuild/core";
2
+ import { StegaOfSource } from "./stegaEncode.js";
3
+ export declare function fetchVal<T extends SelectorSource>(selector: T, locale?: string): SelectorOf<T> extends GenericSelector<infer S> ? Promise<StegaOfSource<S>> : never;
@@ -0,0 +1,3 @@
1
+ import { GenericSelector, SelectorOf, SelectorSource } from "@valbuild/core";
2
+ import { StegaOfSource } from "../stegaEncode.js";
3
+ export declare function useVal<T extends SelectorSource>(selector: T, locale?: string): SelectorOf<T> extends GenericSelector<infer S> ? StegaOfSource<S> : never;
@@ -0,0 +1,4 @@
1
+ export { autoTagJSX } from "./autoTagJSX.js";
2
+ export { fetchVal } from "./fetchVal.js";
3
+ export { useVal } from "./hooks/useVal.js";
4
+ export type { ValEncodedString } from "./stegaEncode.js";
@@ -0,0 +1,24 @@
1
+ import { Json, Val, RichTextSource, RichText } from "@valbuild/core";
2
+ import { FileSource, RemoteSource, Source, SourceObject } from "@valbuild/core";
3
+ import { JsonPrimitive } from "@valbuild/core";
4
+ import { SourceArray } from "@valbuild/core";
5
+ import { I18nSource } from "@valbuild/core";
6
+ declare const brand: unique symbol;
7
+ /**
8
+ * ValEncodedString is a string that is encoded using steganography.
9
+ *
10
+ * This means that there is a hidden / non-visible object embedded in the string.
11
+ * This object includes a path, which is used to automatically tag
12
+ * where the content comes from for contextual editing.
13
+ *
14
+ */
15
+ export type ValEncodedString = string & {
16
+ [brand]: "ValEncodedString";
17
+ };
18
+ export type StegaOfSource<T extends Source> = Json extends T ? Json : T extends I18nSource<readonly string[], infer U> ? StegaOfSource<U> : T extends RemoteSource<infer U> ? StegaOfSource<U> : T extends RichTextSource ? RichText : T extends FileSource ? {
19
+ url: ValEncodedString;
20
+ } : T extends SourceObject ? {
21
+ [key in keyof T]: StegaOfSource<T[key]>;
22
+ } : T extends SourceArray ? StegaOfSource<T[number]>[] : T extends string ? ValEncodedString : T extends JsonPrimitive ? T : never;
23
+ export declare function stegaEncodeVal<T extends Json>(val: Val<T>): T;
24
+ export {};
@@ -0,0 +1,32 @@
1
+ function _toPrimitive(input, hint) {
2
+ if (typeof input !== "object" || input === null) return input;
3
+ var prim = input[Symbol.toPrimitive];
4
+ if (prim !== undefined) {
5
+ var res = prim.call(input, hint || "default");
6
+ if (typeof res !== "object") return res;
7
+ throw new TypeError("@@toPrimitive must return a primitive value.");
8
+ }
9
+ return (hint === "string" ? String : Number)(input);
10
+ }
11
+
12
+ function _toPropertyKey(arg) {
13
+ var key = _toPrimitive(arg, "string");
14
+ return typeof key === "symbol" ? key : String(key);
15
+ }
16
+
17
+ function _defineProperty(obj, key, value) {
18
+ key = _toPropertyKey(key);
19
+ if (key in obj) {
20
+ Object.defineProperty(obj, key, {
21
+ value: value,
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true
25
+ });
26
+ } else {
27
+ obj[key] = value;
28
+ }
29
+ return obj;
30
+ }
31
+
32
+ export { _defineProperty as _, _toPropertyKey as a };
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ function _toPrimitive(input, hint) {
4
+ if (typeof input !== "object" || input === null) return input;
5
+ var prim = input[Symbol.toPrimitive];
6
+ if (prim !== undefined) {
7
+ var res = prim.call(input, hint || "default");
8
+ if (typeof res !== "object") return res;
9
+ throw new TypeError("@@toPrimitive must return a primitive value.");
10
+ }
11
+ return (hint === "string" ? String : Number)(input);
12
+ }
13
+
14
+ function _toPropertyKey(arg) {
15
+ var key = _toPrimitive(arg, "string");
16
+ return typeof key === "symbol" ? key : String(key);
17
+ }
18
+
19
+ function _defineProperty(obj, key, value) {
20
+ key = _toPropertyKey(key);
21
+ if (key in obj) {
22
+ Object.defineProperty(obj, key, {
23
+ value: value,
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true
27
+ });
28
+ } else {
29
+ obj[key] = value;
30
+ }
31
+ return obj;
32
+ }
33
+
34
+ exports._defineProperty = _defineProperty;
35
+ exports._toPropertyKey = _toPropertyKey;
@@ -0,0 +1,32 @@
1
+ function _toPrimitive(input, hint) {
2
+ if (typeof input !== "object" || input === null) return input;
3
+ var prim = input[Symbol.toPrimitive];
4
+ if (prim !== undefined) {
5
+ var res = prim.call(input, hint || "default");
6
+ if (typeof res !== "object") return res;
7
+ throw new TypeError("@@toPrimitive must return a primitive value.");
8
+ }
9
+ return (hint === "string" ? String : Number)(input);
10
+ }
11
+
12
+ function _toPropertyKey(arg) {
13
+ var key = _toPrimitive(arg, "string");
14
+ return typeof key === "symbol" ? key : String(key);
15
+ }
16
+
17
+ function _defineProperty(obj, key, value) {
18
+ key = _toPropertyKey(key);
19
+ if (key in obj) {
20
+ Object.defineProperty(obj, key, {
21
+ value: value,
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true
25
+ });
26
+ } else {
27
+ obj[key] = value;
28
+ }
29
+ return obj;
30
+ }
31
+
32
+ export { _defineProperty as _, _toPropertyKey as a };
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ function _toPrimitive(input, hint) {
4
+ if (typeof input !== "object" || input === null) return input;
5
+ var prim = input[Symbol.toPrimitive];
6
+ if (prim !== undefined) {
7
+ var res = prim.call(input, hint || "default");
8
+ if (typeof res !== "object") return res;
9
+ throw new TypeError("@@toPrimitive must return a primitive value.");
10
+ }
11
+ return (hint === "string" ? String : Number)(input);
12
+ }
13
+
14
+ function _toPropertyKey(arg) {
15
+ var key = _toPrimitive(arg, "string");
16
+ return typeof key === "symbol" ? key : String(key);
17
+ }
18
+
19
+ function _defineProperty(obj, key, value) {
20
+ key = _toPropertyKey(key);
21
+ if (key in obj) {
22
+ Object.defineProperty(obj, key, {
23
+ value: value,
24
+ enumerable: true,
25
+ configurable: true,
26
+ writable: true
27
+ });
28
+ } else {
29
+ obj[key] = value;
30
+ }
31
+ return obj;
32
+ }
33
+
34
+ exports._defineProperty = _defineProperty;
35
+ exports._toPropertyKey = _toPropertyKey;
@@ -0,0 +1,32 @@
1
+ function _toPrimitive(input, hint) {
2
+ if (typeof input !== "object" || input === null) return input;
3
+ var prim = input[Symbol.toPrimitive];
4
+ if (prim !== undefined) {
5
+ var res = prim.call(input, hint || "default");
6
+ if (typeof res !== "object") return res;
7
+ throw new TypeError("@@toPrimitive must return a primitive value.");
8
+ }
9
+ return (hint === "string" ? String : Number)(input);
10
+ }
11
+
12
+ function _toPropertyKey(arg) {
13
+ var key = _toPrimitive(arg, "string");
14
+ return typeof key === "symbol" ? key : String(key);
15
+ }
16
+
17
+ function _defineProperty(obj, key, value) {
18
+ key = _toPropertyKey(key);
19
+ if (key in obj) {
20
+ Object.defineProperty(obj, key, {
21
+ value: value,
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true
25
+ });
26
+ } else {
27
+ obj[key] = value;
28
+ }
29
+ return obj;
30
+ }
31
+
32
+ export { _defineProperty as _, _toPropertyKey as a };
@@ -0,0 +1,25 @@
1
+ import { _ as _defineProperty } from './defineProperty-f319cb47.browser.esm.js';
2
+
3
+ function ownKeys(object, enumerableOnly) {
4
+ var keys = Object.keys(object);
5
+ if (Object.getOwnPropertySymbols) {
6
+ var symbols = Object.getOwnPropertySymbols(object);
7
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
8
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
9
+ })), keys.push.apply(keys, symbols);
10
+ }
11
+ return keys;
12
+ }
13
+ function _objectSpread2(target) {
14
+ for (var i = 1; i < arguments.length; i++) {
15
+ var source = null != arguments[i] ? arguments[i] : {};
16
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
17
+ _defineProperty(target, key, source[key]);
18
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
19
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
20
+ });
21
+ }
22
+ return target;
23
+ }
24
+
25
+ export { _objectSpread2 as _ };
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ var defineProperty = require('./defineProperty-c82a49b0.cjs.dev.js');
4
+
5
+ function ownKeys(object, enumerableOnly) {
6
+ var keys = Object.keys(object);
7
+ if (Object.getOwnPropertySymbols) {
8
+ var symbols = Object.getOwnPropertySymbols(object);
9
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
10
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
11
+ })), keys.push.apply(keys, symbols);
12
+ }
13
+ return keys;
14
+ }
15
+ function _objectSpread2(target) {
16
+ for (var i = 1; i < arguments.length; i++) {
17
+ var source = null != arguments[i] ? arguments[i] : {};
18
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
19
+ defineProperty._defineProperty(target, key, source[key]);
20
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
21
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
22
+ });
23
+ }
24
+ return target;
25
+ }
26
+
27
+ exports._objectSpread2 = _objectSpread2;
@@ -0,0 +1,27 @@
1
+ 'use strict';
2
+
3
+ var defineProperty = require('./defineProperty-36ed93cd.cjs.prod.js');
4
+
5
+ function ownKeys(object, enumerableOnly) {
6
+ var keys = Object.keys(object);
7
+ if (Object.getOwnPropertySymbols) {
8
+ var symbols = Object.getOwnPropertySymbols(object);
9
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
10
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
11
+ })), keys.push.apply(keys, symbols);
12
+ }
13
+ return keys;
14
+ }
15
+ function _objectSpread2(target) {
16
+ for (var i = 1; i < arguments.length; i++) {
17
+ var source = null != arguments[i] ? arguments[i] : {};
18
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
19
+ defineProperty._defineProperty(target, key, source[key]);
20
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
21
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
22
+ });
23
+ }
24
+ return target;
25
+ }
26
+
27
+ exports._objectSpread2 = _objectSpread2;
@@ -0,0 +1,25 @@
1
+ import { _ as _defineProperty } from './defineProperty-12b5bd29.esm.js';
2
+
3
+ function ownKeys(object, enumerableOnly) {
4
+ var keys = Object.keys(object);
5
+ if (Object.getOwnPropertySymbols) {
6
+ var symbols = Object.getOwnPropertySymbols(object);
7
+ enumerableOnly && (symbols = symbols.filter(function (sym) {
8
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
9
+ })), keys.push.apply(keys, symbols);
10
+ }
11
+ return keys;
12
+ }
13
+ function _objectSpread2(target) {
14
+ for (var i = 1; i < arguments.length; i++) {
15
+ var source = null != arguments[i] ? arguments[i] : {};
16
+ i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
17
+ _defineProperty(target, key, source[key]);
18
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
19
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
20
+ });
21
+ }
22
+ return target;
23
+ }
24
+
25
+ export { _objectSpread2 as _ };
@@ -1,5 +1,8 @@
1
- export { ValProvider } from './ValProvider-11be7088.browser.esm.js';
1
+ export { ValProvider } from './ValProvider-c677e164.browser.esm.js';
2
2
  import { Internal } from '@valbuild/core';
3
+ import { createElement } from 'react';
4
+ import parse from 'style-to-object';
5
+ import { jsx } from 'react/jsx-runtime';
3
6
 
4
7
  function useVal(selector, locale) {
5
8
  // const mod = selectable.getModule();
@@ -23,4 +26,137 @@ function useVal(selector, locale) {
23
26
  return Internal.getVal(selector, locale);
24
27
  }
25
28
 
26
- export { useVal };
29
+ function ValRichText(_ref) {
30
+ var children = _ref.children;
31
+ var root = children;
32
+ var path = root.valPath;
33
+ return /*#__PURE__*/jsx("div", {
34
+ "data-val-path": path,
35
+ children: root.children.map(function (child, i) {
36
+ var childType = child.type;
37
+ var childPath = "".concat(path, ".").concat(i);
38
+ switch (childType) {
39
+ case "heading":
40
+ return /*#__PURE__*/jsx(HeadingNodeComponent, {
41
+ path: childPath,
42
+ node: child
43
+ }, childPath);
44
+ case "paragraph":
45
+ return /*#__PURE__*/jsx(ParagraphNodeComponent, {
46
+ path: childPath,
47
+ node: child
48
+ }, childPath);
49
+ case "list":
50
+ return /*#__PURE__*/jsx(ListNodeComponent, {
51
+ path: childPath,
52
+ node: child
53
+ }, childPath);
54
+ default:
55
+ throw Error("Unknown root node type: " + childType);
56
+ }
57
+ })
58
+ });
59
+ }
60
+ function TextNodeComponent(_ref2) {
61
+ var _parse, _node$format;
62
+ var node = _ref2.node;
63
+ var styleProps = node.style ? (_parse = parse(node.style)) !== null && _parse !== void 0 ? _parse : {} : {};
64
+ // TODO: Ugly! We should do this before serializing instead
65
+ if (styleProps["font-family"]) {
66
+ styleProps["fontFamily"] = styleProps["font-family"];
67
+ delete styleProps["font-family"];
68
+ }
69
+ if (styleProps["font-size"]) {
70
+ styleProps["fontSize"] = styleProps["font-size"];
71
+ delete styleProps["font-size"];
72
+ }
73
+ var bitmask = (_node$format = node.format) === null || _node$format === void 0 ? void 0 : _node$format.toString(2);
74
+ var bitmaskOffset = bitmask ? bitmask.length - 1 : 0;
75
+ function isBitOne(bit) {
76
+ if (!bitmask) {
77
+ return false;
78
+ }
79
+ return bitmask.length >= bitmaskOffset - bit && bitmask[bitmaskOffset - bit] === "1";
80
+ }
81
+ if (isBitOne(0)) {
82
+ styleProps["fontWeight"] = "bold";
83
+ }
84
+ if (isBitOne(1)) {
85
+ styleProps["fontStyle"] = "italic";
86
+ }
87
+ if (isBitOne(2)) {
88
+ if (!styleProps["textDecoration"]) {
89
+ styleProps["textDecoration"] = "line-through";
90
+ } else {
91
+ styleProps["textDecoration"] += " line-through";
92
+ }
93
+ }
94
+ if (isBitOne(3)) {
95
+ if (!styleProps["textDecoration"]) {
96
+ styleProps["textDecoration"] = "underline";
97
+ } else {
98
+ styleProps["textDecoration"] += " underline";
99
+ }
100
+ }
101
+ return /*#__PURE__*/jsx("span", {
102
+ style: styleProps,
103
+ children: node.text
104
+ });
105
+ }
106
+ function HeadingNodeComponent(_ref3) {
107
+ var node = _ref3.node,
108
+ path = _ref3.path;
109
+ return /*#__PURE__*/createElement(node.tag, {}, node.children.map(function (child, i) {
110
+ var childPath = "".concat(path, ".").concat(i);
111
+ return /*#__PURE__*/jsx(TextNodeComponent, {
112
+ node: child
113
+ }, childPath);
114
+ }));
115
+ }
116
+ function ParagraphNodeComponent(_ref4) {
117
+ var node = _ref4.node,
118
+ path = _ref4.path;
119
+ return /*#__PURE__*/jsx("p", {
120
+ children: node.children.map(function (child, i) {
121
+ var childPath = "".concat(path, ".").concat(i);
122
+ switch (child.type) {
123
+ case "text":
124
+ return /*#__PURE__*/jsx(TextNodeComponent, {
125
+ node: child
126
+ }, childPath);
127
+ default:
128
+ throw Error("Unknown paragraph node type: " + (child === null || child === void 0 ? void 0 : child.type));
129
+ }
130
+ })
131
+ });
132
+ }
133
+ function ListNodeComponent(_ref5) {
134
+ var node = _ref5.node,
135
+ path = _ref5.path;
136
+ return /*#__PURE__*/createElement(node.tag, {}, node.children.map(function (child, i) {
137
+ var childPath = "".concat(path, ".").concat(i);
138
+ return /*#__PURE__*/jsx(ListItemComponent, {
139
+ path: childPath,
140
+ node: child
141
+ }, childPath);
142
+ }));
143
+ }
144
+ function ListItemComponent(_ref6) {
145
+ var node = _ref6.node,
146
+ path = _ref6.path;
147
+ return /*#__PURE__*/jsx("li", {
148
+ children: node.children.map(function (child, i) {
149
+ var childPath = "".concat(path, ".").concat(i);
150
+ switch (child.type) {
151
+ case "text":
152
+ return /*#__PURE__*/jsx(TextNodeComponent, {
153
+ node: child
154
+ }, childPath);
155
+ default:
156
+ throw Error("Unknown list item node type: " + (child === null || child === void 0 ? void 0 : child.type));
157
+ }
158
+ })
159
+ });
160
+ }
161
+
162
+ export { ValRichText, useVal };
@@ -2,8 +2,15 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var ValProvider = require('./ValProvider-7b9d888e.cjs.dev.js');
5
+ var ValProvider = require('./ValProvider-f647e355.cjs.dev.js');
6
6
  var core = require('@valbuild/core');
7
+ var React = require('react');
8
+ var parse = require('style-to-object');
9
+ var ReactJSXRuntime = require('react/jsx-runtime');
10
+
11
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
12
+
13
+ var parse__default = /*#__PURE__*/_interopDefault(parse);
7
14
 
8
15
  function useVal(selector, locale) {
9
16
  // const mod = selectable.getModule();
@@ -27,8 +34,142 @@ function useVal(selector, locale) {
27
34
  return core.Internal.getVal(selector, locale);
28
35
  }
29
36
 
37
+ function ValRichText(_ref) {
38
+ var children = _ref.children;
39
+ var root = children;
40
+ var path = root.valPath;
41
+ return /*#__PURE__*/ReactJSXRuntime.jsx("div", {
42
+ "data-val-path": path,
43
+ children: root.children.map(function (child, i) {
44
+ var childType = child.type;
45
+ var childPath = "".concat(path, ".").concat(i);
46
+ switch (childType) {
47
+ case "heading":
48
+ return /*#__PURE__*/ReactJSXRuntime.jsx(HeadingNodeComponent, {
49
+ path: childPath,
50
+ node: child
51
+ }, childPath);
52
+ case "paragraph":
53
+ return /*#__PURE__*/ReactJSXRuntime.jsx(ParagraphNodeComponent, {
54
+ path: childPath,
55
+ node: child
56
+ }, childPath);
57
+ case "list":
58
+ return /*#__PURE__*/ReactJSXRuntime.jsx(ListNodeComponent, {
59
+ path: childPath,
60
+ node: child
61
+ }, childPath);
62
+ default:
63
+ throw Error("Unknown root node type: " + childType);
64
+ }
65
+ })
66
+ });
67
+ }
68
+ function TextNodeComponent(_ref2) {
69
+ var _parse, _node$format;
70
+ var node = _ref2.node;
71
+ var styleProps = node.style ? (_parse = parse__default["default"](node.style)) !== null && _parse !== void 0 ? _parse : {} : {};
72
+ // TODO: Ugly! We should do this before serializing instead
73
+ if (styleProps["font-family"]) {
74
+ styleProps["fontFamily"] = styleProps["font-family"];
75
+ delete styleProps["font-family"];
76
+ }
77
+ if (styleProps["font-size"]) {
78
+ styleProps["fontSize"] = styleProps["font-size"];
79
+ delete styleProps["font-size"];
80
+ }
81
+ var bitmask = (_node$format = node.format) === null || _node$format === void 0 ? void 0 : _node$format.toString(2);
82
+ var bitmaskOffset = bitmask ? bitmask.length - 1 : 0;
83
+ function isBitOne(bit) {
84
+ if (!bitmask) {
85
+ return false;
86
+ }
87
+ return bitmask.length >= bitmaskOffset - bit && bitmask[bitmaskOffset - bit] === "1";
88
+ }
89
+ if (isBitOne(0)) {
90
+ styleProps["fontWeight"] = "bold";
91
+ }
92
+ if (isBitOne(1)) {
93
+ styleProps["fontStyle"] = "italic";
94
+ }
95
+ if (isBitOne(2)) {
96
+ if (!styleProps["textDecoration"]) {
97
+ styleProps["textDecoration"] = "line-through";
98
+ } else {
99
+ styleProps["textDecoration"] += " line-through";
100
+ }
101
+ }
102
+ if (isBitOne(3)) {
103
+ if (!styleProps["textDecoration"]) {
104
+ styleProps["textDecoration"] = "underline";
105
+ } else {
106
+ styleProps["textDecoration"] += " underline";
107
+ }
108
+ }
109
+ return /*#__PURE__*/ReactJSXRuntime.jsx("span", {
110
+ style: styleProps,
111
+ children: node.text
112
+ });
113
+ }
114
+ function HeadingNodeComponent(_ref3) {
115
+ var node = _ref3.node,
116
+ path = _ref3.path;
117
+ return /*#__PURE__*/React.createElement(node.tag, {}, node.children.map(function (child, i) {
118
+ var childPath = "".concat(path, ".").concat(i);
119
+ return /*#__PURE__*/ReactJSXRuntime.jsx(TextNodeComponent, {
120
+ node: child
121
+ }, childPath);
122
+ }));
123
+ }
124
+ function ParagraphNodeComponent(_ref4) {
125
+ var node = _ref4.node,
126
+ path = _ref4.path;
127
+ return /*#__PURE__*/ReactJSXRuntime.jsx("p", {
128
+ children: node.children.map(function (child, i) {
129
+ var childPath = "".concat(path, ".").concat(i);
130
+ switch (child.type) {
131
+ case "text":
132
+ return /*#__PURE__*/ReactJSXRuntime.jsx(TextNodeComponent, {
133
+ node: child
134
+ }, childPath);
135
+ default:
136
+ throw Error("Unknown paragraph node type: " + (child === null || child === void 0 ? void 0 : child.type));
137
+ }
138
+ })
139
+ });
140
+ }
141
+ function ListNodeComponent(_ref5) {
142
+ var node = _ref5.node,
143
+ path = _ref5.path;
144
+ return /*#__PURE__*/React.createElement(node.tag, {}, node.children.map(function (child, i) {
145
+ var childPath = "".concat(path, ".").concat(i);
146
+ return /*#__PURE__*/ReactJSXRuntime.jsx(ListItemComponent, {
147
+ path: childPath,
148
+ node: child
149
+ }, childPath);
150
+ }));
151
+ }
152
+ function ListItemComponent(_ref6) {
153
+ var node = _ref6.node,
154
+ path = _ref6.path;
155
+ return /*#__PURE__*/ReactJSXRuntime.jsx("li", {
156
+ children: node.children.map(function (child, i) {
157
+ var childPath = "".concat(path, ".").concat(i);
158
+ switch (child.type) {
159
+ case "text":
160
+ return /*#__PURE__*/ReactJSXRuntime.jsx(TextNodeComponent, {
161
+ node: child
162
+ }, childPath);
163
+ default:
164
+ throw Error("Unknown list item node type: " + (child === null || child === void 0 ? void 0 : child.type));
165
+ }
166
+ })
167
+ });
168
+ }
169
+
30
170
  Object.defineProperty(exports, 'ValProvider', {
31
171
  enumerable: true,
32
172
  get: function () { return ValProvider.ValProvider; }
33
173
  });
174
+ exports.ValRichText = ValRichText;
34
175
  exports.useVal = useVal;