@desplega.ai/slack-mock 0.3.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -70,7 +70,7 @@ a:hover{text-decoration:underline}
70
70
  .sm-side a:hover{background:#522653;color:#fff;text-decoration:none}
71
71
  .sm-side a.sm-active,.sm-side a.sm-active:hover{background:#1164a3;color:#fff}
72
72
  .sm-side-title a:hover{background:none;text-decoration:underline}
73
- .sm-main{flex:1;min-width:280px;display:flex;flex-direction:column;overflow:hidden}
73
+ .sm-main{flex:1;min-width:0;display:flex;flex-direction:column;overflow:hidden}
74
74
  .sm-shot{width:760px;padding:16px;background:#fff}
75
75
  .sm-top{border-bottom:1px solid #e8e8e8;padding:12px 20px;display:flex;align-items:baseline;gap:12px;flex:none}
76
76
  .sm-top h1{font-size:18px;font-weight:900;margin:0}
@@ -101,8 +101,6 @@ a:hover{text-decoration:underline}
101
101
  .sm-composer-box{border:1px solid #bbb;border-radius:8px;padding:8px 10px;background:#fff}
102
102
  .sm-composer-box:focus-within{border-color:#1264a3;box-shadow:0 0 0 1px #1264a3}
103
103
  .sm-composer-row{display:flex;align-items:center;gap:8px;margin-top:6px}
104
- .sm-composer-user{flex:0 1 auto;min-width:0;max-width:170px;border:0;border-radius:4px;background:#f0f0f0;color:#1d1c1d;font-family:inherit;font-size:12px;padding:4px 6px}
105
- .sm-composer-user:hover{background:#e8e8e8}
106
104
  .sm-composer-text{display:block;width:100%;border:0;outline:none;resize:vertical;font-family:inherit;font-size:15px;line-height:20px;color:#1d1c1d;padding:0;background:none}
107
105
  .sm-composer-send{flex:none;margin-left:auto;border:0;border-radius:4px;background:#007a5a;color:#fff;font-family:inherit;font-weight:700;font-size:13px;padding:6px 14px;cursor:pointer}
108
106
  .sm-composer-send:hover{background:#148567;color:#fff}
@@ -116,25 +114,30 @@ a:hover{text-decoration:underline}
116
114
  .sm-mention-name{font-weight:700}
117
115
  .sm-mention-real{color:#616061;font-size:13px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
118
116
 
119
- .sm-side a,.sm-btn,.sm-select,.sm-reaction,.sm-file-card,.sm-prompt,.sm-replies,.sm-back,.sm-panel-close,.sm-panel-expand,.sm-composer-send,.sm-composer-user,.sm-top-actions a{cursor:pointer}
117
+ .sm-side a,.sm-btn,.sm-select,.sm-reaction,.sm-file-card,.sm-prompt,.sm-replies,.sm-back,.sm-panel-close,.sm-panel-expand,.sm-composer-send,.sm-top-actions a{cursor:pointer}
120
118
  .sm-composer-text{cursor:text}
121
119
  .sm-badge,.sm-time,.sm-daydiv,.sm-pill,.sm-emoji-name,.sm-avatar,.sm-name,.sm-composer-hint,.sm-unsupported,.sm-tag,.sm-card{cursor:default}
122
- .sm-top-actions{margin-left:auto;display:flex;gap:12px;align-items:baseline;flex:none}
120
+ .sm-top-actions{margin-left:auto;display:flex;gap:12px;align-items:center;flex:none}
123
121
  .sm-top-actions a{font-size:13px;font-weight:700;color:#616061}
124
122
  .sm-top-actions a:hover{color:#1264a3}
125
- @media (max-width:900px){
126
- .sm-side{display:none}
127
- .sm-app-thread .sm-main{display:none}
128
- .sm-panel{width:100%;min-width:0;border-left:0}
129
- .sm-panel-back{display:block}
130
- .sm-panel-expand,.sm-resize{display:none}
131
- }
123
+ .sm-identity{position:relative}
124
+ .sm-identity[hidden]{display:none}
125
+ .sm-identity summary{display:flex;align-items:center;gap:6px;list-style:none;border:1px solid #ddd;border-radius:16px;padding:2px 8px 2px 3px;font-size:13px;font-weight:700;cursor:pointer}
126
+ .sm-identity summary::-webkit-details-marker{display:none}
127
+ .sm-identity summary:hover{background:#f8f8f8}
128
+ .sm-identity-avatar{width:24px;height:24px;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;color:#fff;font-size:10px;font-weight:700;flex:none}
129
+ .sm-identity-list{position:absolute;right:0;top:100%;z-index:10;width:max-content;min-width:190px;max-width:280px;margin:6px 0 0;padding:4px;list-style:none;background:#fff;border:1px solid #ddd;border-radius:8px;box-shadow:0 4px 16px rgba(0,0,0,.16)}
130
+ .sm-identity-list button{display:flex;align-items:center;gap:8px;width:100%;border:0;border-radius:4px;padding:6px;background:#fff;color:#1d1c1d;font:inherit;text-align:left;cursor:pointer}
131
+ .sm-identity-list button:hover,.sm-identity-list button:focus{background:#f0f0f0;outline:none}
132
+ .sm-identity-user{font-size:12px;color:#616061;margin-left:auto}
133
+ .sm-user-status{margin-left:6px;font-size:12px;font-weight:400;color:#616061}
134
+ .sm-mobile-bar{display:none}
132
135
 
133
136
  .sm-daydiv{display:flex;align-items:center;gap:10px;margin:14px 0 8px}
134
137
  .sm-daydiv:before,.sm-daydiv:after{content:"";flex:1;height:1px;background:#e8e8e8}
135
138
  .sm-daydiv span{border:1px solid #e8e8e8;border-radius:12px;padding:2px 12px;font-size:13px;font-weight:700;color:#454245;background:#fff}
136
139
 
137
- .sm-msg{display:flex;gap:12px;padding:8px 8px;border-radius:6px}
140
+ .sm-msg{position:relative;display:flex;gap:12px;padding:8px 8px;border-radius:6px}
138
141
  .sm-msg:hover{background:#f8f8f8}
139
142
  .sm-msg-eph{background:#fffbe6}
140
143
  .sm-msg-eph:hover{background:#fff7d1}
@@ -157,7 +160,7 @@ a:hover{text-decoration:underline}
157
160
  .sm-msg-new{animation:sm-flash 2.4s ease-out}
158
161
  .sm-msg-changed{animation:sm-flash-soft .9s ease-out}
159
162
  @media (prefers-reduced-motion:reduce){.sm-msg-new,.sm-msg-changed{animation:none}}
160
- .sm-live{font-size:11px;font-weight:600;color:#2eb67d;margin-left:10px;vertical-align:middle}
163
+ .sm-live{font-size:11px;font-weight:600;color:#2eb67d;margin-left:10px;vertical-align:middle;white-space:nowrap}
161
164
  .sm-live-off{color:#e8912d}
162
165
  .sm-composer-lock{display:flex;align-items:center;gap:8px;flex-wrap:wrap;padding:8px 0 2px;font-size:13px;color:#616061}
163
166
  .sm-composer-lock[hidden]{display:none}
@@ -236,7 +239,24 @@ a:hover{text-decoration:underline}
236
239
  .sm-reactions{display:flex;flex-wrap:wrap;gap:6px;margin-top:6px}
237
240
  .sm-reaction{display:inline-flex;align-items:center;gap:5px;background:#f0f0f0;border:1px solid #f0f0f0;border-radius:12px;padding:1px 8px;font-size:12px;line-height:18px;color:#454245}
238
241
  .sm-reaction:hover{background:#e8f5fa;border-color:#1264a3;color:#1d1c1d}
242
+ .sm-reaction[aria-pressed="true"]{background:#e8f5fa;border-color:#1264a3;color:#1264a3}
243
+ .sm-reaction:disabled{cursor:default}
239
244
  .sm-reaction-count{font-weight:700;font-size:12px}
245
+ .sm-message-actions{position:absolute;right:8px;top:-8px;display:flex;gap:2px;padding:3px;background:#fff;border:1px solid #ddd;border-radius:6px;box-shadow:0 1px 4px #0001;opacity:0;z-index:2}
246
+ .sm-msg:hover .sm-message-actions,.sm-msg:focus-within .sm-message-actions{opacity:1}
247
+ .sm-message-actions button,.sm-message-actions a{display:inline-flex;align-items:center;justify-content:center;width:32px;min-height:32px;padding:4px;border:0;border-radius:4px;background:#fff;color:#616061;font:inherit;font-size:12px;cursor:pointer;text-decoration:none}
248
+ .sm-message-actions button:hover,.sm-message-actions a:hover{background:#f0f0f0;color:#1d1c1d}
249
+ .sm-message-actions button:disabled{opacity:.5;cursor:default}
250
+ .sm-message-actions svg{width:18px;height:18px;flex:none}
251
+ .sm-action-error{font-size:13px;color:#a12622;margin-top:6px}
252
+ .sm-reaction-picker{position:fixed;inset:auto;top:0;left:0;margin:0;z-index:100;width:300px;max-width:calc(100vw - 24px);max-height:calc(var(--sm-viewport-height,100dvh) - 24px);padding:16px;border:1px solid #ddd;border-radius:12px;color:#1d1c1d;box-shadow:0 8px 32px #0003}
253
+ .sm-reaction-picker-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:12px}
254
+ .sm-reaction-picker h2{font-size:16px;margin:0}
255
+ .sm-reaction-picker button{min-width:40px;min-height:40px;border:0;border-radius:6px;background:#fff;font:inherit;cursor:pointer}
256
+ .sm-reaction-picker button:hover,.sm-reaction-picker button:focus-visible{background:#f0f0f0}
257
+ .sm-reaction-picker button:disabled{opacity:.5;cursor:default}
258
+ .sm-reaction-choices{display:grid;grid-template-columns:repeat(4,1fr);gap:6px}
259
+ .sm-reaction-choices button{font-size:24px}
240
260
  .sm-file-card:hover{background:#f8f8f8}
241
261
 
242
262
  .sm-replies{display:inline-flex;align-items:center;gap:8px;margin-top:4px;font-size:13px;font-weight:700;color:#1264a3}
@@ -261,6 +281,79 @@ a:hover{text-decoration:underline}
261
281
  .sm-table td{padding:6px 10px 6px 0;border-bottom:1px solid #f2f2f2;vertical-align:top}
262
282
  .sm-tag{display:inline-block;background:#f0f0f0;color:#454245;border-radius:10px;padding:0 8px;font-size:11px;font-weight:700}
263
283
  .sm-muted{color:#616061}
284
+
285
+ @media (min-width:700px) and (max-width:1000px){
286
+ .sm-side{width:180px}
287
+ .sm-panel{min-width:300px;max-width:calc(100% - 360px)}
288
+ .sm-top{padding:8px 12px;gap:6px;align-items:center;flex-wrap:wrap}
289
+ .sm-top h1{min-width:0;overflow-wrap:anywhere}
290
+ .sm-top .sm-sub{display:none}
291
+ .sm-top-actions{min-width:0;max-width:100%;flex-shrink:1}
292
+ .sm-identity{min-width:0;max-width:100%}
293
+ .sm-identity-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
294
+ .sm-replies{flex-wrap:wrap}
295
+ .sm-att-img,.sm-file-img,.sm-video-thumb,.sm-file-card{max-width:100%}
296
+ }
297
+ @media (max-width:699px),(hover:none),(pointer:coarse){
298
+ .sm-message-actions{position:static;opacity:1;justify-content:flex-start;gap:6px;margin-top:6px;padding:0;border:0;box-shadow:none;background:none}
299
+ .sm-message-actions button,.sm-message-actions a{width:40px;min-height:40px;background:none}
300
+ }
301
+ @media (max-width:699px){
302
+ html,body{overflow:hidden;overscroll-behavior:none}
303
+ body{overflow-wrap:anywhere}
304
+ .sm-app{position:fixed;top:var(--sm-viewport-top,0px);left:0;width:100%;height:100dvh;height:var(--sm-viewport-height,100dvh);flex-direction:column}
305
+ .sm-side,.sm-resize{display:none}
306
+ .sm-mobile-bar{display:block;flex:none;background:#3f0e40;color:#fff;padding:calc(8px + env(safe-area-inset-top)) 12px 8px;z-index:10}
307
+ .sm-mobile-heading{display:flex;align-items:center;justify-content:space-between;gap:12px;min-width:0}
308
+ .sm-mobile-workspace{display:flex;align-items:center;min-height:40px;min-width:0;color:#fff;font-size:17px;font-weight:900}
309
+ .sm-mobile-bar .sm-identity{flex:none;max-width:55%;color:#1d1c1d}
310
+ .sm-identity summary{min-height:40px;background:#fff;border-radius:20px}
311
+ .sm-identity-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
312
+ .sm-identity-list{width:280px;max-width:calc(100vw - 24px);max-height:calc(var(--sm-viewport-height,100dvh) - 120px);overflow-y:auto}
313
+ .sm-identity-list button{min-height:40px}
314
+ .sm-identity-list button>span{min-width:0;overflow-wrap:anywhere}
315
+ .sm-identity-user{white-space:normal}
316
+ .sm-channel-switch{display:block;width:100%;min-height:40px;margin-top:6px;padding:6px 10px;border:1px solid #79547a;border-radius:5px;background:#522653;color:#fff;font:inherit;font-size:16px}
317
+ .sm-main{min-height:0}
318
+ .sm-app-thread .sm-main{display:none}
319
+ .sm-panel{width:100%;min-width:0;min-height:0;flex:1;border-left:0}
320
+ .sm-top{padding:6px 12px;align-items:center;gap:10px;flex-wrap:wrap}
321
+ .sm-top h1{font-size:16px;min-width:0}
322
+ .sm-top .sm-sub,.sm-top .sm-identity,.sm-live{display:none}
323
+ .sm-panel-top{padding:6px 12px;align-items:center}
324
+ .sm-panel-back{display:inline-flex;align-items:center;justify-content:center;width:40px;min-height:40px;padding:0;border:0;font-size:22px}
325
+ .sm-panel-close,.sm-panel-expand{display:none}
326
+ .sm-main .sm-page,.sm-panel-body{min-height:0;padding:8px 12px 20px;overscroll-behavior:contain}
327
+ .sm-msg{padding:8px 0;gap:10px}
328
+ .sm-msg-body,.sm-card-v,.sm-field,.sm-att,.sm-context,.sm-file-card{overflow-wrap:anywhere}
329
+ .sm-text,.sm-blocks,.sm-field,.sm-att-text,.sm-att-pretext{font-size:16px;line-height:24px}
330
+ .sm-name{font-size:14px}
331
+ .sm-time{font-size:12px}
332
+ .sm-composer,.sm-panel .sm-composer{padding:8px 12px calc(10px + env(safe-area-inset-bottom))}
333
+ .sm-composer-text{font-size:16px;line-height:22px;resize:none;max-height:30vh}
334
+ .sm-composer-lock input{font-size:16px;min-height:40px;flex:1;min-width:0}
335
+ .sm-composer-lock>span:first-child{width:100%}
336
+ .sm-mentions,.sm-panel .sm-mentions{left:12px;right:12px;max-height:min(260px,40vh)}
337
+ .sm-mention{min-height:40px}
338
+ .sm-btn,.sm-select,.sm-reaction,.sm-prompt,.sm-replies,.sm-back,.sm-icon-btn,.sm-composer-send,.sm-composer-lock .sm-lock-go,.sm-lock-out{min-height:40px;display:inline-flex;align-items:center}
339
+ .sm-btn,.sm-select{max-width:100%;white-space:normal}
340
+ .sm-replies{flex-wrap:wrap;gap:4px 8px}
341
+ .sm-section-split{flex-wrap:wrap}
342
+ .sm-section-main{flex-basis:100%}
343
+ .sm-section-acc,.sm-context>*{min-width:0;max-width:100%}
344
+ .sm-att-img,.sm-file-img,.sm-video-thumb{max-width:100%;height:auto}
345
+ .sm-file-card,.sm-unsupported{max-width:100%}
346
+ .sm-file-card>div:last-child{min-width:0}
347
+ .sm-cards{gap:10px}
348
+ .sm-card{flex:1 1 calc(50% - 5px);min-width:0}
349
+ .sm-table,.sm-table tbody{display:block;width:100%}
350
+ .sm-table tr{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px 14px;padding:12px 0;border-bottom:1px solid #e8e8e8}
351
+ .sm-table tr:first-child{display:none}
352
+ .sm-table td{display:block;padding:0;border:0;overflow-wrap:anywhere}
353
+ .sm-table td:before{content:attr(data-label);display:block;font-size:11px;color:#616061;text-transform:uppercase;letter-spacing:.4px}
354
+ .sm-table td a{display:inline-flex;align-items:center;min-height:40px}
355
+ .sm-shot{width:100%;padding:12px}
356
+ }
264
357
  `;
265
358
 
266
359
  function ctxOf(store: Store): RenderContext {
@@ -399,7 +492,12 @@ function avatarHtml(m: SlackMessage, name: string): string {
399
492
  return `<div class="sm-avatar" style="background:${color}">${escapeHtml(initials(name))}</div>`;
400
493
  }
401
494
 
402
- function reactionsHtml(store: Store, m: SlackMessage): string {
495
+ function reactionsHtml(
496
+ store: Store,
497
+ m: SlackMessage,
498
+ interactive: boolean,
499
+ locked: boolean,
500
+ ): string {
403
501
  if (!m.reactions?.length) return "";
404
502
  const chips = m.reactions.map((r) => {
405
503
  const who = r.users
@@ -409,11 +507,45 @@ function reactionsHtml(store: Store, m: SlackMessage): string {
409
507
  })
410
508
  .join(", ");
411
509
  const char = emojiChar(r.name) ?? `:${r.name}:`;
412
- return `<span class="sm-reaction" title="${escapeHtml(who)}">${escapeHtml(char)}<span class="sm-reaction-count">${r.count}</span></span>`;
510
+ const content = `${escapeHtml(char)}<span class="sm-reaction-count">${r.count}</span>`;
511
+ return interactive
512
+ ? `<button type="button" class="sm-reaction" title="${escapeHtml(who)}" data-reaction="${escapeHtml(r.name)}" data-users="${escapeHtml(JSON.stringify(r.users))}" aria-label="Add :${escapeHtml(r.name)}: reaction, ${r.count} ${r.count === 1 ? "person" : "people"} reacted" aria-pressed="false"${locked ? " disabled" : ""}>${content}</button>`
513
+ : `<span class="sm-reaction" title="${escapeHtml(who)}">${content}</span>`;
413
514
  });
414
515
  return `<div class="sm-reactions">${chips.join("")}</div>`;
415
516
  }
416
517
 
518
+ function messageActions(m: SlackMessage, opts: RenderOptions): string {
519
+ const thread = m.thread_ts ?? m.ts;
520
+ const reactIcon = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" aria-hidden="true"><circle cx="11" cy="12" r="8"/><path d="M7 14c2 3 6 3 8 0M8 9h.01M14 9h.01M20 2v6M17 5h6" stroke-linecap="round"/></svg>`;
521
+ const replyIcon = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" aria-hidden="true"><path d="M5 4h14a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H9l-6 4V6a2 2 0 0 1 2-2Z" stroke-linejoin="round"/><path d="M7 9h10M7 13h6" stroke-linecap="round"/></svg>`;
522
+ return `<div class="sm-message-actions"><button type="button" class="sm-add-reaction" aria-label="Add reaction" aria-haspopup="dialog" aria-controls="sm-reaction-picker" title="Add reaction"${opts.writeGated ? " disabled" : ""}>${reactIcon}</button><a class="sm-reply-action" href="${threadHref(m.channel, thread, opts)}" data-thread="${escapeHtml(thread)}" aria-label="Open thread" title="Open thread">${replyIcon}</a></div><div class="sm-action-error" role="alert" hidden></div>`;
523
+ }
524
+
525
+ function reactionPicker(): string {
526
+ const names = [
527
+ "thumbsup",
528
+ "green_heart",
529
+ "eyes",
530
+ "white_check_mark",
531
+ "tada",
532
+ "rocket",
533
+ "star",
534
+ "thinking_face",
535
+ "sparkles",
536
+ "fire",
537
+ "raised_hands",
538
+ "clap",
539
+ ];
540
+ const buttons = names
541
+ .map(
542
+ (name) =>
543
+ `<button type="button" data-reaction="${name}" aria-label="React with ${name.replaceAll("_", " ")}" title=":${name}:">${escapeHtml(emojiChar(name) ?? `:${name}:`)}</button>`,
544
+ )
545
+ .join("");
546
+ return `<dialog class="sm-reaction-picker" id="sm-reaction-picker" aria-labelledby="sm-reaction-title"><div class="sm-reaction-picker-head"><h2 id="sm-reaction-title">Add a reaction</h2><button type="button" class="sm-reaction-close" aria-label="Close reactions">✕</button></div><div class="sm-reaction-choices">${buttons}</div><div class="sm-action-error" role="alert" hidden></div></dialog>`;
547
+ }
548
+
417
549
  /** The mock serves url_private behind a token, so browser requests carry it in the query. */
418
550
  function fileUrl(f: SlackFile, token: string): string {
419
551
  if (!f.url_private) return "";
@@ -454,6 +586,7 @@ function renderMessage(
454
586
  const name = authorName(store, m);
455
587
  const isApp = Boolean(m.bot_id);
456
588
  const blocks = Array.isArray(m.blocks) && m.blocks.length ? m.blocks : undefined;
589
+ const interactive = !opts.screenshot && !flags.ephemeral && humanUsers(store).length > 0;
457
590
  const body: string[] = [];
458
591
  if (m.streaming_state !== undefined) {
459
592
  // A streamed message (chat.startStream) keeps its Markdown body; the blocks handed to
@@ -466,7 +599,7 @@ function renderMessage(
466
599
  if (m.edited) body.push(`<div class="sm-edited">(edited)</div>`);
467
600
  if (m.attachments?.length) body.push(renderAttachments(m.attachments, ctx));
468
601
  body.push(filesHtml(m.files, store.bot.token));
469
- body.push(reactionsHtml(store, m));
602
+ body.push(reactionsHtml(store, m, interactive, Boolean(opts.writeGated)));
470
603
  if (flags.ephemeral) body.push(`<div class="sm-eph-note">Only visible to you</div>`);
471
604
  if (flags.threadLink && m.reply_count) {
472
605
  const count = `${m.reply_count} ${m.reply_count === 1 ? "reply" : "replies"}`;
@@ -477,12 +610,13 @@ function renderMessage(
477
610
  `<a class="sm-replies" href="${threadHref(m.channel, m.thread_ts ?? m.ts, opts)}">${count}${last}</a>`,
478
611
  );
479
612
  }
613
+ if (interactive) body.push(messageActions(m, opts));
480
614
  const streaming =
481
615
  m.streaming_state === "in_progress"
482
616
  ? `<span class="sm-stream" title="streaming">•••</span>`
483
617
  : "";
484
618
  const open = flags.openTs && flags.openTs === m.ts ? " sm-msg-open" : "";
485
- return `<div class="sm-msg${flags.ephemeral ? " sm-msg-eph" : ""}${open}" data-ts="${escapeHtml(m.ts)}">${avatarHtml(m, name)}<div class="sm-msg-body"><div class="sm-msg-head"><span class="sm-name">${escapeHtml(name)}</span>${isApp ? `<span class="sm-badge">APP</span>` : ""}<span class="sm-time">${timeOf(m.ts)}</span>${streaming}</div>${body.join("")}</div></div>`;
619
+ return `<div class="sm-msg${flags.ephemeral ? " sm-msg-eph" : ""}${open}" data-ts="${escapeHtml(m.ts)}" data-channel="${escapeHtml(m.channel)}">${avatarHtml(m, name)}<div class="sm-msg-body"><div class="sm-msg-head"><span class="sm-name">${escapeHtml(name)}</span>${isApp ? `<span class="sm-badge">APP</span>` : ""}<span class="sm-time">${timeOf(m.ts)}</span>${streaming}</div>${body.join("")}</div></div>`;
486
620
  }
487
621
 
488
622
  /**
@@ -538,7 +672,14 @@ function sidebar(store: Store, opts: RenderOptions, active?: string): string {
538
672
  `<a class="${c.id === active ? "sm-active" : ""}" href="${channelHref(c.id, opts)}">${escapeHtml(channelIcon(c))} ${escapeHtml(c.is_im ? channelLabel(store, c) : c.name)}</a>`,
539
673
  )
540
674
  .join("");
541
- return `<nav class="sm-side"><div class="sm-side-title"><a href="${homeHref(opts)}" style="color:#fff">${escapeHtml(store.team.name)}</a><span class="sm-side-team">${escapeHtml(store.team.id)} · slack-mock</span></div><div class="sm-side-h">Channels</div>${links}</nav>`;
675
+ const options = channels
676
+ .map(
677
+ (c) =>
678
+ `<option value="${escapeHtml(channelHref(c.id, opts))}"${c.id === active ? " selected" : ""}>${escapeHtml(channelLabel(store, c))}</option>`,
679
+ )
680
+ .join("");
681
+ const mobile = `<div class="sm-mobile-bar"><div class="sm-mobile-heading"><a class="sm-mobile-workspace" href="${homeHref(opts)}">${escapeHtml(store.team.name)}</a>${identityChip(store, opts)}</div><select class="sm-channel-switch" aria-label="Channel"><option value="${homeHref(opts)}"${active ? "" : " selected"}>Workspace</option>${options}</select></div>`;
682
+ return `${mobile}<nav class="sm-side"><div class="sm-side-title"><a href="${homeHref(opts)}" style="color:#fff">${escapeHtml(store.team.name)}</a><span class="sm-side-team">${escapeHtml(store.team.id)} · slack-mock</span></div><div class="sm-side-h">Channels</div>${links}</nav>`;
542
683
  }
543
684
 
544
685
  interface ShellParts {
@@ -561,7 +702,7 @@ function shell(store: Store, opts: RenderOptions, parts: ShellParts): string {
561
702
  ? `<meta http-equiv="refresh" content="${Math.max(1, Math.floor(opts.refreshSec))}">`
562
703
  : "";
563
704
  const style = opts.screenshot ? "" : ` style="--sm-panel-w:${panelWidth(opts)}"`;
564
- const head = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>${escapeHtml(parts.title)}</title>${refresh}<style>${CSS}</style></head>`;
705
+ const head = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover"><title>${escapeHtml(parts.title)}</title>${refresh}<style>${CSS}</style></head>`;
565
706
  if (opts.screenshot) {
566
707
  return `${head}<body><div class="sm-shot">${parts.header}<div class="sm-page">${parts.main}</div></div></body></html>`;
567
708
  }
@@ -604,14 +745,14 @@ function indexView(store: Store, opts: RenderOptions): string {
604
745
  const channelRows = channels
605
746
  .map((c) => {
606
747
  const count = store.messages.get(c.id)?.length ?? 0;
607
- return `<tr><td><a href="${channelHref(c.id, opts)}">${escapeHtml(channelIcon(c))} ${escapeHtml(c.is_im ? channelLabel(store, c) : c.name)}</a></td><td><span class="sm-tag">${channelKind(c)}</span></td><td class="sm-muted">${c.id}</td><td>${count}</td></tr>`;
748
+ return `<tr><td data-label="Name"><a href="${channelHref(c.id, opts)}">${escapeHtml(channelIcon(c))} ${escapeHtml(c.is_im ? channelLabel(store, c) : c.name)}</a></td><td data-label="Type"><span class="sm-tag">${channelKind(c)}</span></td><td class="sm-muted" data-label="Id">${c.id}</td><td data-label="Messages">${count}</td></tr>`;
608
749
  })
609
750
  .join("");
610
751
 
611
752
  const userRows = [...store.users.values()]
612
753
  .map(
613
754
  (u) =>
614
- `<tr><td>${escapeHtml(u.name)}</td><td>${escapeHtml(u.real_name)}</td><td class="sm-muted">${escapeHtml(u.profile.title ?? "")}</td><td class="sm-muted">${escapeHtml(u.profile.email ?? "")}</td><td class="sm-muted">${u.id}</td><td>${u.is_bot ? `<span class="sm-tag">bot</span>` : ""}</td></tr>`,
755
+ `<tr><td data-label="Name">${escapeHtml(u.name)}${userStatus(u)}</td><td data-label="Real name">${escapeHtml(u.real_name)}</td><td class="sm-muted" data-label="Title">${escapeHtml(u.profile.title ?? "")}</td><td class="sm-muted" data-label="Email">${escapeHtml(u.profile.email ?? "")}</td><td class="sm-muted" data-label="Id">${u.id}</td><td data-label="Type">${u.is_bot ? `<span class="sm-tag">bot</span>` : ""}</td></tr>`,
615
756
  )
616
757
  .join("");
617
758
 
@@ -627,8 +768,14 @@ ${
627
768
 
628
769
  return shell(store, opts, {
629
770
  title: `${store.team.name} · slack-mock`,
630
- header: topbar(escapeHtml(store.team.name), "slack-mock workspace"),
771
+ header: topbar(
772
+ escapeHtml(store.team.name),
773
+ "slack-mock workspace",
774
+ undefined,
775
+ identityChip(store, opts),
776
+ ),
631
777
  main,
778
+ script: opts.screenshot ? "" : uiScript(store, opts, undefined, false),
632
779
  });
633
780
  }
634
781
 
@@ -660,7 +807,12 @@ function channelColumn(
660
807
  function channelHeader(store: Store, opts: RenderOptions, channel: SlackChannel): string {
661
808
  const sub = [channel.topic.value, channel.purpose.value].filter(Boolean).join(" · ");
662
809
  const back = opts.screenshot ? undefined : { href: homeHref(opts), label: "← Workspace" };
663
- return topbar(escapeHtml(channelLabel(store, channel)), escapeHtml(sub), back);
810
+ return topbar(
811
+ escapeHtml(channelLabel(store, channel)),
812
+ escapeHtml(sub),
813
+ back,
814
+ identityChip(store, opts),
815
+ );
664
816
  }
665
817
 
666
818
  // ---------------------------------------------------------------- composer
@@ -670,6 +822,30 @@ function humanUsers(store: Store): SlackUser[] {
670
822
  return [...store.users.values()].filter((u) => !u.is_bot && !u.deleted);
671
823
  }
672
824
 
825
+ function userStatus(user: SlackUser): string {
826
+ return user.profile.status_text
827
+ ? `<span class="sm-user-status">${escapeHtml(user.profile.status_text)}</span>`
828
+ : "";
829
+ }
830
+
831
+ function identityChip(store: Store, opts: RenderOptions): string {
832
+ if (opts.screenshot) return "";
833
+ const users = humanUsers(store);
834
+ const selected = users[0];
835
+ if (!selected) return "";
836
+ const name = selected.real_name || selected.name;
837
+ const avatar = `<span class="sm-identity-avatar" style="background:${AVATAR_COLORS[hashIndex(selected.id, AVATAR_COLORS.length)]}">${escapeHtml(initials(name))}</span>`;
838
+ const items = users
839
+ .map((u) => {
840
+ const real = u.real_name || u.name;
841
+ const color = AVATAR_COLORS[hashIndex(u.id, AVATAR_COLORS.length)];
842
+ return `<li><button type="button" data-user="${escapeHtml(u.id)}"><span class="sm-identity-avatar" style="background:${color}">${escapeHtml(initials(real))}</span><span>${escapeHtml(real)}${userStatus(u)}</span><span class="sm-identity-user">@${escapeHtml(u.name)}</span></button></li>`;
843
+ })
844
+ .join("");
845
+ const hidden = opts.writeGated ? " hidden" : "";
846
+ return `<details class="sm-identity"${hidden}><summary title="Change posting identity" aria-label="Posting as ${escapeHtml(name)}">${avatar}<span class="sm-identity-name">${escapeHtml(name)}</span></summary><ul class="sm-identity-list">${items}</ul></details>`;
847
+ }
848
+
673
849
  function composer(
674
850
  store: Store,
675
851
  opts: RenderOptions,
@@ -679,19 +855,13 @@ function composer(
679
855
  if (opts.screenshot) return "";
680
856
  const users = humanUsers(store);
681
857
  if (!users.length) return "";
682
- const options = users
683
- .map(
684
- (u, i) =>
685
- `<option value="${escapeHtml(u.id)}"${i === 0 ? " selected" : ""}>${escapeHtml(u.real_name || u.name)}</option>`,
686
- )
687
- .join("");
688
858
  const placeholder = threadTs ? "Reply in thread" : `Message ${channelLabel(store, channel)}`;
689
859
  const thread = threadTs ? ` data-thread="${escapeHtml(threadTs)}"` : "";
690
860
  const gated = opts.writeGated ? ' data-gated="1"' : "";
691
861
  const lock = opts.writeGated
692
862
  ? `<div class="sm-composer-lock" hidden><span>Reading is open. Sign in to post.</span><input class="sm-lock-user" placeholder="user" autocomplete="username"><input class="sm-lock-pass" type="password" placeholder="password" autocomplete="current-password"><button type="button" class="sm-lock-go">Sign in</button><span class="sm-err"></span></div>`
693
863
  : "";
694
- return `<div class="sm-composer" data-channel="${escapeHtml(channel.id)}"${thread}${gated}><div class="sm-mentions"></div><div class="sm-composer-box"><textarea class="sm-composer-text" rows="2" placeholder="${escapeHtml(placeholder)}" data-placeholder="${escapeHtml(placeholder)}"></textarea><div class="sm-composer-row"><select class="sm-composer-user" aria-label="Post as">${options}</select><button type="button" class="sm-composer-send">Send</button></div></div>${lock}<div class="sm-composer-hint">Enter to send, Shift+Enter for a new line, @name to mention<span class="sm-lock-state"></span></div></div>`;
864
+ return `<div class="sm-composer" data-channel="${escapeHtml(channel.id)}"${thread}${gated}><div class="sm-mentions"></div><div class="sm-composer-box"><textarea class="sm-composer-text" rows="2" placeholder="${escapeHtml(placeholder)}" data-placeholder="${escapeHtml(placeholder)}"></textarea><div class="sm-composer-row"><button type="button" class="sm-composer-send">Send</button></div></div>${lock}<div class="sm-composer-hint">Enter to send, Shift+Enter for a new line, @name to mention<span class="sm-lock-state"></span></div></div>`;
695
865
  }
696
866
 
697
867
  /** Mention targets for the composer autocomplete: every user, bots included. */
@@ -699,10 +869,12 @@ function mentionData(store: Store): string {
699
869
  const users = [...store.users.values()]
700
870
  .filter((u) => !u.deleted)
701
871
  .map((u) => ({
872
+ id: u.id,
702
873
  name: u.name,
703
874
  real: u.real_name || u.name,
704
875
  initials: initials(u.real_name || u.name),
705
876
  color: AVATAR_COLORS[hashIndex(u.id, AVATAR_COLORS.length)],
877
+ bot: u.is_bot,
706
878
  }));
707
879
  const json = JSON.stringify(users).replace(/</g, "\\u003c");
708
880
  return `<script type="application/json" id="sm-users">${json}</script>`;
@@ -712,14 +884,18 @@ function mentionData(store: Store): string {
712
884
  * The whole client side: scroll to the newest message, drag the panel edge,
713
885
  * send from the composers, mention autocomplete and Escape to close a thread.
714
886
  */
715
- function uiScript(store: Store, opts: RenderOptions, closeUrl?: string): string {
887
+ function uiScript(store: Store, opts: RenderOptions, closeUrl?: string, autoScroll = true): string {
716
888
  const esc = closeUrl
717
889
  ? `document.addEventListener("keydown",function(e){if(e.key==="Escape"&&!/^(TEXTAREA|INPUT|SELECT)$/.test(document.activeElement&&document.activeElement.tagName||""))location.href=${JSON.stringify(closeUrl)}});`
718
890
  : "";
719
891
  const body = `(function(){
892
+ var viewport=window.visualViewport;
893
+ function fitViewport(){if(viewport&&viewport.scale!==1)return;var style=document.documentElement.style;style.setProperty("--sm-viewport-height",(viewport?viewport.height:innerHeight)+"px");style.setProperty("--sm-viewport-top",(viewport?viewport.offsetTop:0)+"px")}
894
+ fitViewport();addEventListener("resize",fitViewport);
895
+ if(viewport){viewport.addEventListener("resize",fitViewport);viewport.addEventListener("scroll",fitViewport)}
896
+ document.addEventListener("change",function(e){if(e.target.classList.contains("sm-channel-switch"))location.href=e.target.value});
720
897
  var W="sm-panel-w",DEF=${JSON.stringify(panelWidth(opts))},FIXED=${opts.panelWidth ? "true" : "false"};
721
- function scroll(){document.querySelectorAll(".sm-scroll").forEach(function(el){el.scrollTop=el.scrollHeight})}
722
- scroll();addEventListener("load",scroll);
898
+ ${autoScroll ? 'function scroll(){document.querySelectorAll(".sm-scroll").forEach(function(el){el.scrollTop=el.scrollHeight})}\nscroll();addEventListener("load",scroll);' : ""}
723
899
  var handle=document.querySelector(".sm-resize");
724
900
  if(handle){
725
901
  var saved=null;try{saved=localStorage.getItem(W)}catch(e){}
@@ -731,21 +907,54 @@ if(handle){
731
907
  handle.addEventListener("dblclick",function(){try{localStorage.removeItem(W)}catch(e){}document.body.style.setProperty("--sm-panel-w",DEF)});
732
908
  }
733
909
  var raw=document.getElementById("sm-users");
734
- var PEOPLE=(raw?JSON.parse(raw.textContent||"[]"):[]).concat([{name:"here",real:"Notify everyone online",initials:"@",color:"#616061"},{name:"channel",real:"Notify everyone in the channel",initials:"@",color:"#616061"}]);
910
+ var USERS=raw?JSON.parse(raw.textContent||"[]"):[],HUMANS=USERS.filter(function(u){return !u.bot});
911
+ var PEOPLE=USERS.concat([{name:"here",real:"Notify everyone online",initials:"@",color:"#616061"},{name:"channel",real:"Notify everyone in the channel",initials:"@",color:"#616061"}]);
735
912
  function esc(s){return String(s).replace(/[&<>"]/g,function(c){return c==="&"?"&amp;":c==="<"?"&lt;":c===">"?"&gt;":"&quot;"})}
736
- var GATED=${opts.writeGated ? "true" : "false"},LIVE=${opts.live !== false && !opts.refreshSec ? "true" : "false"},CK="sm-presenter";
913
+ var GATED=${opts.writeGated ? "true" : "false"},LIVE=${opts.live !== false && !opts.refreshSec ? "true" : "false"},CK="sm-presenter",IK="sm-identity",currentIdentity="",identityStorage=true;
737
914
  function cred(){try{return localStorage.getItem(CK)||""}catch(e){return ""}}
738
915
  function setCred(v){try{if(v)localStorage.setItem(CK,v);else localStorage.removeItem(CK)}catch(e){}}
916
+ function setIdentity(v){currentIdentity=v;try{if(v)localStorage.setItem(IK,v);else localStorage.removeItem(IK)}catch(e){identityStorage=false}}
917
+ function findIdentity(value,key){for(var i=0;i<HUMANS.length;i++)if(HUMANS[i][key]===value)return HUMANS[i];return null}
918
+ function identity(){var id=currentIdentity;if(identityStorage)try{id=localStorage.getItem(IK)||currentIdentity}catch(e){identityStorage=false}currentIdentity=id;var u=findIdentity(id,"id");if(!u&&HUMANS.length){u=HUMANS[0];setIdentity(u.id)}return u}
919
+ (function(){var url=null,name=null;try{url=new URL(location.href);name=url.searchParams.get("as")}catch(e){}if(url&&name!==null){var u=findIdentity(name,"name");if(u)setIdentity(u.id);url.searchParams.delete("as");var search=url.searchParams.toString();history.replaceState(null,"",url.pathname+(search?"?"+search:"")+url.hash)}})();
739
920
  (function(){var m=/[#&]presenter=([^&]+)/.exec(location.hash||"");if(m){setCred(btoa(decodeURIComponent(m[1])));history.replaceState(null,"",location.pathname+location.search)}})();
740
921
  function authHeaders(h){var c=cred();if(c)h.authorization="Basic "+c;return h}
741
- function lockUi(){document.querySelectorAll(".sm-composer").forEach(function(box){var locked=GATED&&!cred(),lock=box.querySelector(".sm-composer-lock"),ta=box.querySelector(".sm-composer-text"),btn=box.querySelector(".sm-composer-send"),state=box.querySelector(".sm-lock-state");if(lock)lock.hidden=!locked;ta.disabled=locked;btn.disabled=locked;ta.placeholder=locked?"Sign in to post":(ta.dataset.placeholder||"");if(state)state.innerHTML=GATED&&!locked?' · signed in · <a href="#" class="sm-lock-out">Sign out</a>':""})}
922
+ var reactionDialog=document.querySelector(".sm-reaction-picker"),reactionTarget=null,reactionScope=null,reactionBusy=false;
923
+ function closeReactions(restoreFocus){var button=reactionTarget&&reactionTarget.querySelector(".sm-add-reaction");if(reactionDialog&&reactionDialog.open)reactionDialog.close();reactionTarget=null;reactionScope=null;if(restoreFocus&&button&&button.isConnected&&!button.disabled)button.focus({preventScroll:true})}
924
+ function findMessageElement(scope,ts){var found=null;if(scope)scope.querySelectorAll(".sm-msg[data-ts]").forEach(function(message){if(message.dataset.ts===ts)found=message});return found}
925
+ function positionReactions(){
926
+ if(!reactionDialog||!reactionDialog.open||!reactionTarget)return;
927
+ if(!reactionTarget.isConnected){reactionTarget=findMessageElement(reactionScope,reactionTarget.dataset.ts);if(!reactionTarget){closeReactions();return}}
928
+ var button=reactionTarget.querySelector(".sm-add-reaction"),anchor=button.getBoundingClientRect(),v=window.visualViewport,left=v?v.offsetLeft:0,top=v?v.offsetTop:0,width=v?v.width:innerWidth,height=v?v.height:innerHeight,scope=reactionScope.getBoundingClientRect(),pad=12,gap=8;
929
+ if(anchor.bottom<=Math.max(top,scope.top)||anchor.top>=Math.min(top+height,scope.bottom)){closeReactions();return}
930
+ reactionDialog.style.maxWidth=Math.max(0,width-pad*2)+"px";reactionDialog.style.maxHeight=Math.max(0,height-pad*2)+"px";
931
+ var rect=reactionDialog.getBoundingClientRect(),x=Math.max(left+pad,Math.min(anchor.right-rect.width,left+width-rect.width-pad)),y=anchor.bottom+gap;
932
+ if(y+rect.height>top+height-pad)y=anchor.top-rect.height-gap;
933
+ reactionDialog.style.left=x+"px";reactionDialog.style.top=Math.max(top+pad,Math.min(y,top+height-rect.height-pad))+"px";
934
+ }
935
+ document.addEventListener("scroll",function(e){if(!reactionDialog.contains(e.target))positionReactions()},true);
936
+ addEventListener("resize",positionReactions);
937
+ if(window.visualViewport){window.visualViewport.addEventListener("resize",positionReactions);window.visualViewport.addEventListener("scroll",positionReactions)}
938
+ document.addEventListener("pointerdown",function(e){if(reactionDialog.open&&!reactionDialog.contains(e.target)&&!e.target.closest(".sm-add-reaction"))closeReactions()});
939
+ document.addEventListener("focusin",function(e){if(reactionDialog.open&&!reactionDialog.contains(e.target)&&(!reactionTarget||e.target!==reactionTarget.querySelector(".sm-add-reaction")))closeReactions()});
940
+ function hasReaction(button,user){return JSON.parse(button.dataset.users||"[]").indexOf(user)!==-1}
941
+ function reactionUi(root){var u=identity(),locked=(GATED&&!cred())||!u;(root||document).querySelectorAll(".sm-add-reaction,.sm-reaction[data-reaction],.sm-reaction-choices button").forEach(function(button){button.disabled=locked||reactionBusy;if(button.classList.contains("sm-reaction")){var mine=Boolean(u&&hasReaction(button,u.id)),count=button.querySelector(".sm-reaction-count").textContent;button.setAttribute("aria-pressed",String(mine));button.setAttribute("aria-label",(mine?"Remove":"Add")+" :"+button.dataset.reaction+": reaction, "+count+" "+(count==="1"?"person":"people")+" reacted")}});if(locked)closeReactions()}
942
+ function identityUi(){var u=identity();document.querySelectorAll(".sm-identity").forEach(function(chip){chip.hidden=GATED&&!cred();if(!u)return;var av=chip.querySelector("summary .sm-identity-avatar"),name=chip.querySelector(".sm-identity-name"),summary=chip.querySelector("summary");if(av){av.textContent=u.initials;av.style.backgroundColor=u.color}if(name)name.textContent=u.real;if(summary)summary.setAttribute("aria-label","Posting as "+u.real);chip.querySelectorAll("[data-user]").forEach(function(button){if(button.dataset.user===u.id)button.setAttribute("aria-current","true");else button.removeAttribute("aria-current")})});reactionUi()}
943
+ function lockUi(){document.querySelectorAll(".sm-composer").forEach(function(box){var locked=GATED&&!cred(),lock=box.querySelector(".sm-composer-lock"),ta=box.querySelector(".sm-composer-text"),btn=box.querySelector(".sm-composer-send"),state=box.querySelector(".sm-lock-state");if(lock)lock.hidden=!locked;ta.disabled=locked;btn.disabled=locked;ta.placeholder=locked?"Sign in to post":(ta.dataset.placeholder||"");if(state)state.innerHTML=GATED&&!locked?' · signed in · <a href="#" class="sm-lock-out">Sign out</a>':""});identityUi()}
742
944
  function signIn(box){if(!box)return;var u=box.querySelector(".sm-lock-user").value.trim(),p=box.querySelector(".sm-lock-pass").value,err=box.querySelector(".sm-err");if(!u){err.textContent="Enter the presenter user";return}var c=btoa(u+":"+p);err.textContent="";fetch("/mock/presenter",{headers:{authorization:"Basic "+c}}).then(function(r){if(!r.ok)throw new Error(r.status===401||r.status===403?"Wrong user or password":"Sign-in failed ("+r.status+")");setCred(c);lockUi();box.querySelector(".sm-composer-text").focus()}).catch(function(e){err.textContent=e.message})}
743
- document.addEventListener("click",function(e){var out=e.target.closest(".sm-lock-out");if(out){e.preventDefault();setCred("");lockUi();return}var go=e.target.closest(".sm-lock-go");if(go)signIn(go.closest(".sm-composer"))});
945
+ document.addEventListener("click",function(e){var pick=e.target.closest(".sm-identity-list button");if(pick){setIdentity(pick.dataset.user);identityUi();pick.closest(".sm-identity").open=false;return}if(!e.target.closest(".sm-identity"))document.querySelectorAll(".sm-identity[open]").forEach(function(chip){chip.open=false});var out=e.target.closest(".sm-lock-out");if(out){e.preventDefault();setCred("");lockUi();return}var go=e.target.closest(".sm-lock-go");if(go)signIn(go.closest(".sm-composer"))});
946
+ document.addEventListener("keydown",function(e){if(e.key!=="Escape")return;var chip=document.querySelector(".sm-identity[open]");if(!chip)return;e.preventDefault();e.stopImmediatePropagation();chip.open=false;chip.querySelector("summary").focus()});
947
+ document.addEventListener("keydown",function(e){if(e.key==="Escape"&&reactionDialog&&reactionDialog.open){e.preventDefault();e.stopImmediatePropagation();closeReactions(true)}});
744
948
  document.addEventListener("keydown",function(e){var c=e.target.classList;if(e.key==="Enter"&&c&&(c.contains("sm-lock-pass")||c.contains("sm-lock-user"))){e.preventDefault();signIn(e.target.closest(".sm-composer"))}});
949
+ addEventListener("storage",function(e){if(e.key===IK){currentIdentity=e.newValue||"";identityUi()}});
745
950
  lockUi();
746
951
  var pending=null;
747
- function refresh(){if(pending)return;pending=setTimeout(function(){pending=null;fetch(location.href,{headers:{accept:"text/html"},credentials:"same-origin"}).then(function(r){return r.ok?r.text():Promise.reject(r.status)}).then(apply).catch(function(){})},120)}
748
- function apply(html){var doc=new DOMParser().parseFromString(html,"text/html");[".sm-side",".sm-page",".sm-panel-body"].forEach(function(sel){var cur=document.querySelector(sel),nxt=doc.querySelector(sel);if(!cur||!nxt)return;var seen={};cur.querySelectorAll(".sm-msg[data-ts]").forEach(function(el){el.classList.remove("sm-msg-new","sm-msg-changed");seen[el.dataset.ts]=el.outerHTML});var atBottom=cur.scrollHeight-cur.scrollTop-cur.clientHeight<80;cur.innerHTML=nxt.innerHTML;cur.querySelectorAll(".sm-msg[data-ts]").forEach(function(el){var prev=seen[el.dataset.ts];if(prev===undefined)el.classList.add("sm-msg-new");else if(prev!==el.outerHTML)el.classList.add("sm-msg-changed")});if(atBottom)cur.scrollTop=cur.scrollHeight});if(doc.title)document.title=doc.title}
952
+ function refresh(){if(pending)return;pending=setTimeout(function(){pending=null;fetch(location.href,{headers:{accept:"text/html"},credentials:"same-origin"}).then(function(r){return r.ok?r.text():Promise.reject(r.status)}).then(apply).catch(function(){reactionUi()})},120)}
953
+ function apply(html){
954
+ var doc=new DOMParser().parseFromString(html,"text/html"),opener=document.activeElement,focusedMessage=opener&&opener.classList.contains("sm-add-reaction")?opener.closest(".sm-msg"):null,focusedScope=focusedMessage&&focusedMessage.closest(".sm-page,.sm-panel-body");
955
+ reactionUi();reactionUi(doc);[".sm-side",".sm-channel-switch",".sm-page",".sm-panel-body"].forEach(function(sel){var cur=document.querySelector(sel),nxt=doc.querySelector(sel);if(!cur||!nxt)return;var seen={};cur.querySelectorAll(".sm-msg[data-ts]").forEach(function(el){el.classList.remove("sm-msg-new","sm-msg-changed");seen[el.dataset.ts]=el.outerHTML});var atBottom=cur.scrollHeight-cur.scrollTop-cur.clientHeight<80;cur.innerHTML=nxt.innerHTML;cur.querySelectorAll(".sm-msg[data-ts]").forEach(function(el){var prev=seen[el.dataset.ts];if(prev===undefined)el.classList.add("sm-msg-new");else if(prev!==el.outerHTML)el.classList.add("sm-msg-changed")});if(atBottom)cur.scrollTop=cur.scrollHeight});identityUi();positionReactions();if(doc.title)document.title=doc.title;
956
+ if(focusedMessage&&!opener.isConnected){var message=findMessageElement(focusedScope,focusedMessage.dataset.ts);if(message)message.querySelector(".sm-add-reaction").focus({preventScroll:true})}
957
+ }
749
958
  if(LIVE&&window.EventSource){
750
959
  var box0=document.querySelector(".sm-composer"),pm=/^\\/c\\/([^/]+)/.exec(location.pathname),chan=box0?box0.dataset.channel:(pm?decodeURIComponent(pm[1]):null);
751
960
  if(chan){
@@ -757,7 +966,23 @@ if(LIVE&&window.EventSource){
757
966
  es.onerror=function(){down=true;if(dot){dot.textContent="● reconnecting";dot.classList.add("sm-live-off")}};
758
967
  }
759
968
  }
760
- function send(box){var t=box.querySelector(".sm-composer-text"),text=t.value.trim();if(!text||t.disabled)return;var body={channel:box.dataset.channel,user:box.querySelector(".sm-composer-user").value,text:text};if(box.dataset.thread)body.thread_ts=box.dataset.thread;t.disabled=true;fetch("/mock/messages",{method:"POST",headers:authHeaders({"content-type":"application/json"}),body:JSON.stringify(body)}).then(function(r){t.disabled=false;if(r.status===401||r.status===403){setCred("");lockUi();var err=box.querySelector(".sm-err");if(err)err.textContent="Not signed in, or the credential changed. Sign in to post.";return}if(!r.ok)throw new Error("send failed "+r.status);t.value="";if(LIVE)refresh();else location.reload()}).catch(function(){t.disabled=false})}
969
+ function react(message,name){
970
+ var u=identity();if(!message||!u||reactionBusy||(GATED&&!cred()))return;
971
+ var action="add";message.querySelectorAll(".sm-reaction[data-reaction]").forEach(function(button){if(button.dataset.reaction===name&&hasReaction(button,u.id))action="remove"});
972
+ var err=(reactionDialog&&reactionDialog.open?reactionDialog:message).querySelector(".sm-action-error");if(err){err.hidden=true;err.textContent=""}
973
+ reactionBusy=true;reactionUi();
974
+ fetch("/mock/reactions",{method:"POST",headers:authHeaders({"content-type":"application/json"}),body:JSON.stringify({channel:message.dataset.channel,ts:message.dataset.ts,name:name,user:u.id,action:action})}).then(function(r){
975
+ if(r.status===401||r.status===403){setCred("");lockUi();throw new Error("Sign in to react.")}
976
+ return r.json().then(function(data){if(!r.ok&&data.error!=="already_reacted"&&data.error!=="no_reaction")throw new Error("Could not save the reaction. Try again.")})
977
+ }).then(function(){reactionBusy=false;reactionUi();closeReactions(true);refresh()}).catch(function(e){reactionBusy=false;reactionUi();if(err){if(err.closest("dialog")&&!reactionDialog.open)err=message.querySelector(".sm-action-error");err.textContent=e.message==="Sign in to react."?e.message:"Could not save the reaction. Try again.";err.hidden=false;positionReactions()}})
978
+ }
979
+ document.addEventListener("click",function(e){
980
+ var add=e.target.closest(".sm-add-reaction");if(add&&!add.disabled){var message=add.closest(".sm-msg");if(reactionDialog.open&&reactionTarget===message){closeReactions(true);return}reactionTarget=message;reactionScope=message.closest(".sm-page,.sm-panel-body");var err=reactionDialog.querySelector(".sm-action-error");err.hidden=true;err.textContent="";if(!reactionDialog.open)reactionDialog.show();positionReactions();return}
981
+ var choice=e.target.closest("button[data-reaction]");if(choice&&!choice.disabled){react(choice.closest(".sm-reaction-picker")?reactionTarget:choice.closest(".sm-msg"),choice.dataset.reaction);return}
982
+ if(e.target.closest(".sm-reaction-close")){closeReactions(true);return}
983
+ var reply=e.target.closest(".sm-reply-action"),box=document.querySelector(".sm-composer[data-thread]");if(reply&&box&&box.dataset.thread===reply.dataset.thread&&box.dataset.channel===reply.closest(".sm-msg").dataset.channel)e.preventDefault()
984
+ });
985
+ function send(box){var t=box.querySelector(".sm-composer-text"),text=t.value.trim(),user=identity();if(!text||t.disabled||!user)return;var body={channel:box.dataset.channel,user:user.id,text:text};if(box.dataset.thread)body.thread_ts=box.dataset.thread;t.disabled=true;fetch("/mock/messages",{method:"POST",headers:authHeaders({"content-type":"application/json"}),body:JSON.stringify(body)}).then(function(r){t.disabled=false;if(r.status===401||r.status===403){setCred("");lockUi();var err=box.querySelector(".sm-err");if(err)err.textContent="Not signed in, or the credential changed. Sign in to post.";return}if(!r.ok)throw new Error("send failed "+r.status);t.value="";if(LIVE)refresh();else location.reload()}).catch(function(){t.disabled=false})}
761
986
  document.querySelectorAll(".sm-composer").forEach(function(box){
762
987
  var ta=box.querySelector(".sm-composer-text"),menu=box.querySelector(".sm-mentions"),items=[],active=0;
763
988
  function close(){items=[];menu.style.display="none"}
@@ -793,7 +1018,7 @@ document.querySelectorAll(".sm-composer").forEach(function(box){
793
1018
  box.querySelector(".sm-composer-send").addEventListener("click",function(){send(box)});
794
1019
  });
795
1020
  })();`;
796
- return `${mentionData(store)}<script>${body}${esc}</script>`;
1021
+ return `${mentionData(store)}${reactionPicker()}<script>${body}${esc}</script>`;
797
1022
  }
798
1023
 
799
1024
  function channelView(store: Store, opts: RenderOptions, channelId: string): string {
@@ -878,7 +1103,7 @@ function threadView(store: Store, opts: RenderOptions, channelId: string, ts: st
878
1103
  `Thread <span class="sm-muted">·</span> ${escapeHtml(label)}`,
879
1104
  "",
880
1105
  { href: close, label: `← ${label}` },
881
- `<a class="sm-icon-btn" href="${threadHref(channel.id, ts, opts, { full: false })}" title="Collapse to panel" aria-label="Collapse to panel">⤡</a>`,
1106
+ `<a class="sm-icon-btn" href="${threadHref(channel.id, ts, opts, { full: false })}" title="Collapse to panel" aria-label="Collapse to panel">⤡</a>${identityChip(store, opts)}`,
882
1107
  );
883
1108
  return shell(store, opts, {
884
1109
  title,
@@ -891,7 +1116,7 @@ function threadView(store: Store, opts: RenderOptions, channelId: string, ts: st
891
1116
  }
892
1117
 
893
1118
  const expand = threadHref(channel.id, ts, opts, { full: true });
894
- const panel = `<aside class="sm-panel"><div class="sm-panel-top"><div class="sm-panel-heading"><h2 class="sm-panel-title">Thread</h2><div class="sm-panel-sub">${escapeHtml(label)}</div></div><a class="sm-panel-expand" href="${expand}" title="Expand thread">⤢</a><a class="sm-panel-close" href="${close}" title="Close thread">×</a></div><a class="sm-panel-back" href="${close}">← ${escapeHtml(label)}</a><div class="sm-panel-body sm-scroll">${body}</div>${composer(store, opts, channel, ts)}</aside>`;
1119
+ const panel = `<aside class="sm-panel"><div class="sm-panel-top"><a class="sm-panel-back" href="${close}" aria-label="Back to ${escapeHtml(label)}">←</a><div class="sm-panel-heading"><h2 class="sm-panel-title">Thread</h2><div class="sm-panel-sub">${escapeHtml(label)}</div></div><a class="sm-panel-expand" href="${expand}" title="Expand thread">⤢</a><a class="sm-panel-close" href="${close}" title="Close thread">×</a></div><div class="sm-panel-body sm-scroll">${body}</div>${composer(store, opts, channel, ts)}</aside>`;
895
1120
  return shell(store, opts, {
896
1121
  title,
897
1122
  header: channelHeader(store, opts, channel),