nexheal-lib 0.0.13 → 0.0.15

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.
@@ -28,12 +28,28 @@ class AutocompleteControl {
28
28
  addNewItemClicked = new EventEmitter();
29
29
  blurEvent = new EventEmitter();
30
30
  optionPatched = new EventEmitter();
31
+ loadAllOnOpen = false;
31
32
  readonly = false;
32
33
  _disabled = false;
33
34
  _options = [];
34
35
  set options(value) {
35
36
  this._options = value || [];
36
37
  this.processValueBuffer();
38
+ if (this.hasFocus && this.isDropdownOpen) {
39
+ const val = this.inputControl.value || "";
40
+ if (val === "" && this.loadAllOnOpen) {
41
+ this.filteredSuggestions = [...this._options];
42
+ }
43
+ else if (val !== "") {
44
+ const filterValue = val.toString().toLowerCase();
45
+ this.filteredSuggestions = this._options.filter((suggestion) => suggestion[this.optionDisplayProperty]?.toLowerCase().includes(filterValue));
46
+ }
47
+ this.highlightedIndex = this.filteredSuggestions.length > 0 ? 0 : null;
48
+ setTimeout(() => {
49
+ if (this.popperInstance)
50
+ this.popperInstance.update();
51
+ }, 0);
52
+ }
37
53
  }
38
54
  get options() {
39
55
  return this._options;
@@ -80,7 +96,13 @@ class AutocompleteControl {
80
96
  this.search.emit(filterValue);
81
97
  }
82
98
  else {
83
- this.isDropdownOpen = false;
99
+ if (this.loadAllOnOpen && this.hasFocus) {
100
+ this.filterSuggestions("");
101
+ this.search.emit("");
102
+ }
103
+ else {
104
+ this.isDropdownOpen = false;
105
+ }
84
106
  }
85
107
  });
86
108
  }
@@ -153,8 +175,18 @@ class AutocompleteControl {
153
175
  return;
154
176
  }
155
177
  if (value === "") {
156
- this.filteredSuggestions = [];
157
- this.isDropdownOpen = false;
178
+ if (this.loadAllOnOpen) {
179
+ this.filteredSuggestions = [...this.options];
180
+ this.highlightedIndex = this.filteredSuggestions.length > 0 ? 0 : null;
181
+ this.isDropdownOpen = true;
182
+ setTimeout(() => {
183
+ this.createPopperInstance();
184
+ }, 0);
185
+ }
186
+ else {
187
+ this.filteredSuggestions = [];
188
+ this.isDropdownOpen = false;
189
+ }
158
190
  return;
159
191
  }
160
192
  const filterValue = value.toString().toLowerCase();
