@singularsystems/neo-core 0.10.62 → 0.10.64

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.
@@ -27,10 +27,11 @@ export default class DatePicker {
27
27
  constructor(container: HTMLDivElement, options?: IPartialDateProps);
28
28
  inputFocused(e: FocusEvent): void;
29
29
  inputBlurred(): void;
30
+ onInputBlurred(closePopup: boolean): void;
30
31
  inputChanged(): void;
31
32
  inputKeyDown(e: KeyboardEvent): void;
32
33
  private removePopup;
33
- private setBindValueAndClose;
34
+ private setBindValue;
34
35
  private setBindProperty;
35
36
  private setInputValue;
36
37
  private show;
@@ -47,24 +47,27 @@ var DatePicker = /** @class */ (function () {
47
47
  }
48
48
  };
49
49
  DatePicker.prototype.inputBlurred = function () {
50
+ this.onInputBlurred(true);
51
+ };
52
+ DatePicker.prototype.onInputBlurred = function (closePopup) {
50
53
  if (this.inputHasChanged) {
51
54
  if (this.input.value) {
52
55
  // if this is time only, use the existing value to preserve the date.
53
56
  var refDate = this.options.timeOnly && this.bindProperty.value;
54
57
  var parsedDate = DateUtils.tryParse(this.input.value, this.options.formatString, false, refDate || new Date());
55
58
  if (parsedDate) {
56
- this.setBindValueAndClose(parsedDate, false);
59
+ this.setBindValue(parsedDate, { preserveTime: false, close: closePopup });
57
60
  }
58
61
  else {
59
- this.setBindValueAndClose(this.bindProperty.value, false);
62
+ this.setBindValue(this.bindProperty.value, { preserveTime: false, close: closePopup });
60
63
  }
61
64
  }
62
65
  else {
63
- this.setBindValueAndClose(null, true);
66
+ this.setBindValue(null, { preserveTime: true, close: closePopup });
64
67
  }
65
68
  }
66
69
  else {
67
- if (this.options.autoClose)
70
+ if (this.options.autoClose && closePopup)
68
71
  this.removePopup(true);
69
72
  }
70
73
  this.input.readOnly = this.isReadOnly;
@@ -78,6 +81,9 @@ var DatePicker = /** @class */ (function () {
78
81
  this.setCurrentViewDate(parsedDate);
79
82
  this.populateContentContainer(true);
80
83
  }
84
+ if (!this.popup) {
85
+ this.show();
86
+ }
81
87
  }
82
88
  };
83
89
  DatePicker.prototype.inputKeyDown = function (e) {
@@ -85,13 +91,22 @@ var DatePicker = /** @class */ (function () {
85
91
  if (e.key === "Escape") {
86
92
  // Revert to previous value
87
93
  e.preventDefault();
88
- this.setBindValueAndClose(this.bindProperty.value, false);
94
+ this.setBindValue(this.bindProperty.value, { preserveTime: false, close: false });
89
95
  }
90
96
  else if (e.key === "Enter") {
91
- // Set date to today if the current value is null
92
- e.preventDefault();
93
- if (!this.bindProperty.value) {
94
- this.setBindValueAndClose(new Date(), true);
97
+ var prevValue = this.input.value;
98
+ if (!this.bindProperty.value && !this.input.value) {
99
+ // Set date to today if the current value is null
100
+ this.setBindValue(new Date(), { preserveTime: true, close: false });
101
+ }
102
+ else {
103
+ this.onInputBlurred(false);
104
+ }
105
+ if (this.input.value !== prevValue) {
106
+ e.preventDefault();
107
+ }
108
+ else {
109
+ this.removePopup(true);
95
110
  }
96
111
  }
97
112
  };
@@ -109,17 +124,17 @@ var DatePicker = /** @class */ (function () {
109
124
  this.popup = null;
110
125
  }
111
126
  };
112
- DatePicker.prototype.setBindValueAndClose = function (dateValue, preserveTime) {
127
+ DatePicker.prototype.setBindValue = function (dateValue, options) {
113
128
  this.inputHasChanged = false;
114
129
  var oldValue = this.bindProperty.value;
115
- if (oldValue && dateValue && preserveTime) {
130
+ if (oldValue && dateValue && options.preserveTime) {
116
131
  // preserve the time component of the original date.
117
132
  dateValue.setHours(oldValue.getHours(), oldValue.getMinutes(), oldValue.getSeconds(), oldValue.getMilliseconds());
118
133
  }
119
134
  // Note: this may have the side effect of calling update().
120
135
  this.setBindProperty(dateValue, false);
121
136
  this.setInputValue();
122
- if (!this.options.alwaysShow) {
137
+ if (!this.options.alwaysShow && options.close) {
123
138
  this.removePopup(true);
124
139
  }
125
140
  };
@@ -156,7 +171,7 @@ var DatePicker = /** @class */ (function () {
156
171
  };
157
172
  DatePicker.prototype.positionPopup = function (fromBottom) {
158
173
  if (this.popup) {
159
- PositionHelper.checkScreenBounds(this.container, this.popup, fromBottom);
174
+ PositionHelper.checkScreenBounds(this.container, this.popup, fromBottom, this.options.popupAlignRight);
160
175
  }
161
176
  };
162
177
  /**
@@ -319,8 +334,7 @@ var DatePicker = /** @class */ (function () {
319
334
  var cell = this.createAndAppend(trBody, "td");
320
335
  var date = currentDate.getDate();
321
336
  var month = currentDate.getMonth();
322
- cell.innerText = date.toString();
323
- this.setupCell(cell, currentDate.getFullYear() + "," + month + "," + date, currentDate.getTime() >= this.options.minDateNoTime.getTime() && currentDate.getTime() <= this.options.maxDateNoTime.getTime(), currentDate.getTime() == this.today.getTime(), this.boundDateNoTime != null && currentDate.getTime() == this.boundDateNoTime.getTime());
337
+ this.setupCell(cell, date.toString(), currentDate.getFullYear() + "," + month + "," + date, currentDate.getTime() >= this.options.minDateNoTime.getTime() && currentDate.getTime() <= this.options.maxDateNoTime.getTime(), currentDate.getTime() == this.today.getTime(), this.boundDateNoTime != null && currentDate.getTime() == this.boundDateNoTime.getTime());
324
338
  if (month != this.currentViewDate.getMonth()) {
325
339
  cell.classList.add("outside-month");
326
340
  }
@@ -345,8 +359,7 @@ var DatePicker = /** @class */ (function () {
345
359
  trBody = this.createAndAppend(tBody, "tr");
346
360
  }
347
361
  var cell = this.createAndAppend(trBody, "td");
348
- cell.innerText = DateUtils.i18n.monthNames[i];
349
- this.setupCell(cell, i, monthEndDate > this.options.minDateNoTime.getTime() && monthStartDate <= this.options.maxDateNoTime.getTime(), this.today.getFullYear() == year && this.today.getMonth() == i, this.boundDateNoTime != null && this.boundDateNoTime.getFullYear() == year && this.boundDateNoTime.getMonth() == i);
362
+ this.setupCell(cell, DateUtils.i18n.monthNames[i], i, monthEndDate > this.options.minDateNoTime.getTime() && monthStartDate <= this.options.maxDateNoTime.getTime(), this.today.getFullYear() == year && this.today.getMonth() == i, this.boundDateNoTime != null && this.boundDateNoTime.getFullYear() == year && this.boundDateNoTime.getMonth() == i);
350
363
  }
351
364
  this.prevButton.disabled = this.options.minDateNoTime.getFullYear() >= year;
352
365
  this.nextButton.disabled = this.options.maxDateNoTime.getFullYear() <= year;
@@ -361,13 +374,12 @@ var DatePicker = /** @class */ (function () {
361
374
  trBody = this.createAndAppend(tBody, "tr");
362
375
  }
363
376
  var cell = this.createAndAppend(trBody, "td");
364
- cell.innerText = (year + i).toString();
365
- this.setupCell(cell, cell.innerText, year + i >= this.options.minDateNoTime.getFullYear() && year + i <= this.options.maxDateNoTime.getFullYear(), this.today.getFullYear() == year + i, this.boundDateNoTime != null && this.boundDateNoTime.getFullYear() == year + i);
377
+ this.setupCell(cell, (year + i).toString(), (year + i).toString(), year + i >= this.options.minDateNoTime.getFullYear() && year + i <= this.options.maxDateNoTime.getFullYear(), this.today.getFullYear() == year + i, this.boundDateNoTime != null && this.boundDateNoTime.getFullYear() == year + i);
366
378
  }
367
379
  this.prevButton.disabled = this.options.minDateNoTime.getFullYear() >= year;
368
380
  this.nextButton.disabled = this.options.maxDateNoTime.getFullYear() < year + YearsInYearView;
369
381
  };
370
- DatePicker.prototype.setupCell = function (cell, data, selectable, current, isSelected) {
382
+ DatePicker.prototype.setupCell = function (cell, innerText, data, selectable, current, isSelected) {
371
383
  if (selectable) {
372
384
  cell.classList.add("selectable");
373
385
  cell.dataset["date"] = data;
@@ -381,55 +393,56 @@ var DatePicker = /** @class */ (function () {
381
393
  if (isSelected) {
382
394
  cell.classList.add("selected");
383
395
  }
396
+ var cellContent = this.createAndAppend(cell, "span");
397
+ cellContent.innerText = innerText;
384
398
  };
385
399
  DatePicker.prototype.contentClick = function (e) {
400
+ var _a;
386
401
  e.preventDefault();
387
402
  if (e.target) {
388
- if (this.currentViewType == ViewType.Days) {
389
- this.dayClicked(e.target);
390
- }
391
- else if (this.currentViewType == ViewType.Months) {
392
- this.monthClicked(e.target);
403
+ var element = e.target;
404
+ if (!element.dataset["date"]) {
405
+ element = element.parentElement;
393
406
  }
394
- else {
395
- this.yearClicked(e.target);
407
+ var dateString = (_a = element) === null || _a === void 0 ? void 0 : _a.dataset["date"];
408
+ if (dateString) {
409
+ if (this.currentViewType == ViewType.Days) {
410
+ this.dayClicked(dateString);
411
+ }
412
+ else if (this.currentViewType == ViewType.Months) {
413
+ this.monthClicked(dateString);
414
+ }
415
+ else {
416
+ this.yearClicked(dateString);
417
+ }
396
418
  }
397
419
  }
398
420
  };
399
- DatePicker.prototype.dayClicked = function (element) {
400
- var datePartsString = element.dataset["date"];
401
- if (datePartsString) {
402
- var dateParts = datePartsString.split(",");
403
- this.setBindValueAndClose(new Date(parseInt(dateParts[0]), parseInt(dateParts[1]), parseInt(dateParts[2])), true);
404
- }
421
+ DatePicker.prototype.dayClicked = function (datePartsString) {
422
+ var dateParts = datePartsString.split(",");
423
+ this.setBindValue(new Date(parseInt(dateParts[0]), parseInt(dateParts[1]), parseInt(dateParts[2])), { preserveTime: true, close: true });
405
424
  };
406
- DatePicker.prototype.monthClicked = function (element) {
407
- var monthString = element.dataset["date"];
408
- if (monthString) {
409
- this.currentViewDate.setMonth(parseInt(monthString));
410
- if (this.options.monthView) {
411
- this.setBindValueAndClose(this.currentViewDate, true);
412
- }
413
- else {
414
- this.currentViewType = ViewType.Days;
415
- this.canAutoSetDate = true;
416
- this.populateContentContainer(false);
417
- this.contentAnimationHelper.fadeAndScale(true);
418
- }
425
+ DatePicker.prototype.monthClicked = function (monthString) {
426
+ this.currentViewDate.setMonth(parseInt(monthString));
427
+ if (this.options.monthView) {
428
+ this.setBindValue(this.currentViewDate, { preserveTime: true, close: true });
429
+ }
430
+ else {
431
+ this.currentViewType = ViewType.Days;
432
+ this.canAutoSetDate = true;
433
+ this.populateContentContainer(false);
434
+ this.contentAnimationHelper.fadeAndScale(true);
419
435
  }
420
436
  };
421
- DatePicker.prototype.yearClicked = function (element) {
422
- var yearString = element.dataset["date"];
423
- if (yearString) {
424
- this.currentViewDate.setFullYear(parseInt(yearString));
425
- if (this.options.yearView) {
426
- this.setBindValueAndClose(this.currentViewDate, true);
427
- }
428
- else {
429
- this.currentViewType = ViewType.Months;
430
- this.populateContentContainer(false);
431
- this.contentAnimationHelper.fadeAndScale(true);
432
- }
437
+ DatePicker.prototype.yearClicked = function (yearString) {
438
+ this.currentViewDate.setFullYear(parseInt(yearString));
439
+ if (this.options.yearView) {
440
+ this.setBindValue(this.currentViewDate, { preserveTime: true, close: true });
441
+ }
442
+ else {
443
+ this.currentViewType = ViewType.Months;
444
+ this.populateContentContainer(false);
445
+ this.contentAnimationHelper.fadeAndScale(true);
433
446
  }
434
447
  };
435
448
  DatePicker.prototype.headerClick = function (e) {
@@ -26,6 +26,10 @@ export default class DatePickerOptions {
26
26
  * `isClosing` will be false during scrolling with `autoChangeDate` set.
27
27
  * */
28
28
  onDateSelected?: (isClosing: boolean) => void;
29
+ /**
30
+ * If the datepicker popup should be aligned to the right of the input.
31
+ */
32
+ popupAlignRight?: boolean;
29
33
  }
30
34
  export declare class ProcessedDatePickerOptions extends DatePickerOptions {
31
35
  minDateNoTime: Date;
@@ -1,6 +1,7 @@
1
- import { ModelFieldInfo } from "../ModelFieldInfo";
1
+ import { IModelFieldInfoContainer, ModelFieldInfo } from "../ModelFieldInfo";
2
+ import PropertyInfo from "../PropertyInfo";
2
3
  import ValueObject from "../ValueObject";
3
- export declare abstract class CriteriaBase extends ValueObject {
4
+ export declare abstract class CriteriaBase extends ValueObject implements IModelFieldInfoContainer {
4
5
  /**
5
6
  * Extra information about lookup fields in this object.
6
7
  */
@@ -13,4 +14,5 @@ export declare abstract class CriteriaBase extends ValueObject {
13
14
  * You must also call this.makeObservable(); instead of using the @NeoModel decorator.
14
15
  */
15
16
  protected initialiseFieldInfo(fields: (keyof this)[]): void;
17
+ setModelFieldInfo(property: PropertyInfo, displayValue: string): any;
16
18
  }
@@ -25,6 +25,17 @@ var CriteriaBase = /** @class */ (function (_super) {
25
25
  }
26
26
  }
27
27
  };
28
+ CriteriaBase.prototype.setModelFieldInfo = function (property, displayValue) {
29
+ var fieldInfo = this.fieldInfo[property.propertyName];
30
+ if (!fieldInfo) {
31
+ fieldInfo = new ModelFieldInfo(property.readableName, displayValue);
32
+ this.fieldInfo[property.propertyName] = fieldInfo;
33
+ }
34
+ else {
35
+ fieldInfo.valueString = displayValue;
36
+ }
37
+ return fieldInfo;
38
+ };
28
39
  __decorate([
29
40
  Dictionary(ModelFieldInfo),
30
41
  __metadata("design:type", Object)
File without changes
File without changes
@@ -1,4 +1,17 @@
1
1
  import ValueObject from "./ValueObject";
2
+ import PropertyInfo from "./PropertyInfo";
3
+ export interface IModelFieldInfoContainer {
4
+ /**
5
+ * Extra information about lookup fields in this object.
6
+ */
7
+ fieldInfo: {
8
+ [K in keyof this]?: ModelFieldInfo;
9
+ };
10
+ /**
11
+ * Sets the model field info for a property.
12
+ */
13
+ setModelFieldInfo(property: PropertyInfo, displayValue: string): ModelFieldInfo;
14
+ }
2
15
  export declare class ModelFieldInfo extends ValueObject {
3
16
  constructor(displayName: string, valueString: string);
4
17
  /**
@@ -9,4 +22,8 @@ export declare class ModelFieldInfo extends ValueObject {
9
22
  * Lookup of the field value
10
23
  */
11
24
  valueString: string;
25
+ /**
26
+ * If the instance is a container of ModelFieldInfo, the instance is returned, otherwise null is returned.
27
+ */
28
+ static asModelFieldInfoContainer(instance: any): IModelFieldInfoContainer | null;
12
29
  }
@@ -17,6 +17,16 @@ var ModelFieldInfo = /** @class */ (function (_super) {
17
17
  _this.valueString = valueString;
18
18
  return _this;
19
19
  }
20
+ /**
21
+ * If the instance is a container of ModelFieldInfo, the instance is returned, otherwise null is returned.
22
+ */
23
+ ModelFieldInfo.asModelFieldInfoContainer = function (instance) {
24
+ if (instance.fieldInfo &&
25
+ instance.setModelFieldInfo) {
26
+ return instance;
27
+ }
28
+ return null;
29
+ };
20
30
  ModelFieldInfo = __decorate([
21
31
  NeoModel,
22
32
  __metadata("design:paramtypes", [String, String])
@@ -34,6 +34,7 @@ export declare class NeoTypeInfo {
34
34
  /** Copy the property info list from each base type into the current type. */
35
35
  merge(baseConstructor: NeoModelConstructor): void;
36
36
  ensureInitialised(): void;
37
+ createInstance(...args: any): any;
37
38
  /** Gets the override constructor which can setup a neo model. */
38
39
  getOverrideConstructor(): Function;
39
40
  private createWrapperConstructor;
@@ -165,12 +165,19 @@ var NeoTypeInfo = /** @class */ (function () {
165
165
  NeoTypeInfo.prototype.ensureInitialised = function () {
166
166
  if (!this.modelCreator) {
167
167
  // create a new instance which will cause the type to be setup.
168
- if (this.wrapperConstructor) {
169
- this.wrapperConstructor();
170
- }
171
- else {
172
- void new this.objectConstructor();
173
- }
168
+ this.createInstance();
169
+ }
170
+ };
171
+ NeoTypeInfo.prototype.createInstance = function () {
172
+ var args = [];
173
+ for (var _i = 0; _i < arguments.length; _i++) {
174
+ args[_i] = arguments[_i];
175
+ }
176
+ if (this.wrapperConstructor) {
177
+ return this.wrapperConstructor(args);
178
+ }
179
+ else {
180
+ return new this.objectConstructor(args);
174
181
  }
175
182
  };
176
183
  /** Gets the override constructor which can setup a neo model. */
@@ -4,7 +4,7 @@ export { IPropertyInstance, PropertyAccessor } from './PropertyInstance';
4
4
  export { IObservableValue, ObservableValue } from './ObservableValue';
5
5
  export { ObservableProperty } from './ObservableProperty';
6
6
  export { ISelectedItem } from './Misc';
7
- export { ModelFieldInfo } from './ModelFieldInfo';
7
+ export { ModelFieldInfo, IModelFieldInfoContainer } from './ModelFieldInfo';
8
8
  import * as GraphTraverser from './ModelGraphTraverser';
9
9
  export { GraphTraverser };
10
10
  export { AuditValues, AuditValuesBase } from './BaseModels/AuditValues';
@@ -16,14 +16,16 @@ export declare const Settings: {
16
16
  infoIcon: any;
17
17
  expanded: any;
18
18
  collapsed: any;
19
+ sortAsc: any;
20
+ sortDesc: any;
19
21
  };
20
22
  /** Grid default settings */
21
23
  grid: {
22
- /** When specified, the default bootstrap table borders (sides and cells) will be added */
24
+ /** Causes the table to have a border, cells will also have a left and right border. True by default. */
23
25
  isBordered: boolean;
24
26
  /** When specified, every alternating row will receive a slightly darker background color. */
25
27
  isStriped: boolean;
26
- /** When specified, the standard bootstrap table borders (sides and cells) will be removed. */
28
+ /** Removes the default top and bottom borders from rows. */
27
29
  isBorderless: boolean;
28
30
  /** When specified, a background color will be applied on a row if it is being hovered over. */
29
31
  showHover: boolean;
package/dist/Settings.js CHANGED
@@ -14,15 +14,17 @@ export var Settings = {
14
14
  warningIcon: "fa-exclamation-triangle",
15
15
  infoIcon: "fa-exclamation-circle",
16
16
  expanded: "far-minus-square",
17
- collapsed: "far-plus-square"
17
+ collapsed: "far-plus-square",
18
+ sortAsc: "sort-up",
19
+ sortDesc: "sort-down",
18
20
  },
19
21
  /** Grid default settings */
20
22
  grid: {
21
- /** When specified, the default bootstrap table borders (sides and cells) will be added */
23
+ /** Causes the table to have a border, cells will also have a left and right border. True by default. */
22
24
  isBordered: true,
23
25
  /** When specified, every alternating row will receive a slightly darker background color. */
24
26
  isStriped: false,
25
- /** When specified, the standard bootstrap table borders (sides and cells) will be removed. */
27
+ /** Removes the default top and bottom borders from rows. */
26
28
  isBorderless: false,
27
29
  /** When specified, a background color will be applied on a row if it is being hovered over. */
28
30
  showHover: false,
package/dist/Utils.js CHANGED
@@ -71,13 +71,12 @@ var Utils = /** @class */ (function () {
71
71
  * @param args Constructor args.
72
72
  */
73
73
  Utils.createInstance = function (type) {
74
- var _a;
75
74
  var args = [];
76
75
  for (var _i = 1; _i < arguments.length; _i++) {
77
76
  args[_i - 1] = arguments[_i];
78
77
  }
79
78
  if (type.prototype.constructor.neo) {
80
- return new ((_a = (type.prototype.constructor.neo.getOverrideConstructor())).bind.apply(_a, __spreadArrays([void 0], args)))();
79
+ return type.prototype.constructor.neo.createInstance(args);
81
80
  }
82
81
  else {
83
82
  throw "Cannot instantiate '" + type.name + "' because it does not have an @NeoModel attribute.";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@singularsystems/neo-core",
3
- "version": "0.10.62",
3
+ "version": "0.10.64",
4
4
  "description": "Core functionality for the Neo client library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",