-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrary.html
More file actions
435 lines (404 loc) · 18.5 KB
/
Copy pathlibrary.html
File metadata and controls
435 lines (404 loc) · 18.5 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CUE — The HTML Presentation Studio</title>
<link rel="icon" href="/__dm/brand/icons/32x32.png">
<link rel="stylesheet" href="/__dm/cue.css">
<style>
/* Page-specific only. Tokens and shared components live in cue.css. */
* { box-sizing:border-box; margin:0; padding:0; }
body { background:var(--cue-canvas); color:var(--cue-ink);
font-family:var(--cue-sans); -webkit-font-smoothing:antialiased; min-height:100vh; }
header { display:flex; align-items:center; gap:13px;
padding:36px 44px 0; max-width:1560px; margin:0 auto; }
.mark { width:26px; height:26px; border-radius:7px; }
h1 { font-size:21px; font-weight:600; letter-spacing:-.025em; }
.count { font-family:var(--cue-mono); font-size:12px; color:var(--cue-ink-3); }
.grow { flex:1; }
main { padding:8px 44px 90px; max-width:1560px; margin:0 auto; }
.cue-sect:first-child { margin-top:30px; }
.grid { display:grid; grid-template-columns:repeat(auto-fill,minmax(330px,1fr));
gap:22px; min-height:24px; border-radius:var(--cue-r-lg); }
.thumb { cursor:pointer; }
.thumb iframe { width:1920px; height:1080px; border:0; transform-origin:0 0;
pointer-events:none; background:#000; }
.thumb .veil { position:absolute; inset:0; }
.body { padding:14px 10px 4px; }
.title { font-size:15px; font-weight:550; letter-spacing:-.01em; line-height:1.35; }
.cue-meta { margin-top:6px; }
.acts { display:flex; gap:6px; padding:10px 8px 6px; }
.acts .more { margin-left:auto; letter-spacing:.08em; }
/* drag and drop between groups */
.cue-card[draggable="true"] { cursor:grab; }
.cue-card.dragging { opacity:.4; }
.cue-sect.drop-hint h2 { color:var(--cue-ink); }
.cue-sect.drop-hint .cue-rule { background:var(--cue-ink-3); opacity:1; }
.grid.drop-hint { outline:2px dashed var(--cue-line-strong); outline-offset:8px; }
#dropnew { display:none; position:fixed; left:50%; transform:translateX(-50%);
bottom:22px; z-index:60; padding:14px 22px; border-radius:var(--cue-r-md);
font-size:13px; color:var(--cue-ink-2); background:rgba(19,19,21,.96);
border:1.5px dashed var(--cue-line-strong);
-webkit-backdrop-filter:blur(8px); backdrop-filter:blur(8px); }
body.dm-dragging #dropnew { display:block; }
#dropnew.drop-hint { border-color:var(--cue-ink-2); color:var(--cue-ink); }
body.dm-dragging .grid:empty { min-height:56px;
outline:1.5px dashed var(--cue-line); outline-offset:-1px; }
/* hidden decks */
.cue-sect.hid-head { cursor:pointer; user-select:none; }
.cue-sect.hid-head h2 { color:var(--cue-ink-2); }
.hid-grid .cue-card { opacity:.6; }
.hid-grid .cue-card:hover { opacity:1; }
.menu { position:fixed; z-index:80; min-width:186px; padding:5px;
display:flex; flex-direction:column; gap:1px;
background:var(--cue-raised-2); border:1px solid var(--cue-line);
border-radius:var(--cue-r-md); box-shadow:0 14px 40px rgba(0,0,0,.55); }
.menu button { font:13px/1 var(--cue-sans); text-align:left; color:var(--cue-ink-2);
background:transparent; border:0; border-radius:6px; padding:9px 11px; cursor:pointer; }
.menu button:hover { background:var(--cue-raised-3); color:var(--cue-ink); }
.menu button:focus-visible { outline:2px solid var(--cue-focus); outline-offset:-2px; }
.empty { color:var(--cue-ink-3); font-size:16px; padding:70px 0; text-align:center; }
.toast { position:fixed; bottom:22px; right:22px; z-index:70;
padding:11px 17px; border-radius:var(--cue-r-md); font-size:14px;
background:var(--cue-raised-2); border:1px solid var(--cue-line);
color:var(--cue-ink); opacity:0; transition:opacity .25s var(--cue-ease);
pointer-events:none; }
.toast[data-on] { opacity:1; }
.toast[data-err] { border-color:#3A1E22; color:var(--cue-danger); }
@media (prefers-reduced-motion:reduce){ .toast{transition:none} }
@media (max-width:760px){ header,main{padding-left:18px;padding-right:18px}
.grid{grid-template-columns:1fr} }
</style>
</head>
<body>
<header>
<img class="mark" src="/__dm/brand/icons/64x64.png" alt="">
<h1>CUE</h1>
<span class="count" id="root-label">…</span>
<span class="grow"></span>
<button class="cue-btn" id="new-deck">New deck</button>
</header>
<main>
<div id="groups"></div>
<div id="dropnew">Drop here to move into a new folder</div>
<div class="empty" id="empty" hidden>No presentations found in this folder yet.</div>
</main>
<div class="toast" id="toast"></div>
<script>
const groupsEl = document.getElementById('groups');
let allGroups = []; // existing group folders, offered by the Move… prompt
const toastEl = document.getElementById('toast');
let toastTimer;
function toast(msg, err) {
toastEl.textContent = msg;
toastEl.toggleAttribute('data-err', !!err);
toastEl.setAttribute('data-on', '');
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toastEl.removeAttribute('data-on'), 3200);
}
async function api(url, body) {
const r = await fetch(url, body
? { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) }
: undefined);
const data = await r.json();
if (!r.ok) throw new Error(data.error || r.statusText);
return data;
}
function deckUrl(d) { return '/files/' + d.path.split('/').map(encodeURIComponent).join('/'); }
function presenterUrl(d) { return '/__dm/presenter.html?deck=' + encodeURIComponent(d.path); }
function slideshowUrl(d) { return deckUrl(d) + '?_dmshow=1#1'; }
function pdfUrl(d) { return '/api/pdf?path=' + encodeURIComponent(d.path); }
function fmtDate(ms) {
return new Date(ms).toLocaleDateString(undefined, { day: 'numeric', month: 'short', year: 'numeric' });
}
/* Overflow menu for a card's secondary actions. One menu element is reused,
positioned under whichever button opened it, and closed on the next click,
Escape, scroll or resize. */
let menuEl = null;
function closeMenu() { if (menuEl) { menuEl.remove(); menuEl = null; } }
function openMenu(anchor, items) {
const wasOpen = menuEl && menuEl.dataset.owner === anchor.dataset.id;
closeMenu();
if (wasOpen) return;
menuEl = document.createElement('div');
menuEl.className = 'menu';
anchor.dataset.id = anchor.dataset.id || String(Math.random());
menuEl.dataset.owner = anchor.dataset.id;
items.forEach((it) => {
const b = document.createElement('button');
if (it.cls) b.className = it.cls;
b.textContent = it.label;
b.addEventListener('click', (e) => { e.stopPropagation(); closeMenu(); it.fn(); });
menuEl.appendChild(b);
});
document.body.appendChild(menuEl);
const r = anchor.getBoundingClientRect();
const w = menuEl.offsetWidth, h = menuEl.offsetHeight;
menuEl.style.left = Math.max(8, Math.min(r.right - w, innerWidth - w - 8)) + 'px';
menuEl.style.top = (r.bottom + h + 8 > innerHeight ? r.top - h - 6 : r.bottom + 6) + 'px';
menuEl.querySelector('button').focus();
}
addEventListener('click', closeMenu);
addEventListener('scroll', closeMenu, true);
addEventListener('resize', closeMenu);
addEventListener('keydown', (e) => { if (e.key === 'Escape') closeMenu(); });
function card(d) {
const el = document.createElement('div');
el.className = 'cue-card';
const thumb = document.createElement('div');
thumb.className = 'cue-plate thumb';
const frame = document.createElement('iframe');
// _snthumb makes deck-stage suppress its rail; loading=lazy keeps big
// decks from all booting at once.
frame.src = deckUrl(d) + '?_snthumb=1#1';
frame.loading = 'lazy';
frame.tabIndex = -1;
thumb.append(frame, Object.assign(document.createElement('div'), { className: 'veil' }));
const scale = () => { frame.style.transform = 'scale(' + (thumb.clientWidth / 1920) + ')'; };
new ResizeObserver(scale).observe(thumb);
thumb.addEventListener('click', () => { location.href = deckUrl(d); });
const meta = document.createElement('div');
meta.className = 'body';
const title = document.createElement('div');
title.className = 'title';
title.textContent = d.title;
const info = document.createElement('div');
info.className = 'cue-meta';
info.textContent = (d.slides != null ? d.slides + ' slides · ' : '') + fmtDate(d.mtime);
if (d.bundled || d.external) {
const b = document.createElement('span');
b.className = 'cue-tag' + (d.external ? ' cue-tag--warn' : '');
b.textContent = d.bundled ? 'bundled' : 'external';
b.title = d.external ? 'A self-contained deck with its own slide engine — open, present as a window, and manage it here; deep editing is deck-stage-only.' : '';
info.appendChild(b);
}
meta.append(title, info);
const actions = document.createElement('div');
actions.className = 'acts';
const mk = (label, cls, fn) => {
const b = document.createElement('button');
b.className = 'cue-act' + (cls ? ' ' + cls : '');
b.textContent = label;
b.addEventListener('click', fn);
actions.appendChild(b);
};
// Secondary actions live behind an overflow so a card shows three controls
// instead of seven. mkMore() collects them; buildMore() renders the menu.
const extra = [];
const mkMore = (label, fn, cls) => extra.push({ label, fn, cls });
const addManageButtons = () => {
mkMore('Duplicate', async () => {
const name = prompt('Name for the copy:', d.title + ' copy');
if (!name) return;
try { await api('/api/duplicate-deck', { path: d.path, name }); toast('Duplicated'); load(); }
catch (e) { toast(e.message, true); }
});
mkMore('Rename', async () => {
const name = prompt('New name:', d.title);
if (!name || name === d.title) return;
try { await api('/api/rename-deck', { path: d.path, name }); toast('Renamed'); load(); }
catch (e) { toast(e.message, true); }
});
mkMore('Move to folder…', async () => {
const hint = allGroups.length ? '\nExisting folders: ' + allGroups.join(' · ') : '';
const folder = prompt('Move to folder (leave empty for the top level).' + hint, d.group || '');
if (folder === null || folder.trim() === (d.group || '')) return;
try { await api('/api/move-deck', { path: d.path, folder: folder.trim() }); toast('Moved'); load(); }
catch (e) { toast(e.message, true); }
});
// Copy the deck, then open the side-by-side translation editor. Structure
// is never touched — only text — so both language versions stay in step.
mkMore('Translate…', async () => {
const lang = prompt('Language or suffix for the translation:\n(the copy is named "' +
d.title + ' (…)")', 'ES');
if (!lang || !lang.trim()) return;
const name = d.title + ' (' + lang.trim() + ')';
try {
const r = await api('/api/duplicate-deck', { path: d.path, name });
toast('Created ' + name);
location.href = '/__dm/translate.html?src=' + encodeURIComponent(d.path) +
'&dst=' + encodeURIComponent(r.path);
} catch (e) { toast(e.message, true); }
});
// Hiding is library metadata only — the deck's files stay exactly where
// they are. Real deletion lives in the Hidden section.
mkMore('Hide', async () => {
try { await api('/api/hide-deck', { path: d.path, hidden: true }); toast('Hidden — find it in the Hidden section below'); load(); }
catch (e) { toast(e.message, true); }
});
};
if (d.hidden) {
// Hidden-section card: restore, or truly remove (to the recoverable trash).
mk('Open', 'cue-act--primary', () => { location.href = deckUrl(d); });
mk('Unhide', 'cue-act--primary', async () => {
try { await api('/api/hide-deck', { path: d.path, hidden: false }); toast('Restored to the library'); load(); }
catch (e) { toast(e.message, true); }
});
mk('Delete', 'cue-act--danger', async () => {
if (!confirm('Delete “' + d.title + '”?\n\nIt will be moved to the .cue-trash folder next to your decks, so you can still recover it.')) return;
try { await api('/api/delete-deck', { path: d.path }); toast('Moved to trash'); load(); }
catch (e) { toast(e.message, true); }
});
} else if (d.bundled) {
mk('View', 'cue-act--primary', () => { location.href = deckUrl(d); });
mk('Import to edit', 'cue-act--primary', async () => {
try {
const r = await api('/api/unbundle', { path: d.path });
toast('Imported → ' + r.path);
load();
} catch (e) { toast(e.message, true); }
});
} else if (d.external) {
// Non-deck-stage deck: open / share as a window / export; no deck-stage editing.
mk('Open', 'cue-act--primary', () => { location.href = deckUrl(d); });
mk('Window', '', () => { window.open(deckUrl(d), 'dm-ext-' + d.path); });
mkMore('Export PDF', () => { window.open(pdfUrl(d), '_blank'); });
addManageButtons();
} else {
mk('Open', 'cue-act--primary', () => { location.href = deckUrl(d); });
mk('Slideshow', '', () => { window.open(slideshowUrl(d), 'dm-slideshow-' + d.path); });
mk('Present', '', () => { window.open(presenterUrl(d), '_blank'); });
mkMore('Export PDF', () => { window.open(pdfUrl(d), '_blank'); });
addManageButtons();
}
if (extra.length) {
const more = document.createElement('button');
more.className = 'cue-act more';
more.textContent = '\u00b7\u00b7\u00b7';
more.title = 'More actions';
more.setAttribute('aria-haspopup', 'true');
more.addEventListener('click', (e) => { e.stopPropagation(); openMenu(more, extra); });
actions.appendChild(more);
}
el.append(thumb, meta, actions);
// Drag a card onto another section (or the new-folder / Hidden targets).
if (!d.bundled && !d.hidden) {
el.draggable = true;
el.addEventListener('dragstart', (e) => {
dragDeck = d;
e.dataTransfer.setData('text/plain', d.path);
e.dataTransfer.effectAllowed = 'move';
el.classList.add('dragging');
document.body.classList.add('dm-dragging');
});
el.addEventListener('dragend', () => {
dragDeck = null;
el.classList.remove('dragging');
document.body.classList.remove('dm-dragging');
document.querySelectorAll('.drop-hint').forEach((n) => n.classList.remove('drop-hint'));
});
}
return el;
}
let dragDeck = null;
/** Make an element accept dragged deck cards; onDrop gets the dragged deck. */
function dropTarget(elm, onDrop) {
elm.addEventListener('dragover', (e) => {
if (!dragDeck) return;
e.preventDefault();
e.dataTransfer.dropEffect = 'move';
elm.classList.add('drop-hint');
});
elm.addEventListener('dragleave', () => elm.classList.remove('drop-hint'));
elm.addEventListener('drop', (e) => {
e.preventDefault();
elm.classList.remove('drop-hint');
if (dragDeck) onDrop(dragDeck);
});
}
async function dropMove(d, folder) {
if ((d.group || '') === folder) return;
try { await api('/api/move-deck', { path: d.path, folder }); toast('Moved' + (folder ? ' to ' + folder : ' to top level')); load(); }
catch (e) { toast(e.message, true); }
}
async function load() {
try {
const decks = await api('/api/decks');
const visible = decks.filter((d) => !d.hidden);
document.getElementById('root-label').textContent =
visible.length + (visible.length === 1 ? ' deck' : ' decks');
const hiddenDecks = decks.filter((d) => d.hidden);
allGroups = [...new Set(visible.map((d) => d.group).filter(Boolean))].sort();
// Section per group folder; top-level (ungrouped) decks come first. The
// top-level section always exists so it's available as a drop target
// (shown as a labeled strip while dragging).
const byGroup = new Map([['', []]]);
for (const d of visible) {
const g = d.group || '';
if (!byGroup.has(g)) byGroup.set(g, []);
byGroup.get(g).push(d);
}
const keys = [...byGroup.keys()].sort((a, b) =>
a === '' ? -1 : b === '' ? 1 : a.localeCompare(b));
const frag = document.createDocumentFragment();
for (const g of keys) {
const wrap = document.createElement('div');
wrap.className = 'grid';
byGroup.get(g).forEach((d) => wrap.appendChild(card(d)));
const h = document.createElement('div');
h.className = 'cue-sect';
const t = document.createElement('h2');
t.textContent = g || 'Ungrouped';
const n = document.createElement('span');
n.className = 'cue-n';
n.textContent = byGroup.get(g).length;
const rule = document.createElement('span');
rule.className = 'cue-rule';
h.append(t, n, rule);
dropTarget(h, (d) => dropMove(d, g));
frag.appendChild(h);
dropTarget(wrap, (d) => dropMove(d, g));
frag.appendChild(wrap);
}
// Hidden section — collapsed by default, remembered per browser. Cards
// here offer Unhide / Delete; dropping a card on the header hides it.
if (hiddenDecks.length) {
const open = localStorage.getItem('dm.hiddenOpen') === '1';
const h = document.createElement('div');
h.className = 'cue-sect hid-head';
const ht = document.createElement('h2');
ht.textContent = (open ? '▾' : '▸') + ' Hidden';
const hn = document.createElement('span');
hn.className = 'cue-n';
hn.textContent = hiddenDecks.length;
const hr = document.createElement('span');
hr.className = 'cue-rule';
h.append(ht, hn, hr);
h.title = 'Hidden from the library; the files are untouched. Click to expand, or drop a card here to hide it.';
const wrap = document.createElement('div');
wrap.className = 'grid hid-grid';
wrap.hidden = !open;
hiddenDecks.forEach((d) => wrap.appendChild(card(d)));
h.addEventListener('click', () => {
wrap.hidden = !wrap.hidden;
localStorage.setItem('dm.hiddenOpen', wrap.hidden ? '0' : '1');
ht.textContent = (wrap.hidden ? '▸' : '▾') + ' Hidden';
});
dropTarget(h, async (d) => {
try { await api('/api/hide-deck', { path: d.path, hidden: true }); toast('Hidden'); load(); }
catch (e) { toast(e.message, true); }
});
frag.append(h, wrap);
}
groupsEl.replaceChildren(frag);
document.getElementById('empty').hidden = decks.length > 0;
} catch (e) { toast(e.message, true); }
}
// Drop a card on the floating zone to file it into a brand-new folder.
dropTarget(document.getElementById('dropnew'), (d) => {
const folder = prompt('Name for the new folder:');
if (folder && folder.trim()) dropMove(d, folder.trim());
});
document.getElementById('new-deck').addEventListener('click', async () => {
const name = prompt('Name for the new presentation:');
if (!name) return;
try {
const r = await api('/api/new-deck', { name });
toast('Created');
location.href = '/files/' + r.path.split('/').map(encodeURIComponent).join('/');
} catch (e) { toast(e.message, true); }
});
load();
</script>
</body>
</html>