@gjsify/adwaita-core 0.14.0 → 0.16.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/lib/esm/index.js +1 -1
- package/lib/esm/rows.js +1 -0
- package/lib/types/index.d.ts +4 -2
- package/lib/types/rows.d.ts +185 -0
- package/lib/types/rows.spec.d.ts +2 -0
- package/package.json +3 -3
package/lib/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{AdwBreakpoint as e,evaluateBreakpointCondition as t,parseBreakpointCondition as n}from"./breakpoint.js";import{DEFAULT_ICON_COLOR as r,DEFAULT_ICON_COLOR_DARK as i,adwaitaColorScheme as a,isThemeIconColor as o,onAdwaitaColorSchemeChanged as s,setAdwaitaColorScheme as c,themeIconColor as l,toggleAdwaitaColorScheme as u}from"./color-scheme.js";import{AdwAlertResponses as d}from"./dialog.js";import{AdwToast as f,AdwToastQueue as p,DEFAULT_TOAST_TIMEOUT as m}from"./toast.js";export{d as AdwAlertResponses,e as AdwBreakpoint,f as AdwToast,p as AdwToastQueue,r as DEFAULT_ICON_COLOR,i as DEFAULT_ICON_COLOR_DARK,m as DEFAULT_TOAST_TIMEOUT,a as adwaitaColorScheme,t as evaluateBreakpointCondition,o as isThemeIconColor,s as onAdwaitaColorSchemeChanged,n as parseBreakpointCondition,c as setAdwaitaColorScheme,l as themeIconColor,u as toggleAdwaitaColorScheme};
|
|
1
|
+
import{AdwBreakpoint as e,evaluateBreakpointCondition as t,parseBreakpointCondition as n}from"./breakpoint.js";import{DEFAULT_ICON_COLOR as r,DEFAULT_ICON_COLOR_DARK as i,adwaitaColorScheme as a,isThemeIconColor as o,onAdwaitaColorSchemeChanged as s,setAdwaitaColorScheme as c,themeIconColor as l,toggleAdwaitaColorScheme as u}from"./color-scheme.js";import{AdwAlertResponses as d}from"./dialog.js";import{AdwToast as f,AdwToastQueue as p,DEFAULT_TOAST_TIMEOUT as m}from"./toast.js";import{ComboState as h,ExpanderState as g,SpinState as _,ToggleGroupState as v}from"./rows.js";export{d as AdwAlertResponses,e as AdwBreakpoint,f as AdwToast,p as AdwToastQueue,h as ComboState,r as DEFAULT_ICON_COLOR,i as DEFAULT_ICON_COLOR_DARK,m as DEFAULT_TOAST_TIMEOUT,g as ExpanderState,_ as SpinState,v as ToggleGroupState,a as adwaitaColorScheme,t as evaluateBreakpointCondition,o as isThemeIconColor,s as onAdwaitaColorSchemeChanged,n as parseBreakpointCondition,c as setAdwaitaColorScheme,l as themeIconColor,u as toggleAdwaitaColorScheme};
|
package/lib/esm/rows.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";var ExpanderState=class{constructor(){this._expanded=!1,this._listeners=new Set}subscribe(e){return this._listeners.add(e),()=>{this._listeners.delete(e)}}_emit(){for(let e of[...this._listeners])e(this._expanded)}get expanded(){return this._expanded}setExpanded(e){let t=!!e;return t===this._expanded?!1:(this._expanded=t,this._emit(),!0)}toggle(){return this.setExpanded(!this._expanded)}expand(){return this.setExpanded(!0)}collapse(){return this.setExpanded(!1)}},ComboState=class{constructor(){this._options=[],this._selected=0,this._listeners=new Set}subscribe(e){return this._listeners.add(e),()=>{this._listeners.delete(e)}}_emit(e){let t={selected:this._selected,value:this.selectedValue,label:this.selectedLabel,interactive:e};for(let e of[...this._listeners])e(t)}_setIndex(e,t){return e===this._selected?!1:(this._selected=e,this._emit(t),!0)}get options(){return this._options}setOptions(e){this._options=Array.isArray(e)?e:[],this._selected>=this._options.length&&(this._selected=0),this._emit(!1)}get selectedIndex(){return this._selected}setSelectedIndex(e){return this._setIndex(Number.isFinite(e)?e:0,!1)}get selectedValue(){return this._options[this._selected]?.value??``}get selectedLabel(){return this._options[this._selected]?.label??``}setSelectedValue(e){let t=this._options.findIndex(t=>t.value===e);return t>=0?this.setSelectedIndex(t):!1}select(e){return e<0||e===this._selected?!1:this._setIndex(e,!0)}get count(){return this._options.length}},SpinState=class{constructor(){this._value=0,this._min=0,this._max=100,this._step=1,this._listeners=new Set}subscribe(e){return this._listeners.add(e),()=>{this._listeners.delete(e)}}_emit(e){let t={value:this._value,interactive:e};for(let e of[...this._listeners])e(t)}_clamp(e){return Math.min(this._max,Math.max(this._min,e))}_bump(e){let t=this._clamp(this._value+e);return t===this._value?!1:(this._value=t,this._emit(!0),!0)}_reclamp(){let e=this._clamp(this._value);return e===this._value?!1:(this._value=e,this._emit(!1),!0)}get value(){return this._value}get min(){return this._min}get max(){return this._max}get step(){return this._step}setValue(e){let t=this._clamp(Number.isFinite(e)?e:0);return t===this._value?!1:(this._value=t,this._emit(!1),!0)}setMin(e){return this._min=Number.isFinite(e)?e:0,this._reclamp()}setMax(e){return this._max=Number.isFinite(e)?e:0,this._reclamp()}setStep(e){this._step=Number.isFinite(e)&&e>0?e:1}increment(){return this._bump(this._step)}decrement(){return this._bump(-this._step)}},ToggleGroupState=class{constructor(){this._labels=[],this._selected=0,this._listeners=new Set}subscribe(e){return this._listeners.add(e),()=>{this._listeners.delete(e)}}_emit(){let e={selected:this._selected,value:this.selectedValue};for(let t of[...this._listeners])t(e)}get labels(){return this._labels}setLabels(e){this._labels=Array.isArray(e)?e:[],this._selected>=this._labels.length&&(this._selected=0)}get selected(){return this._selected}setSelected(e){let t=Number.isFinite(e)?e:0;return t===this._selected||t<0||t>=this._labels.length?!1:(this._selected=t,this._emit(),!0)}get selectedValue(){return this._labels[this._selected]??``}get count(){return this._labels.length}};export{ComboState,ExpanderState,SpinState,ToggleGroupState};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
export { AdwBreakpoint, evaluateBreakpointCondition, parseBreakpointCondition
|
|
1
|
+
export { AdwBreakpoint, evaluateBreakpointCondition, parseBreakpointCondition } from './breakpoint.js';
|
|
2
2
|
export type { AdwBreakpointHandlers, BreakpointBound, BreakpointConditionGroup, BreakpointConditionLeaf, BreakpointConditionNode, BreakpointDimension, BreakpointSize, } from './breakpoint.js';
|
|
3
3
|
export { DEFAULT_ICON_COLOR, DEFAULT_ICON_COLOR_DARK, adwaitaColorScheme, isThemeIconColor, onAdwaitaColorSchemeChanged, setAdwaitaColorScheme, themeIconColor, toggleAdwaitaColorScheme, } from './color-scheme.js';
|
|
4
4
|
export type { AdwColorScheme } from './color-scheme.js';
|
|
5
5
|
export { AdwToast, AdwToastQueue, DEFAULT_TOAST_TIMEOUT } from './toast.js';
|
|
6
6
|
export type { AdwToastOptions, AdwToastQueueHandlers, AdwToastQueueOptions, ToastScheduler, ToastTimerHandle, } from './toast.js';
|
|
7
7
|
export { AdwAlertResponses } from './dialog.js';
|
|
8
|
-
export type { AdwAlertResponse, AdwResponseAppearance, AdwResponseOptions, OrderedConfirmResponses
|
|
8
|
+
export type { AdwAlertResponse, AdwResponseAppearance, AdwResponseOptions, OrderedConfirmResponses } from './dialog.js';
|
|
9
|
+
export { ComboState, ExpanderState, SpinState, ToggleGroupState } from './rows.js';
|
|
10
|
+
export type { AdwComboOption, ComboStateChange, ComboStateListener, ExpanderStateListener, SpinStateChange, SpinStateListener, ToggleGroupStateChange, ToggleGroupStateListener, } from './rows.js';
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/** Subscriber for {@link ExpanderState} changes — receives the new expanded flag. */
|
|
2
|
+
export type ExpanderStateListener = (expanded: boolean) => void;
|
|
3
|
+
/**
|
|
4
|
+
* The disclosure state of an expander row: a single boolean that toggles between
|
|
5
|
+
* revealed and collapsed. Idempotent — setting the current value again is a no-op
|
|
6
|
+
* and fires no notification. Both programmatic and interactive changes notify (as
|
|
7
|
+
* `Adw.ExpanderRow` does).
|
|
8
|
+
*/
|
|
9
|
+
export declare class ExpanderState {
|
|
10
|
+
private _expanded;
|
|
11
|
+
private readonly _listeners;
|
|
12
|
+
/** Subscribe to expanded-state changes. Returns an unsubscribe function. */
|
|
13
|
+
subscribe(listener: ExpanderStateListener): () => void;
|
|
14
|
+
private _emit;
|
|
15
|
+
/** Whether the disclosure is revealed. */
|
|
16
|
+
get expanded(): boolean;
|
|
17
|
+
/** Set the expanded flag. Notifies only on an actual change. Returns whether it changed. */
|
|
18
|
+
setExpanded(value: boolean): boolean;
|
|
19
|
+
/** Flip expanded↔collapsed (the disclosure tap). Returns whether it changed. */
|
|
20
|
+
toggle(): boolean;
|
|
21
|
+
/** Reveal the disclosure. Returns whether it changed. */
|
|
22
|
+
expand(): boolean;
|
|
23
|
+
/** Collapse the disclosure. Returns whether it changed. */
|
|
24
|
+
collapse(): boolean;
|
|
25
|
+
}
|
|
26
|
+
/** One selectable option in a {@link ComboState}. */
|
|
27
|
+
export interface AdwComboOption {
|
|
28
|
+
/** Display label shown in the row + chooser. */
|
|
29
|
+
label: string;
|
|
30
|
+
/** Underlying value returned by {@link ComboState.selectedValue}. */
|
|
31
|
+
value: string;
|
|
32
|
+
}
|
|
33
|
+
/** Payload of a {@link ComboState} change. */
|
|
34
|
+
export interface ComboStateChange {
|
|
35
|
+
/** The (new) selected index. */
|
|
36
|
+
selected: number;
|
|
37
|
+
/** The selected option's `value` (or `''` when out of range). */
|
|
38
|
+
value: string;
|
|
39
|
+
/** The selected option's `label` (or `''` when out of range) — drives the inline display. */
|
|
40
|
+
label: string;
|
|
41
|
+
/** True for a user pick ({@link ComboState.select}); false for a programmatic set. */
|
|
42
|
+
interactive: boolean;
|
|
43
|
+
}
|
|
44
|
+
/** Subscriber for {@link ComboState} changes. */
|
|
45
|
+
export type ComboStateListener = (change: ComboStateChange) => void;
|
|
46
|
+
/**
|
|
47
|
+
* The selection state of a combo row: an options list plus the selected index,
|
|
48
|
+
* with a two-way index↔value mapping and empty/out-of-range guards. Mirrors
|
|
49
|
+
* `Adw.ComboRow`: a programmatic set ({@link setSelectedIndex} / {@link setSelectedValue}
|
|
50
|
+
* / {@link setOptions}) updates silently (`interactive: false` — the renderer refreshes
|
|
51
|
+
* the inline value but re-emits no `notify::selected`), while {@link select} is the
|
|
52
|
+
* user pick that notifies (`interactive: true`).
|
|
53
|
+
*/
|
|
54
|
+
export declare class ComboState {
|
|
55
|
+
private _options;
|
|
56
|
+
private _selected;
|
|
57
|
+
private readonly _listeners;
|
|
58
|
+
/** Subscribe to selection changes. Returns an unsubscribe function. */
|
|
59
|
+
subscribe(listener: ComboStateListener): () => void;
|
|
60
|
+
private _emit;
|
|
61
|
+
private _setIndex;
|
|
62
|
+
/** The selectable options. */
|
|
63
|
+
get options(): AdwComboOption[];
|
|
64
|
+
/**
|
|
65
|
+
* Replace the options. Resets the selection to 0 when the current index no
|
|
66
|
+
* longer fits (mirroring `Adw.ComboRow`), then notifies (`interactive: false`)
|
|
67
|
+
* so the renderer re-syncs the inline value label (the label may change even at
|
|
68
|
+
* the same index).
|
|
69
|
+
*/
|
|
70
|
+
setOptions(options: AdwComboOption[]): void;
|
|
71
|
+
/** The selected option index (may sit past the options length — {@link selectedValue} then is `''`). */
|
|
72
|
+
get selectedIndex(): number;
|
|
73
|
+
/** Programmatic index set — notifies `interactive: false`. Returns whether it changed. */
|
|
74
|
+
setSelectedIndex(index: number): boolean;
|
|
75
|
+
/** The selected option's `value`, or `''` when out of range. */
|
|
76
|
+
get selectedValue(): string;
|
|
77
|
+
/** The selected option's `label`, or `''` when out of range (the inline display text). */
|
|
78
|
+
get selectedLabel(): string;
|
|
79
|
+
/** Programmatic value set — moves the index to the first option with this `value`. No-op for an unknown value. */
|
|
80
|
+
setSelectedValue(value: string): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Select an option by index as a USER pick (the chooser result) — notifies
|
|
83
|
+
* `interactive: true`. A no-op (returns false) for a negative index or the
|
|
84
|
+
* already-selected one, matching the renderer's chooser guard.
|
|
85
|
+
*/
|
|
86
|
+
select(index: number): boolean;
|
|
87
|
+
/** Number of options. */
|
|
88
|
+
get count(): number;
|
|
89
|
+
}
|
|
90
|
+
/** Payload of a {@link SpinState} change. */
|
|
91
|
+
export interface SpinStateChange {
|
|
92
|
+
/** The new value (already clamped to `[min, max]`). */
|
|
93
|
+
value: number;
|
|
94
|
+
/** True for a stepper press ({@link SpinState.increment}/{@link SpinState.decrement}); false for a programmatic set/re-clamp. */
|
|
95
|
+
interactive: boolean;
|
|
96
|
+
}
|
|
97
|
+
/** Subscriber for {@link SpinState} changes. */
|
|
98
|
+
export type SpinStateListener = (change: SpinStateChange) => void;
|
|
99
|
+
/**
|
|
100
|
+
* The numeric adjustment state of a spin row: `value` bounded by `[min, max]` and
|
|
101
|
+
* stepped by `step`. Every mutation clamps into range. Mirrors `Adw.SpinRow`: a
|
|
102
|
+
* programmatic {@link setValue} (or a re-clamp from a moved {@link setMin}/{@link setMax})
|
|
103
|
+
* notifies `interactive: false` (the renderer refreshes the display but re-emits no
|
|
104
|
+
* `notify::value`), while {@link increment}/{@link decrement} are the stepper presses
|
|
105
|
+
* that notify `interactive: true`.
|
|
106
|
+
*/
|
|
107
|
+
export declare class SpinState {
|
|
108
|
+
private _value;
|
|
109
|
+
private _min;
|
|
110
|
+
private _max;
|
|
111
|
+
private _step;
|
|
112
|
+
private readonly _listeners;
|
|
113
|
+
/** Subscribe to value changes. Returns an unsubscribe function. */
|
|
114
|
+
subscribe(listener: SpinStateListener): () => void;
|
|
115
|
+
private _emit;
|
|
116
|
+
private _clamp;
|
|
117
|
+
private _bump;
|
|
118
|
+
/** Re-clamp the current value after a bound moved; notifies `interactive: false` on change. */
|
|
119
|
+
private _reclamp;
|
|
120
|
+
/** The current numeric value (always within `[min, max]`). */
|
|
121
|
+
get value(): number;
|
|
122
|
+
/** Lower bound. */
|
|
123
|
+
get min(): number;
|
|
124
|
+
/** Upper bound. */
|
|
125
|
+
get max(): number;
|
|
126
|
+
/** Increment/decrement step applied per stepper press. */
|
|
127
|
+
get step(): number;
|
|
128
|
+
/** Programmatic value set — clamp, notify `interactive: false` on change. Returns whether it changed. */
|
|
129
|
+
setValue(value: number): boolean;
|
|
130
|
+
/** Set the lower bound and re-clamp the value into range. Returns whether the value changed. */
|
|
131
|
+
setMin(value: number): boolean;
|
|
132
|
+
/** Set the upper bound and re-clamp the value into range. Returns whether the value changed. */
|
|
133
|
+
setMax(value: number): boolean;
|
|
134
|
+
/** Set the step. A non-positive or non-finite step falls back to `1`. */
|
|
135
|
+
setStep(value: number): void;
|
|
136
|
+
/** Step up by `step`, clamped to `max`. Notifies `interactive: true` on change. Returns whether it changed. */
|
|
137
|
+
increment(): boolean;
|
|
138
|
+
/** Step down by `step`, clamped to `min`. Notifies `interactive: true` on change. Returns whether it changed. */
|
|
139
|
+
decrement(): boolean;
|
|
140
|
+
}
|
|
141
|
+
/** Payload of a {@link ToggleGroupState} change. */
|
|
142
|
+
export interface ToggleGroupStateChange {
|
|
143
|
+
/** The newly-selected segment index. */
|
|
144
|
+
selected: number;
|
|
145
|
+
/** The newly-selected segment's label (or `''` when out of range). */
|
|
146
|
+
value: string;
|
|
147
|
+
}
|
|
148
|
+
/** Subscriber for {@link ToggleGroupState} changes. */
|
|
149
|
+
export type ToggleGroupStateListener = (change: ToggleGroupStateChange) => void;
|
|
150
|
+
/**
|
|
151
|
+
* The selection state of a segmented toggle group: a label list plus the selected
|
|
152
|
+
* index. Mirrors `Adw.ToggleGroup`: {@link setLabels} replaces the segments (resetting
|
|
153
|
+
* the selection to 0 when the current index no longer fits) WITHOUT notifying — the
|
|
154
|
+
* renderer rebuilds its segment views — while {@link setSelected} is the guarded
|
|
155
|
+
* selection change (bounds + no-op-on-same) that notifies. Both programmatic and
|
|
156
|
+
* interactive selections notify (as `Adw.ToggleGroup` does).
|
|
157
|
+
*/
|
|
158
|
+
export declare class ToggleGroupState {
|
|
159
|
+
private _labels;
|
|
160
|
+
private _selected;
|
|
161
|
+
private readonly _listeners;
|
|
162
|
+
/** Subscribe to selection changes. Returns an unsubscribe function. */
|
|
163
|
+
subscribe(listener: ToggleGroupStateListener): () => void;
|
|
164
|
+
private _emit;
|
|
165
|
+
/** The segment labels. */
|
|
166
|
+
get labels(): string[];
|
|
167
|
+
/**
|
|
168
|
+
* Replace the segment labels. Resets the selection to 0 when the current index
|
|
169
|
+
* no longer fits. Silent — the renderer rebuilds its segment views and re-applies
|
|
170
|
+
* the active pill from {@link selected}.
|
|
171
|
+
*/
|
|
172
|
+
setLabels(labels: string[]): void;
|
|
173
|
+
/** The selected segment index. */
|
|
174
|
+
get selected(): number;
|
|
175
|
+
/**
|
|
176
|
+
* Select a segment. Guarded like `Adw.ToggleGroup`: a non-finite, negative,
|
|
177
|
+
* out-of-range, or already-selected index is a no-op. Notifies on a valid change.
|
|
178
|
+
* Returns whether it changed.
|
|
179
|
+
*/
|
|
180
|
+
setSelected(index: number): boolean;
|
|
181
|
+
/** The selected segment's label, or `''` when out of range. */
|
|
182
|
+
get selectedValue(): string;
|
|
183
|
+
/** Number of segments. */
|
|
184
|
+
get count(): number;
|
|
185
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/adwaita-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "Headless Adwaita widget behavior (breakpoint condition grammar + apply/unapply state machine, color-scheme observable) shared by the web and NativeScript Adwaita renderers — pure TS, no platform imports",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "lib/esm/index.js",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"headless"
|
|
40
40
|
],
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@gjsify/cli": "^0.
|
|
43
|
-
"@gjsify/unit": "^0.
|
|
42
|
+
"@gjsify/cli": "^0.16.0",
|
|
43
|
+
"@gjsify/unit": "^0.16.0",
|
|
44
44
|
"@types/node": "^25.9.2",
|
|
45
45
|
"typescript": "^6.0.3"
|
|
46
46
|
},
|