Skip to content

Commit 879ea9a

Browse files
authored
feat: adding a card demo (#20)
1 parent 838e349 commit 879ea9a

File tree

6 files changed

+58
-21
lines changed

6 files changed

+58
-21
lines changed

dist/kasper.js

+10-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/kasper.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

live/css/style.css

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ textarea {
6464
}
6565

6666
textarea {
67-
height: 120px;
67+
height: 76px;
68+
min-height: 76px;
6869
}
6970

7071
button:hover {

live/demo.html

+32-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,16 @@
4848
</div>
4949
<div>{{todo.task}}</div>
5050
</div>
51-
<button type="button" @on:click="onAddCard()">
51+
<void @if="editing.value === category.name">
52+
<textarea
53+
@let="onInputRef($ref)"
54+
@on:change="onCardChange($event, category.name)"
55+
tabindex="0"
56+
name="task"
57+
placeholder="Enter a task"
58+
></textarea>
59+
</void>
60+
<button type="button" @on:click="onAddCard(category.name)">
5261
+ Add a card
5362
</button>
5463
</div>
@@ -79,8 +88,28 @@
7988
this.loading.set(false);
8089
};
8190

82-
onAddCard = () => {
83-
alert("TODO");
91+
onAddCard = (category) => {
92+
this.editing.set(category);
93+
setTimeout(() => {
94+
if (this.textarea) {
95+
this.textarea.focus();
96+
}
97+
}, 1);
98+
};
99+
100+
onInputRef = (ref) => {
101+
this.textarea = ref;
102+
};
103+
104+
onCardChange = (event, category) => {
105+
const todo = {
106+
task: event.target.value,
107+
id: new Date().getTime(),
108+
tags: ["green"],
109+
};
110+
this.todos.value[category].push(todo);
111+
this.editing.set(null);
112+
this.todos.set(this.todos.value);
84113
};
85114

86115
onDragStart = (todoId, category, event) => {

src/scanner.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,15 @@ export class Scanner {
255255
);
256256
break;
257257
case "=":
258+
if (this.match("=")) {
259+
this.addToken(
260+
this.match("=") ? TokenType.EqualEqual : TokenType.EqualEqual,
261+
null
262+
);
263+
break;
264+
}
258265
this.addToken(
259-
this.match("=")
260-
? TokenType.EqualEqual
261-
: this.match(">")
262-
? TokenType.Arrow
263-
: TokenType.Equal,
266+
this.match(">") ? TokenType.Arrow : TokenType.Equal,
264267
null
265268
);
266269
break;

src/transpiler.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,9 @@ export class Transpiler implements KNode.KNodeVisitor<void> {
161161
private doLet(init: KNode.Attribute, node: KNode.Element, parent: Node) {
162162
const originalScope = this.interpreter.scope;
163163
this.interpreter.scope = new Scope(originalScope);
164+
const element = this.createElement(node, parent);
165+
this.interpreter.scope.set("$ref", element);
164166
this.execute(init.value);
165-
this.createElement(node, parent);
166167
this.interpreter.scope = originalScope;
167168
}
168169

@@ -219,7 +220,7 @@ export class Transpiler implements KNode.KNodeVisitor<void> {
219220
}
220221
}
221222

222-
private createElement(node: KNode.Element, parent?: Node): void {
223+
private createElement(node: KNode.Element, parent?: Node): Node | undefined {
223224
const isVoid = node.name === "void";
224225
const isComponent = !!this.registry[node.name];
225226
const element = isVoid ? parent : document.createElement(node.name);
@@ -267,7 +268,7 @@ export class Transpiler implements KNode.KNodeVisitor<void> {
267268
}
268269

269270
if (node.self) {
270-
return;
271+
return element;
271272
}
272273

273274
this.createSiblings(node.children, element);
@@ -276,6 +277,7 @@ export class Transpiler implements KNode.KNodeVisitor<void> {
276277
if (!isVoid && parent) {
277278
parent.appendChild(element);
278279
}
280+
return element;
279281
}
280282

281283
private createComponentArgs(args: KNode.Attribute[]): Record<string, any> {

0 commit comments

Comments
 (0)