@bigmistqke/whiteboard 0.3.1 → 0.5.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.
Files changed (174) hide show
  1. package/README.md +119 -18
  2. package/bin/whiteboard.ts +300 -71
  3. package/dist/bin/whiteboard.js +21 -0
  4. package/dist/client/runtime.js +132 -54
  5. package/dist/define.js +21 -2
  6. package/dist/plugins/callout/index.js +3 -1
  7. package/dist/plugins/callout/public/style.css +30 -0
  8. package/dist/plugins/chat/index.js +7 -4
  9. package/dist/plugins/chat/{client.js → public/client.js} +1 -1
  10. package/dist/plugins/chat/public/style.css +98 -0
  11. package/dist/plugins/code/index.js +3 -1
  12. package/dist/plugins/code/public/style.css +68 -0
  13. package/dist/plugins/comments/index.js +4 -5
  14. package/dist/plugins/comments/public/client.js +19 -0
  15. package/dist/plugins/comments/public/style.css +185 -0
  16. package/dist/plugins/details/index.js +7 -2
  17. package/dist/plugins/details/public/style.css +7 -0
  18. package/dist/plugins/draft/README.md +14 -0
  19. package/dist/plugins/draft/index.js +21 -0
  20. package/dist/plugins/draft/public/style.css +21 -0
  21. package/dist/plugins/form/index.js +37 -8
  22. package/dist/plugins/form/public/style.css +126 -0
  23. package/dist/plugins/gallery/index.js +4 -3
  24. package/dist/plugins/gallery/public/client.js +1 -0
  25. package/dist/plugins/gallery/public/style.css +90 -0
  26. package/dist/plugins/grid/index.js +9 -3
  27. package/dist/plugins/grid/public/style.css +71 -0
  28. package/dist/plugins/iframe/index.js +13 -14
  29. package/dist/plugins/iframe/public/style.css +13 -0
  30. package/dist/plugins/index.js +7 -1
  31. package/dist/plugins/mermaid/index.js +3 -1
  32. package/dist/plugins/mermaid/{style.css → public/style.css} +7 -2
  33. package/dist/plugins/steps/README.md +42 -0
  34. package/dist/plugins/steps/index.js +99 -0
  35. package/dist/plugins/steps/public/client.js +1 -0
  36. package/dist/plugins/steps/public/style.css +77 -0
  37. package/dist/plugins/terminal/host.js +9 -3
  38. package/dist/plugins/terminal/index.js +10 -9
  39. package/dist/plugins/terminal/{style.css → public/style.css} +199 -45
  40. package/dist/plugins/terminal/sizes.js +2 -1
  41. package/dist/plugins/toc/README.md +21 -3
  42. package/dist/plugins/toc/index.js +12 -5
  43. package/dist/plugins/toc/public/client.js +1 -0
  44. package/dist/plugins/toc/public/style.css +99 -0
  45. package/dist/plugins/window/README.md +29 -0
  46. package/dist/plugins/window/index.js +64 -0
  47. package/dist/solid/index.js +14 -11
  48. package/dist/src/auth.js +2 -1
  49. package/dist/src/client/page/base.css +1078 -199
  50. package/dist/src/client/page/main.js +188 -39
  51. package/dist/src/loader.js +14 -3
  52. package/dist/src/package.js +3 -6
  53. package/dist/src/pages/blocks.js +8 -13
  54. package/dist/src/pages/markdown.js +1 -1
  55. package/dist/src/pages/render.js +106 -20
  56. package/dist/src/pages/window.js +31 -0
  57. package/dist/src/public.js +24 -0
  58. package/dist/src/server.js +251 -23
  59. package/package.json +5 -2
  60. package/plugins/callout/index.ts +3 -1
  61. package/plugins/callout/public/style.css +30 -0
  62. package/plugins/chat/autosize.ts +43 -9
  63. package/plugins/chat/client.tsx +22 -5
  64. package/plugins/chat/index.ts +22 -8
  65. package/plugins/chat/public/style.css +98 -0
  66. package/plugins/claude-code/index.ts +49 -14
  67. package/plugins/code/diff.ts +28 -8
  68. package/plugins/code/index.ts +33 -21
  69. package/plugins/code/public/style.css +68 -0
  70. package/plugins/comments/client.ts +139 -71
  71. package/plugins/comments/index.ts +9 -7
  72. package/plugins/comments/public/style.css +185 -0
  73. package/plugins/details/index.ts +7 -2
  74. package/plugins/details/public/style.css +7 -0
  75. package/plugins/draft/README.md +14 -0
  76. package/plugins/draft/index.ts +23 -0
  77. package/plugins/draft/public/style.css +21 -0
  78. package/plugins/forge/index.ts +16 -3
  79. package/plugins/form/index.ts +75 -27
  80. package/plugins/form/public/style.css +126 -0
  81. package/plugins/gallery/client.tsx +9 -3
  82. package/plugins/gallery/index.ts +31 -9
  83. package/plugins/gallery/public/style.css +90 -0
  84. package/plugins/grid/index.ts +19 -5
  85. package/plugins/grid/public/style.css +71 -0
  86. package/plugins/iframe/index.ts +20 -23
  87. package/plugins/iframe/public/style.css +13 -0
  88. package/plugins/index.ts +20 -1
  89. package/plugins/mermaid/index.ts +7 -3
  90. package/plugins/mermaid/{style.css → public/style.css} +7 -2
  91. package/plugins/steps/README.md +42 -0
  92. package/plugins/steps/client.ts +66 -0
  93. package/plugins/steps/index.ts +127 -0
  94. package/plugins/steps/public/style.css +77 -0
  95. package/plugins/terminal/client.ts +105 -48
  96. package/plugins/terminal/host.ts +143 -35
  97. package/plugins/terminal/index.ts +84 -25
  98. package/plugins/terminal/public/style.css +225 -0
  99. package/plugins/terminal/server.ts +64 -13
  100. package/plugins/terminal/sizes.ts +16 -4
  101. package/plugins/toc/README.md +21 -3
  102. package/plugins/toc/client.ts +90 -30
  103. package/plugins/toc/index.ts +26 -10
  104. package/plugins/toc/public/style.css +99 -0
  105. package/plugins/window/README.md +29 -0
  106. package/plugins/window/index.ts +85 -0
  107. package/skills/whiteboard/SKILL.md +3 -1
  108. package/solid/index.tsx +24 -9
  109. package/src/auth.ts +28 -9
  110. package/src/client/forms.ts +74 -28
  111. package/src/client/markdown.ts +15 -4
  112. package/src/client/page/base.css +1078 -199
  113. package/src/client/page/elsewhere.ts +32 -15
  114. package/src/client/page/fresh.ts +91 -23
  115. package/src/client/page/hold.ts +11 -2
  116. package/src/client/page/live.ts +10 -6
  117. package/src/client/page/main.ts +124 -42
  118. package/src/client/page/orphans.ts +25 -10
  119. package/src/client/page/sort.ts +14 -4
  120. package/src/client/page/sticky.ts +11 -3
  121. package/src/client/page/theme.ts +11 -7
  122. package/src/client/page/waiting.ts +141 -34
  123. package/src/client/page/window.ts +40 -0
  124. package/src/client/reactive.ts +19 -0
  125. package/src/client/read.ts +17 -10
  126. package/src/client/runtime.ts +170 -40
  127. package/src/client/scroll.ts +14 -4
  128. package/src/client/toast.ts +19 -5
  129. package/src/config.ts +20 -5
  130. package/src/define.ts +119 -31
  131. package/src/events.ts +111 -24
  132. package/src/html.ts +6 -2
  133. package/src/icons.ts +4 -2
  134. package/src/load.ts +10 -2
  135. package/src/loader.ts +81 -12
  136. package/src/package.ts +9 -8
  137. package/src/pages/blocks.ts +20 -14
  138. package/src/pages/index.ts +2 -2
  139. package/src/pages/markdown.ts +113 -34
  140. package/src/pages/render.ts +233 -41
  141. package/src/pages/window.ts +78 -0
  142. package/src/plugins.ts +90 -24
  143. package/src/public.ts +39 -0
  144. package/src/running.ts +8 -2
  145. package/src/serve.ts +29 -7
  146. package/src/server.ts +591 -110
  147. package/src/status.ts +15 -9
  148. package/dist/plugins/callout/style.css +0 -12
  149. package/dist/plugins/chat/style.css +0 -24
  150. package/dist/plugins/code/style.css +0 -29
  151. package/dist/plugins/comments/client.js +0 -10
  152. package/dist/plugins/comments/style.css +0 -40
  153. package/dist/plugins/details/style.css +0 -3
  154. package/dist/plugins/form/style.css +0 -44
  155. package/dist/plugins/gallery/client.js +0 -1
  156. package/dist/plugins/gallery/style.css +0 -27
  157. package/dist/plugins/grid/style.css +0 -25
  158. package/dist/plugins/iframe/client.js +0 -1
  159. package/dist/plugins/iframe/style.css +0 -29
  160. package/dist/plugins/toc/client.js +0 -1
  161. package/dist/plugins/toc/style.css +0 -19
  162. package/plugins/callout/style.css +0 -12
  163. package/plugins/chat/style.css +0 -24
  164. package/plugins/code/style.css +0 -29
  165. package/plugins/comments/style.css +0 -40
  166. package/plugins/details/style.css +0 -3
  167. package/plugins/form/style.css +0 -44
  168. package/plugins/gallery/style.css +0 -27
  169. package/plugins/grid/style.css +0 -25
  170. package/plugins/iframe/client.ts +0 -46
  171. package/plugins/iframe/style.css +0 -29
  172. package/plugins/terminal/style.css +0 -71
  173. package/plugins/toc/style.css +0 -19
  174. /package/dist/plugins/terminal/{client.js → public/client.js} +0 -0
