@mcpview/components 0.13.1 → 0.14.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 (76) hide show
  1. package/README.md +110 -1
  2. package/esm/preact-components.d.ts +1 -1
  3. package/esm/preact-components.d.ts.map +1 -1
  4. package/esm/preact-controls.d.ts +12 -0
  5. package/esm/preact-controls.d.ts.map +1 -0
  6. package/esm/preact-controls.js +8 -0
  7. package/esm/src/context-row-styles.d.ts +5 -0
  8. package/esm/src/context-row-styles.d.ts.map +1 -0
  9. package/esm/src/context-row-styles.js +96 -0
  10. package/esm/src/interaction-styles.d.ts +5 -0
  11. package/esm/src/interaction-styles.d.ts.map +1 -0
  12. package/esm/src/interaction-styles.js +55 -0
  13. package/esm/src/preact/components.d.ts +24 -1
  14. package/esm/src/preact/components.d.ts.map +1 -1
  15. package/esm/src/preact/components.js +86 -39
  16. package/esm/src/preact/interaction-controls.d.ts +22 -0
  17. package/esm/src/preact/interaction-controls.d.ts.map +1 -0
  18. package/esm/src/preact/interaction-controls.js +25 -0
  19. package/esm/src/preact/interactive-child.d.ts +2 -0
  20. package/esm/src/preact/interactive-child.d.ts.map +1 -0
  21. package/esm/src/preact/interactive-child.js +16 -0
  22. package/esm/src/preact/mod.d.ts +1 -1
  23. package/esm/src/preact/mod.d.ts.map +1 -1
  24. package/esm/src/preact/semantic-element.d.ts.map +1 -1
  25. package/esm/src/preact/semantic-element.js +3 -16
  26. package/esm/src/preact/structural.d.ts.map +1 -1
  27. package/esm/src/preact/structural.js +14 -7
  28. package/esm/src/preact/visual-item-gestures.d.ts +5 -0
  29. package/esm/src/preact/visual-item-gestures.d.ts.map +1 -0
  30. package/esm/src/preact/visual-item-gestures.js +30 -0
  31. package/esm/src/theme.d.ts.map +1 -1
  32. package/esm/src/theme.js +13 -0
  33. package/esm/src/visual-item-gestures.d.ts +17 -0
  34. package/esm/src/visual-item-gestures.d.ts.map +1 -0
  35. package/esm/src/visual-item-gestures.js +393 -0
  36. package/esm/src/visual-item-props.d.ts +27 -0
  37. package/esm/src/visual-item-props.d.ts.map +1 -0
  38. package/esm/src/visual-item-props.js +19 -0
  39. package/package.json +6 -1
  40. package/script/preact-components.d.ts +1 -1
  41. package/script/preact-components.d.ts.map +1 -1
  42. package/script/preact-controls.d.ts +12 -0
  43. package/script/preact-controls.d.ts.map +1 -0
  44. package/script/preact-controls.js +20 -0
  45. package/script/src/context-row-styles.d.ts +5 -0
  46. package/script/src/context-row-styles.d.ts.map +1 -0
  47. package/script/src/context-row-styles.js +99 -0
  48. package/script/src/interaction-styles.d.ts +5 -0
  49. package/script/src/interaction-styles.d.ts.map +1 -0
  50. package/script/src/interaction-styles.js +59 -0
  51. package/script/src/preact/components.d.ts +24 -1
  52. package/script/src/preact/components.d.ts.map +1 -1
  53. package/script/src/preact/components.js +85 -38
  54. package/script/src/preact/interaction-controls.d.ts +22 -0
  55. package/script/src/preact/interaction-controls.d.ts.map +1 -0
  56. package/script/src/preact/interaction-controls.js +29 -0
  57. package/script/src/preact/interactive-child.d.ts +2 -0
  58. package/script/src/preact/interactive-child.d.ts.map +1 -0
  59. package/script/src/preact/interactive-child.js +19 -0
  60. package/script/src/preact/mod.d.ts +1 -1
  61. package/script/src/preact/mod.d.ts.map +1 -1
  62. package/script/src/preact/semantic-element.d.ts.map +1 -1
  63. package/script/src/preact/semantic-element.js +4 -17
  64. package/script/src/preact/structural.d.ts.map +1 -1
  65. package/script/src/preact/structural.js +14 -7
  66. package/script/src/preact/visual-item-gestures.d.ts +5 -0
  67. package/script/src/preact/visual-item-gestures.d.ts.map +1 -0
  68. package/script/src/preact/visual-item-gestures.js +33 -0
  69. package/script/src/theme.d.ts.map +1 -1
  70. package/script/src/theme.js +13 -0
  71. package/script/src/visual-item-gestures.d.ts +17 -0
  72. package/script/src/visual-item-gestures.d.ts.map +1 -0
  73. package/script/src/visual-item-gestures.js +396 -0
  74. package/script/src/visual-item-props.d.ts +27 -0
  75. package/script/src/visual-item-props.d.ts.map +1 -0
  76. package/script/src/visual-item-props.js +22 -0
