abledom 0.0.1 → 0.0.3

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.
package/dist/index.d.ts CHANGED
@@ -2,33 +2,37 @@
2
2
  * Copyright (c) Microsoft Corporation. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- interface ValidationError {
5
+ declare enum ValidationRuleType {
6
+ Error = 1,
7
+ Warning = 2,
8
+ Info = 3
9
+ }
10
+ interface ValidationNotification {
6
11
  id: string;
7
12
  message: string;
13
+ element?: HTMLElement;
8
14
  rel?: Node;
9
15
  link?: string;
10
16
  stack?: string[];
11
17
  relStack?: string[];
12
18
  }
13
19
  interface ValidationResult {
14
- error?: ValidationError;
20
+ notification?: ValidationNotification;
15
21
  dependsOnIds?: Set<string>;
16
22
  }
17
- interface FocusError {
18
- element: HTMLElement;
19
- error: ValidationError;
20
- }
21
- interface BlurError {
22
- element: HTMLElement;
23
+ interface BlurNotification extends ValidationNotification {
23
24
  position?: string[];
24
- error: ValidationError;
25
25
  }
26
- declare abstract class ValidationRule {
26
+ declare abstract class ValidationRule<N extends ValidationNotification = ValidationNotification> {
27
+ abstract type: ValidationRuleType;
27
28
  abstract name: string;
28
29
  private _window?;
29
30
  private _exceptions;
30
- static setWindow(instance: ValidationRule, window: Window): void;
31
+ private _onNotification;
32
+ static init(instance: ValidationRule, window: Window, onNotification: (rule: ValidationRule, notification: ValidationNotification) => void): void;
33
+ static dispose(instance: ValidationRule): void;
31
34
  static checkExceptions(instance: ValidationRule, element: HTMLElement): boolean;
35
+ private dispose;
32
36
  addException(checkException: (element: HTMLElement) => boolean): void;
33
37
  removeException(checkException: (element: HTMLElement) => boolean): void;
34
38
  /**
@@ -45,8 +49,9 @@ declare abstract class ValidationRule {
45
49
  stop?(): void;
46
50
  accept?(element: HTMLElement): boolean;
47
51
  validate?(element: HTMLElement): ValidationResult | null;
48
- focused?(event: FocusEvent): Promise<FocusError | null>;
49
- blurred?(event: FocusEvent): Promise<BlurError | null>;
52
+ notify(notification: N): void;
53
+ focused?(event: FocusEvent): ValidationNotification | null;
54
+ blurred?(event: FocusEvent): BlurNotification | null;
50
55
  }
51
56
 
52
57
  /*!
@@ -55,10 +60,10 @@ declare abstract class ValidationRule {
55
60
  */
56
61
 
57
62
  declare class AbleDOM {
58
- private _window;
63
+ private _win;
59
64
  private _observer;
60
65
  private _clearValidationTimeout;
61
- private _elementsWithErrors;
66
+ private _elementsWithNotifications;
62
67
  private _changedElementIds;
63
68
  private _elementsDependingOnId;
64
69
  private _dependantIdsByElement;
@@ -68,13 +73,14 @@ declare class AbleDOM {
68
73
  private _isStarted;
69
74
  constructor(win: Window);
70
75
  private _onElementId;
71
- private _addValidationError;
72
- private _removeElementError;
76
+ private _addNotification;
77
+ private _removeNotification;
73
78
  private _validate;
74
79
  private _processElementDependingOnIds;
75
80
  private _remove;
76
81
  private _onFocusIn;
77
82
  private _onFocusOut;
83
+ private _notifyAsync;
78
84
  addRule(rule: ValidationRule): void;
79
85
  removeRule(rule: ValidationRule): void;
80
86
  start(): void;
@@ -82,6 +88,7 @@ declare class AbleDOM {
82
88
  }
83
89
 
84
90
  declare class AtomicRule extends ValidationRule {
91
+ type: ValidationRuleType;
85
92
  name: string;
86
93
  anchored: boolean;
87
94
  accept(element: HTMLElement): boolean;
@@ -94,6 +101,7 @@ declare class AtomicRule extends ValidationRule {
94
101
  */
95
102
 
96
103
  declare class FocusableElementLabelRule extends ValidationRule {
104
+ type: ValidationRuleType;
97
105
  name: string;
98
106
  anchored: boolean;
99
107
  private _isAriaHidden;
@@ -108,6 +116,7 @@ declare class FocusableElementLabelRule extends ValidationRule {
108
116
  */
109
117
 
110
118
  declare class ExistingIdRule extends ValidationRule {
119
+ type: ValidationRuleType;
111
120
  name: string;
112
121
  anchored: boolean;
113
122
  accept(element: HTMLElement): boolean;
@@ -119,7 +128,8 @@ declare class ExistingIdRule extends ValidationRule {
119
128
  * Licensed under the MIT License.
120
129
  */
121
130
 
122
- declare class FocusLostRule extends ValidationRule {
131
+ declare class FocusLostRule extends ValidationRule<BlurNotification> {
132
+ type: ValidationRuleType;
123
133
  name: string;
124
134
  anchored: boolean;
125
135
  private _focusLostTimeout;
@@ -128,9 +138,13 @@ declare class FocusLostRule extends ValidationRule {
128
138
  private _focusedElementPosition;
129
139
  private _lastFocusStack;
130
140
  private _lastBlurStack;
141
+ private _mouseEventTimer;
142
+ private _releaseMouseEvent;
131
143
  private _serializeElementPosition;
132
- focused(event: FocusEvent): Promise<FocusError | null>;
133
- blurred(event: FocusEvent): Promise<BlurError | null>;
144
+ focused(event: FocusEvent): null;
145
+ blurred(event: FocusEvent): null;
146
+ start(): void;
147
+ stop(): void;
134
148
  }
135
149
 
136
150
  /*!
@@ -139,13 +153,51 @@ declare class FocusLostRule extends ValidationRule {
139
153
  */
140
154
 
141
155
  declare class BadFocusRule extends ValidationRule {
156
+ type: ValidationRuleType;
142
157
  name: string;
143
158
  anchored: boolean;
144
159
  private _lastFocusStack;
145
160
  private _lastBlurStack;
146
- private _reject;
147
- focused(): Promise<FocusError | null>;
148
- blurred(): Promise<BlurError | null>;
161
+ private _clearCheckTimer;
162
+ focused(): null;
163
+ blurred(): null;
164
+ stop(): void;
165
+ }
166
+
167
+ /*!
168
+ * Copyright (c) Microsoft Corporation. All rights reserved.
169
+ * Licensed under the MIT License.
170
+ */
171
+
172
+ declare class FindElementRule extends ValidationRule {
173
+ type: ValidationRuleType;
174
+ name: string;
175
+ anchored: boolean;
176
+ private _conditions;
177
+ addCondition(name: string, condition: (element: HTMLElement) => boolean): void;
178
+ removeCondition(name: string): void;
179
+ validate(element: HTMLElement): ValidationResult | null;
180
+ }
181
+
182
+ /*!
183
+ * Copyright (c) Microsoft Corporation. All rights reserved.
184
+ * Licensed under the MIT License.
185
+ */
186
+
187
+ declare class CustomNotifyRule extends ValidationRule {
188
+ type: ValidationRuleType;
189
+ name: string;
190
+ anchored: boolean;
191
+ customNotify(message: string, element?: HTMLElement): void;
192
+ }
193
+
194
+ interface HTMLElementAttributes {
195
+ readonly [name: string]: string;
149
196
  }
197
+ declare function isAccessibilityAffectingElement(element: HTMLElement): boolean;
198
+ declare function hasAccessibilityAttribute(attributes: HTMLElementAttributes): boolean;
199
+ declare function matchesSelector(element: HTMLElement, selector: string): boolean;
200
+ declare function isDisplayNone(element: HTMLElement): boolean;
201
+ declare function isElementVisible(element: HTMLElement): boolean;
150
202
 
151
- export { AbleDOM, AtomicRule, BadFocusRule, type BlurError, ExistingIdRule, type FocusError, FocusLostRule, FocusableElementLabelRule, ValidationRule };
203
+ export { AbleDOM, AtomicRule, BadFocusRule, type BlurNotification, CustomNotifyRule, ExistingIdRule, FindElementRule, FocusLostRule, FocusableElementLabelRule, type ValidationNotification, type ValidationResult, ValidationRule, ValidationRuleType, hasAccessibilityAttribute, isAccessibilityAffectingElement, isDisplayNone, isElementVisible, matchesSelector };