@vaadin/component-base 23.1.0-alpha3 → 23.1.0-beta2

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.
@@ -1,11 +1,11 @@
1
1
  interface Vaadin {
2
2
  developmentModeCallback?: {
3
- 'usage-statistics'?: () => void;
4
- 'vaadin-license-checker'?: () => void;
3
+ 'usage-statistics'?(): void;
4
+ 'vaadin-license-checker'?(): void;
5
5
  };
6
6
  registrations?: Array<{ is: string; version: string }>;
7
7
  usageStatsChecker?: {
8
- maybeGatherAndSend: () => void;
8
+ maybeGatherAndSend(): void;
9
9
  };
10
10
  }
11
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/component-base",
3
- "version": "23.1.0-alpha3",
3
+ "version": "23.1.0-beta2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -42,5 +42,5 @@
42
42
  "@vaadin/testing-helpers": "^0.3.2",
43
43
  "sinon": "^13.0.2"
44
44
  },
45
- "gitHead": "8c9e64e8dfa158dd52a9bf6da351ff038c88ca85"
45
+ "gitHead": "f11f9245a0b5e6bf912725a501c27c24b74e7c8d"
46
46
  }
@@ -17,7 +17,7 @@ import { KeyboardMixinClass } from './keyboard-mixin.js';
17
17
  * by the pointer or by releasing the activation key.
18
18
  */
19
19
  export declare function ActiveMixin<T extends Constructor<HTMLElement>>(
20
- base: T
20
+ base: T,
21
21
  ): T & Constructor<ActiveMixinClass> & Constructor<DisabledMixinClass> & Constructor<KeyboardMixinClass>;
22
22
 
23
23
  export declare class ActiveMixinClass {
package/src/async.d.ts ADDED
@@ -0,0 +1,114 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
4
+ * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5
+ * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6
+ * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7
+ * Code distributed by Google as part of the polymer project is also
8
+ * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9
+ */
10
+
11
+ export interface AsyncInterface {
12
+ run(fn: Function, delay?: number): number;
13
+ cancel(handle: number): void;
14
+ }
15
+
16
+ /**
17
+ * Not defined in the TypeScript DOM library.
18
+ * See https://developer.mozilla.org/en-US/docs/Web/API/IdleDeadline
19
+ */
20
+ export interface IdleDeadline {
21
+ didTimeout: boolean;
22
+ timeRemaining(): number;
23
+ }
24
+
25
+ /**
26
+ * Async interface wrapper around `setTimeout`.
27
+ */
28
+ declare namespace timeOut {
29
+ /**
30
+ * Returns a sub-module with the async interface providing the provided
31
+ * delay.
32
+ *
33
+ * @returns An async timeout interface
34
+ */
35
+ function after(delay?: number): AsyncInterface;
36
+
37
+ /**
38
+ * Enqueues a function called in the next task.
39
+ *
40
+ * @returns Handle used for canceling task
41
+ */
42
+ function run(fn: Function, delay?: number): number;
43
+
44
+ /**
45
+ * Cancels a previously enqueued `timeOut` callback.
46
+ */
47
+ function cancel(handle: number): void;
48
+ }
49
+
50
+ export { timeOut };
51
+
52
+ /**
53
+ * Async interface wrapper around `requestAnimationFrame`.
54
+ */
55
+ declare namespace animationFrame {
56
+ /**
57
+ * Enqueues a function called at `requestAnimationFrame` timing.
58
+ *
59
+ * @returns Handle used for canceling task
60
+ */
61
+ function run(fn: (p0: number) => void): number;
62
+
63
+ /**
64
+ * Cancels a previously enqueued `animationFrame` callback.
65
+ */
66
+ function cancel(handle: number): void;
67
+ }
68
+
69
+ export { animationFrame };
70
+
71
+ /**
72
+ * Async interface wrapper around `requestIdleCallback`. Falls back to
73
+ * `setTimeout` on browsers that do not support `requestIdleCallback`.
74
+ */
75
+ declare namespace idlePeriod {
76
+ /**
77
+ * Enqueues a function called at `requestIdleCallback` timing.
78
+ *
79
+ * @returns Handle used for canceling task
80
+ */
81
+ function run(fn: (p0: IdleDeadline) => void): number;
82
+
83
+ /**
84
+ * Cancels a previously enqueued `idlePeriod` callback.
85
+ */
86
+ function cancel(handle: number): void;
87
+ }
88
+
89
+ export { idlePeriod };
90
+
91
+ /**
92
+ * Async interface for enqueuing callbacks that run at microtask timing.
93
+ *
94
+ * Note that microtask timing is achieved via a single `MutationObserver`,
95
+ * and thus callbacks enqueued with this API will all run in a single
96
+ * batch, and not interleaved with other microtasks such as promises.
97
+ * Promises are avoided as an implementation choice for the time being
98
+ * due to Safari bugs that cause Promises to lack microtask guarantees.
99
+ */
100
+ declare namespace microTask {
101
+ /**
102
+ * Enqueues a function called at microtask timing.
103
+ *
104
+ * @returns Handle used for canceling task
105
+ */
106
+ function run(callback?: Function): number;
107
+
108
+ /**
109
+ * Cancels a previously enqueued `microTask` callback.
110
+ */
111
+ function cancel(handle: number): void;
112
+ }
113
+
114
+ export { microTask };
package/src/async.js CHANGED
@@ -70,7 +70,7 @@ const timeOut = {
70
70
  },
71
71
  cancel(handle) {
72
72
  window.clearTimeout(handle);
73
- }
73
+ },
74
74
  };
