litos-ui 0.17.3 → 0.17.4

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,8 +1,8 @@
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
6
  };
7
7
  export default class Calendar extends FormInner<CalendarState> {
8
8
  static baseName: string;
@@ -1,79 +1,83 @@
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";
1
+ import D from "../form/form_inner.js";
2
+ import { $one as y } from "ph-utils/dom";
3
+ import { langs as f } from "./langs.js";
6
4
  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 {
5
+ import { parse as w, endOf as H, startOf as C, format as c } from "ph-utils/date";
6
+ const T = ":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}";
7
+ class A extends D {
9
8
  static baseName = "calendar";
10
9
  _currentDate;
11
10
  _langData;
12
11
  $container;
13
12
  constructor() {
14
13
  super(), this.version = 2, this._currentDate = /* @__PURE__ */ new Date();
15
- const e = k("l_app_locale", "zh-CN", { storage: "session" });
14
+ const t = k("l_app_locale", "zh-CN", { storage: "session" });
16
15
  this._state = {
17
- locale: e
18
- }, this._langData = y[e];
16
+ locale: t,
17
+ minDate: -1 / 0,
18
+ maxDate: 1 / 0
19
+ }, this._langData = f[t];
19
20
  }
20
- setValue(e) {
21
- e != this.value && (super.setValue(e), this._currentDate = x(e), this.rerenderBody());
21
+ setValue(t) {
22
+ t != this.value && (super.setValue(t), this._currentDate = w(t), this.rerenderBody());
22
23
  }
23
24
  connectedCallback() {
24
25
  super.connectedCallback();
25
26
  }
26
27
  afterInit() {
27
- this.$container = h(".calendar-table", this.root);
28
+ this.$container = y(".calendar-table", this.root);
28
29
  }
29
30
  beforeDestroy() {
30
31
  this.$container = void 0;
31
32
  }
32
33
  static get observedAttributes() {
33
- return [...u.observedAttributes, "locale"];
34
+ return [...D.observedAttributes, "locale"];
34
35
  }
35
- attributeChanged(e, r, o) {
36
- switch (e) {
36
+ attributeChanged(t, r, n) {
37
+ switch (t) {
37
38
  case "locale":
38
- y.hasOwnProperty(o) && (this._state.locale = o, this._langData = y[o]);
39
+ f.hasOwnProperty(n) && (this._state.locale = n, this._langData = f[n]);
39
40
  break;
40
41
  case "min-date":
42
+ this._state.minDate = C(n).getTime();
43
+ break;
41
44
  case "max-date":
42
- this._state[v(e)] = o;
45
+ this._state.maxDate = H(n).getTime();
43
46
  break;
44
47
  }
45
48
  }
46
- updateDOM(e) {
47
- e.has("locale") && this.rerenderHeader(), this.$container && (this.$container.innerHTML = this.rerender());
49
+ updateDOM(t) {
50
+ t.has("locale") && this.rerenderHeader(), this.$container && (this.$container.innerHTML = this.rerender());
48
51
  }
49
52
  _renderHeader() {
50
53
  return `<tr>${this._langData.weekdays.map((r) => `<th>${r}</th>`).join("")}</tr>`;
51
54
  }
52
55
  _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;
56
+ const t = this._currentDate.getFullYear(), r = this._currentDate.getMonth(), n = c(null, "yyyy-mm-dd"), b = new Date(t, r, 1);
57
+ let a = b.getDay() - 1;
55
58
  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");
59
+ const m = new Date(t, r + 1, 0), u = m.getDate(), g = c(m, "yyyy-mm"), p = new Date(t, r, 0), $ = p.getDate(), _ = c(p, "yyyy-mm"), x = new Date(t, r + 1, 1), v = c(x, "yyyy-mm"), d = new Date(b);
60
+ d.setDate(d.getDate() - a), d.setHours(0, 0, 0, 0);
57
61
  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>");
62
+ for (let e = 0; e < 42; e++) {
63
+ e % 7 === 0 && (i += "<tr>");
64
+ let o, s = "day", l = "";
65
+ e < a ? (o = `${$ - a + e + 1}`, s += " prev-month", l = _) : e < a + u ? (o = `${e - a + 1}`, l = g) : (o = `${e - a - u + 1}`, s += " next-month disabled", l = v);
66
+ const h = `${l}-${o.padStart(2, "0")}`;
67
+ h === n && (s += " today"), h === this.value && (s += " active"), i += `<td class="${s}" title="${h}">${o}</td>`, e % 7 === 6 && (i += "</tr>");
64
68
  }
65
69
  return i;
66
70
  }
67
71
  rerenderHeader() {
68
72
  if (this.$container) {
69
- const e = h("thead", this.$container);
70
- e.innerHTML = this._renderHeader();
73
+ const t = y("thead", this.$container);
74
+ t.innerHTML = this._renderHeader();
71
75
  }
72
76
  }
73
77
  rerenderBody() {
74
78
  if (this.$container) {
75
- const e = h("tbody", this.$container);
76
- e.innerHTML = this._renderBody();
79
+ const t = y("tbody", this.$container);
80
+ t.innerHTML = this._renderBody();
77
81
  }
78
82
  }
79
83
  rerender() {
@@ -82,7 +86,7 @@ class A extends u {
82
86
  render_v2() {
83
87
  return {
84
88
  template: `<table class="calendar-table">${this.rerender()}</table>`,
85
- style: [w]
89
+ style: [T]
86
90
  };
87
91
  }
88
92
  }
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "litos-ui",
3
- "version": "0.17.3",
3
+ "version": "0.17.4",
4
4
  "description": "基于 Web Component 的 UI 组件库",
5
5
  "keywords": [
6
6
  "component library",