@quandis/qbo4.ui 4.0.1-CI-20241107-011209 → 4.0.1-CI-20241108-204652

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.
@@ -7,44 +7,73 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  var __metadata = (this && this.__metadata) || function (k, v) {
8
8
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
9
  };
10
- import { html } from 'lit';
11
- import { customElement, property } from 'lit/decorators.js';
12
- import { Popover } from 'bootstrap';
13
- import { QboFormElement } from './qbo-form-element.js';
14
- let QboPopover = class QboPopover extends QboFormElement {
10
+ import { LitElement, html } from "lit";
11
+ import { customElement, property, state } from "lit/decorators.js";
12
+ import { computePosition, shift, flip } from "@floating-ui/dom";
13
+ let QboPopover = class QboPopover extends LitElement {
15
14
  constructor() {
16
15
  super(...arguments);
17
- this.contentAtt = 'data-bs-content';
18
- this.contentStyle = 'none';
19
- this.containerAtt = 'data-bs-container';
20
- this.containerValue = 'body';
21
- this.defaultContent = 'No content provided';
22
- this.htmlAtt = 'data-bs-html';
23
- this.htmlValue = 'true';
24
- this.placementAtt = 'data-bs-placement';
25
- this.placementValue = 'left';
26
- this.selector = '*[slot=content]';
27
- this.toggleAtt = 'data-bs-toggle';
28
- this.toggleValue = 'popover';
29
- this.renderInHost = true;
16
+ this.placement = "bottom";
17
+ this.selector = '*[data-popover-trigger]';
18
+ // Internal state to control menu visibility
19
+ this.isOpen = false;
20
+ this.middleware = [flip(), shift()];
21
+ this.handleMenuOpen = (event) => {
22
+ event.preventDefault();
23
+ event.stopPropagation();
24
+ if (event.detail.menu !== this && this.isOpen)
25
+ this.closeMenu();
26
+ };
27
+ this.toggleMenu = (event) => {
28
+ this.isOpen = !this.isOpen;
29
+ this.classList.toggle("open", this.isOpen);
30
+ if (this.isOpen) {
31
+ this.setPosition();
32
+ document.dispatchEvent(new CustomEvent("qbo-popover-open", {
33
+ bubbles: true,
34
+ composed: true,
35
+ detail: { menu: this },
36
+ }));
37
+ }
38
+ };
30
39
  }
31
- createRenderRoot() {
32
- return this.renderInHost ? this : super.createRenderRoot();
40
+ async setPosition() {
41
+ const { x, y } = await computePosition(this.triggerElement, this, {
42
+ placement: this.placement,
43
+ middleware: this.middleware,
44
+ });
45
+ Object.assign(this.style, {
46
+ left: `${x}px`,
47
+ top: `${y}px`,
48
+ });
33
49
  }
34
50
  connectedCallback() {
35
51
  super.connectedCallback();
36
- this.setAttribute(this.toggleAtt, this.toggleValue);
37
- this.setAttribute(this.placementAtt, this.placementValue);
38
- this.setAttribute(this.containerAtt, this.containerValue);
39
- this.setAttribute(this.htmlAtt, this.htmlValue);
52
+ document.addEventListener("qbo-popover-open", this.handleMenuOpen);
40
53
  }
41
- firstUpdated(changedProperties) {
42
- super.firstUpdated(changedProperties);
43
- const content = this.querySelector(this.selector);
44
- if (content instanceof HTMLElement)
45
- content.style.display = this.contentStyle;
46
- this.setAttribute(this.contentAtt, content?.innerHTML ?? this.defaultContent);
47
- new Popover(this);
54
+ disconnectedCallback() {
55
+ super.disconnectedCallback();
56
+ document.removeEventListener("qbo-popover-open", this.handleMenuOpen);
57
+ if (this.triggerElement != null) {
58
+ this.triggerElement.removeEventListener("mouseover", this.toggleMenu);
59
+ this.triggerElement.removeEventListener("mouseout", this.toggleMenu);
60
+ }
61
+ }
62
+ firstUpdated(changes) {
63
+ super.firstUpdated(changes);
64
+ this.triggerElement =
65
+ this.parentElement?.querySelector(this.selector) ||
66
+ this.shadowRoot?.querySelector(this.selector) ||
67
+ document.querySelector(this.selector) ||
68
+ this.parentElement;
69
+ if (this.triggerElement != null) {
70
+ this.triggerElement.addEventListener("mouseover", this.toggleMenu);
71
+ this.triggerElement.addEventListener("mouseout", this.toggleMenu);
72
+ }
73
+ }
74
+ closeMenu() {
75
+ this.isOpen = false;
76
+ this.classList.remove("open");
48
77
  }
49
78
  render() {
50
79
  return html `<slot></slot>`;
@@ -52,56 +81,16 @@ let QboPopover = class QboPopover extends QboFormElement {
52
81
  };
53
82
  __decorate([
54
83
  property({ type: String }),
55
- __metadata("design:type", Object)
56
- ], QboPopover.prototype, "contentAtt", void 0);
57
- __decorate([
58
- property({ type: String }),
59
- __metadata("design:type", Object)
60
- ], QboPopover.prototype, "contentStyle", void 0);
61
- __decorate([
62
- property({ type: String }),
63
- __metadata("design:type", Object)
64
- ], QboPopover.prototype, "containerAtt", void 0);
65
- __decorate([
66
- property({ type: String }),
67
- __metadata("design:type", Object)
68
- ], QboPopover.prototype, "containerValue", void 0);
69
- __decorate([
70
- property({ type: String }),
71
- __metadata("design:type", Object)
72
- ], QboPopover.prototype, "defaultContent", void 0);
73
- __decorate([
74
- property({ type: String }),
75
- __metadata("design:type", Object)
76
- ], QboPopover.prototype, "htmlAtt", void 0);
77
- __decorate([
78
- property({ type: String }),
79
- __metadata("design:type", Object)
80
- ], QboPopover.prototype, "htmlValue", void 0);
81
- __decorate([
82
- property({ type: String }),
83
- __metadata("design:type", Object)
84
- ], QboPopover.prototype, "placementAtt", void 0);
85
- __decorate([
86
- property({ type: String }),
87
- __metadata("design:type", Object)
88
- ], QboPopover.prototype, "placementValue", void 0);
84
+ __metadata("design:type", String)
85
+ ], QboPopover.prototype, "placement", void 0);
89
86
  __decorate([
90
87
  property({ type: String }),
91
88
  __metadata("design:type", Object)
92
89
  ], QboPopover.prototype, "selector", void 0);
93
90
  __decorate([
94
- property({ type: String }),
95
- __metadata("design:type", Object)
96
- ], QboPopover.prototype, "toggleAtt", void 0);
97
- __decorate([
98
- property({ type: String }),
99
- __metadata("design:type", Object)
100
- ], QboPopover.prototype, "toggleValue", void 0);
101
- __decorate([
102
- property({ type: Boolean }),
91
+ state(),
103
92
  __metadata("design:type", Object)
104
- ], QboPopover.prototype, "renderInHost", void 0);
93
+ ], QboPopover.prototype, "isOpen", void 0);
105
94
  QboPopover = __decorate([
106
95
  customElement('qbo-popover')
107
96
  ], QboPopover);
@@ -1,71 +1,97 @@
1
- import { html, PropertyValues } from 'lit';
2
- import { customElement, property } from 'lit/decorators.js';
3
- import { Popover } from 'bootstrap';
4
- import { QboFormElement } from './qbo-form-element.js';
1
+ import { LitElement, PropertyValues, html } from "lit";
2
+ import { customElement, property, state } from "lit/decorators.js";
3
+ import { computePosition, Placement, shift, flip } from "@floating-ui/dom";
5
4
 
6
5
  @customElement('qbo-popover')
7
- export class QboPopover extends QboFormElement {
6
+ export class QboPopover extends LitElement {
8
7
 
9
8
  @property({ type: String })
10
- contentAtt = 'data-bs-content';
9
+ placement: Placement = "bottom";
11
10
 
12
11
  @property({ type: String })
13
- contentStyle = 'none';
14
-
15
- @property({ type: String })
16
- containerAtt = 'data-bs-container';
17
-
18
- @property({ type: String })
19
- containerValue = 'body';
20
-
21
- @property({ type: String })
22
- defaultContent = 'No content provided';
23
-
24
- @property({ type: String })
25
- htmlAtt = 'data-bs-html';
26
-
27
- @property({ type: String })
28
- htmlValue = 'true';
29
-
30
- @property({ type: String })
31
- placementAtt = 'data-bs-placement';
32
-
33
- @property({ type: String })
34
- placementValue = 'left';
12
+ selector = '*[data-popover-trigger]';
13
+
14
+ // Internal state to control menu visibility
15
+ @state() private isOpen = false;
16
+
17
+ private triggerElement!: HTMLElement;
18
+ private middleware = [flip(), shift()];
19
+
20
+ private async setPosition() {
21
+ const { x, y } = await computePosition(
22
+ this.triggerElement,
23
+ this,
24
+ {
25
+ placement: this.placement as Placement | undefined,
26
+ middleware: this.middleware,
27
+ }
28
+ );
29
+
30
+ Object.assign(
31
+ this.style, {
32
+ left: `${x}px`,
33
+ top: `${y}px`,
34
+ });
35
+ }
35
36
 
36
- @property({ type: String })
37
- selector = '*[slot=content]';
37
+ connectedCallback() {
38
+ super.connectedCallback();
38
39
 
39
- @property({ type: String })
40
- toggleAtt = 'data-bs-toggle';
40
+ document.addEventListener("qbo-popover-open", this.handleMenuOpen);
41
+ }
41
42
 
42
- @property({ type: String })
43
- toggleValue = 'popover';
43
+ disconnectedCallback() {
44
+ super.disconnectedCallback();
44
45
 
45
- @property({ type: Boolean })
46
- renderInHost = true;
46
+ document.removeEventListener("qbo-popover-open", this.handleMenuOpen);
47
47
 
48
- createRenderRoot() {
49
- return this.renderInHost ? this : super.createRenderRoot();
48
+ if (this.triggerElement != null) {
49
+ this.triggerElement.removeEventListener("mouseover", this.toggleMenu);
50
+ this.triggerElement.removeEventListener("mouseout", this.toggleMenu);
51
+ }
50
52
  }
51
53
 
52
- connectedCallback() {
53
- super.connectedCallback();
54
-
55
- this.setAttribute(this.toggleAtt, this.toggleValue);
56
- this.setAttribute(this.placementAtt, this.placementValue);
57
- this.setAttribute(this.containerAtt, this.containerValue);
58
- this.setAttribute(this.htmlAtt, this.htmlValue);
59
- }
54
+ firstUpdated(changes: PropertyValues) {
55
+ super.firstUpdated(changes);
60
56
 
61
- firstUpdated(changedProperties: PropertyValues) {
62
- super.firstUpdated(changedProperties);
57
+ this.triggerElement =
58
+ this.parentElement?.querySelector(this.selector) ||
59
+ this.shadowRoot?.querySelector(this.selector) ||
60
+ document.querySelector(this.selector) ||
61
+ this.parentElement as HTMLElement;
63
62
 
64
- const content = this.querySelector(this.selector);
65
- if (content instanceof HTMLElement) content.style.display = this.contentStyle;
66
- this.setAttribute(this.contentAtt, content?.innerHTML ?? this.defaultContent);
63
+ if (this.triggerElement != null) {
64
+ this.triggerElement.addEventListener("mouseover", this.toggleMenu);
65
+ this.triggerElement.addEventListener("mouseout", this.toggleMenu);
66
+ }
67
+ }
67
68
 
68
- new Popover(this);
69
+ handleMenuOpen = (event: Event) => {
70
+ event.preventDefault();
71
+ event.stopPropagation();
72
+
73
+ if ((event as CustomEvent).detail.menu !== this && this.isOpen) this.closeMenu();
74
+ };
75
+
76
+ toggleMenu = (event: Event) => {
77
+ this.isOpen = !this.isOpen;
78
+ this.classList.toggle("open", this.isOpen);
79
+
80
+ if (this.isOpen) {
81
+ this.setPosition();
82
+ document.dispatchEvent(
83
+ new CustomEvent("qbo-popover-open", {
84
+ bubbles: true,
85
+ composed: true,
86
+ detail: { menu: this },
87
+ })
88
+ );
89
+ }
90
+ };
91
+
92
+ closeMenu() {
93
+ this.isOpen = false;
94
+ this.classList.remove("open");
69
95
  }
70
96
 
71
97
  render() {