75
75
  },
76
76
  /**
@@ -93,7 +93,7 @@ const timeOut = {
93
93
  */
94
94
  cancel(handle) {
95
95
  window.clearTimeout(handle);
96
- }
96
+ },
97
97
  };
98
98
  export { timeOut };
99
99
 
@@ -123,7 +123,7 @@ const animationFrame = {
123
123
  */
124
124
  cancel(handle) {
125
125
  window.cancelAnimationFrame(handle);
126
- }
126
+ },
127
127
  };
128
128
  export { animationFrame };
129
129
 
@@ -153,8 +153,12 @@ const idlePeriod = {
153
153
  * @return {void}
154
154
  */
155
155
  cancel(handle) {
156
- window.cancelIdleCallback ? window.cancelIdleCallback(handle) : window.clearTimeout(handle);
157
- }
156
+ if (window.cancelIdleCallback) {
157
+ window.cancelIdleCallback(handle);
158
+ } else {
159
+ window.clearTimeout(handle);
160
+ }
161
+ },
158
162
  };
159
163
  export { idlePeriod };
160
164
 
@@ -202,10 +206,10 @@ const microTask = {
202
206
  const idx = handle - microtaskLastHandle;
203
207
  if (idx >= 0) {
204
208
  if (!microtaskCallbacks[idx]) {
205
- throw new Error('invalid async handle: ' + handle);
209
+ throw new Error(`invalid async handle: ${handle}`);
206
210
  }
207
211
  microtaskCallbacks[idx] = null;
208
212
  }
209
- }
213
+ },
210
214
  };
211
215
  export { microTask };
@@ -16,7 +16,7 @@ export const isChrome = testUserAgent(/Chrome/) && testVendor(/Google Inc/);
16
16
 
17
17
  export const isFirefox = testUserAgent(/Firefox/);
18
18
 
19
- // iPadOS 13 lies and says it's a Mac, but we can distinguish by detecting touch support.
19
+ // IPadOS 13 lies and says it's a Mac, but we can distinguish by detecting touch support.
20
20
  export const isIPad = testPlatform(/^iPad/) || (testPlatform(/^Mac/) && navigator.maxTouchPoints > 1);
21
21
 
22
22
  export const isIPhone = testPlatform(/^iPhone/);
@@ -10,7 +10,7 @@ import { ReactiveController, ReactiveControllerHost } from 'lit';
10
10
  * A mixin for connecting controllers to the element.
11
11
  */
12
12
  export declare function ControllerMixin<T extends Constructor<HTMLElement>>(
13
- superclass: T
13
+ superclass: T,
14
14
  ): T & Constructor<ControllerMixinClass>;
15
15
 
16
16
  export declare class ControllerMixinClass
@@ -27,7 +27,9 @@ export const ControllerMixin = dedupingMixin(
27
27
  super.connectedCallback();
28
28
 
29
29
  this.__controllers.forEach((c) => {
30
- c.hostConnected && c.hostConnected();
30
+ if (c.hostConnected) {
31
+ c.hostConnected();
32
+ }
31
33
  });
32
34
  }
33
35
 
@@ -36,7 +38,9 @@ export const ControllerMixin = dedupingMixin(
36
38
  super.disconnectedCallback();
37
39
 
38
40
  this.__controllers.forEach((c) => {
39
- c.hostDisconnected && c.hostDisconnected();
41
+ if (c.hostDisconnected) {
42
+ c.hostDisconnected();
43
+ }
40
44
  });
41
45
  }
42
46
 
@@ -63,5 +67,5 @@ export const ControllerMixin = dedupingMixin(
63
67
  removeController(controller) {
64
68
  this.__controllers.delete(controller);
65
69
  }
66
- }
70
+ },
67
71
  );
