litos-ui 0.15.5 → 0.15.7
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/button/index.d.ts +4 -0
- package/lib/button/index.js +84 -57
- package/lib/check/checkbox.js +1 -1
- package/lib/check/radio.js +1 -1
- package/lib/{check-BlDsQQo0.js → check-A86JxUfd.js} +1 -1
- package/lib/collapse/index.d.ts +19 -0
- package/lib/collapse/index.js +88 -0
- package/lib/collapse/item.d.ts +15 -0
- package/lib/collapse/item.js +115 -0
- package/lib/color_picker/index.js +1 -1
- package/lib/date_picker/index.js +1 -1
- package/lib/description_panel/index.d.ts +4 -4
- package/lib/description_panel/index.js +59 -11
- package/lib/dialog/dialog_container.js +1 -1
- package/lib/form/form_inner.d.ts +2 -1
- package/lib/form/form_inner.js +16 -15
- package/lib/form/form_item.d.ts +3 -1
- package/lib/form/form_item.js +19 -13
- package/lib/form/index.js +8 -6
- package/lib/icon/d_arrow_left.d.ts +6 -0
- package/lib/icon/d_arrow_left.js +13 -0
- package/lib/icon/d_arrow_right.d.ts +6 -0
- package/lib/icon/d_arrow_right.js +13 -0
- package/lib/icon/more.d.ts +6 -0
- package/lib/icon/more.js +13 -0
- package/lib/icon/select.d.ts +6 -0
- package/lib/icon/select.js +13 -0
- package/lib/icon/zoom_in.d.ts +6 -0
- package/lib/icon/zoom_in.js +13 -0
- package/lib/icon/zoom_out.d.ts +6 -0
- package/lib/icon/zoom_out.js +13 -0
- package/lib/image/image_preview.d.ts +24 -0
- package/lib/image/image_preview.js +104 -0
- package/lib/image/index.d.ts +50 -0
- package/lib/image/index.js +176 -0
- package/lib/index-D4II9KsF.js +4 -0
- package/lib/index.d.ts +36 -4
- package/lib/index.js +157 -120
- package/lib/input/index.d.ts +6 -2
- package/lib/input/index.js +70 -51
- package/lib/litos-ui.css +1 -1
- package/lib/mask/index.d.ts +23 -0
- package/lib/mask/index.js +110 -0
- package/lib/md_input/index.js +11 -11
- package/lib/menu/index.js +46 -42
- package/lib/modal/index.d.ts +1 -1
- package/lib/modal/index.js +7 -7
- package/lib/modal/modal_box.js +10 -10
- package/lib/page_header/index.d.ts +20 -0
- package/lib/page_header/index.js +109 -0
- package/lib/pagination/index.d.ts +27 -0
- package/lib/pagination/index.js +248 -0
- package/lib/qrcode/index.js +4 -4
- package/lib/select/index.d.ts +79 -0
- package/lib/select/index.js +406 -0
- package/lib/select_ori/index.js +10 -10
- package/lib/switch/index.js +4 -4
- package/lib/tabbar/index.js +1 -1
- package/lib/tabbar/item.js +1 -1
- package/lib/table/index.d.ts +46 -0
- package/lib/table/index.js +200 -0
- package/lib/table/types.d.ts +28 -0
- package/lib/table/types.js +1 -0
- package/lib/tabs/index.d.ts +7 -0
- package/lib/tabs/index.js +43 -0
- package/lib/tag/index.d.ts +16 -0
- package/lib/tag/index.js +77 -0
- package/lib/theme/index.js +6 -6
- package/lib/utils/index.d.ts +6 -28
- package/lib/utils/index.js +61 -86
- package/lib/utils/popover.d.ts +137 -0
- package/lib/utils/popover.js +354 -0
- package/lib/utils/transition.js +26 -50
- package/package.json +13 -13
- package/styles/popover.css +66 -0
- package/styles/reset.css +1 -1
- package/styles/select.css +37 -0
- package/styles/tabs.css +13 -0
- package/styles/vars.css +2 -1
- package/lib/index-dwS1N2uN.js +0 -4
- package/lib/popconfirm/index.d.ts +0 -7
- package/lib/popconfirm/index.js +0 -30
- package/lib/popover/index.d.ts +0 -34
- package/lib/popover/index.js +0 -150
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import c from "../base.js";
|
|
2
|
+
import { kebabToCamel as f, parseAttrValue as b } from "../utils/index.js";
|
|
3
|
+
import { $$ as o, $one as p, iterate as g, formatStyle as _, shouldEventNext as u, on as C, off as y } from "ph-utils/dom";
|
|
4
|
+
import { random as x } from "ph-utils";
|
|
5
|
+
const R = ":host{--l-table-td-padding: 10px;--l-table-th-padding: var(--l-table-td-padding);display:inline-block;width:100%;overflow:auto;font-size:14px}.l-table{width:100%;border-collapse:collapse;border-spacing:0}.l-table th{padding:var(--l-table-th-padding);border-bottom:1px solid #e6e6e6}.l-table td{padding:var(--l-table-td-padding);border-bottom:1px solid #e6e6e6}.l-table thead tr,.l-table tfoot tr{text-align:left;background-color:#f2f2f2}.l-table tr{background-color:#fff}.l-table tr:hover{background-color:#f2f2f2}.l-table__empty-col{color:#999;text-align:center}.l-table-stripe tr:nth-child(2n){background-color:#fafafa}.l-table-stripe tr:nth-child(2n):hover{background-color:#f2f2f2}";
|
|
6
|
+
class T extends c {
|
|
7
|
+
static baseName = "table";
|
|
8
|
+
/** 斑马纹 */
|
|
9
|
+
stripe = !0;
|
|
10
|
+
columns = [];
|
|
11
|
+
data = [];
|
|
12
|
+
/** 左边固定列, 格式: [列key, 宽度] */
|
|
13
|
+
_fixedLeft = [];
|
|
14
|
+
/** 右边固定列, 格式: [列key, 宽度] */
|
|
15
|
+
_fixedRight = [];
|
|
16
|
+
/** 缓存列通用样式, 避免渲染数据时,重复计算 */
|
|
17
|
+
_globalColStyles;
|
|
18
|
+
connectedCallback() {
|
|
19
|
+
this.loadStyleText(R), super.connectedCallback();
|
|
20
|
+
}
|
|
21
|
+
setColumns(t) {
|
|
22
|
+
this._fixedLeft = [], this._fixedRight = [], this.columns = this._parseColumns(
|
|
23
|
+
t,
|
|
24
|
+
this._fixedLeft,
|
|
25
|
+
this._fixedRight
|
|
26
|
+
), this.rerender();
|
|
27
|
+
}
|
|
28
|
+
setData(t) {
|
|
29
|
+
this.data = t, this.columns && this.columns.length > 0 && this.rerender();
|
|
30
|
+
}
|
|
31
|
+
static get observedAttributes() {
|
|
32
|
+
return ["stripe"];
|
|
33
|
+
}
|
|
34
|
+
attributeChangedCallback(t, i, l) {
|
|
35
|
+
t = f(t);
|
|
36
|
+
const s = b(
|
|
37
|
+
l,
|
|
38
|
+
this[t],
|
|
39
|
+
t
|
|
40
|
+
);
|
|
41
|
+
if (s !== this[t])
|
|
42
|
+
switch (this[t] = s, t) {
|
|
43
|
+
case "stripe":
|
|
44
|
+
this._updateStripe();
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
render() {
|
|
49
|
+
const t = o("table", {
|
|
50
|
+
class: ["l-table", this.stripe ? "l-table-stripe" : ""]
|
|
51
|
+
});
|
|
52
|
+
return t.appendChild(this._headRender()), t.appendChild(this._bodyRender()), t;
|
|
53
|
+
}
|
|
54
|
+
rerender() {
|
|
55
|
+
if (this.rendered) {
|
|
56
|
+
const t = p("thead", this.root);
|
|
57
|
+
t && t.replaceWith(this._headRender());
|
|
58
|
+
const i = p("tbody", this.root);
|
|
59
|
+
i && i.replaceWith(this._bodyRender());
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
_updateStripe() {
|
|
63
|
+
if (this.rendered) {
|
|
64
|
+
const t = p("table", this.root);
|
|
65
|
+
t && (this.stripe ? t.classList.add("l-table-stripe") : t.classList.remove("l-table-stripe"));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
_headRender() {
|
|
69
|
+
const t = o("thead");
|
|
70
|
+
return this.columns && this._rendHeadRow(t, this.columns), t;
|
|
71
|
+
}
|
|
72
|
+
_rendHeadRow(t, i) {
|
|
73
|
+
const l = o("tr");
|
|
74
|
+
for (let s = 0, a = i.length; s < a; s++) {
|
|
75
|
+
const d = i[s];
|
|
76
|
+
l.appendChild(this._headColRender(d, s)), d.children && this._rendHeadRow(t, d.children);
|
|
77
|
+
}
|
|
78
|
+
t.appendChild(l);
|
|
79
|
+
}
|
|
80
|
+
_headColRender(t, i) {
|
|
81
|
+
const l = o("th");
|
|
82
|
+
if (t.titleColspan && (l.colSpan = t.titleColspan), t.titleRowspan && (l.rowSpan = t.titleRowspan), l.appendChild(
|
|
83
|
+
o("span", {
|
|
84
|
+
textContent: t.title
|
|
85
|
+
})
|
|
86
|
+
), t.sorter) {
|
|
87
|
+
const s = o("span", { class: "caret-wrapper" });
|
|
88
|
+
s.appendChild(o("span", { class: "sort-caret ascending" })), s.appendChild(o("span", { class: "sort-caret descending" })), l.appendChild(s);
|
|
89
|
+
}
|
|
90
|
+
return l;
|
|
91
|
+
}
|
|
92
|
+
_bodyRender() {
|
|
93
|
+
const t = o("tbody");
|
|
94
|
+
if (this.data && this.data.length > 0)
|
|
95
|
+
for (let i = 0, l = this.data.length; i < l; i++) {
|
|
96
|
+
const s = this.data[i];
|
|
97
|
+
if (this.columns) {
|
|
98
|
+
const a = o("tr");
|
|
99
|
+
this._bodyRowRender(this.columns, i, s, a), t.appendChild(a);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
const i = o("tr"), l = o("td", {
|
|
104
|
+
class: "l-table__empty-col",
|
|
105
|
+
textContent: "暂无数据"
|
|
106
|
+
});
|
|
107
|
+
this.columns && (l.colSpan = this.columns.length), i.appendChild(l), t.appendChild(i);
|
|
108
|
+
}
|
|
109
|
+
return t;
|
|
110
|
+
}
|
|
111
|
+
_bodyRowRender(t, i, l, s) {
|
|
112
|
+
for (let a = 0, d = t.length; a < d; a++) {
|
|
113
|
+
const e = t[a];
|
|
114
|
+
if (e.children && e.children.length > 0)
|
|
115
|
+
this._bodyRowRender(e.children, i, l, s);
|
|
116
|
+
else {
|
|
117
|
+
const n = o("td");
|
|
118
|
+
if (typeof e.rowspan == "number" && (n.rowSpan = e.rowspan), typeof e.rowspan == "function" && (n.rowSpan = e.rowspan(l, i)), typeof e.colspan == "number" && (n.colSpan = e.colspan), typeof e.colspan == "function" && (n.colSpan = e.colspan(l, i)), e.fixed && (n.className = "l-fixed"), n.style.cssText = this._getColumnStyle(
|
|
119
|
+
e,
|
|
120
|
+
this._fixedLeft,
|
|
121
|
+
this._fixedRight
|
|
122
|
+
), e.render) {
|
|
123
|
+
const r = e.render(l, i);
|
|
124
|
+
typeof r == "string" ? n.innerHTML = r : Array.isArray(r) ? g(r, (h) => {
|
|
125
|
+
n.appendChild(h);
|
|
126
|
+
}) : n.appendChild(r);
|
|
127
|
+
} else
|
|
128
|
+
n.textContent = e.key ? l[e.key] : "";
|
|
129
|
+
s.appendChild(n);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* 解析列配置,表头跨行跨列、固定列
|
|
135
|
+
* @param columns 列配置
|
|
136
|
+
* @param fixedLeft 左边固定列
|
|
137
|
+
* @param fixedRight 右边固定列
|
|
138
|
+
* @returns
|
|
139
|
+
*/
|
|
140
|
+
_parseColumns(t, i, l) {
|
|
141
|
+
const s = [];
|
|
142
|
+
for (let a = 0, d = t.length; a < d; a++) {
|
|
143
|
+
const e = t[a];
|
|
144
|
+
if (e.id || (e.id = e.key || e.title), e.id || (e.id = `${a}_${x(6)}`), e.fixed) {
|
|
145
|
+
const n = Number.parseFloat(`${e.width || 0}`);
|
|
146
|
+
e.fixed === "left" ? i.push([e.id, n]) : e.fixed === "right" && l.push([e.id, n]);
|
|
147
|
+
}
|
|
148
|
+
if (e.children) {
|
|
149
|
+
const n = this._parseColumns(
|
|
150
|
+
e.children,
|
|
151
|
+
i,
|
|
152
|
+
l
|
|
153
|
+
);
|
|
154
|
+
e.titleRowspan = e.titleRowspan || 1, e.titleColspan || (e.titleColspan = n.reduce((r, h) => r + (h.titleColspan || 1), 0)), s.push({ ...e, children: n });
|
|
155
|
+
} else
|
|
156
|
+
e.titleRowspan = e.titleRowspan || this._getMaxDepth(t), e.titleColspan = e.titleColspan || 1, s.push({ ...e });
|
|
157
|
+
}
|
|
158
|
+
return s;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* 获取多级表头的最大深度
|
|
162
|
+
* @param headers 表头配置
|
|
163
|
+
* @returns 最大深度, 最大跨行数
|
|
164
|
+
*/
|
|
165
|
+
_getMaxDepth(t) {
|
|
166
|
+
let i = 1;
|
|
167
|
+
for (const l of t)
|
|
168
|
+
l.children && (i = Math.max(i, this._getMaxDepth(l.children) + 1));
|
|
169
|
+
return i;
|
|
170
|
+
}
|
|
171
|
+
_getColumnStyle(t, i, l) {
|
|
172
|
+
const s = t.id;
|
|
173
|
+
if (this._globalColStyles && s in this._globalColStyles)
|
|
174
|
+
return this._globalColStyles[s];
|
|
175
|
+
const a = { ...t.style };
|
|
176
|
+
t.width && (typeof t.width == "number" ? a.width = `${t.width}px` : a.width = t.width), this._globalColStyles || (this._globalColStyles = {});
|
|
177
|
+
const d = _(a);
|
|
178
|
+
return this._globalColStyles[s] = d, d;
|
|
179
|
+
}
|
|
180
|
+
_handleTap = (t) => {
|
|
181
|
+
const [i, l, s] = u(
|
|
182
|
+
t,
|
|
183
|
+
"data-action",
|
|
184
|
+
t.currentTarget
|
|
185
|
+
);
|
|
186
|
+
if (i) {
|
|
187
|
+
const a = s.dataset;
|
|
188
|
+
this.emit("action", { detail: a });
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
afterInit() {
|
|
192
|
+
C(this.root, "click", this._handleTap);
|
|
193
|
+
}
|
|
194
|
+
beforeDestroy() {
|
|
195
|
+
y(this.root, "click", this._handleTap);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
export {
|
|
199
|
+
T as default
|
|
200
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface Column {
|
|
2
|
+
/** 列的唯一标识 */
|
|
3
|
+
id?: string;
|
|
4
|
+
/** 列的标题 */
|
|
5
|
+
title?: string;
|
|
6
|
+
/** 列标识, 列排序必传 */
|
|
7
|
+
key?: string;
|
|
8
|
+
/** 列宽度, 固定列时,需要传 */
|
|
9
|
+
width?: number | string;
|
|
10
|
+
/** 是否固定列, left - 固定在左方, right - 固定右方 */
|
|
11
|
+
fixed?: "left" | "right";
|
|
12
|
+
/** 多级表头 */
|
|
13
|
+
children?: Column[];
|
|
14
|
+
/** 表头跨行 */
|
|
15
|
+
titleRowspan?: number;
|
|
16
|
+
/** 表头跨列 */
|
|
17
|
+
titleColspan?: number;
|
|
18
|
+
/** 列是否支持排序 */
|
|
19
|
+
sorter?: boolean;
|
|
20
|
+
/** 列的样式 */
|
|
21
|
+
style?: Record<string, string | null | undefined>;
|
|
22
|
+
/** td colspan */
|
|
23
|
+
colspan?: number | ((rowData: any, rowIndex: number) => number);
|
|
24
|
+
/** td rowspan */
|
|
25
|
+
rowspan?: number | ((rowData: any, rowIndex: number) => number);
|
|
26
|
+
/** 单元格内容渲染函数 */
|
|
27
|
+
render?: (rowData: any, rowIndex: number) => HTMLElement | DocumentFragment | HTMLElement[] | string;
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { $ as _, iterate as i, $one as r, on as d, off as u } from "ph-utils/dom";
|
|
2
|
+
function g() {
|
|
3
|
+
let n = _(".l-tabs");
|
|
4
|
+
function l(e) {
|
|
5
|
+
const t = e.target.parentElement;
|
|
6
|
+
if (t) {
|
|
7
|
+
const o = t.getAttribute("l-current-tab");
|
|
8
|
+
if (o) {
|
|
9
|
+
const b = r(`.l-tabs__content[l-tab="${o}"]`, t);
|
|
10
|
+
b && b.classList.add("l-tabs__content--hide");
|
|
11
|
+
}
|
|
12
|
+
const s = e.detail.name;
|
|
13
|
+
t.setAttribute("l-current-tab", s);
|
|
14
|
+
const c = r(`.l-tabs__content[l-tab="${s}"]`, t);
|
|
15
|
+
c && c.classList.remove("l-tabs__content--hide");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
n && n.length > 0 && i(n, (e) => {
|
|
19
|
+
const a = r(".l-tabs__bar", e);
|
|
20
|
+
if (a) {
|
|
21
|
+
d(a, "change", l);
|
|
22
|
+
const t = a.getAttribute("name");
|
|
23
|
+
t && e.setAttribute("l-current-tab", t);
|
|
24
|
+
const o = _(".l-tabs__content[l-tab]", e);
|
|
25
|
+
i(o, (s) => {
|
|
26
|
+
s.getAttribute("l-tab") === t ? s.classList.remove("l-tabs__content--hide") : s.classList.add("l-tabs__content--hide");
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
function f() {
|
|
31
|
+
n && n.length > 0 && i(n, (e) => {
|
|
32
|
+
const a = r(".l-tabs__bar", e);
|
|
33
|
+
a && (console.log("destroy"), u(a, "change", l));
|
|
34
|
+
}), n = void 0;
|
|
35
|
+
}
|
|
36
|
+
return { destroy: f };
|
|
37
|
+
}
|
|
38
|
+
const m = {
|
|
39
|
+
init: g
|
|
40
|
+
};
|
|
41
|
+
export {
|
|
42
|
+
m as default
|
|
43
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import BaseComponent from "../base";
|
|
2
|
+
export default class Tag extends BaseComponent {
|
|
3
|
+
#private;
|
|
4
|
+
static baseName: string;
|
|
5
|
+
type: string;
|
|
6
|
+
color?: string;
|
|
7
|
+
closeable?: boolean;
|
|
8
|
+
connectedCallback(): void;
|
|
9
|
+
static get observedAttributes(): string[];
|
|
10
|
+
attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
|
|
11
|
+
render(): DocumentFragment;
|
|
12
|
+
afterInit(): void;
|
|
13
|
+
_toggleTypeClass(): void;
|
|
14
|
+
_toggleColorStyle(): void;
|
|
15
|
+
beforeDestroy(): void;
|
|
16
|
+
}
|
package/lib/tag/index.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import s from "../base.js";
|
|
2
|
+
import { parseAttrValue as i } from "../utils/index.js";
|
|
3
|
+
import { isBlank as c } from "ph-utils";
|
|
4
|
+
import { adjust as n } from "ph-utils/color";
|
|
5
|
+
import { $one as g, $$ as l, shouldEventNext as d, on as f, off as h } from "ph-utils/dom";
|
|
6
|
+
const p = ":host{box-sizing:border-box;display:inline-flex;align-items:center;justify-content:center;vertical-align:middle;height:var(--l-tag-height, 22px);padding:0 8px;font-size:12px;line-height:1;border:1px solid var(--l-tag-border-color, var(--l-border-color, #dedede));border-radius:4px;background:var(--l-tag-background, #fff);white-space:nowrap;color:var(--l-tag-color, #333)}:host(.l-tag--primary){--l-tag-border-color: var(--l-primary-color-light3, #d3adf7);--l-tag-background: var(--l-primary-color-light5, #f9f0ff);--l-tag-color: var(--l-primary-color-light3, #d3adf7)}:host(.l-tag--error){--l-tag-color: var(--l-error-color, #ed3f13);--l-tag-background: var(--l-error-color-light5, #fff1f0);--l-tag-border-color: var(--l-error-color, #ed3f13)}:host(.l-tag--success){--l-tag-color: var(--l-success-color, #a0d911);--l-tag-background: var(--l-success-color-light5, #fcffe6);--l-tag-border-color: var(--l-success-color, #a0d911)}:host(.l-tag--info){--l-tag-color: var(--l-info-color, #999999);--l-tag-background: var(--l-info-color-light9, #f5f5f5);--l-tag-border-color: var(--l-border-color, #dedede)}:host(.l-tag--warning){--l-tag-color: var(--l-warning-color, #ff9900);--l-tag-background: var(--l-warning-color-light5, #fff5e6);--l-tag-border-color: var(--l-warning-color, #ff9900)}.l-tag-close{margin-left:3px;font-size:12px;width:14px;height:14px;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;transition:color .3s,background-color .3s;cursor:pointer}.l-tag-close:hover{background-color:var(--l-tag-color, #1890ff);color:#fff}";
|
|
7
|
+
class x extends s {
|
|
8
|
+
static baseName = "tag";
|
|
9
|
+
type = "primary";
|
|
10
|
+
color;
|
|
11
|
+
closeable = !1;
|
|
12
|
+
connectedCallback() {
|
|
13
|
+
this.loadStyleText(p), super.connectedCallback();
|
|
14
|
+
}
|
|
15
|
+
static get observedAttributes() {
|
|
16
|
+
return ["type", "color", "closeable"];
|
|
17
|
+
}
|
|
18
|
+
attributeChangedCallback(o, t, e) {
|
|
19
|
+
const r = i(
|
|
20
|
+
e,
|
|
21
|
+
this[o],
|
|
22
|
+
o
|
|
23
|
+
);
|
|
24
|
+
switch (r !== this[o] && (this[o] = r), o) {
|
|
25
|
+
case "type":
|
|
26
|
+
this._toggleTypeClass();
|
|
27
|
+
break;
|
|
28
|
+
case "color":
|
|
29
|
+
this._toggleColorStyle();
|
|
30
|
+
break;
|
|
31
|
+
case "closable":
|
|
32
|
+
if (!this.rendered) return;
|
|
33
|
+
const a = g(".l-tag-close", this.root);
|
|
34
|
+
a ? a.remove() : this.root.appendChild(this.#o());
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
render() {
|
|
39
|
+
const o = document.createDocumentFragment();
|
|
40
|
+
return o.appendChild(
|
|
41
|
+
l("div", { class: "l-tag-content", innerHTML: "<slot></slot>" })
|
|
42
|
+
), this.closeable && o.appendChild(this.#o()), o.appendChild(l("slot", { name: "suffix" })), o;
|
|
43
|
+
}
|
|
44
|
+
#o() {
|
|
45
|
+
return l("div", {
|
|
46
|
+
class: "l-tag-close",
|
|
47
|
+
innerHTML: "<l-close-icon></l-close-icon>",
|
|
48
|
+
"data-action": "close"
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
#t = (o) => {
|
|
52
|
+
const [t, e, r] = d(o, "data-action", this);
|
|
53
|
+
t && e === "close" && this.emit("close", { detail: { ...r.dataset } });
|
|
54
|
+
};
|
|
55
|
+
afterInit() {
|
|
56
|
+
this._toggleTypeClass(), this._toggleColorStyle(), f(this.root, "click", this.#t);
|
|
57
|
+
}
|
|
58
|
+
_toggleTypeClass() {
|
|
59
|
+
if (!this.rendered) return;
|
|
60
|
+
let o = !1;
|
|
61
|
+
for (const t of this.classList)
|
|
62
|
+
if (t.startsWith("l-tag--")) {
|
|
63
|
+
this.classList.replace(t, `l-tag--${this.type}`), o = !0;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
o || this.classList.add(`l-tag--${this.type}`);
|
|
67
|
+
}
|
|
68
|
+
_toggleColorStyle() {
|
|
69
|
+
this.rendered && (c(this.color) ? (this.style.removeProperty("--l-tag-color"), this.style.removeProperty("--l-tag-border-color"), this.style.removeProperty("--l-tag-background")) : (this.style.setProperty("--l-tag-color", this.color), this.style.setProperty("--l-tag-border-color", this.color), this.style.setProperty("--l-tag-background", n(this.color, 5, !0))));
|
|
70
|
+
}
|
|
71
|
+
beforeDestroy() {
|
|
72
|
+
h(this.root, "click", this.#t);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export {
|
|
76
|
+
x as default
|
|
77
|
+
};
|
package/lib/theme/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import l from "../base.js";
|
|
2
|
-
import { initAttr as
|
|
2
|
+
import { initAttr as r } from "../utils/index.js";
|
|
3
3
|
import { create as i, $one as c, on as o, off as s } from "ph-utils/dom";
|
|
4
|
-
import { getTheme as
|
|
5
|
-
const u = ":host{display:inline-flex;width:auto}.l-theme-btn::part(default){--l-btn-background: transparent;--l-btn-hover-background: transparent;--l-btn-text-color: #9ca3af;--l-btn-hover-text-color: #666666;width:var(--l-form-
|
|
4
|
+
import { getTheme as h, applyTheme as a } from "ph-utils/theme";
|
|
5
|
+
const u = ":host{display:inline-flex;width:auto;box-sizing:border-box}.l-theme-btn::part(default){--l-btn-background: transparent;--l-btn-hover-background: transparent;--l-btn-text-color: #9ca3af;--l-btn-hover-text-color: #666666;width:var(--l-form-control-height, 32px);padding:0;font-size:18px}.l-theme-switch.l-switch--checked{background-color:#65757129;border-color:#3c3f44}.l-theme-switch.l-switch--checked::part(action){background-color:#000;color:#fff}html.dark .l-theme-btn{--l-btn-hover-text-color: #ffffff}", d = [
|
|
6
6
|
{ value: "auto", text: "跟随系统", icon: "l-theme-default-icon" },
|
|
7
7
|
{ value: "light", text: "浅色模式", icon: "l-sun-icon" },
|
|
8
8
|
{ value: "dark", text: "深色模式", icon: "l-moon-icon" }
|
|
@@ -14,7 +14,7 @@ class k extends l {
|
|
|
14
14
|
theme;
|
|
15
15
|
#t;
|
|
16
16
|
connectedCallback() {
|
|
17
|
-
|
|
17
|
+
r(this), this.theme = h(), this.loadStyleText(u), super.connectedCallback(), this.#r();
|
|
18
18
|
}
|
|
19
19
|
disconnectedCallback() {
|
|
20
20
|
super.disconnectedCallback(), this.#c();
|
|
@@ -75,9 +75,9 @@ class k extends l {
|
|
|
75
75
|
const n = t.target.value;
|
|
76
76
|
this.type !== "switch" ? e = n : e = n ? "dark" : "light";
|
|
77
77
|
}
|
|
78
|
-
await
|
|
78
|
+
await a(e), this.theme = e, this.type === "button" && this.#n(this.#t), this.dispatchEvent(new CustomEvent("change", { detail: e }));
|
|
79
79
|
};
|
|
80
|
-
#
|
|
80
|
+
#r() {
|
|
81
81
|
this.#t = c(".l-theme-inner", this.root), this.type === "button" ? o(this.#t, "click", this.#e) : o(this.#t, "change", this.#e);
|
|
82
82
|
}
|
|
83
83
|
#c() {
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -28,34 +28,6 @@ export declare function initAttr(el: HTMLElement): void;
|
|
|
28
28
|
export declare function tagAttr(attr: string, value: string | undefined | boolean): string;
|
|
29
29
|
export declare function tagAttrs(attr: [string, string | undefined | boolean][]): string;
|
|
30
30
|
export declare function setAttrs(el: HTMLElement, attrs: [string, string | undefined | boolean][]): void;
|
|
31
|
-
/**
|
|
32
|
-
* 初始化元素过渡, 同时会监听 l-transition-emit 变化自动执行隐藏动画, show - 显示元素, hide - 隐藏元素
|
|
33
|
-
*
|
|
34
|
-
* 注意需要在页面结束后调用 destroy 销毁监听
|
|
35
|
-
*
|
|
36
|
-
* @param els 需要初始化的元素列表, 如果不传则会自动查找页面中带有 l-transition 属性的元素
|
|
37
|
-
* @returns
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* // html
|
|
41
|
-
* <div
|
|
42
|
-
* l-transition="l-opacity"
|
|
43
|
-
* l-transition-emit="show"
|
|
44
|
-
* l-transition-method="hide"
|
|
45
|
-
* >
|
|
46
|
-
* Hello World
|
|
47
|
-
* </div>
|
|
48
|
-
* // js
|
|
49
|
-
* const trans = createTransition();
|
|
50
|
-
*
|
|
51
|
-
* // 销毁监听
|
|
52
|
-
* transition.destroy();
|
|
53
|
-
*/
|
|
54
|
-
export declare function createTransition(): {
|
|
55
|
-
destroy: () => void;
|
|
56
|
-
add: (elems: HTMLElement[]) => void;
|
|
57
|
-
init: (els?: HTMLElement[]) => void;
|
|
58
|
-
};
|
|
59
31
|
/**
|
|
60
32
|
* 获取悬浮窗 y 偏移
|
|
61
33
|
* @param targetRect
|
|
@@ -80,4 +52,10 @@ export declare function impactDetect(targetRect: DOMRect, popoverRect: DomRectPo
|
|
|
80
52
|
mainAlign: string;
|
|
81
53
|
crossAlign: string;
|
|
82
54
|
};
|
|
55
|
+
/**
|
|
56
|
+
* 短横线命名(kebab-case) 转换为 驼峰命名(camelCase
|
|
57
|
+
* @param attr 待转换的属性名
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
export declare function kebabToCamel(attr: string): string;
|
|
83
61
|
export {};
|
package/lib/utils/index.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { isBlank as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function j(t, r) {
|
|
1
|
+
import { isBlank as $ } from "ph-utils";
|
|
2
|
+
let x = -1;
|
|
3
|
+
function O(t, r) {
|
|
5
4
|
const e = Array.isArray(t) ? t : [t];
|
|
6
|
-
for (const
|
|
7
|
-
const
|
|
8
|
-
customElements.get(
|
|
5
|
+
for (const s of e) {
|
|
6
|
+
const i = r || `l-${s.baseName}`;
|
|
7
|
+
customElements.get(i) || customElements.define(i, s);
|
|
9
8
|
}
|
|
10
9
|
}
|
|
11
|
-
function
|
|
12
|
-
return `l-${++
|
|
10
|
+
function _() {
|
|
11
|
+
return `l-${++x}`;
|
|
13
12
|
}
|
|
14
|
-
function
|
|
13
|
+
function m(t, r, e) {
|
|
15
14
|
if (t == null) return r;
|
|
16
15
|
switch (typeof r) {
|
|
17
16
|
case "boolean":
|
|
@@ -22,111 +21,87 @@ function I(t, r, e) {
|
|
|
22
21
|
return t;
|
|
23
22
|
}
|
|
24
23
|
}
|
|
25
|
-
function
|
|
24
|
+
function j(t) {
|
|
26
25
|
const r = t.attributes;
|
|
27
26
|
for (const e of r) {
|
|
28
|
-
const { name:
|
|
29
|
-
if (
|
|
27
|
+
const { name: s, value: i } = e;
|
|
28
|
+
if (s.startsWith("data-") || s.startsWith("aria-") || s.startsWith("_") || s.startsWith("$") || ["id", "class", "style"].includes(s))
|
|
30
29
|
continue;
|
|
31
|
-
const
|
|
32
|
-
(t._ignoreInitAttrs || []).includes(
|
|
30
|
+
const u = s.split("-").map((o, w) => w === 0 ? o : o[0].toUpperCase() + o.slice(1)).join(""), h = m(i, t[u], s), f = Object.getOwnPropertyNames(t);
|
|
31
|
+
(t._ignoreInitAttrs || []).includes(u) || (s === "value" ? (t[u] = h, t._resetValue = h) : (f.includes(u) || f.includes(`_${u}`)) && (t[u] = h));
|
|
33
32
|
}
|
|
34
33
|
}
|
|
35
|
-
function
|
|
36
|
-
let e = "
|
|
37
|
-
return r === !0 ? e = ` ${t}` : typeof r == "string" &&
|
|
34
|
+
function E(t, r) {
|
|
35
|
+
let e = "";
|
|
36
|
+
return r === !0 ? e = ` ${t}` : typeof r == "string" && !$(r) && (e = ` ${t}="${r}"`), e;
|
|
38
37
|
}
|
|
39
|
-
function
|
|
40
|
-
|
|
38
|
+
function k(t) {
|
|
39
|
+
const r = t.map((e) => E(e[0], e[1]));
|
|
40
|
+
return r.length > 0 ? ` ${r.join("")}` : "";
|
|
41
41
|
}
|
|
42
42
|
function C(t, r) {
|
|
43
43
|
for (const e of r) {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function V() {
|
|
49
|
-
let t;
|
|
50
|
-
const r = {
|
|
51
|
-
attributes: !0,
|
|
52
|
-
attributeFilter: ["l-transition-emit"]
|
|
53
|
-
}, e = (n) => {
|
|
54
|
-
for (let f of n)
|
|
55
|
-
if (f.type === "attributes" && f.attributeName) {
|
|
56
|
-
const u = f.target, c = u.getAttribute(f.attributeName) || "show", d = u.getAttribute("l-transition") || "l", h = u.getAttribute("l-transition-method") || "hide";
|
|
57
|
-
c === "show" ? (u.style.removeProperty("display"), y(u, d, "enter")) : y(u, d, "leave", () => {
|
|
58
|
-
h === "remove" ? u.remove() : u.style.display = "none";
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
function i(n) {
|
|
63
|
-
n && n.length > 0 && (t == null && (t = new MutationObserver(e)), x(n, (f) => {
|
|
64
|
-
const u = f.getAttribute("l-transition");
|
|
65
|
-
u && (y(f, u, "enter"), t.observe(f, r));
|
|
66
|
-
}));
|
|
67
|
-
}
|
|
68
|
-
function s(n) {
|
|
69
|
-
n == null && (n = $("[l-transition]"), i(n));
|
|
44
|
+
const s = e[1], i = e[0];
|
|
45
|
+
s === !0 ? t.setAttribute(i, "") : typeof s == "string" && !$(s) && t.setAttribute(i, s);
|
|
70
46
|
}
|
|
71
|
-
function o() {
|
|
72
|
-
t && (t.disconnect(), t = void 0);
|
|
73
|
-
}
|
|
74
|
-
return { destroy: o, add: i, init: s };
|
|
75
47
|
}
|
|
76
|
-
function
|
|
77
|
-
let
|
|
78
|
-
return e === "top" ?
|
|
48
|
+
function c(t, r, e, s, i = 10) {
|
|
49
|
+
let n = 0;
|
|
50
|
+
return e === "top" ? n = r.height + i : e === "bottom" ? n = -(t.height + i) : (e === "left" || e === "right") && (s === "" ? n = r.height / 2 - t.height / 2 : s === "end" && (n = r.height - t.height)), n;
|
|
79
51
|
}
|
|
80
|
-
function
|
|
81
|
-
let
|
|
82
|
-
return e === "left" ?
|
|
52
|
+
function a(t, r, e, s, i = 10) {
|
|
53
|
+
let n = 0;
|
|
54
|
+
return e === "left" ? n = r.width + i : e === "right" ? n = -(t.width + i) : (e === "top" || e === "bottom") && (s === "" ? n = r.width / 2 - t.width / 2 : s === "end" && (n = r.width - t.width)), n;
|
|
83
55
|
}
|
|
84
|
-
function
|
|
85
|
-
const
|
|
86
|
-
let
|
|
87
|
-
|
|
56
|
+
function P(t, r, e, s, i, n, u, h, f = 10, y = "absolute") {
|
|
57
|
+
const o = window.innerHeight + n - 10, w = window.innerWidth + i - 10;
|
|
58
|
+
let d = t.top + n - h;
|
|
59
|
+
d + r.height > o && (e === "left" || e === "right" ? s = "end" : e = "top", h = c(
|
|
88
60
|
t,
|
|
89
61
|
r,
|
|
90
62
|
e,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
),
|
|
94
|
-
let b = t.left +
|
|
95
|
-
return b + r.width >
|
|
63
|
+
s,
|
|
64
|
+
f
|
|
65
|
+
), d = t.top + n - h), d < n && (e === "left" || e === "right" ? s = "start" : e = "bottom");
|
|
66
|
+
let b = t.left + i - u;
|
|
67
|
+
return b + r.width > w && (e === "top" || e === "bottom" ? s = "end" : e = "left", u = a(
|
|
96
68
|
t,
|
|
97
69
|
r,
|
|
98
70
|
e,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
), b = t.left +
|
|
71
|
+
s,
|
|
72
|
+
f
|
|
73
|
+
), b = t.left + i - u), b < i && (e === "top" || e === "bottom" ? s = "start" : e = "right"), y === "fixed" && (h = c(
|
|
102
74
|
t,
|
|
103
75
|
r,
|
|
104
76
|
e,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
),
|
|
77
|
+
s,
|
|
78
|
+
f
|
|
79
|
+
), u = a(
|
|
108
80
|
t,
|
|
109
81
|
r,
|
|
110
82
|
e,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
), b = t.left +
|
|
83
|
+
s,
|
|
84
|
+
f
|
|
85
|
+
), b = t.left + i - u, d = t.top + n - h), {
|
|
114
86
|
x: b,
|
|
115
|
-
y:
|
|
87
|
+
y: d,
|
|
116
88
|
mainAlign: e,
|
|
117
|
-
crossAlign:
|
|
89
|
+
crossAlign: s
|
|
118
90
|
};
|
|
119
91
|
}
|
|
92
|
+
function p(t) {
|
|
93
|
+
return t.replace(/-(\w)/g, (r, e) => e.toUpperCase());
|
|
94
|
+
}
|
|
120
95
|
export {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
96
|
+
a as getPopoverOffsetX,
|
|
97
|
+
c as getPopoverOffsetY,
|
|
98
|
+
P as impactDetect,
|
|
99
|
+
j as initAttr,
|
|
100
|
+
p as kebabToCamel,
|
|
101
|
+
m as parseAttrValue,
|
|
102
|
+
O as regist,
|
|
128
103
|
C as setAttrs,
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
104
|
+
E as tagAttr,
|
|
105
|
+
k as tagAttrs,
|
|
106
|
+
_ as useId
|
|
132
107
|
};
|