@waggylabs/yumekit 0.4.3 → 0.4.4

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.
@@ -1,5 +1,6 @@
1
1
  export class YumeBadge extends HTMLElement {
2
2
  static get observedAttributes(): string[];
3
+ _onSlotChange(): void;
3
4
  connectedCallback(): void;
4
5
  attributeChangedCallback(name: any, oldValue: any, newValue: any): void;
5
6
  set alignment(val: string);
@@ -21,5 +22,4 @@ export class YumeBadge extends HTMLElement {
21
22
  _getBadgeColors(color: any): any;
22
23
  _getBadgePosition(position: any, alignment: any): string;
23
24
  _getSizeAttributes(size: any): any;
24
- _hasTargetContent(): boolean;
25
25
  }
@@ -1,5 +1,6 @@
1
1
  export class YumeBadge extends HTMLElement {
2
2
  static get observedAttributes(): string[];
3
+ _onSlotChange(): void;
3
4
  connectedCallback(): void;
4
5
  attributeChangedCallback(name: any, oldValue: any, newValue: any): void;
5
6
  set alignment(val: string);
@@ -21,5 +22,4 @@ export class YumeBadge extends HTMLElement {
21
22
  _getBadgeColors(color: any): any;
22
23
  _getBadgePosition(position: any, alignment: any): string;
23
24
  _getSizeAttributes(size: any): any;
24
- _hasTargetContent(): boolean;
25
25
  }
@@ -12,6 +12,7 @@ class YumeBadge extends HTMLElement {
12
12
  constructor() {
13
13
  super();
14
14
  this.attachShadow({ mode: "open" });
15
+ this._onSlotChange = this._onSlotChange.bind(this);
15
16
  this.render();
16
17
  }
17
18
 
@@ -54,21 +55,24 @@ class YumeBadge extends HTMLElement {
54
55
  render() {
55
56
  const [badgeColor, badgeTextColor] = this._getBadgeColors(this.color);
56
57
  const { fontSize, padding, minSize } = this._getSizeAttributes(this.size);
57
- const hasTarget = this._hasTargetContent();
58
- const positionCSS = hasTarget
59
- ? this._getBadgePosition(this.position, this.alignment)
60
- : "";
58
+ const positionCSS = this._getBadgePosition(this.position, this.alignment);
61
59
 
62
60
  this.shadowRoot.innerHTML = `
63
61
  <style>
64
62
  :host {
65
- position: ${hasTarget ? "relative" : "static"};
66
63
  display: inline-flex;
67
64
  align-items: center;
68
65
  }
66
+ .root {
67
+ position: static;
68
+ display: inline-flex;
69
+ align-items: center;
70
+ }
71
+ .root.has-target {
72
+ position: relative;
73
+ }
69
74
  .badge {
70
- position: ${hasTarget ? "absolute" : "static"};
71
- ${positionCSS}
75
+ position: static;
72
76
  background: ${badgeColor};
73
77
  color: ${badgeTextColor};
74
78
  font-size: ${fontSize};
@@ -83,14 +87,24 @@ class YumeBadge extends HTMLElement {
83
87
  height: ${minSize};
84
88
  z-index: 20;
85
89
  }
90
+ .root.has-target .badge {
91
+ position: absolute;
92
+ ${positionCSS}
93
+ }
86
94
  ::slotted(*) {
87
95
  position: relative;
88
96
  display: inline-block;
89
97
  }
90
98
  </style>
91
- ${hasTarget ? "<slot></slot>" : ""}
92
- <div class="badge" part="badge">${this.value}</div>
99
+ <div class="root" part="root">
100
+ <slot></slot>
101
+ <div class="badge" part="badge">${this.value}</div>
102
+ </div>
93
103
  `;
104
+
105
+ const slot = this.shadowRoot.querySelector("slot");
106
+ slot.addEventListener("slotchange", this._onSlotChange);
107
+ this._onSlotChange();
94
108
  }
95
109
 
96
110
  // -------------------------------------------------------------------------
@@ -142,12 +156,14 @@ class YumeBadge extends HTMLElement {
142
156
  return sizeMap[size] || sizeMap.small;
143
157
  }
144
158
 
145
- _hasTargetContent() {
146
- return Array.from(this.childNodes).some((node) => {
147
- if (node.nodeType === Node.ELEMENT_NODE) return true;
148
- if (node.nodeType === Node.TEXT_NODE) return node.textContent.trim() !== "";
149
- return false;
150
- });
159
+ _onSlotChange() {
160
+ const slot = this.shadowRoot.querySelector("slot");
161
+ const root = this.shadowRoot.querySelector(".root");
162
+ if (!slot || !root) return;
163
+ const hasElement = slot
164
+ .assignedNodes({ flatten: true })
165
+ .some((n) => n.nodeType === Node.ELEMENT_NODE);
166
+ root.classList.toggle("has-target", hasElement);
151
167
  }
152
168
  }
153
169
 
@@ -1 +1,57 @@
1
- export {};
1
+ export class YumeMenu extends HTMLElement {
2
+ static get observedAttributes(): string[];
3
+ static _closeAll(except: any): void;
4
+ static _warnTemplateFieldDeprecated(): void;
5
+ static _warnUrlDeprecated(): void;
6
+ _onAnchorClick(e: any): void;
7
+ _onDocumentClick(e: any): void;
8
+ _onScrollOrResize(): void;
9
+ _isReady: boolean;
10
+ _slottedHandlers: Map<any, any>;
11
+ connectedCallback(): void;
12
+ set items(val: any);
13
+ /** Menu items array (JSON attribute). */
14
+ get items(): any;
15
+ disconnectedCallback(): void;
16
+ attributeChangedCallback(name: any, oldVal: any, newVal: any): void;
17
+ set anchor(val: string);
18
+ /** Which anchor element ID triggers this menu. */
19
+ get anchor(): string;
20
+ set direction(val: string);
21
+ /** Direction for menu placement: "down" | "up" | "left" | "right" (default "down"). */
22
+ get direction(): string;
23
+ set history(val: string);
24
+ /**
25
+ * Navigation mode: omit for pushState (SPA-friendly), set to "false" for full-page navigation.
26
+ * Regardless of this setting, a cancelable "navigate" event is always dispatched first.
27
+ */
28
+ get history(): string;
29
+ set size(val: string);
30
+ /** Size: "small" | "medium" | "large" (default "medium"). */
31
+ get size(): string;
32
+ set visible(val: boolean);
33
+ /** Whether the menu is currently visible. */
34
+ get visible(): boolean;
35
+ render(): void;
36
+ _activateItem(item: any): void;
37
+ _activateSlottedItem(el: any): void;
38
+ _buildStyles(): string;
39
+ _computeMenuOffset(direction: any, anchorRect: any, menuRect: any, vw: any, vh: any): {
40
+ top: any;
41
+ left: any;
42
+ };
43
+ _createItemContent(item: any): HTMLElement;
44
+ _createMenuItem(item: any): HTMLElement;
45
+ _createMenuList(items: any): HTMLElement;
46
+ _createSubmenuIndicator(): HTMLElement;
47
+ _dispatchSelect(detail: any): void;
48
+ _findTemplate(name: any): Element;
49
+ _navigateTo(href: any): void;
50
+ _processSlottedItems(): void;
51
+ _setupAnchor(): void;
52
+ _anchorResolveDispose: () => void;
53
+ _anchorEl: HTMLElement;
54
+ _teardownAnchor(): void;
55
+ _teardownSlottedItems(): void;
56
+ _updatePosition(): void;
57
+ }
@@ -1 +1,57 @@
1
- export {};
1
+ export class YumeMenu extends HTMLElement {
2
+ static get observedAttributes(): string[];
3
+ static _closeAll(except: any): void;
4
+ static _warnTemplateFieldDeprecated(): void;
5
+ static _warnUrlDeprecated(): void;
6
+ _onAnchorClick(e: any): void;
7
+ _onDocumentClick(e: any): void;
8
+ _onScrollOrResize(): void;
9
+ _isReady: boolean;
10
+ _slottedHandlers: Map<any, any>;
11
+ connectedCallback(): void;
12
+ set items(val: any);
13
+ /** Menu items array (JSON attribute). */
14
+ get items(): any;
15
+ disconnectedCallback(): void;
16
+ attributeChangedCallback(name: any, oldVal: any, newVal: any): void;
17
+ set anchor(val: string);
18
+ /** Which anchor element ID triggers this menu. */
19
+ get anchor(): string;
20
+ set direction(val: string);
21
+ /** Direction for menu placement: "down" | "up" | "left" | "right" (default "down"). */
22
+ get direction(): string;
23
+ set history(val: string);
24
+ /**
25
+ * Navigation mode: omit for pushState (SPA-friendly), set to "false" for full-page navigation.
26
+ * Regardless of this setting, a cancelable "navigate" event is always dispatched first.
27
+ */
28
+ get history(): string;
29
+ set size(val: string);
30
+ /** Size: "small" | "medium" | "large" (default "medium"). */
31
+ get size(): string;
32
+ set visible(val: boolean);
33
+ /** Whether the menu is currently visible. */
34
+ get visible(): boolean;
35
+ render(): void;
36
+ _activateItem(item: any): void;
37
+ _activateSlottedItem(el: any): void;
38
+ _buildStyles(): string;
39
+ _computeMenuOffset(direction: any, anchorRect: any, menuRect: any, vw: any, vh: any): {
40
+ top: any;
41
+ left: any;
42
+ };
43
+ _createItemContent(item: any): HTMLElement;
44
+ _createMenuItem(item: any): HTMLElement;
45
+ _createMenuList(items: any): HTMLElement;
46
+ _createSubmenuIndicator(): HTMLElement;
47
+ _dispatchSelect(detail: any): void;
48
+ _findTemplate(name: any): Element;
49
+ _navigateTo(href: any): void;
50
+ _processSlottedItems(): void;
51
+ _setupAnchor(): void;
52
+ _anchorResolveDispose: () => void;
53
+ _anchorEl: HTMLElement;
54
+ _teardownAnchor(): void;
55
+ _teardownSlottedItems(): void;
56
+ _updatePosition(): void;
57
+ }