Skip to content

Commit a8a389c

Browse files
authored
ui: added some placeholder handling and changed search node ui (#166)
* ui: added some placeholder handling and changed search node ui * ui: focus search node on creation
1 parent ec9593b commit a8a389c

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

lib/com/search.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ export class SearchNode {
2929
return <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>
3030
}
3131

32+
handlePlaceholder(): any {
33+
return 'Enter search value';
34+
}
35+
3236
displayName(node: Node): any {
33-
return `Search for "${node.name}"`;
37+
return node.name;
3438
}
3539

3640
onAttach(node: Node) {

lib/mod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export async function setup(document: Document, target: HTMLElement, backend: Ba
7575
const search = new SearchNode();
7676
ctx.node.addComponent(search);
7777
workbench.workspace.setExpanded(ctx.path.head, ctx.node, true);
78+
workbench.focus(ctx.path);
7879
}
7980
});
8081

lib/ui/node/editor.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { objectCall, objectHas } from "../../model/hooks.ts";
22

33
export const NodeEditor: m.Component = {
4-
view ({attrs: {workbench, path, onkeydown, disallowEmpty, editValue}, state}) {
4+
view ({attrs: {workbench, path, onkeydown, disallowEmpty, editValue, placeholder}, state}) {
55
const node = path.node;
66
let prop = (editValue) ? "value" : "name";
77

@@ -32,7 +32,6 @@ export const NodeEditor: m.Component = {
3232
}
3333
}
3434

35-
let placeholder;
3635
if (node.raw.Rel === "Fields") {
3736
placeholder = (editValue) ? "Value" : "Field";
3837
}

lib/ui/outline.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export const OutlineNode: m.Component<Attrs, State> = {
3838
node = handleNode.refTo;
3939
}
4040

41-
const expanded = workbench.workspace.getExpanded(path.head, handleNode);
41+
const expanded = workbench.workspace.getExpanded(path.head, handleNode);
42+
const placeholder = objectHas(node, "handlePlaceholder") ? objectCall(node, "handlePlaceholder") : '';
4243

4344
const hover = (e) => {
4445
state.hover = true;
@@ -155,7 +156,8 @@ export const OutlineNode: m.Component<Attrs, State> = {
155156
if (node.id === workbench.context?.node?.id || state.hover) {
156157
return true;
157158
}
158-
return node.name.length > 0;
159+
if (node.name.length > 0) return true;
160+
if (placeholder.length > 0) return true;
159161
}
160162

161163
return (
@@ -187,7 +189,7 @@ export const OutlineNode: m.Component<Attrs, State> = {
187189
</div>
188190
: <div class="flex grow items-start flex-row">
189191
{objectHas(node, "beforeEditor") && m(objectCall(node, "beforeEditor"), {node})}
190-
<NodeEditor workbench={workbench} path={path} onkeydown={checkCommands} />
192+
<NodeEditor workbench={workbench} path={path} onkeydown={checkCommands} placeholder={placeholder} />
191193
{objectHas(node, "afterEditor") && m(objectCall(node, "afterEditor"), {node})}
192194
</div>
193195
}

0 commit comments

Comments
 (0)