{"version":3,"names":["createContext","createMemo","createSignal","runWithOwner","untrack","useContext","createControlledState","readOption","SNAPSHOT_KEYS","snapshotKeys","createDefaultAnchor","getBoundingClientRect","DOMRect","fromRect","width","height","x","y","top","right","bottom","left","toJSON","ContextMenuApiContext","useContextMenu","optional","ctx","Error","createContextMenu","options","disabled","Boolean","name","open","setUncontrolledOpen","controlled","undefined","default","defaultOpen","fallback","state","anchor","setAnchor","ownedWrite","setOpen","next","details","d","reason","isCanceled","onOpenChange","api","Provider","props","children","CONTEXT_MENU_SNAPSHOT_KEYS"],"sources":["create-context-menu.tsx"],"sourcesContent":["import type { JSX } from \"@solidjs/web\";\n/**\n * `createContextMenu` — headless primitive for the ContextMenu compound.\n *\n * ContextMenu is a thin façade over `<Menu.Root>` that:\n *  - Owns an `anchor` signal (virtual element at the right-click point).\n *  - Owns the open state per Base UI's controlled/uncontrolled contract:\n *    the gesture (right-click / long-press) writes the internal signal,\n *    seeded once from `defaultOpen`; a defined `open` option wins.\n *  - Exposes `setAnchor` + `setOpen` so `<ContextMenu.Trigger>` can update\n *    both atomically on contextmenu / pointerdown events.\n *\n * Gesture capture (contextmenu event, long-press timer, move threshold)\n * and DOM concerns stay in `<ContextMenu.Root>` / `<ContextMenu.Trigger>`.\n *\n * Why a separate primitive instead of reusing `createMenu` directly?\n * ContextMenu needs the `anchor` state and the gesture-driven internal open\n * signal. `createMenu` owns `open` as a pure pass-through, but ContextMenu\n * must manage its own open signal that the trigger writes imperatively —\n * that asymmetry warrants a dedicated primitive rather than composing\n * createMenu with extra options.\n */\nimport {\n\ttype Accessor,\n\tcreateContext,\n\tcreateMemo,\n\tcreateSignal,\n\trunWithOwner,\n\tuntrack,\n\tuseContext,\n} from \"solid-js\";\nimport { createControlledState } from \"../internals/create-controlled-state\";\nimport { type MaybeAccessor, readOption } from \"../internals/maybe-accessor\";\nimport {\n\tSNAPSHOT_KEYS,\n\ttype Snapshottable,\n\tsnapshotKeys,\n} from \"../internals/observability/snapshot\";\nimport type {\n\tMenuRootChangeEventDetails,\n\tMenuRootChangeEventReason,\n} from \"../menu/root/menu-root-context\";\nimport type { ContextMenuAnchor } from \"./root/context-menu-root-context\";\n\n// ---------------------------------------------------------------------------\n// Public types\n// ---------------------------------------------------------------------------\n\nexport type ContextMenuChangeReason = MenuRootChangeEventReason;\n\n/** Default zero-sized anchor used before the first contextmenu event. */\nfunction createDefaultAnchor(): ContextMenuAnchor {\n\treturn {\n\t\tgetBoundingClientRect(): DOMRect {\n\t\t\treturn typeof DOMRect !== \"undefined\"\n\t\t\t\t? DOMRect.fromRect({ width: 0, height: 0, x: 0, y: 0 })\n\t\t\t\t: ({\n\t\t\t\t\t\twidth: 0,\n\t\t\t\t\t\theight: 0,\n\t\t\t\t\t\tx: 0,\n\t\t\t\t\t\ty: 0,\n\t\t\t\t\t\ttop: 0,\n\t\t\t\t\t\tright: 0,\n\t\t\t\t\t\tbottom: 0,\n\t\t\t\t\t\tleft: 0,\n\t\t\t\t\t\ttoJSON: () => ({}),\n\t\t\t\t\t} as DOMRect);\n\t\t},\n\t};\n}\n\nexport interface CreateContextMenuOptions {\n\t/**\n\t * Controlled open state. While its resolved value is not `undefined`\n\t * the consumer owns the state — pair with `onOpenChange`. When\n\t * omitted, the gesture-driven internal signal (seeded from\n\t * {@link defaultOpen}) backs the state.\n\t */\n\topen?: MaybeAccessor<boolean | undefined>;\n\t/**\n\t * Initial open state when uncontrolled. Read once at creation.\n\t * @default false\n\t */\n\tdefaultOpen?: MaybeAccessor<boolean | undefined>;\n\t/**\n\t * Whether the menu is disabled.\n\t * @default false\n\t */\n\tdisabled?: MaybeAccessor<boolean>;\n\t/**\n\t * Called via `runWithOwner(null, ...)` so consumer signal writes don't\n\t * trigger SIGNAL_WRITE_IN_OWNED_SCOPE.\n\t */\n\tonOpenChange?: (open: boolean, details: MenuRootChangeEventDetails) => void;\n}\n\nexport interface ContextMenuApi {\n\t/** Reactive accessor for the effective open state. */\n\topen: Accessor<boolean>;\n\t/** Whether the menu is disabled. */\n\tdisabled: Accessor<boolean>;\n\t/** Virtual anchor element — updated by the trigger on each gesture. */\n\tanchor: Accessor<ContextMenuAnchor>;\n\n\t/**\n\t * Update the anchor position. Called by `<ContextMenu.Trigger>` when the\n\t * contextmenu / long-press gesture fires.\n\t */\n\tsetAnchor: (anchor: ContextMenuAnchor) => void;\n\t/**\n\t * Fires `onOpenChange` via `runWithOwner(null, ...)`, honors\n\t * `details.cancel()`, then writes the internal gesture-driven open\n\t * signal so uncontrolled consumers see the change (the write is inert\n\t * while a controlled `open` option is provided).\n\t */\n\tsetOpen: (next: boolean, details?: MenuRootChangeEventDetails) => void;\n\n\t/** Context provider — expose the api via `useContextMenu()`. */\n\tProvider: (props: { children: JSX.Element }) => JSX.Element;\n}\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\nconst ContextMenuApiContext = createContext<ContextMenuApi | null>(null);\n\n/**\n * Read the nearest {@link ContextMenuApi}. Throws unless `optional` is true.\n */\nexport function useContextMenu(): ContextMenuApi;\nexport function useContextMenu(optional: true): ContextMenuApi | null;\nexport function useContextMenu(optional?: boolean): ContextMenuApi | null {\n\tconst ctx = useContext(ContextMenuApiContext);\n\tif (ctx == null && !optional) {\n\t\tthrow new Error(\n\t\t\t\"Base UI: useContextMenu() must be called inside a <cm.Provider>.\",\n\t\t);\n\t}\n\treturn ctx;\n}\n\n// ---------------------------------------------------------------------------\n// Primitive\n// ---------------------------------------------------------------------------\n\n/**\n * Headless primitive for the ContextMenu compound. Owns logical state — open,\n * disabled, anchor. Gesture capture and DOM concerns live in\n * `<ContextMenu.Root>` and `<ContextMenu.Trigger>`.\n */\nexport function createContextMenu(\n\toptions: CreateContextMenuOptions = {},\n): ContextMenuApi {\n\tconst disabled = createMemo<boolean>(\n\t\t() => Boolean(readOption(options.disabled)),\n\t\t{ name: \"contextMenu.disabled\" },\n\t);\n\n\t// Controlled / uncontrolled open state (Base UI `open` / `defaultOpen`\n\t// contract): the `open` option wins while its resolved value is defined;\n\t// otherwise the gesture-driven internal signal (seeded once from\n\t// `defaultOpen`, written by `setOpen`) backs the state.\n\tconst [open, setUncontrolledOpen] = createControlledState<boolean>({\n\t\tcontrolled: () => {\n\t\t\tconst controlled = readOption(options.open);\n\t\t\treturn controlled === undefined ? undefined : Boolean(controlled);\n\t\t},\n\t\tdefault: () => readOption(options.defaultOpen),\n\t\tfallback: false,\n\t\tname: \"<ContextMenu.Root>\",\n\t\tstate: \"open\",\n\t});\n\n\tconst [anchor, setAnchor] = createSignal<ContextMenuAnchor>(\n\t\tcreateDefaultAnchor(),\n\t\t{ ownedWrite: true, name: \"contextMenu.anchor\" },\n\t);\n\n\t// Base UI change flow: fire `onOpenChange` (via `runWithOwner(null, ...)`\n\t// so consumer signal writes don't trip SIGNAL_WRITE_IN_OWNED_SCOPE),\n\t// honor `details.cancel()`, then write the uncontrolled state (inert\n\t// while the `open` option is controlled).\n\tconst setOpen = (\n\t\tnext: boolean,\n\t\tdetails?: MenuRootChangeEventDetails,\n\t): void => {\n\t\tif (untrack(disabled)) return;\n\t\tconst d =\n\t\t\tdetails ??\n\t\t\t({ reason: \"none\", isCanceled: false } as MenuRootChangeEventDetails);\n\t\trunWithOwner(null, () => options.onOpenChange?.(next, d));\n\t\tif (d.isCanceled) return;\n\t\tsetUncontrolledOpen(next);\n\t};\n\n\tconst api: ContextMenuApi = {\n\t\topen,\n\t\tdisabled,\n\t\tanchor,\n\t\tsetAnchor,\n\t\tsetOpen,\n\t\tProvider: (props) => (\n\t\t\t<ContextMenuApiContext value={api}>\n\t\t\t\t{props.children}\n\t\t\t</ContextMenuApiContext>\n\t\t),\n\t};\n\n\t(api as ContextMenuApi & Snapshottable)[SNAPSHOT_KEYS] =\n\t\tCONTEXT_MENU_SNAPSHOT_KEYS;\n\n\treturn api;\n}\n\nconst CONTEXT_MENU_SNAPSHOT_KEYS = snapshotKeys<ContextMenuApi>(\n\t\"open\",\n\t\"disabled\",\n);\n"],"mappings":"AACA;AACA;AACA;AAC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