Adding display, fixing show to include quotes in strings
This commit is contained in:
parent
d99de85dee
commit
8932fef6b9
2 changed files with 41 additions and 27 deletions
|
|
@ -22,7 +22,7 @@ treeNodeHeight = value path expanded \
|
|||
| True \ lineH + (sum (mapWithIndex (item i \
|
||||
(valueLabel item)
|
||||
| Some _ \ lineH
|
||||
| None \ lineH + (treeNodeHeight item (path & [show i]) expanded)
|
||||
| None \ lineH + (treeNodeHeight item (path & [display i]) expanded)
|
||||
) items))
|
||||
| False \ lineH)
|
||||
| _ \ lineH;
|
||||
|
|
@ -40,7 +40,7 @@ visiblePaths = value path expanded \ value
|
|||
| ListValue items \ (
|
||||
[{ path = path, leaf = False }, ...(contains path expanded)
|
||||
| True \ flatten (mapWithIndex (item i \
|
||||
itemPath = path & [show i];
|
||||
itemPath = path & [display i];
|
||||
(valueLabel item)
|
||||
| Some _ \ [{ path = itemPath, leaf = True }]
|
||||
| None \ visiblePaths item itemPath expanded
|
||||
|
|
@ -142,7 +142,7 @@ treeNode = config \
|
|||
| True \ [ui.clickable {
|
||||
onClick = _ \ noOp,
|
||||
child = ui.column { gap = 0, children = mapWithIndex (item i \
|
||||
treeNode { value = item, depth = depth + 1, path = config.path & [show i], expanded = config.expanded, onToggle = config.onToggle, selectedPath = config.selectedPath, prefix = (show i) & ": ", editing = config.editing, onDoneEditing = config.onDoneEditing, onEditLeaf = config.onEditLeaf }
|
||||
treeNode { value = item, depth = depth + 1, path = config.path & [display i], expanded = config.expanded, onToggle = config.onToggle, selectedPath = config.selectedPath, prefix = (display i) & ": ", editing = config.editing, onDoneEditing = config.onDoneEditing, onEditLeaf = config.onEditLeaf }
|
||||
) items }
|
||||
}]
|
||||
| False \ [])
|
||||
|
|
|
|||
|
|
@ -66,6 +66,20 @@ export const _rt = {
|
|||
int: (x: any) => typeof x === 'number' ? Math.floor(x) : parseInt(x, 10) || 0,
|
||||
show: (value: any): string => {
|
||||
if (value === null || value === undefined) return "None";
|
||||
if (typeof value === 'string') return JSON.stringify(value);
|
||||
if (typeof value === 'number') return String(value);
|
||||
if (typeof value === 'boolean') return value ? "True" : "False";
|
||||
if (value._tag) return value._0 !== undefined ? `(${value._tag} ${_rt.show(value._0)})` : value._tag;
|
||||
if (Array.isArray(value)) return `[${value.map(_rt.show).join(", ")}]`;
|
||||
if (typeof value === 'function') return "<function>";
|
||||
if (typeof value === 'object') {
|
||||
const entries = Object.entries(value).map(([k, v]) => `${k} = ${_rt.show(v)}`);
|
||||
return `{ ${entries.join(", ")} }`;
|
||||
}
|
||||
return String(value);
|
||||
},
|
||||
display: (value: any): string => {
|
||||
if (value === null || value === undefined) return "";
|
||||
if (typeof value === 'string') return value;
|
||||
if (typeof value === 'number') return String(value);
|
||||
if (typeof value === 'boolean') return value ? "True" : "False";
|
||||
|
|
@ -209,34 +223,34 @@ export const _rt = {
|
|||
return { _tag: 'Err', _0: e.message };
|
||||
}
|
||||
},
|
||||
"saveModule!": (moduleName: string) => {
|
||||
const moduleDefs = [...definitions.values()]
|
||||
.filter(d => d.module === moduleName);
|
||||
if (moduleDefs.length === 0) return { _tag: 'Err', _0: 'No module: ' + moduleName };
|
||||
//"saveModule!": (moduleName: string) => {
|
||||
// const moduleDefs = [...definitions.values()]
|
||||
// .filter(d => d.module === moduleName);
|
||||
// if (moduleDefs.length === 0) return { _tag: 'Err', _0: 'No module: ' + moduleName };
|
||||
|
||||
const content = '@' + moduleName + '\n\n' +
|
||||
moduleDefs.map(d => prettyPrint(d)).join('\n\n') + '\n\n@\n';
|
||||
// const content = '@' + moduleName + '\n\n' +
|
||||
// moduleDefs.map(d => prettyPrint(d)).join('\n\n') + '\n\n@\n';
|
||||
|
||||
fetch('/api/save', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ filename: moduleName, content })
|
||||
});
|
||||
// fetch('/api/save', {
|
||||
// method: 'POST',
|
||||
// headers: { 'Content-Type': 'application/json' },
|
||||
// body: JSON.stringify({ filename: moduleName, content })
|
||||
// });
|
||||
|
||||
return { _tag: 'Defined', _0: moduleName };
|
||||
},
|
||||
"saveDef!": (name: string) => {
|
||||
const def = definitions.get(name);
|
||||
if (!def) return { _tag: 'Err', _0: 'Unknown: ' + name };
|
||||
const content = prettyPrint(def) + '\n';
|
||||
fetch('/api/save', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ filename: name, content })
|
||||
});
|
||||
// return { _tag: 'Defined', _0: moduleName };
|
||||
//},
|
||||
//"saveDef!": (name: string) => {
|
||||
// const def = definitions.get(name);
|
||||
// if (!def) return { _tag: 'Err', _0: 'Unknown: ' + name };
|
||||
// const content = prettyPrint(def) + '\n';
|
||||
// fetch('/api/save', {
|
||||
// method: 'POST',
|
||||
// headers: { 'Content-Type': 'application/json' },
|
||||
// body: JSON.stringify({ filename: name, content })
|
||||
// });
|
||||
|
||||
return { _tag: 'Defined', _0: name };
|
||||
},
|
||||
// return { _tag: 'Defined', _0: name };
|
||||
//},
|
||||
rebind: (name: string, pathOrValue: any, maybeValue?: any) => {
|
||||
if (maybeValue === undefined) {
|
||||
store[name] = pathOrValue;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue