@mcpview/components 0.13.0 → 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.
- package/README.md +112 -2
- package/esm/preact-components.d.ts +1 -1
- package/esm/preact-components.d.ts.map +1 -1
- package/esm/preact-controls.d.ts +12 -0
- package/esm/preact-controls.d.ts.map +1 -0
- package/esm/preact-controls.js +8 -0
- package/esm/src/context-row-styles.d.ts +5 -0
- package/esm/src/context-row-styles.d.ts.map +1 -0
- package/esm/src/context-row-styles.js +96 -0
- package/esm/src/interaction-styles.d.ts +5 -0
- package/esm/src/interaction-styles.d.ts.map +1 -0
- package/esm/src/interaction-styles.js +55 -0
- package/esm/src/preact/components.d.ts +24 -1
- package/esm/src/preact/components.d.ts.map +1 -1
- package/esm/src/preact/components.js +86 -39
- package/esm/src/preact/interaction-controls.d.ts +22 -0
- package/esm/src/preact/interaction-controls.d.ts.map +1 -0
- package/esm/src/preact/interaction-controls.js +25 -0
- package/esm/src/preact/interactive-child.d.ts +2 -0
- package/esm/src/preact/interactive-child.d.ts.map +1 -0
- package/esm/src/preact/interactive-child.js +16 -0
- package/esm/src/preact/mod.d.ts +1 -1
- package/esm/src/preact/mod.d.ts.map +1 -1
- package/esm/src/preact/semantic-element.d.ts.map +1 -1
- package/esm/src/preact/semantic-element.js +3 -16
- package/esm/src/preact/snippet-javascript.d.ts +10 -0
- package/esm/src/preact/snippet-javascript.d.ts.map +1 -0
- package/esm/src/preact/snippet-javascript.js +46 -0
- package/esm/src/preact/snippet-library.d.ts +2 -0
- package/esm/src/preact/snippet-library.d.ts.map +1 -1
- package/esm/src/preact/snippet-library.js +23 -2
- package/esm/src/preact/structural.d.ts.map +1 -1
- package/esm/src/preact/structural.js +14 -7
- package/esm/src/preact/visual-item-gestures.d.ts +5 -0
- package/esm/src/preact/visual-item-gestures.d.ts.map +1 -0
- package/esm/src/preact/visual-item-gestures.js +30 -0
- package/esm/src/theme.d.ts.map +1 -1
- package/esm/src/theme.js +24 -0
- package/esm/src/visual-item-gestures.d.ts +17 -0
- package/esm/src/visual-item-gestures.d.ts.map +1 -0
- package/esm/src/visual-item-gestures.js +393 -0
- package/esm/src/visual-item-props.d.ts +27 -0
- package/esm/src/visual-item-props.d.ts.map +1 -0
- package/esm/src/visual-item-props.js +19 -0
- package/package.json +7 -1
- package/script/preact-components.d.ts +1 -1
- package/script/preact-components.d.ts.map +1 -1
- package/script/preact-controls.d.ts +12 -0
- package/script/preact-controls.d.ts.map +1 -0
- package/script/preact-controls.js +20 -0
- package/script/src/context-row-styles.d.ts +5 -0
- package/script/src/context-row-styles.d.ts.map +1 -0
- package/script/src/context-row-styles.js +99 -0
- package/script/src/interaction-styles.d.ts +5 -0
- package/script/src/interaction-styles.d.ts.map +1 -0
- package/script/src/interaction-styles.js +59 -0
- package/script/src/preact/components.d.ts +24 -1
- package/script/src/preact/components.d.ts.map +1 -1
- package/script/src/preact/components.js +85 -38
- package/script/src/preact/interaction-controls.d.ts +22 -0
- package/script/src/preact/interaction-controls.d.ts.map +1 -0
- package/script/src/preact/interaction-controls.js +29 -0
- package/script/src/preact/interactive-child.d.ts +2 -0
- package/script/src/preact/interactive-child.d.ts.map +1 -0
- package/script/src/preact/interactive-child.js +19 -0
- package/script/src/preact/mod.d.ts +1 -1
- package/script/src/preact/mod.d.ts.map +1 -1
- package/script/src/preact/semantic-element.d.ts.map +1 -1
- package/script/src/preact/semantic-element.js +4 -17
- package/script/src/preact/snippet-javascript.d.ts +10 -0
- package/script/src/preact/snippet-javascript.d.ts.map +1 -0
- package/script/src/preact/snippet-javascript.js +49 -0
- package/script/src/preact/snippet-library.d.ts +2 -0
- package/script/src/preact/snippet-library.d.ts.map +1 -1
- package/script/src/preact/snippet-library.js +22 -1
- package/script/src/preact/structural.d.ts.map +1 -1
- package/script/src/preact/structural.js +14 -7
- package/script/src/preact/visual-item-gestures.d.ts +5 -0
- package/script/src/preact/visual-item-gestures.d.ts.map +1 -0
- package/script/src/preact/visual-item-gestures.js +33 -0
- package/script/src/theme.d.ts.map +1 -1
- package/script/src/theme.js +24 -0
- package/script/src/visual-item-gestures.d.ts +17 -0
- package/script/src/visual-item-gestures.d.ts.map +1 -0
- package/script/src/visual-item-gestures.js +396 -0
- package/script/src/visual-item-props.d.ts +27 -0
- package/script/src/visual-item-props.d.ts.map +1 -0
- package/script/src/visual-item-props.js +22 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structural.d.ts","sourceRoot":"","sources":["../../../src/src/preact/structural.tsx"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,kEAAkE;AAElE,OAAO,KAAK,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"structural.d.ts","sourceRoot":"","sources":["../../../src/src/preact/structural.tsx"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,kEAAkE;AAElE,OAAO,KAAK,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAIxD,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,iBAAiB,CAAC;IAClC,oFAAoF;IACpF,QAAQ,CAAC,MAAM,CAAC,EAAE,iBAAiB,CAAC;CACrC;AAED,mEAAmE;AACnE,eAAO,MAAM,4BAA4B,IAAI,CAAC;AAE9C,MAAM,WAAW,YAAY;IAC3B,mDAAmD;IACnD,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,gDAAgD;IAChD,QAAQ,CAAC,KAAK,EAAE,SAAS,WAAW,EAAE,CAAC;IACvC,+CAA+C;IAC/C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,sEAAsE;IACtE,QAAQ,CAA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C,oEAAoE;IACpE,QAAQ,CAAC,SAAS,CAAC,EAAE,iBAAiB,CAAC;IACvC,QAAQ,CAAC,YAAY,CAAC,EAAE,oBAAoB,CAAC;IAC7C,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,UAAU,sBAAuB,SAAQ,oBAAoB;IAC3D,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,CAAC;IAChC,QAAQ,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC;CAC9B;AAED,UAAU,2BAA4B,SAAQ,oBAAoB;IAChE,QAAQ,CAAC,UAAU,EAAE,MAAM,IAAI,CAAC;IAChC,mEAAmE;IACnE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,MAAM,gBAAgB,GAAG,sBAAsB,GAAG,2BAA2B,CAAC;AAEpF,+FAA+F;AAC/F,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,GAAG,CAAC,OAAO,CAwChE"}
|
|
@@ -10,6 +10,8 @@ exports.TreeList = TreeList;
|
|
|
10
10
|
exports.LimitGauge = LimitGauge;
|
|
11
11
|
exports.ArtifactRow = ArtifactRow;
|
|
12
12
|
const jsx_runtime_1 = require("preact/jsx-runtime");
|
|
13
|
+
const interactive_child_js_1 = require("./interactive-child.js");
|
|
14
|
+
const interaction_controls_js_1 = require("./interaction-controls.js");
|
|
13
15
|
/** Trailing items kept inline before the leading ones collapse. */
|
|
14
16
|
exports.PATH_BAR_DEFAULT_MAX_VISIBLE = 3;
|
|
15
17
|
/**
|
|
@@ -34,10 +36,6 @@ function PathBar({ label, items, currentId, onSelect, maxVisible = exports.PATH_
|
|
|
34
36
|
: ((0, jsx_runtime_1.jsx)("button", { class: "mcp-view-path-bar-button", onClick: () => onSelect(item.id), type: "button", children: item.label })) }, item.id));
|
|
35
37
|
}) })] }));
|
|
36
38
|
}
|
|
37
|
-
const DRILL_HINT_GLYPH = Object.freeze({
|
|
38
|
-
"in-view": "›",
|
|
39
|
-
"to-model": "~",
|
|
40
|
-
});
|
|
41
39
|
/**
|
|
42
40
|
* Affordance for one available drill-down.
|
|
43
41
|
*
|
|
@@ -49,7 +47,7 @@ function DrillHint(props) {
|
|
|
49
47
|
if (props.onActivate === undefined) {
|
|
50
48
|
return ((0, jsx_runtime_1.jsx)("span", { class: className, "data-degraded": "true", "data-direction": props.direction, children: props.label }));
|
|
51
49
|
}
|
|
52
|
-
return ((0, jsx_runtime_1.jsxs)("button", { "aria-label": props.actionLabel, class: className, "data-direction": props.direction, onClick: props.onActivate, type: "button", children: [(0, jsx_runtime_1.jsx)("span", { class: "mcp-view-drill-hint-label", children: props.label }), (0, jsx_runtime_1.jsx)("span", { "aria-hidden": "true", class: "mcp-view-drill-hint-glyph", children:
|
|
50
|
+
return ((0, jsx_runtime_1.jsxs)("button", { "aria-label": props.actionLabel, class: className, "data-direction": props.direction, onClick: props.onActivate, type: "button", children: [props.direction === "in-view" && (0, jsx_runtime_1.jsx)(interaction_controls_js_1.DisclosureChevron, { expanded: false }), (0, jsx_runtime_1.jsx)("span", { class: "mcp-view-drill-hint-label", children: props.label }), props.direction === "to-model" && ((0, jsx_runtime_1.jsx)("span", { "aria-hidden": "true", class: "mcp-view-drill-hint-glyph", children: "~" }))] }));
|
|
53
51
|
}
|
|
54
52
|
/** Names what one level is, next to the path that reached it. */
|
|
55
53
|
function TypeBadge({ kind, label, className }) {
|
|
@@ -78,8 +76,17 @@ function TreeListItem({ node, level, expanded, onToggle, toggleLabel, selectedId
|
|
|
78
76
|
const children = node.children ?? [];
|
|
79
77
|
const open = children.length > 0 && expanded.has(node.id);
|
|
80
78
|
const selected = selectedId === node.id;
|
|
81
|
-
return ((0, jsx_runtime_1.jsxs)("li", { "aria-expanded": children.length > 0 ? open : undefined, "aria-level": level, "aria-selected": onSelect === undefined ? undefined : selected, class: "mcp-view-tree-list-item", "data-tone": node.tone, role: "treeitem", children: [(0, jsx_runtime_1.jsxs)("div", { class: "mcp-view-tree-list-row", style: { paddingInlineStart: `${(level - 1) * 0.9}rem` },
|
|
82
|
-
|
|
79
|
+
return ((0, jsx_runtime_1.jsxs)("li", { "aria-expanded": children.length > 0 ? open : undefined, "aria-level": level, "aria-selected": onSelect === undefined ? undefined : selected, class: "mcp-view-tree-list-item", "data-tone": node.tone, role: "treeitem", children: [(0, jsx_runtime_1.jsxs)("div", { class: "mcp-view-tree-list-row", style: { paddingInlineStart: `${(level - 1) * 0.9}rem` }, onClick: children.length > 0 && !onSelect
|
|
80
|
+
? (event) => {
|
|
81
|
+
if ((0, interactive_child_js_1.eventStartedInInteractiveChild)(event.currentTarget, event.target))
|
|
82
|
+
return;
|
|
83
|
+
onToggle(node.id);
|
|
84
|
+
}
|
|
85
|
+
: undefined, children: [children.length > 0
|
|
86
|
+
? ((0, jsx_runtime_1.jsx)("button", { "aria-expanded": open, "aria-label": toggleLabel, class: "mcp-view-tree-list-twisty", onClick: (event) => {
|
|
87
|
+
event.stopPropagation();
|
|
88
|
+
onToggle(node.id);
|
|
89
|
+
}, type: "button", children: (0, jsx_runtime_1.jsx)(interaction_controls_js_1.DisclosureChevron, { expanded: open }) }))
|
|
83
90
|
: (0, jsx_runtime_1.jsx)("span", { "aria-hidden": "true", class: "mcp-view-tree-list-twisty", "data-empty": "true" }), node.typeLabel !== undefined && ((0, jsx_runtime_1.jsx)("span", { class: "mcp-view-tree-list-type", children: node.typeLabel })), onSelect === undefined
|
|
84
91
|
? (0, jsx_runtime_1.jsx)("span", { class: "mcp-view-tree-list-label", children: node.label })
|
|
85
92
|
: ((0, jsx_runtime_1.jsx)("button", { class: "mcp-view-tree-list-label", onClick: () => onSelect(node.id), type: "button", children: node.label })), node.detail !== undefined && (0, jsx_runtime_1.jsx)("span", { class: "mcp-view-tree-list-detail", children: node.detail }), node.coverageLabel !== undefined && ((0, jsx_runtime_1.jsx)("span", { class: "mcp-view-tree-list-coverage", "data-tone": node.tone, children: node.coverageLabel }))] }), open && ((0, jsx_runtime_1.jsx)("ul", { class: "mcp-view-tree-list-group", role: "group", children: children.map((child) => ((0, jsx_runtime_1.jsx)(TreeListItem, { expanded: expanded, level: level + 1, node: child, onSelect: onSelect, onToggle: onToggle, selectedId: selectedId, toggleLabel: toggleLabel }, child.id))) }))] }));
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { RefCallback } from "preact";
|
|
2
|
+
import { type VisualItemGestureOptions } from "../visual-item-gestures.js";
|
|
3
|
+
/** A stable callback ref that delegates to the latest gesture callbacks. */
|
|
4
|
+
export declare function useVisualItemGestures<T extends Element = HTMLElement>(options: VisualItemGestureOptions): RefCallback<T>;
|
|
5
|
+
//# sourceMappingURL=visual-item-gestures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visual-item-gestures.d.ts","sourceRoot":"","sources":["../../../src/src/preact/visual-item-gestures.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAE1C,OAAO,EAA0B,KAAK,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEnG,4EAA4E;AAC5E,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,OAAO,GAAG,WAAW,EACnE,OAAO,EAAE,wBAAwB,GAChC,WAAW,CAAC,CAAC,CAAC,CA2BhB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useVisualItemGestures = useVisualItemGestures;
|
|
4
|
+
const hooks_1 = require("preact/hooks");
|
|
5
|
+
const visual_item_gestures_js_1 = require("../visual-item-gestures.js");
|
|
6
|
+
/** A stable callback ref that delegates to the latest gesture callbacks. */
|
|
7
|
+
function useVisualItemGestures(options) {
|
|
8
|
+
const current = (0, hooks_1.useRef)(options);
|
|
9
|
+
const detach = (0, hooks_1.useRef)();
|
|
10
|
+
current.current = options;
|
|
11
|
+
return (0, hooks_1.useCallback)((root) => {
|
|
12
|
+
detach.current?.();
|
|
13
|
+
detach.current = root
|
|
14
|
+
? (0, visual_item_gestures_js_1.bindVisualItemGestures)(root, {
|
|
15
|
+
get onActivate() {
|
|
16
|
+
return current.current.onActivate;
|
|
17
|
+
},
|
|
18
|
+
get onToggle() {
|
|
19
|
+
return current.current.onToggle;
|
|
20
|
+
},
|
|
21
|
+
get onAdd() {
|
|
22
|
+
return current.current.onAdd;
|
|
23
|
+
},
|
|
24
|
+
get getItemBounds() {
|
|
25
|
+
return current.current.getItemBounds;
|
|
26
|
+
},
|
|
27
|
+
get intersectsItem() {
|
|
28
|
+
return current.current.intersectsItem;
|
|
29
|
+
},
|
|
30
|
+
})
|
|
31
|
+
: undefined;
|
|
32
|
+
}, []);
|
|
33
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/src/theme.ts"],"names":[],"mappings":"AAAA,4EAA4E;
|
|
1
|
+
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../src/src/theme.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAI5E,eAAO,MAAM,uBAAuB,mBAAmB,CAAC;AAExD,sEAAsE;AACtE,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CAAC;IACxC,IAAI,EAAE,iBAAiB,CAAC;IACxB,KAAK,EAAE,kBAAkB,CAAC;IAC1B,KAAK,EAAE,kBAAkB,CAAC;IAC1B,MAAM,EAAE,mBAAmB,CAAC;IAC5B,KAAK,EAAE,kBAAkB,CAAC;IAC1B,MAAM,EAAE,mBAAmB,CAAC;IAC5B,MAAM,EAAE,mBAAmB,CAAC;IAC5B,KAAK,EAAE,kBAAkB,CAAC;IAC1B,OAAO,EAAE,oBAAoB,CAAC;IAC9B,OAAO,EAAE,oBAAoB,CAAC;IAC9B,MAAM,EAAE,mBAAmB,CAAC;IAC5B,WAAW,EAAE,yBAAyB,CAAC;IACvC,QAAQ,EAAE,sBAAsB,CAAC;IACjC,QAAQ,EAAE,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oBAAoB;IACnC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAC3C,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAAC;IAC/C,aAAa,CAAC,OAAO,EAAE,OAAO,GAAG,gBAAgB,CAAC;CACnD;AAED,qEAAqE;AACrE,wBAAgB,mBAAmB,CACjC,MAAM,GAAE,oBAA+B,GACtC,gBAAgB,CASlB"}
|
package/script/src/theme.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.MCP_VIEW_THEME_CSS = exports.MCP_VIEW_THEME_TOKENS = exports.MCP_VIEW_THEME_STYLE_ID = void 0;
|
|
5
5
|
exports.installMcpViewTheme = installMcpViewTheme;
|
|
6
|
+
const interaction_styles_js_1 = require("./interaction-styles.js");
|
|
6
7
|
exports.MCP_VIEW_THEME_STYLE_ID = "mcp-view-theme";
|
|
7
8
|
exports.MCP_VIEW_THEME_TOKENS = Object.freeze({
|
|
8
9
|
text: "--mcp-view-text",
|
|
@@ -56,6 +57,7 @@ exports.MCP_VIEW_THEME_TOKENS = Object.freeze({
|
|
|
56
57
|
* and explicit system states. Every token can be overridden by the host.
|
|
57
58
|
*/
|
|
58
59
|
exports.MCP_VIEW_THEME_CSS = String.raw `
|
|
60
|
+
${interaction_styles_js_1.MCP_VIEW_INTERACTION_CSS}
|
|
59
61
|
:root {
|
|
60
62
|
color-scheme: light dark;
|
|
61
63
|
--mcp-view-text: var(--color-text-primary, #101519);
|
|
@@ -740,6 +742,17 @@ exports.MCP_VIEW_THEME_CSS = String.raw `
|
|
|
740
742
|
border: 0;
|
|
741
743
|
white-space: pre;
|
|
742
744
|
}
|
|
745
|
+
.mcp-view-snippet-code code {
|
|
746
|
+
font-variant-ligatures: none;
|
|
747
|
+
font-feature-settings: "liga" 0, "calt" 0;
|
|
748
|
+
}
|
|
749
|
+
.mcp-view-snippet-token-comment { color: var(--mcp-view-muted); }
|
|
750
|
+
.mcp-view-snippet-token-keyword { color: var(--mcp-view-brand-text); }
|
|
751
|
+
.mcp-view-snippet-token-string {
|
|
752
|
+
color: var(--mcp-view-text-secondary);
|
|
753
|
+
color: color-mix(in srgb, var(--mcp-view-success) 85%, var(--mcp-view-text-secondary));
|
|
754
|
+
}
|
|
755
|
+
.mcp-view-snippet-token-literal { color: var(--mcp-view-accent-text); }
|
|
743
756
|
.mcp-view-snippet-source button { justify-self: start; }
|
|
744
757
|
.mcp-view-snippet-empty {
|
|
745
758
|
padding: 8px;
|
|
@@ -1571,6 +1584,17 @@ button.mcp-view-drill-hint:focus-visible {
|
|
|
1571
1584
|
font-size: var(--mcp-view-size-note);
|
|
1572
1585
|
line-height: 1;
|
|
1573
1586
|
}
|
|
1587
|
+
.mcp-view-table-disclosure {
|
|
1588
|
+
display: inline-grid; place-items: center; min-width: 36px; min-height: 36px;
|
|
1589
|
+
margin-inline-end: .2rem; padding: 0; border: 0; border-radius: var(--mcp-view-radius-control);
|
|
1590
|
+
background: none; color: var(--mcp-view-muted); cursor: pointer; vertical-align: middle;
|
|
1591
|
+
}
|
|
1592
|
+
.mcp-view-table-disclosure:focus-visible {
|
|
1593
|
+
outline: 2px solid var(--mcp-view-accent); outline-offset: -2px;
|
|
1594
|
+
}
|
|
1595
|
+
@media (pointer: coarse) {
|
|
1596
|
+
.mcp-view-table-disclosure, button.mcp-view-tree-list-twisty { min-width: 44px; min-height: 44px; }
|
|
1597
|
+
}
|
|
1574
1598
|
.mcp-view-tree-list-twisty[data-empty="true"] { cursor: default; }
|
|
1575
1599
|
.mcp-view-tree-list-twisty:focus-visible {
|
|
1576
1600
|
outline: 2px solid var(--mcp-view-accent);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface VisualItemGestureOptions {
|
|
2
|
+
onActivate?: (id: string) => void;
|
|
3
|
+
onToggle?: (id: string) => void;
|
|
4
|
+
onAdd?: (ids: readonly string[]) => void;
|
|
5
|
+
getItemBounds?: (item: Element) => DOMRectReadOnly;
|
|
6
|
+
intersectsItem?: (item: Element, rect: DOMRectReadOnly) => boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Delegate drill and context gestures to descendants marked with `data-visual-item`.
|
|
10
|
+
* Mark rectangle surfaces with `data-visual-selection-surface` and use `touch-action: pan-y`
|
|
11
|
+
* there to allow horizontal touch selection alongside vertical scrolling.
|
|
12
|
+
* Mark items where a rectangle can start with `data-visual-selection-start`.
|
|
13
|
+
* Use native buttons or focusable equivalents and expose Shift+Space in their keyboard help.
|
|
14
|
+
* Returns the listener cleanup function.
|
|
15
|
+
*/
|
|
16
|
+
export declare function bindVisualItemGestures(root: Element, options: VisualItemGestureOptions): () => void;
|
|
17
|
+
//# sourceMappingURL=visual-item-gestures.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visual-item-gestures.d.ts","sourceRoot":"","sources":["../../src/src/visual-item-gestures.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,wBAAwB;IACvC,UAAU,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAChC,KAAK,CAAC,EAAE,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,KAAK,IAAI,CAAC;IACzC,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,eAAe,CAAC;IACnD,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,KAAK,OAAO,CAAC;CACpE;AAiID;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,wBAAwB,GAChC,MAAM,IAAI,CAmSZ"}
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bindVisualItemGestures = bindVisualItemGestures;
|
|
4
|
+
const itemSelector = "[data-visual-item]";
|
|
5
|
+
const surfaceSelector = "[data-visual-selection-surface]";
|
|
6
|
+
const nativeControl = "button, a[href], input, select, textarea, summary, [contenteditable=true]";
|
|
7
|
+
const interactiveControl = `${nativeControl}, [role=button], [role=link]`;
|
|
8
|
+
const excluded = "[data-visual-ignore], [disabled], [aria-disabled=true]";
|
|
9
|
+
const ordinaryClickDelay = 500;
|
|
10
|
+
const holdDelay = 550;
|
|
11
|
+
const movementThreshold = 8;
|
|
12
|
+
const boundRoots = new WeakSet();
|
|
13
|
+
function isModified(event) {
|
|
14
|
+
return event.shiftKey || event.ctrlKey || event.altKey || event.metaKey;
|
|
15
|
+
}
|
|
16
|
+
function point(event) {
|
|
17
|
+
return { x: event.clientX, y: event.clientY };
|
|
18
|
+
}
|
|
19
|
+
function clipRect(rect, clip) {
|
|
20
|
+
if (clip.right <= clip.left || clip.bottom <= clip.top)
|
|
21
|
+
return undefined;
|
|
22
|
+
const left = Math.max(rect.left, clip.left);
|
|
23
|
+
const top = Math.max(rect.top, clip.top);
|
|
24
|
+
const right = Math.min(rect.right, clip.right);
|
|
25
|
+
const bottom = Math.min(rect.bottom, clip.bottom);
|
|
26
|
+
if (left > right || top > bottom || (left === right && rect.width > 0) ||
|
|
27
|
+
(top === bottom && rect.height > 0))
|
|
28
|
+
return undefined;
|
|
29
|
+
return new DOMRect(left, top, right - left, bottom - top);
|
|
30
|
+
}
|
|
31
|
+
function scrollport(element) {
|
|
32
|
+
const document = element.ownerDocument;
|
|
33
|
+
if (element === document.documentElement)
|
|
34
|
+
return undefined;
|
|
35
|
+
const style = document.defaultView?.getComputedStyle?.(element);
|
|
36
|
+
if (!style || style.display === "contents" || style.display === "inline")
|
|
37
|
+
return undefined;
|
|
38
|
+
const clips = /^(auto|scroll|hidden|clip|overlay)$/;
|
|
39
|
+
const clipX = clips.test(style.overflowX);
|
|
40
|
+
const clipY = clips.test(style.overflowY);
|
|
41
|
+
if (!clipX && !clipY)
|
|
42
|
+
return undefined;
|
|
43
|
+
const bounds = element.getBoundingClientRect();
|
|
44
|
+
let { left, top, right, bottom } = bounds;
|
|
45
|
+
if ("offsetWidth" in element && "offsetHeight" in element) {
|
|
46
|
+
const layout = element;
|
|
47
|
+
const scaleX = layout.offsetWidth > 0 ? bounds.width / layout.offsetWidth : 1;
|
|
48
|
+
const scaleY = layout.offsetHeight > 0 ? bounds.height / layout.offsetHeight : 1;
|
|
49
|
+
left += element.clientLeft * scaleX;
|
|
50
|
+
top += element.clientTop * scaleY;
|
|
51
|
+
right = left + element.clientWidth * scaleX;
|
|
52
|
+
bottom = top + element.clientHeight * scaleY;
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
left: clipX ? left : -Infinity,
|
|
56
|
+
right: clipX ? right : Infinity,
|
|
57
|
+
top: clipY ? top : -Infinity,
|
|
58
|
+
bottom: clipY ? bottom : Infinity,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function clipToScrollports(rect, element, stopBefore, cache) {
|
|
62
|
+
for (let ancestor = element; ancestor && ancestor !== stopBefore && rect; ancestor = ancestor.parentElement) {
|
|
63
|
+
const clip = cache?.has(ancestor) ? cache.get(ancestor) : scrollport(ancestor);
|
|
64
|
+
cache?.set(ancestor, clip);
|
|
65
|
+
if (clip)
|
|
66
|
+
rect = clipRect(rect, clip);
|
|
67
|
+
}
|
|
68
|
+
return rect;
|
|
69
|
+
}
|
|
70
|
+
function selectionRect(start, end, surface) {
|
|
71
|
+
const doc = surface.ownerDocument;
|
|
72
|
+
const viewport = doc.defaultView?.visualViewport;
|
|
73
|
+
const viewportLeft = viewport?.offsetLeft ?? 0;
|
|
74
|
+
const viewportTop = viewport?.offsetTop ?? 0;
|
|
75
|
+
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));
|
|
76
|
+
const inSurface = clipRect(rect, surface.getBoundingClientRect());
|
|
77
|
+
const inViewport = inSurface && clipRect(inSurface, {
|
|
78
|
+
left: viewportLeft,
|
|
79
|
+
top: viewportTop,
|
|
80
|
+
right: viewportLeft + (viewport?.width ?? doc.documentElement.clientWidth ?? Infinity),
|
|
81
|
+
bottom: viewportTop + (viewport?.height ?? doc.documentElement.clientHeight ?? Infinity),
|
|
82
|
+
});
|
|
83
|
+
return clipToScrollports(inViewport, surface);
|
|
84
|
+
}
|
|
85
|
+
function intersects(bounds, rect) {
|
|
86
|
+
return bounds.width > 0 && bounds.height > 0 &&
|
|
87
|
+
bounds.left < rect.right && bounds.right > rect.left &&
|
|
88
|
+
bounds.top < rect.bottom && bounds.bottom > rect.top;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Delegate drill and context gestures to descendants marked with `data-visual-item`.
|
|
92
|
+
* Mark rectangle surfaces with `data-visual-selection-surface` and use `touch-action: pan-y`
|
|
93
|
+
* there to allow horizontal touch selection alongside vertical scrolling.
|
|
94
|
+
* Mark items where a rectangle can start with `data-visual-selection-start`.
|
|
95
|
+
* Use native buttons or focusable equivalents and expose Shift+Space in their keyboard help.
|
|
96
|
+
* Returns the listener cleanup function.
|
|
97
|
+
*/
|
|
98
|
+
function bindVisualItemGestures(root, options) {
|
|
99
|
+
const doc = root.ownerDocument;
|
|
100
|
+
const listeners = new AbortController();
|
|
101
|
+
const capture = { capture: true, signal: listeners.signal };
|
|
102
|
+
const passiveCapture = { ...capture, passive: true };
|
|
103
|
+
boundRoots.add(root);
|
|
104
|
+
let press;
|
|
105
|
+
let pending;
|
|
106
|
+
let suppressClick = false;
|
|
107
|
+
let pointerType = "";
|
|
108
|
+
let overlay;
|
|
109
|
+
function owns(element) {
|
|
110
|
+
for (let node = element; node; node = node.parentElement) {
|
|
111
|
+
if (boundRoots.has(node))
|
|
112
|
+
return node === root;
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
function target(event) {
|
|
117
|
+
const node = event.target;
|
|
118
|
+
if (!node || !("nodeType" in node) || node.nodeType !== 1)
|
|
119
|
+
return null;
|
|
120
|
+
const element = node;
|
|
121
|
+
return owns(element) && !element.closest(excluded) ? element : null;
|
|
122
|
+
}
|
|
123
|
+
function itemFor(element) {
|
|
124
|
+
const item = element.closest(itemSelector);
|
|
125
|
+
const control = element.closest(interactiveControl);
|
|
126
|
+
if (!owns(item) || (control && control !== item && item.contains(control) &&
|
|
127
|
+
!control.hasAttribute("data-visual-activate")))
|
|
128
|
+
return null;
|
|
129
|
+
return item;
|
|
130
|
+
}
|
|
131
|
+
function canToggle(item) {
|
|
132
|
+
return options.onToggle !== undefined && !item.hasAttribute("data-visual-no-toggle");
|
|
133
|
+
}
|
|
134
|
+
function canActivate(item) {
|
|
135
|
+
return options.onActivate !== undefined && !item.hasAttribute("data-visual-no-activate");
|
|
136
|
+
}
|
|
137
|
+
function id(item) {
|
|
138
|
+
return item.getAttribute("data-visual-item") ?? "";
|
|
139
|
+
}
|
|
140
|
+
function clearPending(activate = false) {
|
|
141
|
+
const click = pending;
|
|
142
|
+
pending = undefined;
|
|
143
|
+
if (!click)
|
|
144
|
+
return;
|
|
145
|
+
clearTimeout(click.timer);
|
|
146
|
+
if (activate && owns(click.item) && id(click.item) === click.id && canActivate(click.item)) {
|
|
147
|
+
options.onActivate?.(click.id);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
function clearPress() {
|
|
151
|
+
clearTimeout(press?.hold);
|
|
152
|
+
press = undefined;
|
|
153
|
+
overlay?.remove();
|
|
154
|
+
overlay = undefined;
|
|
155
|
+
}
|
|
156
|
+
function onPointerDown(event) {
|
|
157
|
+
if (!event.isPrimary || event.button !== 0 || isModified(event))
|
|
158
|
+
return;
|
|
159
|
+
const element = target(event);
|
|
160
|
+
if (!element)
|
|
161
|
+
return;
|
|
162
|
+
clearPress();
|
|
163
|
+
suppressClick = false;
|
|
164
|
+
pointerType = event.pointerType;
|
|
165
|
+
const item = itemFor(element);
|
|
166
|
+
const surface = element.closest(surfaceSelector);
|
|
167
|
+
const rectangle = options.onAdd && owns(surface) &&
|
|
168
|
+
!element.closest("[draggable=true]") &&
|
|
169
|
+
(item
|
|
170
|
+
? item.hasAttribute("data-visual-selection-start")
|
|
171
|
+
: !element.closest(interactiveControl));
|
|
172
|
+
if (!item && !rectangle)
|
|
173
|
+
return;
|
|
174
|
+
const active = {
|
|
175
|
+
pointerId: event.pointerId,
|
|
176
|
+
pointerType: event.pointerType,
|
|
177
|
+
start: point(event),
|
|
178
|
+
item,
|
|
179
|
+
surface: rectangle ? surface : null,
|
|
180
|
+
drawing: false,
|
|
181
|
+
};
|
|
182
|
+
press = active;
|
|
183
|
+
if (item && canToggle(item)) {
|
|
184
|
+
const pressedId = id(item);
|
|
185
|
+
active.hold = setTimeout(() => {
|
|
186
|
+
if (press !== active || !owns(item) || id(item) !== pressedId || !canToggle(item))
|
|
187
|
+
return;
|
|
188
|
+
clearPending();
|
|
189
|
+
suppressClick = true;
|
|
190
|
+
options.onToggle?.(pressedId);
|
|
191
|
+
}, holdDelay);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function onPointerMove(event) {
|
|
195
|
+
if (!press || event.pointerId !== press.pointerId)
|
|
196
|
+
return;
|
|
197
|
+
const end = point(event);
|
|
198
|
+
const dx = Math.abs(end.x - press.start.x);
|
|
199
|
+
const dy = Math.abs(end.y - press.start.y);
|
|
200
|
+
if (!press.drawing && Math.max(dx, dy) < movementThreshold)
|
|
201
|
+
return;
|
|
202
|
+
clearTimeout(press.hold);
|
|
203
|
+
if (!press.drawing && (suppressClick || !press.surface ||
|
|
204
|
+
(press.pointerType === "touch" && dx <= dy))) {
|
|
205
|
+
suppressClick = true;
|
|
206
|
+
clearPress();
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
event.preventDefault();
|
|
210
|
+
if (!press.surface)
|
|
211
|
+
return;
|
|
212
|
+
if (!press.drawing) {
|
|
213
|
+
press.drawing = true;
|
|
214
|
+
clearPending();
|
|
215
|
+
overlay = doc.createElement("div");
|
|
216
|
+
overlay.setAttribute("aria-hidden", "true");
|
|
217
|
+
Object.assign(overlay.style, {
|
|
218
|
+
position: "fixed",
|
|
219
|
+
pointerEvents: "none",
|
|
220
|
+
zIndex: "2147483647",
|
|
221
|
+
boxSizing: "border-box",
|
|
222
|
+
border: "1px solid Highlight",
|
|
223
|
+
background: "color-mix(in srgb, Highlight 15%, transparent)",
|
|
224
|
+
});
|
|
225
|
+
doc.body.append(overlay);
|
|
226
|
+
}
|
|
227
|
+
const rect = selectionRect(press.start, end, press.surface);
|
|
228
|
+
if (!overlay)
|
|
229
|
+
return;
|
|
230
|
+
overlay.hidden = !rect;
|
|
231
|
+
if (!rect)
|
|
232
|
+
return;
|
|
233
|
+
Object.assign(overlay.style, {
|
|
234
|
+
left: `${rect.left}px`,
|
|
235
|
+
top: `${rect.top}px`,
|
|
236
|
+
width: `${rect.width}px`,
|
|
237
|
+
height: `${rect.height}px`,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
function onPointerUp(event) {
|
|
241
|
+
if (!press || event.pointerId !== press.pointerId)
|
|
242
|
+
return;
|
|
243
|
+
const { drawing, surface, start } = press;
|
|
244
|
+
clearPress();
|
|
245
|
+
if (!drawing || !surface || !owns(surface))
|
|
246
|
+
return;
|
|
247
|
+
suppressClick = true;
|
|
248
|
+
const rect = selectionRect(start, point(event), surface);
|
|
249
|
+
if (!rect)
|
|
250
|
+
return;
|
|
251
|
+
const matches = new Set();
|
|
252
|
+
const scrollports = new Map();
|
|
253
|
+
for (const item of surface.querySelectorAll(itemSelector)) {
|
|
254
|
+
if (!owns(item) || item.closest(surfaceSelector) !== surface ||
|
|
255
|
+
item.hasAttribute("data-visual-no-toggle") || item.closest(excluded))
|
|
256
|
+
continue;
|
|
257
|
+
const visibility = doc.defaultView?.getComputedStyle?.(item).visibility;
|
|
258
|
+
if (visibility === "hidden" || visibility === "collapse")
|
|
259
|
+
continue;
|
|
260
|
+
const visibleRect = clipToScrollports(rect, item.parentElement, surface, scrollports);
|
|
261
|
+
if (!visibleRect)
|
|
262
|
+
continue;
|
|
263
|
+
const bounds = options.getItemBounds?.(item) ?? item.getBoundingClientRect();
|
|
264
|
+
if (intersects(bounds, visibleRect) && (options.intersectsItem?.(item, visibleRect) ?? true)) {
|
|
265
|
+
matches.add(id(item));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (matches.size > 0)
|
|
269
|
+
options.onAdd?.([...matches]);
|
|
270
|
+
}
|
|
271
|
+
function onCancel(event) {
|
|
272
|
+
if (!press || ("pointerId" in event && event.pointerId !== press.pointerId))
|
|
273
|
+
return;
|
|
274
|
+
suppressClick = true;
|
|
275
|
+
clearPress();
|
|
276
|
+
}
|
|
277
|
+
function onDragStart(event) {
|
|
278
|
+
const element = target(event);
|
|
279
|
+
if (press?.surface && element?.localName === "img" &&
|
|
280
|
+
!element.closest("[draggable=true], a[href], [role=link]")) {
|
|
281
|
+
event.preventDefault();
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
onCancel(event);
|
|
285
|
+
}
|
|
286
|
+
function consume(event) {
|
|
287
|
+
event.preventDefault();
|
|
288
|
+
event.stopPropagation();
|
|
289
|
+
}
|
|
290
|
+
function onClick(event) {
|
|
291
|
+
const element = target(event);
|
|
292
|
+
if (!element)
|
|
293
|
+
return;
|
|
294
|
+
const immediate = element.closest("[data-visual-immediate-activate]");
|
|
295
|
+
if (immediate) {
|
|
296
|
+
// The native control owns activation. Discard its row's pending click
|
|
297
|
+
// before that control receives the event.
|
|
298
|
+
if (pending && immediate.closest(itemSelector) === pending.item)
|
|
299
|
+
clearPending();
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
const item = itemFor(element);
|
|
303
|
+
if (isModified(event)) {
|
|
304
|
+
if (item)
|
|
305
|
+
clearPending();
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
if (event.detail > 0 && suppressClick && (item || element.closest(surfaceSelector))) {
|
|
309
|
+
consume(event);
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
if (!item || (!canActivate(item) && !canToggle(item)))
|
|
313
|
+
return;
|
|
314
|
+
consume(event);
|
|
315
|
+
if (event.detail === 0 || pointerType === "touch" || !canToggle(item)) {
|
|
316
|
+
clearPending(pending?.item !== item);
|
|
317
|
+
if (canActivate(item))
|
|
318
|
+
options.onActivate?.(id(item));
|
|
319
|
+
}
|
|
320
|
+
else if (pending?.item === item && pending.id === id(item)) {
|
|
321
|
+
clearPending();
|
|
322
|
+
options.onToggle?.(id(item));
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
clearPending(true);
|
|
326
|
+
pending = {
|
|
327
|
+
item,
|
|
328
|
+
id: id(item),
|
|
329
|
+
timer: setTimeout(() => clearPending(true), ordinaryClickDelay),
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
function onKeyDown(event) {
|
|
334
|
+
const element = target(event);
|
|
335
|
+
if (!element)
|
|
336
|
+
return;
|
|
337
|
+
if (event.key !== "Enter" && event.key !== " ")
|
|
338
|
+
return;
|
|
339
|
+
const item = itemFor(element);
|
|
340
|
+
if (!item)
|
|
341
|
+
return;
|
|
342
|
+
if (event.key === " " && event.shiftKey && !event.altKey && !event.ctrlKey &&
|
|
343
|
+
!event.metaKey && canToggle(item)) {
|
|
344
|
+
consume(event);
|
|
345
|
+
clearPending();
|
|
346
|
+
if (!event.repeat)
|
|
347
|
+
options.onToggle?.(id(item));
|
|
348
|
+
}
|
|
349
|
+
else if (!isModified(event) && !element.closest(nativeControl) && canActivate(item)) {
|
|
350
|
+
consume(event);
|
|
351
|
+
clearPending(pending?.item !== item);
|
|
352
|
+
if (!event.repeat)
|
|
353
|
+
options.onActivate?.(id(item));
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
root.addEventListener("pointerdown", onPointerDown, passiveCapture);
|
|
357
|
+
doc.addEventListener("pointerdown", (event) => {
|
|
358
|
+
if (!press || event.isPrimary || event.pointerType !== "touch")
|
|
359
|
+
return;
|
|
360
|
+
suppressClick = true;
|
|
361
|
+
clearPress();
|
|
362
|
+
clearPending();
|
|
363
|
+
}, passiveCapture);
|
|
364
|
+
doc.addEventListener("pointermove", onPointerMove, capture);
|
|
365
|
+
doc.addEventListener("pointerup", onPointerUp, passiveCapture);
|
|
366
|
+
doc.addEventListener("pointercancel", onCancel, passiveCapture);
|
|
367
|
+
doc.addEventListener("dragstart", onDragStart, capture);
|
|
368
|
+
root.addEventListener("click", onClick, capture);
|
|
369
|
+
root.addEventListener("keydown", onKeyDown, capture);
|
|
370
|
+
doc.addEventListener("keydown", (event) => {
|
|
371
|
+
if (event.key !== "Escape" || !press?.drawing)
|
|
372
|
+
return;
|
|
373
|
+
consume(event);
|
|
374
|
+
suppressClick = true;
|
|
375
|
+
clearPress();
|
|
376
|
+
}, capture);
|
|
377
|
+
root.addEventListener("contextmenu", (event) => {
|
|
378
|
+
if (press?.pointerType !== "mouse" && press?.item && canToggle(press.item)) {
|
|
379
|
+
event.preventDefault();
|
|
380
|
+
}
|
|
381
|
+
}, capture);
|
|
382
|
+
root.addEventListener("selectstart", (event) => {
|
|
383
|
+
if (press?.surface)
|
|
384
|
+
event.preventDefault();
|
|
385
|
+
}, capture);
|
|
386
|
+
doc.defaultView?.addEventListener("blur", () => {
|
|
387
|
+
clearPress();
|
|
388
|
+
clearPending();
|
|
389
|
+
}, { signal: listeners.signal });
|
|
390
|
+
return () => {
|
|
391
|
+
listeners.abort();
|
|
392
|
+
boundRoots.delete(root);
|
|
393
|
+
clearPress();
|
|
394
|
+
clearPending();
|
|
395
|
+
};
|
|
396
|
+
}
|
|
@@ -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,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.visualItemProps = visualItemProps;
|
|
4
|
+
/** Attributes for a focusable visual item with independent activation and context gestures. */
|
|
5
|
+
function visualItemProps({ id, activation, pressed, selectionStart = pressed !== undefined, }) {
|
|
6
|
+
const canToggle = pressed !== undefined;
|
|
7
|
+
const interactive = activation !== undefined || canToggle;
|
|
8
|
+
return {
|
|
9
|
+
"data-visual-item": interactive ? id : undefined,
|
|
10
|
+
"data-visual-no-activate": activation ? undefined : "",
|
|
11
|
+
"data-visual-no-toggle": canToggle ? undefined : "",
|
|
12
|
+
"data-visual-selection-start": selectionStart ? "" : undefined,
|
|
13
|
+
role: interactive ? "button" : undefined,
|
|
14
|
+
tabIndex: interactive ? 0 : undefined,
|
|
15
|
+
"aria-label": activation?.label,
|
|
16
|
+
"aria-pressed": pressed,
|
|
17
|
+
"aria-keyshortcuts": canToggle ? "Shift+Space" : undefined,
|
|
18
|
+
"aria-expanded": activation?.expanded,
|
|
19
|
+
"aria-controls": activation?.controls,
|
|
20
|
+
title: activation?.label,
|
|
21
|
+
};
|
|
22
|
+
}
|