mdui 2.0.0 → 2.0.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.
Files changed (96) hide show
  1. package/components/avatar/index.js +2 -1
  2. package/components/badge/index.js +2 -1
  3. package/components/bottom-app-bar/index.d.ts +2 -2
  4. package/components/bottom-app-bar/index.js +4 -3
  5. package/components/button/button-base.d.ts +2 -2
  6. package/components/button/button-base.js +15 -14
  7. package/components/button/index.js +2 -1
  8. package/components/button-icon/index.js +2 -1
  9. package/components/card/index.d.ts +1 -1
  10. package/components/card/index.js +5 -2
  11. package/components/checkbox/index.js +7 -10
  12. package/components/checkbox/style.js +1 -1
  13. package/components/chip/index.js +2 -1
  14. package/components/circular-progress/index.js +3 -3
  15. package/components/collapse/collapse-item-style.js +1 -1
  16. package/components/collapse/collapse-item.d.ts +2 -1
  17. package/components/collapse/collapse-item.js +23 -20
  18. package/components/collapse/collapse.d.ts +6 -6
  19. package/components/collapse/collapse.js +57 -34
  20. package/components/dialog/index.d.ts +3 -2
  21. package/components/dialog/index.js +27 -23
  22. package/components/divider/index.js +2 -1
  23. package/components/dropdown/index.d.ts +4 -5
  24. package/components/dropdown/index.js +56 -51
  25. package/components/fab/index.d.ts +1 -0
  26. package/components/fab/index.js +10 -5
  27. package/components/icon/index.js +2 -1
  28. package/components/layout/helper.d.ts +5 -6
  29. package/components/layout/helper.js +42 -48
  30. package/components/layout/layout-item-base.js +1 -2
  31. package/components/layout/layout-item.js +3 -3
  32. package/components/layout/layout-main.js +2 -1
  33. package/components/layout/layout.js +2 -1
  34. package/components/linear-progress/index.js +3 -3
  35. package/components/list/list-item.js +3 -2
  36. package/components/list/list-subheader.js +2 -1
  37. package/components/list/list.js +2 -1
  38. package/components/menu/menu-item.d.ts +1 -0
  39. package/components/menu/menu-item.js +45 -28
  40. package/components/menu/menu.d.ts +4 -1
  41. package/components/menu/menu.js +82 -56
  42. package/components/navigation-bar/navigation-bar-item-style.js +1 -1
  43. package/components/navigation-bar/navigation-bar-item.d.ts +6 -2
  44. package/components/navigation-bar/navigation-bar-item.js +26 -10
  45. package/components/navigation-bar/navigation-bar.d.ts +6 -6
  46. package/components/navigation-bar/navigation-bar.js +49 -42
  47. package/components/navigation-drawer/index.d.ts +5 -1
  48. package/components/navigation-drawer/index.js +62 -41
  49. package/components/navigation-rail/navigation-rail-item-style.js +1 -1
  50. package/components/navigation-rail/navigation-rail-item.d.ts +6 -2
  51. package/components/navigation-rail/navigation-rail-item.js +20 -8
  52. package/components/navigation-rail/navigation-rail.d.ts +4 -5
  53. package/components/navigation-rail/navigation-rail.js +51 -44
  54. package/components/radio/radio-group.d.ts +6 -4
  55. package/components/radio/radio-group.js +61 -48
  56. package/components/radio/radio-style.js +1 -1
  57. package/components/radio/radio.d.ts +3 -2
  58. package/components/radio/radio.js +24 -17
  59. package/components/range-slider/index.js +7 -9
  60. package/components/ripple/index.js +2 -1
  61. package/components/segmented-button/segmented-button-group.d.ts +6 -3
  62. package/components/segmented-button/segmented-button-group.js +84 -69
  63. package/components/segmented-button/segmented-button.d.ts +2 -2
  64. package/components/segmented-button/segmented-button.js +5 -4
  65. package/components/select/index.d.ts +2 -2
  66. package/components/select/index.js +26 -24
  67. package/components/slider/index.js +7 -9
  68. package/components/slider/slider-base-style.js +1 -1
  69. package/components/slider/slider-base.js +1 -5
  70. package/components/snackbar/index.js +2 -1
  71. package/components/switch/index.js +6 -9
  72. package/components/switch/style.js +1 -1
  73. package/components/tabs/tab-panel.js +2 -1
  74. package/components/tabs/tab-style.js +1 -1
  75. package/components/tabs/tab.js +10 -5
  76. package/components/tabs/tabs-style.js +1 -1
  77. package/components/tabs/tabs.d.ts +6 -5
  78. package/components/tabs/tabs.js +52 -38
  79. package/components/text-field/index.d.ts +2 -2
  80. package/components/text-field/index.js +32 -54
  81. package/components/text-field/style.js +1 -1
  82. package/components/tooltip/index.d.ts +5 -5
  83. package/components/tooltip/index.js +30 -25
  84. package/components/top-app-bar/top-app-bar-title-style.js +1 -1
  85. package/components/top-app-bar/top-app-bar-title.js +16 -12
  86. package/components/top-app-bar/top-app-bar.d.ts +2 -2
  87. package/components/top-app-bar/top-app-bar.js +6 -4
  88. package/custom-elements.json +3776 -3481
  89. package/functions/getTheme.js +3 -3
  90. package/functions/snackbar.js +1 -2
  91. package/functions/utils/colorScheme.js +2 -2
  92. package/html-data.zh-cn.json +727 -727
  93. package/mdui.esm.js +8 -8
  94. package/mdui.global.js +8 -8
  95. package/package.json +7 -7
  96. package/web-types.zh-cn.json +1265 -1265
