@singularsystems/neo-core 1.0.5 → 1.0.7

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.
@@ -9,7 +9,6 @@ export default class DatePicker {
9
9
  private contentAnimationHelper;
10
10
  private headerAnimationHelper;
11
11
  private inputHasChanged;
12
- private canAutoSetDate;
13
12
  private input;
14
13
  private popup;
15
14
  private headerContainer;
@@ -61,7 +60,7 @@ export default class DatePicker {
61
60
  private dayClicked;
62
61
  private monthClicked;
63
62
  private yearClicked;
64
- private headerClick;
63
+ private headerLabelClick;
65
64
  private previousClick;
66
65
  private nextClick;
67
66
  private moveCurrent;
@@ -15,7 +15,6 @@ var DatePicker = /** @class */ (function () {
15
15
  this.container = container;
16
16
  this.isReadOnly = false;
17
17
  this.inputHasChanged = false;
18
- this.canAutoSetDate = false;
19
18
  this.currentBindValue = null;
20
19
  this.boundDateNoTime = null;
21
20
  this.options = ProcessedDatePickerOptions.fromPartial(options || {});
@@ -175,7 +174,8 @@ var DatePicker = /** @class */ (function () {
175
174
  };
176
175
  DatePicker.prototype.positionPopup = function (fromBottom) {
177
176
  if (this.popup) {
178
- PositionHelper.checkScreenBounds(this.container, this.popup, fromBottom, this.options.popupAlignRight);
177
+ var textAlign = this.options.popupAlignRight ? undefined : window.getComputedStyle(this.input).textAlign;
178
+ PositionHelper.checkScreenBounds(this.container, this.popup, fromBottom, this.options.popupAlignRight, textAlign);
179
179
  }
180
180
  };
181
181
  /**
@@ -243,13 +243,14 @@ var DatePicker = /** @class */ (function () {
243
243
  };
244
244
  DatePicker.prototype.createHeader = function () {
245
245
  var header = this.createAndAppend(this.popup, "div", "neo-datepicker-header");
246
+ header.addEventListener("mousedown", function (e) { return e.preventDefault(); });
246
247
  this.prevButton = this.createAndAppend(header, "button", "left-button");
247
248
  this.prevButton.type = "button";
248
249
  this.prevButton.innerText = "<";
249
250
  this.prevButton.tabIndex = -1;
250
251
  this.prevButton.addEventListener("mousedown", this.previousClick.bind(this));
251
252
  this.headerContainer = this.createAndAppend(header, "div", "header-text-container");
252
- this.headerContainer.addEventListener("mousedown", this.headerClick.bind(this));
253
+ this.headerContainer.addEventListener("mousedown", this.headerLabelClick.bind(this));
253
254
  this.headerAnimationHelper = new AnimationHelper(this.headerContainer, DatePicker.AnimationClassName);
254
255
  this.nextButton = this.createAndAppend(header, "button", "right-button");
255
256
  this.nextButton.type = "button";
@@ -338,7 +339,6 @@ var DatePicker = /** @class */ (function () {
338
339
  if (currentDate.getMonth() != this.currentViewDate.getMonth())
339
340
  break;
340
341
  }
341
- this.canAutoSetDate = false;
342
342
  };
343
343
  DatePicker.prototype.createMonthsView = function () {
344
344
  this.currentContentTable = this.createAndAppend(this.contentContainer, "table", "month-view");
@@ -421,7 +421,6 @@ var DatePicker = /** @class */ (function () {
421
421
  }
422
422
  else {
423
423
  this.currentViewType = ViewType.Days;
424
- this.canAutoSetDate = true;
425
424
  this.populateContentContainer(false);
426
425
  this.contentAnimationHelper.fadeAndScale(true);
427
426
  }
@@ -437,7 +436,7 @@ var DatePicker = /** @class */ (function () {
437
436
  this.contentAnimationHelper.fadeAndScale(true);
438
437
  }
439
438
  };
440
- DatePicker.prototype.headerClick = function (e) {
439
+ DatePicker.prototype.headerLabelClick = function (e) {
441
440
  e.preventDefault();
442
441
  if (this.currentHeaderLabel.classList.contains("selectable")) {
443
442
  if (this.currentViewType == ViewType.Days) {
@@ -463,7 +462,6 @@ var DatePicker = /** @class */ (function () {
463
462
  };
464
463
  DatePicker.prototype.moveCurrent = function (delta) {
465
464
  if (this.currentViewType == ViewType.Days) {
466
- this.canAutoSetDate = true;
467
465
  this.currentViewDate.setMonth(this.currentViewDate.getMonth() + delta, 1);
468
466
  this.autoSetDay();
469
467
  }
@@ -5,6 +5,7 @@ export default class PositionHelper {
5
5
  * @param popup The element which pops up from the anchor.
6
6
  * @param fromBottom True if the popups bottom style property must be set. Set to false if there are buttons at the top of the popup and the popups height may change.
7
7
  * @param alignRight True if the popup must be aligned to the anchors right position.
8
+ * @param hAlign Horizontal alignment of the popup edge relative to the anchor edge. Overrides alignRight
8
9
  */
9
- static checkScreenBounds(anchor: HTMLElement, popup: HTMLElement, fromBottom?: boolean, alignRight?: boolean): void;
10
+ static checkScreenBounds(anchor: HTMLElement, popup: HTMLElement, fromBottom?: boolean, alignRight?: boolean, hAlign?: "left" | "center" | "right"): void;
10
11
  }
@@ -7,12 +7,14 @@ var PositionHelper = /** @class */ (function () {
7
7
  * @param popup The element which pops up from the anchor.
8
8
  * @param fromBottom True if the popups bottom style property must be set. Set to false if there are buttons at the top of the popup and the popups height may change.
9
9
  * @param alignRight True if the popup must be aligned to the anchors right position.
10
+ * @param hAlign Horizontal alignment of the popup edge relative to the anchor edge. Overrides alignRight
10
11
  */
11
- PositionHelper.checkScreenBounds = function (anchor, popup, fromBottom, alignRight) {
12
+ PositionHelper.checkScreenBounds = function (anchor, popup, fromBottom, alignRight, hAlign) {
12
13
  if (fromBottom === void 0) { fromBottom = true; }
13
14
  if (alignRight === void 0) { alignRight = false; }
14
15
  var popupHeight = popup.offsetHeight;
15
16
  var containerScreenRect = anchor.getBoundingClientRect();
17
+ // Vertical
16
18
  if (containerScreenRect.bottom + anchor.offsetHeight + popupHeight > window.innerHeight - 20 && containerScreenRect.top > popupHeight) {
17
19
  if (fromBottom) {
18
20
  popup.style.top = "auto";
@@ -27,15 +29,30 @@ var PositionHelper = /** @class */ (function () {
27
29
  popup.style.top = "100%";
28
30
  popup.style.bottom = "auto";
29
31
  }
32
+ // Horizontal
30
33
  var popupWidth = popup.offsetWidth;
31
- if ((!alignRight && containerScreenRect.left + popupWidth > window.innerWidth - 20) ||
32
- (alignRight && containerScreenRect.right - popupWidth >= 0)) {
34
+ if (!hAlign) {
35
+ hAlign = alignRight ? "right" : "left";
36
+ }
37
+ var isRightAligned = hAlign === "right" && (containerScreenRect.right - popupWidth >= 0);
38
+ if (isRightAligned) {
33
39
  popup.style.left = "auto";
34
40
  popup.style.right = "0";
35
41
  }
36
42
  else {
37
- popup.style.left = "0";
38
- popup.style.right = "auto";
43
+ var left = 0;
44
+ if (hAlign === "center") {
45
+ left = (containerScreenRect.width - popup.offsetWidth) / 2;
46
+ }
47
+ var leftCheck = containerScreenRect.left + left;
48
+ if (leftCheck < 0) {
49
+ left -= leftCheck;
50
+ }
51
+ else if (leftCheck + popup.offsetWidth > window.innerWidth - 20) {
52
+ left -= (leftCheck + popup.offsetWidth) - (window.innerWidth - 20);
53
+ }
54
+ popup.style.left = left + "px";
55
+ popup.style.right = "";
39
56
  }
40
57
  };
41
58
  return PositionHelper;
@@ -125,24 +125,29 @@ var NeoTypeInfo = /** @class */ (function () {
125
125
  }
126
126
  };
127
127
  NeoTypeInfo.prototype.addRules = function (instance) {
128
- var _a;
129
- var addRulesMethod = (_a = this.objectConstructor.addBusinessRules) !== null && _a !== void 0 ? _a : instance.addBusinessRules;
128
+ var hasStaticMethod = this.objectConstructor.hasOwnProperty("addBusinessRules");
129
+ var addRulesMethod = hasStaticMethod ? this.objectConstructor.addBusinessRules : instance.addBusinessRules;
130
130
  if (addRulesMethod !== undefined) {
131
131
  var validationRules = new ValidationRules();
132
- addRulesMethod(validationRules);
132
+ if (hasStaticMethod) {
133
+ addRulesMethod(validationRules);
134
+ }
135
+ else {
136
+ addRulesMethod.call(instance, validationRules);
137
+ }
133
138
  if (validationRules.rules.some(function (c) { return c instanceof CallbackRule && c.hasArrowFunction; })) {
134
139
  console.error("Warning: ".concat(this.objectConstructor.name, " has rules which have been added using an arrow function."));
135
140
  }
136
141
  var modelProxy = new ModelProxy(instance);
137
- for (var _i = 0, _b = validationRules.rules; _i < _b.length; _i++) {
138
- var rule = _b[_i];
142
+ for (var _i = 0, _a = validationRules.rules; _i < _a.length; _i++) {
143
+ var rule = _a[_i];
139
144
  var properties = rule.getDisplayProperties(this.propertyMap);
140
145
  if (properties === undefined && rule instanceof ExpressionRule) {
141
146
  properties = modelProxy.tryExtractProperties(rule);
142
147
  }
143
148
  if (properties && properties.length) {
144
- for (var _c = 0, properties_1 = properties; _c < properties_1.length; _c++) {
145
- var property = properties_1[_c];
149
+ for (var _b = 0, properties_1 = properties; _b < properties_1.length; _b++) {
150
+ var property = properties_1[_b];
146
151
  property.rules.push(rule);
147
152
  }
148
153
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@singularsystems/neo-core",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Core functionality for the Neo client library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",