@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.
Files changed (58) hide show
  1. package/dist/Divider.cjs +33 -36
  2. package/dist/Divider.js +28 -34
  3. package/dist/Icon.cjs +39 -38
  4. package/dist/Icon.js +36 -38
  5. package/dist/Menu.cjs +506 -575
  6. package/dist/Menu.d.ts +2 -0
  7. package/dist/Menu.js +495 -570
  8. package/dist/MenuItem.cjs +314 -344
  9. package/dist/MenuItem.js +303 -339
  10. package/dist/MenuItemGroup.cjs +98 -116
  11. package/dist/MenuItemGroup.js +91 -113
  12. package/dist/SubMenu/InlineSubMenuList.cjs +58 -82
  13. package/dist/SubMenu/InlineSubMenuList.js +54 -81
  14. package/dist/SubMenu/PopupTrigger.cjs +133 -167
  15. package/dist/SubMenu/PopupTrigger.d.ts +2 -2
  16. package/dist/SubMenu/PopupTrigger.js +126 -165
  17. package/dist/SubMenu/SubMenuList.cjs +18 -26
  18. package/dist/SubMenu/SubMenuList.js +14 -25
  19. package/dist/SubMenu/index.cjs +479 -526
  20. package/dist/SubMenu/index.js +469 -521
  21. package/dist/_virtual/rolldown_runtime.cjs +21 -0
  22. package/dist/context/IdContext.cjs +15 -23
  23. package/dist/context/IdContext.js +15 -27
  24. package/dist/context/MenuContext.cjs +183 -174
  25. package/dist/context/MenuContext.js +180 -177
  26. package/dist/context/PathContext.cjs +54 -79
  27. package/dist/context/PathContext.js +54 -90
  28. package/dist/context/PrivateContext.cjs +11 -17
  29. package/dist/context/PrivateContext.js +11 -20
  30. package/dist/hooks/useAccessibility.cjs +171 -191
  31. package/dist/hooks/useAccessibility.js +168 -193
  32. package/dist/hooks/useActive.cjs +25 -28
  33. package/dist/hooks/useActive.js +23 -28
  34. package/dist/hooks/useDirectionStyle.cjs +11 -17
  35. package/dist/hooks/useDirectionStyle.js +9 -17
  36. package/dist/hooks/useKeyRecords.cjs +70 -88
  37. package/dist/hooks/useKeyRecords.js +68 -89
  38. package/dist/hooks/useMemoCallback.cjs +9 -9
  39. package/dist/hooks/useMemoCallback.js +7 -9
  40. package/dist/index.cjs +21 -21
  41. package/dist/index.d.ts +2 -2
  42. package/dist/index.js +12 -20
  43. package/dist/interface.cjs +0 -1
  44. package/dist/interface.js +0 -1
  45. package/dist/placements.cjs +70 -70
  46. package/dist/placements.js +69 -72
  47. package/dist/utils/commonUtil.cjs +24 -26
  48. package/dist/utils/commonUtil.js +23 -26
  49. package/dist/utils/motionUtil.cjs +2 -9
  50. package/dist/utils/motionUtil.js +3 -10
  51. package/dist/utils/nodeUtil.cjs +49 -77
  52. package/dist/utils/nodeUtil.d.ts +4 -1
  53. package/dist/utils/nodeUtil.js +48 -77
  54. package/dist/utils/timeUtil.cjs +2 -3
  55. package/dist/utils/timeUtil.js +3 -4
  56. package/dist/utils/warnUtil.cjs +8 -14
  57. package/dist/utils/warnUtil.js +7 -14
  58. package/package.json +2 -2
@@ -1,24 +1,18 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const vue = require("vue");
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
- vue.provide(PrivateContextKey, context);
5
+ (0, vue.provide)(PrivateContextKey, context);
7
6
  }
8
7
  function usePrivateContext() {
9
- return vue.inject(PrivateContextKey, {});
8
+ return (0, vue.inject)(PrivateContextKey, {});
10
9
  }
