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.
- package/lib/base.d.ts +13 -1
- package/lib/base.js +35 -5
- package/lib/button/index.js +32 -17
- package/lib/calendar/index.d.ts +30 -0
- package/lib/calendar/index.js +91 -0
- package/lib/calendar/langs.d.ts +4 -0
- package/lib/calendar/langs.js +8 -0
- package/lib/{date_picker → date_picker_ori}/index.d.ts +15 -7
- package/lib/date_picker_ori/index.js +129 -0
- package/lib/dialog/dialog_container.d.ts +16 -8
- package/lib/dialog/dialog_container.js +95 -62
- package/lib/form/form_inner.js +1 -1
- package/lib/form/index.js +5 -5
- package/lib/index.d.ts +5 -3
- package/lib/index.js +16 -14
- package/lib/modal/index.d.ts +24 -6
- package/lib/modal/index.js +145 -96
- package/lib/modal/modal_box.js +9 -13
- package/lib/theme/theme_color.d.ts +10 -4
- package/lib/theme/theme_color.js +14 -17
- package/package.json +1 -1
- package/lib/date_picker/index.js +0 -99
package/lib/base.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export default class BaseComponent<T = Record<string, any>> extends HTMLElement
|
|
|
6
6
|
protected _pendingUpdate: boolean;
|
|
7
7
|
protected _pendingTask?: number;
|
|
8
8
|
protected _changedProperties: Set<string>;
|
|
9
|
+
/** 版本, 1 - 直接调用 render, 2 - 渲染 render_v2 */
|
|
10
|
+
protected version: number;
|
|
9
11
|
constructor(shadow?: boolean, init?: Partial<ShadowRootInit>);
|
|
10
12
|
/**
|
|
11
13
|
* 返回一个数组,表示观察的属性列表
|
|
@@ -22,6 +24,7 @@ export default class BaseComponent<T = Record<string, any>> extends HTMLElement
|
|
|
22
24
|
createStyle(text: string): void;
|
|
23
25
|
createLink(href: string): void;
|
|
24
26
|
loadStyleText(styleText: string | string[]): void;
|
|
27
|
+
styleHtml(styleText: string | string[]): string;
|
|
25
28
|
/**
|
|
26
29
|
* 获取属性值
|
|
27
30
|
* @param key 属性名称
|
|
@@ -37,9 +40,18 @@ export default class BaseComponent<T = Record<string, any>> extends HTMLElement
|
|
|
37
40
|
getAttr(key: string, defaultValue: boolean): boolean;
|
|
38
41
|
getAttr<T extends Record<string, string | number | boolean>>(filepath: string, defaultValue: T): T;
|
|
39
42
|
appendToRoot(el?: HTMLElement | HTMLElement[] | string | DocumentFragment): void;
|
|
43
|
+
appendToRootV2(template?: HTMLElement | string | DocumentFragment, style?: string | string[]): void;
|
|
40
44
|
connectedCallback(): void;
|
|
41
45
|
disconnectedCallback(): void;
|
|
42
|
-
render(): void | string | HTMLElement |
|
|
46
|
+
render(): void | string | HTMLElement | DocumentFragment;
|
|
47
|
+
/**
|
|
48
|
+
* 渲染器
|
|
49
|
+
* @returns [渲染节点,内容, 模板样式]
|
|
50
|
+
*/
|
|
51
|
+
render_v2(): {
|
|
52
|
+
template?: string | HTMLElement | DocumentFragment;
|
|
53
|
+
style?: string | string[];
|
|
54
|
+
};
|
|
43
55
|
/**
|
|
44
56
|
* 初始化事件
|
|
45
57
|
* @deprecated 自0.12.0起弃用,使用 afterInit() 替代
|
package/lib/base.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getAttr as
|
|
1
|
+
import { getAttr as s } from "ph-utils/dom";
|
|
2
2
|
class a extends HTMLElement {
|
|
3
3
|
static baseName = "base-component";
|
|
4
4
|
/** 组件是否渲染完成, 是否已经调用 connectedCallback */
|
|
@@ -11,8 +11,10 @@ class a extends HTMLElement {
|
|
|
11
11
|
// 延迟任务id
|
|
12
12
|
_changedProperties;
|
|
13
13
|
// 已改变的属性集合
|
|
14
|
+
/** 版本, 1 - 直接调用 render, 2 - 渲染 render_v2 */
|
|
15
|
+
version;
|
|
14
16
|
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 });
|
|
17
|
+
super(), this.rendered = !1, this._state = {}, this._pendingUpdate = !1, this.version = 1, this._changedProperties = /* @__PURE__ */ new Set(), e && this.attachShadow({ mode: "open", ...t });
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
18
20
|
* 返回一个数组,表示观察的属性列表
|
|
@@ -22,7 +24,7 @@ class a extends HTMLElement {
|
|
|
22
24
|
}
|
|
23
25
|
// 当属性发生变化时调用的回调函数
|
|
24
26
|
attributeChangedCallback(e, t, n) {
|
|
25
|
-
t !== n && (this.attributeChanged(e, t, n), this.
|
|
27
|
+
t !== n && (this._changedProperties.add(e), this.attributeChanged(e, t, n), this.rendered && this.batchUpdate());
|
|
26
28
|
}
|
|
27
29
|
attributeChanged(e, t, n) {
|
|
28
30
|
}
|
|
@@ -56,8 +58,12 @@ class a extends HTMLElement {
|
|
|
56
58
|
let t = e;
|
|
57
59
|
Array.isArray(t) && (t = t.join("")), this.createStyle(t);
|
|
58
60
|
}
|
|
61
|
+
styleHtml(e) {
|
|
62
|
+
let t = e;
|
|
63
|
+
return Array.isArray(t) && (t = t.join("")), `<style>${t}</style>`;
|
|
64
|
+
}
|
|
59
65
|
getAttr(e, t) {
|
|
60
|
-
return
|
|
66
|
+
return s(this, e, t);
|
|
61
67
|
}
|
|
62
68
|
appendToRoot(e) {
|
|
63
69
|
if (e)
|
|
@@ -66,14 +72,38 @@ class a extends HTMLElement {
|
|
|
66
72
|
t.innerHTML = e, this.root.append(...t.childNodes), t = void 0;
|
|
67
73
|
} else e.length ? this.root.append(...e) : this.root.append(e);
|
|
68
74
|
}
|
|
75
|
+
appendToRootV2(e, t) {
|
|
76
|
+
const n = [];
|
|
77
|
+
if (t && n.push(this.styleHtml(t)), e)
|
|
78
|
+
if (typeof e == "string")
|
|
79
|
+
n.push(e);
|
|
80
|
+
else {
|
|
81
|
+
let i = document.createElement("div");
|
|
82
|
+
i.appendChild(e), n.push(i.innerHTML), i = void 0;
|
|
83
|
+
}
|
|
84
|
+
this.root.innerHTML = n.join("");
|
|
85
|
+
}
|
|
69
86
|
connectedCallback() {
|
|
70
|
-
|
|
87
|
+
if (this.version === 1)
|
|
88
|
+
this.appendToRoot(this.render());
|
|
89
|
+
else {
|
|
90
|
+
const e = this.render_v2();
|
|
91
|
+
this.appendToRootV2(e.template, e.style);
|
|
92
|
+
}
|
|
93
|
+
this.rendered = !0, this.initEvents(), this.afterInit();
|
|
71
94
|
}
|
|
72
95
|
disconnectedCallback() {
|
|
73
96
|
this.cancelPending(), this.removeEvents(), this.beforeDestroy(), this.root.innerHTML = "", this.rendered = !1;
|
|
74
97
|
}
|
|
75
98
|
render() {
|
|
76
99
|
}
|
|
100
|
+
/**
|
|
101
|
+
* 渲染器
|
|
102
|
+
* @returns [渲染节点,内容, 模板样式]
|
|
103
|
+
*/
|
|
104
|
+
render_v2() {
|
|
105
|
+
return {};
|
|
106
|
+
}
|
|
77
107
|
/**
|
|
78
108
|
* 初始化事件
|
|
79
109
|
* @deprecated 自0.12.0起弃用,使用 afterInit() 替代
|
package/lib/button/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { kebabToCamel as b, parseAttrValue as d
|
|
2
|
-
import
|
|
3
|
-
import { addClass as
|
|
4
|
-
import { adjust as
|
|
5
|
-
import { a as
|
|
6
|
-
const
|
|
7
|
-
class
|
|
1
|
+
import { kebabToCamel as b, parseAttrValue as d } from "../utils/index.js";
|
|
2
|
+
import c from "../base.js";
|
|
3
|
+
import { addClass as h, removeClass as p, on as g, off as v, formatClass as f, formatStyle as u } from "ph-utils/dom";
|
|
4
|
+
import { adjust as s } from "ph-utils/color";
|
|
5
|
+
import { a as m } from "../animation-DttknHkX.js";
|
|
6
|
+
const k = ":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 c {
|
|
8
8
|
static baseName = "button";
|
|
9
9
|
// public htmlType: "submit" | "reset" | "button" = "button";
|
|
10
10
|
_disabled = !1;
|
|
@@ -28,14 +28,25 @@ class B extends h {
|
|
|
28
28
|
this.setDisabled(t);
|
|
29
29
|
}
|
|
30
30
|
setLoading(t) {
|
|
31
|
-
this.$btn && (t ? (
|
|
31
|
+
this.$btn && (t ? (h(this.$btn, "l-btn-loading"), this.$btn.disabled = !0, this.$btn.innerHTML = this.loadingBody()) : (p(this.$btn, "l-btn-loading"), this.$btn.disabled = this.disabled, this.$btn.innerHTML = "<slot></slot>"));
|
|
32
32
|
}
|
|
33
33
|
setDisabled(t) {
|
|
34
34
|
this._disabled = t, this.$btn && (this.$btn.disabled = t);
|
|
35
35
|
}
|
|
36
36
|
// 初始化属性观察器
|
|
37
37
|
static get observedAttributes() {
|
|
38
|
-
return [
|
|
38
|
+
return [
|
|
39
|
+
"loading",
|
|
40
|
+
"color",
|
|
41
|
+
"text",
|
|
42
|
+
"ghost",
|
|
43
|
+
"disabled",
|
|
44
|
+
"height",
|
|
45
|
+
"html-type",
|
|
46
|
+
"type",
|
|
47
|
+
"shape",
|
|
48
|
+
"loading-text"
|
|
49
|
+
];
|
|
39
50
|
}
|
|
40
51
|
attributeChanged(t, r, o) {
|
|
41
52
|
switch (t) {
|
|
@@ -58,13 +69,17 @@ class B extends h {
|
|
|
58
69
|
}
|
|
59
70
|
}
|
|
60
71
|
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(
|
|
72
|
+
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(
|
|
73
|
+
this._state.color,
|
|
74
|
+
this._state.text,
|
|
75
|
+
this._state.ghost
|
|
76
|
+
))), t.has("height") && this._updateHeight(this._state.height);
|
|
62
77
|
}
|
|
63
78
|
connectedCallback() {
|
|
64
|
-
|
|
79
|
+
this.loadStyleText([m, k]), super.connectedCallback(), this.isFormButton() && g(this, "click", this._handleClick), this._updateHeight(this._state.height);
|
|
65
80
|
}
|
|
66
81
|
disconnectedCallback() {
|
|
67
|
-
super.disconnectedCallback(), this.isFormButton() &&
|
|
82
|
+
super.disconnectedCallback(), this.isFormButton() && v(this, "click", this._handleClick), this.$btn = void 0;
|
|
68
83
|
}
|
|
69
84
|
isFormButton() {
|
|
70
85
|
const t = this.getHtmlType();
|
|
@@ -74,7 +89,7 @@ class B extends h {
|
|
|
74
89
|
return this._state.htmlType;
|
|
75
90
|
}
|
|
76
91
|
render() {
|
|
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,
|
|
92
|
+
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, i = [
|
|
78
93
|
"l-btn",
|
|
79
94
|
`l-btn-${t}`,
|
|
80
95
|
e === "round" ? "l-btn-round" : "",
|
|
@@ -83,7 +98,7 @@ class B extends h {
|
|
|
83
98
|
l ? "l-btn-text" : "",
|
|
84
99
|
o ? "l-btn-loading" : ""
|
|
85
100
|
];
|
|
86
|
-
r.className =
|
|
101
|
+
r.className = f(i), (this.disabled || o) && (r.disabled = !0), r.type = this._state.htmlType;
|
|
87
102
|
const n = this.applyColor(this._state.color || "", l, a);
|
|
88
103
|
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);
|
|
89
104
|
}
|
|
@@ -93,8 +108,8 @@ class B extends h {
|
|
|
93
108
|
}
|
|
94
109
|
applyColor(t, r = !1, o = !1) {
|
|
95
110
|
if (!t) return "";
|
|
96
|
-
const e =
|
|
97
|
-
return
|
|
111
|
+
const e = s(t, 1, !0), l = s(t, 3, !1);
|
|
112
|
+
return u({
|
|
98
113
|
"--l-btn-border-color": r ? "transparent" : t,
|
|
99
114
|
"--l-btn-text-color": o || r ? t : "#ffffff",
|
|
100
115
|
"--l-btn-hover-text-color": o || r ? e : "#ffffff",
|
|
@@ -118,5 +133,5 @@ class B extends h {
|
|
|
118
133
|
};
|
|
119
134
|
}
|
|
120
135
|
export {
|
|
121
|
-
|
|
136
|
+
H as default
|
|
122
137
|
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import FormInner from "../form/form_inner";
|
|
2
|
+
type CalendarState = {
|
|
3
|
+
locale: string;
|
|
4
|
+
minDate?: string;
|
|
5
|
+
maxDate?: string;
|
|
6
|
+
};
|
|
7
|
+
export default class Calendar extends FormInner<CalendarState> {
|
|
8
|
+
static baseName: string;
|
|
9
|
+
private _currentDate;
|
|
10
|
+
private _langData;
|
|
11
|
+
private $container?;
|
|
12
|
+
constructor();
|
|
13
|
+
setValue(v: string): void;
|
|
14
|
+
connectedCallback(): void;
|
|
15
|
+
afterInit(): void;
|
|
16
|
+
beforeDestroy(): void;
|
|
17
|
+
static get observedAttributes(): string[];
|
|
18
|
+
protected attributeChanged(name: string, oldValue: string, newValue: string): void;
|
|
19
|
+
protected updateDOM(changedProps: Set<string>): void;
|
|
20
|
+
private _renderHeader;
|
|
21
|
+
private _renderBody;
|
|
22
|
+
rerenderHeader(): void;
|
|
23
|
+
rerenderBody(): void;
|
|
24
|
+
rerender(): string;
|
|
25
|
+
render_v2(): {
|
|
26
|
+
template?: string | HTMLElement | DocumentFragment;
|
|
27
|
+
style?: string | string[];
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,91 @@
|
|
|
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 {
|
|
9
|
+
static baseName = "calendar";
|
|
10
|
+
_currentDate;
|
|
11
|
+
_langData;
|
|
12
|
+
$container;
|
|
13
|
+
constructor() {
|
|
14
|
+
super(), this.version = 2, this._currentDate = /* @__PURE__ */ new Date();
|
|
15
|
+
const e = k("l_app_locale", "zh-CN", { storage: "session" });
|
|
16
|
+
this._state = {
|
|
17
|
+
locale: e
|
|
18
|
+
}, this._langData = y[e];
|
|
19
|
+
}
|
|
20
|
+
setValue(e) {
|
|
21
|
+
e != this.value && (super.setValue(e), this._currentDate = x(e), this.rerenderBody());
|
|
22
|
+
}
|
|
23
|
+
connectedCallback() {
|
|
24
|
+
super.connectedCallback();
|
|
25
|
+
}
|
|
26
|
+
afterInit() {
|
|
27
|
+
this.$container = h(".calendar-table", this.root);
|
|
28
|
+
}
|
|
29
|
+
beforeDestroy() {
|
|
30
|
+
this.$container = void 0;
|
|
31
|
+
}
|
|
32
|
+
static get observedAttributes() {
|
|
33
|
+
return [...u.observedAttributes, "locale"];
|
|
34
|
+
}
|
|
35
|
+
attributeChanged(e, r, o) {
|
|
36
|
+
switch (e) {
|
|
37
|
+
case "locale":
|
|
38
|
+
y.hasOwnProperty(o) && (this._state.locale = o, this._langData = y[o]);
|
|
39
|
+
break;
|
|
40
|
+
case "min-date":
|
|
41
|
+
case "max-date":
|
|
42
|
+
this._state[v(e)] = o;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
updateDOM(e) {
|
|
47
|
+
e.has("locale") && this.rerenderHeader(), this.$container && (this.$container.innerHTML = this.rerender());
|
|
48
|
+
}
|
|
49
|
+
_renderHeader() {
|
|
50
|
+
return `<tr>${this._langData.weekdays.map((r) => `<th>${r}</th>`).join("")}</tr>`;
|
|
51
|
+
}
|
|
52
|
+
_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");
|
|
57
|
+
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>");
|
|
64
|
+
}
|
|
65
|
+
return i;
|
|
66
|
+
}
|
|
67
|
+
rerenderHeader() {
|
|
68
|
+
if (this.$container) {
|
|
69
|
+
const e = h("thead", this.$container);
|
|
70
|
+
e.innerHTML = this._renderHeader();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
rerenderBody() {
|
|
74
|
+
if (this.$container) {
|
|
75
|
+
const e = h("tbody", this.$container);
|
|
76
|
+
e.innerHTML = this._renderBody();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
rerender() {
|
|
80
|
+
return `<thead>${this._renderHeader()}</thead><tbody>${this._renderBody()}</tbody>`;
|
|
81
|
+
}
|
|
82
|
+
render_v2() {
|
|
83
|
+
return {
|
|
84
|
+
template: `<table class="calendar-table">${this.rerender()}</table>`,
|
|
85
|
+
style: [w]
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export {
|
|
90
|
+
A as default
|
|
91
|
+
};
|
|
@@ -1,22 +1,30 @@
|
|
|
1
1
|
import FormInner from "../form/form_inner";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
static baseName: string;
|
|
2
|
+
type DateInputType = "date" | "datetime-local" | "time" | "month" | "week";
|
|
3
|
+
type DatePickerOriState = {
|
|
5
4
|
/** 是否显示日期范围选择 */
|
|
6
5
|
range: boolean;
|
|
7
6
|
/** 范围选择器时,为了性能考虑, 立即改变一个日期后,会延迟 300ms 通知, 以响应其它选择器, 0 - 立即触发 */
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
type: "date" | "datetime-local" | "time" | "month" | "week";
|
|
7
|
+
delay: number;
|
|
8
|
+
type: DateInputType;
|
|
11
9
|
width?: string;
|
|
12
10
|
/** 日期范围 */
|
|
13
11
|
min?: string;
|
|
14
12
|
max?: string;
|
|
15
13
|
allowEmpty: boolean;
|
|
16
|
-
|
|
14
|
+
};
|
|
15
|
+
export default class DatePicker extends FormInner {
|
|
16
|
+
#private;
|
|
17
|
+
static baseName: string;
|
|
18
|
+
_state: DatePickerOriState;
|
|
19
|
+
constructor();
|
|
20
|
+
setValue(v: string): void;
|
|
21
|
+
static get observedAttributes(): string[];
|
|
17
22
|
connectedCallback(): void;
|
|
18
23
|
afterInit(): void;
|
|
19
24
|
beforeDestroy(): void;
|
|
20
25
|
protected attributeChange(name: string, oldValue: string, newValue: string): void;
|
|
26
|
+
protected updateDOM(changedProps: Set<string>): void;
|
|
27
|
+
private _updateWidth;
|
|
21
28
|
render(): DocumentFragment;
|
|
22
29
|
}
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import h from "../form/form_inner.js";
|
|
2
|
+
import { iterate as n, $ as o, on as a, off as r, $$ as l } from "ph-utils/dom";
|
|
3
|
+
import { parse as c } from "ph-utils/date";
|
|
4
|
+
import { unitNumberStr as p, parseAttrValue as d, kebabToCamel as u } from "../utils/index.js";
|
|
5
|
+
const m = ":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 w extends h {
|
|
7
|
+
static baseName = "date-picker-ori";
|
|
8
|
+
#t;
|
|
9
|
+
#e;
|
|
10
|
+
#i;
|
|
11
|
+
// 至上一次触发change后,是否有更改
|
|
12
|
+
#s;
|
|
13
|
+
_state;
|
|
14
|
+
constructor() {
|
|
15
|
+
super(), this._state = {
|
|
16
|
+
range: !1,
|
|
17
|
+
delay: 300,
|
|
18
|
+
type: "date",
|
|
19
|
+
allowEmpty: !0
|
|
20
|
+
}, this.#e = [], this.#s = !1;
|
|
21
|
+
}
|
|
22
|
+
setValue(t) {
|
|
23
|
+
super.setValue(t), this.#e = t.split(","), this.rendered && n(this.#t, (i, e) => {
|
|
24
|
+
i.value = this.#e[e];
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
static get observedAttributes() {
|
|
28
|
+
return [
|
|
29
|
+
...h.observedAttributes,
|
|
30
|
+
"range",
|
|
31
|
+
"delay",
|
|
32
|
+
"type",
|
|
33
|
+
"width",
|
|
34
|
+
"min",
|
|
35
|
+
"max",
|
|
36
|
+
"allow-empty"
|
|
37
|
+
];
|
|
38
|
+
}
|
|
39
|
+
connectedCallback() {
|
|
40
|
+
this.loadStyleText(m), this._updateWidth(), super.connectedCallback();
|
|
41
|
+
}
|
|
42
|
+
afterInit() {
|
|
43
|
+
this.#t = o(".l-date-inner", this.root), a(this.#t, "change", this.#h), this._state.range && (a(this.#t, "focus", this.#d), a(this.#t, "blur", this.#n));
|
|
44
|
+
}
|
|
45
|
+
beforeDestroy() {
|
|
46
|
+
r(this.#t, "change", this.#h), this._state.range && (r(this.#t, "focus", this.#d), r(this.#t, "blur", this.#n)), this.#a();
|
|
47
|
+
}
|
|
48
|
+
attributeChange(t, i, e) {
|
|
49
|
+
switch (t) {
|
|
50
|
+
case "type":
|
|
51
|
+
case "min":
|
|
52
|
+
case "max":
|
|
53
|
+
this._state[t] = e;
|
|
54
|
+
break;
|
|
55
|
+
case "range":
|
|
56
|
+
case "allow-empty":
|
|
57
|
+
this._state[u(t)] = d(e, !1, t);
|
|
58
|
+
break;
|
|
59
|
+
case "delay":
|
|
60
|
+
this._state.delay = d(e, 300);
|
|
61
|
+
break;
|
|
62
|
+
case "width":
|
|
63
|
+
this._state.width = p(e);
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
updateDOM(t) {
|
|
68
|
+
t.has("width") && this._updateWidth();
|
|
69
|
+
}
|
|
70
|
+
_updateWidth() {
|
|
71
|
+
this._state.width ? this.style.setProperty("--l-date-picker-width", this._state.width) : this.style.removeProperty("--l-date-picker-width");
|
|
72
|
+
}
|
|
73
|
+
render() {
|
|
74
|
+
const t = document.createDocumentFragment();
|
|
75
|
+
if (t.appendChild(this.#r(0)), this._state.range) {
|
|
76
|
+
const i = l("span", {
|
|
77
|
+
class: "l-date-range-divider",
|
|
78
|
+
textContent: "-"
|
|
79
|
+
});
|
|
80
|
+
t.appendChild(i), t.appendChild(this.#r(1));
|
|
81
|
+
}
|
|
82
|
+
return t;
|
|
83
|
+
}
|
|
84
|
+
#r(t = 0) {
|
|
85
|
+
return l("input", {
|
|
86
|
+
type: this._state.type,
|
|
87
|
+
class: `l-date-inner l-date-inner${t}`,
|
|
88
|
+
name: this.getName(),
|
|
89
|
+
value: this.#e[t],
|
|
90
|
+
"l-datepicker": `${t}`,
|
|
91
|
+
disabled: this.isDisabled() ? !0 : void 0,
|
|
92
|
+
min: this._state.min,
|
|
93
|
+
max: this._state.max
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
#h = (t) => {
|
|
97
|
+
const i = t.target, e = Number(i.getAttribute("l-datepicker"));
|
|
98
|
+
let s = i.value;
|
|
99
|
+
!s && !this._state.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._state.range ? this.#l() : this.#o();
|
|
100
|
+
};
|
|
101
|
+
#a() {
|
|
102
|
+
this.#i !== -1 && (clearTimeout(this.#i), this.#i = -1);
|
|
103
|
+
}
|
|
104
|
+
#l() {
|
|
105
|
+
this.#s && (this.#a(), this.#i = setTimeout(() => {
|
|
106
|
+
this.#o(), this.#s = !1;
|
|
107
|
+
}, this._state.delay));
|
|
108
|
+
}
|
|
109
|
+
#d = () => {
|
|
110
|
+
this.#a();
|
|
111
|
+
};
|
|
112
|
+
#n = () => {
|
|
113
|
+
this.#l();
|
|
114
|
+
};
|
|
115
|
+
#o() {
|
|
116
|
+
this.dispatchEvent(
|
|
117
|
+
new CustomEvent("change", {
|
|
118
|
+
detail: {
|
|
119
|
+
value: this.getValue(),
|
|
120
|
+
dateStr: this.#e,
|
|
121
|
+
dates: this.#e.map((t) => c(t))
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
export {
|
|
128
|
+
w as default
|
|
129
|
+
};
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import BaseComponent from "../base";
|
|
2
|
-
|
|
3
|
-
#private;
|
|
4
|
-
static baseName: string;
|
|
2
|
+
type DialogContainerState = {
|
|
5
3
|
/** 是否显示标题栏 */
|
|
6
4
|
showHeader: boolean;
|
|
7
5
|
/** 头部内容 */
|
|
@@ -18,11 +16,21 @@ export default class DialogContainer extends BaseComponent {
|
|
|
18
16
|
okText: string;
|
|
19
17
|
/** 是否显示右上角关闭按钮, 1 - 显示在框内, 2 - 显示在框角, 0 - 不显示 */
|
|
20
18
|
showClose: number;
|
|
19
|
+
/** 容器类名 */
|
|
21
20
|
containerClass?: string;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
};
|
|
22
|
+
export default class DialogContainer extends BaseComponent<DialogContainerState> {
|
|
23
|
+
#private;
|
|
24
|
+
static baseName: string;
|
|
25
|
+
constructor();
|
|
26
|
+
afterInit(): void;
|
|
27
|
+
beforeDestroy(): void;
|
|
25
28
|
static get observedAttributes(): string[] | null | undefined;
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
protected attributeChanged(name: string, oldValue: string, newValue: string): void;
|
|
30
|
+
render_v2(): {
|
|
31
|
+
template?: string | HTMLElement | DocumentFragment;
|
|
32
|
+
style?: string | string[];
|
|
33
|
+
};
|
|
34
|
+
render(): DocumentFragment;
|
|
28
35
|
}
|
|
36
|
+
export {};
|