Comparing version 2.1.7 to 2.1.8
{ | ||
"name": "araz", | ||
"version": "2.1.7", | ||
"version": "2.1.8", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.ts", |
@@ -14,3 +14,3 @@ import { | ||
} from "lodash-es"; | ||
import { VNode } from "./types"; | ||
import { Children, VNode } from "./types"; | ||
@@ -45,3 +45,3 @@ /** | ||
export const render = async ( | ||
nodes: VNode[] | VNode | ||
nodes: Children | ||
): Promise<DocumentFragment | HTMLElement> => { | ||
@@ -53,51 +53,55 @@ const fragment = document.createDocumentFragment(); | ||
for (const node of nodeArray) { | ||
const { $tag, $attrs = {}, $children = [] } = node; | ||
if (isString(node)) { | ||
fragment.appendChild(document.createTextNode(node)); | ||
} else { | ||
const { $tag, $attrs = {}, $children = [] } = node; | ||
if (!$tag) { | ||
continue; | ||
} | ||
if (!$tag) { | ||
continue; | ||
} | ||
const $el = document.createElement($tag); | ||
const $el = document.createElement($tag); | ||
for (const [key, value] of entries($attrs)) { | ||
if (isEqual(key, "style") && isObject(value)) { | ||
const result = map( | ||
entries(value), | ||
([property, propertyValue]) => | ||
`${kebabCase(property)}:${propertyValue}` | ||
); | ||
const styleString = join(result, "; "); | ||
$el.setAttribute("style", styleString); | ||
} else if (isEqual(key, "class") && isArray(value)) { | ||
const classList = value.join(" "); | ||
$el.setAttribute("class", trim(classList)); | ||
} else if (isEqual(key, "events") && isObject(value)) { | ||
for (const [eventName, eventHandler] of entries(value)) { | ||
const formattedEventName = camelCase(eventName.slice(2)); | ||
if (isFunction(eventHandler)) { | ||
$el.addEventListener( | ||
formattedEventName, | ||
eventHandler as unknown as EventListener | ||
); | ||
for (const [key, value] of entries($attrs)) { | ||
if (isEqual(key, "style") && isObject(value)) { | ||
const result = map( | ||
entries(value), | ||
([property, propertyValue]) => | ||
`${kebabCase(property)}:${propertyValue}` | ||
); | ||
const styleString = join(result, "; "); | ||
$el.setAttribute("style", styleString); | ||
} else if (isEqual(key, "class") && isArray(value)) { | ||
const classList = value.join(" "); | ||
$el.setAttribute("class", trim(classList)); | ||
} else if (isEqual(key, "events") && isObject(value)) { | ||
for (const [eventName, eventHandler] of entries(value)) { | ||
const formattedEventName = camelCase(eventName.slice(2)); | ||
if (isFunction(eventHandler)) { | ||
$el.addEventListener( | ||
formattedEventName, | ||
eventHandler as unknown as EventListener | ||
); | ||
} | ||
} | ||
} else { | ||
$el.setAttribute(key, isString(value) ? value.toString() : ""); | ||
} | ||
} else { | ||
$el.setAttribute(key, isString(value) ? value.toString() : ""); | ||
} | ||
} | ||
if (isString($children)) { | ||
$el.appendChild(document.createTextNode($children)); | ||
} else if (Array.isArray($children)) { | ||
for (const child of $children) { | ||
if (isString(child)) { | ||
$el.appendChild(document.createTextNode(child)); | ||
} else { | ||
const $child = await render(child); | ||
$el.appendChild($child); | ||
if (isString($children)) { | ||
$el.appendChild(document.createTextNode($children)); | ||
} else if (Array.isArray($children)) { | ||
for (const child of $children) { | ||
if (isString(child)) { | ||
$el.appendChild(document.createTextNode(child)); | ||
} else { | ||
const $child = await render(child); | ||
$el.appendChild($child); | ||
} | ||
} | ||
} | ||
fragment.appendChild($el); | ||
} | ||
fragment.appendChild($el); | ||
} | ||
@@ -104,0 +108,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16628
482