11
- const PrivateContextProvider = vue.defineComponent(
12
- (props, { slots }) => {
13
- usePrivateProvider(props);
14
- return () => {
15
- return slots?.default?.();
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, provide, inject } from "vue";
2
- const PrivateContextKey = Symbol("PrivateContext");
1
+ import { defineComponent, inject, provide } from "vue";
2
+ var PrivateContextKey = Symbol("PrivateContext");
3
3
  function usePrivateProvider(context) {
4
- provide(PrivateContextKey, context);
4
+ provide(PrivateContextKey, context);
5
5
  }
6
6
  function usePrivateContext() {
7
- return inject(PrivateContextKey, {});
7
+ return inject(PrivateContextKey, {});
8
8
  }
9
- const PrivateContextProvider = defineComponent(
10
- (props, { slots }) => {
11
- usePrivateProvider(props);
12
- return () => {
13
- return slots?.default?.();
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
- "use strict";
2
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
3
- const KeyCode = require("@v-c/util/dist/KeyCode");
4
- const vue = require("vue");
5
- const IdContext = require("../context/IdContext.cjs");
6
- const { LEFT, RIGHT, UP, DOWN, ENTER, ESC, HOME, END } = KeyCode;
7
- const ArrowKeys = [UP, DOWN, LEFT, RIGHT];
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
- const prev = "prev";
10
- const next = "next";
11
- const children = "children";
12
- const parent = "parent";
13
- if (mode === "inline" && which === ENTER) {
14
- return { inlineTrigger: true };
15
- }
16
- const inline = { [UP]: prev, [DOWN]: next };
17
- const horizontal = {
18
- [LEFT]: isRtl ? next : prev,
19
- [RIGHT]: isRtl ? prev : next,
20
- [DOWN]: children,
21
- [ENTER]: children
22
- };
23
- const vertical = {
24
- [UP]: prev,
25
- [DOWN]: next,
26
- [ENTER]: children,
27
- [ESC]: parent,
28
- [LEFT]: isRtl ? children : parent,
29
- [RIGHT]: isRtl ? parent : children
30
- };
31
- const offsets = {
32
- inline,
33
- horizontal,
34
- vertical,
35
- inlineSub: inline,
36
- horizontalSub: vertical,
37
- verticalSub: vertical
38
- };
39
- const type = offsets[`${mode}${isRootLevel ? "" : "Sub"}`]?.[which];
40
- switch (type) {
41
- case prev:
42
- return { offset: -1, sibling: true };
43
- case next:
44
- return { offset: 1, sibling: true };
45
- case parent:
46
- return { offset: -1, sibling: false };
47
- case children:
48
- return { offset: 1, sibling: false };
49
- default:
50
- return null;
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
- let current = element;
55
- while (current) {
56
- if (current.getAttribute("data-menu-list")) {
57
- return current;
58
- }
59
- current = current.parentElement;
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
- const selector = "[tabindex]";
65
- return Array.from(container.querySelectorAll(selector));
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
- let current = activeElement || document.activeElement;
69
- while (current) {
70
- if (elements.has(current)) {
71
- return current;
72
- }
73
- current = current.parentElement;
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
- if (!container)
79
- return [];
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
- if (!parentQueryContainer) {
85
- return null;
86
- }
87
- const sameLevelFocusableMenuElementList = getFocusableElements(parentQueryContainer, elements);
88
- const count = sameLevelFocusableMenuElementList.length;
89
- let focusIndex = sameLevelFocusableMenuElementList.findIndex((ele) => focusMenuElement === ele);
90
- if (offset < 0) {
91
- if (focusIndex === -1) {
92
- focusIndex = count - 1;
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
- const elements = /* @__PURE__ */ new Set();
104
- const key2element = /* @__PURE__ */ new Map();
105
- const element2key = /* @__PURE__ */ new Map();
106
- keys.forEach((key) => {
107
- const element = document.querySelector(`[data-menu-id='${IdContext.getMenuId(id, key)}']`);
108
- if (element) {
109
- elements.add(element);
110
- element2key.set(element, key);
111
- key2element.set(key, element);
112
- }
113
- });
114
- return { elements, key2element, element2key };
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
- const rafRef = vue.shallowRef();
118
- const activeRef = vue.shallowRef();
119
- const cleanRaf = () => {
120
- if (rafRef.value !== void 0) {
121
- cancelAnimationFrame(rafRef.value);
122
- }
123
- };
124
- vue.onBeforeUnmount(() => {
125
- cleanRaf();
126
- });
127
- return (e) => {
128
- activeRef.value = activeKey.value;
129
- const { which } = e;
130
- if ([...ArrowKeys, ENTER, ESC, HOME, END].includes(which)) {
131
- const keys = getKeys();
132
- let refreshedElements = refreshElements(keys, id);
133
- const { elements, key2element, element2key } = refreshedElements;
134
- const activeElement = key2element.get(activeKey.value);
135
- const focusMenuElement = getFocusElement(activeElement || null, elements);
136
- const focusMenuKey = element2key.get(focusMenuElement);
137
- const offsetObj = getOffset(mode.value, getKeyPath(focusMenuKey, true).length === 1, isRtl.value, which);
138
- if (!offsetObj && which !== HOME && which !== END) {
139
- return;
140
- }
141
- if (ArrowKeys.includes(which) || [HOME, END].includes(which)) {
142
- e.preventDefault();
143
- }
144
- const tryFocus = (menuElement) => {
145
- if (menuElement) {
146
- let focusTargetElement = menuElement;
147
- const link = menuElement.querySelector("a");
148
- if (link?.getAttribute("href")) {
149
- focusTargetElement = link;
150
- }
151
- const targetKey = element2key.get(menuElement);
152
- if (targetKey) {
153
- triggerActiveKey(targetKey);
154
- }
155
- cleanRaf();
156
- rafRef.value = requestAnimationFrame(() => {
157
- if (activeRef.value === targetKey) {
158
- focusTargetElement.focus();
159
- }
160
- });
161
- }
162
- };
163
- if ([HOME, END].includes(which) || offsetObj?.sibling || !focusMenuElement) {
164
- let parentQueryContainer;
165
- if (!focusMenuElement || mode.value === "inline") {
166
- parentQueryContainer = containerRef.value;
167
- } else {
168
- parentQueryContainer = findContainerUL(focusMenuElement);
169
- }
170
- let targetElement;
171
- const focusableElements = getFocusableElements(parentQueryContainer, elements);
172
- if (which === HOME) {
173
- targetElement = focusableElements[0];
174
- } else if (which === END) {
175
- targetElement = focusableElements[focusableElements.length - 1];
176
- } else {
177
- targetElement = getNextFocusElement(
178
- parentQueryContainer,
179
- elements,
180
- focusMenuElement,
181
- offsetObj?.offset
182
- );
183
- }
184
- tryFocus(targetElement);
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;