@singularsystems/neo-core 1.0.4 → 1.0.6

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 || {});
@@ -243,13 +242,14 @@ var DatePicker = /** @class */ (function () {
243
242
  };
244
243
  DatePicker.prototype.createHeader = function () {
245
244
  var header = this.createAndAppend(this.popup, "div", "neo-datepicker-header");
245
+ header.addEventListener("mousedown", function (e) { return e.preventDefault(); });
246
246
  this.prevButton = this.createAndAppend(header, "button", "left-button");
247
247
  this.prevButton.type = "button";
248
248
  this.prevButton.innerText = "<";
249
249
  this.prevButton.tabIndex = -1;
250
250
  this.prevButton.addEventListener("mousedown", this.previousClick.bind(this));
251
251
  this.headerContainer = this.createAndAppend(header, "div", "header-text-container");
252
- this.headerContainer.addEventListener("mousedown", this.headerClick.bind(this));
252
+ this.headerContainer.addEventListener("mousedown", this.headerLabelClick.bind(this));
253
253
  this.headerAnimationHelper = new AnimationHelper(this.headerContainer, DatePicker.AnimationClassName);
254
254
  this.nextButton = this.createAndAppend(header, "button", "right-button");
255
255
  this.nextButton.type = "button";
@@ -338,7 +338,6 @@ var DatePicker = /** @class */ (function () {
338
338
  if (currentDate.getMonth() != this.currentViewDate.getMonth())
339
339
  break;
340
340
  }
341
- this.canAutoSetDate = false;
342
341
  };
343
342
  DatePicker.prototype.createMonthsView = function () {
344
343
  this.currentContentTable = this.createAndAppend(this.contentContainer, "table", "month-view");
@@ -421,7 +420,6 @@ var DatePicker = /** @class */ (function () {
421
420
  }
422
421
  else {
423
422
  this.currentViewType = ViewType.Days;
424
- this.canAutoSetDate = true;
425
423
  this.populateContentContainer(false);
426
424
  this.contentAnimationHelper.fadeAndScale(true);
427
425
  }
@@ -437,7 +435,7 @@ var DatePicker = /** @class */ (function () {
437
435
  this.contentAnimationHelper.fadeAndScale(true);
438
436
  }
439
437
  };
440
- DatePicker.prototype.headerClick = function (e) {
438
+ DatePicker.prototype.headerLabelClick = function (e) {
441
439
  e.preventDefault();
442
440
  if (this.currentHeaderLabel.classList.contains("selectable")) {
443
441
  if (this.currentViewType == ViewType.Days) {
@@ -463,7 +461,6 @@ var DatePicker = /** @class */ (function () {
463
461
  };
464
462
  DatePicker.prototype.moveCurrent = function (delta) {
465
463
  if (this.currentViewType == ViewType.Days) {
466
- this.canAutoSetDate = true;
467
464
  this.currentViewDate.setMonth(this.currentViewDate.getMonth() + delta, 1);
468
465
  this.autoSetDay();
469
466
  }
@@ -46,6 +46,9 @@ export type PartialPlainNonTrackedObject<T> = PartialPlainObject<T> & {
46
46
  export interface NeoModelConstructor extends Function {
47
47
  neo: NeoTypeInfo;
48
48
  }
49
+ export interface NeoModelConstructorInternal extends Function {
50
+ addBusinessRules?(validationRules: ValidationRules<IModelBase>): void;
51
+ }
49
52
  export interface IMakeBindableOptions {
50
53
  /**
51
54
  * Specifies whether properties should be observable
@@ -79,10 +79,15 @@ export default abstract class ModelBase extends BindableBase implements IModelBa
79
79
  * @param shouldSerialise The value determined by the serialiser.
80
80
  */
81
81
  protected canSerialise(shouldSerialise: boolean): boolean;
82
+ /** @deprecated Make your addBusinessRules method `static`. E.g.
83
+ * ```
84
+ * protected static addBusinessRules(rules: ValidationRules<MyType>) {
85
+ * ``` */
86
+ protected addBusinessRules(validationRules: ValidationRules<this>): void;
82
87
  /**
83
- * Add custom business rules. Note, this will be called once per type and should be treated as static.
88
+ * Add custom business rules for this type.
84
89
  */
85
- protected addBusinessRules(validationRules: ValidationRules<this>): void;
90
+ protected static addBusinessRules(rules: ValidationRules<ModelBase>): void;
86
91
  /** The server side type name used to find this type. Include the namespace if there is more than one type with the same name. */
87
92
  static typeName: string | null;
88
93
  }
@@ -142,10 +142,16 @@ var ModelBase = /** @class */ (function (_super) {
142
142
  ModelBase.prototype.canSerialise = function (shouldSerialise) {
143
143
  return shouldSerialise;
144
144
  };
145
+ /** @deprecated Make your addBusinessRules method `static`. E.g.
146
+ * ```
147
+ * protected static addBusinessRules(rules: ValidationRules<MyType>) {
148
+ * ``` */
149
+ ModelBase.prototype.addBusinessRules = function (validationRules) {
150
+ };
145
151
  /**
146
- * Add custom business rules. Note, this will be called once per type and should be treated as static.
152
+ * Add custom business rules for this type.
147
153
  */
148
- ModelBase.prototype.addBusinessRules = function (validationRules) {
154
+ ModelBase.addBusinessRules = function (rules) {
149
155
  };
150
156
  /** The server side type name used to find this type. Include the namespace if there is more than one type with the same name. */
151
157
  ModelBase.typeName = null;
@@ -125,9 +125,16 @@ var NeoTypeInfo = /** @class */ (function () {
125
125
  }
126
126
  };
127
127
  NeoTypeInfo.prototype.addRules = function (instance) {
128
- if (instance.addBusinessRules !== undefined) {
128
+ var hasStaticMethod = this.objectConstructor.hasOwnProperty("addBusinessRules");
129
+ var addRulesMethod = hasStaticMethod ? this.objectConstructor.addBusinessRules : instance.addBusinessRules;
130
+ if (addRulesMethod !== undefined) {
129
131
  var validationRules = new ValidationRules();
130
- instance.addBusinessRules(validationRules);
132
+ if (hasStaticMethod) {
133
+ addRulesMethod(validationRules);
134
+ }
135
+ else {
136
+ addRulesMethod.call(instance, validationRules);
137
+ }
131
138
  if (validationRules.rules.some(function (c) { return c instanceof CallbackRule && c.hasArrowFunction; })) {
132
139
  console.error("Warning: ".concat(this.objectConstructor.name, " has rules which have been added using an arrow function."));
133
140
  }
@@ -26,8 +26,6 @@ export default interface IAuthenticationService {
26
26
  tryCompleteSignIn(): Promise<ISignInResult>;
27
27
  signinSilent(): Promise<any>;
28
28
  endSignInSilent(): Promise<any>;
29
- /** Clears the user locally */
30
- signOutLocal(): void;
31
29
  beginSignOut(): void;
32
30
  endSignOut(): Promise<any>;
33
31
  /** Returns true if there is a user, and the token has not expired */
@@ -11,6 +11,7 @@ export default abstract class OidcAuthService<TUser extends OidcUser = OidcUser>
11
11
  protected userManager: IUserManager;
12
12
  private axios;
13
13
  private _user;
14
+ private isRedirecting;
14
15
  private afterUserLoadedPromise;
15
16
  /**
16
17
  * Creates an Oidc auth service
@@ -18,6 +19,7 @@ export default abstract class OidcAuthService<TUser extends OidcUser = OidcUser>
18
19
  * @param user User which existed in storage at startup
19
20
  */
20
21
  constructor(userManager: IUserManager, axios: AxiosInstance);
22
+ isSigningOut: boolean;
21
23
  loadUserFromToken(): Promise<TUser | null>;
22
24
  loadUserFromSession(): Promise<TUser | null>;
23
25
  ensureSignedIn(redirectLocal?: string): boolean;
@@ -45,7 +47,7 @@ export default abstract class OidcAuthService<TUser extends OidcUser = OidcUser>
45
47
  signinSilent(): Promise<IOidcUser | null>;
46
48
  beginSignOut(): void;
47
49
  endSignOut(): Promise<any>;
48
- signOutLocal(): void;
50
+ private signOutLocal;
49
51
  get user(): TUser | null;
50
52
  get isAuthenticated(): boolean;
51
53
  static createIdentityServerMetadata(identityServerUrl: string): {
@@ -18,6 +18,8 @@ var OidcAuthService = /** @class */ (function () {
18
18
  this.userManager = userManager;
19
19
  this.axios = axios;
20
20
  this._user = null;
21
+ this.isRedirecting = false;
22
+ this.isSigningOut = false;
21
23
  this.userManager = userManager;
22
24
  this.userManager.events.addUserLoaded(this.onUserLoaded.bind(this));
23
25
  this.userManager.events.addUserUnloaded(this.onUserUnloaded.bind(this));
@@ -64,7 +66,11 @@ var OidcAuthService = /** @class */ (function () {
64
66
  * @param redirectPath Local path to redirect to once login is complete.
65
67
  */
66
68
  OidcAuthService.prototype.beginSignIn = function (redirectPath) {
67
- return this.userManager.signinRedirect({ state: redirectPath });
69
+ if (!this.isRedirecting) {
70
+ this.isRedirecting = true;
71
+ return this.userManager.signinRedirect({ state: redirectPath });
72
+ }
73
+ return Promise.resolve();
68
74
  };
69
75
  ;
70
76
  /**
@@ -77,6 +83,7 @@ var OidcAuthService = /** @class */ (function () {
77
83
  switch (_a.label) {
78
84
  case 0:
79
85
  _a.trys.push([0, 2, , 3]);
86
+ this.isRedirecting = false;
80
87
  return [4 /*yield*/, this.userManager.signinRedirectCallback()];
81
88
  case 1:
82
89
  user = _a.sent();
@@ -168,14 +175,20 @@ var OidcAuthService = /** @class */ (function () {
168
175
  return this.userManager.signinSilent();
169
176
  };
170
177
  OidcAuthService.prototype.beginSignOut = function () {
171
- if (this._user) {
172
- this.userManager.signoutRedirect({ id_token_hint: this._user.userData.id_token });
173
- this.signOutLocal();
178
+ if (!this.isRedirecting) {
179
+ if (this._user) {
180
+ this.isRedirecting = true;
181
+ this.isSigningOut = true;
182
+ this.userManager.signoutRedirect({ id_token_hint: this._user.userData.id_token });
183
+ this.signOutLocal();
184
+ }
185
+ this.userManager.clearStaleState();
174
186
  }
175
- this.userManager.clearStaleState();
176
187
  };
177
188
  ;
178
189
  OidcAuthService.prototype.endSignOut = function () {
190
+ this.isRedirecting = false;
191
+ this.isSigningOut = false;
179
192
  return this.userManager.signoutRedirectCallback();
180
193
  };
181
194
  ;
@@ -5,10 +5,12 @@ export declare class ValidationRules<T extends IModelBase> {
5
5
  rules: CustomRule<T>[];
6
6
  /**
7
7
  * Registers a custom rule.
8
- * **NOTE: Do not use `.bind(this)`, and do not use an arrow function:**, either pass in the address of a function: add(this.myRule), or pass an anonymous function: add(function(context) {}).
9
- * @param ruleFunction
8
+ * - Pass in the address of a function: `add(MyType.prototype.myRule)`
9
+ * - or pass an anonymous function: `add(function(context) {})`
10
+ *
11
+ * **NOTE: Do not use `.bind(this)`, and do not use an arrow function**.
10
12
  */
11
- add(ruleFunction: (context: IRuleContext) => void): ICustomRule<T>;
13
+ add(ruleFunction: (this: T, context: IRuleContext) => void): ICustomRule<T>;
12
14
  failWhen(failCondition: RuleExpression<T>, errorTextExpression: ErrorExpression<T>): IExpressionRule<T>;
13
15
  failWhen(failCondition: RuleExpression<T>, errorText: string): IExpressionRule<T>;
14
16
  warnWhen(condition: RuleExpression<T>, warningTextExpression: ErrorExpression<T>): IExpressionRule<T>;
@@ -6,8 +6,10 @@ var ValidationRules = /** @class */ (function () {
6
6
  }
7
7
  /**
8
8
  * Registers a custom rule.
9
- * **NOTE: Do not use `.bind(this)`, and do not use an arrow function:**, either pass in the address of a function: add(this.myRule), or pass an anonymous function: add(function(context) {}).
10
- * @param ruleFunction
9
+ * - Pass in the address of a function: `add(MyType.prototype.myRule)`
10
+ * - or pass an anonymous function: `add(function(context) {})`
11
+ *
12
+ * **NOTE: Do not use `.bind(this)`, and do not use an arrow function**.
11
13
  */
12
14
  ValidationRules.prototype.add = function (ruleFunction) {
13
15
  var rule = new CallbackRule(ruleFunction);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@singularsystems/neo-core",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Core functionality for the Neo client library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",