@desplega.ai/slack-mock 0.2.0 → 0.4.0

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.
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  requireChrome2,
4
4
  screenshot2
5
- } from "./index-v2hesj4s.js";
5
+ } from "./index-xs37gskt.js";
6
6
 
7
7
  // src/store.ts
8
8
  import { appendFileSync, existsSync, mkdirSync, readFileSync } from "fs";
@@ -184,6 +184,8 @@ class Store2 {
184
184
  real_name_normalized: realName,
185
185
  display_name_normalized: input.name,
186
186
  email: input.email,
187
+ title: input.title,
188
+ status_text: input.status,
187
189
  team: this.team.id
188
190
  }
189
191
  };
@@ -1476,7 +1478,7 @@ a:hover{text-decoration:underline}
1476
1478
  .sm-side a:hover{background:#522653;color:#fff;text-decoration:none}
1477
1479
  .sm-side a.sm-active,.sm-side a.sm-active:hover{background:#1164a3;color:#fff}
1478
1480
  .sm-side-title a:hover{background:none;text-decoration:underline}
1479
- .sm-main{flex:1;min-width:280px;display:flex;flex-direction:column;overflow:hidden}
1481
+ .sm-main{flex:1;min-width:0;display:flex;flex-direction:column;overflow:hidden}
1480
1482
  .sm-shot{width:760px;padding:16px;background:#fff}
1481
1483
  .sm-top{border-bottom:1px solid #e8e8e8;padding:12px 20px;display:flex;align-items:baseline;gap:12px;flex:none}
1482
1484
  .sm-top h1{font-size:18px;font-weight:900;margin:0}
@@ -1507,8 +1509,6 @@ a:hover{text-decoration:underline}
1507
1509
  .sm-composer-box{border:1px solid #bbb;border-radius:8px;padding:8px 10px;background:#fff}
1508
1510
  .sm-composer-box:focus-within{border-color:#1264a3;box-shadow:0 0 0 1px #1264a3}
1509
1511
  .sm-composer-row{display:flex;align-items:center;gap:8px;margin-top:6px}
1510
- .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}
1511
- .sm-composer-user:hover{background:#e8e8e8}
1512
1512
  .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}
1513
1513
  .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}
1514
1514
  .sm-composer-send:hover{background:#148567;color:#fff}
@@ -1522,25 +1522,30 @@ a:hover{text-decoration:underline}
1522
1522
  .sm-mention-name{font-weight:700}
1523
1523
  .sm-mention-real{color:#616061;font-size:13px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1524
1524
 
1525
- .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}
1525
+ .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}
1526
1526
  .sm-composer-text{cursor:text}
1527
1527
  .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}
1528
- .sm-top-actions{margin-left:auto;display:flex;gap:12px;align-items:baseline;flex:none}
1528
+ .sm-top-actions{margin-left:auto;display:flex;gap:12px;align-items:center;flex:none}
1529
1529
  .sm-top-actions a{font-size:13px;font-weight:700;color:#616061}
1530
1530
  .sm-top-actions a:hover{color:#1264a3}
1531
- @media (max-width:900px){
1532
- .sm-side{display:none}
1533
- .sm-app-thread .sm-main{display:none}
1534
- .sm-panel{width:100%;min-width:0;border-left:0}
1535
- .sm-panel-back{display:block}
1536
- .sm-panel-expand,.sm-resize{display:none}
1537
- }
1531
+ .sm-identity{position:relative}
1532
+ .sm-identity[hidden]{display:none}
1533
+ .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}
1534
+ .sm-identity summary::-webkit-details-marker{display:none}
1535
+ .sm-identity summary:hover{background:#f8f8f8}
1536
+ .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}
1537
+ .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)}
1538
+ .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}
1539
+ .sm-identity-list button:hover,.sm-identity-list button:focus{background:#f0f0f0;outline:none}
1540
+ .sm-identity-user{font-size:12px;color:#616061;margin-left:auto}
1541
+ .sm-user-status{margin-left:6px;font-size:12px;font-weight:400;color:#616061}
1542
+ .sm-mobile-bar{display:none}
1538
1543
 
1539
1544
  .sm-daydiv{display:flex;align-items:center;gap:10px;margin:14px 0 8px}
1540
1545
  .sm-daydiv:before,.sm-daydiv:after{content:"";flex:1;height:1px;background:#e8e8e8}
1541
1546
  .sm-daydiv span{border:1px solid #e8e8e8;border-radius:12px;padding:2px 12px;font-size:13px;font-weight:700;color:#454245;background:#fff}
1542
1547
 
1543
- .sm-msg{display:flex;gap:12px;padding:8px 8px;border-radius:6px}
1548
+ .sm-msg{position:relative;display:flex;gap:12px;padding:8px 8px;border-radius:6px}
1544
1549
  .sm-msg:hover{background:#f8f8f8}
1545
1550
  .sm-msg-eph{background:#fffbe6}
1546
1551
  .sm-msg-eph:hover{background:#fff7d1}
@@ -1563,7 +1568,7 @@ a:hover{text-decoration:underline}
1563
1568
  .sm-msg-new{animation:sm-flash 2.4s ease-out}
1564
1569
  .sm-msg-changed{animation:sm-flash-soft .9s ease-out}
1565
1570
  @media (prefers-reduced-motion:reduce){.sm-msg-new,.sm-msg-changed{animation:none}}
1566
- .sm-live{font-size:11px;font-weight:600;color:#2eb67d;margin-left:10px;vertical-align:middle}
1571
+ .sm-live{font-size:11px;font-weight:600;color:#2eb67d;margin-left:10px;vertical-align:middle;white-space:nowrap}
1567
1572
  .sm-live-off{color:#e8912d}
1568
1573
  .sm-composer-lock{display:flex;align-items:center;gap:8px;flex-wrap:wrap;padding:8px 0 2px;font-size:13px;color:#616061}
1569
1574
  .sm-composer-lock[hidden]{display:none}
@@ -1642,7 +1647,24 @@ a:hover{text-decoration:underline}
1642
1647
  .sm-reactions{display:flex;flex-wrap:wrap;gap:6px;margin-top:6px}
1643
1648
  .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}
1644
1649
  .sm-reaction:hover{background:#e8f5fa;border-color:#1264a3;color:#1d1c1d}
1650
+ .sm-reaction[aria-pressed="true"]{background:#e8f5fa;border-color:#1264a3;color:#1264a3}
1651
+ .sm-reaction:disabled{cursor:default}
1645
1652
  .sm-reaction-count{font-weight:700;font-size:12px}
1653
+ .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}
1654
+ .sm-msg:hover .sm-message-actions,.sm-msg:focus-within .sm-message-actions{opacity:1}
1655
+ .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}
1656
+ .sm-message-actions button:hover,.sm-message-actions a:hover{background:#f0f0f0;color:#1d1c1d}
1657
+ .sm-message-actions button:disabled{opacity:.5;cursor:default}
1658
+ .sm-message-actions svg{width:18px;height:18px;flex:none}
1659
+ .sm-action-error{font-size:13px;color:#a12622;margin-top:6px}
1660
+ .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}
1661
+ .sm-reaction-picker-head{display:flex;align-items:center;justify-content:space-between;gap:12px;margin-bottom:12px}
1662
+ .sm-reaction-picker h2{font-size:16px;margin:0}
1663
+ .sm-reaction-picker button{min-width:40px;min-height:40px;border:0;border-radius:6px;background:#fff;font:inherit;cursor:pointer}
1664
+ .sm-reaction-picker button:hover,.sm-reaction-picker button:focus-visible{background:#f0f0f0}
1665
+ .sm-reaction-picker button:disabled{opacity:.5;cursor:default}
1666
+ .sm-reaction-choices{display:grid;grid-template-columns:repeat(4,1fr);gap:6px}
1667
+ .sm-reaction-choices button{font-size:24px}
1646
1668
  .sm-file-card:hover{background:#f8f8f8}
1647
1669
 
1648
1670
  .sm-replies{display:inline-flex;align-items:center;gap:8px;margin-top:4px;font-size:13px;font-weight:700;color:#1264a3}
@@ -1667,6 +1689,79 @@ a:hover{text-decoration:underline}
1667
1689
  .sm-table td{padding:6px 10px 6px 0;border-bottom:1px solid #f2f2f2;vertical-align:top}
1668
1690
  .sm-tag{display:inline-block;background:#f0f0f0;color:#454245;border-radius:10px;padding:0 8px;font-size:11px;font-weight:700}
1669
1691
  .sm-muted{color:#616061}
1692
+
1693
+ @media (min-width:700px) and (max-width:1000px){
1694
+ .sm-side{width:180px}
1695
+ .sm-panel{min-width:300px;max-width:calc(100% - 360px)}
1696
+ .sm-top{padding:8px 12px;gap:6px;align-items:center;flex-wrap:wrap}
1697
+ .sm-top h1{min-width:0;overflow-wrap:anywhere}
1698
+ .sm-top .sm-sub{display:none}
1699
+ .sm-top-actions{min-width:0;max-width:100%;flex-shrink:1}
1700
+ .sm-identity{min-width:0;max-width:100%}
1701
+ .sm-identity-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1702
+ .sm-replies{flex-wrap:wrap}
1703
+ .sm-att-img,.sm-file-img,.sm-video-thumb,.sm-file-card{max-width:100%}
1704
+ }
1705
+ @media (max-width:699px),(hover:none),(pointer:coarse){
1706
+ .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}
1707
+ .sm-message-actions button,.sm-message-actions a{width:40px;min-height:40px;background:none}
1708
+ }
1709
+ @media (max-width:699px){
1710
+ html,body{overflow:hidden;overscroll-behavior:none}
1711
+ body{overflow-wrap:anywhere}
1712
+ .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}
1713
+ .sm-side,.sm-resize{display:none}
1714
+ .sm-mobile-bar{display:block;flex:none;background:#3f0e40;color:#fff;padding:calc(8px + env(safe-area-inset-top)) 12px 8px;z-index:10}
1715
+ .sm-mobile-heading{display:flex;align-items:center;justify-content:space-between;gap:12px;min-width:0}
1716
+ .sm-mobile-workspace{display:flex;align-items:center;min-height:40px;min-width:0;color:#fff;font-size:17px;font-weight:900}
1717
+ .sm-mobile-bar .sm-identity{flex:none;max-width:55%;color:#1d1c1d}
1718
+ .sm-identity summary{min-height:40px;background:#fff;border-radius:20px}
1719
+ .sm-identity-name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
1720
+ .sm-identity-list{width:280px;max-width:calc(100vw - 24px);max-height:calc(var(--sm-viewport-height,100dvh) - 120px);overflow-y:auto}
1721
+ .sm-identity-list button{min-height:40px}
1722
+ .sm-identity-list button>span{min-width:0;overflow-wrap:anywhere}
1723
+ .sm-identity-user{white-space:normal}
1724
+ .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}
1725
+ .sm-main{min-height:0}
1726
+ .sm-app-thread .sm-main{display:none}
1727
+ .sm-panel{width:100%;min-width:0;min-height:0;flex:1;border-left:0}
1728
+ .sm-top{padding:6px 12px;align-items:center;gap:10px;flex-wrap:wrap}
1729
+ .sm-top h1{font-size:16px;min-width:0}
1730
+ .sm-top .sm-sub,.sm-top .sm-identity,.sm-live{display:none}
1731
+ .sm-panel-top{padding:6px 12px;align-items:center}
1732
+ .sm-panel-back{display:inline-flex;align-items:center;justify-content:center;width:40px;min-height:40px;padding:0;border:0;font-size:22px}
1733
+ .sm-panel-close,.sm-panel-expand{display:none}
1734
+ .sm-main .sm-page,.sm-panel-body{min-height:0;padding:8px 12px 20px;overscroll-behavior:contain}
1735
+ .sm-msg{padding:8px 0;gap:10px}
1736
+ .sm-msg-body,.sm-card-v,.sm-field,.sm-att,.sm-context,.sm-file-card{overflow-wrap:anywhere}
1737
+ .sm-text,.sm-blocks,.sm-field,.sm-att-text,.sm-att-pretext{font-size:16px;line-height:24px}
1738
+ .sm-name{font-size:14px}
1739
+ .sm-time{font-size:12px}
1740
+ .sm-composer,.sm-panel .sm-composer{padding:8px 12px calc(10px + env(safe-area-inset-bottom))}
1741
+ .sm-composer-text{font-size:16px;line-height:22px;resize:none;max-height:30vh}
1742
+ .sm-composer-lock input{font-size:16px;min-height:40px;flex:1;min-width:0}
1743
+ .sm-composer-lock>span:first-child{width:100%}
1744
+ .sm-mentions,.sm-panel .sm-mentions{left:12px;right:12px;max-height:min(260px,40vh)}
1745
+ .sm-mention{min-height:40px}
1746
+ .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}
1747
+ .sm-btn,.sm-select{max-width:100%;white-space:normal}
1748
+ .sm-replies{flex-wrap:wrap;gap:4px 8px}
1749
+ .sm-section-split{flex-wrap:wrap}
1750
+ .sm-section-main{flex-basis:100%}
1751
+ .sm-section-acc,.sm-context>*{min-width:0;max-width:100%}
1752
+ .sm-att-img,.sm-file-img,.sm-video-thumb{max-width:100%;height:auto}
1753
+ .sm-file-card,.sm-unsupported{max-width:100%}
1754
+ .sm-file-card>div:last-child{min-width:0}
1755
+ .sm-cards{gap:10px}
1756
+ .sm-card{flex:1 1 calc(50% - 5px);min-width:0}
1757
+ .sm-table,.sm-table tbody{display:block;width:100%}
1758
+ .sm-table tr{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px 14px;padding:12px 0;border-bottom:1px solid #e8e8e8}
1759
+ .sm-table tr:first-child{display:none}
1760
+ .sm-table td{display:block;padding:0;border:0;overflow-wrap:anywhere}
1761
+ .sm-table td:before{content:attr(data-label);display:block;font-size:11px;color:#616061;text-transform:uppercase;letter-spacing:.4px}
1762
+ .sm-table td a{display:inline-flex;align-items:center;min-height:40px}
1763
+ .sm-shot{width:100%;padding:12px}
1764
+ }
1670
1765
  `;
1671
1766
  function ctxOf(store) {
1672
1767
  return { users: store.users, channels: store.channels, botUserId: store.bot.userId };
@@ -1787,7 +1882,7 @@ function avatarHtml(m, name) {
1787
1882
  const color = AVATAR_COLORS[hashIndex(seed, AVATAR_COLORS.length)];
1788
1883
  return `<div class="sm-avatar" style="background:${color}">${escapeHtml(initials(name))}</div>`;
1789
1884
  }
1790
- function reactionsHtml(store, m) {
1885
+ function reactionsHtml(store, m, interactive, locked) {
1791
1886
  if (!m.reactions?.length)
1792
1887
  return "";
1793
1888
  const chips = m.reactions.map((r) => {
@@ -1796,10 +1891,35 @@ function reactionsHtml(store, m) {
1796
1891
  return user ? displayName(user) : id;
1797
1892
  }).join(", ");
1798
1893
  const char = emojiChar(r.name) ?? `:${r.name}:`;
1799
- return `<span class="sm-reaction" title="${escapeHtml(who)}">${escapeHtml(char)}<span class="sm-reaction-count">${r.count}</span></span>`;
1894
+ const content = `${escapeHtml(char)}<span class="sm-reaction-count">${r.count}</span>`;
1895
+ return interactive ? `<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>` : `<span class="sm-reaction" title="${escapeHtml(who)}">${content}</span>`;
1800
1896
  });
1801
1897
  return `<div class="sm-reactions">${chips.join("")}</div>`;
1802
1898
  }
1899
+ function messageActions(m, opts) {
1900
+ const thread = m.thread_ts ?? m.ts;
1901
+ 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>`;
1902
+ 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>`;
1903
+ 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>`;
1904
+ }
1905
+ function reactionPicker() {
1906
+ const names = [
1907
+ "thumbsup",
1908
+ "green_heart",
1909
+ "eyes",
1910
+ "white_check_mark",
1911
+ "tada",
1912
+ "rocket",
1913
+ "star",
1914
+ "thinking_face",
1915
+ "sparkles",
1916
+ "fire",
1917
+ "raised_hands",
1918
+ "clap"
1919
+ ];
1920
+ const buttons = names.map((name) => `<button type="button" data-reaction="${name}" aria-label="React with ${name.replaceAll("_", " ")}" title=":${name}:">${escapeHtml(emojiChar(name) ?? `:${name}:`)}</button>`).join("");
1921
+ 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">\u2715</button></div><div class="sm-reaction-choices">${buttons}</div><div class="sm-action-error" role="alert" hidden></div></dialog>`;
1922
+ }
1803
1923
  function fileUrl(f, token) {
1804
1924
  if (!f.url_private)
1805
1925
  return "";
@@ -1824,6 +1944,7 @@ function renderMessage(store, ctx, m, opts, flags = {}) {
1824
1944
  const name = authorName(store, m);
1825
1945
  const isApp = Boolean(m.bot_id);
1826
1946
  const blocks = Array.isArray(m.blocks) && m.blocks.length ? m.blocks : undefined;
1947
+ const interactive = !opts.screenshot && !flags.ephemeral && humanUsers(store).length > 0;
1827
1948
  const body = [];
1828
1949
  if (m.streaming_state !== undefined) {
1829
1950
  if (m.text)
@@ -1839,7 +1960,7 @@ function renderMessage(store, ctx, m, opts, flags = {}) {
1839
1960
  if (m.attachments?.length)
1840
1961
  body.push(renderAttachments(m.attachments, ctx));
1841
1962
  body.push(filesHtml(m.files, store.bot.token));
1842
- body.push(reactionsHtml(store, m));
1963
+ body.push(reactionsHtml(store, m, interactive, Boolean(opts.writeGated)));
1843
1964
  if (flags.ephemeral)
1844
1965
  body.push(`<div class="sm-eph-note">Only visible to you</div>`);
1845
1966
  if (flags.threadLink && m.reply_count) {
@@ -1847,9 +1968,11 @@ function renderMessage(store, ctx, m, opts, flags = {}) {
1847
1968
  const last = m.latest_reply ? `<span class="sm-replies-time">Last reply ${timeOf(m.latest_reply)}</span>` : "";
1848
1969
  body.push(`<a class="sm-replies" href="${threadHref(m.channel, m.thread_ts ?? m.ts, opts)}">${count}${last}</a>`);
1849
1970
  }
1971
+ if (interactive)
1972
+ body.push(messageActions(m, opts));
1850
1973
  const streaming = m.streaming_state === "in_progress" ? `<span class="sm-stream" title="streaming">\u2022\u2022\u2022</span>` : "";
1851
1974
  const open = flags.openTs && flags.openTs === m.ts ? " sm-msg-open" : "";
1852
- 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>`;
1975
+ 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>`;
1853
1976
  }
1854
1977
  function markdownToMrkdwn(text) {
1855
1978
  return text.split(/(```[\s\S]*?```)/).map((part, i) => i % 2 === 1 ? part : part.replace(/\*\*(.+?)\*\*/g, "*$1*").replace(/__(.+?)__/g, "*$1*").replace(/\[([^\]]+)\]\((https?:\/\/[^)\s]+)\)/g, "<$2|$1>").replace(/^#{1,6}\s+(.+)$/gm, "*$1*").replace(/^(\s*)[-*]\s+/gm, "$1\u2022 ")).join("");
@@ -1870,12 +1993,14 @@ function renderMessageList(store, ctx, messages, opts, flags = {}) {
1870
1993
  function sidebar(store, opts, active) {
1871
1994
  const channels = [...store.channels.values()].sort((a, b) => channelLabel(store, a).localeCompare(channelLabel(store, b)));
1872
1995
  const links = channels.map((c) => `<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>`).join("");
1873
- 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)} \xB7 slack-mock</span></div><div class="sm-side-h">Channels</div>${links}</nav>`;
1996
+ const options = channels.map((c) => `<option value="${escapeHtml(channelHref(c.id, opts))}"${c.id === active ? " selected" : ""}>${escapeHtml(channelLabel(store, c))}</option>`).join("");
1997
+ 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>`;
1998
+ 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)} \xB7 slack-mock</span></div><div class="sm-side-h">Channels</div>${links}</nav>`;
1874
1999
  }
1875
2000
  function shell(store, opts, parts) {
1876
2001
  const refresh = opts.refreshSec && !opts.screenshot ? `<meta http-equiv="refresh" content="${Math.max(1, Math.floor(opts.refreshSec))}">` : "";
1877
2002
  const style = opts.screenshot ? "" : ` style="--sm-panel-w:${panelWidth(opts)}"`;
1878
- 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>`;
2003
+ 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>`;
1879
2004
  if (opts.screenshot) {
1880
2005
  return `${head}<body><div class="sm-shot">${parts.header}<div class="sm-page">${parts.main}</div></div></body></html>`;
1881
2006
  }
@@ -1898,18 +2023,19 @@ function indexView(store, opts) {
1898
2023
  const channels = [...store.channels.values()];
1899
2024
  const channelRows = channels.map((c) => {
1900
2025
  const count = store.messages.get(c.id)?.length ?? 0;
1901
- 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>`;
2026
+ 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>`;
1902
2027
  }).join("");
1903
- const userRows = [...store.users.values()].map((u) => `<tr><td>${escapeHtml(u.name)}</td><td>${escapeHtml(u.real_name)}</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>`).join("");
2028
+ const userRows = [...store.users.values()].map((u) => `<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>`).join("");
1904
2029
  const main = `<div class="sm-cards">${cards}</div>
1905
2030
  <div class="sm-h2">Channels</div>
1906
2031
  ${channels.length ? `<table class="sm-table"><tr><th>Name</th><th>Type</th><th>Id</th><th>Messages</th></tr>${channelRows}</table>` : `<div class="sm-empty">No channels yet</div>`}
1907
2032
  <div class="sm-h2">Users</div>
1908
- <table class="sm-table"><tr><th>Name</th><th>Real name</th><th>Email</th><th>Id</th><th></th></tr>${userRows}</table>`;
2033
+ <table class="sm-table"><tr><th>Name</th><th>Real name</th><th>Title</th><th>Email</th><th>Id</th><th></th></tr>${userRows}</table>`;
1909
2034
  return shell(store, opts, {
1910
2035
  title: `${store.team.name} \xB7 slack-mock`,
1911
- header: topbar(escapeHtml(store.team.name), "slack-mock workspace"),
1912
- main
2036
+ header: topbar(escapeHtml(store.team.name), "slack-mock workspace", undefined, identityChip(store, opts)),
2037
+ main,
2038
+ script: opts.screenshot ? "" : uiScript(store, opts, undefined, false)
1913
2039
  });
1914
2040
  }
1915
2041
  function channelMessages(store, channel) {
@@ -1930,40 +2056,66 @@ function channelColumn(store, ctx, opts, channel, openTs) {
1930
2056
  function channelHeader(store, opts, channel) {
1931
2057
  const sub = [channel.topic.value, channel.purpose.value].filter(Boolean).join(" \xB7 ");
1932
2058
  const back = opts.screenshot ? undefined : { href: homeHref(opts), label: "\u2190 Workspace" };
1933
- return topbar(escapeHtml(channelLabel(store, channel)), escapeHtml(sub), back);
2059
+ return topbar(escapeHtml(channelLabel(store, channel)), escapeHtml(sub), back, identityChip(store, opts));
1934
2060
  }
1935
2061
  function humanUsers(store) {
1936
2062
  return [...store.users.values()].filter((u) => !u.is_bot && !u.deleted);
1937
2063
  }
2064
+ function userStatus(user) {
2065
+ return user.profile.status_text ? `<span class="sm-user-status">${escapeHtml(user.profile.status_text)}</span>` : "";
2066
+ }
2067
+ function identityChip(store, opts) {
2068
+ if (opts.screenshot)
2069
+ return "";
2070
+ const users = humanUsers(store);
2071
+ const selected = users[0];
2072
+ if (!selected)
2073
+ return "";
2074
+ const name = selected.real_name || selected.name;
2075
+ const avatar = `<span class="sm-identity-avatar" style="background:${AVATAR_COLORS[hashIndex(selected.id, AVATAR_COLORS.length)]}">${escapeHtml(initials(name))}</span>`;
2076
+ const items = users.map((u) => {
2077
+ const real = u.real_name || u.name;
2078
+ const color = AVATAR_COLORS[hashIndex(u.id, AVATAR_COLORS.length)];
2079
+ 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>`;
2080
+ }).join("");
2081
+ const hidden = opts.writeGated ? " hidden" : "";
2082
+ 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>`;
2083
+ }
1938
2084
  function composer(store, opts, channel, threadTs) {
1939
2085
  if (opts.screenshot)
1940
2086
  return "";
1941
2087
  const users = humanUsers(store);
1942
2088
  if (!users.length)
1943
2089
  return "";
1944
- const options = users.map((u, i) => `<option value="${escapeHtml(u.id)}"${i === 0 ? " selected" : ""}>${escapeHtml(u.real_name || u.name)}</option>`).join("");
1945
2090
  const placeholder = threadTs ? "Reply in thread" : `Message ${channelLabel(store, channel)}`;
1946
2091
  const thread = threadTs ? ` data-thread="${escapeHtml(threadTs)}"` : "";
1947
2092
  const gated = opts.writeGated ? ' data-gated="1"' : "";
1948
2093
  const lock = opts.writeGated ? `<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>` : "";
1949
- 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>`;
2094
+ 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>`;
1950
2095
  }
1951
2096
  function mentionData(store) {
1952
2097
  const users = [...store.users.values()].filter((u) => !u.deleted).map((u) => ({
2098
+ id: u.id,
1953
2099
  name: u.name,
1954
2100
  real: u.real_name || u.name,
1955
2101
  initials: initials(u.real_name || u.name),
1956
- color: AVATAR_COLORS[hashIndex(u.id, AVATAR_COLORS.length)]
2102
+ color: AVATAR_COLORS[hashIndex(u.id, AVATAR_COLORS.length)],
2103
+ bot: u.is_bot
1957
2104
  }));
1958
2105
  const json = JSON.stringify(users).replace(/</g, "\\u003c");
1959
2106
  return `<script type="application/json" id="sm-users">${json}</script>`;
1960
2107
  }
1961
- function uiScript(store, opts, closeUrl) {
2108
+ function uiScript(store, opts, closeUrl, autoScroll = true) {
1962
2109
  const esc = closeUrl ? `document.addEventListener("keydown",function(e){if(e.key==="Escape"&&!/^(TEXTAREA|INPUT|SELECT)$/.test(document.activeElement&&document.activeElement.tagName||""))location.href=${JSON.stringify(closeUrl)}});` : "";
1963
2110
  const body = `(function(){
2111
+ var viewport=window.visualViewport;
2112
+ 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")}
2113
+ fitViewport();addEventListener("resize",fitViewport);
2114
+ if(viewport){viewport.addEventListener("resize",fitViewport);viewport.addEventListener("scroll",fitViewport)}
2115
+ document.addEventListener("change",function(e){if(e.target.classList.contains("sm-channel-switch"))location.href=e.target.value});
1964
2116
  var W="sm-panel-w",DEF=${JSON.stringify(panelWidth(opts))},FIXED=${opts.panelWidth ? "true" : "false"};
1965
- function scroll(){document.querySelectorAll(".sm-scroll").forEach(function(el){el.scrollTop=el.scrollHeight})}
1966
- scroll();addEventListener("load",scroll);
2117
+ ${autoScroll ? `function scroll(){document.querySelectorAll(".sm-scroll").forEach(function(el){el.scrollTop=el.scrollHeight})}
2118
+ scroll();addEventListener("load",scroll);` : ""}
1967
2119
  var handle=document.querySelector(".sm-resize");
1968
2120
  if(handle){
1969
2121
  var saved=null;try{saved=localStorage.getItem(W)}catch(e){}
@@ -1975,21 +2127,54 @@ if(handle){
1975
2127
  handle.addEventListener("dblclick",function(){try{localStorage.removeItem(W)}catch(e){}document.body.style.setProperty("--sm-panel-w",DEF)});
1976
2128
  }
1977
2129
  var raw=document.getElementById("sm-users");
1978
- 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"}]);
2130
+ var USERS=raw?JSON.parse(raw.textContent||"[]"):[],HUMANS=USERS.filter(function(u){return !u.bot});
2131
+ var PEOPLE=USERS.concat([{name:"here",real:"Notify everyone online",initials:"@",color:"#616061"},{name:"channel",real:"Notify everyone in the channel",initials:"@",color:"#616061"}]);
1979
2132
  function esc(s){return String(s).replace(/[&<>"]/g,function(c){return c==="&"?"&amp;":c==="<"?"&lt;":c===">"?"&gt;":"&quot;"})}
1980
- var GATED=${opts.writeGated ? "true" : "false"},LIVE=${opts.live !== false && !opts.refreshSec ? "true" : "false"},CK="sm-presenter";
2133
+ var GATED=${opts.writeGated ? "true" : "false"},LIVE=${opts.live !== false && !opts.refreshSec ? "true" : "false"},CK="sm-presenter",IK="sm-identity",currentIdentity="",identityStorage=true;
1981
2134
  function cred(){try{return localStorage.getItem(CK)||""}catch(e){return ""}}
1982
2135
  function setCred(v){try{if(v)localStorage.setItem(CK,v);else localStorage.removeItem(CK)}catch(e){}}
2136
+ function setIdentity(v){currentIdentity=v;try{if(v)localStorage.setItem(IK,v);else localStorage.removeItem(IK)}catch(e){identityStorage=false}}
2137
+ function findIdentity(value,key){for(var i=0;i<HUMANS.length;i++)if(HUMANS[i][key]===value)return HUMANS[i];return null}
2138
+ 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}
2139
+ (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)}})();
1983
2140
  (function(){var m=/[#&]presenter=([^&]+)/.exec(location.hash||"");if(m){setCred(btoa(decodeURIComponent(m[1])));history.replaceState(null,"",location.pathname+location.search)}})();
1984
2141
  function authHeaders(h){var c=cred();if(c)h.authorization="Basic "+c;return h}
1985
- 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?' \xB7 signed in \xB7 <a href="#" class="sm-lock-out">Sign out</a>':""})}
2142
+ var reactionDialog=document.querySelector(".sm-reaction-picker"),reactionTarget=null,reactionScope=null,reactionBusy=false;
2143
+ 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})}
2144
+ 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}
2145
+ function positionReactions(){
2146
+ if(!reactionDialog||!reactionDialog.open||!reactionTarget)return;
2147
+ if(!reactionTarget.isConnected){reactionTarget=findMessageElement(reactionScope,reactionTarget.dataset.ts);if(!reactionTarget){closeReactions();return}}
2148
+ 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;
2149
+ if(anchor.bottom<=Math.max(top,scope.top)||anchor.top>=Math.min(top+height,scope.bottom)){closeReactions();return}
2150
+ reactionDialog.style.maxWidth=Math.max(0,width-pad*2)+"px";reactionDialog.style.maxHeight=Math.max(0,height-pad*2)+"px";
2151
+ var rect=reactionDialog.getBoundingClientRect(),x=Math.max(left+pad,Math.min(anchor.right-rect.width,left+width-rect.width-pad)),y=anchor.bottom+gap;
2152
+ if(y+rect.height>top+height-pad)y=anchor.top-rect.height-gap;
2153
+ reactionDialog.style.left=x+"px";reactionDialog.style.top=Math.max(top+pad,Math.min(y,top+height-rect.height-pad))+"px";
2154
+ }
2155
+ document.addEventListener("scroll",function(e){if(!reactionDialog.contains(e.target))positionReactions()},true);
2156
+ addEventListener("resize",positionReactions);
2157
+ if(window.visualViewport){window.visualViewport.addEventListener("resize",positionReactions);window.visualViewport.addEventListener("scroll",positionReactions)}
2158
+ document.addEventListener("pointerdown",function(e){if(reactionDialog.open&&!reactionDialog.contains(e.target)&&!e.target.closest(".sm-add-reaction"))closeReactions()});
2159
+ document.addEventListener("focusin",function(e){if(reactionDialog.open&&!reactionDialog.contains(e.target)&&(!reactionTarget||e.target!==reactionTarget.querySelector(".sm-add-reaction")))closeReactions()});
2160
+ function hasReaction(button,user){return JSON.parse(button.dataset.users||"[]").indexOf(user)!==-1}
2161
+ 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()}
2162
+ 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()}
2163
+ 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?' \xB7 signed in \xB7 <a href="#" class="sm-lock-out">Sign out</a>':""});identityUi()}
1986
2164
  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})}
1987
- 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"))});
2165
+ 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"))});
2166
+ 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()});
2167
+ document.addEventListener("keydown",function(e){if(e.key==="Escape"&&reactionDialog&&reactionDialog.open){e.preventDefault();e.stopImmediatePropagation();closeReactions(true)}});
1988
2168
  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"))}});
2169
+ addEventListener("storage",function(e){if(e.key===IK){currentIdentity=e.newValue||"";identityUi()}});
1989
2170
  lockUi();
1990
2171
  var pending=null;
1991
- 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)}
1992
- 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}
2172
+ 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)}
2173
+ function apply(html){
2174
+ 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");
2175
+ 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;
2176
+ if(focusedMessage&&!opener.isConnected){var message=findMessageElement(focusedScope,focusedMessage.dataset.ts);if(message)message.querySelector(".sm-add-reaction").focus({preventScroll:true})}
2177
+ }
1993
2178
  if(LIVE&&window.EventSource){
1994
2179
  var box0=document.querySelector(".sm-composer"),pm=/^\\/c\\/([^/]+)/.exec(location.pathname),chan=box0?box0.dataset.channel:(pm?decodeURIComponent(pm[1]):null);
1995
2180
  if(chan){
@@ -2001,7 +2186,23 @@ if(LIVE&&window.EventSource){
2001
2186
  es.onerror=function(){down=true;if(dot){dot.textContent="\u25CF reconnecting";dot.classList.add("sm-live-off")}};
2002
2187
  }
2003
2188
  }
2004
- 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})}
2189
+ function react(message,name){
2190
+ var u=identity();if(!message||!u||reactionBusy||(GATED&&!cred()))return;
2191
+ var action="add";message.querySelectorAll(".sm-reaction[data-reaction]").forEach(function(button){if(button.dataset.reaction===name&&hasReaction(button,u.id))action="remove"});
2192
+ var err=(reactionDialog&&reactionDialog.open?reactionDialog:message).querySelector(".sm-action-error");if(err){err.hidden=true;err.textContent=""}
2193
+ reactionBusy=true;reactionUi();
2194
+ 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){
2195
+ if(r.status===401||r.status===403){setCred("");lockUi();throw new Error("Sign in to react.")}
2196
+ 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.")})
2197
+ }).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()}})
2198
+ }
2199
+ document.addEventListener("click",function(e){
2200
+ 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}
2201
+ 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}
2202
+ if(e.target.closest(".sm-reaction-close")){closeReactions(true);return}
2203
+ 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()
2204
+ });
2205
+ 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})}
2005
2206
  document.querySelectorAll(".sm-composer").forEach(function(box){
2006
2207
  var ta=box.querySelector(".sm-composer-text"),menu=box.querySelector(".sm-mentions"),items=[],active=0;
2007
2208
  function close(){items=[];menu.style.display="none"}
@@ -2037,7 +2238,7 @@ document.querySelectorAll(".sm-composer").forEach(function(box){
2037
2238
  box.querySelector(".sm-composer-send").addEventListener("click",function(){send(box)});
2038
2239
  });
2039
2240
  })();`;
2040
- return `${mentionData(store)}<script>${body}${esc}</script>`;
2241
+ return `${mentionData(store)}${reactionPicker()}<script>${body}${esc}</script>`;
2041
2242
  }
2042
2243
  function channelView(store, opts, channelId) {
2043
2244
  const channel = store.channels.get(channelId);
@@ -2103,7 +2304,7 @@ function threadView(store, opts, channelId, ts) {
2103
2304
  const close = channelHref(channel.id, opts);
2104
2305
  const title = `Thread \xB7 ${label}`;
2105
2306
  if (opts.threadView === "full") {
2106
- const header = topbar(`Thread <span class="sm-muted">\xB7</span> ${escapeHtml(label)}`, "", { href: close, label: `\u2190 ${label}` }, `<a class="sm-icon-btn" href="${threadHref(channel.id, ts, opts, { full: false })}" title="Collapse to panel" aria-label="Collapse to panel">\u2921</a>`);
2307
+ const header = topbar(`Thread <span class="sm-muted">\xB7</span> ${escapeHtml(label)}`, "", { href: close, label: `\u2190 ${label}` }, `<a class="sm-icon-btn" href="${threadHref(channel.id, ts, opts, { full: false })}" title="Collapse to panel" aria-label="Collapse to panel">\u2921</a>${identityChip(store, opts)}`);
2107
2308
  return shell(store, opts, {
2108
2309
  title,
2109
2310
  header,
@@ -2114,7 +2315,7 @@ function threadView(store, opts, channelId, ts) {
2114
2315
  });
2115
2316
  }
2116
2317
  const expand = threadHref(channel.id, ts, opts, { full: true });
2117
- 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">\u2922</a><a class="sm-panel-close" href="${close}" title="Close thread">\xD7</a></div><a class="sm-panel-back" href="${close}">\u2190 ${escapeHtml(label)}</a><div class="sm-panel-body sm-scroll">${body}</div>${composer(store, opts, channel, ts)}</aside>`;
2318
+ const panel = `<aside class="sm-panel"><div class="sm-panel-top"><a class="sm-panel-back" href="${close}" aria-label="Back to ${escapeHtml(label)}">\u2190</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">\u2922</a><a class="sm-panel-close" href="${close}" title="Close thread">\xD7</a></div><div class="sm-panel-body sm-scroll">${body}</div>${composer(store, opts, channel, ts)}</aside>`;
2118
2319
  return shell(store, opts, {
2119
2320
  title,
2120
2321
  header: channelHeader(store, opts, channel),
@@ -3055,7 +3256,7 @@ class SlackMock2 {
3055
3256
  try {
3056
3257
  const isUiSurface = path === "/" || path === "" || path.startsWith("/c/");
3057
3258
  const isAdminSurface = path.startsWith("/mock/") || isUiSurface && !this.opts.publicUi;
3058
- const isPresenterRoute = path === "/mock/messages" && req.method === "POST" || path === "/mock/presenter";
3259
+ const isPresenterRoute = (path === "/mock/messages" || path === "/mock/reactions") && req.method === "POST" || path === "/mock/presenter";
3059
3260
  const allowed = isPresenterRoute ? this.authorizedPresenter(req) : this.authorizedAdmin(req);
3060
3261
  if (isAdminSurface && !allowed)
3061
3262
  return denied(req, path);
@@ -3549,6 +3750,11 @@ data: ${JSON.stringify(data)}
3549
3750
  this.store.addReaction(this.resolveChannel(input.channel).id, input.ts, input.name, user.id);
3550
3751
  await this.flush();
3551
3752
  }
3753
+ async removeReaction(input) {
3754
+ const user = input.user ? this.user(input.user) : this.defaultHuman();
3755
+ this.store.removeReaction(this.resolveChannel(input.channel).id, input.ts, input.name, user.id);
3756
+ await this.flush();
3757
+ }
3552
3758
  issueResponseUrl(target) {
3553
3759
  const id = `${this.store.team.id}/${slackId("", 10)}/${slackId("", 24).toLowerCase()}`;
3554
3760
  this.responseUrls.set(id, { ...target, expires: Date.now() + 30 * 60000 });
@@ -3827,7 +4033,13 @@ data: ${JSON.stringify(data)}
3827
4033
  if (path === "assistant/start" && req.method === "POST")
3828
4034
  return json(await this.startAssistantThread(body));
3829
4035
  if (path === "reactions" && req.method === "POST") {
3830
- await this.addReaction(body);
4036
+ const input = body;
4037
+ if (input.action !== undefined && input.action !== "add" && input.action !== "remove")
4038
+ throw new SlackApiError2("invalid_arguments");
4039
+ if (input.action === "remove")
4040
+ await this.removeReaction(input);
4041
+ else
4042
+ await this.addReaction(input);
3831
4043
  return json({ ok: true });
3832
4044
  }
3833
4045
  if (path === "api-calls")
package/dist/index.js CHANGED
@@ -4,11 +4,11 @@ import {
4
4
  Store2,
5
5
  SlackMock2,
6
6
  frames2
7
- } from "./index-6c88z809.js";
7
+ } from "./index-y82vvfa1.js";
8
8
  import {
9
9
  findChrome2,
10
10
  screenshot2
11
- } from "./index-v2hesj4s.js";
11
+ } from "./index-xs37gskt.js";
12
12
  export {
13
13
  SlackApiError2 as SlackApiError,
14
14
  SlackMock2 as SlackMock,
@@ -3,7 +3,7 @@ import {
3
3
  findChrome2,
4
4
  requireChrome2,
5
5
  screenshot2
6
- } from "./index-v2hesj4s.js";
6
+ } from "./index-xs37gskt.js";
7
7
  export {
8
8
  findChrome2 as findChrome,
9
9
  requireChrome2 as requireChrome,