mdui 2.0.1 → 2.0.3

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 (127) hide show
  1. package/LICENSE +21 -21
  2. package/components/avatar/index.d.ts +4 -2
  3. package/components/avatar/index.js +4 -2
  4. package/components/badge/index.d.ts +4 -2
  5. package/components/badge/index.js +4 -2
  6. package/components/bottom-app-bar/index.d.ts +9 -3
  7. package/components/bottom-app-bar/index.js +9 -9
  8. package/components/button/button-base.d.ts +5 -5
  9. package/components/button/button-base.js +22 -19
  10. package/components/button/index.d.ts +6 -1
  11. package/components/button/index.js +2 -1
  12. package/components/button-icon/index.d.ts +7 -1
  13. package/components/button-icon/index.js +3 -3
  14. package/components/card/index.d.ts +8 -4
  15. package/components/card/index.js +7 -3
  16. package/components/checkbox/index.d.ts +10 -3
  17. package/components/checkbox/index.js +13 -16
  18. package/components/checkbox/style.js +1 -1
  19. package/components/chip/index.d.ts +8 -1
  20. package/components/chip/index.js +5 -5
  21. package/components/circular-progress/index.d.ts +4 -2
  22. package/components/circular-progress/index.js +5 -4
  23. package/components/collapse/collapse-item-style.js +1 -1
  24. package/components/collapse/collapse-item.d.ts +15 -3
  25. package/components/collapse/collapse-item.js +26 -23
  26. package/components/collapse/collapse.d.ts +16 -8
  27. package/components/collapse/collapse.js +61 -38
  28. package/components/dialog/index.d.ts +12 -4
  29. package/components/dialog/index.js +36 -36
  30. package/components/divider/index.d.ts +4 -2
  31. package/components/divider/index.js +4 -2
  32. package/components/dropdown/index.d.ts +13 -7
  33. package/components/dropdown/index.js +70 -63
  34. package/components/fab/index.d.ts +7 -1
  35. package/components/fab/index.js +10 -5
  36. package/components/icon/index.d.ts +4 -2
  37. package/components/icon/index.js +4 -2
  38. package/components/layout/helper.d.ts +5 -6
  39. package/components/layout/helper.js +42 -48
  40. package/components/layout/layout-item-base.d.ts +3 -2
  41. package/components/layout/layout-item-base.js +3 -4
  42. package/components/layout/layout-item.d.ts +4 -3
  43. package/components/layout/layout-item.js +3 -3
  44. package/components/layout/layout-main.d.ts +4 -2
  45. package/components/layout/layout-main.js +4 -2
  46. package/components/layout/layout.d.ts +4 -2
  47. package/components/layout/layout.js +4 -2
  48. package/components/linear-progress/index.d.ts +4 -2
  49. package/components/linear-progress/index.js +5 -4
  50. package/components/list/list-item-style.js +1 -1
  51. package/components/list/list-item.d.ts +7 -3
  52. package/components/list/list-item.js +5 -3
  53. package/components/list/list-subheader.d.ts +4 -2
  54. package/components/list/list-subheader.js +4 -2
  55. package/components/list/list.d.ts +4 -2
  56. package/components/list/list.js +4 -2
  57. package/components/menu/menu-item.d.ts +12 -3
  58. package/components/menu/menu-item.js +53 -40
  59. package/components/menu/menu.d.ts +9 -3
  60. package/components/menu/menu.js +85 -59
  61. package/components/navigation-bar/navigation-bar-item-style.js +1 -1
  62. package/components/navigation-bar/navigation-bar-item.d.ts +13 -5
  63. package/components/navigation-bar/navigation-bar-item.js +28 -11
  64. package/components/navigation-bar/navigation-bar.d.ts +14 -7
  65. package/components/navigation-bar/navigation-bar.js +58 -49
  66. package/components/navigation-drawer/index.d.ts +13 -2
  67. package/components/navigation-drawer/index.js +69 -49
  68. package/components/navigation-drawer/style.js +1 -1
  69. package/components/navigation-rail/navigation-rail-item-style.js +1 -1
  70. package/components/navigation-rail/navigation-rail-item.d.ts +13 -5
  71. package/components/navigation-rail/navigation-rail-item.js +22 -9
  72. package/components/navigation-rail/navigation-rail.d.ts +8 -6
  73. package/components/navigation-rail/navigation-rail.js +55 -46
  74. package/components/radio/radio-group.d.ts +13 -6
  75. package/components/radio/radio-group.js +69 -59
  76. package/components/radio/radio-style.js +1 -1
  77. package/components/radio/radio.d.ts +11 -5
  78. package/components/radio/radio.js +26 -19
  79. package/components/range-slider/index.d.ts +9 -3
  80. package/components/range-slider/index.js +13 -11
  81. package/components/ripple/index.d.ts +4 -2
  82. package/components/ripple/index.js +4 -2
  83. package/components/ripple/ripple-mixin.d.ts +1 -1
  84. package/components/ripple/ripple-mixin.js +0 -1
  85. package/components/segmented-button/segmented-button-group-style.js +1 -1
  86. package/components/segmented-button/segmented-button-group.d.ts +12 -5
  87. package/components/segmented-button/segmented-button-group.js +92 -77
  88. package/components/segmented-button/segmented-button.d.ts +8 -3
  89. package/components/segmented-button/segmented-button.js +5 -4
  90. package/components/select/index.d.ts +13 -5
  91. package/components/select/index.js +30 -28
  92. package/components/slider/index.d.ts +8 -1
  93. package/components/slider/index.js +11 -18
  94. package/components/slider/slider-base-style.js +1 -1
  95. package/components/slider/slider-base.d.ts +7 -3
  96. package/components/slider/slider-base.js +28 -13
  97. package/components/snackbar/index.d.ts +9 -2
  98. package/components/snackbar/index.js +11 -10
  99. package/components/switch/index.d.ts +10 -3
  100. package/components/switch/index.js +12 -15
  101. package/components/switch/style.js +1 -1
  102. package/components/tabs/tab-panel.d.ts +4 -2
  103. package/components/tabs/tab-panel.js +4 -2
  104. package/components/tabs/tab-style.js +1 -1
  105. package/components/tabs/tab.d.ts +7 -3
  106. package/components/tabs/tab.js +12 -6
  107. package/components/tabs/tabs-style.js +1 -1
  108. package/components/tabs/tabs.d.ts +11 -7
  109. package/components/tabs/tabs.js +57 -40
  110. package/components/text-field/index.d.ts +13 -5
  111. package/components/text-field/index.js +43 -65
  112. package/components/text-field/style.js +1 -1
  113. package/components/tooltip/index.d.ts +14 -7
  114. package/components/tooltip/index.js +45 -38
  115. package/components/top-app-bar/top-app-bar-title-style.js +1 -1
  116. package/components/top-app-bar/top-app-bar-title.d.ts +4 -2
  117. package/components/top-app-bar/top-app-bar-title.js +18 -13
  118. package/components/top-app-bar/top-app-bar.d.ts +9 -3
  119. package/components/top-app-bar/top-app-bar.js +11 -10
  120. package/custom-elements.json +904 -546
  121. package/functions/getTheme.js +3 -3
  122. package/functions/snackbar.js +1 -2
  123. package/functions/utils/colorScheme.js +2 -2
  124. package/mdui.esm.js +8 -8
  125. package/mdui.global.js +8 -8
  126. package/package.json +8 -7
  127. package/web-types.zh-cn.json +1 -1