@@ -77,11 +77,26 @@ function unreadMessages(events, isMessage) {
77
77
  }
78
78
  return events.filter((e) => !fromReader(e) && isMessage(e.type) && !read.has(e.id) && !replaced.has(e.id));
79
79
  }
80
+ // src/client/reactive.ts
81
+ function reactive(get) {
82
+ const listeners = /* @__PURE__ */ new Set();
83
+ const value = (() => get());
84
+ value.on = (fn) => {
85
+ listeners.add(fn);
86
+ return () => {
87
+ listeners.delete(fn);
88
+ };
89
+ };
90
+ value.notify = () => {
91
+ const now = get();
92
+ for (const fn of [...listeners]) fn(now);
93
+ };
94
+ return value;
95
+ }
80
96
  // src/client/forms.ts
81
97
  let root$1;
82
98
  let api$1;
83
99
  let page$1 = "";
84
- const listeners$1 = /* @__PURE__ */ new Set();
85
100
  /** The forms the core looks after: named (a name without a colon: see isQuestionName), without an action. */
86
101
  const managed = (form) => isQuestionName(form.getAttribute("name") ?? "") && !form.hasAttribute("action");
87
102
  const forms = () => [...root$1.querySelectorAll("form")].filter(managed);
@@ -95,14 +110,14 @@ function readForm(form) {
95
110
  for (const el of elements) if (el.name && el.type === "checkbox") boxes[el.name] = (boxes[el.name] ?? 0) + 1;
96
111
  for (const el of elements) {
97
112
  if (!el.name || el.type === "submit" || el.type === "button" || el.type === "reset" || el.type === "file") continue;
98
- if (isOther(el)) el.value = otherText(el)?.value.trim() ?? "";
113
+ const value = isOther(el) ? otherText(el)?.value.trim() ?? "" : el.value;
99
114
  if (el.type === "checkbox") {
100
115
  if (boxes[el.name] > 1) {
101
116
  const list = data[el.name] ??= [];
102
- if (el.checked) list.push(el.value);
117
+ if (el.checked) list.push(value);
103
118
  } else data[el.name] = el.checked;
104
119
  } else if (el.type === "radio") {
105
- if (el.checked) data[el.name] = el.value;
120
+ if (el.checked) data[el.name] = value;
106
121
  else data[el.name] ??= null;
107
122
  } else if (el instanceof HTMLSelectElement && el.multiple) data[el.name] = [...el.selectedOptions].map((o) => o.value);
108
123
  else data[el.name] = el.value;
@@ -201,7 +216,11 @@ const ATTR = {
201
216
  decided: "data-wb-decided"
202
217
  };
203
218
  /** One line quoting an answer: what was chosen, then what was written. */
204
- function outcome(data, action) {
219
+ /**
220
+ * An answer, told apart: the button it was sent with (none for a plain Send), what was chosen
221
+ * (options, short values), and what was written.
222
+ */
223
+ function answerParts(data, action) {
205
224
  const chosen = [], written = [];
206
225
  for (const v of Object.values(data)) {
207
226
  if (v == null || v === "" || v === false) continue;
@@ -211,8 +230,16 @@ function outcome(data, action) {
211
230
  else if (String(v).length > 60 || String(v).includes("\n")) written.push(String(v));
212
231
  else chosen.push(String(v));
213
232
  }
214
- if (action && !["Send", "Submit"].includes(action)) chosen.unshift(action);
215
- return [chosen.join(" · ") || "sent", ...written.map((w) => `“${w.length > 240 ? w.slice(0, 240) + "…" : w}”`)].join("\n");
233
+ return {
234
+ action: action && !["Send", "Submit"].includes(action) ? action : null,
235
+ chosen,
236
+ written
237
+ };
238
+ }
239
+ /** One line quoting an answer: what was chosen, then what was written. */
240
+ function outcome(data, action) {
241
+ const { action: button, chosen, written } = answerParts(data, action);
242
+ return [[button, ...chosen].filter(Boolean).join(" · ") || "sent", ...written.map((w) => `“${w.length > 240 ? w.slice(0, 240) + "…" : w}”`)].join("\n");
216
243
  }
217
244
  let current = [];
218
245
  const justSent = /* @__PURE__ */ new WeakMap();
@@ -232,7 +259,7 @@ function mark() {
232
259
  last
233
260
  };
234
261
  });
235
- for (const fn of listeners$1) fn(current);
262
+ forms_.notify();
236
263
  }
237
264
  /** After the page re-rendered: answers, drafts and marks back on its forms. */
238
265
  function refresh() {
@@ -250,8 +277,8 @@ function trackForms(el, pageId, core) {
250
277
  document.addEventListener("change", saveDraft);
251
278
  document.addEventListener("submit", onSubmit);
252
279
  api$1.onRendered(refresh);
253
- api$1.onListeners(mark);
254
- api$1.onEvents(() => {
280
+ api$1.listeners.on(mark);
281
+ api$1.events.on(() => {
255
282
  restoreLast(false);
256
283
  mark();
257
284
  });
@@ -259,16 +286,9 @@ function trackForms(el, pageId, core) {
259
286
  restoreDrafts();
260
287
  mark();
261
288
  }
262
- /** For the api: every named form and where it stands, and following that. */
263
- const formsApi = {
264
- forms: () => current,
265
- onForms(fn) {
266
- listeners$1.add(fn);
267
- return () => {
268
- listeners$1.delete(fn);
269
- };
270
- }
271
- };
289
+ /** For the api: every named form and where it stands, as it changes. */
290
+ const forms_ = reactive(() => current);
291
+ const formsApi = { forms: forms_ };
272
292
  // src/client/toast.ts
273
293
  let box = null;
274
294
  function place(corner) {
@@ -331,11 +351,11 @@ let isMessage = () => false;
331
351
  let getEvents = () => [];
332
352
  let send = () => {};
333
353
  const sending = /* @__PURE__ */ new Set();
334
- const unread = () => unreadMessages(getEvents(), isMessage).filter((e) => !sending.has(e.id));
354
+ const unread$1 = () => unreadMessages(getEvents(), isMessage).filter((e) => !sending.has(e.id));
335
355
  const queued = /* @__PURE__ */ new Set();
336
356
  let timer = 0;
337
357
  function markRead(ids) {
338
- const open = new Set(unread().map((e) => e.id));
358
+ const open = new Set(unread$1().map((e) => e.id));
339
359
  const fresh = ids.filter((id) => open.has(id));
340
360
  if (!fresh.length) return;
341
361
  for (const id of fresh) {
@@ -367,7 +387,7 @@ function readVisible() {
367
387
  }
368
388
  const observed = /* @__PURE__ */ new WeakSet();
369
389
  function observeMessages() {
370
- const open = new Set(unread().map((e) => e.id));
390
+ const open = new Set(unread$1().map((e) => e.id));
371
391
  for (const el of document.querySelectorAll("[data-wb-message]")) {
372
392
  if (observed.has(el) || !open.has(el.dataset.wbMessage)) continue;
373
393
  observed.add(el);
@@ -467,18 +487,24 @@ const handoff = JSON.parse(document.getElementById("wb-page").textContent);
467
487
  const root = document.getElementById("wb-root");
468
488
  const page = handoff.id;
469
489
  const isDir = handoff.kind === "pages" || handoff.kind === "folder";
490
+ const live = handoff.live !== false;
491
+ const moduleUrl = (path) => new URL(path, document.baseURI).href;
470
492
  let events = [];
471
- const eventListeners = /* @__PURE__ */ new Set();
493
+ const eventsValue = reactive(() => events);
494
+ const unread = reactive(unread$1);
472
495
  function setEvents(next) {
473
496
  events = next;
474
497
  readsArrived(events);
475
- for (const fn of eventListeners) fn(events);
498
+ eventsValue.notify();
499
+ unread.notify();
476
500
  messagesChanged();
477
501
  }
478
502
  async function loadEvents() {
503
+ if (!live) return;
479
504
  setEvents((await (await fetch(`/api/events?page=${encodeURIComponent(page)}`)).json()).filter((e) => e.page === page));
480
505
  }
481
506
  async function append(type, data = {}, action = null) {
507
+ if (!live) throw new Error("a built page is a file: there is no log to append to");
482
508
  const res = await fetch("/api/events", {
483
509
  method: "POST",
484
510
  headers: { "content-type": "application/json" },
@@ -495,10 +521,11 @@ async function append(type, data = {}, action = null) {
495
521
  return saved;
496
522
  }
497
523
  let listeners = [];
498
- const listenerListeners = /* @__PURE__ */ new Set();
524
+ const listenersValue = reactive(() => listeners);
499
525
  async function loadListeners() {
526
+ if (!live) return;
500
527
  listeners = await (await fetch(`/api/listeners?page=${encodeURIComponent(page)}`)).json();
501
- for (const fn of listenerListeners) fn(listeners);
528
+ listenersValue.notify();
502
529
  }
503
530
  const renderedListeners = /* @__PURE__ */ new Set();
504
531
  const corner = document.getElementById("wb-dock") ?? document.body.appendChild(Object.assign(document.createElement("div"), { id: "wb-dock" }));
@@ -506,29 +533,29 @@ let baseTitle = document.title;
506
533
  const badges = /* @__PURE__ */ new Map();
507
534
  let badgeCount = 0;
508
535
  function writeTitle() {
509
- const list = [...badges.values()].sort((a, b) => a.order - b.order || a.since - b.since);
536
+ const list = [...badges.values()].toSorted((a, b) => a.order - b.order || a.since - b.since);
510
537
  document.title = `${list.map((b) => `(${b.text}) `).join("")}${baseTitle}`;
511
538
  }
512
539
  const api = {
513
540
  page,
514
- events: () => events,
515
- onEvents(fn) {
516
- eventListeners.add(fn);
517
- return () => eventListeners.delete(fn);
518
- },
541
+ events: eventsValue,
519
542
  last: (type) => events.findLast((e) => e.type === type),
520
543
  pickedUp: (id) => !!events.find((e) => e.id === id)?.pickedUp,
521
544
  unread,
522
- markRead,
545
+ markRead: (ids) => {
546
+ markRead(ids);
547
+ unread.notify();
548
+ },
523
549
  markdown,
524
550
  append,
525
- listeners: () => listeners,
526
- onListeners(fn) {
527
- listenerListeners.add(fn);
528
- return () => listenerListeners.delete(fn);
529
- },
551
+ listeners: listenersValue,
530
552
  rendered() {
553
+ const frontmatterChanged = JSON.stringify(nextFrontmatter) !== JSON.stringify(frontmatter);
554
+ data = nextData;
555
+ frontmatter = nextFrontmatter;
531
556
  for (const fn of renderedListeners) fn();
557
+ dataValue.notify();
558
+ if (frontmatterChanged) frontmatterValue.notify();
532
559
  },
533
560
  onRendered(fn) {
534
561
  renderedListeners.add(fn);
@@ -557,17 +584,42 @@ async function getJson(url) {
557
584
  if (!res.ok) throw new Error(`${url}: ${res.status}`);
558
585
  return res.json();
559
586
  }
587
+ let data = handoff.data;
588
+ let nextData = data;
589
+ let frontmatter = handoff.frontmatter ?? {};
590
+ let nextFrontmatter = frontmatter;
591
+ const dataValue = reactive(() => data);
592
+ const frontmatterValue = reactive(() => frontmatter);
560
593
  const handle = {
594
+ settings: reactive(() => void 0),
561
595
  id: page,
562
596
  kind: handoff.kind,
563
- data: handoff.data,
597
+ live,
598
+ data: dataValue,
599
+ frontmatter: frontmatterValue,
564
600
  onChange(fn) {
565
601
  changeListeners.add(fn);
566
602
  return () => changeListeners.delete(fn);
567
603
  },
568
- render: () => getJson(`/api/render?page=${encodeURIComponent(page)}`),
604
+ render: async () => {
605
+ const next = await getJson(`/api/render?page=${encodeURIComponent(page)}`);
606
+ nextData = next.data ?? null;
607
+ nextFrontmatter = next.frontmatter ?? {};
608
+ return next;
609
+ },
569
610
  stored: () => getJson(`/api/page?page=${encodeURIComponent(page)}`)
570
611
  };
612
+ /** Did the page change since it was rendered here (its file's time, or it came to be)? Then say so. */
613
+ async function caughtUp() {
614
+ let now;
615
+ try {
616
+ now = (await getJson(`/api/render?page=${encodeURIComponent(page)}`)).mtime ?? null;
617
+ } catch {
618
+ now = null;
619
+ }
620
+ const shown = data?.mtime ?? null;
621
+ if (now !== shown) for (const fn of changeListeners) fn();
622
+ }
571
623
  if (!handoff.client) handle.onChange(async () => {
572
624
  root.innerHTML = (await handle.render()).html;
573
625
  api.rendered();
@@ -578,6 +630,7 @@ function connect() {
578
630
  document.documentElement.dataset.wbLive = "";
579
631
  loadListeners();
580
632
  loadEvents();
633
+ caughtUp();
581
634
  };
582
635
  es.onerror = () => {
583
636
  delete document.documentElement.dataset.wbLive;
@@ -611,28 +664,53 @@ function connect() {
611
664
  }
612
665
  await Promise.all([loadEvents(), loadListeners()]);
613
666
  if (handoff.client) try {
614
- const mount = (await import(handoff.client)).default;
667
+ const mount = (await import(moduleUrl(handoff.client))).default;
615
668
  await mount(root, handle, api);
616
669
  } catch (err) {
617
670
  console.error("page:", err);
618
671
  root.insertAdjacentHTML("afterbegin", String(html`<pre class="wb-error" role="alert">the page failed to start: ${err.message}</pre>`));
619
672
  }
620
- trackForms(root, page, api);
621
- trackReading({
622
- messages: handoff.messages ?? [],
623
- events: () => events,
624
- send: (ids) => {
625
- append(READ, { ids }).catch((err) => console.error("marking read:", err));
626
- }
627
- });
673
+ if (live) {
674
+ trackForms(root, page, api);
675
+ trackReading({
676
+ messages: handoff.messages ?? [],
677
+ events: () => events,
678
+ send: (ids) => {
679
+ append(READ, { ids }).catch((err) => console.error("marking read:", err));
680
+ }
681
+ });
682
+ }
683
+ /**
684
+ * A plugin's page handle: the page's, with its own settings, the page's frontmatter under `plugins:`
685
+ * by its name, heard of only when they changed.
686
+ */
687
+ function handleFor(name) {
688
+ const own = () => {
689
+ const plugins = frontmatter.plugins;
690
+ return plugins && typeof plugins === "object" ? plugins[name] : void 0;
691
+ };
692
+ const settings = reactive(own);
693
+ let last = JSON.stringify(own() ?? null);
694
+ frontmatterValue.on(() => {
695
+ const now = JSON.stringify(own() ?? null);
696
+ if (now === last) return;
697
+ last = now;
698
+ settings.notify();
699
+ });
700
+ return {
701
+ ...handle,
702
+ settings
703
+ };
704
+ }
628
705
  await Promise.all((handoff.plugins ?? []).map(async (ext) => {
629
706
  try {
630
- const mount = (await import(ext.client)).default;
707
+ const mount = (await import(moduleUrl(ext.client))).default;
631
708
  if (typeof mount !== "function") throw new Error("the client module must export a mount(root, page, api) function as default");
632
- await mount(root, handle, api);
709
+ await mount(root, handleFor(ext.name), api);
633
710
  } catch (err) {
634
711
  console.error(`plugin ${ext.name}:`, err);
635
- root.insertAdjacentHTML("afterbegin", String(html`<pre class="wb-error" role="alert">plugin "${ext.name}" failed in the browser: ${err.message}</pre>`));
712
+ root.insertAdjacentHTML("afterbegin", String(html`<pre class="wb-error" role="alert">
713
+ plugin "${ext.name}" failed in the browser: ${err.message}</pre>`));
636
714
  }
637
715
  }));
638
- connect();
716
+ if (live) connect();
package/dist/define.js CHANGED
@@ -1,7 +1,26 @@
1
1
  import { Html, escape, html, raw } from "./src/html.js";
2
+ import { windowFrame } from "./src/pages/window.js";
2
3
  // src/define.ts
3
4
  const defineConfig = (config) => config;
4
- const definePlugin = (plugin) => plugin;
5
+ /**
6
+ * A plugin, with its public folder defaulted to `public/` next to the module that calls this
7
+ * (found from the call stack), when it doesn't say one.
8
+ */
9
+ const definePlugin = (plugin) => plugin.public != null ? plugin : {
10
+ ...plugin,
11
+ public: callerPublic()
12
+ };
13
+ /** `public/` next to the module that called definePlugin: the first frame of the stack in another file. */
14
+ function callerPublic() {
15
+ const own = import.meta.url;
16
+ for (const line of ((/* @__PURE__ */ new Error()).stack ?? "").split("\n").slice(1)) {
17
+ const m = /(file:\/\/[^\s)]+?|\/[^\s():]+?):\d+:\d+/.exec(line);
18
+ if (!m) continue;
19
+ const url = m[1].startsWith("file:") ? m[1] : `file://${m[1]}`;
20
+ if (url === own) continue;
21
+ return new URL("./public/", url);
22
+ }
23
+ }
5
24
  /** A block with typed props, for one written apart from its plugin. */
6
25
  const defineBlock = (block) => block;
7
- export { Html, defineBlock, defineConfig, definePlugin, escape, html, raw };
26
+ export { Html, defineBlock, defineConfig, definePlugin, escape, html, raw, windowFrame };
@@ -1,3 +1,4 @@
1
+ import { builtinPublic } from "../../src/package.js";
1
2
  import fs from "node:fs";
2
3
  import { definePlugin, html, raw } from "@bigmistqke/whiteboard";
3
4
  // plugins/callout/index.ts
@@ -17,9 +18,10 @@ async function render(ctx) {
17
18
  function callout() {
18
19
  return definePlugin({
19
20
  name: "callout",
21
+ public: builtinPublic("callout"),
20
22
  blocks: { callout: {
21
23
  html: render,
22
- style: new URL("./style.css", import.meta.url)
24
+ style: "style.css"
23
25
  } },
24
26
  docs: () => fs.readFileSync(new URL("./README.md", import.meta.url), "utf8")
25
27
  });
@@ -0,0 +1,30 @@
1
+ /* a margin note: a coloured rule and a light tint, set in the body face */
2
+ .wb-callout {
3
+ --c: var(--info);
4
+ margin: calc(var(--rhythm) * 3) 0;
5
+ padding: 1em 1.3em;
6
+ border-left: 3px solid var(--c);
7
+ background: color-mix(in srgb, var(--c) var(--tint-faint), var(--bg));
8
+ border-radius: 0 var(--radius) var(--radius) 0;
9
+ }
10
+ .wb-callout > :first-child {
11
+ margin-top: 0;
12
+ }
13
+ .wb-callout > :last-child {
14
+ margin-bottom: 0;
15
+ }
16
+ .wb-callout-title {
17
+ font: var(--weight-strong) var(--ui-small)/var(--ui-line-height) var(--sans);
18
+ color: var(--c);
19
+ margin-bottom: 0.5em;
20
+ letter-spacing: 0.01em;
21
+ }
22
+ .wb-callout:is([data-type='tip'], [data-type='success']) {
23
+ --c: var(--ok);
24
+ }
25
+ .wb-callout:is([data-type='warning'], [data-type='question']) {
26
+ --c: var(--warn);
27
+ }
28
+ .wb-callout[data-type='danger'] {
29
+ --c: var(--bad);
30
+ }
@@ -1,9 +1,9 @@
1
- import { builtFile } from "../../src/package.js";
1
+ import { builtinPublic } from "../../src/package.js";
2
2
  import { isQuestionName } from "../../src/status.js";
3
3
  import fs from "node:fs";
4
4
  import { definePlugin, html, raw } from "@bigmistqke/whiteboard";
5
5
  // plugins/chat/index.ts
6
- const style = new URL("./style.css", import.meta.url);
6
+ const style = "style.css";
7
7
  /** The chat itself: a client island, so the server renders nothing for it. */
8
8
  const thread = {
9
9
  style,
@@ -13,7 +13,7 @@ const thread = {
13
13
  choices: (ctx.attrs.choices ?? "").split(" ").filter(Boolean)
14
14
  }),
15
15
  html: () => "",
16
- client: builtFile(import.meta.url, "client.js")
16
+ client: "client.js"
17
17
  };
18
18
  const quote = (s) => s.replace(/"/g, "&quot;");
19
19
  /** The chat thread for `chat`, as markup: for the chat block, and for the form plugin under a form. */
@@ -26,12 +26,15 @@ const chat = {
26
26
  const name = c.attrs.name || c.attrs.id || "chat";
27
27
  if (!isQuestionName(name)) throw new Error(`chat name "${name}" has a colon: those names are reserved for events of whiteboard and plugins`);
28
28
  const body = c.children.length ? await c.toHtml(c.children) : "";
29
- return html`<section class="wb-chat-block" data-chat="${name}">${raw(body)}${raw(await chatThread(c, name))}</section>`;
29
+ return html`<section class="wb-chat-block" data-chat="${name}">
30
+ ${raw(body)}${raw(await chatThread(c, name))}
31
+ </section>`;
30
32
  }
31
33
  };
32
34
  function chatPlugin() {
33
35
  return definePlugin({
34
36
  name: "chat",
37
+ public: builtinPublic("chat"),
35
38
  blocks: {
36
39
  chat,
37
40
  "chat-thread": thread