@vaadin/field-highlighter 23.1.0-rc2 → 23.1.0-rc3

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.
Files changed (2) hide show
  1. package/package.json +17 -17
  2. package/src/vaadin-user-tags.js +119 -41
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/field-highlighter",
3
- "version": "23.1.0-rc2",
3
+ "version": "23.1.0-rc3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -34,27 +34,27 @@
34
34
  ],
35
35
  "dependencies": {
36
36
  "@polymer/polymer": "^3.0.0",
37
- "@vaadin/component-base": "23.1.0-rc2",
38
- "@vaadin/vaadin-lumo-styles": "23.1.0-rc2",
39
- "@vaadin/vaadin-material-styles": "23.1.0-rc2",
40
- "@vaadin/vaadin-overlay": "23.1.0-rc2",
41
- "@vaadin/vaadin-themable-mixin": "23.1.0-rc2",
37
+ "@vaadin/component-base": "23.1.0-rc3",
38
+ "@vaadin/vaadin-lumo-styles": "23.1.0-rc3",
39
+ "@vaadin/vaadin-material-styles": "23.1.0-rc3",
40
+ "@vaadin/vaadin-overlay": "23.1.0-rc3",
41
+ "@vaadin/vaadin-themable-mixin": "23.1.0-rc3",
42
42
  "lit": "^2.0.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@esm-bundle/chai": "^4.3.4",
46
- "@vaadin/checkbox": "23.1.0-rc2",
47
- "@vaadin/combo-box": "23.1.0-rc2",
48
- "@vaadin/date-picker": "23.1.0-rc2",
49
- "@vaadin/date-time-picker": "23.1.0-rc2",
50
- "@vaadin/item": "23.1.0-rc2",
51
- "@vaadin/list-box": "23.1.0-rc2",
52
- "@vaadin/radio-group": "23.1.0-rc2",
53
- "@vaadin/select": "23.1.0-rc2",
46
+ "@vaadin/checkbox": "23.1.0-rc3",
47
+ "@vaadin/combo-box": "23.1.0-rc3",
48
+ "@vaadin/date-picker": "23.1.0-rc3",
49
+ "@vaadin/date-time-picker": "23.1.0-rc3",
50
+ "@vaadin/item": "23.1.0-rc3",
51
+ "@vaadin/list-box": "23.1.0-rc3",
52
+ "@vaadin/radio-group": "23.1.0-rc3",
53
+ "@vaadin/select": "23.1.0-rc3",
54
54
  "@vaadin/testing-helpers": "^0.3.2",
55
- "@vaadin/text-field": "23.1.0-rc2",
56
- "@vaadin/time-picker": "23.1.0-rc2",
55
+ "@vaadin/text-field": "23.1.0-rc3",
56
+ "@vaadin/time-picker": "23.1.0-rc3",
57
57
  "sinon": "^13.0.2"
58
58
  },
59
- "gitHead": "154c6782c42145fed21e443559fbe2d781ad3ec7"
59
+ "gitHead": "49c312fbe0228adb559296d45655bbfd4eac6235"
60
60
  }
@@ -10,9 +10,6 @@ import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
10
10
  import { timeOut } from '@vaadin/component-base/src/async.js';
11
11
  import { Debouncer } from '@vaadin/component-base/src/debounce.js';
12
12
 
