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.
- package/lib/calendar/index.d.ts +2 -2
- package/lib/calendar/index.js +38 -34
- package/lib/form/index.js +19 -19
- package/package.json +1 -1
package/lib/calendar/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import FormInner from "../form/form_inner";
|
|
2
2
|
type CalendarState = {
|
|
3
3
|
locale: string;
|
|
4
|
-
minDate
|
|
5
|
-
maxDate
|
|
4
|
+
minDate: number;
|
|
5
|
+
maxDate: number;
|
|
6
6
|
};
|
|
7
7
|
export default class Calendar extends FormInner<CalendarState> {
|
|
8
8
|
static baseName: string;
|
package/lib/calendar/index.js
CHANGED
|
@@ -1,79 +1,83 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
|
|
8
|
-
|
|
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
|
|
14
|
+
const t = k("l_app_locale", "zh-CN", { storage: "session" });
|
|
16
15
|
this._state = {
|
|
17
|
-
locale:
|
|
18
|
-
|
|
16
|
+
locale: t,
|
|
17
|
+
minDate: -1 / 0,
|
|
18
|
+
maxDate: 1 / 0
|
|
19
|
+
}, this._langData = f[t];
|
|
19
20
|
}
|
|
20
|
-
setValue(
|
|
21
|
-
|
|
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 =
|
|
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 [...
|
|
34
|
+
return [...D.observedAttributes, "locale"];
|
|
34
35
|
}
|
|
35
|
-
attributeChanged(
|
|
36
|
-
switch (
|
|
36
|
+
attributeChanged(t, r, n) {
|
|
37
|
+
switch (t) {
|
|
37
38
|
case "locale":
|
|
38
|
-
|
|
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
|
|
45
|
+
this._state.maxDate = H(n).getTime();
|
|
43
46
|
break;
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
|
-
updateDOM(
|
|
47
|
-
|
|
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
|
|
54
|
-
let a =
|
|
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
|
|
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
|
|
59
|
-
|
|
60
|
-
let
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
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
|
|
70
|
-
|
|
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
|
|
76
|
-
|
|
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: [
|
|
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
|
|
6
|
-
const
|
|
7
|
-
class k extends
|
|
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
|
|
34
|
-
this.context({ innerBlock:
|
|
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
|
|
41
|
-
this._state[t] =
|
|
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([
|
|
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:
|
|
84
|
+
const { name: i, value: e, valid: a } = t.detail;
|
|
85
85
|
if (!i) return;
|
|
86
86
|
this._data == null && (this._data = {});
|
|
87
|
-
const
|
|
88
|
-
this._data[i] = e, !this._state.novalidate &&
|
|
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,
|
|
100
|
-
const
|
|
101
|
-
i.push(this.validator.validateKey(
|
|
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
|
|
107
|
-
for (let
|
|
108
|
-
const h = e[
|
|
109
|
-
h.status === "rejected" ?
|
|
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(), ...
|
|
111
|
+
this.errors({ ...this.errors(), ...a });
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
114
|
}
|