Rename package from jrx to jfx

Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
2026-02-28 01:27:37 +00:00
parent b8d1d2de80
commit 2f9e0a9936
21 changed files with 144 additions and 148 deletions

View File

@@ -2,12 +2,12 @@ import type {
ActionBinding,
VisibilityCondition,
} from "@json-render/core";
import { JRX_NODE, FRAGMENT, type JrxNode } from "./types";
import type { JrxComponent } from "./types";
import { JFX_NODE, FRAGMENT, type JfxNode } from "./types";
import type { JfxComponent } from "./types";
export { FRAGMENT as Fragment };
/** Props reserved by jrx — extracted from JSX props and placed on the UIElement level. */
/** Props reserved by jfx — extracted from JSX props and placed on the UIElement level. */
const RESERVED_PROPS = new Set([
"key",
"children",
@@ -18,26 +18,26 @@ const RESERVED_PROPS = new Set([
]);
/**
* Normalize a raw `children` value from JSX props into a flat array of JrxNodes.
* Normalize a raw `children` value from JSX props into a flat array of JfxNodes.
* Handles: undefined, single node, nested arrays, and filters out nulls/booleans.
*/
function normalizeChildren(raw: unknown): JrxNode[] {
function normalizeChildren(raw: unknown): JfxNode[] {
if (raw == null || typeof raw === "boolean") return [];
if (Array.isArray(raw)) {
const result: JrxNode[] = [];
const result: JfxNode[] = [];
for (const child of raw) {
if (child == null || typeof child === "boolean") continue;
if (Array.isArray(child)) {
result.push(...normalizeChildren(child));
} else {
result.push(child as JrxNode);
result.push(child as JfxNode);
}
}
return result;
}
return [raw as JrxNode];
return [raw as JfxNode];
}
/**
@@ -56,20 +56,20 @@ function extractProps(
}
/** Accepted tag types: string literal, Fragment symbol, or a function component. */
type JsxType = string | typeof FRAGMENT | JrxComponent;
type JsxType = string | typeof FRAGMENT | JfxComponent;
/**
* Core factory — shared by `jsx` and `jsxs`.
*
* If `type` is a function, it is called with props (like React calls
* function components). The function returns a JrxNode directly.
* function components). The function returns a JfxNode directly.
*
* If `type` is a string or Fragment, a JrxNode is constructed inline.
* If `type` is a string or Fragment, a JfxNode is constructed inline.
*/
function createNode(
type: JsxType,
rawProps: Record<string, unknown> | null,
): JrxNode {
): JfxNode {
const p = rawProps ?? {};
// Function component — call it, just like React does.
@@ -78,7 +78,7 @@ function createNode(
}
return {
$$typeof: JRX_NODE,
$$typeof: JFX_NODE,
type,
props: extractProps(p),
children: normalizeChildren(p.children),
@@ -102,7 +102,7 @@ export function jsx(
type: JsxType,
props: Record<string, unknown> | null,
key?: string,
): JrxNode {
): JfxNode {
const node = createNode(type, props);
if (key != null) node.key = String(key);
return node;
@@ -116,7 +116,7 @@ export function jsxs(
type: JsxType,
props: Record<string, unknown> | null,
key?: string,
): JrxNode {
): JfxNode {
const node = createNode(type, props);
if (key != null) node.key = String(key);
return node;
@@ -133,7 +133,7 @@ export namespace JSX {
}
/** The type returned by JSX expressions. */
export type Element = JrxNode;
export type Element = JfxNode;
export interface ElementChildrenAttribute {
children: {};