jsl-ui 9.28.2 → 9.28.3

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