woby
Version:
A high-performance framework with fine-grained observable/signal-based reactivity for building rich applications.
1 lines • 6.37 kB
Source Map (JSON)
{"version":3,"file":"runtime-BkkHnWaw.cjs","sources":["../src/methods/create_element.ts","../src/jsx/runtime.ts"],"sourcesContent":["\r\n/* IMPORT */\r\n\r\nimport untrack from '../methods/untrack'\r\nimport wrapElement from '../methods/wrap_element'\r\nimport { createHTMLNode, createSVGNode } from '../utils/creators'\r\nimport { isFunction, isNode, isObject, isString, isSVGElement, isVoidChild } from '../utils/lang'\r\nimport { setChild, setProps } from '../utils/setters'\r\nimport type { Child, Component, Element } from '../types'\r\nimport { FragmentUtils } from '../utils/fragment'\r\n\r\n/* MAIN */\r\n\r\n// It's important to wrap components, so that they can be executed in the right order, from parent to child, rather than from child to parent in some cases\r\n\r\nconst createElement = <P = { children?: Child }>(component: Component<P>, _props?: P | null, ..._children: Child[]) => {\r\n\r\n const children = _children.length > 1 ? _children : (_children.length > 0 ? _children[0] : undefined)\r\n const hasChildren = !isVoidChild(children)\r\n const { ...rest } = _props ?? {}\r\n\r\n if (hasChildren && isObject(_props) && 'children' in _props) {\r\n\r\n throw new Error('Providing \"children\" both as a prop and as rest arguments is forbidden')\r\n\r\n }\r\n\r\n if (isFunction(component)) {\r\n\r\n const props = hasChildren ? { ..._props, children } : _props\r\n\r\n return wrapElement(() => {\r\n\r\n return untrack(() => component.call(component, props as P)) //TSC\r\n\r\n })\r\n\r\n } else if (isString(component)) {\r\n\r\n const isSVG = isSVGElement(component)\r\n const createNode = isSVG ? createSVGNode : createHTMLNode\r\n\r\n return wrapElement((): Child => {\r\n\r\n const child = createNode(component) as HTMLElement //TSC\r\n\r\n if (isSVG) child['isSVG'] = true\r\n\r\n const stack = new Error()\r\n\r\n untrack(() => {\r\n\r\n if (_props) {\r\n setProps(child, _props as any, stack)\r\n }\r\n\r\n if (hasChildren) {\r\n setChild(child, children, FragmentUtils.make(), stack)\r\n }\r\n\r\n })\r\n\r\n return child\r\n\r\n })\r\n\r\n } else if (isNode(component)) {\r\n\r\n return wrapElement(() => component)\r\n\r\n } else {\r\n\r\n throw new Error('Invalid component')\r\n\r\n }\r\n\r\n}\r\n\r\n/* EXPORT */\r\n\r\nexport default createElement","\r\n/* IMPORT */\r\n\r\nimport '../types';\r\nimport './types';\r\nimport Fragment from '../components/fragment';\r\n// import createElement from '../methods/create_element';\r\n// import { wrapCloneElement } from '../methods/wrap_clone_element';\r\nimport type { Child, Component, Element } from '../types';\r\nimport { wrapCloneElement, createElement, CloneableType } from '../index';\r\nimport { SYMBOL_CLONE } from '../constants';\r\n\r\n/* MAIN */\r\n// const jsx = <P = {}>(component: Component<P>, props?: P | null, ...children: Child[]): Element => {\r\n// return wrapCloneElement(createElement<P>(component as any, props, ...children), component, props);\r\n// };\r\n\r\n// React 16\r\nfunction jsx<P extends {} = {}>(component: Component<P>, props?: P, ...children: Child[]): Element;\r\n//React 17\r\nfunction jsx<P extends {} = { key?: string; children?: Child; }>(component: Component<P>, props?: P, key?: string): Element;\r\nfunction jsx<P extends {} = { key?: string; children?: Child; }>(component: Component<P>, props?: P, ...children: (string | Child)[]): Element {\r\n if (typeof children === 'string') // React 16, key\r\n return wrapCloneElement(createElement<P>(component as any, props ?? {} as P, children as string), component, props);\r\n\r\n if (!props) props = {} as any;\r\n if (typeof children === 'string') // React 16, key\r\n Object.assign(props as any, { children });\r\n\r\n return wrapCloneElement(createElement<P>(component as any, props, (props as any)?.key as string), component, props);\r\n};\r\n\r\n//React 17 only\r\nconst jsxDEV = <P extends {} = {}>(component: Component<P>, props: P | null, key: string, isStatic: boolean, source: { fileName: string, lineNumber: number, columnNumber: number; }, self: any): Element => {\r\n if (key)\r\n Object.assign(props, { key })\r\n return wrapCloneElement(createElement<P>(component as any, props), component, props);\r\n};\r\n\r\nexport const getMeta = (target: Element) => target?.[SYMBOL_CLONE] as CloneableType\r\n\r\n/* EXPORT */\r\n\r\nexport { jsx, jsx as jsxs, jsxDEV, Fragment };\r\n"],"names":["isVoidChild","isObject","isFun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