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