jsl-ui 9.28.3 → 9.28.4

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 (170) hide show
  1. package/lib/components/IntervalComponent.d.ts +17 -17
  2. package/lib/components/IntervalComponent.js +65 -65
  3. package/lib/components/auto-suggest/AutoSuggestComponent.d.ts +22 -22
  4. package/lib/components/auto-suggest/AutoSuggestComponent.js +47 -47
  5. package/lib/components/button/ButtonComponent.d.ts +18 -18
  6. package/lib/components/button/ButtonComponent.js +29 -29
  7. package/lib/components/checkbox/CheckBoxComponent.d.ts +28 -28
  8. package/lib/components/checkbox/CheckBoxComponent.js +81 -81
  9. package/lib/components/date/DateComponent.d.ts +32 -32
  10. package/lib/components/date/DateComponent.js +89 -89
  11. package/lib/components/date-range/DateRangeComponent.d.ts +35 -35
  12. package/lib/components/date-range/DateRangeComponent.js +121 -123
  13. package/lib/components/date-time/DateTimeComponent.d.ts +15 -15
  14. package/lib/components/date-time/DateTimeComponent.js +39 -39
  15. package/lib/components/dialog/DialogComponent.d.ts +67 -67
  16. package/lib/components/dialog/DialogComponent.js +192 -198
  17. package/lib/components/drop-down/DropDownComponent.d.ts +27 -27
  18. package/lib/components/drop-down/DropDownComponent.js +60 -60
  19. package/lib/components/expander/ExpanderComponent.d.ts +27 -27
  20. package/lib/components/expander/ExpanderComponent.js +87 -89
  21. package/lib/components/form-field/FormComponent.d.ts +12 -12
  22. package/lib/components/form-field/FormComponent.js +23 -23
  23. package/lib/components/form-field/FormFieldComponent.d.ts +39 -39
  24. package/lib/components/form-field/FormFieldComponent.js +138 -138
  25. package/lib/components/grid/GridComponent.d.ts +26 -26
  26. package/lib/components/grid/GridComponent.js +110 -110
  27. package/lib/components/input/InputComponent.d.ts +33 -33
  28. package/lib/components/input/InputComponent.js +126 -126
  29. package/lib/components/loading/LoadingComponent.d.ts +8 -8
  30. package/lib/components/loading/LoadingComponent.js +20 -20
  31. package/lib/components/navigation/NavigationComponent.d.ts +34 -34
  32. package/lib/components/navigation/NavigationComponent.js +47 -45
  33. package/lib/components/notification/Notification.d.ts +19 -19
  34. package/lib/components/notification/Notification.js +65 -65
  35. package/lib/components/number/NumberComponent.d.ts +26 -26
  36. package/lib/components/number/NumberComponent.js +80 -80
  37. package/lib/components/overlay/OverlayComponent.d.ts +27 -27
  38. package/lib/components/overlay/OverlayComponent.js +134 -137
  39. package/lib/components/progress/ProgressComponent.d.ts +18 -18
  40. package/lib/components/progress/ProgressComponent.js +40 -40
  41. package/lib/components/ribbon-menu/RibbonMenuComponent.d.ts +12 -12
  42. package/lib/components/ribbon-menu/RibbonMenuComponent.js +23 -23
  43. package/lib/components/select/SelectComponent.d.ts +79 -79
  44. package/lib/components/select/SelectComponent.js +352 -356
  45. package/lib/components/select/SelectDDAreaComponent.d.ts +32 -32
  46. package/lib/components/select/SelectDDAreaComponent.js +303 -303
  47. package/lib/components/slider/nouislider.d.ts +44 -44
  48. package/lib/components/slider/nouislider.js +2158 -2158
  49. package/lib/components/stack-panel/SplitterComponent.d.ts +21 -21
  50. package/lib/components/stack-panel/SplitterComponent.js +124 -124
  51. package/lib/components/stack-panel/StackPanelComponent.d.ts +20 -20
  52. package/lib/components/stack-panel/StackPanelComponent.js +50 -50
  53. package/lib/components/tabs/TabsComponent.d.ts +40 -40
  54. package/lib/components/tabs/TabsComponent.js +191 -200
  55. package/lib/components/time/TimeComponent.d.ts +29 -29
  56. package/lib/components/time/TimeComponent.js +102 -104
  57. package/lib/components/tree-view/TreeViewComponent.d.ts +23 -23
  58. package/lib/components/tree-view/TreeViewComponent.js +42 -43
  59. package/lib/components/virtual-render/VirtualRenderComponent.d.ts +30 -30
  60. package/lib/components/virtual-render/VirtualRenderComponent.js +90 -92
  61. package/lib/core/culture.d.ts +5 -5
  62. package/lib/core/culture.js +385 -385
  63. package/lib/core/date.d.ts +14 -14
  64. package/lib/core/date.js +346 -346
  65. package/lib/core/helper.d.ts +13 -13
  66. package/lib/core/helper.js +100 -100
  67. package/lib/core/jq.d.ts +37 -37
  68. package/lib/core/jq.js +362 -362
  69. package/lib/core/lang.d.ts +24 -24
  70. package/lib/core/lang.js +24 -24
  71. package/lib/core/numeric.d.ts +7 -7
  72. package/lib/core/numeric.js +139 -139
  73. package/lib/core/polyfills.js +22 -22
  74. package/lib/core.d.ts +6 -6
  75. package/lib/core.js +6 -6
  76. package/lib/grid/filterDialogs/dateRangeFilter.d.ts +7 -7
  77. package/lib/grid/filterDialogs/dateRangeFilter.js +106 -106
  78. package/lib/grid/filterDialogs/excelFilter.d.ts +9 -9
  79. package/lib/grid/filterDialogs/excelFilter.js +250 -250
  80. package/lib/grid/plugins/ext.overlay.d.ts +2 -2
  81. package/lib/grid/plugins/ext.overlay.js +295 -295
  82. package/lib/grid/plugins/slick.cellrangedecorator.d.ts +12 -12
  83. package/lib/grid/plugins/slick.cellrangedecorator.js +68 -68
  84. package/lib/grid/plugins/slick.cellrangeselector.d.ts +1 -1
  85. package/lib/grid/plugins/slick.cellrangeselector.js +144 -144
  86. package/lib/grid/plugins/slick.cellselectionmodel.d.ts +1 -1
  87. package/lib/grid/plugins/slick.cellselectionmodel.js +194 -194
  88. package/lib/grid/plugins/slick.headerbuttons.d.ts +55 -55
  89. package/lib/grid/plugins/slick.headerbuttons.js +156 -156
  90. package/lib/grid/plugins/slick.headermenu.d.ts +74 -74
  91. package/lib/grid/plugins/slick.headermenu.js +260 -260
  92. package/lib/grid/plugins/slick.rowmovemanager.d.ts +18 -18
  93. package/lib/grid/plugins/slick.rowmovemanager.js +249 -249
  94. package/lib/grid/plugins/slick.rowselectionmodel.d.ts +1 -1
  95. package/lib/grid/plugins/slick.rowselectionmodel.js +167 -167
  96. package/lib/grid/slick.core.d.ts +91 -91
  97. package/lib/grid/slick.core.js +574 -574
  98. package/lib/grid/slick.creator.d.ts +81 -81
  99. package/lib/grid/slick.creator.js +726 -726
  100. package/lib/grid/slick.dataview.d.ts +71 -71
  101. package/lib/grid/slick.dataview.js +1069 -1069
  102. package/lib/grid/slick.editors.core.d.ts +4 -4
  103. package/lib/grid/slick.editors.core.js +235 -235
  104. package/lib/grid/slick.editors.date.d.ts +2 -2
  105. package/lib/grid/slick.editors.date.js +125 -125
  106. package/lib/grid/slick.editors.lookup.d.ts +14 -14
  107. package/lib/grid/slick.editors.lookup.js +352 -352
  108. package/lib/grid/slick.editors.nav.d.ts +6 -6
  109. package/lib/grid/slick.editors.nav.js +22 -22
  110. package/lib/grid/slick.formatters.d.ts +17 -17
  111. package/lib/grid/slick.formatters.js +144 -144
  112. package/lib/grid/slick.grid.d.ts +285 -285
  113. package/lib/grid/slick.grid.js +5409 -5409
  114. package/lib/grid/slick.groupitemmetadataprovider.d.ts +39 -39
  115. package/lib/grid/slick.groupitemmetadataprovider.js +165 -165
  116. package/lib/grid/slick.tree.d.ts +33 -33
  117. package/lib/grid/slick.tree.js +208 -208
  118. package/lib/grid.css +705 -1
  119. package/lib/grid.d.ts +13 -13
  120. package/lib/grid.js +13 -13
  121. package/lib/index.css +2195 -8
  122. package/lib/index.css.map +1 -1
  123. package/lib/index.d.ts +55 -56
  124. package/lib/index.js +61 -61
  125. package/lib/index.js.map +1 -1
  126. package/lib/interaction/dataconverter.d.ts +4 -4
  127. package/lib/interaction/dataconverter.js +1 -0
  128. package/lib/interaction/eventhandler.d.ts +13 -13
  129. package/lib/interaction/eventhandler.js +39 -39
  130. package/lib/interaction/moveable.d.ts +39 -39
  131. package/lib/interaction/moveable.js +160 -160
  132. package/lib/interaction/resizable.d.ts +37 -37
  133. package/lib/interaction/resizable.js +109 -109
  134. package/lib/ui/auto.suggest.d.ts +18 -18
  135. package/lib/ui/auto.suggest.js +244 -244
  136. package/lib/ui/date.picker/date-picker-options.d.ts +11 -11
  137. package/lib/ui/date.picker/date-picker-options.js +76 -76
  138. package/lib/ui/date.picker/lib/date-manip.d.ts +74 -74
  139. package/lib/ui/date.picker/lib/date-manip.js +120 -120
  140. package/lib/ui/date.picker/lib/dom.d.ts +23 -23
  141. package/lib/ui/date.picker/lib/dom.js +28 -28
  142. package/lib/ui/date.picker/lib/emitter.d.ts +13 -13
  143. package/lib/ui/date.picker/lib/emitter.js +49 -49
  144. package/lib/ui/date.picker/lib/fns.d.ts +23 -23
  145. package/lib/ui/date.picker/lib/fns.js +39 -39
  146. package/lib/ui/date.picker/mode/base-mode.d.ts +26 -26
  147. package/lib/ui/date.picker/mode/base-mode.js +248 -248
  148. package/lib/ui/date.picker/mode/dropdown-mode.d.ts +28 -28
  149. package/lib/ui/date.picker/mode/dropdown-mode.js +50 -50
  150. package/lib/ui/date.picker/mode/index.d.ts +28 -28
  151. package/lib/ui/date.picker/mode/index.js +18 -18
  152. package/lib/ui/date.picker/mode/modal-mode.d.ts +25 -25
  153. package/lib/ui/date.picker/mode/modal-mode.js +17 -17
  154. package/lib/ui/date.picker/mode/permanent-mode.d.ts +29 -29
  155. package/lib/ui/date.picker/mode/permanent-mode.js +19 -19
  156. package/lib/ui/date.picker/views/day-picker.d.ts +40 -40
  157. package/lib/ui/date.picker/views/day-picker.js +155 -155
  158. package/lib/ui/date.picker/views/month-picker.d.ts +26 -26
  159. package/lib/ui/date.picker/views/month-picker.js +65 -65
  160. package/lib/ui/date.picker/views/year-picker.d.ts +20 -20
  161. package/lib/ui/date.picker/views/year-picker.js +66 -66
  162. package/lib/ui/date.picker.d.ts +66 -66
  163. package/lib/ui/date.picker.js +32 -32
  164. package/lib/ui/dialog.d.ts +22 -22
  165. package/lib/ui/dialog.js +98 -98
  166. package/lib/ui/drop.down.d.ts +52 -52
  167. package/lib/ui/drop.down.js +2112 -2112
  168. package/lib/ui/number.input.d.ts +13 -13
  169. package/lib/ui/number.input.js +56 -56
  170. package/package.json +1 -1
