@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.
- package/README.md +119 -18
- package/bin/whiteboard.ts +300 -71
- package/dist/bin/whiteboard.js +21 -0
- package/dist/client/runtime.js +132 -54
- package/dist/define.js +21 -2
- package/dist/plugins/callout/index.js +3 -1
- package/dist/plugins/callout/public/style.css +30 -0
- package/dist/plugins/chat/index.js +7 -4
- package/dist/plugins/chat/{client.js → public/client.js} +1 -1
- package/dist/plugins/chat/public/style.css +98 -0
- package/dist/plugins/code/index.js +3 -1
- package/dist/plugins/code/public/style.css +68 -0
- package/dist/plugins/comments/index.js +4 -5
- package/dist/plugins/comments/public/client.js +19 -0
- package/dist/plugins/comments/public/style.css +185 -0
- package/dist/plugins/details/index.js +7 -2
- package/dist/plugins/details/public/style.css +7 -0
- package/dist/plugins/draft/README.md +14 -0
- package/dist/plugins/draft/index.js +21 -0
- package/dist/plugins/draft/public/style.css +21 -0
- package/dist/plugins/form/index.js +37 -8
- package/dist/plugins/form/public/style.css +126 -0
- package/dist/plugins/gallery/index.js +4 -3
- package/dist/plugins/gallery/public/client.js +1 -0
- package/dist/plugins/gallery/public/style.css +90 -0
- package/dist/plugins/grid/index.js +9 -3
- package/dist/plugins/grid/public/style.css +71 -0
- package/dist/plugins/iframe/index.js +13 -14
- package/dist/plugins/iframe/public/style.css +13 -0
- package/dist/plugins/index.js +7 -1
- package/dist/plugins/mermaid/index.js +3 -1
- package/dist/plugins/mermaid/{style.css → public/style.css} +7 -2
- package/dist/plugins/steps/README.md +42 -0
- package/dist/plugins/steps/index.js +99 -0
- package/dist/plugins/steps/public/client.js +1 -0
- package/dist/plugins/steps/public/style.css +77 -0
- package/dist/plugins/terminal/host.js +9 -3
- package/dist/plugins/terminal/index.js +10 -9
- package/dist/plugins/terminal/{style.css → public/style.css} +199 -45
- package/dist/plugins/terminal/sizes.js +2 -1
- package/dist/plugins/toc/README.md +21 -3
- package/dist/plugins/toc/index.js +12 -5
- package/dist/plugins/toc/public/client.js +1 -0
- package/dist/plugins/toc/public/style.css +99 -0
- package/dist/plugins/window/README.md +29 -0
- package/dist/plugins/window/index.js +64 -0
- package/dist/solid/index.js +14 -11
- package/dist/src/auth.js +2 -1
- package/dist/src/client/page/base.css +1078 -199
- package/dist/src/client/page/main.js +188 -39
- package/dist/src/loader.js +14 -3
- package/dist/src/package.js +3 -6
- package/dist/src/pages/blocks.js +8 -13
- package/dist/src/pages/markdown.js +1 -1
- package/dist/src/pages/render.js +106 -20
- package/dist/src/pages/window.js +31 -0
- package/dist/src/public.js +24 -0
- package/dist/src/server.js +251 -23
- package/package.json +5 -2
- package/plugins/callout/index.ts +3 -1
- package/plugins/callout/public/style.css +30 -0
- package/plugins/chat/autosize.ts +43 -9
- package/plugins/chat/client.tsx +22 -5
- package/plugins/chat/index.ts +22 -8
- package/plugins/chat/public/style.css +98 -0
- package/plugins/claude-code/index.ts +49 -14
- package/plugins/code/diff.ts +28 -8
- package/plugins/code/index.ts +33 -21
- package/plugins/code/public/style.css +68 -0
- package/plugins/comments/client.ts +139 -71
- package/plugins/comments/index.ts +9 -7
- package/plugins/comments/public/style.css +185 -0
- package/plugins/details/index.ts +7 -2
- package/plugins/details/public/style.css +7 -0
- package/plugins/draft/README.md +14 -0
- package/plugins/draft/index.ts +23 -0
- package/plugins/draft/public/style.css +21 -0
- package/plugins/forge/index.ts +16 -3
- package/plugins/form/index.ts +75 -27
- package/plugins/form/public/style.css +126 -0
- package/plugins/gallery/client.tsx +9 -3
- package/plugins/gallery/index.ts +31 -9
- package/plugins/gallery/public/style.css +90 -0
- package/plugins/grid/index.ts +19 -5
- package/plugins/grid/public/style.css +71 -0
- package/plugins/iframe/index.ts +20 -23
- package/plugins/iframe/public/style.css +13 -0
- package/plugins/index.ts +20 -1
- package/plugins/mermaid/index.ts +7 -3
- package/plugins/mermaid/{style.css → public/style.css} +7 -2
- package/plugins/steps/README.md +42 -0
- package/plugins/steps/client.ts +66 -0
- package/plugins/steps/index.ts +127 -0
- package/plugins/steps/public/style.css +77 -0
- package/plugins/terminal/client.ts +105 -48
- package/plugins/terminal/host.ts +143 -35
- package/plugins/terminal/index.ts +84 -25
- package/plugins/terminal/public/style.css +225 -0
- package/plugins/terminal/server.ts +64 -13
- package/plugins/terminal/sizes.ts +16 -4
- package/plugins/toc/README.md +21 -3
- package/plugins/toc/client.ts +90 -30
- package/plugins/toc/index.ts +26 -10
- package/plugins/toc/public/style.css +99 -0
- package/plugins/window/README.md +29 -0
- package/plugins/window/index.ts +85 -0
- package/skills/whiteboard/SKILL.md +3 -1
- package/solid/index.tsx +24 -9
- package/src/auth.ts +28 -9
- package/src/client/forms.ts +74 -28
- package/src/client/markdown.ts +15 -4
- package/src/client/page/base.css +1078 -199
- package/src/client/page/elsewhere.ts +32 -15
- package/src/client/page/fresh.ts +91 -23
- package/src/client/page/hold.ts +11 -2
- package/src/client/page/live.ts +10 -6
- package/src/client/page/main.ts +124 -42
- package/src/client/page/orphans.ts +25 -10
- package/src/client/page/sort.ts +14 -4
- package/src/client/page/sticky.ts +11 -3
- package/src/client/page/theme.ts +11 -7
- package/src/client/page/waiting.ts +141 -34
- package/src/client/page/window.ts +40 -0
- package/src/client/reactive.ts +19 -0
- package/src/client/read.ts +17 -10
- package/src/client/runtime.ts +170 -40
- package/src/client/scroll.ts +14 -4
- package/src/client/toast.ts +19 -5
- package/src/config.ts +20 -5
- package/src/define.ts +119 -31
- package/src/events.ts +111 -24
- package/src/html.ts +6 -2
- package/src/icons.ts +4 -2
- package/src/load.ts +10 -2
- package/src/loader.ts +81 -12
- package/src/package.ts +9 -8
- package/src/pages/blocks.ts +20 -14
- package/src/pages/index.ts +2 -2
- package/src/pages/markdown.ts +113 -34
- package/src/pages/render.ts +233 -41
- package/src/pages/window.ts +78 -0
- package/src/plugins.ts +90 -24
- package/src/public.ts +39 -0
- package/src/running.ts +8 -2
- package/src/serve.ts +29 -7
- package/src/server.ts +591 -110
- package/src/status.ts +15 -9
- package/dist/plugins/callout/style.css +0 -12
- package/dist/plugins/chat/style.css +0 -24
- package/dist/plugins/code/style.css +0 -29
- package/dist/plugins/comments/client.js +0 -10
- package/dist/plugins/comments/style.css +0 -40
- package/dist/plugins/details/style.css +0 -3
- package/dist/plugins/form/style.css +0 -44
- package/dist/plugins/gallery/client.js +0 -1
- package/dist/plugins/gallery/style.css +0 -27
- package/dist/plugins/grid/style.css +0 -25
- package/dist/plugins/iframe/client.js +0 -1
- package/dist/plugins/iframe/style.css +0 -29
- package/dist/plugins/toc/client.js +0 -1
- package/dist/plugins/toc/style.css +0 -19
- package/plugins/callout/style.css +0 -12
- package/plugins/chat/style.css +0 -24
- package/plugins/code/style.css +0 -29
- package/plugins/comments/style.css +0 -40
- package/plugins/details/style.css +0 -3
- package/plugins/form/style.css +0 -44
- package/plugins/gallery/style.css +0 -27
- package/plugins/grid/style.css +0 -25
- package/plugins/iframe/client.ts +0 -46
- package/plugins/iframe/style.css +0 -29
- package/plugins/terminal/style.css +0 -71
- package/plugins/toc/style.css +0 -19
- /package/dist/plugins/terminal/{client.js → public/client.js} +0 -0
|
@@ -470,18 +470,33 @@ const unseen = /* @__PURE__ */ new Set();
|
|
|
470
470
|
const timers = /* @__PURE__ */ new WeakMap();
|
|
471
471
|
let storeKey = "";
|
|
472
472
|
let core$1;
|
|
473
|
+
const SERVER_MARKS = /* @__PURE__ */ new Set([
|
|
474
|
+
"data-wb-at",
|
|
475
|
+
"data-wb-key",
|
|
476
|
+
"data-wb-maximize",
|
|
477
|
+
"data-wb-other",
|
|
478
|
+
"data-wb-other-text",
|
|
479
|
+
"data-wb-quiet",
|
|
480
|
+
"data-wb-self",
|
|
481
|
+
"data-wb-sort"
|
|
482
|
+
]);
|
|
473
483
|
/**
|
|
474
|
-
* FNV-1a over the block's HTML
|
|
475
|
-
* [data-wb-quiet] can appear, change or go without the block counting as changed.
|
|
484
|
+
* FNV-1a over the block's HTML as the server sent it, ignoring anything quiet: content inside
|
|
485
|
+
* [data-wb-quiet] can appear, change or go without the block counting as changed. What the browser
|
|
486
|
+
* added is left out, so a block in the page and the same block in a new render have one signature:
|
|
487
|
+
* an island's content (it draws itself; its props are in its key), the page's own elements (a folded
|
|
488
|
+
* form's card), its marks (data-wb-* the server doesn't write: a form's state) and its classes for
|
|
489
|
+
* new content.
|
|
476
490
|
*/
|
|
477
491
|
function signature(el) {
|
|
478
492
|
const clone = el.cloneNode(true);
|
|
479
|
-
for (const q of clone.querySelectorAll("[data-wb-quiet]")) q.remove();
|
|
480
|
-
for (const n of [clone, ...clone.querySelectorAll("
|
|
481
|
-
n.
|
|
482
|
-
n.
|
|
493
|
+
for (const q of clone.querySelectorAll("[data-wb-quiet], .wb-folded")) q.remove();
|
|
494
|
+
for (const n of [clone, ...clone.querySelectorAll("*")]) {
|
|
495
|
+
for (const { name } of [...n.attributes]) if (name.startsWith("data-wb-") && !SERVER_MARKS.has(name)) n.removeAttribute(name);
|
|
496
|
+
n.classList.remove("wb-new", "wb-new-seen");
|
|
497
|
+
if (!n.classList.length) n.removeAttribute("class");
|
|
483
498
|
}
|
|
484
|
-
clone.
|
|
499
|
+
for (const island of clone.querySelectorAll("[data-wb-key]")) island.replaceChildren();
|
|
485
500
|
const s = clone.outerHTML;
|
|
486
501
|
let h = 2166136261;
|
|
487
502
|
for (let i = 0; i < s.length; i++) h = Math.imul(h ^ s.charCodeAt(i), 16777619);
|
|
@@ -671,23 +686,35 @@ function trackUpdate(main, previous, next) {
|
|
|
671
686
|
saveSeen(main);
|
|
672
687
|
update$1();
|
|
673
688
|
}
|
|
689
|
+
// src/client/reactive.ts
|
|
690
|
+
function reactive(get) {
|
|
691
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
692
|
+
const value = (() => get());
|
|
693
|
+
value.on = (fn) => {
|
|
694
|
+
listeners.add(fn);
|
|
695
|
+
return () => {
|
|
696
|
+
listeners.delete(fn);
|
|
697
|
+
};
|
|
698
|
+
};
|
|
699
|
+
value.notify = () => {
|
|
700
|
+
const now = get();
|
|
701
|
+
for (const fn of [...listeners]) fn(now);
|
|
702
|
+
};
|
|
703
|
+
return value;
|
|
704
|
+
}
|
|
674
705
|
// src/client/page/theme.ts
|
|
675
706
|
const media = matchMedia("(prefers-color-scheme: dark)");
|
|
676
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
677
707
|
const resolve = () => document.documentElement.dataset.theme ?? (media.matches ? "dark" : "light");
|
|
678
708
|
let theme = resolve();
|
|
679
709
|
function update() {
|
|
680
710
|
const next = resolve();
|
|
681
711
|
if (next === theme) return;
|
|
682
712
|
theme = next;
|
|
683
|
-
|
|
713
|
+
currentTheme.notify();
|
|
684
714
|
}
|
|
685
715
|
media.addEventListener("change", update);
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
listeners.add(fn);
|
|
689
|
-
return () => listeners.delete(fn);
|
|
690
|
-
}
|
|
716
|
+
/** The theme in effect, as it changes (api.theme). */
|
|
717
|
+
const currentTheme = reactive(() => theme);
|
|
691
718
|
const themePreference = () => document.documentElement.dataset.theme ?? "auto";
|
|
692
719
|
function setThemePreference(pref) {
|
|
693
720
|
if (pref === "auto") delete document.documentElement.dataset.theme;
|
|
@@ -707,6 +734,30 @@ const STATES = [
|
|
|
707
734
|
];
|
|
708
735
|
/** How many things on a page wait for the reader: its open questions and unread messages. */
|
|
709
736
|
const awaiting = (p) => p.open.length + p.unread.length;
|
|
737
|
+
// src/client/forms.ts
|
|
738
|
+
/** One line quoting an answer: what was chosen, then what was written. */
|
|
739
|
+
/**
|
|
740
|
+
* An answer, told apart: the button it was sent with (none for a plain Send), what was chosen
|
|
741
|
+
* (options, short values), and what was written.
|
|
742
|
+
*/
|
|
743
|
+
function answerParts(data, action) {
|
|
744
|
+
const chosen = [], written = [];
|
|
745
|
+
for (const v of Object.values(data)) {
|
|
746
|
+
if (v == null || v === "" || v === false) continue;
|
|
747
|
+
if (Array.isArray(v)) {
|
|
748
|
+
if (v.length) chosen.push(v.join(", "));
|
|
749
|
+
} else if (v === true) continue;
|
|
750
|
+
else if (String(v).length > 60 || String(v).includes("\n")) written.push(String(v));
|
|
751
|
+
else chosen.push(String(v));
|
|
752
|
+
}
|
|
753
|
+
return {
|
|
754
|
+
action: action && !["Send", "Submit"].includes(action) ? action : null,
|
|
755
|
+
chosen,
|
|
756
|
+
written
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
let current$2 = [];
|
|
760
|
+
reactive(() => current$2);
|
|
710
761
|
// src/icons.ts
|
|
711
762
|
/** An inbox: what awaits the reader (the header's menu, the overview). */
|
|
712
763
|
const INBOX_ICON = "<svg viewBox=\"0 0 16 16\" width=\"13\" height=\"13\" aria-hidden=\"true\"><path d=\"M2 9.5 3.8 3.2A1 1 0 0 1 4.8 2.5h6.4a1 1 0 0 1 1 .7L14 9.5V13a.5.5 0 0 1-.5.5h-11A.5.5 0 0 1 2 13Zm0 0h3.5l1 1.5h3l1-1.5H14\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.4\" stroke-linejoin=\"round\"/></svg>";
|
|
@@ -774,8 +825,8 @@ function trackElsewhere(root, handle, core) {
|
|
|
774
825
|
toggle.focus();
|
|
775
826
|
}
|
|
776
827
|
});
|
|
777
|
-
core.
|
|
778
|
-
core.
|
|
828
|
+
core.events.on(reload);
|
|
829
|
+
core.listeners.on(reload);
|
|
779
830
|
handle.onChange(reload);
|
|
780
831
|
load();
|
|
781
832
|
}
|
|
@@ -811,11 +862,50 @@ let waitingToast;
|
|
|
811
862
|
let unreadToast;
|
|
812
863
|
let toastTimer = 0;
|
|
813
864
|
let unreadShown = false;
|
|
865
|
+
const chatsOpen = /* @__PURE__ */ new Set();
|
|
866
|
+
function card(form, name, last) {
|
|
867
|
+
let el = form.querySelector(":scope > .wb-folded");
|
|
868
|
+
if (!el) {
|
|
869
|
+
el = document.createElement("div");
|
|
870
|
+
el.className = "wb-folded";
|
|
871
|
+
el.innerHTML = "<div class=\"wb-folded-head\"><span class=\"wb-folded-choice\"></span><span class=\"wb-folded-change\"></span></div><ul class=\"wb-folded-choices\"></ul><div class=\"wb-folded-text\"></div><button type=\"button\" class=\"wb-folded-chat\"></button>";
|
|
872
|
+
form.prepend(el);
|
|
873
|
+
}
|
|
874
|
+
const { action, chosen, written } = answerParts(last.data, last.action);
|
|
875
|
+
const list = action || chosen.length > 1 ? chosen : [];
|
|
876
|
+
const head = action ?? (chosen.length > 1 ? "answered" : chosen[0] ?? written.shift() ?? "answered");
|
|
877
|
+
el.querySelector(".wb-folded-choice").textContent = `✓ ${head}`;
|
|
878
|
+
const choices = el.querySelector(".wb-folded-choices");
|
|
879
|
+
choices.replaceChildren(...list.map((c) => Object.assign(document.createElement("li"), { textContent: c })));
|
|
880
|
+
choices.hidden = !list.length;
|
|
881
|
+
el.querySelector(".wb-folded-change").textContent = form.hasAttribute("data-wb-just-sent") ? "✓ the agent has it" : "decided · change";
|
|
882
|
+
const text = el.querySelector(".wb-folded-text");
|
|
883
|
+
text.textContent = written.join("\n\n");
|
|
884
|
+
text.hidden = !written.length;
|
|
885
|
+
const messages = api$1.events().filter((e) => e.type === "chat:message" && e.data.chat === name).length;
|
|
886
|
+
const thread = form.querySelector(":scope > [data-block=chat-thread]");
|
|
887
|
+
const unreadHere = !!thread && api$1.unread().some((m) => thread.querySelector(`[data-wb-message="${CSS.escape(m.id)}"]`) || m.type === "chat:message" && m.data.chat === name);
|
|
888
|
+
const box = thread?.querySelector("textarea");
|
|
889
|
+
const writing = !!box && (document.activeElement === box || box.value.trim() !== "");
|
|
890
|
+
if (unreadHere || writing) chatsOpen.add(name);
|
|
891
|
+
const open = chatsOpen.has(name);
|
|
892
|
+
form.toggleAttribute("data-wb-chat-open", open);
|
|
893
|
+
const chat = el.querySelector(".wb-folded-chat");
|
|
894
|
+
chat.hidden = !messages;
|
|
895
|
+
chat.textContent = `💬 ${messages} message${messages === 1 ? "" : "s"} ${open ? "▾" : "▸"}`;
|
|
896
|
+
chat.setAttribute("aria-expanded", String(open));
|
|
897
|
+
}
|
|
814
898
|
function show(list = forms) {
|
|
815
899
|
forms = list;
|
|
816
900
|
for (const { form, name, state, last } of forms) {
|
|
817
901
|
if (last && reopened.has(name) && reopened.get(name) !== last.id && state === "decided") reopened.delete(name);
|
|
818
|
-
|
|
902
|
+
const folded = state === "decided" && !reopened.has(name);
|
|
903
|
+
form.toggleAttribute("data-wb-folded", folded);
|
|
904
|
+
if (folded && last) card(form, name, last);
|
|
905
|
+
else {
|
|
906
|
+
form.querySelector(":scope > .wb-folded")?.remove();
|
|
907
|
+
form.removeAttribute("data-wb-chat-open");
|
|
908
|
+
}
|
|
819
909
|
}
|
|
820
910
|
const unread = api$1.unread().length;
|
|
821
911
|
const parts = ORDER.map((state) => [state, inState(state).length]).filter(([, count]) => count).map(([state, count]) => [state, LABEL[state](count)]);
|
|
@@ -909,14 +999,23 @@ function trackWaiting(root, core) {
|
|
|
909
999
|
const form = target.closest("form[data-wb-folded]");
|
|
910
1000
|
if (!form || target.closest("[data-block=chat-thread]")) return;
|
|
911
1001
|
e.preventDefault();
|
|
1002
|
+
if (target.closest(".wb-folded-chat")) {
|
|
1003
|
+
const name = form.getAttribute("name");
|
|
1004
|
+
if (chatsOpen.has(name) || form.hasAttribute("data-wb-chat-open")) {
|
|
1005
|
+
chatsOpen.delete(name);
|
|
1006
|
+
form.removeAttribute("data-wb-chat-open");
|
|
1007
|
+
} else chatsOpen.add(name);
|
|
1008
|
+
show(forms);
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
912
1011
|
const name = form.getAttribute("name");
|
|
913
1012
|
const last = api$1.last(name);
|
|
914
1013
|
if (last) reopened.set(name, last.id);
|
|
915
1014
|
show(forms);
|
|
916
1015
|
form.querySelector("input:not([type=hidden]), textarea, select")?.focus({ preventScroll: true });
|
|
917
1016
|
});
|
|
918
|
-
api$1.
|
|
919
|
-
api$1.
|
|
1017
|
+
api$1.forms.on(show);
|
|
1018
|
+
api$1.events.on(() => show());
|
|
920
1019
|
show(api$1.forms());
|
|
921
1020
|
document.addEventListener("submit", (e) => {
|
|
922
1021
|
const form = e.target;
|
|
@@ -956,7 +1055,7 @@ function trackLive(root, handle, api) {
|
|
|
956
1055
|
dot.title = !live ? "Reconnecting… the page may be out of date" : !hasAnswers ? "Live" : own ? "Live · an agent is listening on this page" : anyPage ? "Live · an agent is listening on every page" : "Live · no agent is listening right now; answers wait in the log";
|
|
957
1056
|
dot.setAttribute("aria-label", dot.title);
|
|
958
1057
|
};
|
|
959
|
-
api.
|
|
1058
|
+
api.listeners.on(show);
|
|
960
1059
|
new MutationObserver(show).observe(document.documentElement, {
|
|
961
1060
|
attributes: true,
|
|
962
1061
|
attributeFilter: ["data-wb-live"]
|
|
@@ -1067,6 +1166,40 @@ function trackHold() {
|
|
|
1067
1166
|
});
|
|
1068
1167
|
addEventListener("resize", note);
|
|
1069
1168
|
}
|
|
1169
|
+
// src/client/page/window.ts
|
|
1170
|
+
const windows = () => [...document.querySelectorAll("#wb-main .wb-window")];
|
|
1171
|
+
let maximized = null;
|
|
1172
|
+
function apply() {
|
|
1173
|
+
const all = windows();
|
|
1174
|
+
if (maximized != null && !all[maximized]) maximized = null;
|
|
1175
|
+
all.forEach((win, i) => {
|
|
1176
|
+
const on = i === maximized;
|
|
1177
|
+
win.toggleAttribute("data-wb-maximized", on);
|
|
1178
|
+
const button = win.querySelector("[data-wb-maximize]");
|
|
1179
|
+
if (button) {
|
|
1180
|
+
button.title = on ? "Back into the page (Esc)" : "Fill the window";
|
|
1181
|
+
button.setAttribute("aria-label", button.title);
|
|
1182
|
+
button.setAttribute("aria-pressed", String(on));
|
|
1183
|
+
}
|
|
1184
|
+
});
|
|
1185
|
+
document.documentElement.toggleAttribute("data-wb-window-maximized", maximized != null);
|
|
1186
|
+
}
|
|
1187
|
+
function trackWindows(api) {
|
|
1188
|
+
document.addEventListener("click", (e) => {
|
|
1189
|
+
const win = e.target.closest?.("[data-wb-maximize]")?.closest(".wb-window");
|
|
1190
|
+
if (!win) return;
|
|
1191
|
+
const i = windows().indexOf(win);
|
|
1192
|
+
maximized = maximized === i ? null : i;
|
|
1193
|
+
apply();
|
|
1194
|
+
});
|
|
1195
|
+
document.addEventListener("keydown", (e) => {
|
|
1196
|
+
if (e.key === "Escape" && maximized != null) {
|
|
1197
|
+
maximized = null;
|
|
1198
|
+
apply();
|
|
1199
|
+
}
|
|
1200
|
+
});
|
|
1201
|
+
api.onRendered(apply);
|
|
1202
|
+
}
|
|
1070
1203
|
// src/client/page/orphans.ts
|
|
1071
1204
|
/** A message in a chat: the chat block's event. */
|
|
1072
1205
|
const isMessage = (e) => e.type === "chat:message" && typeof e.data.chat === "string";
|
|
@@ -1086,15 +1219,21 @@ function trackOrphanThreads(main, api) {
|
|
|
1086
1219
|
box.hidden = threads.size === 0;
|
|
1087
1220
|
if (box.hidden) return box.replaceChildren();
|
|
1088
1221
|
box.innerHTML = String(html`<h2>Chats no longer on this page</h2>
|
|
1089
|
-
${[...threads].map(([chat, messages]) => {
|
|
1222
|
+
${[...threads].map(([chat, messages]) => {
|
|
1090
1223
|
const replaced = new Set(messages.map((m) => m.data.replaces).filter(Boolean).map(String));
|
|
1091
|
-
return html`<div class="wb-orphan" data-chat="${chat}"
|
|
1224
|
+
return html`<div class="wb-orphan" data-chat="${chat}">
|
|
1225
|
+
<h3>${chat}</h3>
|
|
1226
|
+
${messages.filter((m) => !replaced.has(m.id)).map((m) => {
|
|
1092
1227
|
const who = m.from === "cli" ? "agent" : "you";
|
|
1093
|
-
return html`<div class="wb-orphan-message" data-from="${who}"
|
|
1094
|
-
|
|
1228
|
+
return html`<div class="wb-orphan-message" data-from="${who}">
|
|
1229
|
+
<span class="wb-orphan-who">${who}</span
|
|
1230
|
+
><span class="wb-orphan-text">${String(m.data.text ?? "")}</span>
|
|
1231
|
+
</div>`;
|
|
1232
|
+
})}
|
|
1233
|
+
</div>`;
|
|
1095
1234
|
})}`);
|
|
1096
1235
|
}
|
|
1097
|
-
api.
|
|
1236
|
+
api.events.on(draw);
|
|
1098
1237
|
api.onRendered(draw);
|
|
1099
1238
|
draw();
|
|
1100
1239
|
}
|
|
@@ -1109,7 +1248,7 @@ async function mountOne(el) {
|
|
|
1109
1248
|
el.dataset.wbMounted = "";
|
|
1110
1249
|
if (!island) return;
|
|
1111
1250
|
try {
|
|
1112
|
-
const mod = await import(island.client);
|
|
1251
|
+
const mod = await import(new URL(island.client, document.baseURI).href);
|
|
1113
1252
|
if (!el.isConnected) return;
|
|
1114
1253
|
const mount = mod.default;
|
|
1115
1254
|
if (typeof mount !== "function") throw new Error("the client module must export a mount(element, props, api) function as default");
|
|
@@ -1323,18 +1462,26 @@ function keepPlace(place, sigs) {
|
|
|
1323
1462
|
if (el) window.scrollBy(0, el.getBoundingClientRect().top - place.top);
|
|
1324
1463
|
}
|
|
1325
1464
|
/** The new render of the page, patched in. */
|
|
1465
|
+
let leaving = false;
|
|
1466
|
+
addEventListener("pagehide", () => {
|
|
1467
|
+
leaving = true;
|
|
1468
|
+
});
|
|
1326
1469
|
async function refresh() {
|
|
1327
1470
|
let next;
|
|
1328
1471
|
try {
|
|
1329
1472
|
next = await currentPage.render();
|
|
1330
1473
|
} catch (err) {
|
|
1331
|
-
if (
|
|
1474
|
+
if (leaving) return;
|
|
1475
|
+
if (/: 404$/.test(err.message)) {
|
|
1476
|
+
if (currentPage.data()?.mtime == null) return;
|
|
1477
|
+
leaving = true;
|
|
1478
|
+
return location.reload();
|
|
1479
|
+
}
|
|
1332
1480
|
throw err;
|
|
1333
1481
|
}
|
|
1334
1482
|
const data = next.data;
|
|
1335
|
-
currentPage.data = data;
|
|
1336
1483
|
islands = data.islands;
|
|
1337
|
-
for (const href of data.styles) if (![...document.querySelectorAll("link[rel=stylesheet]")].some((l) => new URL(l.href).pathname === new URL(href, location.href).pathname)) document.head.insertAdjacentHTML("beforeend", String(html`<link rel="stylesheet" href="${href}"
|
|
1484
|
+
for (const href of data.styles) if (![...document.querySelectorAll("link[rel=stylesheet]")].some((l) => new URL(l.href).pathname === new URL(href, location.href).pathname)) document.head.insertAdjacentHTML("beforeend", String(html`<link rel="stylesheet" href="${href}" />`));
|
|
1338
1485
|
const content = new DOMParser().parseFromString(next.html, "text/html").getElementById("wb-main")?.innerHTML ?? "";
|
|
1339
1486
|
const nextSigs = signaturesOf(content);
|
|
1340
1487
|
const place = placeOf(nextSigs);
|
|
@@ -1368,11 +1515,10 @@ const mount = async (root, handle, coreApi) => {
|
|
|
1368
1515
|
core = coreApi;
|
|
1369
1516
|
page = handle.id;
|
|
1370
1517
|
main = root.querySelector("#wb-main");
|
|
1371
|
-
islands = handle.data.islands;
|
|
1518
|
+
islands = handle.data().islands;
|
|
1372
1519
|
api = {
|
|
1373
1520
|
...core,
|
|
1374
|
-
theme: currentTheme
|
|
1375
|
-
onTheme
|
|
1521
|
+
theme: currentTheme
|
|
1376
1522
|
};
|
|
1377
1523
|
const isDir = handle.kind === "pages" || handle.kind === "folder";
|
|
1378
1524
|
themeToggle(root);
|
|
@@ -1384,20 +1530,23 @@ const mount = async (root, handle, coreApi) => {
|
|
|
1384
1530
|
subtree: true
|
|
1385
1531
|
});
|
|
1386
1532
|
handle.onChange(() => refresh());
|
|
1387
|
-
if (isDir) core.
|
|
1388
|
-
if (isDir) core.
|
|
1533
|
+
if (isDir) core.events.on(() => refresh());
|
|
1534
|
+
if (isDir) core.listeners.on(() => refresh());
|
|
1389
1535
|
blockSigs = [...main.children].map(signature);
|
|
1390
|
-
if (
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1536
|
+
if (handle.live) {
|
|
1537
|
+
if (!isDir) trackInitial(main, page, core);
|
|
1538
|
+
if (!isDir) trackWaiting(main, core);
|
|
1539
|
+
trackElsewhere(root, handle, core);
|
|
1540
|
+
trackLive(root, handle, core);
|
|
1541
|
+
}
|
|
1394
1542
|
if (isDir) {
|
|
1395
1543
|
trackSorts();
|
|
1396
1544
|
core.onRendered(applySorts);
|
|
1397
1545
|
}
|
|
1398
1546
|
trackSticky(main, (fn) => core.onRendered(fn));
|
|
1399
1547
|
trackHold();
|
|
1400
|
-
|
|
1548
|
+
trackWindows(core);
|
|
1549
|
+
if (!isDir && handle.live) trackOrphanThreads(main, core);
|
|
1401
1550
|
await mountIslands();
|
|
1402
1551
|
tickTimes();
|
|
1403
1552
|
};
|
package/dist/src/loader.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { importFresh, importOwn } from "./load.js";
|
|
2
2
|
import { createPages } from "./pages/index.js";
|
|
3
3
|
import { pluginCommands } from "./plugins.js";
|
|
4
|
+
import { inPublic, publicDirOf } from "./public.js";
|
|
4
5
|
import fs from "node:fs";
|
|
5
6
|
import path from "node:path";
|
|
6
7
|
import { fileURLToPath } from "node:url";
|
|
@@ -24,6 +25,7 @@ const BUILTIN_COMMANDS = /* @__PURE__ */ new Set([
|
|
|
24
25
|
"scroll",
|
|
25
26
|
"close",
|
|
26
27
|
"prune",
|
|
28
|
+
"build",
|
|
27
29
|
"edit",
|
|
28
30
|
"skill",
|
|
29
31
|
"help"
|
|
@@ -84,12 +86,17 @@ function createConfigLoader(proj, { pages: withPages = true } = {}) {
|
|
|
84
86
|
if (builtin.has(e.name)) plugins[plugins.findIndex((p) => p.name === e.name)] = e;
|
|
85
87
|
else plugins.push(e);
|
|
86
88
|
}
|
|
89
|
+
const publicDirs = new Map(plugins.map((p) => [p.name, publicDirOf(p, proj.wb)]));
|
|
87
90
|
const blocks = plugins.flatMap((p) => Object.entries(p.blocks ?? {}).map(([name, block]) => ({
|
|
88
91
|
name,
|
|
89
92
|
block,
|
|
90
|
-
plugin: p.name
|
|
93
|
+
plugin: p.name,
|
|
94
|
+
public: publicDirs.get(p.name)
|
|
91
95
|
})));
|
|
92
|
-
const styles = plugins.
|
|
96
|
+
const styles = plugins.filter((p) => p.style).map((p) => ({
|
|
97
|
+
plugin: p.name,
|
|
98
|
+
file: inPublic(publicDirs.get(p.name), p.style, `plugin ${p.name}: style`)
|
|
99
|
+
}));
|
|
93
100
|
const links = plugins.flatMap((p) => p.links ? [p.links.bind(p)] : []);
|
|
94
101
|
const pages = withPages ? createPages({
|
|
95
102
|
blocks,
|
|
@@ -103,7 +110,9 @@ function createConfigLoader(proj, { pages: withPages = true } = {}) {
|
|
|
103
110
|
plugins,
|
|
104
111
|
handedOut: declared("handOut"),
|
|
105
112
|
forReader: declared("forReader"),
|
|
106
|
-
|
|
113
|
+
publicDirs,
|
|
114
|
+
files: config?.files !== false,
|
|
115
|
+
build: config?.build ?? {}
|
|
107
116
|
};
|
|
108
117
|
}
|
|
109
118
|
function config() {
|
|
@@ -115,7 +124,9 @@ function createConfigLoader(proj, { pages: withPages = true } = {}) {
|
|
|
115
124
|
plugins: [],
|
|
116
125
|
handedOut: /* @__PURE__ */ new Set(),
|
|
117
126
|
forReader: /* @__PURE__ */ new Set(),
|
|
127
|
+
publicDirs: /* @__PURE__ */ new Map(),
|
|
118
128
|
files: false,
|
|
129
|
+
build: {},
|
|
119
130
|
errors: [error]
|
|
120
131
|
}));
|
|
121
132
|
return cached;
|
package/dist/src/package.js
CHANGED
|
@@ -25,9 +25,6 @@ const FROM_SOURCE = fileURLToPath(import.meta.url).endsWith(".ts");
|
|
|
25
25
|
* dist/. The same whether the module runs from source (plugins/form/index.ts gives
|
|
26
26
|
* dist/plugins/form/client.js) or from dist/ itself.
|
|
27
27
|
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return path.join(PACKAGE_DIR, inDist ? "" : "dist", rel, name);
|
|
32
|
-
}
|
|
33
|
-
export { FROM_SOURCE, PACKAGE_DIR, builtFile, packagePath };
|
|
28
|
+
/** A built-in plugin's public folder: its built browser modules and copied styles (build.ts). */
|
|
29
|
+
const builtinPublic = (name) => packagePath("dist", "plugins", name, "public");
|
|
30
|
+
export { FROM_SOURCE, PACKAGE_DIR, builtinPublic, packagePath };
|
package/dist/src/pages/blocks.js
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
|
+
import { inPublic } from "../public.js";
|
|
1
2
|
import fs from "node:fs";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
3
|
+
import "node:path";
|
|
4
|
+
import "node:url";
|
|
4
5
|
// src/pages/blocks.ts
|
|
5
6
|
const NAME = /^[\w-]+$/;
|
|
6
|
-
/**
|
|
7
|
-
function
|
|
8
|
-
if (ref == null) return null;
|
|
9
|
-
if (ref instanceof URL || typeof ref === "string" && ref.startsWith("file:")) return fileURLToPath(ref);
|
|
10
|
-
if (typeof ref === "string" && path.isAbsolute(ref)) return ref;
|
|
11
|
-
throw new Error(`block "${block}": ${field} must be a URL, e.g. new URL('./${field}.js', import.meta.url)`);
|
|
12
|
-
}
|
|
13
|
-
/** Check and resolve one block into what the engine uses. */
|
|
14
|
-
function normalize({ name, block: b, plugin }) {
|
|
7
|
+
/** Check and resolve one block into what the engine uses: its files in its plugin's public folder. */
|
|
8
|
+
function normalize({ name, block: b, plugin, public: dir }) {
|
|
15
9
|
if (typeof b !== "object" || !b) throw new Error(`plugin ${plugin}: block "${name}" is not an object`);
|
|
16
10
|
if (!NAME.test(name)) throw new Error(`plugin ${plugin}: block name ${JSON.stringify(name)}: use letters, digits, - and _`);
|
|
11
|
+
const file = (ref, field) => ref == null ? null : inPublic(dir, ref, `plugin ${plugin}, block "${name}": ${field}`);
|
|
17
12
|
const files = {
|
|
18
|
-
client:
|
|
19
|
-
style:
|
|
13
|
+
client: file(b.client, "client"),
|
|
14
|
+
style: file(b.style, "style")
|
|
20
15
|
};
|
|
21
16
|
for (const [field, file] of Object.entries(files)) if (file && !fs.existsSync(file)) throw new Error(`plugin ${plugin}, block "${name}": ${field} file not found: ${file}`);
|
|
22
17
|
return {
|
|
@@ -404,7 +404,7 @@ async function renderMarkdown(source, { page, file, resolve, code = null, linkFo
|
|
|
404
404
|
html: stringify(tree.children ?? []),
|
|
405
405
|
title,
|
|
406
406
|
islands,
|
|
407
|
-
styles: [...used.values()].map((t) => t.style).filter((s) => !!s)
|
|
407
|
+
styles: [...new Set([...used.values()].map((t) => t.style).filter((s) => !!s))]
|
|
408
408
|
};
|
|
409
409
|
}
|
|
410
410
|
export { formNames, parseAttrs, renderMarkdown };
|