@fibrae/semi-foundation 0.6.0 → 0.7.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/base/index.d.ts +2 -1
- package/dist/base/index.js +2 -1
- package/dist/base/overlay-session.d.ts +16 -0
- package/dist/base/overlay-session.js +36 -0
- package/dist/components/audio-player/foundation.js +1 -1
- package/dist/components/auto-complete/constants.d.ts +3 -1
- package/dist/components/auto-complete/foundation.d.ts +1 -1
- package/dist/components/auto-complete/foundation.js +15 -16
- package/dist/components/badge/constants.d.ts +3 -1
- package/dist/components/button/constants.d.ts +3 -1
- package/dist/components/card/constants.d.ts +3 -1
- package/dist/components/cascader/constants.d.ts +2 -0
- package/dist/components/cascader/foundation.d.ts +2 -4
- package/dist/components/cascader/foundation.js +4 -1
- package/dist/components/color-picker/foundation.d.ts +2 -0
- package/dist/components/color-picker/foundation.js +5 -0
- package/dist/components/cropper/constants.d.ts +2 -0
- package/dist/components/date-picker/_utils/index.d.ts +1 -2
- package/dist/components/date-picker/_utils/index.js +1 -2
- package/dist/components/date-picker/_utils/is-timestamp.js +1 -1
- package/dist/components/date-picker/_utils/parse-value.js +1 -1
- package/dist/components/date-picker/_utils/picker-type.js +1 -1
- package/dist/components/date-picker/constants.d.ts +2 -0
- package/dist/components/date-picker/foundation.d.ts +3 -4
- package/dist/components/date-picker/foundation.js +8 -3
- package/dist/components/date-picker/input-foundation.d.ts +1 -0
- package/dist/components/date-picker/input-foundation.js +1 -1
- package/dist/components/date-picker/month-foundation.d.ts +1 -1
- package/dist/components/date-picker/month-foundation.js +1 -0
- package/dist/components/date-picker/months-grid-foundation.d.ts +1 -1
- package/dist/components/date-picker/months-grid-foundation.js +1 -1
- package/dist/components/descriptions/constants.d.ts +3 -1
- package/dist/components/dropdown/constants.d.ts +2 -0
- package/dist/components/dropdown/menu-foundation.d.ts +1 -1
- package/dist/components/empty/constants.d.ts +3 -1
- package/dist/components/feedback/constants.d.ts +3 -1
- package/dist/components/highlight/constants.d.ts +3 -1
- package/dist/components/image/constants.d.ts +5 -1
- package/dist/components/image/preview-inner-foundation.js +6 -15
- package/dist/components/input/constants.d.ts +5 -1
- package/dist/components/input-number/constants.d.ts +3 -1
- package/dist/components/modal/constants.d.ts +3 -1
- package/dist/components/modal/modal-content-foundation.d.ts +3 -3
- package/dist/components/modal/modal-content-foundation.js +5 -3
- package/dist/components/modal/modal-foundation.d.ts +0 -2
- package/dist/components/modal/modal-foundation.js +6 -16
- package/dist/components/navigation/constants.d.ts +4 -0
- package/dist/components/overflow-list/constants.d.ts +2 -0
- package/dist/components/pagination/foundation.d.ts +1 -1
- package/dist/components/popconfirm/constants.d.ts +3 -1
- package/dist/components/popover/constants.d.ts +2 -0
- package/dist/components/radio/constants.d.ts +3 -1
- package/dist/components/scroll-list/item-foundation.js +1 -0
- package/dist/components/select/constants.d.ts +2 -0
- package/dist/components/select/foundation.d.ts +1 -4
- package/dist/components/select/foundation.js +31 -56
- package/dist/components/select/select.css +3 -3
- package/dist/components/select/select.scss +8 -3
- package/dist/components/side-sheet/constants.d.ts +2 -0
- package/dist/components/side-sheet/side-sheet-foundation.d.ts +6 -4
- package/dist/components/side-sheet/side-sheet-foundation.js +33 -23
- package/dist/components/slider/constants.d.ts +3 -1
- package/dist/components/slider/foundation.d.ts +7 -7
- package/dist/components/slider/foundation.js +9 -6
- package/dist/components/spin/constants.d.ts +3 -1
- package/dist/components/table/constants.d.ts +2 -0
- package/dist/components/tabs/constants.d.ts +2 -0
- package/dist/components/tabs/foundation.js +19 -60
- package/dist/components/time-picker/combobox-options.js +1 -1
- package/dist/components/time-picker/constants.d.ts +2 -0
- package/dist/components/time-picker/foundation.d.ts +3 -1
- package/dist/components/time-picker/foundation.js +7 -1
- package/dist/components/tooltip/constants.d.ts +2 -0
- package/dist/components/tooltip/foundation.d.ts +13 -15
- package/dist/components/tooltip/foundation.js +54 -15
- package/dist/components/tree/constants.d.ts +2 -0
- package/dist/components/tree/foundation.d.ts +17 -3
- package/dist/components/tree/foundation.js +37 -2
- package/dist/components/tree/shared.d.ts +37 -0
- package/dist/components/tree/shared.js +42 -1
- package/dist/components/tree-select/constants.d.ts +2 -0
- package/dist/components/tree-select/foundation.d.ts +15 -10
- package/dist/components/tree-select/foundation.js +44 -7
- package/dist/components/upload/constants.d.ts +4 -2
- package/dist/components/upload/utils.d.ts +5 -0
- package/dist/components/upload/utils.js +8 -2
- package/dist/components/video-player/foundation.js +1 -1
- package/dist/components/video-player/utils.d.ts +0 -2
- package/dist/components/video-player/utils.js +1 -14
- package/dist/locale/interface.d.ts +2 -0
- package/dist/locale/source/en_US.js +1 -0
- package/dist/locale/source/zh_CN.js +1 -0
- package/dist/utils/a11y.d.ts +9 -0
- package/dist/utils/a11y.js +19 -1
- package/dist/utils/date-fns-extra.d.ts +1 -0
- package/dist/utils/date-fns-extra.js +4 -1
- package/dist/utils/index.d.ts +3 -2
- package/dist/utils/index.js +3 -2
- package/dist/utils/media.d.ts +2 -0
- package/dist/utils/media.js +15 -0
- package/package.json +2 -2
- package/dist/components/date-picker/_utils/is-valid-date.d.ts +0 -1
- package/dist/components/date-picker/_utils/is-valid-date.js +0 -5
|
@@ -1,24 +1,35 @@
|
|
|
1
1
|
import FocusTrapHandle from "../../base/focus-handle.js";
|
|
2
2
|
import BaseFoundation from "../../base/foundation.js";
|
|
3
3
|
import ModalResources from "../../base/modal-resources.js";
|
|
4
|
+
import OverlaySession from "../../base/overlay-session.js";
|
|
4
5
|
import PopupLifecycle from "../../base/popup-lifecycle.js";
|
|
5
6
|
import { coversPage } from "../../utils/dom.js";
|
|
7
|
+
import { warnIfDialogUnnamed } from "../../utils/a11y.js";
|
|
6
8
|
import { strings } from "./constants.js";
|
|
7
9
|
// src/components/side-sheet/side-sheet-foundation.ts
|
|
8
10
|
var SideSheetFoundation = class SideSheetFoundation extends BaseFoundation {
|
|
9
|
-
#
|
|
10
|
-
#resume = false;
|
|
11
|
+
#session = new OverlaySession();
|
|
11
12
|
#lifecycle = new PopupLifecycle();
|
|
12
13
|
#resources = new ModalResources();
|
|
14
|
+
#shownReported = false;
|
|
13
15
|
constructor(adapter) {
|
|
14
16
|
super(adapter);
|
|
15
|
-
if (this.getProp("visible"))
|
|
17
|
+
if (this.getProp("visible")) {
|
|
18
|
+
this.#lifecycle.show();
|
|
19
|
+
this.#shownReported = true;
|
|
20
|
+
}
|
|
16
21
|
}
|
|
17
22
|
#handleEscape = (e) => {
|
|
18
23
|
if (!this.getProp("closeOnEsc")) return false;
|
|
19
24
|
this.handleCancel(e);
|
|
20
25
|
return true;
|
|
21
26
|
};
|
|
27
|
+
#reportShown() {
|
|
28
|
+
if (!this.#shownReported) {
|
|
29
|
+
this.#shownReported = true;
|
|
30
|
+
this.adapter.notifyAfterVisibleChange(true);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
22
33
|
/** Without a mask the width goes on the outer element and the dialog fills it: a percentage repeated on the dialog would compound. */
|
|
23
34
|
static getSheetSize({ placement, canVerticalSetWidth, width, height, mask }) {
|
|
24
35
|
const horizontal = placement === "top" || placement === "bottom";
|
|
@@ -45,16 +56,10 @@ var SideSheetFoundation = class SideSheetFoundation extends BaseFoundation {
|
|
|
45
56
|
return {};
|
|
46
57
|
}
|
|
47
58
|
init() {
|
|
48
|
-
if (this.#resume)
|
|
49
|
-
this.#resume = false;
|
|
50
|
-
this.beforeShow();
|
|
51
|
-
}
|
|
59
|
+
if (this.#session.resume()) this.beforeShow();
|
|
52
60
|
}
|
|
53
61
|
destroy() {
|
|
54
|
-
if (this.#
|
|
55
|
-
this.afterHide();
|
|
56
|
-
this.#resume = true;
|
|
57
|
-
}
|
|
62
|
+
if (this.#session.suspend()) this.#resources.release();
|
|
58
63
|
}
|
|
59
64
|
/** Returns focus again, for a host whose framework refocuses the previously focused element after the close */
|
|
60
65
|
restoreFocus = () => {
|
|
@@ -69,19 +74,26 @@ var SideSheetFoundation = class SideSheetFoundation extends BaseFoundation {
|
|
|
69
74
|
this.adapter.notifyCancel(e);
|
|
70
75
|
};
|
|
71
76
|
/**
|
|
77
|
+
* Hosts call this when the dialog's animation ends, and at once when a run without motion starts: the end of an
|
|
78
|
+
* enter reports afterVisibleChange(true), once per showing.
|
|
79
|
+
*/
|
|
80
|
+
handleAnimationEnd = () => {
|
|
81
|
+
if (this.getProp("visible")) this.#reportShown();
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
72
84
|
* Hosts call this when the sheet stops or starts being hidden (once the animations ended), not on mount, and with
|
|
73
|
-
* `true` when it unmounts for good: afterVisibleChange(false) is reported once per showing
|
|
85
|
+
* `true` when it unmounts for good: afterVisibleChange(false) is reported once per showing, after its `true`.
|
|
74
86
|
*/
|
|
75
87
|
handleHiddenChange = (isHidden) => {
|
|
76
|
-
if (isHidden) this.#lifecycle.ended(() =>
|
|
77
|
-
|
|
78
|
-
this.#
|
|
79
|
-
this.adapter.notifyAfterVisibleChange(
|
|
80
|
-
}
|
|
88
|
+
if (isHidden) this.#lifecycle.ended(() => {
|
|
89
|
+
this.#reportShown();
|
|
90
|
+
this.#shownReported = false;
|
|
91
|
+
this.adapter.notifyAfterVisibleChange(false);
|
|
92
|
+
});
|
|
93
|
+
else this.#lifecycle.show();
|
|
81
94
|
};
|
|
82
95
|
beforeShow = () => {
|
|
83
|
-
if (this.#
|
|
84
|
-
this.#shown = true;
|
|
96
|
+
if (!this.#session.begin()) return;
|
|
85
97
|
this.#lifecycle.show();
|
|
86
98
|
const { mask, getPopupContainer, disableScroll } = this.getProps();
|
|
87
99
|
const modal = SideSheetFoundation.isModal({
|
|
@@ -98,12 +110,10 @@ var SideSheetFoundation = class SideSheetFoundation extends BaseFoundation {
|
|
|
98
110
|
focus: dialog,
|
|
99
111
|
preventScroll: true
|
|
100
112
|
});
|
|
113
|
+
warnIfDialogUnnamed(dialog ?? null, "SideSheet");
|
|
101
114
|
};
|
|
102
115
|
afterHide = () => {
|
|
103
|
-
this.#
|
|
104
|
-
if (!this.#shown) return;
|
|
105
|
-
this.#shown = false;
|
|
106
|
-
this.#resources.release();
|
|
116
|
+
if (this.#session.end()) this.#resources.release();
|
|
107
117
|
};
|
|
108
118
|
};
|
|
109
119
|
export { SideSheetFoundation as default };
|
|
@@ -30,7 +30,6 @@ export interface SliderProps {
|
|
|
30
30
|
showArrow?: boolean;
|
|
31
31
|
className?: string;
|
|
32
32
|
showBoundary?: boolean;
|
|
33
|
-
railStyle?: Record<string, any>;
|
|
34
33
|
verticalReverse?: boolean;
|
|
35
34
|
'aria-label'?: string;
|
|
36
35
|
'aria-labelledby'?: string;
|
|
@@ -96,11 +95,11 @@ export default class SliderFoundation<P extends SliderProps = SliderProps> exten
|
|
|
96
95
|
* `reverse` is the class suffix of a vertical slider drawn from the bottom.
|
|
97
96
|
*/
|
|
98
97
|
static getLayout(props: SliderProps, value: SliderState['currentValue'], { chooseMovePos, isDrag }: Pick<SliderState, 'chooseMovePos' | 'isDrag'>, direction?: string): {
|
|
99
|
-
startProp: "
|
|
98
|
+
startProp: "top" | "left" | "right";
|
|
100
99
|
inputDir: "rtl" | "ltr";
|
|
101
100
|
reverse: string;
|
|
102
101
|
track: {
|
|
103
|
-
sizeProp: "
|
|
102
|
+
sizeProp: "height" | "width";
|
|
104
103
|
size: string;
|
|
105
104
|
start: string;
|
|
106
105
|
};
|
|
@@ -172,10 +171,11 @@ export default class SliderFoundation<P extends SliderProps = SliderProps> exten
|
|
|
172
171
|
*/
|
|
173
172
|
handleInputChange: (value: number, pos: "min" | "max") => void;
|
|
174
173
|
/**
|
|
175
|
-
* A value key stays with the slider unless the consumer's handler already prevented it. Page
|
|
176
|
-
*
|
|
177
|
-
* (Chrome follows the visual direction, Firefox not when vertical, Safari in neither case
|
|
178
|
-
* towards max increases; the cross-axis arrow
|
|
174
|
+
* A value key stays with the slider unless the consumer's handler already prevented it. Page keys keep the native
|
|
175
|
+
* range's change; arrows, Home and End are handled here, since engines map them differently over a vertical or RTL
|
|
176
|
+
* range (Chrome follows the visual direction for arrows, Firefox not when vertical, Safari in neither case, and
|
|
177
|
+
* Safari swaps Home and End on a vertical range). The arrow pointing towards max increases; the cross-axis arrow
|
|
178
|
+
* follows Up and Right.
|
|
179
179
|
*/
|
|
180
180
|
handleKeyDown: (event: Pick<KeyboardEvent, "key" | "defaultPrevented" | "stopPropagation" | "preventDefault" | KeyModifiers>, pos: "min" | "max") => void;
|
|
181
181
|
/**
|
|
@@ -409,10 +409,11 @@ var SliderFoundation = class SliderFoundation extends BaseFoundation {
|
|
|
409
409
|
}
|
|
410
410
|
};
|
|
411
411
|
/**
|
|
412
|
-
* A value key stays with the slider unless the consumer's handler already prevented it. Page
|
|
413
|
-
*
|
|
414
|
-
* (Chrome follows the visual direction, Firefox not when vertical, Safari in neither case
|
|
415
|
-
* towards max increases; the cross-axis arrow
|
|
412
|
+
* A value key stays with the slider unless the consumer's handler already prevented it. Page keys keep the native
|
|
413
|
+
* range's change; arrows, Home and End are handled here, since engines map them differently over a vertical or RTL
|
|
414
|
+
* range (Chrome follows the visual direction for arrows, Firefox not when vertical, Safari in neither case, and
|
|
415
|
+
* Safari swaps Home and End on a vertical range). The arrow pointing towards max increases; the cross-axis arrow
|
|
416
|
+
* follows Up and Right.
|
|
416
417
|
*/
|
|
417
418
|
handleKeyDown = (event, pos) => {
|
|
418
419
|
if (!VALUE_KEYS.includes(event.key) || hasModifier(event)) return;
|
|
@@ -428,11 +429,13 @@ var SliderFoundation = class SliderFoundation extends BaseFoundation {
|
|
|
428
429
|
ArrowRight: "ArrowLeft"
|
|
429
430
|
};
|
|
430
431
|
const delta = increase.includes(event.key) ? 1 : increase.map((key) => opposite[key]).includes(event.key) ? -1 : 0;
|
|
431
|
-
if (!delta) return;
|
|
432
|
+
if (!delta && event.key !== "Home" && event.key !== "End") return;
|
|
432
433
|
event.preventDefault();
|
|
433
434
|
const { currentValue } = this.getStates();
|
|
434
435
|
const value = Array.isArray(currentValue) ? currentValue[pos === "min" ? 0 : 1] : currentValue;
|
|
435
|
-
const
|
|
436
|
+
const stepSize = step > 0 ? step : 1;
|
|
437
|
+
let next = this.normalizeValue(event.key === "Home" ? min : event.key === "End" ? min + Math.round((max - min) / stepSize) * stepSize : value + delta * stepSize);
|
|
438
|
+
if (event.key === "End" && next > max) next = this.normalizeValue(next - stepSize);
|
|
436
439
|
if (next >= min && next <= max) this.handleInputChange(next, pos);
|
|
437
440
|
};
|
|
438
441
|
/**
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare const cssClasses: {
|
|
2
2
|
readonly PREFIX: "semi-table";
|
|
3
3
|
};
|
|
4
|
+
/** Keys of `classNames` and `styles`; the root element takes `className` and `style` */
|
|
5
|
+
export type TablePart = 'header';
|
|
4
6
|
export declare const strings: {
|
|
5
7
|
readonly SIZE_SMALL: "small";
|
|
6
8
|
readonly SIZE_MIDDLE: "middle";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import BaseFoundation from "../../base/foundation.js";
|
|
2
|
+
import { getListTargetIndex, handlePrevent } from "../../utils/a11y.js";
|
|
2
3
|
import { TAB_DATA_KEY_PREFIX, TAB_KEY_ATTRIBUTE, cssClasses } from "./constants.js";
|
|
3
4
|
import { isEqual } from "es-toolkit";
|
|
4
5
|
// src/components/tabs/foundation.ts
|
|
@@ -8,49 +9,15 @@ var TabsFoundation = class TabsFoundation extends BaseFoundation {
|
|
|
8
9
|
const { activeKey: stateActiveKey } = this.getStates();
|
|
9
10
|
if (stateActiveKey !== activeKey) this.adapter.notifyChange(activeKey);
|
|
10
11
|
}
|
|
11
|
-
#handlePrevent(event) {
|
|
12
|
-
event.stopPropagation();
|
|
13
|
-
event.preventDefault();
|
|
14
|
-
}
|
|
15
|
-
#handleArrowKey(event, tab, allTabs) {
|
|
16
|
-
const { tabPosition } = this.getProps();
|
|
17
|
-
if (tabPosition === "left") {
|
|
18
|
-
if (event.key === "ArrowUp" || event.key === "ArrowDown") {
|
|
19
|
-
this.#switchTabOnArrowPress(event.key, tab, allTabs);
|
|
20
|
-
this.#handlePrevent(event);
|
|
21
|
-
}
|
|
22
|
-
} else if (event.key === "ArrowLeft" || event.key === "ArrowRight") {
|
|
23
|
-
this.#switchTabOnArrowPress(event.key, tab, allTabs);
|
|
24
|
-
this.#handlePrevent(event);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
12
|
#handleDeleteKeyDown(event, tab, tabs, itemKey, closable) {
|
|
28
13
|
const { preventScroll } = this.getProps();
|
|
29
14
|
if (closable && tab.getAttribute("aria-disabled") !== "true") {
|
|
30
|
-
|
|
15
|
+
handlePrevent(event);
|
|
31
16
|
this.handleTabDelete(itemKey);
|
|
32
17
|
const index = tabs.indexOf(tab);
|
|
33
18
|
if (tabs.length !== 1) tabs[index + 1 >= tabs.length ? index - 1 : index + 1].focus({ preventScroll });
|
|
34
19
|
}
|
|
35
20
|
}
|
|
36
|
-
#switchTabOnArrowPress(key, tab, allTabs) {
|
|
37
|
-
const { preventScroll } = this.getProps();
|
|
38
|
-
const rtl = this.adapter.getContext("direction") === "rtl";
|
|
39
|
-
const step = {
|
|
40
|
-
ArrowLeft: rtl ? 1 : -1,
|
|
41
|
-
ArrowUp: -1,
|
|
42
|
-
ArrowRight: rtl ? -1 : 1,
|
|
43
|
-
ArrowDown: 1
|
|
44
|
-
}[key];
|
|
45
|
-
const start = allTabs.indexOf(tab);
|
|
46
|
-
for (let offset = 1; offset < allTabs.length; offset++) {
|
|
47
|
-
const candidate = allTabs[(start + step * offset + allTabs.length) % allTabs.length];
|
|
48
|
-
if (candidate.getAttribute("aria-disabled") !== "true") {
|
|
49
|
-
candidate.focus({ preventScroll });
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
21
|
handleNewActiveKey(activeKey) {
|
|
55
22
|
const { activeKey: stateActiveKey } = this.getStates();
|
|
56
23
|
if (stateActiveKey !== activeKey) this.setState({ activeKey });
|
|
@@ -129,33 +96,25 @@ var TabsFoundation = class TabsFoundation extends BaseFoundation {
|
|
|
129
96
|
if (event.altKey || event.ctrlKey || event.metaKey) return;
|
|
130
97
|
const tab = event.currentTarget;
|
|
131
98
|
if (!(tab instanceof HTMLElement) || event.target !== tab) return;
|
|
132
|
-
const { preventScroll } = this.getProps();
|
|
99
|
+
const { preventScroll, tabPosition } = this.getProps();
|
|
133
100
|
const allTabs = [...tab.closest("[role=\"tablist\"]").querySelectorAll(`[${TAB_KEY_ATTRIBUTE}^="${TAB_DATA_KEY_PREFIX}"]`)];
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
case "ArrowUp":
|
|
139
|
-
case "ArrowDown":
|
|
140
|
-
this.#handleArrowKey(event, tab, allTabs);
|
|
141
|
-
break;
|
|
142
|
-
case "Backspace":
|
|
143
|
-
case "Delete":
|
|
144
|
-
this.#handleDeleteKeyDown(event, tab, tabs, itemKey, closable);
|
|
145
|
-
break;
|
|
146
|
-
case "Enter":
|
|
147
|
-
case " ":
|
|
148
|
-
if (tab.getAttribute("aria-disabled") === "true") break;
|
|
101
|
+
const isDisabled = (item) => item.getAttribute("aria-disabled") === "true";
|
|
102
|
+
if (event.key === "Backspace" || event.key === "Delete") this.#handleDeleteKeyDown(event, tab, allTabs.filter((item) => !isDisabled(item)), itemKey, closable);
|
|
103
|
+
else if (event.key === "Enter" || event.key === " ") {
|
|
104
|
+
if (!isDisabled(tab)) {
|
|
149
105
|
this.handleTabClick(itemKey, event);
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
106
|
+
handlePrevent(event);
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
const target = getListTargetIndex(event.key, allTabs.indexOf(tab), allTabs.length, (index) => isDisabled(allTabs[index]), {
|
|
110
|
+
loop: true,
|
|
111
|
+
orientation: tabPosition === "left" ? "vertical" : "horizontal",
|
|
112
|
+
rtl: this.adapter.getContext("direction") === "rtl"
|
|
113
|
+
});
|
|
114
|
+
if (target !== null) {
|
|
115
|
+
allTabs[target].focus({ preventScroll });
|
|
116
|
+
handlePrevent(event);
|
|
117
|
+
}
|
|
159
118
|
}
|
|
160
119
|
};
|
|
161
120
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import isValidDate from "
|
|
1
|
+
import { isValidDate } from "../../utils/date-fns-extra.js";
|
|
2
2
|
import { strings } from "./constants.js";
|
|
3
3
|
// src/components/time-picker/combobox-options.ts
|
|
4
4
|
function formatOption(option, disabledOptions) {
|
|
@@ -87,7 +87,7 @@ export default class TimePickerFoundation<P extends TimePickerBaseProps = TimePi
|
|
|
87
87
|
blur: () => void;
|
|
88
88
|
handleFocus: (e: E) => void;
|
|
89
89
|
/** A custom trigger without a focus target of its own is a button: Enter, Space and Down Arrow open the panel */
|
|
90
|
-
handleTriggerKeyDown: (e: Pick<KeyboardEvent, "key" | "preventDefault">) => void;
|
|
90
|
+
handleTriggerKeyDown: (e: Pick<KeyboardEvent, "key" | "preventDefault"> & Partial<Pick<KeyboardEvent, "ctrlKey" | "metaKey" | "altKey">>) => void;
|
|
91
91
|
/** Closes the panel and reports openChange(false), without blur and without moving focus */
|
|
92
92
|
close: () => void;
|
|
93
93
|
/**
|
|
@@ -99,6 +99,8 @@ export default class TimePickerFoundation<P extends TimePickerBaseProps = TimePi
|
|
|
99
99
|
handlePanelOpen: () => void;
|
|
100
100
|
/** Called for a mousedown outside the trigger and the panel while the panel is shown */
|
|
101
101
|
handleClickOutside: (e: MouseEvent) => void;
|
|
102
|
+
/** Called for a focusin anywhere while the panel is shown; `root` contains the trigger the panel opens from */
|
|
103
|
+
handleDocumentFocusIn: (e: Pick<FocusEvent, "composedPath">, root?: Node | null) => void;
|
|
102
104
|
handleInputChange: (input: string) => void;
|
|
103
105
|
handleInputBlur: () => void;
|
|
104
106
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import BaseFoundation from "../../base/foundation.js";
|
|
2
2
|
import { zonedTimeToUtc } from "../../utils/date-fns-extra.js";
|
|
3
|
+
import { containsWithPopups } from "../../utils/layer.js";
|
|
4
|
+
import { isBrowserChord } from "../../utils/a11y.js";
|
|
3
5
|
import isValidTimeZone from "../../utils/is-valid-time-zone.js";
|
|
4
6
|
import { fromWallTime, parseReference, toWallTime } from "../../utils/zoned-time.js";
|
|
5
7
|
import { getColumns } from "./combobox-options.js";
|
|
@@ -217,7 +219,7 @@ var TimePickerFoundation = class TimePickerFoundation extends BaseFoundation {
|
|
|
217
219
|
};
|
|
218
220
|
/** A custom trigger without a focus target of its own is a button: Enter, Space and Down Arrow open the panel */
|
|
219
221
|
handleTriggerKeyDown = (e) => {
|
|
220
|
-
if (e.key === "Enter" || e.key === " " || e.key === "ArrowDown") {
|
|
222
|
+
if (!isBrowserChord(e) && (e.key === "Enter" || e.key === " " || e.key === "ArrowDown")) {
|
|
221
223
|
e.preventDefault();
|
|
222
224
|
this.handlePanelOpen();
|
|
223
225
|
}
|
|
@@ -246,6 +248,10 @@ var TimePickerFoundation = class TimePickerFoundation extends BaseFoundation {
|
|
|
246
248
|
this.close();
|
|
247
249
|
this.adapter.notifyBlur(e);
|
|
248
250
|
};
|
|
251
|
+
/** Called for a focusin anywhere while the panel is shown; `root` contains the trigger the panel opens from */
|
|
252
|
+
handleDocumentFocusIn = (e, root) => {
|
|
253
|
+
if (root && !containsWithPopups(root, e.composedPath()[0]) && TimePickerFoundation.isPanelShown(this.getProps(), this.getStates())) this.close();
|
|
254
|
+
};
|
|
249
255
|
handleInputChange = (input) => {
|
|
250
256
|
this.setState({ inputValue: input });
|
|
251
257
|
const rangeSeparator = this.getProp("rangeSeparator");
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export declare const cssClasses: {
|
|
2
2
|
readonly PREFIX: "semi-tooltip";
|
|
3
3
|
};
|
|
4
|
+
/** Keys of `classNames` and `styles`; the root element takes `className` and `style` */
|
|
5
|
+
export type TooltipPart = 'wrapper';
|
|
4
6
|
export declare const strings: {
|
|
5
7
|
readonly POSITION_SET: readonly ["top", "topLeft", "topRight", "left", "leftTop", "leftBottom", "right", "rightTop", "rightBottom", "bottom", "bottomLeft", "bottomRight", "leftTopOver", "rightTopOver", "leftBottomOver", "rightBottomOver"];
|
|
6
8
|
readonly TRIGGER_SET: readonly ["hover", "focus", "click", "custom", "contextMenu"];
|
|
@@ -9,25 +9,19 @@ export interface TooltipAdapter<P extends TooltipBaseProps = TooltipBaseProps> e
|
|
|
9
9
|
insertPortal(): Pick<TooltipBaseState, 'portalTarget' | 'colorScheme'>;
|
|
10
10
|
/** Drops what the host renders into the popup itself (its content), right before the foundation unmounts the popup */
|
|
11
11
|
removePortal(): void;
|
|
12
|
-
/** Shows the popup in the top layer, unless it is still open (reopened during its exit animation) */
|
|
13
|
-
showPopover(): void;
|
|
14
|
-
hidePopover(): void;
|
|
15
|
-
/**
|
|
16
|
-
* Settles once the popup's running animations finish or are cancelled, read when called; null when none runs, so
|
|
17
|
-
* the step finishes at once
|
|
18
|
-
*/
|
|
19
|
-
waitAnimations(): Promise<unknown> | null;
|
|
20
12
|
/** Once per opening, after the enter animation; not for an opening closed before it finishes */
|
|
21
13
|
notifyAfterOpen(): void;
|
|
22
14
|
/** Once per opening, after the popup left or when the component unmounts while it is shown */
|
|
23
15
|
notifyAfterClose(): void;
|
|
24
|
-
/** Binds `handler` to every mousedown in the window until `unregisterClickOutsideHandler` */
|
|
25
|
-
registerClickOutsideHandler(handler: (e: MouseEvent) => void): void;
|
|
26
|
-
unregisterClickOutsideHandler(): void;
|
|
27
16
|
isEventInTrigger(e: MouseEvent): boolean;
|
|
28
|
-
/**
|
|
29
|
-
|
|
17
|
+
/**
|
|
18
|
+
* The popups of Tooltips rendered in this one's trigger or content: portaled out of its DOM, they still count as
|
|
19
|
+
* inside for the press outside check. Empty where the framework's own event path covers them (React).
|
|
20
|
+
*/
|
|
21
|
+
getNestedPopups(): (HTMLElement | null | undefined)[];
|
|
30
22
|
notifyClickOutSide(e: MouseEvent): void;
|
|
23
|
+
/** Runs `fn`, the foundation's own window listener, as one update: the onVisibleChange it reports lands before the DOM updates (Solid) */
|
|
24
|
+
batch(fn: () => void): void;
|
|
31
25
|
getPortalContainer(): HTMLElement | null;
|
|
32
26
|
setInitialFocus(): void;
|
|
33
27
|
/** The popup is shown and its enter transition has started; once per opening */
|
|
@@ -93,9 +87,11 @@ export default class Tooltip<P extends TooltipBaseProps = TooltipBaseProps> exte
|
|
|
93
87
|
* Hosts call this after every commit that changes `isInsert`, `transitionState` or the popup element, and again
|
|
94
88
|
* when a hidden popup shows again (Activity, KeepAlive), with the popup in the document. Entering shows the
|
|
95
89
|
* popover, positions it, checks a hover opening a task later and reports afterOpen once the enter animation ends;
|
|
96
|
-
* leaving waits for the exit animation, hides the popover, unmounts it unless
|
|
90
|
+
* leaving releases the Escape layer at once, waits for the exit animation, hides the popover, unmounts it unless
|
|
91
|
+
* keepDOM and reports afterClose. The animations are read once `beforeRead` settles when a host passes one: the
|
|
92
|
+
* phase's DOM is not there yet (Svelte), or what follows must not run inside the closing event (Solid).
|
|
97
93
|
*/
|
|
98
|
-
syncPopup: () => void;
|
|
94
|
+
syncPopup: (beforeRead?: Promise<unknown>) => void;
|
|
99
95
|
/** Hosts call this when the component unmounts for good, not when it is only hidden: reports a close still owed */
|
|
100
96
|
handleUnmount: () => void;
|
|
101
97
|
delayShow(): void;
|
|
@@ -104,6 +100,8 @@ export default class Tooltip<P extends TooltipBaseProps = TooltipBaseProps> exte
|
|
|
104
100
|
calcPosition: () => void;
|
|
105
101
|
delayHide(): void;
|
|
106
102
|
hide: () => void;
|
|
103
|
+
/** Hosts call this from a capture-phase mousedown on the popup content: a press bound for a nested popup portaled out of this DOM */
|
|
104
|
+
markPressInside: (e: Event) => void;
|
|
107
105
|
/**
|
|
108
106
|
* Escape that reaches the popup through the overlay stack (utils/layer) while it is the top layer, wherever the
|
|
109
107
|
* focus is. Returns whether the popup took the key; one that does not leaves it to the layer below.
|
|
@@ -2,6 +2,7 @@ import FocusTrapHandle from "../../base/focus-handle.js";
|
|
|
2
2
|
import BaseFoundation from "../../base/foundation.js";
|
|
3
3
|
import PopupLifecycle from "../../base/popup-lifecycle.js";
|
|
4
4
|
import ReleaseHolder from "../../base/release-holder.js";
|
|
5
|
+
import { isEventInside } from "../../utils/dom.js";
|
|
5
6
|
import { openLayer, popupTriggerSelector } from "../../utils/layer.js";
|
|
6
7
|
import warning from "../../utils/warning.js";
|
|
7
8
|
import { adjustPosition } from "./adjust-position.js";
|
|
@@ -42,6 +43,9 @@ var Tooltip = class Tooltip extends BaseFoundation {
|
|
|
42
43
|
#focusTrap = null;
|
|
43
44
|
#requestedVisible;
|
|
44
45
|
#hidesOnClickOutside = false;
|
|
46
|
+
#clickOutside = null;
|
|
47
|
+
#pressedInside = null;
|
|
48
|
+
#lastPopup = null;
|
|
45
49
|
#stopTracking = null;
|
|
46
50
|
#triggerVisible = true;
|
|
47
51
|
#applied = null;
|
|
@@ -84,7 +88,8 @@ var Tooltip = class Tooltip extends BaseFoundation {
|
|
|
84
88
|
batch.forEach((tooltip, i) => tooltip.#apply(layouts[i]));
|
|
85
89
|
}
|
|
86
90
|
#handleClickOutside = (e) => {
|
|
87
|
-
|
|
91
|
+
const popup = this.adapter.getPortalContainer();
|
|
92
|
+
if (!popup || this.adapter.isEventInTrigger(e) || e === this.#pressedInside || isEventInside(e, popup, ...this.adapter.getNestedPopups())) return;
|
|
88
93
|
this.adapter.notifyClickOutSide(e);
|
|
89
94
|
if (this.#hidesOnClickOutside) this.hide();
|
|
90
95
|
};
|
|
@@ -119,6 +124,13 @@ var Tooltip = class Tooltip extends BaseFoundation {
|
|
|
119
124
|
const { mouseEnterDelay, mouseLeaveDelay } = this.getProps();
|
|
120
125
|
warning((mouseLeaveDelay ?? 0) < (mouseEnterDelay ?? 0), strings.LEAVE_DELAY_WARNING);
|
|
121
126
|
}
|
|
127
|
+
#waitAnimations(beforeRead) {
|
|
128
|
+
const read = () => {
|
|
129
|
+
const animations = this.adapter.getPortalContainer()?.getAnimations() ?? [];
|
|
130
|
+
return animations.length ? Promise.allSettled(animations.map((animation) => animation.finished)) : null;
|
|
131
|
+
};
|
|
132
|
+
return beforeRead ? beforeRead.then(read) : read();
|
|
133
|
+
}
|
|
122
134
|
#afterAnimations(wait, step) {
|
|
123
135
|
const current = this.#syncStep;
|
|
124
136
|
const run = () => {
|
|
@@ -127,6 +139,14 @@ var Tooltip = class Tooltip extends BaseFoundation {
|
|
|
127
139
|
if (wait) wait.then(run);
|
|
128
140
|
else run();
|
|
129
141
|
}
|
|
142
|
+
#showPopover() {
|
|
143
|
+
const popup = this.adapter.getPortalContainer();
|
|
144
|
+
if (popup && !popup.matches(":popover-open")) popup.showPopover();
|
|
145
|
+
this.#lastPopup = popup ?? this.#lastPopup;
|
|
146
|
+
}
|
|
147
|
+
#hidePopover() {
|
|
148
|
+
(this.adapter.getPortalContainer() ?? this.#lastPopup)?.hidePopover();
|
|
149
|
+
}
|
|
130
150
|
#updateStateIfCursorOnTrigger() {
|
|
131
151
|
if (this.adapter.isTriggerHovered()) this.getState("triggerEventSet")[TRIGGER_EVENT_NAMES.mouseEnter]?.();
|
|
132
152
|
}
|
|
@@ -151,15 +171,15 @@ var Tooltip = class Tooltip extends BaseFoundation {
|
|
|
151
171
|
this.adapter.notifyOpen();
|
|
152
172
|
this.#reportVisibleChange(true);
|
|
153
173
|
}
|
|
154
|
-
#enter() {
|
|
174
|
+
#enter(beforeRead) {
|
|
155
175
|
this.#layer.hold(() => openLayer({
|
|
156
176
|
element: this.adapter.getPortalContainer(),
|
|
157
177
|
modal: false,
|
|
158
178
|
onEscape: this.handleEscape
|
|
159
179
|
}));
|
|
160
|
-
this
|
|
180
|
+
this.#showPopover();
|
|
161
181
|
this.#handleShown();
|
|
162
|
-
const entering = this
|
|
182
|
+
const entering = this.#waitAnimations(beforeRead);
|
|
163
183
|
this.#openTimer = setTimeout(() => {
|
|
164
184
|
if (!this.#openedHandled) {
|
|
165
185
|
this.#openedHandled = true;
|
|
@@ -170,11 +190,11 @@ var Tooltip = class Tooltip extends BaseFoundation {
|
|
|
170
190
|
});
|
|
171
191
|
});
|
|
172
192
|
}
|
|
173
|
-
#leave() {
|
|
193
|
+
#leave(beforeRead) {
|
|
174
194
|
this.#layer.release();
|
|
175
|
-
this.#afterAnimations(this
|
|
195
|
+
this.#afterAnimations(this.#waitAnimations(beforeRead), () => {
|
|
176
196
|
if (this.getState("transitionState") !== "leave") return;
|
|
177
|
-
this
|
|
197
|
+
this.#hidePopover();
|
|
178
198
|
if (!this.getProp("keepDOM")) this.#removePortal();
|
|
179
199
|
this.#lifecycle.ended(() => this.adapter.notifyAfterClose());
|
|
180
200
|
});
|
|
@@ -184,7 +204,16 @@ var Tooltip = class Tooltip extends BaseFoundation {
|
|
|
184
204
|
const hides = trigger === "click" || clickTriggerToHide || trigger === "contextMenu";
|
|
185
205
|
if (hides || trigger === "custom") {
|
|
186
206
|
this.#hidesOnClickOutside = hides;
|
|
187
|
-
this
|
|
207
|
+
this.#unwatchClickOutside();
|
|
208
|
+
const openingPress = window.event;
|
|
209
|
+
this.#clickOutside = (e) => e !== openingPress && this.adapter.batch(() => this.#handleClickOutside(e));
|
|
210
|
+
window.addEventListener("mousedown", this.#clickOutside);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
#unwatchClickOutside() {
|
|
214
|
+
if (this.#clickOutside) {
|
|
215
|
+
window.removeEventListener("mousedown", this.#clickOutside);
|
|
216
|
+
this.#clickOutside = null;
|
|
188
217
|
}
|
|
189
218
|
}
|
|
190
219
|
#generateEvent(types) {
|
|
@@ -629,12 +658,12 @@ var Tooltip = class Tooltip extends BaseFoundation {
|
|
|
629
658
|
clearTimeout(this.#openTimer);
|
|
630
659
|
clearTimeout(this.#cursorTimer);
|
|
631
660
|
this.#layer.release();
|
|
632
|
-
if (this.getState("isInsert")) this
|
|
661
|
+
if (this.getState("isInsert")) this.#hidePopover();
|
|
633
662
|
if (this.getState("transitionState") === "leave" && !this.getProp("keepDOM")) this.#removePortal();
|
|
634
663
|
this.#mounted = false;
|
|
635
664
|
this.#requestedVisible = void 0;
|
|
636
665
|
this.#endTracking();
|
|
637
|
-
this
|
|
666
|
+
this.#unwatchClickOutside();
|
|
638
667
|
this.#clearDelayTimer();
|
|
639
668
|
}
|
|
640
669
|
handlePropsChange(prev) {
|
|
@@ -650,15 +679,17 @@ var Tooltip = class Tooltip extends BaseFoundation {
|
|
|
650
679
|
* Hosts call this after every commit that changes `isInsert`, `transitionState` or the popup element, and again
|
|
651
680
|
* when a hidden popup shows again (Activity, KeepAlive), with the popup in the document. Entering shows the
|
|
652
681
|
* popover, positions it, checks a hover opening a task later and reports afterOpen once the enter animation ends;
|
|
653
|
-
* leaving waits for the exit animation, hides the popover, unmounts it unless
|
|
682
|
+
* leaving releases the Escape layer at once, waits for the exit animation, hides the popover, unmounts it unless
|
|
683
|
+
* keepDOM and reports afterClose. The animations are read once `beforeRead` settles when a host passes one: the
|
|
684
|
+
* phase's DOM is not there yet (Svelte), or what follows must not run inside the closing event (Solid).
|
|
654
685
|
*/
|
|
655
|
-
syncPopup = () => {
|
|
686
|
+
syncPopup = (beforeRead) => {
|
|
656
687
|
this.#syncStep++;
|
|
657
688
|
clearTimeout(this.#openTimer);
|
|
658
689
|
if (!this.getState("isInsert") || !this.adapter.getPortalContainer()) return;
|
|
659
690
|
const phase = this.getState("transitionState");
|
|
660
|
-
if (phase === "enter") this.#enter();
|
|
661
|
-
else if (phase === "leave") this.#leave();
|
|
691
|
+
if (phase === "enter") this.#enter(beforeRead);
|
|
692
|
+
else if (phase === "leave") this.#leave(beforeRead);
|
|
662
693
|
};
|
|
663
694
|
/** Hosts call this when the component unmounts for good, not when it is only hidden: reports a close still owed */
|
|
664
695
|
handleUnmount = () => {
|
|
@@ -711,16 +742,24 @@ var Tooltip = class Tooltip extends BaseFoundation {
|
|
|
711
742
|
this.#open = false;
|
|
712
743
|
this.#clearDelayTimer();
|
|
713
744
|
if (!this.#mounted) return;
|
|
714
|
-
this
|
|
745
|
+
this.#unwatchClickOutside();
|
|
715
746
|
this.#endTracking();
|
|
716
747
|
if (wasOpen || this.getState("visible")) {
|
|
717
748
|
this.setState({
|
|
718
749
|
transitionState: "leave",
|
|
719
750
|
visible: false
|
|
720
751
|
});
|
|
752
|
+
if (!this.#openReported) {
|
|
753
|
+
this.#openReported = true;
|
|
754
|
+
this.#reportVisibleChange(true);
|
|
755
|
+
}
|
|
721
756
|
this.#reportVisibleChange(false);
|
|
722
757
|
}
|
|
723
758
|
};
|
|
759
|
+
/** Hosts call this from a capture-phase mousedown on the popup content: a press bound for a nested popup portaled out of this DOM */
|
|
760
|
+
markPressInside = (e) => {
|
|
761
|
+
this.#pressedInside = e;
|
|
762
|
+
};
|
|
724
763
|
/**
|
|
725
764
|
* Escape that reaches the popup through the overlay stack (utils/layer) while it is the top layer, wherever the
|
|
726
765
|
* focus is. Returns whether the popup took the key; one that does not leaves it to the layer below.
|
|
@@ -2,6 +2,8 @@ export declare const cssClasses: {
|
|
|
2
2
|
PREFIX: string;
|
|
3
3
|
PREFIX_OPTION: string;
|
|
4
4
|
};
|
|
5
|
+
/** Keys of `classNames` and `styles`; the root element takes `className` and `style` */
|
|
6
|
+
export type TreePart = 'search';
|
|
5
7
|
export declare const strings: {
|
|
6
8
|
JSON_KEY_SPLIT: string;
|
|
7
9
|
};
|