litos-ui 0.17.1 → 0.17.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.
@@ -1,147 +1,196 @@
1
- import x from "../base.js";
2
- import { parseAttrValue as c, initAttr as g } from "../utils/index.js";
3
- import { $one as i, transition as s, $$ as a, on as u, off as k, shouldEventNext as y } from "ph-utils/dom";
4
- const v = ":host{display:none}:host(.open){display:block}.l-modal-mask{z-index:var(--l-modal-zindex, 100)}.l-modal-wrapper{position:fixed;top:0;left:0;width:100%;height:100%;z-index:calc(var(--l-modal-zindex, 100) + 1)}.l-modal{--l-modal-translate: translate3d(0, 80px, 0);background-color:#fff;border-radius:5px;width:var(--l-modal-width, 27%);margin:auto;box-shadow:0 0 8px #0000001a;position:relative;opacity:1;transform:var(--l-modal-translate) scaleZ(1);transition:opacity .3s,transform .3s}.l-modal-header{display:block;padding:10px;font-size:16px;border-bottom:1px solid var(--l-modal-line-color, rgba(0, 0, 0, .06));font-weight:600;display:flex;align-items:center;gap:5px}.l-modal-footer{padding:10px;border-top:1px solid var(--l-modal-line-color, rgba(0, 0, 0, .06));display:flex;justify-content:flex-end;gap:10px}.l-modal-container{padding:var(--l-modal-container-padding, 15px 10px);font-size:14px}.l-btn-modal-close{--l-form-control-height: auto;position:absolute}.l-modal-close1{right:5px;top:8px}.l-modal-close1::part(default){width:auto;height:auto;padding:5px;border:none;font-size:16px}.l-modal-close2{right:-10px;top:-10px}.l-modal-close2::part(default){width:20px;height:20px;padding:0;background-color:#fff}.mask-transition-enter-from,.mask-transition-leave-to{opacity:0}.modal-transition-enter-from,.modal-transition-leave-to{transform:translateZ(0) scale3d(0,0,0)}.l-modal--mobile{border-radius:10px}.l-modal--mobile .l-modal-header{text-align:center;border-bottom-color:transparent;padding:20px 10px 5px;display:flex;justify-content:center}.l-modal--mobile .l-modal-container{--l-modal-container-padding: 5px 15px 20px;text-align:center}.l-modal--mobile .l-modal-footer{display:flex;justify-content:stretch;align-items:stretch;padding:0;text-align:center;height:50px;gap:0}.l-modal--mobile .l-modal-footer-btn{flex-grow:1;height:100%}.l-modal--mobile .l-modal-footer-btn+.l-modal-footer-btn{border-left:1px solid var(--l-modal-line-color, rgba(0, 0, 0, .06))}.l-modal--middle{--l-modal-translate: translate3d(0, -50%, 0);top:50%}.l-modal--bottom{--l-modal-translate: translate3d(0, -100%, 0);top:100%;width:100%;border-bottom-left-radius:0;border-bottom-right-radius:0}@media screen and (max-width:768px){:host{--l-modal-width: 80%}}", w = ".l-mask{position:fixed;z-index:var(--l-mask-zindex, 100);inset:0;background-color:#0009;transition:opacity .3s;opacity:1}";
5
- class S extends x {
1
+ import f from "../base.js";
2
+ import { $one as d, transition as r, $$ as a, on as b, off as x, shouldEventNext as k } from "ph-utils/dom";
3
+ import { parseAttrValue as n, unitNumberStr as g, kebabToCamel as u } from "../utils/index.js";
4
+ const y = ":host{display:none}:host(.open){display:block}.l-modal-mask{z-index:var(--l-modal-zindex, 100)}.l-modal-wrapper{position:fixed;top:0;left:0;width:100%;height:100%;z-index:calc(var(--l-modal-zindex, 100) + 1)}.l-modal{--l-modal-translate: translate3d(0, 80px, 0);background-color:#fff;border-radius:5px;width:var(--l-modal-width, 27%);margin:auto;box-shadow:0 0 8px #0000001a;position:relative;opacity:1;transform:var(--l-modal-translate) scaleZ(1);transition:opacity .3s,transform .3s}.l-modal-header{display:block;padding:10px;font-size:16px;border-bottom:1px solid var(--l-modal-line-color, rgba(0, 0, 0, .06));font-weight:600;display:flex;align-items:center;gap:5px}.l-modal-footer{padding:10px;border-top:1px solid var(--l-modal-line-color, rgba(0, 0, 0, .06));display:flex;justify-content:flex-end;gap:10px}.l-modal-container{padding:var(--l-modal-container-padding, 15px 10px);font-size:14px}.l-btn-modal-close{--l-form-control-height: auto;position:absolute}.l-modal-close1{right:5px;top:8px}.l-modal-close1::part(default){width:auto;height:auto;padding:5px;border:none;font-size:16px}.l-modal-close2{right:-10px;top:-10px}.l-modal-close2::part(default){width:20px;height:20px;padding:0;background-color:#fff}.mask-transition-enter-from,.mask-transition-leave-to{opacity:0}.modal-transition-enter-from,.modal-transition-leave-to{transform:translateZ(0) scale3d(0,0,0)}.l-modal--mobile{border-radius:10px}.l-modal--mobile .l-modal-header{text-align:center;border-bottom-color:transparent;padding:20px 10px 5px;display:flex;justify-content:center}.l-modal--mobile .l-modal-container{--l-modal-container-padding: 5px 15px 20px;text-align:center}.l-modal--mobile .l-modal-footer{display:flex;justify-content:stretch;align-items:stretch;padding:0;text-align:center;height:50px;gap:0}.l-modal--mobile .l-modal-footer-btn{flex-grow:1;height:100%}.l-modal--mobile .l-modal-footer-btn+.l-modal-footer-btn{border-left:1px solid var(--l-modal-line-color, rgba(0, 0, 0, .06))}.l-modal--middle{--l-modal-translate: translate3d(0, -50%, 0);top:50%}.l-modal--bottom{--l-modal-translate: translate3d(0, -100%, 0);top:100%;width:100%;border-bottom-left-radius:0;border-bottom-right-radius:0}@media screen and (max-width:768px){:host{--l-modal-width: 80%}}", v = ".l-mask{position:fixed;z-index:var(--l-mask-zindex, 100);inset:0;background-color:#0009;transition:opacity .3s;opacity:1}";
5
+ class z extends f {
6
6
  static baseName = "modal";
7
- /** 关闭时销毁 Modal 里的子元素 */
8
- destroyOnClose = !1;
9
- /** 点击蒙层是否允许关闭 */
10
- maskClosable = !0;
11
- /** 是否展示遮罩 */
12
- mask = !0;
13
- /** 是否显示取消按钮 */
14
- cancel = !0;
15
- /** 取消按钮文本 */
16
- cancelText = "取消";
17
- /** 确定按钮文本 */
18
- okText = "确定";
19
- /** 对话框宽度 */
20
- width;
21
- /** 确认按钮加载中 */
22
- confirmLoading = !1;
23
- /** 右上角关闭按钮, 1-显示在框内,2-显示在框角, 0-不显示 */
24
- close = 1;
25
- /** 对话框垂直方向位置 */
26
- verticalAlign = "top";
27
- /** 是否是移动风格弹出框 */
28
- mobile = !1;
29
- /** 设置 Modal 的 z-index */
30
- zIndex;
31
7
  _bodyOverflow = "";
8
+ constructor() {
9
+ super(), this.version = 2, this._state = {
10
+ destroyOnClose: !1,
11
+ maskClosable: !0,
12
+ mask: !0,
13
+ cancel: !0,
14
+ cancelText: "取消",
15
+ okText: "确定",
16
+ confirmLoading: !1,
17
+ close: 1,
18
+ verticalAlign: "top",
19
+ mobile: !1,
20
+ show: !1,
21
+ header: !0,
22
+ footer: !0
23
+ };
24
+ }
32
25
  static get observedAttributes() {
33
- return ["show", "width", "confirm-loading"];
26
+ return [
27
+ "show",
28
+ "width",
29
+ "confirm-loading",
30
+ "destroy-on-close",
31
+ "mask-closable",
32
+ "mask",
33
+ "cancel",
34
+ "cancel-text",
35
+ "ok-text",
36
+ "close",
37
+ "vertical-align",
38
+ "mobile",
39
+ "z-index",
40
+ "header",
41
+ "footer",
42
+ "header-title"
43
+ ];
34
44
  }
35
- attributeChangedCallback(t, l, o) {
36
- if (this.rendered) {
37
- if (t === "show")
38
- c(o, !1, "show") ? this.#o() : this.#a();
39
- else if (t === "width")
40
- this.width = c(o, void 0), this.#t();
41
- else if (t === "confirm-loading") {
42
- this.confirmLoading = c(o, !1, "confirm-loading");
43
- const e = i('l-button[modal-action="ok"]', this.root);
44
- e && e.setAttribute("loading", this.confirmLoading.toString());
45
- }
45
+ attributeChanged(t, o, e) {
46
+ switch (t) {
47
+ case "show":
48
+ case "confirm-loading":
49
+ case "destroy-on-close":
50
+ case "mask-closable":
51
+ case "mask":
52
+ case "cancel":
53
+ case "mobile":
54
+ case "header":
55
+ case "footer":
56
+ this._state[u(t)] = n(e, !1, t);
57
+ break;
58
+ case "cancel-text":
59
+ this._state.cancelText = n(e, "取消");
60
+ break;
61
+ case "ok-text":
62
+ this._state.okText = n(e, "确定");
63
+ break;
64
+ case "close":
65
+ this._state.close = n(e, 1);
66
+ break;
67
+ case "width":
68
+ this._state[t] = g(e);
69
+ break;
70
+ case "vertical-align":
71
+ this._state.verticalAlign = n(e, "top");
72
+ break;
73
+ case "z-index":
74
+ this._state.zIndex = e;
75
+ break;
76
+ case "header-title":
77
+ this._state.headerTitle = e;
78
+ break;
46
79
  }
47
80
  }
48
- connectedCallback() {
49
- g(this), this.loadStyleText([w, v]), super.connectedCallback(), this.#t(), this.zIndex && this.style.setProperty("--l-modal-zindex", this.zIndex);
81
+ updateDOM(t) {
82
+ if (t.has("show") && (this._state.show ? this.#t() : this.#a()), t.has("width") && this._setWidth(), t.has("confirm-loading")) {
83
+ const o = d('l-button[modal-action="ok"]', this.root);
84
+ o && o.setAttribute("loading", this._state.confirmLoading.toString());
85
+ }
86
+ t.has("z-index") && this._setZIndex();
50
87
  }
51
- render() {
52
- this.getAttr("show", !1) && this.#o();
88
+ afterInit() {
89
+ this._setWidth(), this._setZIndex(), this._state.show && this.#t();
53
90
  }
54
- #t() {
55
- this.width ? this.style.setProperty("--l-modal-width", this.width) : this.style.removeProperty("--l-modal-width");
91
+ render_v2() {
92
+ return {
93
+ style: [v, y]
94
+ };
95
+ }
96
+ _setZIndex() {
97
+ this._state.zIndex ? this.style.setProperty("--l-modal-zindex", this._state.zIndex) : this.style.removeProperty("--l-modal-zindex");
56
98
  }
57
- #o() {
99
+ _setWidth() {
100
+ this._state.width ? this.style.setProperty("--l-modal-width", this._state.width) : this.style.removeProperty("--l-modal-width");
101
+ }
102
+ #t() {
58
103
  this._bodyOverflow = getComputedStyle(document.body).overflow, this.classList.add("open"), document.body.style.overflow = "hidden";
59
- let t = i(".l-modal-wrapper", this.root);
104
+ let t = d(".l-modal-wrapper", this.root);
60
105
  if (t) {
61
- const l = i(".l-mask", this.root);
62
- l && s(l, "mask-transition");
63
- const o = i(".l-modal", this.root);
64
- s(o, "modal-transition");
106
+ const o = d(".l-mask", this.root);
107
+ o && r(o, "mask-transition");
108
+ const e = d(".l-modal", this.root);
109
+ r(e, "modal-transition");
65
110
  } else {
66
- const l = document.createDocumentFragment();
67
- let o = null;
68
- this.mask && (o = a("div", { class: "l-mask l-modal-mask", part: "mask" }), l.appendChild(o)), t = a("div", { class: "l-modal-wrapper", part: "wrapper" });
69
- const e = a("div", {
111
+ const o = document.createDocumentFragment();
112
+ let e = null;
113
+ this._state.mask && (e = a("div", { class: "l-mask l-modal-mask", part: "mask" }), o.appendChild(e)), t = a("div", { class: "l-modal-wrapper", part: "wrapper" });
114
+ const l = a("div", {
70
115
  class: [
71
116
  "l-modal",
72
- `l-modal--${this.mobile ? "mobile" : "pc"}`,
73
- `l-modal--${this.verticalAlign}`
117
+ `l-modal--${this._state.mobile ? "mobile" : "pc"}`,
118
+ `l-modal--${this._state.verticalAlign}`
74
119
  ],
75
120
  part: "default"
76
121
  });
77
- if (e.setAttribute("modal-action", "modal"), this.close !== 0) {
78
- const d = a("l-button", {
122
+ if (l.setAttribute("modal-action", "modal"), this._state.close !== 0) {
123
+ const s = a("l-button", {
79
124
  shape: "circle",
80
125
  type: "normal",
81
- class: `l-btn-modal-close l-modal-close${this.close}`,
126
+ class: `l-btn-modal-close l-modal-close${this._state.close}`,
82
127
  "modal-action": "close"
83
- }), n = a("l-close-icon");
84
- d.appendChild(n), e.appendChild(d);
128
+ }), i = a("l-close-icon");
129
+ s.appendChild(i), l.appendChild(s);
130
+ }
131
+ if (this._state.header) {
132
+ const s = a("header", { class: "l-modal-header", part: "header" }), i = a("slot", {
133
+ name: "header"
134
+ });
135
+ i.textContent = this._state.headerTitle || "", s.appendChild(i), l.appendChild(s);
85
136
  }
86
- const p = a("header", { class: "l-modal-header", part: "header" }), h = a("slot", { name: "header" });
87
- h.textContent = this.getAttr("header", ""), p.appendChild(h), e.appendChild(p);
88
- const f = a("div", {
137
+ const h = a("div", {
89
138
  class: "l-modal-container",
90
139
  part: "container"
91
- }), b = a("slot");
92
- if (f.appendChild(b), e.appendChild(f), this.getAttr("footer", !0)) {
93
- const d = a("footer", {
140
+ }), p = a("slot");
141
+ if (h.appendChild(p), l.appendChild(h), this._state.footer) {
142
+ const s = a("footer", {
94
143
  class: "l-modal-footer",
95
144
  part: "footer"
96
- }), n = a("slot", { name: "footer" });
97
- if (this.cancel) {
145
+ }), i = a("slot", { name: "footer" });
146
+ if (this._state.cancel) {
98
147
  const m = a("l-button", {
99
148
  class: "l-modal-footer-btn",
100
- text: this.mobile
149
+ text: this._state.mobile
101
150
  });
102
- m.textContent = this.cancelText, m.setAttribute("modal-action", "cancel"), n.appendChild(m);
151
+ m.textContent = this._state.cancelText, m.setAttribute("modal-action", "cancel"), i.appendChild(m);
103
152
  }
104
- const r = a("l-button", {
153
+ const c = a("l-button", {
105
154
  type: "primary",
106
155
  class: "l-modal-footer-btn",
107
- loading: this.confirmLoading,
108
- text: this.mobile
156
+ loading: this._state.confirmLoading,
157
+ text: this._state.mobile
109
158
  });
110
- r.textContent = this.okText, r.setAttribute("modal-action", "ok"), n.appendChild(r), d.appendChild(n), e.appendChild(d);
159
+ c.textContent = this._state.okText, c.setAttribute("modal-action", "ok"), i.appendChild(c), s.appendChild(i), l.appendChild(s);
111
160
  }
112
- t.appendChild(e), t.setAttribute("role", "dialog"), t.setAttribute("modal-action", "mask"), u(t, "click", this.#l), l.appendChild(t), this.appendToRoot(l), s(e, "modal-transition"), o && s(o, "mask-transition");
161
+ t.appendChild(l), t.setAttribute("role", "dialog"), t.setAttribute("modal-action", "mask"), b(t, "click", this.#o), o.appendChild(t), this.appendToRoot(o), r(l, "modal-transition"), e && r(e, "mask-transition");
113
162
  }
114
163
  }
115
164
  #a() {
116
165
  document.body.style.setProperty("overflow", this._bodyOverflow);
117
- const t = i(".l-modal", this.root);
118
- s(t, "modal-transition", "leave", () => {
119
- this.destroyOnClose && this.#e(), this.classList.remove("open"), this.dispatchEvent(new CustomEvent("close"));
166
+ const t = d(".l-modal", this.root);
167
+ r(t, "modal-transition", "leave", () => {
168
+ this._state.destroyOnClose && this.#e(), this.classList.remove("open"), this.dispatchEvent(new CustomEvent("close"));
120
169
  });
121
- const l = i(".l-mask", this.root);
122
- l && s(l, "mask-transition", "leave");
170
+ const o = d(".l-mask", this.root);
171
+ o && r(o, "mask-transition", "leave");
123
172
  }
124
173
  disconnectedCallback() {
125
174
  this.#e(), super.disconnectedCallback();
126
175
  }
127
176
  #e() {
128
- const t = i(".l-modal-wrapper", this.root);
129
- t && (k(t, "click", this.#l), this.root.removeChild(t));
130
- const l = i(".l-mask", this.root);
131
- l && this.root.removeChild(l);
177
+ const t = d(".l-modal-wrapper", this.root);
178
+ t && (x(t, "click", this.#o), this.root.removeChild(t));
179
+ const o = d(".l-mask", this.root);
180
+ o && this.root.removeChild(o);
132
181
  }
133
- #l = (t) => {
134
- const [l, o] = y(t, "modal-action", this.root);
135
- if (l) {
136
- let e = "";
137
- this.maskClosable && o === "mask" || o === "cancel" || o === "close" ? e = "cancel" : o === "ok" && (e = "ok"), e && this.dispatchEvent(
138
- new CustomEvent(e, {
139
- detail: { action: o }
182
+ #o = (t) => {
183
+ const [o, e] = k(t, "modal-action", this.root);
184
+ if (o) {
185
+ let l = "";
186
+ this._state.maskClosable && e === "mask" || e === "cancel" || e === "close" ? l = "cancel" : e === "ok" && (l = "ok"), l && this.dispatchEvent(
187
+ new CustomEvent(l, {
188
+ detail: { action: e }
140
189
  })
141
190
  );
142
191
  }
143
192
  };
144
193
  }
145
194
  export {
146
- S as default
195
+ z as default
147
196
  };
@@ -13,11 +13,7 @@ function f(t, e, o, l = "alert") {
13
13
  let s = o.icon();
14
14
  s.setAttribute("slot", "header"), n.push(s.outerHTML);
15
15
  }
16
- n.push(`<span slot="header">${t}</span>`), l === "prompt" ? (n.push(
17
- `<l-form-item label="${e}" label-position="top" inner-block>`
18
- ), n.push(
19
- `<l-input placeholder="${o.placeholder || ""}"></l-input>`
20
- ), n.push("</l-form-item>")) : n.push(`<span>${e}</span>`);
16
+ n.push(`<span slot="header">${t}</span>`), l === "prompt" ? (n.push(`<l-form-item label="${e}" label-position="top" inner-block>`), n.push(`<l-input placeholder="${o.placeholder || ""}"></l-input>`), n.push("</l-form-item>")) : n.push(`<span>${e}</span>`);
21
17
  let r = h("l-modal", {
22
18
  cancel: `${o.showCancel}`,
23
19
  innerHTML: n.join(""),
@@ -38,20 +34,20 @@ function f(t, e, o, l = "alert") {
38
34
  "ok",
39
35
  () => {
40
36
  let s = !0;
41
- l === "prompt" && (s = b(".l-modal-box l-input").value), r.removeAttribute("open"), a(s);
37
+ l === "prompt" && (s = b(".l-modal-box l-input").value), r.removeAttribute("show"), a(s);
42
38
  },
43
39
  { once: !0 }
44
40
  ), m(
45
41
  r,
46
42
  "cancel",
47
43
  () => {
48
- r.removeAttribute("open"), a(!1);
44
+ r.removeAttribute("show"), a(!1);
49
45
  },
50
46
  { once: !0 }
51
47
  ), document.body.appendChild(r);
52
48
  });
53
49
  }
54
- function k(t, e, o) {
50
+ function w(t, e, o) {
55
51
  return p([i, c, u]), new Promise((l) => {
56
52
  const a = {
57
53
  showCancel: !1,
@@ -63,7 +59,7 @@ function k(t, e, o) {
63
59
  return f(e || "提示", t, a, "alert");
64
60
  });
65
61
  }
66
- function v(t, e, o) {
62
+ function k(t, e, o) {
67
63
  p([i, c, u, d]);
68
64
  const l = {
69
65
  showCancel: !0,
@@ -74,7 +70,7 @@ function v(t, e, o) {
74
70
  };
75
71
  return f(e || "提示", t, l, "confirm");
76
72
  }
77
- function w(t, e, o) {
73
+ function v(t, e, o) {
78
74
  p([i, c, u, d, $, C]);
79
75
  const l = {
80
76
  showCancel: !0,
@@ -86,9 +82,9 @@ function w(t, e, o) {
86
82
  return f(e || "提示", t, l, "prompt");
87
83
  }
88
84
  const j = {
89
- alert: k,
90
- confirm: v,
91
- prompt: w
85
+ alert: w,
86
+ confirm: k,
87
+ prompt: v
92
88
  };
93
89
  export {
94
90
  j as default
@@ -1,9 +1,15 @@
1
1
  import BaseComponent from "../base";
2
- export default class ThemeColor extends BaseComponent {
2
+ type ThemeColorState = {
3
+ color: string;
4
+ };
5
+ export default class ThemeColor extends BaseComponent<ThemeColorState> {
3
6
  #private;
4
7
  static baseName: string;
5
- color: string;
6
8
  constructor();
7
- connectedCallback(): void;
8
- render(): string | void | HTMLElement | HTMLElement[];
9
+ render_v2(): {
10
+ template?: string | HTMLElement | DocumentFragment;
11
+ style?: string | string[];
12
+ };
13
+ afterInit(): void;
9
14
  }
15
+ export {};
@@ -1,28 +1,25 @@
1
1
  import { $one as t, on as r } from "ph-utils/dom";
2
- import c from "../base.js";
3
- import { getColorTheme as n, applyColorTheme as l } from "ph-utils/theme";
4
- class m extends c {
2
+ import s from "../base.js";
3
+ import { getColorTheme as a, applyColorTheme as c } from "ph-utils/theme";
4
+ class m extends s {
5
5
  static baseName = "theme-color";
6
- color;
7
6
  constructor() {
8
- super(), this.color = n() || "#722ed1";
7
+ super(), this.version = 2, this._state = {
8
+ color: a() || "#722ed1"
9
+ };
9
10
  }
10
- connectedCallback() {
11
- super.connectedCallback(), this.#e();
11
+ render_v2() {
12
+ return {
13
+ template: `<l-color-picker value="${this._state.color}"></l-color-picker>`
14
+ };
12
15
  }
13
- render() {
14
- const e = document.createElement(
15
- "l-color-picker"
16
- );
17
- return e.value = this.color, e;
18
- }
19
- #e() {
16
+ afterInit() {
20
17
  const e = t("l-color-picker", this.root);
21
- e && r(e, "change", this.#o);
18
+ e && r(e, "change", this.#e);
22
19
  }
23
- #o = async (e) => {
20
+ #e = async (e) => {
24
21
  const o = e.detail;
25
- this.color = o, await l(o), this.dispatchEvent(new CustomEvent("change", { detail: o }));
22
+ this._state.color = o, await c(o), this.dispatchEvent(new CustomEvent("change", { detail: o }));
26
23
  };
27
24
  }
28
25
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "litos-ui",
3
- "version": "0.17.1",
3
+ "version": "0.17.3",
4
4
  "description": "基于 Web Component 的 UI 组件库",
5
5
  "keywords": [
6
6
  "component library",
@@ -1,99 +0,0 @@
1
- import { initAttr as l } from "../utils/index.js";
2
- import n from "../form/form_inner.js";
3
- import { iterate as o, formatStyle as d, $ as c, on as a, off as r, $$ as h } from "ph-utils/dom";
4
- import { parse as m } from "ph-utils/date";
5
- const u = ":host{display:inline-flex;align-items:center;width:var(--l-date-picker-width, auto)}.l-date-inner{height:var(--l-form-control-height, 32px);border-radius:3px;outline:none;border:1px solid var(--l-border-color, #dedede);cursor:text;padding:0 5px;flex-grow:1;transition:border-color .3s}.l-date-inner:hover{border-color:var(--l-primary-color-light1, #9254de)}.l-date-inner:focus{border-color:var(--l-primary-color, #722ed1)}.l-date-range-divider{margin:0 10px}";
6
- class y extends n {
7
- static baseName = "date-picker";
8
- /** 是否显示日期范围选择 */
9
- range = !1;
10
- /** 范围选择器时,为了性能考虑, 立即改变一个日期后,会延迟 300ms 通知, 以响应其它选择器, 0 - 立即触发 */
11
- emitTimeout = 300;
12
- /** 原生 type 属性 */
13
- type = "date";
14
- width;
15
- /** 日期范围 */
16
- min;
17
- max;
18
- allowEmpty = !0;
19
- #t = [];
20
- #e = [];
21
- #i = -1;
22
- // 至上一次触发change后,是否有更改
23
- #s = !1;
24
- set value(t) {
25
- this.setValue(t), this.#e = t.split(","), o(this.#t, (i, e) => {
26
- i.value = this.#e[e];
27
- });
28
- }
29
- connectedCallback() {
30
- l(this), this.loadStyleText(u);
31
- const t = {};
32
- this.width && (t["--l-date-picker-width"] = this.width), this.style.cssText = d(t), super.connectedCallback();
33
- }
34
- afterInit() {
35
- this.#t = c(".l-date-inner", this.root), a(this.#t, "change", this.#h), this.range && (a(this.#t, "focus", this.#n), a(this.#t, "blur", this.#o));
36
- }
37
- beforeDestroy() {
38
- r(this.#t, "change", this.#h), this.range && (r(this.#t, "focus", this.#n), r(this.#t, "blur", this.#o)), this.#a();
39
- }
40
- attributeChange(t, i, e) {
41
- t === "value" && e !== this._value && (this.value = e);
42
- }
43
- render() {
44
- const t = document.createDocumentFragment();
45
- if (t.appendChild(this.#r(0)), this.range) {
46
- const i = h("span", {
47
- class: "l-date-range-divider",
48
- textContent: "-"
49
- });
50
- t.appendChild(i), t.appendChild(this.#r(1));
51
- }
52
- return t;
53
- }
54
- #r(t = 0) {
55
- return h("input", {
56
- type: this.type,
57
- class: `l-date-inner l-date-inner${t}`,
58
- name: this.getName(),
59
- value: this.#e[t],
60
- "l-datepicker": `${t}`,
61
- disabled: this.isDisabled(),
62
- min: this.min,
63
- max: this.max
64
- });
65
- }
66
- #h = (t) => {
67
- const i = t.target, e = Number(i.getAttribute("l-datepicker"));
68
- let s = i.value;
69
- !s && !this.allowEmpty && (s = this._resetValue || "", s = s.split(",")[e], i.value = s), this.#e[e] = s, this.#e.join(",") !== this._value && (this.setValue(this.#e.join(",")), this.#s = !0), e === 0 && this.#t.length > 1 ? this.#t[1].min = s : e === 1 && (this.#t[0].max = s), this.range ? this.#l() : this.#d();
70
- };
71
- #a() {
72
- this.#i !== -1 && (clearTimeout(this.#i), this.#i = -1);
73
- }
74
- #l() {
75
- this.#s && (this.#a(), this.#i = setTimeout(() => {
76
- this.#d(), this.#s = !1;
77
- }, this.emitTimeout));
78
- }
79
- #n = () => {
80
- this.#a();
81
- };
82
- #o = () => {
83
- this.#l();
84
- };
85
- #d() {
86
- this.dispatchEvent(
87
- new CustomEvent("change", {
88
- detail: {
89
- value: this.getValue(),
90
- dateStr: this.#e,
91
- dates: this.#e.map((t) => m(t))
92
- }
93
- })
94
- );
95
- }
96
- }
97
- export {
98
- y as default
99
- };