@vaadin/field-base 24.0.0-alpha7 → 24.0.0-alpha8

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 (53) hide show
  1. package/index.d.ts +0 -2
  2. package/index.js +0 -2
  3. package/package.json +3 -3
  4. package/src/checked-mixin.d.ts +2 -2
  5. package/src/checked-mixin.js +2 -2
  6. package/src/error-controller.d.ts +3 -3
  7. package/src/error-controller.js +6 -6
  8. package/src/field-aria-controller.d.ts +1 -1
  9. package/src/field-aria-controller.js +1 -1
  10. package/src/field-mixin.d.ts +1 -1
  11. package/src/field-mixin.js +1 -1
  12. package/src/helper-controller.d.ts +3 -3
  13. package/src/helper-controller.js +5 -5
  14. package/src/input-constraints-mixin.d.ts +2 -4
  15. package/src/input-constraints-mixin.js +2 -2
  16. package/src/input-control-mixin.d.ts +3 -3
  17. package/src/input-control-mixin.js +4 -4
  18. package/src/input-controller.d.ts +1 -1
  19. package/src/input-controller.js +1 -1
  20. package/src/input-field-mixin.d.ts +3 -3
  21. package/src/input-field-mixin.js +2 -1
  22. package/src/input-mixin.d.ts +1 -1
  23. package/src/input-mixin.js +1 -1
  24. package/src/label-controller.d.ts +3 -3
  25. package/src/label-controller.js +5 -20
  26. package/src/label-mixin.d.ts +1 -1
  27. package/src/label-mixin.js +1 -1
  28. package/src/labelled-input-controller.d.ts +1 -1
  29. package/src/labelled-input-controller.js +1 -1
  30. package/src/pattern-mixin.d.ts +2 -4
  31. package/src/pattern-mixin.js +1 -1
  32. package/src/slot-styles-mixin.d.ts +1 -1
  33. package/src/slot-styles-mixin.js +1 -1
  34. package/src/styles/clear-button-styles.d.ts +1 -1
  35. package/src/styles/clear-button-styles.js +1 -1
  36. package/src/styles/field-shared-styles.d.ts +1 -1
  37. package/src/styles/field-shared-styles.js +1 -1
  38. package/src/styles/input-field-container-styles.d.ts +1 -1
  39. package/src/styles/input-field-container-styles.js +1 -1
  40. package/src/styles/input-field-shared-styles.d.ts +1 -1
  41. package/src/styles/input-field-shared-styles.js +1 -1
  42. package/src/text-area-controller.d.ts +1 -1
  43. package/src/text-area-controller.js +1 -1
  44. package/src/validate-mixin.d.ts +1 -1
  45. package/src/validate-mixin.js +1 -1
  46. package/src/virtual-keyboard-controller.d.ts +1 -1
  47. package/src/virtual-keyboard-controller.js +1 -1
  48. package/src/delegate-focus-mixin.d.ts +0 -48
  49. package/src/delegate-focus-mixin.js +0 -228
  50. package/src/delegate-state-mixin.d.ts +0 -20
  51. package/src/delegate-state-mixin.js +0 -125
  52. package/src/slot-target-controller.d.ts +0 -31
  53. package/src/slot-target-controller.js +0 -123
package/index.d.ts CHANGED
@@ -1,6 +1,4 @@
1
1
  export { CheckedMixin } from './src/checked-mixin.js';
2
- export { DelegateFocusMixin } from './src/delegate-focus-mixin.js';
3
- export { DelegateStateMixin } from './src/delegate-state-mixin.js';
4
2
  export { FieldAriaController } from './src/field-aria-controller.js';
5
3
  export { FieldMixin } from './src/field-mixin.js';
6
4
  export { InputController } from './src/input-controller.js';
package/index.js CHANGED
@@ -1,6 +1,4 @@
1
1
  export { CheckedMixin } from './src/checked-mixin.js';
2
- export { DelegateFocusMixin } from './src/delegate-focus-mixin.js';
3
- export { DelegateStateMixin } from './src/delegate-state-mixin.js';
4
2
  export { FieldAriaController } from './src/field-aria-controller.js';
5
3
  export { FieldMixin } from './src/field-mixin.js';
6
4
  export { InputController } from './src/input-controller.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/field-base",
