@singularsystems/neo-core 0.10.71 → 0.10.72

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.
@@ -10,7 +10,6 @@ export default class DatePicker {
10
10
  private headerAnimationHelper;
11
11
  private inputHasChanged;
12
12
  private canAutoSetDate;
13
- private suspendLayout;
14
13
  private input;
15
14
  private popup;
16
15
  private headerContainer;
@@ -25,6 +24,7 @@ export default class DatePicker {
25
24
  private today;
26
25
  private currentViewDate;
27
26
  constructor(container: HTMLDivElement, options?: IPartialDateProps);
27
+ static mustShowInput(options?: IPartialDateProps): boolean | undefined;
28
28
  inputFocused(e: FocusEvent): void;
29
29
  inputBlurred(): void;
30
30
  onInputBlurred(closePopup: boolean): void;
@@ -65,6 +65,7 @@ export default class DatePicker {
65
65
  private previousClick;
66
66
  private nextClick;
67
67
  private moveCurrent;
68
+ private autoSetDay;
68
69
  private createAndAppend;
69
70
  destroy(): void;
70
71
  }
@@ -2,7 +2,6 @@ import DateUtils from '../../Dates/DateUtils';
2
2
  import AnimationHelper from '../AnimationHelper';
3
3
  import { YearsInYearView, ProcessedDatePickerOptions } from './DatePickerOptions';
4
4
  import PositionHelper from '../PositionHelper';
5
- import { Utils } from '../../Utils';
6
5
  // TODO: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat
7
6
  // TODO: Allow input to be shown with inline picker, and specify position.
8
7
  var ViewType;
@@ -17,7 +16,6 @@ var DatePicker = /** @class */ (function () {
17
16
  this.isReadOnly = false;
18
17
  this.inputHasChanged = false;
19
18
  this.canAutoSetDate = false;
20
- this.suspendLayout = false;
21
19
  this.currentBindValue = null;
22
20
  this.boundDateNoTime = null;
23
21
  this.options = ProcessedDatePickerOptions.fromPartial(options || {});
@@ -25,7 +23,7 @@ var DatePicker = /** @class */ (function () {
25
23
  this.inputBlurred = this.inputBlurred.bind(this);
26
24
  this.inputChanged = this.inputChanged.bind(this);
27
25
  this.inputKeyDown = this.inputKeyDown.bind(this);
28
- if (!this.options.alwaysShow) {
26
+ if (DatePicker.mustShowInput(options)) {
29
27
  this.input = this.container.getElementsByTagName('input')[0];
30
28
  this.input.addEventListener("focus", this.inputFocused);
31
29
  this.input.addEventListener("mousedown", this.inputFocused);
@@ -36,7 +34,13 @@ var DatePicker = /** @class */ (function () {
36
34
  this.input.placeholder = "hh:mm" + (this.options.formatString.indexOf("s") > 0 ? ":ss" : "");
37
35
  }
38
36
  }
37
+ if (this.options.alwaysShow) {
38
+ container.classList.add("neo-datepicker-always-show");
39
+ }
39
40
  }
41
+ DatePicker.mustShowInput = function (options) {
42
+ return !options || !options.alwaysShow || options.showInput;
43
+ };
40
44
  DatePicker.prototype.inputFocused = function (e) {
41
45
  if (!this.popup && !this.isReadOnly) {
42
46
  this.show();
@@ -111,7 +115,7 @@ var DatePicker = /** @class */ (function () {
111
115
  }
112
116
  };
113
117
  DatePicker.prototype.removePopup = function (animate) {
114
- if (this.popup) {
118
+ if (this.popup && !this.options.alwaysShow) {
115
119
  if (animate) {
116
120
  AnimationHelper.scale(this.popup, DatePicker.AnimationClassName, 1, 0);
117
121
  AnimationHelper.beginRemove(this.container, this.popup);
@@ -134,26 +138,26 @@ var DatePicker = /** @class */ (function () {
134
138
  // Note: this may have the side effect of calling update().
135
139
  this.setBindProperty(dateValue, false);
136
140
  this.setInputValue();
137
- if (!this.options.alwaysShow && options.close) {
141
+ if (options.close) {
138
142
  this.removePopup(true);
139
143
  }
144
+ if (!options.close || this.options.alwaysShow) {
145
+ this.resetCurrentViewDate();
146
+ this.populateContentContainer(true);
147
+ }
140
148
  };
141
149
  DatePicker.prototype.setBindProperty = function (dateValue, suspend) {
142
- var _this = this;
143
150
  if (dateValue) {
144
151
  dateValue = DateUtils.max(DateUtils.min(dateValue, this.options.maxDate), this.options.minDate);
145
152
  }
146
- if (suspend)
147
- this.suspendLayout = true;
153
+ this.currentBindValue = dateValue;
148
154
  this.bindProperty.value = dateValue;
149
- if (suspend)
150
- Utils.nextTick(function () { return _this.suspendLayout = false; });
151
155
  if (this.options.onDateSelected !== undefined) {
152
156
  this.options.onDateSelected(!suspend);
153
157
  }
154
158
  };
155
159
  DatePicker.prototype.setInputValue = function () {
156
- if (!this.options.alwaysShow) {
160
+ if (this.input) {
157
161
  var displayValue = "";
158
162
  if (this.bindProperty.value) {
159
163
  displayValue = DateUtils.format(this.bindProperty.value, this.options.formatString);
@@ -191,13 +195,9 @@ var DatePicker = /** @class */ (function () {
191
195
  this.currentBindValue = bindProperty === null || bindProperty === void 0 ? void 0 : bindProperty.value;
192
196
  this.resetCurrentViewDate();
193
197
  if (this.options.alwaysShow) {
194
- if (!this.suspendLayout) {
195
- this.createComponents();
196
- }
197
- }
198
- else {
199
- this.setInputValue();
198
+ this.createComponents();
200
199
  }
200
+ this.setInputValue();
201
201
  }
202
202
  };
203
203
  DatePicker.prototype.resetCurrentViewDate = function () {
@@ -312,13 +312,7 @@ var DatePicker = /** @class */ (function () {
312
312
  var currentDate = new Date(this.currentViewDate);
313
313
  var lastDayOfMonth = DateUtils.monthEnd(currentDate);
314
314
  this.prevButton.disabled = this.options.minDateNoTime.getTime() >= currentDate.getTime();
315
- if (this.canAutoSetDate && this.options.autoChangeDate == "start") {
316
- this.setBindProperty(currentDate, true);
317
- }
318
315
  this.nextButton.disabled = this.options.maxDateNoTime.getTime() <= lastDayOfMonth.getTime();
319
- if (this.canAutoSetDate && this.options.autoChangeDate == "end") {
320
- this.setBindProperty(lastDayOfMonth, true);
321
- }
322
316
  // Start with the first Sunday before the first of the month.
323
317
  currentDate.setDate(currentDate.getDate() - currentDate.getDay());
324
318
  var first = true;
@@ -471,6 +465,7 @@ var DatePicker = /** @class */ (function () {
471
465
  if (this.currentViewType == ViewType.Days) {
472
466
  this.canAutoSetDate = true;
473
467
  this.currentViewDate.setMonth(this.currentViewDate.getMonth() + delta, 1);
468
+ this.autoSetDay();
474
469
  }
475
470
  else {
476
471
  this.currentViewDate.setFullYear(this.currentViewDate.getFullYear() + delta * (this.currentViewType == ViewType.Months ? 1 : YearsInYearView));
@@ -478,6 +473,20 @@ var DatePicker = /** @class */ (function () {
478
473
  this.populateContentContainer(false, true);
479
474
  this.contentAnimationHelper.slide(delta, true);
480
475
  };
476
+ DatePicker.prototype.autoSetDay = function () {
477
+ var autoDate = null;
478
+ if (this.options.autoChangeDate === "end") {
479
+ // Forward
480
+ autoDate = DateUtils.monthEnd(this.currentViewDate);
481
+ }
482
+ else if (this.options.autoChangeDate === "start") {
483
+ // Back
484
+ autoDate = this.currentViewDate;
485
+ }
486
+ if (autoDate) {
487
+ this.setBindValue(autoDate, { preserveTime: true, close: false });
488
+ }
489
+ };
481
490
  DatePicker.prototype.createAndAppend = function (parent, elementType, className) {
482
491
  if (className === void 0) { className = ""; }
483
492
  var newElement = document.createElement(elementType);
@@ -13,6 +13,8 @@ export default class DatePickerOptions {
13
13
  timeOnly: boolean;
14
14
  /** Displays the picker inline and without an input control */
15
15
  alwaysShow: boolean;
16
+ /** Shows the input when using `alwaysShow`. */
17
+ showInput: boolean;
16
18
  minDate: Date;
17
19
  maxDate: Date;
18
20
  /** Automatically sets the date to the start or end of the displayed month when scrolling through months. */
@@ -11,11 +11,16 @@ export declare enum NumberFormat {
11
11
  }
12
12
  export default class NumberUtils {
13
13
  static thousandsSeparator: string;
14
+ static decimalSeparator?: string;
15
+ /** Set this to `","` if you want to allow a comma as a decimal separator when parsing string input. */
16
+ static allowAsDecimalSeparator?: string;
14
17
  static defaultCurrencySymbol: string;
15
18
  static numberFormats: {};
16
19
  /** If values typed into numeric editors should be divided by 100 when stored. */
17
20
  static transformPercent: boolean;
18
21
  static initialise(): void;
22
+ /** Uses the users local decimal separator when formatting and parsing numbers. */
23
+ static useLocaleDecimalSeparator(): void;
19
24
  /** Gets a format string for the pre-defined number format.
20
25
  * @param displayDecimals No of decimals to display if using a decimals format.
21
26
  */
@@ -3,7 +3,7 @@ import { DataType } from "./Model/Misc";
3
3
  import Globals from './Globals';
4
4
  export var NumberFormat;
5
5
  (function (NumberFormat) {
6
- // Mask is [Thousands Seperator, Decimals (2 places), Percent, Currency Symbol]
6
+ // Mask is [Thousands Separator, Decimals (2 places), Percent, Currency Symbol]
7
7
  NumberFormat[NumberFormat["None"] = 0] = "None";
8
8
  NumberFormat[NumberFormat["NoDecimals"] = 4096] = "NoDecimals";
9
9
  NumberFormat[NumberFormat["Decimals"] = 4352] = "Decimals";
@@ -24,6 +24,13 @@ var NumberUtils = /** @class */ (function () {
24
24
  NumberUtils.numberFormats[NumberFormat.CurrencyNoDecimals] = "_#,##0;(_#,##0)";
25
25
  NumberUtils.numberFormats[NumberFormat.CurrencyDecimals] = "_#,##0.00;(_#,##0.00)";
26
26
  };
27
+ /** Uses the users local decimal separator when formatting and parsing numbers. */
28
+ NumberUtils.useLocaleDecimalSeparator = function () {
29
+ this.decimalSeparator = 1.1.toLocaleString().substring(1, 2);
30
+ if (this.decimalSeparator !== ".") {
31
+ this.allowAsDecimalSeparator = this.decimalSeparator;
32
+ }
33
+ };
27
34
  /** Gets a format string for the pre-defined number format.
28
35
  * @param displayDecimals No of decimals to display if using a decimals format.
29
36
  */
@@ -232,6 +239,9 @@ var NumberUtils = /** @class */ (function () {
232
239
  }
233
240
  numberStrings[0] = str;
234
241
  }
242
+ if (this.decimalSeparator) {
243
+ decimal = this.decimalSeparator;
244
+ }
235
245
  numberStrings[1] = (numberParts[1] && numberStrings[1]) ? decimal + numberStrings[1] : "";
236
246
  numberStrings[0] = numberStrings[0].replace(/,/g, NumberUtils.thousandsSeparator);
237
247
  return beforeText + numberStrings[0] + numberStrings[1] + afterText; //put back any negation and combine integer and fraction.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@singularsystems/neo-core",
3
- "version": "0.10.71",
3
+ "version": "0.10.72",
4
4
  "description": "Core functionality for the Neo client library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",