@@ -1,14 +1,15 @@
1
1
  import { __decorate } from "tslib";
2
- import { html, LitElement } from 'lit';
3
- import { customElement, property } from 'lit/decorators.js';
2
+ import { html } from 'lit';
3
+ import { customElement, property, state } from 'lit/decorators.js';
4
+ import { classMap } from 'lit/directives/class-map.js';
4
5
  import { ifDefined } from 'lit/directives/if-defined.js';
5
6
  import { live } from 'lit/directives/live.js';
6
7
  import { createRef, ref } from 'lit/directives/ref.js';
8
+ import { MduiElement } from '@mdui/shared/base/mdui-element.js';
7
9
  import { FormController, formResets } from '@mdui/shared/controllers/form.js';
8
10
  import { defaultValue } from '@mdui/shared/decorators/default-value.js';
9
11
  import { watch } from '@mdui/shared/decorators/watch.js';
10
12
  import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
11
- import { emit } from '@mdui/shared/helpers/event.js';
12
13
  import '@mdui/shared/icons/check-box-outline-blank.js';
13
14
  import '@mdui/shared/icons/check-box.js';
14
15
  import '@mdui/shared/icons/indeterminate-check-box.js';
@@ -41,7 +42,7 @@ import { style } from './style.js';
41
42
  * @csspart indeterminate-icon - 不确定状态图标
42
43
  * @csspart label - 文本
43
44
  */
