@gjsify/adwaita-core 0.47.0 → 0.48.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/adjustment.js +1 -0
- package/lib/esm/conformance/adjustment.js +1 -0
- package/lib/esm/conformance/index.js +1 -1
- package/lib/esm/conformance/list.js +1 -0
- package/lib/esm/conformance/menu.js +1 -0
- package/lib/esm/conformance/rows.js +1 -1
- package/lib/esm/conformance/split-button.js +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/list.js +1 -0
- package/lib/esm/menu.js +2 -0
- package/lib/esm/rows.js +1 -1
- package/lib/esm/split-button.js +1 -1
- package/lib/esm/tab-view.js +1 -1
- package/lib/types/adjustment.d.ts +198 -0
- package/lib/types/adjustment.spec.d.ts +2 -0
- package/lib/types/conformance/adjustment.d.ts +33 -0
- package/lib/types/conformance/index.d.ts +8 -2
- package/lib/types/conformance/list.d.ts +171 -0
- package/lib/types/conformance/menu.d.ts +118 -0
- package/lib/types/conformance/rows.d.ts +3 -3
- package/lib/types/conformance/split-button.d.ts +9 -19
- package/lib/types/index.d.ts +11 -5
- package/lib/types/list.d.ts +109 -0
- package/lib/types/list.spec.d.ts +2 -0
- package/lib/types/menu.d.ts +366 -0
- package/lib/types/menu.spec.d.ts +2 -0
- package/lib/types/rows.d.ts +78 -109
- package/lib/types/split-button.d.ts +21 -32
- package/lib/types/tab-view.d.ts +24 -0
- package/package.json +3 -3
package/lib/types/index.d.ts
CHANGED
|
@@ -24,8 +24,12 @@ export { AdwToast, AdwToastQueue, DEFAULT_TOAST_TIMEOUT } from './toast.js';
|
|
|
24
24
|
export type { AdwToastOptions, AdwToastQueueHandlers, AdwToastQueueOptions, ToastScheduler, ToastTimerHandle, } from './toast.js';
|
|
25
25
|
export { AdwAlertResponses, BottomSheetPresentation, resolveBottomSheetClose } from './dialog.js';
|
|
26
26
|
export type { AdwAlertResponse, AdwResponseAppearance, AdwResponseOptions, BottomSheetCloseOutcome, BottomSheetCloseSource, BottomSheetCloseState, BottomSheetPresentationListener, BottomSheetPresentationOptions, BottomSheetTeardownCallback, OrderedConfirmResponses, } from './dialog.js';
|
|
27
|
-
export { ADW_COMBO_NO_SELECTION,
|
|
28
|
-
export type { AdwComboOption, AdwComboOptionInput,
|
|
27
|
+
export { ADW_COMBO_NO_SELECTION, clampListSelection, listItemsChanged, normalizeComboOptions, parseListModel, } from './list.js';
|
|
28
|
+
export type { AdwComboOption, AdwComboOptionInput, AdwListItemsChanged, AdwListModel, AdwListModelInput, } from './list.js';
|
|
29
|
+
export { ADW_ADJUSTMENT_DEFAULTS, adjustmentRange, clampAdjustmentValue, normalizeAdjustment, parseAdjustment, snapAdjustmentValue, SpinState, } from './adjustment.js';
|
|
30
|
+
export type { AdwAdjustment, AdwAdjustmentInput, SpinStateChange, SpinStateListener, SpinStateRangeListener, } from './adjustment.js';
|
|
31
|
+
export { ComboState, ExpanderState, ToggleGroupState } from './rows.js';
|
|
32
|
+
export type { ComboItemsListener, ComboStateChange, ComboStateListener, ExpanderStateListener, ToggleGroupStateChange, ToggleGroupStateListener, } from './rows.js';
|
|
29
33
|
export { glibClamp, gStrStrip, stringIsNotEmpty } from './glib.js';
|
|
30
34
|
export { ViewStackState, normalizeIconName, resolvePageTitle } from './view-stack.js';
|
|
31
35
|
export type { AdwViewStackPageInfo, AdwViewStackPageSpec, ViewStackStateChange, ViewStackStateListener, } from './view-stack.js';
|
|
@@ -44,11 +48,13 @@ export { ADW_LENGTH_UNITS, DEFAULT_DPI, adwLengthToPx, normalizeLengthUnit } fro
|
|
|
44
48
|
export type { AdwLengthUnit } from './length-unit.js';
|
|
45
49
|
export { ADW_SWIPE_BORDER, DEFAULT_MAX_SIDEBAR_WIDTH, DEFAULT_MIN_SIDEBAR_WIDTH, DEFAULT_SIDEBAR_WIDTH_FRACTION, DEFAULT_SIDEBAR_WIDTH_UNIT, INSTANT_SPLIT_VIEW_ANIMATOR, NAVIGATION_SPLIT_VIEW_CRITICALS, NavigationSplitViewState, OverlaySplitViewState, isSidebarAtVisualStart, layoutNavigationSplitView, layoutOverlaySplitView, measureSplitViewHorizontal, resolveNaturalSidebarWidth, resolveNavigationAction, resolveNavigationSidebarWidth, resolveNavigationStack, resolveOverlaySidebarWidth, resolveSidebarBounds, resolveSwipeArea, resolveSwipeRelease, resolveSwipeSnapPoints, resolveSwipeStart, swipeCancelProgress, tagsConflict, } from './split-view.js';
|
|
46
50
|
export type { AdwPackType, AdwTextDirection, NavigationActionInput, NavigationActionResult, NavigationPageRef, NavigationSplitViewChange, NavigationSplitViewHandlers, NavigationSplitViewLayout, NavigationSplitViewListener, NavigationSplitViewOptions, NavigationSplitViewProperty, NavigationStackPlan, OverlaySplitViewChange, OverlaySplitViewLayout, OverlaySplitViewListener, OverlaySplitViewOptions, OverlaySplitViewProperty, SidebarBounds, SidebarWidthInput, SidebarWidthSpec, SplitViewAnimation, SplitViewAnimationRequest, SplitViewAnimator, SplitViewMeasureInput, SplitViewPane, SplitViewPaneRect, SwipeReleasePlan, } from './split-view.js';
|
|
47
|
-
export { DEFAULT_DROPDOWN_TOOLTIP, SPLIT_BUTTON_DISABLED_OPACITY, SplitButtonState, isSplitButtonDirection, menuButtonArrowIcon, menuButtonPopupDirection,
|
|
48
|
-
export type { AdwArrowIcon,
|
|
51
|
+
export { DEFAULT_DROPDOWN_TOOLTIP, SPLIT_BUTTON_DISABLED_OPACITY, SplitButtonState, isSplitButtonDirection, menuButtonArrowIcon, menuButtonPopupDirection, resolveDropdownTooltip, splitButtonArrowIcon, splitButtonPopupDirection, splitButtonRootState, splitButtonStyleClasses, } from './split-button.js';
|
|
52
|
+
export type { AdwArrowIcon, SplitButtonChange, SplitButtonContentMode, SplitButtonDirection, SplitButtonHalfState, SplitButtonListener, SplitButtonProperty, SplitButtonStyleClass, } from './split-button.js';
|
|
53
|
+
export { ADW_MENU_SURFACE_NATIVESCRIPT, ADW_MENU_SURFACE_WEB, assertMenuRenderable, flattenMenu, menuItemAt, menuNodeAt, menuRefusals, normalizeMenuModel, parseDetailedAction, parseMenuModel, resolveMenuItemState, } from './menu.js';
|
|
54
|
+
export type { AdwDetailedAction, AdwMenuAction, AdwMenuActions, AdwMenuDisplayHint, AdwMenuEntryInput, AdwMenuFlatRow, AdwMenuHiddenWhen, AdwMenuInput, AdwMenuItem, AdwMenuItemInput, AdwMenuItemRole, AdwMenuItemState, AdwMenuModel, AdwMenuNode, AdwMenuPath, AdwMenuRefusal, AdwMenuSection, AdwMenuSectionInput, AdwMenuSubmenu, AdwMenuSubmenuInput, AdwMenuSurface, AdwMenuTextDirection, } from './menu.js';
|
|
49
55
|
export { DEFAULT_INDICATOR_DESCRIPTION_STRINGS, INLINE_VIEW_SWITCHER_DISPLAY_MODES, VIEW_SWITCHER_BADGE_LIMIT, VIEW_SWITCHER_DRAG_SWITCH_DELAY, VIEW_SWITCHER_FALLBACK_ICON, VIEW_SWITCHER_NO_SELECTION, VIEW_SWITCHER_POLICIES, ViewSwitcherBarState, ViewSwitcherDragSwitch, ViewSwitcherState, buildInlineToggles, buildViewSwitcherButtons, createViewSwitcherPage, inlineToggleTooltip, isInlineViewSwitcherDisplayMode, isViewSwitcherButtonVisible, isViewSwitcherPolicy, pageIndexForToggle, shouldRevealViewSwitcherBar, stripMnemonic, toggleIndexForPage, viewSwitcherBadgeLabel, viewSwitcherButtonOrientation, viewSwitcherIconName, viewSwitcherIndicatorDescription, viewSwitcherLabel, viewSwitcherPageFromStackPage, viewSwitcherPagesFromStack, } from './view-switcher.js';
|
|
50
56
|
export type { AdwInlineViewSwitcherDisplayMode, AdwViewSwitcherPage, AdwViewSwitcherPageInit, AdwViewSwitcherPolicy, IndicatorDescriptionStrings, InlineToggleModel, ViewSwitcherBarChange, ViewSwitcherBarListener, ViewSwitcherButtonModel, ViewSwitcherDragSwitchOptions, ViewSwitcherScheduler, ViewSwitcherStateChange, ViewSwitcherStateListener, ViewSwitcherStateOptions, ViewSwitcherTimerHandle, } from './view-switcher.js';
|
|
51
|
-
export { DEFAULT_TAB_AUTOHIDE, TabViewState, isDescendantOfPage, successorAfterClose, tabCloseVisible, tabIconState, tabTooltip, tabTooltipIsMarkup, tabsRevealed, } from './tab-view.js';
|
|
57
|
+
export { DEFAULT_TAB_AUTOHIDE, TabViewState, isDescendantOfPage, successorAfterClose, tabCloseVisible, tabIconState, tabTooltip, tabTooltipIsMarkup, tabViewItemsChanged, tabsRevealed, } from './tab-view.js';
|
|
52
58
|
export type { AdwTabPageSpec, AdwTabPageState, TabIconState, TabViewHandlers, TabViewPagesChange, TabViewPagesChangeKind, TabViewPagesListener, TabViewSelectionChange, TabViewSelectionListener, } from './tab-view.js';
|
|
53
59
|
export { ADW_SWIPE_DECELERATION_TOUCH, ADW_SWIPE_DECELERATION_TOUCHPAD, ADW_SWIPE_DRAG_THRESHOLD, ADW_SWIPE_EPSILON, ADW_SWIPE_HISTORY_THRESHOLD_MS, ADW_SWIPE_PARABOLA_MULTIPLIER, ADW_SWIPE_TOUCHPAD_BASE_DISTANCE_H, ADW_SWIPE_TOUCHPAD_BASE_DISTANCE_V, ADW_SWIPE_VELOCITY_CURVE_THRESHOLD, ADW_SWIPE_VELOCITY_THRESHOLD_TOUCH, ADW_SWIPE_VELOCITY_THRESHOLD_TOUCHPAD, SwipeTracker, swipeBounds, swipeClosestPointIndex, swipeEndProgress, swipeNextPointIndex, swipePreviousPointIndex, swipeProjectedPointIndex, swipeSlope, swipeVelocityThreshold, } from './swipe.js';
|
|
54
60
|
export type { AdwSwipeEnd, AdwSwipeEndInput, AdwSwipeRange, AdwSwipeSource } from './swipe.js';
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/** One selectable item — the display text plus the value it is addressed by. */
|
|
2
|
+
export interface AdwComboOption {
|
|
3
|
+
/** Display label shown in the row + chooser. */
|
|
4
|
+
label: string;
|
|
5
|
+
/** Underlying value the item is addressed by. */
|
|
6
|
+
value: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* What an author may write for one item before {@link normalizeComboOptions} has seen it:
|
|
10
|
+
* a bare string (value === label, the `Gtk.StringList` case), or a partial descriptor
|
|
11
|
+
* where either half may stand in for the other.
|
|
12
|
+
*/
|
|
13
|
+
export type AdwComboOptionInput = string | {
|
|
14
|
+
value?: unknown;
|
|
15
|
+
label?: unknown;
|
|
16
|
+
};
|
|
17
|
+
/** A normalised portable list model — what a `model` property holds on every surface. */
|
|
18
|
+
export type AdwListModel = ReadonlyArray<AdwComboOption>;
|
|
19
|
+
/** What a `model` property ACCEPTS: the widened form of {@link AdwListModel}. */
|
|
20
|
+
export type AdwListModelInput = ReadonlyArray<AdwComboOptionInput>;
|
|
21
|
+
/**
|
|
22
|
+
* Raw authored items → the stable `{ value, label }` descriptors every list surface
|
|
23
|
+
* works with.
|
|
24
|
+
*
|
|
25
|
+
* A bare string is both value and label (`Gtk.StringList`'s model, which is what
|
|
26
|
+
* `Adw.ComboRow` is fed in the common case). In a descriptor either half stands in for the
|
|
27
|
+
* missing other, so `{ label: 'Apple' }` is addressable by the value `'Apple'` rather than
|
|
28
|
+
* by `undefined`. ONE home for the rule, so no two list widgets can accept two different
|
|
29
|
+
* item vocabularies.
|
|
30
|
+
*
|
|
31
|
+
* TOTAL — it throws for no input. The doors this reaches are a property assignment and a
|
|
32
|
+
* markup attribute, and an author's typo must not take the widget down.
|
|
33
|
+
*/
|
|
34
|
+
export declare function normalizeComboOptions(raw: AdwListModelInput | null | undefined): AdwComboOption[];
|
|
35
|
+
/**
|
|
36
|
+
* The MARKUP door: a JSON attribute → the normalised model.
|
|
37
|
+
*
|
|
38
|
+
* Total in both of its failure modes, which are different things and both an author slip:
|
|
39
|
+
* unparseable JSON and well-formed JSON that is not an array (an object, a number)
|
|
40
|
+
* each yield the empty model. Neither may stop the element upgrading — the reasoning
|
|
41
|
+
* `parseMenuModel` records for the same door on the same surfaces.
|
|
42
|
+
*
|
|
43
|
+
* It lives here rather than in each element because it was written twice, byte for byte,
|
|
44
|
+
* in `<adw-combo-row>` and `<gtk-drop-down>`: the second copy is where a helper is lifted.
|
|
45
|
+
*/
|
|
46
|
+
export declare function parseListModel(raw: string | null | undefined): AdwComboOption[];
|
|
47
|
+
/**
|
|
48
|
+
* The "no item is selected" index — the TS mirror of `GTK_INVALID_LIST_POSITION`
|
|
49
|
+
* (`AdwComboRow:selected`'s default and empty value).
|
|
50
|
+
*
|
|
51
|
+
* libadwaita spells it `G_MAXUINT` because the property is a `guint`; `-1` is the idiomatic
|
|
52
|
+
* TS sentinel and the spelling {@link ADW_SIDEBAR_NO_SELECTION} uses for the same GTK
|
|
53
|
+
* constant. Without it, an EMPTY model and a model whose first item has an empty label are
|
|
54
|
+
* indistinguishable — both report index 0 with an empty value — so a renderer that wants to
|
|
55
|
+
* draw a placeholder has nothing to test.
|
|
56
|
+
*/
|
|
57
|
+
export declare const ADW_COMBO_NO_SELECTION = -1;
|
|
58
|
+
/**
|
|
59
|
+
* Where a selection lands after the model under it was REPLACED.
|
|
60
|
+
*
|
|
61
|
+
* `GtkSingleSelection` autoselects, so a position the new model does not have falls back
|
|
62
|
+
* to 0 — including the sentinel, which is how a widget recovers a selection when its model
|
|
63
|
+
* grows. An EMPTY model has no 0 to fall back to and lands on
|
|
64
|
+
* {@link ADW_COMBO_NO_SELECTION}.
|
|
65
|
+
*
|
|
66
|
+
* The test is membership and not `selected >= length`: the sentinel is BELOW the range, so
|
|
67
|
+
* a one-sided comparison leaves a `-1` in place and a model that was emptied and refilled
|
|
68
|
+
* comes back with nothing selected.
|
|
69
|
+
*
|
|
70
|
+
* Lifted out of `ComboState.setModel` so a second list widget cannot re-derive it. The
|
|
71
|
+
* cross-renderer rule it encodes was already conformance data — `conformance/rows.ts`
|
|
72
|
+
* carries it as "the ports' shared answer" — it just had no name of its own.
|
|
73
|
+
*/
|
|
74
|
+
export declare function clampListSelection(selected: number, length: number): number;
|
|
75
|
+
/**
|
|
76
|
+
* One positional change — `Gio.ListModel::items-changed`'s own three parameters.
|
|
77
|
+
*
|
|
78
|
+
* `position` is where the model changed, `removed` how many items went, `added` how many
|
|
79
|
+
* arrived. WHAT arrived is deliberately absent, because that is GLib's contract too: a
|
|
80
|
+
* consumer re-reads the model over `[position, position + added)`. Carrying the items
|
|
81
|
+
* would make the signal a second copy of the model that can disagree with it.
|
|
82
|
+
*/
|
|
83
|
+
export interface AdwListItemsChanged {
|
|
84
|
+
/** The position at which the model changed. */
|
|
85
|
+
readonly position: number;
|
|
86
|
+
/** The number of items removed at {@link position}. */
|
|
87
|
+
readonly removed: number;
|
|
88
|
+
/** The number of items added at {@link position}. */
|
|
89
|
+
readonly added: number;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The ONE splice that turns `previous` into `next` — the `items-changed` a model
|
|
93
|
+
* replacement should emit, or `null` when the two are equal and GTK would emit nothing.
|
|
94
|
+
*
|
|
95
|
+
* It is the minimal single range: the shared prefix and the shared suffix are kept, and
|
|
96
|
+
* everything between them is the change. That is `g_list_store_splice`'s shape and its
|
|
97
|
+
* stated reason — one emission per change rather than one per item — and it is what lets
|
|
98
|
+
* a renderer append an item to a hundred-item list by adding ONE node.
|
|
99
|
+
*
|
|
100
|
+
* Items compare by BOTH halves: a descriptor whose label changed at an unchanged value is
|
|
101
|
+
* a different thing to draw, so it is inside the range. Comparing by `value` alone would
|
|
102
|
+
* leave a renamed row showing its old text, which is the exact failure `selection_item_changed`
|
|
103
|
+
* exists for upstream.
|
|
104
|
+
*
|
|
105
|
+
* NOT a diff algorithm. A model that moves one item from the front to the back reports the
|
|
106
|
+
* whole span, because `items-changed` has no vocabulary for a move — GTK's own list store
|
|
107
|
+
* reports `g_list_store_move` the same way.
|
|
108
|
+
*/
|
|
109
|
+
export declare function listItemsChanged(previous: AdwListModel | null | undefined, next: AdwListModel | null | undefined): AdwListItemsChanged | null;
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The values `hidden-when` is documented to take.
|
|
3
|
+
*
|
|
4
|
+
* A union rather than `string` because each one has its OWN visibility rule in
|
|
5
|
+
* {@link resolveMenuItemState}; an unrecognised value is ignored by C on purpose ("this
|
|
6
|
+
* code may be running in context of a desktop shell … and should not spew criticals"),
|
|
7
|
+
* which {@link normalizeMenuModel} reproduces by dropping it.
|
|
8
|
+
*/
|
|
9
|
+
export type AdwMenuHiddenWhen = 'action-disabled' | 'action-missing' | 'macos-menubar';
|
|
10
|
+
/** A section's `display-hint`, which asks for a row of buttons instead of a list. */
|
|
11
|
+
export type AdwMenuDisplayHint = 'horizontal-buttons' | 'circular-buttons' | 'inline-buttons';
|
|
12
|
+
/** A section's `text-direction`, read only when {@link AdwMenuDisplayHint} is horizontal. */
|
|
13
|
+
export type AdwMenuTextDirection = 'ltr' | 'rtl' | 'none';
|
|
14
|
+
/**
|
|
15
|
+
* One menu item — the attributes `GtkPopoverMenu` documents, plus `id`.
|
|
16
|
+
*
|
|
17
|
+
* `id` is OURS and has no meaning to GTK. It survives the round trip anyway, because a
|
|
18
|
+
* `GMenuModel`'s attribute space is open (`g_menu_item_set_attribute` takes any name and
|
|
19
|
+
* GTK ignores what it does not know), so carrying it is not a divergence — it is an
|
|
20
|
+
* unread attribute, exactly like an application's own. It exists because the two
|
|
21
|
+
* renderers' activation events already reported one, falling back to the label.
|
|
22
|
+
*/
|
|
23
|
+
export interface AdwMenuItem {
|
|
24
|
+
readonly kind: 'item';
|
|
25
|
+
/** The user-visible string. `''` for an item that has none — never `undefined`. */
|
|
26
|
+
readonly label: string;
|
|
27
|
+
/**
|
|
28
|
+
* The DETAILED action name — `app.save-as`, `app.view::list`, `win.zoom(2)`.
|
|
29
|
+
*
|
|
30
|
+
* One string rather than an action plus a target, because that is what
|
|
31
|
+
* `g_menu_item_set_detailed_action` takes and what `g_action_parse_detailed_name`
|
|
32
|
+
* can read back for every `GVariant` target type. {@link parseDetailedAction} splits
|
|
33
|
+
* it where a surface needs the halves.
|
|
34
|
+
*/
|
|
35
|
+
readonly action?: string;
|
|
36
|
+
/** Symbolic icon name shown beside the label. */
|
|
37
|
+
readonly icon?: string;
|
|
38
|
+
/** Icon for the button form a `display-hint` section draws instead of a row. */
|
|
39
|
+
readonly verbIcon?: string;
|
|
40
|
+
/** Accelerator text, e.g. `<Control>s`. Display only — it binds nothing. */
|
|
41
|
+
readonly accel?: string;
|
|
42
|
+
/** When this item disappears rather than merely dimming. */
|
|
43
|
+
readonly hiddenWhen?: AdwMenuHiddenWhen;
|
|
44
|
+
/** Names an application widget the surface must host in place of a row. */
|
|
45
|
+
readonly custom?: string;
|
|
46
|
+
/** Whether {@link label} is Pango markup. */
|
|
47
|
+
readonly useMarkup?: boolean;
|
|
48
|
+
/** Stable identifier for activation reporting; defaults to {@link label}. */
|
|
49
|
+
readonly id?: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A `section` link: items drawn inline, separated from their neighbours.
|
|
53
|
+
*
|
|
54
|
+
* A section is NOT a container the user opens — it is a visual grouping, which is why a
|
|
55
|
+
* flat surface may inline it ({@link flattenMenu}) without losing an item.
|
|
56
|
+
*/
|
|
57
|
+
export interface AdwMenuSection {
|
|
58
|
+
readonly kind: 'section';
|
|
59
|
+
/** Optional heading above the group. */
|
|
60
|
+
readonly label?: string;
|
|
61
|
+
readonly displayHint?: AdwMenuDisplayHint;
|
|
62
|
+
readonly textDirection?: AdwMenuTextDirection;
|
|
63
|
+
readonly items: readonly AdwMenuNode[];
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* A `submenu` link: a nested menu the user opens.
|
|
67
|
+
*
|
|
68
|
+
* `submenuAction` is documented under ITEMS (`gtkpopovermenu.c:106-107`) rather than
|
|
69
|
+
* under submenus, and it is here anyway: it names the action that tracks whether the
|
|
70
|
+
* submenu is OPEN, so the only item it can sit on is the one carrying the link — which
|
|
71
|
+
* in this model IS this node. `gtkmenutrackeritem.c:822` and `:1049` read it, and both
|
|
72
|
+
* paths are submenu paths.
|
|
73
|
+
*/
|
|
74
|
+
export interface AdwMenuSubmenu {
|
|
75
|
+
readonly kind: 'submenu';
|
|
76
|
+
readonly label: string;
|
|
77
|
+
readonly icon?: string;
|
|
78
|
+
/** Action tracking whether this submenu is shown (`submenu-action`). */
|
|
79
|
+
readonly submenuAction?: string;
|
|
80
|
+
/**
|
|
81
|
+
* `gtk-macos-special` — macOS menu-bar meaning, ignored everywhere else
|
|
82
|
+
* (`gtkpopovermenu.c:130-131`, read at `gtkmenutrackeritem.c:761`).
|
|
83
|
+
*
|
|
84
|
+
* Carried and never acted on here: no renderer in this workspace exports a macOS
|
|
85
|
+
* menu bar. It is in the model so that a menu written for one survives the trip,
|
|
86
|
+
* which is the whole lossless claim.
|
|
87
|
+
*/
|
|
88
|
+
readonly macosSpecial?: string;
|
|
89
|
+
readonly items: readonly AdwMenuNode[];
|
|
90
|
+
}
|
|
91
|
+
/** Any node of a normalised model. */
|
|
92
|
+
export type AdwMenuNode = AdwMenuItem | AdwMenuSection | AdwMenuSubmenu;
|
|
93
|
+
/**
|
|
94
|
+
* A normalised menu: the value a renderer walks and the GTK host converts.
|
|
95
|
+
*
|
|
96
|
+
* `readonly` throughout, because every renderer holds one across a render and a shared
|
|
97
|
+
* mutable tree is how two widgets showing the same menu would diverge.
|
|
98
|
+
*/
|
|
99
|
+
export type AdwMenuModel = readonly AdwMenuNode[];
|
|
100
|
+
/** An item as authored — `kind` is implied by the absence of a link. */
|
|
101
|
+
export interface AdwMenuItemInput {
|
|
102
|
+
label?: unknown;
|
|
103
|
+
action?: unknown;
|
|
104
|
+
icon?: unknown;
|
|
105
|
+
verbIcon?: unknown;
|
|
106
|
+
accel?: unknown;
|
|
107
|
+
hiddenWhen?: unknown;
|
|
108
|
+
custom?: unknown;
|
|
109
|
+
useMarkup?: unknown;
|
|
110
|
+
id?: unknown;
|
|
111
|
+
}
|
|
112
|
+
/** A section as authored — the `section` key IS the link. */
|
|
113
|
+
export interface AdwMenuSectionInput {
|
|
114
|
+
section: readonly AdwMenuEntryInput[];
|
|
115
|
+
label?: unknown;
|
|
116
|
+
displayHint?: unknown;
|
|
117
|
+
textDirection?: unknown;
|
|
118
|
+
}
|
|
119
|
+
/** A submenu as authored — the `submenu` key IS the link. */
|
|
120
|
+
export interface AdwMenuSubmenuInput {
|
|
121
|
+
submenu: readonly AdwMenuEntryInput[];
|
|
122
|
+
label?: unknown;
|
|
123
|
+
icon?: unknown;
|
|
124
|
+
submenuAction?: unknown;
|
|
125
|
+
macosSpecial?: unknown;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* One authored entry.
|
|
129
|
+
*
|
|
130
|
+
* A BARE STRING is a label-only item, and that form is not a NativeScript leftover: it
|
|
131
|
+
* is the model's own shorthand, the same one {@link normalizeComboOptions} gives an
|
|
132
|
+
* option list, and it is now accepted on every surface rather than on one. What it
|
|
133
|
+
* cannot carry — an action, an icon, a section — is exactly what made
|
|
134
|
+
* `button.menu = ['Save as…']` unable to grow, so the shorthand widens INTO this union
|
|
135
|
+
* instead of standing beside it.
|
|
136
|
+
*/
|
|
137
|
+
export type AdwMenuEntryInput = string | AdwMenuItemInput | AdwMenuSectionInput | AdwMenuSubmenuInput;
|
|
138
|
+
/** A menu as authored, before {@link normalizeMenuModel} has seen it. */
|
|
139
|
+
export type AdwMenuInput = readonly AdwMenuEntryInput[];
|
|
140
|
+
/**
|
|
141
|
+
* Authored entries → the normalised model every renderer walks.
|
|
142
|
+
*
|
|
143
|
+
* TOTAL BY CONSTRUCTION. The input reaches this function from author-written markup (a
|
|
144
|
+
* JSON attribute, an XML attribute, a JSX expression), and a typo must not take the
|
|
145
|
+
* widget down with it — the same rule the `menu` attribute parser it replaces already
|
|
146
|
+
* had. So an unusable entry is DROPPED and an unusable attribute is omitted; nothing
|
|
147
|
+
* here throws. The loud half is {@link assertMenuRenderable}, which runs against a
|
|
148
|
+
* SURFACE and can therefore say something true about what will not be drawn.
|
|
149
|
+
*
|
|
150
|
+
* A link wins over the attributes beside it: `{ label: 'More', submenu: [...] }` is a
|
|
151
|
+
* submenu with a label, never an item that happens to carry a list, because that is how
|
|
152
|
+
* `g_menu_item_get_link` reads the same object.
|
|
153
|
+
*/
|
|
154
|
+
export declare function normalizeMenuModel(input: AdwMenuInput | null | undefined): AdwMenuModel;
|
|
155
|
+
/**
|
|
156
|
+
* A `menu` ATTRIBUTE — a JSON array — as a model.
|
|
157
|
+
*
|
|
158
|
+
* Total for the same reason {@link normalizeMenuModel} is, and it adds the one failure
|
|
159
|
+
* markup can produce that a JS value cannot: `JSON.parse` genuinely throws on a typo,
|
|
160
|
+
* and the widget must degrade to "no menu" rather than fail to upgrade.
|
|
161
|
+
*/
|
|
162
|
+
export declare function parseMenuModel(json: string | null | undefined): AdwMenuModel;
|
|
163
|
+
/**
|
|
164
|
+
* Where a node sits: the index chain from the model's root.
|
|
165
|
+
*
|
|
166
|
+
* A `GMenuModel` addresses its items BY POSITION and a link is a model of its own, so a
|
|
167
|
+
* position inside a submenu is only meaningful together with the positions above it.
|
|
168
|
+
* Resolving a choice by LABEL instead silently dispatches the first of two identically
|
|
169
|
+
* named entries — the defect the split button's activation vectors already pin down, one
|
|
170
|
+
* level deeper now that a menu can nest.
|
|
171
|
+
*/
|
|
172
|
+
export type AdwMenuPath = readonly number[];
|
|
173
|
+
/** The node at a path, or `null` when the path names none. */
|
|
174
|
+
export declare function menuNodeAt(model: AdwMenuModel, path: AdwMenuPath): AdwMenuNode | null;
|
|
175
|
+
/** The item at a path — `null` for a path that names a section, a submenu or nothing. */
|
|
176
|
+
export declare function menuItemAt(model: AdwMenuModel, path: AdwMenuPath): AdwMenuItem | null;
|
|
177
|
+
/** One row of a {@link flattenMenu} walk. */
|
|
178
|
+
export interface AdwMenuFlatRow {
|
|
179
|
+
/** The node this row draws. Sections never appear — they become {@link separated}. */
|
|
180
|
+
readonly node: AdwMenuItem | AdwMenuSubmenu;
|
|
181
|
+
/**
|
|
182
|
+
* Where it lives, for {@link menuItemAt}.
|
|
183
|
+
*
|
|
184
|
+
* It is also the depth: `path.length` counts the links walked to reach the row.
|
|
185
|
+
* There is no separate `depth` field, because nothing would indent by it — GTK
|
|
186
|
+
* draws a section flush with its neighbours — and a field only its own vectors read
|
|
187
|
+
* is a claim nothing holds.
|
|
188
|
+
*/
|
|
189
|
+
readonly path: AdwMenuPath;
|
|
190
|
+
/** Whether a separator belongs above this row — a section boundary. */
|
|
191
|
+
readonly separated: boolean;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* ONE LEVEL of a model as the ordered rows a list draws.
|
|
195
|
+
*
|
|
196
|
+
* SECTIONS ARE INLINED, SUBMENUS ARE NOT, and that asymmetry is `GMenuModel`'s own: a
|
|
197
|
+
* section is a visual grouping that `GtkPopoverMenu` itself draws inline with a
|
|
198
|
+
* separator, so inlining it loses a rule and no item; a submenu is a menu the user
|
|
199
|
+
* OPENS, so inlining it would put its items where they were never offered. A submenu
|
|
200
|
+
* row therefore stays a row, and a surface shows its contents by flattening THAT node's
|
|
201
|
+
* `items` when the user asks — a second popover page on the web, a second sheet on
|
|
202
|
+
* NativeScript. {@link AdwMenuFlatRow.path} is what makes the second call addressable.
|
|
203
|
+
*
|
|
204
|
+
* `separated` marks the FIRST row after a boundary and is never set on the first row of
|
|
205
|
+
* all, because a separator above nothing is a line at the top of the menu.
|
|
206
|
+
*/
|
|
207
|
+
export declare function flattenMenu(model: AdwMenuModel, path?: AdwMenuPath): readonly AdwMenuFlatRow[];
|
|
208
|
+
/** What a `GActionGroup` publishes about one action, in portable form. */
|
|
209
|
+
export interface AdwMenuAction {
|
|
210
|
+
/** `g_action_group_get_action_enabled`. Absent counts as enabled. */
|
|
211
|
+
readonly enabled?: boolean;
|
|
212
|
+
/**
|
|
213
|
+
* `g_action_group_get_action_state`, as its CONTENT in text: `true`/`false` for a
|
|
214
|
+
* toggle, `list` for a radio whose targets are strings.
|
|
215
|
+
*
|
|
216
|
+
* NOT the `GVariant` TEXT form, which would quote the string —
|
|
217
|
+
* `GLib.Variant.new_string('list').print(false)` is `'list'`, with the quotes. A
|
|
218
|
+
* consumer bridging a real `GActionGroup` writes `state.get_string()[0]` for a
|
|
219
|
+
* string and `String(state.get_boolean())` for a boolean; reading `print(false)`
|
|
220
|
+
* instead is what makes every radio row render OFF, because the target it is
|
|
221
|
+
* compared against ({@link AdwDetailedAction.target}) is unquoted too.
|
|
222
|
+
*/
|
|
223
|
+
readonly state?: string;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* The actions a surface knows about — the portable stand-in for a `GActionGroup`.
|
|
227
|
+
*
|
|
228
|
+
* Keyed by the action's own name, prefix included (`app.save-as`), which is the key a
|
|
229
|
+
* detailed action name yields. An action ABSENT from the map is missing, not disabled,
|
|
230
|
+
* and the two differ: `hidden-when="action-missing"` hides one and shows the other.
|
|
231
|
+
*
|
|
232
|
+
* NO MAP AT ALL IS A THIRD THING, and the distinction is load-bearing rather than
|
|
233
|
+
* pedantic: `{}` is a group that knows no actions, so every item in it is insensitive;
|
|
234
|
+
* `undefined` is a surface with no action group to consult, so nothing is known and
|
|
235
|
+
* nothing is dimmed. MEASURED — collapsing the two made every actioned item in the
|
|
236
|
+
* browser renderer arrive `disabled`, because the common case is a menu whose actions
|
|
237
|
+
* the host dispatches itself and never declares.
|
|
238
|
+
*/
|
|
239
|
+
export type AdwMenuActions = Readonly<Record<string, AdwMenuAction>>;
|
|
240
|
+
/** `GtkMenuTrackerItemRole`. */
|
|
241
|
+
export type AdwMenuItemRole = 'normal' | 'check' | 'radio';
|
|
242
|
+
/** What an item's action makes of it. */
|
|
243
|
+
export interface AdwMenuItemState {
|
|
244
|
+
/** `GTK_STATE_FLAG_INSENSITIVE`'s inverse — the action's `enabled`. */
|
|
245
|
+
readonly sensitive: boolean;
|
|
246
|
+
/** Whether the check/radio decoration is drawn. */
|
|
247
|
+
readonly toggled: boolean;
|
|
248
|
+
readonly role: AdwMenuItemRole;
|
|
249
|
+
/** Whether the item is drawn at all — `hidden-when`, folded. */
|
|
250
|
+
readonly visible: boolean;
|
|
251
|
+
}
|
|
252
|
+
/** An action name and the target text beside it. */
|
|
253
|
+
export interface AdwDetailedAction {
|
|
254
|
+
readonly name: string;
|
|
255
|
+
/**
|
|
256
|
+
* The target's CONTENT — `list` for `app.view::list` AND for `app.view('list')`,
|
|
257
|
+
* `2` for `win.zoom(2)`.
|
|
258
|
+
*
|
|
259
|
+
* Never the `GVariant` TEXT, which would quote a string: the two spellings of the
|
|
260
|
+
* same target must compare equal, or a radio written one way and an action state
|
|
261
|
+
* read the other way disagree. MEASURED: without the unquoting,
|
|
262
|
+
* `parseDetailedAction("app.v('list')")` answered `'list'` WITH quotes and every
|
|
263
|
+
* such radio row rendered OFF against a state of `list`.
|
|
264
|
+
*/
|
|
265
|
+
readonly target?: string;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* `app.view::list` → `{ name: 'app.view', target: 'list' }`.
|
|
269
|
+
*
|
|
270
|
+
* The two forms `g_action_parse_detailed_name` accepts, and no third: `::` for a string
|
|
271
|
+
* target and `(…)` for a `GVariant` text one. A quoted `(…)` target is UNQUOTED, so
|
|
272
|
+
* `app.v::list` and `app.v('list')` — the same detailed action to GLib — yield the same
|
|
273
|
+
* target here; without that they did not, and every radio written the second way read
|
|
274
|
+
* OFF.
|
|
275
|
+
*
|
|
276
|
+
* WHAT THIS DELIBERATELY DOES NOT DO is parse the `GVariant`. The target is the text
|
|
277
|
+
* between the delimiters with its quotes removed, so comparing it against an action's
|
|
278
|
+
* `state` is a STRING comparison. That is exact for the string and boolean targets a
|
|
279
|
+
* menu actually uses, and it does not canonicalise WHITESPACE: `win.zoom(2)` and
|
|
280
|
+
* `win.zoom( 2 )` name the same action to GLib and different targets here. A portable
|
|
281
|
+
* model with no `GVariant` implementation cannot close that, and pretending otherwise
|
|
282
|
+
* would be a wrong answer instead of a stated one.
|
|
283
|
+
*
|
|
284
|
+
* IT IS ALSO NOT A VALIDATOR. It never throws and answers something for every string,
|
|
285
|
+
* because it runs on the display side of a menu that has already been accepted. GIO is
|
|
286
|
+
* the authority on whether a detailed action name is legal, and `@gjsify/gtk-host`'s
|
|
287
|
+
* `buildGioMenu` asks it — see {@link AdwMenuItem.action}.
|
|
288
|
+
*/
|
|
289
|
+
export declare function parseDetailedAction(detailed: string | undefined): AdwDetailedAction | null;
|
|
290
|
+
/**
|
|
291
|
+
* `sensitive`, `toggled`, `role` and `visible` for one item — `gtk_menu_tracker_item_*`
|
|
292
|
+
* as a pure fold.
|
|
293
|
+
*
|
|
294
|
+
* This is the whole answer to "where does a menu carry enabled and checked", and the
|
|
295
|
+
* answer is that it does not. C reads all three off the ACTION: `sensitive` is the
|
|
296
|
+
* action's `enabled` flag (c:332), `role` is RADIO when the item has a target and the
|
|
297
|
+
* action has a state (c:336-340), CHECK when the state is a boolean and there is no
|
|
298
|
+
* target (c:342-346), and `toggled` compares the two. An item with no `action` attribute
|
|
299
|
+
* at all is SENSITIVE — C sets it explicitly in the else branch
|
|
300
|
+
* (`gtkmenutrackeritem.c:594`) rather than leaving the field false, because a label with
|
|
301
|
+
* no action is not a disabled command.
|
|
302
|
+
*
|
|
303
|
+
* TWO PLACES THIS IS NOT C, both because a portable action map carries no `GVariantType`:
|
|
304
|
+
*
|
|
305
|
+
* · `can_activate`'s TYPE check. C refuses to activate an item whose target type does
|
|
306
|
+
* not match the action's parameter type, and that refusal feeds
|
|
307
|
+
* `hidden-when="action-missing"`. Here "missing" means only that the action is
|
|
308
|
+
* absent from {@link AdwMenuActions} — a present action with a mistyped target reads
|
|
309
|
+
* as activatable where GTK would hide it.
|
|
310
|
+
* · A boolean state is the TEXT `'true'`/`'false'`, since the state is text. A radio
|
|
311
|
+
* whose targets are literally those two strings would therefore read as a check.
|
|
312
|
+
* GTK tells them apart by `GVariant` type; nothing here can.
|
|
313
|
+
*
|
|
314
|
+
* `macos-menubar` hides an item only in the macOS menubar export (C guards it with
|
|
315
|
+
* `mac_os_mode`, c:534-535), which no renderer here is, so it stays visible.
|
|
316
|
+
*/
|
|
317
|
+
export declare function resolveMenuItemState(item: AdwMenuItem, actions?: AdwMenuActions): AdwMenuItemState;
|
|
318
|
+
/**
|
|
319
|
+
* What a surface can draw.
|
|
320
|
+
*
|
|
321
|
+
* ONE CAPABILITY, because one is what actually differs in a way a reader could not
|
|
322
|
+
* otherwise see. All three surfaces nest (GTK slides a page, the browser swaps the
|
|
323
|
+
* popover's page, NativeScript opens a second sheet) and all three draw every
|
|
324
|
+
* attribute they have a place for, so a field for those would be `true` everywhere and
|
|
325
|
+
* a refusal arm nothing could ever reach — the shape this repository pays most for. A
|
|
326
|
+
* second field lands with the first surface that needs it.
|
|
327
|
+
*/
|
|
328
|
+
export interface AdwMenuSurface {
|
|
329
|
+
/** A name for the diagnostic — `adwaita-web`, `nativescript`. */
|
|
330
|
+
readonly name: string;
|
|
331
|
+
/** Can it host an application widget named by `custom`? Only GTK can. */
|
|
332
|
+
readonly custom: boolean;
|
|
333
|
+
}
|
|
334
|
+
/** The browser popover: it has no `add_child` for a `custom` item to name. */
|
|
335
|
+
export declare const ADW_MENU_SURFACE_WEB: AdwMenuSurface;
|
|
336
|
+
/** The NativeScript action sheet: its rows are STRINGS, so a `custom` widget has no home. */
|
|
337
|
+
export declare const ADW_MENU_SURFACE_NATIVESCRIPT: AdwMenuSurface;
|
|
338
|
+
/** One thing a surface will not draw, with where it is. */
|
|
339
|
+
export interface AdwMenuRefusal {
|
|
340
|
+
readonly path: AdwMenuPath;
|
|
341
|
+
/** The attribute that cannot be honoured. */
|
|
342
|
+
readonly what: 'custom';
|
|
343
|
+
readonly message: string;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Every part of a model the surface cannot render — empty when it can render all of it.
|
|
347
|
+
*
|
|
348
|
+
* IT LISTS WHAT WOULD VANISH, NOT WHAT WOULD LOOK DIFFERENT. An icon a sheet cannot show
|
|
349
|
+
* is a decoration and the row is still there; a `custom` item is a PLACEHOLDER for an
|
|
350
|
+
* application widget, so a surface that ignores it draws a blank row where a control
|
|
351
|
+
* belongs, and the reader has no way to tell. That is the distinction the three-way
|
|
352
|
+
* split in this file's header draws, and it is why refusing everything unsupported
|
|
353
|
+
* would be useless: NativeScript renders no icon and no accelerator on any menu, so a
|
|
354
|
+
* refusal per decoration would fire on every well-formed menu and be switched off.
|
|
355
|
+
*/
|
|
356
|
+
export declare function menuRefusals(model: AdwMenuModel, surface: AdwMenuSurface, path?: AdwMenuPath): AdwMenuRefusal[];
|
|
357
|
+
/**
|
|
358
|
+
* Throw if the surface cannot render the model.
|
|
359
|
+
*
|
|
360
|
+
* Called by a renderer when a menu is SET, so the throw names the assignment rather than
|
|
361
|
+
* arriving as a missing row three interactions later. The message carries every refusal,
|
|
362
|
+
* not the first: a menu written for GTK typically has all of its `custom` items at once,
|
|
363
|
+
* and reporting them one run at a time is how a port becomes a series of identical bug
|
|
364
|
+
* reports.
|
|
365
|
+
*/
|
|
366
|
+
export declare function assertMenuRenderable(model: AdwMenuModel, surface: AdwMenuSurface): void;
|