@@ -1,6 +1,6 @@
1
1
  import { LitElement } from 'lit';
2
2
  import '../icon.js';
3
- import type { CSSResultGroup, TemplateResult } from 'lit';
3
+ import type { CSSResultGroup, PropertyValues, TemplateResult } from 'lit';
4
4
  /**
5
5
  * @summary 对话框组件
6
6
  *
@@ -83,9 +83,10 @@ export declare class Dialog extends LitElement {
83
83
  private readonly panelRef;
84
84
  private readonly bodyRef;
85
85
  private readonly hasSlotController;
86
+ private readonly definedController;
86
87
  private onOpenChange;
87
- connectedCallback(): void;
88
88
  disconnectedCallback(): void;
89
+ protected firstUpdated(_changedProperties: PropertyValues): void;
89
90
  protected render(): TemplateResult;
90
91
  private onOverlayClick;
91
92
  private renderIcon;
@@ -4,6 +4,7 @@ import { customElement, property, queryAssignedElements, } from 'lit/decorators.
4
4
  import { classMap } from 'lit/directives/class-map.js';
5
5
  import { createRef, ref } from 'lit/directives/ref.js';
6
6
  import { when } from 'lit/directives/when.js';
7
+ import { DefinedController } from '@mdui/shared/controllers/defined.js';
7
8
  import { HasSlotController } from '@mdui/shared/controllers/has-slot.js';
8
9
  import { watch } from '@mdui/shared/decorators/watch.js';
9
10
  import { animateTo, stopAnimations } from '@mdui/shared/helpers/animate.js';
@@ -48,7 +49,7 @@ import { style } from './style.js';
48
49
  * @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
49
50
  * @cssprop --z-index - 组件的 CSS 的 `z-index` 值
50
51
  */
