litos-ui 0.17.3 → 0.17.5

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.js CHANGED
@@ -32,7 +32,7 @@ class a extends HTMLElement {
32
32
  this._pendingTask && (cancelAnimationFrame(this._pendingTask), this._pendingTask = void 0, this._pendingUpdate = !1);
33
33
  }
34
34
  batchUpdate() {
35
- this._pendingUpdate || (this.cancelPending(), this._pendingUpdate = !0, requestAnimationFrame(() => {
35
+ this._pendingUpdate || (this.cancelPending(), this._pendingUpdate = !0, this._pendingTask = requestAnimationFrame(() => {
36
36
  const e = new Set(this._changedProperties);
37
37
  this._changedProperties.clear(), this.updateDOM(e), this._pendingUpdate = !1;
38
38
  }));
@@ -1,14 +1,19 @@
1
1
  import FormInner from "../form/form_inner";
2
2
  type CalendarState = {
3
3
  locale: string;
4
- minDate?: string;
5
- maxDate?: string;
4
+ minDate: number;
5
+ maxDate: number;
6
+ year: number;
7
+ month: number;
8
+ type: "select" | "range";
6
9
  };
7
10
  export default class Calendar extends FormInner<CalendarState> {
8
11
  static baseName: string;
9
- private _currentDate;
10
12
  private _langData;
11
13
  private $container?;
14
+ /** 选择的日期列表 */
15
+ private _selectDates;
16
+ private _range?;
12
17
  constructor();
13
18
  setValue(v: string): void;
14
19
  connectedCallback(): void;
@@ -26,5 +31,6 @@ export default class Calendar extends FormInner<CalendarState> {
26
31
  template?: string | HTMLElement | DocumentFragment;
27
32
  style?: string | string[];
28
33
  };
34
+ private _updateCellsState;
29
35
  }
30
36
  export {};
@@ -1,79 +1,108 @@
1
1
  import u from "../form/form_inner.js";
2
- import { kebabToCamel as v } from "../utils/index.js";
3
- import { parse as x, format as c } from "ph-utils/date";
4
- import { $one as h } from "ph-utils/dom";
5
- import { langs as y } from "./langs.js";
6
- import { get as k } from "ph-utils/storage";
7
- const w = ":host{display:block;box-sizing:border-box;width:100%;height:100%}.calendar-table{width:100%;height:100%;border-collapse:collapse}.calendar-table thead{height:var(--calendar-header-height, auto)}.calendar-table th{font-weight:400;cursor:default}.calendar-table .prev-month,.calendar-table .next-month{color:var(--l-calendar-off-text-color, #a8abb2)}.calendar-table .today{color:var(--l-primary-color, #007bff)}.day{text-align:center;cursor:pointer;transition:background-color .2s;font-size:13px}.day:hover{background-color:#0000000a}.day.disabled{background-color:#0000000a;cursor:not-allowed}.day.active{background-color:var(--l-primary-color, #007bff);color:#fff;font-weight:700}";
8
- class A extends u {
2
+ import { parseAttrValue as g } from "../utils/index.js";
3
+ import { $one as m } from "ph-utils/dom";
4
+ import { langs as f } from "./langs.js";
5
+ import { get as T } from "ph-utils/storage";
6
+ import { parse as w, endOf as M, startOf as I, format as c } from "ph-utils/date";
7
+ const O = ":host{display:block;box-sizing:border-box;width:100%;height:100%}.calendar-table{width:100%;height:100%;border-collapse:collapse}.calendar-table thead{height:var(--calendar-header-height, auto)}.calendar-table th{font-weight:400;cursor:default}.calendar-table .prev-month,.calendar-table .next-month{color:var(--l-calendar-off-text-color, #a8abb2)}.calendar-table .today{color:var(--l-primary-color, #007bff)}.day{text-align:center;cursor:pointer;transition:background-color .2s;font-size:13px}.day:hover{background-color:#0000000a}.day.disabled{background-color:#0000000a;cursor:not-allowed}.day.active{background-color:var(--l-primary-color, #007bff);color:#fff;font-weight:700}";
8
+ class Y extends u {
9
9
  static baseName = "calendar";
10
- _currentDate;
11
10
  _langData;
12
11
  $container;
12
+ /** 选择的日期列表 */
13
+ _selectDates;
14
+ _range;
13
15
  constructor() {
14
- super(), this.version = 2, this._currentDate = /* @__PURE__ */ new Date();
15
- const e = k("l_app_locale", "zh-CN", { storage: "session" });
16
+ super(), this.version = 2;
17
+ const t = T("l_app_locale", "zh-CN", { storage: "session" }), e = /* @__PURE__ */ new Date();
16
18
  this._state = {
17
- locale: e
18
- }, this._langData = y[e];
19
+ locale: t,
20
+ minDate: -1 / 0,
21
+ maxDate: 1 / 0,
22
+ year: e.getFullYear(),
23
+ month: e.getMonth(),
24
+ type: "select"
25
+ }, this._langData = f[t], this._selectDates = [];
19
26
  }
20
- setValue(e) {
21
- e != this.value && (super.setValue(e), this._currentDate = x(e), this.rerenderBody());
27
+ setValue(t) {
28
+ t != this.value && (super.setValue(t), this._state.type === "select" ? this._selectDates = t.split(",") : this._range = t.split(",").map((e) => w(e).getTime()), this.batchUpdate());
22
29
  }
23
30
  connectedCallback() {
24
31
  super.connectedCallback();
25
32
  }
26
33
  afterInit() {
27
- this.$container = h(".calendar-table", this.root);
34
+ this.$container = m(".calendar-table", this.root);
28
35
  }
29
36
  beforeDestroy() {
30
37
  this.$container = void 0;
31
38
  }
32
39
  static get observedAttributes() {
33
- return [...u.observedAttributes, "locale"];
40
+ return [
41
+ ...u.observedAttributes,
42
+ "locale",
43
+ "year",
44
+ "month",
45
+ "min-date",
46
+ "max-date",
47
+ "type"
48
+ ];
34
49
  }
35
- attributeChanged(e, r, o) {
36
- switch (e) {
50
+ attributeChanged(t, e, a) {
51
+ switch (t) {
37
52
  case "locale":
38
- y.hasOwnProperty(o) && (this._state.locale = o, this._langData = y[o]);
53
+ f.hasOwnProperty(a) && (this._state.locale = a, this._langData = f[a]);
39
54
  break;
40
55
  case "min-date":
56
+ this._state.minDate = I(a).getTime();
57
+ break;
41
58
  case "max-date":
42
- this._state[v(e)] = o;
59
+ this._state.maxDate = M(a).getTime();
60
+ break;
61
+ case "year":
62
+ this._state.year = g(a, this._state.year);
63
+ break;
64
+ case "month":
65
+ this._state.month = g(a, this._state.month + 1) - 1;
66
+ break;
67
+ case "type":
68
+ this._state.type = a;
43
69
  break;
44
70
  }
45
71
  }
46
- updateDOM(e) {
47
- e.has("locale") && this.rerenderHeader(), this.$container && (this.$container.innerHTML = this.rerender());
72
+ updateDOM(t) {
73
+ t.has("locale") ? this.rerenderHeader() : (t.has("year") || t.has("month")) && this.$container && (this.$container.innerHTML = this.rerender());
48
74
  }
49
75
  _renderHeader() {
50
- return `<tr>${this._langData.weekdays.map((r) => `<th>${r}</th>`).join("")}</tr>`;
76
+ return `<tr>${this._langData.weekdays.map((e) => `<th>${e}</th>`).join("")}</tr>`;
51
77
  }
52
78
  _renderBody() {
53
- const e = this._currentDate.getFullYear(), r = this._currentDate.getMonth(), o = c(null, "yyyy-mm-dd");
54
- let a = new Date(e, r, 1).getDay() - 1;
55
- a < 0 && (a = 6);
56
- const b = new Date(e, r + 1, 0), f = b.getDate(), p = c(b, "yyyy-mm"), m = new Date(e, r, 0), g = m.getDate(), D = c(m, "yyyy-mm"), $ = new Date(e, r + 1, 1), _ = c($, "yyyy-mm");
79
+ const t = this._state.year, e = this._state.month, a = c(null, "yyyy-mm-dd"), b = new Date(t, e, 1);
80
+ let s = b.getDay() - 1;
81
+ s < 0 && (s = 6);
82
+ const p = new Date(t, e + 1, 0), D = p.getDate(), $ = c(p, "yyyy-mm"), _ = new Date(t, e, 0), x = _.getDate(), v = c(_, "yyyy-mm"), k = new Date(t, e + 1, 1), C = c(k, "yyyy-mm"), d = new Date(b);
83
+ d.setDate(d.getDate() - s);
84
+ let h = d.setHours(0, 0, 0, 0);
85
+ const H = 864e5;
57
86
  let i = "";
58
- for (let t = 0; t < 42; t++) {
59
- t % 7 === 0 && (i += "<tr>");
60
- let n, s = "day", l = "";
61
- t < a ? (n = `${g - a + t + 1}`, s += " prev-month", l = D) : t < a + f ? (n = `${t - a + 1}`, l = p) : (n = `${t - a - f + 1}`, s += " next-month disabled", l = _);
62
- const d = `${l}-${n.padStart(2, "0")}`;
63
- d === o && (s += " today"), d === this.value && (s += " active"), i += `<td class="${s}" title="${d}">${n}</td>`, t % 7 === 6 && (i += "</tr>");
87
+ for (let r = 0; r < 42; r++) {
88
+ r % 7 === 0 && (i += "<tr>");
89
+ let n, o = "day", l = "";
90
+ r < s ? (n = `${x - s + r + 1}`, o += " prev-month", l = v) : r < s + D ? (n = `${r - s + 1}`, l = $) : (n = `${r - s - D + 1}`, o += " next-month", l = C), (h < this._state.minDate || h > this._state.maxDate) && (o += " disabled");
91
+ const y = `${l}-${n.padStart(2, "0")}`;
92
+ y === a && (o += " today"), y === this.value && (o += " active"), i += `<td class="${o}" title="${y}">${n}</td>`, h += H, r % 7 === 6 && (i += "</tr>");
64
93
  }
65
94
  return i;
66
95
  }
67
96
  rerenderHeader() {
68
97
  if (this.$container) {
69
- const e = h("thead", this.$container);
70
- e.innerHTML = this._renderHeader();
98
+ const t = m("thead", this.$container);
99
+ t.innerHTML = this._renderHeader();
71
100
  }
72
101
  }
73
102
  rerenderBody() {
74
103
  if (this.$container) {
75
- const e = h("tbody", this.$container);
76
- e.innerHTML = this._renderBody();
104
+ const t = m("tbody", this.$container);
105
+ t.innerHTML = this._renderBody();
77
106
  }
78
107
  }
79
108
  rerender() {
@@ -82,10 +111,13 @@ class A extends u {
82
111
  render_v2() {
83
112
  return {
84
113
  template: `<table class="calendar-table">${this.rerender()}</table>`,
85
- style: [w]
114
+ style: [O]
86
115
  };
87
116
  }
117
+ //只要 minDate、maxDate、_rangeStart、_rangeEnd、_hoverDate、_selectedDates 任何一个发生了改变,都调用这个统一的函数。
118
+ _updateCellsState() {
119
+ }
88
120
  }
89
121
  export {
90
- A as default
122
+ Y as default
91
123
  };
package/lib/form/index.js CHANGED
@@ -2,9 +2,9 @@ import { $one as c, formatClass as d, on as r, off as o } from "ph-utils/dom";
2
2
  import { unitNumberStr as m, parseAttrValue as f } from "../utils/index.js";
3
3
  import u from "ph-utils/validator";
4
4
  import { s as n } from "../index-CrMiSe0x.js";
5
- import b from "../base.js";
6
- const v = ":host{display:block}.l-form{display:flex;gap:20px;flex-flow:column nowrap}.l-form-inline{display:flex;gap:20px;flex-flow:row wrap}.l-form.l-form-inline{--l-form-item-display: flex}.l-form.l-form--left{--l-form-label-align: left}.l-form.l-form--top{--l-form-item-display: grid;--l-form-label-align: left;--l-form-label-empty-display: none;grid-template-columns:1fr}";
7
- class k extends b {
5
+ import v from "../base.js";
6
+ const b = ":host{display:block}.l-form{display:flex;gap:var(--l-form-gap, 20px);flex-flow:column nowrap}.l-form-inline{display:flex;gap:var(--l-form-gap, 20px);flex-flow:row wrap}.l-form.l-form-inline{--l-form-item-display: flex}.l-form.l-form--left{--l-form-label-align: left}.l-form.l-form--top{--l-form-item-display: grid;--l-form-label-align: left;--l-form-label-empty-display: none;grid-template-columns:1fr}";
7
+ class k extends v {
8
8
  static baseName = "form";
9
9
  validator;
10
10
  _data;
@@ -30,15 +30,15 @@ class k extends b {
30
30
  this._state.labelPosition = e;
31
31
  break;
32
32
  case "inner-block":
33
- const s = f(e, !1, t);
34
- this.context({ innerBlock: s });
33
+ const a = f(e, !1, t);
34
+ this.context({ innerBlock: a });
35
35
  break;
36
36
  case "label-width":
37
37
  this._state.labelWidth = m(e);
38
38
  break;
39
39
  default:
40
- const a = f(e, !1, t);
41
- this._state[t] = a;
40
+ const s = f(e, !1, t);
41
+ this._state[t] = s;
42
42
  break;
43
43
  }
44
44
  }
@@ -54,7 +54,7 @@ class k extends b {
54
54
  t.has("label-width") && (this._state.labelWidth ? this.style.setProperty("--l-form-label-width", this._state.labelWidth) : this.style.removeProperty("--l-form-label-width"));
55
55
  }
56
56
  connectedCallback() {
57
- r(this, "form-context-request", this._provide), this.loadStyleText([v]), super.connectedCallback();
57
+ r(this, "form-context-request", this._provide), this.loadStyleText([b]), super.connectedCallback();
58
58
  }
59
59
  afterInit() {
60
60
  r(this, "form-rule-change", this.ruleChange), r(this, "form-value-change", this._valueChange), r(this, "form-action", this._formAction);
@@ -81,11 +81,11 @@ class k extends b {
81
81
  t.detail === "submit" ? this.submit() : this.reset();
82
82
  };
83
83
  _valueChange = (t) => {
84
- const { name: i, value: e, valid: s } = t.detail;
84
+ const { name: i, value: e, valid: a } = t.detail;
85
85
  if (!i) return;
86
86
  this._data == null && (this._data = {});
87
- const a = Object.hasOwn(this._data, i);
88
- this._data[i] = e, !this._state.novalidate && a && s && this.validator.validateKey(i, e, this._data).then(() => {
87
+ const s = Object.hasOwn(this._data, i);
88
+ this._data[i] = e, !this._state.novalidate && s && a && this.validator.validateKey(i, e, this._data).then(() => {
89
89
  const l = this.errors();
90
90
  l[i] = void 0, this.errors({ ...l });
91
91
  }).catch((l) => {
@@ -96,19 +96,19 @@ class k extends b {
96
96
  const i = [];
97
97
  if (this._data != null) {
98
98
  if (Array.isArray(t))
99
- for (let e = 0, s = t.length; e < s; e++) {
100
- const a = t[e];
101
- i.push(this.validator.validateKey(a, this._data[a], this._data));
99
+ for (let e = 0, a = t.length; e < a; e++) {
100
+ const s = t[e];
101
+ i.push(this.validator.validateKey(s, this._data[s], this._data));
102
102
  }
103
103
  else
104
104
  i.push(this.validator.validateKey(t, this._data[t], this._data));
105
105
  Promise.allSettled(i).then((e) => {
106
- let s = {};
107
- for (let a = 0, l = e.length; a < l; a++) {
108
- const h = e[a];
109
- h.status === "rejected" ? s = { ...s, ...h.reason.detail } : s[h.value.key] = void 0;
106
+ let a = {};
107
+ for (let s = 0, l = e.length; s < l; s++) {
108
+ const h = e[s];
109
+ h.status === "rejected" ? a = { ...a, ...h.reason.detail } : a[h.value.key] = void 0;
110
110
  }
111
- this.errors({ ...this.errors(), ...s });
111
+ this.errors({ ...this.errors(), ...a });
112
112
  });
113
113
  }
114
114
  }
@@ -28,6 +28,7 @@ declare class LoadingInstance {
28
28
  /** 隐藏进度条 */
29
29
  hide(): void;
30
30
  destroy(): void;
31
+ updateLoadingText(text: string): void;
31
32
  }
32
33
  declare const _default: {
33
34
  /** 创建并显示进度条 */
@@ -1,49 +1,49 @@
1
1
  import { $ as c, iterate as d, $one as r, addClass as g, hasClass as m, $$ as o } from "ph-utils/dom";
2
- function f(t, e) {
3
- if (m(t, "l-loading")) return;
2
+ function f(e, t) {
3
+ if (m(e, "l-loading")) return;
4
4
  let l;
5
- if (e.fullscreen && r("#l-loading") != null)
5
+ if (t.fullscreen && r("#l-loading") != null)
6
6
  return;
7
7
  const s = ["l-loading"];
8
- (e.mask === 1 || e.mask === 2 && e.shape === "circle") && (l = o("div", {
8
+ (t.mask === 1 || t.mask === 2 && t.shape === "circle") && (l = o("div", {
9
9
  class: "l-loading-mask",
10
10
  style: {
11
- "background-color": e.background,
12
- "--l-loading-zindex": e.zindex
11
+ "background-color": t.background,
12
+ "--l-loading-zindex": t.zindex
13
13
  }
14
- }), t.appendChild(l));
14
+ }), e.appendChild(l));
15
15
  const n = o("div", {
16
- class: `l-loading-spinner l-loading--${e.shape}`,
16
+ class: `l-loading-spinner l-loading--${t.shape}`,
17
17
  style: {
18
- "--l-loading-color": e.color
18
+ "--l-loading-color": t.color
19
19
  }
20
20
  });
21
- if (e.shape === "bar") {
21
+ if (t.shape === "bar") {
22
22
  const i = o("div", { class: "l-loading-progress" });
23
23
  n.appendChild(i);
24
- } else if (e.shape === "circle") {
24
+ } else if (t.shape === "circle") {
25
25
  const i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
26
26
  i.setAttribute("viewBox", "0 0 50 50"), i.classList.add("circle");
27
27
  const a = document.createElementNS("http://www.w3.org/2000/svg", "circle");
28
- if (a.classList.add("path"), a.setAttribute("cx", "25"), a.setAttribute("cy", "25"), a.setAttribute("r", "23"), a.setAttribute("fill", "none"), i.appendChild(a), n.appendChild(i), e.text) {
28
+ if (a.classList.add("path"), a.setAttribute("cx", "25"), a.setAttribute("cy", "25"), a.setAttribute("r", "23"), a.setAttribute("fill", "none"), i.appendChild(a), n.appendChild(i), t.text) {
29
29
  const p = o("p", {
30
30
  class: "l-loading-text",
31
- textContent: e.text
31
+ textContent: t.text
32
32
  });
33
33
  n.appendChild(p);
34
34
  }
35
35
  }
36
- t.appendChild(n), e.lock && s.push("l-loading-lock"), e.fullscreen && (s.push("l-loading-fullscreen"), n.id = "l-loading"), t.classList.add(...s), requestAnimationFrame(() => {
36
+ e.appendChild(n), t.lock && s.push("l-loading-lock"), t.fullscreen && (s.push("l-loading-fullscreen"), n.id = "l-loading"), e.classList.add(...s), requestAnimationFrame(() => {
37
37
  l && (l.style.opacity = "1"), n.style.opacity = "1", g(n, "l-loading-bar--start");
38
38
  });
39
39
  }
40
- function h(t, e) {
41
- const l = t.tagName === "BODY" ? "body" : ".l-loading", s = r(`${l} > .l-loading-mask`, t), n = r(`${l} > .l-loading-spinner`, t);
40
+ function h(e, t) {
41
+ const l = e.tagName === "BODY" ? "body" : ".l-loading", s = r(`${l} > .l-loading-mask`, e), n = r(`${l} > .l-loading-spinner`, e);
42
42
  if (!n) return;
43
43
  function i() {
44
44
  s && s.remove(), n.remove();
45
45
  const a = ["l-loading"];
46
- t.tagName === "BODY" && a.push("l-loading-fullscreen", "l-loading-lock"), t.classList.remove(...a);
46
+ e.tagName === "BODY" && a.push("l-loading-fullscreen", "l-loading-lock"), e.classList.remove(...a);
47
47
  }
48
48
  n.addEventListener("transitionend", i, { once: !0 }), requestAnimationFrame(() => {
49
49
  s && (s.style.opacity = "0"), g(n, "l-loading-bar--finish"), n.style.opacity = "0";
@@ -54,7 +54,7 @@ class b {
54
54
  el;
55
55
  option;
56
56
  isLoading = !1;
57
- constructor(e) {
57
+ constructor(t) {
58
58
  this.option = {
59
59
  fullscreen: !0,
60
60
  lock: !0,
@@ -63,9 +63,9 @@ class b {
63
63
  background: "",
64
64
  color: "",
65
65
  mask: 2,
66
- ...e
66
+ ...t
67
67
  };
68
- const l = (e || {}).to;
68
+ const l = (t || {}).to;
69
69
  let s = null;
70
70
  l != null && (typeof l == "string" ? s = document.querySelector(l) : s = l), (s == null || this.option.fullscreen) && (s = document.body), this.el = s, this.show();
71
71
  }
@@ -80,27 +80,31 @@ class b {
80
80
  destroy() {
81
81
  this.hide(), this.el = void 0;
82
82
  }
83
+ updateLoadingText(t) {
84
+ const l = r(".l-loading-text", this.el);
85
+ l && (l.textContent = t);
86
+ }
83
87
  }
84
- function u(t) {
85
- const e = t.getAttribute("l-loading-text"), l = t.getAttribute("l-loading-lock");
88
+ function u(e) {
89
+ const t = e.getAttribute("l-loading-text"), l = e.getAttribute("l-loading-lock");
86
90
  return {
87
- background: t.getAttribute("l-loading-background"),
88
- text: e ? e === "0" || e === "false" ? void 0 : e : "加载中……",
89
- fullscreen: t.hasAttribute("l-loading-fullscreen"),
91
+ background: e.getAttribute("l-loading-background"),
92
+ text: t ? t === "0" || t === "false" ? void 0 : t : "加载中……",
93
+ fullscreen: e.hasAttribute("l-loading-fullscreen"),
90
94
  lock: !(l === "0" || l === "false"),
91
- mask: Number(t.hasAttribute("l-loading-mask") || 2),
92
- shape: t.getAttribute("l-loading-shape") || "circle",
93
- color: t.getAttribute("l-loading-color")
95
+ mask: Number(e.hasAttribute("l-loading-mask") || 2),
96
+ shape: e.getAttribute("l-loading-shape") || "circle",
97
+ color: e.getAttribute("l-loading-color")
94
98
  };
95
99
  }
96
100
  const k = {
97
101
  /** 创建并显示进度条 */
98
- create(t) {
99
- return new b(t);
102
+ create(e) {
103
+ return new b(e);
100
104
  },
101
105
  /** 根据指令参数初始化进度条 */
102
- init(t) {
103
- const e = t ? `[l-loading="${t}"]` : "[l-loading]", l = c(e);
106
+ init(e) {
107
+ const t = e ? `[l-loading="${e}"]` : "[l-loading]", l = c(t);
104
108
  d(l, (s) => {
105
109
  const n = u(s);
106
110
  f(n.fullscreen ? document.body : s, n);
@@ -114,8 +118,8 @@ const k = {
114
118
  *
115
119
  * @param id 可选参数,指定特定的加载元素 l-loading 对应的值,如果提供,则只关闭匹配该 id 的元素
116
120
  */
117
- close(t) {
118
- const e = t ? `[l-loading="${t}"]` : "[l-loading]", l = c(e);
121
+ close(e) {
122
+ const t = e ? `[l-loading="${e}"]` : "[l-loading]", l = c(t);
119
123
  d(l, (s) => {
120
124
  const n = u(s);
121
125
  h(n.fullscreen ? document.body : s);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "litos-ui",
3
- "version": "0.17.3",
3
+ "version": "0.17.5",
4
4
  "description": "基于 Web Component 的 UI 组件库",
5
5
  "keywords": [
6
6
  "component library",