vira 28.19.6 → 28.20.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/define-vira-element.d.ts +18 -0
- package/dist/elements/define-vira-element.js +19 -0
- package/dist/elements/form/vira-form-fields.d.ts +100 -0
- package/dist/elements/form/vira-form-fields.js +60 -0
- package/dist/elements/form/vira-form.element.d.ts +35 -0
- package/dist/elements/form/vira-form.element.js +151 -0
- package/dist/elements/index.js +25 -0
- package/dist/elements/pop-up/pop-up-helpers.d.ts +33 -0
- package/dist/elements/pop-up/pop-up-helpers.js +58 -0
- package/{src/elements/pop-up/pop-up-menu-item.ts → dist/elements/pop-up/pop-up-menu-item.d.ts} +3 -4
- package/dist/elements/pop-up/pop-up-menu-item.js +1 -0
- package/dist/elements/pop-up/vira-menu-item.element.d.ts +19 -0
- package/{src/elements/pop-up/vira-menu-item.element.ts → dist/elements/pop-up/vira-menu-item.element.js} +11 -28
- package/dist/elements/pop-up/vira-menu-trigger.element.d.ts +41 -0
- package/dist/elements/pop-up/vira-menu-trigger.element.js +121 -0
- package/dist/elements/pop-up/vira-menu.element.d.ts +38 -0
- package/{src/elements/pop-up/vira-menu.element.ts → dist/elements/pop-up/vira-menu.element.js} +49 -76
- package/dist/elements/pop-up/vira-pop-up-menu.element.d.ts +35 -0
- package/{src/elements/pop-up/vira-pop-up-menu.element.ts → dist/elements/pop-up/vira-pop-up-menu.element.js} +22 -34
- package/dist/elements/pop-up/vira-pop-up-trigger.element.d.ts +105 -0
- package/{src/elements/pop-up/vira-pop-up-trigger.element.ts → dist/elements/pop-up/vira-pop-up-trigger.element.js} +104 -199
- package/dist/elements/shared-text-input-logic.d.ts +63 -0
- package/dist/elements/shared-text-input-logic.js +101 -0
- package/dist/elements/vira-bold-text.element.d.ts +9 -0
- package/{src/elements/vira-bold-text.element.ts → dist/elements/vira-bold-text.element.js} +7 -8
- package/dist/elements/vira-button.element.d.ts +31 -0
- package/{src/elements/vira-button.element.ts → dist/elements/vira-button.element.js} +35 -66
- package/dist/elements/vira-card.element.d.ts +18 -0
- package/{src/elements/vira-card.element.ts → dist/elements/vira-card.element.js} +13 -16
- package/dist/elements/vira-checkbox.element.d.ts +34 -0
- package/{src/elements/vira-checkbox.element.ts → dist/elements/vira-checkbox.element.js} +28 -71
- package/dist/elements/vira-collapsible-wrapper.element.d.ts +16 -0
- package/{src/elements/vira-collapsible-wrapper.element.ts → dist/elements/vira-collapsible-wrapper.element.js} +26 -18
- package/dist/elements/vira-dropdown.element.d.ts +46 -0
- package/{src/elements/vira-dropdown.element.ts → dist/elements/vira-dropdown.element.js} +48 -94
- package/dist/elements/vira-error.element.d.ts +7 -0
- package/{src/elements/vira-error.element.ts → dist/elements/vira-error.element.js} +5 -6
- package/dist/elements/vira-icon.element.d.ts +13 -0
- package/{src/elements/vira-icon.element.ts → dist/elements/vira-icon.element.js} +6 -13
- package/dist/elements/vira-image.element.d.ts +45 -0
- package/{src/elements/vira-image.element.ts → dist/elements/vira-image.element.js} +43 -63
- package/dist/elements/vira-input.element.d.ts +62 -0
- package/{src/elements/vira-input.element.ts → dist/elements/vira-input.element.js} +85 -151
- package/dist/elements/vira-link.element.d.ts +73 -0
- package/{src/elements/vira-link.element.ts → dist/elements/vira-link.element.js} +11 -62
- package/dist/elements/vira-modal.element.d.ts +39 -0
- package/{src/elements/vira-modal.element.ts → dist/elements/vira-modal.element.js} +50 -89
- package/dist/elements/vira-overflow-switch.element.d.ts +21 -0
- package/dist/elements/vira-overflow-switch.element.js +110 -0
- package/dist/elements/vira-progress.element.d.ts +18 -0
- package/{src/elements/vira-progress.element.ts → dist/elements/vira-progress.element.js} +11 -26
- package/dist/elements/vira-select.element.d.ts +48 -0
- package/{src/elements/vira-select.element.ts → dist/elements/vira-select.element.js} +41 -96
- package/dist/icons/icon-color.test-helper.d.ts +6 -0
- package/dist/icons/icon-color.test-helper.js +9 -0
- package/dist/icons/icon-css-vars.d.ts +14 -0
- package/{src/icons/icon-css-vars.ts → dist/icons/icon-css-vars.js} +1 -2
- package/dist/icons/icon-svg.d.ts +27 -0
- package/dist/icons/icon-svg.js +48 -0
- package/dist/icons/icon-svgs/bell-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/bell-24.icon.ts → dist/icons/icon-svgs/bell-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/chat-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/chat-24.icon.ts → dist/icons/icon-svgs/chat-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/check-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/check-24.icon.ts → dist/icons/icon-svgs/check-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/chevron-down-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/chevron-down-24.icon.ts → dist/icons/icon-svgs/chevron-down-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/chevron-up-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/chevron-up-24.icon.ts → dist/icons/icon-svgs/chevron-up-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/close-x-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/close-x-24.icon.ts → dist/icons/icon-svgs/close-x-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/commit-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/commit-24.icon.ts → dist/icons/icon-svgs/commit-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/copy-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/copy-24.icon.ts → dist/icons/icon-svgs/copy-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/document-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/document-24.icon.ts → dist/icons/icon-svgs/document-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/document-search-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/document-search-24.icon.ts → dist/icons/icon-svgs/document-search-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/double-chevron-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/double-chevron-24.icon.ts → dist/icons/icon-svgs/double-chevron-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/element-16.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/element-16.icon.ts → dist/icons/icon-svgs/element-16.icon.js} +4 -5
- package/dist/icons/icon-svgs/element-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/element-24.icon.ts → dist/icons/icon-svgs/element-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/external-link-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/external-link-24.icon.ts → dist/icons/icon-svgs/external-link-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/eye-closed-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/eye-closed-24.icon.ts → dist/icons/icon-svgs/eye-closed-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/eye-open-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/eye-open-24.icon.ts → dist/icons/icon-svgs/eye-open-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/filter-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/filter-24.icon.ts → dist/icons/icon-svgs/filter-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/link-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/link-24.icon.ts → dist/icons/icon-svgs/link-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/loader-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/loader-24.icon.ts → dist/icons/icon-svgs/loader-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/loader-animated-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/loader-animated-24.icon.ts → dist/icons/icon-svgs/loader-animated-24.icon.js} +6 -8
- package/dist/icons/icon-svgs/lock-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/lock-24.icon.ts → dist/icons/icon-svgs/lock-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/options-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/options-24.icon.ts → dist/icons/icon-svgs/options-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/pencil-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/pencil-24.icon.ts → dist/icons/icon-svgs/pencil-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/shield-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/shield-24.icon.ts → dist/icons/icon-svgs/shield-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/sort-ascending-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/sort-ascending-24.icon.ts → dist/icons/icon-svgs/sort-ascending-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/sort-descending-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/sort-descending-24.icon.ts → dist/icons/icon-svgs/sort-descending-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/speaker-loud-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/speaker-loud-24.icon.ts → dist/icons/icon-svgs/speaker-loud-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/speaker-medium-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/speaker-medium-24.icon.ts → dist/icons/icon-svgs/speaker-medium-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/speaker-muted-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/speaker-muted-24.icon.ts → dist/icons/icon-svgs/speaker-muted-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/speaker-quiet-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/speaker-quiet-24.icon.ts → dist/icons/icon-svgs/speaker-quiet-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/star-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/star-24.icon.ts → dist/icons/icon-svgs/star-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/status-failure-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/status-failure-24.icon.ts → dist/icons/icon-svgs/status-failure-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/status-in-progress-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/status-in-progress-24.icon.ts → dist/icons/icon-svgs/status-in-progress-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/status-success-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/status-success-24.icon.ts → dist/icons/icon-svgs/status-success-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/status-unknown-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/status-unknown-24.icon.ts → dist/icons/icon-svgs/status-unknown-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/status-warning-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/status-warning-24.icon.ts → dist/icons/icon-svgs/status-warning-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/upload-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/upload-24.icon.ts → dist/icons/icon-svgs/upload-24.icon.js} +4 -5
- package/dist/icons/icon-svgs/x-24.icon.d.ts +8 -0
- package/{src/icons/icon-svgs/x-24.icon.ts → dist/icons/icon-svgs/x-24.icon.js} +4 -5
- package/dist/icons/index.d.ts +86 -0
- package/{src/icons/index.ts → dist/icons/index.js} +39 -43
- package/dist/index.js +4 -0
- package/dist/styles/border.d.ts +9 -0
- package/{src/styles/border.ts → dist/styles/border.js} +1 -2
- package/dist/styles/disabled.d.ts +6 -0
- package/{src/styles/disabled.ts → dist/styles/disabled.js} +2 -3
- package/dist/styles/durations.d.ts +22 -0
- package/{src/styles/durations.ts → dist/styles/durations.js} +1 -2
- package/dist/styles/focus.d.ts +34 -0
- package/{src/styles/focus.ts → dist/styles/focus.js} +8 -29
- package/dist/styles/font.d.ts +9 -0
- package/{src/styles/font.ts → dist/styles/font.js} +1 -2
- package/dist/styles/form-styles.d.ts +20 -0
- package/{src/styles/form-styles.ts → dist/styles/form-styles.js} +1 -6
- package/{src/styles/index.ts → dist/styles/index.d.ts} +0 -1
- package/dist/styles/index.js +13 -0
- package/dist/styles/native-styles.d.ts +13 -0
- package/{src/styles/native-styles.ts → dist/styles/native-styles.js} +3 -5
- package/dist/styles/scrollbar.d.ts +6 -0
- package/{src/styles/scrollbar.ts → dist/styles/scrollbar.js} +3 -4
- package/dist/styles/shadows.d.ts +20 -0
- package/{src/styles/shadows.ts → dist/styles/shadows.js} +6 -8
- package/dist/styles/user-select.d.ts +6 -0
- package/{src/styles/user-select.ts → dist/styles/user-select.js} +2 -3
- package/dist/styles/vira-color-palette.d.ts +95 -0
- package/{src/styles/vira-color-palette.ts → dist/styles/vira-color-palette.js} +1 -11
- package/dist/styles/vira-color-theme.d.ts +1184 -0
- package/dist/styles/vira-color-theme.js +1138 -0
- package/dist/util/define-table.d.ts +110 -0
- package/dist/util/define-table.js +115 -0
- package/dist/util/dynamic-element.d.ts +63 -0
- package/dist/util/dynamic-element.js +61 -0
- package/dist/util/index.js +3 -0
- package/dist/util/pop-up-manager.d.ts +186 -0
- package/dist/util/pop-up-manager.js +214 -0
- package/package.json +6 -6
- package/src/elements/define-vira-element.ts +0 -29
- package/src/elements/form/vira-form-fields.ts +0 -140
- package/src/elements/form/vira-form.element.ts +0 -204
- package/src/elements/pop-up/pop-up-helpers.ts +0 -85
- package/src/elements/pop-up/vira-menu-trigger.element.ts +0 -158
- package/src/elements/shared-text-input-logic.ts +0 -173
- package/src/elements/vira-overflow-switch.element.ts +0 -137
- package/src/icons/icon-color.test-helper.ts +0 -9
- package/src/icons/icon-svg.ts +0 -71
- package/src/styles/vira-color-theme.ts +0 -1142
- package/src/util/define-table.ts +0 -279
- package/src/util/dynamic-element.ts +0 -129
- package/src/util/pop-up-manager.ts +0 -380
- /package/{src/elements/index.ts → dist/elements/index.d.ts} +0 -0
- /package/{src/index.ts → dist/index.d.ts} +0 -0
- /package/{src/util/index.ts → dist/util/index.d.ts} +0 -0
|
@@ -1,380 +0,0 @@
|
|
|
1
|
-
import {assert} from '@augment-vir/assert';
|
|
2
|
-
import {type MaybePromise, mapObjectValues} from '@augment-vir/common';
|
|
3
|
-
import {findOverflowAncestor} from '@augment-vir/web';
|
|
4
|
-
import {type Coords, NavActivateEvent, type NavController, NavDirection} from 'device-navigation';
|
|
5
|
-
import {listenToPageActivation} from 'page-active';
|
|
6
|
-
import {
|
|
7
|
-
type ExtractEventByType,
|
|
8
|
-
type ExtractEventTypes,
|
|
9
|
-
type ListenOptions,
|
|
10
|
-
ListenTarget,
|
|
11
|
-
type RemoveListenerCallback,
|
|
12
|
-
defineTypedCustomEvent,
|
|
13
|
-
defineTypedEvent,
|
|
14
|
-
listenToGlobal,
|
|
15
|
-
} from 'typed-event-target';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Used to prevent pop-ups from closing when a text input is active.
|
|
19
|
-
*
|
|
20
|
-
* @category Internal
|
|
21
|
-
*/
|
|
22
|
-
export function isInputLikeElement(element: Element): boolean {
|
|
23
|
-
return (
|
|
24
|
-
(element instanceof HTMLInputElement &&
|
|
25
|
-
(element.type === 'text' ||
|
|
26
|
-
element.type === 'search' ||
|
|
27
|
-
element.type === 'email' ||
|
|
28
|
-
element.type === 'url' ||
|
|
29
|
-
element.type === 'tel' ||
|
|
30
|
-
element.type === 'password' ||
|
|
31
|
-
element.type === 'number')) ||
|
|
32
|
-
element instanceof HTMLTextAreaElement ||
|
|
33
|
-
(element instanceof HTMLElement && element.isContentEditable)
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* A type used for representing a rectangle's position.
|
|
39
|
-
*
|
|
40
|
-
* @category Internal
|
|
41
|
-
*/
|
|
42
|
-
export type PositionRect = {
|
|
43
|
-
top: number;
|
|
44
|
-
left: number;
|
|
45
|
-
right: number;
|
|
46
|
-
bottom: number;
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* The default empty {@link PositionRect}, with all values set to 0.
|
|
51
|
-
*
|
|
52
|
-
* @category Internal
|
|
53
|
-
*/
|
|
54
|
-
export const emptyPositionRect: PositionRect = {
|
|
55
|
-
top: 0,
|
|
56
|
-
left: 0,
|
|
57
|
-
right: 0,
|
|
58
|
-
bottom: 0,
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Options for {@link PopUpManager}.
|
|
63
|
-
*
|
|
64
|
-
* @category PopUp
|
|
65
|
-
*/
|
|
66
|
-
export type PopUpManagerOptions = {
|
|
67
|
-
/**
|
|
68
|
-
* The minimum number of pixels for allowing the pop-up to go downwards. If the downward
|
|
69
|
-
* available space is less than this, and if the upwards available space is
|
|
70
|
-
* `verticalDiffThreshold` more than the downwards space, the pop-up will be directed upwards.
|
|
71
|
-
*
|
|
72
|
-
* Equation:
|
|
73
|
-
*
|
|
74
|
-
* const directUpwards =
|
|
75
|
-
* downwardsSpace < minDownSpace &&
|
|
76
|
-
* upwardsSpace > DownwardsSpace + verticalDiffThreshold;
|
|
77
|
-
*
|
|
78
|
-
* @default 200
|
|
79
|
-
*/
|
|
80
|
-
minDownSpace: number;
|
|
81
|
-
/**
|
|
82
|
-
* The minimum number of pixels for allowing the pop-up to go rightwards. If the rightward
|
|
83
|
-
* available space is less than this, and if the leftwards available space is
|
|
84
|
-
* `horizontalDiffThreshold` more than the rightwards space, the pop-up will be directed
|
|
85
|
-
* leftwards.
|
|
86
|
-
*
|
|
87
|
-
* Equation:
|
|
88
|
-
*
|
|
89
|
-
* const directLeftwards =
|
|
90
|
-
* rightwardsSpace < minRightSpace &&
|
|
91
|
-
* leftwardsSpace > rightwardsSpace + horizontalDiffThreshold;
|
|
92
|
-
*
|
|
93
|
-
* @default 400
|
|
94
|
-
*/
|
|
95
|
-
minRightSpace: number;
|
|
96
|
-
/**
|
|
97
|
-
* The number of pixels required for the upwards available space to be bigger than the downwards
|
|
98
|
-
* available space before directing the pop-up upwards.
|
|
99
|
-
*
|
|
100
|
-
* Equation:
|
|
101
|
-
*
|
|
102
|
-
* const directUpwards =
|
|
103
|
-
* downwardsSpace < minDownSpace &&
|
|
104
|
-
* upwardsSpace > DownwardsSpace + verticalDiffThreshold;
|
|
105
|
-
*
|
|
106
|
-
* @default 20
|
|
107
|
-
*/
|
|
108
|
-
verticalDiffThreshold: number;
|
|
109
|
-
/**
|
|
110
|
-
* The number of pixels required for the leftwards available space to be bigger than the
|
|
111
|
-
* rightwards available space before directing the pop-up leftwards.
|
|
112
|
-
*
|
|
113
|
-
* Equation:
|
|
114
|
-
*
|
|
115
|
-
* const directLeftwards =
|
|
116
|
-
* rightwardsSpace < minRightSpace &&
|
|
117
|
-
* leftwardsSpace > rightwardsSpace + horizontalDiffThreshold;
|
|
118
|
-
*
|
|
119
|
-
* @default 100
|
|
120
|
-
*/
|
|
121
|
-
horizontalDiffThreshold: number;
|
|
122
|
-
/**
|
|
123
|
-
* Supports navigation of the pop up via the `device-navigation` package.
|
|
124
|
-
*
|
|
125
|
-
* @default true
|
|
126
|
-
*/
|
|
127
|
-
supportNavigation: boolean;
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Output type from `PopUpManager.showPopUp`
|
|
132
|
-
*
|
|
133
|
-
* @category PopUp
|
|
134
|
-
*/
|
|
135
|
-
export type ShowPopUpResult = {
|
|
136
|
-
/**
|
|
137
|
-
* Indicates if the "pop up" should pop in the downwards direction or not. If not, it should pop
|
|
138
|
-
* in the upwards direction. This is determined by how much space is available on either side of
|
|
139
|
-
* the root element.
|
|
140
|
-
*/
|
|
141
|
-
popDown: boolean;
|
|
142
|
-
/**
|
|
143
|
-
* Indicates if the "pop up" should pop in the rightwards direction or not. If not, it should
|
|
144
|
-
* pop in the leftwards direction. This is determined by how much space is available on either
|
|
145
|
-
* side of the root element.
|
|
146
|
-
*/
|
|
147
|
-
popRight: boolean;
|
|
148
|
-
positions: Record<'root' | 'container' | 'diff', PositionRect>;
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* An event fired from {@link PopUpManager} when the pop up should be hidden.
|
|
153
|
-
*
|
|
154
|
-
* @category PopUp
|
|
155
|
-
*/
|
|
156
|
-
export class HidePopUpEvent extends defineTypedEvent('hide-pop-up') {}
|
|
157
|
-
/**
|
|
158
|
-
* An event fired from {@link PopUpManager} when an individual item in the pop up has been selected
|
|
159
|
-
* by the user.
|
|
160
|
-
*
|
|
161
|
-
* @category PopUp
|
|
162
|
-
*/
|
|
163
|
-
export class NavSelectEvent extends defineTypedCustomEvent<Coords>()('nav-select') {}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* All events that can be emitted by {@link PopUpManager}.
|
|
167
|
-
*
|
|
168
|
-
* @category Internal
|
|
169
|
-
*/
|
|
170
|
-
export type PopUpManagerEvents = HidePopUpEvent | NavSelectEvent;
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* A "pop up" manager for items that pop up from the HTML page, like dropdowns or menus.
|
|
174
|
-
*
|
|
175
|
-
* @category PopUp
|
|
176
|
-
*/
|
|
177
|
-
export class PopUpManager {
|
|
178
|
-
private listenTarget = new ListenTarget<PopUpManagerEvents>();
|
|
179
|
-
public options: PopUpManagerOptions = {
|
|
180
|
-
minDownSpace: 200,
|
|
181
|
-
minRightSpace: 400,
|
|
182
|
-
verticalDiffThreshold: 20,
|
|
183
|
-
horizontalDiffThreshold: 100,
|
|
184
|
-
supportNavigation: true,
|
|
185
|
-
};
|
|
186
|
-
private cleanupCallbacks: (() => void)[] = [];
|
|
187
|
-
private lastRootElement: HTMLElement | undefined;
|
|
188
|
-
|
|
189
|
-
constructor(
|
|
190
|
-
public readonly navController: NavController,
|
|
191
|
-
options?: Partial<PopUpManagerOptions> | undefined,
|
|
192
|
-
) {
|
|
193
|
-
this.options = {...this.options, ...options};
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
private attachGlobalListeners() {
|
|
197
|
-
this.cleanupCallbacks = [
|
|
198
|
-
listenToPageActivation(false, (isPageActive) => {
|
|
199
|
-
if (!isPageActive) {
|
|
200
|
-
this.removePopUp();
|
|
201
|
-
}
|
|
202
|
-
}),
|
|
203
|
-
this.navController.listen(NavActivateEvent, (event) => {
|
|
204
|
-
const target = event.composedPath()[0];
|
|
205
|
-
|
|
206
|
-
if (target instanceof Element && isInputLikeElement(target)) {
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (event.detail.success) {
|
|
211
|
-
this.listenTarget.dispatch(new NavSelectEvent({detail: event.detail.coords}));
|
|
212
|
-
this.navController.currentNavEntry?.entry.focus(true);
|
|
213
|
-
event.stopImmediatePropagation();
|
|
214
|
-
event.preventDefault();
|
|
215
|
-
}
|
|
216
|
-
}),
|
|
217
|
-
listenToGlobal(
|
|
218
|
-
'mousedown',
|
|
219
|
-
(event) => {
|
|
220
|
-
if (
|
|
221
|
-
this.lastRootElement &&
|
|
222
|
-
event.composedPath().includes(this.lastRootElement)
|
|
223
|
-
) {
|
|
224
|
-
/** Ignore clicks that came from the pop up host itself. */
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
this.removePopUp();
|
|
228
|
-
},
|
|
229
|
-
{passive: true},
|
|
230
|
-
),
|
|
231
|
-
listenToGlobal('keydown', (event) => {
|
|
232
|
-
const keyCode = event.code;
|
|
233
|
-
|
|
234
|
-
if (keyCode === 'Escape') {
|
|
235
|
-
this.removePopUp();
|
|
236
|
-
} else if (this.options.supportNavigation) {
|
|
237
|
-
const target = event.composedPath()[0];
|
|
238
|
-
|
|
239
|
-
if (target instanceof Element && isInputLikeElement(target)) {
|
|
240
|
-
return;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
if (keyCode === 'ArrowDown') {
|
|
244
|
-
event.stopImmediatePropagation();
|
|
245
|
-
event.preventDefault();
|
|
246
|
-
|
|
247
|
-
this.navController.navigate({
|
|
248
|
-
direction: NavDirection.Down,
|
|
249
|
-
allowWrapping: false,
|
|
250
|
-
});
|
|
251
|
-
} else if (keyCode === 'ArrowUp') {
|
|
252
|
-
event.stopImmediatePropagation();
|
|
253
|
-
event.preventDefault();
|
|
254
|
-
|
|
255
|
-
this.navController.navigate({
|
|
256
|
-
direction: NavDirection.Up,
|
|
257
|
-
allowWrapping: false,
|
|
258
|
-
});
|
|
259
|
-
} else if (keyCode === 'ArrowLeft') {
|
|
260
|
-
event.stopImmediatePropagation();
|
|
261
|
-
event.preventDefault();
|
|
262
|
-
|
|
263
|
-
this.navController.navigate({
|
|
264
|
-
direction: NavDirection.Left,
|
|
265
|
-
allowWrapping: false,
|
|
266
|
-
});
|
|
267
|
-
} else if (keyCode === 'ArrowRight') {
|
|
268
|
-
event.stopImmediatePropagation();
|
|
269
|
-
event.preventDefault();
|
|
270
|
-
|
|
271
|
-
this.navController.navigate({
|
|
272
|
-
direction: NavDirection.Right,
|
|
273
|
-
allowWrapping: false,
|
|
274
|
-
});
|
|
275
|
-
} else if (
|
|
276
|
-
(keyCode === 'Enter' || keyCode === 'Return' || keyCode === 'Space') &&
|
|
277
|
-
this.navController.enterInto({fallbackToActivate: true}).success
|
|
278
|
-
) {
|
|
279
|
-
event.stopImmediatePropagation();
|
|
280
|
-
event.preventDefault();
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}),
|
|
284
|
-
];
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
/** Listen to events emitted from a {@link PopUpManager} instance. */
|
|
288
|
-
public listen<
|
|
289
|
-
const EventDefinition extends Readonly<{
|
|
290
|
-
type: ExtractEventTypes<PopUpManagerEvents>;
|
|
291
|
-
}>,
|
|
292
|
-
>(
|
|
293
|
-
event: EventDefinition,
|
|
294
|
-
listener: (
|
|
295
|
-
event: ExtractEventByType<PopUpManagerEvents, EventDefinition['type']>,
|
|
296
|
-
) => MaybePromise<void>,
|
|
297
|
-
options?: ListenOptions | undefined,
|
|
298
|
-
): RemoveListenerCallback {
|
|
299
|
-
return this.listenTarget.listen(event, listener, options);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
/** Trigger removal or hiding of the pop up. */
|
|
303
|
-
public removePopUp() {
|
|
304
|
-
this.cleanupCallbacks.forEach((callback) => callback());
|
|
305
|
-
this.listenTarget.dispatch(new HidePopUpEvent());
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
/** Trigger showing the pop up. */
|
|
309
|
-
public showPopUp(
|
|
310
|
-
rootElement: HTMLElement,
|
|
311
|
-
options?: Partial<PopUpManagerOptions> | undefined,
|
|
312
|
-
): ShowPopUpResult {
|
|
313
|
-
this.lastRootElement = rootElement;
|
|
314
|
-
const currentOptions = {...this.options, ...options};
|
|
315
|
-
const container = findOverflowAncestor(rootElement);
|
|
316
|
-
assert.instanceOf(container, HTMLElement);
|
|
317
|
-
|
|
318
|
-
const rootRect = rootElement.getBoundingClientRect();
|
|
319
|
-
const containerRect = container.getBoundingClientRect();
|
|
320
|
-
|
|
321
|
-
const containerScrollbarWidth = container.offsetWidth - container.clientWidth;
|
|
322
|
-
const containerScrollbarHeight = container.offsetHeight - container.clientHeight;
|
|
323
|
-
|
|
324
|
-
const containerPosition: PositionRect =
|
|
325
|
-
container === document.body
|
|
326
|
-
? {
|
|
327
|
-
top: 0,
|
|
328
|
-
left: 0,
|
|
329
|
-
right: containerRect.width,
|
|
330
|
-
bottom: containerRect.height,
|
|
331
|
-
}
|
|
332
|
-
: {
|
|
333
|
-
top: containerRect.top,
|
|
334
|
-
left: containerRect.left,
|
|
335
|
-
right: containerRect.right - containerScrollbarWidth,
|
|
336
|
-
bottom: containerRect.bottom - containerScrollbarHeight,
|
|
337
|
-
};
|
|
338
|
-
|
|
339
|
-
const rootPosition: PositionRect = mapObjectValues(emptyPositionRect, (key) => {
|
|
340
|
-
return rootRect[key];
|
|
341
|
-
});
|
|
342
|
-
const diff: PositionRect = mapObjectValues(emptyPositionRect, (key) => {
|
|
343
|
-
const containerDimension = containerPosition[key];
|
|
344
|
-
const hostDimension = rootPosition[key];
|
|
345
|
-
|
|
346
|
-
return Math.abs(containerDimension - hostDimension);
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
const useUp =
|
|
350
|
-
diff.top > diff.bottom + currentOptions.verticalDiffThreshold &&
|
|
351
|
-
diff.bottom < currentOptions.minDownSpace;
|
|
352
|
-
|
|
353
|
-
const useLeft =
|
|
354
|
-
diff.left > diff.right + currentOptions.horizontalDiffThreshold &&
|
|
355
|
-
diff.right < currentOptions.minRightSpace;
|
|
356
|
-
|
|
357
|
-
this.attachGlobalListeners();
|
|
358
|
-
|
|
359
|
-
return {
|
|
360
|
-
popDown: !useUp,
|
|
361
|
-
popRight: !useLeft,
|
|
362
|
-
positions: {
|
|
363
|
-
container: containerPosition,
|
|
364
|
-
root: rootPosition,
|
|
365
|
-
diff,
|
|
366
|
-
},
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Cleanup and destroy the {@link PopUpManager} instance. This:
|
|
372
|
-
*
|
|
373
|
-
* - Removes the existing pop up
|
|
374
|
-
* - Cleans up all internal and external listeners
|
|
375
|
-
*/
|
|
376
|
-
public destroy() {
|
|
377
|
-
this.removePopUp();
|
|
378
|
-
this.listenTarget.destroy();
|
|
379
|
-
}
|
|
380
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|