@type-dom/ui 0.0.7 → 0.0.9

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.
Files changed (225) hide show
  1. package/package.json +1 -2
  2. package/src/aria.d.ts +0 -17
  3. package/src/aria.js +0 -18
  4. package/src/components/basic/td-button/td-button.abstract.d.ts +2 -3
  5. package/src/components/basic/td-button/td-button.abstract.js +30 -26
  6. package/src/components/basic/td-button/td-button.interface.d.ts +0 -1
  7. package/src/components/basic/td-button-group/td-button-group.class.d.ts +2 -3
  8. package/src/components/basic/td-button-group/td-button-group.class.js +14 -16
  9. package/src/components/basic/td-container/td-aside/td-aside.class.js +2 -2
  10. package/src/components/basic/td-container/td-container.class.js +5 -5
  11. package/src/components/basic/td-container/td-container.js +1 -1
  12. package/src/components/basic/td-container/td-footer/td-footer.class.js +2 -2
  13. package/src/components/basic/td-container/td-header/td-header.class.js +3 -4
  14. package/src/components/basic/td-container/td-main/td-main.class.js +2 -2
  15. package/src/components/basic/td-icon/td-icon.class.js +9 -9
  16. package/src/components/basic/td-layout/td-col/td-col.class.d.ts +5 -2
  17. package/src/components/basic/td-layout/td-col/td-col.class.js +80 -80
  18. package/src/components/basic/td-layout/td-row/td-row.class.js +13 -13
  19. package/src/components/basic/td-link/td-link.class.d.ts +0 -1
  20. package/src/components/basic/td-link/td-link.class.js +17 -19
  21. package/src/components/basic/td-scrollbar/bar/bar.class.js +3 -3
  22. package/src/components/basic/td-scrollbar/td-scrollbar.class.js +5 -5
  23. package/src/components/basic/td-scrollbar/thumb/thumb.class.js +3 -3
  24. package/src/components/basic/td-space/td-space.class.js +10 -10
  25. package/src/components/basic/td-text/td-text.class.js +12 -9
  26. package/src/components/data/td-avatar/td-avatar.class.js +12 -13
  27. package/src/components/data/td-badge/td-badge.class.d.ts +1 -0
  28. package/src/components/data/td-badge/td-badge.class.js +15 -11
  29. package/src/components/data/td-card/td-card.class.js +7 -7
  30. package/src/components/data/td-check-tag/td-check-tag.class.d.ts +0 -1
  31. package/src/components/data/td-check-tag/td-check-tag.class.js +9 -11
  32. package/src/components/data/td-collapse/td-collapse.class.js +2 -3
  33. package/src/components/data/td-collapse/td-collapse.interface.d.ts +1 -0
  34. package/src/components/data/td-collapse-item/td-collapse-item.class.js +8 -8
  35. package/src/components/data/td-collapse-transition/td-collapse-transition.util.js +14 -14
  36. package/src/components/data/td-count-down/td-count-down.class.js +1 -1
  37. package/src/components/data/td-descriptions/td-descriptions-row.js +2 -2
  38. package/src/components/data/td-descriptions/td-descriptions.class.js +8 -8
  39. package/src/components/data/td-descriptions/td-descritions-cell.js +14 -14
  40. package/src/components/data/td-descriptions-item/td-descriptions-item.class.js +1 -1
  41. package/src/components/data/td-empty/img-empty.class.js +3 -3
  42. package/src/components/data/td-empty/td-empty.class.js +4 -4
  43. package/src/components/data/td-image/td-image.class.js +6 -6
  44. package/src/components/data/td-image-viewer/td-image-viewer.class.d.ts +2 -1
  45. package/src/components/data/td-image-viewer/td-image-viewer.class.js +14 -10
  46. package/src/components/data/td-result/td-result.class.js +3 -3
  47. package/src/components/data/td-segmented/td-segmented.class.js +26 -30
  48. package/src/components/data/td-statistic/td-statistic.abstract.js +2 -2
  49. package/src/components/data/td-tag/td-tag.class.js +10 -10
  50. package/src/components/feedback/index.d.ts +0 -2
  51. package/src/components/feedback/index.js +3 -5
  52. package/src/components/feedback/td-alert/td-alert.class.js +9 -9
  53. package/src/components/feedback/td-dialog/td-dialog.class.js +4 -4
  54. package/src/components/feedback/td-dialog-content/td-dialog-content.class.js +4 -4
  55. package/src/components/feedback/td-drawer/td-drawer.class.js +1 -1
  56. package/src/components/feedback/td-focus-trap/td-focus-trap.class.d.ts +19 -1
  57. package/src/components/feedback/td-focus-trap/td-focus-trap.class.js +223 -48
  58. package/src/components/feedback/td-focus-trap/tokens.d.ts +2 -1
  59. package/src/components/feedback/td-focus-trap/utils.d.ts +1 -1
  60. package/src/components/feedback/td-focus-trap/utils.js +9 -11
  61. package/src/components/feedback/td-loading/td-loading.class.js +1 -1
  62. package/src/components/feedback/td-message/td-message.class.d.ts +4 -2
  63. package/src/components/feedback/td-message/td-message.class.js +34 -27
  64. package/src/components/feedback/td-message/td-message.style.js +2 -1
  65. package/src/components/feedback/td-message-box/td-message-box.class.d.ts +3 -1
  66. package/src/components/feedback/td-message-box/td-message-box.class.js +79 -75
  67. package/src/components/feedback/td-message-box/td-message-box.interface.d.ts +2 -1
  68. package/src/components/feedback/td-notification/td-notification.class.d.ts +3 -2
  69. package/src/components/feedback/td-notification/td-notification.class.js +29 -29
  70. package/src/components/feedback/td-only-child/td-only-child.class.d.ts +7 -0
  71. package/src/components/feedback/td-only-child/td-only-child.class.js +74 -0
  72. package/src/components/feedback/td-overlay/td-overlay.class.d.ts +1 -1
  73. package/src/components/feedback/td-overlay/td-overlay.class.js +5 -5
  74. package/src/components/feedback/td-popper/arrow/arrow.class.d.ts +6 -0
  75. package/src/components/feedback/td-popper/arrow/arrow.class.js +22 -3
  76. package/src/components/feedback/td-popper/composable/use-focus-trap.d.ts +0 -0
  77. package/src/components/feedback/td-popper/composable/use-focus-trap.js +1 -0
  78. package/src/components/feedback/td-popper/content/content.class.d.ts +1 -0
  79. package/src/components/feedback/td-popper/content/content.class.js +25 -4
  80. package/src/components/feedback/td-popper/content/content.const.d.ts +3 -0
  81. package/src/components/feedback/td-popper/content/content.const.js +29 -0
  82. package/src/components/feedback/td-popper/content/content.interface.d.ts +9 -0
  83. package/src/components/feedback/td-popper/td-popper.class.d.ts +1 -1
  84. package/src/components/feedback/td-popper/td-popper.class.js +35 -2
  85. package/src/components/feedback/td-popper/td-popper.const.d.ts +21 -0
  86. package/src/components/feedback/td-popper/td-popper.const.js +5 -0
  87. package/src/components/feedback/td-popper/trigger/trigger.class.d.ts +11 -0
  88. package/src/components/feedback/td-popper/trigger/trigger.class.js +96 -1
  89. package/src/components/feedback/td-popper/trigger/trigger.const.d.ts +1 -0
  90. package/src/components/feedback/td-popper/trigger/trigger.const.js +12 -0
  91. package/src/components/feedback/td-popper/trigger/trigger.interface.d.ts +1 -0
  92. package/src/components/feedback/td-tooltip/content/content.class.js +1 -1
  93. package/src/components/feedback/td-tooltip/td-tooltip.class.js +1 -1
  94. package/src/components/feedback/td-tooltip/trigger/trigger.class.js +1 -1
  95. package/src/components/form/checkbox-group/checkbox-group.class.js +6 -7
  96. package/src/components/form/checkbox-group/checkbox-option/checkbox-option.class.d.ts +1 -1
  97. package/src/components/form/checkbox-group/checkbox-option/checkbox-option.class.js +21 -20
  98. package/src/components/form/field-item/cascade/field-cascade.abstract.d.ts +1 -1
  99. package/src/components/form/field-item/cascade/field-cascade.abstract.js +48 -43
  100. package/src/components/form/field-item/field-item.abstract.js +3 -3
  101. package/src/components/form/field-item/input/field-input.abstract.d.ts +1 -1
  102. package/src/components/form/field-item/input/field-input.abstract.js +15 -14
  103. package/src/components/form/field-item/options/field-options.abstract.d.ts +1 -3
  104. package/src/components/form/field-item/options/field-options.abstract.js +49 -46
  105. package/src/components/form/field-item/radio/field-radio.abstract.d.ts +1 -1
  106. package/src/components/form/field-item/radio/field-radio.abstract.js +32 -36
  107. package/src/components/form/field-item/select/field-select.abstract.d.ts +1 -1
  108. package/src/components/form/field-item/select/field-select.abstract.js +19 -19
  109. package/src/components/form/field-item/span/field-span.abstract.js +5 -5
  110. package/src/components/form/field-item/textarea/field-textarea.abstract.js +5 -5
  111. package/src/components/form/field-select/field-select.class.d.ts +1 -1
  112. package/src/components/form/field-select/field-select.class.js +23 -24
  113. package/src/components/form/field-select/option/option.class.js +1 -3
  114. package/src/components/form/radio-group/radio-group.class.js +6 -7
  115. package/src/components/form/radio-group/radio-option/radio-option.class.d.ts +0 -1
  116. package/src/components/form/radio-group/radio-option/radio-option.class.js +14 -15
  117. package/src/components/form/select/select.class.d.ts +1 -1
  118. package/src/components/form/select/select.class.js +19 -18
  119. package/src/components/form/td-checkbox/td-checkbox.class.js +3 -3
  120. package/src/components/form/td-checkbox-button/td-checkbox-button.class.js +3 -3
  121. package/src/components/form/td-checkbox-group/td-checkbox-group.class.js +3 -3
  122. package/src/components/form/td-form/td-form.class.js +5 -3
  123. package/src/components/form/td-form-item/td-form-item.class.js +16 -16
  124. package/src/components/form/td-input/td-input-field.class.js +8 -8
  125. package/src/components/form/td-input/td-input.class.d.ts +0 -1
  126. package/src/components/form/td-input/td-input.class.js +9 -11
  127. package/src/components/form/td-input/widget/prefix.js +1 -1
  128. package/src/components/form/td-input/widget/suffix.js +3 -3
  129. package/src/components/form/td-input/widget/td-input-wrapper.class.js +12 -11
  130. package/src/components/form/td-input/widget/td-textarea-wrapper.js +3 -3
  131. package/src/components/form/td-option/td-option.class.js +3 -3
  132. package/src/components/form/td-option-group/td-option-group.class.js +3 -3
  133. package/src/components/form/td-radio/td-radio.class.d.ts +0 -1
  134. package/src/components/form/td-radio/td-radio.class.js +50 -54
  135. package/src/components/form/td-radio-button/td-radio-button.class.d.ts +0 -1
  136. package/src/components/form/td-radio-button/td-radio-button.class.js +46 -50
  137. package/src/components/form/td-radio-group/td-radio-group.class.js +3 -4
  138. package/src/components/form/td-select/dropdown/dropdown.class.js +2 -2
  139. package/src/components/form/td-select/td-select.class.js +2 -2
  140. package/src/components/form/td-switch/td-switch.class.d.ts +1 -1
  141. package/src/components/form/td-switch/td-switch.class.js +27 -28
  142. package/src/components/form/td-switch/widget/td-switch-core.js +6 -6
  143. package/src/components/form/td-switch/widget/td-switch-left.js +3 -3
  144. package/src/components/form/td-switch/widget/td-switch-right.js +2 -2
  145. package/src/components/navigation/td-affix/td-affix.class.d.ts +3 -0
  146. package/src/components/navigation/td-affix/td-affix.class.js +22 -20
  147. package/src/components/navigation/td-anchor/td-anchor-link/td-anchor-link.class.js +1 -1
  148. package/src/components/navigation/td-anchor/td-anchor.class.js +10 -10
  149. package/src/components/navigation/td-backtop/td-backtop.class.d.ts +5 -3
  150. package/src/components/navigation/td-backtop/td-backtop.class.js +42 -34
  151. package/src/components/navigation/td-backtop/td-backtop.interface.d.ts +3 -0
  152. package/src/components/navigation/td-backtop/use-backtop.d.ts +7 -0
  153. package/src/components/navigation/td-backtop/use-backtop.js +44 -0
  154. package/src/components/navigation/td-breadcrumb/td-breadcrumb.class.js +4 -4
  155. package/src/components/navigation/td-breadcrumb-item/td-breadcrumb-item.class.js +3 -3
  156. package/src/components/navigation/td-menu/td-menu.class.js +5 -5
  157. package/src/components/navigation/td-menu/td-menu.interface.d.ts +2 -1
  158. package/src/components/navigation/td-tabs/td-tab-bar.class.js +5 -5
  159. package/src/components/navigation/td-tabs/td-tab-nav.class.js +14 -14
  160. package/src/components/navigation/td-tabs/td-tab-pane.class.js +3 -3
  161. package/src/components/navigation/td-tabs/td-tabs.class.js +22 -25
  162. package/src/components/others/collapsible-box/collapsible-box.js +2 -2
  163. package/src/components/others/collapsible-box/contents/contents.js +2 -2
  164. package/src/components/others/collapsible-box/heading/expand-heading.d.ts +1 -1
  165. package/src/components/others/collapsible-box/heading/expand-heading.js +27 -26
  166. package/src/components/others/custom-block/custom-block.d.ts +11 -0
  167. package/src/components/others/custom-block/custom-block.js +58 -0
  168. package/src/components/others/example/example-float-control.d.ts +8 -0
  169. package/src/components/others/example/example-float-control.js +63 -0
  170. package/src/components/others/example/example-showcase.d.ts +7 -0
  171. package/src/components/others/example/example-showcase.js +20 -0
  172. package/src/components/others/example/example-source-wrapper.d.ts +9 -0
  173. package/src/components/others/example/example-source-wrapper.js +30 -0
  174. package/src/components/others/example/example.d.ts +14 -0
  175. package/src/components/others/example/example.js +77 -0
  176. package/src/components/others/example/index.d.ts +5 -0
  177. package/src/components/others/example/index.js +13 -0
  178. package/src/components/others/example/op-btns.d.ts +7 -0
  179. package/src/components/others/example/op-btns.js +95 -0
  180. package/src/components/others/index.d.ts +4 -0
  181. package/src/components/others/index.js +9 -1
  182. package/src/components/others/menus/menu.d.ts +21 -0
  183. package/src/components/others/menus/menu.js +125 -0
  184. package/src/components/others/menus/menus.d.ts +15 -0
  185. package/src/components/others/menus/menus.js +101 -0
  186. package/src/components/others/td-divider/td-divider.class.js +8 -8
  187. package/src/hooks/index.d.ts +3 -0
  188. package/src/hooks/index.js +6 -0
  189. package/src/hooks/use-cursor.d.ts +1 -0
  190. package/src/hooks/use-cursor.js +56 -0
  191. package/src/hooks/use-escape-keydown.d.ts +4 -0
  192. package/src/hooks/use-escape-keydown.js +31 -0
  193. package/src/hooks/use-forward-ref.d.ts +13 -0
  194. package/src/hooks/use-forward-ref.js +27 -0
  195. package/src/index.d.ts +1 -0
  196. package/src/index.js +1 -0
  197. package/src/ui/ui.abstract.d.ts +1 -1
  198. package/src/ui/ui.abstract.js +3 -3
  199. package/src/ui/ui.interface.d.ts +3 -3
  200. package/src/components/feedback/dialog/dialog.class.d.ts +0 -7
  201. package/src/components/feedback/dialog/dialog.class.js +0 -21
  202. package/src/components/feedback/dialog/dialog.interface.d.ts +0 -4
  203. package/src/components/feedback/dialog/dialog.interface.js +0 -2
  204. package/src/components/feedback/message-box/message-box.d.ts +0 -9
  205. package/src/components/feedback/message-box/message-box.interface.d.ts +0 -4
  206. package/src/components/feedback/message-box/message-box.interface.js +0 -2
  207. package/src/components/feedback/message-box/message-box.js +0 -33
  208. package/src/components/feedback/overlay/container/body/body.d.ts +0 -7
  209. package/src/components/feedback/overlay/container/body/body.js +0 -17
  210. package/src/components/feedback/overlay/container/container.d.ts +0 -15
  211. package/src/components/feedback/overlay/container/container.js +0 -37
  212. package/src/components/feedback/overlay/container/footer/cancel-button/cancel-button.d.ts +0 -8
  213. package/src/components/feedback/overlay/container/footer/cancel-button/cancel-button.js +0 -31
  214. package/src/components/feedback/overlay/container/footer/confirm-button/confirm-button.d.ts +0 -9
  215. package/src/components/feedback/overlay/container/footer/confirm-button/confirm-button.js +0 -31
  216. package/src/components/feedback/overlay/container/footer/footer.d.ts +0 -10
  217. package/src/components/feedback/overlay/container/footer/footer.js +0 -47
  218. package/src/components/feedback/overlay/container/header/close-button/close-button.d.ts +0 -11
  219. package/src/components/feedback/overlay/container/header/close-button/close-button.js +0 -33
  220. package/src/components/feedback/overlay/container/header/header.d.ts +0 -12
  221. package/src/components/feedback/overlay/container/header/header.js +0 -25
  222. package/src/components/feedback/overlay/container/header/title/title.d.ts +0 -9
  223. package/src/components/feedback/overlay/container/header/title/title.js +0 -19
  224. package/src/components/feedback/overlay/overlay.abstract.d.ts +0 -13
  225. package/src/components/feedback/overlay/overlay.abstract.js +0 -59
