@adam26davidson/char-matrix-react-renderer 0.0.2
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/README.md +56 -0
- package/dist/__tests__/mockRenderTarget.d.ts +10 -0
- package/dist/__tests__/mockRenderTarget.d.ts.map +1 -0
- package/dist/__tests__/mockRenderTarget.js +52 -0
- package/dist/__tests__/mockRenderTarget.js.map +1 -0
- package/dist/hostConfig.d.ts +57 -0
- package/dist/hostConfig.d.ts.map +1 -0
- package/dist/hostConfig.js +258 -0
- package/dist/hostConfig.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/renderer.d.ts +14 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +44 -0
- package/dist/renderer.js.map +1 -0
- package/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +38 -0
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# @adam26davidson/char-matrix-react-renderer
|
|
2
|
+
|
|
3
|
+
Declarative React JSX renderer for [`@adam26davidson/char-matrix`](https://www.npmjs.com/package/@adam26davidson/char-matrix) element trees. Built on `react-reconciler`, this package lets you compose char-matrix UIs with JSX, React state, hooks, and component composition.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Custom React reconciler** — Maps React operations to char-matrix element creation, child management, and prop updates
|
|
8
|
+
- **JSX intrinsic elements** — `<cm-container>`, `<cm-text>`, `<cm-table>` with full TypeScript support
|
|
9
|
+
- **In-place updates** — Text content updates without element recreation; children managed via a WeakMap bridge between React's incremental mutations and char-matrix's bulk `setChildren()` API
|
|
10
|
+
- **onClick support** — Click handlers wired through the reconciler
|
|
11
|
+
- **Animation handler wiring** — `DefaultAnimationHandler.setElement()` called automatically after element creation
|
|
12
|
+
- **setRoot bridging** — Reconciler calls `view.setRoot()` when the root element is committed, integrating with the render loop
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @adam26davidson/char-matrix-react-renderer @adam26davidson/char-matrix react
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
```tsx
|
|
23
|
+
import { render, unmount } from "@adam26davidson/char-matrix-react-renderer";
|
|
24
|
+
|
|
25
|
+
function Dashboard() {
|
|
26
|
+
const [time, setTime] = useState(new Date());
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<cm-container elementKey="root" mainAxis="y" widthType="relative" width={1} spacing={1}>
|
|
30
|
+
<cm-text elementKey="clock" text={formatTime(time)} />
|
|
31
|
+
<cm-container elementKey="row" mainAxis="x" spacing={2}>
|
|
32
|
+
<cm-text elementKey="label" text="Hello, world!" bordered paddingX={1} />
|
|
33
|
+
</cm-container>
|
|
34
|
+
</cm-container>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Render into a RenderTarget (e.g. MatrixView)
|
|
39
|
+
render(<Dashboard />, view);
|
|
40
|
+
|
|
41
|
+
// Later, to tear down
|
|
42
|
+
unmount(view);
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Note: use `elementKey` instead of `key` for the char-matrix element key, since React reserves `key` for reconciliation.
|
|
46
|
+
|
|
47
|
+
## Peer dependencies
|
|
48
|
+
|
|
49
|
+
- `@adam26davidson/char-matrix`
|
|
50
|
+
- `react` ^18.0.0
|
|
51
|
+
|
|
52
|
+
## Related packages
|
|
53
|
+
|
|
54
|
+
- [`@adam26davidson/char-matrix`](https://www.npmjs.com/package/@adam26davidson/char-matrix) — Core layout and rendering engine
|
|
55
|
+
- [`@adam26davidson/char-matrix-fx`](https://www.npmjs.com/package/@adam26davidson/char-matrix-fx) — Animations, physics, and surface transforms
|
|
56
|
+
- [`@adam26davidson/char-matrix-react`](https://www.npmjs.com/package/@adam26davidson/char-matrix-react) — Embed React components inside a character matrix layout
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RenderTarget, Element } from "@adam26davidson/char-matrix";
|
|
2
|
+
/**
|
|
3
|
+
* Minimal mock RenderTarget for testing the reconciler.
|
|
4
|
+
* Tracks registered elements and root element.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createMockRenderTarget(width?: number, height?: number): RenderTarget & {
|
|
7
|
+
registeredElements: Set<Element>;
|
|
8
|
+
rootElement: Element | null;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=mockRenderTarget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockRenderTarget.d.ts","sourceRoot":"","sources":["../../src/__tests__/mockRenderTarget.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAc,MAAM,6BAA6B,CAAC;AAErF;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,SAAK,EACV,MAAM,SAAK,GACV,YAAY,GAAG;IAChB,kBAAkB,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACjC,WAAW,EAAE,OAAO,GAAG,IAAI,CAAC;CAC7B,CA4DA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { IntPoint } from "@adam26davidson/char-matrix";
|
|
2
|
+
/**
|
|
3
|
+
* Minimal mock RenderTarget for testing the reconciler.
|
|
4
|
+
* Tracks registered elements and root element.
|
|
5
|
+
*/
|
|
6
|
+
export function createMockRenderTarget(width = 80, height = 24) {
|
|
7
|
+
const registeredElements = new Set();
|
|
8
|
+
let rootElement = null;
|
|
9
|
+
const target = {
|
|
10
|
+
registeredElements,
|
|
11
|
+
get rootElement() {
|
|
12
|
+
return rootElement;
|
|
13
|
+
},
|
|
14
|
+
set rootElement(el) {
|
|
15
|
+
rootElement = el;
|
|
16
|
+
},
|
|
17
|
+
setCursor(_cursor) { },
|
|
18
|
+
setContentLayerChar(_char, _location, _offset, _zIndex) { },
|
|
19
|
+
getContentLayerChar(_location, _offset) {
|
|
20
|
+
return " ";
|
|
21
|
+
},
|
|
22
|
+
setAnimationLayerChar(_char, _location, _offset, _zIndex) { },
|
|
23
|
+
getPixelOffset() {
|
|
24
|
+
return new IntPoint(0, 0);
|
|
25
|
+
},
|
|
26
|
+
getSize() {
|
|
27
|
+
return new IntPoint(width, height);
|
|
28
|
+
},
|
|
29
|
+
getIsMobile() {
|
|
30
|
+
return false;
|
|
31
|
+
},
|
|
32
|
+
registerElement(element) {
|
|
33
|
+
registeredElements.add(element);
|
|
34
|
+
},
|
|
35
|
+
unregisterElement(element) {
|
|
36
|
+
registeredElements.delete(element);
|
|
37
|
+
},
|
|
38
|
+
setRoot(element) {
|
|
39
|
+
// Unregister old root tree
|
|
40
|
+
if (rootElement) {
|
|
41
|
+
rootElement.unregisterWithView();
|
|
42
|
+
}
|
|
43
|
+
rootElement = element;
|
|
44
|
+
element.registerWithView();
|
|
45
|
+
},
|
|
46
|
+
getRoot() {
|
|
47
|
+
return rootElement;
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
return target;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=mockRenderTarget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockRenderTarget.js","sourceRoot":"","sources":["../../src/__tests__/mockRenderTarget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAGvD;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CACpC,KAAK,GAAG,EAAE,EACV,MAAM,GAAG,EAAE;IAKX,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAW,CAAC;IAC9C,IAAI,WAAW,GAAmB,IAAI,CAAC;IAEvC,MAAM,MAAM,GAGR;QACF,kBAAkB;QAClB,IAAI,WAAW;YACb,OAAO,WAAW,CAAC;QACrB,CAAC;QACD,IAAI,WAAW,CAAC,EAAkB;YAChC,WAAW,GAAG,EAAE,CAAC;QACnB,CAAC;QACD,SAAS,CAAC,OAAmB,IAAG,CAAC;QACjC,mBAAmB,CACjB,KAAa,EACb,SAAmB,EACnB,OAAkB,EAClB,OAAgB,IACf,CAAC;QACJ,mBAAmB,CAAC,SAAmB,EAAE,OAAkB;YACzD,OAAO,GAAG,CAAC;QACb,CAAC;QACD,qBAAqB,CACnB,KAAa,EACb,SAAmB,EACnB,OAAkB,EAClB,OAAgB,IACf,CAAC;QACJ,cAAc;YACZ,OAAO,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO;YACL,OAAO,IAAI,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACrC,CAAC;QACD,WAAW;YACT,OAAO,KAAK,CAAC;QACf,CAAC;QACD,eAAe,CAAC,OAAgB;YAC9B,kBAAkB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC;QACD,iBAAiB,CAAC,OAAgB;YAChC,kBAAkB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACrC,CAAC;QACD,OAAO,CAAC,OAAgB;YACtB,2BAA2B;YAC3B,IAAI,WAAW,EAAE,CAAC;gBAChB,WAAW,CAAC,kBAAkB,EAAE,CAAC;YACnC,CAAC;YACD,WAAW,GAAG,OAAO,CAAC;YACtB,OAAO,CAAC,gBAAgB,EAAE,CAAC;QAC7B,CAAC;QACD,OAAO;YACL,OAAO,WAAY,CAAC;QACtB,CAAC;KACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { RenderTarget, Element, Alignment, Axis, SizingMethod, CursorType, ColumnDef, ElementAnimationHandler } from "@adam26davidson/char-matrix";
|
|
2
|
+
export type CMElementType = "cm-container" | "cm-text" | "cm-table";
|
|
3
|
+
/** Props common to all char-matrix elements (mirrors ElementConfig minus view). */
|
|
4
|
+
interface CMBaseProps {
|
|
5
|
+
/** Standard React reconciliation key — stripped from props at runtime. */
|
|
6
|
+
key?: string | number;
|
|
7
|
+
/** The char-matrix element key. React's `key` is stripped from props, so use `elementKey`. */
|
|
8
|
+
elementKey: string;
|
|
9
|
+
width?: number;
|
|
10
|
+
widthType?: SizingMethod;
|
|
11
|
+
height?: number;
|
|
12
|
+
heightType?: SizingMethod;
|
|
13
|
+
scrollable?: boolean;
|
|
14
|
+
paddingTop?: number;
|
|
15
|
+
paddingBottom?: number;
|
|
16
|
+
paddingLeft?: number;
|
|
17
|
+
paddingRight?: number;
|
|
18
|
+
paddingX?: number;
|
|
19
|
+
paddingY?: number;
|
|
20
|
+
padding?: number;
|
|
21
|
+
bordered?: boolean;
|
|
22
|
+
backgroundChar?: string;
|
|
23
|
+
cursor?: CursorType;
|
|
24
|
+
xOffset?: number;
|
|
25
|
+
yOffset?: number;
|
|
26
|
+
animationHandler?: ElementAnimationHandler;
|
|
27
|
+
entranceTiming?: "parallel" | "series";
|
|
28
|
+
exitTiming?: "parallel" | "series";
|
|
29
|
+
zIndex?: number;
|
|
30
|
+
onClick?: () => void;
|
|
31
|
+
}
|
|
32
|
+
export interface CMContainerProps extends CMBaseProps {
|
|
33
|
+
mainAxis: Axis;
|
|
34
|
+
justifyContent?: Alignment;
|
|
35
|
+
alignItems?: Alignment;
|
|
36
|
+
spacing?: number;
|
|
37
|
+
children?: React.ReactNode;
|
|
38
|
+
}
|
|
39
|
+
export interface CMTextProps extends CMBaseProps {
|
|
40
|
+
text: string;
|
|
41
|
+
hoverTransform?: "none" | "uppercase" | "bold";
|
|
42
|
+
}
|
|
43
|
+
export interface CMTableProps extends CMBaseProps {
|
|
44
|
+
columns: ColumnDef[];
|
|
45
|
+
title?: string;
|
|
46
|
+
titleAlign?: "start" | "center" | "end";
|
|
47
|
+
showRowSeparators?: boolean;
|
|
48
|
+
}
|
|
49
|
+
export type CMProps = CMContainerProps | CMTextProps | CMTableProps;
|
|
50
|
+
/** The root container object passed to the reconciler. */
|
|
51
|
+
export interface RootContainer {
|
|
52
|
+
view: RenderTarget;
|
|
53
|
+
rootElement: Element | null;
|
|
54
|
+
}
|
|
55
|
+
export declare const hostConfig: any;
|
|
56
|
+
export {};
|
|
57
|
+
//# sourceMappingURL=hostConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hostConfig.d.ts","sourceRoot":"","sources":["../src/hostConfig.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,YAAY,EACZ,OAAO,EAKP,SAAS,EACT,IAAI,EACJ,YAAY,EACZ,UAAU,EACV,SAAS,EACT,uBAAuB,EACxB,MAAM,6BAA6B,CAAC;AAMrC,MAAM,MAAM,aAAa,GAAG,cAAc,GAAG,SAAS,GAAG,UAAU,CAAC;AAEpE,mFAAmF;AACnF,UAAU,WAAW;IACnB,0EAA0E;IAC1E,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,8FAA8F;IAC9F,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,YAAY,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,YAAY,CAAC;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,uBAAuB,CAAC;IAC3C,cAAc,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC;IACvC,UAAU,CAAC,EAAE,UAAU,GAAG,QAAQ,CAAC;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,MAAM,WAAW,gBAAiB,SAAQ,WAAW;IACnD,QAAQ,EAAE,IAAI,CAAC;IACf,cAAc,CAAC,EAAE,SAAS,CAAC;IAC3B,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,MAAM,WAAW,WAAY,SAAQ,WAAW;IAC9C,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;CAChD;AAED,MAAM,WAAW,YAAa,SAAQ,WAAW;IAC/C,OAAO,EAAE,SAAS,EAAE,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;IACxC,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,MAAM,MAAM,OAAO,GAAG,gBAAgB,GAAG,WAAW,GAAG,YAAY,CAAC;AAEpE,0DAA0D;AAC1D,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,YAAY,CAAC;IACnB,WAAW,EAAE,OAAO,GAAG,IAAI,CAAC;CAC7B;AAqID,eAAO,MAAM,UAAU,EAAE,GAoMxB,CAAC"}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
// react-reconciler types are used via the `any`-typed hostConfig export.
|
|
2
|
+
import { ContainerElement, TextElement, TableElement, } from "@adam26davidson/char-matrix";
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// Element creation helpers
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
function buildBaseConfig(props, view) {
|
|
7
|
+
return {
|
|
8
|
+
key: props.elementKey,
|
|
9
|
+
view,
|
|
10
|
+
width: props.width,
|
|
11
|
+
widthType: props.widthType,
|
|
12
|
+
height: props.height,
|
|
13
|
+
heightType: props.heightType,
|
|
14
|
+
scrollable: props.scrollable,
|
|
15
|
+
paddingTop: props.paddingTop,
|
|
16
|
+
paddingBottom: props.paddingBottom,
|
|
17
|
+
paddingLeft: props.paddingLeft,
|
|
18
|
+
paddingRight: props.paddingRight,
|
|
19
|
+
paddingX: props.paddingX,
|
|
20
|
+
paddingY: props.paddingY,
|
|
21
|
+
padding: props.padding,
|
|
22
|
+
bordered: props.bordered,
|
|
23
|
+
backgroundChar: props.backgroundChar,
|
|
24
|
+
cursor: props.cursor,
|
|
25
|
+
xOffset: props.xOffset,
|
|
26
|
+
yOffset: props.yOffset,
|
|
27
|
+
animationHandler: props.animationHandler,
|
|
28
|
+
entranceTiming: props.entranceTiming,
|
|
29
|
+
exitTiming: props.exitTiming,
|
|
30
|
+
zIndex: props.zIndex,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function createElement(type, props, view) {
|
|
34
|
+
const base = buildBaseConfig(props, view);
|
|
35
|
+
let instance;
|
|
36
|
+
switch (type) {
|
|
37
|
+
case "cm-container": {
|
|
38
|
+
const p = props;
|
|
39
|
+
instance = new ContainerElement({
|
|
40
|
+
...base,
|
|
41
|
+
mainAxis: p.mainAxis,
|
|
42
|
+
justifyContent: p.justifyContent,
|
|
43
|
+
alignItems: p.alignItems,
|
|
44
|
+
spacing: p.spacing,
|
|
45
|
+
});
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
case "cm-text": {
|
|
49
|
+
const p = props;
|
|
50
|
+
instance = new TextElement({
|
|
51
|
+
...base,
|
|
52
|
+
text: p.text,
|
|
53
|
+
hoverTransform: p.hoverTransform,
|
|
54
|
+
});
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
case "cm-table": {
|
|
58
|
+
const p = props;
|
|
59
|
+
instance = new TableElement({
|
|
60
|
+
...base,
|
|
61
|
+
columns: p.columns,
|
|
62
|
+
title: p.title,
|
|
63
|
+
titleAlign: p.titleAlign,
|
|
64
|
+
showRowSeparators: p.showRowSeparators,
|
|
65
|
+
});
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
default:
|
|
69
|
+
throw new Error(`Unknown char-matrix element type: ${type}`);
|
|
70
|
+
}
|
|
71
|
+
// Wire onClick handler
|
|
72
|
+
if (props.onClick) {
|
|
73
|
+
instance.setOnClick(props.onClick);
|
|
74
|
+
}
|
|
75
|
+
// Wire animation handler — DefaultAnimationHandler needs setElement() called
|
|
76
|
+
// after the element is constructed. Duck-type check since setElement is not
|
|
77
|
+
// on the ElementAnimationHandler interface.
|
|
78
|
+
const handler = props.animationHandler;
|
|
79
|
+
if (handler?.setElement) {
|
|
80
|
+
handler.setElement(instance);
|
|
81
|
+
}
|
|
82
|
+
return instance;
|
|
83
|
+
}
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
// Tracked children — we need to maintain an ordered child list per element
|
|
86
|
+
// because Element.setChildren() replaces the whole array.
|
|
87
|
+
// ---------------------------------------------------------------------------
|
|
88
|
+
const childrenMap = new WeakMap();
|
|
89
|
+
function getTrackedChildren(parent) {
|
|
90
|
+
let children = childrenMap.get(parent);
|
|
91
|
+
if (!children) {
|
|
92
|
+
children = [];
|
|
93
|
+
childrenMap.set(parent, children);
|
|
94
|
+
}
|
|
95
|
+
return children;
|
|
96
|
+
}
|
|
97
|
+
function commitChildren(parent) {
|
|
98
|
+
const children = getTrackedChildren(parent);
|
|
99
|
+
parent.setChildren([...children]);
|
|
100
|
+
}
|
|
101
|
+
// The react-reconciler types require many methods that are no-ops for our use case.
|
|
102
|
+
// We implement all the ones that matter and cast the rest.
|
|
103
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
104
|
+
export const hostConfig = {
|
|
105
|
+
// --------------- Feature flags ---------------
|
|
106
|
+
supportsMutation: true,
|
|
107
|
+
supportsPersistence: false,
|
|
108
|
+
supportsHydration: false,
|
|
109
|
+
isPrimaryRenderer: true,
|
|
110
|
+
// --------------- Context ---------------
|
|
111
|
+
getRootHostContext() {
|
|
112
|
+
return {};
|
|
113
|
+
},
|
|
114
|
+
getChildHostContext() {
|
|
115
|
+
return {};
|
|
116
|
+
},
|
|
117
|
+
// --------------- Instance creation ---------------
|
|
118
|
+
createInstance(type, props, rootContainer) {
|
|
119
|
+
return createElement(type, props, rootContainer.view);
|
|
120
|
+
},
|
|
121
|
+
createTextInstance() {
|
|
122
|
+
throw new Error("Raw text nodes are not supported. Use <cm-text text=\"...\"> instead.");
|
|
123
|
+
},
|
|
124
|
+
// --------------- Children (mutation mode) ---------------
|
|
125
|
+
appendInitialChild(parent, child) {
|
|
126
|
+
const children = getTrackedChildren(parent);
|
|
127
|
+
children.push(child);
|
|
128
|
+
// Don't commit yet — React calls this during the "complete" phase.
|
|
129
|
+
// finalizeInitialChildren or the commit phase will handle it.
|
|
130
|
+
},
|
|
131
|
+
appendChild(parent, child) {
|
|
132
|
+
const children = getTrackedChildren(parent);
|
|
133
|
+
children.push(child);
|
|
134
|
+
commitChildren(parent);
|
|
135
|
+
},
|
|
136
|
+
appendChildToContainer(container, child) {
|
|
137
|
+
container.rootElement = child;
|
|
138
|
+
// Use setRoot if available (MatrixView implements this) for full integration
|
|
139
|
+
// with the render loop. Falls back to registerWithView for basic targets.
|
|
140
|
+
if (container.view.setRoot) {
|
|
141
|
+
container.view.setRoot(child);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
child.registerWithView();
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
insertBefore(parent, child, beforeChild) {
|
|
148
|
+
const children = getTrackedChildren(parent);
|
|
149
|
+
const idx = children.indexOf(beforeChild);
|
|
150
|
+
if (idx >= 0) {
|
|
151
|
+
children.splice(idx, 0, child);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
children.push(child);
|
|
155
|
+
}
|
|
156
|
+
commitChildren(parent);
|
|
157
|
+
},
|
|
158
|
+
insertInContainerBefore(container, child, _beforeChild) {
|
|
159
|
+
container.rootElement = child;
|
|
160
|
+
if (container.view.setRoot) {
|
|
161
|
+
container.view.setRoot(child);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
child.registerWithView();
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
removeChild(parent, child) {
|
|
168
|
+
const children = getTrackedChildren(parent);
|
|
169
|
+
const idx = children.indexOf(child);
|
|
170
|
+
if (idx >= 0) {
|
|
171
|
+
children.splice(idx, 1);
|
|
172
|
+
}
|
|
173
|
+
child.unregisterWithView();
|
|
174
|
+
commitChildren(parent);
|
|
175
|
+
},
|
|
176
|
+
removeChildFromContainer(container, child) {
|
|
177
|
+
child.unregisterWithView();
|
|
178
|
+
if (container.rootElement === child) {
|
|
179
|
+
container.rootElement = null;
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
clearContainer(container) {
|
|
183
|
+
if (container.rootElement) {
|
|
184
|
+
container.rootElement.unregisterWithView();
|
|
185
|
+
container.rootElement = null;
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
// --------------- Updates ---------------
|
|
189
|
+
prepareUpdate(_instance, _type, oldProps, newProps) {
|
|
190
|
+
// Return a truthy payload if any prop (other than children) changed.
|
|
191
|
+
const oKeys = Object.keys(oldProps).filter((k) => k !== "children");
|
|
192
|
+
const nKeys = Object.keys(newProps).filter((k) => k !== "children");
|
|
193
|
+
if (oKeys.length !== nKeys.length)
|
|
194
|
+
return { changed: true };
|
|
195
|
+
for (const k of oKeys) {
|
|
196
|
+
if (oldProps[k] !== newProps[k])
|
|
197
|
+
return { changed: true };
|
|
198
|
+
}
|
|
199
|
+
return null;
|
|
200
|
+
},
|
|
201
|
+
commitUpdate(instance, _updatePayload, type, oldProps, newProps) {
|
|
202
|
+
// Update text content
|
|
203
|
+
if (type === "cm-text") {
|
|
204
|
+
const oldText = oldProps.text;
|
|
205
|
+
const newText = newProps.text;
|
|
206
|
+
if (oldText !== newText) {
|
|
207
|
+
instance.setBaseText(newText);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// Update onClick handler
|
|
211
|
+
if (oldProps.onClick !== newProps.onClick) {
|
|
212
|
+
if (newProps.onClick) {
|
|
213
|
+
instance.setOnClick(newProps.onClick);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
// --------------- Finalize ---------------
|
|
218
|
+
finalizeInitialChildren() {
|
|
219
|
+
return true;
|
|
220
|
+
},
|
|
221
|
+
commitMount(instance) {
|
|
222
|
+
// Called after finalizeInitialChildren returns true.
|
|
223
|
+
// Commit the tracked children now that the initial tree is assembled.
|
|
224
|
+
const children = getTrackedChildren(instance);
|
|
225
|
+
if (children.length > 0) {
|
|
226
|
+
instance.setChildren([...children]);
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
// --------------- Misc required methods ---------------
|
|
230
|
+
prepareForCommit() {
|
|
231
|
+
return null;
|
|
232
|
+
},
|
|
233
|
+
resetAfterCommit() { },
|
|
234
|
+
shouldSetTextContent() {
|
|
235
|
+
return false;
|
|
236
|
+
},
|
|
237
|
+
getPublicInstance(instance) {
|
|
238
|
+
return instance;
|
|
239
|
+
},
|
|
240
|
+
preparePortalMount() { },
|
|
241
|
+
scheduleTimeout: setTimeout,
|
|
242
|
+
cancelTimeout: clearTimeout,
|
|
243
|
+
noTimeout: -1,
|
|
244
|
+
getCurrentUpdatePriority() {
|
|
245
|
+
return 0b0000000000000000000000000010000; // DefaultEventPriority
|
|
246
|
+
},
|
|
247
|
+
getInstanceFromNode() {
|
|
248
|
+
return null;
|
|
249
|
+
},
|
|
250
|
+
beforeActiveInstanceBlur() { },
|
|
251
|
+
afterActiveInstanceBlur() { },
|
|
252
|
+
prepareScopeUpdate() { },
|
|
253
|
+
getInstanceFromScope() {
|
|
254
|
+
return null;
|
|
255
|
+
},
|
|
256
|
+
detachDeletedInstance() { },
|
|
257
|
+
};
|
|
258
|
+
//# sourceMappingURL=hostConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hostConfig.js","sourceRoot":"","sources":["../src/hostConfig.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,YAAY,GACb,MAAM,6BAA6B,CAAC;AAgFrC,8EAA8E;AAC9E,2BAA2B;AAC3B,8EAA8E;AAE9E,SAAS,eAAe,CACtB,KAAkB,EAClB,IAAkB;IAElB,OAAO;QACL,GAAG,EAAE,KAAK,CAAC,UAAU;QACrB,IAAI;QACJ,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,aAAa,EAAE,KAAK,CAAC,aAAa;QAClC,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,YAAY,EAAE,KAAK,CAAC,YAAY;QAChC,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,OAAO,EAAE,KAAK,CAAC,OAAO;QACtB,gBAAgB,EAAE,KAAK,CAAC,gBAAgB;QACxC,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,UAAU,EA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B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,WAAW,CAAC,QAAkB;QAC5B,qDAAqD;QACrD,sEAAsE;QACtE,MAAM,QAAQ,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QAC9C,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACxB,QAAQ,CAAC,WAAW,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IAED,wDAAwD;IACxD,gBAAgB;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAED,gBAAgB,KAAI,CAAC;IAErB,oBAAoB;QAClB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,iBAAiB,CAAC,QAAkB;QAClC,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,kBAAkB,KAAI,CAAC;IAEvB,eAAe,EAAE,UAAU;IAC3B,aAAa,EAAE,YAAY;IAC3B,SAAS,EAAE,CAAC,CAAc;IAE1B,wBAAwB;QACtB,OAAO,iCAAiC,CAAC,CAAC,uBAAuB;IACnE,CAAC;IAED,mBAAmB;QACjB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,wBAAwB,KAAI,CAAC;IAC7B,uBAAuB,KAAI,CAAC;IAE5B,kBAAkB,KAAI,CAAC;IACvB,oBAAoB;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,qBAAqB,KAAI,CAAC;CAC3B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC7C,YAAY,EACV,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,aAAa,GACd,MAAM,cAAc,CAAC;AAGtB,OAAO,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAQ7C,oDAAoD;AACpD,OAAO,SAAS,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { RenderTarget, Element } from "@adam26davidson/char-matrix";
|
|
3
|
+
/**
|
|
4
|
+
* Render a React element tree into char-matrix elements attached to the given
|
|
5
|
+
* RenderTarget (view).
|
|
6
|
+
*
|
|
7
|
+
* Returns the root char-matrix Element once the initial render is committed.
|
|
8
|
+
*/
|
|
9
|
+
export declare function render(element: ReactNode, view: RenderTarget): Element;
|
|
10
|
+
/**
|
|
11
|
+
* Unmount a previously rendered tree, unregistering all elements from the view.
|
|
12
|
+
*/
|
|
13
|
+
export declare function unmount(view: RenderTarget): void;
|
|
14
|
+
//# sourceMappingURL=renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAWzE;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,GAAG,OAAO,CA2BtE;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,CAOhD"}
|
package/dist/renderer.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import ReactReconciler from "react-reconciler";
|
|
2
|
+
import { hostConfig } from "./hostConfig";
|
|
3
|
+
const reconciler = ReactReconciler(hostConfig);
|
|
4
|
+
// Map from RenderTarget → fiber root, so we can re-render and unmount.
|
|
5
|
+
const roots = new Map();
|
|
6
|
+
/**
|
|
7
|
+
* Render a React element tree into char-matrix elements attached to the given
|
|
8
|
+
* RenderTarget (view).
|
|
9
|
+
*
|
|
10
|
+
* Returns the root char-matrix Element once the initial render is committed.
|
|
11
|
+
*/
|
|
12
|
+
export function render(element, view) {
|
|
13
|
+
let entry = roots.get(view);
|
|
14
|
+
if (!entry) {
|
|
15
|
+
const container = { view, rootElement: null };
|
|
16
|
+
const fiberRoot = reconciler.createContainer(container, 0, // LegacyRoot tag
|
|
17
|
+
null, // hydrationCallbacks
|
|
18
|
+
false, // isStrictMode
|
|
19
|
+
null, // concurrentUpdatesByDefaultOverride
|
|
20
|
+
"", // identifierPrefix
|
|
21
|
+
(err) => console.error(err), // onUncaughtError
|
|
22
|
+
(err) => console.error(err), // onCaughtError
|
|
23
|
+
(err) => console.error(err), // onRecoverableError
|
|
24
|
+
() => { });
|
|
25
|
+
entry = { fiberRoot, container };
|
|
26
|
+
roots.set(view, entry);
|
|
27
|
+
}
|
|
28
|
+
reconciler.updateContainer(element, entry.fiberRoot, null, () => { });
|
|
29
|
+
// Flush synchronous work so the tree is committed immediately.
|
|
30
|
+
reconciler.flushSync();
|
|
31
|
+
return entry.container.rootElement;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Unmount a previously rendered tree, unregistering all elements from the view.
|
|
35
|
+
*/
|
|
36
|
+
export function unmount(view) {
|
|
37
|
+
const entry = roots.get(view);
|
|
38
|
+
if (entry) {
|
|
39
|
+
reconciler.updateContainer(null, entry.fiberRoot, null, () => { });
|
|
40
|
+
reconciler.flushSync();
|
|
41
|
+
roots.delete(view);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../src/renderer.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,MAAM,kBAAkB,CAAC;AAG/C,OAAO,EAAE,UAAU,EAAiB,MAA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ACH,MAAM,UAAU,OAAO,CAAC,IAAkB;IACxC,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,KAAK,EAAE,CAAC;QACV,UAAU,CAAC,eAAe,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAClE,UAAU,CAAC,SAAS,EAAE,CAAC;QACvB,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACrB,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CMContainerProps, CMTextProps, CMTableProps } from "./hostConfig";
|
|
2
|
+
declare global {
|
|
3
|
+
namespace JSX {
|
|
4
|
+
interface IntrinsicElements {
|
|
5
|
+
"cm-container": CMContainerProps;
|
|
6
|
+
"cm-text": CMTextProps;
|
|
7
|
+
"cm-table": CMTableProps;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEhF,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,GAAG,CAAC;QACZ,UAAU,iBAAiB;YACzB,cAAc,EAAE,gBAAgB,CAAC;YACjC,SAAS,EAAE,WAAW,CAAC;YACvB,UAAU,EAAE,YAAY,CAAC;SAC1B;KACF;CACF"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@adam26davidson/char-matrix-react-renderer",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "rm -rf dist && tsc",
|
|
21
|
+
"clean": "rm -rf dist",
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"test:watch": "vitest"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"react-reconciler": "^0.29.0"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@adam26davidson/char-matrix": "*",
|
|
30
|
+
"react": "^18.0.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/react": "^18.3.3",
|
|
34
|
+
"@types/react-reconciler": "^0.33.0",
|
|
35
|
+
"typescript": "^5.2.2",
|
|
36
|
+
"vitest": "^3.0.2"
|
|
37
|
+
}
|
|
38
|
+
}
|