@@ -0,0 +1,101 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
4
+ * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5
+ * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6
+ * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7
+ * Code distributed by Google as part of the polymer project is also
8
+ * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9
+ */
10
+ import { AsyncInterface } from './async.js';
11
+
12
+ export declare class Debouncer {
13
+ constructor();
14
+
15
+ /**
16
+ * Creates a debouncer if no debouncer is passed as a parameter
17
+ * or it cancels an active debouncer otherwise. The following
18
+ * example shows how a debouncer can be called multiple times within a
19
+ * microtask and "debounced" such that the provided callback function is
20
+ * called once. Add this method to a custom element:
21
+ *
22
+ * ```js
23
+ * import {microTask} from '@vaadin/component-base/src/async.js';
24
+ * import {Debouncer} from '@vaadin/component-base/src/debounce.js';
25
+ * // ...
26
+ *
27
+ * _debounceWork() {
28
+ * this._debounceJob = Debouncer.debounce(this._debounceJob,
29
+ * microTask, () => this._doWork());
30
+ * }
31
+ * ```
32
+ *
33
+ * If the `_debounceWork` method is called multiple times within the same
34
+ * microtask, the `_doWork` function will be called only once at the next
35
+ * microtask checkpoint.
36
+ *
37
+ * Note: In testing it is often convenient to avoid asynchrony. To accomplish
38
+ * this with a debouncer, you can use `enqueueDebouncer` and
39
+ * `flush`. For example, extend the above example by adding
40
+ * `enqueueDebouncer(this._debounceJob)` at the end of the
41
+ * `_debounceWork` method. Then in a test, call `flush` to ensure
42
+ * the debouncer has completed.
43
+ *
44
+ * @param debouncer Debouncer object.
45
+ * @param asyncModule Object with Async interface
46
+ * @param callback Callback to run.
47
+ * @returns Returns a debouncer object.
48
+ */
49
+ static debounce(debouncer: Debouncer | null, asyncModule: AsyncInterface, callback: () => any): Debouncer;
50
+
51
+ /**
52
+ * Sets the scheduler; that is, a module with the Async interface,
53
+ * a callback and optional arguments to be passed to the run function
54
+ * from the async module.
55
+ *
56
+ * @param asyncModule Object with Async interface.
57
+ * @param callback Callback to run.
58
+ */
59
+ setConfig(asyncModule: AsyncInterface, callback: () => any): void;
60
+
61
+ /**
62
+ * Cancels an active debouncer and returns a reference to itself.
63
+ */
64
+ cancel(): void;
65
+
66
+ /**
67
+ * Cancels a debouncer's async callback.
68
+ */
69
+ _cancelAsync(): void;
70
+
71
+ /**
72
+ * Flushes an active debouncer and returns a reference to itself.
73
+ */
74
+ flush(): void;
75
+
76
+ /**
77
+ * Returns true if the debouncer is active.
78
+ *
79
+ * @returns True if active.
80
+ */
81
+ isActive(): boolean;
82
+ }
83
+
84
+ /**
85
+ * Adds a `Debouncer` to a list of globally flushable tasks.
86
+ */
87
+ export declare function enqueueDebouncer(debouncer: Debouncer): void;
88
+
89
+ /**
90
+ * Flushes any enqueued debouncers.
91
+ *
92
+ * @returns Returns whether any debouncers were flushed
93
+ */
94
+ export declare function flushDebouncers(): boolean;
95
+
96
+ /**
97
+ * Forces debouncers added via `enqueueDebouncer` to flush.
98
+ *
99
+ * @return {void}
100
+ */
101
+ export declare function flush(): void;
@@ -35,7 +35,7 @@ declare class DirHelper {
35
35
  scrollType: string,
36
36
  direction: string,
37
37
  element: Element | null,
38
- scrollLeft: number
38
+ scrollLeft: number,
39
39
  ): void;
40
40
  }
41
41
 
package/src/dir-mixin.js CHANGED
@@ -48,8 +48,16 @@ export const DirMixin = (superClass) =>
48
48
  dir: {
49
49
  type: String,
50
50
  value: '',
51
- reflectToAttribute: true
52
- }
51
+ reflectToAttribute: true,
52
+ converter: {
53
+ fromAttribute: (attr) => {
54
+ return !attr ? '' : attr;
55
+ },
56
+ toAttribute: (prop) => {
57
+ return prop === '' ? null : prop;
58
+ },
59
+ },
60
+ },
53
61
  };
54
62
  }
55
63
 
@@ -127,9 +135,11 @@ export const DirMixin = (superClass) =>
127
135
  /** @private */
128
136
  __subscribe(push = true) {
129
137
  if (push) {
130
- directionSubscribers.indexOf(this) === -1 && directionSubscribers.push(this);
131
- } else {
132
- directionSubscribers.indexOf(this) > -1 && directionSubscribers.splice(directionSubscribers.indexOf(this), 1);
138
+ if (!directionSubscribers.includes(this)) {
139
+ directionSubscribers.push(this);
140
+ }
141
+ } else if (directionSubscribers.includes(this)) {
142
+ directionSubscribers.splice(directionSubscribers.indexOf(this), 1);
133
143
  }
134
144
  }
