{"version":3,"names":["createContext","createMemo","createSignal","useContext","readOption","SNAPSHOT_KEYS","snapshotKeys","MenubarApiContext","useMenubar","optional","ctx","Error","createMenubar","options","orientation","name","modal","disabled","Boolean","loopFocus","hasSubmenuOpen","setHasSubmenuOpen","ownedWrite","currentCloser","registerOpenMenu","closer","prev","closeAll","api","open","Provider","props","children","MENUBAR_SNAPSHOT_KEYS"],"sources":["create-menubar.tsx"],"sourcesContent":["import type { JSX } from \"@solidjs/web\";\n/**\n * `createMenubar` — headless primitive for the Menubar compound.\n *\n * Owns:\n *  - `orientation` — horizontal or vertical.\n *  - `modal` — modal mode flag.\n *  - `disabled` — whole-menubar disabled state.\n *  - `loopFocus` — whether arrow-key navigation wraps.\n *  - `hasSubmenuOpen` — whether any child menu is currently open.\n *  - `registerOpenMenu` / `closeAll` — single-open coordinator.\n *\n * DOM concerns (FloatingTree, FloatingNode, role=\"menubar\" element, keyboard\n * handler) stay in `<Menubar>`.\n */\nimport {\n\ttype Accessor,\n\tcreateContext,\n\tcreateMemo,\n\tcreateSignal,\n\tuseContext,\n} from \"solid-js\";\nimport { type MaybeAccessor, readOption } from \"../internals/maybe-accessor\";\nimport {\n\tSNAPSHOT_KEYS,\n\ttype Snapshottable,\n\tsnapshotKeys,\n} from \"../internals/observability/snapshot\";\nimport type { MenuRootOrientation } from \"../menu/root/menu-root-context\";\n\n// ---------------------------------------------------------------------------\n// Public types\n// ---------------------------------------------------------------------------\n\nexport interface CreateMenubarOptions {\n\t/**\n\t * The orientation of the menubar.\n\t * @default \"horizontal\"\n\t */\n\torientation?: MaybeAccessor<MenuRootOrientation>;\n\t/**\n\t * Whether the menubar is modal.\n\t * @default true\n\t */\n\tmodal?: MaybeAccessor<boolean>;\n\t/**\n\t * Whether the whole menubar is disabled.\n\t * @default false\n\t */\n\tdisabled?: MaybeAccessor<boolean>;\n\t/**\n\t * Whether arrow-key focus loops at the ends.\n\t * @default true\n\t */\n\tloopFocus?: MaybeAccessor<boolean>;\n}\n\nexport interface MenubarApi {\n\t/** Visual/keyboard orientation. */\n\torientation: Accessor<MenuRootOrientation>;\n\t/** Whether the menubar is modal. */\n\tmodal: Accessor<boolean>;\n\t/** Whether the whole menubar is disabled. */\n\tdisabled: Accessor<boolean>;\n\t/** Whether arrow-key focus loops at the ends. */\n\tloopFocus: Accessor<boolean>;\n\t/** Whether any child menu is currently open. */\n\thasSubmenuOpen: Accessor<boolean>;\n\n\t/**\n\t * Called by a child menu when it opens. Returns an unregister fn the\n\t * child should call on close / unmount. Enforces single-open invariant\n\t * by closing the previously-open sibling.\n\t */\n\tregisterOpenMenu: (closer: () => void) => () => void;\n\t/** Force-close all registered open menus. */\n\tcloseAll: () => void;\n\n\t/**\n\t * Internal — called by a child `<Menu.Root>` when its open state changes.\n\t * Both register and direct setHasSubmenuOpen paths are preserved for\n\t * idempotency (matches existing Menubar implementation).\n\t */\n\tsetHasSubmenuOpen: (open: boolean) => void;\n\n\t/** Context provider — expose the api via `useMenubar()`. */\n\tProvider: (props: { children: JSX.Element }) => JSX.Element;\n}\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\nconst MenubarApiContext = createContext<MenubarApi | null>(null);\n\n/**\n * Read the nearest {@link MenubarApi}. Throws unless `optional` is true.\n */\nexport function useMenubar(): MenubarApi;\nexport function useMenubar(optional: true): MenubarApi | null;\nexport function useMenubar(optional?: boolean): MenubarApi | null {\n\tconst ctx = useContext(MenubarApiContext);\n\tif (ctx == null && !optional) {\n\t\tthrow new Error(\n\t\t\t\"Base UI: useMenubar() must be called inside a <mb.Provider>.\",\n\t\t);\n\t}\n\treturn ctx;\n}\n\n// ---------------------------------------------------------------------------\n// Primitive\n// ---------------------------------------------------------------------------\n\n/**\n * Headless primitive for the Menubar compound. Owns logical state — orientation,\n * modal, disabled, loopFocus, hasSubmenuOpen, and the single-open coordinator.\n * DOM concerns (FloatingTree, role=\"menubar\" element, keyboard handler) live\n * in `<Menubar>`.\n */\nexport function createMenubar(options: CreateMenubarOptions = {}): MenubarApi {\n\tconst orientation = createMemo<MenuRootOrientation>(\n\t\t() => readOption(options.orientation) ?? \"horizontal\",\n\t\t{ name: \"menubar.orientation\" },\n\t);\n\n\tconst modal = createMemo<boolean>(() => readOption(options.modal) ?? true, {\n\t\tname: \"menubar.modal\",\n\t});\n\n\tconst disabled = createMemo<boolean>(\n\t\t() => Boolean(readOption(options.disabled)),\n\t\t{ name: \"menubar.disabled\" },\n\t);\n\n\tconst loopFocus = createMemo<boolean>(\n\t\t() => readOption(options.loopFocus) ?? true,\n\t\t{ name: \"menubar.loopFocus\" },\n\t);\n\n\tconst [hasSubmenuOpen, setHasSubmenuOpen] = createSignal(false, {\n\t\townedWrite: true,\n\t\tname: \"menubar.hasSubmenuOpen\",\n\t});\n\n\t// Single-open coordinator — only one child menu open at a time.\n\tlet currentCloser: (() => void) | null = null;\n\n\tconst registerOpenMenu = (closer: () => void): (() => void) => {\n\t\tif (currentCloser && currentCloser !== closer) {\n\t\t\tconst prev = currentCloser;\n\t\t\tcurrentCloser = null;\n\t\t\tprev();\n\t\t}\n\t\tcurrentCloser = closer;\n\t\tsetHasSubmenuOpen(true);\n\t\treturn () => {\n\t\t\t// Only the currently-open menu clears the flag: a sibling that\n\t\t\t// closes because another one opened must not reset it.\n\t\t\tif (currentCloser === closer) {\n\t\t\t\tcurrentCloser = null;\n\t\t\t\tsetHasSubmenuOpen(false);\n\t\t\t}\n\t\t};\n\t};\n\n\tconst closeAll = (): void => {\n\t\tif (currentCloser) {\n\t\t\tconst prev = currentCloser;\n\t\t\tcurrentCloser = null;\n\t\t\tsetHasSubmenuOpen(false);\n\t\t\tprev();\n\t\t}\n\t};\n\n\tconst api: MenubarApi = {\n\t\torientation,\n\t\tmodal,\n\t\tdisabled,\n\t\tloopFocus,\n\t\thasSubmenuOpen,\n\t\tregisterOpenMenu,\n\t\tcloseAll,\n\t\tsetHasSubmenuOpen: (open) => {\n\t\t\tsetHasSubmenuOpen(open);\n\t\t},\n\t\tProvider: (props) => (\n\t\t\t<MenubarApiContext value={api}>{props.children}</MenubarApiContext>\n\t\t),\n\t};\n\n\t(api as MenubarApi & Snapshottable)[SNAPSHOT_KEYS] = MENUBAR_SNAPSHOT_KEYS;\n\n\treturn api;\n}\n\nconst MENUBAR_SNAPSHOT_KEYS = snapshotKeys<MenubarApi>(\n\t\"orientation\",\n\t\"modal\",\n\t\"disabled\",\n\t\"loopFocus\",\n\t\"hasSubmenuOpen\",\n);\n"],"mappings":"AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAECA,aAAa,EACbC,UAAU,EACVC,YAAY,EACZC,UAAU,QACJ,UAAU;AACjB,SAA6BC,UAAU,QAAQ,6BAA6B;AAC5E,SACCC,aAAa,EAEbC,YAAY,QACN,qCAAqC;;AAG5C;AACA;AACA;;AAyDA;AACA;AACA;;AAEA,MAAMC,iBAAiB,GAAGP,aAAa,CAAoB,IAAI,CAAC;;AAEhE;AACA;AACA;;AAGA,OAAO,SAASQ,UAAUA,CAACC,QAAkB,EAAqB;EACjE,MAAMC,GAAG,GAAGP,UAAU,CAACI,iBAAiB,CAAC;EACzC,IAAIG,GAAG,IAAI,IAAI,IAAI,CAACD,QAAQ,EAAE;IAC7B,MAAM,IAAIE,KAAK,CACd,8DACD,CAAC;EACF;EACA,OAAOD,GAAG;AACX;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,aAAaA,CAACC,OAA6B,GAAG,CAAC,CAAC,EAAc;EAC7E,MAAMC,WAAW,GAAGb,UAAU,CAC7B,MAAMG,UAAU,CAACS,OAAO,CAACC,WAAW,CAAC,IAAI,YAAY,EACrD;IAAEC,IAAI,EAAE;EAAsB,CAC/B,CAAC;EAED,MAAMC,KAAK,GAAGf,UAAU,CAAU,MAAMG,UAAU,CAACS,OAAO,CAACG,KAAK,CAAC,IAAI,IAAI,EAAE;IAC1ED,IAAI,EAAE;EACP,CAAC,CAA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