@valbuild/react 0.18.0 → 0.19.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.
@@ -8,12 +8,10 @@ var defineProperty = require('./defineProperty-c82a49b0.cjs.dev.js');
8
8
  var fp = require('@valbuild/core/fp');
9
9
  var core = require('@valbuild/core');
10
10
  var ReactJSXRuntime = require('react/jsx-runtime');
11
- var parse = require('style-to-object');
12
11
 
13
12
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
14
13
 
15
14
  var React__default = /*#__PURE__*/_interopDefault(React);
16
- var parse__default = /*#__PURE__*/_interopDefault(parse);
17
15
 
18
16
  function _createForOfIteratorHelper(o, allowArrayLike) {
19
17
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
@@ -608,7 +606,7 @@ var ValContext = /*#__PURE__*/React__default["default"].createContext({
608
606
  }
609
607
  });
610
608
  var ValUI = typeof window !== "undefined" ? /*#__PURE__*/React.lazy(function () {
611
- return Promise.resolve().then(function () { return require('./ValUI-9ac161d2.cjs.dev.js'); });
609
+ return Promise.resolve().then(function () { return require('./ValUI-7d465071.cjs.dev.js'); });
612
610
  }) : null;
613
611
  function ValProvider(_ref) {
614
612
  var _ref$host = _ref.host,
@@ -629,136 +627,138 @@ function ValProvider(_ref) {
629
627
  });
630
628
  }
631
629
 
