vira 27.0.0 → 28.0.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/dist/elements/index.d.ts +7 -7
- package/dist/elements/index.js +7 -7
- package/dist/elements/{popover/popover-helpers.d.ts → pop-up/pop-up-helpers.d.ts} +6 -6
- package/dist/elements/{popover/popover-helpers.js → pop-up/pop-up-helpers.js} +5 -5
- package/dist/elements/{popover → pop-up}/vira-menu-item.element.d.ts +2 -2
- package/dist/elements/{popover → pop-up}/vira-menu-item.element.js +1 -1
- package/dist/elements/pop-up/vira-menu-trigger.element.d.ts +55 -0
- package/dist/elements/{popover → pop-up}/vira-menu-trigger.element.js +33 -29
- package/dist/elements/{popover → pop-up}/vira-menu.element.d.ts +2 -2
- package/dist/elements/{popover → pop-up}/vira-menu.element.js +2 -2
- package/dist/elements/pop-up/vira-pop-up-menu.element.d.ts +35 -0
- package/dist/elements/{popover/vira-popover-menu.element.js → pop-up/vira-pop-up-menu.element.js} +23 -23
- package/dist/elements/pop-up/vira-pop-up-trigger.element.d.ts +81 -0
- package/dist/elements/pop-up/vira-pop-up-trigger.element.js +282 -0
- package/dist/elements/vira-dropdown.element.d.ts +18 -6
- package/dist/elements/vira-dropdown.element.js +10 -8
- package/dist/util/index.d.ts +1 -1
- package/dist/util/index.js +1 -1
- package/dist/util/{popover-manager.d.ts → pop-up-manager.d.ts} +39 -60
- package/dist/util/{popover-manager.js → pop-up-manager.js} +45 -42
- package/package.json +1 -1
- package/dist/elements/popover/vira-menu-trigger.element.d.ts +0 -41
- package/dist/elements/popover/vira-popover-menu.element.d.ts +0 -35
- package/dist/elements/popover/vira-popover-trigger.element.d.ts +0 -67
- package/dist/elements/popover/vira-popover-trigger.element.js +0 -301
- /package/dist/elements/{popover/popover-menu-item.d.ts → pop-up/pop-up-menu-item.d.ts} +0 -0
- /package/dist/elements/{popover/popover-menu-item.js → pop-up/pop-up-menu-item.js} +0 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { assert } from '@augment-vir/assert';
|
|
2
|
+
import { NavController } from 'device-navigation';
|
|
3
|
+
import { classMap, css, defineElementEvent, html, listen, renderIf } from 'element-vir';
|
|
4
|
+
import { createFocusStyles } from '../../styles/focus.js';
|
|
5
|
+
import { noNativeFormStyles, noUserSelect, viraDisabledStyles } from '../../styles/index.js';
|
|
6
|
+
import { HidePopUpEvent, NavSelectEvent, PopUpManager, } from '../../util/pop-up-manager.js';
|
|
7
|
+
import { defineViraElement } from '../define-vira-element.js';
|
|
8
|
+
import { triggerPopUpState } from './pop-up-helpers.js';
|
|
9
|
+
/**
|
|
10
|
+
* Anchor options for pop-ups.
|
|
11
|
+
*
|
|
12
|
+
* @category Internal
|
|
13
|
+
*/
|
|
14
|
+
export var HorizontalAnchor;
|
|
15
|
+
(function (HorizontalAnchor) {
|
|
16
|
+
/**
|
|
17
|
+
* The left side of the pop-up will be anchored to the left side of the trigger, allowing the
|
|
18
|
+
* pop-up to grow on the right side of the trigger.
|
|
19
|
+
*/
|
|
20
|
+
HorizontalAnchor["Left"] = "left";
|
|
21
|
+
/**
|
|
22
|
+
* The Right side of the pop-up will be anchored to the right side of the trigger, allowing the
|
|
23
|
+
* pop-up to grow on the left side of the trigger.
|
|
24
|
+
*/
|
|
25
|
+
HorizontalAnchor["Right"] = "right";
|
|
26
|
+
/**
|
|
27
|
+
* Restrict the pop-up on both sides.
|
|
28
|
+
*
|
|
29
|
+
* This is the default anchor for {@link ViraPopUpTrigger}.
|
|
30
|
+
*/
|
|
31
|
+
HorizontalAnchor["Both"] = "both";
|
|
32
|
+
})(HorizontalAnchor || (HorizontalAnchor = {}));
|
|
33
|
+
/**
|
|
34
|
+
* An element with slots for a pop-up trigger and pop-up contents.
|
|
35
|
+
*
|
|
36
|
+
* @category PopUp
|
|
37
|
+
* @category Elements
|
|
38
|
+
* @see https://electrovir.github.io/vira/book/elements/vira-pop-up-trigger
|
|
39
|
+
*/
|
|
40
|
+
export const ViraPopUpTrigger = defineViraElement()({
|
|
41
|
+
tagName: 'vira-pop-up-trigger',
|
|
42
|
+
state({ host }) {
|
|
43
|
+
return {
|
|
44
|
+
/** `undefined` means the pop up is not currently showing. */
|
|
45
|
+
showPopUpResult: undefined,
|
|
46
|
+
popUpManager: new PopUpManager(new NavController(host, { activateOnMouseUp: true })),
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
slotNames: [
|
|
50
|
+
'trigger',
|
|
51
|
+
'popUp',
|
|
52
|
+
],
|
|
53
|
+
hostClasses: {
|
|
54
|
+
'vira-pop-up-trigger-disabled': ({ inputs }) => !!inputs.isDisabled,
|
|
55
|
+
},
|
|
56
|
+
styles: ({ hostClasses }) => css `
|
|
57
|
+
:host {
|
|
58
|
+
display: inline-flex;
|
|
59
|
+
box-sizing: border-box;
|
|
60
|
+
vertical-align: middle;
|
|
61
|
+
position: relative;
|
|
62
|
+
max-width: 100%;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.dropdown-wrapper {
|
|
66
|
+
${noNativeFormStyles};
|
|
67
|
+
cursor: pointer;
|
|
68
|
+
max-width: 100%;
|
|
69
|
+
position: relative;
|
|
70
|
+
flex-grow: 1;
|
|
71
|
+
box-sizing: border-box;
|
|
72
|
+
|
|
73
|
+
${createFocusStyles({
|
|
74
|
+
elementBorderSize: 1,
|
|
75
|
+
})}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.dropdown-trigger {
|
|
79
|
+
box-sizing: border-box;
|
|
80
|
+
${noUserSelect};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
${hostClasses['vira-pop-up-trigger-disabled'].selector} {
|
|
84
|
+
${viraDisabledStyles}
|
|
85
|
+
pointer-events: auto;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
${hostClasses['vira-pop-up-trigger-disabled'].selector} .dropdown-wrapper {
|
|
89
|
+
pointer-events: none;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.pop-up-positioner {
|
|
93
|
+
position: absolute;
|
|
94
|
+
pointer-events: none;
|
|
95
|
+
display: flex;
|
|
96
|
+
box-sizing: border-box;
|
|
97
|
+
flex-direction: column;
|
|
98
|
+
align-items: flex-start;
|
|
99
|
+
|
|
100
|
+
/* highest possible z-index */
|
|
101
|
+
z-index: 2147483647;
|
|
102
|
+
|
|
103
|
+
& > * {
|
|
104
|
+
pointer-events: auto;
|
|
105
|
+
max-width: 100%;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
&.right-aligned {
|
|
109
|
+
align-items: flex-end;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.open-upwards .pop-up-positioner {
|
|
114
|
+
flex-direction: column-reverse;
|
|
115
|
+
}
|
|
116
|
+
`,
|
|
117
|
+
events: {
|
|
118
|
+
navSelect: defineElementEvent(),
|
|
119
|
+
/**
|
|
120
|
+
* - `undefined` indicates that the pop-up just closed.
|
|
121
|
+
* - {@link ShowPopUpResult} indicates that the pop-up just opened.
|
|
122
|
+
*/
|
|
123
|
+
openChange: defineElementEvent(),
|
|
124
|
+
init: defineElementEvent(),
|
|
125
|
+
},
|
|
126
|
+
cleanup({ state, updateState }) {
|
|
127
|
+
updateState({ showPopUpResult: undefined });
|
|
128
|
+
state.popUpManager.destroy();
|
|
129
|
+
},
|
|
130
|
+
init({ state, updateState, host, inputs, dispatch, events }) {
|
|
131
|
+
/** Refocus the trigger and set the result to `undefined` when the pop up closes. */
|
|
132
|
+
state.popUpManager.listen(HidePopUpEvent, () => {
|
|
133
|
+
updateState({ showPopUpResult: undefined });
|
|
134
|
+
dispatch(new events.openChange(undefined));
|
|
135
|
+
if (!inputs.isDisabled) {
|
|
136
|
+
const dropdownWrapper = host.shadowRoot.querySelector('.dropdown-wrapper');
|
|
137
|
+
assert.instanceOf(dropdownWrapper, HTMLButtonElement, 'failed to find dropdown wrapper child');
|
|
138
|
+
dropdownWrapper.focus();
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
state.popUpManager.listen(NavSelectEvent, (event) => {
|
|
142
|
+
if (!inputs.keepOpenAfterInteraction) {
|
|
143
|
+
triggerPopUpState({
|
|
144
|
+
open: false,
|
|
145
|
+
callback(showPopUpResult) {
|
|
146
|
+
updateState({
|
|
147
|
+
showPopUpResult,
|
|
148
|
+
});
|
|
149
|
+
},
|
|
150
|
+
host,
|
|
151
|
+
popUpManager: state.popUpManager,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
dispatch(new events.navSelect(event.detail));
|
|
155
|
+
});
|
|
156
|
+
dispatch(new events.init({
|
|
157
|
+
navController: state.popUpManager.navController,
|
|
158
|
+
popUpManager: state.popUpManager,
|
|
159
|
+
}));
|
|
160
|
+
},
|
|
161
|
+
render({ dispatch, events, state, inputs, updateState, host, slotNames }) {
|
|
162
|
+
function triggerPopUp({ emitEvent, open }, event) {
|
|
163
|
+
if (state.showPopUpResult && inputs.keepOpenAfterInteraction && event) {
|
|
164
|
+
const dropdownTrigger = host.shadowRoot.querySelector('.dropdown-trigger');
|
|
165
|
+
if (dropdownTrigger && !event.composedPath().includes(dropdownTrigger)) {
|
|
166
|
+
/**
|
|
167
|
+
* Prevent closing the pop-up when `keepOpenAfterInteraction` is turned on and
|
|
168
|
+
* the pop-up was interacted with.
|
|
169
|
+
*/
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
triggerPopUpState({
|
|
174
|
+
open,
|
|
175
|
+
callback(showPopUpResult) {
|
|
176
|
+
updateState({ showPopUpResult });
|
|
177
|
+
if (emitEvent) {
|
|
178
|
+
dispatch(new events.openChange(showPopUpResult));
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
host,
|
|
182
|
+
popUpManager: state.popUpManager,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
if (inputs.isDisabled) {
|
|
186
|
+
triggerPopUp({ open: false, emitEvent: false }, undefined);
|
|
187
|
+
}
|
|
188
|
+
else if (inputs.z_debug_forceOpenState != undefined) {
|
|
189
|
+
if (!inputs.z_debug_forceOpenState && state.showPopUpResult) {
|
|
190
|
+
triggerPopUp({ emitEvent: false, open: false }, undefined);
|
|
191
|
+
}
|
|
192
|
+
else if (inputs.z_debug_forceOpenState && !state.showPopUpResult) {
|
|
193
|
+
triggerPopUp({ emitEvent: false, open: true }, undefined);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const leftCss = inputs.horizontalAnchor === HorizontalAnchor.Right && state.showPopUpResult
|
|
197
|
+
? css `
|
|
198
|
+
left: -${state.showPopUpResult.positions.diff.left}px;
|
|
199
|
+
`
|
|
200
|
+
: css `
|
|
201
|
+
left: ${inputs.popUpOffset?.left || 0}px;
|
|
202
|
+
`;
|
|
203
|
+
const rightCss = state.showPopUpResult && inputs.horizontalAnchor === HorizontalAnchor.Left
|
|
204
|
+
? css `
|
|
205
|
+
right: -${state.showPopUpResult.positions.diff.right}px;
|
|
206
|
+
`
|
|
207
|
+
: css `
|
|
208
|
+
right: ${inputs.popUpOffset?.right || 0}px;
|
|
209
|
+
`;
|
|
210
|
+
const horizontalPositionStyle = css `
|
|
211
|
+
${leftCss}
|
|
212
|
+
${rightCss}
|
|
213
|
+
`;
|
|
214
|
+
/**
|
|
215
|
+
* These styles do _not_ account for window resizing while the menu is open. I decided this
|
|
216
|
+
* was not a major enough problem to tackle. If it becomes major enough in the future,
|
|
217
|
+
* you'll need to hook into a window _or_ container resize listener inside `PopUpManager`
|
|
218
|
+
* and emit a new `ShowPopUpResult` instance when it changes.
|
|
219
|
+
*/
|
|
220
|
+
const positionerStyles = state.showPopUpResult
|
|
221
|
+
? state.showPopUpResult.popDown
|
|
222
|
+
? /** Dropdown going down position. */
|
|
223
|
+
css `
|
|
224
|
+
bottom: -${state.showPopUpResult.positions.diff.bottom}px;
|
|
225
|
+
top: calc(100% + ${inputs.popUpOffset?.vertical || 0}px);
|
|
226
|
+
${horizontalPositionStyle}
|
|
227
|
+
`
|
|
228
|
+
: /** Dropdown going up position. */
|
|
229
|
+
css `
|
|
230
|
+
top: -${state.showPopUpResult.positions.diff.top}px;
|
|
231
|
+
bottom: calc(100% + ${inputs.popUpOffset?.vertical || 0}px);
|
|
232
|
+
${horizontalPositionStyle}
|
|
233
|
+
`
|
|
234
|
+
: undefined;
|
|
235
|
+
function respondToClick(event) {
|
|
236
|
+
triggerPopUp({ emitEvent: true, open: !state.showPopUpResult }, event);
|
|
237
|
+
}
|
|
238
|
+
return html `
|
|
239
|
+
<button
|
|
240
|
+
?disabled=${!!inputs.isDisabled}
|
|
241
|
+
class="dropdown-wrapper ${classMap({
|
|
242
|
+
open: !!state.showPopUpResult,
|
|
243
|
+
'open-upwards': !state.showPopUpResult?.popDown,
|
|
244
|
+
})}"
|
|
245
|
+
role="listbox"
|
|
246
|
+
aria-expanded=${!!state.showPopUpResult}
|
|
247
|
+
${listen('keydown', (event) => {
|
|
248
|
+
if (!state.showPopUpResult && event.code.startsWith('Arrow')) {
|
|
249
|
+
triggerPopUp({ emitEvent: true, open: true }, event);
|
|
250
|
+
}
|
|
251
|
+
})}
|
|
252
|
+
${listen('click', (event) => {
|
|
253
|
+
/** Detail is 0 if it was a keyboard key (like Enter) that triggered this click. */
|
|
254
|
+
if (event.detail === 0) {
|
|
255
|
+
respondToClick(event);
|
|
256
|
+
}
|
|
257
|
+
})}
|
|
258
|
+
${listen('mousedown', (event) => {
|
|
259
|
+
/** Ignore any clicks that aren't the main button. */
|
|
260
|
+
if (event.button === 0) {
|
|
261
|
+
respondToClick(event);
|
|
262
|
+
}
|
|
263
|
+
})}
|
|
264
|
+
>
|
|
265
|
+
<div class="dropdown-trigger">
|
|
266
|
+
<slot name=${slotNames.trigger}></slot>
|
|
267
|
+
</div>
|
|
268
|
+
|
|
269
|
+
<div
|
|
270
|
+
class="pop-up-positioner ${classMap({
|
|
271
|
+
'right-aligned': inputs.horizontalAnchor === HorizontalAnchor.Right,
|
|
272
|
+
})}"
|
|
273
|
+
style=${positionerStyles}
|
|
274
|
+
>
|
|
275
|
+
${renderIf(!!state.showPopUpResult, html `
|
|
276
|
+
<slot name=${slotNames.popUp}></slot>
|
|
277
|
+
`)}
|
|
278
|
+
</div>
|
|
279
|
+
</button>
|
|
280
|
+
`;
|
|
281
|
+
},
|
|
282
|
+
});
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type PartialWithUndefined } from '@augment-vir/common';
|
|
2
2
|
import { type ViraIconSvg } from '../icons/icon-svg.js';
|
|
3
|
-
import { type
|
|
4
|
-
import { type MenuItem } from './
|
|
3
|
+
import { type ShowPopUpResult } from '../util/pop-up-manager.js';
|
|
4
|
+
import { type MenuItem } from './pop-up/pop-up-menu-item.js';
|
|
5
|
+
import { HorizontalAnchor } from './pop-up/vira-pop-up-trigger.element.js';
|
|
5
6
|
/**
|
|
6
7
|
* Test ids for {@link ViraDropdown}.
|
|
7
8
|
*
|
|
@@ -13,7 +14,7 @@ export declare const viraDropdownTestIds: {
|
|
|
13
14
|
prefix: string;
|
|
14
15
|
};
|
|
15
16
|
/**
|
|
16
|
-
* A dropdown element that uses
|
|
17
|
+
* A dropdown element that uses pop-up menus.
|
|
17
18
|
*
|
|
18
19
|
* @category Dropdown
|
|
19
20
|
* @category Elements
|
|
@@ -36,10 +37,21 @@ export declare const ViraDropdown: import("element-vir").DeclarativeElementDefin
|
|
|
36
37
|
isDisabled: boolean;
|
|
37
38
|
/** For debugging purposes only. Very bad for actual production code use. */
|
|
38
39
|
z_debug_forceOpenState: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* - `HorizontalAnchor.Left`: dropdown is anchored to the left side of the trigger and the
|
|
42
|
+
* dropdown can grow to the right.
|
|
43
|
+
* - `HorizontalAnchor.Right`: dropdown is anchored to the right side of the trigger and the
|
|
44
|
+
* dropdown can grow to the left.
|
|
45
|
+
* - `HorizontalAnchor.Both`: dropdown is anchored on both sides of the trigger and cannot
|
|
46
|
+
* grow beyond it. (This is the default experience.)
|
|
47
|
+
*
|
|
48
|
+
* @default HorizontalAnchor.Both
|
|
49
|
+
*/
|
|
50
|
+
horizontalAnchor: HorizontalAnchor;
|
|
39
51
|
}>, {
|
|
40
|
-
/** `undefined` means the
|
|
41
|
-
|
|
52
|
+
/** `undefined` means the pop up is not currently showing. */
|
|
53
|
+
showPopUpResult: ShowPopUpResult | undefined;
|
|
42
54
|
}, {
|
|
43
55
|
selectedChange: import("element-vir").DefineEvent<PropertyKey[]>;
|
|
44
|
-
openChange: import("element-vir").DefineEvent<
|
|
56
|
+
openChange: import("element-vir").DefineEvent<ShowPopUpResult | undefined>;
|
|
45
57
|
}, "vira-dropdown-", "vira-dropdown-", readonly [], readonly []>;
|
|
@@ -6,7 +6,8 @@ import { viraBorders } from '../styles/border.js';
|
|
|
6
6
|
import { viraFormCssVars } from '../styles/form-styles.js';
|
|
7
7
|
import { noUserSelect, viraAnimationDurations } from '../styles/index.js';
|
|
8
8
|
import { defineViraElement } from './define-vira-element.js';
|
|
9
|
-
import { ViraMenuTrigger } from './
|
|
9
|
+
import { ViraMenuTrigger } from './pop-up/vira-menu-trigger.element.js';
|
|
10
|
+
import { HorizontalAnchor } from './pop-up/vira-pop-up-trigger.element.js';
|
|
10
11
|
import { ViraIcon } from './vira-icon.element.js';
|
|
11
12
|
/**
|
|
12
13
|
* Test ids for {@link ViraDropdown}.
|
|
@@ -19,7 +20,7 @@ export const viraDropdownTestIds = {
|
|
|
19
20
|
prefix: 'dropdown-prefix',
|
|
20
21
|
};
|
|
21
22
|
/**
|
|
22
|
-
* A dropdown element that uses
|
|
23
|
+
* A dropdown element that uses pop-up menus.
|
|
23
24
|
*
|
|
24
25
|
* @category Dropdown
|
|
25
26
|
* @category Elements
|
|
@@ -101,8 +102,8 @@ export const ViraDropdown = defineViraElement()({
|
|
|
101
102
|
},
|
|
102
103
|
state() {
|
|
103
104
|
return {
|
|
104
|
-
/** `undefined` means the
|
|
105
|
-
|
|
105
|
+
/** `undefined` means the pop up is not currently showing. */
|
|
106
|
+
showPopUpResult: undefined,
|
|
106
107
|
};
|
|
107
108
|
},
|
|
108
109
|
render({ state, inputs, dispatch, events, updateState }) {
|
|
@@ -136,13 +137,14 @@ export const ViraDropdown = defineViraElement()({
|
|
|
136
137
|
isDisabled: inputs.isDisabled,
|
|
137
138
|
isMultiSelect: inputs.isMultiSelect,
|
|
138
139
|
z_debug_forceOpenState: inputs.z_debug_forceOpenState,
|
|
139
|
-
|
|
140
|
+
popUpOffset: {
|
|
140
141
|
vertical: -1,
|
|
141
142
|
right: 24,
|
|
142
143
|
},
|
|
144
|
+
horizontalAnchor: inputs.horizontalAnchor || HorizontalAnchor.Both,
|
|
143
145
|
})}
|
|
144
146
|
${listen(ViraMenuTrigger.events.openChange, (event) => {
|
|
145
|
-
updateState({
|
|
147
|
+
updateState({ showPopUpResult: event.detail });
|
|
146
148
|
dispatch(new events.openChange(event.detail));
|
|
147
149
|
})}
|
|
148
150
|
${listen(ViraMenuTrigger.events.itemActivate, (event) => {
|
|
@@ -151,8 +153,8 @@ export const ViraDropdown = defineViraElement()({
|
|
|
151
153
|
>
|
|
152
154
|
<div
|
|
153
155
|
class="dropdown-trigger ${classMap({
|
|
154
|
-
open: !!state.
|
|
155
|
-
'open-upwards': !state.
|
|
156
|
+
open: !!state.showPopUpResult,
|
|
157
|
+
'open-upwards': !state.showPopUpResult?.popDown,
|
|
156
158
|
})}"
|
|
157
159
|
${testId(viraDropdownTestIds.trigger)}
|
|
158
160
|
>
|
package/dist/util/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './define-table.js';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './pop-up-manager.js';
|
package/dist/util/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './define-table.js';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './pop-up-manager.js';
|
|
@@ -12,17 +12,6 @@ export type PositionRect = {
|
|
|
12
12
|
right: number;
|
|
13
13
|
bottom: number;
|
|
14
14
|
};
|
|
15
|
-
/**
|
|
16
|
-
* Used to represent the diff between the root element and the viewport.
|
|
17
|
-
*
|
|
18
|
-
* @category Internal
|
|
19
|
-
*/
|
|
20
|
-
export type DiffRect = PositionRect & {
|
|
21
|
-
rootLeftToContainerRight: number;
|
|
22
|
-
rootRightToContainerLeft: number;
|
|
23
|
-
rootTopToContainerBottom: number;
|
|
24
|
-
rootBottomToContainerTop: number;
|
|
25
|
-
};
|
|
26
15
|
/**
|
|
27
16
|
* The default empty {@link PositionRect}, with all values set to 0.
|
|
28
17
|
*
|
|
@@ -30,15 +19,15 @@ export type DiffRect = PositionRect & {
|
|
|
30
19
|
*/
|
|
31
20
|
export declare const emptyPositionRect: PositionRect;
|
|
32
21
|
/**
|
|
33
|
-
* Options for {@link
|
|
22
|
+
* Options for {@link PopUpManager}.
|
|
34
23
|
*
|
|
35
|
-
* @category
|
|
24
|
+
* @category PopUp
|
|
36
25
|
*/
|
|
37
|
-
export type
|
|
26
|
+
export type PopUpManagerOptions = {
|
|
38
27
|
/**
|
|
39
|
-
* The minimum number of pixels for allowing the
|
|
28
|
+
* The minimum number of pixels for allowing the pop-up to go downwards. If the downward
|
|
40
29
|
* available space is less than this, and if the upwards available space is
|
|
41
|
-
* `verticalDiffThreshold` more than the downwards space, the
|
|
30
|
+
* `verticalDiffThreshold` more than the downwards space, the pop-up will be directed upwards.
|
|
42
31
|
*
|
|
43
32
|
* Equation:
|
|
44
33
|
*
|
|
@@ -48,10 +37,10 @@ export type PopoverManagerOptions = {
|
|
|
48
37
|
*
|
|
49
38
|
* @default 200
|
|
50
39
|
*/
|
|
51
|
-
|
|
40
|
+
minDownSpace: number;
|
|
52
41
|
/**
|
|
53
42
|
* The number of pixels required for the upwards available space to be bigger than the downwards
|
|
54
|
-
* available space before directing the
|
|
43
|
+
* available space before directing the pop-up upwards.
|
|
55
44
|
*
|
|
56
45
|
* Equation:
|
|
57
46
|
*
|
|
@@ -63,50 +52,40 @@ export type PopoverManagerOptions = {
|
|
|
63
52
|
*/
|
|
64
53
|
verticalDiffThreshold: number;
|
|
65
54
|
/**
|
|
66
|
-
* Supports navigation of the
|
|
55
|
+
* Supports navigation of the pop up via the `device-navigation` package.
|
|
67
56
|
*
|
|
68
57
|
* @default true
|
|
69
58
|
*/
|
|
70
59
|
supportNavigation: boolean;
|
|
71
60
|
};
|
|
72
61
|
/**
|
|
73
|
-
* Output type from `
|
|
62
|
+
* Output type from `PopUpManager.showPopUp`
|
|
74
63
|
*
|
|
75
|
-
* @category
|
|
64
|
+
* @category PopUp
|
|
76
65
|
*/
|
|
77
|
-
export type
|
|
66
|
+
export type ShowPopUpResult = {
|
|
78
67
|
/**
|
|
79
|
-
* Indicates if the
|
|
80
|
-
* in the upwards direction. This is determined by how much space is available on either
|
|
81
|
-
*
|
|
68
|
+
* Indicates if the "pop up" should pop in the downwards direction or not. If not, it should pop
|
|
69
|
+
* in the upwards direction. This is determined by how much space is available on either side of
|
|
70
|
+
* the root element.
|
|
82
71
|
*/
|
|
83
72
|
popDown: boolean;
|
|
84
|
-
|
|
85
|
-
* Indicates if the popover should pop in the rightwards direction or not. If not, it should pop
|
|
86
|
-
* in the leftwards position. This is determined by how much space is available on either
|
|
87
|
-
* horizontal side of the root element.
|
|
88
|
-
*/
|
|
89
|
-
popRight: boolean;
|
|
90
|
-
positions: {
|
|
91
|
-
root: PositionRect;
|
|
92
|
-
container: PositionRect;
|
|
93
|
-
diff: DiffRect;
|
|
94
|
-
};
|
|
73
|
+
positions: Record<'root' | 'container' | 'diff', PositionRect>;
|
|
95
74
|
};
|
|
96
|
-
declare const
|
|
75
|
+
declare const HidePopUpEvent_base: (new (eventInitDict?: EventInit) => import("typed-event-target").TypedEvent<"hide-pop-up">) & Pick<{
|
|
97
76
|
new (type: string, eventInitDict?: EventInit): Event;
|
|
98
77
|
prototype: Event;
|
|
99
78
|
readonly NONE: 0;
|
|
100
79
|
readonly CAPTURING_PHASE: 1;
|
|
101
80
|
readonly AT_TARGET: 2;
|
|
102
81
|
readonly BUBBLING_PHASE: 3;
|
|
103
|
-
}, "prototype" | "NONE" | "CAPTURING_PHASE" | "AT_TARGET" | "BUBBLING_PHASE"> & Pick<import("typed-event-target").TypedEvent<"hide-
|
|
82
|
+
}, "prototype" | "NONE" | "CAPTURING_PHASE" | "AT_TARGET" | "BUBBLING_PHASE"> & Pick<import("typed-event-target").TypedEvent<"hide-pop-up">, "type">;
|
|
104
83
|
/**
|
|
105
|
-
* An event fired from {@link
|
|
84
|
+
* An event fired from {@link PopUpManager} when the pop up should be hidden.
|
|
106
85
|
*
|
|
107
|
-
* @category
|
|
86
|
+
* @category PopUp
|
|
108
87
|
*/
|
|
109
|
-
export declare class
|
|
88
|
+
export declare class HidePopUpEvent extends HidePopUpEvent_base {
|
|
110
89
|
}
|
|
111
90
|
declare const NavSelectEvent_base: (new (eventInitDict: {
|
|
112
91
|
bubbles?: boolean;
|
|
@@ -122,44 +101,44 @@ declare const NavSelectEvent_base: (new (eventInitDict: {
|
|
|
122
101
|
readonly BUBBLING_PHASE: 3;
|
|
123
102
|
}, "prototype" | "NONE" | "CAPTURING_PHASE" | "AT_TARGET" | "BUBBLING_PHASE"> & Pick<import("typed-event-target").TypedCustomEvent<Coords, "nav-select">, "type">;
|
|
124
103
|
/**
|
|
125
|
-
* An event fired from {@link
|
|
126
|
-
*
|
|
104
|
+
* An event fired from {@link PopUpManager} when an individual item in the pop up has been selected
|
|
105
|
+
* by the user.
|
|
127
106
|
*
|
|
128
|
-
* @category
|
|
107
|
+
* @category PopUp
|
|
129
108
|
*/
|
|
130
109
|
export declare class NavSelectEvent extends NavSelectEvent_base {
|
|
131
110
|
}
|
|
132
111
|
/**
|
|
133
|
-
* All events that can be emitted by {@link
|
|
112
|
+
* All events that can be emitted by {@link PopUpManager}.
|
|
134
113
|
*
|
|
135
114
|
* @category Internal
|
|
136
115
|
*/
|
|
137
|
-
export type
|
|
116
|
+
export type PopUpManagerEvents = HidePopUpEvent | NavSelectEvent;
|
|
138
117
|
/**
|
|
139
|
-
* A "
|
|
118
|
+
* A "pop up" manager for items that pop up from the HTML page, like dropdowns or menus.
|
|
140
119
|
*
|
|
141
|
-
* @category
|
|
120
|
+
* @category PopUp
|
|
142
121
|
*/
|
|
143
|
-
export declare class
|
|
122
|
+
export declare class PopUpManager {
|
|
144
123
|
readonly navController: NavController;
|
|
145
124
|
private listenTarget;
|
|
146
|
-
options:
|
|
125
|
+
options: PopUpManagerOptions;
|
|
147
126
|
private cleanupCallbacks;
|
|
148
127
|
private lastRootElement;
|
|
149
|
-
constructor(navController: NavController, options?: Partial<
|
|
128
|
+
constructor(navController: NavController, options?: Partial<PopUpManagerOptions> | undefined);
|
|
150
129
|
private attachGlobalListeners;
|
|
151
|
-
/** Listen to events emitted from a {@link
|
|
130
|
+
/** Listen to events emitted from a {@link PopUpManager} instance. */
|
|
152
131
|
listen<const EventDefinition extends Readonly<{
|
|
153
|
-
type: ExtractEventTypes<
|
|
154
|
-
}>>(event: EventDefinition, listener: (event: ExtractEventByType<
|
|
155
|
-
/** Trigger removal or hiding of the
|
|
156
|
-
|
|
157
|
-
/** Trigger showing the
|
|
158
|
-
|
|
132
|
+
type: ExtractEventTypes<PopUpManagerEvents>;
|
|
133
|
+
}>>(event: EventDefinition, listener: (event: ExtractEventByType<PopUpManagerEvents, EventDefinition['type']>) => MaybePromise<void>, options?: ListenOptions | undefined): RemoveListenerCallback;
|
|
134
|
+
/** Trigger removal or hiding of the pop up. */
|
|
135
|
+
removePopUp(): void;
|
|
136
|
+
/** Trigger showing the pop up. */
|
|
137
|
+
showPopUp(rootElement: HTMLElement, options?: Partial<PopUpManagerOptions> | undefined): ShowPopUpResult;
|
|
159
138
|
/**
|
|
160
|
-
* Cleanup and destroy the {@link
|
|
139
|
+
* Cleanup and destroy the {@link PopUpManager} instance. This:
|
|
161
140
|
*
|
|
162
|
-
* - Removes the existing
|
|
141
|
+
* - Removes the existing pop up
|
|
163
142
|
* - Cleans up all internal and external listeners
|
|
164
143
|
*/
|
|
165
144
|
destroy(): void;
|