@greypan/web-ui 2.1.1 → 2.1.2
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/README.CN.md +43 -39
- package/README.md +53 -48
- package/dist/assets/menu-portal.js +1 -1
- package/dist/assets/menu-portal.js.map +1 -1
- package/dist/assets/toast-containers.js +1 -1
- package/dist/assets/toast-containers.js.map +1 -1
- package/dist/components/back-top/index.d.ts +3 -1
- package/dist/components/back-top/index.js +16 -12
- package/dist/components/back-top/index.js.map +1 -1
- package/dist/components/back-top/style.js +1 -1
- package/dist/components/back-top/style.js.map +1 -1
- package/dist/components/context-menu/index.d.ts +3 -4
- package/dist/components/context-menu/index.js +55 -69
- package/dist/components/context-menu/index.js.map +1 -1
- package/dist/components/context-menu/style.js +1 -1
- package/dist/components/context-menu/style.js.map +1 -1
- package/dist/components/dialog/index.d.ts +4 -11
- package/dist/components/dialog/index.js +29 -53
- package/dist/components/dialog/index.js.map +1 -1
- package/dist/components/drawer/index.d.ts +4 -11
- package/dist/components/drawer/index.js +42 -63
- package/dist/components/drawer/index.js.map +1 -1
- package/dist/components/dropdown/index.d.ts +3 -3
- package/dist/components/dropdown/index.js +70 -78
- package/dist/components/dropdown/index.js.map +1 -1
- package/dist/components/dropdown/style.js +1 -1
- package/dist/components/dropdown/style.js.map +1 -1
- package/dist/components/dropdown-item/style.js +1 -1
- package/dist/components/dropdown-item/style.js.map +1 -1
- package/dist/components/option/style.js +1 -1
- package/dist/components/option/style.js.map +1 -1
- package/dist/components/popover/index.d.ts +2 -5
- package/dist/components/popover/index.js +47 -70
- package/dist/components/popover/index.js.map +1 -1
- package/dist/components/select/index.d.ts +4 -7
- package/dist/components/select/index.js +64 -74
- package/dist/components/select/index.js.map +1 -1
- package/dist/components/select/style.js +1 -1
- package/dist/components/select/style.js.map +1 -1
- package/dist/components/switch/style.js +1 -1
- package/dist/components/switch/style.js.map +1 -1
- package/dist/components/theme/style.js +1 -1
- package/dist/components/theme/style.js.map +1 -1
- package/dist/components/toast/manager.js +1 -1
- package/dist/components/toast/manager.js.map +1 -1
- package/dist/components/toast/toast.d.ts +1 -1
- package/dist/components/toast/toast.js +26 -26
- package/dist/components/toast/toast.js.map +1 -1
- package/dist/components/tooltip/index.d.ts +3 -5
- package/dist/components/tooltip/index.js +61 -70
- package/dist/components/tooltip/index.js.map +1 -1
- package/dist/icons/generated/ooui-close.d.ts +6 -0
- package/dist/icons/generated/ooui-close.js +10 -0
- package/dist/icons/generated/ooui-close.js.map +1 -0
- package/dist/icons/index.d.ts +1 -0
- package/dist/icons/index.js +2 -1
- package/dist/shared/menu-portal/menu-portal.js +8 -1
- package/dist/shared/menu-portal/menu-portal.js.map +1 -1
- package/dist/shared/menu-portal/menu-tree.js +29 -0
- package/dist/shared/menu-portal/menu-tree.js.map +1 -0
- package/dist/shared/overlay/anchored-panel.js +49 -0
- package/dist/shared/overlay/anchored-panel.js.map +1 -0
- package/dist/shared/overlay/native-dialog-presence.js +45 -0
- package/dist/shared/overlay/native-dialog-presence.js.map +1 -0
- package/dist/shared/overlay/overlay.js +5 -2
- package/dist/shared/overlay/overlay.js.map +1 -1
- package/dist/shared/overlay/portal.js +3 -3
- package/dist/shared/overlay/portal.js.map +1 -1
- package/dist/shared/overlay/presence.js +1 -1
- package/dist/shared/overlay/presence.js.map +1 -1
- package/dist/shared/scroll-lock/scroll-lock.js +15 -1
- package/dist/shared/scroll-lock/scroll-lock.js.map +1 -1
- package/dist/types/vue.d.ts +2 -1
- package/package.json +1 -1
- package/dist/shared/property-converters/boolean-with-false-string.js +0 -9
- package/dist/shared/property-converters/boolean-with-false-string.js.map +0 -1
|
@@ -2,14 +2,13 @@ import e from "../../_virtual/_@oxc-project_runtime@0.140.0/helpers/esm/decorate
|
|
|
2
2
|
import t from "../../assets/glass.js";
|
|
3
3
|
import { normalizeLiteral as n, normalizeNumber as r } from "../../shared/normalize/index.js";
|
|
4
4
|
import i from "../../assets/overlay-motion.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import l from "
|
|
9
|
-
import {
|
|
10
|
-
import { customElement as p, property as m } from "lit/decorators.js";
|
|
5
|
+
import { defineAnchoredPanel as a } from "../../shared/overlay/anchored-panel.js";
|
|
6
|
+
import { createOverlayPortal as o } from "../../shared/overlay/portal.js";
|
|
7
|
+
import s from "./style.js";
|
|
8
|
+
import { LitElement as c, html as l, unsafeCSS as u } from "lit";
|
|
9
|
+
import { customElement as d, property as f } from "lit/decorators.js";
|
|
11
10
|
//#region src/components/popover/index.ts
|
|
12
|
-
var
|
|
11
|
+
var p = [
|
|
13
12
|
"top",
|
|
14
13
|
"top-start",
|
|
15
14
|
"top-end",
|
|
@@ -22,19 +21,29 @@ var h = [
|
|
|
22
21
|
"right",
|
|
23
22
|
"right-start",
|
|
24
23
|
"right-end"
|
|
25
|
-
],
|
|
24
|
+
], m = [
|
|
26
25
|
"click",
|
|
27
26
|
"hover",
|
|
28
27
|
"manual"
|
|
29
|
-
],
|
|
28
|
+
], h = 0, g = class extends c {
|
|
30
29
|
constructor(...e) {
|
|
31
|
-
super(...e), this.open = !1, this.disabled = !1, this._placement = "bottom", this._offset = 8, this._trigger = "click", this.portal = !1, this._suppressEvent = !1, this._shouldOpenInstantly = !0, this._panelId = `wui-popover-panel-${++
|
|
30
|
+
super(...e), this.open = !1, this.disabled = !1, this._placement = "bottom", this._offset = 8, this._trigger = "click", this.portal = !1, this._suppressEvent = !1, this._shouldOpenInstantly = !0, this._panelId = `wui-popover-panel-${++h}`, this._panel = a().make({
|
|
31
|
+
getAnchor: () => this.shadowRoot?.querySelector(".popover-trigger") ?? null,
|
|
32
|
+
getLocalPanel: () => this.shadowRoot?.querySelector(".popover-panel") ?? null,
|
|
33
|
+
getPositioning: () => ({
|
|
34
|
+
placement: this.placement,
|
|
35
|
+
offset: this.offset,
|
|
36
|
+
strategy: this.portal ? "fixed" : "absolute"
|
|
37
|
+
}),
|
|
38
|
+
isPortal: () => this.portal,
|
|
39
|
+
createPortal: () => this._createPortal()
|
|
40
|
+
}), this._onTriggerClick = (e) => {
|
|
32
41
|
this.disabled || (clearTimeout(this._showTimer), clearTimeout(this._hideTimer), this.trigger !== "hover" && (this.open || (this._shouldOpenInstantly = e.detail === 0), this.toggle()));
|
|
33
42
|
}, this._onClickOutside = (e) => {
|
|
34
|
-
this.open && this.trigger !== "manual" && this.trigger !== "hover" && (e.target instanceof Node && this.
|
|
43
|
+
this.open && this.trigger !== "manual" && this.trigger !== "hover" && (e.target instanceof Node && this.portal && this._panel.getPanel()?.contains(e.target) || this._isInsideShadowRoot(e) || (this.open = !1));
|
|
35
44
|
}, this._onFocusOut = () => {
|
|
36
45
|
this.trigger !== "manual" && this.trigger !== "hover" && requestAnimationFrame(() => {
|
|
37
|
-
this.open && !this.matches(":focus-within") && !this.
|
|
46
|
+
this.open && !this.matches(":focus-within") && !this._panel.getPanel()?.matches(":focus-within") && (this.open = !1);
|
|
38
47
|
});
|
|
39
48
|
}, this._onKeydown = (e) => {
|
|
40
49
|
this.open && this.trigger !== "manual" && e.key === "Escape" && (this.open = !1, e.preventDefault());
|
|
@@ -52,9 +61,9 @@ var h = [
|
|
|
52
61
|
}
|
|
53
62
|
static {
|
|
54
63
|
this.styles = [
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
64
|
+
u(t),
|
|
65
|
+
u(i),
|
|
66
|
+
u(s)
|
|
58
67
|
];
|
|
59
68
|
}
|
|
60
69
|
get placement() {
|
|
@@ -62,7 +71,7 @@ var h = [
|
|
|
62
71
|
}
|
|
63
72
|
set placement(e) {
|
|
64
73
|
let t = this._placement;
|
|
65
|
-
this._placement = n(e,
|
|
74
|
+
this._placement = n(e, p, "bottom"), this.requestUpdate("placement", t);
|
|
66
75
|
}
|
|
67
76
|
get offset() {
|
|
68
77
|
return this._offset;
|
|
@@ -76,7 +85,7 @@ var h = [
|
|
|
76
85
|
}
|
|
77
86
|
set trigger(e) {
|
|
78
87
|
let t = this._trigger;
|
|
79
|
-
this._trigger = n(e,
|
|
88
|
+
this._trigger = n(e, m, "click"), this.requestUpdate("trigger", t);
|
|
80
89
|
}
|
|
81
90
|
get isOpen() {
|
|
82
91
|
return this.open;
|
|
@@ -85,13 +94,13 @@ var h = [
|
|
|
85
94
|
super.connectedCallback(), document.addEventListener("click", this._onClickOutside), document.addEventListener("keydown", this._onKeydown), this.addEventListener("focusout", this._onFocusOut), this._syncTriggerListeners();
|
|
86
95
|
}
|
|
87
96
|
disconnectedCallback() {
|
|
88
|
-
super.disconnectedCallback(), document.removeEventListener("click", this._onClickOutside), document.removeEventListener("keydown", this._onKeydown), this.removeEventListener("focusout", this._onFocusOut), this.removeEventListener("pointerenter", this._onPointerEnter), this.removeEventListener("pointerleave", this._onPointerLeave), clearTimeout(this._showTimer), clearTimeout(this._hideTimer), this.
|
|
97
|
+
super.disconnectedCallback(), document.removeEventListener("click", this._onClickOutside), document.removeEventListener("keydown", this._onKeydown), this.removeEventListener("focusout", this._onFocusOut), this.removeEventListener("pointerenter", this._onPointerEnter), this.removeEventListener("pointerleave", this._onPointerLeave), clearTimeout(this._showTimer), clearTimeout(this._hideTimer), this._panel.dispose();
|
|
89
98
|
}
|
|
90
99
|
firstUpdated() {
|
|
91
|
-
this.
|
|
100
|
+
this.open && (requestAnimationFrame(() => this._openOverlay(this._shouldOpenInstantly)), this._shouldOpenInstantly = !0);
|
|
92
101
|
}
|
|
93
102
|
updated(e) {
|
|
94
|
-
if (
|
|
103
|
+
if (e.has("portal") || e.has("overlayContainer") ? requestAnimationFrame(() => this._reconfigureOverlay()) : (e.has("placement") || e.has("offset")) && requestAnimationFrame(() => this._panel.updatePosition()), e.has("open")) if (this.open) {
|
|
95
104
|
let e = this._shouldOpenInstantly;
|
|
96
105
|
this._shouldOpenInstantly = !0, requestAnimationFrame(() => this._openOverlay(e)), this._dispatchChange(!0), this._focusPanel();
|
|
97
106
|
} else this._returnFocus(), this._closeOverlay(), this._suppressEvent || this._dispatchChange(!1);
|
|
@@ -113,55 +122,23 @@ var h = [
|
|
|
113
122
|
_syncTriggerListeners() {
|
|
114
123
|
this.trigger === "hover" && (this.addEventListener("pointerenter", this._onPointerEnter), this.addEventListener("pointerleave", this._onPointerLeave));
|
|
115
124
|
}
|
|
116
|
-
_initLocalOverlay() {
|
|
117
|
-
let e = this.shadowRoot?.querySelector(".popover-trigger"), t = this.shadowRoot?.querySelector(".popover-panel");
|
|
118
|
-
!e || !t || (this._overlay = s.make({
|
|
119
|
-
anchor: e,
|
|
120
|
-
overlay: t,
|
|
121
|
-
placement: this.placement,
|
|
122
|
-
offset: this.offset
|
|
123
|
-
}));
|
|
124
|
-
}
|
|
125
125
|
_openOverlay(e = !1) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
t && o(t, { isInstant: e });
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
_openPortal(e = !1) {
|
|
134
|
-
if (this._portal) {
|
|
135
|
-
this._overlay?.open(), o(this._portal.panel, { isInstant: e });
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
let n = this.shadowRoot?.querySelector(".popover-trigger");
|
|
139
|
-
if (!n) return;
|
|
140
|
-
let r = c({
|
|
126
|
+
this._panel.open(e);
|
|
127
|
+
}
|
|
128
|
+
_createPortal() {
|
|
129
|
+
let e = o({
|
|
141
130
|
container: this.overlayContainer,
|
|
142
131
|
target: this,
|
|
143
|
-
style: `${t}\n${i}\n${
|
|
132
|
+
style: `${t}\n${i}\n${s}`,
|
|
144
133
|
className: "popover-panel portal wui-glass wui-floating-panel"
|
|
145
134
|
});
|
|
146
|
-
|
|
147
|
-
anchor: n,
|
|
148
|
-
overlay: r.panel,
|
|
149
|
-
placement: this.placement,
|
|
150
|
-
offset: this.offset,
|
|
151
|
-
strategy: "fixed"
|
|
152
|
-
}), this._overlay.open(), o(r.panel, { isInstant: e });
|
|
135
|
+
return e.panel.id = this._panelId, e.panel.setAttribute("role", "dialog"), e.panel.tabIndex = -1, e.panel.addEventListener("pointerenter", this._onPanelPointerEnter), e.panel.addEventListener("pointerleave", this._onPanelPointerLeave), e.moveContent(Array.from(this.childNodes).filter((e) => !(e instanceof HTMLElement && e.slot === "trigger"))), e;
|
|
153
136
|
}
|
|
154
137
|
async _closeOverlay() {
|
|
155
|
-
this.
|
|
156
|
-
let e = this._portal?.panel ?? this.shadowRoot?.querySelector(".popover-panel");
|
|
157
|
-
e && !await a(e) || !this._portal || this.open || (this._portal.restoreContent(), this._portal.remove(), this._portal = void 0, this._overlay = void 0);
|
|
158
|
-
}
|
|
159
|
-
_disposeOverlay() {
|
|
160
|
-
this._overlay?.dispose(), this._overlay = void 0, this._portal?.restoreContent(), this._portal?.remove(), this._portal = void 0;
|
|
138
|
+
await this._panel.close(() => this.open);
|
|
161
139
|
}
|
|
162
140
|
_reconfigureOverlay() {
|
|
163
|
-
|
|
164
|
-
this._disposeOverlay(), this.portal || this._initLocalOverlay(), this.open && this._openOverlay(!e);
|
|
141
|
+
this._panel.reconfigure(this.open);
|
|
165
142
|
}
|
|
166
143
|
_dispatchChange(e) {
|
|
167
144
|
this.dispatchEvent(new CustomEvent("open-change", {
|
|
@@ -172,19 +149,19 @@ var h = [
|
|
|
172
149
|
}
|
|
173
150
|
_focusPanel() {
|
|
174
151
|
requestAnimationFrame(() => {
|
|
175
|
-
let e =
|
|
152
|
+
let e = this._panel.getPanel()?.querySelector("[autofocus]");
|
|
176
153
|
e && !e.matches(":disabled, [disabled]") && e.focus();
|
|
177
154
|
});
|
|
178
155
|
}
|
|
179
156
|
_returnFocus() {
|
|
180
|
-
|
|
157
|
+
this._panel.getPanel()?.matches(":focus-within") && this._queryTrigger()?.focus();
|
|
181
158
|
}
|
|
182
159
|
_queryTrigger() {
|
|
183
160
|
let e = (this.shadowRoot?.querySelector("slot[name=\"trigger\"]"))?.assignedElements()[0];
|
|
184
161
|
return e instanceof HTMLElement ? e : null;
|
|
185
162
|
}
|
|
186
163
|
render() {
|
|
187
|
-
return
|
|
164
|
+
return l`
|
|
188
165
|
<div class="popover-anchor">
|
|
189
166
|
<div
|
|
190
167
|
class="popover-trigger"
|
|
@@ -209,23 +186,23 @@ var h = [
|
|
|
209
186
|
`;
|
|
210
187
|
}
|
|
211
188
|
};
|
|
212
|
-
e([
|
|
189
|
+
e([f({
|
|
213
190
|
type: Boolean,
|
|
214
191
|
reflect: !0
|
|
215
|
-
})],
|
|
192
|
+
})], g.prototype, "open", void 0), e([f({
|
|
216
193
|
type: Boolean,
|
|
217
194
|
reflect: !0
|
|
218
|
-
})],
|
|
195
|
+
})], g.prototype, "disabled", void 0), e([f({
|
|
219
196
|
type: String,
|
|
220
197
|
reflect: !0
|
|
221
|
-
})],
|
|
198
|
+
})], g.prototype, "placement", null), e([f({ type: Number })], g.prototype, "offset", null), e([f({
|
|
222
199
|
type: String,
|
|
223
200
|
reflect: !0
|
|
224
|
-
})],
|
|
201
|
+
})], g.prototype, "trigger", null), e([f({
|
|
225
202
|
type: Boolean,
|
|
226
203
|
reflect: !0
|
|
227
|
-
})],
|
|
204
|
+
})], g.prototype, "portal", void 0), e([f({ attribute: !1 })], g.prototype, "overlayContainer", void 0), g = e([d("web-ui-popover")], g);
|
|
228
205
|
//#endregion
|
|
229
|
-
export {
|
|
206
|
+
export { g as WebUiPopover };
|
|
230
207
|
|
|
231
208
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/popover/index.ts"],"sourcesContent":["import type { Placement } from '@floating-ui/dom'\nimport { html, LitElement, unsafeCSS } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\n\nimport glass from '@/assets/glass.css?inline'\nimport overlayMotion from '@/assets/overlay-motion.css?inline'\nimport { normalizeLiteral, normalizeNumber } from '@/shared/normalize'\nimport { withOverlay } from '@/shared/overlay/overlay'\nimport type { OverlayApi } from '@/shared/overlay/overlay'\nimport { createOverlayPortal } from '@/shared/overlay/portal'\nimport type { OverlayContainer, OverlayPortal } from '@/shared/overlay/portal'\nimport { hideOverlayPresence, showOverlayPresence } from '@/shared/overlay/presence'\n\nimport style from './style.css?inline'\n\nconst ALLOWED_PLACEMENTS = [\n 'top',\n 'top-start',\n 'top-end',\n 'bottom',\n 'bottom-start',\n 'bottom-end',\n 'left',\n 'left-start',\n 'left-end',\n 'right',\n 'right-start',\n 'right-end'\n] as const\n\nconst ALLOWED_TRIGGERS = ['click', 'hover', 'manual'] as const\n\nlet popoverIdCounter = 0\n\n@customElement('web-ui-popover')\nexport class WebUiPopover extends LitElement {\n static override styles = [unsafeCSS(glass), unsafeCSS(overlayMotion), unsafeCSS(style)]\n\n @property({ type: Boolean, reflect: true }) open = false\n @property({ type: Boolean, reflect: true }) disabled = false\n\n @property({ type: String, reflect: true })\n get placement(): Placement {\n return this._placement\n }\n set placement(v: string) {\n const old = this._placement\n this._placement = normalizeLiteral(v, ALLOWED_PLACEMENTS, 'bottom')\n this.requestUpdate('placement', old)\n }\n private _placement: Placement = 'bottom'\n\n @property({ type: Number })\n get offset(): number {\n return this._offset\n }\n set offset(v: number) {\n const old = this._offset\n this._offset = normalizeNumber(v, 0, 100, 8)\n this.requestUpdate('offset', old)\n }\n private _offset = 8\n\n @property({ type: String, reflect: true })\n get trigger(): 'click' | 'hover' | 'manual' {\n return this._trigger\n }\n set trigger(v: string) {\n const old = this._trigger\n this._trigger = normalizeLiteral(v, ALLOWED_TRIGGERS, 'click')\n this.requestUpdate('trigger', old)\n }\n private _trigger: 'click' | 'hover' | 'manual' = 'click'\n\n @property({ type: Boolean, reflect: true }) portal = false\n @property({ attribute: false }) overlayContainer?: OverlayContainer\n\n private _overlay?: OverlayApi & { anchor: HTMLElement; overlay: HTMLElement }\n private _showTimer?: ReturnType<typeof setTimeout>\n private _hideTimer?: ReturnType<typeof setTimeout>\n private _suppressEvent = false\n private _portal?: OverlayPortal\n private _shouldOpenInstantly = true\n\n private _panelId = `wui-popover-panel-${++popoverIdCounter}`\n\n /** 当前是否打开 */\n get isOpen(): boolean {\n return this.open\n }\n\n override connectedCallback() {\n super.connectedCallback()\n document.addEventListener('click', this._onClickOutside)\n document.addEventListener('keydown', this._onKeydown)\n this.addEventListener('focusout', this._onFocusOut)\n this._syncTriggerListeners()\n }\n\n override disconnectedCallback() {\n super.disconnectedCallback()\n document.removeEventListener('click', this._onClickOutside)\n document.removeEventListener('keydown', this._onKeydown)\n this.removeEventListener('focusout', this._onFocusOut)\n this.removeEventListener('pointerenter', this._onPointerEnter)\n this.removeEventListener('pointerleave', this._onPointerLeave)\n clearTimeout(this._showTimer)\n clearTimeout(this._hideTimer)\n this._disposeOverlay()\n }\n\n override firstUpdated() {\n this._initLocalOverlay()\n if (this.open) {\n requestAnimationFrame(() => this._openOverlay(this._shouldOpenInstantly))\n this._shouldOpenInstantly = true\n }\n }\n\n protected override updated(changed: Map<string, unknown>) {\n if (changed.has('placement') || changed.has('portal') || changed.has('overlayContainer'))\n requestAnimationFrame(() => this._reconfigureOverlay())\n\n if (changed.has('open')) {\n if (this.open) {\n const isInstant = this._shouldOpenInstantly\n this._shouldOpenInstantly = true\n requestAnimationFrame(() => this._openOverlay(isInstant))\n this._dispatchChange(true)\n this._focusPanel()\n } else {\n this._returnFocus()\n void this._closeOverlay()\n if (!this._suppressEvent) this._dispatchChange(false)\n }\n }\n\n if (changed.has('trigger')) {\n this.removeEventListener('pointerenter', this._onPointerEnter)\n this.removeEventListener('pointerleave', this._onPointerLeave)\n clearTimeout(this._showTimer)\n clearTimeout(this._hideTimer)\n this._syncTriggerListeners()\n }\n }\n\n /** 打开 popover */\n show() {\n if (this.disabled || this.open) return\n this._suppressEvent = true\n this.open = true\n this._suppressEvent = false\n }\n\n /** 关闭 popover */\n close() {\n if (!this.open) return\n this._suppressEvent = true\n this.open = false\n this._suppressEvent = false\n }\n\n /** 切换 popover */\n toggle() {\n if (this.open) this.close()\n else this.show()\n }\n\n private _isInsideShadowRoot(e: MouseEvent): boolean {\n for (const node of e.composedPath()) {\n if (node instanceof Node && node.getRootNode() === this.shadowRoot) return true\n }\n return false\n }\n\n private _syncTriggerListeners() {\n if (this.trigger === 'hover') {\n this.addEventListener('pointerenter', this._onPointerEnter)\n this.addEventListener('pointerleave', this._onPointerLeave)\n }\n }\n\n private _initLocalOverlay() {\n const anchor = this.shadowRoot?.querySelector<HTMLElement>('.popover-trigger')\n const panel = this.shadowRoot?.querySelector<HTMLElement>('.popover-panel')\n if (!anchor || !panel) return\n this._overlay = withOverlay.make({\n anchor,\n overlay: panel,\n placement: this.placement,\n offset: this.offset\n })\n }\n\n private _openOverlay(isInstant = false) {\n if (this.portal) this._openPortal(isInstant)\n else {\n this._overlay?.open()\n const panel = this.shadowRoot?.querySelector<HTMLElement>('.popover-panel')\n if (panel) showOverlayPresence(panel, { isInstant })\n }\n }\n\n private _openPortal(isInstant = false) {\n if (this._portal) {\n this._overlay?.open()\n showOverlayPresence(this._portal.panel, { isInstant })\n return\n }\n const anchor = this.shadowRoot?.querySelector('.popover-trigger') as HTMLElement | null\n if (!anchor) return\n const portal = createOverlayPortal({\n container: this.overlayContainer,\n target: this,\n style: `${glass}\\n${overlayMotion}\\n${style}`,\n className: 'popover-panel portal wui-glass wui-floating-panel'\n })\n portal.panel.id = this._panelId\n portal.panel.setAttribute('role', 'dialog')\n portal.panel.tabIndex = -1\n portal.panel.addEventListener('pointerenter', this._onPanelPointerEnter)\n portal.panel.addEventListener('pointerleave', this._onPanelPointerLeave)\n portal.moveContent(\n Array.from(this.childNodes).filter(node => !(node instanceof HTMLElement && node.slot === 'trigger'))\n )\n this._portal = portal\n this._overlay = withOverlay.make({\n anchor,\n overlay: portal.panel,\n placement: this.placement,\n offset: this.offset,\n strategy: 'fixed'\n })\n this._overlay.open()\n showOverlayPresence(portal.panel, { isInstant })\n }\n\n private async _closeOverlay() {\n this._overlay?.close()\n const panel = this._portal?.panel ?? this.shadowRoot?.querySelector<HTMLElement>('.popover-panel')\n if (panel && !(await hideOverlayPresence(panel))) return\n if (!this._portal || this.open) return\n this._portal.restoreContent()\n this._portal.remove()\n this._portal = undefined\n this._overlay = undefined\n }\n\n private _disposeOverlay() {\n this._overlay?.dispose()\n this._overlay = undefined\n this._portal?.restoreContent()\n this._portal?.remove()\n this._portal = undefined\n }\n\n private _reconfigureOverlay() {\n const panel = this._portal?.panel ?? this.shadowRoot?.querySelector<HTMLElement>('.popover-panel')\n const shouldAnimate = panel?.dataset.wuiPresence === 'entering'\n this._disposeOverlay()\n if (!this.portal) this._initLocalOverlay()\n // 已稳定显示的面板重新定位不应重播动效;正在入场的指针交互则保持原有动效。\n if (this.open) this._openOverlay(!shouldAnimate)\n }\n\n private _dispatchChange(open: boolean) {\n this.dispatchEvent(\n new CustomEvent('open-change', {\n detail: { open },\n bubbles: true,\n composed: true\n })\n )\n }\n\n private _focusPanel() {\n requestAnimationFrame(() => {\n const panel = this._portal?.panel ?? this.shadowRoot?.querySelector<HTMLElement>('.popover-panel')\n const autofocus = panel?.querySelector<HTMLElement>('[autofocus]')\n if (autofocus && !autofocus.matches(':disabled, [disabled]')) autofocus.focus()\n })\n }\n\n private _returnFocus() {\n const panel = this._portal?.panel ?? this.shadowRoot?.querySelector<HTMLElement>('.popover-panel')\n if (!panel?.matches(':focus-within')) return\n const trigger = this._queryTrigger()\n trigger?.focus()\n }\n\n private _queryTrigger(): HTMLElement | null {\n const slot = this.shadowRoot?.querySelector<HTMLSlotElement>('slot[name=\"trigger\"]')\n const el = slot?.assignedElements()[0]\n return el instanceof HTMLElement ? el : null\n }\n\n private _onTriggerClick = (event: MouseEvent) => {\n if (this.disabled) return\n clearTimeout(this._showTimer)\n clearTimeout(this._hideTimer)\n if (this.trigger === 'hover') return\n if (!this.open) this._shouldOpenInstantly = event.detail === 0\n this.toggle()\n }\n\n private _onClickOutside = (e: MouseEvent) => {\n if (!this.open) return\n if (this.trigger === 'manual' || this.trigger === 'hover') return\n if (e.target instanceof Node && this._portal?.panel.contains(e.target)) return\n if (this._isInsideShadowRoot(e)) return\n this.open = false\n }\n\n private _onFocusOut = () => {\n if (this.trigger === 'manual' || this.trigger === 'hover') return\n\n requestAnimationFrame(() => {\n if (this.open && !this.matches(':focus-within') && !this._portal?.panel.matches(':focus-within')) {\n this.open = false\n }\n })\n }\n\n private _onKeydown = (e: KeyboardEvent) => {\n if (!this.open) return\n if (this.trigger === 'manual') return\n if (e.key === 'Escape') {\n this.open = false\n e.preventDefault()\n }\n }\n\n private _onPointerEnter = (e: PointerEvent) => {\n if (e.pointerType === 'touch') return\n if (this.disabled || this.trigger !== 'hover') return\n clearTimeout(this._hideTimer)\n this._showTimer = setTimeout(() => {\n this._shouldOpenInstantly = false\n this.show()\n }, 100)\n }\n\n private _onPointerLeave = (e: PointerEvent) => {\n if (e.pointerType === 'touch') return\n if (this.disabled || this.trigger !== 'hover') return\n clearTimeout(this._showTimer)\n this._hideTimer = setTimeout(() => this.close(), 100)\n }\n\n private _onPanelPointerEnter = (e: PointerEvent) => {\n if (e.pointerType === 'touch') return\n if (this.trigger !== 'hover') return\n clearTimeout(this._hideTimer)\n }\n\n private _onPanelPointerLeave = (e: PointerEvent) => {\n if (e.pointerType === 'touch') return\n if (this.trigger !== 'hover') return\n this._hideTimer = setTimeout(() => this.close(), 100)\n }\n\n override render() {\n return html`\n <div class=\"popover-anchor\">\n <div\n class=\"popover-trigger\"\n aria-expanded=${String(this.open)}\n aria-controls=${this._panelId}\n @click=${this._onTriggerClick}\n >\n <slot name=\"trigger\"></slot>\n </div>\n <div\n id=${this._panelId}\n class=\"popover-panel wui-glass wui-floating-panel\"\n hidden\n role=\"dialog\"\n tabindex=\"-1\"\n @pointerenter=${this._onPanelPointerEnter}\n @pointerleave=${this._onPanelPointerLeave}\n >\n <slot></slot>\n </div>\n </div>\n `\n }\n\n declare readonly $events: {\n 'open-change': CustomEvent<{ open: boolean }>\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'web-ui-popover': WebUiPopover\n }\n}\n"],"mappings":";;;;;;;;;;;AAeA,IAAM,IA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AM,CAAC,CAAA,GAAA,EAAA,WAAA,oBAAA,KAAA,CAAA,GAzC/B,IAAA,EAAA,CAAA,EAAc,gBAAgB,CAAA,GAAA,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/components/popover/index.ts"],"sourcesContent":["import type { Placement } from '@floating-ui/dom'\nimport { html, LitElement, unsafeCSS } from 'lit'\nimport { customElement, property } from 'lit/decorators.js'\n\nimport glass from '@/assets/glass.css?inline'\nimport overlayMotion from '@/assets/overlay-motion.css?inline'\nimport { normalizeLiteral, normalizeNumber } from '@/shared/normalize'\nimport { defineAnchoredPanel } from '@/shared/overlay/anchored-panel'\nimport { createOverlayPortal } from '@/shared/overlay/portal'\nimport type { OverlayContainer, OverlayPortal } from '@/shared/overlay/portal'\n\nimport style from './style.css?inline'\n\nconst ALLOWED_PLACEMENTS = [\n 'top',\n 'top-start',\n 'top-end',\n 'bottom',\n 'bottom-start',\n 'bottom-end',\n 'left',\n 'left-start',\n 'left-end',\n 'right',\n 'right-start',\n 'right-end'\n] as const\n\nconst ALLOWED_TRIGGERS = ['click', 'hover', 'manual'] as const\n\nlet popoverIdCounter = 0\n\n@customElement('web-ui-popover')\nexport class WebUiPopover extends LitElement {\n static override styles = [unsafeCSS(glass), unsafeCSS(overlayMotion), unsafeCSS(style)]\n\n @property({ type: Boolean, reflect: true }) open = false\n @property({ type: Boolean, reflect: true }) disabled = false\n\n @property({ type: String, reflect: true })\n get placement(): Placement {\n return this._placement\n }\n set placement(v: string) {\n const old = this._placement\n this._placement = normalizeLiteral(v, ALLOWED_PLACEMENTS, 'bottom')\n this.requestUpdate('placement', old)\n }\n private _placement: Placement = 'bottom'\n\n @property({ type: Number })\n get offset(): number {\n return this._offset\n }\n set offset(v: number) {\n const old = this._offset\n this._offset = normalizeNumber(v, 0, 100, 8)\n this.requestUpdate('offset', old)\n }\n private _offset = 8\n\n @property({ type: String, reflect: true })\n get trigger(): 'click' | 'hover' | 'manual' {\n return this._trigger\n }\n set trigger(v: string) {\n const old = this._trigger\n this._trigger = normalizeLiteral(v, ALLOWED_TRIGGERS, 'click')\n this.requestUpdate('trigger', old)\n }\n private _trigger: 'click' | 'hover' | 'manual' = 'click'\n\n @property({ type: Boolean, reflect: true }) portal = false\n @property({ attribute: false }) overlayContainer?: OverlayContainer\n\n private _showTimer?: ReturnType<typeof setTimeout>\n private _hideTimer?: ReturnType<typeof setTimeout>\n private _suppressEvent = false\n private _shouldOpenInstantly = true\n\n private _panelId = `wui-popover-panel-${++popoverIdCounter}`\n private readonly _panel = defineAnchoredPanel().make({\n getAnchor: () => this.shadowRoot?.querySelector<HTMLElement>('.popover-trigger') ?? null,\n getLocalPanel: () => this.shadowRoot?.querySelector<HTMLElement>('.popover-panel') ?? null,\n getPositioning: () => ({\n placement: this.placement,\n offset: this.offset,\n strategy: this.portal ? 'fixed' : 'absolute'\n }),\n isPortal: () => this.portal,\n createPortal: () => this._createPortal()\n })\n\n /** 当前是否打开 */\n get isOpen(): boolean {\n return this.open\n }\n\n override connectedCallback() {\n super.connectedCallback()\n document.addEventListener('click', this._onClickOutside)\n document.addEventListener('keydown', this._onKeydown)\n this.addEventListener('focusout', this._onFocusOut)\n this._syncTriggerListeners()\n }\n\n override disconnectedCallback() {\n super.disconnectedCallback()\n document.removeEventListener('click', this._onClickOutside)\n document.removeEventListener('keydown', this._onKeydown)\n this.removeEventListener('focusout', this._onFocusOut)\n this.removeEventListener('pointerenter', this._onPointerEnter)\n this.removeEventListener('pointerleave', this._onPointerLeave)\n clearTimeout(this._showTimer)\n clearTimeout(this._hideTimer)\n this._panel.dispose()\n }\n\n override firstUpdated() {\n if (this.open) {\n requestAnimationFrame(() => this._openOverlay(this._shouldOpenInstantly))\n this._shouldOpenInstantly = true\n }\n }\n\n protected override updated(changed: Map<string, unknown>) {\n if (changed.has('portal') || changed.has('overlayContainer'))\n requestAnimationFrame(() => this._reconfigureOverlay())\n else if (changed.has('placement') || changed.has('offset'))\n requestAnimationFrame(() => this._panel.updatePosition())\n\n if (changed.has('open')) {\n if (this.open) {\n const isInstant = this._shouldOpenInstantly\n this._shouldOpenInstantly = true\n requestAnimationFrame(() => this._openOverlay(isInstant))\n this._dispatchChange(true)\n this._focusPanel()\n } else {\n this._returnFocus()\n void this._closeOverlay()\n if (!this._suppressEvent) this._dispatchChange(false)\n }\n }\n\n if (changed.has('trigger')) {\n this.removeEventListener('pointerenter', this._onPointerEnter)\n this.removeEventListener('pointerleave', this._onPointerLeave)\n clearTimeout(this._showTimer)\n clearTimeout(this._hideTimer)\n this._syncTriggerListeners()\n }\n }\n\n /** 打开 popover */\n show() {\n if (this.disabled || this.open) return\n this._suppressEvent = true\n this.open = true\n this._suppressEvent = false\n }\n\n /** 关闭 popover */\n close() {\n if (!this.open) return\n this._suppressEvent = true\n this.open = false\n this._suppressEvent = false\n }\n\n /** 切换 popover */\n toggle() {\n if (this.open) this.close()\n else this.show()\n }\n\n private _isInsideShadowRoot(e: MouseEvent): boolean {\n for (const node of e.composedPath()) {\n if (node instanceof Node && node.getRootNode() === this.shadowRoot) return true\n }\n return false\n }\n\n private _syncTriggerListeners() {\n if (this.trigger === 'hover') {\n this.addEventListener('pointerenter', this._onPointerEnter)\n this.addEventListener('pointerleave', this._onPointerLeave)\n }\n }\n\n private _openOverlay(isInstant = false) {\n this._panel.open(isInstant)\n }\n\n private _createPortal(): OverlayPortal {\n const portal = createOverlayPortal({\n container: this.overlayContainer,\n target: this,\n style: `${glass}\\n${overlayMotion}\\n${style}`,\n className: 'popover-panel portal wui-glass wui-floating-panel'\n })\n portal.panel.id = this._panelId\n portal.panel.setAttribute('role', 'dialog')\n portal.panel.tabIndex = -1\n portal.panel.addEventListener('pointerenter', this._onPanelPointerEnter)\n portal.panel.addEventListener('pointerleave', this._onPanelPointerLeave)\n portal.moveContent(\n Array.from(this.childNodes).filter(node => !(node instanceof HTMLElement && node.slot === 'trigger'))\n )\n return portal\n }\n\n private async _closeOverlay() {\n await this._panel.close(() => this.open)\n }\n\n private _reconfigureOverlay() {\n this._panel.reconfigure(this.open)\n }\n\n private _dispatchChange(open: boolean) {\n this.dispatchEvent(\n new CustomEvent('open-change', {\n detail: { open },\n bubbles: true,\n composed: true\n })\n )\n }\n\n private _focusPanel() {\n requestAnimationFrame(() => {\n const panel = this._panel.getPanel()\n const autofocus = panel?.querySelector<HTMLElement>('[autofocus]')\n if (autofocus && !autofocus.matches(':disabled, [disabled]')) autofocus.focus()\n })\n }\n\n private _returnFocus() {\n const panel = this._panel.getPanel()\n if (!panel?.matches(':focus-within')) return\n const trigger = this._queryTrigger()\n trigger?.focus()\n }\n\n private _queryTrigger(): HTMLElement | null {\n const slot = this.shadowRoot?.querySelector<HTMLSlotElement>('slot[name=\"trigger\"]')\n const el = slot?.assignedElements()[0]\n return el instanceof HTMLElement ? el : null\n }\n\n private _onTriggerClick = (event: MouseEvent) => {\n if (this.disabled) return\n clearTimeout(this._showTimer)\n clearTimeout(this._hideTimer)\n if (this.trigger === 'hover') return\n if (!this.open) this._shouldOpenInstantly = event.detail === 0\n this.toggle()\n }\n\n private _onClickOutside = (e: MouseEvent) => {\n if (!this.open) return\n if (this.trigger === 'manual' || this.trigger === 'hover') return\n if (e.target instanceof Node && this.portal && this._panel.getPanel()?.contains(e.target)) return\n if (this._isInsideShadowRoot(e)) return\n this.open = false\n }\n\n private _onFocusOut = () => {\n if (this.trigger === 'manual' || this.trigger === 'hover') return\n\n requestAnimationFrame(() => {\n if (this.open && !this.matches(':focus-within') && !this._panel.getPanel()?.matches(':focus-within')) {\n this.open = false\n }\n })\n }\n\n private _onKeydown = (e: KeyboardEvent) => {\n if (!this.open) return\n if (this.trigger === 'manual') return\n if (e.key === 'Escape') {\n this.open = false\n e.preventDefault()\n }\n }\n\n private _onPointerEnter = (e: PointerEvent) => {\n if (e.pointerType === 'touch') return\n if (this.disabled || this.trigger !== 'hover') return\n clearTimeout(this._hideTimer)\n this._showTimer = setTimeout(() => {\n this._shouldOpenInstantly = false\n this.show()\n }, 100)\n }\n\n private _onPointerLeave = (e: PointerEvent) => {\n if (e.pointerType === 'touch') return\n if (this.disabled || this.trigger !== 'hover') return\n clearTimeout(this._showTimer)\n this._hideTimer = setTimeout(() => this.close(), 100)\n }\n\n private _onPanelPointerEnter = (e: PointerEvent) => {\n if (e.pointerType === 'touch') return\n if (this.trigger !== 'hover') return\n clearTimeout(this._hideTimer)\n }\n\n private _onPanelPointerLeave = (e: PointerEvent) => {\n if (e.pointerType === 'touch') return\n if (this.trigger !== 'hover') return\n this._hideTimer = setTimeout(() => this.close(), 100)\n }\n\n override render() {\n return html`\n <div class=\"popover-anchor\">\n <div\n class=\"popover-trigger\"\n aria-expanded=${String(this.open)}\n aria-controls=${this._panelId}\n @click=${this._onTriggerClick}\n >\n <slot name=\"trigger\"></slot>\n </div>\n <div\n id=${this._panelId}\n class=\"popover-panel wui-glass wui-floating-panel\"\n hidden\n role=\"dialog\"\n tabindex=\"-1\"\n @pointerenter=${this._onPanelPointerEnter}\n @pointerleave=${this._onPanelPointerLeave}\n >\n <slot></slot>\n </div>\n </div>\n `\n }\n\n declare readonly $events: {\n 'open-change': CustomEvent<{ open: boolean }>\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'web-ui-popover': WebUiPopover\n }\n}\n"],"mappings":";;;;;;;;;;AAaA,IAAM,IAAqB;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,GAEM,IAAmB;CAAC;CAAS;CAAS;AAAQ,GAEhD,IAAmB,GAGV,IAAN,cAA2B,EAAW;;EAqRX,aAlRmB,KAAA,OAAA,IACI,KAAA,WAAA,IAWvB,KAAA,aAAA,UAWd,KAAA,UAAA,GAW+B,KAAA,WAAA,SAEI,KAAA,SAAA,IAK5B,KAAA,iBAAA,IACM,KAAA,uBAAA,IAEZ,KAAA,WAAA,qBAAqB,EAAE,KAChB,KAAA,SAAA,EAAoB,CAAC,CAAC,KAAK;GACnD,iBAAiB,KAAK,YAAY,cAA2B,kBAA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
|
disabled: boolean;
|
|
10
10
|
required: boolean;
|
|
11
11
|
portal: boolean;
|
|
12
|
-
|
|
12
|
+
noScrollLock: boolean;
|
|
13
13
|
overlayContainer?: OverlayContainer;
|
|
14
14
|
name: string;
|
|
15
15
|
private _value;
|
|
@@ -21,9 +21,8 @@ export declare class WebUiSelect extends LitElement {
|
|
|
21
21
|
private _selectedLabel;
|
|
22
22
|
private _hasTriggerSlot;
|
|
23
23
|
private _options;
|
|
24
|
-
private
|
|
25
|
-
private
|
|
26
|
-
private _hasScrollLock;
|
|
24
|
+
private readonly _scrollLock;
|
|
25
|
+
private readonly _panel;
|
|
27
26
|
get isOpen(): boolean;
|
|
28
27
|
get open(): boolean;
|
|
29
28
|
private _onClickOutside;
|
|
@@ -57,12 +56,10 @@ export declare class WebUiSelect extends LitElement {
|
|
|
57
56
|
private _notifyValueChange;
|
|
58
57
|
private _syncScrollLock;
|
|
59
58
|
private _togglePopup;
|
|
60
|
-
private _initLocalOverlay;
|
|
61
59
|
private _openOverlay;
|
|
62
60
|
private _getDesiredWidth;
|
|
63
|
-
private
|
|
61
|
+
private _createPortal;
|
|
64
62
|
private _closeOverlay;
|
|
65
|
-
private _disposeOverlay;
|
|
66
63
|
private _reconfigureOverlay;
|
|
67
64
|
render(): import('lit').TemplateResult<1>;
|
|
68
65
|
readonly $events: {
|
|
@@ -2,24 +2,32 @@ import e from "../../_virtual/_@oxc-project_runtime@0.140.0/helpers/esm/decorate
|
|
|
2
2
|
import "../icon/index.js";
|
|
3
3
|
import t from "../../assets/glass.js";
|
|
4
4
|
import n from "../../icons/generated/lucide-chevron-down.js";
|
|
5
|
-
import
|
|
6
|
-
import i from "../../
|
|
7
|
-
import { hideOverlayPresence as a, showOverlayPresence as o } from "../../shared/overlay/presence.js";
|
|
8
|
-
import { lockScroll as s, unlockScroll as c } from "../../shared/scroll-lock/scroll-lock.js";
|
|
9
|
-
import { withOverlay as l } from "../../shared/overlay/overlay.js";
|
|
5
|
+
import r from "../../assets/overlay-motion.js";
|
|
6
|
+
import { createScrollLockLease as i } from "../../shared/scroll-lock/scroll-lock.js";
|
|
10
7
|
import "../option/index.js";
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
8
|
+
import { defineAnchoredPanel as a } from "../../shared/overlay/anchored-panel.js";
|
|
9
|
+
import { createOverlayPortal as o } from "../../shared/overlay/portal.js";
|
|
10
|
+
import s from "./style.js";
|
|
11
|
+
import { LitElement as c, html as l, nothing as u, unsafeCSS as d } from "lit";
|
|
12
|
+
import { customElement as f, property as p, state as m } from "lit/decorators.js";
|
|
15
13
|
//#region src/components/select/index.ts
|
|
16
|
-
var
|
|
14
|
+
var h = class extends c {
|
|
17
15
|
constructor(...e) {
|
|
18
|
-
super(...e), this._formDisabled = !1, this.placeholder = "", this.disabled = !1, this.required = !1, this.portal = !1, this.
|
|
19
|
-
|
|
16
|
+
super(...e), this._formDisabled = !1, this.placeholder = "", this.disabled = !1, this.required = !1, this.portal = !1, this.noScrollLock = !1, this.name = "", this._value = "", this._isOpen = !1, this._activeIndex = -1, this._selectedLabel = "", this._hasTriggerSlot = !1, this._options = [], this._scrollLock = i(), this._panel = a().make({
|
|
17
|
+
getAnchor: () => this.shadowRoot?.querySelector(".select-trigger") ?? null,
|
|
18
|
+
getLocalPanel: () => this.shadowRoot?.querySelector(".select-overlay") ?? null,
|
|
19
|
+
getPositioning: () => ({
|
|
20
|
+
placement: "bottom-start",
|
|
21
|
+
offset: 4,
|
|
22
|
+
strategy: this.portal ? "fixed" : "absolute"
|
|
23
|
+
}),
|
|
24
|
+
isPortal: () => this.portal,
|
|
25
|
+
createPortal: () => this._createPortal()
|
|
26
|
+
}), this._onClickOutside = (e) => {
|
|
27
|
+
this._isOpen && e.target instanceof Node && !this.contains(e.target) && !this._panel.getPanel()?.contains(e.target) && this._close();
|
|
20
28
|
}, this._onFocusOut = () => {
|
|
21
29
|
requestAnimationFrame(() => {
|
|
22
|
-
this._isOpen && !this.matches(":focus-within") && !this.
|
|
30
|
+
this._isOpen && !this.matches(":focus-within") && !this._panel.getPanel()?.matches(":focus-within") && this._close();
|
|
23
31
|
});
|
|
24
32
|
}, this._onTriggerSlotChange = (e) => {
|
|
25
33
|
let t = e.target.assignedElements().length > 0;
|
|
@@ -33,7 +41,7 @@ var y = class extends f {
|
|
|
33
41
|
let t = e.target;
|
|
34
42
|
t.removeEventListener("click", this._handleOptionClick), t.removeEventListener("pointerover", this._handleOptionPointerOver), t.removeEventListener("pointerdown", this._handleOptionPointerDown), t.removeEventListener("option-update", this._onOptionUpdate), this._options = this._options.filter((e) => e !== t);
|
|
35
43
|
}, this._onSlotChange = () => {
|
|
36
|
-
let e = this.
|
|
44
|
+
let e = this.portal && this._panel.getPanel() ? [...this._panel.getPanel().querySelectorAll("web-ui-option")] : [...this.querySelectorAll("web-ui-option")];
|
|
37
45
|
this._options = e, this._ensureOptionIds(), this._syncSelected();
|
|
38
46
|
}, this._handleOptionClick = (e) => {
|
|
39
47
|
if (!(e.currentTarget instanceof HTMLElement)) return;
|
|
@@ -67,9 +75,9 @@ var y = class extends f {
|
|
|
67
75
|
}
|
|
68
76
|
static {
|
|
69
77
|
this.styles = [
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
78
|
+
d(t),
|
|
79
|
+
d(r),
|
|
80
|
+
d(s)
|
|
73
81
|
];
|
|
74
82
|
}
|
|
75
83
|
static {
|
|
@@ -99,18 +107,18 @@ var y = class extends f {
|
|
|
99
107
|
disconnectedCallback() {
|
|
100
108
|
super.disconnectedCallback(), this.removeEventListener("option-register", this._onOptionRegister), this.removeEventListener("option-unregister", this._onOptionUnregister), this.removeEventListener("keydown", this._onKeydown), this.removeEventListener("focusout", this._onFocusOut), document.removeEventListener("click", this._onClickOutside), this._options.forEach((e) => {
|
|
101
109
|
e.removeEventListener("click", this._handleOptionClick), e.removeEventListener("pointerover", this._handleOptionPointerOver), e.removeEventListener("pointerdown", this._handleOptionPointerDown), e.removeEventListener("option-update", this._onOptionUpdate);
|
|
102
|
-
}), this._close(), this.
|
|
110
|
+
}), this._close(), this._panel.dispose(), this._scrollLock.release();
|
|
103
111
|
}
|
|
104
112
|
firstUpdated() {
|
|
105
|
-
|
|
113
|
+
requestAnimationFrame(() => {
|
|
106
114
|
this.isConnected && this._onSlotChange();
|
|
107
115
|
});
|
|
108
116
|
}
|
|
109
117
|
willUpdate() {
|
|
110
|
-
this._options = this.
|
|
118
|
+
this._options = this.portal && this._panel.getPanel() ? [...this._panel.getPanel().querySelectorAll("web-ui-option")] : [...this.querySelectorAll("web-ui-option")], this._ensureOptionIds(), this._syncSelected();
|
|
111
119
|
}
|
|
112
120
|
updated(e) {
|
|
113
|
-
(e.has("portal") || e.has("overlayContainer")) && requestAnimationFrame(() => this._reconfigureOverlay()), e.has("
|
|
121
|
+
(e.has("portal") || e.has("overlayContainer")) && requestAnimationFrame(() => this._reconfigureOverlay()), e.has("noScrollLock") && this._syncScrollLock(), this._syncOpenAttribute(), this._syncValidity();
|
|
114
122
|
}
|
|
115
123
|
formResetCallback() {
|
|
116
124
|
this.value = this.getAttribute("value") || "";
|
|
@@ -179,27 +187,14 @@ var y = class extends f {
|
|
|
179
187
|
}));
|
|
180
188
|
}
|
|
181
189
|
_syncScrollLock(e = this._isOpen) {
|
|
182
|
-
|
|
183
|
-
t !== this._hasScrollLock && (t ? s() : c(), this._hasScrollLock = t);
|
|
190
|
+
this._scrollLock.sync(e && !this.noScrollLock);
|
|
184
191
|
}
|
|
185
192
|
_togglePopup() {
|
|
186
193
|
this._isDisabled || (this._isOpen ? this._close() : this._open());
|
|
187
194
|
}
|
|
188
|
-
_initLocalOverlay() {
|
|
189
|
-
let e = this.shadowRoot?.querySelector(".select-trigger"), t = this.shadowRoot?.querySelector(".select-overlay");
|
|
190
|
-
!e || !t || (this._overlay = l.make({
|
|
191
|
-
anchor: e,
|
|
192
|
-
overlay: t,
|
|
193
|
-
placement: "bottom-start",
|
|
194
|
-
offset: 4
|
|
195
|
-
}));
|
|
196
|
-
}
|
|
197
195
|
_openOverlay(e = !1) {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
let t = this.shadowRoot?.querySelector(".select-overlay");
|
|
201
|
-
t && (t.style.width = `${this._getDesiredWidth()}px`), this._overlay?.open(), t && o(t, { isInstant: e });
|
|
202
|
-
}
|
|
196
|
+
let t = this.portal ? null : this._panel.getPanel();
|
|
197
|
+
t && (t.style.width = `${this._getDesiredWidth()}px`), this._panel.open(e);
|
|
203
198
|
}
|
|
204
199
|
_getDesiredWidth() {
|
|
205
200
|
let e = this.shadowRoot?.querySelector(".select-trigger")?.offsetWidth || 0, t = [...this.querySelectorAll("web-ui-option")], n = 0;
|
|
@@ -208,40 +203,31 @@ var y = class extends f {
|
|
|
208
203
|
t > n && (n = t);
|
|
209
204
|
}), Math.max(120, e, n);
|
|
210
205
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
this._overlay?.open(), o(this._portal.panel, { isInstant: e });
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
let n = this.shadowRoot?.querySelector(".select-trigger");
|
|
217
|
-
if (!n) return;
|
|
218
|
-
let r = this._getDesiredWidth(), a = u({
|
|
206
|
+
_createPortal() {
|
|
207
|
+
let e = this._getDesiredWidth(), n = o({
|
|
219
208
|
container: this.overlayContainer,
|
|
220
209
|
target: this,
|
|
221
|
-
style: `${t}\n${
|
|
210
|
+
style: `${t}\n${r}\n${s}`,
|
|
222
211
|
className: "wui-glass select-overlay portal wui-floating-panel"
|
|
223
212
|
});
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
strategy: "fixed"
|
|
230
|
-
}), this._overlay.open(), o(a.panel, { isInstant: e });
|
|
213
|
+
n.panel.style.width = `${e}px`, n.panel.setAttribute("role", "listbox");
|
|
214
|
+
let i = document.createElement("div");
|
|
215
|
+
i.className = "select-scroll";
|
|
216
|
+
let a = document.createElement("div");
|
|
217
|
+
return a.className = "select-content", i.append(a), n.panel.append(i), n.moveContent(Array.from(this.children), a), n;
|
|
231
218
|
}
|
|
232
219
|
async _closeOverlay() {
|
|
233
|
-
this.
|
|
234
|
-
let e = this._portal?.panel ?? this.shadowRoot?.querySelector(".select-overlay");
|
|
235
|
-
e && !await a(e) || !this._portal || this._isOpen || (this._portal.restoreContent(), this._portal.remove(), this._portal = void 0, this._overlay = void 0);
|
|
236
|
-
}
|
|
237
|
-
_disposeOverlay() {
|
|
238
|
-
this._overlay?.dispose(), this._overlay = void 0, this._portal?.restoreContent(), this._portal?.remove(), this._portal = void 0;
|
|
220
|
+
await this._panel.close(() => this._isOpen);
|
|
239
221
|
}
|
|
240
222
|
_reconfigureOverlay() {
|
|
241
|
-
|
|
223
|
+
if (!this.portal) {
|
|
224
|
+
let e = this._panel.getPanel();
|
|
225
|
+
e && (e.style.width = `${this._getDesiredWidth()}px`);
|
|
226
|
+
}
|
|
227
|
+
this._panel.reconfigure(this._isOpen);
|
|
242
228
|
}
|
|
243
229
|
render() {
|
|
244
|
-
return
|
|
230
|
+
return l`
|
|
245
231
|
<div class="wui-select-inner">
|
|
246
232
|
<div
|
|
247
233
|
class="wui-glass select-trigger"
|
|
@@ -252,40 +238,44 @@ var y = class extends f {
|
|
|
252
238
|
aria-expanded=${this._isOpen}
|
|
253
239
|
aria-haspopup="listbox"
|
|
254
240
|
aria-disabled=${String(this._isDisabled)}
|
|
255
|
-
aria-activedescendant=${this._isOpen && this._activeIndex >= 0 ? this._options[this._activeIndex]?.id :
|
|
241
|
+
aria-activedescendant=${this._isOpen && this._activeIndex >= 0 ? this._options[this._activeIndex]?.id : u}
|
|
256
242
|
>
|
|
257
243
|
<slot name="trigger" @slotchange=${this._onTriggerSlotChange}></slot>
|
|
258
|
-
${this._hasTriggerSlot ?
|
|
244
|
+
${this._hasTriggerSlot ? u : l`<span class="label">${this._selectedLabel}</span>`}
|
|
259
245
|
<web-ui-icon class="arrow" .icon=${n}></web-ui-icon>
|
|
260
246
|
</div>
|
|
261
247
|
<div class="wui-glass select-overlay wui-floating-panel" hidden role="listbox">
|
|
262
|
-
<
|
|
248
|
+
<div class="select-scroll">
|
|
249
|
+
<div class="select-content">
|
|
250
|
+
<slot @slotchange=${this._onSlotChange}></slot>
|
|
251
|
+
</div>
|
|
252
|
+
</div>
|
|
263
253
|
</div>
|
|
264
254
|
</div>
|
|
265
255
|
`;
|
|
266
256
|
}
|
|
267
257
|
};
|
|
268
|
-
e([
|
|
258
|
+
e([m()], h.prototype, "_formDisabled", void 0), e([p({
|
|
269
259
|
type: String,
|
|
270
260
|
reflect: !0
|
|
271
|
-
})],
|
|
261
|
+
})], h.prototype, "placeholder", void 0), e([p({
|
|
272
262
|
type: Boolean,
|
|
273
263
|
reflect: !0
|
|
274
|
-
})],
|
|
264
|
+
})], h.prototype, "disabled", void 0), e([p({
|
|
275
265
|
type: Boolean,
|
|
276
266
|
reflect: !0
|
|
277
|
-
})],
|
|
267
|
+
})], h.prototype, "required", void 0), e([p({
|
|
278
268
|
type: Boolean,
|
|
279
269
|
reflect: !0
|
|
280
|
-
})],
|
|
270
|
+
})], h.prototype, "portal", void 0), e([p({
|
|
271
|
+
type: Boolean,
|
|
281
272
|
reflect: !0,
|
|
282
|
-
attribute: "
|
|
283
|
-
|
|
284
|
-
})], y.prototype, "lockScroll", void 0), e([_({ attribute: !1 })], y.prototype, "overlayContainer", void 0), e([_({
|
|
273
|
+
attribute: "no-scroll-lock"
|
|
274
|
+
})], h.prototype, "noScrollLock", void 0), e([p({ attribute: !1 })], h.prototype, "overlayContainer", void 0), e([p({
|
|
285
275
|
type: String,
|
|
286
276
|
reflect: !0
|
|
287
|
-
})],
|
|
277
|
+
})], h.prototype, "name", void 0), e([m()], h.prototype, "_value", void 0), e([m()], h.prototype, "_isOpen", void 0), e([m()], h.prototype, "_activeIndex", void 0), e([m()], h.prototype, "_selectedLabel", void 0), e([m()], h.prototype, "_hasTriggerSlot", void 0), h = e([f("web-ui-select")], h);
|
|
288
278
|
//#endregion
|
|
289
|
-
export {
|
|
279
|
+
export { h as WebUiSelect };
|
|
290
280
|
|
|
291
281
|
//# sourceMappingURL=index.js.map
|