Skip to content

Commit

Permalink
[ci] format
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp authored and astrobot-houston committed Oct 24, 2023
1 parent 4dee387 commit 48bf7c3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 28 deletions.
37 changes: 20 additions & 17 deletions packages/integrations/react/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,41 @@ function isAlreadyHydrated(element) {

function createReactElementFromDOMElement(element) {
let attrs = {};
for(const attr of element.attributes) {
for (const attr of element.attributes) {
attrs[attr.name] = attr.value;
}

return createElement(element.localName, attrs,
Array.from(element.childNodes).map(c => {
if(c.nodeType === Node.TEXT_NODE) {
return c.data;
} else if(c.nodeType === Node.ELEMENT_NODE) {
return createReactElementFromDOMElement(c)
} else {
return undefined;
}
}).filter(a => !!a)
return createElement(
element.localName,
attrs,
Array.from(element.childNodes)
.map((c) => {
if (c.nodeType === Node.TEXT_NODE) {
return c.data;
} else if (c.nodeType === Node.ELEMENT_NODE) {
return createReactElementFromDOMElement(c);
} else {
return undefined;
}
})
.filter((a) => !!a)
);
}

function getChildren(childString, experimentalReactChildren) {
if(experimentalReactChildren && childString) {
if (experimentalReactChildren && childString) {
let children = [];
let template = document.createElement('template');
template.innerHTML = childString;
for(let child of template.content.children) {
children.push(createReactElementFromDOMElement(child))
for (let child of template.content.children) {
children.push(createReactElementFromDOMElement(child));
}
return children;
} else if(childString) {
} else if (childString) {
return createElement(StaticHtml, { value: childString });
} else {
return undefined;
}

}

export default (element) =>
Expand All @@ -55,7 +58,7 @@ export default (element) =>
for (const [key, value] of Object.entries(slotted)) {
props[key] = createElement(StaticHtml, { value, name: key });
}

const componentEl = createElement(
Component,
props,
Expand Down
26 changes: 15 additions & 11 deletions packages/integrations/react/vnode-children.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ export default function convert(children) {
let key = 0;

function createReactElementFromNode(node) {
const childVnodes = Array.isArray(node.children) ? node.children.map(child => {
if(child.type === ELEMENT_NODE) {
return createReactElementFromNode(child);
} else if(child.type === TEXT_NODE) {
// 0-length text gets omitted in JSX
return child.value.trim() ? child.value : undefined;
}
}).filter(n => !!n) : undefined;

if(node.type === DOCUMENT_NODE) {
const childVnodes = Array.isArray(node.children)
? node.children
.map((child) => {
if (child.type === ELEMENT_NODE) {
return createReactElementFromNode(child);
} else if (child.type === TEXT_NODE) {
// 0-length text gets omitted in JSX
return child.value.trim() ? child.value : undefined;
}
})
.filter((n) => !!n)
: undefined;

if (node.type === DOCUMENT_NODE) {
return createElement(Fragment, {}, childVnodes);
} else if(node.type === ELEMENT_NODE) {
} else if (node.type === ELEMENT_NODE) {
const { class: className, ...props } = node.attributes;
return createElement(node.name, { ...props, className, key: `${id}-${key++}` }, childVnodes);
}
Expand Down

0 comments on commit 48bf7c3

Please sign in to comment.