@vvedantb/ui 0.84.0 → 0.85.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.
@@ -4,8 +4,10 @@ import { flushSync } from "react-dom";
4
4
  import { dockPopIn, dockPopOut } from "../../src/motion/dock-motion.js";
5
5
  const OPEN_DELAY_MS = 120;
6
6
  const CLOSE_DELAY_MS = 350;
7
+ const MENU_CLOSE_DELAY_MS = 2000;
7
8
  const OPEN_MENU_TRIGGER = '[aria-haspopup][aria-expanded="true"]';
8
9
  const PANEL_SELECTOR = "[data-sidebar-panel]";
10
+ const PORTAL_MENU = '[role="menu"]';
9
11
  function peekTile(target) {
10
12
  if (!(target instanceof Element)) return null;
11
13
  const tile = target.closest("[data-rail-peek]");
@@ -14,153 +16,326 @@ function peekTile(target) {
14
16
  function inPanel(target) {
15
17
  return target instanceof Element && target.closest(PANEL_SELECTOR) !== null;
16
18
  }
19
+ function inPortal(aside, target) {
20
+ return target instanceof Node && !aside.contains(target);
21
+ }
22
+ function inPortalMenu(aside, target) {
23
+ return target instanceof Element && target.closest(PORTAL_MENU) !== null && !aside.contains(target);
24
+ }
25
+ function openPortalMenu(aside) {
26
+ return Array.from(document.querySelectorAll(PORTAL_MENU)).some(menu => !aside.contains(menu) && menu.getAttribute("data-state") !== "closed");
27
+ }
17
28
  /**
18
29
  * Hover and focus state of an unpinned sidebar. The panel opens as an overlay
19
30
  * when the pointer or focus is on a rail item that has `data-rail-peek` (rail
20
31
  * links and tabs have it), and stays open while the pointer or focus is on a
21
32
  * rail item or in the panel. It grows out of the hovered item with
22
33
  * `dockPopIn` and shrinks back with `dockPopOut`. It stays open while a menu
23
- * opened from the sidebar is open. `Sidebar.Root` makes one when none is
34
+ * opened from the sidebar is open, a right-click menu included, and closes
35
+ * `menuCloseDelay` after that menu closes with the pointer outside. A rail item
36
+ * whose page has no panel closes it, like empty rail. `Sidebar.Root` makes one when none is
24
37
  * passed; pass your own to read `previewPath` or `previewValue` and show the
25
38
  * hovered item's panel without navigating.
26
39
  */
27
- export function useSidebarPeek() {
28
- const $ = _c(12);
40
+ export function useSidebarPeek(t0) {
41
+ const $ = _c(31);
42
+ let t1;
43
+ if ($[0] !== t0) {
44
+ t1 = t0 === undefined ? {} : t0;
45
+ $[0] = t0;
46
+ $[1] = t1;
47
+ } else {
48
+ t1 = $[1];
49
+ }
50
+ const {
51
+ menuCloseDelay: t2
52
+ } = t1;
53
+ const menuCloseDelay = t2 === undefined ? MENU_CLOSE_DELAY_MS : t2;
29
54
  const [peeking, setPeeking] = useState(false);
30
55
  const [tile, setTile] = useState(null);
31
56
  const timer = useRef(undefined);
32
57
  const open = useRef(false);
33
58
  const tileRef = useRef(null);
34
- let t0;
35
- if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
36
- t0 = () => window.clearTimeout(timer.current);
37
- $[0] = t0;
59
+ const noPanelTile = useRef(null);
60
+ const contextMenu = useRef(false);
61
+ const stopWatch = useRef(null);
62
+ let t3;
63
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
64
+ t3 = () => window.clearTimeout(timer.current);
65
+ $[2] = t3;
38
66
  } else {
39
- t0 = $[0];
67
+ t3 = $[2];
40
68
  }
41
- const cancelPending = t0;
42
- let t1;
43
- if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
44
- t1 = () => {
69
+ const cancelPending = t3;
70
+ let t4;
71
+ if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
72
+ t4 = () => {
73
+ stopWatch.current?.();
74
+ stopWatch.current = null;
75
+ contextMenu.current = false;
76
+ };
77
+ $[3] = t4;
78
+ } else {
79
+ t4 = $[3];
80
+ }
81
+ const endMenuWatch = t4;
82
+ let t5;
83
+ if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
84
+ t5 = () => {
45
85
  cancelPending();
86
+ endMenuWatch();
46
87
  open.current = false;
47
88
  setPeeking(false);
48
89
  setTile(null);
49
90
  };
50
- $[1] = t1;
91
+ $[4] = t5;
51
92
  } else {
52
- t1 = $[1];
93
+ t5 = $[4];
53
94
  }
54
- const reset = t1;
55
- let t2;
56
- if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
57
- t2 = () => {
95
+ const reset = t5;
96
+ let t6;
97
+ if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
98
+ t6 = () => {
58
99
  cancelPending();
59
100
  open.current = true;
60
101
  setPeeking(true);
61
102
  };
62
- $[2] = t2;
103
+ $[5] = t6;
63
104
  } else {
64
- t2 = $[2];
105
+ t6 = $[5];
65
106
  }
66
- const hold = t2;
67
- let t3;
68
- if ($[3] === Symbol.for("react.memo_cache_sentinel")) {
69
- t3 = (aside, delayMs) => {
107
+ const hold = t6;
108
+ let t7;
109
+ if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
110
+ t7 = aside => aside.querySelector(OPEN_MENU_TRIGGER) !== null || contextMenu.current && openPortalMenu(aside);
111
+ $[6] = t7;
112
+ } else {
113
+ t7 = $[6];
114
+ }
115
+ const menuHeld = t7;
116
+ let t8;
117
+ if ($[7] === Symbol.for("react.memo_cache_sentinel")) {
118
+ t8 = () => {
119
+ noPanelTile.current = tileRef.current;
120
+ reset();
121
+ };
122
+ $[7] = t8;
123
+ } else {
124
+ t8 = $[7];
125
+ }
126
+ const closeWithoutPanel = t8;
127
+ let scheduleClose;
128
+ let watchMenu;
129
+ if ($[8] !== menuCloseDelay) {
130
+ scheduleClose = (aside_0, t9) => {
131
+ const delayMs = t9 === undefined ? CLOSE_DELAY_MS : t9;
70
132
  cancelPending();
71
- if (open.current) {
133
+ if (!open.current) {
72
134
  return;
73
135
  }
74
136
  timer.current = window.setTimeout(() => {
75
- open.current = true;
76
- flushSync(() => setPeeking(true));
77
- const panel = aside.querySelector(PANEL_SELECTOR);
78
- if (panel && !panel.hasAttribute("data-sidebar-floating")) {
79
- dockPopIn(panel, tileRef.current, "left");
137
+ if (menuHeld(aside_0)) {
138
+ watchMenu(aside_0, true);
139
+ return;
80
140
  }
141
+ const panel = aside_0.querySelector(PANEL_SELECTOR);
142
+ if (!panel) {
143
+ reset();
144
+ return;
145
+ }
146
+ const card = panel.querySelector("[data-sidebar-card]") ?? panel;
147
+ const arrow = panel.querySelector("[data-dock-arrow]");
148
+ dockPopOut(card, tileRef.current, "left", reset, arrow);
81
149
  }, delayMs);
82
150
  };
83
- $[3] = t3;
151
+ watchMenu = (aside_1, alreadyOpen) => {
152
+ if (stopWatch.current) {
153
+ return;
154
+ }
155
+ let seenOpen = alreadyOpen;
156
+ let pointerInside = aside_1.matches(":hover");
157
+ const enter = () => {
158
+ pointerInside = true;
159
+ };
160
+ const leave = () => {
161
+ pointerInside = false;
162
+ };
163
+ const observer = new MutationObserver(() => {
164
+ if (!aside_1.isConnected) {
165
+ return endMenuWatch();
166
+ }
167
+ if (menuHeld(aside_1)) {
168
+ seenOpen = true;
169
+ return;
170
+ }
171
+ if (!seenOpen) {
172
+ return;
173
+ }
174
+ endMenuWatch();
175
+ if (!pointerInside) {
176
+ scheduleClose(aside_1, menuCloseDelay);
177
+ }
178
+ });
179
+ observer.observe(document.body, {
180
+ childList: true,
181
+ subtree: true,
182
+ attributes: true,
183
+ attributeFilter: ["aria-expanded", "data-state"]
184
+ });
185
+ aside_1.addEventListener("pointerenter", enter);
186
+ aside_1.addEventListener("pointerleave", leave);
187
+ stopWatch.current = () => {
188
+ observer.disconnect();
189
+ aside_1.removeEventListener("pointerenter", enter);
190
+ aside_1.removeEventListener("pointerleave", leave);
191
+ };
192
+ };
193
+ $[8] = menuCloseDelay;
194
+ $[9] = scheduleClose;
195
+ $[10] = watchMenu;
84
196
  } else {
85
- t3 = $[3];
197
+ scheduleClose = $[9];
198
+ watchMenu = $[10];
86
199
  }
87
- const scheduleOpen = t3;
88
- let t4;
89
- if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
90
- t4 = aside_0 => {
200
+ let t9;
201
+ if ($[11] === Symbol.for("react.memo_cache_sentinel")) {
202
+ const scheduleOpen = (aside_2, delayMs_0) => {
91
203
  cancelPending();
92
- if (!open.current) {
204
+ if (open.current) {
93
205
  return;
94
206
  }
95
207
  timer.current = window.setTimeout(() => {
96
- if (aside_0.querySelector(OPEN_MENU_TRIGGER)) {
97
- return;
208
+ open.current = true;
209
+ flushSync(() => setPeeking(true));
210
+ const panel_0 = aside_2.querySelector(PANEL_SELECTOR);
211
+ if (!panel_0) {
212
+ return closeWithoutPanel();
98
213
  }
99
- const panel_0 = aside_0.querySelector(PANEL_SELECTOR);
100
- const card = panel_0?.querySelector("[data-sidebar-card]") ?? panel_0;
101
- const arrow = panel_0?.querySelector("[data-dock-arrow]");
102
- dockPopOut(card, tileRef.current, "left", reset, arrow);
103
- }, CLOSE_DELAY_MS);
214
+ if (!panel_0.hasAttribute("data-sidebar-floating")) {
215
+ dockPopIn(panel_0, tileRef.current, "left");
216
+ }
217
+ }, delayMs_0);
104
218
  };
105
- $[4] = t4;
106
- } else {
107
- t4 = $[4];
108
- }
109
- const scheduleClose = t4;
110
- let t5;
111
- if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
112
- t5 = (aside_1, next, delayMs_0) => {
219
+ t9 = (aside_3, next, delayMs_1) => {
220
+ if (next === noPanelTile.current && !open.current) {
221
+ return;
222
+ }
223
+ noPanelTile.current = null;
224
+ const changed = next !== tileRef.current;
113
225
  tileRef.current = next;
226
+ if (open.current && changed) {
227
+ cancelPending();
228
+ flushSync(() => setTile(next));
229
+ if (!aside_3.querySelector(PANEL_SELECTOR)) {
230
+ closeWithoutPanel();
231
+ }
232
+ return;
233
+ }
114
234
  setTile(next);
115
- scheduleOpen(aside_1, delayMs_0);
235
+ scheduleOpen(aside_3, delayMs_1);
116
236
  };
117
- $[5] = t5;
237
+ $[11] = t9;
118
238
  } else {
119
- t5 = $[5];
239
+ t9 = $[11];
120
240
  }
121
- const onTile = t5;
122
- let t6;
123
- if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
124
- t6 = {
125
- onPointerOver: event => {
126
- const next_0 = peekTile(event.target);
127
- if (next_0) {
128
- onTile(event.currentTarget, next_0, OPEN_DELAY_MS);
129
- } else {
130
- if (inPanel(event.target)) {
131
- cancelPending();
132
- } else {
133
- scheduleClose(event.currentTarget);
134
- }
135
- }
136
- },
137
- onPointerLeave: event_0 => scheduleClose(event_0.currentTarget),
138
- onFocus: event_1 => {
139
- const next_1 = peekTile(event_1.target);
140
- if (next_1) {
141
- onTile(event_1.currentTarget, next_1, 0);
142
- } else {
143
- if (inPanel(event_1.target)) {
144
- cancelPending();
145
- }
146
- }
147
- },
148
- onBlur: event_2 => {
149
- if (peekTile(event_2.relatedTarget) === null && !inPanel(event_2.relatedTarget)) {
150
- scheduleClose(event_2.currentTarget);
241
+ const onTile = t9;
242
+ let t10;
243
+ let t11;
244
+ if ($[12] !== scheduleClose) {
245
+ t10 = event => {
246
+ const aside_4 = event.currentTarget;
247
+ const next_0 = peekTile(event.target);
248
+ if (next_0) {
249
+ return onTile(aside_4, next_0, OPEN_DELAY_MS);
250
+ }
251
+ noPanelTile.current = null;
252
+ if (inPanel(event.target) || inPortal(aside_4, event.target)) {
253
+ cancelPending();
254
+ } else {
255
+ scheduleClose(aside_4);
256
+ }
257
+ };
258
+ t11 = event_0 => {
259
+ noPanelTile.current = null;
260
+ scheduleClose(event_0.currentTarget);
261
+ };
262
+ $[12] = scheduleClose;
263
+ $[13] = t10;
264
+ $[14] = t11;
265
+ } else {
266
+ t10 = $[13];
267
+ t11 = $[14];
268
+ }
269
+ let t12;
270
+ if ($[15] === Symbol.for("react.memo_cache_sentinel")) {
271
+ t12 = event_1 => {
272
+ const aside_5 = event_1.currentTarget;
273
+ const next_1 = peekTile(event_1.target);
274
+ if (next_1) {
275
+ onTile(aside_5, next_1, 0);
276
+ } else {
277
+ if (inPanel(event_1.target) || inPortal(aside_5, event_1.target)) {
278
+ cancelPending();
151
279
  }
152
280
  }
153
281
  };
154
- $[6] = t6;
282
+ $[15] = t12;
283
+ } else {
284
+ t12 = $[15];
285
+ }
286
+ let t13;
287
+ if ($[16] !== scheduleClose) {
288
+ t13 = event_2 => {
289
+ const aside_6 = event_2.currentTarget;
290
+ const to = event_2.relatedTarget;
291
+ if (peekTile(to) !== null || inPanel(to) || inPortalMenu(aside_6, to)) {
292
+ return;
293
+ }
294
+ scheduleClose(aside_6);
295
+ };
296
+ $[16] = scheduleClose;
297
+ $[17] = t13;
155
298
  } else {
156
- t6 = $[6];
299
+ t13 = $[17];
157
300
  }
158
- const handlers = t6;
301
+ let t14;
302
+ if ($[18] !== watchMenu) {
303
+ t14 = event_3 => {
304
+ if (!open.current) {
305
+ return;
306
+ }
307
+ cancelPending();
308
+ contextMenu.current = true;
309
+ watchMenu(event_3.currentTarget, false);
310
+ };
311
+ $[18] = watchMenu;
312
+ $[19] = t14;
313
+ } else {
314
+ t14 = $[19];
315
+ }
316
+ let t15;
317
+ if ($[20] !== t10 || $[21] !== t11 || $[22] !== t13 || $[23] !== t14) {
318
+ t15 = {
319
+ onPointerOver: t10,
320
+ onPointerLeave: t11,
321
+ onFocus: t12,
322
+ onBlur: t13,
323
+ onContextMenu: t14
324
+ };
325
+ $[20] = t10;
326
+ $[21] = t11;
327
+ $[22] = t13;
328
+ $[23] = t14;
329
+ $[24] = t15;
330
+ } else {
331
+ t15 = $[24];
332
+ }
333
+ const handlers = t15;
159
334
  const previewPath = peeking && tile instanceof HTMLAnchorElement ? tile.pathname : null;
160
335
  const previewValue = peeking && tile ? tile.dataset.railPeek || null : null;
161
- let t7;
162
- if ($[7] !== peeking || $[8] !== previewPath || $[9] !== previewValue || $[10] !== tile) {
163
- t7 = {
336
+ let t16;
337
+ if ($[25] !== handlers || $[26] !== peeking || $[27] !== previewPath || $[28] !== previewValue || $[29] !== tile) {
338
+ t16 = {
164
339
  peeking,
165
340
  previewPath,
166
341
  previewValue,
@@ -169,13 +344,14 @@ export function useSidebarPeek() {
169
344
  reset,
170
345
  hold
171
346
  };
172
- $[7] = peeking;
173
- $[8] = previewPath;
174
- $[9] = previewValue;
175
- $[10] = tile;
176
- $[11] = t7;
347
+ $[25] = handlers;
348
+ $[26] = peeking;
349
+ $[27] = previewPath;
350
+ $[28] = previewValue;
351
+ $[29] = tile;
352
+ $[30] = t16;
177
353
  } else {
178
- t7 = $[11];
354
+ t16 = $[30];
179
355
  }
180
- return t7;
356
+ return t16;
181
357
  }
@@ -1,8 +1,6 @@
1
1
  import { c as _c } from "react/compiler-runtime";
2
2
  import { memo } from "react";
3
3
  import { cjk } from "@streamdown/cjk";
4
- import { code } from "@streamdown/code";
5
- import { math } from "@streamdown/math";
6
4
  import { Streamdown, defaultRehypePlugins, defaultRemarkPlugins } from "streamdown";
7
5
  import { useCn } from "../ui/ui-config.js";
8
6
  import { parseMarkdownIntoBlocksIncremental } from "./incrementalBlocks.js";
@@ -10,18 +8,25 @@ import { MarkdownBlockquote } from "./MarkdownBlockquote.js";
10
8
  import { MarkdownPre } from "./MarkdownCodeBlock.js";
11
9
  import { MarkdownInlineCode } from "./MarkdownInlineCode.js";
12
10
  import { MarkdownLink } from "./MarkdownLink.js";
11
+ import { useMathPlugin } from "./lazyMath.js";
13
12
  import { mermaidPlugin } from "./mermaid.js";
14
13
  import { copyMarkdownSelection } from "./markdownClipboard.js";
15
14
  import { rehypeGithubAlerts } from "./rehypeGithubAlerts.js";
16
- import "katex/dist/katex.min.css";
17
15
  import { useSmoothText } from "./useSmoothText.js";
18
16
  import { jsx as _jsx } from "react/jsx-runtime";
19
17
  const PLUGINS = {
20
18
  cjk,
21
- code,
22
- math,
23
19
  mermaid: mermaidPlugin
24
20
  };
21
+ let pluginsWithMath = null;
22
+ function pluginsFor(math) {
23
+ if (math === null) return PLUGINS;
24
+ pluginsWithMath ??= {
25
+ ...PLUGINS,
26
+ math
27
+ };
28
+ return pluginsWithMath;
29
+ }
25
30
  const REMARK_PLUGINS = Object.values(defaultRemarkPlugins);
26
31
  const REHYPE_PLUGINS = [...Object.values(defaultRehypePlugins), rehypeGithubAlerts];
27
32
  const MARKDOWN_COMPONENTS = {
@@ -55,7 +60,7 @@ const MARKDOWN_COMPONENTS = {
55
60
  * (mention chips, line breaks).
56
61
  */
57
62
  export const Markdown = /*#__PURE__*/memo(function Markdown(t0) {
58
- const $ = _c(20);
63
+ const $ = _c(23);
59
64
  let children;
60
65
  let className;
61
66
  let components;
@@ -89,6 +94,7 @@ export const Markdown = /*#__PURE__*/memo(function Markdown(t0) {
89
94
  const smooth = t1 === undefined ? true : t1;
90
95
  const merge = useCn();
91
96
  const text = useSmoothText(children, smooth && props.mode === "streaming");
97
+ const math = useMathPlugin(text);
92
98
  let t2;
93
99
  if ($[7] !== className || $[8] !== merge) {
94
100
  t2 = merge("markdown", className);
@@ -99,48 +105,57 @@ export const Markdown = /*#__PURE__*/memo(function Markdown(t0) {
99
105
  t2 = $[9];
100
106
  }
101
107
  let t3;
102
- if ($[10] !== components) {
103
- t3 = components ? {
104
- ...MARKDOWN_COMPONENTS,
105
- ...components
106
- } : MARKDOWN_COMPONENTS;
107
- $[10] = components;
108
+ if ($[10] !== math) {
109
+ t3 = pluginsFor(math);
110
+ $[10] = math;
108
111
  $[11] = t3;
109
112
  } else {
110
113
  t3 = $[11];
111
114
  }
112
115
  let t4;
113
- if ($[12] !== remarkPlugins) {
114
- t4 = remarkPlugins ? [...REMARK_PLUGINS, ...remarkPlugins] : REMARK_PLUGINS;
115
- $[12] = remarkPlugins;
116
+ if ($[12] !== components) {
117
+ t4 = components ? {
118
+ ...MARKDOWN_COMPONENTS,
119
+ ...components
120
+ } : MARKDOWN_COMPONENTS;
121
+ $[12] = components;
116
122
  $[13] = t4;
117
123
  } else {
118
124
  t4 = $[13];
119
125
  }
120
126
  let t5;
121
- if ($[14] !== props || $[15] !== t2 || $[16] !== t3 || $[17] !== t4 || $[18] !== text) {
122
- t5 = /*#__PURE__*/_jsx("div", {
127
+ if ($[14] !== remarkPlugins) {
128
+ t5 = remarkPlugins ? [...REMARK_PLUGINS, ...remarkPlugins] : REMARK_PLUGINS;
129
+ $[14] = remarkPlugins;
130
+ $[15] = t5;
131
+ } else {
132
+ t5 = $[15];
133
+ }
134
+ let t6;
135
+ if ($[16] !== props || $[17] !== t2 || $[18] !== t3 || $[19] !== t4 || $[20] !== t5 || $[21] !== text) {
136
+ t6 = /*#__PURE__*/_jsx("div", {
123
137
  className: "contents",
124
138
  onCopy: copyMarkdownSelection,
125
139
  children: /*#__PURE__*/_jsx(Streamdown, {
126
140
  className: t2,
127
- plugins: PLUGINS,
128
- components: t3,
129
- remarkPlugins: t4,
141
+ plugins: t3,
142
+ components: t4,
143
+ remarkPlugins: t5,
130
144
  rehypePlugins: REHYPE_PLUGINS,
131
145
  parseMarkdownIntoBlocksFn: parseMarkdownIntoBlocksIncremental,
132
146
  ...props,
133
147
  children: text
134
148
  })
135
149
  });
136
- $[14] = props;
137
- $[15] = t2;
138
- $[16] = t3;
139
- $[17] = t4;
140
- $[18] = text;
141
- $[19] = t5;
150
+ $[16] = props;
151
+ $[17] = t2;
152
+ $[18] = t3;
153
+ $[19] = t4;
154
+ $[20] = t5;
155
+ $[21] = text;
156
+ $[22] = t6;
142
157
  } else {
143
- t5 = $[19];
158
+ t6 = $[22];
144
159
  }
145
- return t5;
160
+ return t6;
146
161
  });