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,32 +12,21 @@ inspector = config \
contentWidth = windowWidth - (dialogPadding * 2); contentWidth = windowWidth - (dialogPadding * 2);
contentHeight = windowHeight - (dialogPadding * 2); contentHeight = windowHeight - (dialogPadding * 2);
ui.positioned { ui.column {
x = (config.viewport.width - windowWidth) / 2, gap = 0,
y = (config.viewport.height - windowHeight) / 2, children = mapWithIndex (line i \
textInput {
child = ui.stack { key = "palette-query" & (show i),
children = [ initialValue = line,
# background initialFocus = i == 0,
ui.rect { w = windowWidth, h = windowHeight, color = "#063351", radius = 0, strokeWidth = 1, strokeColor = "#1A5F80" }, color = "white",
ui.column { backgroundColor = "rgba(0,0,0,0.0)",
gap = 0, w = contentWidth,
children = mapWithIndex (line i \ h = textInputHeight,
textInput { # onChange = text \ batch [config.state.query := text, config.state.focusedIndex := 0],
key = "palette-query" & (str i), onChange = text \ batch [],
initialValue = line, onKeyDown = key \ key
initialFocus = i == 0, | _ \ noOp
color = "white", }
backgroundColor = "rgba(0,0,0,0.0)", ) sourceLines
w = contentWidth,
h = textInputHeight,
# onChange = text \ batch [config.state.query := text, config.state.focusedIndex := 0],
onChange = text \ batch [],
onKeyDown = key \ key
| _ \ noOp
}
) 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