13
- const DURATION = 200;
14
- const DELAY = 2000;
15
-
16
13
  const listenOnce = (elem, type) => {
17
14
  return new Promise((resolve) => {
18
15
  const listener = () => {
@@ -96,20 +93,60 @@ export class UserTags extends PolymerElement {
96
93
  value: () => [],
97
94
  },
98
95
 
96
+ duration: {
97
+ type: Number,
98
+ value: 200,
99
+ },
100
+
101
+ delay: {
102
+ type: Number,
103
+ value: 2000,
104
+ },
105
+
99
106
  /** @private */
100
- _flashQueue: {
107
+ __flashQueue: {
101
108
  type: Array,
102
109
  value: () => [],
103
110
  },
111
+
112
+ /** @private */
113
+ __isTargetVisible: {
114
+ type: Boolean,
115
+ value: false,
116
+ },
104
117
  };
105
118
  }
106
119
 
120
+ constructor() {
121
+ super();
122
+
123
+ this.__targetVisibilityObserver = new IntersectionObserver(
124
+ ([entry]) => {
125
+ this.__onTargetVisibilityChange(entry.isIntersecting);
126
+ },
127
+ { threshold: 1 },
128
+ );
129
+ }
130
+
131
+ /** @protected */
132
+ connectedCallback() {
133
+ super.connectedCallback();
134
+
135
+ if (this.target) {
136
+ this.__targetVisibilityObserver.observe(this.target);
137
+ }
138
+ }
139
+
107
140
  /** @protected */
108
141
  disconnectedCallback() {
109
142
  super.disconnectedCallback();
110
143
  this.opened = false;
144
+ if (this.target) {
145
+ this.__targetVisibilityObserver.unobserve(this.target);
146
+ }
111
147
  }
112
148
 
149
+ /** @protected */
113
150
  ready() {
114
151
  super.ready();
115
152
 
@@ -125,8 +162,43 @@ export class UserTags extends PolymerElement {
125
162
  }
126
163
 
127
164
  /** @private */
128
- __targetChanged(target) {
129
- this.$.overlay.positionTarget = target;
165
+ __onTargetVisibilityChange(isVisible) {
166
+ this.__isTargetVisible = isVisible;
167
+
168
+ // Open the overlay and run the flashing animation for the user tags
169
+ // that have been enqueued (if any) during a `.setUsers()` call
170
+ // because the field was not visible at that point.
171
+ if (isVisible && this.__flashQueue.length > 0 && !this.flashing) {
172
+ this.flashTags(this.__flashQueue.shift());
173
+ return;
174
+ }
175
+
176
+ // Open the overlay when the field is visible and focused.
177
+ // - opens the overlay in the case it was not opened during a `.show()` call because the field was not visible at that point.
178
+ // - re-opens the overlay in the case it was closed because the focused field became not visible for a while (see the below check).
179
+ if (isVisible && this.hasFocus) {
180
+ this.opened = true;
181
+ return;
182
+ }
183
+
184
+ // Close the overlay when the field is not visible.
185
+ // The focused field will be re-opened once it becomes visible again (see the above check).
186
+ if (!isVisible && this.opened) {
187
+ this.opened = false;
188
+ }
189
+ }
190
+
191
+ /** @private */
192
+ __targetChanged(newTarget, oldTarget) {
193
+ this.$.overlay.positionTarget = newTarget;
194
+
195
+ if (oldTarget) {
196
+ this.__targetVisibilityObserver.unobserve(oldTarget);
197
+ }
198
+
199
+ if (newTarget) {
200
+ this.__targetVisibilityObserver.observe(newTarget);
201
+ }
130
202
  }
131
203
 
132
204
  /** @private */
@@ -217,12 +289,12 @@ export class UserTags extends PolymerElement {
217
289
  const changedTags = this.getChangedTags(addedUsers, removedUsers);
218
290
 
219
291
  // Check if flash queue contains pending tags for removed users
220
- if (this._flashQueue.length > 0) {
292
+ if (this.__flashQueue.length > 0) {
221
293
  for (let i = 0; i < removedUsers.length; i++) {
222
294
  if (changedTags.removed[i] === null) {
223
- for (let j = 0; j < this._flashQueue.length; j++) {
224
- if (this._flashQueue[j].some((tag) => tag.uid === removedUsers[i].id)) {
225
- this.splice('_flashQueue', i, 1);
295
+ for (let j = 0; j < this.__flashQueue.length; j++) {
296
+ if (this.__flashQueue[j].some((tag) => tag.uid === removedUsers[i].id)) {
297
+ this.splice('__flashQueue', i, 1);
226
298
  }
227
299
  }
228
300
  }
@@ -244,9 +316,9 @@ export class UserTags extends PolymerElement {
244
316
  removed: removedTags,
245
317
  });
246
318
 
247
- if (this.flashing) {
319
+ if (this.flashing || !this.__isTargetVisible) {
248
320
  // Schedule next flash later
249
- this.push('_flashQueue', addedTags);
321
+ this.push('__flashQueue', addedTags);
250
322
  } else {
251
323
  this.flashTags(addedTags);
252
324
  }
@@ -280,36 +352,40 @@ export class UserTags extends PolymerElement {
280
352
 
281
353
  this.flashPromise = new Promise((resolve) => {
282
354
  listenOnce(this.$.overlay, 'vaadin-overlay-open').then(() => {
283
- this._debounceFlashStart = Debouncer.debounce(this._debounceFlashStart, timeOut.after(DURATION + DELAY), () => {
284
- // Animate disappearing
285
- if (!this.hasFocus) {
286
- added.forEach((tag) => tag.classList.remove('show'));
287
- }
288
- this._debounceFlashEnd = Debouncer.debounce(this._debounceFlashEnd, timeOut.after(DURATION), () => {
289
- // Show all tags
290
- const finishFlash = () => {
291
- hidden.forEach((tag) => (tag.style.display = 'block'));
292
- this.flashing = false;
293
- resolve();
294
- };
295
-
296
- if (this.hasFocus) {
297
- finishFlash();
298
- } else {
299
- // Wait for overlay closing animation to complete
300
- listenOnce(this.$.overlay, 'animationend').then(() => {
301
- finishFlash();
302
- });
303
-
304
- this.opened = false;
355
+ this._debounceFlashStart = Debouncer.debounce(
356
+ this._debounceFlashStart,
357
+ timeOut.after(this.duration + this.delay),
358
+ () => {
359
+ // Animate disappearing
360
+ if (!this.hasFocus) {
361
+ added.forEach((tag) => tag.classList.remove('show'));
305
362
  }
306
- });
307
- });
363
+ this._debounceFlashEnd = Debouncer.debounce(this._debounceFlashEnd, timeOut.after(this.duration), () => {
364
+ // Show all tags
365
+ const finishFlash = () => {
366
+ hidden.forEach((tag) => (tag.style.display = 'block'));
367
+ this.flashing = false;
368
+ resolve();
369
+ };
370
+
371
+ if (this.hasFocus) {
372
+ finishFlash();
373
+ } else {
374
+ // Wait for overlay closing animation to complete
375
+ listenOnce(this.$.overlay, 'animationend').then(() => {
376
+ finishFlash();
377
+ });
378
+
379
+ this.opened = false;
380
+ }
381
+ });
382
+ },
383
+ );
308
384
  });
309
385
  }).then(() => {
310
- if (this._flashQueue.length > 0) {
311
- const tags = this._flashQueue[0];
312
- this.splice('_flashQueue', 0, 1);
386
+ if (this.__flashQueue.length > 0) {
387
+ const tags = this.__flashQueue[0];
388
+ this.splice('__flashQueue', 0, 1);
313
389
  this.flashTags(tags);
314
390
  }
315
391
  });
@@ -330,7 +406,7 @@ export class UserTags extends PolymerElement {
330
406
  updateTags(users, changed) {
331
407
  this.applyTagsStart(changed);
332
408
 
333
- this._debounceRender = Debouncer.debounce(this._debounceRender, timeOut.after(DURATION), () => {
409
+ this._debounceRender = Debouncer.debounce(this._debounceRender, timeOut.after(this.duration), () => {
334
410
  this.set('users', users);
335
411
 
336
412
  this.applyTagsEnd(changed);
@@ -349,7 +425,9 @@ export class UserTags extends PolymerElement {
349
425
 
350
426
  show() {
351
427
  this.hasFocus = true;
352
- this.opened = true;
428
+ if (this.__isTargetVisible) {
429
+ this.opened = true;
430
+ }
353
431
  }
354
432
 
355
433
  hide() {