@valbuild/react 0.13.3 → 0.14.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.
- package/README.md +11 -0
- package/dist/{ValProvider-52f2fa13.esm.js → ValProvider-2eb6c2f2.esm.js} +4 -34
- package/dist/ValProvider-74eef393.cjs.js +7 -0
- package/dist/{ValProvider-e1d5ffbe.cjs.prod.js → ValProvider-74eef393.cjs.prod.js} +7 -38
- package/dist/{ValProvider-c7a8476b.browser.esm.js → ValProvider-c677e164.browser.esm.js} +4 -34
- package/dist/{ValProvider-a45a47b9.worker.esm.js → ValProvider-cb5a2161.worker.esm.js} +3 -33
- package/dist/{ValProvider-7364ec46.cjs.dev.js → ValProvider-f647e355.cjs.dev.js} +7 -38
- package/dist/{ValUI-0fbdafd4.cjs.prod.js → ValUI-0c2671a7.cjs.prod.js} +12 -28
- package/dist/{ValUI-371e9bf4.cjs.dev.js → ValUI-334ef1d0.cjs.dev.js} +12 -28
- package/dist/{ValUI-51404232.browser.esm.js → ValUI-bb1d1ed6.browser.esm.js} +11 -27
- package/dist/{ValUI-9a3eb570.esm.js → ValUI-bf82178a.esm.js} +11 -27
- package/dist/declarations/src/ValProvider.d.ts +3 -3
- package/dist/declarations/src/ValRichText.d.ts +2 -2
- package/dist/declarations/src/ValStore.d.ts +1 -1
- package/dist/declarations/src/index.d.ts +3 -3
- package/dist/declarations/src/jsx-runtime.d.ts +1 -1
- package/dist/declarations/src/stega/autoTagJSX.d.ts +1 -0
- package/dist/declarations/src/stega/fetchVal.d.ts +3 -0
- package/dist/declarations/src/stega/hooks/useVal.d.ts +3 -0
- package/dist/declarations/src/stega/index.d.ts +4 -0
- package/dist/declarations/src/stega/stegaEncode.d.ts +24 -0
- package/dist/defineProperty-12b5bd29.esm.js +32 -0
- package/dist/defineProperty-36ed93cd.cjs.prod.js +35 -0
- package/dist/defineProperty-a4bf59bc.worker.esm.js +32 -0
- package/dist/defineProperty-c82a49b0.cjs.dev.js +35 -0
- package/dist/defineProperty-f319cb47.browser.esm.js +32 -0
- package/dist/objectSpread2-30cc2856.browser.esm.js +25 -0
- package/dist/objectSpread2-61fbd9a9.cjs.dev.js +27 -0
- package/dist/objectSpread2-7b752a35.cjs.prod.js +27 -0
- package/dist/objectSpread2-d5a1fe1c.esm.js +25 -0
- package/dist/valbuild-react.browser.esm.js +50 -41
- package/dist/valbuild-react.cjs.dev.js +53 -67
- package/dist/valbuild-react.cjs.prod.js +53 -67
- package/dist/valbuild-react.esm.js +50 -49
- package/dist/valbuild-react.worker.esm.js +50 -49
- package/jsx-dev-runtime/dist/valbuild-react-jsx-dev-runtime.browser.esm.js +2 -2
- package/jsx-dev-runtime/dist/valbuild-react-jsx-dev-runtime.cjs.dev.js +5 -5
- package/jsx-dev-runtime/dist/valbuild-react-jsx-dev-runtime.cjs.prod.js +5 -5
- package/jsx-dev-runtime/dist/valbuild-react-jsx-dev-runtime.esm.js +2 -2
- package/jsx-dev-runtime/dist/valbuild-react-jsx-dev-runtime.worker.esm.js +2 -2
- package/package.json +20 -7
- package/src/ShadowRoot.tsx +8 -4
- package/src/ValProvider.tsx +1 -4
- package/src/ValRichText.tsx +76 -40
- package/src/index.ts +2 -4
- package/src/stega/autoTagJSX.ts +80 -0
- package/src/stega/fetchVal.ts +16 -0
- package/src/stega/hooks/useVal.ts +14 -0
- package/src/stega/index.ts +5 -0
- package/src/stega/stegaEncode.ts +84 -0
- package/stega/README.md +3 -0
- package/stega/dist/valbuild-react-stega.browser.esm.js +126 -0
- package/stega/dist/valbuild-react-stega.cjs.d.ts +2 -0
- package/stega/dist/valbuild-react-stega.cjs.d.ts.map +1 -0
- package/stega/dist/valbuild-react-stega.cjs.dev.js +138 -0
- package/stega/dist/valbuild-react-stega.cjs.js +7 -0
- package/stega/dist/valbuild-react-stega.cjs.prod.js +138 -0
- package/stega/dist/valbuild-react-stega.esm.js +126 -0
- package/stega/dist/valbuild-react-stega.worker.esm.js +147 -0
- package/stega/package.json +7 -0
- package/dist/ValProvider-e1d5ffbe.cjs.js +0 -7
- package/dist/declarations/src/AuthStatus.d.ts +0 -6
- package/dist/declarations/src/ShadowRoot.d.ts +0 -4
- package/dist/declarations/src/ValProviderWrapper.d.ts +0 -3
- package/dist/declarations/src/ValUI.d.ts +0 -8
- package/src/ValProviderWrapper.tsx +0 -15
@@ -1,23 +1,8 @@
|
|
1
|
-
|
2
|
-
import { jsx } from 'react/jsx-runtime';
|
1
|
+
export { ValProvider } from './ValProvider-cb5a2161.worker.esm.js';
|
3
2
|
import { Internal } from '@valbuild/core';
|
3
|
+
import { createElement } from 'react';
|
4
4
|
import parse from 'style-to-object';
|
5
|
-
|
6
|
-
var ValProvider = /*#__PURE__*/lazy(function () {
|
7
|
-
return import('./ValProvider-a45a47b9.worker.esm.js');
|
8
|
-
});
|
9
|
-
function ValProviderWrapper(_ref) {
|
10
|
-
var _ref$host = _ref.host,
|
11
|
-
host = _ref$host === void 0 ? "/api/val" : _ref$host,
|
12
|
-
children = _ref.children;
|
13
|
-
if (!ValProvider) {
|
14
|
-
return null;
|
15
|
-
}
|
16
|
-
return /*#__PURE__*/jsx(ValProvider, {
|
17
|
-
host: host,
|
18
|
-
children: children
|
19
|
-
});
|
20
|
-
}
|
5
|
+
import { jsx } from 'react/jsx-runtime';
|
21
6
|
|
22
7
|
function useVal(selector, locale) {
|
23
8
|
// const mod = selectable.getModule();
|
@@ -41,37 +26,41 @@ function useVal(selector, locale) {
|
|
41
26
|
return Internal.getVal(selector, locale);
|
42
27
|
}
|
43
28
|
|
44
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
45
|
-
var getValPath = Internal.getValPath;
|
46
29
|
function ValRichText(_ref) {
|
47
30
|
var children = _ref.children;
|
31
|
+
var root = children;
|
32
|
+
var path = root.valPath;
|
48
33
|
return /*#__PURE__*/jsx("div", {
|
49
|
-
"data-val-path":
|
50
|
-
children:
|
51
|
-
|
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) {
|
52
39
|
case "heading":
|
53
40
|
return /*#__PURE__*/jsx(HeadingNodeComponent, {
|
41
|
+
path: childPath,
|
54
42
|
node: child
|
55
|
-
},
|
43
|
+
}, childPath);
|
56
44
|
case "paragraph":
|
57
45
|
return /*#__PURE__*/jsx(ParagraphNodeComponent, {
|
46
|
+
path: childPath,
|
58
47
|
node: child
|
59
|
-
},
|
48
|
+
}, childPath);
|
60
49
|
case "list":
|
61
50
|
return /*#__PURE__*/jsx(ListNodeComponent, {
|
51
|
+
path: childPath,
|
62
52
|
node: child
|
63
|
-
},
|
53
|
+
}, childPath);
|
64
54
|
default:
|
65
|
-
throw Error("Unknown node type: " +
|
55
|
+
throw Error("Unknown root node type: " + childType);
|
66
56
|
}
|
67
57
|
})
|
68
58
|
});
|
69
59
|
}
|
70
60
|
function TextNodeComponent(_ref2) {
|
71
|
-
var _parse;
|
61
|
+
var _parse, _node$format;
|
72
62
|
var node = _ref2.node;
|
73
|
-
var
|
74
|
-
var styleProps = actualVal.style ? (_parse = parse(actualVal.style)) !== null && _parse !== void 0 ? _parse : {} : {};
|
63
|
+
var styleProps = node.style ? (_parse = parse(node.style)) !== null && _parse !== void 0 ? _parse : {} : {};
|
75
64
|
// TODO: Ugly! We should do this before serializing instead
|
76
65
|
if (styleProps["font-family"]) {
|
77
66
|
styleProps["fontFamily"] = styleProps["font-family"];
|
@@ -81,9 +70,12 @@ function TextNodeComponent(_ref2) {
|
|
81
70
|
styleProps["fontSize"] = styleProps["font-size"];
|
82
71
|
delete styleProps["font-size"];
|
83
72
|
}
|
84
|
-
var bitmask =
|
85
|
-
var bitmaskOffset = bitmask.length - 1;
|
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;
|
86
75
|
function isBitOne(bit) {
|
76
|
+
if (!bitmask) {
|
77
|
+
return false;
|
78
|
+
}
|
87
79
|
return bitmask.length >= bitmaskOffset - bit && bitmask[bitmaskOffset - bit] === "1";
|
88
80
|
}
|
89
81
|
if (isBitOne(0)) {
|
@@ -108,54 +100,63 @@ function TextNodeComponent(_ref2) {
|
|
108
100
|
}
|
109
101
|
return /*#__PURE__*/jsx("span", {
|
110
102
|
style: styleProps,
|
111
|
-
children:
|
103
|
+
children: node.text
|
112
104
|
});
|
113
105
|
}
|
114
106
|
function HeadingNodeComponent(_ref3) {
|
115
|
-
var node = _ref3.node
|
116
|
-
|
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);
|
117
111
|
return /*#__PURE__*/jsx(TextNodeComponent, {
|
118
112
|
node: child
|
119
|
-
},
|
113
|
+
}, childPath);
|
120
114
|
}));
|
121
115
|
}
|
122
116
|
function ParagraphNodeComponent(_ref4) {
|
123
|
-
var node = _ref4.node
|
117
|
+
var node = _ref4.node,
|
118
|
+
path = _ref4.path;
|
124
119
|
return /*#__PURE__*/jsx("p", {
|
125
|
-
children: node.children.map(function (child) {
|
126
|
-
|
120
|
+
children: node.children.map(function (child, i) {
|
121
|
+
var childPath = "".concat(path, ".").concat(i);
|
122
|
+
switch (child.type) {
|
127
123
|
case "text":
|
128
124
|
return /*#__PURE__*/jsx(TextNodeComponent, {
|
129
125
|
node: child
|
130
|
-
},
|
126
|
+
}, childPath);
|
131
127
|
default:
|
132
|
-
throw Error("Unknown node type: " + (child === null || child === void 0 ? void 0 : child.type));
|
128
|
+
throw Error("Unknown paragraph node type: " + (child === null || child === void 0 ? void 0 : child.type));
|
133
129
|
}
|
134
130
|
})
|
135
131
|
});
|
136
132
|
}
|
137
133
|
function ListNodeComponent(_ref5) {
|
138
|
-
var node = _ref5.node
|
139
|
-
|
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);
|
140
138
|
return /*#__PURE__*/jsx(ListItemComponent, {
|
139
|
+
path: childPath,
|
141
140
|
node: child
|
142
|
-
},
|
141
|
+
}, childPath);
|
143
142
|
}));
|
144
143
|
}
|
145
144
|
function ListItemComponent(_ref6) {
|
146
|
-
var node = _ref6.node
|
145
|
+
var node = _ref6.node,
|
146
|
+
path = _ref6.path;
|
147
147
|
return /*#__PURE__*/jsx("li", {
|
148
148
|
children: node.children.map(function (child, i) {
|
149
|
-
|
149
|
+
var childPath = "".concat(path, ".").concat(i);
|
150
|
+
switch (child.type) {
|
150
151
|
case "text":
|
151
152
|
return /*#__PURE__*/jsx(TextNodeComponent, {
|
152
153
|
node: child
|
153
|
-
},
|
154
|
+
}, childPath);
|
154
155
|
default:
|
155
|
-
throw Error("Unknown node type: " + (child === null || child === void 0 ? void 0 : child.type));
|
156
|
+
throw Error("Unknown list item node type: " + (child === null || child === void 0 ? void 0 : child.type));
|
156
157
|
}
|
157
158
|
})
|
158
159
|
});
|
159
160
|
}
|
160
161
|
|
161
|
-
export {
|
162
|
+
export { ValRichText, useVal };
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { _ as _slicedToArray, a as _typeof } from '../../dist/slicedToArray-1a246338.browser.esm.js';
|
2
2
|
import { Internal } from '@valbuild/core';
|
3
|
-
import * as
|
3
|
+
import * as jsxRuntimeDev from 'react/jsx-dev-runtime';
|
4
4
|
export * from 'react/jsx-dev-runtime';
|
5
5
|
import '../../dist/unsupportedIterableToArray-d3087ed5.browser.esm.js';
|
6
6
|
|
@@ -36,7 +36,7 @@ function jsxDEV(type, props, key, isStaticChildren, source, self) {
|
|
36
36
|
// console.log("jsxDEV", type, props, key, isStaticChildren, source, self);
|
37
37
|
|
38
38
|
devalProps(type, props);
|
39
|
-
return
|
39
|
+
return jsxRuntimeDev.jsxDEV(type, props, key, isStaticChildren, source, self);
|
40
40
|
}
|
41
41
|
|
42
42
|
export { jsxDEV };
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
5
5
|
var slicedToArray = require('../../dist/slicedToArray-b7cf26e0.cjs.dev.js');
|
6
6
|
var core = require('@valbuild/core');
|
7
|
-
var
|
7
|
+
var jsxRuntimeDev = require('react/jsx-dev-runtime');
|
8
8
|
require('../../dist/unsupportedIterableToArray-9e97e24a.cjs.dev.js');
|
9
9
|
|
10
10
|
function _interopNamespace(e) {
|
@@ -25,7 +25,7 @@ function _interopNamespace(e) {
|
|
25
25
|
return Object.freeze(n);
|
26
26
|
}
|
27
27
|
|
28
|
-
var
|
28
|
+
var jsxRuntimeDev__namespace = /*#__PURE__*/_interopNamespace(jsxRuntimeDev);
|
29
29
|
|
30
30
|
var isIntrinsicElement = function isIntrinsicElement(type) {
|
31
31
|
// TODO: think this is not correct, but good enough for now?
|
@@ -59,13 +59,13 @@ function jsxDEV(type, props, key, isStaticChildren, source, self) {
|
|
59
59
|
// console.log("jsxDEV", type, props, key, isStaticChildren, source, self);
|
60
60
|
|
61
61
|
devalProps(type, props);
|
62
|
-
return
|
62
|
+
return jsxRuntimeDev__namespace.jsxDEV(type, props, key, isStaticChildren, source, self);
|
63
63
|
}
|
64
64
|
|
65
65
|
exports.jsxDEV = jsxDEV;
|
66
|
-
Object.keys(
|
66
|
+
Object.keys(jsxRuntimeDev).forEach(function (k) {
|
67
67
|
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
68
68
|
enumerable: true,
|
69
|
-
get: function () { return
|
69
|
+
get: function () { return jsxRuntimeDev[k]; }
|
70
70
|
});
|
71
71
|
});
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
5
5
|
var slicedToArray = require('../../dist/slicedToArray-0eb0bcdb.cjs.prod.js');
|
6
6
|
var core = require('@valbuild/core');
|
7
|
-
var
|
7
|
+
var jsxRuntimeDev = require('react/jsx-dev-runtime');
|
8
8
|
require('../../dist/unsupportedIterableToArray-afbea1dd.cjs.prod.js');
|
9
9
|
|
10
10
|
function _interopNamespace(e) {
|
@@ -25,7 +25,7 @@ function _interopNamespace(e) {
|
|
25
25
|
return Object.freeze(n);
|
26
26
|
}
|
27
27
|
|
28
|
-
var
|
28
|
+
var jsxRuntimeDev__namespace = /*#__PURE__*/_interopNamespace(jsxRuntimeDev);
|
29
29
|
|
30
30
|
var isIntrinsicElement = function isIntrinsicElement(type) {
|
31
31
|
// TODO: think this is not correct, but good enough for now?
|
@@ -59,13 +59,13 @@ function jsxDEV(type, props, key, isStaticChildren, source, self) {
|
|
59
59
|
// console.log("jsxDEV", type, props, key, isStaticChildren, source, self);
|
60
60
|
|
61
61
|
devalProps(type, props);
|
62
|
-
return
|
62
|
+
return jsxRuntimeDev__namespace.jsxDEV(type, props, key, isStaticChildren, source, self);
|
63
63
|
}
|
64
64
|
|
65
65
|
exports.jsxDEV = jsxDEV;
|
66
|
-
Object.keys(
|
66
|
+
Object.keys(jsxRuntimeDev).forEach(function (k) {
|
67
67
|
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
68
68
|
enumerable: true,
|
69
|
-
get: function () { return
|
69
|
+
get: function () { return jsxRuntimeDev[k]; }
|
70
70
|
});
|
71
71
|
});
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { _ as _slicedToArray, a as _typeof } from '../../dist/slicedToArray-d846e1d2.esm.js';
|
2
2
|
import { Internal } from '@valbuild/core';
|
3
|
-
import * as
|
3
|
+
import * as jsxRuntimeDev from 'react/jsx-dev-runtime';
|
4
4
|
export * from 'react/jsx-dev-runtime';
|
5
5
|
import '../../dist/unsupportedIterableToArray-51bb61c2.esm.js';
|
6
6
|
|
@@ -36,7 +36,7 @@ function jsxDEV(type, props, key, isStaticChildren, source, self) {
|
|
36
36
|
// console.log("jsxDEV", type, props, key, isStaticChildren, source, self);
|
37
37
|
|
38
38
|
devalProps(type, props);
|
39
|
-
return
|
39
|
+
return jsxRuntimeDev.jsxDEV(type, props, key, isStaticChildren, source, self);
|
40
40
|
}
|
41
41
|
|
42
42
|
export { jsxDEV };
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { _ as _slicedToArray, a as _typeof } from '../../dist/slicedToArray-9e7d1407.worker.esm.js';
|
2
2
|
import { Internal } from '@valbuild/core';
|
3
|
-
import * as
|
3
|
+
import * as jsxRuntimeDev from 'react/jsx-dev-runtime';
|
4
4
|
export * from 'react/jsx-dev-runtime';
|
5
5
|
import '../../dist/unsupportedIterableToArray-738344ef.worker.esm.js';
|
6
6
|
|
@@ -36,7 +36,7 @@ function jsxDEV(type, props, key, isStaticChildren, source, self) {
|
|
36
36
|
// console.log("jsxDEV", type, props, key, isStaticChildren, source, self);
|
37
37
|
|
38
38
|
devalProps(type, props);
|
39
|
-
return
|
39
|
+
return jsxRuntimeDev.jsxDEV(type, props, key, isStaticChildren, source, self);
|
40
40
|
}
|
41
41
|
|
42
42
|
export { jsxDEV };
|
package/package.json
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
{
|
2
2
|
"name": "@valbuild/react",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.14.0",
|
4
4
|
"private": false,
|
5
|
-
"description": "Val - React",
|
5
|
+
"description": "Val - React internal helpers",
|
6
6
|
"sideEffects": false,
|
7
7
|
"scripts": {
|
8
8
|
"typecheck": "tsc --noEmit",
|
9
9
|
"test": "jest"
|
10
10
|
},
|
11
11
|
"dependencies": {
|
12
|
-
"@valbuild/core": "~0.
|
13
|
-
"@valbuild/ui": "~0.13.
|
12
|
+
"@valbuild/core": "~0.14.0",
|
13
|
+
"@valbuild/ui": "~0.13.4",
|
14
|
+
"@vercel/stega": "^0.1.0",
|
14
15
|
"base64-arraybuffer": "^1.0.2",
|
15
16
|
"style-to-object": "^0.4.1"
|
16
17
|
},
|
@@ -22,8 +23,8 @@
|
|
22
23
|
"react-dom": "^18.2.0"
|
23
24
|
},
|
24
25
|
"peerDependencies": {
|
25
|
-
"react": ">=
|
26
|
-
"react-dom": ">=
|
26
|
+
"react": ">=18.2.0",
|
27
|
+
"react-dom": ">=18.2.0"
|
27
28
|
},
|
28
29
|
"peerDependenciesMeta": {
|
29
30
|
"@types/react": {
|
@@ -34,7 +35,8 @@
|
|
34
35
|
"entrypoints": [
|
35
36
|
"./index.ts",
|
36
37
|
"./jsx-runtime.js",
|
37
|
-
"./jsx-dev-runtime.js"
|
38
|
+
"./jsx-dev-runtime.js",
|
39
|
+
"./stega/index.ts"
|
38
40
|
],
|
39
41
|
"exports": {
|
40
42
|
"envConditions": [
|
@@ -43,6 +45,9 @@
|
|
43
45
|
]
|
44
46
|
}
|
45
47
|
},
|
48
|
+
"externals": [
|
49
|
+
"react"
|
50
|
+
],
|
46
51
|
"main": "dist/valbuild-react.cjs.js",
|
47
52
|
"module": "dist/valbuild-react.esm.js",
|
48
53
|
"browser": {
|
@@ -65,6 +70,14 @@
|
|
65
70
|
},
|
66
71
|
"default": "./jsx-runtime/dist/valbuild-react-jsx-runtime.cjs.js"
|
67
72
|
},
|
73
|
+
"./stega": {
|
74
|
+
"module": {
|
75
|
+
"worker": "./stega/dist/valbuild-react-stega.worker.esm.js",
|
76
|
+
"browser": "./stega/dist/valbuild-react-stega.browser.esm.js",
|
77
|
+
"default": "./stega/dist/valbuild-react-stega.esm.js"
|
78
|
+
},
|
79
|
+
"default": "./stega/dist/valbuild-react-stega.cjs.js"
|
80
|
+
},
|
68
81
|
"./jsx-dev-runtime": {
|
69
82
|
"module": {
|
70
83
|
"worker": "./jsx-dev-runtime/dist/valbuild-react-jsx-dev-runtime.worker.esm.js",
|
package/src/ShadowRoot.tsx
CHANGED
@@ -17,10 +17,14 @@ export const ShadowRoot = ({ children }: { children: React.ReactNode }) => {
|
|
17
17
|
|
18
18
|
useLayoutEffect(() => {
|
19
19
|
if (node.current) {
|
20
|
-
|
21
|
-
|
22
|
-
}
|
23
|
-
|
20
|
+
if (node.current.shadowRoot) {
|
21
|
+
setRoot(node.current.shadowRoot);
|
22
|
+
} else {
|
23
|
+
const root = node.current.attachShadow({
|
24
|
+
mode: "open",
|
25
|
+
});
|
26
|
+
setRoot(root);
|
27
|
+
}
|
24
28
|
}
|
25
29
|
}, []);
|
26
30
|
|
package/src/ValProvider.tsx
CHANGED
@@ -36,10 +36,7 @@ export type ValProviderProps = {
|
|
36
36
|
const ValUI =
|
37
37
|
typeof window !== "undefined" ? lazy(() => import("./ValUI")) : null;
|
38
38
|
|
39
|
-
export
|
40
|
-
host = "/api/val",
|
41
|
-
children,
|
42
|
-
}: ValProviderProps) {
|
39
|
+
export function ValProvider({ host = "/api/val", children }: ValProviderProps) {
|
43
40
|
const valApi = useMemo(() => new ValApi(host), [host]);
|
44
41
|
const valStore = useMemo(() => new ValStore(valApi), [valApi]);
|
45
42
|
return (
|
package/src/ValRichText.tsx
CHANGED
@@ -1,55 +1,58 @@
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
2
1
|
import {
|
3
2
|
HeadingNode,
|
4
3
|
ListItemNode,
|
5
4
|
ListNode,
|
6
5
|
ParagraphNode,
|
7
6
|
RichText,
|
7
|
+
SourcePath,
|
8
8
|
TextNode,
|
9
|
-
Val,
|
10
9
|
} from "@valbuild/core";
|
11
|
-
import { Internal } from "@valbuild/core";
|
12
10
|
import { createElement } from "react";
|
13
11
|
import parse from "style-to-object";
|
14
12
|
|
15
|
-
|
16
|
-
|
13
|
+
export function ValRichText({ children }: { children: RichText }) {
|
14
|
+
const root: RichText = children;
|
15
|
+
const path = root.valPath;
|
17
16
|
return (
|
18
|
-
<div data-val-path={
|
19
|
-
{
|
20
|
-
|
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) {
|
21
22
|
case "heading":
|
22
23
|
return (
|
23
24
|
<HeadingNodeComponent
|
24
|
-
key={
|
25
|
-
|
25
|
+
key={childPath}
|
26
|
+
path={childPath}
|
27
|
+
node={child}
|
26
28
|
/>
|
27
29
|
);
|
28
30
|
case "paragraph":
|
29
31
|
return (
|
30
32
|
<ParagraphNodeComponent
|
31
|
-
key={
|
32
|
-
|
33
|
+
key={childPath}
|
34
|
+
path={childPath}
|
35
|
+
node={child}
|
33
36
|
/>
|
34
37
|
);
|
35
38
|
case "list":
|
36
39
|
return (
|
37
40
|
<ListNodeComponent
|
38
|
-
key={
|
39
|
-
|
41
|
+
key={childPath}
|
42
|
+
path={childPath}
|
43
|
+
node={child}
|
40
44
|
/>
|
41
45
|
);
|
42
46
|
default:
|
43
|
-
throw Error("Unknown node type: " +
|
47
|
+
throw Error("Unknown root node type: " + childType);
|
44
48
|
}
|
45
49
|
})}
|
46
50
|
</div>
|
47
51
|
);
|
48
52
|
}
|
49
53
|
|
50
|
-
function TextNodeComponent({ node }: { node:
|
51
|
-
const
|
52
|
-
const styleProps = actualVal.style ? parse(actualVal.style) ?? {} : {};
|
54
|
+
function TextNodeComponent({ node }: { node: TextNode }) {
|
55
|
+
const styleProps = node.style ? parse(node.style) ?? {} : {};
|
53
56
|
// TODO: Ugly! We should do this before serializing instead
|
54
57
|
if (styleProps["font-family"]) {
|
55
58
|
styleProps["fontFamily"] = styleProps["font-family"];
|
@@ -59,9 +62,12 @@ function TextNodeComponent({ node }: { node: Val<TextNode> }) {
|
|
59
62
|
styleProps["fontSize"] = styleProps["font-size"];
|
60
63
|
delete styleProps["font-size"];
|
61
64
|
}
|
62
|
-
const bitmask =
|
63
|
-
const bitmaskOffset = bitmask.length - 1;
|
65
|
+
const bitmask = node.format?.toString(2);
|
66
|
+
const bitmaskOffset = bitmask ? bitmask.length - 1 : 0;
|
64
67
|
function isBitOne(bit: number) {
|
68
|
+
if (!bitmask) {
|
69
|
+
return false;
|
70
|
+
}
|
65
71
|
return (
|
66
72
|
bitmask.length >= bitmaskOffset - bit &&
|
67
73
|
bitmask[bitmaskOffset - bit] === "1"
|
@@ -87,53 +93,83 @@ function TextNodeComponent({ node }: { node: Val<TextNode> }) {
|
|
87
93
|
styleProps["textDecoration"] += " underline";
|
88
94
|
}
|
89
95
|
}
|
90
|
-
return <span style={styleProps}>{
|
96
|
+
return <span style={styleProps}>{node.text}</span>;
|
91
97
|
}
|
92
98
|
|
93
|
-
function HeadingNodeComponent({
|
99
|
+
function HeadingNodeComponent({
|
100
|
+
node,
|
101
|
+
path,
|
102
|
+
}: {
|
103
|
+
path: SourcePath;
|
104
|
+
node: HeadingNode;
|
105
|
+
}) {
|
94
106
|
return createElement(
|
95
|
-
node.tag
|
107
|
+
node.tag,
|
96
108
|
{},
|
97
|
-
node.children.map((child) =>
|
98
|
-
|
99
|
-
|
109
|
+
node.children.map((child, i) => {
|
110
|
+
const childPath = `${path}.${i}` as SourcePath;
|
111
|
+
return <TextNodeComponent key={childPath} node={child} />;
|
112
|
+
})
|
100
113
|
);
|
101
114
|
}
|
102
115
|
|
103
|
-
function ParagraphNodeComponent({
|
116
|
+
function ParagraphNodeComponent({
|
117
|
+
node,
|
118
|
+
path,
|
119
|
+
}: {
|
120
|
+
path: SourcePath;
|
121
|
+
node: ParagraphNode;
|
122
|
+
}) {
|
104
123
|
return (
|
105
124
|
<p>
|
106
|
-
{node.children.map((child) => {
|
107
|
-
|
125
|
+
{node.children.map((child, i) => {
|
126
|
+
const childPath = `${path}.${i}` as SourcePath;
|
127
|
+
switch (child.type) {
|
108
128
|
case "text":
|
109
|
-
return <TextNodeComponent key={
|
129
|
+
return <TextNodeComponent key={childPath} node={child} />;
|
110
130
|
default:
|
111
|
-
throw Error("Unknown node type: " +
|
131
|
+
throw Error("Unknown paragraph node type: " + child?.type);
|
112
132
|
}
|
113
133
|
})}
|
114
134
|
</p>
|
115
135
|
);
|
116
136
|
}
|
117
137
|
|
118
|
-
function ListNodeComponent({
|
138
|
+
function ListNodeComponent({
|
139
|
+
node,
|
140
|
+
path,
|
141
|
+
}: {
|
142
|
+
path: SourcePath;
|
143
|
+
node: ListNode;
|
144
|
+
}) {
|
119
145
|
return createElement(
|
120
|
-
node.
|
146
|
+
node.tag,
|
121
147
|
{},
|
122
|
-
node.children.map((child) =>
|
123
|
-
|
124
|
-
|
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
|
+
})
|
125
154
|
);
|
126
155
|
}
|
127
156
|
|
128
|
-
function ListItemComponent({
|
157
|
+
function ListItemComponent({
|
158
|
+
node,
|
159
|
+
path,
|
160
|
+
}: {
|
161
|
+
path: SourcePath;
|
162
|
+
node: ListItemNode;
|
163
|
+
}) {
|
129
164
|
return (
|
130
165
|
<li>
|
131
166
|
{node.children.map((child, i) => {
|
132
|
-
|
167
|
+
const childPath = `${path}.${i}` as SourcePath;
|
168
|
+
switch (child.type) {
|
133
169
|
case "text":
|
134
|
-
return <TextNodeComponent key={
|
170
|
+
return <TextNodeComponent key={childPath} node={child} />;
|
135
171
|
default:
|
136
|
-
throw Error("Unknown node type: " +
|
172
|
+
throw Error("Unknown list item node type: " + child?.type);
|
137
173
|
}
|
138
174
|
})}
|
139
175
|
</li>
|
package/src/index.ts
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
export {
|
3
|
-
export { WithVal } from "./WithVal"; */
|
4
|
-
export { ValProviderWrapper as ValProvider } from "./ValProviderWrapper";
|
1
|
+
// NOTE: the exports of this file needs to be kept in sync with ValQuickJSRuntime
|
2
|
+
export { ValProvider } from "./ValProvider";
|
5
3
|
export { useVal } from "./hooks/useVal";
|
6
4
|
export { ValRichText } from "./ValRichText";
|