44
- export let Checkbox = class Checkbox extends RippleMixin(FocusableMixin(LitElement)) {
45
+ let Checkbox = class Checkbox extends RippleMixin(FocusableMixin(MduiElement)) {
45
46
  constructor() {
46
47
  super(...arguments);
47
48
  /**
@@ -113,11 +114,10 @@ export let Checkbox = class Checkbox extends RippleMixin(FocusableMixin(LitEleme
113
114
  this.invalid = !this.inputRef.value.checkValidity();
114
115
  }
115
116
  async onCheckedChange() {
116
- var _a;
117
117
  await this.updateComplete;
118
118
  // reset 引起的值变更,不执行验证;直接修改值引起的变更,需要进行验证
119
119
  const form = this.formController.getForm();
120
- if (form && ((_a = formResets.get(form)) === null || _a === void 0 ? void 0 : _a.has(this))) {
120
+ if (form && formResets.get(form)?.has(this)) {
121
121
  this.invalid = false;
122
122
  formResets.get(form).delete(this);
123
123
  }
@@ -131,7 +131,7 @@ export let Checkbox = class Checkbox extends RippleMixin(FocusableMixin(LitEleme
131
131
  checkValidity() {
132
132
  const valid = this.inputRef.value.checkValidity();
133
133
  if (!valid) {
134
- emit(this, 'invalid', {
134
+ this.emit('invalid', {
135
135
  bubbles: false,
136
136
  cancelable: true,
137
137
  composed: false,
@@ -147,13 +147,13 @@ export let Checkbox = class Checkbox extends RippleMixin(FocusableMixin(LitEleme
147
147
  reportValidity() {
148
148
  this.invalid = !this.inputRef.value.reportValidity();
149
149
  if (this.invalid) {
150
- const requestInvalid = emit(this, 'invalid', {
150
+ const eventProceeded = this.emit('invalid', {
151
151
  bubbles: false,
152
152
  cancelable: true,
153
153
  composed: false,
154
154
  });
155
155
  // 调用了 preventDefault() 时,隐藏默认的表单错误提示
156
- if (requestInvalid.defaultPrevented) {
156
+ if (!eventProceeded) {
157
157
  this.blur();
158
158
  this.focus();
159
159
  }
@@ -170,7 +170,7 @@ export let Checkbox = class Checkbox extends RippleMixin(FocusableMixin(LitEleme
170
170
  this.invalid = !this.inputRef.value.checkValidity();
171
171
  }
172
172
  render() {
173
- return html `<label><input ${ref(this.inputRef)} type="checkbox" name="${ifDefined(this.name)}" value="${ifDefined(this.value)}" .indeterminate="${live(this.indeterminate)}" .disabled="${this.disabled}" .checked="${live(this.checked)}" .required="${this.required}" @change="${this.onChange}"> <i part="control"><mdui-ripple ${ref(this.rippleRef)} .noRipple="${this.noRipple}"></mdui-ripple><slot name="unchecked-icon" part="unchecked-icon" class="icon unchecked-icon">${this.uncheckedIcon
173
+ return html `<label class="${classMap({ invalid: this.invalid })}"><input ${ref(this.inputRef)} type="checkbox" name="${ifDefined(this.name)}" value="${ifDefined(this.value)}" .indeterminate="${live(this.indeterminate)}" .disabled="${this.disabled}" .checked="${live(this.checked)}" .required="${this.required}" @change="${this.onChange}"> <i part="control"><mdui-ripple ${ref(this.rippleRef)} .noRipple="${this.noRipple}"></mdui-ripple><slot name="unchecked-icon" part="unchecked-icon" class="icon unchecked-icon">${this.uncheckedIcon
174
174
  ? html `<mdui-icon name="${this.uncheckedIcon}" class="i"></mdui-icon>`
175
175
  : html `<mdui-icon-check-box-outline-blank class="i"></mdui-icon-check-box-outline-blank>`}</slot><slot name="checked-icon" part="checked-icon" class="icon checked-icon">${this.checkedIcon
176
176
  ? html `<mdui-icon name="${this.checkedIcon}" class="i"></mdui-icon>`
@@ -184,7 +184,7 @@ export let Checkbox = class Checkbox extends RippleMixin(FocusableMixin(LitEleme
184
184
  onChange() {
185
185
  this.checked = this.inputRef.value.checked;
186
186
  this.indeterminate = false;
187
- emit(this, 'change');
187
+ this.emit('change');
188
188
  }
189
189
  };
190
190
  Checkbox.styles = [componentStyle, style];
@@ -238,11 +238,7 @@ __decorate([
238
238
  property({ reflect: true, attribute: 'indeterminate-icon' })
239
239
  ], Checkbox.prototype, "indeterminateIcon", void 0);
240
240
  __decorate([
241
- property({
242
- type: Boolean,
243
- reflect: true,
244
- converter: booleanConverter,
245
- })
241
+ state()
246
242
  ], Checkbox.prototype, "invalid", void 0);
247
243
  __decorate([
248
244
  watch('disabled', true),
@@ -255,3 +251,4 @@ __decorate([
255
251
  Checkbox = __decorate([
256
252
  customElement('mdui-checkbox')
257
253
  ], Checkbox);
254
+ export { Checkbox };
@@ -1,2 +1,2 @@
1
1
  import { css } from 'lit';
2
- export const style = css `:host{position:relative;display:inline-flex;cursor:pointer;-webkit-tap-highlight-color:transparent;border-radius:.125rem;font-size:var(--mdui-typescale-label-large-size);font-weight:var(--mdui-typescale-label-large-weight);letter-spacing:var(--mdui-typescale-label-large-tracking);line-height:var(--mdui-typescale-label-large-line-height)}label{display:inline-flex;align-items:center;width:100%;cursor:inherit;-webkit-user-select:none;user-select:none;touch-action:manipulation;zoom:1;-webkit-user-drag:none}input{position:absolute;padding:0;opacity:0;pointer-events:none;width:1.125rem;height:1.125rem;margin:0 0 0 .6875rem}.icon{display:flex;position:absolute;opacity:1;transform:scale(1);color:rgb(var(--mdui-color-on-surface));font-size:1.5rem;transition:color var(--mdui-motion-duration-short4) var(--mdui-motion-easing-standard)}.checked-icon,.indeterminate-icon{opacity:0;transform:scale(.5);transition-property:color,opacity,transform;transition-duration:var(--mdui-motion-duration-short4);transition-timing-function:var(--mdui-motion-easing-standard)}.icon .i,::slotted([slot=checked-icon]),::slotted([slot=indeterminate-icon]),::slotted([slot=unchecked-icon]){color:inherit;font-size:inherit}i{position:relative;display:flex;align-items:center;justify-content:center;overflow:hidden;border-radius:50%;width:2.5rem;min-width:2.5rem;height:2.5rem;--mdui-comp-ripple-state-layer-color:var(--mdui-color-on-surface)}.label{display:flex;width:100%;padding-top:.625rem;padding-bottom:.625rem;color:rgb(var(--mdui-color-on-surface));transition:color var(--mdui-motion-duration-short4) var(--mdui-motion-easing-standard)}:host([checked]) i{--mdui-comp-ripple-state-layer-color:var(--mdui-color-primary)}:host([checked]) .icon{color:rgb(var(--mdui-color-primary))}:host([checked]) .indeterminate-icon{opacity:0;transform:scale(.5)}:host([checked]) .checked-icon{opacity:1;transform:scale(1)}:host([indeterminate]) i{--mdui-comp-ripple-state-layer-color:var(--mdui-color-primary)}:host([indeterminate]) .icon{color:rgb(var(--mdui-color-primary))}:host([indeterminate]) .checked-icon{opacity:0;transform:scale(.5)}:host([indeterminate]) .indeterminate-icon{opacity:1;transform:scale(1)}:host([invalid]) i{--mdui-comp-ripple-state-layer-color:var(--mdui-color-error)}:host([invalid]) .icon{color:rgb(var(--mdui-color-error))}:host([invalid]) .label{color:rgb(var(--mdui-color-error))}:host([disabled]){cursor:default;pointer-events:none}:host([disabled]) .icon{color:rgba(var(--mdui-color-on-surface),38%)}:host([disabled]) .label{color:rgba(var(--mdui-color-on-surface),38%)}:host([disabled][checked]) .unchecked-icon,:host([disabled][indeterminate]) .unchecked-icon{opacity:0}`;
2
+ export const style = css `:host{position:relative;display:inline-flex;cursor:pointer;-webkit-tap-highlight-color:transparent;border-radius:.125rem;font-size:var(--mdui-typescale-label-large-size);font-weight:var(--mdui-typescale-label-large-weight);letter-spacing:var(--mdui-typescale-label-large-tracking);line-height:var(--mdui-typescale-label-large-line-height)}label{display:inline-flex;align-items:center;width:100%;cursor:inherit;-webkit-user-select:none;user-select:none;touch-action:manipulation;zoom:1;-webkit-user-drag:none}input{position:absolute;padding:0;opacity:0;pointer-events:none;width:1.125rem;height:1.125rem;margin:0 0 0 .6875rem}.icon{display:flex;position:absolute;opacity:1;transform:scale(1);color:rgb(var(--mdui-color-on-surface));font-size:1.5rem;transition:color var(--mdui-motion-duration-short4) var(--mdui-motion-easing-standard)}.checked-icon,.indeterminate-icon{opacity:0;transform:scale(.5);transition-property:color,opacity,transform;transition-duration:var(--mdui-motion-duration-short4);transition-timing-function:var(--mdui-motion-easing-standard)}.icon .i,::slotted([slot=checked-icon]),::slotted([slot=indeterminate-icon]),::slotted([slot=unchecked-icon]){color:inherit;font-size:inherit}i{position:relative;display:flex;align-items:center;justify-content:center;overflow:hidden;border-radius:50%;width:2.5rem;min-width:2.5rem;height:2.5rem;--mdui-comp-ripple-state-layer-color:var(--mdui-color-on-surface)}.label{display:flex;width:100%;padding-top:.625rem;padding-bottom:.625rem;color:rgb(var(--mdui-color-on-surface));transition:color var(--mdui-motion-duration-short4) var(--mdui-motion-easing-standard)}:host([checked]) i{--mdui-comp-ripple-state-layer-color:var(--mdui-color-primary)}:host([checked]) .icon{color:rgb(var(--mdui-color-primary))}:host([checked]) .indeterminate-icon{opacity:0;transform:scale(.5)}:host([checked]) .checked-icon{opacity:1;transform:scale(1)}:host([indeterminate]) i{--mdui-comp-ripple-state-layer-color:var(--mdui-color-primary)}:host([indeterminate]) .icon{color:rgb(var(--mdui-color-primary))}:host([indeterminate]) .checked-icon{opacity:0;transform:scale(.5)}:host([indeterminate]) .indeterminate-icon{opacity:1;transform:scale(1)}.invalid i{--mdui-comp-ripple-state-layer-color:var(--mdui-color-error)}.invalid .icon{color:rgb(var(--mdui-color-error))}.invalid .label{color:rgb(var(--mdui-color-error))}:host([disabled]){cursor:default;pointer-events:none}:host([disabled]) .icon{color:rgba(var(--mdui-color-on-surface),38%)}:host([disabled]) .label{color:rgba(var(--mdui-color-on-surface),38%)}:host([disabled][checked]) .unchecked-icon,:host([disabled][indeterminate]) .unchecked-icon{opacity:0}`;
@@ -33,7 +33,7 @@ import type { CSSResultGroup, PropertyValues, TemplateResult } from 'lit';
33
33
  *
34
34
  * @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
35
35
  */
36
- export declare class Chip extends ButtonBase {
36
+ export declare class Chip extends ButtonBase<ChipEventMap> {
37
37
  static styles: CSSResultGroup;
38
38
  /**
39
39
  * 纸片形状。可选值为:
@@ -95,6 +95,13 @@ export declare class Chip extends ButtonBase {
95
95
  private renderDeleteIcon;
96
96
  private renderInner;
97
97
  }
98
+ export interface ChipEventMap {
99
+ focus: FocusEvent;
100
+ blur: FocusEvent;
101
+ invalid: CustomEvent<void>;
102
+ change: CustomEvent<void>;
103
+ delete: CustomEvent<void>;
104
+ }
98
105
  declare global {
99
106
  interface HTMLElementTagNameMap {
100
107
  'mdui-chip': Chip;
@@ -6,7 +6,6 @@ import cc from 'classcat';
6
6
  import { HasSlotController } from '@mdui/shared/controllers/has-slot.js';
7
7
  import { watch } from '@mdui/shared/decorators/watch.js';
8
8
  import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
9
- import { emit } from '@mdui/shared/helpers/event.js';
10
9
  import { nothingTemplate } from '@mdui/shared/helpers/template.js';
11
10
  import '@mdui/shared/icons/check.js';
12
11
  import '@mdui/shared/icons/clear.js';
@@ -42,7 +41,7 @@ import { style } from './style.js';
42
41
  *
43
42
  * @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
44
43
  */
45
- export let Chip = class Chip extends ButtonBase {
44
+ let Chip = class Chip extends ButtonBase {
46
45
  constructor() {
47
46
  super();
48
47
  /**
@@ -79,7 +78,7 @@ export let Chip = class Chip extends ButtonBase {
79
78
  return this.rippleRef.value;
80
79
  }
81
80
  onSelectedChange() {
82
- emit(this, 'change');
81
+ this.emit('change');
83
82
  }
84
83
  firstUpdated(changedProperties) {
85
84
  super.firstUpdated(changedProperties);
@@ -134,7 +133,7 @@ export let Chip = class Chip extends ButtonBase {
134
133
  }
135
134
  // 按下 Delete 或 BackSpace 键时,触发 delete 事件
136
135
  if (this.deletable && ['Delete', 'Backspace'].includes(event.key)) {
137
- emit(this, 'delete');
136
+ this.emit('delete');
138
137
  }
139
138
  }
140
139
  /**
@@ -142,7 +141,7 @@ export let Chip = class Chip extends ButtonBase {
142
141
  */
143
142
  onDelete(event) {
144
143
  event.stopPropagation();
145
- emit(this, 'delete');
144
+ this.emit('delete');
146
145
  }
147
146
  renderIcon() {
148
147
  if (this.loading) {
@@ -241,3 +240,4 @@ __decorate([
241
240
  Chip = __decorate([
242
241
  customElement('mdui-chip')
243
242
  ], Chip);
243
+ export { Chip };
@@ -1,4 +1,4 @@
1
- import { LitElement } from 'lit';
1
+ import { MduiElement } from '@mdui/shared/base/mdui-element.js';
2
2
  import type { CSSResultGroup, TemplateResult } from 'lit';
3
3
  /**
4
4
  * @summary 圆形进度指示器组件
@@ -7,7 +7,7 @@ import type { CSSResultGroup, TemplateResult } from 'lit';
7
7
  * <mdui-circular-progress></mdui-circular-progress>
8
8
  * ```
9
9
  */
10
- export declare class CircularProgress extends LitElement {
10
+ export declare class CircularProgress extends MduiElement<CircularProgressEventMap> {
11
11
  static styles: CSSResultGroup;
12
12
  /**
13
13
  * 进度指示器的最大值,默认为 1
@@ -21,6 +21,8 @@ export declare class CircularProgress extends LitElement {
21
21
  private renderDeterminate;
22
22
  private renderInDeterminate;
23
23
  }
24
+ export interface CircularProgressEventMap {
25
+ }
24
26
  declare global {
25
27
  interface HTMLElementTagNameMap {
26
28
  'mdui-circular-progress': CircularProgress;
@@ -1,8 +1,9 @@
1
1
  import { __decorate } from "tslib";
2
- import { html, LitElement } from 'lit';
2
+ import { html } from 'lit';
3
3
  import { customElement, property } from 'lit/decorators.js';
4
4
  import { classMap } from 'lit/directives/class-map.js';
5
5
  import { isUndefined } from '@mdui/jq/shared/helper.js';
6
+ import { MduiElement } from '@mdui/shared/base/mdui-element.js';
6
7
  import { componentStyle } from '@mdui/shared/lit-styles/component-style.js';
7
8
  import { style } from './style.js';
8
9
  /**
@@ -12,7 +13,7 @@ import { style } from './style.js';
12
13
  * <mdui-circular-progress></mdui-circular-progress>
13
14
  * ```
14
15
  */
15
- export let CircularProgress = class CircularProgress extends LitElement {
16
+ let CircularProgress = class CircularProgress extends MduiElement {
16
17
  constructor() {
17
18
  super(...arguments);
18
19
  /**
@@ -28,14 +29,13 @@ export let CircularProgress = class CircularProgress extends LitElement {
28
29
  })}">${isDeterminate ? this.renderDeterminate() : this.renderInDeterminate()}</div>`;
29
30
  }
30
31
  renderDeterminate() {
31
- var _a;
32
32
  const value = this.value;
33
33
  const strokeWidth = 4; // 圆环宽度
34
34
  const circleRadius = 18; // 圆环宽度中心点的半径
35
35
  const π = 3.1415926;
36
36
  const center = circleRadius + strokeWidth / 2;
37
37
  const circumference = 2 * π * circleRadius;
38
- const determinateStrokeDashOffset = (1 - value / Math.max((_a = this.max) !== null && _a !== void 0 ? _a : value, value)) * circumference;
38
+ const determinateStrokeDashOffset = (1 - value / Math.max(this.max ?? value, value)) * circumference;
39
39
  return html `<svg viewBox="0 0 ${center * 2} ${center * 2}"><circle class="track" cx="${center}" cy="${center}" r="${circleRadius}" stroke-width="${strokeWidth}"></circle><circle class="circle" cx="${center}" cy="${center}" r="${circleRadius}" stroke-dasharray="${2 * π * circleRadius}" stroke-dashoffset="${determinateStrokeDashOffset}" stroke-width="${strokeWidth}"></circle></svg>`;
40
40
  }
41
41
  renderInDeterminate() {
@@ -59,3 +59,4 @@ __decorate([
59
59
  CircularProgress = __decorate([
60
60
  customElement('mdui-circular-progress')
61
61
  ], CircularProgress);
62
+ export { CircularProgress };
@@ -1,2 +1,2 @@
1
1
  import { css } from 'lit';
2
- export const collapseItemStyle = css `:host{display:flex;flex-direction:column}.header{display:block}.body{display:block;overflow:hidden;transition:height var(--mdui-motion-duration-short4) var(--mdui-motion-easing-emphasized)}.body.opened{overflow:visible}:host([active]) .body{transition-duration:var(--mdui-motion-duration-medium4)}`;
2
+ export const collapseItemStyle = css `:host{display:flex;flex-direction:column}.header{display:block}.body{display:block;overflow:hidden;transition:height var(--mdui-motion-duration-short4) var(--mdui-motion-easing-emphasized)}.body.opened{overflow:visible}.body.active{transition-duration:var(--mdui-motion-duration-medium4)}`;
@@ -1,6 +1,5 @@
1
- import { LitElement } from 'lit';
2
1
  import '@mdui/jq/methods/height.js';
3
- import '@mdui/jq/methods/on.js';
2
+ import { MduiElement } from '@mdui/shared/base/mdui-element.js';
4
3
  import type { JQ } from '@mdui/jq/shared/core.js';
5
4
  import type { CSSResultGroup, TemplateResult, PropertyValues } from 'lit';
6
5
  /**
@@ -24,7 +23,7 @@ import type { CSSResultGroup, TemplateResult, PropertyValues } from 'lit';
24
23
  * @csspart header - 折叠面板的头部内容
25
24
  * @csspart body - 折叠面板的正文内容
26
25
  */
27
- export declare class CollapseItem extends LitElement {
26
+ export declare class CollapseItem extends MduiElement<CollapseItemEventMap> {
28
27
  static styles: CSSResultGroup;
29
28
  /**
30
29
  * 该折叠面板项的值
@@ -47,10 +46,23 @@ export declare class CollapseItem extends LitElement {
47
46
  */
48
47
  protected active: boolean;
49
48
  private state;
49
+ protected isInitial: boolean;
50
50
  protected readonly key: number;
51
51
  private readonly bodyRef;
52
52
  private onActiveChange;
53
53
  protected firstUpdated(changedProperties: PropertyValues): void;
54
54
  protected render(): TemplateResult;
55
+ private onTransitionEnd;
55
56
  private updateBodyHeight;
56
57
  }
58
+ export interface CollapseItemEventMap {
59
+ open: CustomEvent<void>;
60
+ opened: CustomEvent<void>;
61
+ close: CustomEvent<void>;
62
+ closed: CustomEvent<void>;
63
+ }
64
+ declare global {
65
+ interface HTMLElementTagNameMap {
66
+ 'mdui-collapse-item': CollapseItem;
67
+ }
68
+ }
@@ -1,14 +1,13 @@
1
1
  import { __decorate } from "tslib";
2
- import { html, LitElement } from 'lit';
2
+ import { html } from 'lit';
3
3
  import { customElement, property, state } from 'lit/decorators.js';
4
4
  import { classMap } from 'lit/directives/class-map.js';
5
5
  import { createRef, ref } from 'lit/directives/ref.js';
6
6
  import { $ } from '@mdui/jq/$.js';
7
7
  import '@mdui/jq/methods/height.js';
8
- import '@mdui/jq/methods/on.js';
8
+ import { MduiElement } from '@mdui/shared/base/mdui-element.js';
9
9
  import { watch } from '@mdui/shared/decorators/watch.js';
10
10
  import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
11
- import { emit } from '@mdui/shared/helpers/event.js';
12
11
  import { uniqueId } from '@mdui/shared/helpers/uniqueId.js';
13
12
  import { componentStyle } from '@mdui/shared/lit-styles/component-style.js';
14
13
  import { collapseItemStyle } from './collapse-item-style.js';
@@ -33,7 +32,7 @@ import { collapseItemStyle } from './collapse-item-style.js';
33
32
  * @csspart header - 折叠面板的头部内容
34
33
  * @csspart body - 折叠面板的正文内容
35
34
  */
36
- export let CollapseItem = class CollapseItem extends LitElement {
35
+ let CollapseItem = class CollapseItem extends MduiElement {
37
36
  constructor() {
38
37
  super(...arguments);
39
38
  /**
@@ -45,34 +44,41 @@ export let CollapseItem = class CollapseItem extends LitElement {
45
44
  */
46
45
  this.active = false;
47
46
  this.state = 'closed';
47
+ // 是否是初始状态,不显示动画
48
+ this.isInitial = true;
48
49
  // 每一个 `collapse-item` 元素都添加一个唯一的 key
49
50
  this.key = uniqueId();
50
51
  this.bodyRef = createRef();
51
52
  }
52
53
  onActiveChange() {
53
- if (this.hasUpdated) {
54
- this.state = this.active ? 'open' : 'close';
55
- emit(this, this.state);
56
- this.updateBodyHeight();
54
+ if (this.isInitial) {
55
+ this.state = this.active ? 'opened' : 'closed';
56
+ if (this.hasUpdated) {
57
+ this.updateBodyHeight();
58
+ }
57
59
  }
58
60
  else {
59
- this.state = this.active ? 'opened' : 'closed';
61
+ this.state = this.active ? 'open' : 'close';
62
+ this.emit(this.state);
63
+ this.updateBodyHeight();
60
64
  }
61
65
  }
62
66
  firstUpdated(changedProperties) {
63
67
  super.firstUpdated(changedProperties);
64
- $(this.bodyRef.value).on('transitionend', (e) => {
65
- const event = e;
66
- if (event.target === this.bodyRef.value) {
67
- this.state = this.active ? 'opened' : 'closed';
68
- emit(this, this.state);
69
- this.updateBodyHeight();
70
- }
71
- });
72
68
  this.updateBodyHeight();
73
69
  }
74
70
  render() {
75
- return html `<slot name="header" part="header" class="header">${this.header}</slot><slot part="body" class="body ${classMap({ opened: this.state === 'opened' })}" ${ref(this.bodyRef)}></slot>`;
71
+ return html `<slot name="header" part="header" class="header">${this.header}</slot><slot part="body" class="body ${classMap({
72
+ opened: this.state === 'opened',
73
+ active: this.active,
74
+ })}" ${ref(this.bodyRef)} @transitionend="${this.onTransitionEnd}"></slot>`;
75
+ }
76
+ onTransitionEnd(event) {
77
+ if (event.target === this.bodyRef.value) {
78
+ this.state = this.active ? 'opened' : 'closed';
79
+ this.emit(this.state);
80
+ this.updateBodyHeight();
81
+ }
76
82
  }
77
83
  updateBodyHeight() {
78
84
  const scrollHeight = this.bodyRef.value.scrollHeight;
@@ -109,11 +115,7 @@ __decorate([
109
115
  property()
110
116
  ], CollapseItem.prototype, "trigger", void 0);
111
117
  __decorate([
112
- property({
113
- type: Boolean,
114
- reflect: true,
115
- converter: booleanConverter,
116
- })
118
+ state()
117
119
  ], CollapseItem.prototype, "active", void 0);
118
120
  __decorate([
119
121
  state()
@@ -124,3 +126,4 @@ __decorate([
124
126
  CollapseItem = __decorate([
125
127
  customElement('mdui-collapse-item')
126
128
  ], CollapseItem);
129
+ export { CollapseItem };
@@ -1,7 +1,5 @@
1
- import { LitElement } from 'lit';
2
- import '@mdui/jq/methods/find.js';
3
- import '@mdui/jq/methods/get.js';
4
1
  import '@mdui/jq/methods/is.js';
2
+ import { MduiElement } from '@mdui/shared/base/mdui-element.js';
5
3
  import type { CSSResultGroup, TemplateResult } from 'lit';
6
4
  /**
7
5
  * @summary 折叠面板组件。需与 `<mdui-collapse-item>` 组件配合使用
@@ -17,7 +15,7 @@ import type { CSSResultGroup, TemplateResult } from 'lit';
17
15
  *
18
16
  * @slot - `<mdui-collapse-item>` 组件
19
17
  */
20
- export declare class Collapse extends LitElement {
18
+ export declare class Collapse extends MduiElement<CollapseEventMap> {
21
19
  static styles: CSSResultGroup;
22
20
  /**
23
21
  * 是否为手风琴模式
@@ -37,13 +35,23 @@ export declare class Collapse extends LitElement {
37
35
  */
38
36
  disabled: boolean;
39
37
  private activeKeys;
40
- private items;
38
+ private readonly items;
39
+ private isInitial;
40
+ private definedController;
41
41
  private onActiveKeysChange;
42
42
  private onValueChange;
43
- connectedCallback(): void;
44
43
  protected render(): TemplateResult;
45
- private syncItems;
44
+ private setActiveKeys;
45
+ private setValue;
46
46
  private onClick;
47
47
  private onSlotChange;
48
- private updateActive;
48
+ private updateItems;
49
+ }
50
+ export interface CollapseEventMap {
51
+ change: CustomEvent<void>;
52
+ }
53
+ declare global {
54
+ interface HTMLElementTagNameMap {
55
+ 'mdui-collapse': Collapse;
56
+ }
49
57
  }
@@ -1,14 +1,14 @@
1
1
  import { __decorate } from "tslib";
2
- import { html, LitElement } from 'lit';
3
- import { customElement, property, state } from 'lit/decorators.js';
2
+ import { html } from 'lit';
3
+ import { customElement, property, queryAssignedElements, state, } from 'lit/decorators.js';
4
4
  import { $ } from '@mdui/jq/$.js';
5
- import '@mdui/jq/methods/find.js';
6
- import '@mdui/jq/methods/get.js';
7
5
  import '@mdui/jq/methods/is.js';
8
- import { isElement } from '@mdui/jq/shared/helper.js';
6
+ import { isElement, isUndefined } from '@mdui/jq/shared/helper.js';
7
+ import { MduiElement } from '@mdui/shared/base/mdui-element.js';
8
+ import { DefinedController } from '@mdui/shared/controllers/defined.js';
9
9
  import { watch } from '@mdui/shared/decorators/watch.js';
10
+ import { arraysEqualIgnoreOrder } from '@mdui/shared/helpers/array.js';
10
11
  import { booleanConverter } from '@mdui/shared/helpers/decorator.js';
11
- import { emit } from '@mdui/shared/helpers/event.js';
12
12
  import { componentStyle } from '@mdui/shared/lit-styles/component-style.js';
13
13
  import { collapseStyle } from './collapse-style.js';
14
14
  /**
@@ -25,7 +25,7 @@ import { collapseStyle } from './collapse-style.js';
25
25
  *
26
26
  * @slot - `<mdui-collapse-item>` 组件
27
27
  */
28
- export let Collapse = class Collapse extends LitElement {
28
+ let Collapse = class Collapse extends MduiElement {
29
29
  constructor() {
30
30
  super(...arguments);
31
31
  /**
@@ -38,53 +38,67 @@ export let Collapse = class Collapse extends LitElement {
38
38
  this.disabled = false;
39
39
  // 因为 collapse-item 的 value 可能会重复,所以在每个 collapse-item 元素上都添加了一个唯一的 key,通过 activeKey 来记录激活状态的 key
40
40
  this.activeKeys = [];
41
- this.items = [];
41
+ // 是否是初始状态,初始状态不触发 change 事件,没有动画
42
+ this.isInitial = true;
43
+ this.definedController = new DefinedController(this, {
44
+ relatedElements: ['mdui-collapse-item'],
45
+ });
42
46
  }
43
- onActiveKeysChange() {
44
- var _a;
47
+ async onActiveKeysChange() {
48
+ await this.definedController.whenDefined();
45
49
  // 根据 activeKeys 读取对应 collapse-item 的值
46
- this.value = this.accordion
47
- ? (_a = this.items.find((item) => this.activeKeys.includes(item.key))) === null || _a === void 0 ? void 0 : _a.value
50
+ const value = this.accordion
51
+ ? this.items.find((item) => this.activeKeys.includes(item.key))?.value
48
52
  : this.items
49
53
  .filter((item) => this.activeKeys.includes(item.key))
50
54
  .map((item) => item.value);
51
- emit(this, 'change');
55
+ this.setValue(value);
56
+ if (!this.isInitial) {
57
+ this.emit('change');
58
+ }
52
59
  }
53
- onValueChange() {
60
+ async onValueChange() {
61
+ this.isInitial = !this.hasUpdated;
62
+ await this.definedController.whenDefined();
54
63
  if (this.accordion) {
55
64
  const value = this.value;
56
65
  if (!value) {
57
- this.activeKeys = [];
66
+ this.setActiveKeys([]);
58
67
  }
59
68
  else {
60
69
  const item = this.items.find((item) => item.value === value);
61
- this.activeKeys = item ? [item.key] : [];
70
+ this.setActiveKeys(item ? [item.key] : []);
62
71
  }
63
72
  }
64
73
  else {
65
74
  const value = this.value;
66
75
  if (!value.length) {
67
- this.activeKeys = [];
76
+ this.setActiveKeys([]);
68
77
  }
69
78
  else {
70
- this.activeKeys = this.items
79
+ const activeKeys = this.items
71
80
  .filter((item) => value.includes(item.value))
72
81
  .map((item) => item.key);
82
+ this.setActiveKeys(activeKeys);
73
83
  }
74
84
  }
75
- this.updateActive();
76
- }
77
- connectedCallback() {
78
- super.connectedCallback();
79
- this.syncItems();
85
+ this.updateItems();
80
86
  }
81
87
  render() {
82
88
  return html `<slot @slotchange="${this.onSlotChange}" @click="${this.onClick}"></slot>`;
83
89
  }
84
- syncItems() {
85
- this.items = $(this)
86
- .find('mdui-collapse-item')
87
- .get();
90
+ setActiveKeys(activeKeys) {
91
+ if (!arraysEqualIgnoreOrder(this.activeKeys, activeKeys)) {
92
+ this.activeKeys = activeKeys;
93
+ }
94
+ }
95
+ setValue(value) {
96
+ if (this.accordion || isUndefined(this.value) || isUndefined(value)) {
97
+ this.value = value;
98
+ }
99
+ else if (!arraysEqualIgnoreOrder(this.value, value)) {
100
+ this.value = value;
101
+ }
88
102
  }
89
103
  onClick(event) {
90
104
  // 全部禁用
@@ -95,10 +109,10 @@ export let Collapse = class Collapse extends LitElement {
95
109
  if (event.button) {
96
110
  return;
97
111
  }
98
- // collapse-item 被禁用,忽略
99
112
  const target = event.target;
100
113
  const item = target.closest('mdui-collapse-item');
101
- if (item.disabled) {
114
+ // collapse-item 被禁用,忽略
115
+ if (!item || item.disabled) {
102
116
  return;
103
117
  }
104
118
  const path = event.composedPath();
@@ -113,10 +127,10 @@ export let Collapse = class Collapse extends LitElement {
113
127
  }
114
128
  if (this.accordion) {
115
129
  if (this.activeKeys.includes(item.key)) {
116
- this.activeKeys = [];
130
+ this.setActiveKeys([]);
117
131
  }
118
132
  else {
119
- this.activeKeys = [item.key];
133
+ this.setActiveKeys([item.key]);
120
134
  }
121
135
  }
122
136
  else {
@@ -128,16 +142,21 @@ export let Collapse = class Collapse extends LitElement {
128
142
  else {
129
143
  activeKeys.push(item.key);
130
144
  }
131
- this.activeKeys = activeKeys;
145
+ this.setActiveKeys(activeKeys);
132
146
  }
133
- this.updateActive();
147
+ this.isInitial = false;
148
+ this.updateItems();
134
149
  }
135
- onSlotChange() {
136
- this.syncItems();
137
- this.updateActive();
150
+ async onSlotChange() {
151
+ await this.definedController.whenDefined();
152
+ this.updateItems();
138
153
  }
139
- updateActive() {
140
- this.items.forEach((item) => (item.active = this.activeKeys.includes(item.key)));
154
+ // 更新 <mdui-collapse-item> 的状态
155
+ updateItems() {
156
+ this.items.forEach((item) => {
157
+ item.active = this.activeKeys.includes(item.key);
158
+ item.isInitial = this.isInitial;
159
+ });
141
160
  }
142
161
  };
143
162
  Collapse.styles = [
@@ -164,6 +183,9 @@ __decorate([
164
183
  __decorate([
165
184
  state()
166
185
  ], Collapse.prototype, "activeKeys", void 0);
186
+ __decorate([
187
+ queryAssignedElements({ selector: 'mdui-collapse-item', flatten: true })
188
+ ], Collapse.prototype, "items", void 0);
167
189
  __decorate([
168
190
  watch('activeKeys', true)
169
191
  ], Collapse.prototype, "onActiveKeysChange", null);
@@ -173,3 +195,4 @@ __decorate([
173
195
  Collapse = __decorate([
174
196
  customElement('mdui-collapse')
175
197
  ], Collapse);
198
+ export { Collapse };