@type-dom/ui 0.0.8 → 0.0.10
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/README.md +44 -44
- package/package.json +2 -8
- package/src/aria.d.ts +0 -17
- package/src/aria.js +0 -18
- package/src/components/basic/td-button/td-button.abstract.d.ts +2 -3
- package/src/components/basic/td-button/td-button.abstract.js +30 -26
- package/src/components/basic/td-button/td-button.interface.d.ts +0 -1
- package/src/components/basic/td-button-group/td-button-group.class.d.ts +2 -3
- package/src/components/basic/td-button-group/td-button-group.class.js +14 -16
- package/src/components/basic/td-container/td-aside/td-aside.class.js +2 -2
- package/src/components/basic/td-container/td-container.class.js +5 -5
- package/src/components/basic/td-container/td-container.js +1 -1
- package/src/components/basic/td-container/td-footer/td-footer.class.js +2 -2
- package/src/components/basic/td-container/td-header/td-header.class.js +3 -3
- package/src/components/basic/td-container/td-main/td-main.class.js +2 -2
- package/src/components/basic/td-icon/td-icon.class.js +20 -20
- package/src/components/basic/td-layout/td-col/td-col.class.d.ts +5 -2
- package/src/components/basic/td-layout/td-col/td-col.class.js +80 -80
- package/src/components/basic/td-layout/td-row/td-row.class.js +13 -13
- package/src/components/basic/td-link/td-link.class.d.ts +0 -1
- package/src/components/basic/td-link/td-link.class.js +17 -19
- package/src/components/basic/td-scrollbar/bar/bar.class.js +3 -3
- package/src/components/basic/td-scrollbar/td-scrollbar.class.js +5 -5
- package/src/components/basic/td-scrollbar/thumb/thumb.class.js +3 -3
- package/src/components/basic/td-space/td-space.class.js +10 -10
- package/src/components/basic/td-text/td-text.class.js +12 -9
- package/src/components/data/td-avatar/td-avatar.class.js +12 -13
- package/src/components/data/td-badge/td-badge.class.js +9 -8
- package/src/components/data/td-card/td-card.class.js +7 -7
- package/src/components/data/td-check-tag/td-check-tag.class.d.ts +0 -1
- package/src/components/data/td-check-tag/td-check-tag.class.js +9 -11
- package/src/components/data/td-collapse/td-collapse.class.js +2 -2
- package/src/components/data/td-collapse-item/td-collapse-item.class.js +15 -16
- package/src/components/data/td-collapse-transition/td-collapse-transition.util.js +14 -14
- package/src/components/data/td-count-down/td-count-down.class.js +1 -1
- package/src/components/data/td-descriptions/td-descriptions-row.js +2 -2
- package/src/components/data/td-descriptions/td-descriptions.class.js +8 -8
- package/src/components/data/td-descriptions/td-descritions-cell.js +14 -14
- package/src/components/data/td-descriptions-item/td-descriptions-item.class.js +1 -1
- package/src/components/data/td-empty/img-empty.class.js +3 -3
- package/src/components/data/td-empty/td-empty.class.js +4 -4
- package/src/components/data/td-image/td-image.class.js +6 -6
- package/src/components/data/td-image-viewer/td-image-viewer.class.d.ts +2 -1
- package/src/components/data/td-image-viewer/td-image-viewer.class.js +13 -10
- package/src/components/data/td-result/td-result.class.js +3 -3
- package/src/components/data/td-segmented/td-segmented.class.js +14 -17
- package/src/components/data/td-statistic/td-statistic.abstract.js +2 -2
- package/src/components/data/td-tag/td-tag.class.js +9 -9
- package/src/components/feedback/index.d.ts +2 -2
- package/src/components/feedback/index.js +5 -6
- package/src/components/feedback/td-alert/td-alert.class.js +9 -9
- package/src/components/feedback/td-dialog/td-dialog.class.js +5 -5
- package/src/components/feedback/td-dialog-content/td-dialog-content.class.js +4 -4
- package/src/components/feedback/td-drawer/td-drawer.class.js +10 -12
- package/src/components/feedback/td-focus-trap/td-focus-trap.class.d.ts +19 -1
- package/src/components/feedback/td-focus-trap/td-focus-trap.class.js +223 -48
- package/src/components/feedback/td-focus-trap/tokens.d.ts +2 -1
- package/src/components/feedback/td-focus-trap/utils.d.ts +1 -1
- package/src/components/feedback/td-focus-trap/utils.js +9 -11
- package/src/components/feedback/td-loading/td-loading.class.d.ts +2 -0
- package/src/components/feedback/td-loading/td-loading.class.js +7 -1
- package/src/components/feedback/td-message/td-message.class.d.ts +3 -2
- package/src/components/feedback/td-message/td-message.class.js +18 -18
- package/src/components/feedback/td-message/td-message.style.js +2 -1
- package/src/components/feedback/td-message-box/td-message-box.class.d.ts +5 -3
- package/src/components/feedback/td-message-box/td-message-box.class.js +79 -74
- package/src/components/feedback/td-message-box/td-message-box.interface.d.ts +2 -1
- package/src/components/feedback/td-notification/td-notification.class.d.ts +3 -2
- package/src/components/feedback/td-notification/td-notification.class.js +26 -26
- package/src/components/feedback/td-notification/td-notification.style.js +6 -6
- package/src/components/feedback/td-only-child/td-only-child.class.d.ts +7 -0
- package/src/components/feedback/td-only-child/td-only-child.class.js +74 -0
- package/src/components/feedback/td-overlay/td-overlay.class.d.ts +1 -1
- package/src/components/feedback/td-overlay/td-overlay.class.js +5 -5
- package/src/components/feedback/td-popper/arrow/arrow.class.d.ts +6 -0
- package/src/components/feedback/td-popper/arrow/arrow.class.js +22 -3
- package/src/components/feedback/td-popper/composable/use-focus-trap.d.ts +0 -0
- package/src/components/feedback/td-popper/composable/use-focus-trap.js +1 -0
- package/src/components/feedback/td-popper/content/content.class.d.ts +1 -0
- package/src/components/feedback/td-popper/content/content.class.js +25 -4
- package/src/components/feedback/td-popper/content/content.const.d.ts +3 -0
- package/src/components/feedback/td-popper/content/content.const.js +29 -0
- package/src/components/feedback/td-popper/content/content.interface.d.ts +9 -0
- package/src/components/feedback/td-popper/td-popper.class.d.ts +1 -1
- package/src/components/feedback/td-popper/td-popper.class.js +35 -2
- package/src/components/feedback/td-popper/td-popper.const.d.ts +21 -0
- package/src/components/feedback/td-popper/td-popper.const.js +5 -0
- package/src/components/feedback/td-popper/trigger/trigger.class.d.ts +11 -0
- package/src/components/feedback/td-popper/trigger/trigger.class.js +96 -1
- package/src/components/feedback/td-popper/trigger/trigger.const.d.ts +1 -0
- package/src/components/feedback/td-popper/trigger/trigger.const.js +12 -0
- package/src/components/feedback/td-popper/trigger/trigger.interface.d.ts +1 -0
- package/src/components/feedback/td-tooltip/content/content.class.js +1 -1
- package/src/components/feedback/td-tooltip/td-tooltip.class.js +1 -1
- package/src/components/feedback/td-tooltip/trigger/trigger.class.js +1 -1
- package/src/components/form/checkbox-group/checkbox-group.class.js +6 -7
- package/src/components/form/checkbox-group/checkbox-option/checkbox-option.class.d.ts +1 -1
- package/src/components/form/checkbox-group/checkbox-option/checkbox-option.class.js +4 -4
- package/src/components/form/field-item/cascade/field-cascade.abstract.d.ts +1 -1
- package/src/components/form/field-item/cascade/field-cascade.abstract.js +8 -8
- package/src/components/form/field-item/field-item.abstract.js +3 -3
- package/src/components/form/field-item/input/field-input.abstract.d.ts +1 -1
- package/src/components/form/field-item/input/field-input.abstract.js +8 -8
- package/src/components/form/field-item/options/field-options.abstract.d.ts +1 -3
- package/src/components/form/field-item/options/field-options.abstract.js +32 -30
- package/src/components/form/field-item/radio/field-radio.abstract.d.ts +1 -1
- package/src/components/form/field-item/radio/field-radio.abstract.js +32 -35
- package/src/components/form/field-item/select/field-select.abstract.d.ts +1 -1
- package/src/components/form/field-item/select/field-select.abstract.js +5 -5
- package/src/components/form/field-item/span/field-span.abstract.js +5 -5
- package/src/components/form/field-item/textarea/field-textarea.abstract.js +5 -5
- package/src/components/form/field-select/field-select.class.d.ts +1 -1
- package/src/components/form/field-select/field-select.class.js +7 -8
- package/src/components/form/field-select/option/option.class.js +1 -3
- package/src/components/form/radio-group/radio-group.class.js +6 -7
- package/src/components/form/radio-group/radio-option/radio-option.class.d.ts +0 -1
- package/src/components/form/radio-group/radio-option/radio-option.class.js +6 -8
- package/src/components/form/select/select.class.d.ts +1 -1
- package/src/components/form/select/select.class.js +4 -4
- package/src/components/form/td-checkbox/td-checkbox.class.js +3 -3
- package/src/components/form/td-checkbox/td-checkbox.style.js +2 -2
- package/src/components/form/td-checkbox-button/td-checkbox-button.class.js +3 -3
- package/src/components/form/td-checkbox-group/td-checkbox-group.class.js +3 -3
- package/src/components/form/td-form/td-form.class.js +5 -3
- package/src/components/form/td-form-item/td-form-item.class.js +16 -16
- package/src/components/form/td-input/td-input-field.class.js +8 -8
- package/src/components/form/td-input/td-input.class.d.ts +0 -1
- package/src/components/form/td-input/td-input.class.js +9 -11
- package/src/components/form/td-input/widget/prefix.js +1 -1
- package/src/components/form/td-input/widget/suffix.js +3 -3
- package/src/components/form/td-input/widget/td-input-wrapper.class.js +12 -11
- package/src/components/form/td-input/widget/td-textarea-wrapper.js +3 -3
- package/src/components/form/td-input/widget/utils.js +8 -8
- package/src/components/form/td-option/td-option.class.js +3 -3
- package/src/components/form/td-option-group/td-option-group.class.js +3 -3
- package/src/components/form/td-radio/td-radio.class.d.ts +0 -1
- package/src/components/form/td-radio/td-radio.class.js +50 -53
- package/src/components/form/td-radio-button/td-radio-button.class.d.ts +0 -1
- package/src/components/form/td-radio-button/td-radio-button.class.js +46 -49
- package/src/components/form/td-radio-group/td-radio-group.class.js +3 -4
- package/src/components/form/td-select/dropdown/dropdown.class.js +2 -2
- package/src/components/form/td-select/td-select.class.js +2 -2
- package/src/components/form/td-switch/td-switch.class.d.ts +1 -1
- package/src/components/form/td-switch/td-switch.class.js +21 -21
- package/src/components/form/td-switch/widget/td-switch-core.js +10 -10
- package/src/components/form/td-switch/widget/td-switch-left.js +3 -3
- package/src/components/form/td-switch/widget/td-switch-right.js +2 -2
- package/src/components/navigation/td-affix/td-affix.class.d.ts +3 -0
- package/src/components/navigation/td-affix/td-affix.class.js +22 -20
- package/src/components/navigation/td-anchor/td-anchor-link/td-anchor-link.class.js +1 -1
- package/src/components/navigation/td-anchor/td-anchor.class.js +10 -10
- package/src/components/navigation/td-backtop/td-backtop.class.d.ts +5 -3
- package/src/components/navigation/td-backtop/td-backtop.class.js +41 -32
- package/src/components/navigation/td-backtop/td-backtop.interface.d.ts +3 -0
- package/src/components/navigation/td-backtop/use-backtop.d.ts +7 -0
- package/src/components/navigation/td-backtop/use-backtop.js +44 -0
- package/src/components/navigation/td-breadcrumb/td-breadcrumb.class.js +4 -4
- package/src/components/navigation/td-breadcrumb-item/td-breadcrumb-item.class.js +3 -3
- package/src/components/navigation/td-menu/td-menu.class.js +5 -5
- package/src/components/navigation/td-menu/td-menu.interface.d.ts +2 -1
- package/src/components/navigation/td-tabs/td-tab-bar.class.js +5 -5
- package/src/components/navigation/td-tabs/td-tab-nav.class.js +14 -14
- package/src/components/navigation/td-tabs/td-tab-pane.class.js +3 -3
- package/src/components/navigation/td-tabs/td-tabs.class.js +4 -4
- package/src/components/others/collapsible-box/collapsible-box.js +2 -2
- package/src/components/others/collapsible-box/contents/contents.js +2 -2
- package/src/components/others/collapsible-box/heading/expand-heading.d.ts +1 -1
- package/src/components/others/collapsible-box/heading/expand-heading.js +11 -11
- package/src/components/others/custom-block/custom-block.js +2 -2
- package/src/components/others/example/example-float-control.d.ts +1 -1
- package/src/components/others/example/example-float-control.js +8 -8
- package/src/components/others/example/example-showcase.js +3 -3
- package/src/components/others/example/example-source-wrapper.d.ts +6 -2
- package/src/components/others/example/example-source-wrapper.js +3 -3
- package/src/components/others/example/example.d.ts +1 -2
- package/src/components/others/example/example.js +4 -4
- package/src/components/others/example/op-btns.js +9 -10
- package/src/components/others/menus/menu.d.ts +10 -5
- package/src/components/others/menus/menu.js +35 -33
- package/src/components/others/menus/menus.d.ts +6 -1
- package/src/components/others/menus/menus.js +46 -24
- package/src/components/others/td-divider/td-divider.class.js +8 -8
- package/src/hooks/index.d.ts +3 -0
- package/src/hooks/index.js +6 -0
- package/src/hooks/use-cursor.d.ts +1 -0
- package/src/hooks/use-cursor.js +56 -0
- package/src/hooks/use-escape-keydown.d.ts +4 -0
- package/src/hooks/use-escape-keydown.js +31 -0
- package/src/hooks/use-forward-ref.d.ts +13 -0
- package/src/hooks/use-forward-ref.js +27 -0
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/styles/var.d.ts +1 -1
- package/src/styles/var.js +2 -2
- package/src/ui/ui.abstract.d.ts +1 -1
- package/src/ui/ui.abstract.js +2 -2
- package/src/components/feedback/dialog/dialog.class.d.ts +0 -7
- package/src/components/feedback/dialog/dialog.class.js +0 -21
- package/src/components/feedback/dialog/dialog.interface.d.ts +0 -4
- package/src/components/feedback/dialog/dialog.interface.js +0 -2
- package/src/components/feedback/message-box/message-box.d.ts +0 -9
- package/src/components/feedback/message-box/message-box.interface.d.ts +0 -4
- package/src/components/feedback/message-box/message-box.interface.js +0 -2
- package/src/components/feedback/message-box/message-box.js +0 -33
- package/src/components/feedback/overlay/container/body/body.d.ts +0 -7
- package/src/components/feedback/overlay/container/body/body.js +0 -17
- package/src/components/feedback/overlay/container/container.d.ts +0 -15
- package/src/components/feedback/overlay/container/container.js +0 -38
- package/src/components/feedback/overlay/container/footer/cancel-button/cancel-button.d.ts +0 -8
- package/src/components/feedback/overlay/container/footer/cancel-button/cancel-button.js +0 -32
- package/src/components/feedback/overlay/container/footer/confirm-button/confirm-button.d.ts +0 -9
- package/src/components/feedback/overlay/container/footer/confirm-button/confirm-button.js +0 -32
- package/src/components/feedback/overlay/container/footer/footer.d.ts +0 -10
- package/src/components/feedback/overlay/container/footer/footer.js +0 -47
- package/src/components/feedback/overlay/container/header/close-button/close-button.d.ts +0 -11
- package/src/components/feedback/overlay/container/header/close-button/close-button.js +0 -34
- package/src/components/feedback/overlay/container/header/header.d.ts +0 -12
- package/src/components/feedback/overlay/container/header/header.js +0 -25
- package/src/components/feedback/overlay/container/header/title/title.d.ts +0 -9
- package/src/components/feedback/overlay/container/header/title/title.js +0 -19
- package/src/components/feedback/overlay/overlay.abstract.d.ts +0 -13
- package/src/components/feedback/overlay/overlay.abstract.js +0 -60
|
@@ -1,18 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TdFocusTrap = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const utils_1 = require("@type-dom/utils");
|
|
6
|
+
const framework_1 = require("@type-dom/framework");
|
|
7
|
+
const use_escape_keydown_1 = require("../../../hooks/use-escape-keydown");
|
|
4
8
|
const ui_abstract_1 = require("../../../ui/ui.abstract");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
9
|
+
const utils_2 = require("./utils");
|
|
10
|
+
const tokens_1 = require("./tokens");
|
|
7
11
|
class TdFocusTrap extends ui_abstract_1.UI {
|
|
8
12
|
constructor(params = {}) {
|
|
9
13
|
super(params, 'fragment');
|
|
10
14
|
this.className = 'TdFocusTrap';
|
|
11
15
|
this.inheritAttrs = false;
|
|
12
|
-
this.props = this.
|
|
16
|
+
this.props = this.useParams(params);
|
|
13
17
|
}
|
|
14
|
-
|
|
15
|
-
const
|
|
18
|
+
setup() {
|
|
19
|
+
const { focusReason } = (0, utils_2.useFocusReason)();
|
|
20
|
+
this.focusReason = focusReason;
|
|
21
|
+
this.escapeKeydown = (0, use_escape_keydown_1.useEscapeKeydown)((event) => {
|
|
22
|
+
var _a;
|
|
23
|
+
if (this.props.trapped && !((_a = this.focusLayer) === null || _a === void 0 ? void 0 : _a.paused)) {
|
|
24
|
+
this.emit('release-requested', event);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
this.focusLayer = {
|
|
16
28
|
paused: false,
|
|
17
29
|
pause() {
|
|
18
30
|
this.paused = true;
|
|
@@ -21,61 +33,224 @@ class TdFocusTrap extends ui_abstract_1.UI {
|
|
|
21
33
|
this.paused = false;
|
|
22
34
|
}
|
|
23
35
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
this.handelKeydown = this.onKeydown;
|
|
37
|
+
this.provide(tokens_1.FOCUS_TRAP_INJECTION_KEY, {
|
|
38
|
+
focusTrapRef: this.forwardRef,
|
|
39
|
+
onKeydown: this.onKeydown
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
mounted() {
|
|
43
|
+
var _a;
|
|
44
|
+
(_a = this.escapeKeydown) === null || _a === void 0 ? void 0 : _a.mounted();
|
|
45
|
+
if (this.props.trapped) {
|
|
46
|
+
this.startTrap();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
beforeDestroy() {
|
|
50
|
+
var _a;
|
|
51
|
+
(_a = this.escapeKeydown) === null || _a === void 0 ? void 0 : _a.beforeDestroy();
|
|
52
|
+
}
|
|
53
|
+
onKeydown(e) {
|
|
54
|
+
var _a;
|
|
55
|
+
if (!this.props.loop && !this.props.trapped) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if ((_a = this.focusLayer) === null || _a === void 0 ? void 0 : _a.paused) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const { key, altKey, ctrlKey, metaKey, currentTarget, shiftKey } = e;
|
|
62
|
+
const { loop } = this.props;
|
|
63
|
+
const isTabbing = key === utils_1.EVENT_CODE.tab && !altKey && !ctrlKey && !metaKey;
|
|
64
|
+
const currentFocusingEl = document.activeElement;
|
|
65
|
+
if (isTabbing && currentFocusingEl) {
|
|
66
|
+
const container = currentTarget;
|
|
67
|
+
const [first, last] = (0, utils_2.getEdges)(container);
|
|
68
|
+
const isTabbable = first && last;
|
|
69
|
+
if (isTabbable) {
|
|
70
|
+
if (!shiftKey && currentFocusingEl === last) {
|
|
71
|
+
const focusoutPreventedEvent = (0, utils_2.createFocusOutPreventedEvent)({
|
|
72
|
+
focusReason: this.focusReason
|
|
73
|
+
});
|
|
74
|
+
// emit('focusout-prevented', focusoutPreventedEvent);
|
|
75
|
+
if (!focusoutPreventedEvent.defaultPrevented) {
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
if (loop) {
|
|
78
|
+
(0, utils_2.tryFocus)(first, true);
|
|
46
79
|
}
|
|
47
80
|
}
|
|
48
81
|
}
|
|
49
|
-
else
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
82
|
+
else if (shiftKey &&
|
|
83
|
+
[first, container].includes(currentFocusingEl)) {
|
|
84
|
+
const focusoutPreventedEvent = (0, utils_2.createFocusOutPreventedEvent)({
|
|
85
|
+
focusReason: this.focusReason
|
|
86
|
+
});
|
|
87
|
+
// emit('focusout-prevented', focusoutPreventedEvent);
|
|
88
|
+
if (!focusoutPreventedEvent.defaultPrevented) {
|
|
89
|
+
e.preventDefault();
|
|
90
|
+
if (loop) {
|
|
91
|
+
(0, utils_2.tryFocus)(last, true);
|
|
59
92
|
}
|
|
60
93
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
if (currentFocusingEl === container) {
|
|
98
|
+
const focusoutPreventedEvent = (0, utils_2.createFocusOutPreventedEvent)({
|
|
99
|
+
focusReason: this.focusReason
|
|
100
|
+
});
|
|
101
|
+
// emit('focusout-prevented', focusoutPreventedEvent);
|
|
102
|
+
if (!focusoutPreventedEvent.defaultPrevented) {
|
|
103
|
+
e.preventDefault();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
setFocusTrapEl(el) {
|
|
110
|
+
if (el) {
|
|
111
|
+
this.props.focusTrapEl = el;
|
|
112
|
+
this.forwardRef = el;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
setForwardRef(newEl, oldEl) {
|
|
116
|
+
if (newEl) {
|
|
117
|
+
newEl.addEventListener('keydown', this.onKeydown);
|
|
118
|
+
newEl.addEventListener('focusin', this.onFocusIn);
|
|
119
|
+
newEl.addEventListener('focusout', this.onFocusOut);
|
|
120
|
+
}
|
|
121
|
+
if (oldEl) {
|
|
122
|
+
oldEl.removeEventListener('keydown', this.onKeydown);
|
|
123
|
+
oldEl.removeEventListener('focusin', this.onFocusIn);
|
|
124
|
+
oldEl.removeEventListener('focusout', this.onFocusOut);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
trapOnFocus(e) {
|
|
128
|
+
this.emit(tokens_1.ON_TRAP_FOCUS_EVT, e);
|
|
129
|
+
}
|
|
130
|
+
releaseOnFocus(e) {
|
|
131
|
+
this.emit(tokens_1.ON_RELEASE_FOCUS_EVT, e);
|
|
132
|
+
}
|
|
133
|
+
onFocusIn(e) {
|
|
134
|
+
var _a;
|
|
135
|
+
const trapContainer = this.forwardRef;
|
|
136
|
+
if (!trapContainer) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const target = e.target;
|
|
140
|
+
const relatedTarget = e.relatedTarget;
|
|
141
|
+
const isFocusedInTrap = target && trapContainer.contains(target);
|
|
142
|
+
if (!this.props.trapped) {
|
|
143
|
+
const isPrevFocusedInTrap = relatedTarget && trapContainer.contains(relatedTarget);
|
|
144
|
+
if (!isPrevFocusedInTrap) {
|
|
145
|
+
this.lastFocusBeforeTrapped = relatedTarget;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (isFocusedInTrap) {
|
|
149
|
+
this.emit('focusin', e);
|
|
150
|
+
}
|
|
151
|
+
if ((_a = this.focusLayer) === null || _a === void 0 ? void 0 : _a.paused) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (this.props.trapped) {
|
|
155
|
+
if (isFocusedInTrap) {
|
|
156
|
+
this.lastFocusAfterTrapped = target;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
(0, utils_2.tryFocus)(this.lastFocusAfterTrapped, true);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
;
|
|
164
|
+
onFocusOut(e) {
|
|
165
|
+
var _a;
|
|
166
|
+
const trapContainer = this.forwardRef;
|
|
167
|
+
if (((_a = this.focusLayer) === null || _a === void 0 ? void 0 : _a.paused) || !trapContainer) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (this.props.trapped) {
|
|
171
|
+
const relatedTarget = e
|
|
172
|
+
.relatedTarget;
|
|
173
|
+
if (!(0, utils_1.isNil)(relatedTarget) && !trapContainer.contains(relatedTarget)) {
|
|
174
|
+
// Give embedded focus layer time to pause this layer before reclaiming focus
|
|
175
|
+
// And only reclaim focus if it should currently be trapping
|
|
176
|
+
setTimeout(() => {
|
|
177
|
+
var _a;
|
|
178
|
+
if (!((_a = this.focusLayer) === null || _a === void 0 ? void 0 : _a.paused) && this.props.trapped) {
|
|
179
|
+
const focusoutPreventedEvent = (0, utils_2.createFocusOutPreventedEvent)({
|
|
180
|
+
focusReason: this.focusReason
|
|
65
181
|
});
|
|
66
|
-
|
|
182
|
+
this.emit('focusout-prevented', focusoutPreventedEvent);
|
|
67
183
|
if (!focusoutPreventedEvent.defaultPrevented) {
|
|
68
|
-
|
|
69
|
-
if (loop)
|
|
70
|
-
(0, utils_1.tryFocus)(last, true);
|
|
184
|
+
(0, utils_2.tryFocus)(this.lastFocusAfterTrapped, true);
|
|
71
185
|
}
|
|
72
186
|
}
|
|
187
|
+
}, 0);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
const target = e.target;
|
|
192
|
+
const isFocusedInTrap = target && trapContainer.contains(target);
|
|
193
|
+
if (!isFocusedInTrap)
|
|
194
|
+
this.emit('focusout', e);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
startTrap() {
|
|
198
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
199
|
+
// Wait for forwardRef to resolve
|
|
200
|
+
yield (0, framework_1.nextTick)();
|
|
201
|
+
const trapContainer = this.forwardRef;
|
|
202
|
+
if (trapContainer) {
|
|
203
|
+
utils_2.focusableStack.push(this.focusLayer);
|
|
204
|
+
const prevFocusedElement = trapContainer.contains(document.activeElement)
|
|
205
|
+
? this.lastFocusBeforeTrapped
|
|
206
|
+
: document.activeElement;
|
|
207
|
+
this.lastFocusBeforeTrapped = prevFocusedElement;
|
|
208
|
+
const isPrevFocusContained = trapContainer.contains(prevFocusedElement);
|
|
209
|
+
if (!isPrevFocusContained) {
|
|
210
|
+
const focusEvent = new Event(tokens_1.FOCUS_AFTER_TRAPPED, tokens_1.FOCUS_AFTER_TRAPPED_OPTS);
|
|
211
|
+
trapContainer.addEventListener(tokens_1.FOCUS_AFTER_TRAPPED, this.trapOnFocus);
|
|
212
|
+
trapContainer.dispatchEvent(focusEvent);
|
|
213
|
+
if (!focusEvent.defaultPrevented) {
|
|
214
|
+
(0, framework_1.nextTick)(() => {
|
|
215
|
+
let focusStartEl = this.props.focusStartEl;
|
|
216
|
+
if (!(0, utils_1.isString)(focusStartEl)) {
|
|
217
|
+
(0, utils_2.tryFocus)(focusStartEl);
|
|
218
|
+
if (document.activeElement !== focusStartEl) {
|
|
219
|
+
focusStartEl = 'first';
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (focusStartEl === 'first') {
|
|
223
|
+
(0, utils_2.focusFirstDescendant)((0, utils_2.obtainAllFocusableElements)(trapContainer), true);
|
|
224
|
+
}
|
|
225
|
+
if (document.activeElement === prevFocusedElement ||
|
|
226
|
+
focusStartEl === 'container') {
|
|
227
|
+
(0, utils_2.tryFocus)(trapContainer);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
73
231
|
}
|
|
74
232
|
}
|
|
75
|
-
};
|
|
76
|
-
this.addEvents({
|
|
77
|
-
keydown: (evt) => onKeydown(evt)
|
|
78
233
|
});
|
|
79
234
|
}
|
|
235
|
+
stopTrap() {
|
|
236
|
+
var _a;
|
|
237
|
+
const trapContainer = this.forwardRef;
|
|
238
|
+
if (trapContainer) {
|
|
239
|
+
trapContainer.removeEventListener(tokens_1.FOCUS_AFTER_TRAPPED, this.trapOnFocus);
|
|
240
|
+
const releasedEvent = new CustomEvent(tokens_1.FOCUS_AFTER_RELEASED, Object.assign(Object.assign({}, tokens_1.FOCUS_AFTER_TRAPPED_OPTS), { detail: {
|
|
241
|
+
focusReason: this.focusReason
|
|
242
|
+
} }));
|
|
243
|
+
trapContainer.addEventListener(tokens_1.FOCUS_AFTER_RELEASED, this.releaseOnFocus);
|
|
244
|
+
trapContainer.dispatchEvent(releasedEvent);
|
|
245
|
+
if (!releasedEvent.defaultPrevented &&
|
|
246
|
+
(this.focusReason == 'keyboard' ||
|
|
247
|
+
!(0, utils_2.isFocusCausedByUserEvent)() ||
|
|
248
|
+
trapContainer.contains(document.activeElement))) {
|
|
249
|
+
(0, utils_2.tryFocus)((_a = this.lastFocusBeforeTrapped) !== null && _a !== void 0 ? _a : document.body);
|
|
250
|
+
}
|
|
251
|
+
trapContainer.removeEventListener(tokens_1.FOCUS_AFTER_RELEASED, this.releaseOnFocus);
|
|
252
|
+
utils_2.focusableStack.remove(this.focusLayer);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
80
255
|
}
|
|
81
256
|
exports.TdFocusTrap = TdFocusTrap;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { InjectionKey } from '@type-dom/framework';
|
|
1
2
|
export declare const FOCUS_AFTER_TRAPPED = "focus-trap.focus-after-trapped";
|
|
2
3
|
export declare const FOCUS_AFTER_RELEASED = "focus-trap.focus-after-released";
|
|
3
4
|
export declare const FOCUSOUT_PREVENTED = "focus-trap.focusout-prevented";
|
|
@@ -9,4 +10,4 @@ export type FocusTrapInjectionContext = {
|
|
|
9
10
|
focusTrapRef: HTMLElement | undefined;
|
|
10
11
|
onKeydown: (e: KeyboardEvent) => void;
|
|
11
12
|
};
|
|
12
|
-
export declare const FOCUS_TRAP_INJECTION_KEY:
|
|
13
|
+
export declare const FOCUS_TRAP_INJECTION_KEY: InjectionKey<FocusTrapInjectionContext>;
|
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createFocusOutPreventedEvent = exports.useFocusReason = exports.isFocusCausedByUserEvent = exports.focusableStack = exports.focusFirstDescendant = exports.tryFocus = exports.getEdges = exports.isHidden = exports.getVisibleElement = exports.obtainAllFocusableElements = void 0;
|
|
4
4
|
// import { onBeforeUnmount, onMounted, ref } from 'vue'
|
|
5
|
-
const framework_1 = require("@type-dom/framework");
|
|
6
5
|
const tokens_1 = require("./tokens");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
let focusReasonUserCount = 0;
|
|
6
|
+
let focusReason;
|
|
7
|
+
let lastUserFocusTimestamp = 0;
|
|
8
|
+
let lastAutomatedFocusTimestamp = 0;
|
|
11
9
|
const obtainAllFocusableElements = (element) => {
|
|
12
10
|
const nodes = [];
|
|
13
11
|
const walker = document.createTreeWalker(element, NodeFilter.SHOW_ELEMENT, {
|
|
@@ -63,7 +61,7 @@ const tryFocus = (element, shouldSelect) => {
|
|
|
63
61
|
if (element && element.focus) {
|
|
64
62
|
const prevFocusedElement = document.activeElement;
|
|
65
63
|
element.focus({ preventScroll: true });
|
|
66
|
-
lastAutomatedFocusTimestamp
|
|
64
|
+
lastAutomatedFocusTimestamp = window.performance.now();
|
|
67
65
|
if (element !== prevFocusedElement &&
|
|
68
66
|
isSelectable(element) &&
|
|
69
67
|
shouldSelect) {
|
|
@@ -111,16 +109,16 @@ const focusFirstDescendant = (elements, shouldSelect = false) => {
|
|
|
111
109
|
exports.focusFirstDescendant = focusFirstDescendant;
|
|
112
110
|
exports.focusableStack = createFocusableStack();
|
|
113
111
|
const isFocusCausedByUserEvent = () => {
|
|
114
|
-
return lastUserFocusTimestamp
|
|
112
|
+
return lastUserFocusTimestamp > lastAutomatedFocusTimestamp;
|
|
115
113
|
};
|
|
116
114
|
exports.isFocusCausedByUserEvent = isFocusCausedByUserEvent;
|
|
117
115
|
const notifyFocusReasonPointer = () => {
|
|
118
|
-
focusReason
|
|
119
|
-
lastUserFocusTimestamp
|
|
116
|
+
focusReason = 'pointer';
|
|
117
|
+
lastUserFocusTimestamp = window.performance.now();
|
|
120
118
|
};
|
|
121
119
|
const notifyFocusReasonKeydown = () => {
|
|
122
|
-
focusReason
|
|
123
|
-
lastUserFocusTimestamp
|
|
120
|
+
focusReason = 'keyboard';
|
|
121
|
+
lastUserFocusTimestamp = window.performance.now();
|
|
124
122
|
};
|
|
125
123
|
const useFocusReason = () => {
|
|
126
124
|
// onMounted(() => {
|
|
@@ -59,7 +59,13 @@ class TdLoading extends ui_abstract_1.UI {
|
|
|
59
59
|
});
|
|
60
60
|
this.transition.addChild(this.mask);
|
|
61
61
|
this.addChild(this.transition);
|
|
62
|
-
this.props = this.
|
|
62
|
+
this.props = this.useParams(params);
|
|
63
|
+
}
|
|
64
|
+
static service(params) {
|
|
65
|
+
return new TdLoading(params);
|
|
66
|
+
}
|
|
67
|
+
close() {
|
|
68
|
+
// todo close
|
|
63
69
|
}
|
|
64
70
|
}
|
|
65
71
|
exports.TdLoading = TdLoading;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { TypeNode } from '@type-dom/framework';
|
|
1
2
|
import { UI } from '../../../ui/ui.abstract';
|
|
2
3
|
import { ITdMessage, ITdMessageConfig } from './td-message.interface';
|
|
3
4
|
export declare class TdMessage extends UI<undefined> implements ITdMessage {
|
|
@@ -12,8 +13,8 @@ export declare class TdMessage extends UI<undefined> implements ITdMessage {
|
|
|
12
13
|
private repeatNum?;
|
|
13
14
|
private badge?;
|
|
14
15
|
constructor(option?: string | ITdMessageConfig);
|
|
15
|
-
initEvents(): void;
|
|
16
16
|
mounted(): void;
|
|
17
|
+
destroy(root?: TypeNode): void;
|
|
17
18
|
static success(message: string): void;
|
|
18
19
|
static warning(message: string): void;
|
|
19
20
|
static error(message: string): void;
|
|
@@ -21,5 +22,5 @@ export declare class TdMessage extends UI<undefined> implements ITdMessage {
|
|
|
21
22
|
startTimer(): void;
|
|
22
23
|
clearTimer(): void;
|
|
23
24
|
close(): void;
|
|
24
|
-
keydown({ code }: KeyboardEvent)
|
|
25
|
+
keydown: ({ code }: KeyboardEvent) => void;
|
|
25
26
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TdMessage = void 0;
|
|
4
|
+
const utils_1 = require("@type-dom/utils");
|
|
4
5
|
const framework_1 = require("@type-dom/framework");
|
|
5
6
|
const svgs_1 = require("@type-dom/svgs");
|
|
6
7
|
const ui_abstract_1 = require("../../../ui/ui.abstract");
|
|
7
|
-
const aria_1 = require("../../../aria");
|
|
8
8
|
const td_badge_class_1 = require("../../data/td-badge/td-badge.class");
|
|
9
9
|
const td_icon_class_1 = require("../../basic/td-icon/td-icon.class");
|
|
10
10
|
const td_message_interface_1 = require("./td-message.interface");
|
|
@@ -20,6 +20,12 @@ class TdMessage extends ui_abstract_1.UI {
|
|
|
20
20
|
params = option || {};
|
|
21
21
|
}
|
|
22
22
|
super(params, 'fragment');
|
|
23
|
+
this.keydown = ({ code }) => {
|
|
24
|
+
if (code === utils_1.EVENT_CODE.esc) {
|
|
25
|
+
// press esc to close the message
|
|
26
|
+
this.close();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
23
29
|
this.className = 'TdMessage';
|
|
24
30
|
this.visible = false;
|
|
25
31
|
this.stopTimer = undefined;
|
|
@@ -58,7 +64,7 @@ class TdMessage extends ui_abstract_1.UI {
|
|
|
58
64
|
}
|
|
59
65
|
}
|
|
60
66
|
});
|
|
61
|
-
// this.message.
|
|
67
|
+
// this.message.style.hide();
|
|
62
68
|
// this.transition.setSlot(this.message);
|
|
63
69
|
this.transition.addChild(this.message);
|
|
64
70
|
const type = (params === null || params === void 0 ? void 0 : params.type) || 'info';
|
|
@@ -124,9 +130,9 @@ class TdMessage extends ui_abstract_1.UI {
|
|
|
124
130
|
}
|
|
125
131
|
}));
|
|
126
132
|
}
|
|
127
|
-
this.props = this.
|
|
133
|
+
this.props = this.useParams(params);
|
|
128
134
|
const offset = (TdMessage.msgId * 60 + 20) + 'px';
|
|
129
|
-
this.message.
|
|
135
|
+
this.message.style.addObj({
|
|
130
136
|
top: offset
|
|
131
137
|
});
|
|
132
138
|
if (params.grouping) {
|
|
@@ -168,11 +174,6 @@ class TdMessage extends ui_abstract_1.UI {
|
|
|
168
174
|
this.mount(this.to);
|
|
169
175
|
}
|
|
170
176
|
}
|
|
171
|
-
initEvents() {
|
|
172
|
-
this.addEvent('keydown', document, evt => {
|
|
173
|
-
this.keydown(evt);
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
177
|
mounted() {
|
|
177
178
|
if ((this === null || this === void 0 ? void 0 : this.repeatNum) && (this === null || this === void 0 ? void 0 : this.repeatNum) > 1) {
|
|
178
179
|
return;
|
|
@@ -180,7 +181,12 @@ class TdMessage extends ui_abstract_1.UI {
|
|
|
180
181
|
this.startTimer();
|
|
181
182
|
// nextZIndex()
|
|
182
183
|
this.visible = true;
|
|
183
|
-
this.message.
|
|
184
|
+
this.message.style.show('flex');
|
|
185
|
+
document.addEventListener('keydown', this.keydown);
|
|
186
|
+
}
|
|
187
|
+
destroy(root) {
|
|
188
|
+
document.removeEventListener('keydown', this.keydown);
|
|
189
|
+
super.destroy(root);
|
|
184
190
|
}
|
|
185
191
|
static success(message) {
|
|
186
192
|
new TdMessage({
|
|
@@ -220,7 +226,7 @@ class TdMessage extends ui_abstract_1.UI {
|
|
|
220
226
|
close() {
|
|
221
227
|
console.log('close . ');
|
|
222
228
|
this.visible = false;
|
|
223
|
-
this.message.
|
|
229
|
+
this.message.style.hide();
|
|
224
230
|
this.clearTimer();
|
|
225
231
|
TdMessage.msgId = (TdMessage.msgId || 1) - 1;
|
|
226
232
|
TdMessage.msgList = TdMessage.msgList.filter(item => item !== this);
|
|
@@ -230,16 +236,10 @@ class TdMessage extends ui_abstract_1.UI {
|
|
|
230
236
|
const customStyle = {
|
|
231
237
|
top: offset
|
|
232
238
|
};
|
|
233
|
-
msg.message.
|
|
239
|
+
msg.message.style.setObj(customStyle);
|
|
234
240
|
});
|
|
235
241
|
this.destroy();
|
|
236
242
|
}
|
|
237
|
-
keydown({ code }) {
|
|
238
|
-
if (code === aria_1.EVENT_CODE.esc) {
|
|
239
|
-
// press esc to close the message
|
|
240
|
-
this.close();
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
243
|
}
|
|
244
244
|
exports.TdMessage = TdMessage;
|
|
245
245
|
TdMessage.msgId = 0;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { UI } from '../../../ui/ui.abstract';
|
|
2
|
+
import { TdInput } from '../../form/td-input/td-input.class';
|
|
2
3
|
import { ITdMessageBox, ITdMessageBoxConfig, IAction, IMessageBoxInputData } from './td-message-box.interface';
|
|
3
4
|
export declare class TdMessageBox extends UI<undefined> implements ITdMessageBox {
|
|
4
5
|
className: 'TdMessageBox';
|
|
@@ -26,10 +27,11 @@ export declare class TdMessageBox extends UI<undefined> implements ITdMessageBox
|
|
|
26
27
|
constructor(params?: ITdMessageBoxConfig);
|
|
27
28
|
mounted(): void;
|
|
28
29
|
beforeDestroy(): void;
|
|
30
|
+
static show(params?: ITdMessageBoxConfig): Promise<IMessageBoxInputData>;
|
|
29
31
|
static alert(message: string, title?: string, params?: ITdMessageBoxConfig): void;
|
|
30
|
-
static confirm(message: string, title?: string, params?: ITdMessageBoxConfig): Promise<IMessageBoxInputData
|
|
31
|
-
static prompt(message: string, title?: string, params?: ITdMessageBoxConfig): Promise<IMessageBoxInputData
|
|
32
|
-
promise(
|
|
32
|
+
static confirm(message: string, title?: string, params?: ITdMessageBoxConfig): Promise<IMessageBoxInputData>;
|
|
33
|
+
static prompt(message: string, title?: string, params?: ITdMessageBoxConfig): Promise<IMessageBoxInputData>;
|
|
34
|
+
promise(input?: TdInput): Promise<IMessageBoxInputData>;
|
|
33
35
|
doClose(): void;
|
|
34
36
|
handleWrapperClick(): void;
|
|
35
37
|
handleInputEnter: (e: KeyboardEvent) => void;
|