source: Klonkt/src/views/pages/post-edit.ejs@ 8d32dcf

main
Last change on this file since 8d32dcf was b9dc94c, checked in by roboburr <roboburr@…>, 3 months ago

Release scheduling + fan-only previews (premium feature #3)

  • DB: posts.publish_at (scheduled go-live) + posts.fan_only.
  • Release scheduling: published + future publish_at -> status 'scheduled' (excluded from public status='published' queries). Scheduler.js publishes them when the time is reached (setInterval 60s + on boot) + adds them to posts_fts. No public queries changed -> low risk.
  • Fan-only: posts.fan_only; the single-post view shows anonymous visitors a clean login gate (pages/fan-gate.ejs, link /auth/login?next=) instead of the content; logged-in fans see everything. Listings show the teaser.
  • create/save: read publish_at + fan_only; FTS excludes 'scheduled'.
  • editor (post-edit): premium-gated fields "Fans only" + "Publish on" (datetime-local) + "scheduled for" notice.
  • server.js: startScheduler() after initializeDatabase.

node --check passed.

Co-Authored-By: Claude <noreply@…>

  • Property mode set to 100644
File size: 60.0 KB
RevLine 
[7bc636b]1<%
2// Post editor — split into card sections for visual hierarchy:
3// - Identity : title, slug, excerpt
4// - Cover : thumbnail + URL + custom upload button
5// - Content : markdown textarea with attached toolbar
6// - Meta : status, type, pin, noindex, tags
7//
8// All behavior (IDs, names, upload endpoints) is preserved — only layout
9// and styling changed.
10const _hasCover = !!post.cover_image_url;
[851239c]11// In hub-modus moeten save/create/cancel de /user/<slug>/-prefix dragen, anders
12// valt de request terug op de primaire site (siteUrlBase leeg) en rendert de
13// post na opslaan headerless (bareChrome). In solo is _base leeg.
14const _base = (typeof siteUrlBase !== 'undefined' && siteUrlBase) ? siteUrlBase : '';
[7bc636b]15%>
16<div class="container post-edit-page">
17 <h1><%= isNew ? 'Nieuwe post' : 'Post bewerken' %></h1>
18
[851239c]19 <form method="post" action="<%= _base %><%= isNew ? '/posts/create' : '/posts/' + post.slug + '/save' %>" class="post-edit-form">
[7bc636b]20
21 <%# ── IDENTITY ─────────────────────────────────────────────── %>
22 <section class="pe-card">
23 <label class="pe-field">
24 <span>Titel</span>
25 <input type="text" name="title" value="<%= post.title %>" required autofocus>
26 </label>
27 <div class="pe-row pe-row-2">
28 <label class="pe-field">
29 <span>Slug (URL)</span>
30 <input type="text" name="slug" value="<%= post.slug %>" placeholder="auto van titel als leeg">
31 </label>
32 <label class="pe-field">
33 <span>Tags <small>(komma-gescheiden)</small></span>
34 <input type="text" name="tags" value="<%= Array.isArray(post.tags) ? post.tags.join(', ') : '' %>">
35 </label>
36 </div>
37 <label class="pe-field">
38 <span>Excerpt <small>(preview tekst)</small></span>
39 <textarea name="excerpt" rows="2"><%= post.excerpt %></textarea>
40 </label>
41 </section>
42
43 <%# ── COVER ────────────────────────────────────────────────── %>
44 <section class="pe-card">
45 <div class="pe-section-title">Cover</div>
46 <div class="pe-cover-row">
47 <div class="pe-cover-thumb" id="cover-preview-wrap" <%= _hasCover ? '' : 'data-empty' %>>
48 <img src="<%= _hasCover ? post.cover_image_url : '' %>" alt="" id="cover-preview-img" <%= _hasCover ? '' : 'hidden' %>>
49 <% if (!_hasCover) { %><span class="pe-cover-empty">🖼</span><% } %>
50 </div>
51 <div class="pe-cover-actions">
52 <label class="pe-field">
53 <span>Cover URL</span>
[b50a885]54 <input type="text" name="cover_image_url" id="cover-url-field"
[7bc636b]55 value="<%= post.cover_image_url || '' %>"
[b50a885]56 inputmode="url" autocapitalize="none" spellcheck="false"
57 placeholder="/media/… of https://… (of upload met de knop)">
[7bc636b]58 </label>
59 <div class="pe-cover-upload">
60 <button type="button" class="pe-btn pe-btn-secondary" id="cover-upload-trigger">
61 📷 Upload nieuwe cover
62 </button>
63 <input type="file" id="cover-upload-field" accept="image/jpeg,image/png,image/webp,image/gif" hidden>
64 <small id="cover-upload-status" class="pe-status"></small>
65 </div>
66 </div>
67 </div>
68 </section>
69
70 <%# ── CONTENT ──────────────────────────────────────────────── %>
71 <section class="pe-card pe-card-content">
72 <div class="pe-section-title">
73 Content
74 <small>Sleep een afbeelding om in te voegen · selecteer tekst om op te maken</small>
75 </div>
76 <div class="pe-editor-frame">
77 <div class="pe-toolbar" id="pe-toolbar" role="toolbar" aria-label="Format">
78 <button type="button" data-cmd="bold" title="Vet (Ctrl+B)" aria-label="Vet">
79 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 4h8a4 4 0 0 1 0 8H6z"/><path d="M6 12h9a4 4 0 0 1 0 8H6z"/></svg>
80 </button>
81 <button type="button" data-cmd="italic" title="Cursief (Ctrl+I)" aria-label="Cursief">
82 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="19" y1="4" x2="10" y2="4"/><line x1="14" y1="20" x2="5" y2="20"/><line x1="15" y1="4" x2="9" y2="20"/></svg>
83 </button>
84 <button type="button" data-cmd="underline" title="Onderstreept" aria-label="Onderstreept">
85 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 4v6a6 6 0 0 0 12 0V4"/><line x1="4" y1="20" x2="20" y2="20"/></svg>
86 </button>
87 <span class="pe-toolbar-sep" aria-hidden="true"></span>
88 <button type="button" class="pe-tb-text" data-cmd="formatBlock" data-arg="h2" title="Kop">H2</button>
89 <button type="button" class="pe-tb-text" data-cmd="formatBlock" data-arg="h3" title="Subkop">H3</button>
90 <button type="button" class="pe-tb-text" data-cmd="formatBlock" data-arg="p" title="Paragraaf">¶</button>
91 <span class="pe-toolbar-sep" aria-hidden="true"></span>
92 <button type="button" data-cmd="insertUnorderedList" title="Lijst" aria-label="Lijst">
93 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="9" y1="6" x2="20" y2="6"/><line x1="9" y1="12" x2="20" y2="12"/><line x1="9" y1="18" x2="20" y2="18"/><circle cx="4.5" cy="6" r="1.2"/><circle cx="4.5" cy="12" r="1.2"/><circle cx="4.5" cy="18" r="1.2"/></svg>
94 </button>
95 <button type="button" data-cmd="insertOrderedList" title="Genummerde lijst" aria-label="Genummerde lijst">
96 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="10" y1="6" x2="21" y2="6"/><line x1="10" y1="12" x2="21" y2="12"/><line x1="10" y1="18" x2="21" y2="18"/><path d="M4 6h1v4"/><path d="M4 10h2"/><path d="M6 18H4c0-1 2-2 2-3s-1-1.5-2-1"/></svg>
97 </button>
98 <button type="button" data-cmd="formatBlock" data-arg="blockquote" title="Quote" aria-label="Quote">
99 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 21c3 0 7-1 7-8V5c0-1.25-.75-2-2-2H4c-1.25 0-2 .75-2 2v6c0 1.25.75 2 2 2h2.5C6 17.5 4 19 3 19v2z"/><path d="M14 21c3 0 7-1 7-8V5c0-1.25-.75-2-2-2h-4c-1.25 0-2 .75-2 2v6c0 1.25.75 2 2 2h2.5c-.5 4.5-2.5 6-3.5 6v2z"/></svg>
100 </button>
101 <button type="button" data-cmd="link-prompt" title="Link (Ctrl+K)" aria-label="Link">
102 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/></svg>
103 </button>
104 <button type="button" data-cmd="code-wrap" title="Code (inline)" aria-label="Code">
105 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/></svg>
106 </button>
107 <span class="pe-toolbar-sep" aria-hidden="true"></span>
108 <button type="button" id="insert-image-btn" title="Afbeelding invoegen" aria-label="Afbeelding">
109 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><path d="M21 15l-5-5L5 21"/></svg>
110 </button>
111 <button type="button" id="insert-track-btn" title="Track invoegen" aria-label="Track">
112 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 18V5l12-2v13"/><circle cx="6" cy="18" r="3"/><circle cx="18" cy="16" r="3"/></svg>
113 </button>
114 <button type="button" id="insert-playlist-btn" title="Playlist invoegen" aria-label="Playlist">
115 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="8" y1="6" x2="21" y2="6"/><line x1="8" y1="12" x2="21" y2="12"/><line x1="8" y1="18" x2="15" y2="18"/><polygon points="3 5 3 13 9 9"/></svg>
116 </button>
[1907a18]117 <button type="button" id="insert-embed-btn" title="Embed (YouTube, Spotify, SoundCloud, Vimeo…)" aria-label="Media embedden">
118 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="2" y="4" width="20" height="16" rx="2"/><polygon points="10 9 15.5 12 10 15"/></svg>
119 </button>
[7bc636b]120 <span class="pe-toolbar-spacer"></span>
121 <button type="button" data-cmd="removeFormat" title="Wis opmaak" aria-label="Wis opmaak">
122 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 7V4h16v3"/><path d="M9 20h6"/><path d="M5 5l14 14" stroke-linecap="round"/></svg>
123 </button>
124 </div>
125
126 <div id="content-editor"
127 class="pe-editor"
128 contenteditable="true"
129 role="textbox"
130 aria-multiline="true"
131 aria-label="Content"
132 data-placeholder="Begin met schrijven…"></div>
133
134 <%# Hidden field is what actually submits to the server. The visible
135 contenteditable's serialized HTML is copied here on submit. %>
136 <input type="hidden" name="content" id="content-hidden" value="">
137
138 <%# Initial content is injected as a JSON string in a script tag so we
139 can set innerHTML safely from JS. EJS-escaping HTML directly into
140 the editor would render entity-escaped tags as text. %>
141 <script id="initial-content" type="application/json"><%- JSON.stringify(post.content || '').replace(/</g, '\\u003c') %></script>
142
143 <div class="pe-editor-status">
144 <small id="content-upload-status" class="pe-status"></small>
145 <span class="pe-char-count"><span id="char-count">0</span> tekens</span>
146 </div>
147
148 <input type="file" id="content-upload-field" accept="image/jpeg,image/png,image/webp,image/gif" hidden>
149 </div>
150 </section>
151
152 <%# ── META ─────────────────────────────────────────────────── %>
153 <section class="pe-card">
154 <div class="pe-section-title">Publicatie</div>
155 <div class="pe-row pe-row-2">
156 <label class="pe-field">
157 <span>Status</span>
[edc462d]158 <% var _st = isNew ? 'published' : (post.status || 'draft'); %>
[7bc636b]159 <select name="status">
[edc462d]160 <option value="published" <%= _st === 'published' ? 'selected' : '' %>>Gepubliceerd</option>
161 <option value="draft" <%= _st === 'draft' ? 'selected' : '' %>>Concept</option>
162 <option value="archived" <%= _st === 'archived' ? 'selected' : '' %>>Gearchiveerd</option>
[7bc636b]163 </select>
164 </label>
165 <label class="pe-field">
166 <span>Type</span>
167 <select name="type">
168 <% var ptype = post.type || 'post'; %>
169 <option value="post" <%= ptype === 'post' ? 'selected' : '' %>>Post</option>
170 <option value="foto" <%= ptype === 'foto' ? 'selected' : '' %>>Foto</option>
171 <option value="video" <%= ptype === 'video' ? 'selected' : '' %>>Video</option>
172 <option value="audio" <%= ptype === 'audio' ? 'selected' : '' %>>Audio</option>
173 </select>
174 </label>
175 </div>
176 <div class="pe-checkboxes">
[edc462d]177 <div class="pe-pin">
178 <label class="pe-checkbox">
179 <input type="checkbox" id="pin-toggle" <%= (Number(post.pinned) > 0) ? 'checked' : '' %>>
180 <span>📌 Vastpinnen bovenaan</span>
181 </label>
182 <input type="hidden" name="pinned" id="pin-rank" value="<%= post.pinned || 0 %>">
183 <div class="pe-pin-pos" id="pin-pos" <%= (Number(post.pinned) > 0) ? '' : 'hidden' %>>
184 <span class="pe-pin-steps">
185 <button type="button" class="pe-pin-btn" id="pin-up" aria-label="Hoger zetten">▲</button>
186 <button type="button" class="pe-pin-btn" id="pin-down" aria-label="Lager zetten">▼</button>
187 </span>
188 <span class="pe-pin-label" id="pin-label"></span>
189 </div>
190 </div>
[7bc636b]191 <label class="pe-checkbox">
192 <input type="checkbox" name="noindex" value="1" <%= post.noindex ? 'checked' : '' %>>
193 <span>🚫 noindex (verberg voor zoekmachines)</span>
194 </label>
[b9dc94c]195 <% if (typeof premiumUnlocked === 'undefined' || premiumUnlocked) { %>
196 <label class="pe-checkbox">
197 <input type="checkbox" name="fan_only" value="1" <%= post.fan_only ? 'checked' : '' %>>
198 <span>🔒 Alleen voor ingelogde fans</span>
199 </label>
200 <div style="margin-top:8px">
201 <label style="display:block;font-size:12.5px;opacity:.8;margin-bottom:4px">📅 Publiceren op (laat leeg = direct)</label>
202 <input type="datetime-local" name="publish_at" value="<%= post.publish_at ? String(post.publish_at).replace(' ','T').slice(0,16) : '' %>" style="padding:8px 10px;border-radius:8px;border:1px solid var(--rule,rgba(128,128,128,.4));background:transparent;color:inherit">
203 <% if (post.status === 'scheduled' && post.publish_at) { %><div style="font-size:12px;opacity:.7;margin-top:4px">⏳ Ingepland voor <%= post.publish_at %></div><% } %>
204 </div>
205 <% } %>
[7bc636b]206 </div>
207 </section>
208
209 <%# ── ACTIONS (sticky at bottom) ──────────────────────────── %>
210 <div class="pe-actions">
[851239c]211 <a href="<%= _base %><%= isNew ? '/' : '/' + post.slug %>" class="pe-btn">Annuleren</a>
[7bc636b]212 <div class="pe-actions-spacer"></div>
213 <% if (!isNew && post.status !== 'published') { %>
214 <button type="submit" name="action" value="publish" class="pe-btn pe-btn-success">📤 Publish</button>
215 <% } %>
216 <button type="submit" class="pe-btn pe-btn-primary">💾 Opslaan</button>
217 </div>
218 </form>
219</div>
220
221<style>
222/* ─── Page wrapper ──────────────────────────────────────────────── */
223.post-edit-page {
224 max-width: 880px;
225 margin: 1.5rem auto 6rem; /* extra bottom for sticky-actions clearance */
226 padding: 0 1rem;
227}
228.post-edit-page h1 {
229 font-family: var(--font-display, serif);
230 margin: 0 0 1.25rem;
231 font-size: 1.75rem;
232}
233
234.post-edit-form {
235 display: flex; flex-direction: column;
236 gap: 1rem;
237}
238
239/* ─── Card sections ─────────────────────────────────────────────── */
240.pe-card {
241 background: var(--paper);
242 border: 1px solid var(--rule);
243 border-radius: 12px;
244 padding: 1.25rem;
245 display: flex; flex-direction: column;
246 gap: 0.85rem;
247}
248.pe-card-content { padding-bottom: 0; overflow: hidden; } /* editor flush to bottom */
249.pe-section-title {
250 font-size: 0.8rem;
251 font-weight: 600;
252 text-transform: uppercase;
253 letter-spacing: 0.05em;
254 color: var(--ink-soft);
255 display: flex; align-items: baseline; gap: 0.5rem;
256 flex-wrap: wrap;
257}
258.pe-section-title small {
259 font-size: 0.75rem; font-weight: 400;
260 letter-spacing: 0; text-transform: none;
261 color: var(--ink-muted, var(--ink-soft));
262}
263
264/* ─── Field primitives ──────────────────────────────────────────── */
265.pe-field {
266 display: flex; flex-direction: column;
267 gap: 0.35rem;
268 min-width: 0; /* allow grid items to shrink */
269}
270.pe-field > span {
271 font-size: 0.8rem;
272 font-weight: 600;
273 color: var(--ink-soft);
274 display: flex; align-items: baseline; gap: 0.4rem;
275}
276.pe-field > span small {
277 font-weight: 400; color: var(--ink-muted);
278}
279.pe-field input,
280.pe-field textarea,
281.pe-field select {
282 width: 100%;
283 box-sizing: border-box;
284 display: block;
285 padding: 0.6rem 0.75rem;
286 border: 1px solid var(--rule);
287 border-radius: 6px;
288 background: var(--paper-2);
289 color: var(--ink);
290 font-family: var(--font-ui, system-ui), sans-serif;
291 font-size: 0.95rem;
292 -webkit-appearance: none;
293 appearance: none;
294 transition: border-color 120ms;
295}
296.pe-field input:focus,
297.pe-field textarea:focus,
298.pe-field select:focus {
299 outline: 2px solid var(--accent);
300 outline-offset: -1px;
301 border-color: var(--accent);
302}
303.pe-field textarea {
304 font-family: var(--font-mono, monospace);
305 resize: vertical;
306}
307.pe-field select {
308 /* Restore the dropdown arrow we removed with appearance:none */
309 background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
310 background-repeat: no-repeat;
311 background-position: right 0.75rem center;
312 padding-right: 2rem;
313}
314
315.pe-row {
316 display: grid;
317 gap: 0.75rem;
318}
319.pe-row-2 { grid-template-columns: 1fr 1fr; }
320@media (max-width: 600px) {
321 .pe-row-2 { grid-template-columns: 1fr; }
322}
323
324/* ─── Cover field ───────────────────────────────────────────────── */
325.pe-cover-row {
326 display: grid;
327 grid-template-columns: 120px 1fr;
328 gap: 1rem;
329 align-items: start;
330}
331.pe-cover-thumb {
332 width: 120px; height: 120px;
333 border-radius: 10px;
334 overflow: hidden;
335 background: var(--paper-2);
336 border: 1px solid var(--rule);
337 display: flex; align-items: center; justify-content: center;
338 position: relative;
339}
340.pe-cover-thumb[data-empty] {
341 border-style: dashed;
342}
343.pe-cover-thumb img {
344 width: 100%; height: 100%;
345 object-fit: cover; display: block;
346}
347/* Honor HTML hidden — our display:block above otherwise renders an empty
348 broken-image icon when no cover is set. */
349.pe-cover-thumb img[hidden] { display: none; }
350.pe-cover-empty {
351 font-size: 2rem;
352 color: var(--ink-muted, var(--ink-soft));
353 opacity: 0.5;
354}
355.pe-cover-actions {
356 display: flex; flex-direction: column;
357 gap: 0.6rem;
358 min-width: 0;
359}
360.pe-cover-upload {
361 display: flex; align-items: center; gap: 0.6rem;
362 flex-wrap: wrap;
363}
364@media (max-width: 600px) {
365 .pe-cover-row { grid-template-columns: 88px 1fr; }
366 .pe-cover-thumb { width: 88px; height: 88px; }
367}
368
369/* ─── Editor frame (WYSIWYG: top toolbar, contenteditable body, status bar) ─── */
370.pe-editor-frame {
371 margin: 0 -1.25rem -1.25rem; /* break out of card padding for flush edges */
372 border-top: 1px solid var(--rule);
373 background: var(--paper);
374 display: flex; flex-direction: column;
375}
376
377/* Top toolbar — sticks to the top of the viewport while editing */
378.pe-toolbar {
379 display: flex; align-items: center; gap: .15rem;
380 flex-wrap: wrap;
381 padding: .4rem .75rem;
382 background: color-mix(in srgb, var(--paper) 92%, transparent);
383 backdrop-filter: blur(10px);
384 -webkit-backdrop-filter: blur(10px);
385 border-bottom: 1px solid var(--rule);
386 position: sticky;
387 top: 0;
388 z-index: 10;
389}
390.pe-toolbar button {
391 display: inline-flex; align-items: center; justify-content: center;
392 width: 32px; height: 32px;
393 padding: 0;
394 background: transparent;
395 border: 1px solid transparent;
396 border-radius: 6px;
397 color: var(--ink);
398 cursor: pointer;
399 font-family: var(--font-ui, system-ui), sans-serif;
400 font-weight: 600; font-size: .85rem;
401 transition: background var(--transition), color var(--transition), border-color var(--transition);
402 -webkit-tap-highlight-color: transparent;
403}
404.pe-toolbar button:hover {
405 background: var(--paper-2);
406 color: var(--accent);
407}
408.pe-toolbar button:active { transform: scale(.94); }
409.pe-toolbar button.is-active {
410 background: color-mix(in srgb, var(--accent) 14%, var(--paper-2));
411 color: var(--accent);
412 border-color: color-mix(in srgb, var(--accent) 30%, transparent);
413}
414.pe-toolbar button svg { width: 16px; height: 16px; }
415.pe-toolbar button.pe-tb-text { font-family: var(--font-display, serif); font-weight: 700; }
416.pe-toolbar-sep {
417 width: 1px; height: 18px;
418 background: var(--rule);
419 margin: 0 .35rem;
420 flex-shrink: 0;
421}
422.pe-toolbar-spacer { flex: 1; }
423
424/* Editor body — looks like prose, behaves like a textarea */
425.pe-editor {
426 width: 100%;
427 box-sizing: border-box;
428 min-height: 420px;
429 padding: 1.25rem 1.5rem;
430 border: 0;
431 background: transparent;
432 color: var(--ink);
433 font-family: var(--font-body, system-ui), serif;
434 font-size: 1.0625rem;
435 line-height: 1.65;
436 outline: none;
437 overflow-y: auto;
438}
439.pe-editor:focus { outline: none; }
440.pe-editor.is-dragover {
441 outline: 2px dashed var(--accent);
442 outline-offset: -10px;
443}
444.pe-editor[data-placeholder]:empty::before,
445.pe-editor[data-placeholder]:has(br:only-child)::before {
446 content: attr(data-placeholder);
447 color: var(--ink-muted, #999);
448 pointer-events: none;
449 opacity: .55;
450}
451/* Inline prose styles inside the editor — match the public post styling so
452 what you see is roughly what you'll get. Margins are tighter than on the
453 live site since this is a confined writing space. */
454.pe-editor h1, .pe-editor h2, .pe-editor h3, .pe-editor h4 {
455 font-family: var(--font-display, serif);
456 line-height: 1.2;
457 margin: 1.1rem 0 .35rem;
458}
459.pe-editor h1 { font-size: 1.85rem; }
460.pe-editor h2 { font-size: 1.45rem; }
461.pe-editor h3 { font-size: 1.2rem; }
462.pe-editor p { margin: 0 0 .85em; }
463.pe-editor ul, .pe-editor ol { margin: 0 0 .85em 1.4em; padding: 0; }
464.pe-editor li { margin: .15em 0; }
465.pe-editor blockquote {
466 margin: 1em 0;
467 padding: .15em 0 .15em 1em;
468 border-left: 3px solid var(--accent);
469 color: var(--ink-soft, var(--ink));
470 font-style: italic;
471}
472.pe-editor code {
473 background: var(--paper-2);
474 border: 1px solid var(--rule);
475 border-radius: 4px;
476 padding: .1em .35em;
477 font-family: var(--font-mono, ui-monospace, monospace);
478 font-size: .92em;
479}
480.pe-editor a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
481.pe-editor img {
482 max-width: 100%; height: auto;
483 border-radius: 6px;
484 display: block;
485 margin: 1em auto;
486}
487
488/* Shortcode chips — visible inline placeholder in the editor for
489 [[track:UUID]] / [[album:Name]] / [[playlist:slug]]. They serialize back
490 to plain shortcode text on submit. */
491.sc-chip {
492 display: inline-flex; align-items: center; gap: .3rem;
493 padding: .15em .5em;
494 margin: 0 .15em;
495 background: color-mix(in srgb, var(--accent) 10%, var(--paper-2));
496 border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--rule));
497 border-radius: 999px;
498 color: var(--accent);
499 font-family: var(--font-ui, system-ui), sans-serif;
500 font-size: .85em;
501 font-weight: 600;
502 font-style: normal;
503 white-space: nowrap;
504 user-select: none;
505 cursor: default;
506 vertical-align: baseline;
507}
508.sc-chip-icon { display: inline-flex; opacity: .8; }
509.sc-chip-icon svg { width: 12px; height: 12px; }
510
511/* Status bar below the editor */
512.pe-editor-status {
513 display: flex; align-items: center; justify-content: space-between;
514 gap: .75rem;
515 padding: .45rem 1rem;
516 border-top: 1px solid var(--rule);
517 background: var(--paper-2);
518 color: var(--ink-muted, var(--ink-soft));
519 font-size: .78rem;
520}
521.pe-char-count { font-variant-numeric: tabular-nums; }
522
523/* ─── Track picker modal (P59) ─────────────────────────────────
524 Mobile-first: full-screen bottom-sheet on phones, centered card
525 on desktop. Lock body scroll while open via .tp-locked on body. */
526.tp-modal {
527 position: fixed; inset: 0;
528 z-index: 1000;
529 display: flex; align-items: stretch; justify-content: center;
530 /* Avoid the iOS home-indicator + the keyboard when search is focused */
531 padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
532}
533.tp-modal[hidden] { display: none; }
534.tp-backdrop {
535 position: absolute; inset: 0;
536 background: color-mix(in srgb, var(--ink) 55%, transparent);
537 backdrop-filter: blur(4px);
538 -webkit-backdrop-filter: blur(4px);
539 animation: tp-bd-in .18s ease-out;
540}
541@keyframes tp-bd-in { from { opacity: 0 } to { opacity: 1 } }
542
543/* Mobile: sheet docks to the bottom and fills viewport almost completely */
544.tp-sheet {
545 position: relative;
546 margin-top: auto;
547 width: 100%;
548 max-height: calc(100dvh - env(safe-area-inset-top) - 1rem);
549 background: var(--paper);
550 border-top: 1px solid var(--rule);
551 border-radius: 16px 16px 0 0;
552 box-shadow:
553 0 -2px 8px color-mix(in srgb, var(--ink) 8%, transparent),
554 0 -16px 48px color-mix(in srgb, var(--ink) 18%, transparent);
555 display: flex; flex-direction: column;
556 animation: tp-sheet-up .22s cubic-bezier(.2, .8, .25, 1);
557 overflow: hidden;
558}
559@keyframes tp-sheet-up {
560 from { transform: translateY(100%); opacity: .8; }
561 to { transform: translateY(0); opacity: 1; }
562}
563
564/* Header — title + close, with a small grab-handle bar on mobile */
565.tp-header {
566 display: flex; align-items: center; justify-content: space-between;
567 gap: .75rem;
568 padding: .85rem 1rem .65rem;
569 border-bottom: 1px solid var(--rule);
570 position: relative;
571}
572.tp-header::before {
573 /* Grab-handle: visible on mobile only */
574 content: '';
575 position: absolute;
576 top: .35rem; left: 50%;
577 transform: translateX(-50%);
578 width: 38px; height: 4px;
579 background: var(--rule-2, var(--rule));
580 border-radius: 2px;
581}
582.tp-h2 {
583 margin: .35rem 0 0;
584 font-family: var(--font-display, serif);
585 font-size: 1.15rem; font-weight: 600;
586 color: var(--ink);
587 line-height: 1.1;
588}
589.tp-close {
590 width: 32px; height: 32px; border-radius: 8px;
591 display: inline-flex; align-items: center; justify-content: center;
592 background: transparent; border: 1px solid transparent;
593 color: var(--ink-muted, var(--ink-soft));
594 cursor: pointer;
595 transition: background var(--transition), color var(--transition), border-color var(--transition);
596 -webkit-tap-highlight-color: transparent;
597 margin-top: .35rem;
598}
599.tp-close:hover, .tp-close:focus-visible {
600 background: var(--paper-2);
601 color: var(--ink);
602 outline: none;
603}
604.tp-close svg { width: 18px; height: 18px; }
605
606/* Search row — sticky just below header so list scrolls underneath */
607.tp-search-row {
608 position: relative;
609 padding: .65rem 1rem;
610 border-bottom: 1px solid var(--rule);
611 background: var(--paper);
612}
613.tp-search-icon {
614 position: absolute;
615 top: 50%; left: 1.65rem;
616 transform: translateY(-50%);
617 color: var(--ink-muted, var(--ink-soft));
618 pointer-events: none;
619 display: inline-flex;
620}
621.tp-search-icon svg { width: 16px; height: 16px; }
622.tp-search {
623 width: 100%; box-sizing: border-box;
624 padding: .65rem .85rem .65rem 2.4rem;
625 font-family: var(--font-ui, system-ui), sans-serif;
626 font-size: 1rem;
627 background: var(--paper-2);
628 color: var(--ink);
629 border: 1px solid var(--rule);
630 border-radius: 9px;
631 -webkit-appearance: none;
632 appearance: none;
633}
634.tp-search:focus {
635 outline: none;
636 border-color: var(--accent);
637 box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
638}
639
640/* List — vertically scrollable, takes remaining sheet height */
641.tp-list {
642 flex: 1 1 auto;
643 overflow-y: auto;
644 -webkit-overflow-scrolling: touch;
645 padding: .35rem .35rem 1rem;
646}
647.tp-empty {
648 padding: 1.5rem 1rem;
649 text-align: center;
650 color: var(--ink-muted, var(--ink-soft));
651 font-size: .9rem;
652}
653
654/* Track row — tap target ≥ 56px for mobile */
655.tp-row {
656 display: grid;
657 grid-template-columns: 44px 1fr auto;
658 align-items: center;
659 gap: .75rem;
660 width: 100%;
661 padding: .55rem .65rem;
662 border: 0; background: transparent;
663 border-radius: 10px;
664 text-align: left;
665 cursor: pointer;
666 color: inherit;
667 font: inherit;
668 transition: background var(--transition);
669 -webkit-tap-highlight-color: transparent;
670}
671.tp-row:hover, .tp-row:focus-visible {
672 background: color-mix(in srgb, var(--accent) 8%, var(--paper-2));
673 outline: none;
674}
675.tp-row:active { transform: scale(.98); }
676.tp-row[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
677
678.tp-cover {
679 width: 44px; height: 44px;
680 border-radius: 6px;
681 background-size: cover; background-position: center;
682 background-color: var(--rule);
683 display: inline-flex; align-items: center; justify-content: center;
684 flex-shrink: 0;
685}
686.tp-cover-empty {
687 background: linear-gradient(135deg,
688 color-mix(in srgb, var(--accent) 30%, var(--paper-2)),
689 color-mix(in srgb, var(--accent) 8%, var(--paper-2)));
690 color: var(--accent);
691}
692.tp-cover-empty svg { width: 18px; height: 18px; opacity: .8; }
693
694.tp-meta {
695 display: flex; flex-direction: column;
696 min-width: 0;
697 line-height: 1.25;
698}
699.tp-row-title {
700 font-weight: 600; font-size: .94rem;
701 color: var(--ink);
702 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
703}
704.tp-row-artist {
705 font-size: .8rem;
706 color: var(--ink-muted, var(--ink-soft));
707 white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
708 margin-top: .1rem;
709}
710.tp-duration {
711 font-variant-numeric: tabular-nums;
712 font-size: .8rem;
713 color: var(--ink-muted, var(--ink-soft));
714 flex-shrink: 0;
715}
716
717/* Body lock when modal open */
718body.tp-locked { overflow: hidden; touch-action: none; }
719
720/* Desktop: centered card, max-width ~520px */
721@media (min-width: 640px) {
722 .tp-modal {
723 align-items: center;
724 padding: 1.5rem;
725 }
726 .tp-sheet {
727 margin-top: 0;
728 width: 100%;
729 max-width: 520px;
730 max-height: 80dvh;
731 border-radius: 14px;
732 border: 1px solid var(--rule);
733 animation: tp-sheet-pop .2s cubic-bezier(.2, .8, .25, 1);
734 }
735 .tp-header::before { display: none; } /* hide grab-handle on desktop */
736 .tp-header { padding: 1rem 1.25rem .75rem; }
737 .tp-h2 { margin-top: 0; font-size: 1.25rem; }
738 .tp-close { margin-top: 0; }
739 @keyframes tp-sheet-pop {
740 from { transform: translateY(-8px) scale(.97); opacity: 0; }
741 to { transform: translateY(0) scale(1); opacity: 1; }
742 }
743}
744
745/* ─── Buttons ───────────────────────────────────────────────────── */
746.pe-btn {
747 display: inline-flex; align-items: center; gap: 0.4rem;
748 padding: 0.55rem 1rem;
749 border: 1px solid var(--rule);
750 background: var(--paper-2);
751 color: var(--ink);
752 font-family: var(--font-ui, system-ui), sans-serif;
753 font-size: 0.9rem; font-weight: 500;
754 text-decoration: none;
755 border-radius: 6px;
756 cursor: pointer;
757 transition: background 120ms, border-color 120ms;
758 min-height: 40px;
759 -webkit-tap-highlight-color: transparent;
760}
761.pe-btn:hover { border-color: var(--accent); }
762.pe-btn:active { transform: scale(0.97); }
763.pe-btn-tiny {
764 padding: 0.35rem 0.7rem;
765 font-size: 0.85rem;
766 min-height: 32px;
767}
768.pe-btn-secondary { background: var(--paper-2); }
769.pe-btn-primary {
770 background: var(--accent); color: white;
771 border-color: var(--accent);
772}
773.pe-btn-primary:hover { opacity: 0.92; border-color: var(--accent); }
774.pe-btn-success {
775 background: #16a34a; color: white;
776 border-color: #16a34a;
777}
778.pe-btn-success:hover { opacity: 0.92; border-color: #16a34a; }
779
780.pe-status {
781 color: var(--ink-muted, var(--ink-soft));
782 font-size: 0.8rem;
783}
784.pe-status.is-error { color: #dc2626; }
785
786/* ─── Checkboxes (clean inline row) ─────────────────────────────── */
787.pe-checkboxes {
788 display: flex; flex-direction: column;
789 gap: 0.5rem;
790 padding-top: 0.25rem;
791}
792.pe-checkbox {
793 display: inline-flex; align-items: center; gap: 0.5rem;
794 cursor: pointer;
795 font-size: 0.95rem;
796 color: var(--ink);
797 user-select: none;
798}
799.pe-checkbox input[type="checkbox"] {
800 width: 18px; height: 18px;
801 margin: 0;
802 cursor: pointer;
803 accent-color: var(--accent);
804}
805
[edc462d]806/* Vastpinnen: checkbox + ▲▼-stepper met beschrijving (i.p.v. een ruw rang-getal). */
807.pe-pin { display: flex; flex-direction: column; gap: 0.45rem; }
808.pe-pin-pos { display: flex; align-items: center; gap: 0.55rem; padding-left: 1.65rem; }
809.pe-pin-pos[hidden] { display: none; }
810.pe-pin-steps { display: inline-flex; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; }
811.pe-pin-btn {
812 width: 30px; height: 28px; padding: 0;
813 border: none; background: var(--paper-2); color: var(--ink);
814 cursor: pointer; font-size: 0.68rem; line-height: 1;
815 display: inline-flex; align-items: center; justify-content: center;
[7bc636b]816}
[edc462d]817.pe-pin-btn + .pe-pin-btn { border-left: 1px solid var(--rule); }
818.pe-pin-btn:hover { background: color-mix(in srgb, var(--accent) 14%, var(--paper-2)); color: var(--accent); }
819.pe-pin-btn:disabled { opacity: 0.35; cursor: default; }
820.pe-pin-label { font-size: 0.85rem; color: var(--accent); font-weight: 600; }
[7bc636b]821
822/* ─── Sticky action footer ──────────────────────────────────────── */
823.pe-actions {
824 position: sticky;
825 bottom: 0;
826 display: flex; align-items: center;
827 gap: 0.5rem;
828 padding: 0.85rem 1rem;
829 margin: 0.5rem -1rem 0; /* extend to viewport edges on tight container */
830 background: color-mix(in srgb, var(--paper) 94%, transparent);
831 -webkit-backdrop-filter: blur(8px);
832 backdrop-filter: blur(8px);
833 border-top: 1px solid var(--rule);
834 z-index: 10;
835}
836.pe-actions-spacer { flex: 1; }
837
[2beef82]838/* De editor is een focus-scherm: verberg de mobiele site-tabbalk (Home/Zoek/…)
839 zodat er niet twee balken onderaan stapelen (Opslaan-balk + tabbalk). De
840 Opslaan/Annuleren-balk wordt dan de enige onderbalk → gewoon op bottom:0,
841 geen tab-offset meer nodig. Op desktop is de tabbalk toch al verborgen. */
842body:has(.post-edit-page) .bottom-tab { display: none; }
843/* Audiospeler (indien aan het spelen) niet meer 56px optillen voor de nu-verborgen
844 tabbalk, anders zou die zweven boven de actiebalk. */
845body:has(.post-edit-page) .audio-player { bottom: 0; }
[7bc636b]846</style>
847
848<script>
849(function() {
850
851 // ── Cover upload ────────────────────────────────────────────────
852 const coverField = document.getElementById('cover-upload-field');
853 const coverTrigger = document.getElementById('cover-upload-trigger');
854 const coverUrl = document.getElementById('cover-url-field');
855 const coverStatus = document.getElementById('cover-upload-status');
856 const coverWrap = document.getElementById('cover-preview-wrap');
857 const coverImg = document.getElementById('cover-preview-img');
858
859 async function uploadImage(file) {
860 const fd = new FormData();
861 fd.append('image', file);
862 const res = await fetch('/posts/upload-image', { method: 'POST', body: fd });
863 if (!res.ok) {
864 const j = await res.json().catch(() => ({}));
865 throw new Error(j.error || ('Upload failed (' + res.status + ')'));
866 }
867 return await res.json(); // {url, size, mime}
868 }
869
870 function showCoverPreview(url) {
871 if (!coverWrap || !coverImg) return;
872 if (url) {
873 coverImg.src = url;
874 coverImg.hidden = false;
875 coverWrap.removeAttribute('data-empty');
876 const emptyIcon = coverWrap.querySelector('.pe-cover-empty');
877 if (emptyIcon) emptyIcon.remove();
878 } else {
879 coverImg.hidden = true;
880 coverImg.src = '';
881 coverWrap.setAttribute('data-empty', '');
882 if (!coverWrap.querySelector('.pe-cover-empty')) {
883 const span = document.createElement('span');
884 span.className = 'pe-cover-empty';
885 span.textContent = '🖼';
886 coverWrap.appendChild(span);
887 }
888 }
889 }
890
891 if (coverTrigger && coverField) {
892 coverTrigger.addEventListener('click', () => coverField.click());
893 }
894 if (coverField) {
895 coverField.addEventListener('change', async () => {
896 if (!coverField.files[0]) return;
897 coverStatus.classList.remove('is-error');
898 coverStatus.textContent = 'Uploaden…';
899 try {
900 const j = await uploadImage(coverField.files[0]);
901 coverUrl.value = j.url;
902 showCoverPreview(j.url);
903 coverStatus.textContent = 'Geüpload ✓';
904 setTimeout(() => { coverStatus.textContent = ''; }, 2000);
905 } catch (e) {
906 coverStatus.classList.add('is-error');
907 coverStatus.textContent = 'Mislukt: ' + e.message;
908 }
909 });
910 }
911 // Live-update preview when user pastes a URL manually
912 if (coverUrl) {
913 coverUrl.addEventListener('input', () => {
914 const v = coverUrl.value.trim();
915 if (v) showCoverPreview(v); else showCoverPreview('');
916 });
917 }
918
919 // ── WYSIWYG editor (P58) ────────────────────────────────────────
920 // Architecture:
921 // - Visible <div contenteditable> (`#content-editor`) is what the user
922 // types in; it shows real HTML (formatted, not raw markup).
923 // - Hidden <input name="content"> (`#content-hidden`) is what submits.
924 // On submit we serialize the editor's HTML into it, with shortcode
925 // chips reduced back to their [[track:UUID]]/[[album:Name]]/[[playlist:slug]] text.
926 // - Initial content comes from a <script type="application/json"> tag
927 // to avoid HTML-escape-into-DOM issues; we set innerHTML once on load
928 // and walk text nodes to render shortcode tokens as chips.
929 const contentField = document.getElementById('content-upload-field');
930 const contentBtn = document.getElementById('insert-image-btn');
931 const contentStatus = document.getElementById('content-upload-status');
932 const editor = document.getElementById('content-editor');
933 const hiddenField = document.getElementById('content-hidden');
934 const charCountEl = document.getElementById('char-count');
935 const initialEl = document.getElementById('initial-content');
936 const toolbar = document.getElementById('pe-toolbar');
937 const form = editor && editor.closest('form');
938
939 if (!editor) return;
940
941 // ── Shortcode chip rendering / serialization ────────────────────
942 // Pattern matches [[track:UUID]] / [[album:any text]] / [[playlist:slug]]
943 // — but we DON'T want to chipify text the user is mid-typing inside an
944 // HTML attribute; since chipify only walks text nodes (never attribute
945 // values) that's already safe.
[1907a18]946 const SC_RE = /\[\[(track|album|playlist|embed):([^\]]+)\]\]/g;
[7bc636b]947
948 const SC_ICONS = {
949 track: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="6 4 20 12 6 20 6 4"/></svg>',
950 album: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><circle cx="12" cy="12" r="3"/></svg>',
951 playlist: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="8" y1="6" x2="21" y2="6"/><line x1="8" y1="12" x2="21" y2="12"/><line x1="8" y1="18" x2="15" y2="18"/><polygon points="3 5 3 13 9 9"/></svg>',
[1907a18]952 embed: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="20" height="16" rx="2"/><polygon points="10 9 15.5 12 10 15"/></svg>',
[7bc636b]953 };
954
955 function chipLabel(kind, value) {
956 if (kind === 'track') {
957 // UUIDs are noisy — show a 6-char prefix for visual hint
958 const v = String(value || '');
959 return 'Track ' + (v.length > 8 ? v.slice(0, 6) + '…' : v);
960 }
961 if (kind === 'album') return 'Album: ' + value;
962 if (kind === 'playlist') return 'Playlist: ' + value;
[1907a18]963 if (kind === 'embed') {
964 const clean = String(value || '').replace(/^https?:\/\/(www\.)?/, '');
965 return '▶ ' + (clean.length > 36 ? clean.slice(0, 34) + '…' : clean);
966 }
[7bc636b]967 return value;
968 }
969
970 function makeChip(kind, value) {
971 const span = document.createElement('span');
972 span.className = 'sc-chip';
973 span.contentEditable = 'false';
974 span.setAttribute('data-sc', kind + ':' + value);
975 span.innerHTML =
976 '<span class="sc-chip-icon" aria-hidden="true">' + (SC_ICONS[kind] || '') + '</span>' +
977 '<span class="sc-chip-label"></span>';
978 span.querySelector('.sc-chip-label').textContent = chipLabel(kind, value);
979 return span;
980 }
981
982 // Walk text nodes inside `root` and replace [[type:value]] tokens with chips.
983 function chipifyShortcodes(root) {
984 const walker = document.createTreeWalker(root, NodeFilter.SHOW_TEXT, null);
985 const targets = [];
986 while (walker.nextNode()) {
987 const n = walker.currentNode;
988 // Skip text inside existing chips (their .sc-chip-label is set via .textContent so the [[...]] text never appears)
989 if (n.parentElement && n.parentElement.closest('.sc-chip')) continue;
990 if (SC_RE.test(n.nodeValue)) targets.push(n);
991 SC_RE.lastIndex = 0;
992 }
993 for (const node of targets) {
994 const txt = node.nodeValue;
995 const frag = document.createDocumentFragment();
996 let last = 0;
997 let m;
998 SC_RE.lastIndex = 0;
999 while ((m = SC_RE.exec(txt)) !== null) {
1000 if (m.index > last) frag.appendChild(document.createTextNode(txt.slice(last, m.index)));
1001 frag.appendChild(makeChip(m[1], m[2].trim()));
1002 last = m.index + m[0].length;
1003 }
1004 if (last < txt.length) frag.appendChild(document.createTextNode(txt.slice(last)));
1005 node.parentNode.replaceChild(frag, node);
1006 }
1007 }
1008
1009 // Inverse of chipify: clone the editor, replace every chip with its text.
1010 function serializeChips(rootClone) {
1011 const chips = rootClone.querySelectorAll('.sc-chip[data-sc]');
1012 for (const c of chips) {
1013 const txt = '[[' + c.getAttribute('data-sc') + ']]';
1014 c.replaceWith(document.createTextNode(txt));
1015 }
1016 }
1017
1018 // ── Boot: load initial content as HTML, then render shortcodes as chips
1019 try {
1020 const initial = JSON.parse(initialEl.textContent || '""');
1021 editor.innerHTML = initial || '';
1022 chipifyShortcodes(editor);
1023 } catch (e) {
1024 console.error('[editor] could not parse initial content', e);
1025 editor.innerHTML = '';
1026 }
1027
1028 // ── Char counter
1029 function updateCharCount() {
1030 const text = (editor.innerText || '').replace(/\s+/g, ' ').trim();
1031 if (charCountEl) charCountEl.textContent = String(text.length);
1032 }
1033 updateCharCount();
1034 editor.addEventListener('input', updateCharCount);
1035
1036 // ── Toolbar wiring
1037 function execCmd(cmd, arg) {
1038 editor.focus();
1039 document.execCommand(cmd, false, arg);
1040 updateToolbarState();
1041 updateCharCount();
1042 }
1043 function wrapCode() {
1044 const sel = window.getSelection();
1045 if (!sel || sel.rangeCount === 0 || sel.isCollapsed) return;
1046 const range = sel.getRangeAt(0);
1047 const code = document.createElement('code');
1048 code.textContent = sel.toString();
1049 range.deleteContents();
1050 range.insertNode(code);
1051 // Move caret after the new node
1052 range.setStartAfter(code);
1053 range.collapse(true);
1054 sel.removeAllRanges();
1055 sel.addRange(range);
1056 editor.focus();
1057 }
1058 function linkPrompt() {
1059 const url = window.prompt('Link URL (https://… of /pad)');
1060 if (!url) return;
1061 execCmd('createLink', url);
1062 }
[91d948c]1063 // De huidige selectie zit in een <blockquote> binnen de editor? Geef 'm terug.
1064 function blockquoteAncestor() {
1065 const sel = window.getSelection();
1066 if (!sel || sel.rangeCount === 0) return null;
1067 let node = sel.anchorNode;
1068 while (node && node !== editor) {
1069 if (node.nodeType === 1 && node.tagName === 'BLOCKQUOTE') return node;
1070 node = node.parentNode;
1071 }
1072 return null;
1073 }
1074 // Echte toggle: execCommand('formatBlock','blockquote') zet 'm wél AAN maar
1075 // krijgt 'm nooit meer UIT (browser-quirk). Staat de caret al in een quote →
1076 // pak de wrapper uit; anders pas blockquote toe.
1077 function toggleBlockquote() {
1078 editor.focus();
1079 const bq = blockquoteAncestor();
1080 if (bq) {
1081 const parent = bq.parentNode;
1082 // Inhoud uit de quote halen, op z'n plek, en de lege wrapper verwijderen.
1083 const ref = bq;
1084 let firstMoved = null;
1085 while (bq.firstChild) {
1086 const child = bq.firstChild;
1087 if (!firstMoved) firstMoved = child;
1088 parent.insertBefore(child, ref);
1089 }
1090 parent.removeChild(bq);
1091 // Caret terugzetten in de uitgepakte inhoud.
1092 if (firstMoved) {
1093 const sel = window.getSelection();
1094 const range = document.createRange();
1095 range.selectNodeContents(firstMoved.nodeType === 1 ? firstMoved : parent);
1096 range.collapse(false);
1097 sel.removeAllRanges();
1098 sel.addRange(range);
1099 }
1100 } else {
1101 document.execCommand('formatBlock', false, 'blockquote');
1102 }
1103 updateToolbarState();
1104 updateCharCount();
1105 }
[7bc636b]1106
1107 if (toolbar) {
1108 toolbar.addEventListener('click', (e) => {
1109 const btn = e.target.closest('button[data-cmd]');
1110 if (!btn) return;
1111 e.preventDefault();
1112 const cmd = btn.dataset.cmd;
1113 const arg = btn.dataset.arg || null;
1114 if (cmd === 'link-prompt') linkPrompt();
1115 else if (cmd === 'code-wrap') wrapCode();
[91d948c]1116 else if (cmd === 'formatBlock' && arg === 'blockquote') toggleBlockquote();
[7bc636b]1117 else execCmd(cmd, arg);
1118 });
1119 }
1120
1121 // Reflect bold/italic/list state on the toolbar buttons
1122 function updateToolbarState() {
1123 if (!toolbar) return;
1124 const cmds = ['bold', 'italic', 'underline', 'insertUnorderedList', 'insertOrderedList'];
1125 for (const cmd of cmds) {
1126 const btn = toolbar.querySelector('button[data-cmd="' + cmd + '"]');
1127 if (!btn) continue;
1128 try { btn.classList.toggle('is-active', document.queryCommandState(cmd)); } catch(_) {}
1129 }
[91d948c]1130 // Quote-knop: actief als de caret in een <blockquote> staat (toggle-feedback).
1131 const bqBtn = toolbar.querySelector('button[data-cmd="formatBlock"][data-arg="blockquote"]');
1132 if (bqBtn) bqBtn.classList.toggle('is-active', !!blockquoteAncestor());
[7bc636b]1133 }
1134 document.addEventListener('selectionchange', () => {
1135 if (document.activeElement === editor) updateToolbarState();
1136 });
1137
1138 // Keyboard shortcuts: Ctrl/Cmd + B/I/U/K
1139 editor.addEventListener('keydown', (e) => {
1140 const mod = e.ctrlKey || e.metaKey;
1141 if (!mod) return;
1142 const k = e.key.toLowerCase();
1143 if (k === 'b') { e.preventDefault(); execCmd('bold'); }
1144 else if (k === 'i') { e.preventDefault(); execCmd('italic'); }
1145 else if (k === 'u') { e.preventDefault(); execCmd('underline'); }
1146 else if (k === 'k') { e.preventDefault(); linkPrompt(); }
1147 });
1148
1149 // Paste: keep it simple — strip formatting unless user wants it. Default
1150 // execCommand 'paste' includes Word/Google-Docs garbage. We accept inline
1151 // styles from clipboard only when shift is held — otherwise plain text.
1152 editor.addEventListener('paste', (e) => {
1153 if (e.shiftKey) return; // user wants formatted paste
1154 const text = (e.clipboardData || window.clipboardData).getData('text/plain');
1155 if (text == null) return;
1156 e.preventDefault();
1157 document.execCommand('insertText', false, text);
1158 });
1159
1160 // ── Image upload (button + drag-drop into the editor)
1161 async function uploadAndInsertImage(file) {
1162 contentStatus.classList.remove('is-error');
1163 contentStatus.textContent = 'Uploaden…';
1164 try {
1165 const j = await uploadImage(file);
1166 const img = '<img src="' + j.url + '" alt="">';
1167 editor.focus();
1168 document.execCommand('insertHTML', false, img);
1169 contentStatus.textContent = 'Ingevoegd ✓';
1170 setTimeout(() => { contentStatus.textContent = ''; }, 2000);
1171 updateCharCount();
1172 } catch (e) {
1173 contentStatus.classList.add('is-error');
1174 contentStatus.textContent = 'Mislukt: ' + e.message;
1175 }
1176 }
1177
1178 if (contentBtn && contentField) {
1179 contentBtn.addEventListener('click', () => contentField.click());
1180 contentField.addEventListener('change', () => {
1181 if (contentField.files[0]) uploadAndInsertImage(contentField.files[0]);
1182 contentField.value = '';
1183 });
1184
1185 editor.addEventListener('dragover', (e) => {
1186 if (e.dataTransfer && e.dataTransfer.types.includes('Files')) {
1187 e.preventDefault();
1188 editor.classList.add('is-dragover');
1189 }
1190 });
1191 editor.addEventListener('dragleave', () => editor.classList.remove('is-dragover'));
1192 editor.addEventListener('drop', async (e) => {
1193 editor.classList.remove('is-dragover');
1194 const files = e.dataTransfer && e.dataTransfer.files;
1195 if (!files || !files.length) return;
1196 e.preventDefault();
1197 for (const f of files) {
1198 if (f.type.startsWith('image/')) await uploadAndInsertImage(f);
1199 }
1200 });
1201 }
1202
1203 // ── Insert chip helpers (track / playlist)
1204 function insertChip(kind, value) {
1205 editor.focus();
1206 const chip = makeChip(kind, value);
1207 // Insert at caret using the Selection API (execCommand insertNode)
1208 const sel = window.getSelection();
1209 if (sel && sel.rangeCount > 0) {
1210 const range = sel.getRangeAt(0);
1211 range.deleteContents();
1212 range.insertNode(chip);
1213 // Insert a trailing space so the user can keep typing after the chip
1214 const space = document.createTextNode('\u00A0');
1215 chip.after(space);
1216 range.setStartAfter(space);
1217 range.collapse(true);
1218 sel.removeAllRanges();
1219 sel.addRange(range);
1220 } else {
1221 editor.appendChild(chip);
1222 editor.appendChild(document.createTextNode('\u00A0'));
1223 }
1224 updateCharCount();
1225 }
1226
[1907a18]1227 // ── Embed insert: plak een platform-URL -> [[embed:url]]-chip die server-side
1228 // een iframe wordt (YouTube/Spotify/SoundCloud/Vimeo/Apple Music/Bandcamp).
1229 const embedBtn = document.getElementById('insert-embed-btn');
1230 if (embedBtn) {
1231 embedBtn.addEventListener('click', () => {
1232 const raw = window.prompt('Plak een media-URL om in te sluiten\n(YouTube, Spotify, SoundCloud, Vimeo, Apple Music, Bandcamp):');
1233 if (!raw) return;
1234 const url = raw.trim();
1235 if (!/^https?:\/\//i.test(url)) { alert('Geef een volledige URL (https://…).'); return; }
1236 insertChip('embed', url);
1237 });
1238 }
1239
[7bc636b]1240 // ── Track insert: opens the track-picker modal (P59)
1241 const trackBtn = document.getElementById('insert-track-btn');
1242 const trackPicker = document.getElementById('track-picker');
1243 if (trackBtn && trackPicker) {
1244 const tpList = document.getElementById('tp-list');
1245 const tpEmpty = document.getElementById('tp-empty');
1246 const tpSearch = document.getElementById('tp-search');
1247 let tpCache = null; // cached tracks list (fetched once per page load)
1248 let tpLastFocus = null; // element to restore focus to on close
1249
1250 const SVG_NOTE = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9 17V5l12-2v12"/><circle cx="6" cy="17" r="3"/><circle cx="18" cy="15" r="3"/></svg>';
1251
1252 function fmtDur(sec) {
1253 sec = Math.max(0, Math.floor(sec || 0));
1254 const m = Math.floor(sec / 60), s = sec % 60;
1255 return m + ':' + String(s).padStart(2, '0');
1256 }
1257 function escAttr(s) {
1258 return String(s == null ? '' : s).replace(/[&<>"']/g, c => ({
1259 '&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'
1260 }[c]));
1261 }
1262
1263 function renderList(filter) {
1264 if (!Array.isArray(tpCache)) return;
1265 const q = (filter || '').trim().toLowerCase();
1266 const filtered = q
1267 ? tpCache.filter(t =>
1268 (t.title || '').toLowerCase().includes(q) ||
1269 (t.artist || '').toLowerCase().includes(q))
1270 : tpCache;
1271
1272 if (!filtered.length) {
1273 tpList.innerHTML = '';
1274 tpEmpty.textContent = q ? 'Geen tracks gevonden voor "' + q + '"' : 'Nog geen tracks. Upload via Beheer → Audio.';
1275 tpList.appendChild(tpEmpty);
1276 return;
1277 }
1278
1279 tpList.innerHTML = filtered.map(t => {
1280 const cov = t.cover
1281 ? '<span class="tp-cover" style="background-image:url(\'' + escAttr(t.cover) + '\')"></span>'
1282 : '<span class="tp-cover tp-cover-empty">' + SVG_NOTE + '</span>';
1283 const dis = t.playable ? '' : ' aria-disabled="true"';
1284 const sub = t.artist ? '<span class="tp-row-artist">' + escAttr(t.artist) + '</span>' : '';
1285 return (
1286 '<button type="button" class="tp-row" role="option" data-track-id="' + escAttr(t.id) + '"' + dis + '>' +
1287 cov +
1288 '<span class="tp-meta">' +
1289 '<span class="tp-row-title">' + escAttr(t.title) + '</span>' +
1290 sub +
1291 '</span>' +
1292 '<span class="tp-duration">' + fmtDur(t.duration) + '</span>' +
1293 '</button>'
1294 );
1295 }).join('');
1296 }
1297
1298 async function loadTracks() {
1299 if (Array.isArray(tpCache)) return tpCache;
1300 tpEmpty.textContent = 'Tracks laden…';
1301 try {
1302 const r = await fetch('/admin/playlists/api/tracks', { credentials: 'same-origin' });
1303 const j = await r.json();
1304 tpCache = (j && j.ok && Array.isArray(j.tracks)) ? j.tracks : [];
1305 } catch (e) {
1306 tpCache = [];
1307 tpEmpty.textContent = 'Kon tracks niet laden: ' + e.message;
1308 }
1309 return tpCache;
1310 }
1311
1312 function openPicker() {
1313 tpLastFocus = document.activeElement;
1314 trackPicker.hidden = false;
1315 trackPicker.setAttribute('aria-hidden', 'false');
1316 document.body.classList.add('tp-locked');
1317 tpSearch.value = '';
1318 renderList('');
1319 // Defer focus so the open animation doesn't get jumped
1320 setTimeout(() => tpSearch.focus(), 30);
1321 }
1322 function closePicker() {
1323 trackPicker.hidden = true;
1324 trackPicker.setAttribute('aria-hidden', 'true');
1325 document.body.classList.remove('tp-locked');
1326 if (tpLastFocus && typeof tpLastFocus.focus === 'function') {
1327 try { tpLastFocus.focus(); } catch(_) {}
1328 }
1329 }
1330
1331 trackBtn.addEventListener('click', async () => {
1332 openPicker();
1333 await loadTracks();
1334 renderList(tpSearch.value);
1335 });
1336
1337 // Close: backdrop click, [data-tp-close], or Escape
1338 trackPicker.addEventListener('click', (e) => {
1339 if (e.target.closest('[data-tp-close]')) {
1340 closePicker();
1341 return;
1342 }
1343 const row = e.target.closest('.tp-row[data-track-id]');
1344 if (row) {
1345 if (row.getAttribute('aria-disabled') === 'true') return;
1346 const id = row.dataset.trackId;
1347 if (id) {
1348 insertChip('track', id);
1349 closePicker();
1350 }
1351 }
1352 });
1353 document.addEventListener('keydown', (e) => {
1354 if (!trackPicker.hidden && e.key === 'Escape') {
1355 e.preventDefault();
1356 closePicker();
1357 }
1358 });
1359
1360 // Live filter
1361 tpSearch.addEventListener('input', () => renderList(tpSearch.value));
1362 }
1363
1364 // ── Playlist insert (open existing or create new via modal)
1365 const playlistBtn = document.getElementById('insert-playlist-btn');
1366 if (playlistBtn) {
1367 playlistBtn.addEventListener('click', async () => {
1368 if (typeof window.openPlaylistEditor !== 'function') {
1369 alert('Playlist editor niet geladen');
1370 return;
1371 }
1372 try {
1373 const r = await fetch('/admin/playlists/api/list', { credentials: 'same-origin' });
1374 const j = await r.json();
1375 if (j.ok && Array.isArray(j.playlists) && j.playlists.length > 0) {
1376 const choice = prompt(
1377 'Bestaande playlists:\n\n' +
1378 j.playlists.map((p, i) => `${i + 1}. ${p.title} (${p.track_count} tracks)`).join('\n') +
1379 '\n\nKies een nummer om in te voegen, leeg = nieuwe maken:'
1380 );
1381 if (choice && /^\d+$/.test(choice.trim())) {
1382 const idx = parseInt(choice.trim(), 10) - 1;
1383 if (idx >= 0 && idx < j.playlists.length) {
1384 insertChip('playlist', j.playlists[idx].id);
1385 return;
1386 }
1387 }
1388 if (choice === null) return;
1389 }
1390 } catch (_) { /* fall through to create */ }
1391
1392 window.openPlaylistEditor({
1393 mode: 'create',
1394 onSaved: ({ id }) => insertChip('playlist', id),
1395 });
1396 });
1397 }
1398
1399 // ── Submit: serialize editor contents into the hidden field
1400 if (form && hiddenField) {
1401 form.addEventListener('submit', () => {
1402 const clone = editor.cloneNode(true);
1403 serializeChips(clone);
1404 hiddenField.value = clone.innerHTML;
1405 });
1406 }
1407})();
1408</script>
1409
1410<%# ── Track picker modal (P59). Mobile-first: full-screen sheet on small
1411 viewports, centered modal on ≥640px. Populated lazily on first open. %>
1412<% if (typeof user !== 'undefined' && user) { %>
1413<div id="track-picker" class="tp-modal" hidden aria-hidden="true">
1414 <div class="tp-backdrop" data-tp-close></div>
1415 <div class="tp-sheet" role="dialog" aria-modal="true" aria-labelledby="tp-title">
1416 <header class="tp-header">
1417 <h2 id="tp-title" class="tp-h2">Track invoegen</h2>
1418 <button type="button" class="tp-close" data-tp-close aria-label="Sluiten">
1419 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
1420 </button>
1421 </header>
1422 <div class="tp-search-row">
1423 <span class="tp-search-icon" aria-hidden="true">
1424 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="7"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
1425 </span>
1426 <input type="search" class="tp-search" id="tp-search" placeholder="Zoek op titel of artiest…" autocomplete="off" inputmode="search">
1427 </div>
1428 <div class="tp-list" id="tp-list" role="listbox" aria-label="Tracks">
1429 <div class="tp-empty" id="tp-empty">Tracks laden…</div>
1430 </div>
1431 </div>
1432</div>
1433<% } %>
1434
1435<%# Playlist editor modal — included so its global window.openPlaylistEditor
1436 is available when the toolbar button fires. Only renders if user can post. %>
1437<% if (typeof user !== 'undefined' && user) { %>
1438 <%- include('../partials/playlist-editor', { csrfToken: (typeof csrfToken !== 'undefined' ? csrfToken : '') }) %>
1439<% } %>
[edc462d]1440
1441<script>
1442(function () {
1443 // Vastpinnen: checkbox toggelt het verborgen rang-veld (0 = niet gepind),
1444 // ▲▼ verschuift de plek, met een leesbare beschrijving i.p.v. een ruw getal.
1445 var toggle = document.getElementById('pin-toggle');
1446 var rank = document.getElementById('pin-rank');
1447 var pos = document.getElementById('pin-pos');
1448 var label = document.getElementById('pin-label');
1449 var up = document.getElementById('pin-up'); // hoger = lager getal (richting 1/bovenaan)
1450 var down = document.getElementById('pin-down');
1451 if (!toggle || !rank || !pos) return;
1452
1453 function descr(n) {
1454 n = Number(n) || 0;
1455 if (n <= 1) return 'bovenaan';
1456 return n + 'e van boven';
1457 }
1458 function render() {
1459 var on = toggle.checked;
1460 pos.hidden = !on;
1461 if (on && Number(rank.value) < 1) rank.value = 1;
1462 if (!on) rank.value = 0;
1463 if (label) label.textContent = on ? descr(rank.value) : '';
1464 if (up) up.disabled = Number(rank.value) <= 1;
1465 }
1466 toggle.addEventListener('change', render);
1467 if (up) up.addEventListener('click', function () { rank.value = Math.max(1, (Number(rank.value) || 1) - 1); render(); });
1468 if (down) down.addEventListener('click', function () { rank.value = (Number(rank.value) || 0) + 1; render(); });
1469 render();
1470})();
[d3e2987]1471
1472(function () {
1473 // De Opslaan/Annuleren-balk boven de audiospeler houden als er iets speelt
1474 // (anders dekt de fixed speler, z-index 1000, de sticky balk af). De echte
1475 // speler-hoogte wordt gelezen, dus het klopt op elk formaat (de speler krimpt
1476 // op smalle schermen). Geen speler → balk gewoon op bottom:0 (CSS).
1477 var bar = document.querySelector('.pe-actions');
1478 if (!bar) return;
1479 function fit() {
1480 var ap = document.querySelector('.audio-player');
1481 var playing = document.body.classList.contains('has-audio-player') &&
1482 ap && getComputedStyle(ap).display !== 'none';
1483 bar.style.bottom = playing ? Math.round(ap.getBoundingClientRect().height) + 'px' : '';
1484 }
1485 fit();
1486 window.addEventListener('resize', fit);
1487 // De speler verschijnt/verdwijnt via een body-class → daarop reageren.
1488 try { new MutationObserver(fit).observe(document.body, { attributes: true, attributeFilter: ['class'] }); } catch (_) {}
1489})();
[edc462d]1490</script>
Note: See TracBrowser for help on using the repository browser.