@vonage/vwc-popup 2.25.8 → 2.26.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vonage/vwc-popup",
3
- "version": "2.25.8",
3
+ "version": "2.26.0",
4
4
  "description": "popup component",
5
5
  "homepage": "https://github.com/Vonage/vivid/tree/master/components/popup#readme",
6
6
  "license": "ISC",
@@ -29,19 +29,19 @@
29
29
  "dependencies": {
30
30
  "@floating-ui/core": "^0.2.1",
31
31
  "@floating-ui/dom": "^0.1.7",
32
- "@vonage/vvd-core": "2.25.8",
33
- "@vonage/vvd-foundation": "2.25.8",
34
- "@vonage/vwc-elevation": "2.25.8",
35
- "@vonage/vwc-icon-button": "2.25.8",
32
+ "@vonage/vvd-core": "2.26.0",
33
+ "@vonage/vvd-foundation": "2.26.0",
34
+ "@vonage/vwc-elevation": "2.26.0",
35
+ "@vonage/vwc-icon-button": "2.26.0",
36
36
  "lit-element": "^2.4.0",
37
37
  "lit-html": "^1.3.0",
38
38
  "tslib": "^2.3.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@vonage/vvd-design-tokens": "2.25.8",
42
- "@vonage/vvd-typography": "2.25.8",
43
- "@vonage/vvd-umbrella": "2.25.8",
41
+ "@vonage/vvd-design-tokens": "2.26.0",
42
+ "@vonage/vvd-typography": "2.26.0",
43
+ "@vonage/vvd-umbrella": "2.26.0",
44
44
  "typescript": "^4.3.2"
45
45
  },
46
- "gitHead": "0b9f6e05f1ffbb6b31a11ad9e02fe4e54a2df341"
46
+ "gitHead": "1218e3c7fed82e113d00f79adff58524550d26b6"
47
47
  }
@@ -1,5 +1,5 @@
1
1
  import {
2
- PropertyValues, html, LitElement, property, query, TemplateResult
2
+ html, LitElement, property, query, TemplateResult, PropertyValues
3
3
  } from 'lit-element';
4
4
  import { ClassInfo, classMap } from 'lit-html/directives/class-map.js';
5
5
  import { nothing } from 'lit-html';
@@ -7,196 +7,236 @@ import { computePosition, offset, shift, flip, arrow } from '@floating-ui/dom';
7
7
  import type { Placement, Strategy, Padding } from '@floating-ui/core';
8
8
 
