|
4 | 4 | <div id="app"></div> |
5 | 5 |
|
6 | 6 | <script> |
7 | | -const { createVaporApp, defineComponent, reactive, computed, watchEffect, onMounted, onUnmounted } = VueVapor |
| 7 | +const { createVaporApp, defineComponent, reactive, computed, watchEffect, onMounted, onUnmounted, nextTick } = VueVapor |
8 | 8 |
|
9 | 9 | const STORAGE_KEY = 'todos-vuejs-3.x' |
10 | 10 | const todoStorage = { |
|
110 | 110 | state.todos.splice(state.todos.indexOf(todo), 1) |
111 | 111 | } |
112 | 112 |
|
113 | | - function editTodo(todo) { |
| 113 | + async function editTodo(todo) { |
114 | 114 | state.beforeEditCache = todo.title |
115 | 115 | state.editedTodo = todo |
| 116 | + await nextTick() |
| 117 | + document.getElementById(`todo-${todo.id}-input`).focus() |
116 | 118 | } |
117 | 119 |
|
118 | 120 | function doneEdit(todo) { |
|
147 | 149 | }, |
148 | 150 | }) |
149 | 151 |
|
150 | | -const { resolveDirective: _resolveDirective, children: _children, vModelText: _vModelText, withDirectives: _withDirectives, vShow: _vShow, vModelCheckbox: _vModelCheckbox, next: _next, delegate: _delegate, on: _on, setText: _setText, setClass: _setClass, renderEffect: _renderEffect, createFor: _createFor, insert: _insert, setDynamicProp: _setDynamicProp, delegateEvents: _delegateEvents, template: _template } = VueVapor |
| 152 | +const { children: _children, vModelText: _vModelText, withDirectives: _withDirectives, vShow: _vShow, next: _next, delegate: _delegate, on: _on, setDynamicProp: _setDynamicProp, setText: _setText, setClass: _setClass, renderEffect: _renderEffect, createFor: _createFor, insert: _insert, delegateEvents: _delegateEvents, template: _template } = VueVapor |
151 | 153 | const t0 = _template("<li><div class=\"view\"><input class=\"toggle\" type=\"checkbox\"><label></label><button class=\"destroy\"></button></div><input class=\"edit\" type=\"text\"></li>") |
152 | 154 | const t1 = _template("<section class=\"todoapp\"><header class=\"header\"><h1>todos</h1><input class=\"new-todo\" autofocus autocomplete=\"off\" placeholder=\"What needs to be done?\"></header><section class=\"main\"><input id=\"toggle-all\" class=\"toggle-all\" type=\"checkbox\"><label for=\"toggle-all\">Mark all as complete</label><ul class=\"todo-list\"></ul></section><footer class=\"footer\"><span class=\"todo-count\"><strong></strong><span></span></span><ul class=\"filters\"><li><a href=\"#/all\">All</a></li><li><a href=\"#/active\">Active</a></li><li><a href=\"#/completed\">Completed</a></li></ul><button class=\"clear-completed\"> Clear completed </button></footer></section>") |
153 | 155 | _delegateEvents("keyup", "dblclick", "click") |
|
159 | 161 | const n10 = _children(n18, 1) |
160 | 162 | _withDirectives(n10, [[_vShow, () => _ctx.state.todos.length]]) |
161 | 163 | const n1 = n10.firstChild |
162 | | - _withDirectives(n1, [[_vModelCheckbox, () => _ctx.state.allDone]]) |
163 | 164 | const n9 = _next(n1, 2) |
164 | 165 | const n17 = n10.nextSibling |
165 | 166 | _withDirectives(n17, [[_vShow, () => _ctx.state.todos.length]]) |
|
174 | 175 | _delegate(n0, "keyup", () => _ctx.addTodo, { |
175 | 176 | keys: ["enter"] |
176 | 177 | }) |
177 | | - _delegate(n1, "update:modelValue", () => $event => (_ctx.state.allDone = $event)) |
178 | 178 | _on(n1, "change", () => $event => (_ctx.state.allDone = $event.target.checked)) |
179 | 179 | const n2 = _createFor(() => (_ctx.state.filteredTodos), (_block) => { |
180 | 180 | const n8 = t0() |
181 | 181 | const n4 = _children(n8, 0, 0) |
182 | | - _withDirectives(n4, [[_vModelCheckbox, () => _block.s[0].completed]]) |
183 | 182 | const n5 = n4.nextSibling |
184 | 183 | const n6 = n5.nextSibling |
185 | 184 | const n7 = _children(n8, 1) |
186 | | - _withDirectives(n7, [[_vModelText, () => _block.s[0].title], [_ctx.vTodoFocus, () => _block.s[0] === _ctx.state.editedTodo]]) |
187 | | - _delegate(n4, "update:modelValue", () => $event => (_block.s[0].completed = $event)) |
| 185 | + _on(n4, "change", () => $event => (_block.s[0].completed = $event.target.checked)) |
188 | 186 | _delegate(n5, "dblclick", () => $event => (_ctx.editTodo(_block.s[0]))) |
189 | 187 | _delegate(n6, "click", () => $event => (_ctx.removeTodo(_block.s[0]))) |
190 | | - _delegate(n7, "update:modelValue", () => $event => (_block.s[0].title = $event)) |
| 188 | + _on(n7, "input", () => $event => (_block.s[0].title = $event.target.value)) |
191 | 189 | _on(n7, "blur", () => $event => (_ctx.doneEdit(_block.s[0]))) |
192 | 190 | _delegate(n7, "keyup", () => $event => (_ctx.doneEdit(_block.s[0])), { |
193 | 191 | keys: ["enter"] |
|
197 | 195 | }) |
198 | 196 | const _updateEffect = () => { |
199 | 197 | const [todo] = _block.s |
| 198 | + _setDynamicProp(n4, "checked", todo.completed) |
200 | 199 | _setText(n5, todo.title) |
| 200 | + _setDynamicProp(n7, "value", todo.title) |
| 201 | + _setDynamicProp(n7, "id", `todo-${todo.id}-input`) |
201 | 202 | _setClass(n8, ["todo", { |
202 | | - completed: todo.completed, |
203 | | - editing: todo === _ctx.state.editedTodo, |
204 | | - }]) |
| 203 | + completed: todo.completed, |
| 204 | + editing: todo === _ctx.state.editedTodo, |
| 205 | + }]) |
205 | 206 | } |
206 | 207 | _renderEffect(_updateEffect) |
207 | 208 | return [n8, _updateEffect] |
|
0 commit comments