@bigmistqke/whiteboard 0.6.1 → 0.7.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/README.md +13 -7
- package/dist/bin/whiteboard.js +0 -0
- package/dist/client/runtime.js +235 -58
- package/dist/plugins/badge/README.md +3 -1
- package/dist/plugins/badge/public/style.css +17 -0
- package/dist/plugins/chat/public/client.js +2 -2
- package/dist/plugins/chat/public/style.css +9 -0
- package/dist/plugins/comments/public/client.js +7 -2
- package/dist/plugins/comments/public/style.css +4 -0
- package/dist/plugins/grid/public/style.css +0 -5
- package/dist/plugins/index.js +5 -1
- package/dist/plugins/timeline/README.md +40 -0
- package/dist/plugins/timeline/index.js +82 -0
- package/dist/plugins/timeline/public/style.css +118 -0
- package/dist/plugins/toc/README.md +13 -13
- package/dist/plugins/toc/index.js +5 -3
- package/dist/plugins/toc/public/client.js +1 -1
- package/dist/plugins/toc/public/style.css +19 -2
- package/dist/solid/index.js +2 -1
- package/dist/src/auth.js +7 -3
- package/dist/src/client/page/base.css +74 -35
- package/dist/src/client/page/main.js +15 -4
- package/dist/src/events.js +4 -2
- package/dist/src/hub.js +43 -18
- package/dist/src/serve.js +2 -0
- package/dist/src/server.js +49 -11
- package/dist/src/ws.js +128 -0
- package/package.json +1 -1
- package/plugins/badge/README.md +3 -1
- package/plugins/badge/public/style.css +17 -0
- package/plugins/chat/client.tsx +34 -6
- package/plugins/chat/public/style.css +9 -0
- package/plugins/comments/client.ts +48 -5
- package/plugins/comments/public/style.css +4 -0
- package/plugins/grid/public/style.css +0 -5
- package/plugins/index.ts +6 -1
- package/plugins/timeline/README.md +40 -0
- package/plugins/timeline/index.ts +92 -0
- package/plugins/timeline/public/style.css +118 -0
- package/plugins/toc/README.md +13 -13
- package/plugins/toc/client.ts +49 -30
- package/plugins/toc/index.ts +12 -12
- package/plugins/toc/public/style.css +19 -2
- package/solid/index.tsx +3 -0
- package/src/auth.ts +7 -2
- package/src/client/forms.ts +102 -5
- package/src/client/page/base.css +74 -35
- package/src/client/page/elsewhere.ts +12 -3
- package/src/client/page/waiting.ts +10 -5
- package/src/client/read.ts +16 -3
- package/src/client/runtime.ts +134 -45
- package/src/client/toast.ts +35 -5
- package/src/define.ts +10 -0
- package/src/events.ts +7 -1
- package/src/hub.ts +54 -22
- package/src/serve.ts +2 -0
- package/src/server.ts +73 -17
- package/src/ws.ts +155 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=document.createElement(`nav`);e.className=`wb-toc`,e.setAttribute(`aria-label`,`Contents`);const t=document.createElement(`ol`);e.append(t);const n=document.createElement(`button`);n.type=`button`,n.className=`wb-toc-toggle`,n.title=n.ariaLabel=`Contents`,n.innerHTML=`<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"><path d="M2.5 4h11M2.5 8h11M2.5 12h7"/></svg>`;let r,i,a=[];const o=()=>document.querySelector(`.wb-nav`)?.getBoundingClientRect().height??0;function s(){let t=parseFloat(getComputedStyle(e).minWidth)||0;return r.getBoundingClientRect().left>=t+40+16}const c=e=>{let t=/^(\d+(?:\.\d+)?)(px|em|rem|ch|vw)?$/.exec(String(e??``).trim());return t&&Number(t[1])>0?t[1]+(t[2]??`px`):null};function l(){let t=document.querySelector(`meta[name=wb-toc]`),n=d.settings(),r=n&&typeof n==`object`?n:{};for(let[n,i]of[[`minWidth`,`--wb-toc-min-width`],[`maxWidth`,`--wb-toc-max-width`]]){let a=c(r[n])??c(t?.dataset[n]);a?e.style.setProperty(i,a):e.style.removeProperty(i)}}function u(){let t=r.getBoundingClientRect().left;e.style.setProperty(`--wb-toc-right`,`${document.documentElement.clientWidth-t+40}px`),e.style.setProperty(`--wb-toc-room`,`${t-40-16}px`)}let d;function f(){let e=d.settings(),t=document.querySelector(`meta[name=wb-toc]`)?.getAttribute(`content`)===`always`;return e===!1?!1:e===!0||e&&typeof e==`object`?!0:t}function
|
|
1
|
+
const e=document.createElement(`nav`);e.className=`wb-toc`,e.setAttribute(`aria-label`,`Contents`);const t=document.createElement(`ol`);e.append(t);const n=document.createElement(`button`);n.type=`button`,n.className=`wb-toc-toggle`,n.title=n.ariaLabel=`Contents`,n.setAttribute(`aria-expanded`,`false`),n.innerHTML=`<svg viewBox="0 0 16 16" width="14" height="14" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"><path d="M2.5 4h11M2.5 8h11M2.5 12h7"/></svg>`;let r,i,a=[];const o=()=>document.querySelector(`.wb-nav`)?.getBoundingClientRect().height??0;function s(){let t=parseFloat(getComputedStyle(e).minWidth)||0;return r.getBoundingClientRect().left>=t+40+16}const c=e=>{let t=/^(\d+(?:\.\d+)?)(px|em|rem|ch|vw)?$/.exec(String(e??``).trim());return t&&Number(t[1])>0?t[1]+(t[2]??`px`):null};function l(){let t=document.querySelector(`meta[name=wb-toc]`),n=d.settings(),r=n&&typeof n==`object`?n:{};for(let[n,i]of[[`minWidth`,`--wb-toc-min-width`],[`maxWidth`,`--wb-toc-max-width`]]){let a=c(r[n])??c(t?.dataset[n]);a?e.style.setProperty(i,a):e.style.removeProperty(i)}}function u(){let t=r.getBoundingClientRect().left;e.style.setProperty(`--wb-toc-right`,`${document.documentElement.clientWidth-t+40}px`),e.style.setProperty(`--wb-toc-room`,`${t-40-16}px`)}let d;function f(t){e.classList.toggle(`wb-toc-open`,t),e.hidden=!t,n.setAttribute(`aria-expanded`,String(t))}function p(){let e=d.settings(),t=document.querySelector(`meta[name=wb-toc]`)?.getAttribute(`content`)===`always`;return e===!1?!1:e===!0||e&&typeof e==`object`?!0:t}function m(e){let t=e.cloneNode(!0);return t.querySelectorAll(`.wb-badge`).forEach(e=>e.remove()),t.textContent?.trim()??``}function h(){a=p()?[...r.querySelectorAll(`:scope > :is(h2, h3, h4, h5, h6)`)]:[];let i=[0,0,0,0,0],o=[{level:1,list:t}];t.replaceChildren(),a.forEach((e,t)=>{let n=Number(e.tagName[1]);for(i[n-2]++,i.fill(0,n-1);o.length>1&&o.at(-1).level>=n;)o.pop();let r=o.at(-1);r.item&&!r.item.querySelector(`:scope > ol`)&&r.item.append(document.createElement(`ol`));let a=r.item?r.item.querySelector(`:scope > ol`):r.list,s=document.createElement(`li`);s.dataset.level=String(n);let c=document.createElement(`a`);c.href=`#`,c.dataset.index=String(t),c.innerHTML=`<span class="wb-toc-number"></span><span class="wb-toc-text"></span>`,c.querySelector(`.wb-toc-number`).textContent=i.slice(0,n-1).join(`.`),c.querySelector(`.wb-toc-text`).textContent=m(e),s.append(c),a.append(s),o.push({level:n,list:a,item:s})});let c=a.length>1;l(),u(),n.hidden=!c||s(),e.hidden=!c||!s()&&!e.classList.contains(`wb-toc-open`),e.classList.toggle(`wb-toc-docked`,s()),_(),v()}function g(e){let t=-1;for(let n=0;n<a.length&&a[n].compareDocumentPosition(e)&Node.DOCUMENT_POSITION_FOLLOWING;n++)t=n;return t}function _(){let e=/* @__PURE__ */ new Set,n=new Set(i.unread().map(e=>e.id)),o=[...r.querySelectorAll(`form[data-wb-open]`),...[...r.querySelectorAll(`[data-wb-message]`)].filter(e=>n.has(e.dataset.wbMessage))];for(let t of o)e.add(g(t));for(let t of document.querySelectorAll(`[data-wb-holds]`)){if(!t.dataset.wbHolds.split(` `).some(e=>n.has(e)))continue;let r=t.getBoundingClientRect().top,i=-1;a.forEach((e,t)=>{e.getBoundingClientRect().top<=r&&(i=t)}),e.add(i)}t.querySelectorAll(`a`).forEach((t,n)=>t.toggleAttribute(`data-waiting`,e.has(n)))}function v(){let e=o()+40,n=0;a.forEach((t,r)=>{t.getBoundingClientRect().top<=e&&(n=r)}),t.querySelectorAll(`a`).forEach((e,t)=>e.toggleAttribute(`aria-current`,t===n&&a.length>0))}function y(e){let t=a[e];t&&(scrollTo({top:Math.max(0,scrollY+t.getBoundingClientRect().top-o()-12),behavior:`smooth`}),s()||f(!1))}const b=(a,o,s)=>{if(o.kind!==`page`&&o.kind!==`file`)return;d=o,r=a.querySelector(`#wb-main`)??a,i=s,document.body.append(e),a.querySelector(`.wb-nav .wb-theme`)?.before(n),t.addEventListener(`click`,e=>{let t=e.target.closest(`a[data-index]`);t&&(e.preventDefault(),y(Number(t.dataset.index)))}),n.addEventListener(`click`,()=>f(!e.classList.contains(`wb-toc-open`))),document.addEventListener(`keydown`,t=>{t.key===`Escape`&&e.classList.contains(`wb-toc-open`)&&n.click()});let c=0,l=e=>()=>{cancelAnimationFrame(c),c=requestAnimationFrame(e)};addEventListener(`scroll`,l(v),{passive:!0}),addEventListener(`resize`,l(h)),i.onRendered(h),o.settings.on(h),i.forms.on(()=>_()),i.events.on(()=>requestAnimationFrame(_)),h()};export{b as default};
|
|
@@ -38,8 +38,19 @@
|
|
|
38
38
|
margin: 0;
|
|
39
39
|
padding: 0;
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
/* the same space above every item, also the first of a nested list (the page's li + li alone
|
|
42
|
+
would leave that one tight against its section) */
|
|
43
|
+
.wb-toc li {
|
|
44
|
+
margin-top: 0.8em;
|
|
45
|
+
}
|
|
46
|
+
.wb-toc > ol > li:first-child {
|
|
47
|
+
margin-top: 0;
|
|
48
|
+
}
|
|
49
|
+
/* a section's subsections hang on a rail under its number, one rail per level */
|
|
50
|
+
.wb-toc ol ol {
|
|
51
|
+
margin-left: var(--space-md);
|
|
52
|
+
padding-left: var(--space-sm);
|
|
53
|
+
border-left: var(--hairline) solid var(--border, #e3e5e9);
|
|
43
54
|
}
|
|
44
55
|
.wb-toc a {
|
|
45
56
|
display: flex;
|
|
@@ -97,3 +108,9 @@
|
|
|
97
108
|
color: var(--text, CanvasText);
|
|
98
109
|
border-color: var(--muted, #696e76);
|
|
99
110
|
}
|
|
111
|
+
/* the panel is open from it */
|
|
112
|
+
.wb-toc-toggle[aria-expanded='true'] {
|
|
113
|
+
color: var(--accent, #1d5bbf);
|
|
114
|
+
border-color: var(--accent, #1d5bbf);
|
|
115
|
+
background: color-mix(in srgb, var(--accent, #1d5bbf) var(--tint-faint), transparent);
|
|
116
|
+
}
|
package/dist/solid/index.js
CHANGED
package/dist/src/auth.js
CHANGED
|
@@ -13,6 +13,11 @@ function projectToken(wb) {
|
|
|
13
13
|
fs.writeFileSync(file, token + "\n", { mode: 384 });
|
|
14
14
|
return token;
|
|
15
15
|
}
|
|
16
|
+
/** From a page of a whiteboard server on this machine, or from no page at all (the command line)? */
|
|
17
|
+
const sameSite = (req) => {
|
|
18
|
+
const origin = req.headers.origin;
|
|
19
|
+
return !origin || /^http:\/\/(localhost|127\.0\.0\.1)(:\d+)?$/.test(origin);
|
|
20
|
+
};
|
|
16
21
|
/** `base`: the path the project is served under (see ServerOptions), which its cookie is kept to. */
|
|
17
22
|
function createAuth(wb, base = "") {
|
|
18
23
|
const token = projectToken(wb);
|
|
@@ -23,8 +28,7 @@ function createAuth(wb, base = "") {
|
|
|
23
28
|
if (!req) return false;
|
|
24
29
|
const jar = cookies(req);
|
|
25
30
|
if (!(same(jar[COOKIE], token) || same(req.headers["x-whiteboard-token"], token))) return false;
|
|
26
|
-
|
|
27
|
-
if (origin && !/^http:\/\/(localhost|127\.0\.0\.1)(:\d+)?$/.test(origin)) return false;
|
|
31
|
+
if (!sameSite(req)) return false;
|
|
28
32
|
const site = req.headers["sec-fetch-site"];
|
|
29
33
|
if (site && site !== "same-origin" && site !== "none" && !opensPage(req)) return false;
|
|
30
34
|
return true;
|
|
@@ -53,4 +57,4 @@ function createAuth(wb, base = "") {
|
|
|
53
57
|
token
|
|
54
58
|
};
|
|
55
59
|
}
|
|
56
|
-
export { createAuth, projectToken };
|
|
60
|
+
export { createAuth, projectToken, sameSite };
|
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
--warn: light-dark(#6b4fc0, #b4a0ff);
|
|
20
20
|
--bad: light-dark(#c4352b, #ff6f66);
|
|
21
21
|
--info: light-dark(#1d5bbf, #82aaff);
|
|
22
|
+
/* what the reader sent, shown at once but not yet confirmed by the server (an event with
|
|
23
|
+
`sending`): grey, in whatever carries it (a button, a bubble, a comment's text). Confirmed, it
|
|
24
|
+
takes its usual colour (a button flashes --ok first); never got there, --bad */
|
|
25
|
+
--wb-sending: light-dark(#9a9fa7, #6c717a);
|
|
22
26
|
--shadow: none;
|
|
23
27
|
|
|
24
28
|
/* Type. The article is set in --serif at --text-size; everything in it (its margins, its
|
|
@@ -302,7 +306,7 @@ hr::after {
|
|
|
302
306
|
letter-spacing: 0.3em;
|
|
303
307
|
}
|
|
304
308
|
|
|
305
|
-
/* section numbers hanging in the margin: 1, 1.1, 1.1.1, in italic oldstyle figures. Only the
|
|
309
|
+
/* section numbers hanging in the margin: 1, 1.1, 1.1.1, down to h6, in italic oldstyle figures. Only the
|
|
306
310
|
page's own headings (direct children of main), so headings inside cards stay unnumbered. The
|
|
307
311
|
number is an inline-block pulled into the margin, so it shares the heading's baseline. */
|
|
308
312
|
#wb-main {
|
|
@@ -318,8 +322,16 @@ hr::after {
|
|
|
318
322
|
}
|
|
319
323
|
#wb-main > h4 {
|
|
320
324
|
counter-increment: h4;
|
|
325
|
+
counter-reset: h5;
|
|
321
326
|
}
|
|
322
|
-
#wb-main >
|
|
327
|
+
#wb-main > h5 {
|
|
328
|
+
counter-increment: h5;
|
|
329
|
+
counter-reset: h6;
|
|
330
|
+
}
|
|
331
|
+
#wb-main > h6 {
|
|
332
|
+
counter-increment: h6;
|
|
333
|
+
}
|
|
334
|
+
#wb-main > :is(h2, h3, h4, h5, h6)::before {
|
|
323
335
|
display: inline-block;
|
|
324
336
|
box-sizing: content-box;
|
|
325
337
|
width: 64px;
|
|
@@ -347,12 +359,18 @@ hr::after {
|
|
|
347
359
|
content: counter(h2) '.' counter(h3) '.' counter(h4);
|
|
348
360
|
font-size: 1.3em;
|
|
349
361
|
}
|
|
362
|
+
#wb-main > h5::before {
|
|
363
|
+
content: counter(h2) '.' counter(h3) '.' counter(h4) '.' counter(h5);
|
|
364
|
+
}
|
|
365
|
+
#wb-main > h6::before {
|
|
366
|
+
content: counter(h2) '.' counter(h3) '.' counter(h4) '.' counter(h5) '.' counter(h6);
|
|
367
|
+
}
|
|
350
368
|
/* no margin to hang them in: set the number in front of the heading, and indent less */
|
|
351
369
|
@media (max-width: 860px) {
|
|
352
370
|
main {
|
|
353
371
|
--indent: 0px;
|
|
354
372
|
}
|
|
355
|
-
#wb-main > :is(h2, h3, h4)::before {
|
|
373
|
+
#wb-main > :is(h2, h3, h4, h5, h6)::before {
|
|
356
374
|
width: auto;
|
|
357
375
|
margin-left: 0;
|
|
358
376
|
margin-right: 0.6em;
|
|
@@ -682,14 +700,32 @@ form.wb-form[data-wb-folded] {
|
|
|
682
700
|
gap: 0;
|
|
683
701
|
}
|
|
684
702
|
/* named forms: the core marks where each stands (data-wb-open, -pending, -decided); this is how that looks */
|
|
685
|
-
form
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
form[data-wb-
|
|
690
|
-
|
|
703
|
+
/* the button a form was sent with says how that goes (forms.ts): the answer is the form's already
|
|
704
|
+
(optimistic), the button grey while the server hasn't confirmed it, green a moment once it has,
|
|
705
|
+
red ("Try again") when it never got there. The form stays usable: the same answer isn't sent twice. !important: a send's
|
|
706
|
+
state outranks however a plugin or the project styles its buttons (.wb-primary) */
|
|
707
|
+
form button[data-wb-send] {
|
|
708
|
+
transition:
|
|
709
|
+
background-color 0.2s,
|
|
710
|
+
border-color 0.2s,
|
|
711
|
+
color 0.2s;
|
|
712
|
+
}
|
|
713
|
+
form button[data-wb-send='sending'] {
|
|
714
|
+
background: var(--wb-sending) !important;
|
|
715
|
+
border-color: var(--wb-sending) !important;
|
|
716
|
+
color: var(--bg) !important;
|
|
691
717
|
cursor: progress;
|
|
692
718
|
}
|
|
719
|
+
form button[data-wb-send='sent'] {
|
|
720
|
+
background: var(--ok) !important;
|
|
721
|
+
border-color: var(--ok) !important;
|
|
722
|
+
color: var(--bg) !important;
|
|
723
|
+
}
|
|
724
|
+
form button[data-wb-send='failed'] {
|
|
725
|
+
background: var(--bad) !important;
|
|
726
|
+
border-color: var(--bad) !important;
|
|
727
|
+
color: var(--bg) !important;
|
|
728
|
+
}
|
|
693
729
|
/* just sent: a short green flash, and a line saying what happened, for a few seconds */
|
|
694
730
|
@keyframes wb-sent {
|
|
695
731
|
from {
|
|
@@ -702,23 +738,16 @@ form[data-wb-state='sending'] button {
|
|
|
702
738
|
form[data-wb-just-sent] {
|
|
703
739
|
animation: wb-sent 1.4s ease-out;
|
|
704
740
|
}
|
|
705
|
-
form
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
margin-
|
|
709
|
-
color: var(--
|
|
710
|
-
font: var(--
|
|
711
|
-
}
|
|
712
|
-
form[data-wb-sent]:not(.wb-form)::after {
|
|
713
|
-
content: '✓ sent ' attr(data-wb-sent);
|
|
714
|
-
display: block;
|
|
715
|
-
margin-top: var(--space-sm);
|
|
716
|
-
color: var(--ok);
|
|
717
|
-
font: var(--ui-small) var(--sans);
|
|
741
|
+
/* what a sent answer came to, beside the form's last send button (forms.ts): waiting for the agent
|
|
742
|
+
(muted), couldn't send (red) */
|
|
743
|
+
.wb-form-status {
|
|
744
|
+
margin-left: var(--space-md);
|
|
745
|
+
color: var(--muted);
|
|
746
|
+
font: var(--ui-tiny)/var(--ui-line-height) var(--sans);
|
|
718
747
|
}
|
|
719
|
-
form[data-
|
|
720
|
-
content: 'failed to send';
|
|
748
|
+
.wb-form-status[data-kind='bad'] {
|
|
721
749
|
color: var(--bad);
|
|
750
|
+
font-weight: var(--weight-strong);
|
|
722
751
|
}
|
|
723
752
|
|
|
724
753
|
/* a question the reader hasn't answered, or one the agent asks again: outlined, without a label of
|
|
@@ -730,21 +759,25 @@ form[data-wb-open] {
|
|
|
730
759
|
}
|
|
731
760
|
/* the outline sets it off: the form's rules above and below (its borders, which the outline would
|
|
732
761
|
enclose) step aside meanwhile */
|
|
733
|
-
form.wb-form[data-wb-open] {
|
|
762
|
+
form.wb-form:is([data-wb-open], [data-wb-pending], [data-wb-state='sending'], [data-wb-state='failed']) {
|
|
734
763
|
border-top-color: transparent;
|
|
735
764
|
border-bottom-color: transparent;
|
|
736
765
|
}
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
font: var(--ui-tiny)/var(--ui-line-height) var(--sans);
|
|
766
|
+
/* the outline speaks the language of a send too: grey while the answer is on its way (it is the
|
|
767
|
+
form's already, so no longer outlined as unanswered) and while it waits for the agent to pick it
|
|
768
|
+
up, red when it never got there; gone once the agent took it (decided) */
|
|
769
|
+
form:is([data-wb-open], [data-wb-pending], [data-wb-state='sending'], [data-wb-state='failed']) {
|
|
770
|
+
transition: outline-color 0.2s;
|
|
743
771
|
}
|
|
744
|
-
form[data-wb-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
772
|
+
form:is([data-wb-state='sending'], [data-wb-pending]) {
|
|
773
|
+
outline: 2px solid var(--wb-sending);
|
|
774
|
+
outline-offset: 10px;
|
|
775
|
+
border-radius: var(--radius-sm);
|
|
776
|
+
}
|
|
777
|
+
form[data-wb-state='failed'] {
|
|
778
|
+
outline: 2px solid var(--bad);
|
|
779
|
+
outline-offset: 10px;
|
|
780
|
+
border-radius: var(--radius-sm);
|
|
748
781
|
}
|
|
749
782
|
|
|
750
783
|
/* decided: the agent picked up the latest answer; the form folds into one line quoting it */
|
|
@@ -1236,3 +1269,9 @@ main:has(+ .wb-orphans:not([hidden])) {
|
|
|
1236
1269
|
:root[data-wb-window-maximized] {
|
|
1237
1270
|
overflow: hidden;
|
|
1238
1271
|
}
|
|
1272
|
+
@media (prefers-reduced-motion: reduce) {
|
|
1273
|
+
form button[data-wb-send],
|
|
1274
|
+
form:is([data-wb-open], [data-wb-pending], [data-wb-state='sending'], [data-wb-state='failed']) {
|
|
1275
|
+
transition: none;
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
@@ -851,10 +851,17 @@ async function load() {
|
|
|
851
851
|
list.replaceChildren(...rest.length && mine.length ? [heading("here")] : [], ...mine.map(item), ...rest.flatMap((g) => [heading(g.label), ...g.pages.map(item)]));
|
|
852
852
|
}
|
|
853
853
|
let timer = 0;
|
|
854
|
+
let stale = false;
|
|
854
855
|
const reload = () => {
|
|
855
856
|
clearTimeout(timer);
|
|
857
|
+
if (document.hidden) return void (stale = true);
|
|
856
858
|
timer = window.setTimeout(load, 100);
|
|
857
859
|
};
|
|
860
|
+
document.addEventListener("visibilitychange", () => {
|
|
861
|
+
if (document.hidden || !stale) return;
|
|
862
|
+
stale = false;
|
|
863
|
+
reload();
|
|
864
|
+
});
|
|
858
865
|
function trackElsewhere(root, handle, core) {
|
|
859
866
|
current$1 = handle.id;
|
|
860
867
|
const nav = root.querySelector(".wb-nav");
|
|
@@ -874,7 +881,7 @@ function trackElsewhere(root, handle, core) {
|
|
|
874
881
|
core.listeners.on(reload);
|
|
875
882
|
handle.onChange(reload);
|
|
876
883
|
load();
|
|
877
|
-
if (base)
|
|
884
|
+
if (base) document.addEventListener("wb-elsewhere", reload);
|
|
878
885
|
}
|
|
879
886
|
// src/client/page/waiting.ts
|
|
880
887
|
const ORDER = STATES;
|
|
@@ -1074,10 +1081,14 @@ function trackWaiting(root, core) {
|
|
|
1074
1081
|
if (form.dataset.wbState === "sending") return;
|
|
1075
1082
|
sent.disconnect();
|
|
1076
1083
|
if (form.dataset.wbState !== "sent") return;
|
|
1077
|
-
if (fallback) api$1.toast("Sent
|
|
1078
|
-
|
|
1084
|
+
if (fallback) api$1.toast("Sent · to the fallback agent", {
|
|
1085
|
+
name: "sent",
|
|
1086
|
+
details: "No agent waits on this page, so the fallback agent picks it up."
|
|
1087
|
+
});
|
|
1088
|
+
else api$1.toast("Sent · no agent listening", {
|
|
1079
1089
|
kind: "warn",
|
|
1080
|
-
name: "sent"
|
|
1090
|
+
name: "sent",
|
|
1091
|
+
details: "Your answer stays in the log until an agent checks this page."
|
|
1081
1092
|
});
|
|
1082
1093
|
});
|
|
1083
1094
|
sent.observe(form, {
|
package/dist/src/events.js
CHANGED
|
@@ -7,6 +7,8 @@ import crypto from "node:crypto";
|
|
|
7
7
|
* `{ session }`. The colon keeps it apart from form names, which are event types too.
|
|
8
8
|
*/
|
|
9
9
|
const CLAIM = "whiteboard:claim";
|
|
10
|
+
/** An event id as the log has them: the time in base 36, a dash, random hex. */
|
|
11
|
+
const isEventId = (id) => typeof id === "string" && /^[0-9a-z]{6,12}-[0-9a-f]{6,32}$/.test(id);
|
|
10
12
|
/**
|
|
11
13
|
* Append one event; `action` is the button that submitted a form, null for anything else. `from`
|
|
12
14
|
* is set only for events the command line writes ('cli'), so that waits skip them and pages can
|
|
@@ -14,7 +16,7 @@ const CLAIM = "whiteboard:claim";
|
|
|
14
16
|
*/
|
|
15
17
|
function appendEvent(file, input, from = null) {
|
|
16
18
|
const event = {
|
|
17
|
-
id: `${Date.now().toString(36)}-${crypto.randomBytes(3).toString("hex")}`,
|
|
19
|
+
id: isEventId(input.id) ? input.id : `${Date.now().toString(36)}-${crypto.randomBytes(3).toString("hex")}`,
|
|
18
20
|
ts: (/* @__PURE__ */ new Date()).toISOString(),
|
|
19
21
|
page: String(input.page ?? ""),
|
|
20
22
|
type: String(input.type ?? ""),
|
|
@@ -298,4 +300,4 @@ function handOut(file, filter, onEvent, options = {}) {
|
|
|
298
300
|
}, { interval });
|
|
299
301
|
});
|
|
300
302
|
}
|
|
301
|
-
export { CLAIM, PICKED, appendEvent, editEvent, follow, forAgent, fromReader, handOut, matches, parseLines, pick, pickedUp, prune, read, readEvents, rewrite };
|
|
303
|
+
export { CLAIM, PICKED, appendEvent, editEvent, follow, forAgent, fromReader, handOut, isEventId, matches, parseLines, pick, pickedUp, prune, read, readEvents, rewrite };
|
package/dist/src/hub.js
CHANGED
|
@@ -24,7 +24,7 @@ function createHub({ dir = machineDir(), state = stateDir(), home, interval, onS
|
|
|
24
24
|
base: p.base,
|
|
25
25
|
entry: p.entry,
|
|
26
26
|
label: [p.group, p.name].filter(Boolean).join(" › "),
|
|
27
|
-
onChange: () =>
|
|
27
|
+
onChange: () => changed(p.base)
|
|
28
28
|
});
|
|
29
29
|
const fallback = fallbacks.get(p.entry);
|
|
30
30
|
served.set(key, {
|
|
@@ -63,9 +63,19 @@ function createHub({ dir = machineDir(), state = stateDir(), home, interval, onS
|
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
65
|
let touching;
|
|
66
|
+
const changes = /* @__PURE__ */ new Set();
|
|
66
67
|
const touch = () => {
|
|
67
68
|
clearTimeout(touching);
|
|
68
|
-
touching = setTimeout(() =>
|
|
69
|
+
touching = setTimeout(() => {
|
|
70
|
+
root.touch();
|
|
71
|
+
const from = [...changes];
|
|
72
|
+
changes.clear();
|
|
73
|
+
for (const s of served.values()) if (from.some((b) => b !== s.base)) s.server.elsewhere();
|
|
74
|
+
}, 150);
|
|
75
|
+
};
|
|
76
|
+
const changed = (base) => {
|
|
77
|
+
changes.add(base);
|
|
78
|
+
touch();
|
|
69
79
|
};
|
|
70
80
|
const entries = followEntries(() => readMachineConfig(dir), sync, {
|
|
71
81
|
interval,
|
|
@@ -180,29 +190,43 @@ function createHub({ dir = machineDir(), state = stateDir(), home, interval, onS
|
|
|
180
190
|
res.end();
|
|
181
191
|
return;
|
|
182
192
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
res.end();
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
rest = p.slice(s.base.length).split("/").map(encodeURIComponent).join("/") + url.search;
|
|
192
|
-
} else {
|
|
193
|
-
const from = req.headers.referer ? new URL(req.headers.referer).pathname : null;
|
|
194
|
-
s = /^\/(api|_)\//.test(p) && from ? owner(decodeURIComponent(from)) : null;
|
|
195
|
-
if (!s) return root.handle(req, res);
|
|
196
|
-
rest = (req.url ?? "/").replace(/^\/+/, "/");
|
|
193
|
+
const s = owner(p);
|
|
194
|
+
if (s && p === s.base) {
|
|
195
|
+
res.writeHead(302, { location: `${s.base}/${url.search}` });
|
|
196
|
+
res.end();
|
|
197
|
+
return;
|
|
197
198
|
}
|
|
198
|
-
req.
|
|
199
|
-
return s.server.handle(req, res);
|
|
199
|
+
return route(req, p, url).handle(req, res);
|
|
200
200
|
} catch (err) {
|
|
201
201
|
console.error(err);
|
|
202
202
|
send(res, 500, String(err?.stack || err), "text/plain");
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
/**
|
|
206
|
+
* Whose request this is: a project's (`req.url` made the path within it), or else the overview's.
|
|
207
|
+
*/
|
|
208
|
+
function route(req, p, url) {
|
|
209
|
+
let s = owner(p);
|
|
210
|
+
if (s) {
|
|
211
|
+
req.url = p.slice(s.base.length).split("/").map(encodeURIComponent).join("/") + url.search;
|
|
212
|
+
return s.server;
|
|
213
|
+
}
|
|
214
|
+
const from = req.headers.referer ? new URL(req.headers.referer).pathname : null;
|
|
215
|
+
s = /^\/(api|_)\//.test(p) && from ? owner(decodeURIComponent(from)) : null;
|
|
216
|
+
req.url = s ? (req.url ?? "/").replace(/^\/+/, "/") : req.url;
|
|
217
|
+
return s ? s.server : root;
|
|
218
|
+
}
|
|
219
|
+
/** An upgrade (a page's live channel), routed as a request is. */
|
|
220
|
+
function upgrade(req, conn, head) {
|
|
221
|
+
try {
|
|
222
|
+
const url = new URL((req.url ?? "/").replace(/^\/+/, "/"), "http://localhost");
|
|
223
|
+
route(req, decodeURIComponent(url.pathname), url).upgrade(req, conn, head);
|
|
224
|
+
} catch (err) {
|
|
225
|
+
console.error(err);
|
|
226
|
+
conn.destroy();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
206
230
|
* The fallback of a whole entry (a `wait` or `watch` without --page in one of its projects): one
|
|
207
231
|
* per entry, refused (409) while another runs, or while a project of it has a fallback of its own
|
|
208
232
|
* (from a whiteboard before entries). Each project holds it as a listener, so its pages say an
|
|
@@ -247,6 +271,7 @@ function createHub({ dir = machineDir(), state = stateDir(), home, interval, onS
|
|
|
247
271
|
const closers = /* @__PURE__ */ new Set();
|
|
248
272
|
return {
|
|
249
273
|
handle,
|
|
274
|
+
upgrade,
|
|
250
275
|
projects: list,
|
|
251
276
|
rescan() {
|
|
252
277
|
entries.rescan();
|
package/dist/src/serve.js
CHANGED
|
@@ -21,6 +21,7 @@ async function start(project) {
|
|
|
21
21
|
const server = http.createServer((req, res) => {
|
|
22
22
|
wb.handle(req, res);
|
|
23
23
|
});
|
|
24
|
+
server.on("upgrade", (req, conn, head) => wb.upgrade(req, conn, head));
|
|
24
25
|
const candidates = [...new Set([
|
|
25
26
|
recordedPort(project),
|
|
26
27
|
DEFAULT_PORT,
|
|
@@ -93,6 +94,7 @@ async function startShared(dir = machineDir(), state = stateDir()) {
|
|
|
93
94
|
const server = http.createServer((req, res) => {
|
|
94
95
|
hub.handle(req, res);
|
|
95
96
|
});
|
|
97
|
+
server.on("upgrade", (req, conn, head) => hub.upgrade(req, conn, head));
|
|
96
98
|
const first = config.port ?? DEFAULT_PORT;
|
|
97
99
|
const candidates = [...new Set([
|
|
98
100
|
other ? Number(new URL(other.origin).port) : null,
|
package/dist/src/server.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { appendEvent, forAgent, matches, pickedUp, readEvents } from "./events.js";
|
|
1
|
+
import { appendEvent, forAgent, isEventId, matches, pickedUp, readEvents } from "./events.js";
|
|
2
2
|
import { html, raw } from "./html.js";
|
|
3
3
|
import { createConfigLoader, pluginDir, toPath } from "./loader.js";
|
|
4
4
|
import { describeRoutes, dispatch, mountRoutes, pluginCommands, usage } from "./plugins.js";
|
|
5
|
-
import { createAuth } from "./auth.js";
|
|
5
|
+
import { createAuth, sameSite } from "./auth.js";
|
|
6
|
+
import { accept, refuse } from "./ws.js";
|
|
6
7
|
import { FROM_SOURCE, PACKAGE_DIR, VERSION } from "./package.js";
|
|
7
8
|
import { awaiting, covers, fromReader, heard, questionState, unreadMessages } from "./status.js";
|
|
8
9
|
import { titleOf } from "./pages/render.js";
|
|
@@ -442,7 +443,7 @@ function createServer(project, { base = "", entry, label, name, files: filesOpti
|
|
|
442
443
|
};
|
|
443
444
|
}
|
|
444
445
|
const json = (s) => JSON.stringify(s).replace(/</g, "\\u003c");
|
|
445
|
-
const DOCK_STYLE = "#wb-dock{position:fixed;right:16px;bottom:calc(16px + var(--wb-inset-bottom,0px));z-index:30;display:flex;flex-direction:column;align-items:flex-end;gap:6px}#wb-dock:empty{display:none}.wb-toasts{display:flex;flex-direction:column;align-items:flex-end;gap:6px}.wb-toasts:empty{display:none}.wb-toast{display:inline-flex;align-items:center;gap:8px;cursor:pointer;padding:5px 12px;border-radius:99px;font:600 .8rem/1.4 var(--sans,system-ui,sans-serif);background:var(--accent,#1d5bbf);color:var(--accent-text,#fff);border:1px solid transparent;box-shadow:0 2px 10px rgb(0 0 0/.18)}.wb-toast[hidden]{display:none}.wb-toast[data-kind=warn]{background:var(--warn,#6b4fc0)}.wb-toast[data-kind=alert]{background:var(--bad,#c4352b);color:#fff}@keyframes wb-flash{from{outline-color:var(--accent,#1d5bbf)}to{outline-color:transparent}}.wb-flash{outline:3px solid transparent;outline-offset:6px;border-radius:4px;animation:wb-flash 2s ease-out}.wb-toast-dismiss{margin-right:-4px;padding:0 4px;border-left:1px solid rgb(255 255 255/.35);opacity:.75}.wb-toast-dismiss:hover{opacity:1}";
|
|
446
|
+
const DOCK_STYLE = "#wb-dock{position:fixed;right:16px;bottom:calc(16px + var(--wb-inset-bottom,0px));z-index:30;display:flex;flex-direction:column;align-items:flex-end;gap:6px}#wb-dock:empty{display:none}.wb-toasts{display:flex;flex-direction:column;align-items:flex-end;gap:6px}.wb-toasts:empty{display:none}.wb-toast{display:inline-flex;align-items:center;gap:8px;cursor:pointer;padding:5px 12px;border-radius:99px;font:600 .8rem/1.4 var(--sans,system-ui,sans-serif);background:var(--accent,#1d5bbf);color:var(--accent-text,#fff);border:1px solid transparent;box-shadow:0 2px 10px rgb(0 0 0/.18)}.wb-toast[hidden]{display:none}.wb-toast[data-kind=warn]{background:var(--warn,#6b4fc0)}.wb-toast[data-kind=alert]{background:var(--bad,#c4352b);color:#fff}@keyframes wb-flash{from{outline-color:var(--accent,#1d5bbf)}to{outline-color:transparent}}.wb-flash{outline:3px solid transparent;outline-offset:6px;border-radius:4px;animation:wb-flash 2s ease-out}.wb-toast-dismiss{margin-right:-4px;padding:0 4px;border-left:1px solid rgb(255 255 255/.35);opacity:.75}.wb-toast-dismiss:hover{opacity:1}.wb-toast{max-width:min(24rem,calc(100vw - 32px));text-align:left}.wb-toast-more{margin:0 -4px 0 -2px;padding:0 4px;opacity:.75}.wb-toast-more:hover{opacity:1}.wb-toast[data-open]{flex-wrap:wrap;border-radius:12px}.wb-toast-details{flex-basis:100%;padding:2px 0 3px;font-weight:400;cursor:text}.wb-toast-details[hidden]{display:none}";
|
|
446
447
|
/** `extras`: what plugins add to <head> and <body> (see shellExtras). */
|
|
447
448
|
function shell(page, { page: rendered, out, notices }, extras = {
|
|
448
449
|
head: [],
|
|
@@ -484,10 +485,12 @@ function createServer(project, { base = "", entry, label, name, files: filesOpti
|
|
|
484
485
|
...fallback && { fallback }
|
|
485
486
|
}));
|
|
486
487
|
const clients = /* @__PURE__ */ new Set();
|
|
488
|
+
/** what the browser appended lately, by id: a send it retries is answered with what it got */
|
|
489
|
+
const appended = /* @__PURE__ */ new Map();
|
|
487
490
|
function notify(client, kind) {
|
|
488
491
|
client.pending ??= /* @__PURE__ */ new Set();
|
|
489
492
|
if (client.pending.size === 0) setTimeout(() => {
|
|
490
|
-
for (const k of client.pending) client.
|
|
493
|
+
for (const k of client.pending) client.send(k);
|
|
491
494
|
client.pending.clear();
|
|
492
495
|
}, 60);
|
|
493
496
|
client.pending.add(kind);
|
|
@@ -495,6 +498,10 @@ function createServer(project, { base = "", entry, label, name, files: filesOpti
|
|
|
495
498
|
const notifyAll = (kind) => {
|
|
496
499
|
for (const c of clients) notify(c, kind);
|
|
497
500
|
};
|
|
501
|
+
const listenersChanged = () => {
|
|
502
|
+
notifyAll("listeners");
|
|
503
|
+
onChange?.();
|
|
504
|
+
};
|
|
498
505
|
function pageChanged(id) {
|
|
499
506
|
onChange?.();
|
|
500
507
|
for (const c of clients) if (c.isDir ? !c.page || id.startsWith(c.page + "/") : c.page === id || c.page + "/index" === id) notify(c, "change");
|
|
@@ -645,7 +652,12 @@ function createServer(project, { base = "", entry, label, name, files: filesOpti
|
|
|
645
652
|
if (p === "/api/events" && req.method === "POST") {
|
|
646
653
|
const body = JSON.parse(await readBody(req));
|
|
647
654
|
if (!body.type) return sendJson(res, 400, { error: "event type required" });
|
|
648
|
-
|
|
655
|
+
const again = isEventId(body.id) ? appended.get(body.id) : void 0;
|
|
656
|
+
if (again) return sendJson(res, 200, again);
|
|
657
|
+
const event = appendEvent(project.eventsFile, body);
|
|
658
|
+
appended.set(event.id, event);
|
|
659
|
+
if (appended.size > 1e3) appended.delete(appended.keys().next().value);
|
|
660
|
+
return sendJson(res, 200, event);
|
|
649
661
|
}
|
|
650
662
|
if (p === "/api/scroll" && req.method === "POST") {
|
|
651
663
|
const { page: id, to } = JSON.parse(await readBody(req));
|
|
@@ -653,7 +665,7 @@ function createServer(project, { base = "", entry, label, name, files: filesOpti
|
|
|
653
665
|
let tabs = 0;
|
|
654
666
|
for (const c of clients) {
|
|
655
667
|
if (c.isDir || c.page !== id && c.page + "/index" !== id) continue;
|
|
656
|
-
c.
|
|
668
|
+
c.send("scroll", { to });
|
|
657
669
|
tabs++;
|
|
658
670
|
}
|
|
659
671
|
return sendJson(res, 200, { tabs });
|
|
@@ -698,7 +710,7 @@ function createServer(project, { base = "", entry, label, name, files: filesOpti
|
|
|
698
710
|
...fallback && { fallback }
|
|
699
711
|
};
|
|
700
712
|
listeners.add(l);
|
|
701
|
-
|
|
713
|
+
listenersChanged();
|
|
702
714
|
const ping = setInterval(() => res.write(": ping\n\n"), 25e3);
|
|
703
715
|
const end = () => {
|
|
704
716
|
clearInterval(ping);
|
|
@@ -711,7 +723,7 @@ function createServer(project, { base = "", entry, label, name, files: filesOpti
|
|
|
711
723
|
});
|
|
712
724
|
req.on("close", () => {
|
|
713
725
|
end();
|
|
714
|
-
|
|
726
|
+
listenersChanged();
|
|
715
727
|
});
|
|
716
728
|
return;
|
|
717
729
|
}
|
|
@@ -735,11 +747,12 @@ function createServer(project, { base = "", entry, label, name, files: filesOpti
|
|
|
735
747
|
});
|
|
736
748
|
res.write(": connected\n\n");
|
|
737
749
|
const client = {
|
|
738
|
-
res,
|
|
750
|
+
send: (event, data = {}) => res.write(`event: ${event}\ndata: ${JSON.stringify(data)}\n\n`),
|
|
739
751
|
page: q.page || "",
|
|
740
752
|
isDir: "dir" in q
|
|
741
753
|
};
|
|
742
754
|
clients.add(client);
|
|
755
|
+
client.send("reload");
|
|
743
756
|
const ping = setInterval(() => res.write(": ping\n\n"), 25e3);
|
|
744
757
|
const end = () => {
|
|
745
758
|
clearInterval(ping);
|
|
@@ -959,8 +972,32 @@ function createServer(project, { base = "", entry, label, name, files: filesOpti
|
|
|
959
972
|
if (![...built.values()].includes(path.join(outDir, "index.html"))) warnings.push("no README.md or index.md in the top folder: the site has no index.html");
|
|
960
973
|
return result;
|
|
961
974
|
}
|
|
975
|
+
/** The live channel: /api/live, a WebSocket from a page of this server's (see ws.ts). */
|
|
976
|
+
function upgrade(req, conn, _head) {
|
|
977
|
+
const url = new URL((req.url ?? "/").replace(/^\/+/, "/"), "http://localhost");
|
|
978
|
+
if (decodeURIComponent(url.pathname) !== "/api/live") return refuse(conn, 404, "Not Found");
|
|
979
|
+
if (!sameSite(req)) return refuse(conn, 403, "Forbidden");
|
|
980
|
+
const socket = accept(req, conn);
|
|
981
|
+
if (!socket) return;
|
|
982
|
+
const client = {
|
|
983
|
+
send: (event, data = {}) => socket.send(JSON.stringify({
|
|
984
|
+
event,
|
|
985
|
+
data
|
|
986
|
+
})),
|
|
987
|
+
page: url.searchParams.get("page") ?? "",
|
|
988
|
+
isDir: url.searchParams.has("dir")
|
|
989
|
+
};
|
|
990
|
+
clients.add(client);
|
|
991
|
+
const stop = () => socket.close();
|
|
992
|
+
streams.add(stop);
|
|
993
|
+
socket.onClose(() => {
|
|
994
|
+
clients.delete(client);
|
|
995
|
+
streams.delete(stop);
|
|
996
|
+
});
|
|
997
|
+
}
|
|
962
998
|
return {
|
|
963
999
|
handle,
|
|
1000
|
+
upgrade,
|
|
964
1001
|
listeners: () => listenersFor(null),
|
|
965
1002
|
async overview() {
|
|
966
1003
|
await config();
|
|
@@ -975,11 +1012,12 @@ function createServer(project, { base = "", entry, label, name, files: filesOpti
|
|
|
975
1012
|
touch() {
|
|
976
1013
|
for (const c of clients) if (c.isDir && !c.page) notify(c, "change");
|
|
977
1014
|
},
|
|
1015
|
+
elsewhere: () => notifyAll("elsewhere"),
|
|
978
1016
|
addListener(l) {
|
|
979
1017
|
listeners.add(l);
|
|
980
|
-
|
|
1018
|
+
listenersChanged();
|
|
981
1019
|
return () => {
|
|
982
|
-
if (listeners.delete(l))
|
|
1020
|
+
if (listeners.delete(l)) listenersChanged();
|
|
983
1021
|
};
|
|
984
1022
|
},
|
|
985
1023
|
status: (page = null) => status(page),
|