@@ -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 aria_1 = require("../../../aria");
6
- const utils_1 = require("./utils");
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.setParams(params);
16
+ this.props = this.useParams(params);
13
17
  }
14
- initEvents() {
15
- const focusLayer = {
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
- const { focusReason } = (0, utils_1.useFocusReason)();
25
- const onKeydown = (e) => {
26
- if (!this.props.loop && !this.props.trapped)
27
- return;
28
- if (focusLayer.paused)
29
- return;
30
- const { key, altKey, ctrlKey, metaKey, currentTarget, shiftKey } = e;
31
- const { loop } = this.props;
32
- const isTabbing = key === aria_1.EVENT_CODE.tab && !altKey && !ctrlKey && !metaKey;
33
- const currentFocusingEl = document.activeElement;
34
- if (isTabbing && currentFocusingEl) {
35
- const container = currentTarget;
36
- const [first, last] = (0, utils_1.getEdges)(container);
37
- const isTabbable = first && last;
38
- if (!isTabbable) {
39
- if (currentFocusingEl === container) {
40
- const focusoutPreventedEvent = (0, utils_1.createFocusOutPreventedEvent)({
41
- focusReason: focusReason.value
42
- });
43
- // emit('focusout-prevented', focusoutPreventedEvent);
44
- if (!focusoutPreventedEvent.defaultPrevented) {
45
- e.preventDefault();
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
- if (!shiftKey && currentFocusingEl === last) {
51
- const focusoutPreventedEvent = (0, utils_1.createFocusOutPreventedEvent)({
52
- focusReason: focusReason.value
53
- });
54
- // emit('focusout-prevented', focusoutPreventedEvent);
55
- if (!focusoutPreventedEvent.defaultPrevented) {
56
- e.preventDefault();
57
- if (loop)
58
- (0, utils_1.tryFocus)(first, true);
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
- else if (shiftKey &&
62
- [first, container].includes(currentFocusingEl)) {
63
- const focusoutPreventedEvent = (0, utils_1.createFocusOutPreventedEvent)({
64
- focusReason: focusReason.value
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
- // emit('focusout-prevented', focusoutPreventedEvent);
182
+ this.emit('focusout-prevented', focusoutPreventedEvent);
67
183
  if (!focusoutPreventedEvent.defaultPrevented) {
68
- e.preventDefault();
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: unique symbol;
13
+ export declare const FOCUS_TRAP_INJECTION_KEY: InjectionKey<FocusTrapInjectionContext>;
@@ -1,4 +1,4 @@
1
- declare const focusReason: import("dist/libs/framework/src/reactivity/ref").Ref<"pointer" | "keyboard" | undefined>;
1
+ declare let focusReason: 'pointer' | 'keyboard';
2
2
  export type FocusLayer = {
3
3
  paused: boolean;
4
4
  pause: () => void;
@@ -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
- const focusReason = (0, framework_1.ref)();
8
- const lastUserFocusTimestamp = (0, framework_1.ref)(0);
9
- const lastAutomatedFocusTimestamp = (0, framework_1.ref)(0);
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.value = window.performance.now();
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.value > lastAutomatedFocusTimestamp.value;
112
+ return lastUserFocusTimestamp > lastAutomatedFocusTimestamp;
115
113
  };
116
114
  exports.isFocusCausedByUserEvent = isFocusCausedByUserEvent;
117
115
  const notifyFocusReasonPointer = () => {
118
- focusReason.value = 'pointer';
119
- lastUserFocusTimestamp.value = window.performance.now();
116
+ focusReason = 'pointer';
117
+ lastUserFocusTimestamp = window.performance.now();
120
118
  };
121
119
  const notifyFocusReasonKeydown = () => {
122
- focusReason.value = 'keyboard';
123
- lastUserFocusTimestamp.value = window.performance.now();
120
+ focusReason = 'keyboard';
121
+ lastUserFocusTimestamp = window.performance.now();
124
122
  };
125
123
  const useFocusReason = () => {
126
124
  // onMounted(() => {
@@ -59,7 +59,7 @@ 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.setParams(params);
62
+ this.props = this.useParams(params);
63
63
  }
64
64
  }
65
65
  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 {
@@ -10,9 +11,10 @@ export declare class TdMessage extends UI<undefined> implements ITdMessage {
10
11
  static msgId: number;
11
12
  static msgList: TdMessage[];
12
13
  private repeatNum?;
14
+ private badge?;
13
15
  constructor(option?: string | ITdMessageConfig);
14
- initEvents(): void;
15
16
  mounted(): void;
17
+ destroy(root?: TypeNode): void;
16
18
  static success(message: string): void;
17
19
  static warning(message: string): void;
18
20
  static error(message: string): void;
@@ -20,5 +22,5 @@ export declare class TdMessage extends UI<undefined> implements ITdMessage {
20
22
  startTimer(): void;
21
23
  clearTimer(): void;
22
24
  close(): void;
23
- keydown({ code }: KeyboardEvent): void;
25
+ keydown: ({ code }: KeyboardEvent) => void;
24
26
  }
@@ -1,16 +1,17 @@
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");
11
11
  const td_message_style_1 = require("./td-message.style");
12
12
  class TdMessage extends ui_abstract_1.UI {
13
13
  constructor(option) {
14
+ var _a;
14
15
  let params = {};
15
16
  if (typeof option === 'string') {
16
17
  params.message = option;
@@ -19,6 +20,12 @@ class TdMessage extends ui_abstract_1.UI {
19
20
  params = option || {};
20
21
  }
21
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
+ };
22
29
  this.className = 'TdMessage';
23
30
  this.visible = false;
24
31
  this.stopTimer = undefined;
@@ -57,9 +64,9 @@ class TdMessage extends ui_abstract_1.UI {
57
64
  }
58
65
  }
59
66
  });
60
- // this.message.ctrl.hide();
67
+ // this.message.style.hide();
61
68
  // this.transition.setSlot(this.message);
62
- this.transition.addSlot(this.message);
69
+ this.transition.addChild(this.message);
63
70
  const type = (params === null || params === void 0 ? void 0 : params.type) || 'info';
64
71
  const iconComponent = (params === null || params === void 0 ? void 0 : params.icon) || (new svgs_1.TypeComponentsMap[type]()) || '';
65
72
  console.log('iconComponent', iconComponent);
@@ -123,12 +130,11 @@ class TdMessage extends ui_abstract_1.UI {
123
130
  }
124
131
  }));
125
132
  }
126
- this.props = this.setParams(params);
133
+ this.props = this.useParams(params);
127
134
  const offset = (TdMessage.msgId * 60 + 20) + 'px';
128
- const customStyle = {
135
+ this.message.style.addObj({
129
136
  top: offset
130
- };
131
- this.message.ctrl.addStyleObj(customStyle);
137
+ });
132
138
  if (params.grouping) {
133
139
  if (TdMessage.msgList.length === 0) {
134
140
  TdMessage.msgId = TdMessage.msgId + 1;
@@ -141,12 +147,19 @@ class TdMessage extends ui_abstract_1.UI {
141
147
  msg.repeatNum = (msg.repeatNum || 1) + 1;
142
148
  console.log('msg.repeatNum is ', msg.repeatNum);
143
149
  if (msg.repeatNum > 1) {
144
- const badgeType = msg.props.type ? (msg.props.type === 'error' ? 'danger' : msg.props.type) : 'info';
145
- msg.message.addChild(new td_badge_class_1.TdBadge({
146
- value: msg.repeatNum,
147
- type: badgeType,
148
- styleObj: td_message_style_1.$messageBadgeStyle
149
- }));
150
+ if (msg.repeatNum === 2) {
151
+ const badgeType = msg.props.type ? (msg.props.type === 'error' ? 'danger' : msg.props.type) : 'info';
152
+ msg.badge = new td_badge_class_1.TdBadge({
153
+ value: msg.repeatNum,
154
+ type: badgeType,
155
+ styleObj: td_message_style_1.$messageBadgeStyle
156
+ });
157
+ msg.message.addChild(msg.badge);
158
+ }
159
+ else {
160
+ // msg.badge!.props.value = msg.repeatNum;
161
+ (_a = msg.badge) === null || _a === void 0 ? void 0 : _a.changeValue(msg.repeatNum);
162
+ }
150
163
  }
151
164
  this.clearTimer();
152
165
  msg.clearTimer();
@@ -161,11 +174,6 @@ class TdMessage extends ui_abstract_1.UI {
161
174
  this.mount(this.to);
162
175
  }
163
176
  }
164
- initEvents() {
165
- this.addEvent('keydown', document, evt => {
166
- this.keydown(evt);
167
- });
168
- }
169
177
  mounted() {
170
178
  if ((this === null || this === void 0 ? void 0 : this.repeatNum) && (this === null || this === void 0 ? void 0 : this.repeatNum) > 1) {
171
179
  return;
@@ -173,7 +181,12 @@ class TdMessage extends ui_abstract_1.UI {
173
181
  this.startTimer();
174
182
  // nextZIndex()
175
183
  this.visible = true;
176
- this.message.ctrl.show('flex');
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);
177
190
  }
178
191
  static success(message) {
179
192
  new TdMessage({
@@ -213,7 +226,7 @@ class TdMessage extends ui_abstract_1.UI {
213
226
  close() {
214
227
  console.log('close . ');
215
228
  this.visible = false;
216
- this.message.ctrl.hide();
229
+ this.message.style.hide();
217
230
  this.clearTimer();
218
231
  TdMessage.msgId = (TdMessage.msgId || 1) - 1;
219
232
  TdMessage.msgList = TdMessage.msgList.filter(item => item !== this);
@@ -223,16 +236,10 @@ class TdMessage extends ui_abstract_1.UI {
223
236
  const customStyle = {
224
237
  top: offset
225
238
  };
226
- msg.message.ctrl.setStyleObj(customStyle);
239
+ msg.message.style.setObj(customStyle);
227
240
  });
228
241
  this.destroy();
229
242
  }
230
- keydown({ code }) {
231
- if (code === aria_1.EVENT_CODE.esc) {
232
- // press esc to close the message
233
- this.close();
234
- }
235
- }
236
243
  }
237
244
  exports.TdMessage = TdMessage;
238
245
  TdMessage.msgId = 0;
@@ -40,7 +40,8 @@ exports.$messageStyle = {
40
40
  padding: exports.$message.padding,
41
41
  display: 'flex',
42
42
  alignItems: 'center',
43
- gap: '8px'
43
+ gap: '8px',
44
+ zIndex: 9999,
44
45
  };
45
46
  exports.$messageContentStyle = {
46
47
  padding: 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 | undefined>;
29
31
  static alert(message: string, title?: string, params?: ITdMessageBoxConfig): void;
30
32
  static confirm(message: string, title?: string, params?: ITdMessageBoxConfig): Promise<IMessageBoxInputData | undefined>;
31
33
  static prompt(message: string, title?: string, params?: ITdMessageBoxConfig): Promise<IMessageBoxInputData | undefined>;
32
- promise(value?: string): Promise<IMessageBoxInputData | undefined>;
34
+ promise(input?: TdInput): Promise<IMessageBoxInputData | undefined>;
33
35
  doClose(): void;
34
36
  handleWrapperClick(): void;
35
37
  handleInputEnter: (e: KeyboardEvent) => void;