Skip to content

Commit d20e733

Browse files
authored
closes #299 and closes #295 (#300)
1 parent f5ee361 commit d20e733

File tree

4 files changed

+77
-3
lines changed

4 files changed

+77
-3
lines changed

lib/com/description.tsx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { component } from "../model/components.ts";
2+
import { Node } from "../model/mod.ts";
3+
import { objectManaged } from "../model/hooks.ts";
4+
5+
@component
6+
export class Description {
7+
text: string;
8+
9+
constructor() {
10+
this.text = "";
11+
}
12+
13+
editor() {
14+
return DescriptionEditor;
15+
}
16+
17+
static initialize(workbench: Workbench) {
18+
workbench.commands.registerCommand({
19+
id: "add-description",
20+
title: "Add Description",
21+
when: (ctx: Context) => {
22+
if (!ctx.node) return false;
23+
if (ctx.path.previous && objectManaged(ctx.path.previous)) return false;
24+
if (ctx.node.hasComponent(Description)) return false;
25+
return true;
26+
},
27+
action: (ctx: Context, name: string) => {
28+
const desc = new Description();
29+
ctx.node.addComponent(desc);
30+
ctx.node.changed();
31+
}
32+
});
33+
}
34+
}
35+
36+
const DescriptionEditor = {
37+
view({attrs: {node}}) {
38+
const oninput = (e) => {
39+
const desc = node.getComponent(Description);
40+
desc.text = e.target.value;
41+
node.changed();
42+
}
43+
const onblur = (e) => {
44+
const desc = node.getComponent(Description);
45+
if (desc.text === "") {
46+
node.removeComponent(Description);
47+
}
48+
node.changed();
49+
}
50+
51+
return <input class="node-description" placeholder="Add Description" type="text" value={node.getComponent(Description).text} onblur={onblur} oninput={oninput} />
52+
}
53+
}

lib/mod.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { Clock } from "./com/clock.tsx";
2727
import { Tag } from "./com/tag.tsx";
2828
import { Template } from "./com/template.tsx";
2929
import { Document } from "./com/document.tsx";
30+
import { Description } from "./com/description.tsx";
3031
import { objectManaged } from "./model/hooks.ts";
3132

3233
export { BrowserBackend, SearchIndex_MiniSearch } from "./backend/browser.ts";
@@ -61,6 +62,7 @@ export async function setup(document: Document, target: HTMLElement, backend: Ba
6162
Tag,
6263
Template,
6364
SmartNode,
65+
Description,
6466
].forEach(com => {
6567
if (com.initialize) {
6668
com.initialize(workbench);
@@ -240,6 +242,7 @@ export async function setup(document: Document, target: HTMLElement, backend: Ba
240242
title: "Add checkbox",
241243
when: (ctx: Context) => {
242244
if (!ctx.node) return false;
245+
if (ctx.node.hasComponent(Checkbox)) return false;
243246
if (ctx.node.raw.Rel === "Fields") return false;
244247
if (ctx.node.parent && ctx.node.parent.hasComponent(Document)) return false;
245248
return true;

lib/ui/node/editor.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { objectCall, objectHas } from "../../model/hooks.ts";
22
import { Document } from "../../com/document.tsx";
3+
import { Description } from "../../com/description.tsx";
34

45
export const NodeEditor: m.Component = {
56
view ({attrs: {workbench, path, onkeydown, oninput, disallowEmpty, editValue, placeholder}, state}) {
@@ -45,7 +46,16 @@ export const NodeEditor: m.Component = {
4546
if (node.parent && node.parent.hasComponent(Document) && window.Editor) {
4647
editor = CodeMirrorEditor;
4748
}
48-
return m(editor, {id, getter, setter, display, onkeydown, onfocus, oninput, placeholder, workbench, path});
49+
let desc = undefined;
50+
if (node.hasComponent(Description)) {
51+
desc = node.getComponent(Description);
52+
}
53+
return (
54+
<div class="node-editor flex flex-col">
55+
{m(editor, {id, getter, setter, display, onkeydown, onfocus, oninput, placeholder, workbench, path})}
56+
{(desc) ? m(desc.editor(), {node}) :null}
57+
</div>
58+
)
4959
}
5060
}
5161

web/static/app/main.css

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,21 @@ with their icon for Safari only*/
230230

231231
/*------------NODES------------*/
232232
/*keep max line length from getting too long for readibility*/
233-
.text-editor {
233+
.node-editor {
234234
width: 100%;
235235
margin-bottom: var(--2);
236236
}
237237
.text-editor textarea, .panel-back-parent {
238238
max-width: 768px;
239239
}
240+
.node-description {
241+
padding: 0;
242+
color: var(--color-text-secondary);
243+
line-height: 150%;
244+
font-size: 13px;
245+
border: 0;
246+
outline: 0;
247+
}
240248
/*todo: check unused textarea styles in panel.tsx*/
241249
.text-editor > textarea, .text-editor > span {
242250
outline: none;
@@ -249,7 +257,7 @@ with their icon for Safari only*/
249257
line-height: var(--body-line-height);
250258
border: none;
251259
}
252-
.title-node textarea, .title-node > .text-editor > span {
260+
.title-node .text-editor > textarea, .title-node .text-editor > span {
253261
font-size: var(--6);
254262
font-weight: var(--weight-bold);
255263
}

0 commit comments

Comments
 (0)