51
- export let Dialog = class Dialog extends LitElement {
52
+ let Dialog = class Dialog extends LitElement {
52
53
  constructor() {
53
54
  super(...arguments);
54
55
  /**
@@ -75,10 +76,17 @@ export let Dialog = class Dialog extends LitElement {
75
76
  this.panelRef = createRef();
76
77
  this.bodyRef = createRef();
77
78
  this.hasSlotController = new HasSlotController(this, 'header', 'icon', 'headline', 'description', 'action', '[default]');
79
+ this.definedController = new DefinedController(this, {
80
+ relatedElements: ['mdui-top-app-bar'],
81
+ });
78
82
  }
79
83
  async onOpenChange() {
80
- var _a;
81
84
  const hasUpdated = this.hasUpdated;
85
+ // 默认为关闭状态。因此首次渲染时,且为关闭状态,不执行
86
+ if (!this.open && !hasUpdated) {
87
+ return;
88
+ }
89
+ await this.definedController.whenDefined();
82
90
  if (!hasUpdated) {
83
91
  await this.updateComplete;
84
92
  }
@@ -87,6 +95,11 @@ export let Dialog = class Dialog extends LitElement {
87
95
  const easingLinear = getEasing(this, 'linear');
88
96
  const easingEmphasizedDecelerate = getEasing(this, 'emphasized-decelerate');
89
97
  const easingEmphasizedAccelerate = getEasing(this, 'emphasized-accelerate');
98
+ const stopAnimation = () => Promise.all([
99
+ stopAnimations(this.overlayRef.value),
100
+ stopAnimations(this.panelRef.value),
101
+ ...children.map((child) => stopAnimations(child)),
102
+ ]);
90
103
  // 打开
91
104
  // 要区分是否首次渲染,首次渲染不触发事件,不执行动画;非首次渲染,触发事件,执行动画
92
105
  if (this.open) {
@@ -100,7 +113,7 @@ export let Dialog = class Dialog extends LitElement {
100
113
  }
101
114
  this.style.display = 'flex';
102
115
  // 包含 <mdui-top-app-bar slot="header"> 时
103
- const topAppBarElements = (_a = this.topAppBarElements) !== null && _a !== void 0 ? _a : [];
116
+ const topAppBarElements = this.topAppBarElements ?? [];
104
117
  if (topAppBarElements.length) {
105
118
  const topAppBarElement = topAppBarElements[0];
106
119
  // top-app-bar 未设置 scrollTarget 时,默认设置为 bodyRef
@@ -113,11 +126,7 @@ export let Dialog = class Dialog extends LitElement {
113
126
  this.originalTrigger = document.activeElement;
114
127
  this.modalHelper.activate();
115
128
  lockScreen(this);
116
- await Promise.all([
117
- stopAnimations(this.overlayRef.value),
118
- stopAnimations(this.panelRef.value),
119
- ...children.map((child) => stopAnimations(child)),
120
- ]);
129
+ await stopAnimation();
121
130
  // 设置聚焦
122
131
  requestAnimationFrame(() => {
123
132
  const autoFocusTarget = this.querySelector('[autofocus]');
@@ -158,9 +167,8 @@ export let Dialog = class Dialog extends LitElement {
158
167
  if (hasUpdated) {
159
168
  emit(this, 'opened');
160
169
  }
161
- return;
162
170
  }
163
- if (!this.open && hasUpdated) {
171
+ else {
164
172
  const requestClose = emit(this, 'close', {
165
173
  cancelable: true,
166
174
  });
@@ -168,11 +176,7 @@ export let Dialog = class Dialog extends LitElement {
168
176
  return;
169
177
  }
170
178
  this.modalHelper.deactivate();
171
- await Promise.all([
172
- stopAnimations(this.overlayRef.value),
173
- stopAnimations(this.panelRef.value),
174
- ...children.map((child) => stopAnimations(child)),
175
- ]);
179
+ await stopAnimation();
176
180
  const duration = getDuration(this, 'short4');
177
181
  await Promise.all([
178
182
  animateTo(this.overlayRef.value, [{ opacity: 1 }, { opacity: 0 }], {
@@ -190,15 +194,18 @@ export let Dialog = class Dialog extends LitElement {
190
194
  unlockScreen(this);
191
195
  // 对话框关闭后,恢复焦点到原有的元素上
192
196
  const trigger = this.originalTrigger;
193
- if (typeof (trigger === null || trigger === void 0 ? void 0 : trigger.focus) === 'function') {
197
+ if (typeof trigger?.focus === 'function') {
194
198
  setTimeout(() => trigger.focus());
195
199
  }
196
200
  emit(this, 'closed');
197
- return;
198
201
  }
199
202
  }
200
- connectedCallback() {
201
- super.connectedCallback();
203
+ disconnectedCallback() {
204
+ super.disconnectedCallback();
205
+ unlockScreen(this);
206
+ }
207
+ firstUpdated(_changedProperties) {
208
+ super.firstUpdated(_changedProperties);
202
209
  this.modalHelper = new Modal(this);
203
210
  this.addEventListener('keydown', (event) => {
204
211
  if (this.open && this.closeOnEsc && event.key === 'Escape') {
@@ -207,10 +214,6 @@ export let Dialog = class Dialog extends LitElement {
207
214
  }
208
215
  });
209
216
  }
210
- disconnectedCallback() {
211
- super.disconnectedCallback();
212
- unlockScreen(this);
213
- }
214
217
  render() {
215
218
  const hasActionSlot = this.hasSlotController.test('action');
216
219
  const hasDefaultSlot = this.hasSlotController.test('[default]');
@@ -305,3 +308,4 @@ __decorate([
305
308
  Dialog = __decorate([
306
309
  customElement('mdui-dialog')
307
310
  ], Dialog);
311
+ export { Dialog };
@@ -11,7 +11,7 @@ import { style } from './style.js';
11
11
  * <mdui-divider></mdui-divider>
12
12
  * ```
13
13
  */
14
- export let Divider = class Divider extends LitElement {
14
+ let Divider = class Divider extends LitElement {
15
15
  constructor() {
16
16
  super(...arguments);
17
17
  /**
@@ -56,3 +56,4 @@ __decorate([
56
56
  Divider = __decorate([
57
57
  customElement('mdui-divider')
58
58
  ], Divider);
59
+ export { Divider };
@@ -1,7 +1,6 @@
1
1
  import { LitElement } from 'lit';
2
2
  import '@mdui/jq/methods/height.js';
3
3
  import '@mdui/jq/methods/is.js';
4
- import '@mdui/jq/methods/on.js';
5
4
  import '@mdui/jq/methods/width.js';
6
5
  import type { CSSResultGroup, PropertyValues, TemplateResult } from 'lit';
7
6
  /**
@@ -84,8 +83,8 @@ export declare class Dropdown extends LitElement {
84
83
  * 是否在触发 dropdown 时的光标所在的位置打开 dropdown。通常用于在打开鼠标右键菜单时使用
85
84
  */
86
85
  openOnPointer: boolean;
87
- private readonly triggerSlots;
88
- private readonly panelSlots;
86
+ private readonly triggerElements;
87
+ private readonly panelElements;
89
88
  private pointerOffsetX;
90
89
  private pointerOffsetY;
91
90
  private animateDirection;
@@ -93,9 +92,9 @@ export declare class Dropdown extends LitElement {
93
92
  private closeTimeout;
94
93
  private observeResize?;
95
94
  private readonly panelRef;
95
+ private readonly definedController;
96
96
  constructor();
97
- private get triggerSlot();
98
- private get panelSlot();
97
+ private get triggerElement();
99
98
  private onPositionChange;
100
99
  private onOpenChange;
101
100
  connectedCallback(): void;
@@ -5,8 +5,9 @@ import { createRef, ref } from 'lit/directives/ref.js';
5
5
  import { $ } from '@mdui/jq/$.js';
6
6
  import '@mdui/jq/methods/height.js';
7
7
  import '@mdui/jq/methods/is.js';
8
- import '@mdui/jq/methods/on.js';
9
8
  import '@mdui/jq/methods/width.js';
9
+ import { isFunction } from '@mdui/jq/shared/helper.js';
10
+ import { DefinedController } from '@mdui/shared/controllers/defined.js';
10
11
  import { watch } from '@mdui/shared/decorators/watch.js';
11
12
  import { animateTo, stopAnimations } from '@mdui/shared/helpers/animate.js';
12
13
  import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
@@ -41,7 +42,7 @@ import { style } from './style.js';
41
42
  *
42
43
  * @cssprop --z-index - 组件的 CSS 的 `z-index` 值
43
44
  */
44
- export let Dropdown = class Dropdown extends LitElement {
45
+ let Dropdown = class Dropdown extends LitElement {
45
46
  constructor() {
46
47
  super();
47
48
  /**
@@ -97,6 +98,9 @@ export let Dropdown = class Dropdown extends LitElement {
97
98
  */
98
99
  this.openOnPointer = false;
99
100
  this.panelRef = createRef();
101
+ this.definedController = new DefinedController(this, {
102
+ relatedElements: [''],
103
+ });
100
104
  this.onDocumentClick = this.onDocumentClick.bind(this);
101
105
  this.onDocumentKeydown = this.onDocumentKeydown.bind(this);
102
106
  this.onWindowScroll = this.onWindowScroll.bind(this);
@@ -107,31 +111,33 @@ export let Dropdown = class Dropdown extends LitElement {
107
111
  this.onMouseEnter = this.onMouseEnter.bind(this);
108
112
  this.onPanelClick = this.onPanelClick.bind(this);
109
113
  }
110
- get triggerSlot() {
111
- return this.triggerSlots[0];
112
- }
113
- get panelSlot() {
114
- return this.panelSlots[0];
114
+ get triggerElement() {
115
+ return this.triggerElements[0];
115
116
  }
116
117
  // 这些属性变更时,需要更新样式
117
118
  async onPositionChange() {
118
- // 打开动画开始前,设置 panel 的样式
119
+ // 如果是打开状态,则更新 panel 的位置
119
120
  if (this.open) {
121
+ await this.definedController.whenDefined();
120
122
  this.updatePositioner();
121
123
  }
122
124
  }
123
125
  async onOpenChange() {
124
- var _a, _b, _c, _d;
125
126
  const hasUpdated = this.hasUpdated;
127
+ // 默认为关闭状态。因此首次渲染时,且为关闭状态,不执行
128
+ if (!this.open && !hasUpdated) {
129
+ return;
130
+ }
131
+ await this.definedController.whenDefined();
132
+ if (!hasUpdated) {
133
+ await this.updateComplete;
134
+ }
126
135
  const easingLinear = getEasing(this, 'linear');
127
136
  const easingEmphasizedDecelerate = getEasing(this, 'emphasized-decelerate');
128
137
  const easingEmphasizedAccelerate = getEasing(this, 'emphasized-accelerate');
129
138
  // 打开
130
139
  // 要区分是否首次渲染,首次渲染时不触发事件,不执行动画;非首次渲染,触发事件,执行动画
131
140
  if (this.open) {
132
- if (!hasUpdated) {
133
- await this.updateComplete;
134
- }
135
141
  if (hasUpdated) {
136
142
  const requestOpen = emit(this, 'open', {
137
143
  cancelable: true,
@@ -141,9 +147,10 @@ export let Dropdown = class Dropdown extends LitElement {
141
147
  }
142
148
  }
143
149
  // dropdown 打开时,尝试把焦点放到 panel 中
144
- if (typeof ((_a = this.panelSlot) === null || _a === void 0 ? void 0 : _a.focus) === 'function') {
145
- this.panelSlot.focus();
146
- }
150
+ const focusablePanel = this.panelElements.find((panel) => isFunction(panel.focus));
151
+ setTimeout(() => {
152
+ focusablePanel?.focus();
153
+ });
147
154
  const duration = getDuration(this, 'medium4');
148
155
  await stopAnimations(this.panelRef.value);
149
156
  this.panelRef.value.hidden = false;
@@ -164,10 +171,8 @@ export let Dropdown = class Dropdown extends LitElement {
164
171
  if (hasUpdated) {
165
172
  emit(this, 'opened');
166
173
  }
167
- return;
168
174
  }
169
- // 关闭
170
- if (!this.open && hasUpdated) {
175
+ else {
171
176
  const requestClose = emit(this, 'close', {
172
177
  cancelable: true,
173
178
  });
@@ -176,10 +181,10 @@ export let Dropdown = class Dropdown extends LitElement {
176
181
  }
177
182
  // dropdown 关闭时,如果不支持 focus 触发,且焦点在 dropdown 内,则焦点回到 trigger 上
178
183
  if (!this.hasTrigger('focus') &&
179
- typeof ((_b = this.triggerSlot) === null || _b === void 0 ? void 0 : _b.focus) === 'function' &&
184
+ isFunction(this.triggerElement?.focus) &&
180
185
  (this.contains(document.activeElement) ||
181
- this.contains((_d = (_c = document.activeElement) === null || _c === void 0 ? void 0 : _c.assignedSlot) !== null && _d !== void 0 ? _d : null))) {
182
- this.triggerSlot.focus();
186
+ this.contains(document.activeElement?.assignedSlot ?? null))) {
187
+ this.triggerElement.focus();
183
188
  }
184
189
  const duration = getDuration(this, 'short4');
185
190
  await stopAnimations(this.panelRef.value);
@@ -199,35 +204,35 @@ export let Dropdown = class Dropdown extends LitElement {
199
204
  }
200
205
  connectedCallback() {
201
206
  super.connectedCallback();
202
- document.addEventListener('pointerdown', this.onDocumentClick);
203
- document.addEventListener('keydown', this.onDocumentKeydown);
204
- window.addEventListener('scroll', this.onWindowScroll);
205
- // triggerSlot 的尺寸变化时,重新调整 panel 的位置
206
- this.updateComplete.then(() => {
207
- this.observeResize = observeResize(this.triggerSlot, () => {
208
- this.updatePositioner();
209
- });
207
+ this.definedController.whenDefined().then(() => {
208
+ document.addEventListener('pointerdown', this.onDocumentClick);
209
+ document.addEventListener('keydown', this.onDocumentKeydown);
210
+ window.addEventListener('scroll', this.onWindowScroll);
210
211
  });
211
212
  }
212
213
  disconnectedCallback() {
213
- var _a;
214
214
  super.disconnectedCallback();
215
215
  document.removeEventListener('pointerdown', this.onDocumentClick);
216
216
  document.removeEventListener('keydown', this.onDocumentKeydown);
217
217
  window.removeEventListener('scroll', this.onWindowScroll);
218
- (_a = this.observeResize) === null || _a === void 0 ? void 0 : _a.unobserve();
218
+ this.observeResize?.unobserve();
219
219
  }
220
220
  firstUpdated(changedProperties) {
221
221
  super.firstUpdated(changedProperties);
222
222
  this.addEventListener('mouseleave', this.onMouseLeave);
223
- this.triggerSlot.addEventListener('focus', this.onFocus);
224
- this.triggerSlot.addEventListener('click', this.onClick);
225
- this.triggerSlot.addEventListener('contextmenu', this.onContextMenu);
226
- this.triggerSlot.addEventListener('mouseenter', this.onMouseEnter);
227
- $(this.panelRef.value).on('click', this.onPanelClick);
223
+ this.definedController.whenDefined().then(() => {
224
+ this.triggerElement.addEventListener('focus', this.onFocus);
225
+ this.triggerElement.addEventListener('click', this.onClick);
226
+ this.triggerElement.addEventListener('contextmenu', this.onContextMenu);
227
+ this.triggerElement.addEventListener('mouseenter', this.onMouseEnter);
228
+ // triggerElement 的尺寸变化时,重新调整 panel 的位置
229
+ this.observeResize = observeResize(this.triggerElement, () => {
230
+ this.updatePositioner();
231
+ });
232
+ });
228
233
  }
229
234
  render() {
230
- return html `<slot name="trigger" part="trigger" class="trigger"></slot><slot ${ref(this.panelRef)} part="panel" class="panel" hidden></slot>`;
235
+ return html `<slot name="trigger" part="trigger" class="trigger"></slot><slot ${ref(this.panelRef)} part="panel" class="panel" hidden @click="${this.onPanelClick}"></slot>`;
231
236
  }
232
237
  /**
233
238
  * 获取 dropdown 打开、关闭动画的 CSS scaleX 或 scaleY
@@ -250,7 +255,7 @@ export let Dropdown = class Dropdown extends LitElement {
250
255
  // 当包含 contextmenu 且不包含 click 时,点击 trigger,关闭
251
256
  if (this.hasTrigger('contextmenu') &&
252
257
  !this.hasTrigger('click') &&
253
- path.includes(this.triggerSlot)) {
258
+ path.includes(this.triggerElement)) {
254
259
  this.open = false;
255
260
  }
256
261
  }
@@ -258,7 +263,6 @@ export let Dropdown = class Dropdown extends LitElement {
258
263
  * 在 document 上按下按键时,根据条件判断是否要关闭 dropdown
259
264
  */
260
265
  onDocumentKeydown(event) {
261
- var _a;
262
266
  if (this.disabled || !this.open) {
263
267
  return;
264
268
  }
@@ -270,8 +274,7 @@ export let Dropdown = class Dropdown extends LitElement {
270
274
  // 按下 Tab 键时,关闭 dropdown
271
275
  if (event.key === 'Tab') {
272
276
  // 如果不支持 focus 触发,则焦点回到 trigger 上(这个会在 onOpenChange 中执行 )这里只需阻止默认的 Tab 行为
273
- if (!this.hasTrigger('focus') &&
274
- typeof ((_a = this.triggerSlot) === null || _a === void 0 ? void 0 : _a.focus) === 'function') {
277
+ if (!this.hasTrigger('focus') && isFunction(this.triggerElement?.focus)) {
275
278
  event.preventDefault();
276
279
  }
277
280
  this.open = false;
@@ -304,10 +307,9 @@ export let Dropdown = class Dropdown extends LitElement {
304
307
  this.open = !this.open;
305
308
  }
306
309
  onPanelClick(e) {
307
- const event = e;
308
310
  if (!this.disabled &&
309
311
  !this.stayOpenOnClick &&
310
- $(event.target).is('mdui-menu-item')) {
312
+ $(e.target).is('mdui-menu-item')) {
311
313
  this.open = false;
312
314
  }
313
315
  }
@@ -345,17 +347,19 @@ export let Dropdown = class Dropdown extends LitElement {
345
347
  this.open = false;
346
348
  }, this.closeDelay || 50);
347
349
  }
350
+ // 更新 panel 的位置
348
351
  updatePositioner() {
349
- var _a;
350
352
  const $panel = $(this.panelRef.value);
351
353
  const $window = $(window);
352
- const panelSlots = this.panelSlots;
354
+ const panelElements = this.panelElements;
353
355
  const panelRect = {
354
- width: Math.max(...((_a = panelSlots === null || panelSlots === void 0 ? void 0 : panelSlots.map((panel) => panel.offsetWidth)) !== null && _a !== void 0 ? _a : [])),
355
- height: panelSlots === null || panelSlots === void 0 ? void 0 : panelSlots.map((panel) => panel.offsetHeight).reduce((total, height) => total + height),
356
+ width: Math.max(...(panelElements?.map((panel) => panel.offsetWidth) ?? [])),
357
+ height: panelElements
358
+ ?.map((panel) => panel.offsetHeight)
359
+ .reduce((total, height) => total + height, 0),
356
360
  };
357
- // 在光标位置触发时,假设 triggerSlot 的宽高为 0,位置位于光标位置
358
- const triggerClientRect = this.triggerSlot.getBoundingClientRect();
361
+ // 在光标位置触发时,假设 triggerElement 的宽高为 0,位置位于光标位置
362
+ const triggerClientRect = this.triggerElement.getBoundingClientRect();
359
363
  const triggerRect = this.openOnPointer
360
364
  ? {
361
365
  top: this.pointerOffsetY + triggerClientRect.top,
@@ -555,10 +559,10 @@ __decorate([
555
559
  ], Dropdown.prototype, "openOnPointer", void 0);
556
560
  __decorate([
557
561
  queryAssignedElements({ slot: 'trigger', flatten: true })
558
- ], Dropdown.prototype, "triggerSlots", void 0);
562
+ ], Dropdown.prototype, "triggerElements", void 0);
559
563
  __decorate([
560
564
  queryAssignedElements({ flatten: true })
561
- ], Dropdown.prototype, "panelSlots", void 0);
565
+ ], Dropdown.prototype, "panelElements", void 0);
562
566
  __decorate([
563
567
  watch('placement', true),
564
568
  watch('openOnPointer', true)
@@ -569,3 +573,4 @@ __decorate([
569
573
  Dropdown = __decorate([
570
574
  customElement('mdui-dropdown')
571
575
  ], Dropdown);
576
+ export { Dropdown };
@@ -53,6 +53,7 @@ export declare class Fab extends ButtonBase {
53
53
  extended: boolean;
54
54
  private readonly rippleRef;
55
55
  private readonly hasSlotController;
56
+ private readonly definedController;
56
57
  protected get rippleElement(): Ripple;
57
58
  /**
58
59
  * extended 变更时,设置动画
@@ -3,6 +3,7 @@ import { html } from 'lit';
3
3
  import { customElement, property } from 'lit/decorators.js';
4
4
  import { createRef, ref } from 'lit/directives/ref.js';
5
5
  import cc from 'classcat';
6
+ import { DefinedController } from '@mdui/shared/controllers/defined.js';
6
7
  import { HasSlotController } from '@mdui/shared/controllers/has-slot.js';
7
8
  import { watch } from '@mdui/shared/decorators/watch.js';
8
9
  import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
@@ -34,7 +35,7 @@ import { style } from './style.js';
34
35
  * @cssprop --shape-corner-normal - `size="normal"` 时,组件的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
35
36
  * @cssprop --shape-corner-large - `size="large"` 时,组件的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
36
37
  */
37
- export let Fab = class Fab extends ButtonBase {
38
+ let Fab = class Fab extends ButtonBase {
38
39
  constructor() {
39
40
  super(...arguments);
40
41
  /**
@@ -59,6 +60,9 @@ export let Fab = class Fab extends ButtonBase {
59
60
  this.extended = false;
60
61
  this.rippleRef = createRef();
61
62
  this.hasSlotController = new HasSlotController(this, 'icon');
63
+ this.definedController = new DefinedController(this, {
64
+ relatedElements: [''],
65
+ });
62
66
  }
63
67
  get rippleElement() {
64
68
  return this.rippleRef.value;
@@ -68,15 +72,15 @@ export let Fab = class Fab extends ButtonBase {
68
72
  */
69
73
  async onExtendedChange() {
70
74
  const hasUpdated = this.hasUpdated;
71
- if (!this.extended) {
72
- this.style.width = '';
75
+ if (this.extended) {
76
+ this.style.width = `${this.scrollWidth}px`;
73
77
  }
74
78
  else {
75
- this.style.width = `${this.scrollWidth}px`;
79
+ this.style.width = '';
76
80
  }
81
+ await this.definedController.whenDefined();
77
82
  await this.updateComplete;
78
83
  if (this.extended && !hasUpdated) {
79
- await delay();
80
84
  this.style.width = `${this.scrollWidth}px`;
81
85
  }
82
86
  if (!hasUpdated) {
@@ -142,3 +146,4 @@ __decorate([
142
146
  Fab = __decorate([
143
147
  customElement('mdui-fab')
144
148
  ], Fab);
149
+ export { Fab };
@@ -17,7 +17,7 @@ import { style } from './style.js';
17
17
  *
18
18
  * @slot - `svg` 图标的内容
19
19
  */
20
- export let Icon = class Icon extends LitElement {
20
+ let Icon = class Icon extends LitElement {
21
21
  constructor() {
22
22
  super(...arguments);
23
23
  this.hasSlotController = new HasSlotController(this, '[default]');
@@ -55,3 +55,4 @@ __decorate([
55
55
  Icon = __decorate([
56
56
  customElement('mdui-icon')
57
57
  ], Icon);
58
+ export { Icon };
@@ -6,11 +6,9 @@ import type { LayoutMain } from './layout-main.js';
6
6
  import type { Layout } from './layout.js';
7
7
  export type LayoutPlacement = 'top' | 'left' | 'right' | 'bottom';
8
8
  export declare class LayoutManager {
9
- private $layout;
10
9
  private $main?;
11
10
  private states;
12
11
  private items?;
13
- constructor(element: Layout);
14
12
  /**
15
13
  * 注册 `<mdui-layout-main>`
16
14
  */
@@ -39,10 +37,6 @@ export declare class LayoutManager {
39
37
  * 获取 `<mdui-layout-item>` 及 `<mdui-layout-main>` 元素
40
38
  */
41
39
  getItemsAndMain(): (LayoutItemBase | LayoutMain)[];
42
- /**
43
- * 检查指定 `<mdui-layout-item>` 元素是否已注册
44
- */
45
- hasItem(element: LayoutItemBase): boolean;
46
40
  /**
47
41
  * 更新 `order` 值,更新完后重新计算布局
48
42
  */
@@ -60,6 +54,11 @@ export declare class LayoutManager {
60
54
  * 按 order 排序,order 相同时,按在 DOM 中的顺序排序
61
55
  */
62
56
  private resort;
57
+ /**
58
+ * 组件宽度是否为 0
59
+ * mdui-navigation-drawer 较为特殊,在为模态化时,占据的宽度为 0
60
+ */
61
+ private isNoWidth;
63
62
  }
64
63
  /**
65
64
  * 获取 layout 实例