@@ -1,356 +1,352 @@
1
- import "./SelectStyle.scss";
2
- import { JSLRender } from "jsl-render";
3
- import { SelectDDAreaComponent } from "./SelectDDAreaComponent";
4
- import { EventHandler } from "../../interaction/eventhandler";
5
- export class SelectComponent {
6
- constructor(o) {
7
- var _a;
8
- this.expanded = false;
9
- this.doNotFocus = false;
10
- const defaultOptions = {
11
- data: undefined,
12
- keyColumn: "value",
13
- textColumn: "text",
14
- dropdownHeight: "10rem",
15
- dropDirection: "auto",
16
- enableSearch: true,
17
- enableAnimation: true,
18
- enableKeyboard: true,
19
- rowHeight: 28,
20
- allowEmpty: true,
21
- enabled: true,
22
- openOnEnter: true,
23
- focusFirstItem: true,
24
- autoShrink: true,
25
- bindMode: "toModel",
26
- onAppend: (dom) => {
27
- document.body.appendChild(dom);
28
- },
29
- onRenderGroup: (args) => {
30
- args.node.content = args.groupValue;
31
- },
32
- onRender: o.multiple ? (args) => {
33
- if (args.isCurrent) {
34
- args.node.content = args.data.map((d) => d[this.options.textColumn]).join(", ");
35
- }
36
- else {
37
- args.node.content = args.data[this.options.textColumn];
38
- }
39
- } : (args) => {
40
- args.node.content = args.data[this.options.textColumn];
41
- },
42
- matchSearch: (data, term) => { var _a; return (((_a = data[this.options.textColumn]) !== null && _a !== void 0 ? _a : "").toString().toLowerCase().indexOf(term.toLowerCase()) >= 0); }
43
- };
44
- this.options = { ...defaultOptions, ...o };
45
- this.options.onChange = EventHandler.Create(o.onChange);
46
- if (this.options.bindTo != null && this.options.property != null && this.options.value == null) {
47
- this.options.value = (((_a = this.options.converter) === null || _a === void 0 ? void 0 : _a.toUI) ?
48
- this.options.converter.toUI(this.options.bindTo[this.options.property]) :
49
- this.options.bindTo[this.options.property]);
50
- }
51
- this.setValue(this.options.value);
52
- }
53
- render() {
54
- var _a, _b;
55
- if (this.options.bindMode !== "toModel" && this.options.bindTo != null && this.options.property != null) {
56
- const value = ((_a = this.options.converter) === null || _a === void 0 ? void 0 : _a.toUI) ?
57
- this.options.converter.toUI(this.options.bindTo[this.options.property]) :
58
- this.options.bindTo[this.options.property];
59
- if (value != null) {
60
- if (this.options.multiple) {
61
- this.selected = this.options.data.filter((x) => value.indexOf(x[this.options.keyColumn]) >= 0);
62
- }
63
- else {
64
- this.selected = this.options.data.filter((x) => x[this.options.keyColumn] === value)[0];
65
- }
66
- }
67
- else {
68
- this.selected = this.options.multiple ? [] : null;
69
- }
70
- }
71
- return {
72
- tag: "div",
73
- attr: {
74
- style: this.options.style,
75
- class: "select-comp " + (this.expanded ? "expanded " : "") + (!this.options.enabled ? "disabled " : "") + ((_b = this.options.class) !== null && _b !== void 0 ? _b : ""),
76
- mousedown: (e) => { if (this.expanded || e.which === 3) {
77
- return;
78
- } {
79
- this.doNotFocus = true;
80
- this.show();
81
- } }
82
- },
83
- children: [this.renderSelection(), {
84
- tag: "button",
85
- attr: {
86
- disabled: this.options.enabled ? undefined : "disabled",
87
- class: "sel-expander",
88
- keydown: (e) => {
89
- if (this.options.openOnEnter && this.options.enabled) {
90
- if (e.which === SelectComponent.ENTER_KEY) {
91
- this.toggle();
92
- }
93
- else if (!this.expanded) {
94
- if (e.key && e.key.length === 1) {
95
- this.show(e.key);
96
- }
97
- }
98
- }
99
- },
100
- focus: (e) => {
101
- if (!this.doNotFocus && this.options.openOnFocus && this.options.enabled) {
102
- this.toggle();
103
- }
104
- if (this.doNotFocus) {
105
- this.doNotFocus = false;
106
- }
107
- }, click: (e) => {
108
- e.preventDefault();
109
- }
110
- },
111
- content: this.expanded ? "▲" : "▼"
112
- }]
113
- };
114
- }
115
- onCreate(node) {
116
- this.dom = node.dom;
117
- }
118
- onUpdate(node) {
119
- this.dom = node.dom;
120
- }
121
- onInit(renderer) {
122
- this.renderer = renderer;
123
- }
124
- toggle() {
125
- this.expanded = !this.expanded;
126
- if (this.expanded) {
127
- this.show();
128
- }
129
- else {
130
- this.close();
131
- }
132
- }
133
- isExpanded() {
134
- return this.expanded;
135
- }
136
- show(searchTxt) {
137
- var _a;
138
- if (!this.options.enabled) {
139
- return;
140
- }
141
- this.expanded = true;
142
- const dimension = this.dom.getBoundingClientRect();
143
- const left = Math.round(dimension.left + window.pageXOffset);
144
- const top = Math.round(dimension.top + window.pageYOffset);
145
- this.dropdownArea = document.createElement("div");
146
- this.dropdownArea.className = "sel-comp-dd " + ((_a = this.options.dropdownClass) !== null && _a !== void 0 ? _a : "");
147
- this.dropdownArea.style.width = this.options.dropdownWidth || (Math.round(dimension.width) + "px");
148
- this.dropdownArea.style.height = this.options.dropdownHeight;
149
- this.dropdownArea.style.left = left + "px";
150
- if (this.options.dropDirection === "up") {
151
- this.dropdownArea.style.top = "calc(" + top + "px - " + this.options.dropdownHeight + ")";
152
- this.dropdownArea.classList.add("sel-comp-dd-up");
153
- }
154
- else {
155
- this.dropdownArea.style.top = Math.round(top + dimension.height) + "px";
156
- this.dropdownArea.classList.add("sel-comp-dd-down");
157
- }
158
- this.options.onAppend(this.dropdownArea);
159
- const ddDimension = this.dropdownArea.getBoundingClientRect();
160
- if (this.options.dropDirection === "auto") {
161
- // check if there is enought room for dropdown at bottom
162
- if (ddDimension.bottom > window.innerHeight) {
163
- // position "up"
164
- this.dropdownArea.style.top = "calc(" + Math.round(top) + "px - " + this.options.dropdownHeight + ")";
165
- this.dropdownArea.classList.add("sel-comp-dd-up");
166
- this.dropdownArea.classList.remove("sel-comp-dd-down");
167
- }
168
- }
169
- const ddAreaComp = new SelectDDAreaComponent(this.options, this, {
170
- renderHeight: ddDimension.height - 2,
171
- searchTxt
172
- });
173
- if (this.options.autoShrink) {
174
- ddAreaComp.onRender.subscribe((data) => {
175
- let ddHeight;
176
- if (this.options.enableSearch) {
177
- ddHeight = Math.min((data.length * this.options.rowHeight + 4), ddDimension.height - 2) + "px + 1.8rem";
178
- this.dropdownArea.style.height = "calc(" + ddHeight + ")";
179
- }
180
- else {
181
- ddHeight = Math.min((data.length * this.options.rowHeight + 4), ddDimension.height - 2) + "px";
182
- this.dropdownArea.style.height = ddHeight;
183
- }
184
- if (this.dropdownArea.classList.contains("sel-comp-dd-up")) {
185
- this.dropdownArea.style.top = "calc(" + Math.round(top) + "px - (" + ddHeight + "))";
186
- }
187
- });
188
- }
189
- new JSLRender(this.dropdownArea, false).render(ddAreaComp);
190
- requestAnimationFrame(() => {
191
- const s = this.dropdownArea.querySelector(".sel-search input");
192
- s.focus();
193
- s.selectionStart = s.selectionEnd = s.value.length;
194
- });
195
- }
196
- destroy() {
197
- const x = document.querySelector(".sel-comp-dd");
198
- if (x != null && x.parentElement != null) {
199
- try {
200
- x.parentElement.removeChild(x);
201
- }
202
- catch (ex) {
203
- // under certain conditions the child may not be in the parentElements child collection anymore, although the child node still has that element as its parent (e.g. blur event handler) - weird JavaScript stuff eh
204
- }
205
- }
206
- this.expanded = false;
207
- }
208
- close() {
209
- var _a;
210
- this.expanded = false;
211
- this.focused = null;
212
- this.doNotFocus = true;
213
- try {
214
- if (((_a = this.dropdownArea) === null || _a === void 0 ? void 0 : _a.parentElement) != null) {
215
- this.dropdownArea.parentElement.removeChild(this.dropdownArea);
216
- }
217
- if (this.renderer != null) {
218
- this.renderer.refresh();
219
- }
220
- this.dom.querySelector(".sel-expander").focus();
221
- }
222
- catch (e) {
223
- // https://stackoverflow.com/questions/21926083/failed-to-execute-removechild-on-node
224
- }
225
- }
226
- setFocus(item) {
227
- this.focused = item;
228
- }
229
- getFocus() {
230
- return this.focused;
231
- }
232
- getValue() {
233
- if (this.selected == null) {
234
- return null;
235
- }
236
- if (this.options.multiple) {
237
- return this.selected.map((itm) => itm[this.options.keyColumn]);
238
- }
239
- else {
240
- return this.selected[this.options.keyColumn];
241
- }
242
- }
243
- setValue(value) {
244
- var _a;
245
- if (value != null) {
246
- if (this.options.multiple) {
247
- this.selected = this.options.data.filter((x) => value.indexOf(x[this.options.keyColumn]) >= 0);
248
- }
249
- else {
250
- this.selected = this.options.data.filter((x) => x[this.options.keyColumn] === value)[0];
251
- }
252
- }
253
- else {
254
- this.selected = this.options.multiple ? [] : null;
255
- }
256
- if (this.options.bindTo && this.options.bindMode !== "fromModel" && this.options.property) {
257
- this.options.bindTo[this.options.property] = ((_a = this.options.converter) === null || _a === void 0 ? void 0 : _a.toData) ? this.options.converter.toData(value) : value;
258
- }
259
- if (this.renderer != null) {
260
- this.renderer.refresh();
261
- }
262
- }
263
- getSelected() {
264
- return this.selected;
265
- }
266
- setSelected(item) {
267
- var _a;
268
- if (this.options.multiple) {
269
- if (item == null) {
270
- this.selected = [];
271
- }
272
- else {
273
- if (Array.isArray(item)) {
274
- this.selected = item;
275
- }
276
- else {
277
- this.selected.push(item);
278
- }
279
- }
280
- }
281
- else {
282
- this.selected = item;
283
- }
284
- const value = this.getValue();
285
- if (this.options.bindMode !== "fromModel" && this.options.bindTo != null && this.options.property != null) {
286
- this.options.bindTo[this.options.property] =
287
- ((_a = this.options.converter) === null || _a === void 0 ? void 0 : _a.toData) ? this.options.converter.toData(value) : value;
288
- }
289
- if (this.options.onChange != null) {
290
- this.options.onChange.notify(value, this.selected);
291
- }
292
- this.renderer.refresh();
293
- }
294
- focus() {
295
- var _a;
296
- if (this.dom == null) {
297
- requestAnimationFrame(() => {
298
- var _a;
299
- if (this.dom != null) {
300
- (_a = this.dom.querySelector(".sel-expander")) === null || _a === void 0 ? void 0 : _a.focus();
301
- }
302
- });
303
- }
304
- else {
305
- (_a = this.dom.querySelector(".sel-expander")) === null || _a === void 0 ? void 0 : _a.focus();
306
- }
307
- }
308
- hasSelection() {
309
- if (this.options.multiple) {
310
- return this.selected.length > 0;
311
- }
312
- return this.selected != null;
313
- }
314
- renderSelection() {
315
- let node;
316
- if (this.hasSelection()) {
317
- node = { tag: "div", attr: { class: "sel-dd-item" } };
318
- const res = this.options.onRender({
319
- isSelected: true,
320
- isCurrent: true,
321
- isFocused: false,
322
- data: this.selected,
323
- node
324
- });
325
- if (res != null) {
326
- node.children = [res];
327
- }
328
- }
329
- let clearbtn;
330
- if (this.options.allowEmpty) {
331
- clearbtn = {
332
- tag: "button", content: "✗",
333
- attr: {
334
- disabled: this.options.enabled ? undefined : "disabled",
335
- title: "clear", class: "clear-btn",
336
- mousedown: (e) => {
337
- if (!this.options.enabled) {
338
- return;
339
- }
340
- e.stopImmediatePropagation();
341
- this.setSelected(null);
342
- },
343
- click: (e) => {
344
- e.preventDefault();
345
- this.setSelected(null);
346
- }
347
- }
348
- };
349
- }
350
- return {
351
- tag: "div", attr: { class: "sel-result" }, content: node != null ? undefined : this.options.placehoder,
352
- children: node == null ? undefined : [node, clearbtn]
353
- };
354
- }
355
- }
356
- SelectComponent.ENTER_KEY = 13;
1
+ import "./SelectStyle.scss";
2
+ import { JSLRender } from "jsl-render";
3
+ import { SelectDDAreaComponent } from "./SelectDDAreaComponent";
4
+ import { EventHandler } from "../../interaction/eventhandler";
5
+ export class SelectComponent {
6
+ constructor(o) {
7
+ var _a;
8
+ this.expanded = false;
9
+ this.doNotFocus = false;
10
+ const defaultOptions = {
11
+ data: undefined,
12
+ keyColumn: "value",
13
+ textColumn: "text",
14
+ dropdownHeight: "10rem",
15
+ dropDirection: "auto",
16
+ enableSearch: true,
17
+ enableAnimation: true,
18
+ enableKeyboard: true,
19
+ rowHeight: 28,
20
+ allowEmpty: true,
21
+ enabled: true,
22
+ openOnEnter: true,
23
+ focusFirstItem: true,
24
+ autoShrink: true,
25
+ bindMode: "toModel",
26
+ onAppend: (dom) => {
27
+ document.body.appendChild(dom);
28
+ },
29
+ onRenderGroup: (args) => {
30
+ args.node.content = args.groupValue;
31
+ },
32
+ onRender: o.multiple ? (args) => {
33
+ if (args.isCurrent) {
34
+ args.node.content = args.data.map((d) => d[this.options.textColumn]).join(", ");
35
+ }
36
+ else {
37
+ args.node.content = args.data[this.options.textColumn];
38
+ }
39
+ } : (args) => {
40
+ args.node.content = args.data[this.options.textColumn];
41
+ },
42
+ matchSearch: (data, term) => { var _a; return (((_a = data[this.options.textColumn]) !== null && _a !== void 0 ? _a : "").toString().toLowerCase().indexOf(term.toLowerCase()) >= 0); }
43
+ };
44
+ this.options = { ...defaultOptions, ...o };
45
+ this.options.onChange = EventHandler.Create(o.onChange);
46
+ if (this.options.bindTo != null && this.options.property != null && this.options.value == null) {
47
+ this.options.value = (((_a = this.options.converter) === null || _a === void 0 ? void 0 : _a.toUI) ?
48
+ this.options.converter.toUI(this.options.bindTo[this.options.property]) :
49
+ this.options.bindTo[this.options.property]);
50
+ }
51
+ this.setValue(this.options.value);
52
+ }
53
+ render() {
54
+ var _a, _b;
55
+ if (this.options.bindMode !== "toModel" && this.options.bindTo != null && this.options.property != null) {
56
+ const value = ((_a = this.options.converter) === null || _a === void 0 ? void 0 : _a.toUI) ?
57
+ this.options.converter.toUI(this.options.bindTo[this.options.property]) :
58
+ this.options.bindTo[this.options.property];
59
+ if (value != null) {
60
+ if (this.options.multiple) {
61
+ this.selected = this.options.data.filter((x) => value.indexOf(x[this.options.keyColumn]) >= 0);
62
+ }
63
+ else {
64
+ this.selected = this.options.data.filter((x) => x[this.options.keyColumn] === value)[0];
65
+ }
66
+ }
67
+ else {
68
+ this.selected = this.options.multiple ? [] : null;
69
+ }
70
+ }
71
+ return {
72
+ tag: "div", attr: {
73
+ style: this.options.style,
74
+ class: "select-comp " + (this.expanded ? "expanded " : "") + (!this.options.enabled ? "disabled " : "") + ((_b = this.options.class) !== null && _b !== void 0 ? _b : ""),
75
+ mousedown: (e) => { if (this.expanded || e.which === 3) {
76
+ return;
77
+ } {
78
+ this.doNotFocus = true;
79
+ this.show();
80
+ } }
81
+ },
82
+ children: [this.renderSelection(), {
83
+ tag: "button", attr: {
84
+ disabled: this.options.enabled ? undefined : "disabled",
85
+ class: "sel-expander", keydown: (e) => {
86
+ if (this.options.openOnEnter && this.options.enabled) {
87
+ if (e.which === SelectComponent.ENTER_KEY) {
88
+ e.preventDefault();
89
+ e.stopPropagation();
90
+ e.stopImmediatePropagation();
91
+ this.toggle();
92
+ }
93
+ else if (!this.expanded) {
94
+ if (e.key && e.key.length === 1) {
95
+ this.show(e.key);
96
+ }
97
+ }
98
+ }
99
+ }, focus: (e) => {
100
+ if (!this.doNotFocus && this.options.openOnFocus && this.options.enabled) {
101
+ this.toggle();
102
+ }
103
+ if (this.doNotFocus) {
104
+ this.doNotFocus = false;
105
+ }
106
+ }, click: (e) => {
107
+ e.preventDefault();
108
+ }
109
+ }, content: this.expanded ? "▲" : "▼"
110
+ }]
111
+ };
112
+ }
113
+ onCreate(node) {
114
+ this.dom = node.dom;
115
+ }
116
+ onUpdate(node) {
117
+ this.dom = node.dom;
118
+ }
119
+ onInit(renderer) {
120
+ this.renderer = renderer;
121
+ }
122
+ toggle() {
123
+ this.expanded = !this.expanded;
124
+ if (this.expanded) {
125
+ this.show();
126
+ }
127
+ else {
128
+ this.close();
129
+ }
130
+ }
131
+ isExpanded() {
132
+ return this.expanded;
133
+ }
134
+ show(searchTxt) {
135
+ var _a;
136
+ if (!this.options.enabled) {
137
+ return;
138
+ }
139
+ this.expanded = true;
140
+ const dimension = this.dom.getBoundingClientRect();
141
+ const left = Math.round(dimension.left + window.pageXOffset);
142
+ const top = Math.round(dimension.top + window.pageYOffset);
143
+ this.dropdownArea = document.createElement("div");
144
+ this.dropdownArea.className = "sel-comp-dd " + ((_a = this.options.dropdownClass) !== null && _a !== void 0 ? _a : "");
145
+ this.dropdownArea.style.width = this.options.dropdownWidth || (Math.round(dimension.width) + "px");
146
+ this.dropdownArea.style.height = this.options.dropdownHeight;
147
+ this.dropdownArea.style.left = left + "px";
148
+ if (this.options.dropDirection === "up") {
149
+ this.dropdownArea.style.top = "calc(" + top + "px - " + this.options.dropdownHeight + ")";
150
+ this.dropdownArea.classList.add("sel-comp-dd-up");
151
+ }
152
+ else {
153
+ this.dropdownArea.style.top = Math.round(top + dimension.height) + "px";
154
+ this.dropdownArea.classList.add("sel-comp-dd-down");
155
+ }
156
+ this.options.onAppend(this.dropdownArea);
157
+ const ddDimension = this.dropdownArea.getBoundingClientRect();
158
+ if (this.options.dropDirection === "auto") {
159
+ // check if there is enought room for dropdown at bottom
160
+ if (ddDimension.bottom > window.innerHeight) {
161
+ // position "up"
162
+ this.dropdownArea.style.top = "calc(" + Math.round(top) + "px - " + this.options.dropdownHeight + ")";
163
+ this.dropdownArea.classList.add("sel-comp-dd-up");
164
+ this.dropdownArea.classList.remove("sel-comp-dd-down");
165
+ }
166
+ }
167
+ const ddAreaComp = new SelectDDAreaComponent(this.options, this, {
168
+ renderHeight: ddDimension.height - 2,
169
+ searchTxt
170
+ });
171
+ if (this.options.autoShrink) {
172
+ ddAreaComp.onRender.subscribe((data) => {
173
+ let ddHeight;
174
+ if (this.options.enableSearch) {
175
+ ddHeight = Math.min((data.length * this.options.rowHeight + 4), ddDimension.height - 2) + "px + 1.8rem";
176
+ this.dropdownArea.style.height = "calc(" + ddHeight + ")";
177
+ }
178
+ else {
179
+ ddHeight = Math.min((data.length * this.options.rowHeight + 4), ddDimension.height - 2) + "px";
180
+ this.dropdownArea.style.height = ddHeight;
181
+ }
182
+ if (this.dropdownArea.classList.contains("sel-comp-dd-up")) {
183
+ this.dropdownArea.style.top = "calc(" + Math.round(top) + "px - (" + ddHeight + "))";
184
+ }
185
+ });
186
+ }
187
+ new JSLRender(this.dropdownArea, false).render(ddAreaComp);
188
+ requestAnimationFrame(() => {
189
+ const s = this.dropdownArea.querySelector(".sel-search input");
190
+ s.focus();
191
+ s.selectionStart = s.selectionEnd = s.value.length;
192
+ });
193
+ }
194
+ destroy() {
195
+ const x = document.querySelector(".sel-comp-dd");
196
+ if (x != null && x.parentElement != null) {
197
+ try {
198
+ x.parentElement.removeChild(x);
199
+ }
200
+ catch (ex) {
201
+ // under certain conditions the child may not be in the parentElements child collection anymore, although the child node still has that element as its parent (e.g. blur event handler) - weird JavaScript stuff eh
202
+ }
203
+ }
204
+ this.expanded = false;
205
+ }
206
+ close() {
207
+ var _a;
208
+ this.expanded = false;
209
+ this.focused = null;
210
+ this.doNotFocus = true;
211
+ try {
212
+ if (((_a = this.dropdownArea) === null || _a === void 0 ? void 0 : _a.parentElement) != null) {
213
+ this.dropdownArea.parentElement.removeChild(this.dropdownArea);
214
+ }
215
+ if (this.renderer != null) {
216
+ this.renderer.refresh();
217
+ }
218
+ this.dom.querySelector(".sel-expander").focus();
219
+ }
220
+ catch (e) {
221
+ // https://stackoverflow.com/questions/21926083/failed-to-execute-removechild-on-node
222
+ }
223
+ }
224
+ setFocus(item) {
225
+ this.focused = item;
226
+ }
227
+ getFocus() {
228
+ return this.focused;
229
+ }
230
+ getValue() {
231
+ if (this.selected == null) {
232
+ return null;
233
+ }
234
+ if (this.options.multiple) {
235
+ return this.selected.map((itm) => itm[this.options.keyColumn]);
236
+ }
237
+ else {
238
+ return this.selected[this.options.keyColumn];
239
+ }
240
+ }
241
+ setValue(value) {
242
+ var _a;
243
+ if (value != null) {
244
+ if (this.options.multiple) {
245
+ this.selected = this.options.data.filter((x) => value.indexOf(x[this.options.keyColumn]) >= 0);
246
+ }
247
+ else {
248
+ this.selected = this.options.data.filter((x) => x[this.options.keyColumn] === value)[0];
249
+ }
250
+ }
251
+ else {
252
+ this.selected = this.options.multiple ? [] : null;
253
+ }
254
+ if (this.options.bindTo && this.options.bindMode !== "fromModel" && this.options.property) {
255
+ this.options.bindTo[this.options.property] = ((_a = this.options.converter) === null || _a === void 0 ? void 0 : _a.toData) ? this.options.converter.toData(value) : value;
256
+ }
257
+ if (this.renderer != null) {
258
+ this.renderer.refresh();
259
+ }
260
+ }
261
+ getSelected() {
262
+ return this.selected;
263
+ }
264
+ setSelected(item) {
265
+ var _a;
266
+ if (this.options.multiple) {
267
+ if (item == null) {
268
+ this.selected = [];
269
+ }
270
+ else {
271
+ if (Array.isArray(item)) {
272
+ this.selected = item;
273
+ }
274
+ else {
275
+ this.selected.push(item);
276
+ }
277
+ }
278
+ }
279
+ else {
280
+ this.selected = item;
281
+ }
282
+ const value = this.getValue();
283
+ if (this.options.bindMode !== "fromModel" && this.options.bindTo != null && this.options.property != null) {
284
+ this.options.bindTo[this.options.property] =
285
+ ((_a = this.options.converter) === null || _a === void 0 ? void 0 : _a.toData) ? this.options.converter.toData(value) : value;
286
+ }
287
+ if (this.options.onChange != null) {
288
+ this.options.onChange.notify(value, this.selected);
289
+ }
290
+ this.renderer.refresh();
291
+ }
292
+ focus() {
293
+ var _a;
294
+ if (this.dom == null) {
295
+ requestAnimationFrame(() => {
296
+ var _a;
297
+ if (this.dom != null) {
298
+ (_a = this.dom.querySelector(".sel-expander")) === null || _a === void 0 ? void 0 : _a.focus();
299
+ }
300
+ });
301
+ }
302
+ else {
303
+ (_a = this.dom.querySelector(".sel-expander")) === null || _a === void 0 ? void 0 : _a.focus();
304
+ }
305
+ }
306
+ hasSelection() {
307
+ if (this.options.multiple) {
308
+ return this.selected.length > 0;
309
+ }
310
+ return this.selected != null;
311
+ }
312
+ renderSelection() {
313
+ let node;
314
+ if (this.hasSelection()) {
315
+ node = { tag: "div", attr: { class: "sel-dd-item" } };
316
+ const res = this.options.onRender({
317
+ isSelected: true,
318
+ isCurrent: true,
319
+ isFocused: false,
320
+ data: this.selected,
321
+ node
322
+ });
323
+ if (res != null) {
324
+ node.children = [res];
325
+ }
326
+ }
327
+ let clearbtn;
328
+ if (this.options.allowEmpty) {
329
+ clearbtn = {
330
+ tag: "button", content: "✗", attr: {
331
+ disabled: this.options.enabled ? undefined : "disabled",
332
+ title: "clear", class: "clear-btn", mousedown: (e) => {
333
+ if (!this.options.enabled) {
334
+ return;
335
+ }
336
+ e.stopImmediatePropagation();
337
+ this.setSelected(null);
338
+ },
339
+ click: (e) => {
340
+ e.preventDefault();
341
+ this.setSelected(null);
342
+ }
343
+ }
344
+ };
345
+ }
346
+ return {
347
+ tag: "div", attr: { class: "sel-result" }, content: node != null ? undefined : this.options.placehoder,
348
+ children: node == null ? undefined : [node, clearbtn]
349
+ };
350
+ }
351
+ }
352
+ SelectComponent.ENTER_KEY = 13;