@greypan/web-ui 6.4.0 → 8.0.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.
Files changed (148) hide show
  1. package/README.CN.md +211 -50
  2. package/README.md +222 -61
  3. package/dist/assets/glass.js +1 -1
  4. package/dist/assets/glass.js.map +1 -1
  5. package/dist/assets/selection-control.js +6 -0
  6. package/dist/assets/selection-control.js.map +1 -0
  7. package/dist/assets/toast-containers.js.map +1 -1
  8. package/dist/components/autocomplete/index.d.ts +19 -5
  9. package/dist/components/autocomplete/index.js +142 -108
  10. package/dist/components/autocomplete/index.js.map +1 -1
  11. package/dist/components/autocomplete/style.js +1 -1
  12. package/dist/components/autocomplete/style.js.map +1 -1
  13. package/dist/components/avatar/index.js +4 -4
  14. package/dist/components/badge/style.js.map +1 -1
  15. package/dist/components/button/index.js +15 -15
  16. package/dist/components/button/style.js.map +1 -1
  17. package/dist/components/button-group/index.js +5 -5
  18. package/dist/components/checkbox/index.d.ts +9 -2
  19. package/dist/components/checkbox/index.js +50 -26
  20. package/dist/components/checkbox/index.js.map +1 -1
  21. package/dist/components/checkbox/style.js +1 -1
  22. package/dist/components/checkbox/style.js.map +1 -1
  23. package/dist/components/checkbox-group/index.d.ts +3 -0
  24. package/dist/components/checkbox-group/index.js +27 -16
  25. package/dist/components/checkbox-group/index.js.map +1 -1
  26. package/dist/components/checkbox-group/style.js +1 -1
  27. package/dist/components/checkbox-group/style.js.map +1 -1
  28. package/dist/components/collapse/index.js.map +1 -1
  29. package/dist/components/context-menu/index.d.ts +10 -0
  30. package/dist/components/context-menu/index.js +51 -34
  31. package/dist/components/context-menu/index.js.map +1 -1
  32. package/dist/components/dialog/index.d.ts +6 -0
  33. package/dist/components/dialog/index.js +49 -21
  34. package/dist/components/dialog/index.js.map +1 -1
  35. package/dist/components/dialog/style.js +1 -1
  36. package/dist/components/dialog/style.js.map +1 -1
  37. package/dist/components/drawer/index.d.ts +22 -4
  38. package/dist/components/drawer/index.js +141 -110
  39. package/dist/components/drawer/index.js.map +1 -1
  40. package/dist/components/drawer/style.js +1 -1
  41. package/dist/components/drawer/style.js.map +1 -1
  42. package/dist/components/dropdown/index.d.ts +21 -1
  43. package/dist/components/dropdown/index.js +77 -51
  44. package/dist/components/dropdown/index.js.map +1 -1
  45. package/dist/components/editable-text/index.d.ts +471 -0
  46. package/dist/components/editable-text/index.js +206 -0
  47. package/dist/components/editable-text/index.js.map +1 -0
  48. package/dist/components/editable-text/style.js +6 -0
  49. package/dist/components/editable-text/style.js.map +1 -0
  50. package/dist/components/image-preview/index.js +103 -80
  51. package/dist/components/image-preview/index.js.map +1 -1
  52. package/dist/components/image-preview/style.js +1 -1
  53. package/dist/components/image-preview/style.js.map +1 -1
  54. package/dist/components/index.d.ts +1 -0
  55. package/dist/components/index.js +39 -38
  56. package/dist/components/input/index.d.ts +2 -0
  57. package/dist/components/input/index.js +12 -6
  58. package/dist/components/input/index.js.map +1 -1
  59. package/dist/components/input/style.js.map +1 -1
  60. package/dist/components/input-number/index.js +15 -15
  61. package/dist/components/layout/index.js +9 -9
  62. package/dist/components/layout/index.js.map +1 -1
  63. package/dist/components/layout/style.js +1 -1
  64. package/dist/components/layout/style.js.map +1 -1
  65. package/dist/components/popover/index.d.ts +8 -2
  66. package/dist/components/popover/index.js +53 -55
  67. package/dist/components/popover/index.js.map +1 -1
  68. package/dist/components/radio/index.d.ts +1 -1
  69. package/dist/components/radio/index.js +22 -21
  70. package/dist/components/radio/index.js.map +1 -1
  71. package/dist/components/radio/style.js +1 -1
  72. package/dist/components/radio/style.js.map +1 -1
  73. package/dist/components/radio-group/index.d.ts +3 -0
  74. package/dist/components/radio-group/index.js +27 -16
  75. package/dist/components/radio-group/index.js.map +1 -1
  76. package/dist/components/radio-group/style.js +1 -1
  77. package/dist/components/radio-group/style.js.map +1 -1
  78. package/dist/components/segmented/index.d.ts +4 -1
  79. package/dist/components/segmented/index.js +42 -29
  80. package/dist/components/segmented/index.js.map +1 -1
  81. package/dist/components/segmented/style.js +1 -1
  82. package/dist/components/segmented/style.js.map +1 -1
  83. package/dist/components/segmented-trigger/style.js +1 -1
  84. package/dist/components/segmented-trigger/style.js.map +1 -1
  85. package/dist/components/select/index.d.ts +2 -0
  86. package/dist/components/select/index.js +38 -34
  87. package/dist/components/select/index.js.map +1 -1
  88. package/dist/components/slider/index.js +11 -11
  89. package/dist/components/slider/index.js.map +1 -1
  90. package/dist/components/slider/style.js +1 -1
  91. package/dist/components/slider/style.js.map +1 -1
  92. package/dist/components/svg-draw-lines/index.d.ts +13 -2
  93. package/dist/components/svg-draw-lines/index.js +44 -31
  94. package/dist/components/svg-draw-lines/index.js.map +1 -1
  95. package/dist/components/switch/index.js +12 -12
  96. package/dist/components/switch/index.js.map +1 -1
  97. package/dist/components/switch/style.js.map +1 -1
  98. package/dist/components/textarea/index.js +6 -6
  99. package/dist/components/textarea/index.js.map +1 -1
  100. package/dist/components/textarea/style.js.map +1 -1
  101. package/dist/components/theme/index.d.ts +15 -0
  102. package/dist/components/theme/index.js +178 -21
  103. package/dist/components/theme/index.js.map +1 -1
  104. package/dist/components/theme/style.js +1 -1
  105. package/dist/components/theme/style.js.map +1 -1
  106. package/dist/components/toast/index.d.ts +1 -1
  107. package/dist/components/toast/manager.d.ts +1 -3
  108. package/dist/components/toast/manager.js +92 -49
  109. package/dist/components/toast/manager.js.map +1 -1
  110. package/dist/components/toast/style.js.map +1 -1
  111. package/dist/components/toast/toast.d.ts +37 -0
  112. package/dist/components/toast/toast.js +74 -21
  113. package/dist/components/toast/toast.js.map +1 -1
  114. package/dist/components/toast/types.d.ts +0 -4
  115. package/dist/components/tooltip/index.d.ts +6 -1
  116. package/dist/components/tooltip/index.js +21 -19
  117. package/dist/components/tooltip/index.js.map +1 -1
  118. package/dist/shared/gesture/drag-gesture.js +66 -64
  119. package/dist/shared/gesture/drag-gesture.js.map +1 -1
  120. package/dist/shared/gesture/physics.js +7 -29
  121. package/dist/shared/gesture/physics.js.map +1 -1
  122. package/dist/shared/menu-behavior/index.js +3 -4
  123. package/dist/shared/menu-behavior/index.js.map +1 -1
  124. package/dist/shared/option-portal/combobox-shell.js +48 -7
  125. package/dist/shared/option-portal/combobox-shell.js.map +1 -1
  126. package/dist/shared/option-portal/index.js +9 -9
  127. package/dist/shared/overlay/anchored-panel.js +36 -31
  128. package/dist/shared/overlay/anchored-panel.js.map +1 -1
  129. package/dist/shared/overlay/native-dialog-presence.js +16 -0
  130. package/dist/shared/overlay/native-dialog-presence.js.map +1 -1
  131. package/dist/shared/overlay/nested-drawer-layers.js +7 -4
  132. package/dist/shared/overlay/nested-drawer-layers.js.map +1 -1
  133. package/dist/shared/overlay/open-overlay.js +198 -0
  134. package/dist/shared/overlay/open-overlay.js.map +1 -0
  135. package/dist/shared/overlay/presence.js +19 -22
  136. package/dist/shared/overlay/presence.js.map +1 -1
  137. package/dist/shared/theme/duration.js +9 -0
  138. package/dist/shared/theme/duration.js.map +1 -0
  139. package/dist/shared/theme/reduced-motion.js +15 -0
  140. package/dist/shared/theme/reduced-motion.js.map +1 -0
  141. package/dist/shared/theme/root-sync.js +42 -0
  142. package/dist/shared/theme/root-sync.js.map +1 -0
  143. package/package.json +1 -1
  144. package/dist/shared/overlay/composition.js +0 -57
  145. package/dist/shared/overlay/composition.js.map +0 -1
  146. package/dist/shared/overlay/lifecycle.js +0 -41
  147. package/dist/shared/overlay/lifecycle.js.map +0 -1
  148. package/dist/vite.svg +0 -1
