@primitiv-ui/web 0.1.54 → 0.1.55
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/README.md +32 -3
- package/dist/cdn/chunks/chunk-PKW6AKXD.js +1 -0
- package/dist/cdn/modal.js +1 -1
- package/dist/cdn/popover.js +1 -0
- package/dist/custom-elements.json +379 -0
- package/dist/define/index.d.ts +1 -0
- package/dist/define/index.js +1 -0
- package/dist/define/popover.d.ts +1 -0
- package/dist/define/popover.js +11 -0
- package/dist/frameworks/events.d.ts +4 -0
- package/dist/frameworks/react.d.ts +15 -2
- package/dist/frameworks/svelte.d.ts +12 -1
- package/dist/frameworks/vue.d.ts +12 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/popover/PopoverController.d.ts +55 -0
- package/dist/popover/PopoverController.js +100 -0
- package/dist/popover/elements.d.ts +98 -0
- package/dist/popover/elements.js +230 -0
- package/dist/popover/index.d.ts +2 -0
- package/dist/popover/index.js +2 -0
- package/dist/primitiv-web.js +1 -1
- package/dist/tags.d.ts +8 -0
- package/package.json +10 -2
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a {@link PopoverController} asks of whoever hosts it. The controller
|
|
3
|
+
* owns behaviour and never owns state (RFC 0033 D28): the custom elements keep
|
|
4
|
+
* the open state in a reflected `open` attribute, the React adapter keeps it in
|
|
5
|
+
* React, and each answers these calls from wherever it keeps it.
|
|
6
|
+
*/
|
|
7
|
+
export type PopoverControllerHost = {
|
|
8
|
+
/** The state the controller cannot see for itself. */
|
|
9
|
+
state(): {
|
|
10
|
+
/** Whether the popover is open. */
|
|
11
|
+
open: boolean;
|
|
12
|
+
};
|
|
13
|
+
/** Apply a change the user asked for: `open` is the state afterwards. */
|
|
14
|
+
change(open: boolean): void;
|
|
15
|
+
/** The trigger: Escape hands focus back to it, and a press on it is not an outside press. */
|
|
16
|
+
trigger(): HTMLElement | null;
|
|
17
|
+
/**
|
|
18
|
+
* The element to hand `showPopover({ source })`, which makes it the panel's
|
|
19
|
+
* implicit anchor for CSS anchor positioning. Optional: without it the panel
|
|
20
|
+
* is shown with no source, and positioning is the consumer's to wire.
|
|
21
|
+
*/
|
|
22
|
+
source?(): HTMLElement | null;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* The DOM behaviour of a popover, over a `popover="auto"` panel: the browser
|
|
26
|
+
* owns the top layer and light dismiss, and this adds the rest of the WAI-ARIA
|
|
27
|
+
* non-modal dialog pattern:
|
|
28
|
+
*
|
|
29
|
+
* - **Sync** — {@link PopoverController.sync | `sync()`} shows or hides the
|
|
30
|
+
* panel to match the host's state, moving focus into it as it opens (its
|
|
31
|
+
* first focusable, or the panel itself). A host calls it whenever that state
|
|
32
|
+
* may have changed.
|
|
33
|
+
* - **Dismissal** — the browser light-dismissing the panel is reported, Escape
|
|
34
|
+
* inside it closes it and hands focus back to the trigger, and where the
|
|
35
|
+
* browser has no Popover API a press outside closes it.
|
|
36
|
+
*
|
|
37
|
+
* Opening from the trigger is the host's, as a plain click.
|
|
38
|
+
*/
|
|
39
|
+
export declare class PopoverController {
|
|
40
|
+
#private;
|
|
41
|
+
constructor(content: HTMLElement, host: PopoverControllerHost);
|
|
42
|
+
/**
|
|
43
|
+
* Start listening. Connecting again while connected does nothing, so a host
|
|
44
|
+
* whose lifecycle runs twice never stacks handlers.
|
|
45
|
+
*/
|
|
46
|
+
connect(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Stop listening, and forget the panel was showing: a host disconnects when
|
|
49
|
+
* it leaves the document, which hides a popover with no event, so the next
|
|
50
|
+
* sync shows it again.
|
|
51
|
+
*/
|
|
52
|
+
disconnect(): void;
|
|
53
|
+
/** Show or hide the panel to match the host's state. */
|
|
54
|
+
sync(): void;
|
|
55
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { FOCUSABLE_SELECTOR, popoverKeydown, popoverPressDismisses } from "@primitiv-ui/core";
|
|
2
|
+
/**
|
|
3
|
+
* The DOM behaviour of a popover, over a `popover="auto"` panel: the browser
|
|
4
|
+
* owns the top layer and light dismiss, and this adds the rest of the WAI-ARIA
|
|
5
|
+
* non-modal dialog pattern:
|
|
6
|
+
*
|
|
7
|
+
* - **Sync** — {@link PopoverController.sync | `sync()`} shows or hides the
|
|
8
|
+
* panel to match the host's state, moving focus into it as it opens (its
|
|
9
|
+
* first focusable, or the panel itself). A host calls it whenever that state
|
|
10
|
+
* may have changed.
|
|
11
|
+
* - **Dismissal** — the browser light-dismissing the panel is reported, Escape
|
|
12
|
+
* inside it closes it and hands focus back to the trigger, and where the
|
|
13
|
+
* browser has no Popover API a press outside closes it.
|
|
14
|
+
*
|
|
15
|
+
* Opening from the trigger is the host's, as a plain click.
|
|
16
|
+
*/
|
|
17
|
+
export class PopoverController {
|
|
18
|
+
#content;
|
|
19
|
+
#host;
|
|
20
|
+
#connection = null;
|
|
21
|
+
/** Whether this controller showed the panel and has not hidden it since. */
|
|
22
|
+
#shown = false;
|
|
23
|
+
constructor(content, host) {
|
|
24
|
+
this.#content = content;
|
|
25
|
+
this.#host = host;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Start listening. Connecting again while connected does nothing, so a host
|
|
29
|
+
* whose lifecycle runs twice never stacks handlers.
|
|
30
|
+
*/
|
|
31
|
+
connect() {
|
|
32
|
+
if (this.#connection)
|
|
33
|
+
return;
|
|
34
|
+
this.#connection = new AbortController();
|
|
35
|
+
const { signal } = this.#connection;
|
|
36
|
+
this.#content.addEventListener("toggle", (event) => this.#toggle(event), { signal });
|
|
37
|
+
this.#content.addEventListener("keydown", (event) => this.#keydown(event), { signal });
|
|
38
|
+
document.addEventListener("click", (event) => this.#press(event), { signal });
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Stop listening, and forget the panel was showing: a host disconnects when
|
|
42
|
+
* it leaves the document, which hides a popover with no event, so the next
|
|
43
|
+
* sync shows it again.
|
|
44
|
+
*/
|
|
45
|
+
disconnect() {
|
|
46
|
+
this.#connection?.abort();
|
|
47
|
+
this.#connection = null;
|
|
48
|
+
this.#shown = false;
|
|
49
|
+
}
|
|
50
|
+
/** Show or hide the panel to match the host's state. */
|
|
51
|
+
sync() {
|
|
52
|
+
const { open } = this.#host.state();
|
|
53
|
+
if (open && !this.#shown) {
|
|
54
|
+
this.#shown = true;
|
|
55
|
+
const source = this.#host.source?.();
|
|
56
|
+
if (source)
|
|
57
|
+
this.#content.showPopover({ source });
|
|
58
|
+
else
|
|
59
|
+
this.#content.showPopover();
|
|
60
|
+
// Move focus into the panel (WAI-ARIA non-modal dialog): the first
|
|
61
|
+
// focusable, or the panel itself, which carries tabindex="-1".
|
|
62
|
+
(this.#content.querySelector(FOCUSABLE_SELECTOR) ?? this.#content).focus();
|
|
63
|
+
}
|
|
64
|
+
else if (!open && this.#shown) {
|
|
65
|
+
this.#shown = false;
|
|
66
|
+
try {
|
|
67
|
+
this.#content.hidePopover();
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// Already hidden: the browser light-dismissed it first.
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
#toggle(event) {
|
|
75
|
+
if (event.newState !== "closed")
|
|
76
|
+
return;
|
|
77
|
+
this.#shown = false;
|
|
78
|
+
this.#host.change(false);
|
|
79
|
+
}
|
|
80
|
+
#keydown(event) {
|
|
81
|
+
// A popover nested in this panel handles its own Escape first, as the
|
|
82
|
+
// event bubbles out of it; leave that one alone, or both would close.
|
|
83
|
+
if (event.defaultPrevented || !popoverKeydown(event.key))
|
|
84
|
+
return;
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
this.#host.change(false);
|
|
87
|
+
this.#host.trigger()?.focus();
|
|
88
|
+
}
|
|
89
|
+
#press(event) {
|
|
90
|
+
const target = event.target;
|
|
91
|
+
const dismisses = popoverPressDismisses({
|
|
92
|
+
open: this.#host.state().open,
|
|
93
|
+
nativeLightDismiss: "popover" in HTMLElement.prototype,
|
|
94
|
+
inTrigger: this.#host.trigger()?.contains(target) ?? false,
|
|
95
|
+
inPopover: target.closest("[popover]") !== null,
|
|
96
|
+
});
|
|
97
|
+
if (dismisses)
|
|
98
|
+
this.#host.change(false);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { ElementBase, type ElementRegistry } from "../internal/element.js";
|
|
2
|
+
import { PrimitivRootElement } from "../internal/RootElement.js";
|
|
3
|
+
export type { ElementRegistry };
|
|
4
|
+
/**
|
|
5
|
+
* `<primitiv-popover>` — the state owner of a non-modal popover: a trigger
|
|
6
|
+
* that opens a floating panel, built on the native Popover API. The browser
|
|
7
|
+
* puts the panel in the top layer and light-dismisses it; the element adds the
|
|
8
|
+
* rest of the WAI-ARIA non-modal dialog pattern — focus moves into the panel
|
|
9
|
+
* as it opens, Escape closes it and hands focus back to the trigger, and the
|
|
10
|
+
* trigger's `aria-expanded` follows it.
|
|
11
|
+
*
|
|
12
|
+
* The panel is shown with its trigger (or the anchor) as its source, which
|
|
13
|
+
* makes that element the panel's implicit anchor, so CSS anchor positioning
|
|
14
|
+
* (`position-area`) places it with no `anchor-name` to wire.
|
|
15
|
+
*
|
|
16
|
+
* The root finds its own parts, so a popover nested in a panel keeps its own,
|
|
17
|
+
* and reconciles their ARIA from its reflected state whenever a part arrives,
|
|
18
|
+
* leaves, or changes an attribute the root reads (the lifecycle is
|
|
19
|
+
* `PrimitivRootElement`'s).
|
|
20
|
+
*
|
|
21
|
+
* @customElement primitiv-popover
|
|
22
|
+
* @summary The state owner of a non-modal popover on the native Popover API.
|
|
23
|
+
* @attr {boolean} open - Whether the panel is open. Reflected: it changes as the user opens and dismisses it, so a server re-render or a history snapshot sees the live state. Set it (or the `open` property) to open or close the panel from script.
|
|
24
|
+
* @fires {CustomEvent<{ open: boolean }>} primitiv-popover-change - Bubbles, cancelable, fired before a user-driven change is applied — a trigger or close click, Escape, or a light dismiss — with the open state afterwards. Call `preventDefault()` to veto it.
|
|
25
|
+
*/
|
|
26
|
+
export declare class PrimitivPopoverElement extends PrimitivRootElement {
|
|
27
|
+
#private;
|
|
28
|
+
protected readonly controller: {
|
|
29
|
+
connect(): void;
|
|
30
|
+
disconnect(): void;
|
|
31
|
+
};
|
|
32
|
+
protected readonly reconcileOn: readonly string[];
|
|
33
|
+
/** Whether the panel is open, reflected as the boolean `open` attribute. */
|
|
34
|
+
get open(): boolean;
|
|
35
|
+
set open(next: boolean);
|
|
36
|
+
protected reconcile(): void;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* `<primitiv-popover-trigger>` — an interactive part. It decorates exactly one
|
|
40
|
+
* child the consumer writes, a `<button>`, which toggles the panel and receives
|
|
41
|
+
* `aria-haspopup="dialog"`, `aria-expanded` and `aria-controls`, so the
|
|
42
|
+
* rendered DOM matches React's (RFC 0033 D24).
|
|
43
|
+
*
|
|
44
|
+
* @customElement primitiv-popover-trigger
|
|
45
|
+
*/
|
|
46
|
+
export declare class PrimitivPopoverTriggerElement extends ElementBase {
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* `<primitiv-popover-anchor>` — optional. It decorates exactly one element the
|
|
50
|
+
* consumer writes, which the panel is anchored to in place of the trigger: a
|
|
51
|
+
* field, say, whose trigger is an icon inside it.
|
|
52
|
+
*
|
|
53
|
+
* @customElement primitiv-popover-anchor
|
|
54
|
+
*/
|
|
55
|
+
export declare class PrimitivPopoverAnchorElement extends ElementBase {
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* `<primitiv-popover-content>` — the panel. Structural: the root gives it an
|
|
59
|
+
* id, `role="dialog"`, `popover="auto"` (write it in your markup too, so the
|
|
60
|
+
* panel is hidden before the script loads), `tabindex="-1"`, `data-state`, and
|
|
61
|
+
* `aria-labelledby` / `aria-describedby` pointing at the title and description.
|
|
62
|
+
*
|
|
63
|
+
* @customElement primitiv-popover-content
|
|
64
|
+
*/
|
|
65
|
+
export declare class PrimitivPopoverContentElement extends ElementBase {
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* `<primitiv-popover-title>` — decorates exactly one heading the consumer
|
|
69
|
+
* writes, whose id becomes the panel's `aria-labelledby`.
|
|
70
|
+
*
|
|
71
|
+
* @customElement primitiv-popover-title
|
|
72
|
+
*/
|
|
73
|
+
export declare class PrimitivPopoverTitleElement extends ElementBase {
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* `<primitiv-popover-description>` — decorates exactly one element the
|
|
77
|
+
* consumer writes (a `<p>`, usually), whose id becomes the panel's
|
|
78
|
+
* `aria-describedby`.
|
|
79
|
+
*
|
|
80
|
+
* @customElement primitiv-popover-description
|
|
81
|
+
*/
|
|
82
|
+
export declare class PrimitivPopoverDescriptionElement extends ElementBase {
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* `<primitiv-popover-close>` — an interactive part. It decorates exactly one
|
|
86
|
+
* `<button>` the consumer writes, which closes the panel. A popover may have
|
|
87
|
+
* several.
|
|
88
|
+
*
|
|
89
|
+
* @customElement primitiv-popover-close
|
|
90
|
+
*/
|
|
91
|
+
export declare class PrimitivPopoverCloseElement extends ElementBase {
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Define the seven Popover elements on `registry` (the global `customElements`
|
|
95
|
+
* by default). Safe to call more than once, and a no-op where there is no
|
|
96
|
+
* registry (a server render).
|
|
97
|
+
*/
|
|
98
|
+
export declare function definePopover(registry?: ElementRegistry | undefined): void;
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { defineElements, ElementBase, reportOnce, write } from "../internal/element.js";
|
|
2
|
+
import { PrimitivRootElement } from "../internal/RootElement.js";
|
|
3
|
+
import { PopoverController } from "./PopoverController.js";
|
|
4
|
+
// Stryker disable StringLiteral: static — evaluated once at import, so runtime mutant switching never reaches them; the names are pinned by the definePopover registry test instead.
|
|
5
|
+
const ROOT = "primitiv-popover";
|
|
6
|
+
const TRIGGER = "primitiv-popover-trigger";
|
|
7
|
+
const ANCHOR = "primitiv-popover-anchor";
|
|
8
|
+
const CONTENT = "primitiv-popover-content";
|
|
9
|
+
const TITLE = "primitiv-popover-title";
|
|
10
|
+
const DESCRIPTION = "primitiv-popover-description";
|
|
11
|
+
const CLOSE = "primitiv-popover-close";
|
|
12
|
+
// Stryker restore StringLiteral
|
|
13
|
+
/**
|
|
14
|
+
* The one element child `part` decorates — the `<button>`, heading or anchor
|
|
15
|
+
* element the consumer writes — or `null`, reported once, when it has anything
|
|
16
|
+
* but exactly one (RFC 0033 D24). `what` names the child in the report.
|
|
17
|
+
*/
|
|
18
|
+
function decoratable(part, what) {
|
|
19
|
+
if (part.childElementCount === 1)
|
|
20
|
+
return part.firstElementChild;
|
|
21
|
+
reportOnce(part, `<${part.localName}> needs exactly one element child (${what}) to decorate.`);
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* `<primitiv-popover>` — the state owner of a non-modal popover: a trigger
|
|
26
|
+
* that opens a floating panel, built on the native Popover API. The browser
|
|
27
|
+
* puts the panel in the top layer and light-dismisses it; the element adds the
|
|
28
|
+
* rest of the WAI-ARIA non-modal dialog pattern — focus moves into the panel
|
|
29
|
+
* as it opens, Escape closes it and hands focus back to the trigger, and the
|
|
30
|
+
* trigger's `aria-expanded` follows it.
|
|
31
|
+
*
|
|
32
|
+
* The panel is shown with its trigger (or the anchor) as its source, which
|
|
33
|
+
* makes that element the panel's implicit anchor, so CSS anchor positioning
|
|
34
|
+
* (`position-area`) places it with no `anchor-name` to wire.
|
|
35
|
+
*
|
|
36
|
+
* The root finds its own parts, so a popover nested in a panel keeps its own,
|
|
37
|
+
* and reconciles their ARIA from its reflected state whenever a part arrives,
|
|
38
|
+
* leaves, or changes an attribute the root reads (the lifecycle is
|
|
39
|
+
* `PrimitivRootElement`'s).
|
|
40
|
+
*
|
|
41
|
+
* @customElement primitiv-popover
|
|
42
|
+
* @summary The state owner of a non-modal popover on the native Popover API.
|
|
43
|
+
* @attr {boolean} open - Whether the panel is open. Reflected: it changes as the user opens and dismisses it, so a server re-render or a history snapshot sees the live state. Set it (or the `open` property) to open or close the panel from script.
|
|
44
|
+
* @fires {CustomEvent<{ open: boolean }>} primitiv-popover-change - Bubbles, cancelable, fired before a user-driven change is applied — a trigger or close click, Escape, or a light dismiss — with the open state afterwards. Call `preventDefault()` to veto it.
|
|
45
|
+
*/
|
|
46
|
+
export class PrimitivPopoverElement extends PrimitivRootElement {
|
|
47
|
+
/** The panel the root currently decorates, and the controller over it. */
|
|
48
|
+
#content = null;
|
|
49
|
+
#popover = null;
|
|
50
|
+
/** The decorated trigger and close buttons, and the anchor, as of the last reconcile. */
|
|
51
|
+
#trigger = null;
|
|
52
|
+
#anchor = null;
|
|
53
|
+
// Stryker disable next-line ArrayDeclaration: equivalent — the first reconcile runs as the root connects, before any click can reach it, and replaces it.
|
|
54
|
+
#closers = [];
|
|
55
|
+
/** The root's own click listener, while connected. */
|
|
56
|
+
#listening = null;
|
|
57
|
+
controller = {
|
|
58
|
+
connect: () => this.#connect(),
|
|
59
|
+
disconnect: () => this.#disconnect(),
|
|
60
|
+
};
|
|
61
|
+
reconcileOn = ["open"];
|
|
62
|
+
/** Whether the panel is open, reflected as the boolean `open` attribute. */
|
|
63
|
+
get open() {
|
|
64
|
+
return this.hasAttribute("open");
|
|
65
|
+
}
|
|
66
|
+
set open(next) {
|
|
67
|
+
this.toggleAttribute("open", next);
|
|
68
|
+
}
|
|
69
|
+
/** The controller's view of this element: state lives in the reflected attribute. */
|
|
70
|
+
#host() {
|
|
71
|
+
return {
|
|
72
|
+
state: () => ({ open: this.open }),
|
|
73
|
+
change: (open) => this.#change(open),
|
|
74
|
+
trigger: () => this.#trigger,
|
|
75
|
+
source: () => this.#anchor ?? this.#trigger,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/** A change the user asked for: announced first, so a listener can veto it. */
|
|
79
|
+
#change(open) {
|
|
80
|
+
if (open === this.open)
|
|
81
|
+
return;
|
|
82
|
+
if (this.announce("primitiv-popover-change", { open }))
|
|
83
|
+
this.open = open;
|
|
84
|
+
// A veto can leave the panel out of step — the browser is light-dismissing
|
|
85
|
+
// it — so put it back where the state says, once that dismissal is done.
|
|
86
|
+
else
|
|
87
|
+
queueMicrotask(() => this.#popover?.sync());
|
|
88
|
+
}
|
|
89
|
+
#connect() {
|
|
90
|
+
this.#listening = new AbortController();
|
|
91
|
+
this.addEventListener("click", (event) => this.#click(event), { signal: this.#listening.signal });
|
|
92
|
+
this.#popover?.connect();
|
|
93
|
+
}
|
|
94
|
+
#disconnect() {
|
|
95
|
+
// A root disconnects only after it connected, so it is listening.
|
|
96
|
+
this.#listening.abort();
|
|
97
|
+
this.#listening = null;
|
|
98
|
+
this.#popover?.disconnect();
|
|
99
|
+
}
|
|
100
|
+
#click(event) {
|
|
101
|
+
const target = event.target;
|
|
102
|
+
if (this.#trigger?.contains(target))
|
|
103
|
+
this.#change(!this.open);
|
|
104
|
+
else if (this.#closers.some((button) => button.contains(target)))
|
|
105
|
+
this.#change(false);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Decorate `content` from now on: the controller follows it. Only a
|
|
109
|
+
* reconcile calls this, and a root reconciles only while connected, so the
|
|
110
|
+
* new controller listens at once.
|
|
111
|
+
*/
|
|
112
|
+
#use(content) {
|
|
113
|
+
// Stryker disable next-line ConditionalExpression: equivalent — rebuilding the controller over the same panel swaps one listener set for an identical one.
|
|
114
|
+
if (content === this.#content)
|
|
115
|
+
return;
|
|
116
|
+
this.#popover?.disconnect();
|
|
117
|
+
this.#content = content;
|
|
118
|
+
this.#popover = content ? new PopoverController(content, this.#host()) : null;
|
|
119
|
+
this.#popover?.connect();
|
|
120
|
+
}
|
|
121
|
+
reconcile() {
|
|
122
|
+
const open = this.open;
|
|
123
|
+
const state = open ? "open" : "closed";
|
|
124
|
+
const rootId = this.rootId();
|
|
125
|
+
write(this, "data-state", state);
|
|
126
|
+
const [content = null] = this.parts(CONTENT);
|
|
127
|
+
const [triggerPart] = this.parts(TRIGGER);
|
|
128
|
+
const [anchorPart] = this.parts(ANCHOR);
|
|
129
|
+
const [titlePart] = this.parts(TITLE);
|
|
130
|
+
const [descriptionPart] = this.parts(DESCRIPTION);
|
|
131
|
+
this.#trigger = triggerPart ? decoratable(triggerPart, "a <button>") : null;
|
|
132
|
+
this.#anchor = anchorPart ? decoratable(anchorPart, "the element to anchor to") : null;
|
|
133
|
+
const title = titlePart ? decoratable(titlePart, "a heading") : null;
|
|
134
|
+
const description = descriptionPart ? decoratable(descriptionPart, "a <p>") : null;
|
|
135
|
+
if (title && !title.id)
|
|
136
|
+
title.id = `${rootId}-title`;
|
|
137
|
+
if (description && !description.id)
|
|
138
|
+
description.id = `${rootId}-description`;
|
|
139
|
+
if (content) {
|
|
140
|
+
if (!content.id)
|
|
141
|
+
content.id = `${rootId}-content`;
|
|
142
|
+
write(content, "role", "dialog");
|
|
143
|
+
if (!content.hasAttribute("popover"))
|
|
144
|
+
content.setAttribute("popover", "auto");
|
|
145
|
+
write(content, "tabindex", "-1");
|
|
146
|
+
write(content, "data-state", state);
|
|
147
|
+
write(content, "aria-labelledby", title ? title.id : null);
|
|
148
|
+
write(content, "aria-describedby", description ? description.id : null);
|
|
149
|
+
}
|
|
150
|
+
if (this.#trigger) {
|
|
151
|
+
write(this.#trigger, "aria-haspopup", "dialog");
|
|
152
|
+
write(this.#trigger, "aria-expanded", String(open));
|
|
153
|
+
write(this.#trigger, "aria-controls", content ? content.id : null);
|
|
154
|
+
}
|
|
155
|
+
this.#closers = this.parts(CLOSE).flatMap((part) => decoratable(part, "a <button>") ?? []);
|
|
156
|
+
this.#use(content);
|
|
157
|
+
this.#popover?.sync();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* `<primitiv-popover-trigger>` — an interactive part. It decorates exactly one
|
|
162
|
+
* child the consumer writes, a `<button>`, which toggles the panel and receives
|
|
163
|
+
* `aria-haspopup="dialog"`, `aria-expanded` and `aria-controls`, so the
|
|
164
|
+
* rendered DOM matches React's (RFC 0033 D24).
|
|
165
|
+
*
|
|
166
|
+
* @customElement primitiv-popover-trigger
|
|
167
|
+
*/
|
|
168
|
+
export class PrimitivPopoverTriggerElement extends ElementBase {
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* `<primitiv-popover-anchor>` — optional. It decorates exactly one element the
|
|
172
|
+
* consumer writes, which the panel is anchored to in place of the trigger: a
|
|
173
|
+
* field, say, whose trigger is an icon inside it.
|
|
174
|
+
*
|
|
175
|
+
* @customElement primitiv-popover-anchor
|
|
176
|
+
*/
|
|
177
|
+
export class PrimitivPopoverAnchorElement extends ElementBase {
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* `<primitiv-popover-content>` — the panel. Structural: the root gives it an
|
|
181
|
+
* id, `role="dialog"`, `popover="auto"` (write it in your markup too, so the
|
|
182
|
+
* panel is hidden before the script loads), `tabindex="-1"`, `data-state`, and
|
|
183
|
+
* `aria-labelledby` / `aria-describedby` pointing at the title and description.
|
|
184
|
+
*
|
|
185
|
+
* @customElement primitiv-popover-content
|
|
186
|
+
*/
|
|
187
|
+
export class PrimitivPopoverContentElement extends ElementBase {
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* `<primitiv-popover-title>` — decorates exactly one heading the consumer
|
|
191
|
+
* writes, whose id becomes the panel's `aria-labelledby`.
|
|
192
|
+
*
|
|
193
|
+
* @customElement primitiv-popover-title
|
|
194
|
+
*/
|
|
195
|
+
export class PrimitivPopoverTitleElement extends ElementBase {
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* `<primitiv-popover-description>` — decorates exactly one element the
|
|
199
|
+
* consumer writes (a `<p>`, usually), whose id becomes the panel's
|
|
200
|
+
* `aria-describedby`.
|
|
201
|
+
*
|
|
202
|
+
* @customElement primitiv-popover-description
|
|
203
|
+
*/
|
|
204
|
+
export class PrimitivPopoverDescriptionElement extends ElementBase {
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* `<primitiv-popover-close>` — an interactive part. It decorates exactly one
|
|
208
|
+
* `<button>` the consumer writes, which closes the panel. A popover may have
|
|
209
|
+
* several.
|
|
210
|
+
*
|
|
211
|
+
* @customElement primitiv-popover-close
|
|
212
|
+
*/
|
|
213
|
+
export class PrimitivPopoverCloseElement extends ElementBase {
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Define the seven Popover elements on `registry` (the global `customElements`
|
|
217
|
+
* by default). Safe to call more than once, and a no-op where there is no
|
|
218
|
+
* registry (a server render).
|
|
219
|
+
*/
|
|
220
|
+
export function definePopover(registry = globalThis.customElements) {
|
|
221
|
+
defineElements(registry, [
|
|
222
|
+
[ROOT, PrimitivPopoverElement],
|
|
223
|
+
[TRIGGER, PrimitivPopoverTriggerElement],
|
|
224
|
+
[ANCHOR, PrimitivPopoverAnchorElement],
|
|
225
|
+
[CONTENT, PrimitivPopoverContentElement],
|
|
226
|
+
[TITLE, PrimitivPopoverTitleElement],
|
|
227
|
+
[DESCRIPTION, PrimitivPopoverDescriptionElement],
|
|
228
|
+
[CLOSE, PrimitivPopoverCloseElement],
|
|
229
|
+
]);
|
|
230
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { PopoverController, type PopoverControllerHost } from "./PopoverController.js";
|
|
2
|
+
export { definePopover, PrimitivPopoverAnchorElement, PrimitivPopoverCloseElement, PrimitivPopoverContentElement, PrimitivPopoverDescriptionElement, PrimitivPopoverElement, PrimitivPopoverTitleElement, PrimitivPopoverTriggerElement, } from "./elements.js";
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { PopoverController } from "./PopoverController.js";
|
|
2
|
+
export { definePopover, PrimitivPopoverAnchorElement, PrimitivPopoverCloseElement, PrimitivPopoverContentElement, PrimitivPopoverDescriptionElement, PrimitivPopoverElement, PrimitivPopoverTitleElement, PrimitivPopoverTriggerElement, } from "./elements.js";
|
package/dist/primitiv-web.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function v(e,t,o){return`${e}-${t}-${o}`}function M({orientation:e,dir:t,homeEnd:o=!1,activate:n=!1}){let l={};if(e==="horizontal"||e==="both"){let s=t==="rtl"?"ArrowLeft":"ArrowRight",d=t==="rtl"?"ArrowRight":"ArrowLeft";l[s]="next",l[d]="prev"}return(e==="vertical"||e==="both")&&(l.ArrowDown="next",l.ArrowUp="prev"),o&&(l.Home="first",l.End="last"),n&&(l.Enter="activate",l[" "]="activate"),l}function O({action:e,navigable:t,currentKey:o}){let n=t.length;if(n===0)return null;switch(e){case"activate":return{target:o};case"first":return{target:t[0]};case"last":return{target:t[n-1]};case void 0:return null;case"next":case"prev":{let l=t.indexOf(o);if(l===-1)return null;let s=e==="next"?1:n-1;return{target:t[(l+s)%n]}}}}function V(e){return e.active??e.values[0]}function w(e,t){return e.disabled.has(t)||e.active===t?null:t}function X(e,t,o){let n=M({orientation:e.orientation,dir:e.dir,homeEnd:!0,activate:!0})[o],l=O({action:n,navigable:e.values,currentKey:t});if(!l)return null;let s=l.target,d=e.activationMode==="automatic"||n==="activate";return{focus:s,activate:d?w(e,s):null}}function Y(e,t){return e.disabled.has(t)?null:e.expanded.includes(t)?e.expanded.filter(o=>o!==t):e.multiple?[...e.expanded,t]:[t]}function J(e,t,o){let n=M({orientation:e.orientation,dir:e.dir,homeEnd:!0,activate:!0})[o];if(n==="activate")return e.disabled.has(t)?null:{focus:null,toggle:t};let l=e.values.filter(d=>!e.disabled.has(d)),s=O({action:n,navigable:l,currentKey:t});return s&&{focus:s.target,toggle:null}}function H(e){return e.disabled?null:!e.open}function Q(e,t){if(t!=="Enter"&&t!==" ")return null;let o=H(e);return o===null?null:{open:o}}var Z=["a[href]","button:not([disabled])","input:not([disabled])","select:not([disabled])","textarea:not([disabled])",'[tabindex]:not([tabindex="-1"])'].join(",");function tt({key:e,shiftKey:t,active:o,count:n}){if(e!=="Tab")return null;if(n===0)return{focus:null};let l=n-1;return!t&&o===l?{focus:0}:t&&o===0?{focus:l}:null}function et(e,t){return t.x<e.left||t.x>e.right||t.y<e.top||t.y>e.bottom}var b=class{#t;#e=new Map;#o=null;constructor(t){this.#t=t}registerTrigger(t,o,n={}){this.#e.set(o,{value:t,disabled:n.disabled??!1})}setTriggers(t){this.#e.clear();for(let{value:o,element:n,disabled:l}of t)this.registerTrigger(o,n,{disabled:l})}unregisterTrigger(t){this.#e.delete(t)}connect(){if(this.#o)return;this.#o=new AbortController;let{signal:t}=this.#o;this.#t.addEventListener("click",o=>this.#n(o,this.onTriggerClick),{signal:t}),this.#t.addEventListener("keydown",o=>this.#n(o,this.onTriggerKeydown),{signal:t})}disconnect(){this.#o?.abort(),this.#o=null}ordered(){return[...this.#e].sort(([t],[o])=>t.compareDocumentPosition(o)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1)}disabled(){let t=new Set;for(let o of this.#e.values())o.disabled&&t.add(o.value);return t}#n(t,o){for(let[n,l]of this.#e)if(n.contains(t.target))return o.call(this,l,t)}};var x=class extends b{#t;constructor(t,o){super(t),this.#t=o}#e(t){let{expanded:o,multiple:n}=this.#t.state(),l=Y({disabled:this.disabled(),expanded:o,multiple:n},t);l!==null&&this.#t.change(l)}onTriggerClick(t){this.#e(t.value)}onTriggerKeydown(t,o){let{expanded:n,multiple:l,orientation:s,dir:d}=this.#t.state(),u=this.ordered(),a=u.map(([,c])=>c.value),i=J({values:a,disabled:this.disabled(),expanded:n,multiple:l,orientation:s,dir:d},t.value,o.key);i&&(o.preventDefault(),i.toggle!==null&&this.#e(i.toggle),i.focus!==null&&u[a.indexOf(i.focus)][0].focus())}};var p=globalThis.HTMLElement??class{};function r(e,t,o){e.getAttribute(t)!==o&&(o===null?e.removeAttribute(t):e.setAttribute(t,o))}var gt=new WeakSet;function h(e,t){gt.has(e)||(gt.add(e),console.error(t,e))}function f(e,t){if(e)for(let[o,n]of t)e.get(o)||e.define(o,n)}function y(e,t,o){return[...e.querySelectorAll(t)].filter(n=>n.closest(o)===e)}var At=0,m=class extends p{#t;#e=new MutationObserver(()=>this.reconcile());connectedCallback(){this.controller.connect(),this.#e.observe(this,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[...this.reconcileOn]}),this.reconcile()}disconnectedCallback(){this.controller.disconnect(),this.#e.disconnect()}rootId(){return this.id||(this.#t??=`${this.localName}-${++At}`)}direction(){return this.matches(":dir(rtl)")?"rtl":"ltr"}parts(t){return y(this,t,this.localName)}announce(t,o){return this.dispatchEvent(new CustomEvent(t,{bubbles:!0,cancelable:!0,detail:o}))}};var Mt="primitiv-accordion",T="primitiv-accordion-item",ot="primitiv-accordion-trigger",ht="primitiv-accordion-content",mt="primitiv-accordion-trigger-icon";function Ot(e){return(e??"").split(/\s+/).filter(Boolean)}function wt(e){return e.childElementCount===1?e.firstElementChild:(h(e,`<${ot}> needs exactly one element child (a <button>) to decorate.`),null)}var R=class extends m{#t=new Set;#e=!1;controller=new x(this,this.#o());reconcileOn=["value","disabled","orientation","force-mount"];get value(){return Ot(this.getAttribute("value"))}set value(t){this.setAttribute("value",typeof t=="string"?t:t.join(" "))}#o(){return{state:()=>({expanded:this.value,multiple:this.hasAttribute("multiple"),orientation:this.#n(),dir:this.direction()}),change:t=>{this.announce("primitiv-accordion-change",{value:t})&&(this.value=t)}}}#n(){return this.getAttribute("orientation")==="horizontal"?"horizontal":"vertical"}reconcile(){let t=new Set(this.value),o=this.rootId();r(this,"data-orientation",this.#n());let n=[];for(let l of this.parts(T)){let s=l.getAttribute("value");if(s===null){h(l,`<${T}> needs a value, which pairs it with the root's value.`);continue}let d=t.has(s),u=d?"open":"closed",[a]=y(l,ot,T),[i]=y(l,ht,T),c=a?wt(a):null;if(c){let g=a.hasAttribute("disabled");n.push({value:s,element:c,disabled:g}),c.id||(c.id=v(o,"heading",s)),r(c,"aria-expanded",String(d)),r(c,"aria-disabled",String(g)),r(c,"data-disabled",String(g)),r(c,"data-state",u)}if(i){i.id||(i.id=v(o,"panel",s));let g=i.hasAttribute("force-mount");i.hasAttribute("role")||i.setAttribute("role","region"),r(i,"aria-labelledby",c?c.id:null),r(i,"hidden",d||g?null:""),r(i,"aria-hidden",d?null:"true"),r(i,"data-state",u),this.#e&&d&&!this.#t.has(s)&&i.dispatchEvent(new CustomEvent("primitiv-accordion-show",{bubbles:!0}))}c&&r(c,"aria-controls",i?i.id:null);for(let g of y(l,mt,T))r(g,"aria-hidden","true"),r(g,"data-state",u)}this.controller.setTriggers(n),this.#t=t,this.#e=!0}},L=class extends p{},K=class extends p{},S=class extends p{},k=class extends p{};function nt(e=globalThis.customElements){f(e,[[Mt,R],[T,L],[ot,K],[ht,S],[mt,k]])}var E=class extends b{#t;constructor(t,o){super(t),this.#t=o}onTriggerClick(t){let o=H({open:this.#t.state().open,disabled:t.disabled});o!==null&&this.#t.change(o)}onTriggerKeydown(t,o){let n=Q({open:this.#t.state().open,disabled:t.disabled},o.key);n&&(o.preventDefault(),this.#t.change(n.open))}};var Ht="primitiv-collapsible",it="primitiv-collapsible-trigger",bt="primitiv-collapsible-content",ft="primitiv-collapsible-trigger-icon",Rt="--primitiv-collapsible-collapsed-height";function Lt(e){return e.childElementCount===1?e.firstElementChild:(h(e,`<${it}> needs exactly one element child (a <button>) to decorate.`),null)}function Kt(e){return Number.isNaN(Number(e))?e:`${e}px`}function St(e,t,o){e.style.getPropertyValue(t)!==o&&(e.style.setProperty(t,o),e.getAttribute("style")===""&&e.removeAttribute("style"))}var I=class extends m{#t;controller=new E(this,this.#e());reconcileOn=["open","disabled","force-mount","collapsed-height"];get open(){return this.hasAttribute("open")}set open(t){this.toggleAttribute("open",t)}#e(){return{state:()=>({open:this.open}),change:t=>{this.announce("primitiv-collapsible-change",{open:t})&&(this.open=t)}}}reconcile(){let t=this.open,o=t?"open":"closed",n=this.hasAttribute("disabled"),l=this.rootId();r(this,"data-state",o),r(this,"data-disabled",String(n));let[s]=this.parts(it),[d]=this.parts(bt),u=s?Lt(s):null;if(u&&(u.id||(u.id=`${l}-trigger`),r(u,"aria-expanded",String(t)),r(u,"aria-disabled",n?"true":null),r(u,"data-disabled",String(n)),r(u,"data-state",o)),d){d.id||(d.id=`${l}-content`);let a=d.getAttribute("collapsed-height"),i=a!==null,c=i||d.hasAttribute("force-mount");r(d,"hidden",t||c?null:""),r(d,"aria-hidden",t||i?null:"true"),r(d,"data-state",o),r(d,"data-disabled",String(n)),r(d,"data-clamped",i?"true":null),St(d,Rt,i?Kt(a):""),t&&this.#t===!1&&d.dispatchEvent(new CustomEvent("primitiv-collapsible-show",{bubbles:!0}))}u&&r(u,"aria-controls",d?d.id:null);for(let a of this.parts(ft))r(a,"aria-hidden","true"),r(a,"data-state",o);this.controller.setTriggers(u?[{value:"trigger",element:u,disabled:n}]:[]),this.#t=t}},D=class extends p{},N=class extends p{},P=class extends p{};function rt(e=globalThis.customElements){f(e,[[Ht,I],[it,D],[bt,N],[ft,P]])}var C=class{#t;#e;#o=null;constructor(t,o){this.#t=t,this.#e=o}connect(){if(this.#o)return;this.#o=new AbortController;let{signal:t}=this.#o,o=this.#t;o.addEventListener("close",()=>this.#e.change(!1),{signal:t}),o.addEventListener("cancel",n=>this.#n(n),{signal:t}),o.addEventListener("pointerdown",n=>this.#i(n),{signal:t}),o.addEventListener("keydown",n=>this.#r(n),{signal:t})}disconnect(){this.#o?.abort(),this.#o=null}sync(){let{open:t}=this.#e.state();t&&!this.#t.open?this.#t.showModal():!t&&this.#t.open&&this.#t.close()}#n(t){this.#e.escapeKeyDown?.(t);let o=t.defaultPrevented;t.preventDefault(),o||this.#e.change(!1)}#i(t){let o={x:t.clientX,y:t.clientY};et(this.#t.getBoundingClientRect(),o)&&(this.#e.pointerDownOutside?.(t),t.defaultPrevented||this.#e.change(!1))}#r(t){if(!this.#t.open)return;let o=[...this.#t.querySelectorAll(Z)],n=tt({key:t.key,shiftKey:t.shiftKey,active:o.indexOf(document.activeElement),count:o.length});n&&(t.preventDefault(),n.focus!==null&&o[n.focus].focus())}};var kt="primitiv-modal",vt="primitiv-modal-trigger",st="primitiv-modal-content",yt="primitiv-modal-title",Tt="primitiv-modal-description",xt="primitiv-modal-close";function lt(e,t){return e.childElementCount===1?e.firstElementChild:(h(e,`<${e.localName}> needs exactly one element child (${t}) to decorate.`),null)}function It(e){let t=e.firstElementChild;return e.childElementCount===1&&t instanceof HTMLDialogElement?t:(h(e,`<${st}> needs exactly one <dialog> child to decorate.`),null)}var $=class extends m{#t=null;#e=null;#o=[];#n=[];#i=null;controller={connect:()=>this.#a(),disconnect:()=>this.#d()};reconcileOn=["open"];get open(){return this.hasAttribute("open")}set open(t){this.toggleAttribute("open",t)}#r(){return{state:()=>({open:this.open}),change:t=>this.#l(t)}}#l(t){t!==this.open&&(this.announce("primitiv-modal-change",{open:t})?this.open=t:this.#e?.sync())}#a(){this.#i=new AbortController,this.addEventListener("click",t=>this.#c(t),{signal:this.#i.signal}),this.#e?.connect()}#d(){this.#i.abort(),this.#i=null,this.#e?.disconnect(),this.#t&&r(this.#t,"open",null)}#c(t){let o=t.target;this.#o.some(n=>n.contains(o))?this.#l(!0):this.#n.some(n=>n.contains(o))&&this.#l(!1)}#u(t){t!==this.#t&&(this.#e?.disconnect(),t&&r(t,"open",null),this.#t=t,this.#e=t?new C(t,this.#r()):null,this.#e?.connect())}reconcile(){let t=this.open,o=t?"open":"closed",n=this.rootId();r(this,"data-state",o);let[l]=this.parts(st),s=l?It(l):null,[d]=this.parts(yt),u=d?lt(d,"a heading"):null,[a]=this.parts(Tt),i=a?lt(a,"a <p>"):null;u&&!u.id&&(u.id=`${n}-title`),i&&!i.id&&(i.id=`${n}-description`),s&&(s.id||(s.id=`${n}-content`),r(s,"data-state",o),r(s,"aria-labelledby",u?u.id:null),r(s,"aria-describedby",i?i.id:null)),this.#o=this.#s(vt);for(let c of this.#o)r(c,"aria-haspopup","dialog"),r(c,"aria-expanded",String(t)),r(c,"aria-controls",s?s.id:null);this.#n=this.#s(xt),this.#u(s),this.#e?.sync()}#s(t){return this.parts(t).flatMap(o=>lt(o,"a <button>")??[])}},B=class extends p{},G=class extends p{},z=class extends p{},F=class extends p{},U=class extends p{};function at(e=globalThis.customElements){f(e,[[kt,$],[vt,B],[st,G],[yt,z],[Tt,F],[xt,U]])}var A=class extends b{#t;constructor(t,o){super(t),this.#t=o}onTriggerClick(t){let{active:o}=this.#t.state(),n=w({disabled:this.disabled(),active:o},t.value);if(n!==null){let l=this.ordered().map(([,s])=>s.value);this.#t.activate(n,l.indexOf(n))}}onTriggerKeydown(t,o){let{active:n,orientation:l,dir:s,activationMode:d}=this.#t.state(),u=this.ordered(),a=u.map(([,c])=>c.value),i=X({values:a,disabled:this.disabled(),active:n,orientation:l,dir:s,activationMode:d},t.value,o.key);i&&(o.preventDefault(),i.activate!==null&&this.#t.activate(i.activate,a.indexOf(i.activate)),u[a.indexOf(i.focus)][0].focus())}};var Dt="primitiv-tabs",Et="primitiv-tabs-list",dt="primitiv-tabs-trigger",Ct="primitiv-tabs-content";function Nt(e){let t=e.getAttribute("value");return e.childElementCount===1&&t!==null?{tab:e.firstElementChild,value:t}:(h(e,`<${dt}> needs a value and exactly one element child (a <button>, an <a href> or a router link) to decorate.`),null)}var _=class extends m{#t;#e=!1;controller=new A(this,this.#o());reconcileOn=["value","disabled","label","orientation"];get value(){return this.getAttribute("value")??void 0}set value(t){this.setAttribute("value",t)}#o(){return{state:()=>({active:this.value,orientation:this.#i(),dir:this.direction(),activationMode:this.#n()}),activate:(t,o)=>{this.announce("primitiv-tabs-change",{value:t,index:o})&&(this.value=t)}}}#n(){let t=this.getAttribute("activation-mode");return t==="manual"?t:"automatic"}#i(){return this.getAttribute("orientation")==="vertical"?"vertical":"horizontal"}reconcile(){let t=this.#i(),o=this.value,n=this.rootId();r(this,"data-orientation",t);for(let a of this.parts(Et)){r(a,"role","tablist"),r(a,"aria-orientation",t),r(a,"data-orientation",t);let i=a.getAttribute("label");i!==null&&r(a,"aria-label",i)}let l=new Map;for(let a of this.parts(Ct)){let i=a.getAttribute("value");i!==null&&l.set(i,a)}let s=this.parts(dt).flatMap(a=>{let i=Nt(a);return i?[{trigger:a,...i}]:[]}),d=V({values:s.map(a=>a.value),active:o});this.controller.setTriggers(s.map(({trigger:a,tab:i,value:c})=>({value:c,element:i,disabled:a.hasAttribute("disabled")})));for(let{trigger:a,tab:i,value:c}of s){let g=l.get(c),ut=c===o,pt=a.hasAttribute("disabled");i.id||(i.id=v(n,"trigger",c)),g&&!g.id&&(g.id=v(n,"panel",c)),r(i,"role","tab"),r(i,"aria-selected",String(ut)),r(i,"aria-controls",g?g.id:null),r(i,"tabindex",c===d?"0":"-1"),r(i,"aria-disabled",pt?"true":null),r(i,"data-disabled",pt?"":null),r(i,"data-state",ut?"active":"inactive"),r(i,"data-orientation",t),g&&r(g,"aria-labelledby",i.id)}for(let[a,i]of l){let c=a===o;r(i,"role","tabpanel"),r(i,"tabindex","0"),r(i,"hidden",c?null:""),r(i,"data-state",c?"active":"inactive"),r(i,"data-orientation",t)}let u=l.get(o);this.#e&&o!==this.#t&&u&&u.dispatchEvent(new CustomEvent("primitiv-tabs-show",{bubbles:!0})),this.#t=o,this.#e=!0}},q=class extends p{},j=class extends p{},W=class extends p{};function ct(e=globalThis.customElements){f(e,[[Dt,_],[Et,q],[dt,j],[Ct,W]])}nt();rt();at();ct();export{x as AccordionController,E as CollapsibleController,C as ModalController,S as PrimitivAccordionContentElement,R as PrimitivAccordionElement,L as PrimitivAccordionItemElement,K as PrimitivAccordionTriggerElement,k as PrimitivAccordionTriggerIconElement,N as PrimitivCollapsibleContentElement,I as PrimitivCollapsibleElement,D as PrimitivCollapsibleTriggerElement,P as PrimitivCollapsibleTriggerIconElement,U as PrimitivModalCloseElement,G as PrimitivModalContentElement,F as PrimitivModalDescriptionElement,$ as PrimitivModalElement,z as PrimitivModalTitleElement,B as PrimitivModalTriggerElement,W as PrimitivTabsContentElement,_ as PrimitivTabsElement,q as PrimitivTabsListElement,j as PrimitivTabsTriggerElement,A as TabsController,nt as defineAccordion,rt as defineCollapsible,at as defineModal,ct as defineTabs};
|
|
1
|
+
function v(e,t,o){return`${e}-${t}-${o}`}function H({orientation:e,dir:t,homeEnd:o=!1,activate:n=!1}){let s={};if(e==="horizontal"||e==="both"){let l=t==="rtl"?"ArrowLeft":"ArrowRight",d=t==="rtl"?"ArrowRight":"ArrowLeft";s[l]="next",s[d]="prev"}return(e==="vertical"||e==="both")&&(s.ArrowDown="next",s.ArrowUp="prev"),o&&(s.Home="first",s.End="last"),n&&(s.Enter="activate",s[" "]="activate"),s}function L({action:e,navigable:t,currentKey:o}){let n=t.length;if(n===0)return null;switch(e){case"activate":return{target:o};case"first":return{target:t[0]};case"last":return{target:t[n-1]};case void 0:return null;case"next":case"prev":{let s=t.indexOf(o);if(s===-1)return null;let l=e==="next"?1:n-1;return{target:t[(s+l)%n]}}}}function it(e){return e.active??e.values[0]}function R(e,t){return e.disabled.has(t)||e.active===t?null:t}function rt(e,t,o){let n=H({orientation:e.orientation,dir:e.dir,homeEnd:!0,activate:!0})[o],s=L({action:n,navigable:e.values,currentKey:t});if(!s)return null;let l=s.target,d=e.activationMode==="automatic"||n==="activate";return{focus:l,activate:d?R(e,l):null}}function st(e,t){return e.disabled.has(t)?null:e.expanded.includes(t)?e.expanded.filter(o=>o!==t):e.multiple?[...e.expanded,t]:[t]}function lt(e,t,o){let n=H({orientation:e.orientation,dir:e.dir,homeEnd:!0,activate:!0})[o];if(n==="activate")return e.disabled.has(t)?null:{focus:null,toggle:t};let s=e.values.filter(d=>!e.disabled.has(d)),l=L({action:n,navigable:s,currentKey:t});return l&&{focus:l.target,toggle:null}}function K(e){return e.disabled?null:!e.open}function at(e,t){if(t!=="Enter"&&t!==" ")return null;let o=K(e);return o===null?null:{open:o}}var E=["a[href]","button:not([disabled])","input:not([disabled])","select:not([disabled])","textarea:not([disabled])",'[tabindex]:not([tabindex="-1"])'].join(",");function ct({key:e,shiftKey:t,active:o,count:n}){if(e!=="Tab")return null;if(n===0)return{focus:null};let s=n-1;return!t&&o===s?{focus:0}:t&&o===0?{focus:s}:null}function dt(e,t){return t.x<e.left||t.x>e.right||t.y<e.top||t.y>e.bottom}function pt(e){return e==="Escape"?{open:!1}:null}function ut({open:e,nativeLightDismiss:t,inTrigger:o,inPopover:n}){return e&&!t&&!o&&!n}var f=class{#t;#e=new Map;#o=null;constructor(t){this.#t=t}registerTrigger(t,o,n={}){this.#e.set(o,{value:t,disabled:n.disabled??!1})}setTriggers(t){this.#e.clear();for(let{value:o,element:n,disabled:s}of t)this.registerTrigger(o,n,{disabled:s})}unregisterTrigger(t){this.#e.delete(t)}connect(){if(this.#o)return;this.#o=new AbortController;let{signal:t}=this.#o;this.#t.addEventListener("click",o=>this.#n(o,this.onTriggerClick),{signal:t}),this.#t.addEventListener("keydown",o=>this.#n(o,this.onTriggerKeydown),{signal:t})}disconnect(){this.#o?.abort(),this.#o=null}ordered(){return[...this.#e].sort(([t],[o])=>t.compareDocumentPosition(o)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1)}disabled(){let t=new Set;for(let o of this.#e.values())o.disabled&&t.add(o.value);return t}#n(t,o){for(let[n,s]of this.#e)if(n.contains(t.target))return o.call(this,s,t)}};var x=class extends f{#t;constructor(t,o){super(t),this.#t=o}#e(t){let{expanded:o,multiple:n}=this.#t.state(),s=st({disabled:this.disabled(),expanded:o,multiple:n},t);s!==null&&this.#t.change(s)}onTriggerClick(t){this.#e(t.value)}onTriggerKeydown(t,o){let{expanded:n,multiple:s,orientation:l,dir:d}=this.#t.state(),p=this.ordered(),a=p.map(([,c])=>c.value),i=lt({values:a,disabled:this.disabled(),expanded:n,multiple:s,orientation:l,dir:d},t.value,o.key);i&&(o.preventDefault(),i.toggle!==null&&this.#e(i.toggle),i.focus!==null&&p[a.indexOf(i.focus)][0].focus())}};var u=globalThis.HTMLElement??class{};function r(e,t,o){e.getAttribute(t)!==o&&(o===null?e.removeAttribute(t):e.setAttribute(t,o))}var Mt=new WeakSet;function g(e,t){Mt.has(e)||(Mt.add(e),console.error(t,e))}function b(e,t){if(e)for(let[o,n]of t)e.get(o)||e.define(o,n)}function y(e,t,o){return[...e.querySelectorAll(t)].filter(n=>n.closest(o)===e)}var Ft=0,m=class extends u{#t;#e=new MutationObserver(()=>this.reconcile());connectedCallback(){this.controller.connect(),this.#e.observe(this,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[...this.reconcileOn]}),this.reconcile()}disconnectedCallback(){this.controller.disconnect(),this.#e.disconnect()}rootId(){return this.id||(this.#t??=`${this.localName}-${++Ft}`)}direction(){return this.matches(":dir(rtl)")?"rtl":"ltr"}parts(t){return y(this,t,this.localName)}announce(t,o){return this.dispatchEvent(new CustomEvent(t,{bubbles:!0,cancelable:!0,detail:o}))}};var Ut="primitiv-accordion",T="primitiv-accordion-item",ht="primitiv-accordion-trigger",Ot="primitiv-accordion-content",wt="primitiv-accordion-trigger-icon";function _t(e){return(e??"").split(/\s+/).filter(Boolean)}function qt(e){return e.childElementCount===1?e.firstElementChild:(g(e,`<${ht}> needs exactly one element child (a <button>) to decorate.`),null)}var P=class extends m{#t=new Set;#e=!1;controller=new x(this,this.#o());reconcileOn=["value","disabled","orientation","force-mount"];get value(){return _t(this.getAttribute("value"))}set value(t){this.setAttribute("value",typeof t=="string"?t:t.join(" "))}#o(){return{state:()=>({expanded:this.value,multiple:this.hasAttribute("multiple"),orientation:this.#n(),dir:this.direction()}),change:t=>{this.announce("primitiv-accordion-change",{value:t})&&(this.value=t)}}}#n(){return this.getAttribute("orientation")==="horizontal"?"horizontal":"vertical"}reconcile(){let t=new Set(this.value),o=this.rootId();r(this,"data-orientation",this.#n());let n=[];for(let s of this.parts(T)){let l=s.getAttribute("value");if(l===null){g(s,`<${T}> needs a value, which pairs it with the root's value.`);continue}let d=t.has(l),p=d?"open":"closed",[a]=y(s,ht,T),[i]=y(s,Ot,T),c=a?qt(a):null;if(c){let h=a.hasAttribute("disabled");n.push({value:l,element:c,disabled:h}),c.id||(c.id=v(o,"heading",l)),r(c,"aria-expanded",String(d)),r(c,"aria-disabled",String(h)),r(c,"data-disabled",String(h)),r(c,"data-state",p)}if(i){i.id||(i.id=v(o,"panel",l));let h=i.hasAttribute("force-mount");i.hasAttribute("role")||i.setAttribute("role","region"),r(i,"aria-labelledby",c?c.id:null),r(i,"hidden",d||h?null:""),r(i,"aria-hidden",d?null:"true"),r(i,"data-state",p),this.#e&&d&&!this.#t.has(l)&&i.dispatchEvent(new CustomEvent("primitiv-accordion-show",{bubbles:!0}))}c&&r(c,"aria-controls",i?i.id:null);for(let h of y(s,wt,T))r(h,"aria-hidden","true"),r(h,"data-state",p)}this.controller.setTriggers(n),this.#t=t,this.#e=!0}},S=class extends u{},k=class extends u{},D=class extends u{},I=class extends u{};function gt(e=globalThis.customElements){b(e,[[Ut,P],[T,S],[ht,k],[Ot,D],[wt,I]])}var C=class extends f{#t;constructor(t,o){super(t),this.#t=o}onTriggerClick(t){let o=K({open:this.#t.state().open,disabled:t.disabled});o!==null&&this.#t.change(o)}onTriggerKeydown(t,o){let n=at({open:this.#t.state().open,disabled:t.disabled},o.key);n&&(o.preventDefault(),this.#t.change(n.open))}};var jt="primitiv-collapsible",mt="primitiv-collapsible-trigger",Ht="primitiv-collapsible-content",Lt="primitiv-collapsible-trigger-icon",Wt="--primitiv-collapsible-collapsed-height";function Vt(e){return e.childElementCount===1?e.firstElementChild:(g(e,`<${mt}> needs exactly one element child (a <button>) to decorate.`),null)}function Xt(e){return Number.isNaN(Number(e))?e:`${e}px`}function Yt(e,t,o){e.style.getPropertyValue(t)!==o&&(e.style.setProperty(t,o),e.getAttribute("style")===""&&e.removeAttribute("style"))}var N=class extends m{#t;controller=new C(this,this.#e());reconcileOn=["open","disabled","force-mount","collapsed-height"];get open(){return this.hasAttribute("open")}set open(t){this.toggleAttribute("open",t)}#e(){return{state:()=>({open:this.open}),change:t=>{this.announce("primitiv-collapsible-change",{open:t})&&(this.open=t)}}}reconcile(){let t=this.open,o=t?"open":"closed",n=this.hasAttribute("disabled"),s=this.rootId();r(this,"data-state",o),r(this,"data-disabled",String(n));let[l]=this.parts(mt),[d]=this.parts(Ht),p=l?Vt(l):null;if(p&&(p.id||(p.id=`${s}-trigger`),r(p,"aria-expanded",String(t)),r(p,"aria-disabled",n?"true":null),r(p,"data-disabled",String(n)),r(p,"data-state",o)),d){d.id||(d.id=`${s}-content`);let a=d.getAttribute("collapsed-height"),i=a!==null,c=i||d.hasAttribute("force-mount");r(d,"hidden",t||c?null:""),r(d,"aria-hidden",t||i?null:"true"),r(d,"data-state",o),r(d,"data-disabled",String(n)),r(d,"data-clamped",i?"true":null),Yt(d,Wt,i?Xt(a):""),t&&this.#t===!1&&d.dispatchEvent(new CustomEvent("primitiv-collapsible-show",{bubbles:!0}))}p&&r(p,"aria-controls",d?d.id:null);for(let a of this.parts(Lt))r(a,"aria-hidden","true"),r(a,"data-state",o);this.controller.setTriggers(p?[{value:"trigger",element:p,disabled:n}]:[]),this.#t=t}},$=class extends u{},B=class extends u{},G=class extends u{};function bt(e=globalThis.customElements){b(e,[[jt,N],[mt,$],[Ht,B],[Lt,G]])}var A=class{#t;#e;#o=null;constructor(t,o){this.#t=t,this.#e=o}connect(){if(this.#o)return;this.#o=new AbortController;let{signal:t}=this.#o,o=this.#t;o.addEventListener("close",()=>this.#e.change(!1),{signal:t}),o.addEventListener("cancel",n=>this.#n(n),{signal:t}),o.addEventListener("pointerdown",n=>this.#i(n),{signal:t}),o.addEventListener("keydown",n=>this.#r(n),{signal:t})}disconnect(){this.#o?.abort(),this.#o=null}sync(){let{open:t}=this.#e.state();t&&!this.#t.open?this.#t.showModal():!t&&this.#t.open&&this.#t.close()}#n(t){this.#e.escapeKeyDown?.(t);let o=t.defaultPrevented;t.preventDefault(),o||this.#e.change(!1)}#i(t){let o={x:t.clientX,y:t.clientY};dt(this.#t.getBoundingClientRect(),o)&&(this.#e.pointerDownOutside?.(t),t.defaultPrevented||this.#e.change(!1))}#r(t){if(!this.#t.open)return;let o=[...this.#t.querySelectorAll(E)],n=ct({key:t.key,shiftKey:t.shiftKey,active:o.indexOf(document.activeElement),count:o.length});n&&(t.preventDefault(),n.focus!==null&&o[n.focus].focus())}};var Jt="primitiv-modal",Rt="primitiv-modal-trigger",vt="primitiv-modal-content",Kt="primitiv-modal-title",Pt="primitiv-modal-description",St="primitiv-modal-close";function ft(e,t){return e.childElementCount===1?e.firstElementChild:(g(e,`<${e.localName}> needs exactly one element child (${t}) to decorate.`),null)}function Qt(e){let t=e.firstElementChild;return e.childElementCount===1&&t instanceof HTMLDialogElement?t:(g(e,`<${vt}> needs exactly one <dialog> child to decorate.`),null)}var z=class extends m{#t=null;#e=null;#o=[];#n=[];#i=null;controller={connect:()=>this.#l(),disconnect:()=>this.#c()};reconcileOn=["open"];get open(){return this.hasAttribute("open")}set open(t){this.toggleAttribute("open",t)}#r(){return{state:()=>({open:this.open}),change:t=>this.#s(t)}}#s(t){t!==this.open&&(this.announce("primitiv-modal-change",{open:t})?this.open=t:this.#e?.sync())}#l(){this.#i=new AbortController,this.addEventListener("click",t=>this.#d(t),{signal:this.#i.signal}),this.#e?.connect()}#c(){this.#i.abort(),this.#i=null,this.#e?.disconnect(),this.#t&&r(this.#t,"open",null)}#d(t){let o=t.target;this.#o.some(n=>n.contains(o))?this.#s(!0):this.#n.some(n=>n.contains(o))&&this.#s(!1)}#p(t){t!==this.#t&&(this.#e?.disconnect(),t&&r(t,"open",null),this.#t=t,this.#e=t?new A(t,this.#r()):null,this.#e?.connect())}reconcile(){let t=this.open,o=t?"open":"closed",n=this.rootId();r(this,"data-state",o);let[s]=this.parts(vt),l=s?Qt(s):null,[d]=this.parts(Kt),p=d?ft(d,"a heading"):null,[a]=this.parts(Pt),i=a?ft(a,"a <p>"):null;p&&!p.id&&(p.id=`${n}-title`),i&&!i.id&&(i.id=`${n}-description`),l&&(l.id||(l.id=`${n}-content`),r(l,"data-state",o),r(l,"aria-labelledby",p?p.id:null),r(l,"aria-describedby",i?i.id:null)),this.#o=this.#a(Rt);for(let c of this.#o)r(c,"aria-haspopup","dialog"),r(c,"aria-expanded",String(t)),r(c,"aria-controls",l?l.id:null);this.#n=this.#a(St),this.#p(l),this.#e?.sync()}#a(t){return this.parts(t).flatMap(o=>ft(o,"a <button>")??[])}},F=class extends u{},U=class extends u{},_=class extends u{},q=class extends u{},j=class extends u{};function yt(e=globalThis.customElements){b(e,[[Jt,z],[Rt,F],[vt,U],[Kt,_],[Pt,q],[St,j]])}var M=class{#t;#e;#o=null;#n=!1;constructor(t,o){this.#t=t,this.#e=o}connect(){if(this.#o)return;this.#o=new AbortController;let{signal:t}=this.#o;this.#t.addEventListener("toggle",o=>this.#i(o),{signal:t}),this.#t.addEventListener("keydown",o=>this.#r(o),{signal:t}),document.addEventListener("click",o=>this.#s(o),{signal:t})}disconnect(){this.#o?.abort(),this.#o=null,this.#n=!1}sync(){let{open:t}=this.#e.state();if(t&&!this.#n){this.#n=!0;let o=this.#e.source?.();o?this.#t.showPopover({source:o}):this.#t.showPopover(),(this.#t.querySelector(E)??this.#t).focus()}else if(!t&&this.#n){this.#n=!1;try{this.#t.hidePopover()}catch{}}}#i(t){t.newState==="closed"&&(this.#n=!1,this.#e.change(!1))}#r(t){t.defaultPrevented||!pt(t.key)||(t.preventDefault(),this.#e.change(!1),this.#e.trigger()?.focus())}#s(t){let o=t.target;ut({open:this.#e.state().open,nativeLightDismiss:"popover"in HTMLElement.prototype,inTrigger:this.#e.trigger()?.contains(o)??!1,inPopover:o.closest("[popover]")!==null})&&this.#e.change(!1)}};var Zt="primitiv-popover",kt="primitiv-popover-trigger",Dt="primitiv-popover-anchor",It="primitiv-popover-content",Nt="primitiv-popover-title",$t="primitiv-popover-description",Bt="primitiv-popover-close";function O(e,t){return e.childElementCount===1?e.firstElementChild:(g(e,`<${e.localName}> needs exactly one element child (${t}) to decorate.`),null)}var W=class extends m{#t=null;#e=null;#o=null;#n=null;#i=[];#r=null;controller={connect:()=>this.#c(),disconnect:()=>this.#d()};reconcileOn=["open"];get open(){return this.hasAttribute("open")}set open(t){this.toggleAttribute("open",t)}#s(){return{state:()=>({open:this.open}),change:t=>this.#l(t),trigger:()=>this.#o,source:()=>this.#n??this.#o}}#l(t){t!==this.open&&(this.announce("primitiv-popover-change",{open:t})?this.open=t:queueMicrotask(()=>this.#e?.sync()))}#c(){this.#r=new AbortController,this.addEventListener("click",t=>this.#p(t),{signal:this.#r.signal}),this.#e?.connect()}#d(){this.#r.abort(),this.#r=null,this.#e?.disconnect()}#p(t){let o=t.target;this.#o?.contains(o)?this.#l(!this.open):this.#i.some(n=>n.contains(o))&&this.#l(!1)}#a(t){t!==this.#t&&(this.#e?.disconnect(),this.#t=t,this.#e=t?new M(t,this.#s()):null,this.#e?.connect())}reconcile(){let t=this.open,o=t?"open":"closed",n=this.rootId();r(this,"data-state",o);let[s=null]=this.parts(It),[l]=this.parts(kt),[d]=this.parts(Dt),[p]=this.parts(Nt),[a]=this.parts($t);this.#o=l?O(l,"a <button>"):null,this.#n=d?O(d,"the element to anchor to"):null;let i=p?O(p,"a heading"):null,c=a?O(a,"a <p>"):null;i&&!i.id&&(i.id=`${n}-title`),c&&!c.id&&(c.id=`${n}-description`),s&&(s.id||(s.id=`${n}-content`),r(s,"role","dialog"),s.hasAttribute("popover")||s.setAttribute("popover","auto"),r(s,"tabindex","-1"),r(s,"data-state",o),r(s,"aria-labelledby",i?i.id:null),r(s,"aria-describedby",c?c.id:null)),this.#o&&(r(this.#o,"aria-haspopup","dialog"),r(this.#o,"aria-expanded",String(t)),r(this.#o,"aria-controls",s?s.id:null)),this.#i=this.parts(Bt).flatMap(h=>O(h,"a <button>")??[]),this.#a(s),this.#e?.sync()}},V=class extends u{},X=class extends u{},Y=class extends u{},J=class extends u{},Q=class extends u{},Z=class extends u{};function Tt(e=globalThis.customElements){b(e,[[Zt,W],[kt,V],[Dt,X],[It,Y],[Nt,J],[$t,Q],[Bt,Z]])}var w=class extends f{#t;constructor(t,o){super(t),this.#t=o}onTriggerClick(t){let{active:o}=this.#t.state(),n=R({disabled:this.disabled(),active:o},t.value);if(n!==null){let s=this.ordered().map(([,l])=>l.value);this.#t.activate(n,s.indexOf(n))}}onTriggerKeydown(t,o){let{active:n,orientation:s,dir:l,activationMode:d}=this.#t.state(),p=this.ordered(),a=p.map(([,c])=>c.value),i=rt({values:a,disabled:this.disabled(),active:n,orientation:s,dir:l,activationMode:d},t.value,o.key);i&&(o.preventDefault(),i.activate!==null&&this.#t.activate(i.activate,a.indexOf(i.activate)),p[a.indexOf(i.focus)][0].focus())}};var te="primitiv-tabs",Gt="primitiv-tabs-list",Et="primitiv-tabs-trigger",zt="primitiv-tabs-content";function ee(e){let t=e.getAttribute("value");return e.childElementCount===1&&t!==null?{tab:e.firstElementChild,value:t}:(g(e,`<${Et}> needs a value and exactly one element child (a <button>, an <a href> or a router link) to decorate.`),null)}var tt=class extends m{#t;#e=!1;controller=new w(this,this.#o());reconcileOn=["value","disabled","label","orientation"];get value(){return this.getAttribute("value")??void 0}set value(t){this.setAttribute("value",t)}#o(){return{state:()=>({active:this.value,orientation:this.#i(),dir:this.direction(),activationMode:this.#n()}),activate:(t,o)=>{this.announce("primitiv-tabs-change",{value:t,index:o})&&(this.value=t)}}}#n(){let t=this.getAttribute("activation-mode");return t==="manual"?t:"automatic"}#i(){return this.getAttribute("orientation")==="vertical"?"vertical":"horizontal"}reconcile(){let t=this.#i(),o=this.value,n=this.rootId();r(this,"data-orientation",t);for(let a of this.parts(Gt)){r(a,"role","tablist"),r(a,"aria-orientation",t),r(a,"data-orientation",t);let i=a.getAttribute("label");i!==null&&r(a,"aria-label",i)}let s=new Map;for(let a of this.parts(zt)){let i=a.getAttribute("value");i!==null&&s.set(i,a)}let l=this.parts(Et).flatMap(a=>{let i=ee(a);return i?[{trigger:a,...i}]:[]}),d=it({values:l.map(a=>a.value),active:o});this.controller.setTriggers(l.map(({trigger:a,tab:i,value:c})=>({value:c,element:i,disabled:a.hasAttribute("disabled")})));for(let{trigger:a,tab:i,value:c}of l){let h=s.get(c),Ct=c===o,At=a.hasAttribute("disabled");i.id||(i.id=v(n,"trigger",c)),h&&!h.id&&(h.id=v(n,"panel",c)),r(i,"role","tab"),r(i,"aria-selected",String(Ct)),r(i,"aria-controls",h?h.id:null),r(i,"tabindex",c===d?"0":"-1"),r(i,"aria-disabled",At?"true":null),r(i,"data-disabled",At?"":null),r(i,"data-state",Ct?"active":"inactive"),r(i,"data-orientation",t),h&&r(h,"aria-labelledby",i.id)}for(let[a,i]of s){let c=a===o;r(i,"role","tabpanel"),r(i,"tabindex","0"),r(i,"hidden",c?null:""),r(i,"data-state",c?"active":"inactive"),r(i,"data-orientation",t)}let p=s.get(o);this.#e&&o!==this.#t&&p&&p.dispatchEvent(new CustomEvent("primitiv-tabs-show",{bubbles:!0})),this.#t=o,this.#e=!0}},et=class extends u{},ot=class extends u{},nt=class extends u{};function xt(e=globalThis.customElements){b(e,[[te,tt],[Gt,et],[Et,ot],[zt,nt]])}gt();bt();yt();Tt();xt();export{x as AccordionController,C as CollapsibleController,A as ModalController,M as PopoverController,D as PrimitivAccordionContentElement,P as PrimitivAccordionElement,S as PrimitivAccordionItemElement,k as PrimitivAccordionTriggerElement,I as PrimitivAccordionTriggerIconElement,B as PrimitivCollapsibleContentElement,N as PrimitivCollapsibleElement,$ as PrimitivCollapsibleTriggerElement,G as PrimitivCollapsibleTriggerIconElement,j as PrimitivModalCloseElement,U as PrimitivModalContentElement,q as PrimitivModalDescriptionElement,z as PrimitivModalElement,_ as PrimitivModalTitleElement,F as PrimitivModalTriggerElement,X as PrimitivPopoverAnchorElement,Z as PrimitivPopoverCloseElement,Y as PrimitivPopoverContentElement,Q as PrimitivPopoverDescriptionElement,W as PrimitivPopoverElement,J as PrimitivPopoverTitleElement,V as PrimitivPopoverTriggerElement,nt as PrimitivTabsContentElement,tt as PrimitivTabsElement,et as PrimitivTabsListElement,ot as PrimitivTabsTriggerElement,w as TabsController,gt as defineAccordion,bt as defineCollapsible,yt as defineModal,Tt as definePopover,xt as defineTabs};
|
package/dist/tags.d.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import type { PrimitivAccordionContentElement, PrimitivAccordionElement, PrimitivAccordionItemElement, PrimitivAccordionTriggerElement, PrimitivAccordionTriggerIconElement } from "./accordion/elements.js";
|
|
16
16
|
import type { PrimitivCollapsibleContentElement, PrimitivCollapsibleElement, PrimitivCollapsibleTriggerElement, PrimitivCollapsibleTriggerIconElement } from "./collapsible/elements.js";
|
|
17
17
|
import type { PrimitivModalCloseElement, PrimitivModalContentElement, PrimitivModalDescriptionElement, PrimitivModalElement, PrimitivModalTitleElement, PrimitivModalTriggerElement } from "./modal/elements.js";
|
|
18
|
+
import type { PrimitivPopoverAnchorElement, PrimitivPopoverCloseElement, PrimitivPopoverContentElement, PrimitivPopoverDescriptionElement, PrimitivPopoverElement, PrimitivPopoverTitleElement, PrimitivPopoverTriggerElement } from "./popover/elements.js";
|
|
18
19
|
import type { PrimitivTabsContentElement, PrimitivTabsElement, PrimitivTabsListElement, PrimitivTabsTriggerElement } from "./tabs/elements.js";
|
|
19
20
|
declare global {
|
|
20
21
|
interface HTMLElementTagNameMap {
|
|
@@ -33,6 +34,13 @@ declare global {
|
|
|
33
34
|
"primitiv-modal-title": PrimitivModalTitleElement;
|
|
34
35
|
"primitiv-modal-description": PrimitivModalDescriptionElement;
|
|
35
36
|
"primitiv-modal-close": PrimitivModalCloseElement;
|
|
37
|
+
"primitiv-popover": PrimitivPopoverElement;
|
|
38
|
+
"primitiv-popover-trigger": PrimitivPopoverTriggerElement;
|
|
39
|
+
"primitiv-popover-anchor": PrimitivPopoverAnchorElement;
|
|
40
|
+
"primitiv-popover-content": PrimitivPopoverContentElement;
|
|
41
|
+
"primitiv-popover-title": PrimitivPopoverTitleElement;
|
|
42
|
+
"primitiv-popover-description": PrimitivPopoverDescriptionElement;
|
|
43
|
+
"primitiv-popover-close": PrimitivPopoverCloseElement;
|
|
36
44
|
"primitiv-tabs": PrimitivTabsElement;
|
|
37
45
|
"primitiv-tabs-list": PrimitivTabsListElement;
|
|
38
46
|
"primitiv-tabs-trigger": PrimitivTabsTriggerElement;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primitiv-ui/web",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.55",
|
|
4
4
|
"description": "Primitiv's headless components as standard custom elements: light DOM, no framework, no runtime dependencies. Works in plain HTML, server-rendered stacks, React, Vue, Angular and anything else that renders HTML.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -22,6 +22,10 @@
|
|
|
22
22
|
"types": "./dist/modal/index.d.ts",
|
|
23
23
|
"default": "./dist/modal/index.js"
|
|
24
24
|
},
|
|
25
|
+
"./popover": {
|
|
26
|
+
"types": "./dist/popover/index.d.ts",
|
|
27
|
+
"default": "./dist/popover/index.js"
|
|
28
|
+
},
|
|
25
29
|
"./tabs": {
|
|
26
30
|
"types": "./dist/tabs/index.d.ts",
|
|
27
31
|
"default": "./dist/tabs/index.js"
|
|
@@ -42,6 +46,10 @@
|
|
|
42
46
|
"types": "./dist/define/modal.d.ts",
|
|
43
47
|
"default": "./dist/define/modal.js"
|
|
44
48
|
},
|
|
49
|
+
"./define/popover": {
|
|
50
|
+
"types": "./dist/define/popover.d.ts",
|
|
51
|
+
"default": "./dist/define/popover.js"
|
|
52
|
+
},
|
|
45
53
|
"./define/tabs": {
|
|
46
54
|
"types": "./dist/define/tabs.d.ts",
|
|
47
55
|
"default": "./dist/define/tabs.js"
|
|
@@ -76,7 +84,7 @@
|
|
|
76
84
|
"directory": "packages/web"
|
|
77
85
|
},
|
|
78
86
|
"dependencies": {
|
|
79
|
-
"@primitiv-ui/core": "0.1.
|
|
87
|
+
"@primitiv-ui/core": "0.1.55"
|
|
80
88
|
},
|
|
81
89
|
"devDependencies": {
|
|
82
90
|
"@custom-elements-manifest/analyzer": "0.11.0",
|