litos-ui 0.15.8 → 0.16.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/button/index.d.ts +4 -0
- package/lib/button/index.js +48 -40
- package/lib/check/checkbox.js +1 -1
- package/lib/check/index.d.ts +2 -1
- package/lib/check/index.js +25 -12
- package/lib/check/radio.js +1 -1
- package/lib/check-C7YSuH60.js +4 -0
- package/lib/color_picker/index.js +1 -1
- package/lib/description_panel/index.js +4 -9
- package/lib/dialog/dialog_container.js +4 -6
- package/lib/index-DvcllHRh.js +4 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +163 -164
- package/lib/input/index.js +1 -1
- package/lib/mask/index.js +1 -6
- package/lib/message/index.d.ts +11 -12
- package/lib/message/index.js +38 -39
- package/lib/modal/index.js +1 -1
- package/lib/select/index.js +1 -6
- package/lib/select_ori/index.js +1 -1
- package/lib/space/index.d.ts +8 -0
- package/lib/space/index.js +35 -0
- package/lib/table/index.d.ts +2 -2
- package/lib/table/index.js +109 -100
- package/lib/table/types.d.ts +1 -1
- package/lib/utils/index.d.ts +0 -25
- package/lib/utils/index.js +40 -87
- package/lib/utils/popover.js +24 -17
- package/package.json +72 -71
- package/styles/container.css +1 -0
- package/styles/dark.css +13 -0
- package/styles/reset.css +3 -5
- package/styles/vars.css +10 -12
- package/lib/check-A86JxUfd.js +0 -4
- package/lib/index-D4II9KsF.js +0 -4
package/lib/table/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import p from "../base.js";
|
|
2
2
|
import { kebabToCamel as b, parseAttrValue as x } from "../utils/index.js";
|
|
3
|
-
import { $one as h, $$ as
|
|
3
|
+
import { $one as h, $$ as d, iterate as g, formatStyle as f, shouldEventNext as y, on as u, off as C } from "ph-utils/dom";
|
|
4
4
|
import { random as _ } from "ph-utils";
|
|
5
|
-
const m = ":host{
|
|
6
|
-
class
|
|
5
|
+
const m = ":host{display:inline-block;width:100%;max-height:var(--l-table-max-height, 100%);overflow:auto;font-size:var(--l-table-font-size, 14px)}.l-table{width:100%;border-collapse:collapse;border-spacing:0;table-layout:var(--l-table-layout, auto)}.l-table th,.l-table td{border-bottom:1px solid var(--l-table-border-color, #e6e6e6)}.l-table th{padding:var(--l-table-th-padding, 10px);text-align:left;background-color:var(--l-table-th-bg, #f2f2f2);color:var(--l-table-th-color, #000000)}.l-table td{background-color:var(--l-table-td-bg, #ffffff);color:var(--l-table-td-color, #000000);padding:var(--l-table-td-padding, 10px);transition:background-color .3s}.l-table tr:hover td{background-color:var(--l-table-row-hover-bg, #f2f2f2)}.l-table .l-table__empty-col{color:var(--l-table-empty-color, #999999);text-align:center}.l-table-stripe tr:nth-child(2n) td{background-color:var(--l-table-stripe-bg, #fafafa)}.l-table-stripe tr:nth-child(2n):hover td{background-color:var(--l-table-row-hover-bg, #f2f2f2)}.l-table-border th,.l-table-border td{border:1px solid var(--l-table-border-color, #e6e6e6)}.l-table-fixed{--l-table-layout: fixed}.l-table-fixed .l-fixed{position:-webkit-sticky;position:sticky;z-index:1;box-sizing:border-box}.l-table-fixed thead.l-fixed,.l-table-fixed tfoot.l-fixed{z-index:2}.l-table .caret-wrapper{display:inline-flex;justify-content:center;align-items:center;vertical-align:middle;height:14px;width:20px;position:relative}.l-table .caret-wrapper .ascending{border-bottom-color:var(--l-table-sort-inactive-color, #c0c4cc);top:-5px}.l-table .caret-wrapper .descending{border-top-color:var(--l-table-sort-inactive-color, #c0c4cc);bottom:-3px}.l-table .sort-caret{display:inline-block;width:0;height:0;border:5px solid transparent;position:absolute;border-radius:3px}.l-table .sort-column{cursor:pointer}.l-table .sort-asc .ascending{border-bottom-color:var(--l-primary-color, #52c41a)}.l-table .sort-desc .descending{border-top-color:var(--l-primary-color, #52c41a)}";
|
|
6
|
+
class H extends p {
|
|
7
7
|
static baseName = "table";
|
|
8
8
|
/** 斑马纹 */
|
|
9
9
|
stripe = !0;
|
|
@@ -25,39 +25,36 @@ class S extends c {
|
|
|
25
25
|
connectedCallback() {
|
|
26
26
|
this.loadStyleText(m), super.connectedCallback();
|
|
27
27
|
}
|
|
28
|
-
setColumns(
|
|
29
|
-
let i = 0,
|
|
30
|
-
this.columns = this._parseColumns(
|
|
28
|
+
setColumns(t) {
|
|
29
|
+
let i = 0, e = 0;
|
|
30
|
+
this.columns = this._parseColumns(t, i, e), this.rerender("all");
|
|
31
31
|
}
|
|
32
|
-
setData(
|
|
33
|
-
this.data =
|
|
32
|
+
setData(t, i) {
|
|
33
|
+
this.data = t, this.sortInfo = i, this.columns && this.columns.length > 0 && this.rerender(i ? "all" : "body");
|
|
34
34
|
}
|
|
35
|
-
|
|
36
|
-
this.sortInfo = e, this.rerender("all");
|
|
37
|
-
}
|
|
38
|
-
changeFixed(e) {
|
|
35
|
+
changeFixed(t) {
|
|
39
36
|
const i = {
|
|
40
37
|
fixedHead: this.fixedHead,
|
|
41
38
|
fixedColumn: this.fixedColumn,
|
|
42
|
-
...
|
|
39
|
+
...t
|
|
43
40
|
};
|
|
44
41
|
if (this.fixedHead = i.fixedHead, this.fixedColumn = i.fixedColumn, this.rendered) {
|
|
45
|
-
const
|
|
46
|
-
|
|
42
|
+
const e = h(".l-table", this.root);
|
|
43
|
+
e && (this.fixedHead || this.fixedColumn ? e.classList.add("l-table-fixed") : e.classList.remove("l-table-fixed"));
|
|
47
44
|
}
|
|
48
45
|
}
|
|
49
46
|
static get observedAttributes() {
|
|
50
47
|
return ["stripe", "border", "fixed-head", "max-height", "table-layout"];
|
|
51
48
|
}
|
|
52
|
-
attributeChangedCallback(
|
|
53
|
-
|
|
49
|
+
attributeChangedCallback(t, i, e) {
|
|
50
|
+
t = b(t);
|
|
54
51
|
const s = x(
|
|
55
|
-
|
|
56
|
-
this[
|
|
57
|
-
|
|
52
|
+
e,
|
|
53
|
+
this[t],
|
|
54
|
+
t
|
|
58
55
|
);
|
|
59
|
-
if (s !== this[
|
|
60
|
-
switch (this[
|
|
56
|
+
if (s !== this[t])
|
|
57
|
+
switch (this[t] = s, t) {
|
|
61
58
|
case "stripe":
|
|
62
59
|
this._classAttrChannge("stripe", s);
|
|
63
60
|
break;
|
|
@@ -76,7 +73,7 @@ class S extends c {
|
|
|
76
73
|
}
|
|
77
74
|
}
|
|
78
75
|
render() {
|
|
79
|
-
const
|
|
76
|
+
const t = d("table", {
|
|
80
77
|
class: [
|
|
81
78
|
"l-table",
|
|
82
79
|
this.stripe ? "l-table-stripe" : "",
|
|
@@ -84,43 +81,43 @@ class S extends c {
|
|
|
84
81
|
this.fixedHead || this.fixedColumn ? "l-table-fixed" : ""
|
|
85
82
|
]
|
|
86
83
|
});
|
|
87
|
-
return
|
|
84
|
+
return t.appendChild(this._headRender()), t.appendChild(this._bodyRender()), t;
|
|
88
85
|
}
|
|
89
|
-
rerender(
|
|
86
|
+
rerender(t) {
|
|
90
87
|
if (this.rendered) {
|
|
91
|
-
if (
|
|
88
|
+
if (t === "all" || t === "head") {
|
|
92
89
|
const i = h("thead", this.root);
|
|
93
90
|
i && i.replaceWith(this._headRender());
|
|
94
91
|
}
|
|
95
|
-
if (
|
|
92
|
+
if (t === "all" || t === "body") {
|
|
96
93
|
const i = h("tbody", this.root);
|
|
97
94
|
i && i.replaceWith(this._bodyRender());
|
|
98
95
|
}
|
|
99
96
|
}
|
|
100
97
|
}
|
|
101
|
-
_changeCssVar(
|
|
98
|
+
_changeCssVar(t, i) {
|
|
102
99
|
if (!this.rendered) return;
|
|
103
|
-
const
|
|
104
|
-
i ? this.style.setProperty(
|
|
100
|
+
const e = `--l-table-${t}`;
|
|
101
|
+
i ? this.style.setProperty(e, i) : this.style.removeProperty(e);
|
|
105
102
|
}
|
|
106
103
|
_changeMaxHeight() {
|
|
107
|
-
let
|
|
108
|
-
|
|
104
|
+
let t = this.maxHeight;
|
|
105
|
+
t && typeof t == "number" && (t = `${t}px`), this._changeCssVar("max-height", t);
|
|
109
106
|
}
|
|
110
|
-
_classAttrChannge(
|
|
107
|
+
_classAttrChannge(t, i) {
|
|
111
108
|
if (this.rendered) {
|
|
112
|
-
const
|
|
113
|
-
|
|
109
|
+
const e = h("table", this.root);
|
|
110
|
+
e && e.classList.toggle(`l-table-${t}`, i);
|
|
114
111
|
}
|
|
115
112
|
}
|
|
116
113
|
_updateFixedHead() {
|
|
117
114
|
if (this.rendered) {
|
|
118
|
-
const
|
|
119
|
-
|
|
115
|
+
const t = h("thead", this.root);
|
|
116
|
+
t && (t.classList.toggle("l-fixed", this.fixedHead), t.style.top = this.fixedHead ? "0" : "");
|
|
120
117
|
}
|
|
121
118
|
}
|
|
122
119
|
_headRender() {
|
|
123
|
-
const
|
|
120
|
+
const t = d("thead", {
|
|
124
121
|
class: {
|
|
125
122
|
"l-fixed": this.fixedHead
|
|
126
123
|
},
|
|
@@ -128,62 +125,62 @@ class S extends c {
|
|
|
128
125
|
top: this.fixedHead ? "0" : void 0
|
|
129
126
|
}
|
|
130
127
|
});
|
|
131
|
-
return this.columns && this._rendHeadRow(
|
|
128
|
+
return this.columns && this._rendHeadRow(t, this.columns), t;
|
|
132
129
|
}
|
|
133
|
-
_rendHeadRow(
|
|
134
|
-
const
|
|
130
|
+
_rendHeadRow(t, i) {
|
|
131
|
+
const e = d("tr");
|
|
135
132
|
for (let s = 0, a = i.length; s < a; s++) {
|
|
136
133
|
const r = i[s];
|
|
137
|
-
|
|
134
|
+
e.appendChild(this._headColRender(r, s)), r.children && this._rendHeadRow(t, r.children);
|
|
138
135
|
}
|
|
139
|
-
|
|
136
|
+
t.appendChild(e);
|
|
140
137
|
}
|
|
141
|
-
_headColRender(
|
|
142
|
-
const
|
|
143
|
-
if (
|
|
144
|
-
|
|
145
|
-
textContent:
|
|
138
|
+
_headColRender(t, i) {
|
|
139
|
+
const e = d("th");
|
|
140
|
+
if (t.titleColspan && t.titleColspan > 1 && (e.colSpan = t.titleColspan), t.titleRowspan && t.titleRowspan > 1 && (e.rowSpan = t.titleRowspan), e.style.cssText = this._getColumnStyle(t, "th"), t.fixed && e.classList.add("l-fixed"), e.appendChild(
|
|
141
|
+
d("span", {
|
|
142
|
+
textContent: t.title
|
|
146
143
|
})
|
|
147
|
-
),
|
|
148
|
-
const s =
|
|
149
|
-
s.appendChild(
|
|
144
|
+
), t.sorter) {
|
|
145
|
+
const s = d("span", { class: "caret-wrapper" });
|
|
146
|
+
s.appendChild(d("span", { class: "sort-caret ascending" })), s.appendChild(d("span", { class: "sort-caret descending" })), e.classList.add("sort-column"), e.setAttribute("data-action", "sort"), e.setAttribute("data-col", `${i}`), e.appendChild(s);
|
|
150
147
|
}
|
|
151
|
-
return t;
|
|
148
|
+
return this.sortInfo && this.sortInfo.key === t.key && e.classList.add(this.sortInfo.order === "asc" ? "sort-asc" : "sort-desc"), e;
|
|
152
149
|
}
|
|
153
150
|
_bodyRender() {
|
|
154
|
-
const
|
|
151
|
+
const t = d("tbody");
|
|
155
152
|
if (this.data && this.data.length > 0)
|
|
156
|
-
for (let i = 0,
|
|
153
|
+
for (let i = 0, e = this.data.length; i < e; i++) {
|
|
157
154
|
const s = this.data[i];
|
|
158
155
|
if (this.columns) {
|
|
159
|
-
const a =
|
|
160
|
-
this._bodyRowRender(this.columns, i, s, a),
|
|
156
|
+
const a = d("tr");
|
|
157
|
+
this._bodyRowRender(this.columns, i, s, a), t.appendChild(a);
|
|
161
158
|
}
|
|
162
159
|
}
|
|
163
160
|
else {
|
|
164
|
-
const i =
|
|
161
|
+
const i = d("tr"), e = d("td", {
|
|
165
162
|
class: "l-table__empty-col",
|
|
166
163
|
textContent: "暂无数据"
|
|
167
164
|
});
|
|
168
|
-
this.columns && (
|
|
165
|
+
this.columns && (e.colSpan = this.columns.length), i.appendChild(e), t.appendChild(i);
|
|
169
166
|
}
|
|
170
|
-
return
|
|
167
|
+
return t;
|
|
171
168
|
}
|
|
172
|
-
_bodyRowRender(
|
|
173
|
-
for (let a = 0, r =
|
|
174
|
-
const l =
|
|
169
|
+
_bodyRowRender(t, i, e, s) {
|
|
170
|
+
for (let a = 0, r = t.length; a < r; a++) {
|
|
171
|
+
const l = t[a];
|
|
175
172
|
if (l.children && l.children.length > 0)
|
|
176
|
-
this._bodyRowRender(l.children, i,
|
|
173
|
+
this._bodyRowRender(l.children, i, e, s);
|
|
177
174
|
else {
|
|
178
|
-
const
|
|
179
|
-
if (typeof l.rowspan == "number" && (
|
|
180
|
-
const n = l.render(
|
|
181
|
-
typeof n == "string" ?
|
|
182
|
-
|
|
183
|
-
}) :
|
|
175
|
+
const o = d("td");
|
|
176
|
+
if (typeof l.rowspan == "number" && (o.rowSpan = l.rowspan), typeof l.rowspan == "function" && (o.rowSpan = l.rowspan(e, i)), typeof l.colspan == "number" && (o.colSpan = l.colspan), typeof l.colspan == "function" && (o.colSpan = l.colspan(e, i)), l.fixed && (o.className = "l-fixed"), o.style.cssText = this._getColumnStyle(l), l.render) {
|
|
177
|
+
const n = l.render(e, i);
|
|
178
|
+
typeof n == "string" ? o.innerHTML = n : Array.isArray(n) ? g(n, (c) => {
|
|
179
|
+
o.appendChild(c);
|
|
180
|
+
}) : o.appendChild(n);
|
|
184
181
|
} else
|
|
185
|
-
|
|
186
|
-
s.appendChild(
|
|
182
|
+
o.textContent = l.key ? e[l.key] : "";
|
|
183
|
+
s.appendChild(o);
|
|
187
184
|
}
|
|
188
185
|
}
|
|
189
186
|
}
|
|
@@ -194,23 +191,23 @@ class S extends c {
|
|
|
194
191
|
* @param rightOffset 右边固定列偏移
|
|
195
192
|
* @returns
|
|
196
193
|
*/
|
|
197
|
-
_parseColumns(
|
|
194
|
+
_parseColumns(t, i, e) {
|
|
198
195
|
const s = [];
|
|
199
|
-
for (let a = 0, r =
|
|
200
|
-
const l =
|
|
196
|
+
for (let a = 0, r = t.length; a < r; a++) {
|
|
197
|
+
const l = t[a];
|
|
201
198
|
if (l.id || (l.id = l.key || l.title), l.id || (l.id = `${a}_${_(6)}`), l.fixed) {
|
|
202
|
-
const
|
|
203
|
-
l.fixed === "left" ? (l.left = i, i +=
|
|
199
|
+
const o = Number.parseFloat(`${l.width || 0}`);
|
|
200
|
+
l.fixed === "left" ? (l.left = i, i += o) : l.fixed === "right" && (l.right = e, e += o);
|
|
204
201
|
}
|
|
205
202
|
if (l.children) {
|
|
206
|
-
const
|
|
203
|
+
const o = this._parseColumns(
|
|
207
204
|
l.children,
|
|
208
205
|
i,
|
|
209
|
-
|
|
206
|
+
e
|
|
210
207
|
);
|
|
211
|
-
l.titleRowspan = l.titleRowspan || 1, l.titleColspan || (l.titleColspan =
|
|
208
|
+
l.titleRowspan = l.titleRowspan || 1, l.titleColspan || (l.titleColspan = o.reduce((n, c) => n + (c.titleColspan || 1), 0)), s.push({ ...l, children: o });
|
|
212
209
|
} else
|
|
213
|
-
l.titleRowspan = l.titleRowspan || this._getMaxDepth(
|
|
210
|
+
l.titleRowspan = l.titleRowspan || this._getMaxDepth(t), l.titleColspan = l.titleColspan || 1, s.push({ ...l });
|
|
214
211
|
}
|
|
215
212
|
return s;
|
|
216
213
|
}
|
|
@@ -219,42 +216,54 @@ class S extends c {
|
|
|
219
216
|
* @param headers 表头配置
|
|
220
217
|
* @returns 最大深度, 最大跨行数
|
|
221
218
|
*/
|
|
222
|
-
_getMaxDepth(
|
|
219
|
+
_getMaxDepth(t) {
|
|
223
220
|
let i = 1;
|
|
224
|
-
for (const
|
|
225
|
-
|
|
221
|
+
for (const e of t)
|
|
222
|
+
e.children && (i = Math.max(i, this._getMaxDepth(e.children) + 1));
|
|
226
223
|
return i;
|
|
227
224
|
}
|
|
228
|
-
_getColumnStyle(
|
|
229
|
-
const
|
|
230
|
-
if (this._globalColStyles &&
|
|
231
|
-
return this._globalColStyles[
|
|
225
|
+
_getColumnStyle(t, i = "td") {
|
|
226
|
+
const e = t.id;
|
|
227
|
+
if (this._globalColStyles && e in this._globalColStyles)
|
|
228
|
+
return this._globalColStyles[e][i];
|
|
232
229
|
const s = {};
|
|
233
|
-
|
|
234
|
-
const a =
|
|
230
|
+
t.width && (typeof t.width == "number" ? s.width = `${t.width}px` : s.width = t.width), t.fixed && (t.fixed === "left" ? (s.left = `${t.left}px`, s["box-shadow"] = "-4px 0 4px -4px #d9d9d9 inset") : t.fixed === "right" && (s.right = `${t.right}px`, s["box-shadow"] = "4px 0 4px -4px #d9d9d9 inset")), this._globalColStyles || (this._globalColStyles = {});
|
|
231
|
+
const a = f(s), r = {
|
|
235
232
|
th: a,
|
|
236
|
-
td: a +
|
|
233
|
+
td: a + f(t.style || "")
|
|
237
234
|
};
|
|
238
|
-
return this._globalColStyles[
|
|
235
|
+
return this._globalColStyles[e] = r, r[i];
|
|
239
236
|
}
|
|
240
|
-
_handleTap = (
|
|
241
|
-
const [i,
|
|
242
|
-
|
|
237
|
+
_handleTap = (t) => {
|
|
238
|
+
const [i, e, s] = y(
|
|
239
|
+
t,
|
|
243
240
|
"data-action",
|
|
244
|
-
|
|
241
|
+
t.currentTarget
|
|
245
242
|
);
|
|
246
243
|
if (i) {
|
|
247
244
|
const a = s.dataset;
|
|
248
|
-
|
|
245
|
+
if (e === "sort") {
|
|
246
|
+
const r = parseInt(a.col), l = this.columns[r], o = this.sortInfo && this.sortInfo.order === "desc" ? "asc" : "desc";
|
|
247
|
+
this.sortInfo = { key: l.key, order: o }, l.sorter === "custom" ? this.emit("sort", { detail: { index: r, key: l.key, dir: o } }) : (this.data = this._dataSort(), this.rerender("all"));
|
|
248
|
+
} else
|
|
249
|
+
this.emit(e, { detail: a });
|
|
249
250
|
}
|
|
250
251
|
};
|
|
251
252
|
afterInit() {
|
|
252
|
-
this._changeMaxHeight(),
|
|
253
|
+
this._changeMaxHeight(), u(this.root, "click", this._handleTap);
|
|
253
254
|
}
|
|
254
255
|
beforeDestroy() {
|
|
255
|
-
|
|
256
|
+
C(this.root, "click", this._handleTap);
|
|
257
|
+
}
|
|
258
|
+
_dataSort() {
|
|
259
|
+
if (!this.sortInfo || !this.data) return;
|
|
260
|
+
const { key: t, order: i } = this.sortInfo;
|
|
261
|
+
return this.data.sort((e, s) => {
|
|
262
|
+
const a = e[t], r = s[t];
|
|
263
|
+
return i === "asc" ? a - r : r - a;
|
|
264
|
+
});
|
|
256
265
|
}
|
|
257
266
|
}
|
|
258
267
|
export {
|
|
259
|
-
|
|
268
|
+
H as default
|
|
260
269
|
};
|
package/lib/table/types.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export interface Column {
|
|
|
20
20
|
/** 表头跨列 */
|
|
21
21
|
titleColspan?: number;
|
|
22
22
|
/** 列是否支持排序 */
|
|
23
|
-
sorter?: boolean | "
|
|
23
|
+
sorter?: boolean | "custom";
|
|
24
24
|
/** 列的样式 */
|
|
25
25
|
style?: Record<string, string | null | undefined>;
|
|
26
26
|
/** td colspan */
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -28,34 +28,9 @@ 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
|
-
* 获取悬浮窗 y 偏移
|
|
33
|
-
* @param targetRect
|
|
34
|
-
* @param popoverRect
|
|
35
|
-
* @param mainAlign
|
|
36
|
-
* @param crossAlign
|
|
37
|
-
* @returns
|
|
38
|
-
*/
|
|
39
|
-
export declare function getPopoverOffsetY(targetRect: DOMRect, popoverRect: DomRectPos, mainAlign: string, crossAlign: string, offset?: number): number;
|
|
40
|
-
type DomRectPos = {
|
|
41
|
-
x: number;
|
|
42
|
-
y: number;
|
|
43
|
-
width: number;
|
|
44
|
-
height: number;
|
|
45
|
-
left: number;
|
|
46
|
-
top: number;
|
|
47
|
-
};
|
|
48
|
-
export declare function getPopoverOffsetX(targetRect: DOMRect, popoverRect: DomRectPos, mainAlign: string, crossAlign: string, offset?: number): number;
|
|
49
|
-
export declare function impactDetect(targetRect: DOMRect, popoverRect: DomRectPos, mainAlign: string, crossAlign: string, scrollLeft: number, scrollTop: number, leftDiff: number, topDiff: number, offset?: number, position?: string): {
|
|
50
|
-
x: number;
|
|
51
|
-
y: number;
|
|
52
|
-
mainAlign: string;
|
|
53
|
-
crossAlign: string;
|
|
54
|
-
};
|
|
55
31
|
/**
|
|
56
32
|
* 短横线命名(kebab-case) 转换为 驼峰命名(camelCase
|
|
57
33
|
* @param attr 待转换的属性名
|
|
58
34
|
* @returns
|
|
59
35
|
*/
|
|
60
36
|
export declare function kebabToCamel(attr: string): string;
|
|
61
|
-
export {};
|
package/lib/utils/index.js
CHANGED
|
@@ -1,107 +1,60 @@
|
|
|
1
|
-
import { isBlank as
|
|
2
|
-
let
|
|
3
|
-
function
|
|
4
|
-
const
|
|
5
|
-
for (const
|
|
6
|
-
const
|
|
7
|
-
customElements.get(
|
|
1
|
+
import { isBlank as u } from "ph-utils";
|
|
2
|
+
let m = -1;
|
|
3
|
+
function b(t, e) {
|
|
4
|
+
const s = Array.isArray(t) ? t : [t];
|
|
5
|
+
for (const n of s) {
|
|
6
|
+
const r = e || `l-${n.baseName}`;
|
|
7
|
+
customElements.get(r) || customElements.define(r, n);
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
|
-
function
|
|
11
|
-
return `l-${++
|
|
10
|
+
function y() {
|
|
11
|
+
return `l-${++m}`;
|
|
12
12
|
}
|
|
13
|
-
function
|
|
14
|
-
if (t == null) return
|
|
15
|
-
switch (typeof
|
|
13
|
+
function l(t, e, s) {
|
|
14
|
+
if (t == null) return e;
|
|
15
|
+
switch (typeof e) {
|
|
16
16
|
case "boolean":
|
|
17
|
-
return ["", "true", "1", "on",
|
|
17
|
+
return ["", "true", "1", "on", s].includes(t);
|
|
18
18
|
case "number":
|
|
19
19
|
return Number(t);
|
|
20
20
|
default:
|
|
21
21
|
return t;
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
function
|
|
25
|
-
const
|
|
26
|
-
for (const
|
|
27
|
-
const { name:
|
|
28
|
-
if (
|
|
24
|
+
function $(t) {
|
|
25
|
+
const e = t.attributes;
|
|
26
|
+
for (const s of e) {
|
|
27
|
+
const { name: n, value: r } = s;
|
|
28
|
+
if (n.startsWith("data-") || n.startsWith("aria-") || n.startsWith("_") || n.startsWith("$") || ["id", "class", "style"].includes(n))
|
|
29
29
|
continue;
|
|
30
|
-
const
|
|
31
|
-
(t._ignoreInitAttrs || []).includes(
|
|
30
|
+
const i = n.split("-").map((c, f) => f === 0 ? c : c[0].toUpperCase() + c.slice(1)).join(""), o = l(r, t[i], n), a = Object.getOwnPropertyNames(t);
|
|
31
|
+
(t._ignoreInitAttrs || []).includes(i) || (n === "value" ? (t[i] = o, t._resetValue = o) : (a.includes(i) || a.includes(`_${i}`)) && (t[i] = o));
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
function
|
|
35
|
-
let
|
|
36
|
-
return
|
|
34
|
+
function p(t, e) {
|
|
35
|
+
let s = "";
|
|
36
|
+
return e === !0 ? s = ` ${t}` : typeof e == "string" && !u(e) && (s = ` ${t}="${e}"`), s;
|
|
37
37
|
}
|
|
38
|
-
function
|
|
39
|
-
const
|
|
40
|
-
return
|
|
38
|
+
function h(t) {
|
|
39
|
+
const e = t.map((s) => p(s[0], s[1]));
|
|
40
|
+
return e.length > 0 ? ` ${e.join("")}` : "";
|
|
41
41
|
}
|
|
42
|
-
function
|
|
43
|
-
for (const
|
|
44
|
-
const
|
|
45
|
-
|
|
42
|
+
function I(t, e) {
|
|
43
|
+
for (const s of e) {
|
|
44
|
+
const n = s[1], r = s[0];
|
|
45
|
+
n === !0 ? t.setAttribute(r, "") : typeof n == "string" && !u(n) && t.setAttribute(r, n);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
function
|
|
49
|
-
|
|
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;
|
|
51
|
-
}
|
|
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;
|
|
55
|
-
}
|
|
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(
|
|
60
|
-
t,
|
|
61
|
-
r,
|
|
62
|
-
e,
|
|
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(
|
|
68
|
-
t,
|
|
69
|
-
r,
|
|
70
|
-
e,
|
|
71
|
-
s,
|
|
72
|
-
f
|
|
73
|
-
), b = t.left + i - u), b < i && (e === "top" || e === "bottom" ? s = "start" : e = "right"), y === "fixed" && (h = c(
|
|
74
|
-
t,
|
|
75
|
-
r,
|
|
76
|
-
e,
|
|
77
|
-
s,
|
|
78
|
-
f
|
|
79
|
-
), u = a(
|
|
80
|
-
t,
|
|
81
|
-
r,
|
|
82
|
-
e,
|
|
83
|
-
s,
|
|
84
|
-
f
|
|
85
|
-
), b = t.left + i - u, d = t.top + n - h), {
|
|
86
|
-
x: b,
|
|
87
|
-
y: d,
|
|
88
|
-
mainAlign: e,
|
|
89
|
-
crossAlign: s
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
function p(t) {
|
|
93
|
-
return t.replace(/-(\w)/g, (r, e) => e.toUpperCase());
|
|
48
|
+
function N(t) {
|
|
49
|
+
return t.replace(/-(\w)/g, (e, s) => s.toUpperCase());
|
|
94
50
|
}
|
|
95
51
|
export {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
E as tagAttr,
|
|
105
|
-
k as tagAttrs,
|
|
106
|
-
_ as useId
|
|
52
|
+
$ as initAttr,
|
|
53
|
+
N as kebabToCamel,
|
|
54
|
+
l as parseAttrValue,
|
|
55
|
+
b as regist,
|
|
56
|
+
I as setAttrs,
|
|
57
|
+
p as tagAttr,
|
|
58
|
+
h as tagAttrs,
|
|
59
|
+
y as useId
|
|
107
60
|
};
|
package/lib/utils/popover.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $one as T, $ as y, iterate as $, on as d, off as a, shouldEventNext as
|
|
1
|
+
import { $one as T, $ as y, iterate as $, on as d, off as a, shouldEventNext as P, $$ as w } from "ph-utils/dom";
|
|
2
2
|
function E(s, t, e, o, n = 10, r = "x") {
|
|
3
3
|
const i = r === "x" ? "width" : "height";
|
|
4
4
|
let p = ["left", "right", "top", "bottom"];
|
|
@@ -50,13 +50,13 @@ function O(s, t, e, o, n = 10) {
|
|
|
50
50
|
n,
|
|
51
51
|
"x"
|
|
52
52
|
), m = s.left + i - u, f = s.top + p - c;
|
|
53
|
-
const
|
|
53
|
+
const g = `${e}${o === "" ? "" : "-" + o}`;
|
|
54
54
|
return {
|
|
55
55
|
x: m,
|
|
56
56
|
y: f,
|
|
57
57
|
mainAlign: e,
|
|
58
58
|
crossAlign: o,
|
|
59
|
-
placement:
|
|
59
|
+
placement: g
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
function M(s, t, e, o) {
|
|
@@ -202,9 +202,9 @@ class z {
|
|
|
202
202
|
this._clearHideTimer(), this.$reference != e && this.show(e);
|
|
203
203
|
};
|
|
204
204
|
_onMouseLeave = () => {
|
|
205
|
-
this._clearHideTimer(), this._hideTimer = setTimeout(() => {
|
|
205
|
+
this._clearHideTimer(), this.options.trigger === "hover" && (this._hideTimer = setTimeout(() => {
|
|
206
206
|
this.hide();
|
|
207
|
-
}, 50);
|
|
207
|
+
}, 50));
|
|
208
208
|
};
|
|
209
209
|
_onRefTap = (t) => {
|
|
210
210
|
this._destroyUpdater();
|
|
@@ -224,17 +224,24 @@ class z {
|
|
|
224
224
|
show(t) {
|
|
225
225
|
const e = t.dataset;
|
|
226
226
|
let o = e.disabled;
|
|
227
|
-
if (o == null && (o = this.options.disabled), !o
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
offset
|
|
236
|
-
|
|
237
|
-
|
|
227
|
+
if (o == null && (o = this.options.disabled), !o) {
|
|
228
|
+
if (this.$reference) {
|
|
229
|
+
if (this.$reference === t)
|
|
230
|
+
return;
|
|
231
|
+
this.hide();
|
|
232
|
+
}
|
|
233
|
+
if (this.$reference = t, this.popoverElement || (this._renderPopover(), this._bindPopoverEvents()), this.popoverElement) {
|
|
234
|
+
this.options.updateContent && this.options.updateContent(this.popoverElement, e), this._destroyUpdater();
|
|
235
|
+
const n = e.placement || this.options.placement || "top", r = Number(e.offset || this.options.offset || 10), i = e.popoverWidth || this.options.popoverWidth;
|
|
236
|
+
this.popoverElement.style.display = "block";
|
|
237
|
+
let p;
|
|
238
|
+
i && (i !== "trigger" ? p = Number(i) : p = i), this.updater = L(this.$reference, this.popoverElement, {
|
|
239
|
+
placement: n,
|
|
240
|
+
popoverWidth: p,
|
|
241
|
+
offset: r,
|
|
242
|
+
arrowSize: this.options.arrowSize
|
|
243
|
+
}), this.options.onOpenChange && this.options.onOpenChange(!0);
|
|
244
|
+
}
|
|
238
245
|
}
|
|
239
246
|
}
|
|
240
247
|
isShow() {
|
|
@@ -261,7 +268,7 @@ class z {
|
|
|
261
268
|
return;
|
|
262
269
|
}
|
|
263
270
|
if (this.popoverElement && (this.popoverElement.contains(e) || this.popoverElement == e)) {
|
|
264
|
-
const [o, n, r] =
|
|
271
|
+
const [o, n, r] = P(
|
|
265
272
|
t,
|
|
266
273
|
"data-action",
|
|
267
274
|
this.popoverElement
|