@aurelia-ui-toolkits/headless 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (284) hide show
  1. package/dist/alert/ui-alert.html +19 -0
  2. package/dist/alert/ui-alert.js +67 -0
  3. package/dist/alert/ui-alert.js.map +1 -0
  4. package/dist/alert-service/alert-configuration.js +11 -0
  5. package/dist/alert-service/alert-configuration.js.map +1 -0
  6. package/dist/alert-service/alert-modal/alert-modal.html +12 -0
  7. package/dist/alert-service/alert-modal/alert-modal.js +31 -0
  8. package/dist/alert-service/alert-modal/alert-modal.js.map +1 -0
  9. package/dist/alert-service/alert-modal/i-alert-modal-payload.js +2 -0
  10. package/dist/alert-service/alert-modal/i-alert-modal-payload.js.map +1 -0
  11. package/dist/alert-service/alert-service.js +108 -0
  12. package/dist/alert-service/alert-service.js.map +1 -0
  13. package/dist/alert-service/decorators/confirm-action.js +14 -0
  14. package/dist/alert-service/decorators/confirm-action.js.map +1 -0
  15. package/dist/alert-service/decorators/using-progress.js +23 -0
  16. package/dist/alert-service/decorators/using-progress.js.map +1 -0
  17. package/dist/alert-service/exceptions-tracker.js +4 -0
  18. package/dist/alert-service/exceptions-tracker.js.map +1 -0
  19. package/dist/alert-service/prompt-dialog/prompt-dialog.html +13 -0
  20. package/dist/alert-service/prompt-dialog/prompt-dialog.js +39 -0
  21. package/dist/alert-service/prompt-dialog/prompt-dialog.js.map +1 -0
  22. package/dist/badge/ui-badge.html +6 -0
  23. package/dist/badge/ui-badge.js +44 -0
  24. package/dist/badge/ui-badge.js.map +1 -0
  25. package/dist/base/boolean-attr.js +4 -0
  26. package/dist/base/boolean-attr.js.map +1 -0
  27. package/dist/base/i-validated-element.js +2 -0
  28. package/dist/base/i-validated-element.js.map +1 -0
  29. package/dist/base/keys.js +14 -0
  30. package/dist/base/keys.js.map +1 -0
  31. package/dist/breadcrumbs/ui-breadcrumbs.html +10 -0
  32. package/dist/breadcrumbs/ui-breadcrumbs.js +31 -0
  33. package/dist/breadcrumbs/ui-breadcrumbs.js.map +1 -0
  34. package/dist/button/enhance-ui-button.js +25 -0
  35. package/dist/button/enhance-ui-button.js.map +1 -0
  36. package/dist/button/ui-button.html +20 -0
  37. package/dist/button/ui-button.js +77 -0
  38. package/dist/button/ui-button.js.map +1 -0
  39. package/dist/button/ui-icon-button.html +20 -0
  40. package/dist/button/ui-icon-button.js +77 -0
  41. package/dist/button/ui-icon-button.js.map +1 -0
  42. package/dist/checkbox/ui-checkbox.html +32 -0
  43. package/dist/checkbox/ui-checkbox.js +186 -0
  44. package/dist/checkbox/ui-checkbox.js.map +1 -0
  45. package/dist/chip/ui-chip.html +32 -0
  46. package/dist/chip/ui-chip.js +129 -0
  47. package/dist/chip/ui-chip.js.map +1 -0
  48. package/dist/combobox/enhance-ui-combobox.js +26 -0
  49. package/dist/combobox/enhance-ui-combobox.js.map +1 -0
  50. package/dist/combobox/ui-combobox.html +76 -0
  51. package/dist/combobox/ui-combobox.js +478 -0
  52. package/dist/combobox/ui-combobox.js.map +1 -0
  53. package/dist/disclosure/ui-disclosure.html +28 -0
  54. package/dist/disclosure/ui-disclosure.js +75 -0
  55. package/dist/disclosure/ui-disclosure.js.map +1 -0
  56. package/dist/drawer/ui-drawer.html +35 -0
  57. package/dist/drawer/ui-drawer.js +246 -0
  58. package/dist/drawer/ui-drawer.js.map +1 -0
  59. package/dist/index.js +135 -0
  60. package/dist/index.js.map +1 -0
  61. package/dist/input/enhance-ui-input.js +26 -0
  62. package/dist/input/enhance-ui-input.js.map +1 -0
  63. package/dist/input/ui-input.html +56 -0
  64. package/dist/input/ui-input.js +259 -0
  65. package/dist/input/ui-input.js.map +1 -0
  66. package/dist/list/ui-list-item.html +22 -0
  67. package/dist/list/ui-list-item.js +59 -0
  68. package/dist/list/ui-list-item.js.map +1 -0
  69. package/dist/list/ui-list.html +10 -0
  70. package/dist/list/ui-list.js +316 -0
  71. package/dist/list/ui-list.js.map +1 -0
  72. package/dist/menu/ui-menu.html +20 -0
  73. package/dist/menu/ui-menu.js +154 -0
  74. package/dist/menu/ui-menu.js.map +1 -0
  75. package/dist/popup/ui-popup.html +16 -0
  76. package/dist/popup/ui-popup.js +397 -0
  77. package/dist/popup/ui-popup.js.map +1 -0
  78. package/dist/progress/ui-progress.html +17 -0
  79. package/dist/progress/ui-progress.js +76 -0
  80. package/dist/progress/ui-progress.js.map +1 -0
  81. package/dist/radio/ui-radio-group.html +27 -0
  82. package/dist/radio/ui-radio-group.js +259 -0
  83. package/dist/radio/ui-radio-group.js.map +1 -0
  84. package/dist/radio/ui-radio.html +11 -0
  85. package/dist/radio/ui-radio.js +55 -0
  86. package/dist/radio/ui-radio.js.map +1 -0
  87. package/dist/segmented-control/ui-segment.html +10 -0
  88. package/dist/segmented-control/ui-segment.js +44 -0
  89. package/dist/segmented-control/ui-segment.js.map +1 -0
  90. package/dist/segmented-control/ui-segmented-control.html +9 -0
  91. package/dist/segmented-control/ui-segmented-control.js +134 -0
  92. package/dist/segmented-control/ui-segmented-control.js.map +1 -0
  93. package/dist/select/enhance-ui-select.js +26 -0
  94. package/dist/select/enhance-ui-select.js.map +1 -0
  95. package/dist/select/ui-select.html +70 -0
  96. package/dist/select/ui-select.js +323 -0
  97. package/dist/select/ui-select.js.map +1 -0
  98. package/dist/slider/ui-slider.html +69 -0
  99. package/dist/slider/ui-slider.js +362 -0
  100. package/dist/slider/ui-slider.js.map +1 -0
  101. package/dist/splitter/ui-splitter.html +14 -0
  102. package/dist/splitter/ui-splitter.js +257 -0
  103. package/dist/splitter/ui-splitter.js.map +1 -0
  104. package/dist/switch/ui-switch.html +23 -0
  105. package/dist/switch/ui-switch.js +121 -0
  106. package/dist/switch/ui-switch.js.map +1 -0
  107. package/dist/table/enhance-ui-table.js +25 -0
  108. package/dist/table/enhance-ui-table.js.map +1 -0
  109. package/dist/table/ui-table-column.html +17 -0
  110. package/dist/table/ui-table-column.js +127 -0
  111. package/dist/table/ui-table-column.js.map +1 -0
  112. package/dist/table/ui-table.html +56 -0
  113. package/dist/table/ui-table.js +225 -0
  114. package/dist/table/ui-table.js.map +1 -0
  115. package/dist/tabs/ui-tab.html +10 -0
  116. package/dist/tabs/ui-tab.js +52 -0
  117. package/dist/tabs/ui-tab.js.map +1 -0
  118. package/dist/tabs/ui-tabs.html +3 -0
  119. package/dist/tabs/ui-tabs.js +112 -0
  120. package/dist/tabs/ui-tabs.js.map +1 -0
  121. package/dist/toast/ui-toast-region.html +11 -0
  122. package/dist/toast/ui-toast-region.js +38 -0
  123. package/dist/toast/ui-toast-region.js.map +1 -0
  124. package/dist/toast/ui-toast-service.js +70 -0
  125. package/dist/toast/ui-toast-service.js.map +1 -0
  126. package/dist/tooltip/ui-tooltip-service.js +63 -0
  127. package/dist/tooltip/ui-tooltip-service.js.map +1 -0
  128. package/dist/tooltip/ui-tooltip.js +221 -0
  129. package/dist/tooltip/ui-tooltip.js.map +1 -0
  130. package/dist/top-app-bar/ui-top-app-bar.html +24 -0
  131. package/dist/top-app-bar/ui-top-app-bar.js +68 -0
  132. package/dist/top-app-bar/ui-top-app-bar.js.map +1 -0
  133. package/dist/tree/ui-tree.html +38 -0
  134. package/dist/tree/ui-tree.js +340 -0
  135. package/dist/tree/ui-tree.js.map +1 -0
  136. package/dist/types/alert/ui-alert.d.ts +11 -0
  137. package/dist/types/alert-service/alert-configuration.d.ts +8 -0
  138. package/dist/types/alert-service/alert-modal/alert-modal.d.ts +7 -0
  139. package/dist/types/alert-service/alert-modal/i-alert-modal-payload.d.ts +14 -0
  140. package/dist/types/alert-service/alert-service.d.ts +17 -0
  141. package/dist/types/alert-service/decorators/confirm-action.d.ts +3 -0
  142. package/dist/types/alert-service/decorators/using-progress.d.ts +6 -0
  143. package/dist/types/alert-service/exceptions-tracker.d.ts +3 -0
  144. package/dist/types/alert-service/prompt-dialog/prompt-dialog.d.ts +17 -0
  145. package/dist/types/badge/ui-badge.d.ts +7 -0
  146. package/dist/types/base/boolean-attr.d.ts +1 -0
  147. package/dist/types/base/i-validated-element.d.ts +10 -0
  148. package/dist/types/base/keys.d.ts +12 -0
  149. package/dist/types/breadcrumbs/ui-breadcrumbs.d.ts +8 -0
  150. package/dist/types/button/enhance-ui-button.d.ts +3 -0
  151. package/dist/types/button/ui-button.d.ts +16 -0
  152. package/dist/types/button/ui-icon-button.d.ts +18 -0
  153. package/dist/types/checkbox/ui-checkbox.d.ts +32 -0
  154. package/dist/types/chip/ui-chip.d.ts +26 -0
  155. package/dist/types/combobox/enhance-ui-combobox.d.ts +3 -0
  156. package/dist/types/combobox/ui-combobox.d.ts +79 -0
  157. package/dist/types/disclosure/ui-disclosure.d.ts +18 -0
  158. package/dist/types/drawer/ui-drawer.d.ts +38 -0
  159. package/dist/types/index.d.ts +91 -0
  160. package/dist/types/input/enhance-ui-input.d.ts +3 -0
  161. package/dist/types/input/ui-input.d.ts +44 -0
  162. package/dist/types/list/ui-list-item.d.ts +10 -0
  163. package/dist/types/list/ui-list.d.ts +45 -0
  164. package/dist/types/menu/ui-menu.d.ts +29 -0
  165. package/dist/types/popup/ui-popup.d.ts +61 -0
  166. package/dist/types/progress/ui-progress.d.ts +15 -0
  167. package/dist/types/radio/ui-radio-group.d.ts +37 -0
  168. package/dist/types/radio/ui-radio.d.ts +11 -0
  169. package/dist/types/segmented-control/ui-segment.d.ts +8 -0
  170. package/dist/types/segmented-control/ui-segmented-control.d.ts +17 -0
  171. package/dist/types/select/enhance-ui-select.d.ts +3 -0
  172. package/dist/types/select/ui-select.d.ts +50 -0
  173. package/dist/types/slider/ui-slider.d.ts +58 -0
  174. package/dist/types/splitter/ui-splitter.d.ts +39 -0
  175. package/dist/types/switch/ui-switch.d.ts +23 -0
  176. package/dist/types/table/enhance-ui-table.d.ts +3 -0
  177. package/dist/types/table/ui-table-column.d.ts +22 -0
  178. package/dist/types/table/ui-table.d.ts +51 -0
  179. package/dist/types/tabs/ui-tab.d.ts +10 -0
  180. package/dist/types/tabs/ui-tabs.d.ts +16 -0
  181. package/dist/types/toast/ui-toast-region.d.ts +6 -0
  182. package/dist/types/toast/ui-toast-service.d.ts +28 -0
  183. package/dist/types/tooltip/ui-tooltip-service.d.ts +23 -0
  184. package/dist/types/tooltip/ui-tooltip.d.ts +35 -0
  185. package/dist/types/top-app-bar/ui-top-app-bar.d.ts +9 -0
  186. package/dist/types/tree/ui-tree.d.ts +70 -0
  187. package/dist/types/validation/ui-validation-controller-factory.d.ts +7 -0
  188. package/dist/types/validation/ui-validation-result-presenter.d.ts +4 -0
  189. package/dist/types/validation/validate.d.ts +13 -0
  190. package/dist/validation/ui-validation-controller-factory.js +17 -0
  191. package/dist/validation/ui-validation-controller-factory.js.map +1 -0
  192. package/dist/validation/ui-validation-result-presenter.js +23 -0
  193. package/dist/validation/ui-validation-result-presenter.js.map +1 -0
  194. package/dist/validation/validate.js +24 -0
  195. package/dist/validation/validate.js.map +1 -0
  196. package/package.json +50 -0
  197. package/src/alert/ui-alert.html +19 -0
  198. package/src/alert/ui-alert.ts +33 -0
  199. package/src/alert-service/alert-configuration.ts +11 -0
  200. package/src/alert-service/alert-modal/alert-modal.html +12 -0
  201. package/src/alert-service/alert-modal/alert-modal.ts +19 -0
  202. package/src/alert-service/alert-modal/i-alert-modal-payload.ts +14 -0
  203. package/src/alert-service/alert-service.ts +116 -0
  204. package/src/alert-service/decorators/confirm-action.ts +18 -0
  205. package/src/alert-service/decorators/using-progress.ts +32 -0
  206. package/src/alert-service/exceptions-tracker.ts +3 -0
  207. package/src/alert-service/prompt-dialog/prompt-dialog.html +13 -0
  208. package/src/alert-service/prompt-dialog/prompt-dialog.ts +37 -0
  209. package/src/badge/ui-badge.html +6 -0
  210. package/src/badge/ui-badge.ts +17 -0
  211. package/src/base/boolean-attr.ts +3 -0
  212. package/src/base/i-validated-element.ts +11 -0
  213. package/src/base/keys.ts +12 -0
  214. package/src/breadcrumbs/ui-breadcrumbs.html +10 -0
  215. package/src/breadcrumbs/ui-breadcrumbs.ts +14 -0
  216. package/src/button/enhance-ui-button.ts +9 -0
  217. package/src/button/ui-button.html +20 -0
  218. package/src/button/ui-button.ts +60 -0
  219. package/src/button/ui-icon-button.html +20 -0
  220. package/src/button/ui-icon-button.ts +62 -0
  221. package/src/checkbox/ui-checkbox.html +32 -0
  222. package/src/checkbox/ui-checkbox.ts +188 -0
  223. package/src/chip/ui-chip.html +32 -0
  224. package/src/chip/ui-chip.ts +118 -0
  225. package/src/combobox/enhance-ui-combobox.ts +10 -0
  226. package/src/combobox/ui-combobox.html +76 -0
  227. package/src/combobox/ui-combobox.ts +450 -0
  228. package/src/disclosure/ui-disclosure.html +28 -0
  229. package/src/disclosure/ui-disclosure.ts +68 -0
  230. package/src/drawer/ui-drawer.html +35 -0
  231. package/src/drawer/ui-drawer.ts +219 -0
  232. package/src/index.ts +152 -0
  233. package/src/input/enhance-ui-input.ts +10 -0
  234. package/src/input/ui-input.html +56 -0
  235. package/src/input/ui-input.ts +225 -0
  236. package/src/list/ui-list-item.html +22 -0
  237. package/src/list/ui-list-item.ts +25 -0
  238. package/src/list/ui-list.html +10 -0
  239. package/src/list/ui-list.ts +330 -0
  240. package/src/menu/ui-menu.html +20 -0
  241. package/src/menu/ui-menu.ts +103 -0
  242. package/src/popup/ui-popup.html +16 -0
  243. package/src/popup/ui-popup.ts +391 -0
  244. package/src/progress/ui-progress.html +17 -0
  245. package/src/progress/ui-progress.ts +51 -0
  246. package/src/radio/ui-radio-group.html +27 -0
  247. package/src/radio/ui-radio-group.ts +250 -0
  248. package/src/radio/ui-radio.html +11 -0
  249. package/src/radio/ui-radio.ts +35 -0
  250. package/src/resource.d.ts +4 -0
  251. package/src/segmented-control/ui-segment.html +10 -0
  252. package/src/segmented-control/ui-segment.ts +20 -0
  253. package/src/segmented-control/ui-segmented-control.html +9 -0
  254. package/src/segmented-control/ui-segmented-control.ts +119 -0
  255. package/src/select/enhance-ui-select.ts +10 -0
  256. package/src/select/ui-select.html +70 -0
  257. package/src/select/ui-select.ts +294 -0
  258. package/src/slider/ui-slider.html +69 -0
  259. package/src/slider/ui-slider.ts +329 -0
  260. package/src/splitter/ui-splitter.html +14 -0
  261. package/src/splitter/ui-splitter.ts +249 -0
  262. package/src/switch/ui-switch.html +23 -0
  263. package/src/switch/ui-switch.ts +121 -0
  264. package/src/table/enhance-ui-table.ts +9 -0
  265. package/src/table/ui-table-column.html +17 -0
  266. package/src/table/ui-table-column.ts +108 -0
  267. package/src/table/ui-table.html +56 -0
  268. package/src/table/ui-table.ts +209 -0
  269. package/src/tabs/ui-tab.html +10 -0
  270. package/src/tabs/ui-tab.ts +30 -0
  271. package/src/tabs/ui-tabs.html +3 -0
  272. package/src/tabs/ui-tabs.ts +105 -0
  273. package/src/toast/ui-toast-region.html +11 -0
  274. package/src/toast/ui-toast-region.ts +18 -0
  275. package/src/toast/ui-toast-service.ts +100 -0
  276. package/src/tooltip/ui-tooltip-service.ts +84 -0
  277. package/src/tooltip/ui-tooltip.ts +200 -0
  278. package/src/top-app-bar/ui-top-app-bar.html +24 -0
  279. package/src/top-app-bar/ui-top-app-bar.ts +27 -0
  280. package/src/tree/ui-tree.html +38 -0
  281. package/src/tree/ui-tree.ts +363 -0
  282. package/src/validation/ui-validation-controller-factory.ts +20 -0
  283. package/src/validation/ui-validation-result-presenter.ts +26 -0
  284. package/src/validation/validate.ts +35 -0
