master
Dustin Swan 2 weeks ago
parent 8c20a29b54
commit 68f4fbe9b3
Signed by: dustinswan
GPG Key ID: 30D46587E2100467

@ -68,11 +68,6 @@ palette = config \
} }
}; };
# local onSelect, calls passed in config.onSelect
onSelect = text \ text
| "" \ config.onSelect paletteState.query
| _ \ config.onSelect text;
ui.stateful { ui.stateful {
key = "palette", key = "palette",
focusable = False, focusable = False,
@ -85,7 +80,7 @@ palette = config \
| Key { printable = True } \ { state = state.{ focusedIndex = 0 }, emit = [] } | Key { printable = True } \ { state = state.{ focusedIndex = 0 }, emit = [] }
| Key { key = "ArrowUp" } \ { state = state.{ focusedIndex = max 0 (state.focusedIndex - 1) }, emit = [] } | Key { key = "ArrowUp" } \ { state = state.{ focusedIndex = max 0 (state.focusedIndex - 1) }, emit = [] }
| Key { key = "ArrowDown" } \ { state = state.{ focusedIndex = min (len results - 1) (state.focusedIndex + 1) }, emit = [] } | Key { key = "ArrowDown" } \ { state = state.{ focusedIndex = min (len results - 1) (state.focusedIndex + 1) }, emit = [] }
| Key { key = "Enter" } \ { state = state, emit = [onSelect (unwrapOr "" (nth state.focusedIndex results))] } | Key { key = "Enter" } \ { state = state, emit = [config.onSelect (unwrapOr "" (nth state.focusedIndex results))] }
| _ \ { state = state, emit = [] }, | _ \ { state = state, emit = [] },
view = state \ view = state \

@ -12,19 +12,11 @@ inspector = config \
contentWidth = windowWidth - (dialogPadding * 2); contentWidth = windowWidth - (dialogPadding * 2);
contentHeight = windowHeight - (dialogPadding * 2); contentHeight = windowHeight - (dialogPadding * 2);
ui.positioned {
x = (config.viewport.width - windowWidth) / 2,
y = (config.viewport.height - windowHeight) / 2,
child = ui.stack {
children = [
# background
ui.rect { w = windowWidth, h = windowHeight, color = "#063351", radius = 0, strokeWidth = 1, strokeColor = "#1A5F80" },
ui.column { ui.column {
gap = 0, gap = 0,
children = mapWithIndex (line i \ children = mapWithIndex (line i \
textInput { textInput {
key = "palette-query" & (str i), key = "palette-query" & (show i),
initialValue = line, initialValue = line,
initialFocus = i == 0, initialFocus = i == 0,
color = "white", color = "white",
@ -37,7 +29,4 @@ inspector = config \
| _ \ noOp | _ \ noOp
} }
) sourceLines ) sourceLines
}
]
}
}; };

@ -11,6 +11,8 @@ osState = {
nextId = 0 nextId = 0
}; };
openPalette = _ \ osState.palette.visible := not (osState.palette.visible);
windowWidth = window \ window.fullWidth windowWidth = window \ window.fullWidth
| True \ viewport.width | True \ viewport.width
| False \ window.width; | False \ window.width;
@ -77,9 +79,9 @@ focusWindow = index \
onSelect = input \ onSelect = input \
result = eval input; result = eval input;
result result
| Value v \ openWindow input (ui.text { content = show v, color = "white" }) | Value v \ openWindow input (_ \ ui.text { content = show v, color = "white" })
| Defined name \ noOp | Defined name \ openWindow name (_ \ inspector { name = name })
| Err msg \ openWindow "Error" (ui.text { content = msg, color = "red" }); | Err msg \ openWindow "Error" (_ \ ui.text { content = msg, color = "red" });
renderWindow = window isActive \ renderWindow = window isActive \
titleBarHeight = 30; titleBarHeight = 30;
@ -127,7 +129,7 @@ renderWindow = window isActive \
child = ui.clip { child = ui.clip {
w = (windowWidth window), w = (windowWidth window),
h = viewport.height - titleBarHeight, h = viewport.height - titleBarHeight,
child = window.content child = window.content 0
} }
} }
] ]
@ -158,6 +160,10 @@ renderWindows = _ \
} }
}; };
search = q \
storeRes = storeSearch q;
[...storeRes, q];
os = ui.stateful { os = ui.stateful {
key = "os", key = "os",
autoFocus = True, autoFocus = True,
@ -166,7 +172,7 @@ os = ui.stateful {
update = state event \ event update = state event \ event
| Key { key = "p", meta = True } \ | Key { key = "p", meta = True } \
{ state = state, emit = [osState.palette.visible := not (osState.palette.visible)] } { state = state, emit = [openPalette] }
| Key { key = "ArrowLeft", meta = True } \ | Key { key = "ArrowLeft", meta = True } \
( (
newIndex = max 0 (osState.wm.focusedIndex - 1); newIndex = max 0 (osState.wm.focusedIndex - 1);
@ -193,7 +199,7 @@ os = ui.stateful {
# keep palette at the end so it's on top # keep palette at the end so it's on top
osState.palette.visible osState.palette.visible
| True \ palette { | True \ palette {
search = storeSearch, search = search,
onSelect = onSelect, onSelect = onSelect,
viewport = viewport, viewport = viewport,
} }

@ -29,6 +29,7 @@ export function compile(ast: AST, useStore = true, bound = new Set<string>(), to
const newBound = new Set([...bound, ...ast.params]); const newBound = new Set([...bound, ...ast.params]);
const params = ast.params.map(sanitizeName).join(') => ('); const params = ast.params.map(sanitizeName).join(') => (');
const id = astIdCounter++; const id = astIdCounter++;
astRegistry.set(id, ast);
return `Object.assign((${params}) => ${compile(ast.body, useStore, newBound, topLevel)}, { _astId: (${id}) })`; return `Object.assign((${params}) => ${compile(ast.body, useStore, newBound, topLevel)}, { _astId: (${id}) })`;
} }

@ -259,11 +259,19 @@ function valueToAst(value: any): AST {
// Functions // Functions
if (typeof value === 'function') { if (typeof value === 'function') {
if (value._astId !== undefined) { if (value._astId === undefined) {
return astRegistry.get(value._astId)!; throw new Error('Cannot persist native functions');
} }
const ast = astRegistry.get(value._astId)!;
throw new Error('Cannot serialize function without _astId'); if (!ast) {
console.error('Registry size:', astRegistry.size, 'Looking for:', value._astId,
'Function:', value.toString().slice(0, 200));
throw new Error(`AST registry miss for _astId ${value._astId}`);
}
return ast;
} }
throw new Error(`Cannot convert to AST: ${typeof value}`); throw new Error(`Cannot convert to AST: ${typeof value}`);

Loading…
Cancel
Save