@@ -0,0 +1,393 @@
1
+ const itemSelector = "[data-visual-item]";
2
+ const surfaceSelector = "[data-visual-selection-surface]";
3
+ const nativeControl = "button, a[href], input, select, textarea, summary, [contenteditable=true]";
4
+ const interactiveControl = `${nativeControl}, [role=button], [role=link]`;
5
+ const excluded = "[data-visual-ignore], [disabled], [aria-disabled=true]";
6
+ const ordinaryClickDelay = 500;
7
+ const holdDelay = 550;
8
+ const movementThreshold = 8;
9
+ const boundRoots = new WeakSet();
10
+ function isModified(event) {
11
+ return event.shiftKey || event.ctrlKey || event.altKey || event.metaKey;
12
+ }
13
+ function point(event) {
14
+ return { x: event.clientX, y: event.clientY };
15
+ }
16
+ function clipRect(rect, clip) {
17
+ if (clip.right <= clip.left || clip.bottom <= clip.top)
18
+ return undefined;
19
+ const left = Math.max(rect.left, clip.left);
20
+ const top = Math.max(rect.top, clip.top);
21
+ const right = Math.min(rect.right, clip.right);
22
+ const bottom = Math.min(rect.bottom, clip.bottom);
23
+ if (left > right || top > bottom || (left === right && rect.width > 0) ||
24
+ (top === bottom && rect.height > 0))
25
+ return undefined;
26
+ return new DOMRect(left, top, right - left, bottom - top);
27
+ }
28
+ function scrollport(element) {
29
+ const document = element.ownerDocument;
30
+ if (element === document.documentElement)
31
+ return undefined;
32
+ const style = document.defaultView?.getComputedStyle?.(element);
33
+ if (!style || style.display === "contents" || style.display === "inline")
34
+ return undefined;
35
+ const clips = /^(auto|scroll|hidden|clip|overlay)$/;
36
+ const clipX = clips.test(style.overflowX);
37
+ const clipY = clips.test(style.overflowY);
38
+ if (!clipX && !clipY)
39
+ return undefined;
40
+ const bounds = element.getBoundingClientRect();
41
+ let { left, top, right, bottom } = bounds;
42
+ if ("offsetWidth" in element && "offsetHeight" in element) {
43
+ const layout = element;
44
+ const scaleX = layout.offsetWidth > 0 ? bounds.width / layout.offsetWidth : 1;
45
+ const scaleY = layout.offsetHeight > 0 ? bounds.height / layout.offsetHeight : 1;
46
+ left += element.clientLeft * scaleX;
47
+ top += element.clientTop * scaleY;
48
+ right = left + element.clientWidth * scaleX;
49
+ bottom = top + element.clientHeight * scaleY;
50
+ }
51
+ return {
52
+ left: clipX ? left : -Infinity,
53
+ right: clipX ? right : Infinity,
54
+ top: clipY ? top : -Infinity,
55
+ bottom: clipY ? bottom : Infinity,
56
+ };
57
+ }
58
+ function clipToScrollports(rect, element, stopBefore, cache) {
59
+ for (let ancestor = element; ancestor && ancestor !== stopBefore && rect; ancestor = ancestor.parentElement) {
60
+ const clip = cache?.has(ancestor) ? cache.get(ancestor) : scrollport(ancestor);
61
+ cache?.set(ancestor, clip);
62
+ if (clip)
63
+ rect = clipRect(rect, clip);
64
+ }
65
+ return rect;
66
+ }
67
+ function selectionRect(start, end, surface) {
68
+ const doc = surface.ownerDocument;
69
+ const viewport = doc.defaultView?.visualViewport;
70
+ const viewportLeft = viewport?.offsetLeft ?? 0;
71
+ const viewportTop = viewport?.offsetTop ?? 0;
72
+ const rect = new DOMRect(Math.min(start.x, end.x), Math.min(start.y, end.y), Math.abs(end.x - start.x), Math.abs(end.y - start.y));
73
+ const inSurface = clipRect(rect, surface.getBoundingClientRect());
74
+ const inViewport = inSurface && clipRect(inSurface, {
75
+ left: viewportLeft,
76
+ top: viewportTop,
77
+ right: viewportLeft + (viewport?.width ?? doc.documentElement.clientWidth ?? Infinity),
78
+ bottom: viewportTop + (viewport?.height ?? doc.documentElement.clientHeight ?? Infinity),
79
+ });
80
+ return clipToScrollports(inViewport, surface);
81
+ }
82
+ function intersects(bounds, rect) {
83
+ return bounds.width > 0 && bounds.height > 0 &&
84
+ bounds.left < rect.right && bounds.right > rect.left &&
85
+ bounds.top < rect.bottom && bounds.bottom > rect.top;
86
+ }
87
+ /**
88
+ * Delegate drill and context gestures to descendants marked with `data-visual-item`.
89
+ * Mark rectangle surfaces with `data-visual-selection-surface` and use `touch-action: pan-y`
90
+ * there to allow horizontal touch selection alongside vertical scrolling.
91
+ * Mark items where a rectangle can start with `data-visual-selection-start`.
92
+ * Use native buttons or focusable equivalents and expose Shift+Space in their keyboard help.
93
+ * Returns the listener cleanup function.
94
+ */
95
+ export function bindVisualItemGestures(root, options) {
96
+ const doc = root.ownerDocument;
97
+ const listeners = new AbortController();
98
+ const capture = { capture: true, signal: listeners.signal };
99
+ const passiveCapture = { ...capture, passive: true };
100
+ boundRoots.add(root);
101
+ let press;
102
+ let pending;
103
+ let suppressClick = false;
104
+ let pointerType = "";
105
+ let overlay;
106
+ function owns(element) {
107
+ for (let node = element; node; node = node.parentElement) {
108
+ if (boundRoots.has(node))
109
+ return node === root;
110
+ }
111
+ return false;
112
+ }
113
+ function target(event) {
114
+ const node = event.target;
115
+ if (!node || !("nodeType" in node) || node.nodeType !== 1)
116
+ return null;
117
+ const element = node;
118
+ return owns(element) && !element.closest(excluded) ? element : null;
119
+ }
120
+ function itemFor(element) {
121
+ const item = element.closest(itemSelector);
122
+ const control = element.closest(interactiveControl);
123
+ if (!owns(item) || (control && control !== item && item.contains(control) &&
124
+ !control.hasAttribute("data-visual-activate")))
125
+ return null;
126
+ return item;
127
+ }
128
+ function canToggle(item) {
129
+ return options.onToggle !== undefined && !item.hasAttribute("data-visual-no-toggle");
130
+ }
131
+ function canActivate(item) {
132
+ return options.onActivate !== undefined && !item.hasAttribute("data-visual-no-activate");
133
+ }
134
+ function id(item) {
135
+ return item.getAttribute("data-visual-item") ?? "";
136
+ }
137
+ function clearPending(activate = false) {
138
+ const click = pending;
139
+ pending = undefined;
140
+ if (!click)
141
+ return;
142
+ clearTimeout(click.timer);
143
+ if (activate && owns(click.item) && id(click.item) === click.id && canActivate(click.item)) {
144
+ options.onActivate?.(click.id);
145
+ }
146
+ }
147
+ function clearPress() {
148
+ clearTimeout(press?.hold);
149
+ press = undefined;
150
+ overlay?.remove();
151
+ overlay = undefined;
152
+ }
153
+ function onPointerDown(event) {
154
+ if (!event.isPrimary || event.button !== 0 || isModified(event))
155
+ return;
156
+ const element = target(event);
157
+ if (!element)
158
+ return;
159
+ clearPress();
160
+ suppressClick = false;
161
+ pointerType = event.pointerType;
162
+ const item = itemFor(element);
163
+ const surface = element.closest(surfaceSelector);
164
+ const rectangle = options.onAdd && owns(surface) &&
165
+ !element.closest("[draggable=true]") &&
166
+ (item
167
+ ? item.hasAttribute("data-visual-selection-start")
168
+ : !element.closest(interactiveControl));
169
+ if (!item && !rectangle)
170
+ return;
171
+ const active = {
172
+ pointerId: event.pointerId,
173
+ pointerType: event.pointerType,
174
+ start: point(event),
175
+ item,
176
+ surface: rectangle ? surface : null,
177
+ drawing: false,
178
+ };
179
+ press = active;
180
+ if (item && canToggle(item)) {
181
+ const pressedId = id(item);
182
+ active.hold = setTimeout(() => {
183
+ if (press !== active || !owns(item) || id(item) !== pressedId || !canToggle(item))
184
+ return;
185
+ clearPending();
186
+ suppressClick = true;
187
+ options.onToggle?.(pressedId);
188
+ }, holdDelay);
189
+ }
190
+ }
191
+ function onPointerMove(event) {
192
+ if (!press || event.pointerId !== press.pointerId)
193
+ return;
194
+ const end = point(event);
195
+ const dx = Math.abs(end.x - press.start.x);
196
+ const dy = Math.abs(end.y - press.start.y);
197
+ if (!press.drawing && Math.max(dx, dy) < movementThreshold)
198
+ return;
199
+ clearTimeout(press.hold);
200
+ if (!press.drawing && (suppressClick || !press.surface ||
201
+ (press.pointerType === "touch" && dx <= dy))) {
202
+ suppressClick = true;
203
+ clearPress();
204
+ return;
205
+ }
206
+ event.preventDefault();
207
+ if (!press.surface)
208
+ return;
209
+ if (!press.drawing) {
210
+ press.drawing = true;
211
+ clearPending();
212
+ overlay = doc.createElement("div");
213
+ overlay.setAttribute("aria-hidden", "true");
214
+ Object.assign(overlay.style, {
215
+ position: "fixed",
216
+ pointerEvents: "none",
217
+ zIndex: "2147483647",
218
+ boxSizing: "border-box",
219
+ border: "1px solid Highlight",
220
+ background: "color-mix(in srgb, Highlight 15%, transparent)",
221
+ });
222
+ doc.body.append(overlay);
223
+ }
224
+ const rect = selectionRect(press.start, end, press.surface);
225
+ if (!overlay)
226
+ return;
227
+ overlay.hidden = !rect;
228
+ if (!rect)
229
+ return;
230
+ Object.assign(overlay.style, {
231
+ left: `${rect.left}px`,
232
+ top: `${rect.top}px`,
233
+ width: `${rect.width}px`,
234
+ height: `${rect.height}px`,
235
+ });
236
+ }
237
+ function onPointerUp(event) {
238
+ if (!press || event.pointerId !== press.pointerId)
239
+ return;
240
+ const { drawing, surface, start } = press;
241
+ clearPress();
242
+ if (!drawing || !surface || !owns(surface))
243
+ return;
244
+ suppressClick = true;
245
+ const rect = selectionRect(start, point(event), surface);
246
+ if (!rect)
247
+ return;
248
+ const matches = new Set();
249
+ const scrollports = new Map();
250
+ for (const item of surface.querySelectorAll(itemSelector)) {
251
+ if (!owns(item) || item.closest(surfaceSelector) !== surface ||
252
+ item.hasAttribute("data-visual-no-toggle") || item.closest(excluded))
253
+ continue;
254
+ const visibility = doc.defaultView?.getComputedStyle?.(item).visibility;
255
+ if (visibility === "hidden" || visibility === "collapse")
256
+ continue;
257
+ const visibleRect = clipToScrollports(rect, item.parentElement, surface, scrollports);
258
+ if (!visibleRect)
259
+ continue;
260
+ const bounds = options.getItemBounds?.(item) ?? item.getBoundingClientRect();
261
+ if (intersects(bounds, visibleRect) && (options.intersectsItem?.(item, visibleRect) ?? true)) {
262
+ matches.add(id(item));
263
+ }
264
+ }
265
+ if (matches.size > 0)
266
+ options.onAdd?.([...matches]);
267
+ }
268
+ function onCancel(event) {
269
+ if (!press || ("pointerId" in event && event.pointerId !== press.pointerId))
270
+ return;
271
+ suppressClick = true;
272
+ clearPress();
273
+ }
274
+ function onDragStart(event) {
275
+ const element = target(event);
276
+ if (press?.surface && element?.localName === "img" &&
277
+ !element.closest("[draggable=true], a[href], [role=link]")) {
278
+ event.preventDefault();
279
+ return;
280
+ }
281
+ onCancel(event);
282
+ }
283
+ function consume(event) {
284
+ event.preventDefault();
285
+ event.stopPropagation();
286
+ }
287
+ function onClick(event) {
288
+ const element = target(event);
289
+ if (!element)
290
+ return;
291
+ const immediate = element.closest("[data-visual-immediate-activate]");
292
+ if (immediate) {
293
+ // The native control owns activation. Discard its row's pending click
294
+ // before that control receives the event.
295
+ if (pending && immediate.closest(itemSelector) === pending.item)
296
+ clearPending();
297
+ return;
298
+ }
299
+ const item = itemFor(element);
300
+ if (isModified(event)) {
301
+ if (item)
302
+ clearPending();
303
+ return;
304
+ }
305
+ if (event.detail > 0 && suppressClick && (item || element.closest(surfaceSelector))) {
306
+ consume(event);
307
+ return;
308
+ }
309
+ if (!item || (!canActivate(item) && !canToggle(item)))
310
+ return;
311
+ consume(event);
312
+ if (event.detail === 0 || pointerType === "touch" || !canToggle(item)) {
313
+ clearPending(pending?.item !== item);
314
+ if (canActivate(item))
315
+ options.onActivate?.(id(item));
316
+ }
317
+ else if (pending?.item === item && pending.id === id(item)) {
318
+ clearPending();
319
+ options.onToggle?.(id(item));
320
+ }
321
+ else {
322
+ clearPending(true);
323
+ pending = {
324
+ item,
325
+ id: id(item),
326
+ timer: setTimeout(() => clearPending(true), ordinaryClickDelay),
327
+ };
328
+ }
329
+ }
330
+ function onKeyDown(event) {
331
+ const element = target(event);
332
+ if (!element)
333
+ return;
334
+ if (event.key !== "Enter" && event.key !== " ")
335
+ return;
336
+ const item = itemFor(element);
337
+ if (!item)
338
+ return;
339
+ if (event.key === " " && event.shiftKey && !event.altKey && !event.ctrlKey &&
340
+ !event.metaKey && canToggle(item)) {
341
+ consume(event);
342
+ clearPending();
343
+ if (!event.repeat)
344
+ options.onToggle?.(id(item));
345
+ }
346
+ else if (!isModified(event) && !element.closest(nativeControl) && canActivate(item)) {
347
+ consume(event);
348
+ clearPending(pending?.item !== item);
349
+ if (!event.repeat)
350
+ options.onActivate?.(id(item));
351
+ }
352
+ }
353
+ root.addEventListener("pointerdown", onPointerDown, passiveCapture);
354
+ doc.addEventListener("pointerdown", (event) => {
355
+ if (!press || event.isPrimary || event.pointerType !== "touch")
356
+ return;
357
+ suppressClick = true;
358
+ clearPress();
359
+ clearPending();
360
+ }, passiveCapture);
361
+ doc.addEventListener("pointermove", onPointerMove, capture);
362
+ doc.addEventListener("pointerup", onPointerUp, passiveCapture);
363
+ doc.addEventListener("pointercancel", onCancel, passiveCapture);
364
+ doc.addEventListener("dragstart", onDragStart, capture);
365
+ root.addEventListener("click", onClick, capture);
366
+ root.addEventListener("keydown", onKeyDown, capture);
367
+ doc.addEventListener("keydown", (event) => {
368
+ if (event.key !== "Escape" || !press?.drawing)
369
+ return;
370
+ consume(event);
371
+ suppressClick = true;
372
+ clearPress();
373
+ }, capture);
374
+ root.addEventListener("contextmenu", (event) => {
375
+ if (press?.pointerType !== "mouse" && press?.item && canToggle(press.item)) {
376
+ event.preventDefault();
377
+ }
378
+ }, capture);
379
+ root.addEventListener("selectstart", (event) => {
380
+ if (press?.surface)
381
+ event.preventDefault();
382
+ }, capture);
383
+ doc.defaultView?.addEventListener("blur", () => {
384
+ clearPress();
385
+ clearPending();
386
+ }, { signal: listeners.signal });
387
+ return () => {
388
+ listeners.abort();
389
+ boundRoots.delete(root);
390
+ clearPress();
391
+ clearPending();
392
+ };
393
+ }
@@ -0,0 +1,27 @@
1
+ /** Presentation state for an element using the visual item gestures. */
2
+ export interface VisualItemPropsOptions {
3
+ id: string;
4
+ activation?: {
5
+ label?: string;
6
+ expanded?: boolean;
7
+ controls?: string;
8
+ };
9
+ pressed?: boolean | "mixed";
10
+ selectionStart?: boolean;
11
+ }
12
+ /** Attributes for a focusable visual item with independent activation and context gestures. */
13
+ export declare function visualItemProps({ id, activation, pressed, selectionStart, }: VisualItemPropsOptions): {
14
+ "data-visual-item": string | undefined;
15
+ "data-visual-no-activate": string | undefined;
16
+ "data-visual-no-toggle": string | undefined;
17
+ "data-visual-selection-start": string | undefined;
18
+ role: "button" | undefined;
19
+ tabIndex: number | undefined;
20
+ "aria-label": string | undefined;
21
+ "aria-pressed": boolean | "mixed" | undefined;
22
+ "aria-keyshortcuts": string | undefined;
23
+ "aria-expanded": boolean | undefined;
24
+ "aria-controls": string | undefined;
25
+ title: string | undefined;
26
+ };
27
+ //# sourceMappingURL=visual-item-props.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"visual-item-props.d.ts","sourceRoot":"","sources":["../../src/src/visual-item-props.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,MAAM,WAAW,sBAAsB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,CAAC,EAAE;QACX,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;IAC5B,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,+FAA+F;AAC/F,wBAAgB,eAAe,CAAC,EAC9B,EAAE,EACF,UAAU,EACV,OAAO,EACP,cAAsC,GACvC,EAAE,sBAAsB,GAAG;IAC1B,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,yBAAyB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9C,uBAAuB,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5C,6BAA6B,EAAE,MAAM,GAAG,SAAS,CAAC;IAClD,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC3B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC,cAAc,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;IAC9C,mBAAmB,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,eAAe,EAAE,OAAO,GAAG,SAAS,CAAC;IACrC,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3B,CAiBA"}
@@ -0,0 +1,19 @@
1
+ /** Attributes for a focusable visual item with independent activation and context gestures. */
2
+ export function visualItemProps({ id, activation, pressed, selectionStart = pressed !== undefined, }) {
3
+ const canToggle = pressed !== undefined;
4
+ const interactive = activation !== undefined || canToggle;
5
+ return {
6
+ "data-visual-item": interactive ? id : undefined,
7
+ "data-visual-no-activate": activation ? undefined : "",
8
+ "data-visual-no-toggle": canToggle ? undefined : "",
9
+ "data-visual-selection-start": selectionStart ? "" : undefined,
10
+ role: interactive ? "button" : undefined,
11
+ tabIndex: interactive ? 0 : undefined,
12
+ "aria-label": activation?.label,
13
+ "aria-pressed": pressed,
14
+ "aria-keyshortcuts": canToggle ? "Shift+Space" : undefined,
15
+ "aria-expanded": activation?.expanded,
16
+ "aria-controls": activation?.controls,
17
+ title: activation?.label,
18
+ };
19
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcpview/components",
3
- "version": "0.13.1",
3
+ "version": "0.14.0",
4
4
  "description": "Optional light-first component runtime for small composable MCP App viewers",
5
5
  "keywords": [
6
6
  "mcp",
@@ -27,6 +27,11 @@
27
27
  "import": "./esm/mod.js",
28
28
  "require": "./script/mod.js"
29
29
  },
30
+ "./preact/controls": {
31
+ "types": "./esm/preact-controls.d.ts",
32
+ "import": "./esm/preact-controls.js",
33
+ "require": "./script/preact-controls.js"
34
+ },
30
35
  "./preact/context": {
31
36
  "types": "./esm/preact-context.d.ts",
32
37
  "import": "./esm/preact-context.js",
@@ -10,7 +10,7 @@
10
10
  */
11
11
  import "./_dnt.polyfills.js";
12
12
  export { Badge, BadgeGroup, Button, Card, CodeBlock, CrossSelection, DataTable, EmptyState, InlineCode, KeyValueList, Message, Metric, MetricGrid, NoticeGroup, renderStatusMessage, Row, Skeleton, Stack, StateMessage, TextInput, Toolbar, } from "./src/preact/components.js";
13
- export type { BadgeGroupProps, BadgeProps, ButtonProps, CardProps, CodeBlockProps, CrossSelectionProps, DataTableColumn, DataTableProps, EmptyStateProps, InlineCodeProps, KeyValueItem, KeyValueLayout, KeyValueListProps, MessageProps, MetricGridProps, MetricItem, MetricProps, NoticeGroupProps, PresentationTone, RowProps, SkeletonProps, StackProps, StateMessageProps, StatusMessageMount, TextInputProps, ToolbarProps, } from "./src/preact/components.js";
13
+ export type { BadgeGroupProps, BadgeProps, ButtonProps, CardProps, CodeBlockProps, CrossSelectionProps, DataTableColumn, DataTableDisclosure, DataTableProps, EmptyStateProps, InlineCodeProps, KeyValueItem, KeyValueLayout, KeyValueListProps, MessageProps, MetricGridProps, MetricItem, MetricProps, NoticeGroupProps, PresentationTone, RowProps, SkeletonProps, StackProps, StateMessageProps, StatusMessageMount, TextInputProps, ToolbarProps, } from "./src/preact/components.js";
14
14
  export { ArtifactRow, DrillHint, LimitGauge, PATH_BAR_DEFAULT_MAX_VISIBLE, PathBar, Slot3D, StaleBanner, TreeList, TypeBadge, } from "./src/preact/structural.js";
15
15
  export type { ArtifactFingerprint, ArtifactRowProps, ArtifactVerification, DrillHintDirection, DrillHintProps, LimitGaugeLimit, LimitGaugeProps, PathBarItem, PathBarProps, Slot3DProps, StaleBannerAction, StaleBannerProps, TreeListNode, TreeListProps, TypeBadgeProps, ViewKind, } from "./src/preact/structural.js";
16
16
  export { IntervalPlot, SeriesChart, Sparkline } from "./src/preact/plots.js";
@@ -1 +1 @@
1
- {"version":3,"file":"preact-components.d.ts","sourceRoot":"","sources":["../src/preact-components.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,qBAAqB,CAAC;AAG7B,OAAO,EACL,KAAK,EACL,UAAU,EACV,MAAM,EACN,IAAI,EACJ,SAAS,EACT,cAAc,EACd,SAAS,EACT,UAAU,EACV,UAAU,EACV,YAAY,EACZ,OAAO,EACP,MAAM,EACN,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,GAAG,EACH,QAAQ,EACR,KAAK,EACL,YAAY,EACZ,SAAS,EACT,OAAO,GACR,MAAM,4BAA4B,CAAC;AACpC,YAAY,EACV,eAAe,EACf,UAAU,EACV,WAAW,EACX,SAAS,EACT,cAAc,EACd,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,eAAe,EACf,eAAe,EACf,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,QAAQ,EACR,aAAa,EACb,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,YAAY,GACb,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,WAAW,EACX,SAAS,EACT,UAAU,EACV,4BAA4B,EAC5B,OAAO,EACP,MAAM,EACN,WAAW,EACX,QAAQ,EACR,SAAS,GACV,MAAM,4BAA4B,CAAC;AACpC,YAAY,EACV,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,eAAe,EACf,WAAW,EACX,YAAY,EACZ,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,cAAc,EACd,QAAQ,GACT,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAC7E,YAAY,EACV,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,sBAAsB,EACtB,eAAe,EACf,WAAW,EACX,cAAc,GACf,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,cAAc,EACd,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,cAAc,EACd,eAAe,EACf,YAAY,GACb,MAAM,kCAAkC,CAAC;AAC1C,YAAY,EACV,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AACvE,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEtF,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,YAAY,EACV,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,iCAAiC,CAAC"}
1
+ {"version":3,"file":"preact-components.d.ts","sourceRoot":"","sources":["../src/preact-components.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,qBAAqB,CAAC;AAG7B,OAAO,EACL,KAAK,EACL,UAAU,EACV,MAAM,EACN,IAAI,EACJ,SAAS,EACT,cAAc,EACd,SAAS,EACT,UAAU,EACV,UAAU,EACV,YAAY,EACZ,OAAO,EACP,MAAM,EACN,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,GAAG,EACH,QAAQ,EACR,KAAK,EACL,YAAY,EACZ,SAAS,EACT,OAAO,GACR,MAAM,4BAA4B,CAAC;AACpC,YAAY,EACV,eAAe,EACf,UAAU,EACV,WAAW,EACX,SAAS,EACT,cAAc,EACd,mBAAmB,EACnB,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,eAAe,EACf,eAAe,EACf,YAAY,EACZ,cAAc,EACd,iBAAiB,EACjB,YAAY,EACZ,eAAe,EACf,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,QAAQ,EACR,aAAa,EACb,UAAU,EACV,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,YAAY,GACb,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,WAAW,EACX,SAAS,EACT,UAAU,EACV,4BAA4B,EAC5B,OAAO,EACP,MAAM,EACN,WAAW,EACX,QAAQ,EACR,SAAS,GACV,MAAM,4BAA4B,CAAC;AACpC,YAAY,EACV,mBAAmB,EACnB,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,eAAe,EACf,WAAW,EACX,YAAY,EACZ,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,cAAc,EACd,QAAQ,GACT,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAC7E,YAAY,EACV,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,sBAAsB,EACtB,eAAe,EACf,WAAW,EACX,cAAc,GACf,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,cAAc,EACd,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,cAAc,EACd,eAAe,EACf,YAAY,GACb,MAAM,kCAAkC,CAAC;AAC1C,YAAY,EACV,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AACvE,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEtF,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,YAAY,EACV,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,iCAAiC,CAAC"}
@@ -0,0 +1,12 @@
1
+ /** Lightweight Preact controls for drill-down and context pinning. @module */
2
+ import "./_dnt.polyfills.js";
3
+ export { ContextPinButton, DisclosureChevron } from "./src/preact/interaction-controls.js";
4
+ export type { ContextPinButtonProps, DisclosureChevronProps, } from "./src/preact/interaction-controls.js";
5
+ export { installMcpViewInteractionStyles, MCP_VIEW_INTERACTION_CSS, } from "./src/interaction-styles.js";
6
+ export { bindVisualItemGestures } from "./src/visual-item-gestures.js";
7
+ export type { VisualItemGestureOptions } from "./src/visual-item-gestures.js";
8
+ export { useVisualItemGestures } from "./src/preact/visual-item-gestures.js";
9
+ export { CONTEXT_ROW_OUTLINE, MCP_VIEW_CONTEXT_ROW_CSS } from "./src/context-row-styles.js";
10
+ export { visualItemProps } from "./src/visual-item-props.js";
11
+ export type { VisualItemPropsOptions } from "./src/visual-item-props.js";
12
+ //# sourceMappingURL=preact-controls.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preact-controls.d.ts","sourceRoot":"","sources":["../src/preact-controls.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,OAAO,qBAAqB,CAAC;AAE7B,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAC3F,YAAY,EACV,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACL,+BAA+B,EAC/B,wBAAwB,GACzB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,YAAY,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAC9E,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,YAAY,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.visualItemProps = exports.MCP_VIEW_CONTEXT_ROW_CSS = exports.CONTEXT_ROW_OUTLINE = exports.useVisualItemGestures = exports.bindVisualItemGestures = exports.MCP_VIEW_INTERACTION_CSS = exports.installMcpViewInteractionStyles = exports.DisclosureChevron = exports.ContextPinButton = void 0;
4
+ /** Lightweight Preact controls for drill-down and context pinning. @module */
5
+ require("./_dnt.polyfills.js");
6
+ var interaction_controls_js_1 = require("./src/preact/interaction-controls.js");
7
+ Object.defineProperty(exports, "ContextPinButton", { enumerable: true, get: function () { return interaction_controls_js_1.ContextPinButton; } });
8
+ Object.defineProperty(exports, "DisclosureChevron", { enumerable: true, get: function () { return interaction_controls_js_1.DisclosureChevron; } });
9
+ var interaction_styles_js_1 = require("./src/interaction-styles.js");
10
+ Object.defineProperty(exports, "installMcpViewInteractionStyles", { enumerable: true, get: function () { return interaction_styles_js_1.installMcpViewInteractionStyles; } });
11
+ Object.defineProperty(exports, "MCP_VIEW_INTERACTION_CSS", { enumerable: true, get: function () { return interaction_styles_js_1.MCP_VIEW_INTERACTION_CSS; } });
12
+ var visual_item_gestures_js_1 = require("./src/visual-item-gestures.js");
13
+ Object.defineProperty(exports, "bindVisualItemGestures", { enumerable: true, get: function () { return visual_item_gestures_js_1.bindVisualItemGestures; } });
14
+ var visual_item_gestures_js_2 = require("./src/preact/visual-item-gestures.js");
15
+ Object.defineProperty(exports, "useVisualItemGestures", { enumerable: true, get: function () { return visual_item_gestures_js_2.useVisualItemGestures; } });
16
+ var context_row_styles_js_1 = require("./src/context-row-styles.js");
17
+ Object.defineProperty(exports, "CONTEXT_ROW_OUTLINE", { enumerable: true, get: function () { return context_row_styles_js_1.CONTEXT_ROW_OUTLINE; } });
18
+ Object.defineProperty(exports, "MCP_VIEW_CONTEXT_ROW_CSS", { enumerable: true, get: function () { return context_row_styles_js_1.MCP_VIEW_CONTEXT_ROW_CSS; } });
19
+ var visual_item_props_js_1 = require("./src/visual-item-props.js");
20
+ Object.defineProperty(exports, "visualItemProps", { enumerable: true, get: function () { return visual_item_props_js_1.visualItemProps; } });
@@ -0,0 +1,5 @@
1
+ /** Class for a standalone selected or partially selected visual item. */
2
+ export declare const CONTEXT_ROW_OUTLINE = "mcp-view-context-row-outline";
3
+ /** Opt-in outlines for adjacent selected rows and standalone pressed items. */
4
+ export declare const MCP_VIEW_CONTEXT_ROW_CSS: string;
5
+ //# sourceMappingURL=context-row-styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-row-styles.d.ts","sourceRoot":"","sources":["../../src/src/context-row-styles.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,eAAO,MAAM,mBAAmB,iCAAiC,CAAC;AAElE,+EAA+E;AAC/E,eAAO,MAAM,wBAAwB,EAAE,MA4FtC,CAAC"}
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MCP_VIEW_CONTEXT_ROW_CSS = exports.CONTEXT_ROW_OUTLINE = void 0;
4
+ /** Class for a standalone selected or partially selected visual item. */
5
+ exports.CONTEXT_ROW_OUTLINE = "mcp-view-context-row-outline";
6
+ /** Opt-in outlines for adjacent selected rows and standalone pressed items. */
7
+ exports.MCP_VIEW_CONTEXT_ROW_CSS = String.raw `
8
+ .${exports.CONTEXT_ROW_OUTLINE}:is([aria-pressed="true"], [aria-pressed="mixed"]) {
9
+ box-shadow: inset 0 0 0 2px var(--mcp-view-context-row-accent, var(--mcp-view-accent, Highlight));
10
+ }
11
+
12
+ /* Only adjoining selected rows share edges. A visible detail or action rail
13
+ after a row breaks the run before the next row. */
14
+ [data-mcp-view-context-row] {
15
+ --mcp-view-context-row-top: 2px;
16
+ --mcp-view-context-row-bottom: 2px;
17
+ --mcp-view-context-row-seam: 0px;
18
+ }
19
+
20
+ [data-mcp-view-context-row="selected"]:not([data-mcp-view-context-row-break]):has(+ [data-mcp-view-context-row="selected"]) {
21
+ --mcp-view-context-row-bottom: 0px;
22
+ --mcp-view-context-row-seam: 1px;
23
+ }
24
+
25
+ [data-mcp-view-context-row="selected"]:not([data-mcp-view-context-row-break]) + [data-mcp-view-context-row="selected"] {
26
+ --mcp-view-context-row-top: 0px;
27
+ }
28
+
29
+ [data-mcp-view-context-row="selected"] > [data-mcp-view-context-row-outline],
30
+ [data-mcp-view-context-row="selected"] > * > [data-mcp-view-context-row-outline] {
31
+ position: relative;
32
+ box-shadow:
33
+ inset 2px 0 var(--mcp-view-context-row-accent, var(--mcp-view-accent, Highlight)),
34
+ inset -2px 0 var(--mcp-view-context-row-accent, var(--mcp-view-accent, Highlight)),
35
+ inset 0 var(--mcp-view-context-row-top) var(--mcp-view-context-row-accent, var(--mcp-view-accent, Highlight)),
36
+ inset 0 calc(-1 * var(--mcp-view-context-row-bottom)) var(--mcp-view-context-row-accent, var(--mcp-view-accent, Highlight));
37
+ }
38
+
39
+ /* Collapsed table borders paint above the cells. Inset shadows on each
40
+ cell join across the row while preserving the neutral border. */
41
+ tr[data-mcp-view-context-row="selected"] > td {
42
+ --mcp-view-context-cell-left: 0px;
43
+ --mcp-view-context-cell-right: 0px;
44
+ box-shadow:
45
+ inset var(--mcp-view-context-cell-left) 0 var(--mcp-view-context-row-accent, var(--mcp-view-accent, Highlight)),
46
+ inset calc(-1 * var(--mcp-view-context-cell-right)) 0 var(--mcp-view-context-row-accent, var(--mcp-view-accent, Highlight)),
47
+ inset 0 var(--mcp-view-context-row-top) var(--mcp-view-context-row-accent, var(--mcp-view-accent, Highlight)),
48
+ inset 0 calc(-1 * var(--mcp-view-context-row-bottom)) var(--mcp-view-context-row-accent, var(--mcp-view-accent, Highlight));
49
+ }
50
+
51
+ tr[data-mcp-view-context-row="selected"] > td:first-child {
52
+ --mcp-view-context-cell-left: 2px;
53
+ }
54
+
55
+ tr[data-mcp-view-context-row="selected"] > td:last-child {
56
+ --mcp-view-context-cell-right: 2px;
57
+ }
58
+
59
+
60
+ /* Continue the side edges across the one-pixel neutral separator only. */
61
+ [data-mcp-view-context-row="selected"] > [data-mcp-view-context-row-outline]::after,
62
+ [data-mcp-view-context-row="selected"] > * > [data-mcp-view-context-row-outline]::after {
63
+ content: "";
64
+ position: absolute;
65
+ inset-inline: 0;
66
+ inset-block-end: -1px;
67
+ height: var(--mcp-view-context-row-seam);
68
+ border-inline: 2px solid var(--mcp-view-context-row-accent, var(--mcp-view-accent, Highlight));
69
+ pointer-events: none;
70
+ }
71
+
72
+ tr[data-mcp-view-context-row="selected"] > td:is(:first-child, :last-child) {
73
+ position: relative;
74
+ }
75
+
76
+ tr[data-mcp-view-context-row="selected"] > td:is(:first-child, :last-child)::after {
77
+ content: "";
78
+ position: absolute;
79
+ inset-block-end: -1px;
80
+ width: 2px;
81
+ height: var(--mcp-view-context-row-seam);
82
+ background: var(--mcp-view-context-row-accent, var(--mcp-view-accent, Highlight));
83
+ pointer-events: none;
84
+ }
85
+
86
+ tr[data-mcp-view-context-row="selected"] > td:first-child::after {
87
+ inset-inline-start: 0;
88
+ }
89
+
90
+ tr[data-mcp-view-context-row="selected"] > td:last-child::after {
91
+ inset-inline-end: 0;
92
+ }
93
+
94
+ tr[data-mcp-view-context-row="selected"] > td:only-child::after {
95
+ width: auto;
96
+ background: none;
97
+ border-inline: 2px solid var(--mcp-view-context-row-accent, var(--mcp-view-accent, Highlight));
98
+ }
99
+ `;
@@ -0,0 +1,5 @@
1
+ /** Standalone styles for exploration and context controls. No global theme is required. */
2
+ export declare const MCP_VIEW_INTERACTION_CSS: string;
3
+ /** Install only the interaction styles once in a standalone viewer's document. */
4
+ export declare function installMcpViewInteractionStyles(target?: Document): HTMLStyleElement;
5
+ //# sourceMappingURL=interaction-styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interaction-styles.d.ts","sourceRoot":"","sources":["../../src/src/interaction-styles.ts"],"names":[],"mappings":"AAEA,2FAA2F;AAC3F,eAAO,MAAM,wBAAwB,EAAE,MAwCtC,CAAC;AAEF,kFAAkF;AAClF,wBAAgB,+BAA+B,CAAC,MAAM,GAAE,QAAmB,GAAG,gBAAgB,CAS7F"}