litos-ui 0.1.0 → 0.2.0
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 +6 -3
- package/lib/base.js +49 -39
- package/lib/browser.d.ts +5 -4
- package/lib/button/index.d.ts +4 -0
- package/lib/button/index.js +73 -59
- package/lib/form/form_events.d.ts +12 -4
- package/lib/form/form_events.js +19 -15
- package/lib/form/form_inner.d.ts +34 -0
- package/lib/form/form_inner.js +121 -0
- package/lib/form/form_item.d.ts +33 -0
- package/lib/form/form_item.js +124 -7
- package/lib/form/index.d.ts +22 -1
- package/lib/form/index.js +108 -19
- package/lib/form/types.js +1 -0
- package/lib/icon/arrow_down.js +8 -6
- package/lib/icon/base.js +24 -19
- package/lib/icon/caret_bottom.js +8 -6
- package/lib/icon/caret_top.js +8 -6
- package/lib/icon/font_icon.js +18 -13
- package/lib/icon/info.js +8 -6
- package/lib/icon/loading.js +8 -6
- package/lib/icon/mask_close.js +8 -6
- package/lib/icon/search.js +8 -6
- package/lib/icon/success.js +7 -5
- package/lib/icon/warn.js +8 -6
- package/lib/index-B_9rPBWp.js +4 -0
- package/lib/index-Boq1Q7q9.js +4 -0
- package/lib/index-CCcVpk6U.js +4 -0
- package/lib/index-ColsUDnt.js +4 -0
- package/lib/index.d.ts +8 -4
- package/lib/index.js +29 -25
- package/lib/input/index.d.ts +17 -16
- package/lib/input/index.js +86 -86
- package/lib/litos-ui.css +1 -1
- package/lib/litos-ui.min.js +1 -1
- package/lib/radio/index.d.ts +27 -0
- package/lib/radio/index.js +113 -0
- package/lib/transition.js +27 -22
- package/lib/util.js +23 -20
- package/package.json +6 -5
- package/styles/reset.css +5 -0
- package/lib/index-CWq5_ldX.js +0 -4
- package/lib/index-CbaSCp33.js +0 -4
- package/lib/index-JjjljTZ2.js +0 -4
package/lib/base.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export default class BaseComponent extends HTMLElement {
|
|
2
2
|
static baseName: string;
|
|
3
|
+
rendered: boolean;
|
|
3
4
|
constructor(shadow?: boolean);
|
|
4
5
|
/**
|
|
5
6
|
* 返回一个数组,表示观察的属性列表
|
|
@@ -7,10 +8,12 @@ export default class BaseComponent extends HTMLElement {
|
|
|
7
8
|
static get observedAttributes(): string[] | undefined | null;
|
|
8
9
|
attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
|
|
9
10
|
get shadow(): ShadowRoot;
|
|
11
|
+
get root(): ShadowRoot | HTMLElement;
|
|
10
12
|
createStyle(text: string): void;
|
|
11
13
|
createLink(href: string): void;
|
|
12
14
|
loadStyle(styleNames: string[]): void;
|
|
13
15
|
loadExternalStyle(styleNames: string[]): void;
|
|
16
|
+
loadStyleText(styleText: string): void;
|
|
14
17
|
setProperty(key: string, value: any): void;
|
|
15
18
|
setProperties(properties: Record<string, any>): void;
|
|
16
19
|
/**
|
|
@@ -23,9 +26,9 @@ export default class BaseComponent extends HTMLElement {
|
|
|
23
26
|
* @param key 属性名称
|
|
24
27
|
* @param defaultValue 默认值
|
|
25
28
|
*/
|
|
26
|
-
getAttr(
|
|
27
|
-
getAttr(
|
|
28
|
-
getAttr(
|
|
29
|
+
getAttr(key: string, defaultValue: string): string;
|
|
30
|
+
getAttr(key: string, defaultValue: number): number;
|
|
31
|
+
getAttr(key: string, defaultValue: boolean): boolean;
|
|
29
32
|
getAttr<T extends Record<string, string | number | boolean>>(filepath: string, defaultValue: T): T;
|
|
30
33
|
connectedCallback(): void;
|
|
31
34
|
disconnectedCallback(): void;
|
package/lib/base.js
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var d = Object.defineProperty;
|
|
2
|
+
var c = (s, n, e) => n in s ? d(s, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[n] = e;
|
|
3
|
+
var l = (s, n, e) => c(s, typeof n != "symbol" ? n + "" : n, e);
|
|
4
|
+
import { getAttr as h } from "ph-utils/dom";
|
|
5
|
+
const a = (s, n, e) => {
|
|
6
|
+
const t = s[n];
|
|
7
|
+
return t ? typeof t == "function" ? t() : Promise.resolve(t) : new Promise((r, o) => {
|
|
5
8
|
(typeof queueMicrotask == "function" ? queueMicrotask : setTimeout)(
|
|
6
|
-
|
|
9
|
+
o.bind(
|
|
7
10
|
null,
|
|
8
11
|
new Error(
|
|
9
|
-
"Unknown variable dynamic import: " +
|
|
12
|
+
"Unknown variable dynamic import: " + n + (n.split("/").length !== e ? ". Note that variables only represent file names one level deep." : "")
|
|
10
13
|
)
|
|
11
14
|
)
|
|
12
15
|
);
|
|
13
16
|
});
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
};
|
|
18
|
+
class u extends HTMLElement {
|
|
19
|
+
constructor(e = !0) {
|
|
20
|
+
super();
|
|
21
|
+
l(this, "rendered", !1);
|
|
22
|
+
e && this.attachShadow({ mode: "open" });
|
|
17
23
|
}
|
|
18
24
|
/**
|
|
19
25
|
* 返回一个数组,表示观察的属性列表
|
|
@@ -22,56 +28,60 @@ const o = (a, t, e) => {
|
|
|
22
28
|
return [];
|
|
23
29
|
}
|
|
24
30
|
// 当属性发生变化时调用的回调函数
|
|
25
|
-
|
|
26
|
-
attributeChangedCallback(t, e, n) {
|
|
31
|
+
attributeChangedCallback(e, t, r) {
|
|
27
32
|
}
|
|
28
33
|
get shadow() {
|
|
29
34
|
return this.shadowRoot;
|
|
30
35
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
get root() {
|
|
37
|
+
return this.shadowRoot || this;
|
|
38
|
+
}
|
|
39
|
+
createStyle(e) {
|
|
40
|
+
const t = document.createElement("style");
|
|
41
|
+
t.textContent = e.trim(), this.shadow.appendChild(t);
|
|
34
42
|
}
|
|
35
|
-
createLink(
|
|
36
|
-
const
|
|
37
|
-
|
|
43
|
+
createLink(e) {
|
|
44
|
+
const t = document.createElement("link");
|
|
45
|
+
t.rel = "stylesheet", t.href = e, this.shadow.appendChild(t);
|
|
38
46
|
}
|
|
39
|
-
loadStyle(
|
|
40
|
-
for (let
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
this.createStyle(
|
|
47
|
+
loadStyle(e) {
|
|
48
|
+
for (let t = 0, r = e.length; t < r; t++) {
|
|
49
|
+
const o = e[t];
|
|
50
|
+
a(/* @__PURE__ */ Object.assign({ "./button/index.less": () => import("./index-Boq1Q7q9.js"), "./form/index.less": () => import("./index-ColsUDnt.js"), "./icon/index.less": () => import("./index-DZ2ZMrk1.js"), "./input/index.less": () => import("./index-B_9rPBWp.js"), "./radio/index.less": () => import("./index-CCcVpk6U.js") }), `./${o}/index.less`, 3).then((i) => {
|
|
51
|
+
this.createStyle(i.default);
|
|
44
52
|
});
|
|
45
53
|
}
|
|
46
54
|
}
|
|
47
|
-
loadExternalStyle(
|
|
48
|
-
for (let
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
this.createStyle(
|
|
55
|
+
loadExternalStyle(e) {
|
|
56
|
+
for (let t = 0, r = e.length; t < r; t++) {
|
|
57
|
+
const o = e[t];
|
|
58
|
+
a(/* @__PURE__ */ Object.assign({ "./styles/animation.css": () => import("./animation-QfX4RtqD.js") }), `./styles/${o}.css`, 3).then((i) => {
|
|
59
|
+
this.createStyle(i.default);
|
|
52
60
|
});
|
|
53
61
|
}
|
|
54
62
|
}
|
|
55
|
-
|
|
56
|
-
this
|
|
63
|
+
loadStyleText(e) {
|
|
64
|
+
this.createStyle(e);
|
|
57
65
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
this.setProperty(e, t[e]);
|
|
66
|
+
setProperty(e, t) {
|
|
67
|
+
this[e] = t;
|
|
61
68
|
}
|
|
62
|
-
|
|
63
|
-
|
|
69
|
+
setProperties(e) {
|
|
70
|
+
for (const t in e)
|
|
71
|
+
this.setProperty(t, e[t]);
|
|
72
|
+
}
|
|
73
|
+
getAttr(e, t) {
|
|
74
|
+
return h(this, e, t);
|
|
64
75
|
}
|
|
65
76
|
connectedCallback() {
|
|
66
|
-
this.render();
|
|
77
|
+
this.render(), this.rendered = !0;
|
|
67
78
|
}
|
|
68
79
|
disconnectedCallback() {
|
|
69
80
|
}
|
|
70
81
|
render() {
|
|
71
82
|
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
let l = i;
|
|
83
|
+
}
|
|
84
|
+
l(u, "baseName", "base-component");
|
|
75
85
|
export {
|
|
76
|
-
|
|
86
|
+
u as default
|
|
77
87
|
};
|
package/lib/browser.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import "../../styles/reset.css";
|
|
2
2
|
import "../../styles/message.css";
|
|
3
3
|
import "./styles/animation.css";
|
|
4
|
-
import "./button/index.
|
|
5
|
-
import "./icon/index.
|
|
6
|
-
import "./input/index.
|
|
7
|
-
import "./form/index.
|
|
4
|
+
import "./button/index.less";
|
|
5
|
+
import "./icon/index.less";
|
|
6
|
+
import "./input/index.less";
|
|
7
|
+
import "./form/index.less";
|
|
8
|
+
import "./radio/index.less";
|
package/lib/button/index.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import BaseComponent from "../base";
|
|
2
2
|
export default class Button extends BaseComponent {
|
|
3
3
|
static baseName: string;
|
|
4
|
+
htmlType: "submit" | "reset" | "button";
|
|
4
5
|
constructor();
|
|
5
6
|
static get observedAttributes(): string[];
|
|
6
7
|
attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
|
|
7
8
|
connectedCallback(): void;
|
|
9
|
+
disconnectedCallback(): void;
|
|
8
10
|
render(): void;
|
|
9
11
|
loadingBody(): string;
|
|
10
12
|
applyColor(color: string, text?: boolean, ghost?: boolean): string;
|
|
13
|
+
private _handleClick;
|
|
14
|
+
private _getForm;
|
|
11
15
|
}
|
package/lib/button/index.js
CHANGED
|
@@ -1,82 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
n && (s += `${n};`);
|
|
12
|
-
}
|
|
13
|
-
else
|
|
14
|
-
for (const t in r)
|
|
15
|
-
r[t] && (s += `${t}:${r[t]};`);
|
|
16
|
-
return s;
|
|
17
|
-
}
|
|
18
|
-
h(y);
|
|
19
|
-
const a = class a extends p {
|
|
1
|
+
var b = Object.defineProperty;
|
|
2
|
+
var h = (r, o, t) => o in r ? b(r, o, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[o] = t;
|
|
3
|
+
var i = (r, o, t) => h(r, typeof o != "symbol" ? o + "" : o, t);
|
|
4
|
+
import { regist as p, initAttr as g, parseAttrValue as m } from "../util.js";
|
|
5
|
+
import u from "../base.js";
|
|
6
|
+
import { $one as y, addClass as k, removeClass as A, on as C, off as T, formatClass as $, formatStyle as v, getAttr as x } from "ph-utils/dom";
|
|
7
|
+
import L from "../icon/loading.js";
|
|
8
|
+
import { adjust as d } from "ph-utils/color";
|
|
9
|
+
p(L);
|
|
10
|
+
class M extends u {
|
|
20
11
|
constructor() {
|
|
21
|
-
super()
|
|
12
|
+
super();
|
|
13
|
+
i(this, "htmlType", "button");
|
|
14
|
+
i(this, "_handleClick", (t) => {
|
|
15
|
+
const e = t.target, s = x(e, "html-type");
|
|
16
|
+
if (s === "reset" || s === "submit") {
|
|
17
|
+
const l = this._getForm();
|
|
18
|
+
l && (s === "reset" ? l.reset() : s === "submit" && l.submit());
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
g(this);
|
|
22
22
|
}
|
|
23
23
|
// 初始化属性观察器
|
|
24
24
|
static get observedAttributes() {
|
|
25
25
|
return ["loading", "color"];
|
|
26
26
|
}
|
|
27
27
|
// 当属性发生变化时调用的回调函数
|
|
28
|
-
attributeChangedCallback(
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
n.style.cssText = this.applyColor(e, o, l);
|
|
28
|
+
attributeChangedCallback(t, e, s) {
|
|
29
|
+
const l = y(".l-button", this.root);
|
|
30
|
+
if (l) {
|
|
31
|
+
if (t === "loading")
|
|
32
|
+
m(s, !1, t) ? (k(l, "l-btn-loading"), l.disabled = !0, l.innerHTML = this.loadingBody()) : (A(l, "l-btn-loading"), l.disabled = this.getAttr("disabled", !1), l.innerHTML = "<slot></slot>");
|
|
33
|
+
else if (t === "color") {
|
|
34
|
+
const n = this.getAttr("text", !1), a = this.getAttr("ghost", !1);
|
|
35
|
+
l.style.cssText = this.applyColor(s, n, a);
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
39
|
connectedCallback() {
|
|
41
|
-
this.loadStyle(["button"]), this.render();
|
|
40
|
+
this.loadStyle(["button"]), this.loadExternalStyle(["animation"]), this.render(), (this.htmlType === "reset" || this.htmlType === "submit") && C(this, "click", this._handleClick);
|
|
41
|
+
}
|
|
42
|
+
disconnectedCallback() {
|
|
43
|
+
super.disconnectedCallback(), (this.htmlType === "reset" || this.htmlType === "submit") && T(this, "click", this._handleClick);
|
|
42
44
|
}
|
|
43
45
|
render() {
|
|
44
|
-
const
|
|
46
|
+
const t = this.getAttr("type", "normal"), e = document.createElement("button"), s = this.getAttr("loading", !1), l = this.getAttr("shape", "default"), n = this.getAttr("text", !1), a = this.getAttr("ghost", !1), f = [
|
|
45
47
|
"l-btn",
|
|
46
|
-
`l-btn-${
|
|
48
|
+
`l-btn-${t}`,
|
|
47
49
|
this.getAttr("block", !1) ? "l-btn-block" : "",
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
l === "round" ? "l-btn-round" : "",
|
|
51
|
+
l === "circle" ? "l-btn-circle" : "",
|
|
52
|
+
a ? "l-btn-ghost" : "",
|
|
53
|
+
n ? "l-btn-text" : "",
|
|
54
|
+
s ? "l-btn-loading" : ""
|
|
53
55
|
];
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
56
|
+
e.className = $(f), e.disabled = this.getAttr("disabled", !1) || s, e.type = this.getAttr("html-type", "button");
|
|
57
|
+
const c = this.applyColor(this.getAttr("color"), n, a);
|
|
58
|
+
c && (e.style.cssText = c), s ? e.innerHTML = this.loadingBody() : e.innerHTML = "<slot></slot>", e.setAttribute("part", "default"), this.root.appendChild(e);
|
|
57
59
|
}
|
|
58
60
|
loadingBody() {
|
|
59
|
-
const
|
|
60
|
-
return
|
|
61
|
+
const t = this.getAttr("loading-text", ""), e = ['<l-loading-icon class="l-rotate-anim"></l-loading-icon>'];
|
|
62
|
+
return t === "" ? e.push("<slot></slot>") : e.push(`<span>${t}</span>`), e.join("");
|
|
61
63
|
}
|
|
62
|
-
applyColor(
|
|
63
|
-
if (!
|
|
64
|
-
const
|
|
65
|
-
return
|
|
66
|
-
"--l-btn-border-color":
|
|
67
|
-
"--l-btn-text-color":
|
|
68
|
-
"--l-btn-hover-text-color":
|
|
69
|
-
"--l-btn-background":
|
|
70
|
-
"--l-btn-active-text-color":
|
|
71
|
-
"--l-btn-hover-border-color":
|
|
72
|
-
"--l-btn-hover-background":
|
|
73
|
-
"--l-btn-active-background":
|
|
74
|
-
"--l-btn-active-border-color":
|
|
64
|
+
applyColor(t, e = !1, s = !1) {
|
|
65
|
+
if (!t) return "";
|
|
66
|
+
const l = d(t, 1, !0), n = d(t, 3, !1);
|
|
67
|
+
return v({
|
|
68
|
+
"--l-btn-border-color": e ? "transparent" : t,
|
|
69
|
+
"--l-btn-text-color": s || e ? t : "#ffffff",
|
|
70
|
+
"--l-btn-hover-text-color": s || e ? l : "#ffffff",
|
|
71
|
+
"--l-btn-background": s || e ? "transparent" : t,
|
|
72
|
+
"--l-btn-active-text-color": s || e ? n : "#ffffff",
|
|
73
|
+
"--l-btn-hover-border-color": e ? "transparent" : l,
|
|
74
|
+
"--l-btn-hover-background": s || e ? "transparent" : l,
|
|
75
|
+
"--l-btn-active-background": s || e ? "transparent" : n,
|
|
76
|
+
"--l-btn-active-border-color": e ? "transparent" : n
|
|
75
77
|
});
|
|
76
78
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
_getForm() {
|
|
80
|
+
let t = this.parentElement, e;
|
|
81
|
+
for (; t != null; ) {
|
|
82
|
+
const s = t.tagName;
|
|
83
|
+
if (s === "L-FORM") {
|
|
84
|
+
e = t;
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
if (s === "BODY") break;
|
|
88
|
+
t = t.parentElement;
|
|
89
|
+
}
|
|
90
|
+
return t = null, e;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
i(M, "baseName", "button");
|
|
80
94
|
export {
|
|
81
|
-
|
|
95
|
+
M as default
|
|
82
96
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
type EventName = "attributeChanged" | "formSubmitted" | "ruleChange" | "valueChange" | "validateChange" | "reset" | "submit";
|
|
1
2
|
/**
|
|
2
3
|
* 添加表单事件监听器。
|
|
3
4
|
* @param formId - 表单的唯一标识符。
|
|
@@ -5,7 +6,7 @@
|
|
|
5
6
|
* @param cb - 当事件触发时调用的回调函数,接收两个参数:属性名和属性值。
|
|
6
7
|
* 该函数用于将回调函数添加到指定表单ID的事件监听器集合中。
|
|
7
8
|
*/
|
|
8
|
-
export declare function add(
|
|
9
|
+
export declare function add(id: string, event: EventName, cb: (...param: any) => void): void;
|
|
9
10
|
/**
|
|
10
11
|
* 移除指定表单的事件监听器。
|
|
11
12
|
* @param formId - 表单的唯一标识符。
|
|
@@ -14,11 +15,18 @@ export declare function add(formId: string, event: "attributeChanged" | "formSub
|
|
|
14
15
|
* 该函数会从事件存储中移除指定的回调函数,如果某个事件类型下没有更多的回调函数,则删除该事件类型;
|
|
15
16
|
* 如果表单下没有更多的事件类型,则删除该表单;如果事件存储为空,则重置事件存储。
|
|
16
17
|
*/
|
|
17
|
-
export declare function remove(
|
|
18
|
+
export declare function remove(id: string, event: EventName, cb: (...params: any) => void): void;
|
|
19
|
+
/**
|
|
20
|
+
* 清除事件存储。如果提供了ID,则删除特定ID的事件;如果没有提供ID,则清除所有事件。
|
|
21
|
+
* 当事件存储为空时,将其设置为undefined。
|
|
22
|
+
* @param id 可选参数,指定要删除的事件ID。
|
|
23
|
+
*/
|
|
24
|
+
export declare function clear(id?: string): void;
|
|
18
25
|
/**
|
|
19
26
|
* 触发指定表单的事件,并执行所有注册的回调函数。
|
|
20
|
-
* @param
|
|
27
|
+
* @param id - 表单的唯一标识符。
|
|
21
28
|
* @param event - 要触发的事件名称。
|
|
22
29
|
* @param params - 要传递给回调函数的参数列表。
|
|
23
30
|
*/
|
|
24
|
-
export declare function emit(
|
|
31
|
+
export declare function emit(id: string, event: EventName, ...params: any): void;
|
|
32
|
+
export {};
|
package/lib/form/form_events.js
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
let
|
|
2
|
-
function
|
|
3
|
-
|
|
1
|
+
let e;
|
|
2
|
+
function n(l, f, t) {
|
|
3
|
+
e == null && (e = /* @__PURE__ */ new Map()), e.has(l) || e.set(l, /* @__PURE__ */ new Map([[f, /* @__PURE__ */ new Set()]])), e.get(l).has(f) || e.get(l).set(f, /* @__PURE__ */ new Set()), e.get(l).get(f).add(t);
|
|
4
4
|
}
|
|
5
|
-
function
|
|
6
|
-
var
|
|
7
|
-
(
|
|
5
|
+
function r(l, f, t) {
|
|
6
|
+
var i, o, g, u, a, c;
|
|
7
|
+
(o = (i = e == null ? void 0 : e.get(l)) == null ? void 0 : i.get(f)) == null || o.delete(t), ((u = (g = e == null ? void 0 : e.get(l)) == null ? void 0 : g.get(f)) == null ? void 0 : u.size) == 0 && ((a = e.get(l)) == null || a.delete(f)), ((c = e == null ? void 0 : e.get(l)) == null ? void 0 : c.size) == 0 && e.delete(l), (e == null ? void 0 : e.size) == 0 && (e = void 0);
|
|
8
8
|
}
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
function w(l) {
|
|
10
|
+
l == null ? e != null && (e.clear(), e = void 0) : e != null && (e.delete(l), e.size === 0 && (e = void 0));
|
|
11
|
+
}
|
|
12
|
+
function z(l, f, ...t) {
|
|
13
|
+
var o;
|
|
14
|
+
const i = (o = e == null ? void 0 : e.get(l)) == null ? void 0 : o.get(f);
|
|
15
|
+
if (i != null)
|
|
16
|
+
for (const g of i)
|
|
17
|
+
g(...t);
|
|
15
18
|
}
|
|
16
19
|
export {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
z as
|
|
20
|
+
n as add,
|
|
21
|
+
w as clear,
|
|
22
|
+
z as emit,
|
|
23
|
+
r as remove
|
|
20
24
|
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import BaseComponent from "../base";
|
|
2
|
+
export default class FormInner extends BaseComponent {
|
|
3
|
+
disabled: boolean;
|
|
4
|
+
name?: string;
|
|
5
|
+
protected formAttrs: Record<string, any>;
|
|
6
|
+
protected formItemAttrs: Record<string, any>;
|
|
7
|
+
_value: any;
|
|
8
|
+
_resetValue?: any;
|
|
9
|
+
protected _firstPushValue: boolean;
|
|
10
|
+
private _reseting;
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param firstPushValue 是否第一次赋值 value 时, 推送数据到 Form, 默认: true
|
|
14
|
+
*/
|
|
15
|
+
constructor(firstPushValue?: boolean);
|
|
16
|
+
set value(value: any);
|
|
17
|
+
get value(): any;
|
|
18
|
+
setValue(value: any): void;
|
|
19
|
+
getValue(): any;
|
|
20
|
+
static get observedAttributes(): string[];
|
|
21
|
+
attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
|
|
22
|
+
protected attributeChange(name: string, oldValue: string, newValue: string): void;
|
|
23
|
+
connectedCallback(): void;
|
|
24
|
+
disconnectedCallback(): void;
|
|
25
|
+
isDisabled(): any;
|
|
26
|
+
getName(): any;
|
|
27
|
+
private _getForm;
|
|
28
|
+
private _formAttributeChanged;
|
|
29
|
+
/** disable 属性改变时回调 */
|
|
30
|
+
protected _changeDisabled(): void;
|
|
31
|
+
protected pushValueChange(): void;
|
|
32
|
+
private _resetFieldValue;
|
|
33
|
+
reset(): void;
|
|
34
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
var d = Object.defineProperty;
|
|
2
|
+
var n = (h, r, t) => r in h ? d(h, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : h[r] = t;
|
|
3
|
+
var e = (h, r, t) => n(h, typeof r != "symbol" ? r + "" : r, t);
|
|
4
|
+
import A from "../base.js";
|
|
5
|
+
import { parseAttrValue as g } from "../util.js";
|
|
6
|
+
import { add as o, remove as u, emit as b } from "./form_events.js";
|
|
7
|
+
class I extends A {
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param firstPushValue 是否第一次赋值 value 时, 推送数据到 Form, 默认: true
|
|
11
|
+
*/
|
|
12
|
+
constructor(t = !0) {
|
|
13
|
+
super();
|
|
14
|
+
e(this, "disabled", !1);
|
|
15
|
+
e(this, "name");
|
|
16
|
+
e(this, "formAttrs", {});
|
|
17
|
+
e(this, "formItemAttrs", {});
|
|
18
|
+
e(this, "_value", "");
|
|
19
|
+
e(this, "_resetValue");
|
|
20
|
+
e(this, "_firstPushValue", !0);
|
|
21
|
+
e(this, "_reseting", !1);
|
|
22
|
+
e(this, "_formAttributeChanged", (t, s, i) => {
|
|
23
|
+
i === this.formAttrs.formId ? this.formAttrs[t] = s : this.formItemAttrs[t] = s, t === "disabled" && this._changeDisabled();
|
|
24
|
+
});
|
|
25
|
+
e(this, "_resetFieldValue", () => {
|
|
26
|
+
this._reseting = !0, this.reset();
|
|
27
|
+
});
|
|
28
|
+
this._firstPushValue = t;
|
|
29
|
+
}
|
|
30
|
+
set value(t) {
|
|
31
|
+
this.setValue(t);
|
|
32
|
+
}
|
|
33
|
+
get value() {
|
|
34
|
+
return this.getValue();
|
|
35
|
+
}
|
|
36
|
+
setValue(t) {
|
|
37
|
+
this._value = t, this.pushValueChange();
|
|
38
|
+
}
|
|
39
|
+
getValue() {
|
|
40
|
+
return this._value;
|
|
41
|
+
}
|
|
42
|
+
static get observedAttributes() {
|
|
43
|
+
return ["disabled"];
|
|
44
|
+
}
|
|
45
|
+
attributeChangedCallback(t, s, i) {
|
|
46
|
+
if (t === "disabled") {
|
|
47
|
+
const l = g(i, !1, t);
|
|
48
|
+
l !== this.disabled && (this._changeDisabled(), this.disabled = l);
|
|
49
|
+
} else
|
|
50
|
+
this.attributeChange(t, s, i);
|
|
51
|
+
}
|
|
52
|
+
attributeChange(t, s, i) {
|
|
53
|
+
}
|
|
54
|
+
connectedCallback() {
|
|
55
|
+
const t = this._getForm();
|
|
56
|
+
this.formAttrs = t.formAttr, this.formItemAttrs = t.formItemAttr, this.formAttrs.id && (o(this.formAttrs.id, "attributeChanged", this._formAttributeChanged), o(this.formAttrs.id, "reset", this._resetFieldValue), this._firstPushValue && this.pushValueChange()), this.formItemAttrs.id && o(
|
|
57
|
+
this.formItemAttrs.id,
|
|
58
|
+
"attributeChanged",
|
|
59
|
+
this._formAttributeChanged
|
|
60
|
+
), this.render();
|
|
61
|
+
}
|
|
62
|
+
disconnectedCallback() {
|
|
63
|
+
this.formAttrs.id && (u(this.formAttrs.id, "attributeChanged", this._formAttributeChanged), u(this.formAttrs.id, "reset", this._resetFieldValue)), this.formItemAttrs.id && u(
|
|
64
|
+
this.formItemAttrs.id,
|
|
65
|
+
"attributeChanged",
|
|
66
|
+
this._formAttributeChanged
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
isDisabled() {
|
|
70
|
+
return this.disabled === !0 || this.formItemAttrs.disabled === !0 ? !0 : this.formAttrs.disabled || !1;
|
|
71
|
+
}
|
|
72
|
+
getName() {
|
|
73
|
+
return this.name ? this.name : this.formItemAttrs.name;
|
|
74
|
+
}
|
|
75
|
+
_getForm() {
|
|
76
|
+
let t = this.parentElement, s = {}, i = {};
|
|
77
|
+
for (; t != null; ) {
|
|
78
|
+
const l = t.tagName;
|
|
79
|
+
if (l === "L-FORM") {
|
|
80
|
+
const f = t.sharedAttrs;
|
|
81
|
+
for (let a = 0; a < f.length; a++) {
|
|
82
|
+
const m = f[a];
|
|
83
|
+
s[m] = t[m];
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
if (l === "BODY") break;
|
|
88
|
+
if (l === "L-FORM-ITEM") {
|
|
89
|
+
const f = t.sharedAttrs;
|
|
90
|
+
for (let a = 0; a < f.length; a++) {
|
|
91
|
+
const m = f[a];
|
|
92
|
+
i[m] = t[m];
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
t = t.parentElement;
|
|
96
|
+
}
|
|
97
|
+
return t = null, {
|
|
98
|
+
formAttr: s,
|
|
99
|
+
formItemAttr: i
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** disable 属性改变时回调 */
|
|
103
|
+
_changeDisabled() {
|
|
104
|
+
}
|
|
105
|
+
pushValueChange() {
|
|
106
|
+
const t = this.getName();
|
|
107
|
+
this.formAttrs.id && t && b(
|
|
108
|
+
this.formAttrs.id,
|
|
109
|
+
"valueChange",
|
|
110
|
+
t,
|
|
111
|
+
this._value,
|
|
112
|
+
!this._reseting
|
|
113
|
+
), this._reseting = !1;
|
|
114
|
+
}
|
|
115
|
+
reset() {
|
|
116
|
+
this.value = this._resetValue || "";
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export {
|
|
120
|
+
I as default
|
|
121
|
+
};
|
package/lib/form/form_item.d.ts
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
import BaseComponent from "../base";
|
|
2
|
+
import type { RuleType } from "ph-utils/validator";
|
|
2
3
|
export default class FormItem extends BaseComponent {
|
|
3
4
|
static baseName: string;
|
|
4
5
|
disabled: boolean;
|
|
5
6
|
sharedAttrs: string[];
|
|
7
|
+
/** 是否必须 */
|
|
8
|
+
required: boolean;
|
|
9
|
+
error?: string;
|
|
10
|
+
/** 标签文本 */
|
|
11
|
+
label?: string;
|
|
12
|
+
id: string;
|
|
13
|
+
/** 内置验证规则: required - 必填, same:password - 一般用于验证确认密码和密码, phone - 验证电话号码 */
|
|
14
|
+
verify?: string;
|
|
15
|
+
/** 验证失败错误信息 */
|
|
16
|
+
validity?: string;
|
|
17
|
+
/** 自定义验证的正则 */
|
|
18
|
+
pattern?: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
innerBlock: boolean;
|
|
21
|
+
labelPosition?: "left" | "right" | "top";
|
|
22
|
+
private formId?;
|
|
23
|
+
constructor();
|
|
24
|
+
static get observedAttributes(): string[];
|
|
25
|
+
attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
|
|
26
|
+
connectedCallback(): void;
|
|
27
|
+
disconnectedCallback(): void;
|
|
28
|
+
setRules(rules: {
|
|
29
|
+
required?: boolean;
|
|
30
|
+
rules?: RuleType[];
|
|
31
|
+
message?: string;
|
|
32
|
+
}): void;
|
|
33
|
+
setError(error: string): void;
|
|
34
|
+
render(): void;
|
|
35
|
+
private _validateChange;
|
|
36
|
+
private _updateError;
|
|
37
|
+
private _updateLabel;
|
|
38
|
+
private _getFormId;
|
|
6
39
|
}
|