3
- "version": "24.0.0-alpha7",
3
+ "version": "24.0.0-alpha8",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -32,7 +32,7 @@
32
32
  "dependencies": {
33
33
  "@open-wc/dedupe-mixin": "^1.3.0",
34
34
  "@polymer/polymer": "^3.0.0",
35
- "@vaadin/component-base": "24.0.0-alpha7",
35
+ "@vaadin/component-base": "24.0.0-alpha8",
36
36
  "lit": "^2.0.0"
37
37
  },
38
38
  "devDependencies": {
@@ -40,5 +40,5 @@
40
40
  "@vaadin/testing-helpers": "^0.3.2",
41
41
  "sinon": "^13.0.2"
42
42
  },
43
- "gitHead": "aeb4535336813636736759e0a5de148b26bfc3b6"
43
+ "gitHead": "476752249bb12295c500980d98a3256ad3b22b73"
44
44
  }
@@ -1,11 +1,11 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
7
+ import type { DelegateStateMixinClass } from '@vaadin/component-base/src/delegate-state-mixin.js';
7
8
  import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
8
- import type { DelegateStateMixinClass } from './delegate-state-mixin.js';
9
9
  import type { InputMixinClass } from './input-mixin.js';
10
10
 
11
11
  /**
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
7
+ import { DelegateStateMixin } from '@vaadin/component-base/src/delegate-state-mixin.js';
7
8
  import { DisabledMixin } from '@vaadin/component-base/src/disabled-mixin.js';
8
9
  import { isElementFocused } from '@vaadin/component-base/src/focus-utils.js';
9
- import { DelegateStateMixin } from './delegate-state-mixin.js';
10
10
  import { InputMixin } from './input-mixin.js';
11
11
 
12
12
  /**
@@ -1,14 +1,14 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
6
+ import { SlotChildObserveController } from '@vaadin/component-base/src/slot-child-observe-controller.js';
7
7
 
8
8
  /**
9
9
  * A controller that manages the error message node content.
10
10
  */
