@phnx-labs/artifacts-cli 0.15.0 → 0.16.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.
- package/CHANGELOG.md +24 -0
- package/dist/commands/comments.d.ts +2 -0
- package/dist/commands/comments.js +4 -1
- package/dist/commands/comments.js.map +1 -1
- package/dist/commands/share.d.ts +2 -4
- package/dist/commands/share.js +11 -11
- package/dist/commands/share.js.map +1 -1
- package/dist/lib/collab.d.ts +3 -2
- package/dist/lib/collab.js +727 -535
- package/dist/lib/collab.js.map +1 -1
- package/dist/lib/selection-toolbar.d.ts +4 -4
- package/dist/lib/selection-toolbar.js +13 -22
- package/dist/lib/selection-toolbar.js.map +1 -1
- package/dist/lib/share/media-core.js +0 -25
- package/dist/lib/share/media-core.js.map +1 -1
- package/dist/lib/share/worker-media-template.js +9 -6
- package/dist/lib/share/worker-media-template.js.map +1 -1
- package/dist/lib/share/worker-template.js +69 -168
- package/dist/lib/share/worker-template.js.map +1 -1
- package/package.json +1 -1
package/dist/lib/collab.js
CHANGED
|
@@ -12,8 +12,9 @@ import { createHash } from 'node:crypto';
|
|
|
12
12
|
*
|
|
13
13
|
* GET /__collab/context?share=<encoded path>
|
|
14
14
|
* GET /__collab/threads?share=<path>[&after=<cursor>]
|
|
15
|
-
*
|
|
16
|
-
* POST /__collab/threads
|
|
15
|
+
* GET /__collab/members?share=<path>&q= people to tag
|
|
16
|
+
* POST /__collab/threads { share, anchor, body?, mentions? } no body: a highlight
|
|
17
|
+
* POST /__collab/threads/:threadId/replies { share, body, mentions? }
|
|
17
18
|
* PATCH /__collab/comments/:commentId { share, body } | { share, deleted: true }
|
|
18
19
|
* PATCH /__collab/threads/:threadId { share, status: "open" | "resolved" }
|
|
19
20
|
* GET /__collab/events?share=<path> (text/event-stream)
|
|
@@ -79,67 +80,133 @@ export function visibilityLabel(value) {
|
|
|
79
80
|
};
|
|
80
81
|
return typeof value === 'string' && Object.prototype.hasOwnProperty.call(labels, value) ? labels[value] : null;
|
|
81
82
|
}
|
|
83
|
+
// The comment box, history card and margin pins are share chrome, the console's
|
|
84
|
+
// menu panel surface (rush/console SharePanel.tsx) whatever theme the page has;
|
|
85
|
+
// marks are the one gold. The thread list keeps the page's own colours.
|
|
86
|
+
const FONT = '"ash-inter",Inter,system-ui,-apple-system,"Segoe UI",sans-serif';
|
|
82
87
|
const COLLAB_CSS = [
|
|
83
|
-
|
|
84
|
-
'.collab-
|
|
85
|
-
'.collab-mark{background:
|
|
86
|
-
'.collab-mark.is-
|
|
87
|
-
'.collab-mark.is-
|
|
88
|
-
'.collab-mark
|
|
88
|
+
'.collab-rail,.collab-rail *,.collab-pop,.collab-pop *,.collab-pin{box-sizing:border-box}',
|
|
89
|
+
'.collab-mark{background:rgba(201,169,98,.24);border-bottom:2px solid rgba(201,169,98,.9);color:inherit;border-radius:2px;box-decoration-break:clone;-webkit-box-decoration-break:clone;cursor:pointer;transition:background .2s}',
|
|
90
|
+
'.collab-mark.is-highlight,.collab-mark.is-draft{background:rgba(201,169,98,.14)}',
|
|
91
|
+
'.collab-mark:hover,.collab-mark.is-selected{background:rgba(201,169,98,.4)}',
|
|
92
|
+
'.collab-mark.is-resolved{background:none;border-bottom:1px dashed rgba(201,169,98,.6)}',
|
|
93
|
+
'.collab-mark.is-pulse{animation:collab-pulse 1.1s cubic-bezier(.22,1,.36,1) 2}',
|
|
94
|
+
'.collab-mark:focus-visible{outline:2px solid #c9a962;outline-offset:2px}',
|
|
95
|
+
// The box at a selection and a thread's history.
|
|
96
|
+
`.collab-pop{position:fixed;z-index:2147483000;width:360px;max-width:calc(100vw - 24px);border-radius:16px;border:1px solid rgba(255,255,255,.12);background:rgba(20,20,24,.97);-webkit-backdrop-filter:blur(28px);backdrop-filter:blur(28px);box-shadow:0 24px 60px -20px rgba(0,0,0,.95);color:#fff;font:13px/1.45 ${FONT};text-align:left;-webkit-font-smoothing:antialiased;animation:collab-in .2s cubic-bezier(.22,1,.36,1)}`,
|
|
97
|
+
'.collab-pop[hidden]{display:none}',
|
|
98
|
+
'.collab-pop.is-floating{top:72px;left:50%;transform:translateX(-50%)}',
|
|
99
|
+
'.collab-pop button,.collab-pin{font:inherit;color:inherit;background:none;border:0;margin:0;cursor:pointer}',
|
|
100
|
+
'.collab-pop button:focus-visible,.collab-pop a:focus-visible,.collab-pin:focus-visible{outline:2px solid rgba(255,255,255,.3);outline-offset:2px}',
|
|
101
|
+
'.collab-pop svg,.collab-rail svg,.collab-launcher svg{flex:none;display:block}',
|
|
102
|
+
'.collab-field{display:flex;align-items:flex-end;gap:8px;padding:8px 8px 8px 10px}',
|
|
103
|
+
'.collab-field>.collab-face{margin-bottom:3px}',
|
|
104
|
+
'.collab-face{position:relative;display:grid;place-items:center;flex:none;width:24px;height:24px;border-radius:22.5%;border:1px solid rgba(255,255,255,.14);background:#27272a;color:#f4f4f5;font:600 11px/1 ' + FONT + '}',
|
|
105
|
+
'.collab-face img{width:100%;height:100%;border-radius:inherit;object-fit:cover}',
|
|
106
|
+
'.collab-face.sm{width:20px;height:20px;font-size:10px}',
|
|
107
|
+
'.collab-globe{position:absolute;right:-4px;bottom:-4px;display:grid;place-items:center;width:14px;height:14px;border-radius:22.5%;border:1px solid #09090b;background:#3f3f46;color:#e4e4e7}',
|
|
108
|
+
'.collab-input{flex:1;min-width:0;max-height:140px;overflow-y:auto;padding:5px 0;font-size:13.5px;line-height:1.45;color:#fff;outline:none;white-space:pre-wrap;overflow-wrap:anywhere;cursor:text}',
|
|
109
|
+
'.collab-input:empty::before{content:attr(data-placeholder);color:#71717a}',
|
|
110
|
+
'.collab-chip{display:inline-block;padding:0 5px;border-radius:6px;background:rgba(201,169,98,.16);color:#e8d29a;font-weight:500;white-space:nowrap}',
|
|
111
|
+
'.collab-act{display:inline-flex;align-items:center;gap:6px;height:30px;padding:0 12px;border-radius:999px !important;border:1px solid rgba(255,255,255,.08) !important;color:#d4d4d8 !important;font-size:12.5px !important;white-space:nowrap;transition:background .15s,border-color .15s}',
|
|
112
|
+
'.collab-act:hover{border-color:rgba(255,255,255,.25) !important;color:#fff !important}',
|
|
113
|
+
'.collab-act.send{width:30px;padding:0;justify-content:center;border-color:#fff !important;background:#fff !important;color:#09090b !important}',
|
|
114
|
+
'.collab-act.send:hover{background:#e4e4e7 !important}',
|
|
115
|
+
'.collab-act:disabled{opacity:.5;cursor:default}',
|
|
116
|
+
// People: the console share panel's suggestions, grouped as its people are.
|
|
117
|
+
'.collab-people{position:relative;margin:0 6px 6px;padding:4px;border-radius:12px;border:1px solid rgba(255,255,255,.08);background:#09090b;max-height:300px;overflow-y:auto;list-style:none}',
|
|
118
|
+
'.collab-people[hidden]{display:none}',
|
|
119
|
+
'.collab-label{display:flex;align-items:center;gap:6px;padding:8px 8px 4px;font-size:11px;font-weight:500;letter-spacing:.08em;text-transform:uppercase;color:#a1a1aa}',
|
|
120
|
+
'.collab-label b{font-weight:500;color:#71717a}',
|
|
121
|
+
'.collab-row{position:relative;z-index:1;display:flex;align-items:center;gap:8px;padding:6px 8px;border-radius:10px;cursor:pointer}',
|
|
122
|
+
'.collab-row .collab-name{min-width:0;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:13px;color:#fff}',
|
|
123
|
+
'.collab-row .collab-mail{min-width:0;max-width:46%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:12px;color:#a1a1aa}',
|
|
124
|
+
'.collab-row.is-locked .collab-face{opacity:.55}.collab-row.is-locked .collab-name{color:#a1a1aa}',
|
|
125
|
+
'.collab-pill{position:absolute;z-index:0;left:4px;right:4px;top:0;border-radius:10px;background:rgba(255,255,255,.07);pointer-events:none;transition:transform .3s cubic-bezier(.22,1,.36,1),height .3s cubic-bezier(.22,1,.36,1)}',
|
|
126
|
+
'.collab-guest{display:inline-flex;align-items:center;gap:4px;flex:none;padding:2px 8px;border-radius:999px;border:1px dashed rgba(255,255,255,.25);font-size:11px;color:#d4d4d8}',
|
|
127
|
+
'.collab-add{flex:none;display:inline-flex;align-items:center;gap:4px;height:26px;padding:0 10px;border-radius:999px;border:1px solid rgba(255,255,255,.08);font-size:12px;color:#d4d4d8;text-decoration:none}',
|
|
128
|
+
'.collab-row[aria-selected="true"] .collab-add,.collab-add:hover{border-color:rgba(255,255,255,.3);color:#fff}',
|
|
129
|
+
'.collab-none{padding:10px 8px;font-size:12px;color:#a1a1aa}',
|
|
130
|
+
// A thread's history.
|
|
131
|
+
'.collab-card-head{display:flex;align-items:center;gap:6px;padding:10px 8px 4px 14px}',
|
|
132
|
+
'.collab-card-head .collab-quote{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:12px;color:#a1a1aa}',
|
|
133
|
+
'.collab-icon{display:grid;place-items:center;width:28px;height:28px;border-radius:999px;color:#a1a1aa;transition:background .15s,color .15s}',
|
|
134
|
+
'.collab-icon:hover{background:rgba(255,255,255,.06);color:#fff}',
|
|
135
|
+
'.collab-icon[aria-pressed="true"]{color:#6ee7b7}',
|
|
136
|
+
'.collab-entries{list-style:none;margin:0;padding:6px 14px 8px;display:grid;gap:12px;max-height:280px;overflow-y:auto}',
|
|
137
|
+
'.collab-entry{display:flex;gap:10px}',
|
|
138
|
+
'.collab-entry>div{min-width:0;flex:1}',
|
|
139
|
+
'.collab-who{font-size:12px;color:#a1a1aa}.collab-who b{font-weight:500;color:#fff}',
|
|
140
|
+
'.collab-entry.is-note .collab-who{padding-top:2px}',
|
|
141
|
+
'.collab-text{margin:2px 0 0;font-size:13.5px;color:#e4e4e7;white-space:pre-wrap;overflow-wrap:anywhere}',
|
|
142
|
+
'.collab-text.is-muted{color:#71717a;font-style:italic}',
|
|
143
|
+
'.collab-entry-head{display:flex;align-items:center;gap:6px;min-height:20px}',
|
|
144
|
+
'.collab-entry-head .collab-entry-acts{margin:0 -6px 0 auto}',
|
|
145
|
+
'.collab-entry-acts{display:flex;gap:2px;margin:4px 0 0 -6px;opacity:0;transition:opacity .15s}',
|
|
146
|
+
'.collab-entry:hover .collab-entry-acts,.collab-entry:focus-within .collab-entry-acts,.collab-entry-acts.is-shown{opacity:1}',
|
|
147
|
+
'@media(hover:none){.collab-entry-acts{opacity:1}}',
|
|
148
|
+
'.collab-entry-acts button{height:20px;padding:0 6px;border-radius:6px;font-size:12px;color:#a1a1aa}',
|
|
149
|
+
'.collab-entry-acts button:hover{background:rgba(255,255,255,.06);color:#fff}',
|
|
150
|
+
'.collab-edit{width:100%;min-height:56px;margin-top:4px;padding:6px 8px;border:1px solid rgba(255,255,255,.12);border-radius:8px;background:rgba(255,255,255,.04);color:#fff;font:13.5px/1.45 ' + FONT + ';resize:vertical}',
|
|
151
|
+
'.collab-edit:focus-visible{outline:0;border-color:rgba(201,169,98,.6)}',
|
|
152
|
+
'.collab-stale{margin:0;padding:0 14px 4px;font-size:12px;color:#71717a}',
|
|
153
|
+
'.collab-sep{height:1px;background:rgba(255,255,255,.08)}',
|
|
154
|
+
'.collab-error{margin:0;padding:0 14px 10px;font-size:12px;color:#fca5a5}',
|
|
155
|
+
// Pins in the margin: whose comment, how many.
|
|
156
|
+
`.collab-pin{position:absolute;z-index:30;display:flex;align-items:center;gap:4px;padding:2px 7px 2px 2px;border-radius:999px;border:1px solid rgba(255,255,255,.12);background:#09090b;box-shadow:0 4px 12px rgba(0,0,0,.25);font:600 11px/1 ${FONT};color:#e4e4e7;animation:collab-in .25s cubic-bezier(.22,1,.36,1)}`,
|
|
157
|
+
'.collab-pin:hover{border-color:rgba(255,255,255,.3)}',
|
|
158
|
+
'.collab-pin.is-resolved{opacity:.5}',
|
|
159
|
+
// Every thread on the page, from the bar's Comments button or the launcher.
|
|
89
160
|
'.collab-rail{position:fixed;top:0;right:0;z-index:35;display:flex;flex-direction:column;width:var(--collab-rail-width);height:100vh;border-left:1px solid var(--line,#ddd);background:var(--surface,#fff);color:var(--text,#111);font:13px/1.5 var(--font-body,sans-serif)}',
|
|
90
161
|
'.collab-rail[hidden],.collab-launcher[hidden]{display:none}',
|
|
91
|
-
'.collab-head{display:flex;
|
|
92
|
-
'.collab-head-title{font
|
|
93
|
-
'.collab-visibility{
|
|
162
|
+
'.collab-head{display:flex;align-items:center;gap:8px;padding:12px 12px 12px 16px;border-bottom:1px solid var(--line,#ddd)}',
|
|
163
|
+
'.collab-head-title{font-weight:600}',
|
|
164
|
+
'.collab-visibility{padding:2px 8px;border-radius:999px;background:color-mix(in srgb,var(--muted,#666) 12%,transparent);font-size:11px;color:var(--muted,#666)}',
|
|
94
165
|
'.collab-visibility[hidden]{display:none}',
|
|
95
|
-
'.collab-
|
|
96
|
-
'.collab-
|
|
97
|
-
'.collab-
|
|
98
|
-
'.collab-rail
|
|
99
|
-
'.collab-rail
|
|
100
|
-
'.collab-
|
|
101
|
-
'.collab-
|
|
102
|
-
'.collab-
|
|
103
|
-
'.collab-
|
|
104
|
-
'.collab-
|
|
105
|
-
'.collab-
|
|
106
|
-
'.collab-stale{
|
|
107
|
-
'.collab-
|
|
108
|
-
'.collab-
|
|
109
|
-
'.collab-author{color:var(--text,#111)}',
|
|
110
|
-
'.collab-body{margin:3px 0 0;white-space:pre-wrap;overflow-wrap:anywhere}',
|
|
111
|
-
'.collab-body.is-deleted,.collab-body.is-pending{color:var(--muted,#666);font-style:italic}',
|
|
112
|
-
'.collab-actions{display:flex;flex-wrap:wrap;gap:6px;margin-top:8px}',
|
|
113
|
-
'.collab-rail textarea{width:100%;min-height:60px;resize:vertical;border:1px solid var(--line,#ddd);border-radius:8px;padding:8px;background:var(--bg,#fff);color:inherit;font:13px/1.45 var(--font-body,sans-serif)}',
|
|
114
|
-
'.collab-rail textarea:focus-visible{outline:2px solid var(--accent,#16a34a);outline-offset:1px}',
|
|
115
|
-
'.collab-empty{margin:14px 12px;color:var(--muted,#666)}',
|
|
116
|
-
'.collab-error{margin:6px 0 0;color:var(--danger,#b91c1c);font:500 11.5px/1.4 var(--font-mono,monospace)}',
|
|
117
|
-
'.collab-mentions{margin:6px 0 0;padding:4px;list-style:none;max-height:220px;overflow-y:auto;border:1px solid var(--line,#ddd);border-radius:10px;background:var(--surface,#fff);box-shadow:0 8px 26px rgba(0,0,0,.14)}',
|
|
118
|
-
'.collab-mentions[hidden]{display:none}',
|
|
119
|
-
'.collab-mention{display:flex;align-items:center;gap:9px;padding:6px 8px;border-radius:7px;cursor:pointer}',
|
|
120
|
-
'.collab-mention[aria-selected="true"]{background:color-mix(in srgb,var(--accent-alt,#3b82f6) 14%,transparent)}',
|
|
121
|
-
'.collab-mention-avatar{flex:none;display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;border-radius:999px;object-fit:cover;background:var(--surface-alt,#eee);color:var(--muted,#666);font:600 10px/1 var(--font-mono,monospace)}',
|
|
122
|
-
'.collab-mention-name{color:var(--text,#111);font-weight:600}',
|
|
123
|
-
'.collab-mention-email{display:block;color:var(--muted,#666);font-size:11.5px;overflow-wrap:anywhere}',
|
|
124
|
-
'.collab-provenance{padding:10px 16px;border-top:1px solid var(--line,#ddd);color:var(--muted,#666);font:11px/1.5 var(--font-mono,monospace);overflow-wrap:anywhere}',
|
|
166
|
+
'.collab-close{margin-left:auto;display:grid;place-items:center;width:28px;height:28px;padding:0;border:0;border-radius:999px;background:none;color:var(--muted,#666);cursor:pointer}',
|
|
167
|
+
'.collab-close:hover{background:color-mix(in srgb,var(--muted,#666) 14%,transparent)}',
|
|
168
|
+
'.collab-list{flex:1;overflow-y:auto;margin:0;padding:8px;list-style:none}',
|
|
169
|
+
'.collab-rail .collab-item{display:grid;gap:6px;width:100%;height:auto;margin:0 0 2px;padding:10px 12px;border:0;border-radius:10px;background:none;color:inherit;font:inherit;line-height:1.45;text-align:left;cursor:pointer}',
|
|
170
|
+
'.collab-rail .collab-item:hover,.collab-rail .collab-item.is-selected{background:color-mix(in srgb,var(--muted,#888) 10%,transparent)}',
|
|
171
|
+
'.collab-rail .collab-item.is-resolved{opacity:.55}',
|
|
172
|
+
'.collab-rail button:focus-visible,.collab-launcher:focus-visible{outline:2px solid #c9a962;outline-offset:2px}',
|
|
173
|
+
'.collab-item .collab-quote{padding-left:8px;border-left:2px solid rgba(201,169,98,.6);font-size:12px;color:var(--muted,#666);overflow-wrap:anywhere}',
|
|
174
|
+
'.collab-item .collab-last{display:flex;gap:8px;align-items:flex-start;font-size:13px;overflow-wrap:anywhere}',
|
|
175
|
+
'.collab-item .collab-last b{font-weight:600}',
|
|
176
|
+
'.collab-dim{color:var(--muted,#666);font-size:12px}',
|
|
177
|
+
'.collab-rail .collab-stale{padding:0;color:var(--muted,#666)}',
|
|
178
|
+
'.collab-empty{margin:16px;color:var(--muted,#666)}',
|
|
179
|
+
'.collab-provenance{margin:0;padding:10px 16px;border-top:1px solid var(--line,#ddd);color:var(--muted,#666);font:11px/1.5 var(--font-mono,monospace);overflow-wrap:anywhere}',
|
|
125
180
|
'.collab-provenance[hidden]{display:none}',
|
|
126
|
-
'.collab-launcher{position:fixed;right:18px;bottom:18px;z-index:34;display:inline-flex;align-items:center;gap:7px;height:38px;padding:0 15px;border:1px solid var(--line,#ddd);border-radius:999px;background:var(--surface,#fff);color:var(--text,#111);font:600 12px/1 var(--font-
|
|
127
|
-
'.collab-count{
|
|
181
|
+
'.collab-launcher{position:fixed;right:18px;bottom:18px;z-index:34;display:inline-flex;align-items:center;gap:7px;height:38px;padding:0 15px;border:1px solid var(--line,#ddd);border-radius:999px;background:var(--surface,#fff);color:var(--text,#111);font:600 12px/1 var(--font-body,sans-serif);box-shadow:0 8px 26px rgba(0,0,0,.16);cursor:pointer}',
|
|
182
|
+
'.collab-count{font-variant-numeric:tabular-nums}',
|
|
128
183
|
'.collab-live{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}',
|
|
184
|
+
'@keyframes collab-in{from{opacity:0;translate:0 4px}to{opacity:1;translate:0 0}}',
|
|
185
|
+
'@keyframes collab-pulse{0%{box-shadow:0 0 0 0 rgba(201,169,98,.6)}100%{box-shadow:0 0 0 10px rgba(201,169,98,0)}}',
|
|
129
186
|
'@media(min-width:981px){body.collab-rail-open{padding-right:var(--collab-rail-width)}body.collab-rail-open .collab-launcher{display:none}}',
|
|
130
187
|
// The contents rail is fixed and centres itself on the viewport, while the
|
|
131
|
-
// open
|
|
132
|
-
// the article back the width the
|
|
133
|
-
//
|
|
134
|
-
// than landing on top of the prose.
|
|
188
|
+
// open thread list re-centres the article inside the remaining column. Give
|
|
189
|
+
// the article back the width the list took before letting the two fixed
|
|
190
|
+
// rails coexist; below that, the contents rail returns inline.
|
|
135
191
|
'@media(min-width:981px) and (max-width:1719px){body.collab-rail-open .toc{position:static;width:auto;max-height:none;margin:24px 0 8px;overflow:visible}}',
|
|
136
192
|
'@media(min-width:1720px){body.collab-rail-open .toc{left:max(20px,calc(50% - var(--content-width)/2 - 236px - var(--collab-rail-width)/2))}}',
|
|
137
|
-
|
|
138
|
-
//
|
|
139
|
-
'@media(max-width:
|
|
140
|
-
'@media(prefers-reduced-motion:reduce){.collab-
|
|
141
|
-
'@media print{.collab-rail,.collab-launcher{display:none}.collab-mark{background:none;border-bottom:1px solid var(--line,#ddd)}}',
|
|
193
|
+
'@media(max-width:980px){.collab-rail{top:auto;bottom:0;left:0;width:auto;height:auto;max-height:72vh;border-left:none;border-top:1px solid var(--line,#ddd);border-radius:16px 16px 0 0;box-shadow:0 -10px 34px rgba(0,0,0,.22)}}',
|
|
194
|
+
// A phone gets sheets from the bottom and no margin pins.
|
|
195
|
+
'@media(max-width:640px){.collab-pop,.collab-pop.is-floating{left:8px !important;right:8px;top:auto !important;bottom:8px;width:auto;max-width:none;transform:none;border-radius:20px}.collab-pin{display:none}}',
|
|
196
|
+
'@media(prefers-reduced-motion:reduce){.collab-pop,.collab-pin,.collab-pill,.collab-mark,.collab-rail,.collab-launcher{transition:none !important;animation:none !important}}',
|
|
197
|
+
'@media print{.collab-rail,.collab-launcher,.collab-pop,.collab-pins{display:none}.collab-mark{background:none;border-bottom:1px solid var(--line,#ddd)}}',
|
|
142
198
|
].join('');
|
|
199
|
+
// Lucide glyphs at the 1.5 stroke rush/DESIGN.md sets for every interface icon.
|
|
200
|
+
const ICON_PATHS = {
|
|
201
|
+
send: '<path d="m5 12 7-7 7 7"/><path d="M12 19V5"/>',
|
|
202
|
+
highlight: '<path d="m9 11-6 6v3h9l3-3"/><path d="m22 12-4.6 4.6a2 2 0 0 1-2.8 0l-5.2-5.2a2 2 0 0 1 0-2.8L14 4"/>',
|
|
203
|
+
resolve: '<circle cx="12" cy="12" r="10"/><path d="m9 12 2 2 4-4"/>',
|
|
204
|
+
close: '<path d="M18 6 6 18"/><path d="m6 6 12 12"/>',
|
|
205
|
+
globe: '<circle cx="12" cy="12" r="10"/><path d="M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"/><path d="M2 12h20"/>',
|
|
206
|
+
lock: '<rect width="18" height="11" x="3" y="11" rx="2"/><path d="M7 11V7a5 5 0 0 1 10 0v4"/>',
|
|
207
|
+
out: '<path d="M7 7h10v10"/><path d="M7 17 17 7"/>',
|
|
208
|
+
comments: '<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/>',
|
|
209
|
+
};
|
|
143
210
|
export const COLLAB_SCRIPT = `<script>
|
|
144
211
|
(() => {
|
|
145
212
|
const reader = window.__artifactsReader;
|
|
@@ -154,27 +221,68 @@ export const COLLAB_SCRIPT = `<script>
|
|
|
154
221
|
const share = normalizeSharePath(location.pathname);
|
|
155
222
|
const revision = document.querySelector('meta[name=${JSON.stringify(BODY_REVISION_META)}]')?.content || '';
|
|
156
223
|
const endpoint = (path, params) => path + '?' + new URLSearchParams(params).toString();
|
|
224
|
+
// A page cannot grant access: any page's script runs on this origin and could
|
|
225
|
+
// add itself. The owner adds a tagged teammate in the console's Share panel.
|
|
226
|
+
const CONSOLE_SHARE = 'https://cloud.getrush.ai/console/artifacts';
|
|
227
|
+
const ICONS = ${JSON.stringify(ICON_PATHS)};
|
|
228
|
+
const icon = (name, size) => '<svg width="' + size + '" height="' + size + '" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' + ICONS[name] + '</svg>';
|
|
157
229
|
|
|
158
230
|
const threads = new Map();
|
|
159
231
|
const seen = new Set();
|
|
232
|
+
// Display names by actor id, from authors and the people list, so a tag in
|
|
233
|
+
// the history reads as a name.
|
|
234
|
+
const names = new Map();
|
|
160
235
|
let context = null;
|
|
161
236
|
let cursor = '';
|
|
162
237
|
let appliedEvents = 0;
|
|
163
|
-
let filter = 'open';
|
|
164
|
-
let selected = null;
|
|
165
|
-
let draft = null;
|
|
166
238
|
let stream = null;
|
|
167
|
-
//
|
|
168
|
-
//
|
|
169
|
-
|
|
170
|
-
let
|
|
239
|
+
// What the box shows: { kind: 'compose', anchor } at a selection, or
|
|
240
|
+
// { kind: 'thread', id } for a thread's history. Never both.
|
|
241
|
+
let open = null;
|
|
242
|
+
let fieldSeq = 0;
|
|
171
243
|
|
|
172
244
|
const canComment = () => Boolean(context && context.permissions && context.permissions.comment === true);
|
|
173
245
|
const canResolve = () => Boolean(context && context.permissions && context.permissions.resolve === true);
|
|
174
246
|
const viewerId = () => (context && context.viewer && context.viewer.id) || null;
|
|
175
|
-
const
|
|
247
|
+
const viewerActor = () => ({ id: viewerId(), name: (context.viewer && context.viewer.name) || null, kind: 'human' });
|
|
176
248
|
const idempotencyKey = () => (crypto.randomUUID ? crypto.randomUUID() : Date.now().toString(36) + Math.random().toString(36).slice(2));
|
|
177
|
-
const
|
|
249
|
+
const live = (thread) => (thread.comments || []).filter((comment) => !comment.deleted);
|
|
250
|
+
const phone = () => matchMedia('(max-width: 640px)').matches;
|
|
251
|
+
const ago = (value) => {
|
|
252
|
+
const time = Date.parse(value);
|
|
253
|
+
if (Number.isNaN(time)) return '';
|
|
254
|
+
const seconds = Math.max(0, (Date.now() - time) / 1000);
|
|
255
|
+
if (seconds < 60) return 'just now';
|
|
256
|
+
if (seconds < 3600) return Math.floor(seconds / 60) + 'm ago';
|
|
257
|
+
if (seconds < 86400) return Math.floor(seconds / 3600) + 'h ago';
|
|
258
|
+
return new Date(time).toLocaleDateString(undefined, { month: 'short', day: 'numeric' });
|
|
259
|
+
};
|
|
260
|
+
// A thread that began as a highlight: no first comment written with it.
|
|
261
|
+
const highlightedFirst = (thread) => Boolean(thread.created_by && thread.created_at
|
|
262
|
+
&& (!thread.comments.length || thread.comments[0].created_at !== thread.created_at));
|
|
263
|
+
|
|
264
|
+
const h = (tag, props, ...children) => {
|
|
265
|
+
const element = document.createElement(tag);
|
|
266
|
+
for (const [key, value] of Object.entries(props || {})) {
|
|
267
|
+
if (value === null || value === undefined || value === false) continue;
|
|
268
|
+
if (key === 'class') element.className = value;
|
|
269
|
+
else if (key === 'html') element.innerHTML = value;
|
|
270
|
+
else if (key === 'text') element.textContent = value;
|
|
271
|
+
else if (key.startsWith('on')) element.addEventListener(key.slice(2), value);
|
|
272
|
+
else element.setAttribute(key, value === true ? '' : String(value));
|
|
273
|
+
}
|
|
274
|
+
for (const child of children.flat()) if (child !== null && child !== undefined && child !== false) element.append(child);
|
|
275
|
+
return element;
|
|
276
|
+
};
|
|
277
|
+
const face = (person, size) => {
|
|
278
|
+
const tile = h('span', { class: 'collab-face' + (size ? ' ' + size : ''), 'aria-hidden': 'true' });
|
|
279
|
+
const url = person && person.avatar_url;
|
|
280
|
+
if (typeof url === 'string' && /^https:\\/\\//.test(url)) tile.append(h('img', { src: url, alt: '', referrerpolicy: 'no-referrer' }));
|
|
281
|
+
else tile.textContent = (Array.from(String((person && person.name) || '').trim())[0] || '?').toUpperCase();
|
|
282
|
+
if (person && person.guest) tile.append(h('span', { class: 'collab-globe', html: icon('globe', 9) }));
|
|
283
|
+
return tile;
|
|
284
|
+
};
|
|
285
|
+
const remember = (actor) => { if (actor && actor.id && actor.name) names.set(actor.id, actor.name); };
|
|
178
286
|
|
|
179
287
|
// One key per intent, reused across every retry of that intent, so a response
|
|
180
288
|
// lost on the wire cannot become a second thread or a duplicate reply.
|
|
@@ -199,422 +307,538 @@ export const COLLAB_SCRIPT = `<script>
|
|
|
199
307
|
style.textContent = ':root{--collab-rail-width:340px}' + ${JSON.stringify(COLLAB_CSS)};
|
|
200
308
|
document.head.append(style);
|
|
201
309
|
|
|
202
|
-
const rail =
|
|
203
|
-
rail.className = 'collab-rail';
|
|
204
|
-
rail.hidden = true;
|
|
205
|
-
rail.setAttribute('aria-label', 'Review threads');
|
|
310
|
+
const rail = h('aside', { class: 'collab-rail', hidden: true, 'aria-label': 'Comments' });
|
|
206
311
|
rail.innerHTML = '<div class="collab-head">'
|
|
207
|
-
+ '<span class="collab-head-title">
|
|
312
|
+
+ '<span class="collab-head-title">Comments</span>'
|
|
208
313
|
+ '<span class="collab-visibility" hidden></span>'
|
|
209
|
-
+ '<button type="button" class="collab-close" aria-label="Close
|
|
210
|
-
+ '
|
|
211
|
-
+ '<button type="button" data-collab-filter="open" aria-pressed="true">Open</button>'
|
|
212
|
-
+ '<button type="button" data-collab-filter="resolved" aria-pressed="false">Resolved</button>'
|
|
213
|
-
+ '</div></div>'
|
|
214
|
-
+ '<div class="collab-list" role="list"></div>'
|
|
314
|
+
+ '<button type="button" class="collab-close" aria-label="Close comments" title="Close">' + icon('close', 16) + '</button>'
|
|
315
|
+
+ '</div><ul class="collab-list"></ul>'
|
|
215
316
|
+ '<p class="collab-provenance" hidden></p>';
|
|
317
|
+
const list = rail.querySelector('.collab-list');
|
|
216
318
|
// On a share served with the attribution bar, the bar's Comments button is
|
|
217
|
-
// the launcher; anywhere else
|
|
319
|
+
// the launcher; anywhere else Comments floats in the corner.
|
|
218
320
|
const hostedLauncher = document.querySelector('.agents-share-bar [data-ash-comments]');
|
|
219
321
|
const launcher = hostedLauncher || document.createElement('button');
|
|
220
322
|
if (!hostedLauncher) {
|
|
221
323
|
launcher.type = 'button';
|
|
222
324
|
launcher.className = 'collab-launcher';
|
|
223
|
-
launcher.innerHTML = '
|
|
325
|
+
launcher.innerHTML = icon('comments', 15) + 'Comments <span class="collab-count">0</span>';
|
|
224
326
|
}
|
|
225
327
|
launcher.hidden = true;
|
|
226
328
|
launcher.setAttribute('aria-expanded', 'false');
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
const list = rail.querySelector('.collab-list');
|
|
232
|
-
const announce = (message) => { live.textContent = message; };
|
|
329
|
+
const liveRegion = h('div', { class: 'collab-live', role: 'status', 'aria-live': 'polite' });
|
|
330
|
+
const announce = (message) => { liveRegion.textContent = message; };
|
|
331
|
+
const pop = h('div', { class: 'collab-pop', role: 'dialog', hidden: true });
|
|
332
|
+
const pins = h('div', { class: 'collab-pins' });
|
|
233
333
|
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
launcher.setAttribute('aria-expanded', 'true');
|
|
238
|
-
if (focus) { const first = list.querySelector('.collab-thread'); (first || rail.querySelector('.collab-close')).focus(); }
|
|
239
|
-
};
|
|
240
|
-
const closeRail = () => {
|
|
241
|
-
rail.hidden = true;
|
|
242
|
-
document.body.classList.remove('collab-rail-open');
|
|
243
|
-
launcher.setAttribute('aria-expanded', 'false');
|
|
244
|
-
selected = null;
|
|
245
|
-
const target = returnTo;
|
|
246
|
-
returnTo = null;
|
|
247
|
-
paintAll();
|
|
248
|
-
const mark = target && reader.root.querySelector('mark[data-collab-thread="' + CSS.escape(target) + '"]');
|
|
249
|
-
// A reader can collapse the quoted section while Review is open. Focusing
|
|
250
|
-
// its hidden mark would leave focus in the now-hidden rail.
|
|
251
|
-
(mark && mark.getClientRects().length ? mark : launcher).focus();
|
|
334
|
+
const markOf = (id) => {
|
|
335
|
+
const marks = reader.root.querySelectorAll('mark[data-collab-thread="' + CSS.escape(id) + '"]');
|
|
336
|
+
return [...marks].filter((mark) => mark.getClientRects().length);
|
|
252
337
|
};
|
|
253
338
|
|
|
254
|
-
|
|
339
|
+
// --- Painting the page ---------------------------------------------------
|
|
340
|
+
const markLabel = (thread) => {
|
|
341
|
+
const comments = live(thread);
|
|
342
|
+
if (!comments.length) return 'Highlight' + (thread.created_by && thread.created_by.name ? ' by ' + thread.created_by.name : '');
|
|
343
|
+
return 'Comment thread, ' + comments.length + ' comment' + (comments.length === 1 ? '' : 's') + ': ' + String(comments[0].body || '').slice(0, 80);
|
|
344
|
+
};
|
|
345
|
+
const paintMarks = () => {
|
|
255
346
|
reader.clearMarks('mark[data-collab-thread]');
|
|
256
347
|
for (const thread of threads.values()) {
|
|
257
|
-
if (thread.draft) continue;
|
|
258
348
|
const found = reader.quoteAt(thread.anchor);
|
|
259
349
|
// Repaint only on an unambiguous anchor resolution AND an exact quote
|
|
260
350
|
// match. Anything else leaves the prose alone; the thread stays legible in
|
|
261
|
-
// the
|
|
351
|
+
// the list instead of decorating the wrong sentence.
|
|
262
352
|
thread.stale = found === null || reader.normalizeQuote(found) !== reader.normalizeQuote(thread.anchor.quote);
|
|
263
|
-
if (thread.stale
|
|
353
|
+
if (thread.stale) continue;
|
|
264
354
|
reader.paint(thread.anchor, () => {
|
|
265
|
-
const mark =
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
mark.setAttribute('role', 'button');
|
|
270
|
-
const first = thread.comments.find((comment) => !comment.deleted);
|
|
271
|
-
mark.setAttribute('aria-label', 'Review thread, ' + thread.comments.length + ' comment' + (thread.comments.length === 1 ? '' : 's') + (first ? ': ' + first.body.slice(0, 80) : ''));
|
|
272
|
-
mark.addEventListener('click', (event) => { event.preventDefault(); event.stopPropagation(); select(thread.id, thread.id); });
|
|
273
|
-
mark.addEventListener('keydown', (event) => {
|
|
274
|
-
if (event.key !== 'Enter' && event.key !== ' ' && event.key !== 'Spacebar') return;
|
|
275
|
-
event.preventDefault(); event.stopPropagation(); select(thread.id, thread.id);
|
|
355
|
+
const mark = h('mark', {
|
|
356
|
+
class: 'collab-mark' + (live(thread).length ? '' : ' is-highlight') + (thread.status === 'resolved' ? ' is-resolved' : '')
|
|
357
|
+
+ (open && open.id === thread.id ? ' is-selected' : ''),
|
|
358
|
+
tabindex: '0', role: 'button', 'aria-label': markLabel(thread),
|
|
276
359
|
});
|
|
360
|
+
mark.dataset.collabThread = thread.id;
|
|
361
|
+
const opener = (event, focus) => { event.preventDefault(); event.stopPropagation(); showThread(thread.id, { focus, returnTo: () => markOf(thread.id)[0] }); };
|
|
362
|
+
mark.addEventListener('click', (event) => opener(event, false));
|
|
363
|
+
mark.addEventListener('keydown', (event) => { if (event.key === 'Enter' || event.key === ' ' || event.key === 'Spacebar') opener(event, true); });
|
|
277
364
|
return mark;
|
|
278
365
|
});
|
|
279
366
|
}
|
|
367
|
+
if (open && open.kind === 'compose') {
|
|
368
|
+
reader.paint(open.anchor, () => { const mark = h('mark', { class: 'collab-mark is-draft' }); mark.dataset.collabThread = 'draft'; return mark; });
|
|
369
|
+
}
|
|
280
370
|
};
|
|
281
371
|
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
if (
|
|
285
|
-
const
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
372
|
+
const paintPins = () => {
|
|
373
|
+
pins.replaceChildren();
|
|
374
|
+
if (phone()) return;
|
|
375
|
+
const column = reader.root.getBoundingClientRect();
|
|
376
|
+
const width = document.documentElement.clientWidth - (document.body.classList.contains('collab-rail-open') && !rail.hidden ? rail.offsetWidth : 0);
|
|
377
|
+
if (column.right + 60 > width) return;
|
|
378
|
+
let last = -Infinity;
|
|
379
|
+
for (const thread of threads.values()) {
|
|
380
|
+
const comments = live(thread);
|
|
381
|
+
const [first] = markOf(thread.id);
|
|
382
|
+
if (!comments.length || !first) continue;
|
|
383
|
+
let top = first.getBoundingClientRect().top + scrollY - 2;
|
|
384
|
+
if (top - last < 28) top = last + 28;
|
|
385
|
+
last = top;
|
|
386
|
+
const author = comments[comments.length - 1].author;
|
|
387
|
+
const pin = h('button', {
|
|
388
|
+
type: 'button', class: 'collab-pin' + (thread.status === 'resolved' ? ' is-resolved' : ''),
|
|
389
|
+
style: 'left:' + (column.right + scrollX + 16) + 'px;top:' + top + 'px',
|
|
390
|
+
'aria-label': comments.length + ' comment' + (comments.length === 1 ? '' : 's') + ' on “' + thread.anchor.quote + '”',
|
|
391
|
+
}, face(author, 'sm'), String(comments.length));
|
|
392
|
+
pin.addEventListener('click', () => showThread(thread.id, { focus: true, returnTo: () => [...pins.children].find((el) => el.dataset.thread === thread.id) }));
|
|
393
|
+
pin.dataset.thread = thread.id;
|
|
394
|
+
pins.append(pin);
|
|
298
395
|
}
|
|
299
396
|
};
|
|
300
397
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
398
|
+
// --- The field: one input for a new comment or a reply, with tags ----------
|
|
399
|
+
const field = ({ label, emptyAction, onSubmit, onEscape }) => {
|
|
400
|
+
const listId = 'collab-people-' + (++fieldSeq);
|
|
401
|
+
const input = h('div', {
|
|
402
|
+
class: 'collab-input', contenteditable: 'true', role: 'combobox', 'aria-label': label, 'aria-multiline': 'true',
|
|
403
|
+
'aria-autocomplete': 'list', 'aria-expanded': 'false', 'aria-controls': listId, 'data-placeholder': label,
|
|
404
|
+
});
|
|
405
|
+
const act = h('button', { type: 'button', class: 'collab-act' });
|
|
406
|
+
const people = h('ul', { class: 'collab-people', id: listId, role: 'listbox', 'aria-label': 'People', hidden: true });
|
|
407
|
+
const element = h('div', null, h('div', { class: 'collab-field' }, face(context.viewer), input, act), people);
|
|
408
|
+
let query = null;
|
|
409
|
+
let rows = [];
|
|
410
|
+
let active = 0;
|
|
411
|
+
let timer = null;
|
|
412
|
+
let ticket = 0;
|
|
413
|
+
let busy = false;
|
|
309
414
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
option.setAttribute('
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
415
|
+
const serialize = (node) => [...node.childNodes].map((child) => {
|
|
416
|
+
if (child.nodeType === 3) return child.data;
|
|
417
|
+
if (child.classList && child.classList.contains('collab-chip')) return '@' + child.dataset.name;
|
|
418
|
+
if (child.nodeName === 'BR') return '\\n';
|
|
419
|
+
return (/^(DIV|P)$/.test(child.nodeName) ? '\\n' : '') + serialize(child);
|
|
420
|
+
}).join('');
|
|
421
|
+
const text = () => serialize(input).replace(/\\u00a0/g, ' ').trim();
|
|
422
|
+
const tags = () => [...new Set([...input.querySelectorAll('.collab-chip')].map((tag) => tag.dataset.id))];
|
|
423
|
+
const paintAct = () => {
|
|
424
|
+
const sending = Boolean(text()) || !emptyAction;
|
|
425
|
+
act.className = 'collab-act' + (sending ? ' send' : '');
|
|
426
|
+
act.innerHTML = sending ? icon('send', 15) : icon('highlight', 14) + emptyAction;
|
|
427
|
+
act.setAttribute('aria-label', sending ? 'Send' : emptyAction);
|
|
428
|
+
act.title = act.getAttribute('aria-label');
|
|
429
|
+
act.disabled = busy;
|
|
430
|
+
};
|
|
431
|
+
const caret = () => {
|
|
432
|
+
const selection = getSelection();
|
|
433
|
+
if (!selection.rangeCount || !input.contains(selection.anchorNode) || selection.anchorNode.nodeType !== 3) return null;
|
|
434
|
+
return { node: selection.anchorNode, offset: selection.anchorOffset };
|
|
435
|
+
};
|
|
436
|
+
const chip = (person) => {
|
|
437
|
+
const element = h('span', { class: 'collab-chip', contenteditable: 'false', text: '@' + person.name });
|
|
438
|
+
element.dataset.id = person.id;
|
|
439
|
+
element.dataset.name = person.name;
|
|
440
|
+
return element;
|
|
441
|
+
};
|
|
442
|
+
const closeList = () => {
|
|
443
|
+
clearTimeout(timer);
|
|
444
|
+
ticket += 1;
|
|
445
|
+
query = null;
|
|
446
|
+
rows = [];
|
|
447
|
+
people.replaceChildren();
|
|
448
|
+
people.hidden = true;
|
|
449
|
+
input.setAttribute('aria-expanded', 'false');
|
|
450
|
+
input.removeAttribute('aria-activedescendant');
|
|
451
|
+
place();
|
|
452
|
+
};
|
|
453
|
+
// One highlight travels to the active row (rush/DESIGN.md, Interaction states).
|
|
454
|
+
const slide = () => {
|
|
455
|
+
const pill = people.querySelector('.collab-pill');
|
|
456
|
+
const row = people.querySelector('#' + listId + '-' + active);
|
|
457
|
+
for (const option of people.querySelectorAll('.collab-row')) option.setAttribute('aria-selected', option === row ? 'true' : 'false');
|
|
458
|
+
if (!row) return;
|
|
459
|
+
if (pill) { pill.style.height = row.offsetHeight + 'px'; pill.style.transform = 'translateY(' + row.offsetTop + 'px)'; }
|
|
460
|
+
input.setAttribute('aria-activedescendant', row.id);
|
|
461
|
+
row.scrollIntoView({ block: 'nearest' });
|
|
462
|
+
};
|
|
463
|
+
const addLink = (person) => CONSOLE_SHARE + '?' + new URLSearchParams({ share: share.replace(/^\\/+/, ''), add: person.email }).toString();
|
|
464
|
+
const choose = (person) => {
|
|
465
|
+
if (person.needs_access) {
|
|
466
|
+
window.open(addLink(person), '_blank', 'noopener');
|
|
467
|
+
announce('Opened the Share panel to add ' + person.name);
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
input.focus();
|
|
471
|
+
const at = caret();
|
|
472
|
+
const tag = chip(person);
|
|
473
|
+
const space = document.createTextNode(' ');
|
|
474
|
+
if (at) {
|
|
475
|
+
const before = at.node.data.slice(0, at.offset);
|
|
476
|
+
const start = before.lastIndexOf('@');
|
|
477
|
+
const after = at.node.splitText(at.offset);
|
|
478
|
+
at.node.data = before.slice(0, Math.max(start, 0));
|
|
479
|
+
after.parentNode.insertBefore(tag, after);
|
|
480
|
+
after.parentNode.insertBefore(space, after);
|
|
481
|
+
} else input.append(tag, space);
|
|
482
|
+
const range = document.createRange();
|
|
483
|
+
range.setStartAfter(space);
|
|
484
|
+
range.collapse(true);
|
|
485
|
+
getSelection().removeAllRanges();
|
|
486
|
+
getSelection().addRange(range);
|
|
487
|
+
closeList();
|
|
488
|
+
paintAct();
|
|
489
|
+
};
|
|
490
|
+
const paintList = (members) => {
|
|
491
|
+
const inside = members.filter((m) => !m.guest && !m.needs_access);
|
|
492
|
+
const outside = members.filter((m) => m.guest && !m.needs_access);
|
|
493
|
+
const locked = members.filter((m) => m.needs_access);
|
|
494
|
+
rows = [...inside, ...outside, ...locked];
|
|
495
|
+
active = 0;
|
|
496
|
+
people.replaceChildren();
|
|
497
|
+
if (!rows.length) {
|
|
498
|
+
people.append(h('li', { class: 'collab-none', role: 'presentation', text: 'No one here matches “' + query + '”' }));
|
|
361
499
|
} else {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
500
|
+
people.append(h('li', { class: 'collab-pill', 'aria-hidden': 'true' }));
|
|
501
|
+
const group = (title, members, glyph) => {
|
|
502
|
+
if (!members.length) return;
|
|
503
|
+
people.append(h('li', { class: 'collab-label', role: 'presentation', html: glyph ? icon(glyph, 12) : '' }, title, h('b', { text: String(members.length) })));
|
|
504
|
+
for (const member of members) {
|
|
505
|
+
const index = rows.indexOf(member);
|
|
506
|
+
const right = member.needs_access
|
|
507
|
+
? h('a', { class: 'collab-add', href: addLink(member), target: '_blank', rel: 'noopener', tabindex: '-1', html: 'Add' + icon('out', 11) })
|
|
508
|
+
: member.guest ? h('span', { class: 'collab-guest', html: icon('globe', 12) + 'Guest' }) : null;
|
|
509
|
+
const row = h('li', {
|
|
510
|
+
id: listId + '-' + index, class: 'collab-row' + (member.needs_access ? ' is-locked' : ''), role: 'option', 'aria-selected': 'false',
|
|
511
|
+
}, face(member), h('span', { class: 'collab-name', text: member.name }), h('span', { class: 'collab-mail', text: member.email || '' }), right);
|
|
512
|
+
row.addEventListener('mousedown', (event) => { if (!event.target.closest('a')) event.preventDefault(); });
|
|
513
|
+
row.addEventListener('mousemove', () => { if (active !== index) { active = index; slide(); } });
|
|
514
|
+
row.addEventListener('click', (event) => { if (event.target.closest('a')) { event.stopPropagation(); return; } choose(member); });
|
|
515
|
+
people.append(row);
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
group('In your org', inside);
|
|
519
|
+
group('Outside your org', outside, 'globe');
|
|
520
|
+
group("Can't open yet", locked, 'lock');
|
|
365
521
|
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
522
|
+
people.hidden = false;
|
|
523
|
+
input.setAttribute('aria-expanded', String(rows.length > 0));
|
|
524
|
+
slide();
|
|
525
|
+
place();
|
|
526
|
+
};
|
|
527
|
+
const lookup = async (q) => {
|
|
528
|
+
const mine = ++ticket;
|
|
529
|
+
let members = null;
|
|
530
|
+
try {
|
|
531
|
+
const response = await fetch(endpoint('/__collab/members', { share, q }), { headers: { accept: 'application/json' } });
|
|
532
|
+
if (response.ok) {
|
|
533
|
+
const payload = await response.json();
|
|
534
|
+
members = (Array.isArray(payload.members) ? payload.members : [])
|
|
535
|
+
.filter((member) => member && typeof member.id === 'string' && typeof member.name === 'string' && member.name.trim()
|
|
536
|
+
&& (!member.needs_access || typeof member.email === 'string'));
|
|
537
|
+
}
|
|
538
|
+
} catch {}
|
|
539
|
+
if (mine !== ticket || query === null) return;
|
|
540
|
+
// A page with no member list answers nothing; the comment posts untagged.
|
|
541
|
+
if (members === null) { closeList(); return; }
|
|
542
|
+
for (const member of members) remember(member);
|
|
543
|
+
paintList(members);
|
|
544
|
+
};
|
|
545
|
+
input.addEventListener('input', () => {
|
|
546
|
+
const at = caret();
|
|
547
|
+
const found = at && /(^|\\s)@([^\\s@]{0,40})$/.exec(at.node.data.slice(0, at.offset).replace(/\\u00a0/g, ' '));
|
|
548
|
+
if (found) {
|
|
549
|
+
query = found[2];
|
|
550
|
+
clearTimeout(timer);
|
|
551
|
+
timer = setTimeout(() => lookup(query), 120);
|
|
552
|
+
} else if (query !== null) closeList();
|
|
553
|
+
paintAct();
|
|
375
554
|
});
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
if (
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
555
|
+
input.addEventListener('paste', (event) => {
|
|
556
|
+
event.preventDefault();
|
|
557
|
+
document.execCommand('insertText', false, (event.clipboardData && event.clipboardData.getData('text/plain')) || '');
|
|
558
|
+
});
|
|
559
|
+
input.addEventListener('blur', () => { if (query !== null) setTimeout(() => { if (!element.contains(document.activeElement)) closeList(); }, 0); });
|
|
560
|
+
input.addEventListener('keydown', (event) => {
|
|
561
|
+
if (event.isComposing) return;
|
|
562
|
+
if (!people.hidden && rows.length) {
|
|
563
|
+
if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
564
|
+
event.preventDefault();
|
|
565
|
+
active = (active + (event.key === 'ArrowDown' ? 1 : rows.length - 1)) % rows.length;
|
|
566
|
+
slide();
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
if (event.key === 'Enter' || event.key === 'Tab') { event.preventDefault(); choose(rows[active]); return; }
|
|
388
570
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
}
|
|
423
|
-
return false;
|
|
571
|
+
if (event.key === 'Escape') {
|
|
572
|
+
event.preventDefault();
|
|
573
|
+
event.stopPropagation();
|
|
574
|
+
if (query !== null) closeList(); else onEscape();
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
if (event.key === 'Enter' && !event.shiftKey) { event.preventDefault(); act.click(); }
|
|
578
|
+
});
|
|
579
|
+
act.addEventListener('click', () => { if (!busy) onSubmit(text(), tags()); });
|
|
580
|
+
paintAct();
|
|
581
|
+
return {
|
|
582
|
+
element, input,
|
|
583
|
+
focus: () => input.focus(),
|
|
584
|
+
// Puts text back with its tags, after a send that did not go through.
|
|
585
|
+
set: (value, tagged) => {
|
|
586
|
+
input.replaceChildren();
|
|
587
|
+
let rest = value || '';
|
|
588
|
+
const people = (tagged || []).filter((person) => person && person.name);
|
|
589
|
+
while (rest) {
|
|
590
|
+
let next = null;
|
|
591
|
+
for (const person of people) {
|
|
592
|
+
const at = rest.indexOf('@' + person.name);
|
|
593
|
+
if (at !== -1 && (!next || at < next.at)) next = { at, person };
|
|
594
|
+
}
|
|
595
|
+
if (!next) { input.append(rest); break; }
|
|
596
|
+
if (next.at) input.append(rest.slice(0, next.at));
|
|
597
|
+
input.append(chip(next.person));
|
|
598
|
+
rest = rest.slice(next.at + next.person.name.length + 1);
|
|
599
|
+
}
|
|
600
|
+
paintAct();
|
|
601
|
+
},
|
|
602
|
+
tagged: () => [...input.querySelectorAll('.collab-chip')].map((tag) => ({ id: tag.dataset.id, name: tag.dataset.name })),
|
|
603
|
+
busy: (on) => { busy = on; paintAct(); },
|
|
604
|
+
};
|
|
424
605
|
};
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
606
|
+
|
|
607
|
+
// --- The box --------------------------------------------------------------
|
|
608
|
+
// It picks its side once per opening, leaving room for the people list, so it
|
|
609
|
+
// never jumps when the list opens.
|
|
610
|
+
const anchorMark = () => {
|
|
611
|
+
if (!open) return null;
|
|
612
|
+
const marks = markOf(open.kind === 'compose' ? 'draft' : open.id);
|
|
613
|
+
return marks[marks.length - 1] || null;
|
|
428
614
|
};
|
|
429
|
-
|
|
430
|
-
if (
|
|
431
|
-
if (
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
615
|
+
function place() {
|
|
616
|
+
if (pop.hidden || !open) return;
|
|
617
|
+
if (phone()) { pop.style.left = ''; pop.style.top = ''; return; }
|
|
618
|
+
const anchor = anchorMark();
|
|
619
|
+
pop.classList.toggle('is-floating', !anchor);
|
|
620
|
+
if (!anchor) { pop.style.left = ''; pop.style.top = ''; return; }
|
|
621
|
+
const rect = anchor.getBoundingClientRect();
|
|
622
|
+
const width = pop.offsetWidth || 360;
|
|
623
|
+
const height = pop.offsetHeight;
|
|
624
|
+
pop.style.left = Math.min(Math.max(12, rect.left), innerWidth - width - 12) + 'px';
|
|
625
|
+
if (!open.side) open.side = rect.bottom + 10 + Math.max(height, 340) <= innerHeight - 8 || rect.top < 360 ? 'below' : 'above';
|
|
626
|
+
pop.style.top = (open.side === 'below' ? rect.bottom + 10 : Math.max(8, rect.top - height - 10)) + 'px';
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
const closePop = (restore) => {
|
|
630
|
+
if (!open) return;
|
|
631
|
+
// Focus goes back to what opened the box, or to the launcher when that is
|
|
632
|
+
// gone or hidden (a collapsed section).
|
|
633
|
+
const back = open.returnTo;
|
|
634
|
+
open = null;
|
|
635
|
+
pop.hidden = true;
|
|
636
|
+
pop.replaceChildren();
|
|
637
|
+
// Repainting replaces marks and list items, so focus goes back after it.
|
|
638
|
+
refresh();
|
|
639
|
+
if (restore) {
|
|
640
|
+
const target = back && back();
|
|
641
|
+
(target && target.getClientRects().length ? target : launcher).focus();
|
|
443
642
|
}
|
|
444
643
|
};
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
const
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
644
|
+
|
|
645
|
+
const compose = (record, restore) => {
|
|
646
|
+
closePop(false);
|
|
647
|
+
open = {
|
|
648
|
+
kind: 'compose',
|
|
649
|
+
anchor: { revision, quote: record.quote, section: record.section, start: record.start, end: record.end },
|
|
650
|
+
returnTo: () => null,
|
|
651
|
+
};
|
|
652
|
+
const anchor = open.anchor;
|
|
653
|
+
paintMarks();
|
|
654
|
+
const box = field({
|
|
655
|
+
label: 'Comment, or @ to tag',
|
|
656
|
+
emptyAction: 'Highlight',
|
|
657
|
+
onSubmit: (text, ids) => createThread(anchor, text, ids, box.tagged()),
|
|
658
|
+
onEscape: () => closePop(true),
|
|
659
|
+
});
|
|
660
|
+
pop.setAttribute('aria-label', 'Comment on the selection');
|
|
661
|
+
pop.replaceChildren(...(restore && restore.error ? [h('p', { class: 'collab-error', role: 'alert', text: restore.error })] : []), box.element);
|
|
662
|
+
if (restore) box.set(restore.text, restore.people);
|
|
663
|
+
pop.hidden = false;
|
|
664
|
+
place();
|
|
665
|
+
box.focus();
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
const entryText = (comment) => {
|
|
669
|
+
const paragraph = h('p', { class: 'collab-text' + (comment.deleted || comment.pending ? ' is-muted' : '') });
|
|
670
|
+
if (comment.deleted) { paragraph.textContent = 'Comment deleted'; return paragraph; }
|
|
671
|
+
let rest = String(comment.body || '');
|
|
672
|
+
const tagged = (comment.mentions || []).map((id) => names.get(id)).filter(Boolean);
|
|
673
|
+
while (rest) {
|
|
674
|
+
let next = null;
|
|
675
|
+
for (const name of tagged) {
|
|
676
|
+
const at = rest.indexOf('@' + name);
|
|
677
|
+
if (at !== -1 && (!next || at < next.at)) next = { at, name };
|
|
678
|
+
}
|
|
679
|
+
if (!next) { paragraph.append(rest); break; }
|
|
680
|
+
if (next.at) paragraph.append(rest.slice(0, next.at));
|
|
681
|
+
paragraph.append(h('span', { class: 'collab-chip', text: '@' + next.name }));
|
|
682
|
+
rest = rest.slice(next.at + next.name.length + 1);
|
|
480
683
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
if (
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
body.className = 'collab-body' + (comment.deleted ? ' is-deleted' : '') + (comment.pending ? ' is-pending' : '');
|
|
492
|
-
body.textContent = comment.deleted ? 'Comment deleted' : comment.body;
|
|
493
|
-
item.append(byline, body);
|
|
494
|
-
if (mine && canComment()) {
|
|
495
|
-
const actions = document.createElement('div');
|
|
496
|
-
actions.className = 'collab-actions';
|
|
497
|
-
actions.append(button('edit', 'Edit', comment.id), button('delete', 'Delete', comment.id));
|
|
498
|
-
item.append(actions);
|
|
684
|
+
return paragraph;
|
|
685
|
+
};
|
|
686
|
+
const when = (value) => h('time', { datetime: value, title: new Date(value).toLocaleString(), text: ago(value) });
|
|
687
|
+
|
|
688
|
+
const entries = (thread) => {
|
|
689
|
+
const items = [];
|
|
690
|
+
if (highlightedFirst(thread)) {
|
|
691
|
+
const by = thread.created_by;
|
|
692
|
+
items.push(h('li', { class: 'collab-entry is-note' }, face(by, 'sm'),
|
|
693
|
+
h('span', { class: 'collab-who' }, h('b', { text: by.name || 'Someone' }), ' highlighted this · ', when(thread.created_at))));
|
|
499
694
|
}
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
695
|
+
for (const comment of thread.comments) {
|
|
696
|
+
const mine = !comment.deleted && !comment.pending && comment.author && comment.author.id === viewerId() && canComment();
|
|
697
|
+
const who = h('span', { class: 'collab-who' }, h('b', { text: (comment.author && comment.author.name) || 'Unknown' }), ' · ', when(comment.created_at),
|
|
698
|
+
comment.edited ? ' · edited' : '', comment.pending ? ' · sending…' : '');
|
|
699
|
+
const head = h('div', { class: 'collab-entry-head' }, who);
|
|
700
|
+
const body = h('div', null, head);
|
|
701
|
+
if (mine && thread.editing === comment.id) {
|
|
702
|
+
const editor = h('textarea', { class: 'collab-edit', 'aria-label': 'Edit comment' });
|
|
703
|
+
editor.value = thread.editValue || '';
|
|
704
|
+
editor.addEventListener('input', () => revise(thread.id, () => ({ editValue: editor.value })));
|
|
705
|
+
const cancel = () => { revise(thread.id, () => ({ editing: null })); refreshCard(); };
|
|
706
|
+
editor.addEventListener('keydown', (event) => {
|
|
707
|
+
if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); cancel(); }
|
|
708
|
+
if (event.key === 'Enter' && !event.shiftKey) { event.preventDefault(); save(); }
|
|
709
|
+
});
|
|
710
|
+
const save = () => { const value = editor.value.trim(); if (value) patchComment(thread, comment.id, { body: value }, 'Edit failed.'); };
|
|
711
|
+
body.append(editor, h('div', { class: 'collab-entry-acts is-shown' },
|
|
712
|
+
h('button', { type: 'button', text: 'Save', onclick: save }),
|
|
713
|
+
h('button', { type: 'button', text: 'Cancel', onclick: cancel })));
|
|
714
|
+
requestAnimationFrame(() => editor.focus());
|
|
715
|
+
} else {
|
|
716
|
+
body.append(entryText(comment));
|
|
717
|
+
if (mine) {
|
|
718
|
+
head.append(h('div', { class: 'collab-entry-acts' },
|
|
719
|
+
h('button', { type: 'button', text: 'Edit', onclick: () => { revise(thread.id, () => ({ editing: comment.id, editValue: comment.body })); refreshCard(); } }),
|
|
720
|
+
h('button', { type: 'button', text: 'Delete', onclick: () => patchComment(thread, comment.id, { deleted: true }, 'Delete failed.') })));
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
items.push(h('li', { class: 'collab-entry' }, face(comment.author), body));
|
|
524
724
|
}
|
|
725
|
+
return h('ul', { class: 'collab-entries' }, items);
|
|
726
|
+
};
|
|
525
727
|
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
const textarea = document.createElement('textarea');
|
|
541
|
-
textarea.setAttribute('aria-label', thread.draft ? 'Comment' : 'Reply');
|
|
542
|
-
textarea.placeholder = thread.draft ? 'Comment on this selection…' : 'Reply…';
|
|
543
|
-
textarea.value = thread.composerValue || '';
|
|
544
|
-
textarea.setAttribute('role', 'combobox');
|
|
545
|
-
textarea.setAttribute('aria-multiline', 'true');
|
|
546
|
-
textarea.setAttribute('aria-autocomplete', 'list');
|
|
547
|
-
textarea.setAttribute('aria-haspopup', 'listbox');
|
|
548
|
-
textarea.setAttribute('aria-expanded', 'false');
|
|
549
|
-
textarea.setAttribute('aria-controls', 'collab-mentions');
|
|
550
|
-
textarea.addEventListener('blur', () => { if (mention && mention.threadId === thread.id) closeMentions(); });
|
|
551
|
-
textarea.addEventListener('input', () => { thread.composerValue = textarea.value; findMention(thread, textarea); });
|
|
552
|
-
textarea.addEventListener('keydown', (event) => mentionKey(event, thread, textarea));
|
|
553
|
-
const row = document.createElement('div');
|
|
554
|
-
row.className = 'collab-actions';
|
|
555
|
-
const submit = document.createElement('button');
|
|
556
|
-
submit.type = 'submit';
|
|
557
|
-
submit.textContent = thread.draft ? 'Post comment' : 'Send reply';
|
|
558
|
-
row.append(submit, button('cancel', 'Cancel'));
|
|
559
|
-
form.append(textarea, row);
|
|
560
|
-
if (thread.error) { const error = document.createElement('p'); error.className = 'collab-error'; error.textContent = thread.error; form.append(error); }
|
|
561
|
-
form.addEventListener('submit', (event) => {
|
|
562
|
-
event.preventDefault();
|
|
563
|
-
const value = textarea.value.trim();
|
|
564
|
-
if (!value) return;
|
|
565
|
-
const mentions = mentionedIds(thread, value);
|
|
566
|
-
closeMentions();
|
|
567
|
-
if (thread.draft) createThread(value, mentions); else replyTo(thread, value, mentions);
|
|
568
|
-
});
|
|
569
|
-
item.append(form);
|
|
570
|
-
} else if (thread.error) {
|
|
571
|
-
const error = document.createElement('p');
|
|
572
|
-
error.className = 'collab-error';
|
|
573
|
-
error.textContent = thread.error;
|
|
574
|
-
item.append(error);
|
|
575
|
-
}
|
|
728
|
+
const cardHead = (thread) => {
|
|
729
|
+
const resolved = thread.status === 'resolved';
|
|
730
|
+
return h('div', { class: 'collab-card-head' },
|
|
731
|
+
h('span', { class: 'collab-quote', text: '“' + thread.anchor.quote + '”' }),
|
|
732
|
+
canResolve() && !thread.pending ? h('button', {
|
|
733
|
+
type: 'button', class: 'collab-icon', 'aria-pressed': String(resolved), 'aria-label': resolved ? 'Reopen' : 'Resolve',
|
|
734
|
+
title: resolved ? 'Reopen' : 'Resolve', html: icon('resolve', 15), onclick: () => setStatus(thread, resolved ? 'open' : 'resolved'),
|
|
735
|
+
}) : null,
|
|
736
|
+
h('button', { type: 'button', class: 'collab-icon', 'aria-label': 'Close', title: 'Close', html: icon('close', 14), onclick: () => closePop(true) }));
|
|
737
|
+
};
|
|
738
|
+
const staleNote = (thread) => thread.stale ? h('p', { class: 'collab-stale', text:
|
|
739
|
+
// The exact wording is part of the cross-repo contract: a thread whose
|
|
740
|
+
// text moved is reported honestly rather than silently re-anchored.
|
|
741
|
+
thread.anchor.revision && thread.anchor.revision !== revision ? 'From an earlier revision' : 'Anchored text not found' }) : null;
|
|
576
742
|
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
743
|
+
const showThread = (id, options) => {
|
|
744
|
+
const thread = threads.get(id);
|
|
745
|
+
if (!thread) return;
|
|
746
|
+
if (open && open.kind === 'compose') closePop(false);
|
|
747
|
+
open = { kind: 'thread', id, returnTo: (options && options.returnTo) || (() => markOf(id)[0]) };
|
|
748
|
+
const reply = canComment() && !thread.pending ? field({
|
|
749
|
+
label: 'Reply, or @ to tag',
|
|
750
|
+
onSubmit: (text, ids) => { if (text) replyTo(id, text, ids, reply.tagged()); },
|
|
751
|
+
onEscape: () => closePop(true),
|
|
752
|
+
}) : null;
|
|
753
|
+
open.reply = reply;
|
|
754
|
+
pop.setAttribute('aria-label', 'Thread on “' + thread.anchor.quote.slice(0, 60) + '”');
|
|
755
|
+
pop.replaceChildren(cardHead(thread), staleNote(thread) || '', entries(thread), ...(reply ? [h('div', { class: 'collab-sep' }), reply.element] : []));
|
|
756
|
+
pop.hidden = false;
|
|
757
|
+
refresh();
|
|
758
|
+
place();
|
|
759
|
+
if (options && options.focus) (reply ? reply.input : pop.querySelector('.collab-icon')).focus();
|
|
581
760
|
};
|
|
582
761
|
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
const
|
|
588
|
-
|
|
589
|
-
|
|
762
|
+
// A teammate's change repaints the history and the head, never the reply
|
|
763
|
+
// being typed.
|
|
764
|
+
const refreshCard = () => {
|
|
765
|
+
if (!open || open.kind !== 'thread') return;
|
|
766
|
+
const thread = threads.get(open.id);
|
|
767
|
+
if (!thread) { closePop(false); return; }
|
|
768
|
+
pop.querySelector('.collab-card-head')?.replaceWith(cardHead(thread));
|
|
769
|
+
pop.querySelector('.collab-entries')?.replaceWith(entries(thread));
|
|
770
|
+
pop.querySelector('.collab-error')?.remove();
|
|
771
|
+
if (thread.error) pop.querySelector('.collab-entries').after(h('p', { class: 'collab-error', role: 'alert', text: thread.error }));
|
|
772
|
+
place();
|
|
773
|
+
};
|
|
774
|
+
|
|
775
|
+
// --- Every thread, from the launcher -----------------------------------------
|
|
776
|
+
const openRail = (focus) => {
|
|
777
|
+
rail.hidden = false;
|
|
778
|
+
document.body.classList.add('collab-rail-open');
|
|
779
|
+
launcher.setAttribute('aria-expanded', 'true');
|
|
780
|
+
paintRail();
|
|
781
|
+
paintPins();
|
|
782
|
+
if (focus) (list.querySelector('.collab-item') || rail.querySelector('.collab-close')).focus();
|
|
783
|
+
};
|
|
784
|
+
const closeRail = () => {
|
|
785
|
+
rail.hidden = true;
|
|
786
|
+
document.body.classList.remove('collab-rail-open');
|
|
787
|
+
launcher.setAttribute('aria-expanded', 'false');
|
|
788
|
+
paintPins();
|
|
789
|
+
launcher.focus();
|
|
790
|
+
};
|
|
791
|
+
const jump = (id) => {
|
|
792
|
+
const [mark] = markOf(id);
|
|
793
|
+
if (mark) {
|
|
794
|
+
scrollTo({ top: Math.max(0, mark.getBoundingClientRect().top + scrollY - innerHeight / 3), behavior: 'instant' });
|
|
795
|
+
for (const each of markOf(id)) { each.classList.remove('is-pulse'); void each.offsetWidth; each.classList.add('is-pulse'); }
|
|
796
|
+
}
|
|
797
|
+
showThread(id, { focus: true, returnTo: () => list.querySelector('[data-thread-id="' + CSS.escape(id) + '"]') || markOf(id)[0] });
|
|
798
|
+
};
|
|
799
|
+
const paintRail = () => {
|
|
800
|
+
const all = [...threads.values()];
|
|
801
|
+
const shown = [...all.filter((thread) => thread.status !== 'resolved'), ...all.filter((thread) => thread.status === 'resolved')];
|
|
590
802
|
list.replaceChildren();
|
|
591
|
-
if (!shown.length) {
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
803
|
+
if (!shown.length) list.append(h('li', { class: 'collab-empty', text: canComment() ? 'Select text to comment or highlight.' : 'No comments yet.' }));
|
|
804
|
+
for (const thread of shown) {
|
|
805
|
+
const comments = live(thread);
|
|
806
|
+
const last = comments[comments.length - 1];
|
|
807
|
+
const actor = last ? last.author : thread.created_by;
|
|
808
|
+
const item = h('button', {
|
|
809
|
+
type: 'button', class: 'collab-item' + (thread.status === 'resolved' ? ' is-resolved' : '') + (open && open.id === thread.id ? ' is-selected' : ''),
|
|
810
|
+
'data-thread-id': thread.id,
|
|
811
|
+
},
|
|
812
|
+
h('span', { class: 'collab-quote', text: thread.anchor.quote }),
|
|
813
|
+
thread.stale ? h('span', { class: 'collab-stale', text: thread.anchor.revision && thread.anchor.revision !== revision ? 'From an earlier revision' : 'Anchored text not found' }) : null,
|
|
814
|
+
h('span', { class: 'collab-last' }, face(actor, 'sm'), h('span', null,
|
|
815
|
+
h('b', { text: (actor && actor.name) || 'Someone' }),
|
|
816
|
+
last ? h('span', { class: 'collab-dim', text: ' · ' + ago(last.created_at) }) : h('span', { class: 'collab-dim', text: ' highlighted this' }),
|
|
817
|
+
last ? h('br') : null, last ? String(last.body || '') : null)),
|
|
818
|
+
thread.status === 'resolved' ? h('span', { class: 'collab-dim', text: 'Resolved' }) : null);
|
|
819
|
+
item.addEventListener('click', () => jump(thread.id));
|
|
820
|
+
list.append(h('li', null, item));
|
|
596
821
|
}
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
placePicker();
|
|
601
|
-
const open = [...threads.values()].filter((thread) => !thread.draft && thread.status !== 'resolved').length;
|
|
602
|
-
launcher.querySelector('.collab-count').textContent = String(open);
|
|
603
|
-
launcher.setAttribute('aria-label', open === 1 ? '1 open review thread' : open + ' open review threads');
|
|
822
|
+
const count = all.filter((thread) => thread.status !== 'resolved').length;
|
|
823
|
+
launcher.querySelector('.collab-count').textContent = String(count);
|
|
824
|
+
launcher.setAttribute('aria-label', count === 1 ? '1 open comment thread' : count + ' open comment threads');
|
|
604
825
|
};
|
|
605
826
|
|
|
827
|
+
const refresh = () => { paintMarks(); paintPins(); paintRail(); refreshCard(); };
|
|
828
|
+
|
|
829
|
+
// --- Server state ------------------------------------------------------------
|
|
606
830
|
// The single door every server snapshot comes through, from the stream, from
|
|
607
831
|
// catch-up, and from a write's own response. Snapshots are whole threads and
|
|
608
|
-
// each carries the cursor it was written at, so
|
|
609
|
-
//
|
|
610
|
-
//
|
|
611
|
-
// whose response is overtaken by someone else's resolve would silently reopen
|
|
612
|
-
// that thread on the replying reader's screen and stay wrong.
|
|
832
|
+
// each carries the cursor it was written at, so a thread never moves
|
|
833
|
+
// backwards: a slow write response that lands after a teammate's newer change
|
|
834
|
+
// must not revert it.
|
|
613
835
|
const upsert = (thread) => {
|
|
614
836
|
if (!thread || !thread.id) return false;
|
|
615
837
|
const existing = threads.get(thread.id);
|
|
616
838
|
if (existing && Number(thread.cursor || 0) < Number(existing.cursor || 0)) return false;
|
|
617
|
-
|
|
839
|
+
remember(thread.created_by);
|
|
840
|
+
for (const comment of thread.comments || []) remember(comment.author);
|
|
841
|
+
threads.set(thread.id, { ...existing, ...thread, comments: thread.comments || [], error: null });
|
|
618
842
|
return true;
|
|
619
843
|
};
|
|
620
844
|
|
|
@@ -623,31 +847,29 @@ export const COLLAB_SCRIPT = `<script>
|
|
|
623
847
|
// so a reconnect that replays and a catch-up that refetches land exactly once.
|
|
624
848
|
const applyEnvelope = (rawId, payload) => {
|
|
625
849
|
// SSE hands back a string cursor and JSON hands back a number; both name the
|
|
626
|
-
// same durable change, so the dedupe key is normalized
|
|
627
|
-
// an event the stream already delivered.
|
|
850
|
+
// same durable change, so the dedupe key is normalized.
|
|
628
851
|
const id = rawId === null || rawId === undefined ? '' : String(rawId);
|
|
629
852
|
if (!id || seen.has(id)) return false;
|
|
630
853
|
seen.add(id);
|
|
631
854
|
// Envelopes carry whole-thread snapshots, so one at or before the newest
|
|
632
|
-
// change already materialized holds nothing new.
|
|
633
|
-
// whole stream to a fresh subscriber would otherwise walk a resolved thread
|
|
634
|
-
// back to open, because the newest event is the one already deduped.
|
|
855
|
+
// change already materialized holds nothing new.
|
|
635
856
|
if (Number(id) <= Number(cursor || 0)) return false;
|
|
636
857
|
appliedEvents += 1;
|
|
637
858
|
cursor = String(id);
|
|
638
859
|
if (payload && payload.thread) {
|
|
639
860
|
// The stream can outrun the POST response for the author's own write. The
|
|
640
|
-
// server echoes the idempotency key, so the optimistic row is retired
|
|
641
|
-
// the event instead of briefly double-painting its own selection.
|
|
861
|
+
// server echoes the idempotency key, so the optimistic row is retired here.
|
|
642
862
|
if (payload.thread.idempotency_key) threads.delete('pending:' + payload.thread.idempotency_key);
|
|
643
863
|
const previous = threads.get(payload.thread.id);
|
|
644
864
|
upsert(payload.thread);
|
|
645
|
-
const
|
|
646
|
-
const
|
|
647
|
-
|
|
648
|
-
|
|
865
|
+
const comments = payload.thread.comments || [];
|
|
866
|
+
const last = comments[comments.length - 1];
|
|
867
|
+
const actor = last ? last.author : payload.thread.created_by;
|
|
868
|
+
if (!actor || actor.id !== viewerId()) {
|
|
869
|
+
const who = (actor && actor.name) || 'a teammate';
|
|
870
|
+
if (!previous) announce((last ? 'New comment from ' : 'New highlight from ') + who);
|
|
649
871
|
else if (previous.status !== payload.thread.status) announce('Thread ' + payload.thread.status);
|
|
650
|
-
else announce('New comment from ' +
|
|
872
|
+
else announce('New comment from ' + who);
|
|
651
873
|
}
|
|
652
874
|
}
|
|
653
875
|
return true;
|
|
@@ -663,59 +885,58 @@ export const COLLAB_SCRIPT = `<script>
|
|
|
663
885
|
else { upsert(thread); if (thread.cursor) { seen.add(String(thread.cursor)); if (Number(thread.cursor) > Number(cursor || 0)) cursor = String(thread.cursor); } }
|
|
664
886
|
}
|
|
665
887
|
if (!after && payload.cursor && Number(payload.cursor) > Number(cursor || 0)) cursor = String(payload.cursor);
|
|
666
|
-
|
|
667
|
-
paintAll();
|
|
888
|
+
refresh();
|
|
668
889
|
};
|
|
669
890
|
|
|
670
891
|
const connect = () => {
|
|
671
892
|
stream = new EventSource(endpoint('/__collab/events', { share }));
|
|
672
893
|
// The browser resends Last-Event-ID on its own reconnect; the explicit
|
|
673
|
-
// catch-up covers everything the server could not replay from memory.
|
|
674
|
-
// paths funnel through applyEnvelope, so the overlap is deduped, not doubled.
|
|
894
|
+
// catch-up covers everything the server could not replay from memory.
|
|
675
895
|
stream.addEventListener('open', () => { loadThreads(cursor || '0').catch(() => {}); });
|
|
676
896
|
stream.addEventListener('thread', (event) => {
|
|
677
897
|
let payload = null;
|
|
678
898
|
try { payload = JSON.parse(event.data); } catch { return; }
|
|
679
|
-
if (applyEnvelope(event.lastEventId, payload))
|
|
899
|
+
if (applyEnvelope(event.lastEventId, payload)) refresh();
|
|
680
900
|
});
|
|
681
901
|
};
|
|
682
902
|
|
|
683
|
-
const
|
|
684
|
-
|
|
903
|
+
const settleWrite = (result) => {
|
|
904
|
+
upsert(result.thread);
|
|
905
|
+
if (result.cursor) { seen.add(String(result.cursor)); if (Number(result.cursor) > Number(cursor || 0)) cursor = String(result.cursor); }
|
|
906
|
+
};
|
|
907
|
+
|
|
908
|
+
// An empty box is a highlight: a thread with no comment.
|
|
909
|
+
const createThread = async (anchor, body, mentions, tagged) => {
|
|
685
910
|
const key = idempotencyKey();
|
|
686
911
|
const optimisticId = 'pending:' + key;
|
|
687
|
-
const
|
|
688
|
-
threads.delete('draft');
|
|
689
|
-
draft = null;
|
|
912
|
+
const now = new Date().toISOString();
|
|
690
913
|
threads.set(optimisticId, {
|
|
691
|
-
id: optimisticId, status: 'open', anchor,
|
|
692
|
-
comments: [{ id: optimisticId + ':1', body, author:
|
|
914
|
+
id: optimisticId, status: 'open', anchor, pending: true, created_by: viewerActor(), created_at: now,
|
|
915
|
+
comments: body ? [{ id: optimisticId + ':1', body, mentions, author: viewerActor(), created_at: now, pending: true }] : [],
|
|
693
916
|
});
|
|
694
|
-
|
|
695
|
-
|
|
917
|
+
open = null;
|
|
918
|
+
pop.hidden = true;
|
|
919
|
+
pop.replaceChildren();
|
|
920
|
+
refresh();
|
|
696
921
|
try {
|
|
697
|
-
const result = await send('POST', '/__collab/threads', { anchor, body, ...(mentions.length ? { mentions } : {}) }, key);
|
|
922
|
+
const result = await send('POST', '/__collab/threads', { anchor, ...(body ? { body } : {}), ...(mentions.length ? { mentions } : {}) }, key);
|
|
698
923
|
threads.delete(optimisticId);
|
|
699
924
|
settleWrite(result);
|
|
700
|
-
|
|
701
|
-
renderRail(); paintAll();
|
|
925
|
+
announce(body ? 'Comment posted' : 'Highlighted');
|
|
702
926
|
} catch (error) {
|
|
703
927
|
// Roll the optimistic thread back and hand the text to the reader again,
|
|
704
928
|
// rather than leaving a comment on screen that the server never stored.
|
|
705
929
|
threads.delete(optimisticId);
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
selected = 'draft';
|
|
709
|
-
renderRail(); paintAll();
|
|
930
|
+
refresh();
|
|
931
|
+
compose(anchor, { text: body, people: tagged, error: 'Not sent: ' + error.message });
|
|
710
932
|
announce('Comment could not be sent. ' + error.message);
|
|
933
|
+
return;
|
|
711
934
|
}
|
|
935
|
+
refresh();
|
|
712
936
|
};
|
|
713
937
|
|
|
714
938
|
// Re-reads the thread out of the map rather than trusting the object captured
|
|
715
|
-
// when the button was clicked
|
|
716
|
-
// a fresh object, so an in-place edit of the captured one — in particular the
|
|
717
|
-
// rollback and its error message — would be written to a detached object and
|
|
718
|
-
// never reach the screen, losing the failure silently.
|
|
939
|
+
// when the button was clicked: a concurrent write replaces the map entry.
|
|
719
940
|
const revise = (id, change) => {
|
|
720
941
|
const current = threads.get(id);
|
|
721
942
|
if (!current) return null;
|
|
@@ -724,36 +945,28 @@ export const COLLAB_SCRIPT = `<script>
|
|
|
724
945
|
return next;
|
|
725
946
|
};
|
|
726
947
|
|
|
727
|
-
const settleWrite = (result) => {
|
|
728
|
-
upsert(result.thread);
|
|
729
|
-
if (result.cursor) { seen.add(String(result.cursor)); if (Number(result.cursor) > Number(cursor || 0)) cursor = String(result.cursor); }
|
|
730
|
-
};
|
|
731
|
-
|
|
732
948
|
// A rollback only undoes this write. If a newer server snapshot landed while
|
|
733
|
-
// the request was in flight it already carries the truth
|
|
734
|
-
// change is gone anyway and only the error is worth adding.
|
|
949
|
+
// the request was in flight it already carries the truth.
|
|
735
950
|
const overtaken = (before, current) => Number(current.cursor || 0) > Number(before);
|
|
736
951
|
|
|
737
|
-
const replyTo = async (
|
|
738
|
-
const id = thread.id;
|
|
952
|
+
const replyTo = async (id, body, mentions, tagged) => {
|
|
739
953
|
const key = idempotencyKey();
|
|
740
954
|
const optimisticId = 'pending:' + key;
|
|
955
|
+
const reply = open && open.id === id ? open.reply : null;
|
|
956
|
+
if (reply) reply.set('', []);
|
|
741
957
|
revise(id, (current) => ({
|
|
742
|
-
comments: [...current.comments, { id: optimisticId, body, author:
|
|
743
|
-
|
|
958
|
+
comments: [...current.comments, { id: optimisticId, body, mentions, author: viewerActor(), created_at: new Date().toISOString(), pending: true }],
|
|
959
|
+
error: null,
|
|
744
960
|
}));
|
|
745
|
-
|
|
961
|
+
refresh();
|
|
746
962
|
try {
|
|
747
963
|
settleWrite(await send('POST', '/__collab/threads/' + encodeURIComponent(id) + '/replies', { body, ...(mentions.length ? { mentions } : {}) }, key));
|
|
748
|
-
revise(id, () => ({ mentions: [] }));
|
|
749
964
|
} catch (error) {
|
|
750
|
-
revise(id, (current) => ({
|
|
751
|
-
|
|
752
|
-
composer: true, composerValue: body, error: 'Not sent: ' + error.message,
|
|
753
|
-
}));
|
|
965
|
+
revise(id, (current) => ({ comments: current.comments.filter((comment) => comment.id !== optimisticId), error: 'Not sent: ' + error.message }));
|
|
966
|
+
if (open && open.id === id && open.reply) open.reply.set(body, tagged);
|
|
754
967
|
announce('Reply could not be sent. ' + error.message);
|
|
755
968
|
}
|
|
756
|
-
|
|
969
|
+
refresh();
|
|
757
970
|
};
|
|
758
971
|
|
|
759
972
|
const patchComment = async (thread, commentId, payload, failureMessage) => {
|
|
@@ -769,7 +982,7 @@ export const COLLAB_SCRIPT = `<script>
|
|
|
769
982
|
editing: current.editing === commentId ? null : current.editing,
|
|
770
983
|
error: null,
|
|
771
984
|
}));
|
|
772
|
-
|
|
985
|
+
refresh();
|
|
773
986
|
try {
|
|
774
987
|
settleWrite(await send('PATCH', '/__collab/comments/' + encodeURIComponent(commentId), payload, key));
|
|
775
988
|
} catch (error) {
|
|
@@ -781,7 +994,7 @@ export const COLLAB_SCRIPT = `<script>
|
|
|
781
994
|
}));
|
|
782
995
|
announce(failureMessage + ' ' + error.message);
|
|
783
996
|
}
|
|
784
|
-
|
|
997
|
+
refresh();
|
|
785
998
|
};
|
|
786
999
|
|
|
787
1000
|
const setStatus = async (thread, status) => {
|
|
@@ -790,7 +1003,7 @@ export const COLLAB_SCRIPT = `<script>
|
|
|
790
1003
|
const baseCursor = Number(thread.cursor || 0);
|
|
791
1004
|
const key = idempotencyKey();
|
|
792
1005
|
revise(id, () => ({ status, error: null }));
|
|
793
|
-
|
|
1006
|
+
refresh();
|
|
794
1007
|
try {
|
|
795
1008
|
settleWrite(await send('PATCH', '/__collab/threads/' + encodeURIComponent(id), { status }, key));
|
|
796
1009
|
} catch (error) {
|
|
@@ -800,56 +1013,37 @@ export const COLLAB_SCRIPT = `<script>
|
|
|
800
1013
|
}));
|
|
801
1014
|
announce('Status not saved. ' + error.message);
|
|
802
1015
|
}
|
|
803
|
-
|
|
1016
|
+
refresh();
|
|
804
1017
|
};
|
|
805
1018
|
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
if (!target) return;
|
|
809
|
-
const item = target.closest('[data-thread-id]');
|
|
810
|
-
const thread = item && threads.get(item.dataset.threadId);
|
|
811
|
-
if (!thread) return;
|
|
812
|
-
const action = target.dataset.collabAction;
|
|
813
|
-
// Rendering replaces the clicked item, so the new field is found through the list.
|
|
814
|
-
const field = (form) => list.querySelector('[data-thread-id="' + CSS.escape(thread.id) + '"] .' + form + ' textarea');
|
|
815
|
-
if (action === 'reply') { thread.composer = true; thread.composerValue = ''; renderRail(); field('collab-composer')?.focus(); return; }
|
|
816
|
-
if (action === 'cancel') {
|
|
817
|
-
closeMentions();
|
|
818
|
-
if (thread.draft) { threads.delete('draft'); draft = null; selected = null; }
|
|
819
|
-
else { thread.composer = false; thread.composerValue = ''; thread.error = null; }
|
|
820
|
-
renderRail(); paintAll(); return;
|
|
821
|
-
}
|
|
822
|
-
if (action === 'resolve') { setStatus(thread, 'resolved'); return; }
|
|
823
|
-
if (action === 'reopen') { setStatus(thread, 'open'); return; }
|
|
824
|
-
if (action === 'delete') { patchComment(thread, target.dataset.collabTarget, { deleted: true }, 'Delete failed.'); return; }
|
|
825
|
-
if (action === 'edit') {
|
|
826
|
-
const comment = thread.comments.find((value) => value.id === target.dataset.collabTarget);
|
|
827
|
-
if (!comment) return;
|
|
828
|
-
thread.editing = comment.id;
|
|
829
|
-
thread.editValue = comment.body;
|
|
830
|
-
renderRail(); field('collab-editor')?.focus(); return;
|
|
831
|
-
}
|
|
832
|
-
if (action === 'cancel-edit') { thread.editing = null; renderRail(); }
|
|
833
|
-
});
|
|
834
|
-
|
|
835
|
-
list.addEventListener('focusin', (event) => {
|
|
836
|
-
const item = event.target.closest('[data-thread-id]');
|
|
837
|
-
if (!item || item.dataset.threadId === selected) return;
|
|
838
|
-
selected = item.dataset.threadId;
|
|
839
|
-
paintAll();
|
|
840
|
-
});
|
|
841
|
-
|
|
842
|
-
rail.addEventListener('click', (event) => { if (event.target.closest('.collab-close')) closeRail(); });
|
|
1019
|
+
// --- Wiring ------------------------------------------------------------------
|
|
1020
|
+
rail.querySelector('.collab-close').addEventListener('click', () => closeRail());
|
|
843
1021
|
rail.addEventListener('keydown', (event) => { if (event.key === 'Escape') { event.preventDefault(); closeRail(); } });
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
1022
|
+
pop.addEventListener('keydown', (event) => { if (event.key === 'Escape') { event.preventDefault(); closePop(true); } });
|
|
1023
|
+
launcher.addEventListener('click', () => { if (!rail.hidden) { closeRail(); return; } openRail(true); });
|
|
1024
|
+
// A press anywhere else closes the box; the press that lands on a mark or a
|
|
1025
|
+
// pin opens that thread instead.
|
|
1026
|
+
document.addEventListener('pointerdown', (event) => {
|
|
1027
|
+
if (!open || pop.contains(event.target) || event.target.closest('.collab-pin, mark[data-collab-thread], .collab-rail, .agents-share-bar')) return;
|
|
1028
|
+
closePop(false);
|
|
1029
|
+
}, true);
|
|
1030
|
+
addEventListener('resize', () => { paintPins(); place(); });
|
|
1031
|
+
addEventListener('scroll', place, { passive: true });
|
|
1032
|
+
if (window.ResizeObserver) new ResizeObserver(() => paintPins()).observe(reader.root);
|
|
1033
|
+
// A notice links to #thread=<id>: that thread opens where it sits.
|
|
1034
|
+
const openFromHash = () => {
|
|
1035
|
+
const found = /^#thread=([^&]+)$/.exec(location.hash);
|
|
1036
|
+
let id = null;
|
|
1037
|
+
try { id = found && decodeURIComponent(found[1]); } catch {}
|
|
1038
|
+
if (id && threads.has(id)) jump(id);
|
|
1039
|
+
};
|
|
1040
|
+
addEventListener('hashchange', openFromHash);
|
|
848
1041
|
|
|
849
1042
|
const mount = async () => {
|
|
850
|
-
if (hostedLauncher) document.body.append(rail,
|
|
851
|
-
else document.body.append(rail, launcher,
|
|
1043
|
+
if (hostedLauncher) document.body.append(rail, pins, pop, liveRegion);
|
|
1044
|
+
else document.body.append(rail, launcher, pins, pop, liveRegion);
|
|
852
1045
|
launcher.hidden = false;
|
|
1046
|
+
remember(context.viewer);
|
|
853
1047
|
const label = visibilityLabel(context.visibility);
|
|
854
1048
|
const chip = rail.querySelector('.collab-visibility');
|
|
855
1049
|
if (label) { chip.textContent = label; chip.hidden = false; }
|
|
@@ -858,22 +1052,20 @@ export const COLLAB_SCRIPT = `<script>
|
|
|
858
1052
|
provenance.textContent = 'Produced by ' + [context.producer.agent, context.producer.session].filter(Boolean).join(' · ');
|
|
859
1053
|
provenance.hidden = false;
|
|
860
1054
|
}
|
|
1055
|
+
// Selecting text opens the box at once. A selection that starts on a mark
|
|
1056
|
+
// opens that mark's thread instead of a second one on the same words.
|
|
861
1057
|
if (canComment()) {
|
|
862
|
-
window.__artifactsSelection?.
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
selected = 'draft';
|
|
869
|
-
returnTo = null;
|
|
870
|
-
openRail(false);
|
|
871
|
-
renderRail();
|
|
872
|
-
list.querySelector('[data-thread-id="draft"] textarea')?.focus();
|
|
1058
|
+
window.__artifactsSelection?.claim((record) => {
|
|
1059
|
+
const start = getSelection().anchorNode;
|
|
1060
|
+
const mark = start && start.parentElement && start.parentElement.closest('mark[data-collab-thread]');
|
|
1061
|
+
getSelection().removeAllRanges();
|
|
1062
|
+
if (mark && threads.has(mark.dataset.collabThread)) showThread(mark.dataset.collabThread, { focus: true });
|
|
1063
|
+
else compose(record);
|
|
873
1064
|
});
|
|
874
1065
|
}
|
|
875
1066
|
await loadThreads();
|
|
876
1067
|
connect();
|
|
1068
|
+
openFromHash();
|
|
877
1069
|
window.__artifactsCollab = {
|
|
878
1070
|
share, revision,
|
|
879
1071
|
appliedEvents: () => appliedEvents,
|
|
@@ -891,8 +1083,8 @@ export const COLLAB_SCRIPT = `<script>
|
|
|
891
1083
|
if (!response.ok) return;
|
|
892
1084
|
discovered = await response.json();
|
|
893
1085
|
} catch { return; }
|
|
894
|
-
// Fail closed on anything short of an explicit read grant: no
|
|
895
|
-
// launcher, no
|
|
1086
|
+
// Fail closed on anything short of an explicit read grant: no list, no
|
|
1087
|
+
// launcher, no marks — the page stays exactly the standalone artifact.
|
|
896
1088
|
if (!discovered || !discovered.permissions || discovered.permissions.read !== true) return;
|
|
897
1089
|
// Rush could not take this page's threads; there is nothing to show.
|
|
898
1090
|
if (discovered.unavailable) return;
|