|
|
|
@ -67,11 +67,14 @@ export function runAppCompiled(app: App, canvas: HTMLCanvasElement, rt: any) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function expandStateful(ui: UIValue, path: number[]): UIValue {
|
|
|
|
function expandStateful(ui: UIValue, path: number[], renderedKeys: Set<string>): UIValue {
|
|
|
|
switch (ui.kind) {
|
|
|
|
switch (ui.kind) {
|
|
|
|
case 'stateful': {
|
|
|
|
case 'stateful': {
|
|
|
|
const fullKey = [...path, ui.key].join('.');
|
|
|
|
const fullKey = [...path, ui.key].join('.');
|
|
|
|
|
|
|
|
renderedKeys.add(fullKey);
|
|
|
|
|
|
|
|
|
|
|
|
let instance = componentInstances.get(fullKey);
|
|
|
|
let instance = componentInstances.get(fullKey);
|
|
|
|
|
|
|
|
const isNew = !instance;
|
|
|
|
|
|
|
|
|
|
|
|
if (!instance) {
|
|
|
|
if (!instance) {
|
|
|
|
instance = {
|
|
|
|
instance = {
|
|
|
|
@ -86,6 +89,10 @@ export function runAppCompiled(app: App, canvas: HTMLCanvasElement, rt: any) {
|
|
|
|
instance.view = ui.view;
|
|
|
|
instance.view = ui.view;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ui.autoFocus && isNew) {
|
|
|
|
|
|
|
|
setFocus(fullKey);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const viewResult = instance.view(instance.state);
|
|
|
|
const viewResult = instance.view(instance.state);
|
|
|
|
let viewUI = valueToUI(viewResult);
|
|
|
|
let viewUI = valueToUI(viewResult);
|
|
|
|
|
|
|
|
|
|
|
|
@ -96,7 +103,7 @@ export function runAppCompiled(app: App, canvas: HTMLCanvasElement, rt: any) {
|
|
|
|
event: { _tag: 'FocusAndClick', _0: fullKey }
|
|
|
|
event: { _tag: 'FocusAndClick', _0: fullKey }
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return expandStateful(viewUI, path);
|
|
|
|
return expandStateful(viewUI, path, renderedKeys);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case 'stack':
|
|
|
|
case 'stack':
|
|
|
|
@ -105,7 +112,7 @@ export function runAppCompiled(app: App, canvas: HTMLCanvasElement, rt: any) {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
...ui,
|
|
|
|
...ui,
|
|
|
|
children: ui.children.map((child: UIValue, i: number) =>
|
|
|
|
children: ui.children.map((child: UIValue, i: number) =>
|
|
|
|
expandStateful(child, [...path, i])
|
|
|
|
expandStateful(child, [...path, i], renderedKeys)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -117,7 +124,7 @@ export function runAppCompiled(app: App, canvas: HTMLCanvasElement, rt: any) {
|
|
|
|
case 'clip': {
|
|
|
|
case 'clip': {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
...ui,
|
|
|
|
...ui,
|
|
|
|
child: expandStateful((ui as any).child, [...path, 0])
|
|
|
|
child: expandStateful((ui as any).child, [...path, 0], renderedKeys)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -130,11 +137,17 @@ export function runAppCompiled(app: App, canvas: HTMLCanvasElement, rt: any) {
|
|
|
|
|
|
|
|
|
|
|
|
function rerender() {
|
|
|
|
function rerender() {
|
|
|
|
const viewport = { width: window.innerWidth, height: window.innerHeight };
|
|
|
|
const viewport = { width: window.innerWidth, height: window.innerHeight };
|
|
|
|
|
|
|
|
const renderedKeys = new Set<string>();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const uiValue = app.view(state)(viewport);
|
|
|
|
const uiValue = app.view(state)(viewport);
|
|
|
|
const ui = valueToUI(uiValue);
|
|
|
|
const ui = valueToUI(uiValue);
|
|
|
|
const expandedUI = expandStateful(ui, []);
|
|
|
|
const expandedUI = expandStateful(ui, [], renderedKeys);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (focusedComponentKey && !renderedKeys.has(focusedComponentKey)) {
|
|
|
|
|
|
|
|
focusedComponentKey = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
render(expandedUI, canvas);
|
|
|
|
render(expandedUI, canvas);
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Render error:', error);
|
|
|
|
console.error('Render error:', error);
|
|
|
|
|