11
- export class ErrorController extends SlotController {
11
+ export class ErrorController extends SlotChildObserveController {
12
12
  /**
13
13
  * String used for the error message text content.
14
14
  */
@@ -1,14 +1,14 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { SlotObserveController } from '@vaadin/component-base/src/slot-observe-controller.js';
6
+ import { SlotChildObserveController } from '@vaadin/component-base/src/slot-child-observe-controller.js';
7
7
 
8
8
  /**
9
9
  * A controller that manages the error message node content.
10
10
  */
11
- export class ErrorController extends SlotObserveController {
11
+ export class ErrorController extends SlotChildObserveController {
12
12
  constructor(host) {
13
13
  super(host, 'error-message', 'div');
14
14
  }
@@ -79,8 +79,8 @@ export class ErrorController extends SlotObserveController {
79
79
  }
80
80
 
81
81
  /**
82
- * Override method inherited from `SlotObserveController`
83
- * to restore and the default error message element.
82
+ * Override method inherited from `SlotChildObserveController`
83
+ * to restore the default error message element.
84
84
  *
85
85
  * @protected
86
86
  * @override
@@ -90,7 +90,7 @@ export class ErrorController extends SlotObserveController {
90
90
  }
91
91
 
92
92
  /**
93
- * Override method inherited from `SlotObserveController`
93
+ * Override method inherited from `SlotChildObserveController`
94
94
  * to update the error message text and hidden state.
95
95
  *
96
96
  * Note: unlike with other controllers, this method is
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { addValueToAttribute, removeValueFromAttribute } from '@vaadin/component-base/src/dom-utils.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
@@ -1,14 +1,14 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
6
+ import { SlotChildObserveController } from '@vaadin/component-base/src/slot-child-observe-controller.js';
7
7
 
8
8
  /**
9
9
  * A controller that manages the helper node content.
10
10
  */
11
- export class HelperController extends SlotController {
11
+ export class HelperController extends SlotChildObserveController {
12
12
  /**
13
13
  * String used for the helper text.
14
14
  */
@@ -1,14 +1,14 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { SlotObserveController } from '@vaadin/component-base/src/slot-observe-controller.js';
6
+ import { SlotChildObserveController } from '@vaadin/component-base/src/slot-child-observe-controller.js';
7
7
 
8
8
  /**
9
9
  * A controller that manages the helper node content.
10
10
  */
11
- export class HelperController extends SlotObserveController {
11
+ export class HelperController extends SlotChildObserveController {
12
12
  constructor(host) {
13
13
  // Do not provide tag name, as we create helper lazily.
14
14
  super(host, 'helper', null);
@@ -35,7 +35,7 @@ export class HelperController extends SlotObserveController {
35
35
  }
36
36
 
37
37
  /**
38
- * Override method inherited from `SlotObserveController`
38
+ * Override method inherited from `SlotChildObserveController`
39
39
  * to create the default helper element lazily as needed.
40
40
  *
41
41
  * @param {Node | undefined} node
@@ -57,7 +57,7 @@ export class HelperController extends SlotObserveController {
57
57
  }
58
58
 
59
59
  /**
60
- * Override method inherited from `SlotObserveController`
60
+ * Override method inherited from `SlotChildObserveController`
61
61
  * to update the default helper element text content.
62
62
  *
63
63
  * @param {Node | undefined} node
@@ -1,11 +1,10 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
7
- import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
8
- import type { DelegateStateMixinClass } from './delegate-state-mixin.js';
7
+ import type { DelegateStateMixinClass } from '@vaadin/component-base/src/delegate-state-mixin.js';
9
8
  import type { InputMixinClass } from './input-mixin.js';
10
9
  import type { ValidateMixinClass } from './validate-mixin.js';
11
10
 
@@ -15,7 +14,6 @@ import type { ValidateMixinClass } from './validate-mixin.js';
15
14
  export declare function InputConstraintsMixin<T extends Constructor<HTMLElement>>(
16
15
  base: T,
17
16
  ): Constructor<DelegateStateMixinClass> &
18
- Constructor<DisabledMixinClass> &
19
17
  Constructor<InputConstraintsMixinClass> &
20
18
  Constructor<InputMixinClass> &
21
19
  Constructor<ValidateMixinClass> &
@@ -1,10 +1,10 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
7
- import { DelegateStateMixin } from './delegate-state-mixin.js';
7
+ import { DelegateStateMixin } from '@vaadin/component-base/src/delegate-state-mixin.js';
8
8
  import { InputMixin } from './input-mixin.js';
9
9
  import { ValidateMixin } from './validate-mixin.js';
10
10
 
@@ -1,15 +1,15 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
7
7
  import type { ControllerMixinClass } from '@vaadin/component-base/src/controller-mixin.js';
8
+ import type { DelegateFocusMixinClass } from '@vaadin/component-base/src/delegate-focus-mixin.js';
9
+ import type { DelegateStateMixinClass } from '@vaadin/component-base/src/delegate-state-mixin.js';
8
10
  import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
9
11
  import type { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js';
10
12
  import type { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
11
- import type { DelegateFocusMixinClass } from './delegate-focus-mixin.js';
12
- import type { DelegateStateMixinClass } from './delegate-state-mixin.js';
13
13
  import type { FieldMixinClass } from './field-mixin.js';
14
14
  import type { InputConstraintsMixinClass } from './input-constraints-mixin.js';
15
15
  import type { InputMixinClass } from './input-mixin.js';
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { timeOut } from '@vaadin/component-base/src/async.js';
7
7
  import { Debouncer } from '@vaadin/component-base/src/debounce.js';
8
+ import { DelegateFocusMixin } from '@vaadin/component-base/src/delegate-focus-mixin.js';
8
9
  import { KeyboardMixin } from '@vaadin/component-base/src/keyboard-mixin.js';
9
- import { DelegateFocusMixin } from './delegate-focus-mixin.js';
10
10
  import { FieldMixin } from './field-mixin.js';
11
11
  import { InputConstraintsMixin } from './input-constraints-mixin.js';
12
12
  import { SlotStylesMixin } from './slot-styles-mixin.js';
@@ -315,8 +315,8 @@ export const InputControlMixin = (superclass) =>
315
315
  _allowedCharPatternChanged(charPattern) {
316
316
  if (charPattern) {
317
317
  try {
318
- this.__allowedCharRegExp = new RegExp(`^${charPattern}$`);
319
- this.__allowedTextRegExp = new RegExp(`^${charPattern}*$`);
318
+ this.__allowedCharRegExp = new RegExp(`^${charPattern}$`, 'u');
319
+ this.__allowedTextRegExp = new RegExp(`^${charPattern}*$`, 'u');
320
320
  } catch (e) {
321
321
  console.error(e);
322
322
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
@@ -1,15 +1,15 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
7
7
  import type { ControllerMixinClass } from '@vaadin/component-base/src/controller-mixin.js';
8
+ import type { DelegateFocusMixinClass } from '@vaadin/component-base/src/delegate-focus-mixin.js';
9
+ import type { DelegateStateMixinClass } from '@vaadin/component-base/src/delegate-state-mixin.js';
8
10
  import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
9
11
  import type { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js';
10
12
  import type { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
11
- import type { DelegateFocusMixinClass } from './delegate-focus-mixin.js';
12
- import type { DelegateStateMixinClass } from './delegate-state-mixin.js';
13
13
  import type { FieldMixinClass } from './field-mixin.js';
14
14
  import type { InputConstraintsMixinClass } from './input-constraints-mixin.js';
15
15
  import type { InputControlMixinClass } from './input-control-mixin.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { InputControlMixin } from './input-control-mixin.js';
@@ -46,6 +46,7 @@ export const InputFieldMixin = (superclass) =>
46
46
  */
47
47
  autocapitalize: {
48
48
  type: String,
49
+ reflectToAttribute: true,
49
50
  },
50
51
  };
51
52
  }
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
@@ -1,14 +1,14 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
6
+ import { SlotChildObserveController } from '@vaadin/component-base/src/slot-child-observe-controller.js';
7
7
 
8
8
  /**
9
9
  * A controller to manage the label element.
10
10
  */
11
- export class LabelController extends SlotController {
11
+ export class LabelController extends SlotChildObserveController {
12
12
  /**
13
13
  * String used for the label.
14
14
  */
@@ -1,14 +1,14 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
- import { SlotObserveController } from '@vaadin/component-base/src/slot-observe-controller.js';
6
+ import { SlotChildObserveController } from '@vaadin/component-base/src/slot-child-observe-controller.js';
7
7
 
8
8
  /**
9
9
  * A controller to manage the label element.
10
10
  */
11
- export class LabelController extends SlotObserveController {
11
+ export class LabelController extends SlotChildObserveController {
12
12
  constructor(host) {
13
13
  super(host, 'label', 'label');
14
14
  }
@@ -34,7 +34,7 @@ export class LabelController extends SlotObserveController {
34
34
  }
35
35
 
36
36
  /**
37
- * Override method inherited from `SlotObserveController`
37
+ * Override method inherited from `SlotChildObserveController`
38
38
  * to restore and observe the default label element.
39
39
  *
40
40
  * @protected
@@ -53,7 +53,7 @@ export class LabelController extends SlotObserveController {
53
53
  }
54
54
 
55
55
  /**
56
- * Override method inherited from `SlotObserveController`
56
+ * Override method inherited from `SlotChildObserveController`
57
57
  * to update the default label element text content.
58
58
  *
59
59
  * @param {Node | undefined} node
@@ -69,21 +69,6 @@ export class LabelController extends SlotObserveController {
69
69
  super.updateDefaultNode(node);
70
70
  }
71
71
 
72
- /**
73
- * Override method inherited from `SlotMixin` to observe
74
- * the default label node, but not the custom one.
75
- *
76
- * @param {Node} node
77
- * @protected
78
- * @override
79
- */
80
- initNode(node) {
81
- if (node === this.defaultNode) {
82
- this.updateDefaultNode(node);
83
- this.observeNode(node);
84
- }
85
- }
86
-
87
72
  /**
88
73
  * Override to observe the newly added custom node.
89
74
  *
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { ReactiveController } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
 
@@ -1,11 +1,10 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
7
- import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
8
- import type { DelegateStateMixinClass } from './delegate-state-mixin.js';
7
+ import type { DelegateStateMixinClass } from '@vaadin/component-base/src/delegate-state-mixin.js';
9
8
  import type { InputConstraintsMixinClass } from './input-constraints-mixin.js';
10
9
  import type { InputMixinClass } from './input-mixin.js';
11
10
  import type { ValidateMixinClass } from './validate-mixin.js';
@@ -16,7 +15,6 @@ import type { ValidateMixinClass } from './validate-mixin.js';
16
15
  export declare function PatternMixin<T extends Constructor<HTMLElement>>(
17
16
  base: T,
18
17
  ): Constructor<DelegateStateMixinClass> &
19
- Constructor<DisabledMixinClass> &
20
18
  Constructor<InputConstraintsMixinClass> &
21
19
  Constructor<InputMixinClass> &
22
20
  Constructor<PatternMixinClass> &
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { InputConstraintsMixin } from './input-constraints-mixin.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd..
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd..
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { CSSResult } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd..
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd..
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { css } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd..
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd..
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { CSSResult } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd..
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd..
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { css } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd..
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd..
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { CSSResult } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd..
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd..
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { css } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd..
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd..
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { CSSResult } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd..
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd..
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { clearButton } from './clear-button-styles.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { Constructor } from '@open-wc/dedupe-mixin';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import type { ReactiveController } from 'lit';
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
3
+ * Copyright (c) 2021 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
 
@@ -1,48 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import type { Constructor } from '@open-wc/dedupe-mixin';
7
- import type { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
8
- import type { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js';
9
- import type { TabindexMixinClass } from '@vaadin/component-base/src/tabindex-mixin.js';
10
-
11
- /**
12
- * A mixin to forward focus to an element in the light DOM.
13
- */
14
- export declare function DelegateFocusMixin<T extends Constructor<HTMLElement>>(
15
- base: T,
16
- ): Constructor<DelegateFocusMixinClass> &
17
- Constructor<DisabledMixinClass> &
18
- Constructor<FocusMixinClass> &
19
- Constructor<TabindexMixinClass> &
20
- T;
21
-
22
- export declare class DelegateFocusMixinClass {
23
- /**
24
- * Specify that this control should have input focus when the page loads.
25
- */
26
- autofocus: boolean;
27
-
28
- /**
29
- * A reference to the focusable element controlled by the mixin.
30
- * It can be an input, textarea, button or any element with tabindex > -1.
31
- *
32
- * Any component implementing this mixin is expected to provide it
33
- * by using `this._setFocusElement(input)` Polymer API.
34
- */
35
- readonly focusElement: HTMLElement | null | undefined;
36
-
37
- protected _addFocusListeners(element: HTMLElement): void;
38
-
39
- protected _removeFocusListeners(element: HTMLElement): void;
40
-
41
- protected _focusElementChanged(element: HTMLElement, oldElement: HTMLElement): void;
42
-
43
- protected _onBlur(event: FocusEvent): void;
44
-
45
- protected _onFocus(event: FocusEvent): void;
46
-
47
- protected _setFocusElement(element: HTMLElement): void;
48
- }
@@ -1,228 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
7
- import { FocusMixin } from '@vaadin/component-base/src/focus-mixin.js';
8
- import { TabindexMixin } from '@vaadin/component-base/src/tabindex-mixin.js';
9
-
10
- /**
11
- * A mixin to forward focus to an element in the light DOM.
12
- *
13
- * @polymerMixin
14
- * @mixes FocusMixin
15
- * @mixes TabindexMixin
16
- */
17
- export const DelegateFocusMixin = dedupingMixin(
18
- (superclass) =>
19
- class DelegateFocusMixinClass extends FocusMixin(TabindexMixin(superclass)) {
20
- static get properties() {
21
- return {
22
- /**
23
- * Specify that this control should have input focus when the page loads.
24
- */
25
- autofocus: {
26
- type: Boolean,
27
- },
28
-
29
- /**
30
- * A reference to the focusable element controlled by the mixin.
31
- * It can be an input, textarea, button or any element with tabindex > -1.
32
- *
33
- * Any component implementing this mixin is expected to provide it
34
- * by using `this._setFocusElement(input)` Polymer API.
35
- *
36
- * Toggling `tabindex` attribute on the host element propagates its value to `focusElement`.
37
- *
38
- * @protected
39
- * @type {!HTMLElement}
40
- */
41
- focusElement: {
42
- type: Object,
43
- readOnly: true,
44
- observer: '_focusElementChanged',
45
- },
46
-
47
- /**
48
- * Override the property from `TabIndexMixin`
49
- * to ensure the `tabindex` attribute of the focus element
50
- * will be restored to `0` after re-enabling the element.
51
- *
52
- * @protected
53
- * @override
54
- */
55
- _lastTabIndex: {
56
- value: 0,
57
- },
58
- };
59
- }
60
-
61
- constructor() {
62
- super();
63
-
64
- this._boundOnBlur = this._onBlur.bind(this);
65
- this._boundOnFocus = this._onFocus.bind(this);
66
- }
67
-
68
- /** @protected */
69
- ready() {
70
- super.ready();
71
-
72
- if (this.autofocus && !this.disabled) {
73
- requestAnimationFrame(() => {
74
- this.focus();
75
- this.setAttribute('focus-ring', '');
76
- });
77
- }
78
- }
79
-
80
- /**
81
- * @protected
82
- * @override
83
- */
84
- focus() {
85
- if (!this.focusElement || this.disabled) {
86
- return;
87
- }
88
-
89
- this.focusElement.focus();
90
- this._setFocused(true);
91
- }
92
-
93
- /**
94
- * @protected
95
- * @override
96
- */
97
- blur() {
98
- if (!this.focusElement) {
99
- return;
100
- }
101
- this.focusElement.blur();
102
- this._setFocused(false);
103
- }
104
-
105
- /**
106
- * @protected
107
- * @override
108
- */
109
- click() {
110
- if (this.focusElement && !this.disabled) {
111
- this.focusElement.click();
112
- }
113
- }
114
-
115
- /** @protected */
116
- _focusElementChanged(element, oldElement) {
117
- if (element) {
118
- element.disabled = this.disabled;
119
- this._addFocusListeners(element);
120
- this.__forwardTabIndex(this.tabindex);
121
- } else if (oldElement) {
122
- this._removeFocusListeners(oldElement);
123
- }
124
- }
125
-
126
- /**
127
- * @param {HTMLElement} element
128
- * @protected
129
- */
130
- _addFocusListeners(element) {
131
- element.addEventListener('blur', this._boundOnBlur);
132
- element.addEventListener('focus', this._boundOnFocus);
133
- }
134
-
135
- /**
136
- * @param {HTMLElement} element
137
- * @protected
138
- */
139
- _removeFocusListeners(element) {
140
- element.removeEventListener('blur', this._boundOnBlur);
141
- element.removeEventListener('focus', this._boundOnFocus);
142
- }
143
-
144
- /**
145
- * Focus event does not bubble, so we dispatch it manually
146
- * on the host element to support adding focus listeners
147
- * when the focusable element is placed in light DOM.
148
- * @param {FocusEvent} event
149
- * @protected
150
- */
151
- _onFocus(event) {
152
- event.stopPropagation();
153
- this.dispatchEvent(new Event('focus'));
154
- }
155
-
156
- /**
157
- * Blur event does not bubble, so we dispatch it manually
158
- * on the host element to support adding blur listeners
159
- * when the focusable element is placed in light DOM.
160
- * @param {FocusEvent} event
161
- * @protected
162
- */
163
- _onBlur(event) {
164
- event.stopPropagation();
165
- this.dispatchEvent(new Event('blur'));
166
- }
167
-
168
- /**
169
- * @param {Event} event
170
- * @return {boolean}
171
- * @protected
172
- * @override
173
- */
174
- _shouldSetFocus(event) {
175
- return event.target === this.focusElement;
176
- }
177
-
178
- /**
179
- * @param {boolean} disabled
180
- * @param {boolean} oldDisabled
181
- * @protected
182
- * @override
183
- */
184
- _disabledChanged(disabled, oldDisabled) {
185
- super._disabledChanged(disabled, oldDisabled);
186
-
187
- if (this.focusElement) {
188
- this.focusElement.disabled = disabled;
189
- }
190
-
191
- if (disabled) {
192
- this.blur();
193
- }
194
- }
195
-
196
- /**
197
- * Override an observer from `TabindexMixin`.
198
- * Do not call super to remove tabindex attribute
199
- * from the host after it has been forwarded.
200
- * @param {string} tabindex
201
- * @protected
202
- * @override
203
- */
204
- _tabindexChanged(tabindex) {
205
- this.__forwardTabIndex(tabindex);
206
- }
207
-
208
- /** @private */
209
- __forwardTabIndex(tabindex) {
210
- if (tabindex !== undefined && this.focusElement) {
211
- this.focusElement.tabIndex = tabindex;
212
-
213
- // Preserve tabindex="-1" on the host element
214
- if (tabindex !== -1) {
215
- this.tabindex = undefined;
216
- }
217
- }
218
-
219
- if (this.disabled && tabindex) {
220
- // If tabindex attribute was changed while component was disabled
221
- if (tabindex !== -1) {
222
- this._lastTabIndex = tabindex;
223
- }
224
- this.tabindex = undefined;
225
- }
226
- }
227
- },
228
- );
@@ -1,20 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import type { Constructor } from '@open-wc/dedupe-mixin';
7
-
8
- /**
9
- * A mixin to delegate properties and attributes to a target element.
10
- */
11
- export declare function DelegateStateMixin<T extends Constructor<HTMLElement>>(
12
- base: T,
13
- ): Constructor<DelegateStateMixinClass> & T;
14
-
15
- export declare class DelegateStateMixinClass {
16
- /**
17
- * A target element to which attributes and properties are delegated.
18
- */
19
- stateTarget: HTMLElement | null;
20
- }
@@ -1,125 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import { dedupingMixin } from '@polymer/polymer/lib/utils/mixin.js';
7
-
8
- /**
9
- * A mixin to delegate properties and attributes to a target element.
10
- *
11
- * @polymerMixin
12
- */
13
- export const DelegateStateMixin = dedupingMixin(
14
- (superclass) =>
15
- class DelegateStateMixinClass extends superclass {
16
- static get properties() {
17
- return {
18
- /**
19
- * A target element to which attributes and properties are delegated.
20
- * @protected
21
- */
22
- stateTarget: {
23
- type: Object,
24
- observer: '_stateTargetChanged',
25
- },
26
- };
27
- }
28
-
29
- /**
30
- * An array of the host attributes to delegate to the target element.
31
- */
32
- static get delegateAttrs() {
33
- return [];
34
- }
35
-
36
- /**
37
- * An array of the host properties to delegate to the target element.
38
- */
39
- static get delegateProps() {
40
- return [];
41
- }
42
-
43
- /** @protected */
44
- ready() {
45
- super.ready();
46
-
47
- this._createDelegateAttrsObserver();
48
- this._createDelegatePropsObserver();
49
- }
50
-
51
- /** @protected */
52
- _stateTargetChanged(target) {
53
- if (target) {
54
- this._ensureAttrsDelegated();
55
- this._ensurePropsDelegated();
56
- }
57
- }
58
-
59
- /** @protected */
60
- _createDelegateAttrsObserver() {
61
- this._createMethodObserver(`_delegateAttrsChanged(${this.constructor.delegateAttrs.join(', ')})`);
62
- }
63
-
64
- /** @protected */
65
- _createDelegatePropsObserver() {
66
- this._createMethodObserver(`_delegatePropsChanged(${this.constructor.delegateProps.join(', ')})`);
67
- }
68
-
69
- /** @protected */
70
- _ensureAttrsDelegated() {
71
- this.constructor.delegateAttrs.forEach((name) => {
72
- this._delegateAttribute(name, this[name]);
73
- });
74
- }
75
-
76
- /** @protected */
77
- _ensurePropsDelegated() {
78
- this.constructor.delegateProps.forEach((name) => {
79
- this._delegateProperty(name, this[name]);
80
- });
81
- }
82
-
83
- /** @protected */
84
- _delegateAttrsChanged(...values) {
85
- this.constructor.delegateAttrs.forEach((name, index) => {
86
- this._delegateAttribute(name, values[index]);
87
- });
88
- }
89
-
90
- /** @protected */
91
- _delegatePropsChanged(...values) {
92
- this.constructor.delegateProps.forEach((name, index) => {
93
- this._delegateProperty(name, values[index]);
94
- });
95
- }
96
-
97
- /** @protected */
98
- _delegateAttribute(name, value) {
99
- if (!this.stateTarget) {
100
- return;
101
- }
102
-
103
- if (name === 'invalid') {
104
- this._delegateAttribute('aria-invalid', value ? 'true' : false);
105
- }
106
-
107
- if (typeof value === 'boolean') {
108
- this.stateTarget.toggleAttribute(name, value);
109
- } else if (value) {
110
- this.stateTarget.setAttribute(name, value);
111
- } else {
112
- this.stateTarget.removeAttribute(name);
113
- }
114
- }
115
-
116
- /** @protected */
117
- _delegateProperty(name, value) {
118
- if (!this.stateTarget) {
119
- return;
120
- }
121
-
122
- this.stateTarget[name] = value;
123
- }
124
- },
125
- );
@@ -1,31 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
- import type { ReactiveController } from 'lit';
7
-
8
- export class SlotTargetController implements ReactiveController {
9
- /**
10
- * The source `<slot>` element to copy nodes from.
11
- */
12
- protected sourceSlot: HTMLSlotElement;
13
-
14
- /**
15
- * Function used to get a reference to slot target.
16
- */
17
- protected targetFactory: () => HTMLElement;
18
-
19
- /**
20
- * Function called after copying nodes to target.
21
- */
22
- protected copyCallback?: (nodes: HTMLElement[]) => void;
23
-
24
- constructor(
25
- sourceSlot: HTMLSlotElement,
26
- targetFactory: () => HTMLElement,
27
- copyCallback?: (nodes: HTMLElement[]) => void,
28
- );
29
-
30
- hostConnected(): void;
31
- }
@@ -1,123 +0,0 @@
1
- /**
2
- * @license
3
- * Copyright (c) 2021 - 2022 Vaadin Ltd.
4
- * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
- */
6
-
7
- /**
8
- * A controller to copy the content from a source slot to a target element.
9
- */
10
- export class SlotTargetController {
11
- constructor(sourceSlot, targetFactory, callback) {
12
- /**
13
- * The source `<slot>` element to copy nodes from.
14
- */
15
- this.sourceSlot = sourceSlot;
16
-
17
- /**
18
- * Function used to get a reference to slot target.
19
- */
20
- this.targetFactory = targetFactory;
21
-
22
- /**
23
- * Function called after copying nodes to target.
24
- */
25
- this.copyCallback = callback;
26
-
27
- if (sourceSlot) {
28
- sourceSlot.addEventListener('slotchange', () => {
29
- // Copy in progress, ignore this event.
30
- if (this.__copying) {
31
- this.__copying = false;
32
- } else {
33
- this.__checkAndCopyNodesToSlotTarget();
34
- }
35
- });
36
- }
37
- }
38
-
39
- hostConnected() {
40
- this.__sourceSlotObserver = new MutationObserver(() => this.__checkAndCopyNodesToSlotTarget());
41
-
42
- // Ensure the content is up to date when host is connected
43
- // to handle e.g. mutating text content while disconnected.
44
- // Note, `hostConnected()` is called twice if the controller
45
- // is initialized in `ready()` when using `ControllerMixin`.
46
- if (!this.__copying) {
47
- this.__checkAndCopyNodesToSlotTarget();
48
- }
49
- }
50
-
51
- /**
52
- * Copies every node from the source slot to the target element
53
- * once the source slot' content is changed.
54
- *
55
- * @private
56
- */
57
- __checkAndCopyNodesToSlotTarget() {
58
- this.__sourceSlotObserver.disconnect();
59
-
60
- // Ensure slot target element is up to date.
61
- const slotTarget = this.targetFactory();
62
-
63
- if (!slotTarget) {
64
- return;
65
- }
66
-
67
- // Remove any existing clones from the slot target
68
- if (this.__slotTargetClones) {
69
- this.__slotTargetClones.forEach((node) => {
70
- if (node.parentElement === slotTarget) {
71
- slotTarget.removeChild(node);
72
- }
73
- });
74
- delete this.__slotTargetClones;
75
- }
76
-
77
- // Exclude whitespace text nodes
78
- const nodes = this.sourceSlot
79
- .assignedNodes({ flatten: true })
80
- .filter((node) => !(node.nodeType === Node.TEXT_NODE && node.textContent.trim() === ''));
81
-
82
- if (nodes.length > 0) {
83
- slotTarget.innerHTML = '';
84
-
85
- // Ignore next slotchange
86
- this.__copying = true;
87
-
88
- this.__copyNodesToSlotTarget(nodes, slotTarget);
89
- }
90
- }
91
-
92
- /**
93
- * Copies the nodes to the target element.
94
- *
95
- * @param {!Array<!Node>} nodes
96
- * @param {HTMLElement} slotTarget
97
- * @private
98
- */
99
- __copyNodesToSlotTarget(nodes, slotTarget) {
100
- this.__slotTargetClones ||= [];
101
-
102
- nodes.forEach((node) => {
103
- // Clone the nodes and append the clones to the target
104
- const clone = node.cloneNode(true);
105
- this.__slotTargetClones.push(clone);
106
-
107
- slotTarget.appendChild(clone);
108
-
109
- // Observe all changes to the source node to have the clones updated
110
- this.__sourceSlotObserver.observe(node, {
111
- attributes: true,
112
- childList: true,
113
- subtree: true,
114
- characterData: true,
115
- });
116
- });
117
-
118
- // Run callback e.g. to show a deprecation warning
119
- if (typeof this.copyCallback === 'function') {
120
- this.copyCallback(nodes);
121
- }
122
- }
123
- }