scorpiox-bot-plugin-notes
←ui_html.hc
452 lines · 22 KBHEADBlameDownload
1/* Generated by tools/gen_ui.py from src/ui.html. Do not edit by hand. */
2#ifndef SX_NOTES_UI_HTML_H
3#define SX_NOTES_UI_HTML_H
4
5static const char *UI_HTML =
6 "<!DOCTYPE html>\n"
7 "<html lang=\"en\"><head><meta charset=\"utf-8\">\n"
8 "<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n"
9 "<title>notes</title>\n"
10 "\001\n"
11 "<style>\n"
12 "*{box-sizing:border-box}\n"
13 "html,body{margin:0;height:100%}\n"
14 "body{background:var(--bg);color:var(--text);font-family:var(--font);\n"
15 " font-size:14px;line-height:1.5;-webkit-font-smoothing:antialiased;overflow:hidden}\n"
16 "#app{display:grid;grid-template-columns:288px minmax(0,1fr);height:100%;min-height:0}\n"
17 ".pane{min-width:0;min-height:0;display:flex;flex-direction:column}\n"
18 "#side{background:var(--bg-2);border-right:1px solid var(--line)}\n"
19 ".side-hd{display:flex;align-items:center;gap:8px;padding:12px 12px 8px}\n"
20 ".brand{font-size:12px;font-weight:700;letter-spacing:.09em;text-transform:uppercase;\n"
21 " color:var(--text-2);flex:1}\n"
22 ".side-ft{display:flex;align-items:center;gap:8px;padding:8px 12px;\n"
23 " border-top:1px solid var(--line);font-size:11px;color:var(--text-2)}\n"
24 ".side-ft .grow{flex:1}\n"
25 ".icon{display:inline-flex;align-items:center;justify-content:center;gap:6px;\n"
26 " background:var(--surface-2);border:1px solid var(--line);color:var(--text);\n"
27 " border-radius:9px;width:30px;height:30px;padding:0;cursor:pointer;font-family:inherit;\n"
28 " font-size:12px;font-weight:600}\n"
29 ".icon:hover{background:var(--surface-hover);border-color:var(--line-2)}\n"
30 ".icon:active{transform:scale(.96)}\n"
31 ".icon svg{width:15px;height:15px;display:block;fill:none;stroke:currentColor;\n"
32 " stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}\n"
33 ".icon.danger{color:var(--red)}\n"
34 ".btn{background:var(--blue);color:#fff;border:0;border-radius:980px;padding:6px 14px;\n"
35 " font-weight:600;font-size:12.5px;cursor:pointer;font-family:inherit}\n"
36 ".btn:active{transform:scale(.98)}\n"
37 ".search{margin:0 12px 8px;padding:8px 11px;border-radius:9px;border:1px solid var(--line);\n"
38 " background:var(--input-bg);color:var(--text);font-family:inherit;font-size:13px}\n"
39 ".search:focus{outline:2px solid var(--blue);outline-offset:-1px}\n"
40 ".list{flex:1 1 auto;overflow-y:auto;padding:0 8px 8px}\n"
41 ".item{display:block;width:100%;text-align:left;background:transparent;border:0;\n"
42 " border-radius:10px;padding:9px 10px;color:var(--text);cursor:pointer;font-family:inherit;\n"
43 " margin-bottom:2px;position:relative}\n"
44 ".item:hover{background:var(--surface-hover)}\n"
45 ".item.sel{background:var(--surface-2);box-shadow:inset 2px 0 0 var(--blue)}\n"
46 ".item .t{font-size:13.5px;font-weight:600;white-space:nowrap;overflow:hidden;\n"
47 " text-overflow:ellipsis;padding-right:18px}\n"
48 ".item .m{font-size:11px;color:var(--text-2);white-space:nowrap;overflow:hidden;\n"
49 " text-overflow:ellipsis;margin-top:2px}\n"
50 ".item .pinmark{position:absolute;top:9px;right:9px;width:11px;height:11px;color:var(--blue);\n"
51 " display:none}\n"
52 ".item.pinned .pinmark{display:block}\n"
53 ".item .pinmark svg{width:11px;height:11px;fill:currentColor;stroke:none}\n"
54 ".empty{padding:18px 12px;color:var(--text-2);font-size:12.5px;text-align:center}\n"
55 ".hidden{display:none!important}\n"
56 "#main{background:var(--bg)}\n"
57 ".toolbar{display:flex;align-items:center;gap:8px;padding:10px 14px;\n"
58 " border-bottom:1px solid var(--line);flex:0 0 auto;min-width:0}\n"
59 ".toolbar .title{flex:1 1 auto;min-width:0;background:transparent;border:0;color:var(--text);\n"
60 " font-family:inherit;font-size:16px;font-weight:650;padding:4px 2px;border-radius:6px}\n"
61 ".toolbar .title:focus{outline:0;background:var(--input-bg);padding:4px 8px}\n"
62 ".state{font-size:11px;font-weight:600;color:var(--text-2);white-space:nowrap;\n"
63 " padding:2px 8px;border-radius:999px;background:var(--surface-2)}\n"
64 ".state.dirty{color:var(--orange)}\n"
65 ".state.ok{color:var(--green)}\n"
66 ".back{display:none}\n"
67 ".split{flex:1 1 auto;display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);\n"
68 " min-height:0}\n"
69 ".editor{width:100%;height:100%;resize:none;border:0;border-right:1px solid var(--line);\n"
70 " background:var(--bg);color:var(--text);font-family:var(--mono);font-size:13px;\n"
71 " line-height:1.65;padding:16px 18px;tab-size:2}\n"
72 ".editor:focus{outline:0}\n"
73 ".preview{overflow-y:auto;padding:16px 20px 40px;min-width:0}\n"
74 ".preview h1,.preview h2,.preview h3,.preview h4,.preview h5,.preview h6{\n"
75 " line-height:1.25;margin:18px 0 8px;font-weight:650}\n"
76 ".preview h1{font-size:24px;letter-spacing:-.01em}\n"
77 ".preview h2{font-size:19px}\n"
78 ".preview h3{font-size:16px}\n"
79 ".preview h4,.preview h5,.preview h6{font-size:14px;color:var(--text-2)}\n"
80 ".preview h1:first-child,.preview h2:first-child,.preview p:first-child{margin-top:0}\n"
81 ".preview p{margin:0 0 10px}\n"
82 ".preview ul,.preview ol{margin:0 0 10px;padding-left:22px}\n"
83 ".preview li{margin:2px 0}\n"
84 ".preview blockquote{margin:0 0 10px;padding:2px 12px;border-left:3px solid var(--line-2);\n"
85 " color:var(--text-2)}\n"
86 ".preview code{font-family:var(--mono);font-size:12px;background:var(--code-bg);\n"
87 " padding:1px 5px;border-radius:5px}\n"
88 ".preview pre{background:var(--code-bg);border:1px solid var(--line);border-radius:10px;\n"
89 " padding:11px 13px;overflow-x:auto;margin:0 0 12px}\n"
90 ".preview pre code{background:transparent;padding:0;font-size:12px;line-height:1.55}\n"
91 ".preview hr{border:0;border-top:1px solid var(--line);margin:16px 0}\n"
92 ".preview a{color:var(--blue);text-decoration:none;font-weight:600}\n"
93 ".preview a:hover{text-decoration:underline}\n"
94 ".preview table{border-collapse:collapse;margin:0 0 12px;font-size:13px}\n"
95 ".preview th,.preview td{border:1px solid var(--line);padding:5px 9px;text-align:left}\n"
96 ".preview th{color:var(--text-2);font-size:11.5px;text-transform:uppercase;letter-spacing:.04em}\n"
97 ".welcome{flex:1 1 auto;display:flex;flex-direction:column;align-items:center;\n"
98 " justify-content:center;gap:10px;color:var(--text-2);font-size:13px;padding:24px;text-align:center}\n"
99 ".welcome svg{width:34px;height:34px;fill:none;stroke:currentColor;stroke-width:1.4;\n"
100 " stroke-linecap:round;stroke-linejoin:round;opacity:.55}\n"
101 ".toast{position:fixed;left:50%;bottom:18px;transform:translateX(-50%);\n"
102 " background:var(--modal-bg);border:1px solid var(--line-2);color:var(--text);\n"
103 " padding:8px 14px;border-radius:999px;font-size:12.5px;box-shadow:var(--shadow-lg);\n"
104 " opacity:0;pointer-events:none;transition:opacity .16s var(--ease);z-index:9}\n"
105 ".toast.show{opacity:1}\n"
106 "@media (max-width:700px){\n"
107 " body{overflow:hidden}\n"
108 " #app{grid-template-columns:minmax(0,1fr)}\n"
109 " #side,#main{grid-column:1;grid-row:1;width:100%}\n"
110 " #app[data-view=\"edit\"] #side{display:none}\n"
111 " #app[data-view=\"list\"] #main{display:none}\n"
112 " #side{border-right:0}\n"
113 " .back{display:inline-flex}\n"
114 " .split{grid-template-columns:minmax(0,1fr)}\n"
115 " .editor{border-right:0}\n"
116 " #app:not([data-view=\"preview\"]) .preview{display:none}\n"
117 " .toolbar{padding:8px 10px;gap:6px}\n"
118 " .toolbar .title{font-size:15px}\n"
119 " .editor{padding:12px}\n"
120 " .preview{padding:12px 14px 32px}\n"
121 "}\n"
122 "</style>\n"
123 "</head><body>\n"
124 "<div id=\"app\" data-view=\"list\">\n"
125 " <aside id=\"side\" class=\"pane\">\n"
126 " <div class=\"side-hd\">\n"
127 " <span class=\"brand\">notes</span>\n"
128 " <button id=\"btnNew\" class=\"icon\" title=\"New note\" aria-label=\"New note\">\n"
129 " <svg viewBox=\"0 0 24 24\"><path d=\"M12 5v14M5 12h14\"/></svg></button>\n"
130 " </div>\n"
131 " <input id=\"q\" class=\"search\" placeholder=\"Search notes\" autocomplete=\"off\" spellcheck=\"false\">\n"
132 " <div id=\"list\" class=\"list\"></div>\n"
133 " <div id=\"listEmpty\" class=\"empty hidden\">No notes yet. Create one with the plus button.</div>\n"
134 " <div class=\"side-ft\">\n"
135 " <span id=\"count\">0 notes</span><span class=\"grow\"></span>\n"
136 " <button id=\"btnTheme\" class=\"icon embed-hide\" title=\"Toggle appearance\" aria-label=\"Toggle appearance\">\n"
137 " <svg viewBox=\"0 0 24 24\"><circle cx=\"12\" cy=\"12\" r=\"4.5\"/><path d=\"M12 2v2M12 20v2M2 12h2M20 12h2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M19.1 4.9l-1.4 1.4M6.3 17.7l-1.4 1.4\"/></svg></button>\n"
138 " </div>\n"
139 " </aside>\n"
140 " <main id=\"main\" class=\"pane\">\n"
141 " <div id=\"editorWrap\" class=\"pane hidden\">\n"
142 " <div class=\"toolbar\">\n"
143 " <button id=\"btnBack\" class=\"icon back\" title=\"All notes\" aria-label=\"All notes\">\n"
144 " <svg viewBox=\"0 0 24 24\"><path d=\"M15 5l-7 7 7 7\"/></svg></button>\n"
145 " <input id=\"title\" class=\"title\" placeholder=\"Untitled note\" spellcheck=\"false\">\n"
146 " <span id=\"state\" class=\"state\">saved</span>\n"
147 " <button id=\"btnPin\" class=\"icon\" title=\"Pin note\" aria-label=\"Pin note\">\n"
148 " <svg viewBox=\"0 0 24 24\"><path d=\"M9 3h6l-1 6 3 3v2H7v-2l3-3-1-6zM12 14v7\"/></svg></button>\n"
149 " <button id=\"btnPreview\" class=\"icon back\" title=\"Toggle preview\" aria-label=\"Toggle preview\">\n"
150 " <svg viewBox=\"0 0 24 24\"><path d=\"M1 12s4-7 11-7 11 7 11 7-4 7-11 7S1 12 1 12z\"/><circle cx=\"12\" cy=\"12\" r=\"3\"/></svg></button>\n"
151 " <button id=\"btnSave\" class=\"btn\" title=\"Save (Ctrl/Cmd+S)\">Save</button>\n"
152 " <button id=\"btnDel\" class=\"icon danger\" title=\"Delete note\" aria-label=\"Delete note\">\n"
153 " <svg viewBox=\"0 0 24 24\"><path d=\"M4 7h16M9 7V5h6v2M6 7l1 13h10l1-13M10 11v6M14 11v6\"/></svg></button>\n"
154 " </div>\n"
155 " <div class=\"split\">\n"
156 " <textarea id=\"body\" class=\"editor\" spellcheck=\"false\" placeholder=\"Write markdown — # heading, **bold**, - list, `code`\"></textarea>\n"
157 " <div id=\"preview\" class=\"preview\"></div>\n"
158 " </div>\n"
159 " </div>\n"
160 " <div id=\"welcome\" class=\"welcome\">\n"
161 " <svg viewBox=\"0 0 24 24\"><path d=\"M6 3h9l5 5v13H6z\"/><path d=\"M14 3v5h5M9 13h7M9 17h5\"/></svg>\n"
162 " <div>Select a note or create a new one.</div>\n"
163 " <div style=\"font-size:11.5px\">Ctrl/Cmd+S saves &middot; Ctrl/Cmd+K searches</div>\n"
164 " </div>\n"
165 " </main>\n"
166 "</div>\n"
167 "<div id=\"toast\" class=\"toast\"></div>\n"
168 "<script>\n"
169 "(function(){\n"
170 "\"use strict\";\n"
171 "var app=document.getElementById('app');\n"
172 "var listEl=document.getElementById('list');\n"
173 "var listEmpty=document.getElementById('listEmpty');\n"
174 "var countEl=document.getElementById('count');\n"
175 "var qEl=document.getElementById('q');\n"
176 "var titleEl=document.getElementById('title');\n"
177 "var bodyEl=document.getElementById('body');\n"
178 "var previewEl=document.getElementById('preview');\n"
179 "var stateEl=document.getElementById('state');\n"
180 "var editorWrap=document.getElementById('editorWrap');\n"
181 "var welcome=document.getElementById('welcome');\n"
182 "var toastEl=document.getElementById('toast');\n"
183 "\n"
184 "var q=new URLSearchParams(location.search);\n"
185 "var node=q.get('node')||'';\n"
186 "var sid=q.get('id')||'';\n"
187 "var pwd=q.get('pwd')||(node&&localStorage.getItem('bot_pwd_'+node))||\n"
188 " localStorage.getItem('bot_active_pwd')||'';\n"
189 "var HUB=q.get('plugin')||'';\n"
190 "var SCROLLKEY='bot_notes_scroll';\n"
191 "\n"
192 "/* Two call routes, and getting this wrong is the most common plugin bug:\n"
193 " * page served through the hub (bot.scorpiox.net/plugins?plugin=plugin_notes&node=..)\n"
194 " * -> call the hub proxy back: /plugins?plugin=plugin_notes&action=..\n"
195 " * opened directly on the node\n"
196 " * -> the plugin itself is the route: /plugin_notes?action=..\n"
197 " * Calling /plugins?plugin= on the node returns the discovery list, not us. */\n"
198 "function url(action,extra){\n"
199 " var u=(HUB?'/plugins?plugin='+encodeURIComponent(HUB):'/plugin_notes')+\n"
200 " '?action='+encodeURIComponent(action)+\n"
201 " (extra?('&'+extra):'')+\n"
202 " (node?'&node='+encodeURIComponent(node):'')+\n"
203 " (sid?'&id='+encodeURIComponent(sid):'')+\n"
204 " (pwd?'&pwd='+encodeURIComponent(pwd):'');\n"
205 " return u;\n"
206 "}\n"
207 "function hdr(extra){\n"
208 " var h=extra||{};\n"
209 " if(pwd)h['X-Bot-Password']=pwd;\n"
210 " return h;\n"
211 "}\n"
212 "function api(action,extra){\n"
213 " return fetch(url(action,extra),{headers:hdr({})}).then(function(r){\n"
214 " if(!r.ok)throw new Error('HTTP '+r.status);\n"
215 " return r.json();\n"
216 " });\n"
217 "}\n"
218 "function apiPost(action,extra,payload){\n"
219 " return fetch(url(action,extra),{method:'POST',\n"
220 " headers:hdr({'Content-Type':'application/json'}),\n"
221 " body:JSON.stringify(payload||{})}).then(function(r){\n"
222 " if(!r.ok)throw new Error('HTTP '+r.status);\n"
223 " return r.json();\n"
224 " });\n"
225 "}\n"
226 "\n"
227 "var notes=[]; /* list rows */\n"
228 "var cur=null; /* {id,title,body,pinned} */\n"
229 "var dirty=false;\n"
230 "var saveTimer=null, prevTimer=null, searchTimer=null;\n"
231 "var saving=false;\n"
232 "\n"
233 "function toast(msg){\n"
234 " toastEl.textContent=msg;\n"
235 " toastEl.classList.add('show');\n"
236 " clearTimeout(toast._t);\n"
237 " toast._t=setTimeout(function(){toastEl.classList.remove('show');},1800);\n"
238 "}\n"
239 "function setState(kind,text){\n"
240 " stateEl.className='state'+(kind?(' '+kind):'');\n"
241 " stateEl.textContent=text;\n"
242 "}\n"
243 "function fmtDate(iso){\n"
244 " if(!iso)return '';\n"
245 " try{\n"
246 " var d=new Date(iso);var now=new Date();\n"
247 " var diff=(now-d)/1000;\n"
248 " if(diff<60)return 'just now';\n"
249 " if(diff<3600)return Math.floor(diff/60)+' min ago';\n"
250 " if(diff<86400)return Math.floor(diff/3600)+' h ago';\n"
251 " if(diff<604800)return Math.floor(diff/86400)+' d ago';\n"
252 " return d.toLocaleDateString();\n"
253 " }catch(e){return ''}\n"
254 "}\n"
255 "\n"
256 "function renderList(){\n"
257 " while(listEl.firstChild)listEl.removeChild(listEl.firstChild);\n"
258 " var shown=0;\n"
259 " notes.forEach(function(n){\n"
260 " var b=document.createElement('button');\n"
261 " b.className='item'+(n.pinned?' pinned':'')+(cur&&cur.id===n.id?' sel':'');\n"
262 " b.setAttribute('data-id',n.id);\n"
263 " var t=document.createElement('div');t.className='t';t.textContent=n.title||'Untitled';\n"
264 " var m=document.createElement('div');m.className='m';\n"
265 " m.textContent=(n.pinned?'Pinned · ':'')+fmtDate(n.updated);\n"
266 " var pm=document.createElement('span');pm.className='pinmark';\n"
267 " pm.innerHTML='<svg viewBox=\"0 0 24 24\"><path d=\"M9 3h6l-1 6 3 3v2H7v-2l3-3-1-6z\"/></svg>';\n"
268 " b.appendChild(t);b.appendChild(m);b.appendChild(pm);\n"
269 " b.onclick=function(){openNote(n.id);};\n"
270 " listEl.appendChild(b);shown++;\n"
271 " });\n"
272 " listEmpty.classList.toggle('hidden',shown>0);\n"
273 " countEl.textContent=shown+(shown===1?' note':' notes');\n"
274 " if(cur){\n"
275 " var sel=listEl.querySelector('.item.sel');\n"
276 " if(sel&&sel.scrollIntoView)sel.scrollIntoView({block:'nearest'});\n"
277 " }\n"
278 "}\n"
279 "\n"
280 "function refresh(){\n"
281 " return api('list').then(function(d){\n"
282 " notes=(d&&d.notes)||[];\n"
283 " renderList();\n"
284 " }).catch(function(e){\n"
285 " toast('Could not load notes: '+e.message);\n"
286 " });\n"
287 "}\n"
288 "\n"
289 "function setView(v){app.setAttribute('data-view',v);}\n"
290 "\n"
291 "function openNote(id){\n"
292 " return api('get','id='+encodeURIComponent(id)).then(function(d){\n"
293 " if(!d||!d.note){toast('Note not found');return;}\n"
294 " cur={id:d.note.id,title:d.note.title||'',body:d.note.body||'',\n"
295 " pinned:!!d.note.pinned};\n"
296 " titleEl.value=cur.title;\n"
297 " bodyEl.value=cur.body;\n"
298 " editorWrap.classList.remove('hidden');\n"
299 " welcome.classList.add('hidden');\n"
300 " setState('','saved');\n"
301 " dirty=false;\n"
302 " setView('edit');\n"
303 " document.getElementById('btnPin').classList.toggle('active',cur.pinned);\n"
304 " renderList();\n"
305 " if(window.matchMedia('(min-width:701px)').matches){\n"
306 " bodyEl.focus();\n"
307 " }\n"
308 " renderPreview();\n"
309 " }).catch(function(e){toast('Could not open note: '+e.message);});\n"
310 "}\n"
311 "\n"
312 "function newNote(){\n"
313 " cur={id:'',title:'',body:'',pinned:false};\n"
314 " titleEl.value='';bodyEl.value='';\n"
315 " editorWrap.classList.remove('hidden');\n"
316 " welcome.classList.add('hidden');\n"
317 " setState('dirty','unsaved');\n"
318 " dirty=true;\n"
319 " setView('edit');\n"
320 " previewEl.innerHTML='';\n"
321 " titleEl.focus();\n"
322 "}\n"
323 "\n"
324 "function scheduleSave(){\n"
325 " dirty=true;\n"
326 " setState('dirty','unsaved');\n"
327 " clearTimeout(saveTimer);\n"
328 " saveTimer=setTimeout(function(){save();},800);\n"
329 "}\n"
330 "\n"
331 "function save(force){\n"
332 " if(!cur)return Promise.resolve();\n"
333 " if(!dirty&&!force)return Promise.resolve();\n"
334 " if(saving)return Promise.resolve();\n"
335 " saving=true;\n"
336 " setState('','saving');\n"
337 " var payload={title:titleEl.value,body:bodyEl.value,pinned:cur.pinned?1:0};\n"
338 " if(cur.id)payload.id=cur.id;\n"
339 " return apiPost('save','',payload).then(function(d){\n"
340 " saving=false;\n"
341 " if(d&&d.note){\n"
342 " cur.id=d.note.id;cur.title=d.note.title;cur.body=bodyEl.value;\n"
343 " dirty=false;\n"
344 " setState('ok','saved');\n"
345 " return refresh();\n"
346 " }\n"
347 " throw new Error(d&&d.error?d.error:'save failed');\n"
348 " }).catch(function(e){\n"
349 " saving=false;\n"
350 " setState('dirty','unsaved');\n"
351 " toast('Save failed: '+e.message);\n"
352 " });\n"
353 "}\n"
354 "\n"
355 "function removeNote(){\n"
356 " if(!cur||!cur.id){newNote();return;}\n"
357 " if(!window.confirm('Move \"'+(cur.title||'Untitled')+'\" to the trash?'))return;\n"
358 " apiPost('delete','id='+encodeURIComponent(cur.id),{}).then(function(){\n"
359 " cur=null;\n"
360 " editorWrap.classList.add('hidden');\n"
361 " welcome.classList.remove('hidden');\n"
362 " setView('list');\n"
363 " toast('Moved to trash');\n"
364 " return refresh();\n"
365 " }).catch(function(e){toast('Delete failed: '+e.message);});\n"
366 "}\n"
367 "\n"
368 "function togglePin(){\n"
369 " if(!cur)return;\n"
370 " cur.pinned=!cur.pinned;\n"
371 " document.getElementById('btnPin').classList.toggle('active',cur.pinned);\n"
372 " if(!cur.id){scheduleSave();return;}\n"
373 " apiPost('pin','id='+encodeURIComponent(cur.id),{pin:cur.pinned?1:0})\n"
374 " .then(function(){return refresh();})\n"
375 " .catch(function(e){toast('Pin failed: '+e.message);});\n"
376 "}\n"
377 "\n"
378 "function renderPreview(){\n"
379 " if(!cur)return;\n"
380 " var text=bodyEl.value;\n"
381 " clearTimeout(prevTimer);\n"
382 " prevTimer=setTimeout(function(){\n"
383 " apiPost('render','',{body:text}).then(function(d){\n"
384 " if(d&&typeof d.html==='string')previewEl.innerHTML=d.html;\n"
385 " }).catch(function(){/* preview is best-effort */});\n"
386 " },220);\n"
387 "}\n"
388 "\n"
389 "function doSearch(){\n"
390 " var term=qEl.value.trim();\n"
391 " clearTimeout(searchTimer);\n"
392 " searchTimer=setTimeout(function(){\n"
393 " if(!term){refresh();return;}\n"
394 " api('search','q='+encodeURIComponent(term)).then(function(d){\n"
395 " notes=(d&&d.notes)||[];\n"
396 " renderList();\n"
397 " }).catch(function(e){toast('Search failed: '+e.message);});\n"
398 " },180);\n"
399 "}\n"
400 "\n"
401 "document.getElementById('btnNew').onclick=newNote;\n"
402 "document.getElementById('btnSave').onclick=function(){save(true);};\n"
403 "document.getElementById('btnDel').onclick=removeNote;\n"
404 "document.getElementById('btnPin').onclick=togglePin;\n"
405 "document.getElementById('btnBack').onclick=function(){\n"
406 " setView('list');renderList();\n"
407 "};\n"
408 "document.getElementById('btnPreview').onclick=function(){\n"
409 " setView(app.getAttribute('data-view')==='preview'?'edit':'preview');\n"
410 "};\n"
411 "qEl.addEventListener('input',doSearch);\n"
412 "titleEl.addEventListener('input',scheduleSave);\n"
413 "bodyEl.addEventListener('input',function(){scheduleSave();renderPreview();});\n"
414 "titleEl.addEventListener('keydown',function(e){\n"
415 " if(e.key==='Enter'){e.preventDefault();bodyEl.focus();}\n"
416 "});\n"
417 "bodyEl.addEventListener('keydown',function(e){\n"
418 " if(e.key==='Tab'){\n"
419 " e.preventDefault();\n"
420 " var s=bodyEl.selectionStart,en=bodyEl.selectionEnd;\n"
421 " bodyEl.value=bodyEl.value.slice(0,s)+' '+bodyEl.value.slice(en);\n"
422 " bodyEl.selectionStart=bodyEl.selectionEnd=s+2;\n"
423 " scheduleSave();renderPreview();\n"
424 " }\n"
425 "});\n"
426 "document.addEventListener('keydown',function(e){\n"
427 " var mod=e.metaKey||e.ctrlKey;\n"
428 " if(!mod)return;\n"
429 " var k=(e.key||'').toLowerCase();\n"
430 " if(k==='s'){e.preventDefault();save(true);}\n"
431 " else if(k==='k'){e.preventDefault();qEl.focus();qEl.select();}\n"
432 " else if(k==='n'&&e.altKey){e.preventDefault();newNote();}\n"
433 "});\n"
434 "\n"
435 "var themeBtn=document.getElementById('btnTheme');\n"
436 "if(themeBtn&&window.sxApplyTheme){\n"
437 " themeBtn.onclick=function(){\n"
438 " window.sxApplyTheme(window.sxTheme&&window.sxTheme()==='dark'?'light':'dark');\n"
439 " };\n"
440 "}\n"
441 "\n"
442 "refresh().then(function(){\n"
443 " if(notes.length&&window.matchMedia('(min-width:701px)').matches){\n"
444 " /* stay on the list — the user picks; predictable beats clever */\n"
445 " }\n"
446 "});\n"
447 "})();\n"
448 "</script>\n"
449 "\002</body></html>\n"
450 ;
451
452#endif /* SX_NOTES_UI_HTML_H */