unsys-canvas 0.2.1 → 0.2.2

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/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { createContext, lazy, memo, useLayoutEffect, useCallback, useState, useEffect, Suspense, useRef, Component, useMemo, useContext } from 'react';
1
+ import { createContext, lazy, memo, useLayoutEffect, useCallback, useState, useEffect, Suspense, useRef, Component, useContext } from 'react';
2
2
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
3
  import '@excalidraw/excalidraw/index.css';
4
4
  import katex from 'katex';
@@ -2007,11 +2007,6 @@ function unsysCanvasZoomAtPoint(input) {
2007
2007
  scrollY: baseScrollY - (appLayerY - appLayerY / nextZoom)
2008
2008
  };
2009
2009
  }
2010
- function clampUnsysRange(value, min, max) {
2011
- if (!Number.isFinite(value)) return min;
2012
- if (max < min) return min;
2013
- return Math.min(max, Math.max(min, value));
2014
- }
2015
2010
  function unsysCanvasSceneToViewport(scene, appState) {
2016
2011
  const zoom = unsysCanvasZoomValue(appState);
2017
2012
  const scrollX = Number(appState?.scrollX) || 0;
@@ -2080,88 +2075,18 @@ function unsysCanvasRevealScroll(elements, appState, pad = 40) {
2080
2075
  }
2081
2076
  return { scrollX, scrollY };
2082
2077
  }
2083
- function unsysCanvasSelectionViewportRect(elements, appState) {
2084
- const bounds = unsysCanvasContentBounds(elements);
2085
- if (!bounds) return null;
2086
- const topLeft = unsysCanvasSceneToViewport({ x: bounds.minX, y: bounds.minY }, appState);
2087
- const bottomRight = unsysCanvasSceneToViewport({ x: bounds.maxX, y: bounds.maxY }, appState);
2088
- return {
2089
- left: Math.min(topLeft.x, bottomRight.x),
2090
- top: Math.min(topLeft.y, bottomRight.y),
2091
- right: Math.max(topLeft.x, bottomRight.x),
2092
- bottom: Math.max(topLeft.y, bottomRight.y)
2093
- };
2094
- }
2095
2078
  function unsysCanvasViewportToHost(point, host) {
2096
2079
  return {
2097
2080
  x: point.x - (Number(host?.left) || 0),
2098
2081
  y: point.y - (Number(host?.top) || 0)
2099
2082
  };
2100
2083
  }
2101
- function unsysCanvasSelectionHostRect(elements, appState, host) {
2102
- const rect = unsysCanvasSelectionViewportRect(elements, appState);
2103
- if (!rect) return null;
2104
- const originLeft = Number(host?.left) || 0;
2105
- const originTop = Number(host?.top) || 0;
2106
- return {
2107
- left: rect.left - originLeft,
2108
- top: rect.top - originTop,
2109
- right: rect.right - originLeft,
2110
- bottom: rect.bottom - originTop
2111
- };
2112
- }
2113
- var UNSYS_CANVAS_COMMAND_PICKER_WIDTH = 264;
2114
- var UNSYS_CANVAS_COMMAND_PICKER_HEIGHT = 220;
2115
- var UNSYS_CANVAS_COMMAND_PICKER_GAP = 8;
2116
- var UNSYS_CANVAS_COMMAND_PICKER_PAD = 8;
2117
- var UNSYS_CANVAS_COMMAND_PICKER_AFFORDANCE_SIZE = 24;
2118
- function placeUnsysCanvasCommandPicker(input) {
2119
- const pad = input.pad ?? UNSYS_CANVAS_COMMAND_PICKER_PAD;
2120
- const gap = input.gap ?? UNSYS_CANVAS_COMMAND_PICKER_GAP;
2121
- const boxW = input.box?.width ?? UNSYS_CANVAS_COMMAND_PICKER_WIDTH;
2122
- const boxH = input.box?.height ?? UNSYS_CANVAS_COMMAND_PICKER_HEIGHT;
2123
- const viewW = Math.max(0, Number(input.viewport.width) || 0);
2124
- const viewH = Math.max(0, Number(input.viewport.height) || 0);
2125
- const maxLeft = Math.max(pad, viewW - boxW - pad);
2126
- const maxTop = Math.max(pad, viewH - boxH - pad);
2127
- const clamp = (left2, top2) => ({
2128
- left: Math.round(clampUnsysRange(left2, pad, maxLeft)),
2129
- top: Math.round(clampUnsysRange(top2, pad, maxTop))
2130
- });
2131
- const sel = input.selection;
2132
- if (!sel) {
2133
- const pointer = input.pointer ?? { x: pad, y: pad };
2134
- return clamp(Number(pointer.x) || 0, Number(pointer.y) || 0);
2135
- }
2136
- const left = sel.left;
2137
- let top = sel.bottom + gap;
2138
- if (top + boxH + pad > viewH) top = sel.top - gap - boxH;
2139
- return clamp(left, top);
2140
- }
2141
- function placeUnsysCanvasCommandPickerAffordance(input) {
2142
- const size = input.size ?? UNSYS_CANVAS_COMMAND_PICKER_AFFORDANCE_SIZE;
2143
- return placeUnsysCanvasCommandPicker({
2144
- selection: input.selection,
2145
- viewport: input.viewport,
2146
- box: { width: size, height: size },
2147
- gap: input.gap,
2148
- pad: input.pad
2149
- });
2150
- }
2151
2084
  function ileLearnMoreSelectionKey(selectedElementIds) {
2152
2085
  return Object.keys(selectedElementIds ?? {}).filter((id) => Boolean(selectedElementIds?.[id])).sort().join(",");
2153
2086
  }
2154
2087
  function unsysCanvasPromptMode(selectedElementIds) {
2155
2088
  return ileLearnMoreSelectionKey(selectedElementIds) ? "commands" : "ask";
2156
2089
  }
