litos-ui 0.16.2 → 0.17.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/base.d.ts CHANGED
@@ -1,13 +1,21 @@
1
- export default class BaseComponent extends HTMLElement {
1
+ export default class BaseComponent<T = Record<string, any>> extends HTMLElement {
2
2
  static baseName: string;
3
3
  /** 组件是否渲染完成, 是否已经调用 connectedCallback */
4
4
  rendered: boolean;
5
+ protected _state: T;
6
+ protected _pendingUpdate: boolean;
7
+ protected _pendingTask?: number;
8
+ protected _changedProperties: Set<string>;
5
9
  constructor(shadow?: boolean, init?: Partial<ShadowRootInit>);
6
10
  /**
7
11
  * 返回一个数组,表示观察的属性列表
8
12
  */
9
13
  static get observedAttributes(): string[] | undefined | null;
10
- attributeChangedCallback(_name: string, _oldValue: string, _newValue: string): void;
14
+ attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
15
+ protected attributeChanged(name: string, oldValue: string, newValue: string): void;
16
+ cancelPending(): void;
17
+ batchUpdate(): void;
18
+ protected updateDOM(changedProps: Set<string>): void;
11
19
  /** @deprecated */
12
20
  get shadow(): ShadowRoot;
13
21
  get root(): ShadowRoot | HTMLElement;
@@ -52,4 +60,5 @@ export default class BaseComponent extends HTMLElement {
52
60
  * @returns 是否成功触发事件
53
61
  */
54
62
  emit(name: string, eventOption?: Partial<CustomEventInit>): boolean;
63
+ emitInject(name: string, callback: (context: Signal<any>) => void): void;
55
64
  }
package/lib/base.js CHANGED
@@ -1,10 +1,18 @@
1
- import { getAttr as r } from "ph-utils/dom";
2
- class i extends HTMLElement {
1
+ import { getAttr as i } from "ph-utils/dom";
2
+ class a extends HTMLElement {
3
3
  static baseName = "base-component";
4
4
  /** 组件是否渲染完成, 是否已经调用 connectedCallback */
5
- rendered = !1;
6
- constructor(t = !0, e = {}) {
7
- super(), this.rendered = !1, t && this.attachShadow({ mode: "open", ...e });
5
+ rendered;
6
+ // state
7
+ _state;
8
+ // 是否正在批量更新
9
+ _pendingUpdate;
10
+ _pendingTask;
11
+ // 延迟任务id
12
+ _changedProperties;
13
+ // 已改变的属性集合
14
+ constructor(e = !0, t = {}) {
15
+ super(), this.rendered = !1, this._state = {}, this._pendingUpdate = !1, this._changedProperties = /* @__PURE__ */ new Set(), e && this.attachShadow({ mode: "open", ...t });
8
16
  }
9
17
  /**
10
18
  * 返回一个数组,表示观察的属性列表
@@ -13,7 +21,21 @@ class i extends HTMLElement {
13
21
  return [];
14
22
  }
15
23
  // 当属性发生变化时调用的回调函数
16
- attributeChangedCallback(t, e, s) {
24
+ attributeChangedCallback(e, t, n) {
25
+ t !== n && (this.attributeChanged(e, t, n), this._changedProperties.add(e), this.rendered && this.batchUpdate());
26
+ }
27
+ attributeChanged(e, t, n) {
28
+ }
29
+ cancelPending() {
30
+ this._pendingTask && (cancelAnimationFrame(this._pendingTask), this._pendingTask = void 0, this._pendingUpdate = !1);
31
+ }
32
+ batchUpdate() {
33
+ this._pendingUpdate || (this.cancelPending(), this._pendingUpdate = !0, requestAnimationFrame(() => {
34
+ const e = new Set(this._changedProperties);
35
+ this._changedProperties.clear(), this.updateDOM(e), this._pendingUpdate = !1;
36
+ }));
37
+ }
38
+ updateDOM(e) {
17
39
  }
18
40
  /** @deprecated */
19
41
  get shadow() {
@@ -22,33 +44,33 @@ class i extends HTMLElement {
22
44
  get root() {
23
45
  return this.shadowRoot || this;
24
46
  }
25
- createStyle(t) {
26
- const e = document.createElement("style");
27
- e.textContent = t.trim(), this.root.appendChild(e);
47
+ createStyle(e) {
48
+ const t = document.createElement("style");
49
+ t.textContent = e.trim(), this.root.appendChild(t);
28
50
  }
29
- createLink(t) {
30
- const e = document.createElement("link");
31
- e.rel = "stylesheet", e.href = t, this.root.appendChild(e);
51
+ createLink(e) {
52
+ const t = document.createElement("link");
53
+ t.rel = "stylesheet", t.href = e, this.root.appendChild(t);
32
54
  }
33
- loadStyleText(t) {
34
- let e = t;
35
- Array.isArray(e) && (e = e.join("")), this.createStyle(e);
55
+ loadStyleText(e) {
56
+ let t = e;
57
+ Array.isArray(t) && (t = t.join("")), this.createStyle(t);
36
58
  }
37
- getAttr(t, e) {
38
- return r(this, t, e);
59
+ getAttr(e, t) {
60
+ return i(this, e, t);
39
61
  }
40
- appendToRoot(t) {
41
- if (t)
42
- if (typeof t == "string") {
43
- let e = document.createElement("div");
44
- e.innerHTML = t, this.root.append(...e.childNodes), e = void 0;
45
- } else t.length ? this.root.append(...t) : this.root.append(t);
62
+ appendToRoot(e) {
63
+ if (e)
64
+ if (typeof e == "string") {
65
+ let t = document.createElement("div");
66
+ t.innerHTML = e, this.root.append(...t.childNodes), t = void 0;
67
+ } else e.length ? this.root.append(...e) : this.root.append(e);
46
68
  }
47
69
  connectedCallback() {
48
70
  this.appendToRoot(this.render()), this.rendered = !0, this.initEvents(), this.afterInit();
49
71
  }
50
72
  disconnectedCallback() {
51
- this.removeEvents(), this.beforeDestroy(), this.root.innerHTML = "", this.rendered = !1;
73
+ this.cancelPending(), this.removeEvents(), this.beforeDestroy(), this.root.innerHTML = "", this.rendered = !1;
52
74
  }
53
75
  render() {
54
76
  }
@@ -75,12 +97,22 @@ class i extends HTMLElement {
75
97
  * @param eventOption 自定义事件配置选项, 默认: bubbles: true
76
98
  * @returns 是否成功触发事件
77
99
  */
78
- emit(t, e) {
100
+ emit(e, t) {
79
101
  return this.dispatchEvent(
80
- new CustomEvent(t, { bubbles: !0, composed: !1, ...e })
102
+ new CustomEvent(e, { bubbles: !0, composed: !1, ...t })
81
103
  );
82
104
  }
105
+ emitInject(e, t) {
106
+ this.emit(e, {
107
+ bubbles: !0,
108
+ composed: !0,
109
+ detail: {
110
+ context: e,
111
+ callback: t
112
+ }
113
+ });
114
+ }
83
115
  }
84
116
  export {
85
- i as default
117
+ a as default
86
118
  };
@@ -1,13 +1,28 @@
1
1
  import BaseComponent from "../base";
2
- export default class Button extends BaseComponent {
2
+ type ButtonState = {
3
+ loading: boolean;
4
+ htmlType: string;
5
+ text: boolean;
6
+ ghost: boolean;
7
+ color?: string;
8
+ height?: string;
9
+ disabled: boolean;
10
+ type: "normal" | "primary";
11
+ shape: "default" | "round" | "circle";
12
+ loadingText: string;
13
+ };
14
+ export default class Button extends BaseComponent<ButtonState> {
3
15
  static baseName: string;
4
16
  _disabled: boolean;
17
+ $btn?: HTMLButtonElement;
18
+ constructor();
5
19
  get disabled(): boolean;
6
20
  set disabled(value: boolean);
7
21
  setLoading(loading: boolean): void;
8
22
  setDisabled(value: boolean): void;
9
23
  static get observedAttributes(): string[];
10
- attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
24
+ protected attributeChanged(name: string, _oldValue: string, newValue: string): void;
25
+ protected updateDOM(changedProps: Set<string>): void;
11
26
  connectedCallback(): void;
12
27
  disconnectedCallback(): void;
13
28
  isFormButton(): boolean;
@@ -17,5 +32,5 @@ export default class Button extends BaseComponent {
17
32
  applyColor(color: string, text?: boolean, ghost?: boolean): string;
18
33
  private _updateHeight;
19
34
  private _handleClick;
20
- private _getForm;
21
35
  }
36
+ export {};
@@ -1,13 +1,26 @@
1
- import { initAttr as c, parseAttrValue as s } from "../utils/index.js";
1
+ import { kebabToCamel as b, parseAttrValue as d, initAttr as c } from "../utils/index.js";
2
2
  import h from "../base.js";
3
- import { $one as b, addClass as g, removeClass as f, on as p, off as v, formatClass as u, formatStyle as m, getAttr as k } from "ph-utils/dom";
4
- import { adjust as d } from "ph-utils/color";
5
- import { a as x } from "../animation-DttknHkX.js";
6
- const y = ":host{--l-btn-padding: 0 15px;--l-btn-text-color: #ffffff;--l-btn-hover-text-color: var(--l-btn-text-color);--l-btn-active-text-color: var(--l-btn-text-color);--l-btn-border-color: var(--l-primary-color, #722ed1);--l-btn-background: var(--l-btn-border-color);--l-btn-hover-border-color: var(--l-primary-color-light1, #9254de);--l-btn-hover-background: var(--l-btn-hover-border-color);--l-btn-active-border-color: var(--l-primary-color-dark1, #531dab);--l-btn-active-background: var(--l-btn-active-border-color);--l-btn-disabled-color: #c9c9c9;--l-btn-disabled-background: #fbfbfb;--l-btn-disabled-border-color: #e6e6e6;--l-btn-height: var(--l-form-control-height, 32px);display:inline-flex;width:auto;height:var(--l-btn-height);text-indent:0;box-sizing:border-box;border-radius:var(--l-border-radius, 3px)}:host([block]){width:100%}.l-btn{width:100%;display:inline-flex;justify-content:center;align-items:center;cursor:pointer;outline:none;box-sizing:border-box;vertical-align:middle;padding:var(--l-btn-padding);line-height:1;height:100%;border-radius:inherit;color:var(--l-btn-text-color);background:var(--l-btn-background);border:1px solid var(--l-btn-border-color);position:relative;gap:var(--l-btn-gap, 5px);font-size:inherit;transition:border-color .3s,background-color .3s,color .3s}.l-btn:hover{border-color:var(--l-btn-hover-border-color, var(--l-btn-hover-background));color:var(--l-btn-hover-text-color);background:var(--l-btn-hover-background)}.l-btn:active{border-color:var(--l-btn-active-border-color, var(--l-btn-active-background));color:var(--l-btn-active-text-color);background:var(--l-btn-active-background)}.l-btn-normal{--l-btn-text-color: auto;--l-btn-background: transparent;--l-btn-border-color: #d9d9d9;--l-btn-hover-text-color: var(--l-primary-color-light1, #9254de);--l-btn-active-text-color: var(--l-primary-color-dark1, #531dab);--l-btn-hover-background: #fff;--l-btn-active-background: #fff;--l-btn-hover-border-color: var(--l-btn-hover-text-color);--l-btn-active-border-color: var(--l-btn-active-text-color)}.l-btn-primary{--l-btn-background: var(--l-primary-color, #722ed1);--l-btn-hover-background: var(--l-primary-color-light1, #9254de);--l-btn-active-background: var(--l-primary-color-dark1, #531dab);--l-btn-disabled-border-color: var(--l-primary-color-light2, #b37feb);--l-btn-disabled-background: var(--l-primary-color-light2, #b37feb);--l-btn-disabled-color: #ffffff}.l-btn:disabled{border-color:var(--l-btn-disabled-border-color);background:var(--l-btn-disabled-background);color:var(--l-btn-disabled-color);cursor:not-allowed;opacity:1}.l-btn.l-btn-loading{cursor:default}.l-btn-text{--l-btn-background: transparent;--l-btn-border-color: transparent;--l-btn-hover-border-color: transparent;--l-btn-active-border-color: transparent;--l-btn-disabled-background: transparent;--l-btn-disabled-border-color: transparent;--l-btn-hover-background: transparent;--l-btn-active-background: transparent;--l-btn-padding: 5px}.l-btn-primary.l-btn-text{--l-btn-text-color: var(--l-primary-color, #722ed1);--l-btn-hover-text-color: var(--l-primary-color-light1, #9254de);--l-btn-active-text-color: var(--l-primary-color-dark1, #531dab)}.l-btn-ghost{--l-btn-text-color: var(--l-btn-border-color);--l-btn-background: transparent;--l-btn-hover-background: transparent;--l-btn-active-background: transparent;--l-btn-hover-text-color: var(--l-btn-hover-border-color);--l-btn-active-text-color: var(--l-btn-active-border-color)}.l-btn-round{border-radius:calc(var(--l-form-control-height, 32px) / 2)}.l-btn-circle{border-radius:50%;width:var(--l-form-control-height, 32px);padding:0}.l-btn:not(.l-btn-text)+.l-btn{margin-left:10px}html.dark .l-btn:disabled{--l-btn-disabled-background: rgba(255, 255, 255, .08);--l-btn-disabled-color: rgba(255, 255, 255, .3);--l-btn-disabled-border-color: rgba(255, 255, 255, .3)}";
7
- class H extends h {
3
+ import { addClass as p, removeClass as g, on as v, off as f, formatClass as u, formatStyle as m } from "ph-utils/dom";
4
+ import { adjust as i } from "ph-utils/color";
5
+ import { a as k } from "../animation-DttknHkX.js";
6
+ const x = ":host{--l-btn-padding: 0 15px;--l-btn-text-color: #ffffff;--l-btn-hover-text-color: var(--l-btn-text-color);--l-btn-active-text-color: var(--l-btn-text-color);--l-btn-border-color: var(--l-primary-color, #722ed1);--l-btn-background: var(--l-btn-border-color);--l-btn-hover-border-color: var(--l-primary-color-light1, #9254de);--l-btn-hover-background: var(--l-btn-hover-border-color);--l-btn-active-border-color: var(--l-primary-color-dark1, #531dab);--l-btn-active-background: var(--l-btn-active-border-color);--l-btn-disabled-color: #c9c9c9;--l-btn-disabled-background: #fbfbfb;--l-btn-disabled-border-color: #e6e6e6;--l-btn-height: var(--l-form-control-height, 32px);display:inline-flex;width:auto;height:var(--l-btn-height);text-indent:0;box-sizing:border-box;border-radius:var(--l-border-radius, 3px)}:host([block]){width:100%}.l-btn{width:100%;display:inline-flex;justify-content:center;align-items:center;cursor:pointer;outline:none;box-sizing:border-box;vertical-align:middle;padding:var(--l-btn-padding);line-height:1;height:100%;border-radius:inherit;color:var(--l-btn-text-color);background:var(--l-btn-background);border:1px solid var(--l-btn-border-color);position:relative;gap:var(--l-btn-gap, 5px);font-size:inherit;transition:border-color .3s,background-color .3s,color .3s}.l-btn:hover{border-color:var(--l-btn-hover-border-color, var(--l-btn-hover-background));color:var(--l-btn-hover-text-color);background:var(--l-btn-hover-background)}.l-btn:active{border-color:var(--l-btn-active-border-color, var(--l-btn-active-background));color:var(--l-btn-active-text-color);background:var(--l-btn-active-background)}.l-btn-normal{--l-btn-text-color: auto;--l-btn-background: transparent;--l-btn-border-color: #d9d9d9;--l-btn-hover-text-color: var(--l-primary-color-light1, #9254de);--l-btn-active-text-color: var(--l-primary-color-dark1, #531dab);--l-btn-hover-background: #fff;--l-btn-active-background: #fff;--l-btn-hover-border-color: var(--l-btn-hover-text-color);--l-btn-active-border-color: var(--l-btn-active-text-color)}.l-btn-primary{--l-btn-background: var(--l-primary-color, #722ed1);--l-btn-hover-background: var(--l-primary-color-light1, #9254de);--l-btn-active-background: var(--l-primary-color-dark1, #531dab);--l-btn-disabled-border-color: var(--l-primary-color-light2, #b37feb);--l-btn-disabled-background: var(--l-primary-color-light2, #b37feb);--l-btn-disabled-color: #ffffff}.l-btn:disabled{border-color:var(--l-btn-disabled-border-color);background:var(--l-btn-disabled-background);color:var(--l-btn-disabled-color);cursor:not-allowed;opacity:1}.l-btn.l-btn-loading{cursor:default}.l-btn-text{--l-btn-background: transparent;--l-btn-border-color: transparent;--l-btn-hover-border-color: transparent;--l-btn-active-border-color: transparent;--l-btn-disabled-background: transparent;--l-btn-disabled-border-color: transparent;--l-btn-hover-background: transparent;--l-btn-active-background: transparent;--l-btn-padding: 5px}.l-btn-primary.l-btn-text{--l-btn-text-color: var(--l-primary-color, #722ed1);--l-btn-hover-text-color: var(--l-primary-color-light1, #9254de);--l-btn-active-text-color: var(--l-primary-color-dark1, #531dab)}.l-btn-ghost{--l-btn-text-color: var(--l-btn-border-color);--l-btn-background: transparent;--l-btn-hover-background: transparent;--l-btn-active-background: transparent;--l-btn-hover-text-color: var(--l-btn-hover-border-color);--l-btn-active-text-color: var(--l-btn-active-border-color)}.l-btn-round{border-radius:calc(var(--l-form-control-height, 32px) / 2)}.l-btn-circle{border-radius:50%;width:var(--l-form-control-height, 32px);padding:0}.l-btn:not(.l-btn-text)+.l-btn{margin-left:10px}html.dark .l-btn:disabled{--l-btn-disabled-background: rgba(255, 255, 255, .08);--l-btn-disabled-color: rgba(255, 255, 255, .3);--l-btn-disabled-border-color: rgba(255, 255, 255, .3)}";
7
+ class B extends h {
8
8
  static baseName = "button";
9
9
  // public htmlType: "submit" | "reset" | "button" = "button";
10
10
  _disabled = !1;
11
+ $btn;
12
+ constructor() {
13
+ super(), this._state = {
14
+ loading: !1,
15
+ htmlType: "button",
16
+ text: !1,
17
+ ghost: !1,
18
+ disabled: !1,
19
+ type: "normal",
20
+ shape: "default",
21
+ loadingText: "加载中……"
22
+ };
23
+ }
11
24
  get disabled() {
12
25
  return this._disabled;
13
26
  }
@@ -15,110 +28,95 @@ class H extends h {
15
28
  this.setDisabled(t);
16
29
  }
17
30
  setLoading(t) {
18
- const r = b(".l-btn", this.root);
19
- r && (t ? (g(r, "l-btn-loading"), r.disabled = !0, r.innerHTML = this.loadingBody()) : (f(r, "l-btn-loading"), r.disabled = this.disabled, r.innerHTML = "<slot></slot>"));
31
+ this.$btn && (t ? (p(this.$btn, "l-btn-loading"), this.$btn.disabled = !0, this.$btn.innerHTML = this.loadingBody()) : (g(this.$btn, "l-btn-loading"), this.$btn.disabled = this.disabled, this.$btn.innerHTML = "<slot></slot>"));
20
32
  }
21
33
  setDisabled(t) {
22
- this._disabled = t;
23
- const r = b(".l-btn", this.root);
24
- r && (r.disabled = t);
34
+ this._disabled = t, this.$btn && (this.$btn.disabled = t);
25
35
  }
26
36
  // 初始化属性观察器
27
37
  static get observedAttributes() {
28
- return ["loading", "color", "disabled", "height"];
29
- }
30
- // 当属性发生变化时调用的回调函数
31
- attributeChangedCallback(t, r, o) {
32
- const e = b(".l-btn", this.root);
33
- if (e) {
34
- if (t === "loading") {
35
- const l = s(o, !1, t);
36
- this.setLoading(l);
37
- return;
38
- } else if (t === "color") {
39
- const l = this.getAttr("text", !1), a = this.getAttr("ghost", !1);
40
- e.style.cssText = this.applyColor(o, l, a);
41
- return;
42
- } else if (t === "disabled") {
43
- const l = s(o, !1, "disabled");
44
- this.setDisabled(l);
45
- return;
46
- }
38
+ return ["loading", "color", "text", "ghost", "disabled", "height", "html-type", "type", "shape", "loading-text"];
39
+ }
40
+ attributeChanged(t, r, o) {
41
+ switch (t) {
42
+ case "color":
43
+ case "height":
44
+ case "shape":
45
+ case "type":
46
+ this._state[t] = o;
47
+ break;
48
+ case "text":
49
+ case "ghost":
50
+ case "disabled":
51
+ case "loading":
52
+ this._state[t] = d(o, !1, t);
53
+ break;
54
+ case "html-type":
55
+ case "loading-text":
56
+ this._state[b(t)] = o;
57
+ break;
47
58
  }
48
- if (!this.rendered) return;
49
- const n = o.trim();
50
- t === "height" && this._updateHeight(n);
59
+ }
60
+ updateDOM(t) {
61
+ this.$btn && (t.has("loading") && this.setLoading(this._state.loading), t.has("disabled") && this.setDisabled(this.disabled), t.has("color") && this._state.color && (this.$btn.style.cssText = this.applyColor(this._state.color, this._state.text, this._state.ghost))), t.has("height") && this._updateHeight(this._state.height);
51
62
  }
52
63
  connectedCallback() {
53
- c(this), this.loadStyleText([x, y]), this.render(), this.isFormButton() && p(this, "click", this._handleClick), this._updateHeight(this.getAttr("height"));
64
+ c(this), this.loadStyleText([k, x]), this.render(), this.isFormButton() && v(this, "click", this._handleClick), this._updateHeight(this._state.height);
54
65
  }
55
66
  disconnectedCallback() {
56
- super.disconnectedCallback(), this.isFormButton() && v(this, "click", this._handleClick);
67
+ super.disconnectedCallback(), this.isFormButton() && f(this, "click", this._handleClick), this.$btn = void 0;
57
68
  }
58
69
  isFormButton() {
59
70
  const t = this.getHtmlType();
60
71
  return t === "submit" || t === "reset";
61
72
  }
62
73
  getHtmlType() {
63
- return this.getAttr("html-type", "button");
74
+ return this._state.htmlType;
64
75
  }
65
76
  render() {
66
- const t = this.getAttr("type", "normal"), r = document.createElement("button"), o = this.getAttr("loading", !1), e = this.getAttr("shape", "default"), n = this.getAttr("text", !1), l = this.getAttr("ghost", !1), a = [
77
+ const t = this._state.type, r = document.createElement("button"), o = this._state.loading, e = this._state.shape, l = this._state.text, a = this._state.ghost, s = [
67
78
  "l-btn",
68
79
  `l-btn-${t}`,
69
80
  e === "round" ? "l-btn-round" : "",
70
81
  e === "circle" ? "l-btn-circle" : "",
71
- l ? "l-btn-ghost" : "",
72
- n ? "l-btn-text" : "",
82
+ a ? "l-btn-ghost" : "",
83
+ l ? "l-btn-text" : "",
73
84
  o ? "l-btn-loading" : ""
74
85
  ];
75
- r.className = u(a), (this.disabled || o) && (r.disabled = !0), r.type = this.getAttr("html-type", "button");
76
- const i = this.applyColor(this.getAttr("color"), n, l);
77
- i && (r.style.cssText = i), o ? r.innerHTML = this.loadingBody() : r.innerHTML = "<slot></slot>", r.setAttribute("part", "default"), this.root.appendChild(r);
86
+ r.className = u(s), (this.disabled || o) && (r.disabled = !0), r.type = this._state.htmlType;
87
+ const n = this.applyColor(this._state.color || "", l, a);
88
+ n && (r.style.cssText = n), o ? r.innerHTML = this.loadingBody() : r.innerHTML = "<slot></slot>", r.setAttribute("part", "default"), this.$btn = r, this.root.appendChild(r);
78
89
  }
79
90
  loadingBody() {
80
- const t = this.getAttr("loading-text", "加载中……"), r = ['<l-loading-icon class="l-rotate-anim"></l-loading-icon>'];
91
+ const t = this._state.loadingText, r = ['<l-loading-icon class="l-rotate-anim"></l-loading-icon>'];
81
92
  return t ? r.push(`<span>${t}</span>`) : r.push("<slot></slot>"), r.join("");
82
93
  }
83
94
  applyColor(t, r = !1, o = !1) {
84
95
  if (!t) return "";
85
- const e = d(t, 1, !0), n = d(t, 3, !1);
96
+ const e = i(t, 1, !0), l = i(t, 3, !1);
86
97
  return m({
87
98
  "--l-btn-border-color": r ? "transparent" : t,
88
99
  "--l-btn-text-color": o || r ? t : "#ffffff",
89
100
  "--l-btn-hover-text-color": o || r ? e : "#ffffff",
90
101
  "--l-btn-background": o || r ? "transparent" : t,
91
- "--l-btn-active-text-color": o || r ? n : "#ffffff",
102
+ "--l-btn-active-text-color": o || r ? l : "#ffffff",
92
103
  "--l-btn-hover-border-color": r ? "transparent" : e,
93
104
  "--l-btn-hover-background": o || r ? "transparent" : e,
94
- "--l-btn-active-background": o || r ? "transparent" : n,
95
- "--l-btn-active-border-color": r ? "transparent" : n
105
+ "--l-btn-active-background": o || r ? "transparent" : l,
106
+ "--l-btn-active-border-color": r ? "transparent" : l
96
107
  });
97
108
  }
98
109
  _updateHeight(t) {
99
110
  t && (typeof t == "number" && (t = `${t}px`), this.style.setProperty("--l-btn-height", t));
100
111
  }
101
- _handleClick = (t) => {
102
- const r = t.target, o = k(r, "html-type");
103
- if (o === "reset" || o === "submit") {
104
- const e = this._getForm();
105
- e && (o === "reset" ? e.reset() : o === "submit" && e.submit());
106
- }
112
+ _handleClick = () => {
113
+ (this._state.htmlType === "reset" || this._state.htmlType === "submit") && this.emit("form-action", {
114
+ bubbles: !0,
115
+ composed: !0,
116
+ detail: this._state.htmlType
117
+ });
107
118
  };
108
- _getForm() {
109
- let t = this.parentElement, r;
110
- for (; t != null; ) {
111
- const o = t.tagName;
112
- if (o === "L-FORM") {
113
- r = t;
114
- break;
115
- }
116
- if (o === "BODY") break;
117
- t = t.parentElement;
118
- }
119
- return t = null, r;
120
- }
121
119
  }
122
120
  export {
123
- H as default
121
+ B as default
124
122
  };
@@ -1,12 +1,18 @@
1
1
  import FormInner from "../form/form_inner";
2
- export default class Check extends FormInner {
2
+ type CheckState = {
3
+ /** 是否为按钮样式 */
4
+ button: boolean;
5
+ label?: string;
6
+ indeterminate: boolean;
7
+ };
8
+ export default class Check extends FormInner<CheckState> {
3
9
  #private;
4
10
  /** 是否选中 */
5
11
  private _checked;
6
- label?: string;
7
- /** 是否为按钮样式 */
8
- button: boolean;
9
- _inputType: string;
12
+ _inputType: "radio" | "checkbox";
13
+ $input?: HTMLInputElement;
14
+ _groupCtx?: Signal<string[]>;
15
+ _groupCtxStop?: SignalStop;
10
16
  setChecked(isChecked: boolean): void;
11
17
  getChecked(): boolean;
12
18
  constructor();
@@ -18,6 +24,8 @@ export default class Check extends FormInner {
18
24
  protected attributeChange(name: string, _oldValue: string, newValue: string): void;
19
25
  protected checkedChange(): void;
20
26
  protected disabledChange(): void;
27
+ private _updateIndeterminate;
21
28
  emitChange(): void;
22
29
  _doChangeAction(): void;
23
30
  }
31
+ export {};
@@ -1,14 +1,15 @@
1
- import n from "../form/form_inner.js";
2
- import { initAttr as l, parseAttrValue as d } from "../utils/index.js";
3
- import { addClass as h, on as r, off as o, $$ as s, removeClass as k, $one as u, toggleClass as C } from "ph-utils/dom";
4
- class m extends n {
1
+ import { e as l } from "../index-CrMiSe0x.js";
2
+ import d from "../form/form_inner.js";
3
+ import { stopSignal as o, parseAttrValue as c } from "../utils/index.js";
4
+ import { addClass as n, on as u, off as p, $$ as i, removeClass as r, toggleClass as k } from "ph-utils/dom";
5
+ class f extends d {
5
6
  /** 是否选中 */
6
- _checked = !1;
7
- label;
8
- /** 是否为按钮样式 */
9
- button = !1;
10
- _inputType = "radio";
7
+ _checked;
8
+ _inputType;
11
9
  // input类型
10
+ $input;
11
+ _groupCtx;
12
+ _groupCtxStop;
12
13
  setChecked(e) {
13
14
  this._checked = e, this.checkedChange();
14
15
  }
@@ -16,7 +17,7 @@ class m extends n {
16
17
  return this._checked;
17
18
  }
18
19
  constructor() {
19
- super(), Object.defineProperty(this, "checked", {
20
+ super(), this._checked = !1, this._inputType = "radio", Object.defineProperty(this, "checked", {
20
21
  configurable: !0,
21
22
  enumerable: !0,
22
23
  get: this.getChecked,
@@ -24,53 +25,79 @@ class m extends n {
24
25
  });
25
26
  }
26
27
  static get observedAttributes() {
27
- return ["disabled", "checked", "value", "name"];
28
+ return ["checked", "label", "button", "indeterminate", ...d.observedAttributes];
28
29
  }
29
30
  connectedCallback() {
30
- l(this), super.connectedCallback(), this.getChecked() && h(this, "is-checked"), this.isDisabled() && h(this, "is-disabled");
31
+ super.connectedCallback(), this.getChecked() && this.setChecked(!0), this.isDisabled() && n(this, "is-disabled"), this._updateIndeterminate(), this.emitInject("check-context-request", (e) => {
32
+ this._groupCtx = e;
33
+ }), this._groupCtxStop = l(() => {
34
+ if (this.value == null) return;
35
+ const e = this._groupCtx ? this._groupCtx() : [];
36
+ this.setChecked(e.includes(this.value));
37
+ });
31
38
  }
32
39
  afterInit() {
33
- r(this, "click", this.#e), console.log("inner value: " + this.value);
40
+ u(this, "click", this.#e);
34
41
  }
35
42
  beforeDestroy() {
36
- o(this, "click", this.#e);
43
+ p(this, "click", this.#e), this._groupCtxStop = o(this._groupCtxStop);
37
44
  }
38
45
  render() {
39
- const e = document.createDocumentFragment(), c = s("input", {
46
+ const e = document.createDocumentFragment(), s = i("input", {
40
47
  type: this._inputType,
41
48
  class: "l-check__input",
42
49
  name: this.getName(),
43
50
  value: this.value,
44
- checked: this.getChecked()
51
+ checked: this.getChecked(),
52
+ disabled: this.isDisabled() ? "disabled" : void 0
45
53
  });
46
- if (this.isDisabled() && (c.disabled = !0), e.appendChild(c), !this.button) {
47
- const a = s("span", { class: "l-check__inner" });
54
+ if (this.$input = s, e.appendChild(s), !this._state.button) {
55
+ const a = i("span", { class: "l-check__inner" });
48
56
  e.appendChild(a);
49
57
  }
50
- const t = s("label", {
58
+ const t = i("label", {
51
59
  class: "l-check__label",
52
60
  part: "label"
53
- }), i = s("slot", {
54
- textContent: this.label
61
+ }), h = i("slot", {
62
+ textContent: this._state.label
55
63
  });
56
- return t.appendChild(i), e.appendChild(t), e;
64
+ return t.appendChild(h), e.appendChild(t), e;
57
65
  }
58
- attributeChange(e, c, t) {
59
- if (e === "checked") {
60
- const i = d(t, !1, "checked");
61
- i !== this.getChecked() && this.setChecked(i);
66
+ attributeChange(e, s, t) {
67
+ switch (e) {
68
+ case "checked":
69
+ const h = c(t, !1, "checked");
70
+ this.setChecked(h);
71
+ break;
72
+ case "button":
73
+ this._state[e] = c(t, !1, e);
74
+ break;
75
+ case "indeterminate":
76
+ const a = c(t, !1, e);
77
+ this._state.indeterminate = a, this._updateIndeterminate();
78
+ break;
79
+ case "label":
80
+ this._state.label = t;
81
+ break;
62
82
  }
63
83
  }
64
84
  checkedChange() {
65
- this.getChecked() ? h(this, "is-checked") : k(this, "is-checked");
66
- const e = u("input", this.root);
67
- e && (e.checked = this.getChecked());
85
+ this.getChecked() ? n(this, "is-checked") : r(this, "is-checked"), this.$input && (this.$input.checked = this.getChecked());
68
86
  }
69
87
  disabledChange() {
70
- C(this, "is-disabled");
88
+ k(this, "is-disabled"), this.$input && (this.$input.disabled = this.isDisabled());
89
+ }
90
+ _updateIndeterminate() {
91
+ this._state.indeterminate ? n(this, "is-indeterminate") : r(this, "is-indeterminate");
71
92
  }
72
93
  #e = () => {
73
- this.isDisabled() || this._doChangeAction();
94
+ if (!this.isDisabled())
95
+ if (this.value && this._groupCtx)
96
+ this.emitChange();
97
+ else {
98
+ const e = this._inputType === "radio" ? !0 : !this.getChecked();
99
+ this.setChecked(e), this.emitChange();
100
+ }
74
101
  };
75
102
  emitChange() {
76
103
  this.emit("change", {
@@ -79,12 +106,13 @@ class m extends n {
79
106
  name: this.getName(),
80
107
  checked: this.getChecked()
81
108
  },
82
- composed: !0
109
+ composed: !0,
110
+ bubbles: !0
83
111
  });
84
112
  }
85
113
  _doChangeAction() {
86
114
  }
87
115
  }
88
116
  export {
89
- m as default
117
+ f as default
90
118
  };
@@ -1,6 +1,6 @@
1
1
  import e from "./check.js";
2
- import { c as r } from "../check-D-KVLA1z.js";
3
- const o = '.l-check__inner:after{content:"";width:calc(var(--l-check-size) * .6);height:calc(var(--l-check-size) * .3);display:block;border:solid 1px transparent;border-right:none;border-top:none;transform:rotate(-45deg);transition:border-color .2s ease-in-out;margin-top:-3px}:host([indeterminate]) .l-check__inner{background-color:var(--l-primary-color, #722ed1)}:host([indeterminate]) .l-check__inner:after{content:"";width:calc(var(--l-check-size) * .4);height:1px;display:block;border:1px solid #fff;border-right:none;border-top:none;border-left:none;transform:rotate(0);margin-top:0}:host(.is-checked) .l-check__inner{background-color:var(--l-primary-color, #722ed1)}:host(.is-checked) .l-check__inner:after{border-color:#fff}:host(.is-disabled) .l-check__inner{background-color:var(--l-disabled-color, #e6e6e6);border-color:var(--l-disabled-color, #e6e6e6)}';
2
+ import { c as r } from "../check-CksURvTv.js";
3
+ const o = ':host(.is-indeterminate) .l-check__inner{background-color:var(--l-primary-color, #722ed1)}:host(.is-indeterminate) .l-check__inner:after{content:"";width:calc(var(--l-check-size) * .4);height:1px;display:block;border:1px solid #fff;border-right:none;border-top:none;border-left:none;transform:rotate(0);margin-top:0}.l-check__inner:after,:host(.is-checked) .l-check__inner:after{content:"";width:calc(var(--l-check-size) * .6);height:calc(var(--l-check-size) * .3);display:block;border:solid 1px transparent;border-right:none;border-top:none;transform:rotate(-45deg);transition:border-color .2s ease-in-out;margin-top:-3px}:host(.is-checked) .l-check__inner{background-color:var(--l-primary-color, #722ed1)}:host(.is-checked) .l-check__inner:after{border-color:#fff}:host(.is-disabled) .l-check__inner{background-color:var(--l-disabled-color, #e6e6e6);border-color:var(--l-disabled-color, #e6e6e6)}';
4
4
  class i extends e {
5
5
  static baseName = "checkbox";
6
6
  constructor() {
@@ -10,7 +10,7 @@ class i extends e {
10
10
  this.loadStyleText([r, o]), super.connectedCallback();
11
11
  }
12
12
  _doChangeAction() {
13
- this.getChecked() ? this.removeAttribute("checked") : this.setAttribute("checked", ""), this.emitChange();
13
+ this.getChecked() ? this.setChecked(!1) : this.setChecked(!0), this.emitChange();
14
14
  }
15
15
  }
16
16
  export {
@@ -1,5 +1,4 @@
1
1
  import CheckGroup from ".";
2
2
  export default class CheckboxGroup extends CheckGroup {
3
3
  static baseName: string;
4
- setValue(value: string): void;
5
4
  }
@@ -1,11 +1,7 @@
1
- import c from "./index.js";
2
- class a extends c {
1
+ import e from "./index.js";
2
+ class c extends e {
3
3
  static baseName = "checkbox-group";
4
- setValue(e) {
5
- let s = this.checkedValues.indexOf(e);
6
- s >= 0 ? this.checkedValues.splice(s, 1) : this.checkedValues.push(e), super.setValue(this.checkedValues.join("&"));
7
- }
8
4
  }
9
5
  export {
10
- a as default
6
+ c as default
11
7
  };