@pontive/pontkit-core 1.25.0 → 1.27.0
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 +4 -0
- package/catalog.json +1 -1
- package/custom-elements.json +1 -1
- package/dist/index.js +14 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -8
- package/dist/index.mjs.map +1 -1
- package/dist/pont2/core/attrs.d.ts +22 -0
- package/dist/pont2/core/controllers/roving-focus.d.ts +38 -0
- package/dist/pont2/core/events.d.ts +28 -0
- package/dist/pont2/core/form-control.d.ts +70 -0
- package/dist/pont2/core/host-element.d.ts +129 -0
- package/dist/pont2/core/icons.d.ts +20 -0
- package/dist/pont2/core/ids.d.ts +6 -0
- package/dist/pont2/core/index.d.ts +8 -0
- package/dist/pont2/core/names.d.ts +78 -0
- package/dist/pont2/core/popup/anchored.d.ts +48 -0
- package/dist/pont2/core/popup/index.d.ts +5 -0
- package/dist/pont2/core/popup/list.d.ts +38 -0
- package/dist/pont2/core/popup/popup-content.d.ts +68 -0
- package/dist/pont2/core/popup/popup-root.d.ts +94 -0
- package/dist/pont2/core/popup/position.d.ts +73 -0
- package/dist/pont2/globals.css +109 -0
- package/dist/pont2/index.d.ts +44 -0
- package/dist/pont2/index.mjs +3805 -0
- package/dist/pont2/index.mjs.map +1 -0
- package/dist/pont2/kit/alert/alert.d.ts +62 -0
- package/dist/pont2/kit/aliases.d.ts +33 -0
- package/dist/pont2/kit/avatar/avatar.d.ts +52 -0
- package/dist/pont2/kit/index.d.ts +3 -0
- package/dist/pont2/kit/input-otp/input-otp.d.ts +52 -0
- package/dist/pont2/primitives/alert/alert.d.ts +49 -0
- package/dist/pont2/primitives/avatar/avatar.d.ts +89 -0
- package/dist/pont2/primitives/badge/badge.d.ts +30 -0
- package/dist/pont2/primitives/button/button.d.ts +113 -0
- package/dist/pont2/primitives/button-group/button-group.d.ts +55 -0
- package/dist/pont2/primitives/card/card.d.ts +63 -0
- package/dist/pont2/primitives/checkbox/checkbox.d.ts +54 -0
- package/dist/pont2/primitives/combobox/combobox.d.ts +213 -0
- package/dist/pont2/primitives/dropdown-menu/dropdown-menu.d.ts +267 -0
- package/dist/pont2/primitives/empty/empty.d.ts +60 -0
- package/dist/pont2/primitives/field/field.d.ts +146 -0
- package/dist/pont2/primitives/input/input.d.ts +47 -0
- package/dist/pont2/primitives/input-group/input-group.d.ts +97 -0
- package/dist/pont2/primitives/input-otp/input-otp.d.ts +121 -0
- package/dist/pont2/primitives/input-otp/otp.d.ts +22 -0
- package/dist/pont2/primitives/item/item.d.ts +100 -0
- package/dist/pont2/primitives/kbd/kbd.d.ts +29 -0
- package/dist/pont2/primitives/label/label.d.ts +37 -0
- package/dist/pont2/primitives/native-select/native-select.d.ts +59 -0
- package/dist/pont2/primitives/popover/popover.d.ts +85 -0
- package/dist/pont2/primitives/progress/progress.d.ts +80 -0
- package/dist/pont2/primitives/radio-group/radio-group.d.ts +93 -0
- package/dist/pont2/primitives/select/select.d.ts +184 -0
- package/dist/pont2/primitives/separator/separator.d.ts +34 -0
- package/dist/pont2/primitives/skeleton/skeleton.d.ts +18 -0
- package/dist/pont2/primitives/slider/slider-math.d.ts +42 -0
- package/dist/pont2/primitives/slider/slider.d.ts +85 -0
- package/dist/pont2/primitives/spinner/spinner.d.ts +29 -0
- package/dist/pont2/primitives/switch/switch.d.ts +55 -0
- package/dist/pont2/primitives/table/table.d.ts +55 -0
- package/dist/pont2/primitives/tabs/tabs.d.ts +126 -0
- package/dist/pont2/primitives/textarea/textarea.d.ts +41 -0
- package/dist/pont2/primitives/tooltip/tooltip.d.ts +69 -0
- package/dist/pont2/styles.css +4137 -0
- package/dist/pont2/with-legacy.css +10 -0
- package/dist/styles.css +6 -0
- package/package.json +16 -4
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Directive, ElementPart, PartInfo } from 'lit/directive.js';
|
|
2
|
+
export type AttrValue = string | number | boolean | null | undefined;
|
|
3
|
+
export type AttrMap = Record<string, AttrValue>;
|
|
4
|
+
/**
|
|
5
|
+
* `<button ${attrs({ "data-provider": "google", "aria-busy": loading })}>`
|
|
6
|
+
*
|
|
7
|
+
* Lit has no attribute spread; part functions need one. It plays the role of
|
|
8
|
+
* `{...props}` in a shadcn component: a composing component can put extra
|
|
9
|
+
* attributes on the *same* element a part renders, so it never has to wrap
|
|
10
|
+
* that element. `true` → empty attribute; `false`/`null`/`undefined` → removed;
|
|
11
|
+
* keys dropped since the previous render are removed.
|
|
12
|
+
*/
|
|
13
|
+
declare class AttrsDirective extends Directive {
|
|
14
|
+
private prev;
|
|
15
|
+
constructor(info: PartInfo);
|
|
16
|
+
render(_attrs: AttrMap): symbol;
|
|
17
|
+
update(part: ElementPart, [map]: [AttrMap]): symbol;
|
|
18
|
+
}
|
|
19
|
+
export declare const attrs: (_attrs: AttrMap) => import('lit-html/directive.js').DirectiveResult<typeof AttrsDirective>;
|
|
20
|
+
/** Imperative twin of `attrs()`, for code that holds a node rather than a template. */
|
|
21
|
+
export declare function applyAttrs(el: Element, map: AttrMap, previous?: Iterable<string>): void;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
export type Orientation = "horizontal" | "vertical" | "both";
|
|
3
|
+
export interface RovingFocusOptions {
|
|
4
|
+
/** Candidate items, in DOM order. Called on every key press, so it may query live. */
|
|
5
|
+
items: () => HTMLElement[];
|
|
6
|
+
orientation?: () => Orientation;
|
|
7
|
+
/** Wrap from last to first (Base UI `loopFocus`, default true). */
|
|
8
|
+
loop?: () => boolean;
|
|
9
|
+
/** Items to skip. Default: `[data-disabled]` / `aria-disabled="true"` / `:disabled`. */
|
|
10
|
+
isDisabled?: (item: HTMLElement) => boolean;
|
|
11
|
+
/** Called after focus moves through the keyboard (radio/tabs use it to activate). */
|
|
12
|
+
onNavigate?: (item: HTMLElement, event: KeyboardEvent) => void;
|
|
13
|
+
}
|
|
14
|
+
/** `ltr` unless the nearest `[dir]` ancestor (or the document) says `rtl`. */
|
|
15
|
+
export declare function directionOf(el: Element): "ltr" | "rtl";
|
|
16
|
+
/**
|
|
17
|
+
* Roving tabindex (WAI-ARIA APG "managing focus within composites"): exactly
|
|
18
|
+
* one item is a tab stop (`tabindex="0"`), the rest are `-1`, and arrow keys,
|
|
19
|
+
* Home and End move focus between them. Used by RadioGroup, Tabs, ToggleGroup
|
|
20
|
+
* and menus, which is what Base UI's `CompositeRoot` does internally.
|
|
21
|
+
*
|
|
22
|
+
* The host calls `sync(active)` whenever the "current" item may have
|
|
23
|
+
* changed (selection, items added or removed).
|
|
24
|
+
*/
|
|
25
|
+
export declare class RovingFocusController implements ReactiveController {
|
|
26
|
+
private readonly host;
|
|
27
|
+
private readonly opts;
|
|
28
|
+
constructor(host: ReactiveControllerHost & HTMLElement, options: RovingFocusOptions);
|
|
29
|
+
hostConnected(): void;
|
|
30
|
+
hostDisconnected(): void;
|
|
31
|
+
/** Make `active` (or the first enabled item) the single tab stop. */
|
|
32
|
+
sync(active?: HTMLElement | null): void;
|
|
33
|
+
/** Focus an item and make it the tab stop. */
|
|
34
|
+
focus(item: HTMLElement, options?: FocusOptions): void;
|
|
35
|
+
private onFocusIn;
|
|
36
|
+
private onKeyDown;
|
|
37
|
+
private findNext;
|
|
38
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event conventions (docs/02-conventions.md, "Events"):
|
|
3
|
+
*
|
|
4
|
+
* - Value-holding widgets fire the platform's own `input` (while the value
|
|
5
|
+
* changes through interaction) and `change` (when it is committed), both
|
|
6
|
+
* bubbling, exactly like native controls. The new value is read from the
|
|
7
|
+
* target (`e.target.checked`, `e.target.value`), so `@change=${…}` in Lit,
|
|
8
|
+
* `onChange` via @lit/react and `addEventListener("change")` all work.
|
|
9
|
+
* - Anything without a native equivalent is a `pont2-<name>` CustomEvent with
|
|
10
|
+
* a typed `detail`, bubbling and composed. Base UI's `onOpenChange(open,
|
|
11
|
+
* details)` becomes `pont2-open-change` with `{ open, reason }`; it is
|
|
12
|
+
* cancelable, and `preventDefault()` keeps the current state (Base UI's
|
|
13
|
+
* `eventDetails.cancel()`).
|
|
14
|
+
* - Events fire only for user-initiated changes, never for property writes,
|
|
15
|
+
* matching native controls (and Base UI's controlled props).
|
|
16
|
+
*/
|
|
17
|
+
export declare function fireNative(target: EventTarget, type: "input" | "change"): void;
|
|
18
|
+
export declare function fire<T>(target: EventTarget, type: `pont2-${string}`, detail: T, cancelable?: boolean): boolean;
|
|
19
|
+
export type OpenChangeReason = "trigger-press" | "trigger-hover" | "trigger-focus" | "outside-press" | "escape-key" | "item-press" | "list-navigation" | "input-change" | "focus-out" | "imperative";
|
|
20
|
+
export interface OpenChangeDetail {
|
|
21
|
+
open: boolean;
|
|
22
|
+
reason: OpenChangeReason;
|
|
23
|
+
}
|
|
24
|
+
declare global {
|
|
25
|
+
interface HTMLElementEventMap {
|
|
26
|
+
"pont2-open-change": CustomEvent<OpenChangeDetail>;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { PropertyDeclarations, PropertyValues } from 'lit';
|
|
2
|
+
import { HostElement } from './host-element';
|
|
3
|
+
export interface ValidityResult {
|
|
4
|
+
flags: ValidityStateFlags;
|
|
5
|
+
message: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* # FormControlElement: Tier 2 form-associated widget
|
|
9
|
+
*
|
|
10
|
+
* The base for widgets whose host is an ARIA widget root *and* a form control
|
|
11
|
+
* (Checkbox, Switch, RadioGroup, Slider, Select, Combobox, InputOTP …). It is
|
|
12
|
+
* a **form-associated custom element** (FACE), so with no hidden `<input>`:
|
|
13
|
+
*
|
|
14
|
+
* - it submits `name=value` with its `<form>` (`internals.setFormValue`);
|
|
15
|
+
* - it takes part in constraint validation (`setValidity`, `:invalid`,
|
|
16
|
+
* `checkValidity()`, `reportValidity()`, blocking submit when `required`);
|
|
17
|
+
* - it is disabled by `disabled`, by an ancestor `<fieldset disabled>` and by
|
|
18
|
+
* its form, through `formDisabledCallback`;
|
|
19
|
+
* - it resets with its form (`formResetCallback`) and restores on
|
|
20
|
+
* back/forward navigation (`formStateRestoreCallback`);
|
|
21
|
+
* - it is labelable: `<label for>` and wrapping labels work, and `labels`
|
|
22
|
+
* lists them;
|
|
23
|
+
* - the `form="id"` content attribute works natively.
|
|
24
|
+
*
|
|
25
|
+
* Base UI renders a visually hidden `<input>` next to each such widget to get
|
|
26
|
+
* the same effect in React. A FACE makes that node unnecessary, which is
|
|
27
|
+
* one node fewer than shadcn/Base UI.
|
|
28
|
+
*
|
|
29
|
+
* Subclasses implement `formValue()`, `resetToDefault()` and optionally
|
|
30
|
+
* `validate()`; the base syncs internals/data attributes after every update.
|
|
31
|
+
*/
|
|
32
|
+
export declare abstract class FormControlElement extends HostElement {
|
|
33
|
+
static formAssociated: boolean;
|
|
34
|
+
static properties: PropertyDeclarations;
|
|
35
|
+
name: string;
|
|
36
|
+
disabled: boolean;
|
|
37
|
+
required: boolean;
|
|
38
|
+
readOnly: boolean;
|
|
39
|
+
/** Disabled by an ancestor `<fieldset disabled>` or the form. */
|
|
40
|
+
protected formDisabled: boolean;
|
|
41
|
+
private _customMessage;
|
|
42
|
+
constructor();
|
|
43
|
+
/** What the control submits. `null` submits nothing (an unchecked checkbox). */
|
|
44
|
+
protected abstract formValue(): string | File | FormData | null;
|
|
45
|
+
/** Restore the default value (the one in the markup). */
|
|
46
|
+
protected abstract resetToDefault(): void;
|
|
47
|
+
/** Built-in constraint check. Return `null` when valid. */
|
|
48
|
+
protected validate(): ValidityResult | null;
|
|
49
|
+
/** Whether the host itself is a tab stop. Composite widgets with an inner roving tab stop return false. */
|
|
50
|
+
protected get hostFocusable(): boolean;
|
|
51
|
+
/** Element `reportValidity()` should point at (must be inside the host). */
|
|
52
|
+
protected get validationAnchor(): HTMLElement | undefined;
|
|
53
|
+
get form(): HTMLFormElement | null;
|
|
54
|
+
get labels(): NodeList;
|
|
55
|
+
get validity(): ValidityState;
|
|
56
|
+
get validationMessage(): string;
|
|
57
|
+
get willValidate(): boolean;
|
|
58
|
+
/** `disabled` or disabled by a fieldset/form. */
|
|
59
|
+
get isDisabled(): boolean;
|
|
60
|
+
checkValidity(): boolean;
|
|
61
|
+
reportValidity(): boolean;
|
|
62
|
+
setCustomValidity(message: string): void;
|
|
63
|
+
formResetCallback(): void;
|
|
64
|
+
formDisabledCallback(disabled: boolean): void;
|
|
65
|
+
formStateRestoreCallback(state: string | File | FormData | null): void;
|
|
66
|
+
/** Override to restore from the value `formValue()` produced. */
|
|
67
|
+
protected restoreState(_state: string | File | FormData | null): void;
|
|
68
|
+
protected updated(changed: PropertyValues): void;
|
|
69
|
+
protected syncValidity(): void;
|
|
70
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { LitElement, PropertyValues } from 'lit';
|
|
2
|
+
import { DirectiveResult } from 'lit/directive.js';
|
|
3
|
+
import { AttrMap } from './attrs';
|
|
4
|
+
/**
|
|
5
|
+
* # HostElement: the host is the component's root element
|
|
6
|
+
*
|
|
7
|
+
* The base class of every pont2 element. A shadcn component is a function
|
|
8
|
+
* that returns its root element and then disappears. A custom element cannot
|
|
9
|
+
* disappear, so in pont2 **the host *is* the root**: `<pont2-prim-separator>` is the
|
|
10
|
+
* separator, it does not render one.
|
|
11
|
+
*
|
|
12
|
+
* What a subclass gets:
|
|
13
|
+
*
|
|
14
|
+
* | Static / member | Does |
|
|
15
|
+
* |---------------------|----------------------------------------------------------------------|
|
|
16
|
+
* | `static identity` | Stamps `data-pont2-<identity>`. Every class in the chain adds its own, so a subclass keeps its base's styles (`pont2-prim-item-separator` carries `data-pont2-separator` *and* `data-pont2-item-separator`). |
|
|
17
|
+
* | `static slotName` | Stamps `data-slot` (shadcn's convention). Most-derived class wins. An author-written `data-slot` is never overwritten. |
|
|
18
|
+
* | `static role` | Default ARIA role through `ElementInternals`. An author's `role=""` attribute still wins. |
|
|
19
|
+
* | `internals` | `ElementInternals`: default ARIA, custom states, forms (see FormControlElement). |
|
|
20
|
+
* | `setData()` | Writes component-owned `data-*` state on the host (Base UI's presence-style attributes). |
|
|
21
|
+
* | `setState()` | Adds/removes a CustomStateSet entry, matchable as `:state(x)`. |
|
|
22
|
+
* | `static part()` | The same identity, slot and role as attributes, for a composite to put on a plain element (see below). |
|
|
23
|
+
* | `static composite` | Marks a kit composite: it renders its whole subtree from properties (docs/10-primitives-and-kit.md). |
|
|
24
|
+
*
|
|
25
|
+
* Light DOM throughout: `createRenderRoot()` returns `this`. Most Tier 1
|
|
26
|
+
* elements never override `render()`; their children are whatever the author
|
|
27
|
+
* wrote, left exactly where the author wrote them.
|
|
28
|
+
*/
|
|
29
|
+
export declare abstract class HostElement extends LitElement {
|
|
30
|
+
/** Style identity → `data-pont2-<identity>`. Inherited along the class chain. */
|
|
31
|
+
static identity?: string;
|
|
32
|
+
/** shadcn `data-slot` value. Most-derived wins; never overrides the author. */
|
|
33
|
+
static slotName?: string;
|
|
34
|
+
/** Default ARIA role, set through ElementInternals (author attribute wins). */
|
|
35
|
+
static role?: string;
|
|
36
|
+
/**
|
|
37
|
+
* `true` on kit composites (`src/kit/`): the element renders its entire
|
|
38
|
+
* subtree from properties, so author-written children are a mistake (use the
|
|
39
|
+
* `pont2-prim-*` form for custom content). Reported once in development.
|
|
40
|
+
*/
|
|
41
|
+
static composite: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* A **part**: this element's identity, `data-slot` and default role as plain
|
|
44
|
+
* attributes, for a template to put on a native element.
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* html`<div ${AlertTitle.part()}>${this.heading}</div>`
|
|
48
|
+
* // → <div data-pont2-alert-title data-slot="alert-title">…</div>
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* The result is styled by the element's recipe and found by `sel()` lookups,
|
|
52
|
+
* exactly like the element itself, so a composite reproduces shadcn's DOM
|
|
53
|
+
* without nesting custom elements. A part carries **attributes only**: use
|
|
54
|
+
* it for Tier 1 elements whose host adds nothing but identity, slot and role.
|
|
55
|
+
* An element with behaviour (state, observers, keyboard, form association)
|
|
56
|
+
* has to be rendered as the element. `extra` adds or overrides attributes.
|
|
57
|
+
*/
|
|
58
|
+
static part(extra?: AttrMap): DirectiveResult;
|
|
59
|
+
protected readonly internals: ElementInternals;
|
|
60
|
+
protected createRenderRoot(): HTMLElement;
|
|
61
|
+
/**
|
|
62
|
+
* Elements that do not override `render()` (most Tier 1 hosts) skip Lit's
|
|
63
|
+
* template rendering entirely. Otherwise lit-html would append a `<!---->`
|
|
64
|
+
* part marker to the author's children: a stray node in a component whose
|
|
65
|
+
* whole point is to add none, and one more node for React to step around.
|
|
66
|
+
*/
|
|
67
|
+
protected update(changed: PropertyValues): void;
|
|
68
|
+
connectedCallback(): void;
|
|
69
|
+
/**
|
|
70
|
+
* Sets `data-<name>`: a string value, `true` → empty (presence) attribute,
|
|
71
|
+
* `false`/`null`/`undefined` → removed. Base UI exposes state as presence
|
|
72
|
+
* attributes (`data-checked`, `data-disabled`, `data-open`), which is what
|
|
73
|
+
* shadcn's Base UI styles select on, so `true`/`false` is the common call.
|
|
74
|
+
*/
|
|
75
|
+
protected setData(name: string, value: string | boolean | null | undefined): void;
|
|
76
|
+
/** Adds or removes a custom state, matchable in CSS as `:state(<name>)`. */
|
|
77
|
+
protected setState(name: string, on: boolean): void;
|
|
78
|
+
}
|
|
79
|
+
/** Every `identity` declared along the prototype chain, most-derived first. */
|
|
80
|
+
export declare function identitiesOf(ctor: typeof HostElement): string[];
|
|
81
|
+
/**
|
|
82
|
+
* # ShellElement: Tier 3 (native-bound) host
|
|
83
|
+
*
|
|
84
|
+
* Some shadcn roots must stay *native* elements: `<button>`, `<a>`, `<input>`,
|
|
85
|
+
* `<textarea>`, `<label>`, `<select>`, `<table>`, `<fieldset>`. Their behaviour
|
|
86
|
+
* (implicit form submission, `SubmitEvent.submitter`, autofill, password
|
|
87
|
+
* managers, real links, `for=` labelling, table parsing) cannot be emulated
|
|
88
|
+
* faithfully by a custom element.
|
|
89
|
+
*
|
|
90
|
+
* For those, the host is a **transparent shell**: `display: contents`
|
|
91
|
+
* (`[data-pont2-shell]` in styles/base.css), no role, no styles, no box. It
|
|
92
|
+
* exists only so HTML authors have a tag. Everything styled or announced lives
|
|
93
|
+
* on the one native element inside it. Two nodes is the platform floor for
|
|
94
|
+
* native semantics, and composition never adds a third.
|
|
95
|
+
*
|
|
96
|
+
* Never style a shell, give it a role, or anchor positioning to it. Use
|
|
97
|
+
* `control` (the native element) instead.
|
|
98
|
+
*/
|
|
99
|
+
export declare abstract class ShellElement extends HostElement {
|
|
100
|
+
static identity: string;
|
|
101
|
+
/** The single native element this shell stands for. */
|
|
102
|
+
abstract get control(): HTMLElement | null;
|
|
103
|
+
focus(options?: FocusOptions): void;
|
|
104
|
+
blur(): void;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* # NativeEnhancer: Tier 3 element form ("asChild")
|
|
108
|
+
*
|
|
109
|
+
* `<pont2-prim-button variant="outline"><button>Save</button></pont2-prim-button>`
|
|
110
|
+
*
|
|
111
|
+
* The author writes the native element; the shell applies the recipe to it
|
|
112
|
+
* (attributes only). The native node is never moved, wrapped or re-created,
|
|
113
|
+
* so React, a parent Lit template or server HTML keep owning it. A
|
|
114
|
+
* MutationObserver re-applies the recipe if the child is swapped.
|
|
115
|
+
*
|
|
116
|
+
* This is shadcn's `asChild` / Base UI's `render` prop, expressed in HTML.
|
|
117
|
+
*/
|
|
118
|
+
export declare abstract class NativeEnhancer<T extends HTMLElement = HTMLElement> extends ShellElement {
|
|
119
|
+
/** Selector for the native child this enhancer applies its recipe to. */
|
|
120
|
+
static nativeSelector: string;
|
|
121
|
+
private _observer?;
|
|
122
|
+
private _warned;
|
|
123
|
+
get control(): T | null;
|
|
124
|
+
/** Apply the recipe (attributes / properties) to the native element. */
|
|
125
|
+
protected abstract apply(control: T): void;
|
|
126
|
+
connectedCallback(): void;
|
|
127
|
+
disconnectedCallback(): void;
|
|
128
|
+
protected updated(): void;
|
|
129
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TemplateResult } from 'lit';
|
|
2
|
+
export declare const icons: {
|
|
3
|
+
check: () => TemplateResult<1>;
|
|
4
|
+
minus: () => TemplateResult<1>;
|
|
5
|
+
x: () => TemplateResult<1>;
|
|
6
|
+
chevronDown: () => TemplateResult<1>;
|
|
7
|
+
chevronUp: () => TemplateResult<1>;
|
|
8
|
+
chevronRight: () => TemplateResult<1>;
|
|
9
|
+
chevronLeft: () => TemplateResult<1>;
|
|
10
|
+
chevronsUpDown: () => TemplateResult<1>;
|
|
11
|
+
search: () => TemplateResult<1>;
|
|
12
|
+
circle: () => TemplateResult<1>;
|
|
13
|
+
loaderCircle: () => TemplateResult<1>;
|
|
14
|
+
circleAlert: () => TemplateResult<1>;
|
|
15
|
+
circleX: () => TemplateResult<1>;
|
|
16
|
+
circleCheck: () => TemplateResult<1>;
|
|
17
|
+
triangleAlert: () => TemplateResult<1>;
|
|
18
|
+
info: () => TemplateResult<1>;
|
|
19
|
+
};
|
|
20
|
+
export type IconName = keyof typeof icons;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** A document-unique id, e.g. `pont2-field-3`. Like React's `useId()`. */
|
|
2
|
+
export declare function uid(scope?: string): string;
|
|
3
|
+
/** Returns `el.id`, assigning a fresh `uid(scope)` first if it has none. */
|
|
4
|
+
export declare function ensureId(el: Element, scope?: string): string;
|
|
5
|
+
/** Adds/removes an id in a space-separated IDREF list attribute (aria-describedby etc.). */
|
|
6
|
+
export declare function toggleIdRef(el: Element, attr: string, id: string, on: boolean): void;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pont2 namespace, in one place.
|
|
3
|
+
*
|
|
4
|
+
* | Thing | Form | Example |
|
|
5
|
+
* |------------------|-------------------------------|--------------------------------------|
|
|
6
|
+
* | primitive tag | `pont2-prim-<name>` | `pont2-prim-alert`, `pont2-prim-alert-title` |
|
|
7
|
+
* | kit tag | `pont2-<name>` | `pont2-alert` (composite), `pont2-button` (alias) |
|
|
8
|
+
* | identity attr | `data-pont2-<identity>` | `data-pont2-alert` (tier-neutral: "this is an alert") |
|
|
9
|
+
* | slot attr | `data-slot="<name>"` | `data-slot="item-separator"` (shadcn's own, unprefixed) |
|
|
10
|
+
* | state attrs | `data-<state>` | `data-checked`, `data-open` (Base UI's own, unprefixed) |
|
|
11
|
+
* | CSS custom prop | `--pont2-<name>` | `--pont2-primary` |
|
|
12
|
+
* | cascade layer | `pont2.<layer>` | `pont2.primitives`, `pont2.kit` |
|
|
13
|
+
* | custom event | `pont2-<name>` | `pont2-open-change` |
|
|
14
|
+
*
|
|
15
|
+
* Two element surfaces share one namespace (docs/10-primitives-and-kit.md):
|
|
16
|
+
*
|
|
17
|
+
* - **primitives** `pont2-prim-*`: shadcn's components, one for one.
|
|
18
|
+
* - **kit** `pont2-*`: what applications use. A kit element is either an
|
|
19
|
+
* *alias* of a primitive (same behaviour, second tag) or a *composite* (a
|
|
20
|
+
* subclass of a primitive that renders the primitive's children from
|
|
21
|
+
* properties). Invariant: **`pont2-<name>` is always a `<name>` at its
|
|
22
|
+
* root**, which is what lets `sel()` / `tags()` match both surfaces at once.
|
|
23
|
+
*
|
|
24
|
+
* The identity attribute is tier-neutral on purpose: it says *what* an element
|
|
25
|
+
* is (an alert), not *which tag* produced it. Recipes and lookups key on it, so
|
|
26
|
+
* a primitive, its alias, a composite built on it and hand-written recipe
|
|
27
|
+
* markup are all styled and found the same way.
|
|
28
|
+
*
|
|
29
|
+
* `data-slot` and the state attributes stay unprefixed on purpose: they are
|
|
30
|
+
* shadcn's and Base UI's public styling contract, and keeping them verbatim
|
|
31
|
+
* is what lets shadcn styles port across mechanically.
|
|
32
|
+
*/
|
|
33
|
+
export declare const PREFIX = "pont2";
|
|
34
|
+
/** Tag segment that marks the primitive surface. */
|
|
35
|
+
export declare const PRIM = "prim";
|
|
36
|
+
/** Kit tag: `tag("alert")` → `pont2-alert`. */
|
|
37
|
+
export declare const tag: (name: string) => `pont2-${string}`;
|
|
38
|
+
/** Primitive tag: `primTag("alert")` → `pont2-prim-alert`. */
|
|
39
|
+
export declare const primTag: (name: string) => `pont2-prim-${string}`;
|
|
40
|
+
export declare const identityAttr: (identity: string) => `data-pont2-${string}`;
|
|
41
|
+
/**
|
|
42
|
+
* Selector for every element that *is* a `<name>`: its primitive tag, its kit
|
|
43
|
+
* tag (an alias or a composite, which by the kit invariant has that root) and
|
|
44
|
+
* its identity attribute (upgraded elements, parts rendered by composites,
|
|
45
|
+
* hand-written recipe markup).
|
|
46
|
+
*
|
|
47
|
+
* `sel("alert")` → `:is(pont2-prim-alert, pont2-alert, [data-pont2-alert])`
|
|
48
|
+
*
|
|
49
|
+
* Use it for every structural lookup (`closest`, `querySelector`), so a
|
|
50
|
+
* component works whichever surface its parts were written with.
|
|
51
|
+
* Tier 3 shells are the exception: their identity attribute lives on the
|
|
52
|
+
* native child, so look shells up with `tags()`.
|
|
53
|
+
*/
|
|
54
|
+
export declare const sel: (name: string) => string;
|
|
55
|
+
/** The element tags only, on both surfaces: `:is(pont2-prim-x, pont2-x)`. Use for shells. */
|
|
56
|
+
export declare const tags: (name: string) => string;
|
|
57
|
+
/**
|
|
58
|
+
* Registers an element once. Re-registration (HMR, a second bundle copy) is a
|
|
59
|
+
* no-op rather than a thrown DOMException, but a *different* class under the
|
|
60
|
+
* same tag is reported, because that means two copies of pont2 are loaded.
|
|
61
|
+
*/
|
|
62
|
+
export declare function define(name: string, ctor: CustomElementConstructor): void;
|
|
63
|
+
/**
|
|
64
|
+
* Promotes a primitive to the kit surface unchanged: `pont2-<name>` becomes a
|
|
65
|
+
* second tag for `pont2-prim-<name>`.
|
|
66
|
+
*
|
|
67
|
+
* The platform forbids registering one constructor under two names, so the
|
|
68
|
+
* alias is an empty subclass. It inherits everything (identity, slot, role,
|
|
69
|
+
* properties, form association), so it is styled, announced and submitted
|
|
70
|
+
* exactly like the primitive, and `instanceof` the primitive class holds.
|
|
71
|
+
*
|
|
72
|
+
* ```ts
|
|
73
|
+
* defineAlias("pont2-button", Pont2Button); // <pont2-prim-button> → also <pont2-button>
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* Returns the alias constructor.
|
|
77
|
+
*/
|
|
78
|
+
export declare function defineAlias<T extends CustomElementConstructor>(kitTag: `pont2-${string}`, base: T): T;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Align, Side } from './position';
|
|
2
|
+
export interface AnchoredOptions {
|
|
3
|
+
side: Side;
|
|
4
|
+
align: Align;
|
|
5
|
+
sideOffset: number;
|
|
6
|
+
alignOffset: number;
|
|
7
|
+
collisionPadding: number;
|
|
8
|
+
/** Select's `alignItemWithTrigger`: the item to lay over the anchor, if any. */
|
|
9
|
+
alignItem?: HTMLElement | null;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Keeps a floating element (a `popover` in the top layer, so `position:
|
|
13
|
+
* fixed` against the viewport) attached to an anchor element.
|
|
14
|
+
*
|
|
15
|
+
* It only *writes CSS custom properties and data attributes* on the floating
|
|
16
|
+
* element; the stylesheet turns them into `left`/`top`. Base UI's variables
|
|
17
|
+
* are written under pont2's namespace (read by pont2 CSS) and also verbatim,
|
|
18
|
+
* so shadcn classes (`max-h-(--available-height)`, `w-(--anchor-width)`,
|
|
19
|
+
* `origin-(--transform-origin)`) port unchanged into app CSS:
|
|
20
|
+
*
|
|
21
|
+
* | Written | Meaning |
|
|
22
|
+
* |-------------------------|--------------------------------------------|
|
|
23
|
+
* | `--pont2-popup-x/y` | viewport position of the box (px) |
|
|
24
|
+
* | `--pont2-anchor-width/height` (+ `--anchor-*`) | size of the anchor |
|
|
25
|
+
* | `--pont2-available-width/height` (+ `--available-*`) | room left before the collision padding |
|
|
26
|
+
* | `--pont2-transform-origin` (+ `--transform-origin`) | the anchor point the box grows from |
|
|
27
|
+
* | `--pont2-arrow-x/y` | anchor centre relative to the box (for arrows) |
|
|
28
|
+
* | `data-side`, `data-align` | the side/alignment actually used (after flip) |
|
|
29
|
+
*
|
|
30
|
+
* Updates are batched to one per animation frame and re-run on scroll (any
|
|
31
|
+
* ancestor, captured), resize, and size changes of either element.
|
|
32
|
+
*/
|
|
33
|
+
export declare class AnchoredPositioner {
|
|
34
|
+
private readonly floating;
|
|
35
|
+
private readonly anchor;
|
|
36
|
+
private readonly options;
|
|
37
|
+
private frame;
|
|
38
|
+
private running;
|
|
39
|
+
private ro?;
|
|
40
|
+
private observedAnchor;
|
|
41
|
+
constructor(floating: HTMLElement, anchor: () => Element | null, options: () => AnchoredOptions);
|
|
42
|
+
start(): void;
|
|
43
|
+
stop(): void;
|
|
44
|
+
private observeAnchor;
|
|
45
|
+
private schedule;
|
|
46
|
+
/** Measure and write synchronously (also called right after showPopover, before first paint). */
|
|
47
|
+
update(): void;
|
|
48
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List navigation and typeahead for popup lists (menus, select, combobox).
|
|
3
|
+
*
|
|
4
|
+
* Two focus models, as in Base UI:
|
|
5
|
+
* - **real focus** (Menu, Select): the highlighted item *is* `document.activeElement`;
|
|
6
|
+
* items carry `tabindex="-1"` and `data-highlighted` follows focus;
|
|
7
|
+
* - **virtual focus** (Combobox): focus stays in the `<input>`; the highlighted
|
|
8
|
+
* item gets `data-highlighted` and the input points at it with
|
|
9
|
+
* `aria-activedescendant`.
|
|
10
|
+
*
|
|
11
|
+
* Both share `moveIndex()` and `Typeahead`.
|
|
12
|
+
*/
|
|
13
|
+
export declare const isItemDisabled: (el: Element) => boolean;
|
|
14
|
+
export declare const isItemVisible: (el: HTMLElement) => boolean;
|
|
15
|
+
export type Move = "next" | "prev" | "first" | "last";
|
|
16
|
+
/** Index of the next enabled item in `direction` from `current` (−1 = none yet). */
|
|
17
|
+
export declare function moveIndex(items: readonly Element[], current: number, move: Move, { loop, isDisabled }?: {
|
|
18
|
+
loop?: boolean;
|
|
19
|
+
isDisabled?: (el: Element) => boolean;
|
|
20
|
+
}): number;
|
|
21
|
+
/** Keyboard key → move, for a vertical list. */
|
|
22
|
+
export declare function keyToMove(key: string): Move | null;
|
|
23
|
+
/**
|
|
24
|
+
* Typeahead (APG): printable keys typed within 500ms build a prefix; the
|
|
25
|
+
* first enabled item after the current one whose label starts with it wins.
|
|
26
|
+
* Repeating one character cycles through items starting with it.
|
|
27
|
+
*/
|
|
28
|
+
export declare class Typeahead {
|
|
29
|
+
private readonly timeout;
|
|
30
|
+
private buffer;
|
|
31
|
+
private timer;
|
|
32
|
+
constructor(timeout?: number);
|
|
33
|
+
/** Whether a keyboard event is a typeahead character. */
|
|
34
|
+
static isChar(e: KeyboardEvent): boolean;
|
|
35
|
+
get active(): boolean;
|
|
36
|
+
match(key: string, items: readonly Element[], current: number, label?: (el: Element) => string): number;
|
|
37
|
+
reset(): void;
|
|
38
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { PropertyDeclarations } from 'lit';
|
|
2
|
+
import { OpenChangeReason } from '../events';
|
|
3
|
+
import { HostElement } from '../host-element';
|
|
4
|
+
import { AnchoredPositioner } from './anchored';
|
|
5
|
+
import { Align, Side } from './position';
|
|
6
|
+
/**
|
|
7
|
+
* # PopupContent: base for every popup surface
|
|
8
|
+
*
|
|
9
|
+
* DropdownMenuContent, SelectContent, ComboboxContent, PopoverContent and
|
|
10
|
+
* TooltipContent all extend it. The host **is** the popup (shadcn's
|
|
11
|
+
* `data-slot="…-content"` element); Base UI's separate `Portal` and
|
|
12
|
+
* `Positioner` wrappers have no counterpart, because:
|
|
13
|
+
*
|
|
14
|
+
* - **Portal → the native Popover API.** The host carries `popover="manual"`
|
|
15
|
+
* and `showPopover()` lifts it into the browser's top layer: it escapes
|
|
16
|
+
* `overflow: hidden` and stacking contexts *without moving the node*. It
|
|
17
|
+
* stays exactly where the author wrote it, so React/Lit/server HTML keep
|
|
18
|
+
* owning it, and it inherits CSS custom properties from its real ancestors.
|
|
19
|
+
* - **Positioner → AnchoredPositioner**, which writes position variables on
|
|
20
|
+
* this same element (see anchored.ts).
|
|
21
|
+
*
|
|
22
|
+
* Base UI DOM: Portal > Positioner div > Popup div[data-slot=…-content] > children
|
|
23
|
+
* pont2 DOM: pont2-…-content[popover][data-slot=…-content] > children
|
|
24
|
+
*
|
|
25
|
+
* Open/close states are Base UI's: `data-open` / `data-closed`, plus
|
|
26
|
+
* `data-starting-style` (first frame after opening) and `data-ending-style`
|
|
27
|
+
* (while closing). On close the element stays in the top layer until its
|
|
28
|
+
* CSS animations/transitions finish, then `hidePopover()` runs, so shadcn's
|
|
29
|
+
* `animate-out` classes port as plain keyframes.
|
|
30
|
+
*
|
|
31
|
+
* The content never decides it is open; its root does. It *requests*
|
|
32
|
+
* closing (Escape, outside press, Tab) through `onRequestClose`, which the
|
|
33
|
+
* root turns into a cancelable `pont2-open-change` event.
|
|
34
|
+
*/
|
|
35
|
+
export declare abstract class PopupContent extends HostElement {
|
|
36
|
+
static identity: string;
|
|
37
|
+
static properties: PropertyDeclarations;
|
|
38
|
+
side: Side;
|
|
39
|
+
align: Align;
|
|
40
|
+
sideOffset: number;
|
|
41
|
+
alignOffset: number;
|
|
42
|
+
collisionPadding: number;
|
|
43
|
+
/** Set by the root: asked to close for `reason`. */
|
|
44
|
+
onRequestClose?: (reason: OpenChangeReason) => void;
|
|
45
|
+
/** Set by the root: elements that do not count as "outside" (the trigger). */
|
|
46
|
+
insideElements: () => (Element | null | undefined)[];
|
|
47
|
+
/** Set by the root: what the popup is anchored to. */
|
|
48
|
+
anchorElement: () => Element | null;
|
|
49
|
+
protected readonly positioner: AnchoredPositioner;
|
|
50
|
+
private closing?;
|
|
51
|
+
private generation;
|
|
52
|
+
constructor();
|
|
53
|
+
connectedCallback(): void;
|
|
54
|
+
disconnectedCallback(): void;
|
|
55
|
+
get isOpen(): boolean;
|
|
56
|
+
/** Select overrides this to lay the selected item over the trigger. */
|
|
57
|
+
protected alignItem(): HTMLElement | null;
|
|
58
|
+
/** True if the event path is inside this popup or one of its inside elements. */
|
|
59
|
+
containsPath(path: EventTarget[]): boolean;
|
|
60
|
+
requestClose(reason: OpenChangeReason): void;
|
|
61
|
+
/** Re-measure (e.g. after the content changed size). */
|
|
62
|
+
reposition(): void;
|
|
63
|
+
show(): void;
|
|
64
|
+
/** Starts the close; resolves once the exit animation finished and the popover is hidden. */
|
|
65
|
+
hide(): Promise<void>;
|
|
66
|
+
}
|
|
67
|
+
/** Open popups, bottom → top (read-only view, for tests and devtools). */
|
|
68
|
+
export declare const openPopups: () => readonly PopupContent[];
|