@valbuild/react 0.18.0 → 0.20.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.
@@ -7,7 +7,6 @@ import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
7
7
  import { useValApi } from './valbuild-react.esm.js';
8
8
  import './defineProperty-b209a901.esm.js';
9
9
  import '@valbuild/core/fp';
10
- import 'style-to-object';
11
10
 
12
11
  function ShadowContent(_ref) {
13
12
  var root = _ref.root,
@@ -15,7 +14,8 @@ function ShadowContent(_ref) {
15
14
  return /*#__PURE__*/createPortal(children, root);
16
15
  }
17
16
  var ShadowRoot = function ShadowRoot(_ref2) {
18
- var children = _ref2.children;
17
+ var children = _ref2.children,
18
+ style = _ref2.style;
19
19
  var node = useRef(null);
20
20
  var _useState = useState(null),
21
21
  _useState2 = _slicedToArray(_useState, 2),
@@ -35,6 +35,7 @@ var ShadowRoot = function ShadowRoot(_ref2) {
35
35
  }, []);
36
36
  return /*#__PURE__*/jsx("div", {
37
37
  ref: node,
38
+ style: style,
38
39
  children: root && /*#__PURE__*/jsx(ShadowContent, {
39
40
  root: root,
40
41
  children: children
@@ -82,6 +83,12 @@ function ValUI() {
82
83
  }
83
84
  return /*#__PURE__*/jsx(Fragment, {
84
85
  children: /*#__PURE__*/jsxs(ShadowRoot, {
86
+ style: {
87
+ position: "absolute",
88
+ top: 0,
89
+ left: 0,
90
+ zIndex: 8999 // 1 less than the NextJS error z-index: 9000
91
+ },
85
92
  children: [/*#__PURE__*/jsx("link", {
86
93
  rel: "preconnect",
87
94
  href: "https://fonts.googleapis.com"
@@ -9,7 +9,6 @@ var ReactJSXRuntime = require('react/jsx-runtime');
9
9
  var dist_valbuildReact = require('./valbuild-react.cjs.dev.js');
10
10
  require('./defineProperty-c82a49b0.cjs.dev.js');
11
11
  require('@valbuild/core/fp');
12
- require('style-to-object');
13
12
 
14
13
  function ShadowContent(_ref) {
15
14
  var root = _ref.root,
@@ -17,7 +16,8 @@ function ShadowContent(_ref) {
17
16
  return /*#__PURE__*/reactDom.createPortal(children, root);
18
17
  }
19
18
  var ShadowRoot = function ShadowRoot(_ref2) {
20
- var children = _ref2.children;
19
+ var children = _ref2.children,
20
+ style = _ref2.style;
21
21
  var node = React.useRef(null);
22
22
  var _useState = React.useState(null),
23
23
  _useState2 = slicedToArray._slicedToArray(_useState, 2),
@@ -37,6 +37,7 @@ var ShadowRoot = function ShadowRoot(_ref2) {
37
37
  }, []);
38
38
  return /*#__PURE__*/ReactJSXRuntime.jsx("div", {
39
39
  ref: node,
40
+ style: style,
40
41
  children: root && /*#__PURE__*/ReactJSXRuntime.jsx(ShadowContent, {
41
42
  root: root,
42
43
  children: children
@@ -84,6 +85,12 @@ function ValUI() {
84
85
  }
85
86
  return /*#__PURE__*/ReactJSXRuntime.jsx(ReactJSXRuntime.Fragment, {
86
87
  children: /*#__PURE__*/ReactJSXRuntime.jsxs(ShadowRoot, {
88
+ style: {
89
+ position: "absolute",
90
+ top: 0,
91
+ left: 0,
92
+ zIndex: 8999 // 1 less than the NextJS error z-index: 9000
93
+ },
87
94
  children: [/*#__PURE__*/ReactJSXRuntime.jsx("link", {
88
95
  rel: "preconnect",
89
96
  href: "https://fonts.googleapis.com"
@@ -7,7 +7,6 @@ import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
7
7
  import { useValApi } from './valbuild-react.browser.esm.js';
8
8
  import './defineProperty-034d0378.browser.esm.js';
9
9
  import '@valbuild/core/fp';
10
- import 'style-to-object';
11
10
 
12
11
  function ShadowContent(_ref) {
13
12
  var root = _ref.root,
@@ -15,7 +14,8 @@ function ShadowContent(_ref) {
15
14
  return /*#__PURE__*/createPortal(children, root);
16
15
  }
17
16
  var ShadowRoot = function ShadowRoot(_ref2) {
18
- var children = _ref2.children;
17
+ var children = _ref2.children,
18
+ style = _ref2.style;
19
19
  var node = useRef(null);
20
20
  var _useState = useState(null),
21
21
  _useState2 = _slicedToArray(_useState, 2),
@@ -35,6 +35,7 @@ var ShadowRoot = function ShadowRoot(_ref2) {
35
35
  }, []);
36
36
  return /*#__PURE__*/jsx("div", {
37
37
  ref: node,
38
+ style: style,
38
39
  children: root && /*#__PURE__*/jsx(ShadowContent, {
39
40
  root: root,
40
41
  children: children
@@ -82,6 +83,12 @@ function ValUI() {
82
83
  }
83
84
  return /*#__PURE__*/jsx(Fragment, {
84
85
  children: /*#__PURE__*/jsxs(ShadowRoot, {
86
+ style: {
87
+ position: "absolute",
88
+ top: 0,
89
+ left: 0,
90
+ zIndex: 8999 // 1 less than the NextJS error z-index: 9000
91
+ },
85
92
  children: [/*#__PURE__*/jsx("link", {
86
93
  rel: "preconnect",
87
94
  href: "https://fonts.googleapis.com"
@@ -9,7 +9,6 @@ var ReactJSXRuntime = require('react/jsx-runtime');
9
9
  var dist_valbuildReact = require('./valbuild-react.cjs.prod.js');
10
10
  require('./defineProperty-36ed93cd.cjs.prod.js');
11
11
  require('@valbuild/core/fp');
12
- require('style-to-object');
13
12
 
14
13
  function ShadowContent(_ref) {
15
14
  var root = _ref.root,
@@ -17,7 +16,8 @@ function ShadowContent(_ref) {
17
16
  return /*#__PURE__*/reactDom.createPortal(children, root);
18
17
  }
19
18
  var ShadowRoot = function ShadowRoot(_ref2) {
20
- var children = _ref2.children;
19
+ var children = _ref2.children,
20
+ style = _ref2.style;
21
21
  var node = React.useRef(null);
22
22
  var _useState = React.useState(null),
23
23
  _useState2 = slicedToArray._slicedToArray(_useState, 2),
@@ -37,6 +37,7 @@ var ShadowRoot = function ShadowRoot(_ref2) {
37
37
  }, []);
38
38
  return /*#__PURE__*/ReactJSXRuntime.jsx("div", {
39
39
  ref: node,
40
+ style: style,
40
41
  children: root && /*#__PURE__*/ReactJSXRuntime.jsx(ShadowContent, {
41
42
  root: root,
42
43
  children: children
@@ -84,6 +85,12 @@ function ValUI() {
84
85
  }
85
86
  return /*#__PURE__*/ReactJSXRuntime.jsx(ReactJSXRuntime.Fragment, {
86
87
  children: /*#__PURE__*/ReactJSXRuntime.jsxs(ShadowRoot, {
88
+ style: {
89
+ position: "absolute",
90
+ top: 0,
91
+ left: 0,
92
+ zIndex: 8999 // 1 less than the NextJS error z-index: 9000
93
+ },
87
94
  children: [/*#__PURE__*/ReactJSXRuntime.jsx("link", {
88
95
  rel: "preconnect",
89
96
  href: "https://fonts.googleapis.com"
@@ -1,5 +1,23 @@
1
1
  /// <reference types="react" />
2
- import { RichText } from "@valbuild/core";
3
- export declare function ValRichText({ children }: {
4
- children: RichText;
2
+ import { RichText, RichTextOptions } from "@valbuild/core";
3
+ type Tags = keyof Pick<RichTextOptions, "img" | "ul" | "ol">;
4
+ type Classes = keyof Pick<RichTextOptions, "bold" | "italic" | "lineThrough">;
5
+ type ThemeOptions<O extends RichTextOptions> = {
6
+ tags: (O["headings"] extends Array<unknown> ? {
7
+ [Key in O["headings"][number]]: string;
8
+ } : {}) & {
9
+ [Key in Tags & keyof O as O[Key] extends true ? Key extends "ul" | "ol" ? Key | "li" : Key : never]: string;
10
+ } & {
11
+ p?: string;
12
+ };
13
+ classes: {
14
+ [Key in Classes & keyof O as O[Key] extends true ? Key : never]: string;
15
+ } & (O["img"] extends true ? {
16
+ imgContainer?: string;
17
+ } : {});
18
+ };
19
+ export declare function ValRichText<O extends RichTextOptions>({ theme, children, }: {
20
+ theme: ThemeOptions<O>;
21
+ children: RichText<O>;
5
22
  }): JSX.Element;
23
+ export {};
@@ -1,2 +1,2 @@
1
1
  export { autoTagJSX } from "./autoTagJSX.js";
2
- export { transform, getModuleIds, type ValEncodedString, type StegaOfSource, } from "./transform.js";
2
+ export { stegaEncode, getModuleIds, type ValEncodedString, type StegaOfSource, } from "./stegaEncode.js";
@@ -14,12 +14,12 @@ declare const brand: unique symbol;
14
14
  export type ValEncodedString = string & {
15
15
  [brand]: "ValEncodedString";
16
16
  };
17
- export type StegaOfSource<T extends Source> = Json extends T ? Json : T extends RichTextSource ? RichText : T extends FileSource ? {
17
+ export type StegaOfSource<T extends Source> = Json extends T ? Json : T extends RichTextSource<infer O> ? RichText<O> : T extends FileSource ? {
18
18
  url: ValEncodedString;
19
19
  } : T extends SourceObject ? {
20
20
  [key in keyof T]: StegaOfSource<T[key]>;
21
21
  } : T extends SourceArray ? StegaOfSource<T[number]>[] : T extends string ? ValEncodedString : T extends JsonPrimitive ? T : never;
22
- export declare function transform(input: any, opts: {
22
+ export declare function stegaEncode(input: any, opts: {
23
23
  getModule?: (moduleId: string) => any;
24
24
  disabled?: boolean;
25
25
  }): any;
@@ -1,10 +1,9 @@
1
- import React, { useContext, useMemo, lazy, createElement } from 'react';
1
+ import React, { useContext, useMemo, lazy } from 'react';
2
2
  import { _ as _unsupportedIterableToArray, a as _slicedToArray } from './slicedToArray-0cbb3d34.browser.esm.js';
3
3
  import { _ as _toPropertyKey, a as _defineProperty } from './defineProperty-034d0378.browser.esm.js';
4
4
  import { result } from '@valbuild/core/fp';
5
5
  import { ValApi } from '@valbuild/core';
6
6
  import { jsxs, jsx } from 'react/jsx-runtime';
7
- import parse from 'style-to-object';
8
7
 
9
8
  function _createForOfIteratorHelper(o, allowArrayLike) {
10
9
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
@@ -599,7 +598,7 @@ var ValContext = /*#__PURE__*/React.createContext({
599
598
  }
600
599
  });
601
600
  var ValUI = /*#__PURE__*/lazy(function () {
602
- return import('./ValUI-64e3e5f2.browser.esm.js');
601
+ return import('./ValUI-b51ca60e.browser.esm.js');
603
602
  }) ;
604
603
  function ValProvider(_ref) {
605
604
  var _ref$host = _ref.host,
@@ -620,136 +619,138 @@ function ValProvider(_ref) {
620
619
  });
621
620
  }
622
621
 
622
+ /* eslint-disable @typescript-eslint/ban-types */
623
623
  function ValRichText(_ref) {
624
- var children = _ref.children;
624
+ var theme = _ref.theme,
625
+ children = _ref.children;
625
626
  var root = children;
626
- var path = root.valPath;
627
- return /*#__PURE__*/jsx("div", {
628
- "data-val-path": path,
629
- children: root.children.map(function (child, i) {
630
- var childType = child.type;
631
- var childPath = "".concat(path, ".").concat(i);
632
- switch (childType) {
633
- case "heading":
634
- return /*#__PURE__*/jsx(HeadingNodeComponent, {
635
- path: childPath,
636
- node: child
637
- }, childPath);
638
- case "paragraph":
639
- return /*#__PURE__*/jsx(ParagraphNodeComponent, {
640
- path: childPath,
641
- node: child
642
- }, childPath);
643
- case "list":
644
- return /*#__PURE__*/jsx(ListNodeComponent, {
645
- path: childPath,
646
- node: child
647
- }, childPath);
648
- default:
649
- throw Error("Unknown root node type: " + childType);
650
- }
651
- })
652
- });
653
- }
654
- function TextNodeComponent(_ref2) {
655
- var _parse, _node$format;
656
- var node = _ref2.node;
657
- var styleProps = node.style ? (_parse = parse(node.style)) !== null && _parse !== void 0 ? _parse : {} : {};
658
- // TODO: Ugly! We should do this before serializing instead
659
- if (styleProps["font-family"]) {
660
- styleProps["fontFamily"] = styleProps["font-family"];
661
- delete styleProps["font-family"];
662
- }
663
- if (styleProps["font-size"]) {
664
- styleProps["fontSize"] = styleProps["font-size"];
665
- delete styleProps["font-size"];
666
- }
667
- var bitmask = (_node$format = node.format) === null || _node$format === void 0 ? void 0 : _node$format.toString(2);
668
- var bitmaskOffset = bitmask ? bitmask.length - 1 : 0;
669
- function isBitOne(bit) {
670
- if (!bitmask) {
671
- return false;
627
+ function withRenderTag(clazz, current) {
628
+ var renderClass = theme.tags[clazz];
629
+ if (renderClass && current) {
630
+ return [current, renderClass].join(" ");
672
631
  }
673
- return bitmask.length >= bitmaskOffset - bit && bitmask[bitmaskOffset - bit] === "1";
674
- }
675
- if (isBitOne(0)) {
676
- styleProps["fontWeight"] = "bold";
677
- }
678
- if (isBitOne(1)) {
679
- styleProps["fontStyle"] = "italic";
632
+ if (renderClass) {
633
+ return renderClass;
634
+ }
635
+ return current;
680
636
  }
681
- if (isBitOne(2)) {
682
- if (!styleProps["textDecoration"]) {
683
- styleProps["textDecoration"] = "line-through";
684
- } else {
685
- styleProps["textDecoration"] += " line-through";
637
+ function withRenderClass(clazz, current) {
638
+ var renderClass = theme.classes[clazz];
639
+ if (renderClass && current) {
640
+ return [current, renderClass].join(" ");
641
+ }
642
+ if (renderClass) {
643
+ return renderClass;
686
644
  }
645
+ return current;
687
646
  }
688
- if (isBitOne(3)) {
689
- if (!styleProps["textDecoration"]) {
690
- styleProps["textDecoration"] = "underline";
691
- } else {
692
- styleProps["textDecoration"] += " underline";
647
+ function toReact(node, key) {
648
+ var _anyNode$class, _anyNode$children;
649
+ if (typeof node === "string") {
650
+ return node;
651
+ }
652
+ if (node.tag === "p") {
653
+ return /*#__PURE__*/jsx("p", {
654
+ className: withRenderTag("p"),
655
+ children: node.children.map(toReact)
656
+ }, key);
657
+ }
658
+ if (node.tag === "img") {
659
+ return /*#__PURE__*/jsx("div", {
660
+ className: withRenderClass("imgContainer"),
661
+ children: /*#__PURE__*/jsx("img", {
662
+ className: withRenderTag("img"),
663
+ src: node.src
664
+ })
665
+ }, key);
666
+ }
667
+ // if (node.tag === "blockquote") {
668
+ // return <blockquote key={key}>{node.children.map(toReact)}</blockquote>;
669
+ // }
670
+ if (node.tag === "ul") {
671
+ return /*#__PURE__*/jsx("ul", {
672
+ className: withRenderTag("ul"),
673
+ children: node.children.map(toReact)
674
+ }, key);
675
+ }
676
+ if (node.tag === "ol") {
677
+ return /*#__PURE__*/jsx("ol", {
678
+ className: withRenderTag("ol"),
679
+ children: node.children.map(toReact)
680
+ }, key);
681
+ }
682
+ if (node.tag === "li") {
683
+ return /*#__PURE__*/jsx("li", {
684
+ className: withRenderTag("li"),
685
+ children: node.children.map(toReact)
686
+ }, key);
687
+ }
688
+ if (node.tag === "span") {
689
+ return /*#__PURE__*/jsx("span", {
690
+ className: node.classes.map(function (nodeClass) {
691
+ switch (nodeClass) {
692
+ case "bold":
693
+ return withRenderClass("bold");
694
+ case "line-through":
695
+ return withRenderClass("lineThrough");
696
+ case "italic":
697
+ return withRenderClass("italic");
698
+ }
699
+ }).join(" "),
700
+ children: node.children.map(toReact)
701
+ }, key);
693
702
  }
703
+ if (node.tag === "h1") {
704
+ return /*#__PURE__*/jsx("h1", {
705
+ className: withRenderTag("h1"),
706
+ children: node.children.map(toReact)
707
+ }, key);
708
+ }
709
+ if (node.tag === "h2") {
710
+ return /*#__PURE__*/jsx("h2", {
711
+ className: withRenderTag("h2"),
712
+ children: node.children.map(toReact)
713
+ }, key);
714
+ }
715
+ if (node.tag === "h3") {
716
+ return /*#__PURE__*/jsx("h3", {
717
+ className: withRenderTag("h3"),
718
+ children: node.children.map(toReact)
719
+ }, key);
720
+ }
721
+ if (node.tag === "h4") {
722
+ return /*#__PURE__*/jsx("h4", {
723
+ className: withRenderTag("h4"),
724
+ children: node.children.map(toReact)
725
+ }, key);
726
+ }
727
+ if (node.tag === "h5") {
728
+ return /*#__PURE__*/jsx("h5", {
729
+ className: withRenderTag("h5"),
730
+ children: node.children.map(toReact)
731
+ }, key);
732
+ }
733
+ if (node.tag === "h6") {
734
+ return /*#__PURE__*/jsx("h6", {
735
+ className: withRenderTag("h6"),
736
+ children: node.children.map(toReact)
737
+ }, key);
738
+ }
739
+ console.error("Unknown tag", node.tag);
740
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
741
+ var anyNode = node;
742
+ if (!(anyNode !== null && anyNode !== void 0 && anyNode.tag)) {
743
+ return null;
744
+ }
745
+ return /*#__PURE__*/React.createElement(anyNode.tag, {
746
+ key: key,
747
+ className: (_anyNode$class = anyNode["class"]) === null || _anyNode$class === void 0 ? void 0 : _anyNode$class.join(" "),
748
+ children: (_anyNode$children = anyNode.children) === null || _anyNode$children === void 0 ? void 0 : _anyNode$children.map(toReact)
749
+ });
694
750
  }
695
- return /*#__PURE__*/jsx("span", {
696
- style: styleProps,
697
- children: node.text
698
- });
699
- }
700
- function HeadingNodeComponent(_ref3) {
701
- var node = _ref3.node,
702
- path = _ref3.path;
703
- return /*#__PURE__*/createElement(node.tag, {}, node.children.map(function (child, i) {
704
- var childPath = "".concat(path, ".").concat(i);
705
- return /*#__PURE__*/jsx(TextNodeComponent, {
706
- node: child
707
- }, childPath);
708
- }));
709
- }
710
- function ParagraphNodeComponent(_ref4) {
711
- var node = _ref4.node,
712
- path = _ref4.path;
713
- return /*#__PURE__*/jsx("p", {
714
- children: node.children.map(function (child, i) {
715
- var childPath = "".concat(path, ".").concat(i);
716
- switch (child.type) {
717
- case "text":
718
- return /*#__PURE__*/jsx(TextNodeComponent, {
719
- node: child
720
- }, childPath);
721
- default:
722
- throw Error("Unknown paragraph node type: " + (child === null || child === void 0 ? void 0 : child.type));
723
- }
724
- })
725
- });
726
- }
727
- function ListNodeComponent(_ref5) {
728
- var node = _ref5.node,
729
- path = _ref5.path;
730
- return /*#__PURE__*/createElement(node.tag, {}, node.children.map(function (child, i) {
731
- var childPath = "".concat(path, ".").concat(i);
732
- return /*#__PURE__*/jsx(ListItemComponent, {
733
- path: childPath,
734
- node: child
735
- }, childPath);
736
- }));
737
- }
738
- function ListItemComponent(_ref6) {
739
- var node = _ref6.node,
740
- path = _ref6.path;
741
- return /*#__PURE__*/jsx("li", {
742
- children: node.children.map(function (child, i) {
743
- var childPath = "".concat(path, ".").concat(i);
744
- switch (child.type) {
745
- case "text":
746
- return /*#__PURE__*/jsx(TextNodeComponent, {
747
- node: child
748
- }, childPath);
749
- default:
750
- throw Error("Unknown list item node type: " + (child === null || child === void 0 ? void 0 : child.type));
751
- }
752
- })
751
+ return /*#__PURE__*/jsx("div", {
752
+ "data-val-path": root.valPath,
753
+ children: root.children.map(toReact)
753
754
  });
754
755
  }
755
756