port ujsx from Deno-only to cross-platform (Node/Bun/Deno)
Add npm project configuration (package.json, tsconfig.json, tsup, vitest) matching the taskgraph_ts conventions. All source imports changed from .ts to .js extensions for Node16 module resolution. Tests migrated from Deno.test to vitest. Fixed strict type errors (noUncheckedIndexedAccess). Preserved deno.json with sloppy-imports for dual Deno/Node compatibility. Subpath exports: schema, h, reactive, context, events, pointer, host, transform, jsx-runtime — plus barrel export at root. Build: ESM + CJS dual output via tsup. 22 tests passing.
This commit is contained in:
49
src/core/h.ts
Normal file
49
src/core/h.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import type { UNode, UElement, URoot, UType, UComponent, UniversalProps } from "./schema.js";
|
||||
|
||||
let _idCounter = 0;
|
||||
|
||||
export function h(type: UType, props?: UniversalProps | null, ...children: UNode[]): UElement | URoot {
|
||||
const resolvedProps: UniversalProps = props ? { ...props } : {};
|
||||
const flatChildren = children.flat(Infinity as 1).filter((c: UNode) => c != null && c !== false) as UNode[];
|
||||
|
||||
if (type === "root") {
|
||||
return {
|
||||
type: "root",
|
||||
props: resolvedProps,
|
||||
children: flatChildren,
|
||||
} as URoot;
|
||||
}
|
||||
|
||||
return {
|
||||
type: type as string,
|
||||
props: resolvedProps,
|
||||
children: flatChildren,
|
||||
} as UElement;
|
||||
}
|
||||
|
||||
export function createRoot(id: string | undefined, ...children: UNode[]): URoot {
|
||||
return {
|
||||
type: "root",
|
||||
props: { id: id ?? `root_${++_idCounter}` },
|
||||
children: children.flat(Infinity as 1).filter((c: UNode) => c != null && c !== false) as UNode[],
|
||||
};
|
||||
}
|
||||
|
||||
export function createComponent<P extends UniversalProps>(
|
||||
name: string,
|
||||
render: (props: P) => UNode,
|
||||
targets?: string[],
|
||||
): UComponent<P> {
|
||||
const c = render as unknown as UComponent<P>;
|
||||
c.displayName = name;
|
||||
c.targets = targets;
|
||||
return c;
|
||||
}
|
||||
|
||||
export function Fragment(props: { children?: UNode[] }): UNode[] {
|
||||
return ((props.children ?? []) as UNode[]).flat(Infinity as 1).filter((c: UNode) => c != null && c !== false) as UNode[];
|
||||
}
|
||||
|
||||
export const jsx = h;
|
||||
export const jsxs = h;
|
||||
export const jsxDEV = h;
|
||||
Reference in New Issue
Block a user