@pronto-tools-and-more/components-renderer 5.0.2 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pronto-tools-and-more/components-renderer",
3
- "version": "5.0.2",
3
+ "version": "5.2.0",
4
4
  "description": "",
5
5
  "main": "src/componentsRendererMain.js",
6
6
  "type": "module",
@@ -1,20 +1,5 @@
1
- import * as IsHtml from "../IsHtml/IsHtml.js";
2
-
3
- export const createElement = (tag, props, children) => {
4
- if (IsHtml.isHtml(tag)) {
5
- return {
6
- type: "section",
7
- content: [
8
- {
9
- type: "html",
10
- tag: "div",
11
- content: "abc",
12
- },
13
- ],
14
- };
15
- }
1
+ export const createElement = (tag, props, ...children) => {
16
2
  return {
17
- type: "section",
18
3
  tag,
19
4
  props,
20
5
  children,
@@ -0,0 +1,8 @@
1
+ import * as FakeNode from "../FakeNode/FakeNode.js";
2
+
3
+ export const createFakeSection = (children) => {
4
+ return {
5
+ type: "section",
6
+ content: [FakeNode.fakeNode, ...children],
7
+ };
8
+ };
@@ -0,0 +1,6 @@
1
+ // fake node (to allow using normal html)
2
+ export const fakeNode = {
3
+ type: "html",
4
+ tag: "div",
5
+ content: '<img src="x" onerror="globalThis.fixRender(this)" />',
6
+ };
@@ -0,0 +1,7 @@
1
+ const isComplex = (child) => {
2
+ return typeof child !== "string";
3
+ };
4
+
5
+ export const hasComplexChildren = (element) => {
6
+ return element.children.some(isComplex);
7
+ };
@@ -1,4 +1,33 @@
1
+ import * as CreateFakeSection from "../CreateFakeSection/CreateFakeSection.js";
2
+ import * as HasComplexChildren from "../HasComplexChildren/HasComplexChildren.js";
3
+
1
4
  export const renderElement = (element) => {
2
- if (element.isReactComponent) {
5
+ if (typeof element === "string") {
6
+ return {
7
+ type: "html",
8
+ tag: "div",
9
+ content: element,
10
+ };
3
11
  }
12
+ if (element.tag) {
13
+ const hasComplexChildren = HasComplexChildren.hasComplexChildren(element);
14
+ const renderedChildren = hasComplexChildren
15
+ ? element.children.map(renderElement)
16
+ : [];
17
+ const content = hasComplexChildren ? "" : element.children[0] || "";
18
+ const className =
19
+ element.props && element.props.className
20
+ ? element.props.className
21
+ : undefined;
22
+ return CreateFakeSection.createFakeSection([
23
+ {
24
+ type: "html",
25
+ tag: element.tag,
26
+ class: className,
27
+ content,
28
+ },
29
+ ...renderedChildren,
30
+ ]);
31
+ }
32
+ return {};
4
33
  };
@@ -0,0 +1,9 @@
1
+ import * as RenderElement from "../RenderElement/RenderElement.js";
2
+
3
+ export const renderView = (view) => {
4
+ return {
5
+ path: view.path,
6
+ name: view.name,
7
+ content: view.content.map(RenderElement.renderElement),
8
+ };
9
+ };
@@ -2,6 +2,7 @@ import * as Assert from "../Assert/Assert.js";
2
2
  import * as CreateViews from "../CreateViews/CreateViews.js";
3
3
  import * as LoadRoutes from "../LoadRoutes/LoadRoutes.js";
4
4
  import * as LoadSwc from "../LoadSwc/LoadSwc.js";
5
+ import * as RenderView from "../RenderView/RenderView.js";
5
6
  import * as SwcNodePath from "../SwcNodePath/SwcNodePath.js";
6
7
 
7
8
  export const renderViews = async (componentsPathMain, tsconfigPath) => {
@@ -12,5 +13,6 @@ export const renderViews = async (componentsPathMain, tsconfigPath) => {
12
13
  const values = Object.values(module);
13
14
  // TODO return views string instead of json for faster performance?
14
15
  const views = CreateViews.createViews(values);
15
- return views;
16
+ const rendered = views.map(RenderView.renderView);
17
+ return rendered;
16
18
  };