@primitiv-ui/core 0.1.43 → 0.1.45
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/dist/accordion/policy.d.ts +47 -0
- package/dist/accordion/policy.js +41 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** Layout axis of the accordion: which arrow pair moves between triggers. */
|
|
2
|
+
export type AccordionOrientation = "vertical" | "horizontal";
|
|
3
|
+
/** Reading direction. Under `"rtl"` the horizontal arrows are mirrored. */
|
|
4
|
+
export type AccordionReadingDirection = "ltr" | "rtl";
|
|
5
|
+
/**
|
|
6
|
+
* Everything Accordion's toggle and keyboard rules depend on, as plain data.
|
|
7
|
+
* Each surface builds it from wherever it keeps state — React state, or a
|
|
8
|
+
* custom element's attributes — and applies the outcome back the same way.
|
|
9
|
+
*/
|
|
10
|
+
export type AccordionState = {
|
|
11
|
+
/** Every item's value, in DOM order, disabled ones included. */
|
|
12
|
+
values: readonly string[];
|
|
13
|
+
/** The values of the disabled items. */
|
|
14
|
+
disabled: ReadonlySet<string>;
|
|
15
|
+
/** The values of the open items. */
|
|
16
|
+
expanded: readonly string[];
|
|
17
|
+
/** Whether more than one item may be open at once. */
|
|
18
|
+
multiple: boolean;
|
|
19
|
+
orientation: AccordionOrientation;
|
|
20
|
+
dir: AccordionReadingDirection;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The open items after toggling `value`: an open item closes; a closed one
|
|
24
|
+
* opens and, unless `multiple`, closes every other. `null` for a disabled item,
|
|
25
|
+
* which never toggles, so no change is reported.
|
|
26
|
+
*/
|
|
27
|
+
export declare function accordionToggle(state: Pick<AccordionState, "disabled" | "expanded" | "multiple">, value: string): string[] | null;
|
|
28
|
+
/** What a key press on a trigger asks for: a trigger to move focus to, or an
|
|
29
|
+
* item to toggle — never both. */
|
|
30
|
+
export type AccordionKeyOutcome = {
|
|
31
|
+
focus: string | null;
|
|
32
|
+
toggle: string | null;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Accordion's keyboard contract for a key press on the trigger of `focused`:
|
|
36
|
+
*
|
|
37
|
+
* - arrows follow `orientation`, mirrored under RTL, and wrap at the ends; Home
|
|
38
|
+
* / End jump to the first and last enabled trigger. They move focus only;
|
|
39
|
+
* - Enter / Space toggle the focused item;
|
|
40
|
+
* - disabled items are **skipped**, unlike Tabs, which lands on them. While focus
|
|
41
|
+
* sits on a disabled trigger the arrows and Enter / Space do nothing, though
|
|
42
|
+
* Home / End still jump.
|
|
43
|
+
*
|
|
44
|
+
* Returns `null` for a key Accordion does not handle, which tells the caller to
|
|
45
|
+
* leave the event alone (no `preventDefault`).
|
|
46
|
+
*/
|
|
47
|
+
export declare function accordionKeydown(state: AccordionState, focused: string, key: string): AccordionKeyOutcome | null;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { getKeyToActionMap } from "../keyboard/getKeyToActionMap.js";
|
|
2
|
+
import { resolveRovingTarget } from "../keyboard/resolveRovingTarget.js";
|
|
3
|
+
/**
|
|
4
|
+
* The open items after toggling `value`: an open item closes; a closed one
|
|
5
|
+
* opens and, unless `multiple`, closes every other. `null` for a disabled item,
|
|
6
|
+
* which never toggles, so no change is reported.
|
|
7
|
+
*/
|
|
8
|
+
export function accordionToggle(state, value) {
|
|
9
|
+
if (state.disabled.has(value))
|
|
10
|
+
return null;
|
|
11
|
+
if (state.expanded.includes(value))
|
|
12
|
+
return state.expanded.filter((open) => open !== value);
|
|
13
|
+
return state.multiple ? [...state.expanded, value] : [value];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Accordion's keyboard contract for a key press on the trigger of `focused`:
|
|
17
|
+
*
|
|
18
|
+
* - arrows follow `orientation`, mirrored under RTL, and wrap at the ends; Home
|
|
19
|
+
* / End jump to the first and last enabled trigger. They move focus only;
|
|
20
|
+
* - Enter / Space toggle the focused item;
|
|
21
|
+
* - disabled items are **skipped**, unlike Tabs, which lands on them. While focus
|
|
22
|
+
* sits on a disabled trigger the arrows and Enter / Space do nothing, though
|
|
23
|
+
* Home / End still jump.
|
|
24
|
+
*
|
|
25
|
+
* Returns `null` for a key Accordion does not handle, which tells the caller to
|
|
26
|
+
* leave the event alone (no `preventDefault`).
|
|
27
|
+
*/
|
|
28
|
+
export function accordionKeydown(state, focused, key) {
|
|
29
|
+
const action = getKeyToActionMap({
|
|
30
|
+
orientation: state.orientation,
|
|
31
|
+
dir: state.dir,
|
|
32
|
+
homeEnd: true,
|
|
33
|
+
activate: true,
|
|
34
|
+
})[key];
|
|
35
|
+
if (action === "activate") {
|
|
36
|
+
return state.disabled.has(focused) ? null : { focus: null, toggle: focused };
|
|
37
|
+
}
|
|
38
|
+
const navigable = state.values.filter((value) => !state.disabled.has(value));
|
|
39
|
+
const result = resolveRovingTarget({ action, navigable, currentKey: focused });
|
|
40
|
+
return result && { focus: result.target, toggle: null };
|
|
41
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,3 +2,4 @@ export { deriveId } from "./ids/deriveId.js";
|
|
|
2
2
|
export { getKeyToActionMap, type RovingKeyAction } from "./keyboard/getKeyToActionMap.js";
|
|
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
|
+
export { accordionKeydown, accordionToggle, type AccordionKeyOutcome, type AccordionOrientation, type AccordionReadingDirection, type AccordionState, } from "./accordion/policy.js";
|
package/dist/index.js
CHANGED
|
@@ -2,3 +2,4 @@ export { deriveId } from "./ids/deriveId.js";
|
|
|
2
2
|
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
|
+
export { accordionKeydown, accordionToggle, } from "./accordion/policy.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primitiv-ui/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.45",
|
|
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",
|