@pyreon/react-compat 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/analysis/dom.js.html +5406 -0
- package/lib/analysis/jsx-runtime.js.html +5406 -0
- package/lib/dom.js +39 -0
- package/lib/dom.js.map +1 -0
- package/lib/jsx-runtime.js +93 -0
- package/lib/jsx-runtime.js.map +1 -0
- package/lib/types/dom.d.ts +39 -0
- package/lib/types/dom.d.ts.map +1 -0
- package/lib/types/dom2.d.ts +19 -0
- package/lib/types/dom2.d.ts.map +1 -0
- package/lib/types/jsx-runtime.d.ts +92 -0
- package/lib/types/jsx-runtime.d.ts.map +1 -0
- package/lib/types/jsx-runtime2.d.ts +10 -0
- package/lib/types/jsx-runtime2.d.ts.map +1 -0
- package/package.json +4 -4
- package/src/jsx-dev-runtime.ts +1 -0
package/lib/dom.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { mount } from "@pyreon/runtime-dom";
|
|
2
|
+
|
|
3
|
+
//#region src/dom.ts
|
|
4
|
+
/**
|
|
5
|
+
* @pyreon/react-compat/dom
|
|
6
|
+
*
|
|
7
|
+
* Drop-in for `react-dom/client` — provides `createRoot` so you can keep
|
|
8
|
+
* the same entry-point pattern as a React app.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Drop-in for React 18's `createRoot(container).render(element)`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { createRoot } from "@pyreon/react-compat/dom"
|
|
15
|
+
* createRoot(document.getElementById("app")!).render(<App />)
|
|
16
|
+
*/
|
|
17
|
+
function createRoot(container) {
|
|
18
|
+
let cleanup = null;
|
|
19
|
+
return {
|
|
20
|
+
render(element) {
|
|
21
|
+
if (cleanup) cleanup();
|
|
22
|
+
cleanup = mount(element, container);
|
|
23
|
+
},
|
|
24
|
+
unmount() {
|
|
25
|
+
if (cleanup) {
|
|
26
|
+
cleanup();
|
|
27
|
+
cleanup = null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** Alias — matches React 17's `render(element, container)` signature. */
|
|
33
|
+
function render(element, container) {
|
|
34
|
+
mount(element, container);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { createRoot, render };
|
|
39
|
+
//# sourceMappingURL=dom.js.map
|
package/lib/dom.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom.js","names":[],"sources":["../src/dom.ts"],"sourcesContent":["import type { VNodeChild } from \"@pyreon/core\"\n/**\n * @pyreon/react-compat/dom\n *\n * Drop-in for `react-dom/client` — provides `createRoot` so you can keep\n * the same entry-point pattern as a React app.\n */\nimport { mount } from \"@pyreon/runtime-dom\"\n\n/**\n * Drop-in for React 18's `createRoot(container).render(element)`.\n *\n * @example\n * import { createRoot } from \"@pyreon/react-compat/dom\"\n * createRoot(document.getElementById(\"app\")!).render(<App />)\n */\nexport function createRoot(container: Element): {\n render: (element: VNodeChild) => void\n unmount: () => void\n} {\n let cleanup: (() => void) | null = null\n return {\n render(element: VNodeChild) {\n if (cleanup) cleanup()\n cleanup = mount(element, container as HTMLElement)\n },\n unmount() {\n if (cleanup) {\n cleanup()\n cleanup = null\n }\n },\n }\n}\n\n/** Alias — matches React 17's `render(element, container)` signature. */\nexport function render(element: VNodeChild, container: Element): void {\n mount(element, container as HTMLElement)\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,SAAgB,WAAW,WAGzB;CACA,IAAI,UAA+B;AACnC,QAAO;EACL,OAAO,SAAqB;AAC1B,OAAI,QAAS,UAAS;AACtB,aAAU,MAAM,SAAS,UAAyB;;EAEpD,UAAU;AACR,OAAI,SAAS;AACX,aAAS;AACT,cAAU;;;EAGf;;;AAIH,SAAgB,OAAO,SAAqB,WAA0B;AACpE,OAAM,SAAS,UAAyB"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Fragment, h } from "@pyreon/core";
|
|
2
|
+
import { signal } from "@pyreon/reactivity";
|
|
3
|
+
|
|
4
|
+
//#region src/jsx-runtime.ts
|
|
5
|
+
let _currentCtx = null;
|
|
6
|
+
let _hookIndex = 0;
|
|
7
|
+
function beginRender(ctx) {
|
|
8
|
+
_currentCtx = ctx;
|
|
9
|
+
_hookIndex = 0;
|
|
10
|
+
ctx.pendingEffects = [];
|
|
11
|
+
ctx.pendingLayoutEffects = [];
|
|
12
|
+
}
|
|
13
|
+
function endRender() {
|
|
14
|
+
_currentCtx = null;
|
|
15
|
+
_hookIndex = 0;
|
|
16
|
+
}
|
|
17
|
+
function runLayoutEffects(entries) {
|
|
18
|
+
for (const entry of entries) {
|
|
19
|
+
if (entry.cleanup) entry.cleanup();
|
|
20
|
+
const cleanup = entry.fn();
|
|
21
|
+
entry.cleanup = typeof cleanup === "function" ? cleanup : void 0;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function scheduleEffects(ctx, entries) {
|
|
25
|
+
if (entries.length === 0) return;
|
|
26
|
+
queueMicrotask(() => {
|
|
27
|
+
for (const entry of entries) {
|
|
28
|
+
if (ctx.unmounted) return;
|
|
29
|
+
if (entry.cleanup) entry.cleanup();
|
|
30
|
+
const cleanup = entry.fn();
|
|
31
|
+
entry.cleanup = typeof cleanup === "function" ? cleanup : void 0;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
const _wrapperCache = /* @__PURE__ */ new WeakMap();
|
|
36
|
+
function wrapCompatComponent(reactComponent) {
|
|
37
|
+
let wrapped = _wrapperCache.get(reactComponent);
|
|
38
|
+
if (wrapped) return wrapped;
|
|
39
|
+
wrapped = ((props) => {
|
|
40
|
+
const ctx = {
|
|
41
|
+
hooks: [],
|
|
42
|
+
scheduleRerender: () => {},
|
|
43
|
+
pendingEffects: [],
|
|
44
|
+
pendingLayoutEffects: [],
|
|
45
|
+
unmounted: false
|
|
46
|
+
};
|
|
47
|
+
const version = signal(0);
|
|
48
|
+
let updateScheduled = false;
|
|
49
|
+
ctx.scheduleRerender = () => {
|
|
50
|
+
if (ctx.unmounted || updateScheduled) return;
|
|
51
|
+
updateScheduled = true;
|
|
52
|
+
queueMicrotask(() => {
|
|
53
|
+
updateScheduled = false;
|
|
54
|
+
if (!ctx.unmounted) version.set(version.peek() + 1);
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
return () => {
|
|
58
|
+
version();
|
|
59
|
+
beginRender(ctx);
|
|
60
|
+
const result = reactComponent(props);
|
|
61
|
+
const layoutEffects = ctx.pendingLayoutEffects;
|
|
62
|
+
const effects = ctx.pendingEffects;
|
|
63
|
+
endRender();
|
|
64
|
+
runLayoutEffects(layoutEffects);
|
|
65
|
+
scheduleEffects(ctx, effects);
|
|
66
|
+
return result;
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
_wrapperCache.set(reactComponent, wrapped);
|
|
70
|
+
return wrapped;
|
|
71
|
+
}
|
|
72
|
+
function jsx(type, props, key) {
|
|
73
|
+
const { children, ...rest } = props;
|
|
74
|
+
const propsWithKey = key != null ? {
|
|
75
|
+
...rest,
|
|
76
|
+
key
|
|
77
|
+
} : rest;
|
|
78
|
+
if (typeof type === "function") return h(wrapCompatComponent(type), children !== void 0 ? {
|
|
79
|
+
...propsWithKey,
|
|
80
|
+
children
|
|
81
|
+
} : propsWithKey);
|
|
82
|
+
const childArray = children === void 0 ? [] : Array.isArray(children) ? children : [children];
|
|
83
|
+
if (typeof type === "string" && propsWithKey.className !== void 0) {
|
|
84
|
+
propsWithKey.class = propsWithKey.className;
|
|
85
|
+
delete propsWithKey.className;
|
|
86
|
+
}
|
|
87
|
+
return h(type, propsWithKey, ...childArray);
|
|
88
|
+
}
|
|
89
|
+
const jsxs = jsx;
|
|
90
|
+
|
|
91
|
+
//#endregion
|
|
92
|
+
export { Fragment, jsx, jsxs };
|
|
93
|
+
//# sourceMappingURL=jsx-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx-runtime.js","names":[],"sources":["../src/jsx-runtime.ts"],"sourcesContent":["/**\n * Compat JSX runtime for React compatibility mode.\n *\n * When `jsxImportSource` is set to `@pyreon/react-compat` (via the vite plugin's\n * `compat: \"react\"` option), OXC rewrites JSX to import from this file:\n * <div className=\"x\" /> → jsx(\"div\", { className: \"x\" })\n *\n * For component VNodes, we wrap the component function so it returns a reactive\n * accessor — enabling React-style re-renders on state change while Pyreon's\n * existing renderer handles all DOM work.\n */\n\nimport type { ComponentFn, Props, VNode, VNodeChild } from \"@pyreon/core\"\nimport { Fragment, h } from \"@pyreon/core\"\nimport { signal } from \"@pyreon/reactivity\"\n\nexport { Fragment }\n\n// ─── Render context (used by hooks) ──────────────────────────────────────────\n\nexport interface RenderContext {\n hooks: unknown[]\n scheduleRerender: () => void\n /** Effect entries pending execution after render */\n pendingEffects: EffectEntry[]\n /** Layout effect entries pending execution after render */\n pendingLayoutEffects: EffectEntry[]\n /** Set to true when the component is unmounted */\n unmounted: boolean\n}\n\nexport interface EffectEntry {\n // biome-ignore lint/suspicious/noConfusingVoidType: matches React's effect signature\n fn: () => (() => void) | void\n deps: unknown[] | undefined\n cleanup: (() => void) | undefined\n}\n\nlet _currentCtx: RenderContext | null = null\nlet _hookIndex = 0\n\nexport function getCurrentCtx(): RenderContext | null {\n return _currentCtx\n}\n\nexport function getHookIndex(): number {\n return _hookIndex++\n}\n\nexport function beginRender(ctx: RenderContext): void {\n _currentCtx = ctx\n _hookIndex = 0\n ctx.pendingEffects = []\n ctx.pendingLayoutEffects = []\n}\n\nexport function endRender(): void {\n _currentCtx = null\n _hookIndex = 0\n}\n\n// ─── Effect runners ──────────────────────────────────────────────────────────\n\nfunction runLayoutEffects(entries: EffectEntry[]): void {\n for (const entry of entries) {\n if (entry.cleanup) entry.cleanup()\n const cleanup = entry.fn()\n entry.cleanup = typeof cleanup === \"function\" ? cleanup : undefined\n }\n}\n\nfunction scheduleEffects(ctx: RenderContext, entries: EffectEntry[]): void {\n if (entries.length === 0) return\n queueMicrotask(() => {\n for (const entry of entries) {\n if (ctx.unmounted) return\n if (entry.cleanup) entry.cleanup()\n const cleanup = entry.fn()\n entry.cleanup = typeof cleanup === \"function\" ? cleanup : undefined\n }\n })\n}\n\n// ─── Component wrapping ──────────────────────────────────────────────────────\n\n// biome-ignore lint/complexity/noBannedTypes: Function is needed for generic component wrapping\nconst _wrapperCache = new WeakMap<Function, ComponentFn>()\n\n// biome-ignore lint/complexity/noBannedTypes: Function is needed for generic component wrapping\nfunction wrapCompatComponent(reactComponent: Function): ComponentFn {\n let wrapped = _wrapperCache.get(reactComponent)\n if (wrapped) return wrapped\n\n // The wrapper returns a reactive accessor (() => VNodeChild) which Pyreon's\n // mountChild treats as a reactive expression via mountReactive.\n wrapped = ((props: Props) => {\n const ctx: RenderContext = {\n hooks: [],\n scheduleRerender: () => {\n // Will be replaced below after version signal is created\n },\n pendingEffects: [],\n pendingLayoutEffects: [],\n unmounted: false,\n }\n\n const version = signal(0)\n let updateScheduled = false\n\n ctx.scheduleRerender = () => {\n if (ctx.unmounted || updateScheduled) return\n updateScheduled = true\n queueMicrotask(() => {\n updateScheduled = false\n if (!ctx.unmounted) version.set(version.peek() + 1)\n })\n }\n\n // Return reactive accessor — Pyreon's mountChild calls mountReactive\n return () => {\n version() // tracked read — triggers re-execution when state changes\n beginRender(ctx)\n const result = (reactComponent as ComponentFn)(props)\n const layoutEffects = ctx.pendingLayoutEffects\n const effects = ctx.pendingEffects\n endRender()\n\n runLayoutEffects(layoutEffects)\n scheduleEffects(ctx, effects)\n\n return result\n }\n }) as unknown as ComponentFn\n\n _wrapperCache.set(reactComponent, wrapped)\n return wrapped\n}\n\n// ─── JSX functions ───────────────────────────────────────────────────────────\n\nexport function jsx(\n type: string | ComponentFn | symbol,\n props: Props & { children?: VNodeChild | VNodeChild[] },\n key?: string | number | null,\n): VNode {\n const { children, ...rest } = props\n const propsWithKey = (key != null ? { ...rest, key } : rest) as Props\n\n if (typeof type === \"function\") {\n // Wrap React-style component for re-render support\n const wrapped = wrapCompatComponent(type)\n const componentProps = children !== undefined ? { ...propsWithKey, children } : propsWithKey\n return h(wrapped, componentProps)\n }\n\n // DOM element or symbol (Fragment): children go in vnode.children\n const childArray = children === undefined ? [] : Array.isArray(children) ? children : [children]\n\n // Map className → class for React compat\n if (typeof type === \"string\" && propsWithKey.className !== undefined) {\n propsWithKey.class = propsWithKey.className\n delete propsWithKey.className\n }\n\n return h(type, propsWithKey, ...(childArray as VNodeChild[]))\n}\n\nexport const jsxs = jsx\nexport const jsxDEV = jsx\n"],"mappings":";;;;AAsCA,IAAI,cAAoC;AACxC,IAAI,aAAa;AAUjB,SAAgB,YAAY,KAA0B;AACpD,eAAc;AACd,cAAa;AACb,KAAI,iBAAiB,EAAE;AACvB,KAAI,uBAAuB,EAAE;;AAG/B,SAAgB,YAAkB;AAChC,eAAc;AACd,cAAa;;AAKf,SAAS,iBAAiB,SAA8B;AACtD,MAAK,MAAM,SAAS,SAAS;AAC3B,MAAI,MAAM,QAAS,OAAM,SAAS;EAClC,MAAM,UAAU,MAAM,IAAI;AAC1B,QAAM,UAAU,OAAO,YAAY,aAAa,UAAU;;;AAI9D,SAAS,gBAAgB,KAAoB,SAA8B;AACzE,KAAI,QAAQ,WAAW,EAAG;AAC1B,sBAAqB;AACnB,OAAK,MAAM,SAAS,SAAS;AAC3B,OAAI,IAAI,UAAW;AACnB,OAAI,MAAM,QAAS,OAAM,SAAS;GAClC,MAAM,UAAU,MAAM,IAAI;AAC1B,SAAM,UAAU,OAAO,YAAY,aAAa,UAAU;;GAE5D;;AAMJ,MAAM,gCAAgB,IAAI,SAAgC;AAG1D,SAAS,oBAAoB,gBAAuC;CAClE,IAAI,UAAU,cAAc,IAAI,eAAe;AAC/C,KAAI,QAAS,QAAO;AAIpB,aAAY,UAAiB;EAC3B,MAAM,MAAqB;GACzB,OAAO,EAAE;GACT,wBAAwB;GAGxB,gBAAgB,EAAE;GAClB,sBAAsB,EAAE;GACxB,WAAW;GACZ;EAED,MAAM,UAAU,OAAO,EAAE;EACzB,IAAI,kBAAkB;AAEtB,MAAI,yBAAyB;AAC3B,OAAI,IAAI,aAAa,gBAAiB;AACtC,qBAAkB;AAClB,wBAAqB;AACnB,sBAAkB;AAClB,QAAI,CAAC,IAAI,UAAW,SAAQ,IAAI,QAAQ,MAAM,GAAG,EAAE;KACnD;;AAIJ,eAAa;AACX,YAAS;AACT,eAAY,IAAI;GAChB,MAAM,SAAU,eAA+B,MAAM;GACrD,MAAM,gBAAgB,IAAI;GAC1B,MAAM,UAAU,IAAI;AACpB,cAAW;AAEX,oBAAiB,cAAc;AAC/B,mBAAgB,KAAK,QAAQ;AAE7B,UAAO;;;AAIX,eAAc,IAAI,gBAAgB,QAAQ;AAC1C,QAAO;;AAKT,SAAgB,IACd,MACA,OACA,KACO;CACP,MAAM,EAAE,UAAU,GAAG,SAAS;CAC9B,MAAM,eAAgB,OAAO,OAAO;EAAE,GAAG;EAAM;EAAK,GAAG;AAEvD,KAAI,OAAO,SAAS,WAIlB,QAAO,EAFS,oBAAoB,KAAK,EAClB,aAAa,SAAY;EAAE,GAAG;EAAc;EAAU,GAAG,aAC/C;CAInC,MAAM,aAAa,aAAa,SAAY,EAAE,GAAG,MAAM,QAAQ,SAAS,GAAG,WAAW,CAAC,SAAS;AAGhG,KAAI,OAAO,SAAS,YAAY,aAAa,cAAc,QAAW;AACpE,eAAa,QAAQ,aAAa;AAClC,SAAO,aAAa;;AAGtB,QAAO,EAAE,MAAM,cAAc,GAAI,WAA4B;;AAG/D,MAAa,OAAO"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { mount } from "@pyreon/runtime-dom";
|
|
2
|
+
|
|
3
|
+
//#region src/dom.ts
|
|
4
|
+
/**
|
|
5
|
+
* @pyreon/react-compat/dom
|
|
6
|
+
*
|
|
7
|
+
* Drop-in for `react-dom/client` — provides `createRoot` so you can keep
|
|
8
|
+
* the same entry-point pattern as a React app.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Drop-in for React 18's `createRoot(container).render(element)`.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import { createRoot } from "@pyreon/react-compat/dom"
|
|
15
|
+
* createRoot(document.getElementById("app")!).render(<App />)
|
|
16
|
+
*/
|
|
17
|
+
function createRoot(container) {
|
|
18
|
+
let cleanup = null;
|
|
19
|
+
return {
|
|
20
|
+
render(element) {
|
|
21
|
+
if (cleanup) cleanup();
|
|
22
|
+
cleanup = mount(element, container);
|
|
23
|
+
},
|
|
24
|
+
unmount() {
|
|
25
|
+
if (cleanup) {
|
|
26
|
+
cleanup();
|
|
27
|
+
cleanup = null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** Alias — matches React 17's `render(element, container)` signature. */
|
|
33
|
+
function render(element, container) {
|
|
34
|
+
mount(element, container);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { createRoot, render };
|
|
39
|
+
//# sourceMappingURL=dom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom.d.ts","names":[],"sources":["../../src/dom.ts"],"mappings":";;;;;;;;;;;;;;;;AAgBA,SAAgB,UAAA,CAAW,SAAA,EAGzB;EACA,IAAI,OAAA,GAA+B,IAAA;EACnC,OAAO;IACL,MAAA,CAAO,OAAA,EAAqB;MAC1B,IAAI,OAAA,EAAS,OAAA,CAAA,CAAS;MACtB,OAAA,GAAU,KAAA,CAAM,OAAA,EAAS,SAAA,CAAyB;;IAEpD,OAAA,CAAA,EAAU;MACR,IAAI,OAAA,EAAS;QACX,OAAA,CAAA,CAAS;QACT,OAAA,GAAU,IAAA;;;GAGf;;;AAIH,SAAgB,MAAA,CAAO,OAAA,EAAqB,SAAA,EAA0B;EACpE,KAAA,CAAM,OAAA,EAAS,SAAA,CAAyB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { VNodeChild } from "@pyreon/core";
|
|
2
|
+
|
|
3
|
+
//#region src/dom.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* Drop-in for React 18's `createRoot(container).render(element)`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* import { createRoot } from "@pyreon/react-compat/dom"
|
|
9
|
+
* createRoot(document.getElementById("app")!).render(<App />)
|
|
10
|
+
*/
|
|
11
|
+
declare function createRoot(container: Element): {
|
|
12
|
+
render: (element: VNodeChild) => void;
|
|
13
|
+
unmount: () => void;
|
|
14
|
+
};
|
|
15
|
+
/** Alias — matches React 17's `render(element, container)` signature. */
|
|
16
|
+
declare function render(element: VNodeChild, container: Element): void;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { createRoot, render };
|
|
19
|
+
//# sourceMappingURL=dom2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom2.d.ts","names":[],"sources":["../../src/dom.ts"],"mappings":";;;;;AAgBA;;;;;iBAAgB,UAAA,CAAW,SAAA,EAAW,OAAA;EACpC,MAAA,GAAS,OAAA,EAAS,UAAA;EAClB,OAAA;AAAA;;iBAkBc,MAAA,CAAO,OAAA,EAAS,UAAA,EAAY,SAAA,EAAW,OAAA"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { Fragment, h } from "@pyreon/core";
|
|
2
|
+
import { signal } from "@pyreon/reactivity";
|
|
3
|
+
|
|
4
|
+
//#region src/jsx-runtime.ts
|
|
5
|
+
|
|
6
|
+
function beginRender(ctx) {
|
|
7
|
+
_currentCtx = ctx;
|
|
8
|
+
_hookIndex = 0;
|
|
9
|
+
ctx.pendingEffects = [];
|
|
10
|
+
ctx.pendingLayoutEffects = [];
|
|
11
|
+
}
|
|
12
|
+
function endRender() {
|
|
13
|
+
_currentCtx = null;
|
|
14
|
+
_hookIndex = 0;
|
|
15
|
+
}
|
|
16
|
+
function runLayoutEffects(entries) {
|
|
17
|
+
for (const entry of entries) {
|
|
18
|
+
if (entry.cleanup) entry.cleanup();
|
|
19
|
+
const cleanup = entry.fn();
|
|
20
|
+
entry.cleanup = typeof cleanup === "function" ? cleanup : void 0;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function scheduleEffects(ctx, entries) {
|
|
24
|
+
if (entries.length === 0) return;
|
|
25
|
+
queueMicrotask(() => {
|
|
26
|
+
for (const entry of entries) {
|
|
27
|
+
if (ctx.unmounted) return;
|
|
28
|
+
if (entry.cleanup) entry.cleanup();
|
|
29
|
+
const cleanup = entry.fn();
|
|
30
|
+
entry.cleanup = typeof cleanup === "function" ? cleanup : void 0;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function wrapCompatComponent(reactComponent) {
|
|
35
|
+
let wrapped = _wrapperCache.get(reactComponent);
|
|
36
|
+
if (wrapped) return wrapped;
|
|
37
|
+
wrapped = props => {
|
|
38
|
+
const ctx = {
|
|
39
|
+
hooks: [],
|
|
40
|
+
scheduleRerender: () => {},
|
|
41
|
+
pendingEffects: [],
|
|
42
|
+
pendingLayoutEffects: [],
|
|
43
|
+
unmounted: false
|
|
44
|
+
};
|
|
45
|
+
const version = signal(0);
|
|
46
|
+
let updateScheduled = false;
|
|
47
|
+
ctx.scheduleRerender = () => {
|
|
48
|
+
if (ctx.unmounted || updateScheduled) return;
|
|
49
|
+
updateScheduled = true;
|
|
50
|
+
queueMicrotask(() => {
|
|
51
|
+
updateScheduled = false;
|
|
52
|
+
if (!ctx.unmounted) version.set(version.peek() + 1);
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
return () => {
|
|
56
|
+
version();
|
|
57
|
+
beginRender(ctx);
|
|
58
|
+
const result = reactComponent(props);
|
|
59
|
+
const layoutEffects = ctx.pendingLayoutEffects;
|
|
60
|
+
const effects = ctx.pendingEffects;
|
|
61
|
+
endRender();
|
|
62
|
+
runLayoutEffects(layoutEffects);
|
|
63
|
+
scheduleEffects(ctx, effects);
|
|
64
|
+
return result;
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
_wrapperCache.set(reactComponent, wrapped);
|
|
68
|
+
return wrapped;
|
|
69
|
+
}
|
|
70
|
+
function jsx(type, props, key) {
|
|
71
|
+
const {
|
|
72
|
+
children,
|
|
73
|
+
...rest
|
|
74
|
+
} = props;
|
|
75
|
+
const propsWithKey = key != null ? {
|
|
76
|
+
...rest,
|
|
77
|
+
key
|
|
78
|
+
} : rest;
|
|
79
|
+
if (typeof type === "function") return h(wrapCompatComponent(type), children !== void 0 ? {
|
|
80
|
+
...propsWithKey,
|
|
81
|
+
children
|
|
82
|
+
} : propsWithKey);
|
|
83
|
+
const childArray = children === void 0 ? [] : Array.isArray(children) ? children : [children];
|
|
84
|
+
if (typeof type === "string" && propsWithKey.className !== void 0) {
|
|
85
|
+
propsWithKey.class = propsWithKey.className;
|
|
86
|
+
delete propsWithKey.className;
|
|
87
|
+
}
|
|
88
|
+
return h(type, propsWithKey, ...childArray);
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
export { Fragment, jsx, jsxs };
|
|
92
|
+
//# sourceMappingURL=jsx-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx-runtime.d.ts","names":[],"sources":["../../src/jsx-runtime.ts"],"mappings":";;;;;AAiDA,SAAgB,WAAA,CAAY,GAAA,EAA0B;EACpD,WAAA,GAAc,GAAA;EACd,UAAA,GAAa,CAAA;EACb,GAAA,CAAI,cAAA,GAAiB,EAAE;EACvB,GAAA,CAAI,oBAAA,GAAuB,EAAE;;AAG/B,SAAgB,SAAA,CAAA,EAAkB;EAChC,WAAA,GAAc,IAAA;EACd,UAAA,GAAa,CAAA;;AAKf,SAAS,gBAAA,CAAiB,OAAA,EAA8B;EACtD,KAAK,MAAM,KAAA,IAAS,OAAA,EAAS;IAC3B,IAAI,KAAA,CAAM,OAAA,EAAS,KAAA,CAAM,OAAA,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0,0 +1,10 @@
|
|
|
1
|
+
import { ComponentFn, Fragment, Props, VNode, VNodeChild } from "@pyreon/core";
|
|
2
|
+
|
|
3
|
+
//#region src/jsx-runtime.d.ts
|
|
4
|
+
declare function jsx(type: string | ComponentFn | symbol, props: Props & {
|
|
5
|
+
children?: VNodeChild | VNodeChild[];
|
|
6
|
+
}, key?: string | number | null): VNode;
|
|
7
|
+
declare const jsxs: typeof jsx;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { Fragment, jsx, jsxs };
|
|
10
|
+
//# sourceMappingURL=jsx-runtime2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsx-runtime2.d.ts","names":[],"sources":["../../src/jsx-runtime.ts"],"mappings":";;;iBA4IgB,GAAA,CACd,IAAA,WAAe,WAAA,WACf,KAAA,EAAO,KAAA;EAAU,QAAA,GAAW,UAAA,GAAa,UAAA;AAAA,GACzC,GAAA,4BACC,KAAA;AAAA,cAuBU,IAAA,SAAI,GAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pyreon/react-compat",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "React-compatible API shim for Pyreon — write React-style hooks that run on Pyreon's reactive engine",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
"prepublishOnly": "bun run build"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@pyreon/core": "^0.5.
|
|
58
|
-
"@pyreon/reactivity": "^0.5.
|
|
59
|
-
"@pyreon/runtime-dom": "^0.5.
|
|
57
|
+
"@pyreon/core": "^0.5.1",
|
|
58
|
+
"@pyreon/reactivity": "^0.5.1",
|
|
59
|
+
"@pyreon/runtime-dom": "^0.5.1"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@happy-dom/global-registrator": "^20.8.3",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Fragment, jsx, jsxs } from "./jsx-runtime"
|