@v-c/menu 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Divider.cjs +33 -36
- package/dist/Divider.js +28 -34
- package/dist/Icon.cjs +39 -38
- package/dist/Icon.js +36 -38
- package/dist/Menu.cjs +506 -575
- package/dist/Menu.d.ts +2 -0
- package/dist/Menu.js +495 -570
- package/dist/MenuItem.cjs +314 -344
- package/dist/MenuItem.js +303 -339
- package/dist/MenuItemGroup.cjs +98 -116
- package/dist/MenuItemGroup.js +91 -113
- package/dist/SubMenu/InlineSubMenuList.cjs +58 -82
- package/dist/SubMenu/InlineSubMenuList.js +54 -81
- package/dist/SubMenu/PopupTrigger.cjs +133 -167
- package/dist/SubMenu/PopupTrigger.d.ts +2 -2
- package/dist/SubMenu/PopupTrigger.js +126 -165
- package/dist/SubMenu/SubMenuList.cjs +18 -26
- package/dist/SubMenu/SubMenuList.js +14 -25
- package/dist/SubMenu/index.cjs +479 -526
- package/dist/SubMenu/index.js +469 -521
- package/dist/_virtual/rolldown_runtime.cjs +21 -0
- package/dist/context/IdContext.cjs +15 -23
- package/dist/context/IdContext.js +15 -27
- package/dist/context/MenuContext.cjs +183 -174
- package/dist/context/MenuContext.js +180 -177
- package/dist/context/PathContext.cjs +54 -79
- package/dist/context/PathContext.js +54 -90
- package/dist/context/PrivateContext.cjs +11 -17
- package/dist/context/PrivateContext.js +11 -20
- package/dist/hooks/useAccessibility.cjs +171 -191
- package/dist/hooks/useAccessibility.js +168 -193
- package/dist/hooks/useActive.cjs +25 -28
- package/dist/hooks/useActive.js +23 -28
- package/dist/hooks/useDirectionStyle.cjs +11 -17
- package/dist/hooks/useDirectionStyle.js +9 -17
- package/dist/hooks/useKeyRecords.cjs +70 -88
- package/dist/hooks/useKeyRecords.js +68 -89
- package/dist/hooks/useMemoCallback.cjs +9 -9
- package/dist/hooks/useMemoCallback.js +7 -9
- package/dist/index.cjs +21 -21
- package/dist/index.d.ts +2 -2
- package/dist/index.js +12 -20
- package/dist/interface.cjs +0 -1
- package/dist/interface.js +0 -1
- package/dist/placements.cjs +70 -70
- package/dist/placements.js +69 -72
- package/dist/utils/commonUtil.cjs +24 -26
- package/dist/utils/commonUtil.js +23 -26
- package/dist/utils/motionUtil.cjs +2 -9
- package/dist/utils/motionUtil.js +3 -10
- package/dist/utils/nodeUtil.cjs +49 -77
- package/dist/utils/nodeUtil.d.ts +4 -1
- package/dist/utils/nodeUtil.js +48 -77
- package/dist/utils/timeUtil.cjs +2 -3
- package/dist/utils/timeUtil.js +3 -4
- package/dist/utils/warnUtil.cjs +8 -14
- package/dist/utils/warnUtil.js +7 -14
- package/package.json +2 -2
|
@@ -1,24 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const PrivateContextKey = Symbol("PrivateContext");
|
|
1
|
+
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
2
|
+
let vue = require("vue");
|
|
3
|
+
var PrivateContextKey = Symbol("PrivateContext");
|
|
5
4
|
function usePrivateProvider(context) {
|
|
6
|
-
|
|
5
|
+
(0, vue.provide)(PrivateContextKey, context);
|
|
7
6
|
}
|
|
8
7
|
function usePrivateContext() {
|
|
9
|
-
|
|
8
|
+
return (0, vue.inject)(PrivateContextKey, {});
|
|
10
9
|
}
|
|
11
|
-
const PrivateContextProvider = vue.defineComponent(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
props: ["_internalRenderMenuItem", "_internalRenderSubMenuItem"]
|
|
20
|
-
}
|
|
21
|
-
);
|
|
10
|
+
const PrivateContextProvider = (0, vue.defineComponent)((props, { slots }) => {
|
|
11
|
+
usePrivateProvider(props);
|
|
12
|
+
return () => {
|
|
13
|
+
return slots?.default?.();
|
|
14
|
+
};
|
|
15
|
+
}, { props: ["_internalRenderMenuItem", "_internalRenderSubMenuItem"] });
|
|
22
16
|
exports.PrivateContextProvider = PrivateContextProvider;
|
|
23
17
|
exports.usePrivateContext = usePrivateContext;
|
|
24
18
|
exports.usePrivateProvider = usePrivateProvider;
|
|
@@ -1,24 +1,15 @@
|
|
|
1
|
-
import { defineComponent,
|
|
2
|
-
|
|
1
|
+
import { defineComponent, inject, provide } from "vue";
|
|
2
|
+
var PrivateContextKey = Symbol("PrivateContext");
|
|
3
3
|
function usePrivateProvider(context) {
|
|
4
|
-
|
|
4
|
+
provide(PrivateContextKey, context);
|
|
5
5
|
}
|
|
6
6
|
function usePrivateContext() {
|
|
7
|
-
|
|
7
|
+
return inject(PrivateContextKey, {});
|
|
8
8
|
}
|
|
9
|
-
const PrivateContextProvider = defineComponent(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
{
|
|
17
|
-
props: ["_internalRenderMenuItem", "_internalRenderSubMenuItem"]
|
|
18
|
-
}
|
|
19
|
-
);
|
|
20
|
-
export {
|
|
21
|
-
PrivateContextProvider,
|
|
22
|
-
usePrivateContext,
|
|
23
|
-
usePrivateProvider
|
|
24
|
-
};
|
|
9
|
+
const PrivateContextProvider = defineComponent((props, { slots }) => {
|
|
10
|
+
usePrivateProvider(props);
|
|
11
|
+
return () => {
|
|
12
|
+
return slots?.default?.();
|
|
13
|
+
};
|
|
14
|
+
}, { props: ["_internalRenderMenuItem", "_internalRenderSubMenuItem"] });
|
|
15
|
+
export { PrivateContextProvider, usePrivateContext, usePrivateProvider };
|
|
@@ -1,209 +1,189 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
3
|
+
const require_IdContext = require("../context/IdContext.cjs");
|
|
4
|
+
let vue = require("vue");
|
|
5
|
+
let __v_c_util_dist_KeyCode = require("@v-c/util/dist/KeyCode");
|
|
6
|
+
__v_c_util_dist_KeyCode = require_rolldown_runtime.__toESM(__v_c_util_dist_KeyCode);
|
|
7
|
+
var { LEFT, RIGHT, UP, DOWN, ENTER, ESC, HOME, END } = __v_c_util_dist_KeyCode.default;
|
|
8
|
+
var ArrowKeys = [
|
|
9
|
+
UP,
|
|
10
|
+
DOWN,
|
|
11
|
+
LEFT,
|
|
12
|
+
RIGHT
|
|
13
|
+
];
|
|
8
14
|
function getOffset(mode, isRootLevel, isRtl, which) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
15
|
+
const prev = "prev";
|
|
16
|
+
const next = "next";
|
|
17
|
+
const children = "children";
|
|
18
|
+
const parent = "parent";
|
|
19
|
+
if (mode === "inline" && which === ENTER) return { inlineTrigger: true };
|
|
20
|
+
const inline = {
|
|
21
|
+
[UP]: prev,
|
|
22
|
+
[DOWN]: next
|
|
23
|
+
};
|
|
24
|
+
const horizontal = {
|
|
25
|
+
[LEFT]: isRtl ? next : prev,
|
|
26
|
+
[RIGHT]: isRtl ? prev : next,
|
|
27
|
+
[DOWN]: children,
|
|
28
|
+
[ENTER]: children
|
|
29
|
+
};
|
|
30
|
+
const vertical = {
|
|
31
|
+
[UP]: prev,
|
|
32
|
+
[DOWN]: next,
|
|
33
|
+
[ENTER]: children,
|
|
34
|
+
[ESC]: parent,
|
|
35
|
+
[LEFT]: isRtl ? children : parent,
|
|
36
|
+
[RIGHT]: isRtl ? parent : children
|
|
37
|
+
};
|
|
38
|
+
switch ({
|
|
39
|
+
inline,
|
|
40
|
+
horizontal,
|
|
41
|
+
vertical,
|
|
42
|
+
inlineSub: inline,
|
|
43
|
+
horizontalSub: vertical,
|
|
44
|
+
verticalSub: vertical
|
|
45
|
+
}[`${mode}${isRootLevel ? "" : "Sub"}`]?.[which]) {
|
|
46
|
+
case prev: return {
|
|
47
|
+
offset: -1,
|
|
48
|
+
sibling: true
|
|
49
|
+
};
|
|
50
|
+
case next: return {
|
|
51
|
+
offset: 1,
|
|
52
|
+
sibling: true
|
|
53
|
+
};
|
|
54
|
+
case parent: return {
|
|
55
|
+
offset: -1,
|
|
56
|
+
sibling: false
|
|
57
|
+
};
|
|
58
|
+
case children: return {
|
|
59
|
+
offset: 1,
|
|
60
|
+
sibling: false
|
|
61
|
+
};
|
|
62
|
+
default: return null;
|
|
63
|
+
}
|
|
52
64
|
}
|
|
53
65
|
function findContainerUL(element) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
66
|
+
let current = element;
|
|
67
|
+
while (current) {
|
|
68
|
+
if (current.getAttribute("data-menu-list")) return current;
|
|
69
|
+
current = current.parentElement;
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
62
72
|
}
|
|
63
73
|
function getFocusNodeList(container, includeDisabled) {
|
|
64
|
-
|
|
65
|
-
|
|
74
|
+
const selector = includeDisabled ? "[tabindex]" : "[tabindex]:not([tabindex=\"-1\"]):not([disabled]):not([aria-disabled=\"true\"])";
|
|
75
|
+
return Array.from(container.querySelectorAll(selector));
|
|
66
76
|
}
|
|
67
77
|
function getFocusElement(activeElement, elements) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
return null;
|
|
78
|
+
let current = activeElement || document.activeElement;
|
|
79
|
+
while (current) {
|
|
80
|
+
if (elements.has(current)) return current;
|
|
81
|
+
current = current.parentElement;
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
76
84
|
}
|
|
77
85
|
function getFocusableElements(container, elements) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const list = getFocusNodeList(container);
|
|
81
|
-
return list.filter((ele) => elements.has(ele));
|
|
86
|
+
if (!container) return [];
|
|
87
|
+
return getFocusNodeList(container, true).filter((ele) => elements.has(ele));
|
|
82
88
|
}
|
|
83
89
|
function getNextFocusElement(parentQueryContainer, elements, focusMenuElement, offset = 1) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
} else {
|
|
94
|
-
focusIndex -= 1;
|
|
95
|
-
}
|
|
96
|
-
} else if (offset > 0) {
|
|
97
|
-
focusIndex += 1;
|
|
98
|
-
}
|
|
99
|
-
focusIndex = (focusIndex + count) % count;
|
|
100
|
-
return sameLevelFocusableMenuElementList[focusIndex];
|
|
90
|
+
if (!parentQueryContainer) return null;
|
|
91
|
+
const sameLevelFocusableMenuElementList = getFocusableElements(parentQueryContainer, elements);
|
|
92
|
+
const count = sameLevelFocusableMenuElementList.length;
|
|
93
|
+
let focusIndex = sameLevelFocusableMenuElementList.findIndex((ele) => focusMenuElement === ele);
|
|
94
|
+
if (offset < 0) if (focusIndex === -1) focusIndex = count - 1;
|
|
95
|
+
else focusIndex -= 1;
|
|
96
|
+
else if (offset > 0) focusIndex += 1;
|
|
97
|
+
focusIndex = (focusIndex + count) % count;
|
|
98
|
+
return sameLevelFocusableMenuElementList[focusIndex];
|
|
101
99
|
}
|
|
102
100
|
function refreshElements(keys, id) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
101
|
+
const elements = /* @__PURE__ */ new Set();
|
|
102
|
+
const key2element = /* @__PURE__ */ new Map();
|
|
103
|
+
const element2key = /* @__PURE__ */ new Map();
|
|
104
|
+
keys.forEach((key) => {
|
|
105
|
+
const element = document.querySelector(`[data-menu-id='${require_IdContext.getMenuId(id, key)}']`);
|
|
106
|
+
if (element) {
|
|
107
|
+
elements.add(element);
|
|
108
|
+
element2key.set(element, key);
|
|
109
|
+
key2element.set(key, element);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
return {
|
|
113
|
+
elements,
|
|
114
|
+
key2element,
|
|
115
|
+
element2key
|
|
116
|
+
};
|
|
115
117
|
}
|
|
116
118
|
function useAccessibility(mode, activeKey, isRtl, id, containerRef, getKeys, getKeyPath, triggerActiveKey, triggerAccessibilityOpen, originOnKeyDown) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
} else if (offsetObj.inlineTrigger) {
|
|
186
|
-
triggerAccessibilityOpen(focusMenuKey);
|
|
187
|
-
} else if (offsetObj.offset > 0) {
|
|
188
|
-
triggerAccessibilityOpen(focusMenuKey, true);
|
|
189
|
-
cleanRaf();
|
|
190
|
-
rafRef.value = requestAnimationFrame(() => {
|
|
191
|
-
refreshedElements = refreshElements(keys, id);
|
|
192
|
-
const controlId = focusMenuElement.getAttribute("aria-controls");
|
|
193
|
-
const subQueryContainer = controlId ? document.getElementById(controlId) : null;
|
|
194
|
-
const targetElement = getNextFocusElement(subQueryContainer, refreshedElements.elements);
|
|
195
|
-
tryFocus(targetElement);
|
|
196
|
-
});
|
|
197
|
-
} else if (offsetObj.offset < 0) {
|
|
198
|
-
const keyPath = getKeyPath(focusMenuKey, true);
|
|
199
|
-
const parentKey = keyPath[keyPath.length - 2];
|
|
200
|
-
const parentMenuElement = key2element.get(parentKey);
|
|
201
|
-
triggerAccessibilityOpen(parentKey, false);
|
|
202
|
-
tryFocus(parentMenuElement);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
originOnKeyDown?.(e);
|
|
206
|
-
};
|
|
119
|
+
const rafRef = (0, vue.shallowRef)();
|
|
120
|
+
const activeRef = (0, vue.shallowRef)();
|
|
121
|
+
const cleanRaf = () => {
|
|
122
|
+
if (rafRef.value !== void 0) cancelAnimationFrame(rafRef.value);
|
|
123
|
+
};
|
|
124
|
+
(0, vue.onBeforeUnmount)(() => {
|
|
125
|
+
cleanRaf();
|
|
126
|
+
});
|
|
127
|
+
return (e) => {
|
|
128
|
+
activeRef.value = activeKey.value;
|
|
129
|
+
const { which } = e;
|
|
130
|
+
if ([
|
|
131
|
+
...ArrowKeys,
|
|
132
|
+
ENTER,
|
|
133
|
+
ESC,
|
|
134
|
+
HOME,
|
|
135
|
+
END
|
|
136
|
+
].includes(which)) {
|
|
137
|
+
const keys = getKeys();
|
|
138
|
+
let refreshedElements = refreshElements(keys, id);
|
|
139
|
+
const { elements, key2element, element2key } = refreshedElements;
|
|
140
|
+
const focusMenuElement = getFocusElement(key2element.get(activeKey.value) || null, elements);
|
|
141
|
+
const focusMenuKey = element2key.get(focusMenuElement);
|
|
142
|
+
const offsetObj = getOffset(mode.value, getKeyPath(focusMenuKey, true).length === 1, isRtl.value, which);
|
|
143
|
+
if (!offsetObj && which !== HOME && which !== END) return;
|
|
144
|
+
if (ArrowKeys.includes(which) || [HOME, END].includes(which)) e.preventDefault();
|
|
145
|
+
const tryFocus = (menuElement) => {
|
|
146
|
+
if (menuElement) {
|
|
147
|
+
let focusTargetElement = menuElement;
|
|
148
|
+
const link = menuElement.querySelector("a");
|
|
149
|
+
if (link?.getAttribute("href")) focusTargetElement = link;
|
|
150
|
+
const targetKey = element2key.get(menuElement);
|
|
151
|
+
if (targetKey) triggerActiveKey(targetKey);
|
|
152
|
+
cleanRaf();
|
|
153
|
+
rafRef.value = requestAnimationFrame(() => {
|
|
154
|
+
if (activeRef.value === targetKey) focusTargetElement.focus();
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
if ([HOME, END].includes(which) || offsetObj?.sibling || !focusMenuElement) {
|
|
159
|
+
let parentQueryContainer;
|
|
160
|
+
if (!focusMenuElement || mode.value === "inline") parentQueryContainer = containerRef.value;
|
|
161
|
+
else parentQueryContainer = findContainerUL(focusMenuElement);
|
|
162
|
+
let targetElement;
|
|
163
|
+
const focusableElements = getFocusableElements(parentQueryContainer, elements);
|
|
164
|
+
if (which === HOME) targetElement = focusableElements[0];
|
|
165
|
+
else if (which === END) targetElement = focusableElements[focusableElements.length - 1];
|
|
166
|
+
else targetElement = getNextFocusElement(parentQueryContainer, elements, focusMenuElement, offsetObj?.offset);
|
|
167
|
+
tryFocus(targetElement);
|
|
168
|
+
} else if (offsetObj.inlineTrigger) triggerAccessibilityOpen(focusMenuKey);
|
|
169
|
+
else if (offsetObj.offset > 0) {
|
|
170
|
+
triggerAccessibilityOpen(focusMenuKey, true);
|
|
171
|
+
cleanRaf();
|
|
172
|
+
rafRef.value = requestAnimationFrame(() => {
|
|
173
|
+
refreshedElements = refreshElements(keys, id);
|
|
174
|
+
const controlId = focusMenuElement.getAttribute("aria-controls");
|
|
175
|
+
tryFocus(getNextFocusElement(controlId ? document.getElementById(controlId) : null, refreshedElements.elements));
|
|
176
|
+
});
|
|
177
|
+
} else if (offsetObj.offset < 0) {
|
|
178
|
+
const keyPath = getKeyPath(focusMenuKey, true);
|
|
179
|
+
const parentKey = keyPath[keyPath.length - 2];
|
|
180
|
+
const parentMenuElement = key2element.get(parentKey);
|
|
181
|
+
triggerAccessibilityOpen(parentKey, false);
|
|
182
|
+
tryFocus(parentMenuElement);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
originOnKeyDown?.(e);
|
|
186
|
+
};
|
|
207
187
|
}
|
|
208
188
|
exports.default = useAccessibility;
|
|
209
189
|
exports.getFocusableElements = getFocusableElements;
|