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 {
key = "palette",
focusable = False,
@ -85,7 +80,7 @@ palette = config \
| Key { printable = True } \ { state = state.{ focusedIndex = 0 }, 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 = "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 = [] },
view = state \

@ -12,32 +12,21 @@ inspector = config \
contentWidth = windowWidth - (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 {
gap = 0,
children = mapWithIndex (line i \
textInput {
key = "palette-query" & (str i),
initialValue = line,
initialFocus = i == 0,
color = "white",
backgroundColor = "rgba(0,0,0,0.0)",
w = contentWidth,
h = textInputHeight,
# onChange = text \ batch [config.state.query := text, config.state.focusedIndex := 0],
onChange = text \ batch [],
onKeyDown = key \ key
| _ \ noOp
}
) sourceLines
}
]
}
ui.column {
gap = 0,
children = mapWithIndex (line i \
textInput {
key = "palette-query" & (show i),
initialValue = line,
initialFocus = i == 0,
color = "white",
backgroundColor = "rgba(0,0,0,0.0)",
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
};
openPalette = _ \ osState.palette.visible := not (osState.palette.visible);
windowWidth = window \ window.fullWidth
| True \ viewport.width
| False \ window.width;
@ -77,9 +79,9 @@ focusWindow = index \
onSelect = input \
result = eval input;
result
| Value v \ openWindow input (ui.text { content = show v, color = "white" })
| Defined name \ noOp
| Err msg \ openWindow "Error" (ui.text { content = msg, color = "red" });
| Value v \ openWindow input (_ \ ui.text { content = show v, color = "white" })
| Defined name \ openWindow name (_ \ inspector { name = name })
| Err msg \ openWindow "Error" (_ \ ui.text { content = msg, color = "red" });
renderWindow = window isActive \
titleBarHeight = 30;
@ -127,7 +129,7 @@ renderWindow = window isActive \
child = ui.clip {
w = (windowWidth window),
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 {
key = "os",
autoFocus = True,
@ -166,7 +172,7 @@ os = ui.stateful {
update = state event \ event
| Key { key = "p", meta = True } \
{ state = state, emit = [osState.palette.visible := not (osState.palette.visible)] }
{ state = state, emit = [openPalette] }
| Key { key = "ArrowLeft", meta = True } \
(
newIndex = max 0 (osState.wm.focusedIndex - 1);
@ -193,7 +199,7 @@ os = ui.stateful {
# keep palette at the end so it's on top
osState.palette.visible
| True \ palette {
search = storeSearch,
search = search,
onSelect = onSelect,
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 params = ast.params.map(sanitizeName).join(') => (');
const id = astIdCounter++;
astRegistry.set(id, ast);
return `Object.assign((${params}) => ${compile(ast.body, useStore, newBound, topLevel)}, { _astId: (${id}) })`;
}

@ -259,11 +259,19 @@ function valueToAst(value: any): AST {
// Functions
if (typeof value === 'function') {
if (value._astId !== undefined) {
return astRegistry.get(value._astId)!;
if (value._astId === undefined) {
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}`);

Loading…
Cancel
Save