135
145
 
@@ -22,8 +22,8 @@ export const DisabledMixin = dedupingMixin(
22
22
  type: Boolean,
23
23
  value: false,
24
24
  observer: '_disabledChanged',
25
- reflectToAttribute: true
26
- }
25
+ reflectToAttribute: true,
26
+ },
27
27
  };
28
28
  }
29
29
 
@@ -58,5 +58,5 @@ export const DisabledMixin = dedupingMixin(
58
58
  super.click();
59
59
  }
60
60
  }
61
- }
61
+ },
62
62
  );
@@ -12,7 +12,7 @@ import { DirMixinClass } from './dir-mixin.js';
12
12
  * A mixin providing common logic for Vaadin components.
13
13
  */
14
14
  export declare function ElementMixin<T extends Constructor<HTMLElement>>(
15
- superclass: T
15
+ superclass: T,
16
16
  ): T & Constructor<DirMixinClass> & Constructor<ElementMixinClass>;
17
17
 
18
18
  export declare class ElementMixinClass {
@@ -39,7 +39,7 @@ const registered = new Set();
39
39
  export const ElementMixin = (superClass) =>
40
40
  class VaadinElementMixin extends DirMixin(superClass) {
41
41
  static get version() {
42
- return '23.1.0-alpha3';
42
+ return '23.1.0-beta2';
43
43
  }
44
44
 
45
45
  /** @protected */
@@ -67,7 +67,7 @@ export const ElementMixin = (superClass) =>
67
67
 
68
68
  if (document.doctype === null) {
69
69
  console.warn(
70
- 'Vaadin components require the "standards mode" declaration. Please add <!DOCTYPE html> to the HTML document.'
70
+ 'Vaadin components require the "standards mode" declaration. Please add <!DOCTYPE html> to the HTML document.',
71
71
  );
72
72
  }
73
73
  }
@@ -16,7 +16,7 @@ window.addEventListener(
16
16
  () => {
17
17
  keyboardActive = true;
18
18
  },
19
- { capture: true }
19
+ { capture: true },
20
20
  );
21
21
 
22
22
  window.addEventListener(
@@ -24,7 +24,7 @@ window.addEventListener(
24
24
  () => {
25
25
  keyboardActive = false;
26
26
  },
27
- { capture: true }
27
+ { capture: true },
28
28
  );
29
29
 
30
30
  /**
@@ -68,7 +68,7 @@ export const FocusMixin = dedupingMixin(
68
68
  disconnectedCallback() {
69
69
  super.disconnectedCallback();
70
70
 
71
- // in non-Chrome browsers, blur does not fire on the element when it is disconnected.
71
+ // In non-Chrome browsers, blur does not fire on the element when it is disconnected.
72
72
  // reproducible in `<vaadin-date-picker>` when closing on `Cancel` or `Today` click.
73
73
  if (this.hasAttribute('focused')) {
74
74
  this._setFocused(false);
@@ -84,7 +84,7 @@ export const FocusMixin = dedupingMixin(
84
84
  _setFocused(focused) {
85
85
  this.toggleAttribute('focused', focused);
86
86
 
87
- // focus-ring is true when the element was focused from the keyboard.
87
+ // Focus-ring is true when the element was focused from the keyboard.
88
88
  // Focus Ring [A11ycasts]: https://youtu.be/ilj2P5-5CjI
89
89
  this.toggleAttribute('focus-ring', focused && this._keyboardActive);
90
90
  }
@@ -110,5 +110,5 @@ export const FocusMixin = dedupingMixin(
110
110
  _shouldRemoveFocus(_event) {
111
111
  return true;
112
112
  }
113
- }
113
+ },
114
114
  );
package/src/gestures.d.ts CHANGED
@@ -65,12 +65,12 @@ export { prevent };
65
65
  declare function prevent(evName: string): void;
66
66
 
67
67
  export interface GestureRecognizer {
68
- reset: () => void;
69
- mousedown?: (e: MouseEvent) => void;
70
- mousemove?: (e: MouseEvent) => void;
71
- mouseup?: (e: MouseEvent) => void;
72
- touchstart?: (e: TouchEvent) => void;
73
- touchmove?: (e: TouchEvent) => void;
74
- touchend?: (e: TouchEvent) => void;
75
- click?: (e: MouseEvent) => void;
68
+ reset(): void;
69
+ mousedown?(e: MouseEvent): void;
70
+ mousemove?(e: MouseEvent): void;
71
+ mouseup?(e: MouseEvent): void;
72
+ touchstart?(e: TouchEvent): void;
73
+ touchmove?(e: TouchEvent): void;
74
+ touchend?(e: TouchEvent): void;
75
+ click?(e: MouseEvent): void;
76
76
  }