630
+ /* eslint-disable @typescript-eslint/ban-types */
632
631
  function ValRichText(_ref) {
633
- var children = _ref.children;
632
+ var theme = _ref.theme,
633
+ children = _ref.children;
634
634
  var root = children;
635
- var path = root.valPath;
636
- return /*#__PURE__*/ReactJSXRuntime.jsx("div", {
637
- "data-val-path": path,
638
- children: root.children.map(function (child, i) {
639
- var childType = child.type;
640
- var childPath = "".concat(path, ".").concat(i);
641
- switch (childType) {
642
- case "heading":
643
- return /*#__PURE__*/ReactJSXRuntime.jsx(HeadingNodeComponent, {
644
- path: childPath,
645
- node: child
646
- }, childPath);
647
- case "paragraph":
648
- return /*#__PURE__*/ReactJSXRuntime.jsx(ParagraphNodeComponent, {
649
- path: childPath,
650
- node: child
651
- }, childPath);
652
- case "list":
653
- return /*#__PURE__*/ReactJSXRuntime.jsx(ListNodeComponent, {
654
- path: childPath,
655
- node: child
656
- }, childPath);
657
- default:
658
- throw Error("Unknown root node type: " + childType);
659
- }
660
- })
661
- });
662
- }
663
- function TextNodeComponent(_ref2) {
664
- var _parse, _node$format;
665
- var node = _ref2.node;
666
- var styleProps = node.style ? (_parse = parse__default["default"](node.style)) !== null && _parse !== void 0 ? _parse : {} : {};
667
- // TODO: Ugly! We should do this before serializing instead
668
- if (styleProps["font-family"]) {
669
- styleProps["fontFamily"] = styleProps["font-family"];
670
- delete styleProps["font-family"];
671
- }
672
- if (styleProps["font-size"]) {
673
- styleProps["fontSize"] = styleProps["font-size"];
674
- delete styleProps["font-size"];
675
- }
676
- var bitmask = (_node$format = node.format) === null || _node$format === void 0 ? void 0 : _node$format.toString(2);
677
- var bitmaskOffset = bitmask ? bitmask.length - 1 : 0;
678
- function isBitOne(bit) {
679
- if (!bitmask) {
680
- return false;
635
+ function withRenderTag(clazz, current) {
636
+ var renderClass = theme.tags[clazz];
637
+ if (renderClass && current) {
638
+ return [current, renderClass].join(" ");
681
639
  }
682
- return bitmask.length >= bitmaskOffset - bit && bitmask[bitmaskOffset - bit] === "1";
683
- }
684
- if (isBitOne(0)) {
685
- styleProps["fontWeight"] = "bold";
686
- }
687
- if (isBitOne(1)) {
688
- styleProps["fontStyle"] = "italic";
640
+ if (renderClass) {
641
+ return renderClass;
642
+ }
643
+ return current;
689
644
  }
690
- if (isBitOne(2)) {
691
- if (!styleProps["textDecoration"]) {
692
- styleProps["textDecoration"] = "line-through";
693
- } else {
694
- styleProps["textDecoration"] += " line-through";
645
+ function withRenderClass(clazz, current) {
646
+ var renderClass = theme.classes[clazz];
647
+ if (renderClass && current) {
648
+ return [current, renderClass].join(" ");
649
+ }
650
+ if (renderClass) {
651
+ return renderClass;
695
652
  }
653
+ return current;
696
654
  }
697
- if (isBitOne(3)) {
698
- if (!styleProps["textDecoration"]) {
699
- styleProps["textDecoration"] = "underline";
700
- } else {
701
- styleProps["textDecoration"] += " underline";
655
+ function toReact(node, key) {
656
+ var _anyNode$class, _anyNode$children;
657
+ if (typeof node === "string") {
658
+ return node;
659
+ }
660
+ if (node.tag === "p") {
661
+ return /*#__PURE__*/ReactJSXRuntime.jsx("p", {
662
+ className: withRenderTag("p"),
663
+ children: node.children.map(toReact)
664
+ }, key);
665
+ }
666
+ if (node.tag === "img") {
667
+ return /*#__PURE__*/ReactJSXRuntime.jsx("div", {
668
+ className: withRenderClass("imgContainer"),
669
+ children: /*#__PURE__*/ReactJSXRuntime.jsx("img", {
670
+ className: withRenderTag("img"),
671
+ src: node.src
672
+ })
673
+ }, key);
674
+ }
675
+ // if (node.tag === "blockquote") {
676
+ // return <blockquote key={key}>{node.children.map(toReact)}</blockquote>;
677
+ // }
678
+ if (node.tag === "ul") {
679
+ return /*#__PURE__*/ReactJSXRuntime.jsx("ul", {
680
+ className: withRenderTag("ul"),
681
+ children: node.children.map(toReact)
682
+ }, key);
683
+ }
684
+ if (node.tag === "ol") {
685
+ return /*#__PURE__*/ReactJSXRuntime.jsx("ol", {
686
+ className: withRenderTag("ol"),
687
+ children: node.children.map(toReact)
688
+ }, key);
689
+ }
690
+ if (node.tag === "li") {
691
+ return /*#__PURE__*/ReactJSXRuntime.jsx("li", {
692
+ className: withRenderTag("li"),
693
+ children: node.children.map(toReact)
694
+ }, key);
695
+ }
696
+ if (node.tag === "span") {
697
+ return /*#__PURE__*/ReactJSXRuntime.jsx("span", {
698
+ className: node.classes.map(function (nodeClass) {
699
+ switch (nodeClass) {
700
+ case "bold":
701
+ return withRenderClass("bold");
702
+ case "line-through":
703
+ return withRenderClass("lineThrough");
704
+ case "italic":
705
+ return withRenderClass("italic");
706
+ }
707
+ }).join(" "),
708
+ children: node.children.map(toReact)
709
+ }, key);
702
710
  }
711
+ if (node.tag === "h1") {
712
+ return /*#__PURE__*/ReactJSXRuntime.jsx("h1", {
713
+ className: withRenderTag("h1"),
714
+ children: node.children.map(toReact)
715
+ }, key);
716
+ }
717
+ if (node.tag === "h2") {
718
+ return /*#__PURE__*/ReactJSXRuntime.jsx("h2", {
719
+ className: withRenderTag("h2"),
720
+ children: node.children.map(toReact)
721
+ }, key);
722
+ }
723
+ if (node.tag === "h3") {
724
+ return /*#__PURE__*/ReactJSXRuntime.jsx("h3", {
725
+ className: withRenderTag("h3"),
726
+ children: node.children.map(toReact)
727
+ }, key);
728
+ }
729
+ if (node.tag === "h4") {
730
+ return /*#__PURE__*/ReactJSXRuntime.jsx("h4", {
731
+ className: withRenderTag("h4"),
732
+ children: node.children.map(toReact)
733
+ }, key);
734
+ }
735
+ if (node.tag === "h5") {
736
+ return /*#__PURE__*/ReactJSXRuntime.jsx("h5", {
737
+ className: withRenderTag("h5"),
738
+ children: node.children.map(toReact)
739
+ }, key);
740
+ }
741
+ if (node.tag === "h6") {
742
+ return /*#__PURE__*/ReactJSXRuntime.jsx("h6", {
743
+ className: withRenderTag("h6"),
744
+ children: node.children.map(toReact)
745
+ }, key);
746
+ }
747
+ console.error("Unknown tag", node.tag);
748
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
749
+ var anyNode = node;
750
+ if (!(anyNode !== null && anyNode !== void 0 && anyNode.tag)) {
751
+ return null;
752
+ }
753
+ return /*#__PURE__*/React__default["default"].createElement(anyNode.tag, {
754
+ key: key,
755
+ className: (_anyNode$class = anyNode["class"]) === null || _anyNode$class === void 0 ? void 0 : _anyNode$class.join(" "),
756
+ children: (_anyNode$children = anyNode.children) === null || _anyNode$children === void 0 ? void 0 : _anyNode$children.map(toReact)
757
+ });
703
758
  }
704
- return /*#__PURE__*/ReactJSXRuntime.jsx("span", {
705
- style: styleProps,
706
- children: node.text
707
- });
708
- }
709
- function HeadingNodeComponent(_ref3) {
710
- var node = _ref3.node,
711
- path = _ref3.path;
712
- return /*#__PURE__*/React.createElement(node.tag, {}, node.children.map(function (child, i) {
713
- var childPath = "".concat(path, ".").concat(i);
714
- return /*#__PURE__*/ReactJSXRuntime.jsx(TextNodeComponent, {
715
- node: child
716
- }, childPath);
717
- }));
718
- }
719
- function ParagraphNodeComponent(_ref4) {
720
- var node = _ref4.node,
721
- path = _ref4.path;
722
- return /*#__PURE__*/ReactJSXRuntime.jsx("p", {
723
- children: node.children.map(function (child, i) {
724
- var childPath = "".concat(path, ".").concat(i);
725
- switch (child.type) {
726
- case "text":
727
- return /*#__PURE__*/ReactJSXRuntime.jsx(TextNodeComponent, {
728
- node: child
729
- }, childPath);
730
- default:
731
- throw Error("Unknown paragraph node type: " + (child === null || child === void 0 ? void 0 : child.type));
732
- }
733
- })
734
- });
735
- }
736
- function ListNodeComponent(_ref5) {
737
- var node = _ref5.node,
738
- path = _ref5.path;
739
- return /*#__PURE__*/React.createElement(node.tag, {}, node.children.map(function (child, i) {
740
- var childPath = "".concat(path, ".").concat(i);
741
- return /*#__PURE__*/ReactJSXRuntime.jsx(ListItemComponent, {
742
- path: childPath,
743
- node: child
744
- }, childPath);
745
- }));
746
- }
747
- function ListItemComponent(_ref6) {
748
- var node = _ref6.node,
749
- path = _ref6.path;
750
- return /*#__PURE__*/ReactJSXRuntime.jsx("li", {
751
- children: node.children.map(function (child, i) {
752
- var childPath = "".concat(path, ".").concat(i);
753
- switch (child.type) {
754
- case "text":
755
- return /*#__PURE__*/ReactJSXRuntime.jsx(TextNodeComponent, {
756
- node: child
757
- }, childPath);
758
- default:
759
- throw Error("Unknown list item node type: " + (child === null || child === void 0 ? void 0 : child.type));
760
- }
761
- })
759
+ return /*#__PURE__*/ReactJSXRuntime.jsx("div", {
760
+ "data-val-path": root.valPath,
761
+ children: root.children.map(toReact)
762
762
  });
763
763
  }
764
764
 
@@ -8,12 +8,10 @@ var defineProperty = require('./defineProperty-36ed93cd.cjs.prod.js');
8
8
  var fp = require('@valbuild/core/fp');
9
9
  var core = require('@valbuild/core');
10
10
  var ReactJSXRuntime = require('react/jsx-runtime');
11
- var parse = require('style-to-object');
12
11
 
13
12
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
14
13
 
15
14
  var React__default = /*#__PURE__*/_interopDefault(React);
16
- var parse__default = /*#__PURE__*/_interopDefault(parse);
17
15
 
18
16
  function _createForOfIteratorHelper(o, allowArrayLike) {
19
17
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
@@ -608,7 +606,7 @@ var ValContext = /*#__PURE__*/React__default["default"].createContext({
608
606
  }
609
607
  });
610
608
  var ValUI = typeof window !== "undefined" ? /*#__PURE__*/React.lazy(function () {
611
- return Promise.resolve().then(function () { return require('./ValUI-3e00aae3.cjs.prod.js'); });
609
+ return Promise.resolve().then(function () { return require('./ValUI-b5f81233.cjs.prod.js'); });
612
610
  }) : null;
613
611
  function ValProvider(_ref) {
614
612
  var _ref$host = _ref.host,
@@ -629,136 +627,138 @@ function ValProvider(_ref) {
629
627
  });
630
628
  }
631
629
 
630
+ /* eslint-disable @typescript-eslint/ban-types */
632
631
  function ValRichText(_ref) {
633
- var children = _ref.children;
632
+ var theme = _ref.theme,
633
+ children = _ref.children;
634
634
  var root = children;
635
- var path = root.valPath;
636
- return /*#__PURE__*/ReactJSXRuntime.jsx("div", {
637
- "data-val-path": path,
638
- children: root.children.map(function (child, i) {
639
- var childType = child.type;
640
- var childPath = "".concat(path, ".").concat(i);
641
- switch (childType) {
642
- case "heading":
643
- return /*#__PURE__*/ReactJSXRuntime.jsx(HeadingNodeComponent, {
644
- path: childPath,
645
- node: child
646
- }, childPath);
647
- case "paragraph":
648
- return /*#__PURE__*/ReactJSXRuntime.jsx(ParagraphNodeComponent, {
649
- path: childPath,
650
- node: child
651
- }, childPath);
652
- case "list":
653
- return /*#__PURE__*/ReactJSXRuntime.jsx(ListNodeComponent, {
654
- path: childPath,
655
- node: child
656
- }, childPath);
657
- default:
658
- throw Error("Unknown root node type: " + childType);
659
- }
660
- })
661
- });
662
- }
663
- function TextNodeComponent(_ref2) {
664
- var _parse, _node$format;
665
- var node = _ref2.node;
666
- var styleProps = node.style ? (_parse = parse__default["default"](node.style)) !== null && _parse !== void 0 ? _parse : {} : {};
667
- // TODO: Ugly! We should do this before serializing instead
668
- if (styleProps["font-family"]) {
669
- styleProps["fontFamily"] = styleProps["font-family"];
670
- delete styleProps["font-family"];
671
- }
672
- if (styleProps["font-size"]) {
673
- styleProps["fontSize"] = styleProps["font-size"];
674
- delete styleProps["font-size"];
675
- }
676
- var bitmask = (_node$format = node.format) === null || _node$format === void 0 ? void 0 : _node$format.toString(2);
677
- var bitmaskOffset = bitmask ? bitmask.length - 1 : 0;
678
- function isBitOne(bit) {
679
- if (!bitmask) {
680
- return false;
635
+ function withRenderTag(clazz, current) {
636
+ var renderClass = theme.tags[clazz];
637
+ if (renderClass && current) {
638
+ return [current, renderClass].join(" ");
681
639
  }
682
- return bitmask.length >= bitmaskOffset - bit && bitmask[bitmaskOffset - bit] === "1";
683
- }
684
- if (isBitOne(0)) {
685
- styleProps["fontWeight"] = "bold";
686
- }
687
- if (isBitOne(1)) {
688
- styleProps["fontStyle"] = "italic";
640
+ if (renderClass) {
641
+ return renderClass;
642
+ }
643
+ return current;
689
644
  }
690
- if (isBitOne(2)) {
691
- if (!styleProps["textDecoration"]) {
692
- styleProps["textDecoration"] = "line-through";
693
- } else {
694
- styleProps["textDecoration"] += " line-through";
645
+ function withRenderClass(clazz, current) {
646
+ var renderClass = theme.classes[clazz];
647
+ if (renderClass && current) {
648
+ return [current, renderClass].join(" ");
649
+ }
650
+ if (renderClass) {
651
+ return renderClass;
695
652
  }
653
+ return current;
696
654
  }
697
- if (isBitOne(3)) {
698
- if (!styleProps["textDecoration"]) {
699
- styleProps["textDecoration"] = "underline";
700
- } else {
701
- styleProps["textDecoration"] += " underline";
655
+ function toReact(node, key) {
656
+ var _anyNode$class, _anyNode$children;
657
+ if (typeof node === "string") {
658
+ return node;
659
+ }
660
+ if (node.tag === "p") {
661
+ return /*#__PURE__*/ReactJSXRuntime.jsx("p", {
662
+ className: withRenderTag("p"),
663
+ children: node.children.map(toReact)
664
+ }, key);
665
+ }
666
+ if (node.tag === "img") {
667
+ return /*#__PURE__*/ReactJSXRuntime.jsx("div", {
668
+ className: withRenderClass("imgContainer"),
669
+ children: /*#__PURE__*/ReactJSXRuntime.jsx("img", {
670
+ className: withRenderTag("img"),
671
+ src: node.src
672
+ })
673
+ }, key);
674
+ }
675
+ // if (node.tag === "blockquote") {
676
+ // return <blockquote key={key}>{node.children.map(toReact)}</blockquote>;
677
+ // }
678
+ if (node.tag === "ul") {
679
+ return /*#__PURE__*/ReactJSXRuntime.jsx("ul", {
680
+ className: withRenderTag("ul"),
681
+ children: node.children.map(toReact)
682
+ }, key);
683
+ }
684
+ if (node.tag === "ol") {
685
+ return /*#__PURE__*/ReactJSXRuntime.jsx("ol", {
686
+ className: withRenderTag("ol"),
687
+ children: node.children.map(toReact)
688
+ }, key);
689
+ }
690
+ if (node.tag === "li") {
691
+ return /*#__PURE__*/ReactJSXRuntime.jsx("li", {
692
+ className: withRenderTag("li"),
693
+ children: node.children.map(toReact)
694
+ }, key);
695
+ }
696
+ if (node.tag === "span") {
697
+ return /*#__PURE__*/ReactJSXRuntime.jsx("span", {
698
+ className: node.classes.map(function (nodeClass) {
699
+ switch (nodeClass) {
700
+ case "bold":
701
+ return withRenderClass("bold");
702
+ case "line-through":
703
+ return withRenderClass("lineThrough");
704
+ case "italic":
705
+ return withRenderClass("italic");
706
+ }
707
+ }).join(" "),
708
+ children: node.children.map(toReact)
709
+ }, key);
702
710
  }
711
+ if (node.tag === "h1") {
712
+ return /*#__PURE__*/ReactJSXRuntime.jsx("h1", {
713
+ className: withRenderTag("h1"),
714
+ children: node.children.map(toReact)
715
+ }, key);
716
+ }
717
+ if (node.tag === "h2") {
718
+ return /*#__PURE__*/ReactJSXRuntime.jsx("h2", {
719
+ className: withRenderTag("h2"),
720
+ children: node.children.map(toReact)
721
+ }, key);
722
+ }
723
+ if (node.tag === "h3") {
724
+ return /*#__PURE__*/ReactJSXRuntime.jsx("h3", {
725
+ className: withRenderTag("h3"),
726
+ children: node.children.map(toReact)
727
+ }, key);
728
+ }
729
+ if (node.tag === "h4") {
730
+ return /*#__PURE__*/ReactJSXRuntime.jsx("h4", {
731
+ className: withRenderTag("h4"),
732
+ children: node.children.map(toReact)
733
+ }, key);
734
+ }
735
+ if (node.tag === "h5") {
736
+ return /*#__PURE__*/ReactJSXRuntime.jsx("h5", {
737
+ className: withRenderTag("h5"),
738
+ children: node.children.map(toReact)
739
+ }, key);
740
+ }
741
+ if (node.tag === "h6") {
742
+ return /*#__PURE__*/ReactJSXRuntime.jsx("h6", {
743
+ className: withRenderTag("h6"),
744
+ children: node.children.map(toReact)
745
+ }, key);
746
+ }
747
+ console.error("Unknown tag", node.tag);
748
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
749
+ var anyNode = node;
750
+ if (!(anyNode !== null && anyNode !== void 0 && anyNode.tag)) {
751
+ return null;
752
+ }
753
+ return /*#__PURE__*/React__default["default"].createElement(anyNode.tag, {
754
+ key: key,
755
+ className: (_anyNode$class = anyNode["class"]) === null || _anyNode$class === void 0 ? void 0 : _anyNode$class.join(" "),
756
+ children: (_anyNode$children = anyNode.children) === null || _anyNode$children === void 0 ? void 0 : _anyNode$children.map(toReact)
757
+ });
703
758
  }
704
- return /*#__PURE__*/ReactJSXRuntime.jsx("span", {
705
- style: styleProps,
706
- children: node.text
707
- });
708
- }
709
- function HeadingNodeComponent(_ref3) {
710
- var node = _ref3.node,
711
- path = _ref3.path;
712
- return /*#__PURE__*/React.createElement(node.tag, {}, node.children.map(function (child, i) {
713
- var childPath = "".concat(path, ".").concat(i);
714
- return /*#__PURE__*/ReactJSXRuntime.jsx(TextNodeComponent, {
715
- node: child
716
- }, childPath);
717
- }));
718
- }
719
- function ParagraphNodeComponent(_ref4) {
720
- var node = _ref4.node,
721
- path = _ref4.path;
722
- return /*#__PURE__*/ReactJSXRuntime.jsx("p", {
723
- children: node.children.map(function (child, i) {
724
- var childPath = "".concat(path, ".").concat(i);
725
- switch (child.type) {
726
- case "text":
727
- return /*#__PURE__*/ReactJSXRuntime.jsx(TextNodeComponent, {
728
- node: child
729
- }, childPath);
730
- default:
731
- throw Error("Unknown paragraph node type: " + (child === null || child === void 0 ? void 0 : child.type));
732
- }
733
- })
734
- });
735
- }
736
- function ListNodeComponent(_ref5) {
737
- var node = _ref5.node,
738
- path = _ref5.path;
739
- return /*#__PURE__*/React.createElement(node.tag, {}, node.children.map(function (child, i) {
740
- var childPath = "".concat(path, ".").concat(i);
741
- return /*#__PURE__*/ReactJSXRuntime.jsx(ListItemComponent, {
742
- path: childPath,
743
- node: child
744
- }, childPath);
745
- }));
746
- }
747
- function ListItemComponent(_ref6) {
748
- var node = _ref6.node,
749
- path = _ref6.path;
750
- return /*#__PURE__*/ReactJSXRuntime.jsx("li", {
751
- children: node.children.map(function (child, i) {
752
- var childPath = "".concat(path, ".").concat(i);
753
- switch (child.type) {
754
- case "text":
755
- return /*#__PURE__*/ReactJSXRuntime.jsx(TextNodeComponent, {
756
- node: child
757
- }, childPath);
758
- default:
759
- throw Error("Unknown list item node type: " + (child === null || child === void 0 ? void 0 : child.type));
760
- }
761
- })
759
+ return /*#__PURE__*/ReactJSXRuntime.jsx("div", {
760
+ "data-val-path": root.valPath,
761
+ children: root.children.map(toReact)
762
762
  });
763
763
  }
764
764