@skf-design-system/ui-components 1.0.2-beta.12 → 1.0.2-beta.13

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.
@@ -31,9 +31,5 @@ export declare class SkfPopover extends SkfPopoverBase {
31
31
  /** @internal */
32
32
  hideArrowChanged(): void;
33
33
  /** @internal */
34
- openExtended(): void;
35
- /** @internal */
36
34
  addEventListeners($element: HTMLElement | Element): void;
37
- /** @internal */
38
- _checkClickOutside: (e: Event) => void;
39
35
  }
@@ -1,43 +1,35 @@
1
1
  import { SkfPopoverBase as h } from "../../internal/base-classes/popover/popover.base.js";
2
- import { watch as l } from "../../internal/helpers/watch.js";
3
- import { property as c } from "lit/decorators.js";
2
+ import { watch as d } from "../../internal/helpers/watch.js";
3
+ import { property as f } from "lit/decorators.js";
4
4
  import { styles as w } from "./popover.styles.js";
5
- var f = Object.defineProperty, v = Object.getOwnPropertyDescriptor, n = (d, t, i, s) => {
6
- for (var e = s > 1 ? void 0 : s ? v(t, i) : t, o = d.length - 1, p; o >= 0; o--)
7
- (p = d[o]) && (e = (s ? p(t, i, e) : p(e)) || e);
8
- return s && e && f(t, i, e), e;
5
+ var c = Object.defineProperty, m = Object.getOwnPropertyDescriptor, a = (l, r, o, s) => {
6
+ for (var t = s > 1 ? void 0 : s ? m(r, o) : r, i = l.length - 1, p; i >= 0; i--)
7
+ (p = l[i]) && (t = (s ? p(r, o, t) : p(t)) || t);
8
+ return s && t && c(r, o, t), t;
9
9
  };
10
- const a = class a extends h {
10
+ const n = class n extends h {
11
11
  constructor() {
12
- super(), this.offset = 8, this.hideArrow = !1, this._checkClickOutside = (t) => {
13
- this.isOpen && !this.contains(t.target) && this.close();
14
- }, this.arrow = !this.hideArrow, this.placement = "bottom-start", this.triggerEvent = "click", this.variant = "popup", h.classMap = { popover: !0 };
12
+ super(), this.offset = 8, this.hideArrow = !1, this.arrow = !this.hideArrow, this.placement = "bottom-start", this.triggerEvent = "click", this.variant = "popup", h.classMap = { popover: !0 };
15
13
  }
16
14
  hideArrowChanged() {
17
15
  this.arrow = !this.hideArrow;
18
16
  }
19
17
  /** @internal */
20
- openExtended() {
21
- window.top && window.self !== window.top && window.top.addEventListener("click", this._checkClickOutside, {
22
- signal: this.signal
23
- });
24
- }
25
- /** @internal */
26
- addEventListeners(t) {
27
- t.addEventListener(this.triggerEvent, this.open, { signal: this.signal });
18
+ addEventListeners(r) {
19
+ r.addEventListener(this.triggerEvent, this.open, { signal: this.signal });
28
20
  }
29
21
  };
30
- a.styles = [h.styles, w];
31
- let r = a;
32
- n([
33
- c({ type: Number })
34
- ], r.prototype, "offset", 2);
35
- n([
36
- c({ type: Boolean })
37
- ], r.prototype, "hideArrow", 2);
38
- n([
39
- l("hideArrow")
40
- ], r.prototype, "hideArrowChanged", 1);
22
+ n.styles = [h.styles, w];
23
+ let e = n;
24
+ a([
25
+ f({ type: Number })
26
+ ], e.prototype, "offset", 2);
27
+ a([
28
+ f({ type: Boolean })
29
+ ], e.prototype, "hideArrow", 2);
30
+ a([
31
+ d("hideArrow")
32
+ ], e.prototype, "hideArrowChanged", 1);
41
33
  export {
42
- r as SkfPopover
34
+ e as SkfPopover
43
35
  };
@@ -23,9 +23,5 @@ export declare class SkfTooltip extends SkfPopoverBase {
23
23
  constructor();
24
24
  connectedCallback(): void;
25
25
  /** @internal */
26
- openExtended(): void;
27
- /** @internal */
28
- closeExtended(): void;
29
- /** @internal */
30
26
  addEventListeners($element: HTMLElement | Element): void;
31
27
  }
@@ -8,16 +8,20 @@ const e = class e extends t {
8
8
  super.connectedCallback(), this.role = "tooltip";
9
9
  }
10
10
  /** @internal */
11
- openExtended() {
12
- this.$anchor?.setAttribute("aria-describedby", this.id);
13
- }
14
- /** @internal */
15
- closeExtended() {
16
- this.$anchor?.removeAttribute("aria-describedby");
17
- }
18
- /** @internal */
19
11
  addEventListeners(s) {
20
- s.addEventListener("blur", this.close, { signal: this.signal }), s.addEventListener("focus", this.open, { signal: this.signal }), s.addEventListener("mouseenter", this.open, { signal: this.signal }), s.addEventListener("mouseleave", this.close, { signal: this.signal });
12
+ s.addEventListener(
13
+ "blur",
14
+ () => {
15
+ this.close("blur");
16
+ },
17
+ { signal: this.signal }
18
+ ), s.addEventListener("focus", this.open, { signal: this.signal }), s.addEventListener("mouseenter", this.open, { signal: this.signal }), s.addEventListener(
19
+ "mouseleave",
20
+ () => {
21
+ this.close("mouseleave");
22
+ },
23
+ { signal: this.signal }
24
+ );
21
25
  }
22
26
  };
23
27
  e.styles = [t.styles, a];
@@ -15,6 +15,7 @@ import { type CSSResultGroup } from 'lit';
15
15
  export declare class SkfPopoverBase extends SkfElement {
16
16
  static styles: CSSResultGroup;
17
17
  static classMap: {};
18
+ _skipClosingThisTick: boolean;
18
19
  /** @internal - The popover element, aka `this` */
19
20
  $popover: this;
20
21
  /** Where the popover is positioned relative to the anchor element if it fits */
@@ -35,6 +36,10 @@ export declare class SkfPopoverBase extends SkfElement {
35
36
  triggerEvent: 'mouseenter' | 'click';
36
37
  /** @internal - Reference to the arrow element */
37
38
  $arrow: HTMLElement;
39
+ /**
40
+ * Used to store the outside click listener reference for cleanup and to avoid duplicates
41
+ */
42
+ _skfPopoverOutsideClickListener?: (e: MouseEvent) => void;
38
43
  protected abortEventsController: AbortController;
39
44
  protected signal: AbortSignal;
40
45
  protected popoverController: PopoverController;
@@ -48,11 +53,7 @@ export declare class SkfPopoverBase extends SkfElement {
48
53
  reposition: () => Promise<void>;
49
54
  handleEscapeKey: (e: KeyboardEvent) => void;
50
55
  open: (e: Event) => void;
51
- /** @internal add additional open tasks here in UI component */
52
- openExtended(): void;
53
- close: () => void;
54
- /** @internal add additional close tasks here in UI component */
55
- closeExtended(): void;
56
+ close: (reason?: string) => void;
56
57
  /** @internal eventlisteners here should implement abort signal */
57
58
  addEventListeners($element: HTMLElement | Element): void;
58
59
  /** @internal */
@@ -1,25 +1,25 @@
1
- import { flip as w, offset as $, arrow as E, computePosition as O } from "@floating-ui/dom";
1
+ import { flip as y, offset as $, arrow as E, computePosition as O } from "@floating-ui/dom";
2
2
  import { SkfElement as C } from "../../components/skf-element.js";
3
- import { PopoverController as x } from "../../controllers/popover.controller.js";
4
- import { uuid as A } from "../../helpers/uuid.js";
3
+ import { PopoverController as T } from "../../controllers/popover.controller.js";
4
+ import { uuid as k } from "../../helpers/uuid.js";
5
5
  import { watch as f } from "../../helpers/watch.js";
6
- import { componentStyles as S } from "../../../styles/component.styles.js";
7
- import { nothing as P, html as g } from "lit";
8
- import { property as u, state as c, query as _ } from "lit/decorators.js";
9
- import { classMap as L } from "lit/directives/class-map.js";
10
- import { styles as F } from "./popover.styles.js";
11
- var k = Object.defineProperty, T = Object.getOwnPropertyDescriptor, r = (m, t, o, i) => {
12
- for (var e = i > 1 ? void 0 : i ? T(t, o) : t, n = m.length - 1, a; n >= 0; n--)
13
- (a = m[n]) && (e = (i ? a(t, o, e) : a(e)) || e);
14
- return i && e && k(t, o, e), e;
15
- }, p;
16
- const s = (p = class extends C {
6
+ import { componentStyles as P } from "../../../styles/component.styles.js";
7
+ import { nothing as _, html as m } from "lit";
8
+ import { property as u, state as c, query as A } from "lit/decorators.js";
9
+ import { classMap as S } from "lit/directives/class-map.js";
10
+ import { styles as L } from "./popover.styles.js";
11
+ var x = Object.defineProperty, F = Object.getOwnPropertyDescriptor, r = (g, t, s, o) => {
12
+ for (var e = o > 1 ? void 0 : o ? F(t, s) : t, n = g.length - 1, a; n >= 0; n--)
13
+ (a = g[n]) && (e = (o ? a(t, s, e) : a(e)) || e);
14
+ return o && e && x(t, s, e), e;
15
+ }, h;
16
+ const i = (h = class extends C {
17
17
  constructor() {
18
- super(...arguments), this.$popover = this, this.placement = "top", this.variant = "popup", this.isOpen = !1, this.offset = 0, this.arrow = !1, this.triggerEvent = "mouseenter", this.abortEventsController = new AbortController(), this.signal = this.abortEventsController.signal, this.popoverController = new x(this), this._toggleOpen = (t) => {
18
+ super(...arguments), this._skipClosingThisTick = !1, this.$popover = this, this.placement = "top", this.variant = "popup", this.isOpen = !1, this.offset = 0, this.arrow = !1, this.triggerEvent = "mouseenter", this.abortEventsController = new AbortController(), this.signal = this.abortEventsController.signal, this.popoverController = new T(this), this._toggleOpen = (t) => {
19
19
  this.isOpen = t ?? !this.isOpen;
20
20
  }, this._handleToggle = (t) => {
21
- const o = t.newState === "open";
22
- this.isOpen = o, this.emit(o ? "skf-opened" : "skf-closed");
21
+ const s = t.newState === "open";
22
+ this.isOpen = s, this.emit(s ? "skf-opened" : "skf-closed");
23
23
  }, this.handleToggleOpen = async () => {
24
24
  this.$anchor && (this.isOpen ? (this.$popover.togglePopover(!0), this.$popover.animate([{ opacity: 0 }, { opacity: 1 }], { duration: 250, fill: "forwards" })) : (await this.$popover.animate([{ opacity: 0 }], { duration: 150, fill: "forwards" }).finished, this.$popover && this.$popover.togglePopover(this.isOpen)));
25
25
  }, this.handleAnchorChange = async () => {
@@ -29,18 +29,18 @@ const s = (p = class extends C {
29
29
  this.$anchor = t.getElementById(this.anchor), this.$anchor && (this.addEventListeners(this.$anchor), this.popoverController.start());
30
30
  }, this.reposition = async () => {
31
31
  if (!this.$anchor) return;
32
- const t = [w(), $(this.offset)];
32
+ const t = [y(), $(this.offset)];
33
33
  this.arrow && t.push(E({ element: this.$arrow }));
34
- const { x: o, y: i, middlewareData: e } = await O(this.$anchor, this.$popover, {
34
+ const { x: s, y: o, middlewareData: e } = await O(this.$anchor, this.$popover, {
35
35
  placement: this.placement,
36
36
  middleware: t,
37
37
  strategy: "fixed"
38
38
  });
39
39
  if (Object.assign(this.$popover.style, {
40
- left: `${String(o)}px`,
41
- top: `${String(i)}px`
40
+ left: `${String(s)}px`,
41
+ top: `${String(o)}px`
42
42
  }), this.arrow) {
43
- const n = this.placement.split("-")[0], a = { top: "bottom", right: "left", bottom: "top", left: "right" }[n] ?? "", h = e.flip?.index, d = e.arrow?.x, l = e.arrow?.y, v = typeof d == "number" ? `${String(d)}px` : "", b = typeof l == "number" ? `${String(l)}px` : "", y = {
43
+ const n = this.placement.split("-")[0], a = { top: "bottom", right: "left", bottom: "top", left: "right" }[n] ?? "", p = e.flip?.index, d = e.arrow?.x, l = e.arrow?.y, v = typeof d == "number" ? `${String(d)}px` : "", b = typeof l == "number" ? `${String(l)}px` : "", w = {
44
44
  bottom: 45,
45
45
  right: 135,
46
46
  top: 225,
@@ -49,16 +49,18 @@ const s = (p = class extends C {
49
49
  Object.assign(this.$arrow.style, {
50
50
  top: b,
51
51
  [this.placement.includes("left") ? "right" : "left"]: v,
52
- [h ? n : a]: "calc(var(--_skf-popover-arrow-size) * -1)",
53
- rotate: `${(y[a] + (h ? 180 : 0)).toString()}deg`
52
+ [p ? n : a]: "calc(var(--_skf-popover-arrow-size) * -1)",
53
+ rotate: `${(w[a] + (p ? 180 : 0)).toString()}deg`
54
54
  });
55
55
  }
56
56
  }, this.handleEscapeKey = (t) => {
57
57
  t.key === "Escape" && this.close();
58
58
  }, this.open = (t) => {
59
- t.stopPropagation(), this._toggleOpen(!0), this.abortEventsController = new AbortController(), this.signal = this.abortEventsController.signal, document.addEventListener("keydown", this.handleEscapeKey, { signal: this.signal }), this.openExtended();
60
- }, this.close = () => {
61
- this.closeExtended(), this._toggleOpen(!1), this.abortEventsController.abort();
59
+ t.stopPropagation();
60
+ const o = this.tagName === "SKF-MENU" ? void 0 : !0;
61
+ this._toggleOpen(o), this.abortEventsController = new AbortController(), this.signal = this.abortEventsController.signal, document.addEventListener("keydown", this.handleEscapeKey, { signal: this.signal }), this.tagName === "SKF-TOOLTIP" && this.$anchor?.setAttribute("aria-describedby", this.id);
62
+ }, this.close = (t = "") => {
63
+ console.log("Popover closing", t), this._toggleOpen(!1), this.abortEventsController.abort(), this.tagName === "SKF-TOOLTIP" && this.$anchor?.removeAttribute("aria-describedby");
62
64
  };
63
65
  }
64
66
  connectedCallback() {
@@ -75,24 +77,28 @@ const s = (p = class extends C {
75
77
  this.$anchor.addEventListener(
76
78
  "focusout",
77
79
  (o) => {
78
- const i = this.contains(o.relatedTarget);
79
- t && i || this.close();
80
+ const e = this.contains(o.relatedTarget);
81
+ t && e || this._skipClosingThisTick || this.close("anchor focus out");
80
82
  },
81
83
  { signal: this.signal }
82
84
  ), this.addEventListener(
83
85
  "focusout",
84
86
  (o) => {
85
- const i = this.contains(o.relatedTarget);
86
- t && i || this.close();
87
+ const e = this.contains(o.relatedTarget);
88
+ t && e || this.close("popover focusout");
87
89
  },
88
90
  { signal: this.signal }
89
- ), this.$popover.id = await A(this.$anchor.id), ["popup", "menu"].includes(this.variant) && (this.$anchor.setAttribute("aria-haspopup", "true"), this.setAttribute("aria-labelledby", this.$anchor.id)), ["menu"].includes(this.variant) && this.$anchor.setAttribute("aria-controls", this.$popover.id), ["popup"].includes(this.variant) && t && (this.role = "dialog"), ["tooltip"].includes(this.variant) && this.$anchor.addEventListener("focusin", this.open, { signal: this.signal });
90
- }
91
- /** @internal add additional open tasks here in UI component */
92
- openExtended() {
93
- }
94
- /** @internal add additional close tasks here in UI component */
95
- closeExtended() {
91
+ ), this._skfPopoverOutsideClickListener ??= (o) => {
92
+ this.isOpen && this.$anchor && !this.contains(o.target) && !this.$anchor.contains(o.target) ? this.close("outside click") : (this._skipClosingThisTick = !0, setTimeout(() => {
93
+ this._skipClosingThisTick = !1;
94
+ }, 0));
95
+ }, document.addEventListener("mousedown", this._skfPopoverOutsideClickListener, {
96
+ signal: this.signal
97
+ });
98
+ const s = window.top && window.self !== window.top;
99
+ console.log("contains frames", s), s && window.top && !this._skipClosingThisTick && window.top.addEventListener("mousedown", this._skfPopoverOutsideClickListener, {
100
+ signal: this.signal
101
+ }), this.$popover.id = await k(this.$anchor.id), ["popup", "menu"].includes(this.variant) && (this.$anchor.setAttribute("aria-haspopup", "true"), this.setAttribute("aria-labelledby", this.$anchor.id)), ["menu"].includes(this.variant) && this.$anchor.setAttribute("aria-controls", this.$popover.id), ["popup"].includes(this.variant) && t && (this.role = "dialog"), ["tooltip"].includes(this.variant) && this.$anchor.addEventListener("focusin", this.open, { signal: this.signal });
96
102
  }
97
103
  /** @internal eventlisteners here should implement abort signal */
98
104
  addEventListeners(t) {
@@ -103,10 +109,10 @@ const s = (p = class extends C {
103
109
  this.abortEventsController.abort();
104
110
  }
105
111
  render() {
106
- return ["popup", "menu"].includes(this.variant) && this.$anchor?.setAttribute("aria-expanded", this.isOpen ? "true" : "false"), g`
107
- <div class=${L({ popover: !0, ...p.classMap })} id="root">
112
+ return ["popup", "menu"].includes(this.variant) && this.$anchor?.setAttribute("aria-expanded", this.isOpen ? "true" : "false"), m`
113
+ <div class=${S({ popover: !0, ...h.classMap })} id="root">
108
114
  <slot></slot>
109
- ${this.arrow ? g`<div id="arrow"></div>` : P}
115
+ ${this.arrow ? m`<div id="arrow"></div>` : _}
110
116
  </div>
111
117
  `;
112
118
  }
@@ -121,54 +127,54 @@ const s = (p = class extends C {
121
127
  '[tabindex]:not([tabindex="-1"])'
122
128
  ]).length > 0;
123
129
  function e(n, a) {
124
- const h = Array.from(
130
+ const p = Array.from(
125
131
  n.querySelectorAll(a.join(", "))
126
132
  ), d = Array.from(n.querySelectorAll("*")).map((l) => l.shadowRoot).filter((l) => l !== null);
127
133
  for (const l of d)
128
- h.push(
134
+ p.push(
129
135
  ...e(l, a)
130
136
  );
131
- return h;
137
+ return p;
132
138
  }
133
139
  }
134
- }, p.styles = [S, F], p.classMap = {}, p);
140
+ }, h.styles = [P, L], h.classMap = {}, h);
135
141
  r([
136
142
  u()
137
- ], s.prototype, "placement", 2);
143
+ ], i.prototype, "placement", 2);
138
144
  r([
139
145
  u()
140
- ], s.prototype, "variant", 2);
146
+ ], i.prototype, "variant", 2);
141
147
  r([
142
148
  u()
143
- ], s.prototype, "anchor", 2);
149
+ ], i.prototype, "anchor", 2);
144
150
  r([
145
151
  c()
146
- ], s.prototype, "isOpen", 2);
152
+ ], i.prototype, "isOpen", 2);
147
153
  r([
148
154
  c()
149
- ], s.prototype, "offset", 2);
155
+ ], i.prototype, "offset", 2);
150
156
  r([
151
157
  c()
152
- ], s.prototype, "$anchor", 2);
158
+ ], i.prototype, "$anchor", 2);
153
159
  r([
154
160
  c()
155
- ], s.prototype, "arrow", 2);
161
+ ], i.prototype, "arrow", 2);
156
162
  r([
157
163
  c()
158
- ], s.prototype, "triggerEvent", 2);
164
+ ], i.prototype, "triggerEvent", 2);
159
165
  r([
160
- _("#arrow")
161
- ], s.prototype, "$arrow", 2);
166
+ A("#arrow")
167
+ ], i.prototype, "$arrow", 2);
162
168
  r([
163
169
  f("isOpen", { afterUpdate: !0 })
164
- ], s.prototype, "handleToggleOpen", 2);
170
+ ], i.prototype, "handleToggleOpen", 2);
165
171
  r([
166
172
  f("$anchor")
167
- ], s.prototype, "handleAnchorEl", 1);
173
+ ], i.prototype, "handleAnchorEl", 1);
168
174
  r([
169
175
  f("anchor")
170
- ], s.prototype, "handleAnchorChange", 2);
171
- let U = s;
176
+ ], i.prototype, "handleAnchorChange", 2);
177
+ let z = i;
172
178
  export {
173
- U as SkfPopoverBase
179
+ z as SkfPopoverBase
174
180
  };
package/package.json CHANGED
@@ -35,7 +35,7 @@
35
35
  "sideEffects": true,
36
36
  "type": "module",
37
37
  "types": "./dist/index.d.ts",
38
- "version": "1.0.2-beta.12",
38
+ "version": "1.0.2-beta.13",
39
39
  "dependencies": {
40
40
  "@floating-ui/dom": "^1.7.1",
41
41
  "@js-temporal/polyfill": "^0.5.1",