-
Notifications
You must be signed in to change notification settings - Fork 6
/
todomvc.html
103 lines (98 loc) · 3.95 KB
/
todomvc.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<!doctype html>
<html lang="en" data-framework="sprae">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>sprae • TodoMVC</title>
<link rel="stylesheet" href="https://unpkg.com/todomvc-common/base.css">
<link rel="stylesheet" href="https://unpkg.com/todomvc-app-css/index.css">
<style>
[\:each] {
display: none;
}
</style>
</head>
<body>
<section class="todoapp">
<header class="header">
<h1>todos</h1>
<input :ref="input" class="new-todo"
placeholder="What needs to be done?" autofocus :onkeypress.enter="e => {
save(todos = [...todos, { text: input.value, done: false}]);
input.value = ''
}">
</header>
<section class="main">
<input id="toggle-all" class="toggle-all" type="checkbox" :onclick="(e, all) => (
all = todos.every(item => item.done),
save(todos = todos.map(item => (item.done = !all, item)))
)">
<label for="toggle-all">Mark all as complete</label>
<ul class="todo-list">
<li :each="item in todos" :ref="li" :class="{ completed: item.done }"
:hidden="hash === '#/active' ? item.done : hash === '#/completed' ? !item.done : false"
:ondblclick="e => ( edit.focus(), li.classList.add('editing') )">
<div class="view">
<input class="toggle" type="checkbox" :value="item.done"
:onchange="e => save(todos)" />
<label :text="item.text"></label>
<button class="destroy"
:onclick="e => save(todos = todos.filter(i => i !== item))"></button>
</div>
<input :ref="edit" class="edit" :value="item.text"
:oninput="e => (save(todos))"
:onblur="e => (li.classList.remove('editing'))"
:onkeypress.enter="e => (edit.blur())" />
</li>
</ul>
</section>
<footer class="footer">
<span class="todo-count"
:with="{count: todos.filter(item => !item.done).length}">
<strong :text="count">#</strong> <span
:text="plur('item', count)">items</span> left
</span>
<ul class="filters">
<li
:each="label, key in {'#/': 'All', '#/active': 'Active', '#/completed': 'Completed'}">
<a :class="{selected: hash === key}" :href="key" :text="label"></a>
</li>
</ul>
<button class="clear-completed"
:hidden="todos.every(item => !item.done)"
:onclick="e => save(todos = todos.filter(item => !item.done ? true : false))">
Clear completed
</button>
</footer>
</section>
<footer class="info">
<p>Double-click to edit a todo</p>
<p>Created by <a href="https://github.com/dy">dy</a></p>
<p>Part of <a href="http://todomvc.com">TodoMVC</a></p>
</footer>
<script src="https://unpkg.com/todomvc-common/base.js"></script>
<script type="importmap"> {
"imports": {
"sprae": "https://cdn.jsdelivr.net/npm/sprae/dist/sprae.min.js",
"plur": "https://cdn.skypack.dev/plur",
"swapdom": "https://cdn.skypack.dev/swapdom",
"ulive": "https://cdn.skypack.dev/ulive",
"subscript/justin": "https://cdn.skypack.dev/subscript/justin.js"
}
}
</script>
<script type="module">
// import sprae from '../sprae.js'
import sprae from 'sprae'
import plur from 'plur'
let state = sprae(document.body, {
plur, console,
todos: JSON.parse(localStorage.getItem('todomvc.items') || '[]'),
hash: window.location.hash || '#/',
save: items => localStorage.setItem('todomvc.items', JSON.stringify(items))
})
// hash source
window.addEventListener('hashchange', e => state.hash = window.location.hash)
</script>
</body>
</html>