0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-27 22:19:04 -05:00

[ci] format

This commit is contained in:
matthewp 2023-10-24 12:07:52 +00:00 committed by astrobot-houston
parent 4dee38711c
commit 48bf7c3de6
2 changed files with 35 additions and 28 deletions

View file

@ -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) =>
@ -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,

View file

@ -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);
}