2157
- function unsysCanvasSlashBarOpen(input) {
2158
- return Boolean(input.selectionActive && input.slashIntent);
2159
- }
2160
- function unsysCanvasSlashKeyOpensBar(input) {
2161
- if (input.typingInField) return false;
2162
- if (!input.selectionActive) return false;
2163
- return input.key === "/";
2164
- }
2165
2090
 
2166
2091
  // src/lib/work-canvas/work-canvas-xai-parse.ts
2167
2092
  var UNSYS_CANVAS_REPLY_TEXT_KEYS = [
@@ -3034,9 +2959,9 @@ var UNSYS_CANVAS_COMMANDS = [
3034
2959
  }
3035
2960
  ];
3036
2961
  var UNSYS_CANVAS_CHEATSHEET_LABEL = "Command cheat sheet";
3037
- var UNSYS_CANVAS_COMMAND_PICKER_LABEL = "Command picker";
3038
- var UNSYS_CANVAS_COMMAND_PICKER_SHORTCUT = "/";
3039
- var UNSYS_CANVAS_COMMAND_PICKER_TOOLTIP = "Type to filter commands, then Enter to run one on the current selection. Escape closes. Shortcut / while something is selected. Also right-click or the / control near the selection.";
2962
+ var UNSYS_CANVAS_CONTEXT_MENU_ROW_LABEL = "Right-click menu";
2963
+ var UNSYS_CANVAS_CONTEXT_MENU_ROW_HINT = "Right-click";
2964
+ var UNSYS_CANVAS_CONTEXT_MENU_ROW_TOOLTIP = "Right-click a selection. Every command is listed in the Commands section at the top of the board menu, with its shortcut. Click one to run it on that selection. On touch, press and hold.";
3040
2965
  function unsysCanvasCommandsFor(_guide, extras = []) {
3041
2966
  const catalog = UNSYS_CANVAS_COMMANDS.map((command) => ({ ...command }));
3042
2967
  const seen = new Set(catalog.map((command) => command.id));
@@ -3116,33 +3041,6 @@ function filterUnsysCanvasCommands(query, guide, extras = []) {
3116
3041
  (command) => unsysCanvasCommandMatchNames(command).some((name) => name.startsWith(q))
3117
3042
  );
3118
3043
  }
