@primitiv-ui/core 0.1.46 → 0.1.47

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.
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Everything Collapsible's toggle and keyboard rules depend on, as plain data.
3
+ * Each surface builds it from wherever it keeps state — React state, or a
4
+ * custom element's attributes — and applies the outcome back the same way.
5
+ */
6
+ export type CollapsibleState = {
7
+ /** Whether the panel is open. */
8
+ open: boolean;
9
+ /** Whether the collapsible is disabled: it never toggles. */
10
+ disabled: boolean;
11
+ };
12
+ /**
13
+ * The open state after a toggle: the opposite of the current one, or `null`
14
+ * while disabled, when nothing toggles and no change is reported.
15
+ */
16
+ export declare function collapsibleToggle(state: CollapsibleState): boolean | null;
17
+ /** What a key press on the trigger asks for: the open state to move to. */
18
+ export type CollapsibleKeyOutcome = {
19
+ open: boolean;
20
+ };
21
+ /**
22
+ * Collapsible's keyboard contract for a key press on its trigger: Enter and
23
+ * Space toggle it. A trigger may be a non-button element (an `<a>`, a
24
+ * `<div role="button">`), so the keys are handled explicitly rather than left
25
+ * to native activation.
26
+ *
27
+ * Returns `null` for any other key, and for every key while disabled, which
28
+ * tells the caller to leave the event alone (no `preventDefault`).
29
+ */
30
+ export declare function collapsibleKeydown(state: CollapsibleState, key: string): CollapsibleKeyOutcome | null;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The open state after a toggle: the opposite of the current one, or `null`
3
+ * while disabled, when nothing toggles and no change is reported.
4
+ */
5
+ export function collapsibleToggle(state) {
6
+ return state.disabled ? null : !state.open;
7
+ }
8
+ /**
9
+ * Collapsible's keyboard contract for a key press on its trigger: Enter and
10
+ * Space toggle it. A trigger may be a non-button element (an `<a>`, a
11
+ * `<div role="button">`), so the keys are handled explicitly rather than left
12
+ * to native activation.
13
+ *
14
+ * Returns `null` for any other key, and for every key while disabled, which
15
+ * tells the caller to leave the event alone (no `preventDefault`).
16
+ */
17
+ export function collapsibleKeydown(state, key) {
18
+ if (key !== "Enter" && key !== " ")
19
+ return null;
20
+ const open = collapsibleToggle(state);
21
+ return open === null ? null : { open };
22
+ }
package/dist/index.d.ts CHANGED
@@ -3,3 +3,4 @@ export { getKeyToActionMap, type RovingKeyAction } from "./keyboard/getKeyToActi
3
3
  export { resolveRovingTarget, type ResolveRovingTargetOptions, } from "./keyboard/resolveRovingTarget.js";
4
4
  export { tabsClick, tabsKeydown, tabsTabStop, type TabsActivationMode, type TabsKeyOutcome, type TabsOrientation, type TabsReadingDirection, type TabsState, } from "./tabs/policy.js";
5
5
  export { accordionKeydown, accordionToggle, type AccordionKeyOutcome, type AccordionOrientation, type AccordionReadingDirection, type AccordionState, } from "./accordion/policy.js";
6
+ export { collapsibleKeydown, collapsibleToggle, type CollapsibleKeyOutcome, type CollapsibleState, } from "./collapsible/policy.js";
package/dist/index.js CHANGED
@@ -3,3 +3,4 @@ export { getKeyToActionMap } from "./keyboard/getKeyToActionMap.js";
3
3
  export { resolveRovingTarget, } from "./keyboard/resolveRovingTarget.js";
4
4
  export { tabsClick, tabsKeydown, tabsTabStop, } from "./tabs/policy.js";
5
5
  export { accordionKeydown, accordionToggle, } from "./accordion/policy.js";
6
+ export { collapsibleKeydown, collapsibleToggle, } from "./collapsible/policy.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primitiv-ui/core",
3
- "version": "0.1.46",
3
+ "version": "0.1.47",
4
4
  "description": "The framework-free behaviour core shared by every Primitiv surface — keyboard maps, roving-focus targets, id derivation and per-component policy, as pure functions with no DOM and no dependencies.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",