@valbuild/next 0.13.10 → 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.
- package/dist/declarations/src/index.d.ts +5 -6
- package/dist/valbuild-next.cjs.dev.js +22 -383
- package/dist/valbuild-next.cjs.prod.js +22 -383
- package/dist/valbuild-next.esm.js +5 -371
- package/package.json +4 -6
- package/src/index.ts +12 -6
- package/tsconfig.json +5 -1
- package/dist/declarations/src/ValRichText.d.ts +0 -5
- package/dist/declarations/src/autoTagJSX.d.ts +0 -1
- package/dist/declarations/src/fetchVal.d.ts +0 -3
- package/dist/declarations/src/hooks/useVal.d.ts +0 -3
- package/dist/declarations/src/stegaEncode.d.ts +0 -24
- package/src/ValRichText.tsx +0 -179
- package/src/autoTagJSX.ts +0 -77
- package/src/fetchVal.ts +0 -16
- package/src/hooks/useVal.ts +0 -14
- package/src/stegaEncode.ts +0 -76
|
@@ -1,373 +1,7 @@
|
|
|
1
|
-
import jsxRuntime, { jsx } from 'react/jsx-runtime';
|
|
2
|
-
import jsxRuntimeDev from 'react/jsx-dev-runtime';
|
|
3
|
-
import React, { createElement } from 'react';
|
|
4
|
-
import { VERCEL_STEGA_REGEX, vercelStegaDecode, vercelStegaSplit, vercelStegaCombine } from '@vercel/stega';
|
|
5
|
-
import { useVal as useVal$1 } from '@valbuild/react';
|
|
6
|
-
export { ValProvider } from '@valbuild/react';
|
|
7
|
-
import { Internal } from '@valbuild/core';
|
|
8
1
|
export * from '@valbuild/core';
|
|
9
|
-
|
|
2
|
+
export { ValProvider, ValRichText } from '@valbuild/react';
|
|
3
|
+
import { autoTagJSX } from '@valbuild/react/stega';
|
|
4
|
+
export { fetchVal, useVal } from '@valbuild/react/stega';
|
|
10
5
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function _iterableToArrayLimit(arr, i) {
|
|
16
|
-
var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"];
|
|
17
|
-
if (null != _i) {
|
|
18
|
-
var _s,
|
|
19
|
-
_e,
|
|
20
|
-
_x,
|
|
21
|
-
_r,
|
|
22
|
-
_arr = [],
|
|
23
|
-
_n = !0,
|
|
24
|
-
_d = !1;
|
|
25
|
-
try {
|
|
26
|
-
if (_x = (_i = _i.call(arr)).next, 0 === i) {
|
|
27
|
-
if (Object(_i) !== _i) return;
|
|
28
|
-
_n = !1;
|
|
29
|
-
} else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0);
|
|
30
|
-
} catch (err) {
|
|
31
|
-
_d = !0, _e = err;
|
|
32
|
-
} finally {
|
|
33
|
-
try {
|
|
34
|
-
if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return;
|
|
35
|
-
} finally {
|
|
36
|
-
if (_d) throw _e;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return _arr;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function _arrayLikeToArray(arr, len) {
|
|
44
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
45
|
-
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
46
|
-
return arr2;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function _unsupportedIterableToArray(o, minLen) {
|
|
50
|
-
if (!o) return;
|
|
51
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
52
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
53
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
54
|
-
if (n === "Map" || n === "Set") return Array.from(o);
|
|
55
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function _nonIterableRest() {
|
|
59
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function _slicedToArray(arr, i) {
|
|
63
|
-
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function _typeof(obj) {
|
|
67
|
-
"@babel/helpers - typeof";
|
|
68
|
-
|
|
69
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
70
|
-
return typeof obj;
|
|
71
|
-
} : function (obj) {
|
|
72
|
-
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
73
|
-
}, _typeof(obj);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
var isIntrinsicElement = function isIntrinsicElement(type) {
|
|
77
|
-
// TODO: think this is not correct, but good enough for now?
|
|
78
|
-
return typeof type === "string";
|
|
79
|
-
};
|
|
80
|
-
var addValPathIfFound = function addValPathIfFound(type, props) {
|
|
81
|
-
var valSources = [];
|
|
82
|
-
if (isIntrinsicElement(type) && props && _typeof(props) === "object") {
|
|
83
|
-
for (var _i = 0, _Object$entries = Object.entries(props); _i < _Object$entries.length; _i++) {
|
|
84
|
-
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
85
|
-
key = _Object$entries$_i[0],
|
|
86
|
-
value = _Object$entries$_i[1];
|
|
87
|
-
if (typeof value === "string" && value.match(VERCEL_STEGA_REGEX)) {
|
|
88
|
-
var encodedBits = vercelStegaDecode(value);
|
|
89
|
-
if (!encodedBits || _typeof(encodedBits) !== "object") continue;
|
|
90
|
-
if ("origin" in encodedBits && "data" in encodedBits && _typeof(encodedBits.data) === "object" && encodedBits.data && "valPath" in encodedBits.data) {
|
|
91
|
-
var _encodedBits$data;
|
|
92
|
-
var valPath = encodedBits === null || encodedBits === void 0 ? void 0 : (_encodedBits$data = encodedBits.data) === null || _encodedBits$data === void 0 ? void 0 : _encodedBits$data.valPath;
|
|
93
|
-
if (valPath) {
|
|
94
|
-
console.log("Found encoded valPath", valPath);
|
|
95
|
-
valSources.push(valPath);
|
|
96
|
-
props[key] = vercelStegaSplit(value).cleaned;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (valSources.length > 0) {
|
|
102
|
-
props["data-val-path"] = valSources.join(",");
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
function WrapJsx(jsx) {
|
|
107
|
-
if (typeof jsx !== "function") return jsx;
|
|
108
|
-
return function (type, props) {
|
|
109
|
-
addValPathIfFound(type, props);
|
|
110
|
-
for (var _len = arguments.length, rest = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
111
|
-
rest[_key - 2] = arguments[_key];
|
|
112
|
-
}
|
|
113
|
-
return jsx.call.apply(jsx, [jsx, type, props].concat(rest));
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
var JsxPro = jsxRuntime;
|
|
117
|
-
var JsxDev = jsxRuntimeDev;
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* createElement _may_ be called by jsx runtime as a fallback in certain cases,
|
|
121
|
-
* so we need to wrap it regardless.
|
|
122
|
-
*
|
|
123
|
-
* The jsx exports depend on the `NODE_ENV` var to ensure the users' bundler doesn't
|
|
124
|
-
* include both, so one of them will be set with `undefined` values.
|
|
125
|
-
*/
|
|
126
|
-
React.createElement = WrapJsx(React.createElement);
|
|
127
|
-
JsxDev.jsx && ( /* */JsxDev.jsx = WrapJsx(JsxDev.jsx));
|
|
128
|
-
JsxPro.jsx && ( /* */JsxPro.jsx = WrapJsx(JsxPro.jsx));
|
|
129
|
-
JsxDev.jsxs && ( /* */JsxDev.jsxs = WrapJsx(JsxDev.jsxs));
|
|
130
|
-
JsxPro.jsxs && ( /* */JsxPro.jsxs = WrapJsx(JsxPro.jsxs));
|
|
131
|
-
JsxDev.jsxDEV && ( /**/JsxDev.jsxDEV = WrapJsx(JsxDev.jsxDEV));
|
|
132
|
-
JsxPro.jsxDEV && ( /**/JsxPro.jsxDEV = WrapJsx(JsxPro.jsxDEV));
|
|
133
|
-
|
|
134
|
-
function _toPrimitive(input, hint) {
|
|
135
|
-
if (typeof input !== "object" || input === null) return input;
|
|
136
|
-
var prim = input[Symbol.toPrimitive];
|
|
137
|
-
if (prim !== undefined) {
|
|
138
|
-
var res = prim.call(input, hint || "default");
|
|
139
|
-
if (typeof res !== "object") return res;
|
|
140
|
-
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
141
|
-
}
|
|
142
|
-
return (hint === "string" ? String : Number)(input);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function _toPropertyKey(arg) {
|
|
146
|
-
var key = _toPrimitive(arg, "string");
|
|
147
|
-
return typeof key === "symbol" ? key : String(key);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function _defineProperty(obj, key, value) {
|
|
151
|
-
key = _toPropertyKey(key);
|
|
152
|
-
if (key in obj) {
|
|
153
|
-
Object.defineProperty(obj, key, {
|
|
154
|
-
value: value,
|
|
155
|
-
enumerable: true,
|
|
156
|
-
configurable: true,
|
|
157
|
-
writable: true
|
|
158
|
-
});
|
|
159
|
-
} else {
|
|
160
|
-
obj[key] = value;
|
|
161
|
-
}
|
|
162
|
-
return obj;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function ownKeys(object, enumerableOnly) {
|
|
166
|
-
var keys = Object.keys(object);
|
|
167
|
-
if (Object.getOwnPropertySymbols) {
|
|
168
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
169
|
-
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
170
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
171
|
-
})), keys.push.apply(keys, symbols);
|
|
172
|
-
}
|
|
173
|
-
return keys;
|
|
174
|
-
}
|
|
175
|
-
function _objectSpread2(target) {
|
|
176
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
177
|
-
var source = null != arguments[i] ? arguments[i] : {};
|
|
178
|
-
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
179
|
-
_defineProperty(target, key, source[key]);
|
|
180
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
181
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
return target;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* ValEncodedString is a string that is encoded using steganography.
|
|
189
|
-
*
|
|
190
|
-
* This means that there is a hidden / non-visible object embedded in the string.
|
|
191
|
-
* This object includes a path, which is used to automatically tag
|
|
192
|
-
* where the content comes from for contextual editing.
|
|
193
|
-
*
|
|
194
|
-
*/
|
|
195
|
-
|
|
196
|
-
function stegaEncodeVal(val) {
|
|
197
|
-
if (_typeof(val.val) === "object") {
|
|
198
|
-
if (Array.isArray(val)) {
|
|
199
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
200
|
-
return val.map(stegaEncodeVal);
|
|
201
|
-
}
|
|
202
|
-
if (_typeof(val.val) === "object" && val.val && "_type" in val.val && val.val["_type"] === "richtext") {
|
|
203
|
-
return _objectSpread2(_objectSpread2({}, val.val), {}, {
|
|
204
|
-
valPath: Internal.getValPath(val)
|
|
205
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return Object.fromEntries(Object.entries(val).map(function (_ref) {
|
|
210
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
211
|
-
key = _ref2[0],
|
|
212
|
-
value = _ref2[1];
|
|
213
|
-
return [key, stegaEncodeVal(value)];
|
|
214
|
-
}));
|
|
215
|
-
}
|
|
216
|
-
if (typeof val.val === "string") {
|
|
217
|
-
return vercelStegaCombine(val.val, {
|
|
218
|
-
origin: "app.val.build",
|
|
219
|
-
data: {
|
|
220
|
-
valPath: Internal.getValPath(val)
|
|
221
|
-
}
|
|
222
|
-
}); // TODO: skip should false at least for URLs? Dates...?
|
|
223
|
-
}
|
|
224
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
225
|
-
return val.val;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
function useVal(selector, locale) {
|
|
229
|
-
return stegaEncodeVal(useVal$1(selector, locale));
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
function fetchVal(selector, locale) {
|
|
233
|
-
return Internal.fetchVal(selector, locale).then(function (val) {
|
|
234
|
-
return stegaEncodeVal(val);
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
239
|
-
function ValRichText(_ref) {
|
|
240
|
-
var children = _ref.children;
|
|
241
|
-
var root = children;
|
|
242
|
-
var path = root.valPath;
|
|
243
|
-
return /*#__PURE__*/jsx("div", {
|
|
244
|
-
"data-val-path": path,
|
|
245
|
-
children: root.children.map(function (child, i) {
|
|
246
|
-
var childType = child.type;
|
|
247
|
-
var childPath = "".concat(path, ".").concat(i);
|
|
248
|
-
console.log("'".concat(childType, "', ").concat(childPath));
|
|
249
|
-
switch (childType) {
|
|
250
|
-
case "heading":
|
|
251
|
-
return /*#__PURE__*/jsx(HeadingNodeComponent, {
|
|
252
|
-
path: childPath,
|
|
253
|
-
node: child
|
|
254
|
-
}, childPath);
|
|
255
|
-
case "paragraph":
|
|
256
|
-
return /*#__PURE__*/jsx(ParagraphNodeComponent, {
|
|
257
|
-
path: childPath,
|
|
258
|
-
node: child
|
|
259
|
-
}, childPath);
|
|
260
|
-
case "list":
|
|
261
|
-
return /*#__PURE__*/jsx(ListNodeComponent, {
|
|
262
|
-
path: childPath,
|
|
263
|
-
node: child
|
|
264
|
-
}, childPath);
|
|
265
|
-
default:
|
|
266
|
-
throw Error("Unknown root node type: " + childType);
|
|
267
|
-
}
|
|
268
|
-
})
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
function TextNodeComponent(_ref2) {
|
|
272
|
-
var _parse, _node$format;
|
|
273
|
-
var node = _ref2.node;
|
|
274
|
-
var styleProps = node.style ? (_parse = parse(node.style)) !== null && _parse !== void 0 ? _parse : {} : {};
|
|
275
|
-
// TODO: Ugly! We should do this before serializing instead
|
|
276
|
-
if (styleProps["font-family"]) {
|
|
277
|
-
styleProps["fontFamily"] = styleProps["font-family"];
|
|
278
|
-
delete styleProps["font-family"];
|
|
279
|
-
}
|
|
280
|
-
if (styleProps["font-size"]) {
|
|
281
|
-
styleProps["fontSize"] = styleProps["font-size"];
|
|
282
|
-
delete styleProps["font-size"];
|
|
283
|
-
}
|
|
284
|
-
var bitmask = (_node$format = node.format) === null || _node$format === void 0 ? void 0 : _node$format.toString(2);
|
|
285
|
-
var bitmaskOffset = bitmask ? bitmask.length - 1 : 0;
|
|
286
|
-
function isBitOne(bit) {
|
|
287
|
-
if (!bitmask) {
|
|
288
|
-
return false;
|
|
289
|
-
}
|
|
290
|
-
return bitmask.length >= bitmaskOffset - bit && bitmask[bitmaskOffset - bit] === "1";
|
|
291
|
-
}
|
|
292
|
-
if (isBitOne(0)) {
|
|
293
|
-
styleProps["fontWeight"] = "bold";
|
|
294
|
-
}
|
|
295
|
-
if (isBitOne(1)) {
|
|
296
|
-
styleProps["fontStyle"] = "italic";
|
|
297
|
-
}
|
|
298
|
-
if (isBitOne(2)) {
|
|
299
|
-
if (!styleProps["textDecoration"]) {
|
|
300
|
-
styleProps["textDecoration"] = "line-through";
|
|
301
|
-
} else {
|
|
302
|
-
styleProps["textDecoration"] += " line-through";
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
if (isBitOne(3)) {
|
|
306
|
-
if (!styleProps["textDecoration"]) {
|
|
307
|
-
styleProps["textDecoration"] = "underline";
|
|
308
|
-
} else {
|
|
309
|
-
styleProps["textDecoration"] += " underline";
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
return /*#__PURE__*/jsx("span", {
|
|
313
|
-
style: styleProps,
|
|
314
|
-
children: node.text
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
function HeadingNodeComponent(_ref3) {
|
|
318
|
-
var node = _ref3.node,
|
|
319
|
-
path = _ref3.path;
|
|
320
|
-
return /*#__PURE__*/createElement(node.tag, {}, node.children.map(function (child, i) {
|
|
321
|
-
var childPath = "".concat(path, ".").concat(i);
|
|
322
|
-
return /*#__PURE__*/jsx(TextNodeComponent, {
|
|
323
|
-
node: child
|
|
324
|
-
}, childPath);
|
|
325
|
-
}));
|
|
326
|
-
}
|
|
327
|
-
function ParagraphNodeComponent(_ref4) {
|
|
328
|
-
var node = _ref4.node,
|
|
329
|
-
path = _ref4.path;
|
|
330
|
-
return /*#__PURE__*/jsx("p", {
|
|
331
|
-
children: node.children.map(function (child, i) {
|
|
332
|
-
var childPath = "".concat(path, ".").concat(i);
|
|
333
|
-
switch (child.type) {
|
|
334
|
-
case "text":
|
|
335
|
-
return /*#__PURE__*/jsx(TextNodeComponent, {
|
|
336
|
-
node: child
|
|
337
|
-
}, childPath);
|
|
338
|
-
default:
|
|
339
|
-
throw Error("Unknown paragraph node type: " + (child === null || child === void 0 ? void 0 : child.type));
|
|
340
|
-
}
|
|
341
|
-
})
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
function ListNodeComponent(_ref5) {
|
|
345
|
-
var node = _ref5.node,
|
|
346
|
-
path = _ref5.path;
|
|
347
|
-
return /*#__PURE__*/createElement(node.tag, {}, node.children.map(function (child, i) {
|
|
348
|
-
var childPath = "".concat(path, ".").concat(i);
|
|
349
|
-
return /*#__PURE__*/jsx(ListItemComponent, {
|
|
350
|
-
path: childPath,
|
|
351
|
-
node: child
|
|
352
|
-
}, childPath);
|
|
353
|
-
}));
|
|
354
|
-
}
|
|
355
|
-
function ListItemComponent(_ref6) {
|
|
356
|
-
var node = _ref6.node,
|
|
357
|
-
path = _ref6.path;
|
|
358
|
-
return /*#__PURE__*/jsx("li", {
|
|
359
|
-
children: node.children.map(function (child, i) {
|
|
360
|
-
var childPath = "".concat(path, ".").concat(i);
|
|
361
|
-
switch (child.type) {
|
|
362
|
-
case "text":
|
|
363
|
-
return /*#__PURE__*/jsx(TextNodeComponent, {
|
|
364
|
-
node: child
|
|
365
|
-
}, childPath);
|
|
366
|
-
default:
|
|
367
|
-
throw Error("Unknown list item node type: " + (child === null || child === void 0 ? void 0 : child.type));
|
|
368
|
-
}
|
|
369
|
-
})
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
export { ValRichText, fetchVal, useVal };
|
|
6
|
+
// NOTE! Side effects:
|
|
7
|
+
autoTagJSX();
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"next",
|
|
9
9
|
"react"
|
|
10
10
|
],
|
|
11
|
-
"version": "0.
|
|
11
|
+
"version": "0.15.0",
|
|
12
12
|
"scripts": {
|
|
13
13
|
"typecheck": "tsc --noEmit",
|
|
14
14
|
"test": "jest"
|
|
@@ -30,11 +30,9 @@
|
|
|
30
30
|
"exports": true
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@valbuild/core": "~0.
|
|
34
|
-
"@valbuild/react": "~0.
|
|
35
|
-
"@valbuild/server": "~0.
|
|
36
|
-
"@vercel/stega": "^0.0.5",
|
|
37
|
-
"style-to-object": "^0.4.1"
|
|
33
|
+
"@valbuild/core": "~0.15.0",
|
|
34
|
+
"@valbuild/react": "~0.15.0",
|
|
35
|
+
"@valbuild/server": "~0.15.0"
|
|
38
36
|
},
|
|
39
37
|
"peerDependencies": {
|
|
40
38
|
"next": ">=12.3.4",
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
export * from "@valbuild/core";
|
|
2
2
|
|
|
3
3
|
export { ValProvider } from "@valbuild/react";
|
|
4
|
-
export {
|
|
5
|
-
|
|
6
|
-
export
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
4
|
+
export { ValRichText } from "@valbuild/react";
|
|
5
|
+
|
|
6
|
+
export { useVal } from "@valbuild/react/stega";
|
|
7
|
+
export { type ValEncodedString } from "@valbuild/react/stega";
|
|
8
|
+
export { fetchVal } from "@valbuild/react/stega";
|
|
9
|
+
|
|
10
|
+
// Auto-tag JSX with Val paths:
|
|
11
|
+
import { autoTagJSX } from "@valbuild/react/stega";
|
|
12
|
+
|
|
13
|
+
// NOTE! Side effects:
|
|
14
|
+
autoTagJSX();
|
package/tsconfig.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { SelectorSource, SelectorOf, GenericSelector } from "@valbuild/core";
|
|
2
|
-
import { StegaOfSource } from "./stegaEncode";
|
|
3
|
-
export declare function fetchVal<T extends SelectorSource>(selector: T, locale?: string): SelectorOf<T> extends GenericSelector<infer S> ? Promise<StegaOfSource<S>> : never;
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { GenericSelector, SelectorOf, SelectorSource } from "@valbuild/core";
|
|
2
|
-
import { StegaOfSource } from "../stegaEncode";
|
|
3
|
-
export declare function useVal<T extends SelectorSource>(selector: T, locale?: string): SelectorOf<T> extends GenericSelector<infer S> ? StegaOfSource<S> : never;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Json, Val, RichTextSource, RichText } from "@valbuild/core";
|
|
2
|
-
import { FileSource, RemoteSource, Source, SourceObject } from "@valbuild/core";
|
|
3
|
-
import { JsonPrimitive } from "@valbuild/core/src/Json";
|
|
4
|
-
import { SourceArray } from "@valbuild/core/src/source";
|
|
5
|
-
import { I18nSource } from "@valbuild/core/src/source/i18n";
|
|
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 {};
|
package/src/ValRichText.tsx
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
import {
|
|
3
|
-
HeadingNode,
|
|
4
|
-
ListItemNode,
|
|
5
|
-
ListNode,
|
|
6
|
-
ParagraphNode,
|
|
7
|
-
RichText,
|
|
8
|
-
SourcePath,
|
|
9
|
-
TextNode,
|
|
10
|
-
} from "@valbuild/core";
|
|
11
|
-
import { createElement } from "react";
|
|
12
|
-
import parse from "style-to-object";
|
|
13
|
-
|
|
14
|
-
export function ValRichText({ children }: { children: RichText }) {
|
|
15
|
-
const root: RichText = children;
|
|
16
|
-
const path = root.valPath;
|
|
17
|
-
return (
|
|
18
|
-
<div data-val-path={path}>
|
|
19
|
-
{root.children.map((child, i) => {
|
|
20
|
-
const childType = child.type;
|
|
21
|
-
const childPath = `${path}.${i}` as SourcePath;
|
|
22
|
-
console.log(`'${childType}', ${childPath}`);
|
|
23
|
-
switch (childType) {
|
|
24
|
-
case "heading":
|
|
25
|
-
return (
|
|
26
|
-
<HeadingNodeComponent
|
|
27
|
-
key={childPath}
|
|
28
|
-
path={childPath}
|
|
29
|
-
node={child}
|
|
30
|
-
/>
|
|
31
|
-
);
|
|
32
|
-
case "paragraph":
|
|
33
|
-
return (
|
|
34
|
-
<ParagraphNodeComponent
|
|
35
|
-
key={childPath}
|
|
36
|
-
path={childPath}
|
|
37
|
-
node={child}
|
|
38
|
-
/>
|
|
39
|
-
);
|
|
40
|
-
case "list":
|
|
41
|
-
return (
|
|
42
|
-
<ListNodeComponent
|
|
43
|
-
key={childPath}
|
|
44
|
-
path={childPath}
|
|
45
|
-
node={child}
|
|
46
|
-
/>
|
|
47
|
-
);
|
|
48
|
-
default:
|
|
49
|
-
throw Error("Unknown root node type: " + childType);
|
|
50
|
-
}
|
|
51
|
-
})}
|
|
52
|
-
</div>
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function TextNodeComponent({ node }: { node: TextNode }) {
|
|
57
|
-
const styleProps = node.style ? parse(node.style) ?? {} : {};
|
|
58
|
-
// TODO: Ugly! We should do this before serializing instead
|
|
59
|
-
if (styleProps["font-family"]) {
|
|
60
|
-
styleProps["fontFamily"] = styleProps["font-family"];
|
|
61
|
-
delete styleProps["font-family"];
|
|
62
|
-
}
|
|
63
|
-
if (styleProps["font-size"]) {
|
|
64
|
-
styleProps["fontSize"] = styleProps["font-size"];
|
|
65
|
-
delete styleProps["font-size"];
|
|
66
|
-
}
|
|
67
|
-
const bitmask = node.format?.toString(2);
|
|
68
|
-
const bitmaskOffset = bitmask ? bitmask.length - 1 : 0;
|
|
69
|
-
function isBitOne(bit: number) {
|
|
70
|
-
if (!bitmask) {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
return (
|
|
74
|
-
bitmask.length >= bitmaskOffset - bit &&
|
|
75
|
-
bitmask[bitmaskOffset - bit] === "1"
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
if (isBitOne(0)) {
|
|
79
|
-
styleProps["fontWeight"] = "bold";
|
|
80
|
-
}
|
|
81
|
-
if (isBitOne(1)) {
|
|
82
|
-
styleProps["fontStyle"] = "italic";
|
|
83
|
-
}
|
|
84
|
-
if (isBitOne(2)) {
|
|
85
|
-
if (!styleProps["textDecoration"]) {
|
|
86
|
-
styleProps["textDecoration"] = "line-through";
|
|
87
|
-
} else {
|
|
88
|
-
styleProps["textDecoration"] += " line-through";
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (isBitOne(3)) {
|
|
92
|
-
if (!styleProps["textDecoration"]) {
|
|
93
|
-
styleProps["textDecoration"] = "underline";
|
|
94
|
-
} else {
|
|
95
|
-
styleProps["textDecoration"] += " underline";
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
return <span style={styleProps}>{node.text}</span>;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function HeadingNodeComponent({
|
|
102
|
-
node,
|
|
103
|
-
path,
|
|
104
|
-
}: {
|
|
105
|
-
path: SourcePath;
|
|
106
|
-
node: HeadingNode;
|
|
107
|
-
}) {
|
|
108
|
-
return createElement(
|
|
109
|
-
node.tag,
|
|
110
|
-
{},
|
|
111
|
-
node.children.map((child, i) => {
|
|
112
|
-
const childPath = `${path}.${i}` as SourcePath;
|
|
113
|
-
return <TextNodeComponent key={childPath} node={child} />;
|
|
114
|
-
})
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function ParagraphNodeComponent({
|
|
119
|
-
node,
|
|
120
|
-
path,
|
|
121
|
-
}: {
|
|
122
|
-
path: SourcePath;
|
|
123
|
-
node: ParagraphNode;
|
|
124
|
-
}) {
|
|
125
|
-
return (
|
|
126
|
-
<p>
|
|
127
|
-
{node.children.map((child, i) => {
|
|
128
|
-
const childPath = `${path}.${i}` as SourcePath;
|
|
129
|
-
switch (child.type) {
|
|
130
|
-
case "text":
|
|
131
|
-
return <TextNodeComponent key={childPath} node={child} />;
|
|
132
|
-
default:
|
|
133
|
-
throw Error("Unknown paragraph node type: " + (child as any)?.type);
|
|
134
|
-
}
|
|
135
|
-
})}
|
|
136
|
-
</p>
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function ListNodeComponent({
|
|
141
|
-
node,
|
|
142
|
-
path,
|
|
143
|
-
}: {
|
|
144
|
-
path: SourcePath;
|
|
145
|
-
node: ListNode;
|
|
146
|
-
}) {
|
|
147
|
-
return createElement(
|
|
148
|
-
node.tag,
|
|
149
|
-
{},
|
|
150
|
-
node.children.map((child, i) => {
|
|
151
|
-
const childPath = `${path}.${i}` as SourcePath;
|
|
152
|
-
return (
|
|
153
|
-
<ListItemComponent key={childPath} path={childPath} node={child} />
|
|
154
|
-
);
|
|
155
|
-
})
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function ListItemComponent({
|
|
160
|
-
node,
|
|
161
|
-
path,
|
|
162
|
-
}: {
|
|
163
|
-
path: SourcePath;
|
|
164
|
-
node: ListItemNode;
|
|
165
|
-
}) {
|
|
166
|
-
return (
|
|
167
|
-
<li>
|
|
168
|
-
{node.children.map((child, i) => {
|
|
169
|
-
const childPath = `${path}.${i}` as SourcePath;
|
|
170
|
-
switch (child.type) {
|
|
171
|
-
case "text":
|
|
172
|
-
return <TextNodeComponent key={childPath} node={child} />;
|
|
173
|
-
default:
|
|
174
|
-
throw Error("Unknown list item node type: " + (child as any)?.type);
|
|
175
|
-
}
|
|
176
|
-
})}
|
|
177
|
-
</li>
|
|
178
|
-
);
|
|
179
|
-
}
|