3119
- function unsysCanvasFuzzySubsequence(name, query) {
3120
- let i = 0;
3121
- for (const ch of name) {
3122
- if (ch === query[i]) i += 1;
3123
- if (i >= query.length) return true;
3124
- }
3125
- return false;
3126
- }
3127
- function unsysCanvasCommandFuzzyScore(command, query) {
3128
- const q = String(query || "").trim().toLowerCase();
3129
- if (!q) return 1;
3130
- if (command.shortcut && command.shortcut.toLowerCase() === q) return 100;
3131
- let best = 0;
3132
- for (const name of unsysCanvasCommandMatchNames(command)) {
3133
- if (name === q) best = Math.max(best, 90);
3134
- else if (name.startsWith(q)) best = Math.max(best, 80);
3135
- else if (name.includes(q)) best = Math.max(best, 50);
3136
- else if (unsysCanvasFuzzySubsequence(name, q)) best = Math.max(best, 20);
3137
- }
3138
- return best;
3139
- }
3140
- function fuzzyFilterUnsysCanvasCommands(query, guide, extras = []) {
3141
- const catalog = unsysCanvasCommandsFor(guide, extras);
3142
- const q = String(query || "").trim().toLowerCase();
3143
- if (!q) return catalog;
3144
- return catalog.map((command) => ({ command, score: unsysCanvasCommandFuzzyScore(command, q) })).filter((row) => row.score > 0).sort((a, b) => b.score - a.score || a.command.label.localeCompare(b.command.label)).map((row) => row.command);
3145
- }
3146
3044
  function unsysCanvasCommandDraft(raw) {
3147
3045
  const trimmed = String(raw ?? "").trim();
3148
3046
  if (!trimmed.startsWith("/")) {
@@ -3748,184 +3646,116 @@ function CanvasPromptBar({
3748
3646
  useEffect(() => () => publishCommands(null), [publishCommands]);
3749
3647
  return null;
3750
3648
  }
3751
- var UNSYS_CANVAS_COMMAND_RAIL_CLASS = "pointer-events-auto relative flex min-h-9 w-full min-w-0 flex-row items-center justify-start gap-1.5 whitespace-nowrap rounded-none border border-white/45 bg-black px-1.5 py-2 text-left font-mono text-[11px] leading-tight text-white shadow-[inset_0_1px_0_rgba(255,255,255,0.35)] hover:border-white hover:bg-neutral-950 disabled:cursor-not-allowed disabled:border-neutral-800 disabled:bg-neutral-950 disabled:text-neutral-600 disabled:opacity-100 disabled:shadow-none disabled:hover:border-neutral-800 disabled:hover:bg-neutral-950 disabled:hover:text-neutral-600";
3752
- var UNSYS_CANVAS_COMMAND_SIDEBAR_CLASS = "pointer-events-auto relative flex min-h-9 w-full min-w-0 flex-row items-center justify-start gap-1.5 overflow-hidden whitespace-nowrap rounded-none border border-white/35 bg-black px-1.5 py-1.5 text-left font-mono text-[11px] leading-tight text-white shadow-[inset_0_1px_0_rgba(255,255,255,0.2)] hover:border-white hover:bg-neutral-950 disabled:cursor-not-allowed disabled:border-neutral-800 disabled:bg-neutral-950 disabled:text-neutral-600 disabled:opacity-100 disabled:shadow-none disabled:hover:border-neutral-800 disabled:hover:bg-neutral-950 disabled:hover:text-neutral-600";
3753
- var UNSYS_CANVAS_COMMAND_SIDEBAR_MARK_CLASS = "h-3.5 w-3.5 shrink-0";
3754
- var UNSYS_CANVAS_COMMAND_STRIPE_CLASS = "pointer-events-auto relative flex h-10 w-10 shrink-0 items-center justify-center rounded-none border border-white/35 bg-black text-white shadow-[inset_0_1px_0_rgba(255,255,255,0.2)] hover:border-white hover:bg-neutral-950 disabled:cursor-not-allowed disabled:border-neutral-800 disabled:bg-neutral-950 disabled:text-neutral-600 disabled:opacity-100 disabled:shadow-none disabled:hover:border-neutral-800 disabled:hover:bg-neutral-950 disabled:hover:text-neutral-600";
3755
- var UNSYS_CANVAS_COMMAND_STRIPE_MARK_CLASS = "h-4 w-4 shrink-0";
3756
- var ICON_PATHS = {
3757
- focus: "M8 2v2.5M8 11.5V14M2 8h2.5M11.5 8H14M8 5.5a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5z",
3758
- next: "M2 8h9M8 4.5l4.5 3.5L8 11.5M13.5 3.5v9",
3759
- simplify: "M3 4h10M3 8h7M3 12h4",
3760
- breakdown: "M2 6.5h4v3H2zM10 2.5h4v3h-4zM10 10.5h4v3h-4zM6 8h4M10 8V4M10 8v6.5",
3761
- concepts: "M2 2.5h4v3H2zM10 2.5h4v3h-4zM6 10.5h4v3H6zM4 5.5v5M12 5.5v5M8 8.5v2",
3762
- define: "M3 2.5h10v11H3zM5.5 5.5h5M5.5 8h7M5.5 10.5h4",
3763
- answer: "M3 3h10v7H8l-3 3v-3H3z",
3764
- draw: "M10.5 2.5l3 3-8 8H2.5v-3zM9 4l3 3",
3765
- refactor: "M4 3h5v2H6.5A4.5 4.5 0 1 1 3 10M12 13H7v-2h2.5A4.5 4.5 0 1 1 13 6",
3766
- pretty: "M2.5 2.5h11v11H2.5zM5 6h6M5 8.5h6M5 11h4",
3767
- picker: "M3 4.5h10M3 8h7M3 11.5h4",
3768
- dictate: "M8 2.5a2 2 0 0 1 2 2V8a2 2 0 1 1-4 0V4.5a2 2 0 0 1 2-2zM5 8.5a3 3 0 0 0 6 0M8 11.5V14",
3769
- pointer: "M4.2 8.2a3.6 3.6 0 1 1 3.6-3.6l5.8 5.8a2.2 2.2 0 0 1-3.1 3.1zM9.4 9.4l2.1 2.1M7 7.2l1.3 1.3M4.8 4.8l1.8 1.8",
3770
- commit: "M3 8h10M10 5l3 3-3 3",
3771
- "rail-expand": "M6 3l5 5-5 5",
3772
- "rail-collapse": "M10 3L5 8l5 5",
3773
- boards: "M2.5 3.5h4.5v4.5H2.5zM9 3.5h4.5v4.5H9zM2.5 10h4.5v3H2.5zM9 10h4.5v3H9z",
3774
- save: "M3 8.5V13h10V8.5M8 2.5v8M5 8l3 3 3-3"
3649
+
3650
+ // src/lib/work-canvas/work-canvas-context-menu.ts
3651
+ var UNSYS_CANVAS_CONTEXT_MENU_LABEL = "Commands";
3652
+ var UNSYS_CANVAS_CONTEXT_MENU_SELECTORS = {
3653
+ list: "ul.context-menu",
3654
+ popover: ".context-menu-popover",
3655
+ item: "context-menu-item",
3656
+ label: "context-menu-item__label",
3657
+ shortcut: "context-menu-item__shortcut",
3658
+ separator: "context-menu-item-separator",
3659
+ /** Only on the menu for a canvas click, never for a selection. */
3660
+ canvasOnlyTestId: "selectAll"
3775
3661
  };
3776
- function CommandMark({
3777
- id,
3778
- className = "h-3.5 w-3.5"
3779
- }) {
3780
- const d = ICON_PATHS[id] ?? ICON_PATHS.simplify;
3781
- return /* @__PURE__ */ jsx(
3782
- "svg",
3783
- {
3784
- viewBox: "0 0 16 16",
3785
- className,
3786
- fill: "none",
3787
- stroke: "currentColor",
3788
- strokeWidth: 1.4,
3789
- strokeLinecap: "round",
3790
- strokeLinejoin: "round",
3791
- "aria-hidden": true,
3792
- "data-unsys-canvas-command-mark": id,
3793
- "data-command-icon": id,
3794
- children: /* @__PURE__ */ jsx("path", { d })
3795
- }
3796
- );
3662
+ function unsysCanvasContextMenuEntries(extras = []) {
3663
+ return unsysCanvasCommandsFor(null, extras).map((command) => ({
3664
+ id: command.id,
3665
+ label: command.label,
3666
+ shortcut: unsysCanvasCommandShortcutLabel(command.shortcut),
3667
+ title: command.tooltip
3668
+ }));
3797
3669
  }
3798
- function UnsysCanvasCommandPicker({
3799
- open,
3800
- left,
3801
- top,
3802
- query,
3803
- extras = [],
3804
- onQueryChange,
3805
- onRun,
3806
- onClose
3807
- }) {
3808
- const inputRef = useRef(null);
3809
- const [active, setActive] = useState(0);
3810
- const matches = useMemo(
3811
- () => fuzzyFilterUnsysCanvasCommands(query, null, extras),
3812
- [extras, query]
3813
- );
3814
- useEffect(() => {
3815
- setActive(0);
3816
- }, [query, open]);
3817
- useEffect(() => {
3818
- if (!open) return;
3819
- inputRef.current?.focus();
3820
- inputRef.current?.select();
3821
- }, [open]);
3822
- if (!open) return null;
3823
- const runAt = (index) => {
3824
- const command = matches[index];
3825
- if (!command) return;
3826
- onRun(command.id);
3827
- };
3828
- return /* @__PURE__ */ jsxs(
3829
- "div",
3830
- {
3831
- "data-unsys-canvas-command-picker": true,
3832
- role: "dialog",
3833
- "aria-label": UNSYS_CANVAS_COMMAND_PICKER_LABEL,
3834
- className: "pointer-events-auto absolute z-[70] w-[16.5rem] border border-white bg-black text-white shadow-[0_12px_40px_rgba(0,0,0,0.55)]",
3835
- style: { left, top },
3836
- onMouseDown: (event) => event.preventDefault(),
3837
- children: [
3838
- /* @__PURE__ */ jsx(
3839
- "input",
3840
- {
3841
- ref: inputRef,
3842
- "data-unsys-canvas-command-picker-input": true,
3843
- value: query,
3844
- onChange: (event) => onQueryChange(event.target.value.replace(/^\//, "")),
3845
- placeholder: "Filter commands",
3846
- "aria-label": UNSYS_CANVAS_COMMAND_PICKER_LABEL,
3847
- className: "w-full border-b border-white/30 bg-black px-2 py-1.5 font-mono text-[12px] text-white outline-none placeholder:text-white/35",
3848
- onKeyDown: (event) => {
3849
- if (event.key === "Escape") {
3850
- event.preventDefault();
3851
- event.stopPropagation();
3852
- onClose();
3853
- return;
3854
- }
3855
- if (event.key === "ArrowDown") {
3856
- event.preventDefault();
3857
- setActive((prev) => Math.min(matches.length - 1, prev + 1));
3858
- return;
3859
- }
3860
- if (event.key === "ArrowUp") {
3861
- event.preventDefault();
3862
- setActive((prev) => Math.max(0, prev - 1));
3863
- return;
3864
- }
3865
- if (event.key === "Enter") {
3866
- event.preventDefault();
3867
- event.stopPropagation();
3868
- runAt(active);
3869
- }
3870
- }
3871
- }
3872
- ),
3873
- /* @__PURE__ */ jsx("ul", { "data-unsys-canvas-command-picker-list": true, className: "max-h-56 overflow-y-auto py-1", children: matches.length ? matches.map((command, index) => /* @__PURE__ */ jsx(
3874
- PickerRow,
3875
- {
3876
- command,
3877
- active: index === active,
3878
- onRun: () => onRun(command.id)
3879
- },
3880
- command.id
3881
- )) : /* @__PURE__ */ jsx("li", { className: "px-2 py-2 font-mono text-[11px] text-white/45", children: "No matching commands" }) })
3882
- ]
3883
- }
3670
+ function unsysCanvasContextMenuIsForSelection(list) {
3671
+ return !list.querySelector(
3672
+ `[data-testid="${UNSYS_CANVAS_CONTEXT_MENU_SELECTORS.canvasOnlyTestId}"]`
3884
3673
  );
3885
3674
  }
3886
- function PickerRow({
3887
- command,
3888
- active,
3889
- onRun
3890
- }) {
3891
- const shortcut = unsysCanvasCommandShortcutLabel(command.shortcut);
3892
- return /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs(
3893
- "button",
3894
- {
3895
- type: "button",
3896
- "data-unsys-canvas-command-picker-row": command.id,
3897
- "data-active": active ? "true" : "false",
3898
- onClick: onRun,
3899
- className: `flex w-full items-center gap-2 px-2 py-1.5 text-left font-mono text-[11px] ${active ? "bg-white text-neutral-950" : "text-white hover:bg-white/10"}`,
3900
- children: [
3901
- /* @__PURE__ */ jsx(CommandMark, { id: command.id, label: command.label, className: "h-3.5 w-3.5 shrink-0" }),
3902
- /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate", children: command.label }),
3903
- shortcut ? /* @__PURE__ */ jsx("kbd", { className: "shrink-0 text-[10px] opacity-55", children: shortcut }) : null
3904
- ]
3905
- }
3906
- ) });
3675
+ var SECTION_ATTR = "data-unsys-canvas-context-section";
3676
+ var ROW_ATTR = "data-unsys-canvas-context-command";
3677
+ function buildSection(doc, entries, onRun) {
3678
+ const S = UNSYS_CANVAS_CONTEXT_MENU_SELECTORS;
3679
+ const nodes = [];
3680
+ const header = doc.createElement("li");
3681
+ header.setAttribute(SECTION_ATTR, "header");
3682
+ header.textContent = UNSYS_CANVAS_CONTEXT_MENU_LABEL;
3683
+ header.style.cssText = "padding:0.25rem 1.25rem;font-size:0.65rem;letter-spacing:0.08em;text-transform:uppercase;opacity:0.55;pointer-events:none;";
3684
+ nodes.push(header);
3685
+ for (const entry of entries) {
3686
+ const li = doc.createElement("li");
3687
+ li.setAttribute(SECTION_ATTR, "item");
3688
+ li.setAttribute("data-testid", `unsys-canvas-command-${entry.id}`);
3689
+ const button = doc.createElement("button");
3690
+ button.type = "button";
3691
+ button.className = S.item;
3692
+ button.setAttribute(ROW_ATTR, entry.id);
3693
+ if (entry.title) button.title = entry.title;
3694
+ const label = doc.createElement("div");
3695
+ label.className = S.label;
3696
+ label.textContent = entry.label;
3697
+ const kbd = doc.createElement("kbd");
3698
+ kbd.className = S.shortcut;
3699
+ kbd.textContent = entry.shortcut;
3700
+ button.append(label, kbd);
3701
+ li.append(button);
3702
+ li.addEventListener("click", (event) => {
3703
+ event.preventDefault();
3704
+ event.stopPropagation();
3705
+ onRun(entry.id);
3706
+ });
3707
+ nodes.push(li);
3708
+ }
3709
+ const hr = doc.createElement("hr");
3710
+ hr.setAttribute(SECTION_ATTR, "separator");
3711
+ hr.className = S.separator;
3712
+ nodes.push(hr);
3713
+ return nodes;
3714
+ }
3715
+ function refitPopover(list, host) {
3716
+ const popover = list.closest(UNSYS_CANVAS_CONTEXT_MENU_SELECTORS.popover);
3717
+ if (!popover) return;
3718
+ const pad = 10;
3719
+ const bounds = host.getBoundingClientRect();
3720
+ const rect = popover.getBoundingClientRect();
3721
+ const room = bounds.height - pad * 2;
3722
+ if (rect.height > room) {
3723
+ popover.style.maxHeight = `${room}px`;
3724
+ popover.style.overflowY = "auto";
3725
+ popover.style.top = `${pad}px`;
3726
+ return;
3727
+ }
3728
+ const overflow = rect.bottom - (bounds.bottom - pad);
3729
+ if (overflow > 0) {
3730
+ const top = Number.parseFloat(popover.style.top) || 0;
3731
+ popover.style.top = `${Math.max(pad, top - overflow)}px`;
3732
+ }
3907
3733
  }
3908
- function UnsysCanvasCommandPickerAffordance({
3909
- visible,
3910
- left,
3911
- top,
3912
- onOpen
3913
- }) {
3914
- if (!visible) return null;
3915
- return /* @__PURE__ */ jsx(
3916
- "button",
3917
- {
3918
- type: "button",
3919
- "data-unsys-canvas-command-picker-affordance": true,
3920
- "aria-label": UNSYS_CANVAS_COMMAND_PICKER_LABEL,
3921
- title: UNSYS_CANVAS_COMMAND_PICKER_LABEL,
3922
- className: "pointer-events-auto absolute z-[60] flex h-6 w-6 items-center justify-center border border-white/50 bg-black font-mono text-[11px] text-white hover:border-white",
3923
- style: { left, top },
3924
- onMouseDown: (event) => event.preventDefault(),
3925
- onClick: onOpen,
3926
- children: "/"
3734
+ function installUnsysCanvasContextMenu(options) {
3735
+ const { host } = options;
3736
+ const doc = host.ownerDocument;
3737
+ const ObserverCtor = doc.defaultView?.MutationObserver ?? globalThis.MutationObserver;
3738
+ if (!ObserverCtor) return () => {
3739
+ };
3740
+ const inject = () => {
3741
+ const lists = host.querySelectorAll(UNSYS_CANVAS_CONTEXT_MENU_SELECTORS.list);
3742
+ for (const list of lists) {
3743
+ if (list.querySelector(`[${SECTION_ATTR}]`)) continue;
3744
+ if (!options.canRun() || !unsysCanvasContextMenuIsForSelection(list)) continue;
3745
+ const entries = options.getEntries();
3746
+ if (!entries.length) continue;
3747
+ const nodes = buildSection(doc, entries, (id) => {
3748
+ options.closeMenu();
3749
+ options.onRun(id);
3750
+ });
3751
+ list.prepend(...nodes);
3752
+ refitPopover(list, host);
3927
3753
  }
3928
- );
3754
+ };
3755
+ const observer = new ObserverCtor(inject);
3756
+ observer.observe(host, { childList: true, subtree: true });
3757
+ inject();
3758
+ return () => observer.disconnect();
3929
3759
  }
3930
3760
 
3931
3761
  // src/lib/session-branch-model.ts
@@ -8629,11 +8459,7 @@ function ExcalidrawCanvas({
8629
8459
  const [isLoaded, setIsLoaded] = useState(false);
8630
8460
  const [canvasApiReady, setCanvasApiReady] = useState(false);
8631
8461
  const [commandText, setCommandText] = useState("");
8632
- const [slashBarOpen, setSlashBarOpen] = useState(false);
8633
- const [pickerPos, setPickerPos] = useState({ left: 24, top: 24 });
8634
- const commandInputRef = useRef(null);
8635
- const lastPointerHostRef = useRef({ x: 24, y: 24 });
8636
- const pickerSelectedRef = useRef([]);
8462
+ const contextMenuSelectedRef = useRef([]);
8637
8463
  const selectionWasActiveRef = useRef(false);
8638
8464
  const [askInFlight, setAskInFlight] = useState(0);
8639
8465
  const lastReplaceNonceRef = useRef(null);
@@ -9003,7 +8829,6 @@ function ExcalidrawCanvas({
9003
8829
  const active = Boolean(onAskRef.current) && unsysCanvasPromptMode(appState?.selectedElementIds ?? {}) === "commands";
9004
8830
  if (selectionWasActiveRef.current && !active) {
9005
8831
  setCommandText("");
9006
- setSlashBarOpen(false);
9007
8832
  }
9008
8833
  selectionWasActiveRef.current = active;
9009
8834
  setCanvasSelectionActive((prev) => prev === active ? prev : active);
@@ -9086,40 +8911,10 @@ function ExcalidrawCanvas({
9086
8911
  emitCanvasEventsRef.current(canvasEventCollectorRef.current.laser(payload));
9087
8912
  }
9088
8913
  });
9089
- const openCommandPickerAt = useCallback(
9090
- (pointer) => {
9091
- const host = canvasHostRef.current;
9092
- const viewport = {
9093
- width: host?.clientWidth ?? 320,
9094
- height: host?.clientHeight ?? 240
9095
- };
9096
- const selected = selectedCanvasElements();
9097
- const selection = unsysCanvasSelectionHostRect(
9098
- selected,
9099
- excalidrawAPIRef.current?.getAppState?.() ?? {}
9100
- );
9101
- setPickerPos(
9102
- placeUnsysCanvasCommandPicker({
9103
- selection,
9104
- pointer: pointer ?? lastPointerHostRef.current,
9105
- viewport
9106
- })
9107
- );
9108
- pickerSelectedRef.current = selected;
9109
- setCommandText("");
9110
- setSlashBarOpen(true);
9111
- },
9112
- [selectedCanvasElements]
9113
- );
9114
8914
  useEffect(() => {
9115
8915
  const onKey = (event) => {
9116
8916
  const target = event.target;
9117
8917
  const typingInField = target?.tagName === "INPUT" || target?.tagName === "TEXTAREA" || Boolean(target?.isContentEditable);
9118
- if (slashBarOpen && event.key === "Escape" && !typingInField) {
9119
- event.preventDefault();
9120
- setSlashBarOpen(false);
9121
- return;
9122
- }
9123
8918
  if (typingInField) return;
9124
8919
  const letter = unsysCanvasCommandShortcutKeyFromEvent(event);
9125
8920
  const key = String(event.key || "").toLowerCase();
@@ -9128,7 +8923,7 @@ function ExcalidrawCanvas({
9128
8923
  const kind = event.shiftKey ? "redo" : "undo";
9129
8924
  emitCanvasEventsRef.current(canvasEventCollectorRef.current.history(kind, { key }));
9130
8925
  }
9131
- if (letter && !slashBarOpen) {
8926
+ if (letter) {
9132
8927
  const command = unsysCanvasCommandByShortcut(letter, markModeRef.current, extraCommands);
9133
8928
  if (command) {
9134
8929
  event.preventDefault();
@@ -9136,34 +8931,35 @@ function ExcalidrawCanvas({
9136
8931
  return;
9137
8932
  }
9138
8933
  }
9139
- if (!unsysCanvasSlashKeyOpensBar({
9140
- key: event.key,
9141
- selectionActive: canvasSelectionActive,
9142
- typingInField
9143
- })) {
9144
- return;
9145
- }
9146
- event.preventDefault();
9147
- openCommandPickerAt(lastPointerHostRef.current);
9148
8934
  };
9149
8935
  window.addEventListener("keydown", onKey);
9150
8936
  return () => window.removeEventListener("keydown", onKey);
9151
- }, [
9152
- canvasSelectionActive,
9153
- extraCommands,
9154
- handleQuickActionRef,
9155
- openCommandPickerAt,
9156
- slashBarOpen
9157
- ]);
8937
+ }, [extraCommands, handleQuickActionRef]);
8938
+ const viewModeEnabledRef = useRef(viewModeEnabled);
8939
+ viewModeEnabledRef.current = viewModeEnabled;
8940
+ const extraCommandsForMenuRef = useRef(extraCommands);
8941
+ extraCommandsForMenuRef.current = extraCommands;
9158
8942
  useEffect(() => {
9159
- if (!unsysCanvasSlashBarOpen({
9160
- selectionActive: canvasSelectionActive,
9161
- slashIntent: slashBarOpen
9162
- })) {
9163
- return;
9164
- }
9165
- commandInputRef.current?.focus();
9166
- }, [canvasSelectionActive, slashBarOpen]);
8943
+ const host = canvasHostRef.current;
8944
+ if (!host || !isLoaded) return;
8945
+ return installUnsysCanvasContextMenu({
8946
+ host,
8947
+ getEntries: () => unsysCanvasContextMenuEntries(extraCommandsForMenuRef.current),
8948
+ canRun: () => {
8949
+ if (!onAskRef.current || viewModeEnabledRef.current) return false;
8950
+ const selected = selectedCanvasElements();
8951
+ contextMenuSelectedRef.current = selected;
8952
+ return selected.length > 0;
8953
+ },
8954
+ onRun: (id) => {
8955
+ const selected = contextMenuSelectedRef.current;
8956
+ handleQuickActionRef.current(id, selected.length ? selected : void 0);
8957
+ },
8958
+ closeMenu: () => {
8959
+ excalidrawAPIRef.current?.updateScene({ appState: { contextMenu: null } });
8960
+ }
8961
+ });
8962
+ }, [handleQuickActionRef, isLoaded, selectedCanvasElements]);
9167
8963
  useEffect(() => {
9168
8964
  if (applyElementsNonce == null || applyElementsNonce === lastApplyNonceRef.current) return;
9169
8965
  pendingApplyRef.current = {
@@ -9481,22 +9277,6 @@ function ExcalidrawCanvas({
9481
9277
  className: "relative min-h-0 flex-1",
9482
9278
  "data-unsys-canvas-host": true,
9483
9279
  style: { backgroundColor: sidebarStyle.canvas.background },
9484
- onMouseMove: (event) => {
9485
- const rect = event.currentTarget.getBoundingClientRect();
9486
- lastPointerHostRef.current = {
9487
- x: event.clientX - rect.left,
9488
- y: event.clientY - rect.top
9489
- };
9490
- },
9491
- onContextMenu: (event) => {
9492
- if (!canvasSelectionActive) return;
9493
- event.preventDefault();
9494
- const rect = event.currentTarget.getBoundingClientRect();
9495
- openCommandPickerAt({
9496
- x: event.clientX - rect.left,
9497
- y: event.clientY - rect.top
9498
- });
9499
- },
9500
9280
  children: [
9501
9281
  isLoaded && /* @__PURE__ */ jsx(UnsysExcalidrawErrorBoundary, { children: /* @__PURE__ */ jsx(
9502
9282
  UnsysExcalidrawMount,
@@ -9564,7 +9344,6 @@ function ExcalidrawCanvas({
9564
9344
  askInFlight,
9565
9345
  canvasSelectionActive,
9566
9346
  submitCommand,
9567
- slashBarOpen,
9568
9347
  commandText,
9569
9348
  setCommandText,
9570
9349
  handleQuickAction,
@@ -9582,61 +9361,7 @@ function ExcalidrawCanvas({
9582
9361
  selectedMarkTexts: selectedCanvasElements().map((element) => element.text || "").filter((text) => text.trim()),
9583
9362
  markSpeech: dictateTranscript || ""
9584
9363
  }
9585
- ),
9586
- (() => {
9587
- const selected = selectedCanvasElements();
9588
- const hostRect = unsysCanvasSelectionHostRect(
9589
- selected,
9590
- excalidrawAPIRef.current?.getAppState?.() ?? {}
9591
- );
9592
- const hostViewport = {
9593
- width: canvasHostRef.current?.clientWidth ?? 320,
9594
- height: canvasHostRef.current?.clientHeight ?? 240
9595
- };
9596
- const affordancePos = hostRect ? placeUnsysCanvasCommandPickerAffordance({
9597
- selection: hostRect,
9598
- viewport: hostViewport
9599
- }) : null;
9600
- const pickerOpen = unsysCanvasSlashBarOpen({
9601
- selectionActive: canvasSelectionActive,
9602
- slashIntent: slashBarOpen
9603
- });
9604
- return /* @__PURE__ */ jsxs(Fragment, { children: [
9605
- /* @__PURE__ */ jsx(
9606
- UnsysCanvasCommandPickerAffordance,
9607
- {
9608
- visible: canvasSelectionActive && !pickerOpen && Boolean(affordancePos),
9609
- left: affordancePos?.left ?? 0,
9610
- top: affordancePos?.top ?? 0,
9611
- onOpen: () => openCommandPickerAt()
9612
- }
9613
- ),
9614
- /* @__PURE__ */ jsx(
9615
- UnsysCanvasCommandPicker,
9616
- {
9617
- open: pickerOpen,
9618
- left: pickerPos.left,
9619
- top: pickerPos.top,
9620
- query: commandText,
9621
- extras: extraCommands,
9622
- onQueryChange: setCommandText,
9623
- onClose: () => {
9624
- setSlashBarOpen(false);
9625
- setCommandText("");
9626
- },
9627
- onRun: (id) => {
9628
- const selectedForRun = pickerSelectedRef.current;
9629
- setSlashBarOpen(false);
9630
- setCommandText("");
9631
- handleQuickActionRef.current(
9632
- id,
9633
- selectedForRun.length ? selectedForRun : void 0
9634
- );
9635
- }
9636
- }
9637
- )
9638
- ] });
9639
- })()
9364
+ )
9640
9365
  ]
9641
9366
  }
9642
9367
  )
@@ -9657,6 +9382,53 @@ function ExtraCommandsProvider({
9657
9382
  function useExtraCommands() {
9658
9383
  return useContext(ExtraCommandsContext);
9659
9384
  }
9385
+ var UNSYS_CANVAS_COMMAND_RAIL_CLASS = "pointer-events-auto relative flex min-h-9 w-full min-w-0 flex-row items-center justify-start gap-1.5 whitespace-nowrap rounded-none border border-white/45 bg-black px-1.5 py-2 text-left font-mono text-[11px] leading-tight text-white shadow-[inset_0_1px_0_rgba(255,255,255,0.35)] hover:border-white hover:bg-neutral-950 disabled:cursor-not-allowed disabled:border-neutral-800 disabled:bg-neutral-950 disabled:text-neutral-600 disabled:opacity-100 disabled:shadow-none disabled:hover:border-neutral-800 disabled:hover:bg-neutral-950 disabled:hover:text-neutral-600";
9386
+ var UNSYS_CANVAS_COMMAND_SIDEBAR_CLASS = "pointer-events-auto relative flex min-h-9 w-full min-w-0 flex-row items-center justify-start gap-1.5 overflow-hidden whitespace-nowrap rounded-none border border-white/35 bg-black px-1.5 py-1.5 text-left font-mono text-[11px] leading-tight text-white shadow-[inset_0_1px_0_rgba(255,255,255,0.2)] hover:border-white hover:bg-neutral-950 disabled:cursor-not-allowed disabled:border-neutral-800 disabled:bg-neutral-950 disabled:text-neutral-600 disabled:opacity-100 disabled:shadow-none disabled:hover:border-neutral-800 disabled:hover:bg-neutral-950 disabled:hover:text-neutral-600";
9387
+ var UNSYS_CANVAS_COMMAND_SIDEBAR_MARK_CLASS = "h-3.5 w-3.5 shrink-0";
9388
+ var UNSYS_CANVAS_COMMAND_STRIPE_CLASS = "pointer-events-auto relative flex h-10 w-10 shrink-0 items-center justify-center rounded-none border border-white/35 bg-black text-white shadow-[inset_0_1px_0_rgba(255,255,255,0.2)] hover:border-white hover:bg-neutral-950 disabled:cursor-not-allowed disabled:border-neutral-800 disabled:bg-neutral-950 disabled:text-neutral-600 disabled:opacity-100 disabled:shadow-none disabled:hover:border-neutral-800 disabled:hover:bg-neutral-950 disabled:hover:text-neutral-600";
9389
+ var UNSYS_CANVAS_COMMAND_STRIPE_MARK_CLASS = "h-4 w-4 shrink-0";
9390
+ var ICON_PATHS = {
9391
+ focus: "M8 2v2.5M8 11.5V14M2 8h2.5M11.5 8H14M8 5.5a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5z",
9392
+ next: "M2 8h9M8 4.5l4.5 3.5L8 11.5M13.5 3.5v9",
9393
+ simplify: "M3 4h10M3 8h7M3 12h4",
9394
+ breakdown: "M2 6.5h4v3H2zM10 2.5h4v3h-4zM10 10.5h4v3h-4zM6 8h4M10 8V4M10 8v6.5",
9395
+ concepts: "M2 2.5h4v3H2zM10 2.5h4v3h-4zM6 10.5h4v3H6zM4 5.5v5M12 5.5v5M8 8.5v2",
9396
+ define: "M3 2.5h10v11H3zM5.5 5.5h5M5.5 8h7M5.5 10.5h4",
9397
+ answer: "M3 3h10v7H8l-3 3v-3H3z",
9398
+ draw: "M10.5 2.5l3 3-8 8H2.5v-3zM9 4l3 3",
9399
+ refactor: "M4 3h5v2H6.5A4.5 4.5 0 1 1 3 10M12 13H7v-2h2.5A4.5 4.5 0 1 1 13 6",
9400
+ pretty: "M2.5 2.5h11v11H2.5zM5 6h6M5 8.5h6M5 11h4",
9401
+ picker: "M3 4.5h10M3 8h7M3 11.5h4",
9402
+ dictate: "M8 2.5a2 2 0 0 1 2 2V8a2 2 0 1 1-4 0V4.5a2 2 0 0 1 2-2zM5 8.5a3 3 0 0 0 6 0M8 11.5V14",
9403
+ pointer: "M4.2 8.2a3.6 3.6 0 1 1 3.6-3.6l5.8 5.8a2.2 2.2 0 0 1-3.1 3.1zM9.4 9.4l2.1 2.1M7 7.2l1.3 1.3M4.8 4.8l1.8 1.8",
9404
+ commit: "M3 8h10M10 5l3 3-3 3",
9405
+ "rail-expand": "M6 3l5 5-5 5",
9406
+ "rail-collapse": "M10 3L5 8l5 5",
9407
+ boards: "M2.5 3.5h4.5v4.5H2.5zM9 3.5h4.5v4.5H9zM2.5 10h4.5v3H2.5zM9 10h4.5v3H9z",
9408
+ save: "M3 8.5V13h10V8.5M8 2.5v8M5 8l3 3 3-3"
9409
+ };
9410
+ function CommandMark({
9411
+ id,
9412
+ className = "h-3.5 w-3.5"
9413
+ }) {
9414
+ const d = ICON_PATHS[id] ?? ICON_PATHS.simplify;
9415
+ return /* @__PURE__ */ jsx(
9416
+ "svg",
9417
+ {
9418
+ viewBox: "0 0 16 16",
9419
+ className,
9420
+ fill: "none",
9421
+ stroke: "currentColor",
9422
+ strokeWidth: 1.4,
9423
+ strokeLinecap: "round",
9424
+ strokeLinejoin: "round",
9425
+ "aria-hidden": true,
9426
+ "data-unsys-canvas-command-mark": id,
9427
+ "data-command-icon": id,
9428
+ children: /* @__PURE__ */ jsx("path", { d })
9429
+ }
9430
+ );
9431
+ }
9660
9432
  function dictateButtonClass(kind, square, wide, plate, iconOnly) {
9661
9433
  const pressed = kind === "idle" ? " aria-pressed:bg-white aria-pressed:text-neutral-950" : "";
9662
9434
  if (iconOnly) return `${UNSYS_CANVAS_COMMAND_STRIPE_CLASS}${pressed}`;
@@ -9912,16 +9684,16 @@ function CanvasCommandCheatsheet({
9912
9684
  /* @__PURE__ */ jsxs(
9913
9685
  "li",
9914
9686
  {
9915
- "data-unsys-canvas-command-cheatsheet-row": "picker",
9687
+ "data-unsys-canvas-command-cheatsheet-row": "context-menu",
9916
9688
  className: "flex items-start gap-2 border border-white/20 px-2 py-2",
9917
9689
  children: [
9918
- /* @__PURE__ */ jsx(CommandMark, { id: "picker", label: UNSYS_CANVAS_COMMAND_PICKER_LABEL, className: "mt-0.5 h-4 w-4 shrink-0" }),
9690
+ /* @__PURE__ */ jsx(CommandMark, { id: "picker", label: UNSYS_CANVAS_CONTEXT_MENU_ROW_LABEL, className: "mt-0.5 h-4 w-4 shrink-0" }),
9919
9691
  /* @__PURE__ */ jsxs("div", { className: "min-w-0 flex-1", children: [
9920
9692
  /* @__PURE__ */ jsxs("div", { className: "flex items-baseline justify-between gap-2", children: [
9921
- /* @__PURE__ */ jsx("span", { className: "font-mono text-[12px] font-semibold", children: UNSYS_CANVAS_COMMAND_PICKER_LABEL }),
9922
- /* @__PURE__ */ jsx("span", { className: "flex shrink-0 items-baseline gap-1.5 font-mono text-[10px] text-white/55", children: /* @__PURE__ */ jsx("kbd", { "data-shortcut-apple": UNSYS_CANVAS_COMMAND_PICKER_SHORTCUT, children: UNSYS_CANVAS_COMMAND_PICKER_SHORTCUT }) })
9693
+ /* @__PURE__ */ jsx("span", { className: "font-mono text-[12px] font-semibold", children: UNSYS_CANVAS_CONTEXT_MENU_ROW_LABEL }),
9694
+ /* @__PURE__ */ jsx("span", { className: "flex shrink-0 items-baseline gap-1.5 font-mono text-[10px] text-white/55", children: /* @__PURE__ */ jsx("kbd", { children: UNSYS_CANVAS_CONTEXT_MENU_ROW_HINT }) })
9923
9695
  ] }),
9924
- /* @__PURE__ */ jsx("p", { className: "mt-1 font-mono text-[11px] leading-snug text-white/70", children: UNSYS_CANVAS_COMMAND_PICKER_TOOLTIP })
9696
+ /* @__PURE__ */ jsx("p", { className: "mt-1 font-mono text-[11px] leading-snug text-white/70", children: UNSYS_CANVAS_CONTEXT_MENU_ROW_TOOLTIP })
9925
9697
  ] })
9926
9698
  ]
9927
9699
  }
@@ -9981,7 +9753,7 @@ function CanvasCommandCheatsheet({
9981
9753
  }
9982
9754
 
9983
9755
  // src/lib/session-instructions.ts
9984
- var CANVAS_HELP = "Write and draw on the board. Select marks, then run a command. / opens the command picker. Dictate places a Work note from speech. The pointer laser can Simplify, Concepts, Subdivide, Do/run, Refactor, or Pretty.";
9756
+ var CANVAS_HELP = "Write and draw on the board. Select marks, then run a command from the right-click menu. Dictate places a Work note from speech. The pointer laser can Simplify, Concepts, Subdivide, Do/run, Refactor, or Pretty.";
9985
9757
  var SESSION_INSTRUCTIONS = {
9986
9758
  board: CANVAS_HELP
9987
9759
  };