@@ -373,6 +373,12 @@ declare const WebUiAutocomplete_base: {
373
373
  * 可编辑输入框:`value` 即当前输入文本(表单值),键入时按 `filter` 模式过滤候选,
374
374
  * 选择 option 时文本回填为该项 label,`selected-value` 暴露该项的 value。
375
375
  * `allow-custom-value` 开启后,Enter 可把不匹配候选的原文作为 custom value 显式提交。
376
+ *
377
+ * 触发器跟随 select 的 wrapper div 模式:`slot[name="trigger"]` 可替换默认触发器
378
+ * (shadow 内的 `web-ui-input`);多行触发器(如 `web-ui-textarea`)保留 Enter 换行语义,
379
+ * 关闭面板用 Escape 或 blur。
380
+ * tab 位只属于触发器自身:默认触发器是 shadow 内 input,自定义触发器由消费者提供
381
+ * 可聚焦元素(README 契约);包装 div 恒为 tabindex="-1",不占顺序焦点,避免双 tab 位。
376
382
  */
377
383
  export declare class WebUiAutocomplete extends WebUiAutocomplete_base {
378
384
  static styles: import('lit').CSSResult[];
@@ -403,6 +409,7 @@ export declare class WebUiAutocomplete extends WebUiAutocomplete_base {
403
409
  private _isOpen;
404
410
  private _activeIndex;
405
411
  private _focused;
412
+ private _hasTriggerSlot;
406
413
  private static _nextInstanceId;
407
414
  private readonly _idPrefix;
408
415
  private readonly _a11yOptionIds;
@@ -412,13 +419,19 @@ export declare class WebUiAutocomplete extends WebUiAutocomplete_base {
412
419
  private _portalContent?;
413
420
  private readonly _scrollLock;
414
421
  private readonly _optionPortal;
422
+ private readonly _trigger;
423
+ private readonly _overlay;
415
424
  private readonly _panel;
416
425
  get isOpen(): boolean;
417
426
  get open(): boolean;
427
+ focus(options?: FocusOptions): void;
428
+ blur(): void;
418
429
  private _onClickOutside;
419
430
  private _onFocusOut;
420
431
  private _handlePanelPointerDown;
421
432
  connectedCallback(): void;
433
+ private _onTriggerSlotChange;
434
+ private _syncTriggerSlot;
422
435
  attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
423
436
  disconnectedCallback(): void;
424
437
  firstUpdated(): void;
@@ -427,6 +440,7 @@ export declare class WebUiAutocomplete extends WebUiAutocomplete_base {
427
440
  formDisabledCallback(disabled: boolean): void;
428
441
  private _syncValidity;
429
442
  private _syncOpenAttribute;
443
+ private _syncOverlayInert;
430
444
  private _syncSelectedValue;
431
445
  private _syncOptionA11y;
432
446
  private _getA11yOptionId;
@@ -449,11 +463,11 @@ export declare class WebUiAutocomplete extends WebUiAutocomplete_base {
449
463
  private _findExactOption;
450
464
  private _hasExactOption;
451
465
  private _selectCustomValue;
452
- private _onInput;
453
- private _onInnerChange;
454
- private _onFocus;
455
- private _onInputClick;
456
- private _onBlur;
466
+ private _onTriggerInput;
467
+ private _onTriggerClick;
468
+ private _onTriggerFocusIn;
469
+ private _onTriggerFocusOut;
470
+ private _isSlottedFocus;
457
471
  private readonly _openController;
458
472
  private _open;
459
473
  private _close;
@@ -1,32 +1,36 @@
1
1
  import e from "../../_virtual/_@oxc-project_runtime@0.149.0/helpers/esm/decorate.js";
2
- import "../option/index.js";
3
2
  import t from "../../assets/glass.js";
4
- import n from "../../assets/overlay-motion.js";
3
+ import { normalizeLiteral as n } from "../../shared/normalize/index.js";
5
4
  import { FormAssociated as r, FormAssociationController as i, defineFormAssociation as a } from "../../shared/form-association/index.js";
6
- import { normalizeLiteral as o } from "../../shared/normalize/index.js";
5
+ import "../input/index.js";
6
+ import "../option/index.js";
7
+ import o from "../../assets/overlay-motion.js";
7
8
  import { dispatchOpenChangeEvent as s } from "../../shared/open-state/index.js";
8
- import { overlayComposition as c } from "../../shared/overlay/composition.js";
9
- import { createComboboxOpenController as l, createOptionListenerBinding as u, handleComboboxFocusOut as d, nextWrappingIndex as f } from "../../shared/option-portal/combobox-shell.js";
9
+ import { createComboboxOpenController as c, createOptionListenerBinding as l, defineComboboxTrigger as u, handleComboboxFocusOut as d, nextWrappingIndex as f } from "../../shared/option-portal/combobox-shell.js";
10
10
  import { defineOptionPortal as p } from "../../shared/option-portal/index.js";
11
11
  import { defineAnchoredPanel as m } from "../../shared/overlay/anchored-panel.js";
12
- import { applyOverlayVariables as h, defineOverlayPortal as g } from "../../shared/overlay/portal.js";
13
- import { defineScrollLockLease as _ } from "../../shared/scroll-lock/scroll-lock.js";
14
- import v from "./style.js";
15
- import { LitElement as y, html as b, nothing as x, unsafeCSS as S } from "lit";
16
- import { customElement as C, property as w, state as T } from "lit/decorators.js";
17
- import { ifDefined as E } from "lit/directives/if-defined.js";
12
+ import { defineOpenOverlay as h } from "../../shared/overlay/open-overlay.js";
13
+ import { applyOverlayVariables as g, defineOverlayPortal as _ } from "../../shared/overlay/portal.js";
14
+ import { defineScrollLockLease as v } from "../../shared/scroll-lock/scroll-lock.js";
15
+ import y from "./style.js";
16
+ import { LitElement as b, html as x, nothing as S, unsafeCSS as C } from "lit";
17
+ import { customElement as w, property as T, state as E } from "lit/decorators.js";
18
+ import { ifDefined as D } from "lit/directives/if-defined.js";
18
19
  //#region src/components/autocomplete/index.ts
19
- var D, O = [
20
+ var O, k = [
20
21
  "none",
21
22
  "prefix",
22
23
  "contains"
23
24
  ];
24
- function k(e) {
25
+ function A(e) {
25
26
  return e instanceof Element && e.getAttribute("slot") === "empty";
26
27
  }
27
- var A = class extends r(y) {
28
+ function j(e) {
29
+ return e instanceof Element && e.slot === "trigger";
30
+ }
31
+ var M = class extends r(b) {
28
32
  static {
29
- D = this;
33
+ O = this;
30
34
  }
31
35
  constructor(...e) {
32
36
  super(...e), this.placeholder = "", this.borderless = !1, this.disabled = !1, this.readonly = !1, this.required = !1, this.portal = !1, this.noScrollLock = !1, this.allowCustomValue = !1, this.name = "", this.ariaLabel = null, this._filter = "contains", this._value = "", this._selectedValue = "", this._formAssociation = a({
@@ -45,19 +49,33 @@ var A = class extends r(y) {
45
49
  typeof e == "string" && (this.value = e);
46
50
  },
47
51
  syncValidity: () => this._syncValidity()
48
- }).make(), this._formAssociationController = new i(this, this._formAssociation), this._isOpen = !1, this._activeIndex = -1, this._focused = !1, this._idPrefix = `web-ui-autocomplete-${++D._nextInstanceId}`, this._a11yOptionIds = /* @__PURE__ */ new WeakMap(), this._nextA11yOptionId = 0, this._options = [], this._scrollLock = _().make(), this._optionPortal = p().make({
52
+ }).make(), this._formAssociationController = new i(this, this._formAssociation), this._isOpen = !1, this._activeIndex = -1, this._focused = !1, this._hasTriggerSlot = !1, this._idPrefix = `web-ui-autocomplete-${++O._nextInstanceId}`, this._a11yOptionIds = /* @__PURE__ */ new WeakMap(), this._nextA11yOptionId = 0, this._options = [], this._scrollLock = v().make(), this._optionPortal = p().make({
49
53
  element: this,
50
54
  idPrefix: `${this._idPrefix}-option`,
51
55
  getPortal: () => this._portal,
52
56
  getPortalContent: () => this._portalContent,
53
57
  isOpen: () => this.portal && this._isOpen,
54
- getMigratableNodes: () => Array.from(this.childNodes).filter((e) => !k(e)),
58
+ getMigratableNodes: () => Array.from(this.childNodes).filter((e) => !A(e) && !j(e)),
55
59
  hasUpdated: () => this.hasUpdated,
56
60
  requestUpdate: () => this.requestUpdate(),
57
61
  bindOption: (e) => this._bindOption(e),
58
62
  unbindOption: (e) => this._unbindOption(e)
63
+ }), this._trigger = u().make({
64
+ getWrapper: () => this.shadowRoot?.querySelector(".autocomplete-trigger") ?? null,
65
+ getCustomTrigger: () => {
66
+ let e = this.shadowRoot?.querySelector("slot[name=\"trigger\"]")?.assignedElements()[0];
67
+ return e instanceof HTMLElement ? e : null;
68
+ },
69
+ getFallbackTrigger: () => this.shadowRoot?.querySelector(".autocomplete-input") ?? null,
70
+ onInput: (e) => this._onTriggerInput(e),
71
+ onClick: () => this._onTriggerClick(),
72
+ onFocusIn: (e) => this._onTriggerFocusIn(e),
73
+ onFocusOut: (e) => this._onTriggerFocusOut(e)
74
+ }), this._overlay = h().make({
75
+ requestClose: () => this._close(),
76
+ isConnected: () => this.isConnected
59
77
  }), this._panel = m().make({
60
- getAnchor: () => this.shadowRoot?.querySelector(".input-wrapper") ?? null,
78
+ getAnchor: () => this._trigger.getTrigger() ?? this.shadowRoot?.querySelector(".autocomplete-trigger") ?? null,
61
79
  getLocalPanel: () => this.shadowRoot?.querySelector(".autocomplete-overlay") ?? null,
62
80
  getPositioning: () => ({
63
81
  placement: "bottom-start",
@@ -66,16 +84,17 @@ var A = class extends r(y) {
66
84
  strategy: this.portal ? "fixed" : "absolute"
67
85
  }),
68
86
  isPortal: () => this.portal,
69
- createPortal: () => this._createPortal()
87
+ createPortal: () => this._createPortal(),
88
+ openOverlay: this._overlay
70
89
  }), this._onClickOutside = (e) => {
71
- if (!this._isOpen) return;
72
- let t = e.composedPath(), n = this._panel.getPanel();
73
- !t.includes(this) && !(n && c.containsEvent(n, e)) && this._close();
90
+ this._isOpen && (e.composedPath().includes(this) || this._panel.getHandle()?.containsEvent(e) || this._close());
74
91
  }, this._onFocusOut = () => {
75
- d(this, () => this._panel.getPanel(), () => this._isOpen, () => this._close());
92
+ d(this, () => this._panel.getHandle(), () => this._isOpen, () => this._close());
76
93
  }, this._handlePanelPointerDown = (e) => {
77
94
  e.preventDefault();
78
- }, this._optionListeners = u({
95
+ }, this._onTriggerSlotChange = () => {
96
+ this._syncTriggerSlot();
97
+ }, this._optionListeners = l({
79
98
  onClick: (e) => this._handleOptionClick(e),
80
99
  onPointerOver: (e) => this._handleOptionPointerOver(e),
81
100
  onPointerDown: (e) => this._handleOptionPointerDown(e),
@@ -94,16 +113,12 @@ var A = class extends r(y) {
94
113
  this._optionPortal.scheduleRefresh();
95
114
  }, this._onKeydown = (e) => {
96
115
  if (!(this._isDisabled || this.readonly)) switch (e.key) {
97
- case "Escape":
98
- this._isOpen && (this._close(), e.preventDefault());
99
- break;
100
116
  case "ArrowDown":
101
- e.preventDefault(), this._isOpen ? this._navigateActive(1) : this._open(!0);
102
- break;
103
117
  case "ArrowUp":
104
- e.preventDefault(), this._isOpen ? this._navigateActive(-1) : this._open(!0);
118
+ if (this._isOpen && this._trigger.isMultilineEdit(e)) break;
119
+ e.preventDefault(), this._isOpen ? this._navigateActive(e.key === "ArrowDown" ? 1 : -1) : this._open(!0);
105
120
  break;
106
- case "Enter": if (this._isOpen) {
121
+ case "Enter": if (this._isOpen && !this._trigger.isMultilineEdit(e)) {
107
122
  e.preventDefault();
108
123
  let t = this._options[this._activeIndex];
109
124
  if (t && !t.disabled && !t.hasAttribute("data-filtered")) {
@@ -118,19 +133,21 @@ var A = class extends r(y) {
118
133
  this.allowCustomValue && this._value && !this._hasExactOption(this._value) && this._selectCustomValue();
119
134
  }
120
135
  }
121
- }, this._onInput = (e) => {
122
- if (this._isDisabled || this.readonly) return;
123
- let t = e.target;
124
- t.value !== this._value && (this.value = t.value, this._activeIndex = -1, this._syncActiveOption(), this._isOpen || this._open());
125
- }, this._onInnerChange = (e) => {
126
- e.stopPropagation();
127
- }, this._onFocus = () => {
128
- this._isDisabled || (this._focused = !0);
129
- }, this._onInputClick = () => {
136
+ }, this._onTriggerInput = (e) => {
137
+ this._isDisabled || this.readonly || e !== this._value && (this.value = e, this._activeIndex = -1, this._syncActiveOption(), this._isOpen || this._open());
138
+ }, this._onTriggerClick = () => {
130
139
  this._isDisabled || this.readonly || this._options.length > 0 && this._open();
131
- }, this._onBlur = () => {
132
- this._focused = !1;
133
- }, this._openController = l({
140
+ }, this._onTriggerFocusIn = (e) => {
141
+ this._isDisabled || (this._focused = !0, this._isSlottedFocus(e) && this.dispatchEvent(new FocusEvent("focus", {
142
+ composed: !0,
143
+ relatedTarget: e.relatedTarget
144
+ })));
145
+ }, this._onTriggerFocusOut = (e) => {
146
+ this._focused = !1, this._isSlottedFocus(e) && this.dispatchEvent(new FocusEvent("blur", {
147
+ composed: !0,
148
+ relatedTarget: e.relatedTarget
149
+ }));
150
+ }, this._openController = c({
134
151
  canOpen: () => !this._isDisabled && !this.readonly,
135
152
  getIsOpen: () => this._isOpen,
136
153
  setIsOpen: (e) => {
@@ -154,9 +171,9 @@ var A = class extends r(y) {
154
171
  }
155
172
  static {
156
173
  this.styles = [
157
- S(t),
158
- S(n),
159
- S(v)
174
+ C(t),
175
+ C(o),
176
+ C(y)
160
177
  ];
161
178
  }
162
179
  get filter() {
@@ -164,7 +181,7 @@ var A = class extends r(y) {
164
181
  }
165
182
  set filter(e) {
166
183
  let t = this._filter;
167
- this._filter = o(e, O, "contains"), this.requestUpdate("filter", t);
184
+ this._filter = n(e, k, "contains"), this.requestUpdate("filter", t);
168
185
  }
169
186
  get value() {
170
187
  return this._value;
@@ -192,8 +209,18 @@ var A = class extends r(y) {
192
209
  get open() {
193
210
  return this._isOpen;
194
211
  }
212
+ focus(e) {
213
+ this._trigger.focusTrigger(e);
214
+ }
215
+ blur() {
216
+ this._trigger.blurTrigger();
217
+ }
195
218
  connectedCallback() {
196
- super.connectedCallback(), this._optionPortal.bindHost(), this.addEventListener("keydown", this._onKeydown), this.addEventListener("focusout", this._onFocusOut), document.addEventListener("click", this._onClickOutside);
219
+ super.connectedCallback(), this._optionPortal.bindHost(), this._trigger.bind(), this.addEventListener("keydown", this._onKeydown), this.addEventListener("focusout", this._onFocusOut), document.addEventListener("click", this._onClickOutside);
220
+ }
221
+ _syncTriggerSlot() {
222
+ let e = Array.from(this.children).some(j);
223
+ this._hasTriggerSlot !== e && (this._hasTriggerSlot = e, this.hasUpdated && this._reconfigureOverlay());
197
224
  }
198
225
  attributeChangedCallback(e, t, n) {
199
226
  super.attributeChangedCallback(e, t, n), e === "selected-value" && this.isConnected && n !== this._selectedValue && queueMicrotask(() => {
@@ -201,19 +228,18 @@ var A = class extends r(y) {
201
228
  });
202
229
  }
203
230
  disconnectedCallback() {
204
- super.disconnectedCallback(), this._optionPortal.dispose(), this.removeEventListener("keydown", this._onKeydown), this.removeEventListener("focusout", this._onFocusOut), document.removeEventListener("click", this._onClickOutside), this._options.forEach(this._unbindOption), this._close(), this._portal = void 0, this._portalContent = void 0, this._panel.dispose(), this._scrollLock.release();
231
+ super.disconnectedCallback(), this._optionPortal.dispose(), this._trigger.dispose(), this.removeEventListener("keydown", this._onKeydown), this.removeEventListener("focusout", this._onFocusOut), document.removeEventListener("click", this._onClickOutside), this._options.forEach(this._unbindOption), this._close(), this._portal = void 0, this._portalContent = void 0, this._panel.dispose(), this._scrollLock.release();
205
232
  }
206
233
  firstUpdated() {
207
- requestAnimationFrame(() => {
234
+ this._trigger.bind(), requestAnimationFrame(() => {
208
235
  this.isConnected && this._optionPortal.scheduleRefresh();
209
236
  });
210
237
  }
211
238
  willUpdate() {
212
- this._refreshOptions(), this._optionPortal.ensureOptionIds(this._options), this._syncSelectedValue(), this._applyFilter(), this._syncOptionA11y(), this._syncActiveOption();
239
+ this._syncTriggerSlot(), this._refreshOptions(), this._optionPortal.ensureOptionIds(this._options), this._syncSelectedValue(), this._applyFilter(), this._syncOptionA11y(), this._syncActiveOption();
213
240
  }
214
241
  updated(e) {
215
- let t = this.shadowRoot?.querySelector(".autocomplete-input");
216
- t && t.value !== this._value && (t.value = this._value), (e.has("portal") || e.has("overlayContainer")) && requestAnimationFrame(() => this._reconfigureOverlay()), e.has("noScrollLock") && this._syncScrollLock(), this.toggleAttribute("focused", this._focused), this._syncOpenAttribute(), this._syncValidity(), this._syncEmptyState();
242
+ this._trigger.setValue(this._value), (e.has("portal") || e.has("overlayContainer")) && requestAnimationFrame(() => this._reconfigureOverlay()), e.has("noScrollLock") && this._syncScrollLock(), this.toggleAttribute("focused", this._focused), this._syncOpenAttribute(), this._syncOverlayInert(), this._syncValidity(), this._syncEmptyState();
217
243
  }
218
244
  formDisabledCallback(e) {
219
245
  this._formAssociation.setDisabled(e), e && this._isOpen && this._close();
@@ -225,6 +251,9 @@ var A = class extends r(y) {
225
251
  _syncOpenAttribute() {
226
252
  this.toggleAttribute("open", this._isOpen);
227
253
  }
254
+ _syncOverlayInert() {
255
+ this._panel.getHandle()?.setInert(this._isDisabled || this.readonly);
256
+ }
228
257
  _syncSelectedValue() {
229
258
  let e = this._value.trim().toLowerCase(), t = e ? this._options.find((t) => !t.disabled && t.label.trim().toLowerCase() === e)?.value ?? "" : "";
230
259
  this._setSelectedValue(t);
@@ -296,6 +325,10 @@ var A = class extends r(y) {
296
325
  composed: !0
297
326
  }));
298
327
  }
328
+ _isSlottedFocus(e) {
329
+ let t = e.target;
330
+ return t instanceof Node && !!this.shadowRoot && !this.shadowRoot.contains(t);
331
+ }
299
332
  _open(e = !1) {
300
333
  this._openController.open(e);
301
334
  }
@@ -306,26 +339,26 @@ var A = class extends r(y) {
306
339
  s(this, this._isOpen);
307
340
  }
308
341
  _openOverlay(e = !1) {
309
- this._panel.open(e), this._syncEmptyState();
342
+ this._panel.open(e), this._syncOverlayInert(), this._syncEmptyState();
310
343
  }
311
344
  async _closeOverlay() {
312
345
  await this._panel.close(() => this._isOpen) && (this._portal = void 0, this._portalContent = void 0);
313
346
  }
314
347
  _reconfigureOverlay() {
315
- this._portal = void 0, this._portalContent = void 0, this._panel.reconfigure(this._isOpen);
348
+ this._portal = void 0, this._portalContent = void 0, this._panel.reconfigure(this._isOpen), this._syncOverlayInert();
316
349
  }
317
350
  _syncScrollLock(e = this._isOpen) {
318
351
  this._scrollLock.sync(e && !this.noScrollLock);
319
352
  }
320
353
  _createPortal() {
321
- let e = g().make({
354
+ let e = _().make({
322
355
  container: this.overlayContainer,
323
356
  target: this,
324
- style: `${t}\n${n}\n${v}`,
357
+ style: `${t}\n${o}\n${y}`,
325
358
  className: "wui-glass autocomplete-overlay portal wui-floating-panel",
326
359
  onContentChange: (e) => {
327
360
  this._optionPortal.scheduleRefresh();
328
- let t = e.flatMap((e) => [...e.removedNodes]).filter(k);
361
+ let t = e.flatMap((e) => [...e.removedNodes]).filter(A);
329
362
  if (t.length) {
330
363
  this._portal?.removeContent(t);
331
364
  let e = this._portal?.panel.querySelector(".autocomplete-empty");
@@ -333,18 +366,18 @@ var A = class extends r(y) {
333
366
  }
334
367
  }
335
368
  });
336
- this._portal = e, h(e.panel, this, [
369
+ this._portal = e, g(e.panel, this, [
337
370
  "--wui-overlay-min-width",
338
371
  "--wui-autocomplete-max-width",
339
372
  "--wui-autocomplete-max-height"
340
373
  ]), e.panel.setAttribute("aria-hidden", "true"), e.panel.addEventListener("pointerdown", this._handlePanelPointerDown);
374
+ let n = document.createElement("div");
375
+ n.className = "autocomplete-scroll";
341
376
  let r = document.createElement("div");
342
- r.className = "autocomplete-scroll";
377
+ r.className = "autocomplete-content", this._portalContent = r;
343
378
  let i = document.createElement("div");
344
- i.className = "autocomplete-content", this._portalContent = i;
345
- let a = document.createElement("div");
346
- a.className = "autocomplete-empty", a.hidden = !0, a.dataset.wuiA11yEmpty = this._getEmptySlotText(), r.append(i), i.append(a), e.panel.append(r);
347
- for (let t of Array.from(this.childNodes)) t instanceof Comment || (k(t) ? e.appendContent([t], a) : e.appendContent([t], i));
379
+ i.className = "autocomplete-empty", i.hidden = !0, i.dataset.wuiA11yEmpty = this._getEmptySlotText(), n.append(r), r.append(i), e.panel.append(n);
380
+ for (let t of Array.from(this.childNodes)) t instanceof Comment || j(t) || (A(t) ? e.appendContent([t], i) : e.appendContent([t], r));
348
381
  return e;
349
382
  }
350
383
  _getLabelledbyText() {
@@ -359,36 +392,37 @@ var A = class extends r(y) {
359
392
  return (this.shadowRoot?.querySelector("slot[name=\"empty\"]"))?.assignedElements().map((e) => e.textContent?.trim()).filter(Boolean).join(" ").trim() || "无匹配选项";
360
393
  }
361
394
  render() {
362
- let e = `${this._idPrefix}-listbox`, t = `${this._idPrefix}-label`, n = this._getLabelledbyText(), r = this._options.filter((e) => !e.hasAttribute("data-filtered")), i = this._isOpen && this._activeIndex >= 0 ? this._options[this._activeIndex] : void 0, a = i ? this._getA11yOptionId(i) : x;
363
- return b`
395
+ let e = `${this._idPrefix}-listbox`, t = `${this._idPrefix}-label`, n = this._getLabelledbyText(), r = this._options.filter((e) => !e.hasAttribute("data-filtered")), i = this._isOpen && this._activeIndex >= 0 ? this._options[this._activeIndex] : void 0, a = i ? this._getA11yOptionId(i) : S;
396
+ return x`
364
397
  <div class="wui-autocomplete-inner">
365
- ${n ? b`<span class="autocomplete-a11y-only" id=${t}>${n}</span>` : x}
366
- <div class="wui-glass input-wrapper">
367
- <input
368
- class="autocomplete-input"
369
- type="text"
370
- placeholder=${this.placeholder}
371
- name=${this.name}
372
- .value=${this._value}
373
- aria-label=${E(this.ariaLabel)}
374
- aria-labelledby=${n ? t : x}
375
- ?disabled=${this._isDisabled}
376
- ?readonly=${this.readonly}
377
- ?required=${this.required}
378
- role="combobox"
379
- aria-expanded=${this._isOpen}
380
- aria-haspopup="listbox"
381
- aria-autocomplete="list"
382
- aria-controls=${e}
383
- aria-disabled=${String(this._isDisabled)}
384
- aria-readonly=${this.readonly ? "true" : x}
385
- aria-activedescendant=${a}
386
- @input=${this._onInput}
387
- @change=${this._onInnerChange}
388
- @click=${this._onInputClick}
389
- @focus=${this._onFocus}
390
- @blur=${this._onBlur}
391
- />
398
+ ${n ? x`<span class="autocomplete-a11y-only" id=${t}>${n}</span>` : S}
399
+ <div
400
+ class="autocomplete-trigger"
401
+ ?data-custom-trigger=${this._hasTriggerSlot}
402
+ role="combobox"
403
+ aria-expanded=${this._isOpen}
404
+ aria-haspopup="listbox"
405
+ aria-autocomplete="list"
406
+ aria-controls=${e}
407
+ aria-disabled=${String(this._isDisabled)}
408
+ aria-readonly=${this.readonly ? "true" : S}
409
+ aria-label=${D(this.ariaLabel)}
410
+ aria-labelledby=${n ? t : S}
411
+ aria-activedescendant=${a}
412
+ tabindex="-1"
413
+ >
414
+ <slot name="trigger" @slotchange=${this._onTriggerSlotChange}></slot>
415
+ ${this._hasTriggerSlot ? S : x`<web-ui-input
416
+ class="autocomplete-input"
417
+ .value=${this._value}
418
+ placeholder=${this.placeholder}
419
+ name=${this.name}
420
+ ?borderless=${this.borderless}
421
+ ?disabled=${this._isDisabled}
422
+ ?readonly=${this.readonly}
423
+ ?required=${this.required}
424
+ aria-label=${D(this.ariaLabel || n || void 0)}
425
+ ></web-ui-input>`}
392
426
  </div>
393
427
  <div
394
428
  class="autocomplete-a11y-listbox"
@@ -397,7 +431,7 @@ var A = class extends r(y) {
397
431
  ?hidden=${!this._isOpen}
398
432
  aria-hidden=${String(!this._isOpen)}
399
433
  >
400
- ${r.map((e) => b`<div
434
+ ${r.map((e) => x`<div
401
435
  id=${this._getA11yOptionId(e)}
402
436
  role="option"
403
437
  aria-selected=${e.value === this._selectedValue ? "true" : "false"}
@@ -427,46 +461,46 @@ var A = class extends r(y) {
427
461
  `;
428
462
  }
429
463
  };
430
- e([w({
464
+ e([T({
431
465
  type: String,
432
466
  reflect: !0
433
- })], A.prototype, "placeholder", void 0), e([w({
467
+ })], M.prototype, "placeholder", void 0), e([T({
434
468
  type: Boolean,
435
469
  reflect: !0
436
- })], A.prototype, "borderless", void 0), e([w({
470
+ })], M.prototype, "borderless", void 0), e([T({
437
471
  type: Boolean,
438
472
  reflect: !0
439
- })], A.prototype, "disabled", void 0), e([w({
473
+ })], M.prototype, "disabled", void 0), e([T({
440
474
  type: Boolean,
441
475
  reflect: !0
442
- })], A.prototype, "readonly", void 0), e([w({
476
+ })], M.prototype, "readonly", void 0), e([T({
443
477
  type: Boolean,
444
478
  reflect: !0
445
- })], A.prototype, "required", void 0), e([w({
479
+ })], M.prototype, "required", void 0), e([T({
446
480
  type: Boolean,
447
481
  reflect: !0
448
- })], A.prototype, "portal", void 0), e([w({
482
+ })], M.prototype, "portal", void 0), e([T({
449
483
  type: Boolean,
450
484
  reflect: !0,
451
485
  attribute: "no-scroll-lock"
452
- })], A.prototype, "noScrollLock", void 0), e([w({
486
+ })], M.prototype, "noScrollLock", void 0), e([T({
453
487
  type: Boolean,
454
488
  reflect: !0,
455
489
  attribute: "allow-custom-value"
456
- })], A.prototype, "allowCustomValue", void 0), e([w({ attribute: !1 })], A.prototype, "overlayContainer", void 0), e([w({
490
+ })], M.prototype, "allowCustomValue", void 0), e([T({ attribute: !1 })], M.prototype, "overlayContainer", void 0), e([T({
457
491
  type: String,
458
492
  reflect: !0
459
- })], A.prototype, "name", void 0), e([w({
493
+ })], M.prototype, "name", void 0), e([T({
460
494
  type: String,
461
495
  attribute: "aria-label"
462
- })], A.prototype, "ariaLabel", void 0), e([w({
496
+ })], M.prototype, "ariaLabel", void 0), e([T({
463
497
  type: String,
464
498
  attribute: "aria-labelledby"
465
- })], A.prototype, "ariaLabelledby", void 0), e([w({
499
+ })], M.prototype, "ariaLabelledby", void 0), e([T({
466
500
  type: String,
467
501
  reflect: !0
468
- })], A.prototype, "filter", null), e([T()], A.prototype, "_value", void 0), e([T()], A.prototype, "_selectedValue", void 0), e([T()], A.prototype, "_isOpen", void 0), e([T()], A.prototype, "_activeIndex", void 0), e([T()], A.prototype, "_focused", void 0), A = D = e([C("web-ui-autocomplete")], A);
502
+ })], M.prototype, "filter", null), e([E()], M.prototype, "_value", void 0), e([E()], M.prototype, "_selectedValue", void 0), e([E()], M.prototype, "_isOpen", void 0), e([E()], M.prototype, "_activeIndex", void 0), e([E()], M.prototype, "_focused", void 0), e([E()], M.prototype, "_hasTriggerSlot", void 0), M = O = e([w("web-ui-autocomplete")], M);
469
503
  //#endregion
470
- export { A as WebUiAutocomplete };
504
+ export { M as WebUiAutocomplete };
471
505
 
472
506
  //# sourceMappingURL=index.js.map