@@ -0,0 +1,219 @@
1
+ import { bindable, BindingMode, customElement, INode, resolve } from 'aurelia';
2
+ import { booleanAttr } from '../base/boolean-attr';
3
+ import { Keys } from '../base/keys';
4
+ import template from './ui-drawer.html?raw';
5
+
6
+ type DrawerSide = 'left' | 'right' | 'top' | 'bottom';
7
+
8
+ @customElement({ name: 'ui-drawer', template })
9
+ export class UiDrawer implements EventListenerObject {
10
+ private readonly host = resolve(INode) as HTMLElement;
11
+
12
+ @bindable({ mode: BindingMode.twoWay, set: booleanAttr })
13
+ open: boolean = false;
14
+ openChanged(newValue: boolean): void {
15
+ if (newValue) {
16
+ this.startOpenState();
17
+ return;
18
+ }
19
+
20
+ this.stopOpenState();
21
+ }
22
+
23
+ @bindable
24
+ side: DrawerSide = 'right';
25
+
26
+ @bindable({ set: booleanAttr })
27
+ persistent: boolean = false;
28
+
29
+ @bindable({ set: booleanAttr })
30
+ modal: boolean = true;
31
+
32
+ @bindable({ set: booleanAttr })
33
+ closeOnOutside: boolean = true;
34
+
35
+ @bindable({ set: booleanAttr })
36
+ closeOnEscape: boolean = true;
37
+
38
+ @bindable({ set: booleanAttr })
39
+ focusOnOpen: boolean = true;
40
+
41
+ @bindable({ set: booleanAttr })
42
+ restoreFocus: boolean = true;
43
+
44
+ @bindable
45
+ trigger: HTMLElement | undefined;
46
+
47
+ @bindable
48
+ label: string | undefined;
49
+
50
+ @bindable
51
+ labelledBy: string | undefined;
52
+
53
+ @bindable
54
+ describedBy: string | undefined;
55
+
56
+ @bindable
57
+ portalTarget: string | Element | null | undefined;
58
+
59
+ @bindable
60
+ portalPosition: InsertPosition = 'beforeend';
61
+
62
+ panelElement: HTMLElement | undefined;
63
+ private listening = false;
64
+ private previousFocus: HTMLElement | undefined;
65
+
66
+ attaching(): void {
67
+ if (this.open) {
68
+ this.startOpenState();
69
+ }
70
+ }
71
+
72
+ detaching(): void {
73
+ this.stopOpenState(false);
74
+ }
75
+
76
+ handleEvent(event: Event): void {
77
+ if (!this.open) {
78
+ return;
79
+ }
80
+
81
+ if (event.type === 'keydown') {
82
+ this.onWindowKeyDown(event as KeyboardEvent);
83
+ return;
84
+ }
85
+
86
+ if (event.type === 'pointerdown') {
87
+ this.onWindowPointerDown(event as PointerEvent);
88
+ }
89
+ }
90
+
91
+ private startOpenState(): void {
92
+ if (this.persistent) {
93
+ return;
94
+ }
95
+
96
+ this.previousFocus = document.activeElement instanceof HTMLElement ? document.activeElement : undefined;
97
+ this.setListeners(true);
98
+ if (this.focusOnOpen) {
99
+ queueMicrotask(() => this.focusPanel());
100
+ }
101
+ }
102
+
103
+ private stopOpenState(restore = true): void {
104
+ this.setListeners(false);
105
+ if (!this.persistent && restore && this.restoreFocus) {
106
+ this.restorePreviousFocus();
107
+ }
108
+ }
109
+
110
+ private onWindowPointerDown(event: PointerEvent): void {
111
+ if (!this.closeOnOutside) {
112
+ return;
113
+ }
114
+
115
+ const target = event.target as Node | null;
116
+ if (!target || this.panelElement?.contains(target) || this.trigger?.contains(target) || this.isPortalledPopup(target)) {
117
+ return;
118
+ }
119
+
120
+ this.requestClose();
121
+ }
122
+
123
+ private onWindowKeyDown(event: KeyboardEvent): void {
124
+ if (this.closeOnEscape && event.key === Keys.Escape) {
125
+ event.preventDefault();
126
+ this.requestClose();
127
+ return;
128
+ }
129
+
130
+ if (this.modal && event.key === Keys.Tab) {
131
+ this.trapFocus(event);
132
+ }
133
+ }
134
+
135
+ private requestClose(): void {
136
+ this.open = false;
137
+ this.host.dispatchEvent(new CustomEvent('drawer-close', { bubbles: true }));
138
+ }
139
+
140
+ private setListeners(listen: boolean): void {
141
+ if (listen === this.listening) {
142
+ return;
143
+ }
144
+
145
+ this.listening = listen;
146
+ if (listen) {
147
+ window.addEventListener('pointerdown', this, true);
148
+ window.addEventListener('keydown', this, true);
149
+ return;
150
+ }
151
+
152
+ window.removeEventListener('pointerdown', this, true);
153
+ window.removeEventListener('keydown', this, true);
154
+ }
155
+
156
+ private isPortalledPopup(target: Node): boolean {
157
+ return target instanceof HTMLElement && !!target.closest('.ui-popup__panel');
158
+ }
159
+
160
+ private focusPanel(): void {
161
+ const focusTarget = this.getFocusableElements()[0];
162
+ (focusTarget ?? this.panelElement)?.focus();
163
+ }
164
+
165
+ private restorePreviousFocus(): void {
166
+ const target = this.trigger ?? this.previousFocus;
167
+ if (target && document.contains(target)) {
168
+ target.focus();
169
+ }
170
+ this.previousFocus = undefined;
171
+ }
172
+
173
+ private trapFocus(event: KeyboardEvent): void {
174
+ const focusable = this.getFocusableElements();
175
+ if (!focusable.length) {
176
+ event.preventDefault();
177
+ this.panelElement?.focus();
178
+ return;
179
+ }
180
+
181
+ const first = focusable[0];
182
+ const last = focusable[focusable.length - 1];
183
+ if (event.shiftKey && document.activeElement === first) {
184
+ event.preventDefault();
185
+ last.focus();
186
+ return;
187
+ }
188
+
189
+ if (!event.shiftKey && document.activeElement === last) {
190
+ event.preventDefault();
191
+ first.focus();
192
+ }
193
+ }
194
+
195
+ private getFocusableElements(): HTMLElement[] {
196
+ const selector = [
197
+ 'a[href]',
198
+ 'button',
199
+ 'input:not([type="hidden"])',
200
+ 'select',
201
+ 'textarea',
202
+ 'iframe',
203
+ '[tabindex]',
204
+ '[contenteditable="true"]'
205
+ ].join(',');
206
+
207
+ return Array.from(this.panelElement?.querySelectorAll<HTMLElement>(selector) ?? [])
208
+ .filter((element) => this.isFocusable(element));
209
+ }
210
+
211
+ private isFocusable(element: HTMLElement): boolean {
212
+ if (element.tabIndex < 0 || element.hasAttribute('disabled') || element.getAttribute('aria-hidden') === 'true') {
213
+ return false;
214
+ }
215
+
216
+ const style = window.getComputedStyle(element);
217
+ return style.display !== 'none' && style.visibility !== 'hidden';
218
+ }
219
+ }
package/src/index.ts ADDED
@@ -0,0 +1,152 @@
1
+ import { DialogConfigurationStandard } from '@aurelia/dialog';
2
+ import { AppTask, IAttrMapper, IContainer, NodeObserverLocator, Registration } from 'aurelia';
3
+ import { AlertConfiguration } from './alert-service/alert-configuration';
4
+ import { AlertModal } from './alert-service/alert-modal/alert-modal';
5
+ import { AlertService } from './alert-service/alert-service';
6
+ import { ExceptionsTracker } from './alert-service/exceptions-tracker';
7
+ import { PromptDialog } from './alert-service/prompt-dialog/prompt-dialog';
8
+ import { UiAlert } from './alert/ui-alert';
9
+ import { UiBadge } from './badge/ui-badge';
10
+ import { UiBreadcrumbs } from './breadcrumbs/ui-breadcrumbs';
11
+ import { UiButton } from './button/ui-button';
12
+ import { UiIconButton } from './button/ui-icon-button';
13
+ import { UiCheckbox } from './checkbox/ui-checkbox';
14
+ import { UiChip } from './chip/ui-chip';
15
+ import { UiCombobox } from './combobox/ui-combobox';
16
+ import { UiDisclosure } from './disclosure/ui-disclosure';
17
+ import { UiDrawer } from './drawer/ui-drawer';
18
+ import { IError, UiInput } from './input/ui-input';
19
+ import { UiMenu } from './menu/ui-menu';
20
+ import { UiList } from './list/ui-list';
21
+ import { UiListItem } from './list/ui-list-item';
22
+ import { UiPopup } from './popup/ui-popup';
23
+ import { UiProgress } from './progress/ui-progress';
24
+ import { UiRadio } from './radio/ui-radio';
25
+ import { UiRadioGroup } from './radio/ui-radio-group';
26
+ import { UiSegment } from './segmented-control/ui-segment';
27
+ import { UiSegmentedControl } from './segmented-control/ui-segmented-control';
28
+ import { UiSelect } from './select/ui-select';
29
+ import { UiSlider } from './slider/ui-slider';
30
+ import { UiSplitter } from './splitter/ui-splitter';
31
+ import { UiSwitch } from './switch/ui-switch';
32
+ import { UiTab } from './tabs/ui-tab';
33
+ import { UiTabs } from './tabs/ui-tabs';
34
+ import { UiTable } from './table/ui-table';
35
+ import { UiTableColumn } from './table/ui-table-column';
36
+ import { UiToastRegion } from './toast/ui-toast-region';
37
+ import { UiToastService } from './toast/ui-toast-service';
38
+ import { UiTooltip } from './tooltip/ui-tooltip';
39
+ import { UiTooltipService } from './tooltip/ui-tooltip-service';
40
+ import { UiTopAppBar } from './top-app-bar/ui-top-app-bar';
41
+ import { UiTree } from './tree/ui-tree';
42
+ import { EnhanceUiButton } from './button/enhance-ui-button';
43
+ import { EnhanceUiCombobox } from './combobox/enhance-ui-combobox';
44
+ import { EnhanceUiInput } from './input/enhance-ui-input';
45
+ import { EnhanceUiSelect } from './select/enhance-ui-select';
46
+ import { EnhanceUiTable } from './table/enhance-ui-table';
47
+ import { UiValidationControllerFactory } from './validation/ui-validation-controller-factory';
48
+
49
+ export { UiButton };
50
+ export { AlertConfiguration };
51
+ export { AlertModal };
52
+ export { AlertService };
53
+ export { UiAlert };
54
+ export { UiBadge };
55
+ export { UiBreadcrumbs };
56
+ export { UiIconButton };
57
+ export { UiCheckbox };
58
+ export { UiChip };
59
+ export { UiCombobox };
60
+ export { UiDisclosure };
61
+ export { UiDrawer };
62
+ export { UiInput };
63
+ export { UiMenu };
64
+ export { UiValidationControllerFactory };
65
+ export type { IError };
66
+ export { UiList };
67
+ export { UiListItem };
68
+ export { UiPopup };
69
+ export { UiProgress };
70
+ export { UiRadio };
71
+ export { UiRadioGroup };
72
+ export { UiSegment };
73
+ export { UiSegmentedControl };
74
+ export { UiSelect };
75
+ export { UiSlider };
76
+ export { UiSplitter };
77
+ export { UiSwitch };
78
+ export { UiTab };
79
+ export { UiTabs };
80
+ export { UiTable };
81
+ export { UiTableColumn };
82
+ export { UiToastRegion };
83
+ export { UiToastService };
84
+ export { UiTooltip };
85
+ export { UiTooltipService };
86
+ export { UiTopAppBar };
87
+ export { UiTree };
88
+ export { ExceptionsTracker };
89
+ export { PromptDialog };
90
+ export { confirmAction } from './alert-service/decorators/confirm-action';
91
+ export { usingProgress } from './alert-service/decorators/using-progress';
92
+ export type { IWithAlertService } from './alert-service/decorators/using-progress';
93
+ export type { IAlertModalPayload } from './alert-service/alert-modal/i-alert-modal-payload';
94
+ export type { IPromptDialogData } from './alert-service/prompt-dialog/prompt-dialog';
95
+ export type { UiBreadcrumbItem } from './breadcrumbs/ui-breadcrumbs';
96
+
97
+ let registered = false; //
98
+
99
+ export const AureliaHeadlessConfiguration = {
100
+ register(container: IContainer): IContainer {
101
+ if (registered) {
102
+ return container;
103
+ }
104
+ registered = true;
105
+ AppTask.creating(IContainer, c => {
106
+ const attrMapper = c.get(IAttrMapper);
107
+ const nodeObserverLocator = c.get(NodeObserverLocator);
108
+
109
+ // attrMapper.useTwoWay((el, property) => el.tagName === 'MDC-CHECKBOX' ? property === 'checked' : false);
110
+ // nodeObserverLocator.useConfig('MDC-CHECKBOX', 'checked', { events: ['change'], type: CheckedObserver });
111
+
112
+ // attrMapper.useTwoWay((el, property) => el.tagName === 'MDC-CHIP' ? property === 'checked' : false);
113
+ // nodeObserverLocator.useConfig('MDC-CHIP', 'checked', { events: ['change'], type: CheckedObserver });
114
+
115
+ // attrMapper.useTwoWay((el, property) => el.tagName === 'MDC-RADIO' ? property === 'checked' : false);
116
+ // nodeObserverLocator.useConfig('MDC-RADIO', 'checked', { events: ['change'], type: CheckedObserver });
117
+
118
+ // attrMapper.useTwoWay((el, property) => el.hasAttribute('mdc-segmented-button-segment-element') ? property === 'checked' : false);
119
+ // nodeObserverLocator.useConfig('MDC-SEGMENTED-BUTTON-SEGMENT', 'checked', { events: [segmentedButtonEvents.SELECTED, 'unselected'], type: CheckedObserver });
120
+
121
+ // attrMapper.useTwoWay((el, property) => el.tagName === 'MDC-SELECT' ? property === 'value' : false);
122
+ // nodeObserverLocator.useConfig('MDC-SELECT', 'value', { events: [strings.CHANGE_EVENT], type: MdcSelectValueObserver });
123
+
124
+ // attrMapper.useTwoWay((el, property) => el.tagName === 'MDC-SLIDER' ? property === 'value' || property === 'valuestart' : false);
125
+ // nodeObserverLocator.useConfig({
126
+ // 'MDC-SLIDER': {
127
+ // value: { events: [sliderEvents.CHANGE, sliderEvents.INPUT] },
128
+ // valuestart: { events: [sliderEvents.CHANGE, sliderEvents.INPUT] }
129
+ // }
130
+ // });
131
+
132
+ // attrMapper.useTwoWay((el, property) => el.hasAttribute('mdc-switch-element') ? property === 'selected' : false);
133
+ // nodeObserverLocator.useConfig('MDC-SWITCH', 'selected', { events: ['change'] });
134
+
135
+ attrMapper.useTwoWay((el, property) => el.hasAttribute('ui-input-element') ? property === 'value' : false);
136
+ nodeObserverLocator.useConfig('UI-INPUT', 'value', { events: ['input', 'change'] });
137
+ attrMapper.useTwoWay((el, property) => el.hasAttribute('ui-select-element') ? property === 'value' : false);
138
+ nodeObserverLocator.useConfig('UI-SELECT', 'value', { events: ['input', 'change'] });
139
+ attrMapper.useTwoWay((el, property) => el.hasAttribute('ui-combobox-element') ? property === 'value' : false);
140
+ nodeObserverLocator.useConfig('UI-COMBOBOX', 'value', { events: ['input', 'change'] });
141
+ attrMapper.useTwoWay((el, property) => el.tagName === 'UI-RADIO-GROUP' ? property === 'value' : false);
142
+ nodeObserverLocator.useConfig('UI-RADIO-GROUP', 'value', { events: ['input', 'change'] });
143
+ attrMapper.useTwoWay((el, property) => el.tagName === 'UI-SLIDER' ? property === 'value' : false);
144
+ nodeObserverLocator.useConfig('UI-SLIDER', 'value', { events: ['input', 'change'] });
145
+ attrMapper.useTwoWay((el, property) => el.tagName === 'UI-SWITCH' ? property === 'checked' : false);
146
+ nodeObserverLocator.useConfig('UI-SWITCH', 'checked', { events: ['input', 'change'] });
147
+
148
+ }).register(container);
149
+
150
+ return container.register(DialogConfigurationStandard, AlertModal, PromptDialog, Registration.singleton(AlertConfiguration, AlertConfiguration), Registration.singleton(AlertService, AlertService), Registration.singleton(ExceptionsTracker, ExceptionsTracker), UiAlert, UiBadge, UiBreadcrumbs, UiButton, UiIconButton, EnhanceUiButton, UiCheckbox, UiChip, UiCombobox, EnhanceUiCombobox, UiDisclosure, UiDrawer, UiInput, EnhanceUiInput, UiList, UiListItem, UiMenu, UiPopup, UiProgress, UiRadio, UiRadioGroup, UiSegment, UiSegmentedControl, UiSelect, EnhanceUiSelect, UiSlider, UiSplitter, UiSwitch, UiTab, UiTabs, UiTable, UiTableColumn, EnhanceUiTable, UiToastRegion, Registration.singleton(UiToastService, UiToastService), UiTooltip, Registration.singleton(UiTooltipService, UiTooltipService), UiTopAppBar, UiTree);
151
+ }
152
+ };
@@ -0,0 +1,10 @@
1
+ import { templateCompilerHooks } from 'aurelia';
2
+
3
+ @templateCompilerHooks
4
+ export class EnhanceUiInput {
5
+ compiling(template: HTMLElement | HTMLTemplateElement) {
6
+ template.innerHTML = template.innerHTML
7
+ .replaceAll('<ui-input ', '<label as-element="ui-input" ui-input-element ')
8
+ .replaceAll('</ui-input>', '</label>');
9
+ }
10
+ }
@@ -0,0 +1,56 @@
1
+ <template class="ui-input"
2
+ data-disabled.attr="disabled ? '' : null"
3
+ data-invalid.attr="invalid || errors.size ? '' : null"
4
+ data-focus.attr="focus ? '' : null"
5
+ data-active.attr="active ? '' : null"
6
+ data-inset.attr="inset ? '' : null"
7
+ data-has-value.attr="inputEl.value ? '' : null">
8
+ <label class="ui-input__label"
9
+ for.bind="id"
10
+ id.bind="!inset && label ? labelId : null"
11
+ show.bind="label && !inset">${label}</label>
12
+
13
+ <div class="ui-input__control">
14
+ <span class="ui-input__leading" show.bind="leadingNodes.length">
15
+ <au-slot name="leading"></au-slot>
16
+ </span>
17
+
18
+ <span class="ui-input__inset-label"
19
+ id.bind="inset && label ? labelId : null"
20
+ show.bind="label && inset">${label}</span>
21
+
22
+ <input ref="inputEl"
23
+ class="ui-input__native"
24
+ id.bind="id"
25
+ type.bind="type || null"
26
+ name.attr="name || null"
27
+ value.bind="value"
28
+ placeholder.attr="inset ? null : placeholder || null"
29
+ autocomplete.attr="autocomplete || null"
30
+ disabled.bind="disabled"
31
+ readonly.bind="readonly"
32
+ required.bind="required"
33
+ aria-labelledby.bind="label ? labelId : null"
34
+ aria-invalid.bind="invalid || errors.size ? 'true' : 'false'"
35
+ aria-describedby.bind="errors.size ? errorsId : (helperNodes.length ? helperId : null)"
36
+ focusin.trigger="onFocusIn()"
37
+ focusout.trigger="onFocusOut()"
38
+ pointerdown.trigger="onPointerDown()"
39
+ pointerup.trigger="onPointerUp()"
40
+ pointerleave.trigger="onPointerLeave()">
41
+
42
+ <span class="ui-input__trailing" show.bind="trailingNodes.length">
43
+ <au-slot name="trailing"></au-slot>
44
+ </span>
45
+ </div>
46
+
47
+ <div class="ui-input__subscript" show.bind="errors.size || helperText || helperNodes.length">
48
+ <div class="ui-input__helper" id.bind="helperId" show.bind="!errors.size && (helperText || helperNodes.length)">
49
+ <au-slot name="helper">${helperText}</au-slot>
50
+ </div>
51
+
52
+ <div class="ui-input__errors" id.bind="errorsId" show.bind="errors.size">
53
+ <div class="ui-input__error" repeat.for="[error, _] of errors" if.bind="error.message">${error.message}</div>
54
+ </div>
55
+ </div>
56
+ </template>
@@ -0,0 +1,225 @@
1
+ import { bindable, CustomElement, customElement, resolve, slotted } from 'aurelia';
2
+ import { booleanAttr } from '../base/boolean-attr';
3
+ import template from './ui-input.html?raw';
4
+ import { IValidatedElement } from '../base/i-validated-element';
5
+
6
+ let nextInputId = 0;
7
+
8
+ export interface IError {
9
+ message: string | undefined;
10
+ }
11
+
12
+ @customElement({ name: 'ui-input', template })
13
+ export class UiInput {
14
+ constructor() {
15
+ defineUiInputElementApis(resolve(Element) as HTMLElement);
16
+ }
17
+
18
+ errors = new Map<IError, boolean>();
19
+ focus: boolean = false;
20
+ active: boolean = false;
21
+ inputEl!: HTMLInputElement;
22
+
23
+ @bindable
24
+ label: string | undefined;
25
+
26
+ @bindable({ set: booleanAttr })
27
+ inset: boolean = false;
28
+
29
+ @bindable
30
+ helperText: string | undefined;
31
+
32
+ @bindable
33
+ id: string = `ui-input-${++nextInputId}`;
34
+
35
+ @bindable
36
+ type: string | undefined;
37
+
38
+ @bindable
39
+ name: string | undefined;
40
+
41
+ @bindable
42
+ placeholder: string | undefined;
43
+
44
+ @bindable
45
+ autocomplete: AutoFill | undefined;
46
+
47
+ @bindable({ set: booleanAttr })
48
+ disabled: boolean = false;
49
+
50
+ @bindable({ set: booleanAttr })
51
+ readonly: boolean = false;
52
+
53
+ @bindable({ set: booleanAttr })
54
+ required: boolean = false;
55
+
56
+ @bindable({ set: booleanAttr })
57
+ invalid: boolean = false;
58
+
59
+ @slotted({ slotName: 'helper' })
60
+ helperNodes: readonly Node[] = [];
61
+
62
+ @slotted({ slotName: 'leading' })
63
+ leadingNodes: readonly Node[] = [];
64
+
65
+ @slotted({ slotName: 'trailing' })
66
+ trailingNodes: readonly Node[] = [];
67
+
68
+ private initialValue: string | undefined;
69
+ get value(): string | undefined {
70
+ if (this.inputEl) {
71
+ return this.inputEl.value;
72
+ } else {
73
+ return this.initialValue;
74
+ }
75
+ }
76
+ set value(value: string) {
77
+ if (this.inputEl) {
78
+ this.inputEl.value = value;
79
+ } else {
80
+ this.initialValue = value;
81
+ }
82
+ }
83
+
84
+
85
+ get labelId(): string {
86
+ return `${this.id}-label`;
87
+ }
88
+
89
+ get helperId(): string {
90
+ return `${this.id}-helper`;
91
+ }
92
+
93
+ get errorsId(): string {
94
+ return `${this.id}-errors`;
95
+ }
96
+
97
+ attached() {
98
+ if (this.initialValue !== undefined) {
99
+ this.value = this.initialValue;
100
+ }
101
+ }
102
+
103
+ addError(error: IError): void {
104
+ if (this.findError(error)) {
105
+ return;
106
+ }
107
+
108
+ this.errors.set(error, true);
109
+ }
110
+
111
+ removeError(error: IError): void {
112
+ const existing = this.findError(error);
113
+ if (existing) {
114
+ this.errors.delete(existing);
115
+ return;
116
+ }
117
+
118
+ this.errors.delete(error);
119
+ }
120
+
121
+ onFocusIn(): void {
122
+ if (!this.disabled) {
123
+ this.focus = true;
124
+ }
125
+ }
126
+
127
+ onFocusOut(): void {
128
+ this.focus = false;
129
+ }
130
+
131
+ onPointerDown(): void {
132
+ if (!this.disabled) {
133
+ this.active = true;
134
+ }
135
+ }
136
+
137
+ onPointerUp(): void {
138
+ this.active = false;
139
+ }
140
+
141
+ onPointerLeave(): void {
142
+ this.active = false;
143
+ }
144
+
145
+ private findError(error: IError): IError | undefined {
146
+ for (const existing of this.errors.keys()) {
147
+ if (existing === error || existing.message === error.message) {
148
+ return existing;
149
+ }
150
+ }
151
+
152
+ return undefined;
153
+ }
154
+ }
155
+
156
+ export interface IUiInputElement extends IValidatedElement {
157
+ value: string;
158
+ }
159
+
160
+ function defineUiInputElementApis(element: HTMLElement) {
161
+ Object.defineProperties(element, {
162
+ tagName: {
163
+ get() {
164
+ return 'UI-INPUT';
165
+ }
166
+ },
167
+ value: {
168
+ get(this: IUiInputElement) {
169
+ return CustomElement.for<UiInput>(this).viewModel.value;
170
+ },
171
+ set(this: IUiInputElement, value: string) {
172
+ CustomElement.for<UiInput>(this).viewModel.value = value;
173
+ },
174
+ configurable: true
175
+ },
176
+ disabled: {
177
+ get(this: IUiInputElement) {
178
+ return CustomElement.for<UiInput>(this).viewModel.disabled;
179
+ },
180
+ set(this: IUiInputElement, value: boolean) {
181
+ CustomElement.for<UiInput>(this).viewModel.disabled = value;
182
+ },
183
+ configurable: true
184
+ },
185
+ readOnly: {
186
+ get(this: IUiInputElement) {
187
+ return CustomElement.for<UiInput>(this).viewModel.readonly;
188
+ },
189
+ set(this: IUiInputElement, value: boolean) {
190
+ CustomElement.for<UiInput>(this).viewModel.readonly = value;
191
+ },
192
+ configurable: true
193
+ },
194
+ addError: {
195
+ value(this: IUiInputElement, error: IError) {
196
+ CustomElement.for<UiInput>(this).viewModel.addError(error);
197
+ },
198
+ configurable: true
199
+ },
200
+ removeError: {
201
+ value(this: IUiInputElement, error: IError) {
202
+ CustomElement.for<UiInput>(this).viewModel.removeError(error);
203
+ },
204
+ configurable: true
205
+ },
206
+ focus: {
207
+ value(this: IUiInputElement) {
208
+ CustomElement.for<UiInput>(this).viewModel.inputEl.focus();
209
+ },
210
+ configurable: true
211
+ },
212
+ blur: {
213
+ value(this: IUiInputElement) {
214
+ CustomElement.for<UiInput>(this).viewModel.inputEl.blur();
215
+ },
216
+ configurable: true
217
+ },
218
+ isFocused: {
219
+ get(this: IUiInputElement) {
220
+ return document.activeElement === CustomElement.for<UiInput>(this).viewModel.inputEl;
221
+ },
222
+ configurable: true
223
+ }
224
+ });
225
+ }
@@ -0,0 +1,22 @@
1
+ <template class="ui-list-item"
2
+ role="option"
3
+ aria-selected.attr="selected ? 'true' : 'false'"
4
+ aria-disabled.attr="disabled ? '' : null"
5
+ data-active.attr="parentList.activeItem === value ? '' : null"
6
+ data-selected.attr="parentList.selected === value ? '' : null"
7
+ data-disabled.attr="disabled ? '' : null">
8
+ <span class="ui-list-item__leading" show.bind="leadingNodes.length">
9
+ <au-slot name="leading"></au-slot>
10
+ </span>
11
+ <span class="ui-list-item__content">
12
+ <span class="ui-list-item__primary">
13
+ <au-slot></au-slot>
14
+ </span>
15
+ <span class="ui-list-item__secondary" show.bind="secondaryNodes.length">
16
+ <au-slot name="secondary"></au-slot>
17
+ </span>
18
+ </span>
19
+ <span class="ui-list-item__trailing" show.bind="trailingNodes.length">
20
+ <au-slot name="trailing"></au-slot>
21
+ </span>
22
+ </template>