@zag-js/menubar 2.0.0-next.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Chakra UI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,9 @@
1
+ export { anatomy } from './menubar.anatomy.mjs';
2
+ export { connect } from './menubar.connect.mjs';
3
+ export { machine } from './menubar.machine.mjs';
4
+ export { props, splitProps } from './menubar.props.mjs';
5
+ export { MenubarApi as Api, ElementIds, MenubarMachine as Machine, MenuCloseReason, MenubarEventMap, MenubarMenuContext, MenubarProps as Props, MenubarService as Service } from './menubar.types.mjs';
6
+ export { Orientation } from '@zag-js/types';
7
+ import '@zag-js/anatomy';
8
+ import '@zag-js/core';
9
+ import '@zag-js/dom-query';
@@ -0,0 +1,9 @@
1
+ export { anatomy } from './menubar.anatomy.js';
2
+ export { connect } from './menubar.connect.js';
3
+ export { machine } from './menubar.machine.js';
4
+ export { props, splitProps } from './menubar.props.js';
5
+ export { MenubarApi as Api, ElementIds, MenubarMachine as Machine, MenuCloseReason, MenubarEventMap, MenubarMenuContext, MenubarProps as Props, MenubarService as Service } from './menubar.types.js';
6
+ export { Orientation } from '@zag-js/types';
7
+ import '@zag-js/anatomy';
8
+ import '@zag-js/core';
9
+ import '@zag-js/dom-query';
package/dist/index.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ anatomy: () => import_menubar.anatomy,
25
+ connect: () => import_menubar2.connect,
26
+ machine: () => import_menubar3.machine
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+ var import_menubar = require("./menubar.anatomy.js");
30
+ var import_menubar2 = require("./menubar.connect.js");
31
+ var import_menubar3 = require("./menubar.machine.js");
32
+ __reExport(index_exports, require("./menubar.props.js"), module.exports);
33
+ // Annotate the CommonJS export names for ESM import in node:
34
+ 0 && (module.exports = {
35
+ anatomy,
36
+ connect,
37
+ machine,
38
+ ...require("./menubar.props.js")
39
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,10 @@
1
+ // src/index.ts
2
+ import { anatomy } from "./menubar.anatomy.mjs";
3
+ import { connect } from "./menubar.connect.mjs";
4
+ import { machine } from "./menubar.machine.mjs";
5
+ export * from "./menubar.props.mjs";
6
+ export {
7
+ anatomy,
8
+ connect,
9
+ machine
10
+ };
@@ -0,0 +1,6 @@
1
+ import * as _zag_js_anatomy from '@zag-js/anatomy';
2
+
3
+ declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root">;
4
+ declare const parts: Record<"root", _zag_js_anatomy.AnatomyPart>;
5
+
6
+ export { anatomy, parts };
@@ -0,0 +1,6 @@
1
+ import * as _zag_js_anatomy from '@zag-js/anatomy';
2
+
3
+ declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root">;
4
+ declare const parts: Record<"root", _zag_js_anatomy.AnatomyPart>;
5
+
6
+ export { anatomy, parts };
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/menubar.anatomy.ts
21
+ var menubar_anatomy_exports = {};
22
+ __export(menubar_anatomy_exports, {
23
+ anatomy: () => anatomy,
24
+ parts: () => parts
25
+ });
26
+ module.exports = __toCommonJS(menubar_anatomy_exports);
27
+ var import_anatomy = require("@zag-js/anatomy");
28
+ var anatomy = (0, import_anatomy.createAnatomy)("menubar").parts("root");
29
+ var parts = anatomy.build();
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ anatomy,
33
+ parts
34
+ });
@@ -0,0 +1,8 @@
1
+ // src/menubar.anatomy.ts
2
+ import { createAnatomy } from "@zag-js/anatomy";
3
+ var anatomy = createAnatomy("menubar").parts("root");
4
+ var parts = anatomy.build();
5
+ export {
6
+ anatomy,
7
+ parts
8
+ };
@@ -0,0 +1,8 @@
1
+ import { PropTypes, NormalizeProps } from '@zag-js/types';
2
+ import { MenubarService, MenubarApi } from './menubar.types.mjs';
3
+ import '@zag-js/core';
4
+ import '@zag-js/dom-query';
5
+
6
+ declare function connect<T extends PropTypes>(service: MenubarService, normalize: NormalizeProps<T>): MenubarApi<T>;
7
+
8
+ export { connect };
@@ -0,0 +1,8 @@
1
+ import { PropTypes, NormalizeProps } from '@zag-js/types';
2
+ import { MenubarService, MenubarApi } from './menubar.types.js';
3
+ import '@zag-js/core';
4
+ import '@zag-js/dom-query';
5
+
6
+ declare function connect<T extends PropTypes>(service: MenubarService, normalize: NormalizeProps<T>): MenubarApi<T>;
7
+
8
+ export { connect };
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/menubar.connect.ts
31
+ var menubar_connect_exports = {};
32
+ __export(menubar_connect_exports, {
33
+ connect: () => connect
34
+ });
35
+ module.exports = __toCommonJS(menubar_connect_exports);
36
+ var import_dom_query = require("@zag-js/dom-query");
37
+ var import_menubar = require("./menubar.anatomy.js");
38
+ var dom = __toESM(require("./menubar.dom.js"));
39
+ function connect(service, normalize) {
40
+ const { context, send, prop, scope } = service;
41
+ const hasOpenMenu = context.get("hasOpenMenu");
42
+ const activeId = context.get("activeId");
43
+ const orientation = prop("orientation");
44
+ const isHorizontal = orientation === "horizontal";
45
+ const disabled = !!prop("disabled");
46
+ return {
47
+ hasOpenMenu,
48
+ orientation,
49
+ disabled,
50
+ getMenuContext() {
51
+ return { rootId: dom.getRootId(scope), disabled, orientation, activeId };
52
+ },
53
+ getRootProps() {
54
+ return normalize.element({
55
+ ...import_menubar.parts.root.attrs(scope.id),
56
+ id: dom.getRootId(scope),
57
+ role: "menubar",
58
+ dir: prop("dir"),
59
+ "aria-orientation": orientation,
60
+ "data-orientation": orientation,
61
+ "aria-disabled": (0, import_dom_query.ariaAttr)(disabled),
62
+ "data-disabled": (0, import_dom_query.dataAttr)(disabled),
63
+ // Explicit "true"/"false" so menu triggers can read it via `dataset.hasOpenMenu`.
64
+ "data-has-open-menu": hasOpenMenu ? "true" : "false",
65
+ onKeyDown(event) {
66
+ if (event.defaultPrevented || disabled) return;
67
+ const target = (0, import_dom_query.getEventTarget)(event);
68
+ if (!dom.isTriggerEl(target)) return;
69
+ const keyMap = {
70
+ ArrowRight() {
71
+ if (isHorizontal) send({ type: "TRIGGER.FOCUS_NEXT" });
72
+ },
73
+ ArrowLeft() {
74
+ if (isHorizontal) send({ type: "TRIGGER.FOCUS_PREV" });
75
+ },
76
+ ArrowDown() {
77
+ if (!isHorizontal) send({ type: "TRIGGER.FOCUS_NEXT" });
78
+ },
79
+ ArrowUp() {
80
+ if (!isHorizontal) send({ type: "TRIGGER.FOCUS_PREV" });
81
+ },
82
+ Home() {
83
+ send({ type: "TRIGGER.FOCUS_FIRST" });
84
+ },
85
+ End() {
86
+ send({ type: "TRIGGER.FOCUS_LAST" });
87
+ }
88
+ };
89
+ const exec = keyMap[(0, import_dom_query.getEventKey)(event, { dir: prop("dir"), orientation })];
90
+ if (exec) {
91
+ exec(event);
92
+ event.preventDefault();
93
+ return;
94
+ }
95
+ if ((0, import_dom_query.isPrintableKey)(event) && !(0, import_dom_query.isModifierKey)(event)) {
96
+ send({ type: "TYPEAHEAD", key: event.key });
97
+ event.preventDefault();
98
+ }
99
+ }
100
+ });
101
+ }
102
+ };
103
+ }
104
+ // Annotate the CommonJS export names for ESM import in node:
105
+ 0 && (module.exports = {
106
+ connect
107
+ });
@@ -0,0 +1,72 @@
1
+ // src/menubar.connect.ts
2
+ import { ariaAttr, dataAttr, getEventKey, getEventTarget, isModifierKey, isPrintableKey } from "@zag-js/dom-query";
3
+ import { parts } from "./menubar.anatomy.mjs";
4
+ import * as dom from "./menubar.dom.mjs";
5
+ function connect(service, normalize) {
6
+ const { context, send, prop, scope } = service;
7
+ const hasOpenMenu = context.get("hasOpenMenu");
8
+ const activeId = context.get("activeId");
9
+ const orientation = prop("orientation");
10
+ const isHorizontal = orientation === "horizontal";
11
+ const disabled = !!prop("disabled");
12
+ return {
13
+ hasOpenMenu,
14
+ orientation,
15
+ disabled,
16
+ getMenuContext() {
17
+ return { rootId: dom.getRootId(scope), disabled, orientation, activeId };
18
+ },
19
+ getRootProps() {
20
+ return normalize.element({
21
+ ...parts.root.attrs(scope.id),
22
+ id: dom.getRootId(scope),
23
+ role: "menubar",
24
+ dir: prop("dir"),
25
+ "aria-orientation": orientation,
26
+ "data-orientation": orientation,
27
+ "aria-disabled": ariaAttr(disabled),
28
+ "data-disabled": dataAttr(disabled),
29
+ // Explicit "true"/"false" so menu triggers can read it via `dataset.hasOpenMenu`.
30
+ "data-has-open-menu": hasOpenMenu ? "true" : "false",
31
+ onKeyDown(event) {
32
+ if (event.defaultPrevented || disabled) return;
33
+ const target = getEventTarget(event);
34
+ if (!dom.isTriggerEl(target)) return;
35
+ const keyMap = {
36
+ ArrowRight() {
37
+ if (isHorizontal) send({ type: "TRIGGER.FOCUS_NEXT" });
38
+ },
39
+ ArrowLeft() {
40
+ if (isHorizontal) send({ type: "TRIGGER.FOCUS_PREV" });
41
+ },
42
+ ArrowDown() {
43
+ if (!isHorizontal) send({ type: "TRIGGER.FOCUS_NEXT" });
44
+ },
45
+ ArrowUp() {
46
+ if (!isHorizontal) send({ type: "TRIGGER.FOCUS_PREV" });
47
+ },
48
+ Home() {
49
+ send({ type: "TRIGGER.FOCUS_FIRST" });
50
+ },
51
+ End() {
52
+ send({ type: "TRIGGER.FOCUS_LAST" });
53
+ }
54
+ };
55
+ const exec = keyMap[getEventKey(event, { dir: prop("dir"), orientation })];
56
+ if (exec) {
57
+ exec(event);
58
+ event.preventDefault();
59
+ return;
60
+ }
61
+ if (isPrintableKey(event) && !isModifierKey(event)) {
62
+ send({ type: "TYPEAHEAD", key: event.key });
63
+ event.preventDefault();
64
+ }
65
+ }
66
+ });
67
+ }
68
+ };
69
+ }
70
+ export {
71
+ connect
72
+ };
@@ -0,0 +1,18 @@
1
+ import { Scope } from '@zag-js/core';
2
+
3
+ declare const getRootId: (ctx: Scope) => any;
4
+ declare const getRootEl: (ctx: Scope) => HTMLElement | null;
5
+ /**
6
+ * The menubar's items are the menu triggers rendered inside it. Because menus are
7
+ * portalled, only the top-level triggers (role=menuitem) live within the root subtree.
8
+ */
9
+ declare const getTriggerEls: (ctx: Scope) => HTMLElement[];
10
+ declare const isTriggerEl: (el: EventTarget | null) => el is HTMLElement;
11
+ declare const getFirstTriggerEl: (ctx: Scope) => HTMLElement | undefined;
12
+ declare const getLastTriggerEl: (ctx: Scope) => HTMLElement | undefined;
13
+ declare const getNextTriggerEl: (ctx: Scope, id: string, loop: boolean) => HTMLElement;
14
+ declare const getPrevTriggerEl: (ctx: Scope, id: string, loop: boolean) => HTMLElement | null;
15
+ declare const getValidActiveId: (ctx: Scope, activeId: string | null) => string | null;
16
+ declare const requestOpenMenu: (ctx: Scope, triggerId: string) => void;
17
+
18
+ export { getFirstTriggerEl, getLastTriggerEl, getNextTriggerEl, getPrevTriggerEl, getRootEl, getRootId, getTriggerEls, getValidActiveId, isTriggerEl, requestOpenMenu };
@@ -0,0 +1,18 @@
1
+ import { Scope } from '@zag-js/core';
2
+
3
+ declare const getRootId: (ctx: Scope) => any;
4
+ declare const getRootEl: (ctx: Scope) => HTMLElement | null;
5
+ /**
6
+ * The menubar's items are the menu triggers rendered inside it. Because menus are
7
+ * portalled, only the top-level triggers (role=menuitem) live within the root subtree.
8
+ */
9
+ declare const getTriggerEls: (ctx: Scope) => HTMLElement[];
10
+ declare const isTriggerEl: (el: EventTarget | null) => el is HTMLElement;
11
+ declare const getFirstTriggerEl: (ctx: Scope) => HTMLElement | undefined;
12
+ declare const getLastTriggerEl: (ctx: Scope) => HTMLElement | undefined;
13
+ declare const getNextTriggerEl: (ctx: Scope, id: string, loop: boolean) => HTMLElement;
14
+ declare const getPrevTriggerEl: (ctx: Scope, id: string, loop: boolean) => HTMLElement | null;
15
+ declare const getValidActiveId: (ctx: Scope, activeId: string | null) => string | null;
16
+ declare const requestOpenMenu: (ctx: Scope, triggerId: string) => void;
17
+
18
+ export { getFirstTriggerEl, getLastTriggerEl, getNextTriggerEl, getPrevTriggerEl, getRootEl, getRootId, getTriggerEls, getValidActiveId, isTriggerEl, requestOpenMenu };
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/menubar.dom.ts
21
+ var menubar_dom_exports = {};
22
+ __export(menubar_dom_exports, {
23
+ getFirstTriggerEl: () => getFirstTriggerEl,
24
+ getLastTriggerEl: () => getLastTriggerEl,
25
+ getNextTriggerEl: () => getNextTriggerEl,
26
+ getPrevTriggerEl: () => getPrevTriggerEl,
27
+ getRootEl: () => getRootEl,
28
+ getRootId: () => getRootId,
29
+ getTriggerEls: () => getTriggerEls,
30
+ getValidActiveId: () => getValidActiveId,
31
+ isTriggerEl: () => isTriggerEl,
32
+ requestOpenMenu: () => requestOpenMenu
33
+ });
34
+ module.exports = __toCommonJS(menubar_dom_exports);
35
+ var import_dom_query = require("@zag-js/dom-query");
36
+ var import_utils = require("@zag-js/utils");
37
+ var import_menubar = require("./menubar.anatomy.js");
38
+ var getRootId = (ctx) => ctx.ids?.root ?? `menubar:${ctx.id}`;
39
+ var getRootEl = (ctx) => ctx.query(ctx.selector(import_menubar.parts.root));
40
+ var getTriggerEls = (ctx) => {
41
+ const rootEl = getRootEl(ctx);
42
+ if (!rootEl) return [];
43
+ const els = rootEl.querySelectorAll("[role=menuitem]");
44
+ return Array.from(els).filter(
45
+ (el) => !el.hasAttribute("data-disabled") && el.getAttribute("aria-disabled") !== "true"
46
+ );
47
+ };
48
+ var isTriggerEl = (el) => {
49
+ return (0, import_dom_query.isHTMLElement)(el) && el.getAttribute("role") === "menuitem";
50
+ };
51
+ var getFirstTriggerEl = (ctx) => (0, import_utils.first)(getTriggerEls(ctx));
52
+ var getLastTriggerEl = (ctx) => (0, import_utils.last)(getTriggerEls(ctx));
53
+ var getNextTriggerEl = (ctx, id, loop) => (0, import_dom_query.nextById)(getTriggerEls(ctx), id, loop);
54
+ var getPrevTriggerEl = (ctx, id, loop) => (0, import_dom_query.prevById)(getTriggerEls(ctx), id, loop);
55
+ var getValidActiveId = (ctx, activeId) => {
56
+ const triggers = getTriggerEls(ctx);
57
+ if (!triggers.length) return null;
58
+ return triggers.some((el) => el.id === activeId) ? activeId : triggers[0].id;
59
+ };
60
+ var requestOpenMenu = (ctx, triggerId) => {
61
+ const rootEl = getRootEl(ctx);
62
+ if (!rootEl) return;
63
+ const win = (0, import_dom_query.getWindow)(rootEl);
64
+ rootEl.dispatchEvent(new win.CustomEvent("menubar:open-request", { detail: { triggerId } }));
65
+ };
66
+ // Annotate the CommonJS export names for ESM import in node:
67
+ 0 && (module.exports = {
68
+ getFirstTriggerEl,
69
+ getLastTriggerEl,
70
+ getNextTriggerEl,
71
+ getPrevTriggerEl,
72
+ getRootEl,
73
+ getRootId,
74
+ getTriggerEls,
75
+ getValidActiveId,
76
+ isTriggerEl,
77
+ requestOpenMenu
78
+ });
@@ -0,0 +1,44 @@
1
+ // src/menubar.dom.ts
2
+ import { getWindow, isHTMLElement, nextById, prevById } from "@zag-js/dom-query";
3
+ import { first, last } from "@zag-js/utils";
4
+ import { parts } from "./menubar.anatomy.mjs";
5
+ var getRootId = (ctx) => ctx.ids?.root ?? `menubar:${ctx.id}`;
6
+ var getRootEl = (ctx) => ctx.query(ctx.selector(parts.root));
7
+ var getTriggerEls = (ctx) => {
8
+ const rootEl = getRootEl(ctx);
9
+ if (!rootEl) return [];
10
+ const els = rootEl.querySelectorAll("[role=menuitem]");
11
+ return Array.from(els).filter(
12
+ (el) => !el.hasAttribute("data-disabled") && el.getAttribute("aria-disabled") !== "true"
13
+ );
14
+ };
15
+ var isTriggerEl = (el) => {
16
+ return isHTMLElement(el) && el.getAttribute("role") === "menuitem";
17
+ };
18
+ var getFirstTriggerEl = (ctx) => first(getTriggerEls(ctx));
19
+ var getLastTriggerEl = (ctx) => last(getTriggerEls(ctx));
20
+ var getNextTriggerEl = (ctx, id, loop) => nextById(getTriggerEls(ctx), id, loop);
21
+ var getPrevTriggerEl = (ctx, id, loop) => prevById(getTriggerEls(ctx), id, loop);
22
+ var getValidActiveId = (ctx, activeId) => {
23
+ const triggers = getTriggerEls(ctx);
24
+ if (!triggers.length) return null;
25
+ return triggers.some((el) => el.id === activeId) ? activeId : triggers[0].id;
26
+ };
27
+ var requestOpenMenu = (ctx, triggerId) => {
28
+ const rootEl = getRootEl(ctx);
29
+ if (!rootEl) return;
30
+ const win = getWindow(rootEl);
31
+ rootEl.dispatchEvent(new win.CustomEvent("menubar:open-request", { detail: { triggerId } }));
32
+ };
33
+ export {
34
+ getFirstTriggerEl,
35
+ getLastTriggerEl,
36
+ getNextTriggerEl,
37
+ getPrevTriggerEl,
38
+ getRootEl,
39
+ getRootId,
40
+ getTriggerEls,
41
+ getValidActiveId,
42
+ isTriggerEl,
43
+ requestOpenMenu
44
+ };
@@ -0,0 +1,8 @@
1
+ import * as _zag_js_core from '@zag-js/core';
2
+ import { MenubarSchema } from './menubar.types.mjs';
3
+ import '@zag-js/dom-query';
4
+ import '@zag-js/types';
5
+
6
+ declare const machine: _zag_js_core.Machine<MenubarSchema>;
7
+
8
+ export { machine };
@@ -0,0 +1,8 @@
1
+ import * as _zag_js_core from '@zag-js/core';
2
+ import { MenubarSchema } from './menubar.types.js';
3
+ import '@zag-js/dom-query';
4
+ import '@zag-js/types';
5
+
6
+ declare const machine: _zag_js_core.Machine<MenubarSchema>;
7
+
8
+ export { machine };