@@ -184,6 +216,13 @@ class AutocompleteControl {
184
216
  // events
185
217
  onFocus() {
186
218
  this.hasFocus = true;
219
+ if (this.readonly)
220
+ return;
221
+ if (this.loadAllOnOpen) {
222
+ const val = this.inputControl.value || "";
223
+ this.filterSuggestions(val);
224
+ this.search.emit(val);
225
+ }
187
226
  }
188
227
  onBlur() {
189
228
  this.blurEvent.emit();
@@ -304,7 +343,7 @@ class AutocompleteControl {
304
343
  this.optionSelected.emit(this.selectedItems);
305
344
  }
306
345
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: AutocompleteControl, deps: [], target: i0.ɵɵFactoryTarget.Component });
307
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.1.3", type: AutocompleteControl, isStandalone: true, selector: "autocomplete-control", inputs: { title: "title", required: "required", placeholder: "placeholder", customClass: "customClass", clearVal: "clearVal", field: "field", error: "error", errorMessage: "errorMessage", autocomplete: "autocomplete", inputLoader: "inputLoader", isAddNewItem: "isAddNewItem", optionDisplayProperty: "optionDisplayProperty", readonly: "readonly", options: "options", disabled: "disabled" }, outputs: { optionSelected: "optionSelected", search: "search", selectionCleared: "selectionCleared", addNewItemClicked: "addNewItemClicked", blurEvent: "blurEvent", optionPatched: "optionPatched" }, providers: [
346
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.1.3", type: AutocompleteControl, isStandalone: true, selector: "autocomplete-control", inputs: { title: "title", required: "required", placeholder: "placeholder", customClass: "customClass", clearVal: "clearVal", field: "field", error: "error", errorMessage: "errorMessage", autocomplete: "autocomplete", inputLoader: "inputLoader", isAddNewItem: "isAddNewItem", optionDisplayProperty: "optionDisplayProperty", loadAllOnOpen: "loadAllOnOpen", readonly: "readonly", options: "options", disabled: "disabled" }, outputs: { optionSelected: "optionSelected", search: "search", selectionCleared: "selectionCleared", addNewItemClicked: "addNewItemClicked", blurEvent: "blurEvent", optionPatched: "optionPatched" }, providers: [
308
347
  {
309
348
  provide: NG_VALUE_ACCESSOR,
310
349
  useExisting: AutocompleteControl,
@@ -357,6 +396,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.3", ngImpor
357
396
  type: Output
358
397
  }], optionPatched: [{
359
398
  type: Output
399
+ }], loadAllOnOpen: [{
400
+ type: Input
360
401
  }], readonly: [{
361
402
  type: Input
362
403
  }], options: [{
@@ -386,6 +427,7 @@ class CalendarControl {
386
427
  timeOnly = false;
387
428
  dateFormat = "dd/MM/yyyy";
388
429
  placeholder = "dd-mm-yyyy";
430
+ viewMode = "date";
389
431
  _disabled = false;
390
432
  get disabled() {
391
433
  return this._disabled;
@@ -409,6 +451,22 @@ class CalendarControl {
409
451
  selectionCleared = new EventEmitter();
410
452
  blurEvent = new EventEmitter();
411
453
  dateSelected = new EventEmitter();
454
+ _defaultDate;
455
+ get defaultDate() {
456
+ return this._defaultDate;
457
+ }
458
+ set defaultDate(value) {
459
+ this._defaultDate = value;
460
+ if (value && !this.selectedDate) {
461
+ const parsed = new Date(value);
462
+ if (!isNaN(parsed.getTime())) {
463
+ this.displayMonth = parsed.getMonth();
464
+ this.displayYear = parsed.getFullYear();
465
+ this.selectedHour = parsed.getHours();
466
+ this.selectedMinute = parsed.getMinutes();
467
+ }
468
+ }
469
+ }
412
470
  _minDate;
413
471
  _maxDate;
414
472
  get minDate() {
@@ -785,6 +843,15 @@ class CalendarControl {
785
843
  }
786
844
  parseDate(val) {
787
845
  if (typeof val === "string") {
846
+ if (this.viewMode === "month") {
847
+ const mIndex = this.months.findIndex(m => m.toLowerCase() === val.trim().toLowerCase());
848
+ if (mIndex !== -1) {
849
+ return new Date(this.todayYear, mIndex, 1);
850
+ }
851
+ }
852
+ if (this.viewMode === "date" && val.length <= 2 && !isNaN(+val)) {
853
+ return new Date(this.todayYear, this.todayMonth, +val);
854
+ }
788
855
  const m = val.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/);
789
856
  if (m) {
790
857
  const d = +m[1], mo = +m[2] - 1, y = +m[3];
@@ -793,7 +860,13 @@ class CalendarControl {
793
860
  }
794
861
  // fallback
795
862
  const date = new Date(val);
796
- return isNaN(date.getTime()) ? null : date;
863
+ if (!isNaN(date.getTime()))
864
+ return date;
865
+ // final fallback for weird year parsing
866
+ if (this.viewMode === "year" && !isNaN(+val)) {
867
+ return new Date(+val, 0, 1);
868
+ }
869
+ return null;
797
870
  }
798
871
  formatOutput(date) {
799
872
  const datePart = this.datePipe.transform(date, this.dateFormat);
@@ -842,7 +915,21 @@ class CalendarControl {
842
915
  ];
843
916
  selectMonth(index) {
844
917
  this.displayMonth = index;
845
- this.currentView = "day";
918
+ if (this.viewMode === "month") {
919
+ const picked = new Date(this.displayYear, this.displayMonth, 1);
920
+ if (this.isDateDisabled(picked))
921
+ return;
922
+ this.selectedDate = picked;
923
+ const out = this.formatOutput(picked);
924
+ this.inputControl.setValue(out, { emitEvent: false });
925
+ this.onChangeFn(out);
926
+ this.onTouchedFn();
927
+ this.dateSelected.emit(picked);
928
+ this.isOpen = false;
929
+ }
930
+ else {
931
+ this.currentView = "day";
932
+ }
846
933
  }
847
934
  get displayMonthName() {
848
935
  return this.months[this.displayMonth];
@@ -883,7 +970,21 @@ class CalendarControl {
883
970
  }
884
971
  selectYear(year) {
885
972
  this.displayYear = year;
886
- this.currentView = "month";
973
+ if (this.viewMode === "year") {
974
+ const picked = new Date(this.displayYear, 0, 1);
975
+ if (this.isDateDisabled(picked))
976
+ return;
977
+ this.selectedDate = picked;
978
+ const out = this.formatOutput(picked);
979
+ this.inputControl.setValue(out, { emitEvent: false });
980
+ this.onChangeFn(out);
981
+ this.onTouchedFn();
982
+ this.dateSelected.emit(picked);
983
+ this.isOpen = false;
984
+ }
985
+ else {
986
+ this.currentView = "month";
987
+ }
887
988
  }
888
989
  prevYearRange() {
889
990
  this.displayYear -= this.yearRangeSize;
@@ -994,12 +1095,28 @@ class CalendarControl {
994
1095
  if (this.isOpen) {
995
1096
  // mark this one as current
996
1097
  CalendarControl._currentlyOpen = this;
997
- // reset the month/year view
998
- this.currentView = "day";
1098
+ if (this.viewMode === "month") {
1099
+ this.currentView = "month";
1100
+ }
1101
+ else if (this.viewMode === "year") {
1102
+ this.currentView = "yearRange";
1103
+ }
1104
+ else {
1105
+ this.currentView = "day";
1106
+ }
999
1107
  if (this.selectedDate) {
1000
1108
  this.displayMonth = this.selectedDate.getMonth();
1001
1109
  this.displayYear = this.selectedDate.getFullYear();
1002
1110
  }
1111
+ else if (this._defaultDate) {
1112
+ const parsed = new Date(this._defaultDate);
1113
+ if (!isNaN(parsed.getTime())) {
1114
+ this.displayMonth = parsed.getMonth();
1115
+ this.displayYear = parsed.getFullYear();
1116
+ this.selectedHour = parsed.getHours();
1117
+ this.selectedMinute = parsed.getMinutes();
1118
+ }
1119
+ }
1003
1120
  else {
1004
1121
  const now = new Date();
1005
1122
  this.displayMonth = now.getMonth();
@@ -1047,15 +1164,24 @@ class CalendarControl {
1047
1164
  this.selectionCleared.emit();
1048
1165
  event.stopPropagation();
1049
1166
  this.selectedDate = null;
1050
- this.selectedHour = this.today.getHours();
1051
- this.selectedMinute = this.today.getMinutes();
1167
+ if (this._defaultDate) {
1168
+ const parsed = new Date(this._defaultDate);
1169
+ if (!isNaN(parsed.getTime())) {
1170
+ this.selectedHour = parsed.getHours();
1171
+ this.selectedMinute = parsed.getMinutes();
1172
+ }
1173
+ }
1174
+ else {
1175
+ this.selectedHour = this.today.getHours();
1176
+ this.selectedMinute = this.today.getMinutes();
1177
+ }
1052
1178
  this.inputControl.setValue("", { emitEvent: false });
1053
1179
  this.onChangeFn(null);
1054
1180
  this.onTouchedFn();
1055
1181
  this.dateSelected.emit(null);
1056
1182
  }
1057
1183
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.3", ngImport: i0, type: CalendarControl, deps: [{ token: i1.DatePipe }], target: i0.ɵɵFactoryTarget.Component });
1058
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.1.3", type: CalendarControl, isStandalone: true, selector: "calendar-control", inputs: { title: "title", required: "required", customClass: "customClass", clearVal: "clearVal", deFocus: "deFocus", error: "error", errorMessage: "errorMessage", inputLoader: "inputLoader", hourFormat: "hourFormat", selectionMode: "selectionMode", timeOnly: "timeOnly", dateFormat: "dateFormat", placeholder: "placeholder", disabled: "disabled", readonly: "readonly", submitted: "submitted", inputPlaceholder: "inputPlaceholder", closeVal: ["close-val", "closeVal"], showTime: "showTime", minDate: "minDate", maxDate: "maxDate" }, outputs: { selectionCleared: "selectionCleared", blurEvent: "blurEvent", dateSelected: "dateSelected" }, host: { listeners: { "document:click": "clickOutside($event)" } }, providers: [
1184
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.1.3", type: CalendarControl, isStandalone: true, selector: "calendar-control", inputs: { title: "title", required: "required", customClass: "customClass", clearVal: "clearVal", deFocus: "deFocus", error: "error", errorMessage: "errorMessage", inputLoader: "inputLoader", hourFormat: "hourFormat", selectionMode: "selectionMode", timeOnly: "timeOnly", dateFormat: "dateFormat", placeholder: "placeholder", viewMode: "viewMode", disabled: "disabled", readonly: "readonly", submitted: "submitted", inputPlaceholder: "inputPlaceholder", closeVal: ["close-val", "closeVal"], showTime: "showTime", defaultDate: "defaultDate", minDate: "minDate", maxDate: "maxDate" }, outputs: { selectionCleared: "selectionCleared", blurEvent: "blurEvent", dateSelected: "dateSelected" }, host: { listeners: { "document:click": "clickOutside($event)" } }, providers: [
1059
1185
  DatePipe,
1060
1186
  {
1061
1187
  provide: NG_VALUE_ACCESSOR,
@@ -1104,6 +1230,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.3", ngImpor
1104
1230
  type: Input
1105
1231
  }], placeholder: [{
1106
1232
  type: Input
1233
+ }], viewMode: [{
1234
+ type: Input
1107
1235
  }], disabled: [{
1108
1236
  type: Input
1109
1237
  }], readonly: [{
@@ -1123,6 +1251,8 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.3", ngImpor
1123
1251
  type: Output
1124
1252
  }], dateSelected: [{
1125
1253
  type: Output
1254
+ }], defaultDate: [{
1255
+ type: Input
1126
1256
  }], minDate: [{
1127
1257
  type: Input
1128
1258
  }], maxDate: [{