9
9
  export class VWCPopupBase extends LitElement {
10
+ private get PADDING(): Padding { return 0; };
11
+ private get DISTANCE(): number { return 12; };
12
+
10
13
  private onResizeWindow = this.updatePosition.bind(this);
11
- @query('.popup-wrapper') protected popupEl!: HTMLElement;
12
- @query('.popup-arrow') protected arrowEl!: HTMLElement;
13
- protected padding: Padding = 0;
14
- protected distance = 12;
15
-
16
- /**
17
- * @prop open - indicates whether the popup is open
18
- * accepts boolean value
19
- * @public
20
- * */
21
- @property({ type: Boolean, reflect: true })
22
- open = false;
23
-
24
- /**
25
- * @prop anchor - the anchor of the popup
26
- * accepts Element
27
- * @public
28
- * */
29
- @property({ type: Object })
30
- anchor: HTMLElement | null = null;
31
-
32
- /**
33
- * @prop dismissible - adds close button to the popup
34
- * accepts boolean value
35
- * @public
36
- * */
37
- @property({ type: Boolean, reflect: true })
38
- dismissible?: boolean;
39
-
40
- /**
41
- * @prop corner - the placement of the popup
42
- * accepts | 'top'
43
- | 'top-start'
44
- | 'top-end'
45
- | 'right'
46
- | 'right-start'
47
- | 'right-end'
48
- | 'bottom'
49
- | 'bottom-start'
50
- | 'bottom-end'
51
- | 'left'
52
- | 'left-start'
53
- | 'left-end';
54
- * @public
55
- * */
56
- @property({ type: String, reflect: true })
57
- corner: Placement = 'left';
58
-
59
- /**
60
- * @prop strategy - the position of the popup
61
- * accepts 'absolute' | 'fixed';
62
- * @public
63
- * */
64
- @property({ type: String, reflect: true })
65
- strategy: Strategy = 'fixed';
66
-
67
- /**
68
- * @prop arrow - adds small triangle to indicate the trigger element
69
- * accepts boolean value
70
- * @public
71
- * */
72
- @property({ type: Boolean, reflect: true })
73
- arrow?: boolean;
74
-
75
- /**
76
- * @prop alternate - set the color-scheme to dark
77
- * accepts boolean value
78
- * @public
79
- * */
80
- @property({ type: Boolean, reflect: true })
81
- alternate?: boolean;
82
-
83
- /**
84
- * Opens the popup
85
- * @public
86
- */
87
- show(): void {
88
- this.open = true;
89
- }
90
-
91
- /**
92
- * Closes the popup
93
- * @public
94
- */
95
- hide(): void {
96
- this.open = false;
97
- }
98
-
99
- override connectedCallback(): void {
100
- super.connectedCallback();
101
- document.addEventListener('scroll', this.updatePosition);
102
- window.addEventListener('resize', this.onResizeWindow);
103
- }
104
-
105
- override disconnectedCallback(): void {
106
- super.disconnectedCallback();
107
- document.removeEventListener('scroll', this.updatePosition);
108
- window.removeEventListener('resize', this.onResizeWindow);
109
- }
110
-
111
- protected override firstUpdated(changedProperties: PropertyValues): void {
112
- super.firstUpdated(changedProperties);
113
- this.updatePosition();
114
- }
115
-
116
- protected override updated(changes: Map<string, boolean>): void {
117
- super.updated(changes);
118
- this.updatePosition();
119
- }
120
-
121
- /**
122
- * Updates popup position, if succeeded returns - true, if not - false
123
- * @public
124
- */
125
- async updatePosition() {
126
- if (!this.open || !this.anchor) {
127
- return;
128
- }
129
-
130
- const middleware = [flip(), shift({ padding: this.padding })];
131
- this.arrow ? middleware.push(arrow({ element: this.arrowEl, padding: this.padding }), offset(this.distance)) : nothing;
132
- const positionData = await computePosition(this.anchor, this.popupEl, {
133
- placement: this.corner,
134
- strategy: this.strategy,
135
- middleware: middleware
136
- });
137
- this.assignPopupPosition(positionData);
138
- this.arrow ? this.assignArrowPosition(positionData) : nothing;
139
- }
140
-
141
- private assignPopupPosition(data: any): void {
142
- const { x: popupX, y: popupY } = data;
143
- Object.assign(this.popupEl.style, {
144
- left: `${popupX}px`,
145
- top: `${popupY}px`,
146
- });
147
- }
148
-
149
- private assignArrowPosition(data: any): void {
150
- const { x: arrowX, y: arrowY } = data.middlewareData.arrow;
151
- const staticSide: any = { top: 'bottom', right: 'left', bottom: 'top', left: 'right' };
152
- const side: string = staticSide[data.placement.split('-')[0]];
153
- Object.assign(this.arrowEl.style, {
154
- left: arrowX != null ? `${arrowX}px` : '',
155
- top: arrowY != null ? `${arrowY}px` : '',
156
- right: '',
157
- bottom: '',
158
- [side]: '-4px',
159
- });
160
- }
161
-
162
- private handleDismissClick(): void {
163
- this.hide();
164
- }
165
-
166
- private renderDismissButton(): TemplateResult | unknown {
167
- return this.dismissible
168
- ? html`<vwc-icon-button @click=${this.handleDismissClick} class="popup-dismissible-button" icon="close-small-solid"
169
- shape="circled" dense></vwc-icon-button>`
170
- : nothing;
171
- }
172
-
173
- private renderArrow(): TemplateResult | unknown {
174
- return this.arrow ? html`<div class="popup-arrow"></div>` : nothing;
175
- }
176
-
177
- protected getRenderClasses(): ClassInfo {
178
- return {
179
- ['popup-open']: !!this.open,
180
- ['popup-dismissible']: !!this.dismissible
181
- };
182
- }
183
-
184
- protected override render(): TemplateResult {
185
- const part = this.alternate ? 'vvd-scheme-alternate' : '';
186
- const aria = this.open ? 'false' : 'true';
187
-
188
- return html`
189
- <div class="popup-wrapper">
190
- <vwc-elevation dp="2" >
191
- <div class="popup ${classMap(this.getRenderClasses())}" aria-hidden=${aria} part=${part}>
192
- <div class="popup-content">
193
- <slot></slot>
194
- ${this.renderDismissButton()}
195
- </div>
196
- ${this.renderArrow()}
197
- </div>
198
- </vwc-elevation>
199
- </div>
14
+ @query('.popup-wrapper')
15
+ private popupEl!: HTMLElement;
16
+ @query('.popup-arrow')
17
+ private arrowEl!: HTMLElement;
18
+
19
+ private get middleware(): Array<any> {
20
+ return (
21
+ this.arrow ? [flip(), shift({ padding: this.PADDING }), arrow({ element: this.arrowEl, padding: this.PADDING }), offset(this.DISTANCE)]
22
+ : [flip(), shift({ padding: this.PADDING })]);
23
+ };
24
+
25
+ /**
26
+ * @prop open - indicates whether the popup is open
27
+ * accepts boolean value
28
+ * @public
29
+ * */
30
+ @property({ type: Boolean, reflect: true })
31
+ open = false;
32
+
33
+ /**
34
+ * @prop anchor - ID reference to element in the popup’s owner document.
35
+ * accepts string
36
+ * @public
37
+ * */
38
+ @property({ type: String, reflect: true })
39
+ anchor = '';
40
+
41
+ /**
42
+ * @prop anchorEl - popup's anchor element
43
+ * accepts Element
44
+ * @private
45
+ * */
46
+ @property({ type: Element, reflect: true })
47
+ private anchorEl: Element | null | undefined;
48
+
49
+ /**
50
+ * @prop dismissible - adds close button to the popup
51
+ * accepts boolean value
52
+ * @public
53
+ * */
54
+ @property({ type: Boolean, reflect: true })
55
+ dismissible?: boolean;
56
+
57
+ /**
58
+ * @prop corner - the placement of the popup
59
+ * accepts | 'top'
60
+ | 'top-start'
61
+ | 'top-end'
62
+ | 'right'
63
+ | 'right-start'
64
+ | 'right-end'
65
+ | 'bottom'
66
+ | 'bottom-start'
67
+ | 'bottom-end'
68
+ | 'left'
69
+ | 'left-start'
70
+ | 'left-end';
71
+ * @public
72
+ * */
73
+ @property({ type: String, reflect: true })
74
+ corner: Placement = 'left';
75
+
76
+ /**
77
+ * @prop strategy - the position of the popup
78
+ * accepts 'absolute' | 'fixed';
79
+ * @public
80
+ * */
81
+ @property({ type: String, reflect: true })
82
+ strategy: Strategy = 'fixed';
83
+
84
+ /**
85
+ * @prop arrow - adds small triangle to indicate the trigger element
86
+ * accepts boolean value
87
+ * @public
88
+ * */
89
+ @property({ type: Boolean, reflect: true })
90
+ arrow?: boolean;
91
+
92
+ /**
93
+ * @prop alternate - set the color-scheme to dark
94
+ * accepts boolean value
95
+ * @public
96
+ * */
97
+ @property({ type: Boolean, reflect: true })
98
+ alternate?: boolean;
99
+
100
+ /**
101
+ * Gets the anchor element by id
102
+ */
103
+ private getAnchorById(): HTMLElement | null {
104
+ return document.getElementById(this.anchor);
105
+ };
106
+
107
+ /**
108
+ * Opens the popup
109
+ * @public
110
+ */
111
+ show(): void {
112
+ if (this.anchorEl) { // only if anchor element exists
113
+ this.open = true;
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Closes the popup
119
+ * @public
120
+ */
121
+ hide(): void {
122
+ this.open = false;
123
+ }
124
+
125
+ private sizeObserver = new ResizeObserver(() => {
126
+ return this.updatePosition();
127
+ });
128
+
129
+ override connectedCallback(): void {
130
+ super.connectedCallback();
131
+ window.addEventListener('scroll', this.updatePosition);
132
+ window.addEventListener('resize', this.onResizeWindow);
133
+ }
134
+
135
+ override disconnectedCallback(): void {
136
+ super.disconnectedCallback();
137
+ window.removeEventListener('scroll', this.updatePosition);
138
+ window.removeEventListener('resize', this.onResizeWindow);
139
+ // Disconnect the observer to stop from running in the background
140
+ this.sizeObserver.disconnect();
141
+ }
142
+
143
+ protected override firstUpdated(_changedProperties: PropertyValues): void {
144
+ super.firstUpdated(_changedProperties);
145
+ this.anchorEl = this.getAnchorById();
146
+ if(this.anchorEl) this.sizeObserver.observe(this.anchorEl);
147
+ }
148
+
149
+ protected override updated(changes: Map<string, boolean>): void {
150
+ super.updated(changes);
151
+ if (changes.has('anchor')) {
152
+ this.sizeObserver.disconnect();
153
+ this.anchorEl = this.getAnchorById();
154
+ if(this.anchorEl) this.sizeObserver.observe(this.anchorEl);
155
+ }
156
+ this.updatePosition();
157
+ }
158
+
159
+ /**
160
+ * Updates popup position, if succeeded returns - true, if not - false
161
+ * @public
162
+ */
163
+ async updatePosition() {
164
+ if (!this.open) {
165
+ return;
166
+ }
167
+ if (!this.anchorEl) {
168
+ this.hide();
169
+ console.error('Anchor is not defined');
170
+ return;
171
+ }
172
+ const positionData = await computePosition(this.anchorEl, this.popupEl, {
173
+ placement: this.corner,
174
+ strategy: this.strategy,
175
+ middleware: this.middleware
176
+ });
177
+ this.assignPopupPosition(positionData);
178
+ if (this.arrow) { this.assignArrowPosition(positionData); }
179
+ }
180
+
181
+ private assignPopupPosition(data: any): void {
182
+ const { x: popupX, y: popupY } = data;
183
+ Object.assign(this.popupEl.style, {
184
+ left: `${popupX}px`,
185
+ top: `${popupY}px`,
186
+ });
187
+ }
188
+
189
+ private assignArrowPosition(data: any): void {
190
+ const { x: arrowX, y: arrowY } = data.middlewareData.arrow;
191
+ const staticSide: any = { top: 'bottom', right: 'left', bottom: 'top', left: 'right' };
192
+ const side: string = staticSide[data.placement.split('-')[0]];
193
+ Object.assign(this.arrowEl.style, {
194
+ left: arrowX != null ? `${arrowX}px` : '',
195
+ top: arrowY != null ? `${arrowY}px` : '',
196
+ right: '',
197
+ bottom: '',
198
+ [side]: '-4px',
199
+ });
200
+ }
201
+
202
+ private handleDismissClick(): void {
203
+ this.hide();
204
+ }
205
+
206
+ private renderDismissButton(): TemplateResult | unknown {
207
+ return this.dismissible
208
+ ? html`<vwc-icon-button @click=${this.handleDismissClick} class="popup-dismissible-button" icon="close-small-solid"
209
+ shape="circled" dense></vwc-icon-button>`
210
+ : nothing;
211
+ }
212
+
213
+ private renderArrow(): TemplateResult | unknown {
214
+ return this.arrow ? html`<div class="popup-arrow"></div>` : nothing;
215
+ }
216
+
217
+ protected getRenderClasses(): ClassInfo {
218
+ return {
219
+ ['popup-open']: !!this.open,
220
+ ['popup-dismissible']: !!this.dismissible
221
+ };
222
+ }
223
+
224
+ protected override render(): TemplateResult {
225
+ const part = this.alternate ? 'vvd-scheme-alternate' : '';
226
+ const aria = this.open ? 'false' : 'true';
227
+
228
+ return html`
229
+ <div class="popup-wrapper">
230
+ <vwc-elevation dp="2">
231
+ <div class="popup ${classMap(this.getRenderClasses())}" aria-hidden=${aria} part=${part}>
232
+ <div class="popup-content">
233
+ <slot></slot>
234
+ ${this.renderDismissButton()}
235
+ </div>
236
+ ${this.renderArrow()}
237
+ </div>
238
+ </vwc-elevation>
239
+ </div>
200
240
  `;
201
- }
241
+ }
202
242
  }
@@ -1,24 +1,28 @@
1
- import { PropertyValues, LitElement, TemplateResult } from 'lit-element';
1
+ import { LitElement, TemplateResult, PropertyValues } from 'lit-element';
2
2
  import { ClassInfo } from 'lit-html/directives/class-map.js';
3
- import type { Placement, Strategy, Padding } from '@floating-ui/core';
3
+ import type { Placement, Strategy } from '@floating-ui/core';
4
4
  export declare class VWCPopupBase extends LitElement {
5
+ private get PADDING();
6
+ private get DISTANCE();
5
7
  private onResizeWindow;
6
- protected popupEl: HTMLElement;
7
- protected arrowEl: HTMLElement;
8
- protected padding: Padding;
9
- protected distance: number;
8
+ private popupEl;
9
+ private arrowEl;
10
+ private get middleware();
10
11
  open: boolean;
11
- anchor: HTMLElement | null;
12
+ anchor: string;
13
+ private anchorEl;
12
14
  dismissible?: boolean;
13
15
  corner: Placement;
14
16
  strategy: Strategy;
15
17
  arrow?: boolean;
16
18
  alternate?: boolean;
19
+ private getAnchorById;
17
20
  show(): void;
18
21
  hide(): void;
22
+ private sizeObserver;
19
23
  connectedCallback(): void;
20
24
  disconnectedCallback(): void;
21
- protected firstUpdated(changedProperties: PropertyValues): void;
25
+ protected firstUpdated(_changedProperties: PropertyValues): void;
22
26
  protected updated(changes: Map<string, boolean>): void;
23
27
  updatePosition(): Promise<void>;
24
28
  private assignPopupPosition;
package/vwc-popup-base.js CHANGED
@@ -7,50 +7,80 @@ export class VWCPopupBase extends LitElement {
7
7
  constructor() {
8
8
  super(...arguments);
9
9
  this.onResizeWindow = this.updatePosition.bind(this);
10
- this.padding = 0;
11
- this.distance = 12;
12
10
  this.open = false;
13
- this.anchor = null;
11
+ this.anchor = '';
14
12
  this.corner = 'left';
15
13
  this.strategy = 'fixed';
14
+ this.sizeObserver = new ResizeObserver(() => {
15
+ return this.updatePosition();
16
+ });
17
+ }
18
+ get PADDING() { return 0; }
19
+ ;
20
+ get DISTANCE() { return 12; }
21
+ ;
22
+ get middleware() {
23
+ return (this.arrow ? [flip(), shift({ padding: this.PADDING }), arrow({ element: this.arrowEl, padding: this.PADDING }), offset(this.DISTANCE)]
24
+ : [flip(), shift({ padding: this.PADDING })]);
25
+ }
26
+ ;
27
+ getAnchorById() {
28
+ return document.getElementById(this.anchor);
16
29
  }
30
+ ;
17
31
  show() {
18
- this.open = true;
32
+ if (this.anchorEl) {
33
+ this.open = true;
34
+ }
19
35
  }
20
36
  hide() {
21
37
  this.open = false;
22
38
  }
23
39
  connectedCallback() {
24
40
  super.connectedCallback();
25
- document.addEventListener('scroll', this.updatePosition);
41
+ window.addEventListener('scroll', this.updatePosition);
26
42
  window.addEventListener('resize', this.onResizeWindow);
27
43
  }
28
44
  disconnectedCallback() {
29
45
  super.disconnectedCallback();
30
- document.removeEventListener('scroll', this.updatePosition);
46
+ window.removeEventListener('scroll', this.updatePosition);
31
47
  window.removeEventListener('resize', this.onResizeWindow);
48
+ this.sizeObserver.disconnect();
32
49
  }
33
- firstUpdated(changedProperties) {
34
- super.firstUpdated(changedProperties);
35
- this.updatePosition();
50
+ firstUpdated(_changedProperties) {
51
+ super.firstUpdated(_changedProperties);
52
+ this.anchorEl = this.getAnchorById();
53
+ if (this.anchorEl)
54
+ this.sizeObserver.observe(this.anchorEl);
36
55
  }
37
56
  updated(changes) {
38
57
  super.updated(changes);
58
+ if (changes.has('anchor')) {
59
+ this.sizeObserver.disconnect();
60
+ this.anchorEl = this.getAnchorById();
61
+ if (this.anchorEl)
62
+ this.sizeObserver.observe(this.anchorEl);
63
+ }
39
64
  this.updatePosition();
40
65
  }
41
66
  async updatePosition() {
42
- if (!this.open || !this.anchor) {
67
+ if (!this.open) {
43
68
  return;
44
69
  }
45
- const middleware = [flip(), shift({ padding: this.padding })];
46
- this.arrow ? middleware.push(arrow({ element: this.arrowEl, padding: this.padding }), offset(this.distance)) : nothing;
47
- const positionData = await computePosition(this.anchor, this.popupEl, {
70
+ if (!this.anchorEl) {
71
+ this.hide();
72
+ console.error('Anchor is not defined');
73
+ return;
74
+ }
75
+ const positionData = await computePosition(this.anchorEl, this.popupEl, {
48
76
  placement: this.corner,
49
77
  strategy: this.strategy,
50
- middleware: middleware
78
+ middleware: this.middleware
51
79
  });
52
80
  this.assignPopupPosition(positionData);
53
- this.arrow ? this.assignArrowPosition(positionData) : nothing;
81
+ if (this.arrow) {
82
+ this.assignArrowPosition(positionData);
83
+ }
54
84
  }
55
85
  assignPopupPosition(data) {
56
86
  const { x: popupX, y: popupY } = data;
@@ -77,7 +107,7 @@ export class VWCPopupBase extends LitElement {
77
107
  renderDismissButton() {
78
108
  return this.dismissible
79
109
  ? html `<vwc-icon-button @click=${this.handleDismissClick} class="popup-dismissible-button" icon="close-small-solid"
80
- shape="circled" dense></vwc-icon-button>`
110
+ shape="circled" dense></vwc-icon-button>`
81
111
  : nothing;
82
112
  }
83
113
  renderArrow() {
@@ -93,17 +123,17 @@ export class VWCPopupBase extends LitElement {
93
123
  const part = this.alternate ? 'vvd-scheme-alternate' : '';
94
124
  const aria = this.open ? 'false' : 'true';
95
125
  return html `
96
- <div class="popup-wrapper">
97
- <vwc-elevation dp="2" >
98
- <div class="popup ${classMap(this.getRenderClasses())}" aria-hidden=${aria} part=${part}>
99
- <div class="popup-content">
100
- <slot></slot>
101
- ${this.renderDismissButton()}
102
- </div>
103
- ${this.renderArrow()}
104
- </div>
105
- </vwc-elevation>
106
- </div>
126
+ <div class="popup-wrapper">
127
+ <vwc-elevation dp="2">
128
+ <div class="popup ${classMap(this.getRenderClasses())}" aria-hidden=${aria} part=${part}>
129
+ <div class="popup-content">
130
+ <slot></slot>
131
+ ${this.renderDismissButton()}
132
+ </div>
133
+ ${this.renderArrow()}
134
+ </div>
135
+ </vwc-elevation>
136
+ </div>
107
137
  `;
108
138
  }
109
139
  }
@@ -117,8 +147,11 @@ __decorate([
117
147
  property({ type: Boolean, reflect: true })
118
148
  ], VWCPopupBase.prototype, "open", void 0);
119
149
  __decorate([
120
- property({ type: Object })
150
+ property({ type: String, reflect: true })
121
151
  ], VWCPopupBase.prototype, "anchor", void 0);
152
+ __decorate([
153
+ property({ type: Element, reflect: true })
154
+ ], VWCPopupBase.prototype, "anchorEl", void 0);
122
155
  __decorate([
123
156
  property({ type: Boolean, reflect: true })
124
157
  ], VWCPopupBase.prototype, "dismissible", void 0);
@@ -1 +1 @@
1
- {"version":3,"file":"vwc-popup-base.js","sourceRoot":"","sources":["src/vwc-popup-base.ts"],"names":[],"mappings":";AAAA,OAAO,EACU,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EACjD,MAAM,aAAa,CAAC;AACrB,OAAO,EAAa,QAAQ,E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ClassInfo, classMap } from 'lit-html/directives/class-map.js';\nimport { nothing } from 'lit-html';\nimport { computePosition, offset, shift, flip, arrow } from '@floating-ui/dom';\nimport type { Placement, Strategy, Padding } from '@floating-ui/core';\n\nexport class VWCPopupBase extends LitElement {\n\tprivate onResizeWindow = this.updatePosition.bind(this);\n\t@query('.popup-wrapper') protected popupEl!: HTMLElement;\n\t@query('.popup-arrow') protected arrowEl!: HTMLElement;\n\tprotected padding: Padding = 0;\n\tprotected distance = 12;\n\n\t/**\n\t * @prop open - indicates whether the popup is open\n\t * accepts boolean value\n\t * @public\n\t * */\n\t@property({ type: Boolean, reflect: true })\n\t\topen = false;\n\n\t/**\n\t * @prop anchor - the anchor of the popup\n\t * accepts Element\n\t * @public\n\t * */\n\t@property({ type: Object })\n\t\tanchor: HTMLElement | null = null;\n\n\t/**\n\t * @prop dismissible - adds close button to the popup\n\t * accepts boolean value\n\t * @public\n\t * */\n\t@property({ type: Boolean, reflect: true })\n\t\tdismissible?: boolean;\n\n\t/**\n\t * @prop corner - the placement of the popup\n\t * accepts | 'top'\n\t\t\t\t| 'top-start'\n\t\t\t\t| 'top-end'\n\t\t\t\t| 'right'\n\t\t\t\t| 'right-start'\n\t\t\t\t| 'right-end'\n\t\t\t\t| 'bottom'\n\t\t\t\t| 'bottom-start'\n\t\t\t\t| 'bottom-end'\n\t\t\t\t| 'left'\n\t\t\t\t| 'left-start'\n\t\t\t\t| 'left-end';\n\t * @public\n\t * */\n\t@property({ type: String, reflect: true })\n\t\tcorner: Placement = 'left';\n\n\t/**\n\t * @prop strategy - the position of the popup\n\t * accepts 'absolute' | 'fixed';\n\t* @public\n\t* */\n\t@property({ type: String, reflect: true })\n\t\tstrategy: Strategy = 'fixed';\n\n\t/**\n\t * @prop arrow - adds small triangle to indicate the trigger element\n\t * accepts boolean value\n\t * @public\n\t * */\n\t@property({ type: Boolean, reflect: true })\n\t\tarrow?: boolean;\n\n\t/**\n\t * @prop alternate - set the color-scheme to dark\n\t * accepts boolean value\n\t * @public\n\t * */\n\t@property({ type: Boolean, reflect: true })\n\t\talternate?: boolean;\n\n\t/**\n\t* Opens the popup\n\t* @public\n\t*/\n\tshow(): void {\n\t\tthis.open = true;\n\t}\n\n\t/**\n\t * Closes the popup\n\t * @public\n\t */\n\thide(): void {\n\t\tthis.open = false;\n\t}\n\n\toverride connectedCallback(): void {\n\t\tsuper.connectedCallback();\n\t\tdocument.addEventListener('scroll', this.updatePosition);\n\t\twindow.addEventListener('resize', this.onResizeWindow);\n\t}\n\n\toverride disconnectedCallback(): void {\n\t\tsuper.disconnectedCallback();\n\t\tdocument.removeEventListener('scroll', this.updatePosition);\n\t\twindow.removeEventListener('resize', this.onResizeWindow);\n\t}\n\n\tprotected override firstUpdated(changedProperties: PropertyValues): void {\n\t\tsuper.firstUpdated(changedProperties);\n\t\tthis.updatePosition();\n\t}\n\n\tprotected override updated(changes: Map<string, boolean>): void {\n\t\tsuper.updated(changes);\n\t\tthis.updatePosition();\n\t}\n\n\t/**\n\t * Updates popup position, if succeeded returns - true, if not - false\n\t * @public\n\t */\n\tasync updatePosition() {\n\t\tif (!this.open || !this.anchor) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst middleware = [flip(), shift({ padding: this.padding })];\n\t\tthis.arrow ? middleware.push(arrow({ element: this.arrowEl, padding: this.padding }), offset(this.distance)) : nothing;\n\t\tconst positionData = await computePosition(this.anchor, this.popupEl, {\n\t\t\tplacement: this.corner,\n\t\t\tstrategy: this.strategy,\n\t\t\tmiddleware: middleware\n\t\t});\n\t\tthis.assignPopupPosition(positionData);\n\t\tthis.arrow ? this.assignArrowPosition(positionData) : nothing;\n\t}\n\n\tprivate assignPopupPosition(data: any): void {\n\t\tconst { x: popupX, y: popupY } = data;\n\t\tObject.assign(this.popupEl.style, {\n\t\t\tleft: `${popupX}px`,\n\t\t\ttop: `${popupY}px`,\n\t\t});\n\t}\n\n\tprivate assignArrowPosition(data: any): void {\n\t\tconst { x: arrowX, y: arrowY } = data.middlewareData.arrow;\n\t\tconst staticSide: any = { top: 'bottom', right: 'left', bottom: 'top', left: 'right' };\n\t\tconst side: string = staticSide[data.placement.split('-')[0]];\n\t\tObject.assign(this.arrowEl.style, {\n\t\t\tleft: arrowX != null ? `${arrowX}px` : '',\n\t\t\ttop: arrowY != null ? `${arrowY}px` : '',\n\t\t\tright: '',\n\t\t\tbottom: '',\n\t\t\t[side]: '-4px',\n\t\t});\n\t}\n\n\tprivate handleDismissClick(): void {\n\t\tthis.hide();\n\t}\n\n\tprivate renderDismissButton(): TemplateResult | unknown {\n\t\treturn this.dismissible\n\t\t\t? html`<vwc-icon-button @click=${this.handleDismissClick} class=\"popup-dismissible-button\" icon=\"close-small-solid\"\n\tshape=\"circled\" dense></vwc-icon-button>`\n\t\t\t: nothing;\n\t}\n\n\tprivate renderArrow(): TemplateResult | unknown {\n\t\treturn this.arrow ? html`<div class=\"popup-arrow\"></div>` : nothing;\n\t}\n\n\tprotected getRenderClasses(): ClassInfo {\n\t\treturn {\n\t\t\t['popup-open']: !!this.open,\n\t\t\t['popup-dismissible']: !!this.dismissible\n\t\t};\n\t}\n\n\tprotected override render(): TemplateResult {\n\t\tconst part = this.alternate ? 'vvd-scheme-alternate' : '';\n\t\tconst aria = this.open ? 'false' : 'true';\n\n\t\treturn html`\n\t\t\t<div class=\"popup-wrapper\">\n\t\t\t\t<vwc-elevation dp=\"2\" >\n\t\t\t\t\t<div class=\"popup ${classMap(this.getRenderClasses())}\" aria-hidden=${aria} part=${part}>\n\t\t\t\t\t\t<div class=\"popup-content\">\n\t\t\t\t\t\t\t<slot></slot>\n\t\t\t\t\t\t\t${this.renderDismissButton()}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t${this.renderArrow()}\n\t\t\t\t\t</div>\n\t\t\t\t</vwc-elevation>\n\t\t\t</div>\n\t\t`;\n\t}\n}\n"]}
1
+ {"version":3,"file":"vwc-popup-base.js","sourceRoot":"","sources":["src/vwc-popup-base.ts"],"names":[],"mappings":";AAAA,OAAO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/directives/class-map.js';\nimport { nothing } from 'lit-html';\nimport { computePosition, offset, shift, flip, arrow } from '@floating-ui/dom';\nimport type { Placement, Strategy, Padding } from '@floating-ui/core';\n\nexport class VWCPopupBase extends LitElement {\n\tprivate get PADDING(): Padding { return 0; };\n\tprivate get DISTANCE(): number { return 12; };\n\n\tprivate onResizeWindow = this.updatePosition.bind(this);\n @query('.popup-wrapper')\n\tprivate popupEl!: HTMLElement;\n @query('.popup-arrow')\n private arrowEl!: HTMLElement;\n\n private get middleware(): Array<any> {\n \treturn (\n \t\tthis.arrow ? [flip(), shift({ padding: this.PADDING }), arrow({ element: this.arrowEl, padding: this.PADDING }), offset(this.DISTANCE)]\n \t\t\t: [flip(), shift({ padding: this.PADDING })]);\n };\n\n /**\n * @prop open - indicates whether the popup is open\n * accepts boolean value\n * @public\n * */\n @property({ type: Boolean, reflect: true })\n \topen = false;\n\n /**\n * @prop anchor - ID reference to element in the popup’s owner document.\n * accepts string\n * @public\n * */\n @property({ type: String, reflect: true })\n \tanchor = '';\n\n /**\n * @prop anchorEl - popup's anchor element\n * accepts Element\n * @private\n * */\n @property({ type: Element, reflect: true })\n private anchorEl: Element | null | undefined;\n\n /**\n * @prop dismissible - adds close button to the popup\n * accepts boolean value\n * @public\n * */\n @property({ type: Boolean, reflect: true })\n \tdismissible?: boolean;\n\n /**\n * @prop corner - the placement of the popup\n * accepts | 'top'\n | 'top-start'\n | 'top-end'\n | 'right'\n | 'right-start'\n | 'right-end'\n | 'bottom'\n | 'bottom-start'\n | 'bottom-end'\n | 'left'\n | 'left-start'\n | 'left-end';\n * @public\n * */\n @property({ type: String, reflect: true })\n \tcorner: Placement = 'left';\n\n /**\n * @prop strategy - the position of the popup\n * accepts 'absolute' | 'fixed';\n * @public\n * */\n @property({ type: String, reflect: true })\n \tstrategy: Strategy = 'fixed';\n\n /**\n * @prop arrow - adds small triangle to indicate the trigger element\n * accepts boolean value\n * @public\n * */\n @property({ type: Boolean, reflect: true })\n \tarrow?: boolean;\n\n /**\n * @prop alternate - set the color-scheme to dark\n * accepts boolean value\n * @public\n * */\n @property({ type: Boolean, reflect: true })\n \talternate?: boolean;\n\n /**\n * Gets the anchor element by id\n */\n private getAnchorById(): HTMLElement | null {\n \treturn document.getElementById(this.anchor);\n };\n\n /**\n * Opens the popup\n * @public\n */\n show(): void {\n \tif (this.anchorEl) { // only if anchor element exists\n \t\tthis.open = true;\n \t}\n }\n\n /**\n * Closes the popup\n * @public\n */\n hide(): void {\n \tthis.open = false;\n }\n\n private sizeObserver = new ResizeObserver(() => {\n \treturn this.updatePosition();\n });\n\n override connectedCallback(): void {\n \tsuper.connectedCallback();\n \twindow.addEventListener('scroll', this.updatePosition);\n \twindow.addEventListener('resize', this.onResizeWindow);\n }\n\n override disconnectedCallback(): void {\n \tsuper.disconnectedCallback();\n \twindow.removeEventListener('scroll', this.updatePosition);\n \twindow.removeEventListener('resize', this.onResizeWindow);\n \t// Disconnect the observer to stop from running in the background\n \tthis.sizeObserver.disconnect();\n }\n\n protected override firstUpdated(_changedProperties: PropertyValues): void {\n \tsuper.firstUpdated(_changedProperties);\n \tthis.anchorEl = this.getAnchorById();\n \tif(this.anchorEl) this.sizeObserver.observe(this.anchorEl);\n }\n\n protected override updated(changes: Map<string, boolean>): void {\n \tsuper.updated(changes);\n \tif (changes.has('anchor')) {\n \t\tthis.sizeObserver.disconnect();\n \t\tthis.anchorEl = this.getAnchorById();\n \t\tif(this.anchorEl) this.sizeObserver.observe(this.anchorEl);\n \t}\n \tthis.updatePosition();\n }\n\n /**\n * Updates popup position, if succeeded returns - true, if not - false\n * @public\n */\n async updatePosition() {\n \tif (!this.open) {\n \t\treturn;\n \t}\n \tif (!this.anchorEl) {\n \t\tthis.hide();\n \t\tconsole.error('Anchor is not defined');\n \t\treturn;\n \t}\n \tconst positionData = await computePosition(this.anchorEl, this.popupEl, {\n \t\tplacement: this.corner,\n \t\tstrategy: this.strategy,\n \t\tmiddleware: this.middleware\n \t});\n \tthis.assignPopupPosition(positionData);\n \tif (this.arrow) { this.assignArrowPosition(positionData); }\n }\n\n private assignPopupPosition(data: any): void {\n \tconst { x: popupX, y: popupY } = data;\n \tObject.assign(this.popupEl.style, {\n \t\tleft: `${popupX}px`,\n \t\ttop: `${popupY}px`,\n \t});\n }\n\n private assignArrowPosition(data: any): void {\n \tconst { x: arrowX, y: arrowY } = data.middlewareData.arrow;\n \tconst staticSide: any = { top: 'bottom', right: 'left', bottom: 'top', left: 'right' };\n \tconst side: string = staticSide[data.placement.split('-')[0]];\n \tObject.assign(this.arrowEl.style, {\n \t\tleft: arrowX != null ? `${arrowX}px` : '',\n \t\ttop: arrowY != null ? `${arrowY}px` : '',\n \t\tright: '',\n \t\tbottom: '',\n \t\t[side]: '-4px',\n \t});\n }\n\n private handleDismissClick(): void {\n \tthis.hide();\n }\n\n private renderDismissButton(): TemplateResult | unknown {\n \treturn this.dismissible\n \t\t? html`<vwc-icon-button @click=${this.handleDismissClick} class=\"popup-dismissible-button\" icon=\"close-small-solid\"\n shape=\"circled\" dense></vwc-icon-button>`\n \t\t: nothing;\n }\n\n private renderArrow(): TemplateResult | unknown {\n \treturn this.arrow ? html`<div class=\"popup-arrow\"></div>` : nothing;\n }\n\n protected getRenderClasses(): ClassInfo {\n \treturn {\n \t\t['popup-open']: !!this.open,\n \t\t['popup-dismissible']: !!this.dismissible\n \t};\n }\n\n protected override render(): TemplateResult {\n \tconst part = this.alternate ? 'vvd-scheme-alternate' : '';\n \tconst aria = this.open ? 'false' : 'true';\n\n \treturn html`\n <div class=\"popup-wrapper\">\n <vwc-elevation dp=\"2\">\n <div class=\"popup ${classMap(this.getRenderClasses())}\" aria-hidden=${aria} part=${part}>\n <div class=\"popup-content\">\n <slot></slot>\n ${this.renderDismissButton()}\n </div>\n ${this.renderArrow()}\n </div>\n </vwc-elevation>\n </div>\n\t\t`;\n }\n}\n"]}