litos-ui 0.15.7 → 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.
Files changed (44) hide show
  1. package/lib/button/index.d.ts +4 -0
  2. package/lib/button/index.js +24 -16
  3. package/lib/check/check.js +6 -7
  4. package/lib/check/checkbox.js +1 -1
  5. package/lib/check/index.d.ts +2 -1
  6. package/lib/check/index.js +25 -12
  7. package/lib/check/radio.js +10 -6
  8. package/lib/check-C7YSuH60.js +4 -0
  9. package/lib/color_picker/index.js +1 -1
  10. package/lib/description_panel/index.js +4 -9
  11. package/lib/dialog/dialog_container.js +4 -6
  12. package/lib/form/form_inner.d.ts +3 -0
  13. package/lib/form/form_inner.js +28 -23
  14. package/lib/image/image_preview.js +3 -3
  15. package/lib/index-DvcllHRh.js +4 -0
  16. package/lib/index.d.ts +2 -0
  17. package/lib/index.js +163 -164
  18. package/lib/input/index.d.ts +2 -1
  19. package/lib/input/index.js +37 -26
  20. package/lib/mask/index.js +1 -6
  21. package/lib/message/index.d.ts +11 -12
  22. package/lib/message/index.js +39 -40
  23. package/lib/modal/index.js +1 -1
  24. package/lib/select/index.js +1 -6
  25. package/lib/select_ori/index.js +1 -1
  26. package/lib/space/index.d.ts +8 -0
  27. package/lib/space/index.js +35 -0
  28. package/lib/tabbar/index.d.ts +3 -1
  29. package/lib/tabbar/index.js +13 -7
  30. package/lib/table/index.d.ts +27 -10
  31. package/lib/table/index.js +165 -96
  32. package/lib/table/types.d.ts +9 -1
  33. package/lib/tag/index.js +4 -1
  34. package/lib/utils/index.d.ts +0 -25
  35. package/lib/utils/index.js +40 -87
  36. package/lib/utils/popover.js +24 -17
  37. package/package.json +41 -40
  38. package/styles/container.css +1 -0
  39. package/styles/dark.css +13 -0
  40. package/styles/reset.css +3 -5
  41. package/styles/vars.css +10 -12
  42. package/lib/check-A86JxUfd.js +0 -4
  43. package/lib/index-D4II9KsF.js +0 -4
  44. package/lib/menu/base.js +0 -1
@@ -1,7 +1,7 @@
1
1
  import x from "../base.js";
2
2
  import { parseAttrValue as c, initAttr as g } from "../utils/index.js";
3
3
  import { $one as i, transition as s, $$ as a, on as u, off as k, shouldEventNext as y } from "ph-utils/dom";
4
- const v = ":host{display:none}:host(.open){display:block}.l-modal-mask{z-index:var(--l-modal-zindex, 100)}.l-modal-wrapper{position:fixed;top:0;left:0;width:100%;height:100%;z-index:calc(var(--l-modal-zindex, 100) + 1)}.l-modal{--l-modal-translate: translate3d(0, 80px, 0);background-color:#fff;border-radius:5px;width:var(--l-modal-width, 27%);margin:auto;box-shadow:0 0 8px #0000001a;position:relative;opacity:1;transform:var(--l-modal-translate) scaleZ(1);transition:opacity .3s,transform .3s}.l-modal-header{display:block;padding:10px;font-size:16px;border-bottom:1px solid var(--l-modal-line-color, rgba(0, 0, 0, .06));font-weight:600;display:flex;align-items:center;gap:5px}.l-modal-footer{padding:10px;border-top:1px solid var(--l-modal-line-color, rgba(0, 0, 0, .06));display:flex;justify-content:flex-end;gap:10px}.l-modal-container{padding:var(--l-modal-container-padding, 15px 10px);font-size:14px}.l-btn-modal-close{--l-form-control-height: auto;position:absolute}.l-modal-close1{right:5px;top:8px}.l-modal-close1::part(default){width:auto;height:auto;padding:5px;border:none;font-size:16px}.l-modal-close2{right:-10px;top:-10px}.l-modal-close2::part(default){width:20px;height:20px;padding:0;background-color:#fff}.mask-transition-enter-from,.mask-transition-leave-to{opacity:0}.modal-transition-enter-from,.modal-transition-leave-to{transform:translateZ(0) scale3d(0,0,0)}.l-modal--mobile{border-radius:10px}.l-modal--mobile .l-modal-header{text-align:center;border-bottom-color:transparent;padding:20px 10px 5px;display:flex;justify-content:center}.l-modal--mobile .l-modal-container{--l-modal-container-padding: 5px 15px 20px;text-align:center}.l-modal--mobile .l-modal-footer{display:flex;justify-content:stretch;align-items:stretch;padding:0;text-align:center;height:50px;gap:0}.l-modal--mobile .l-modal-footer-btn{flex-grow:1;height:100%}.l-modal--mobile .l-modal-footer-btn+.l-modal-footer-btn{border-left:1px solid var(--l-modal-line-color, rgba(0, 0, 0, .06))}.l-modal--middle{--l-modal-translate: translate3d(0, -50%, 0);top:50%}.l-modal--bottom{--l-modal-translate: translate3d(0, -100%, 0);top:100%;width:100%;border-bottom-left-radius:0;border-bottom-right-radius:0}@media screen and (max-width: 768px){:host{--l-modal-width: 80%}}", w = ".l-mask{position:fixed;z-index:var(--l-mask-zindex, 100);inset:0;background-color:#0009;transition:opacity .3s;opacity:1}";
4
+ const v = ":host{display:none}:host(.open){display:block}.l-modal-mask{z-index:var(--l-modal-zindex, 100)}.l-modal-wrapper{position:fixed;top:0;left:0;width:100%;height:100%;z-index:calc(var(--l-modal-zindex, 100) + 1)}.l-modal{--l-modal-translate: translate3d(0, 80px, 0);background-color:#fff;border-radius:5px;width:var(--l-modal-width, 27%);margin:auto;box-shadow:0 0 8px #0000001a;position:relative;opacity:1;transform:var(--l-modal-translate) scaleZ(1);transition:opacity .3s,transform .3s}.l-modal-header{display:block;padding:10px;font-size:16px;border-bottom:1px solid var(--l-modal-line-color, rgba(0, 0, 0, .06));font-weight:600;display:flex;align-items:center;gap:5px}.l-modal-footer{padding:10px;border-top:1px solid var(--l-modal-line-color, rgba(0, 0, 0, .06));display:flex;justify-content:flex-end;gap:10px}.l-modal-container{padding:var(--l-modal-container-padding, 15px 10px);font-size:14px}.l-btn-modal-close{--l-form-control-height: auto;position:absolute}.l-modal-close1{right:5px;top:8px}.l-modal-close1::part(default){width:auto;height:auto;padding:5px;border:none;font-size:16px}.l-modal-close2{right:-10px;top:-10px}.l-modal-close2::part(default){width:20px;height:20px;padding:0;background-color:#fff}.mask-transition-enter-from,.mask-transition-leave-to{opacity:0}.modal-transition-enter-from,.modal-transition-leave-to{transform:translateZ(0) scale3d(0,0,0)}.l-modal--mobile{border-radius:10px}.l-modal--mobile .l-modal-header{text-align:center;border-bottom-color:transparent;padding:20px 10px 5px;display:flex;justify-content:center}.l-modal--mobile .l-modal-container{--l-modal-container-padding: 5px 15px 20px;text-align:center}.l-modal--mobile .l-modal-footer{display:flex;justify-content:stretch;align-items:stretch;padding:0;text-align:center;height:50px;gap:0}.l-modal--mobile .l-modal-footer-btn{flex-grow:1;height:100%}.l-modal--mobile .l-modal-footer-btn+.l-modal-footer-btn{border-left:1px solid var(--l-modal-line-color, rgba(0, 0, 0, .06))}.l-modal--middle{--l-modal-translate: translate3d(0, -50%, 0);top:50%}.l-modal--bottom{--l-modal-translate: translate3d(0, -100%, 0);top:100%;width:100%;border-bottom-left-radius:0;border-bottom-right-radius:0}@media screen and (max-width:768px){:host{--l-modal-width: 80%}}", w = ".l-mask{position:fixed;z-index:var(--l-mask-zindex, 100);inset:0;background-color:#0009;transition:opacity .3s;opacity:1}";
5
5
  class L extends x {
6
6
  static baseName = "modal";
7
7
  /** 是否显示对话框 */
@@ -103,12 +103,7 @@ class O extends x {
103
103
  this[e],
104
104
  e
105
105
  );
106
- if (s !== this[e] && (this[e] = s), this.rendered)
107
- switch (e) {
108
- case "width":
109
- s ? this.style.setProperty("--l-select-width", s) : this.style.removeProperty("--l-select-width");
110
- break;
111
- }
106
+ s !== this[e] && (this[e] = s), this.rendered && e === "width" && (s ? this.style.setProperty("--l-select-width", s) : this.style.removeProperty("--l-select-width"));
112
107
  }
113
108
  setOptions(e) {
114
109
  this.options = e, this._backOptions = [...e], this._popover && this.expanded && this._popover.updatePopoverContent();
@@ -1,7 +1,7 @@
1
1
  import a from "../form/form_inner.js";
2
2
  import { tagAttrs as c } from "../utils/index.js";
3
3
  import { $one as r, on as h, off as o } from "ph-utils/dom";
4
- import { i as d } from "../index-D4II9KsF.js";
4
+ import { i as d } from "../index-DvcllHRh.js";
5
5
  class v extends a {
6
6
  static baseName = "select-ori";
7
7
  $select;
@@ -0,0 +1,8 @@
1
+ import BaseComponent from "../base";
2
+ export default class Space extends BaseComponent {
3
+ static baseName: string;
4
+ connectedCallback(): void;
5
+ static get observedAttributes(): string[];
6
+ attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
7
+ render(): string;
8
+ }
@@ -0,0 +1,35 @@
1
+ import r from "../base.js";
2
+ import { kebabToCamel as p, parseAttrValue as i } from "../utils/index.js";
3
+ import { isNumeric as o } from "ph-utils";
4
+ const c = ":host{box-sizing:border-box;display:var(--l-space-display, flex);align-items:var(--l-space-align, center);justify-content:var(--l-space-justify, flex-start);gap:var(--l-space-gap, 10px);flex-wrap:var(--l-space-wrap, nowrap);flex-direction:var(--l-space-direction, row)}";
5
+ class u extends r {
6
+ static baseName = "space";
7
+ connectedCallback() {
8
+ this.loadStyleText(c), super.connectedCallback();
9
+ }
10
+ static get observedAttributes() {
11
+ return ["inline", "align", "justify", "gap", "direction", "wrap"];
12
+ }
13
+ attributeChangedCallback(e, y, l) {
14
+ e = p(e);
15
+ const t = i(l, this[e], e);
16
+ if (e === "inline")
17
+ i(l, !1, "inline") ? this.style.setProperty("--l-space-display", "inline-flex") : this.style.removeProperty("--l-space-display");
18
+ else if (e === "gap")
19
+ if (t) {
20
+ const s = t.split(",").map((a) => o(a) ? `${a}px` : a);
21
+ this.style.setProperty("--l-space-gap", s.join(" "));
22
+ } else
23
+ this.style.removeProperty("--l-space-gap");
24
+ else {
25
+ const s = `--l-space-${e}`;
26
+ t ? this.style.setProperty(s, t) : this.style.removeProperty(s);
27
+ }
28
+ }
29
+ render() {
30
+ return "<slot></slot>";
31
+ }
32
+ }
33
+ export {
34
+ u as default
35
+ };
@@ -9,9 +9,11 @@ export default class Tabbar extends BaseComponent {
9
9
  * 3. card - 卡片
10
10
  */
11
11
  type: "nav" | "bar" | "card";
12
- name?: string;
12
+ _name: string;
13
13
  gap?: string;
14
14
  private $line?;
15
+ get name(): string;
16
+ set name(nameValue: string);
15
17
  connectedCallback(): void;
16
18
  static get observedAttributes(): string[] | null | undefined;
17
19
  attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
@@ -1,7 +1,7 @@
1
1
  import { isBlank as h, isNumeric as c } from "ph-utils";
2
2
  import d from "../base.js";
3
3
  import { parseAttrValue as l } from "../utils/index.js";
4
- import { addClass as b, removeClass as o, $one as r, create as n, $$ as p, on as f, off as m, shouldEventNext as u, isVisible as v } from "ph-utils/dom";
4
+ import { addClass as b, removeClass as s, $one as r, create as n, $$ as p, on as f, off as m, shouldEventNext as u, isVisible as v } from "ph-utils/dom";
5
5
  const g = ":host{--l-tabbar-hover-color: var(--l-primary-color-light1, #9254de);--l-tabbar-active-color: var(--l-primary-color, #722ed1);--l-tabbar-item-gap: 0;--l-tabbar-height: 38px;position:relative;overflow:hidden;height:var(--l-tabbar-height);background-color:#fff;display:flex;flex-wrap:nowrap;align-items:stretch;gap:var(--l-tabbar-item-gap);box-sizing:border-box}:host(.l-tabbar--nav){--l-tabbar-height: 50px;--l-tabbar-item-grow: 1;width:100%}:host(.l-tabbar--bar){--l-tabbar-bar-vertical-padding: 10px;--l-tabbar-item-gap: 30px;--l-tabbar-line-color: var(--l-primary-color, #722ed1);overflow:auto;white-space:nowrap}.l-tabbar--bar-line{position:absolute;width:32px;left:0;bottom:0;border-radius:1px;height:2px;background-color:var(--l-tabbar-line-color);transition:all .3s ease-in-out}:host(.l-tabbar--card){--l-tabbar-card-border-color: #f5f7fa;--l-tabbar-line-color: #fff;--l-tabbar-item-gap: 0;--l-tabbar-card-border-radius: 5px}.l-tabbar-card-border{position:absolute;left:0;right:0;bottom:0;height:1px;background-color:var(--l-tabbar-card-border-color)}";
6
6
  class _ extends d {
7
7
  static baseName = "tabbar";
@@ -12,9 +12,15 @@ class _ extends d {
12
12
  * 3. card - 卡片
13
13
  */
14
14
  type = "nav";
15
- name;
15
+ _name = "";
16
16
  gap;
17
17
  $line;
18
+ get name() {
19
+ return this._name;
20
+ }
21
+ set name(t) {
22
+ this._name = t;
23
+ }
18
24
  connectedCallback() {
19
25
  this.loadStyleText(g), b(this, `l-tabbar--${this.type}`), this.#t(), super.connectedCallback();
20
26
  }
@@ -27,9 +33,9 @@ class _ extends d {
27
33
  this.name = i, this._updateActive(), this._updateLine();
28
34
  } else if (t === "type") {
29
35
  const i = l(a, "nav");
30
- if (i !== this.type && (o(this, `l-tabbar--${this.type}`), this.type = i, o(this, `l-tabbar--${i}`), i === "card")) {
31
- let s = r(".l-tabbar-card-border", this.root);
32
- s || (s = n("div", { class: "l-tabbar-card-border" }), this.root.appendChild(s));
36
+ if (i !== this.type && (s(this, `l-tabbar--${this.type}`), this.type = i, s(this, `l-tabbar--${i}`), i === "card")) {
37
+ let o = r(".l-tabbar-card-border", this.root);
38
+ o || (o = n("div", { class: "l-tabbar-card-border" }), this.root.appendChild(o));
33
39
  }
34
40
  } else {
35
41
  const i = l(a, void 0);
@@ -64,7 +70,7 @@ class _ extends d {
64
70
  };
65
71
  _updateActive() {
66
72
  const t = r(".active", this);
67
- t && o(t, "active");
73
+ t && s(t, "active");
68
74
  const e = r(`[name="${this.name}"]`, this);
69
75
  e && b(e, "active");
70
76
  }
@@ -91,7 +97,7 @@ class _ extends d {
91
97
  #t() {
92
98
  const t = this.getAttr("justify-content");
93
99
  if (h(t) ? this.style.removeProperty("justify-content") : this.style.setProperty("justify-content", t), h(this.gap))
94
- this.style.removeProperty("--l-tabbar-item-gap"), o(this, "l-tabbar-gap");
100
+ this.style.removeProperty("--l-tabbar-item-gap"), s(this, "l-tabbar-gap");
95
101
  else {
96
102
  let e = this.gap;
97
103
  c(e, { isPositive: !0 }) && (e = `${e}px`), b(this, "l-tabbar-gap"), this.style.setProperty("--l-tabbar-item-gap", e);
@@ -1,25 +1,40 @@
1
1
  import BaseComponent from "../base";
2
- import type { Column } from "./types";
2
+ import type { Column, SortOption } from "./types";
3
+ type ChangeFixedParams = {
4
+ fixedColumn?: boolean;
5
+ fixedHead?: boolean;
6
+ };
3
7
  export default class Table extends BaseComponent {
4
8
  static baseName: string;
5
9
  /** 斑马纹 */
6
10
  stripe: boolean;
11
+ /** 是否显示四周边框 */
12
+ border: boolean;
13
+ /** 是否固定表头 */
14
+ fixedHead: boolean;
15
+ /** 是否固定列,在进行列解析时,会自动确认该属性 */
16
+ fixedColumn: boolean;
17
+ /** 最大高度 */
18
+ maxHeight?: number | string;
19
+ /** 表格布局 */
20
+ tableLayout?: "auto" | "fixed";
7
21
  columns?: Column[];
8
22
  data?: any[];
9
- /** 左边固定列, 格式: [列key, 宽度] */
10
- private _fixedLeft;
11
- /** 右边固定列, 格式: [列key, 宽度] */
12
- private _fixedRight;
23
+ sortInfo?: SortOption;
13
24
  /** 缓存列通用样式, 避免渲染数据时,重复计算 */
14
25
  private _globalColStyles?;
15
26
  connectedCallback(): void;
16
27
  setColumns(columns: Column[]): void;
17
- setData(data: any[]): void;
28
+ setData(data: any[], sortInfo?: SortOption): void;
29
+ changeFixed(params?: ChangeFixedParams): void;
18
30
  static get observedAttributes(): string[];
19
31
  attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
20
32
  render(): HTMLElement;
21
- rerender(): void;
22
- private _updateStripe;
33
+ rerender(partial: "head" | "body" | "all"): void;
34
+ private _changeCssVar;
35
+ private _changeMaxHeight;
36
+ private _classAttrChannge;
37
+ private _updateFixedHead;
23
38
  private _headRender;
24
39
  private _rendHeadRow;
25
40
  private _headColRender;
@@ -28,8 +43,8 @@ export default class Table extends BaseComponent {
28
43
  /**
29
44
  * 解析列配置,表头跨行跨列、固定列
30
45
  * @param columns 列配置
31
- * @param fixedLeft 左边固定列
32
- * @param fixedRight 右边固定列
46
+ * @param leftOffset 左边固定列偏移
47
+ * @param rightOffset 右边固定列偏移
33
48
  * @returns
34
49
  */
35
50
  private _parseColumns;
@@ -43,4 +58,6 @@ export default class Table extends BaseComponent {
43
58
  private _handleTap;
44
59
  afterInit(): void;
45
60
  beforeDestroy(): void;
61
+ private _dataSort;
46
62
  }
63
+ export {};
@@ -1,159 +1,213 @@
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 {
1
+ import p from "../base.js";
2
+ import { kebabToCamel as b, parseAttrValue as x } from "../utils/index.js";
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
+ import { random as _ } from "ph-utils";
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;
10
+ /** 是否显示四周边框 */
11
+ border = !1;
12
+ /** 是否固定表头 */
13
+ fixedHead = !1;
14
+ /** 是否固定列,在进行列解析时,会自动确认该属性 */
15
+ fixedColumn = !1;
16
+ /** 最大高度 */
17
+ maxHeight;
18
+ /** 表格布局 */
19
+ tableLayout;
10
20
  columns = [];
11
21
  data = [];
12
- /** 左边固定列, 格式: [列key, 宽度] */
13
- _fixedLeft = [];
14
- /** 右边固定列, 格式: [列key, 宽度] */
15
- _fixedRight = [];
22
+ sortInfo;
16
23
  /** 缓存列通用样式, 避免渲染数据时,重复计算 */
17
24
  _globalColStyles;
18
25
  connectedCallback() {
19
- this.loadStyleText(R), super.connectedCallback();
26
+ this.loadStyleText(m), super.connectedCallback();
20
27
  }
21
28
  setColumns(t) {
22
- this._fixedLeft = [], this._fixedRight = [], this.columns = this._parseColumns(
23
- t,
24
- this._fixedLeft,
25
- this._fixedRight
26
- ), this.rerender();
29
+ let i = 0, e = 0;
30
+ this.columns = this._parseColumns(t, i, e), this.rerender("all");
31
+ }
32
+ setData(t, i) {
33
+ this.data = t, this.sortInfo = i, this.columns && this.columns.length > 0 && this.rerender(i ? "all" : "body");
27
34
  }
28
- setData(t) {
29
- this.data = t, this.columns && this.columns.length > 0 && this.rerender();
35
+ changeFixed(t) {
36
+ const i = {
37
+ fixedHead: this.fixedHead,
38
+ fixedColumn: this.fixedColumn,
39
+ ...t
40
+ };
41
+ if (this.fixedHead = i.fixedHead, this.fixedColumn = i.fixedColumn, this.rendered) {
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"));
44
+ }
30
45
  }
31
46
  static get observedAttributes() {
32
- return ["stripe"];
47
+ return ["stripe", "border", "fixed-head", "max-height", "table-layout"];
33
48
  }
34
- attributeChangedCallback(t, i, l) {
35
- t = f(t);
36
- const s = b(
37
- l,
49
+ attributeChangedCallback(t, i, e) {
50
+ t = b(t);
51
+ const s = x(
52
+ e,
38
53
  this[t],
39
54
  t
40
55
  );
41
56
  if (s !== this[t])
42
57
  switch (this[t] = s, t) {
43
58
  case "stripe":
44
- this._updateStripe();
59
+ this._classAttrChannge("stripe", s);
60
+ break;
61
+ case "border":
62
+ this._classAttrChannge("border", s);
63
+ break;
64
+ case "fixedHead":
65
+ this._updateFixedHead(), this.changeFixed();
66
+ break;
67
+ case "maxHeight":
68
+ this._changeMaxHeight();
69
+ break;
70
+ case "tableLayout":
71
+ this._changeCssVar("table-layout", s);
45
72
  break;
46
73
  }
47
74
  }
48
75
  render() {
49
- const t = o("table", {
50
- class: ["l-table", this.stripe ? "l-table-stripe" : ""]
76
+ const t = d("table", {
77
+ class: [
78
+ "l-table",
79
+ this.stripe ? "l-table-stripe" : "",
80
+ this.border ? "l-table-border" : "",
81
+ this.fixedHead || this.fixedColumn ? "l-table-fixed" : ""
82
+ ]
51
83
  });
52
84
  return t.appendChild(this._headRender()), t.appendChild(this._bodyRender()), t;
53
85
  }
54
- rerender() {
86
+ rerender(t) {
55
87
  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());
88
+ if (t === "all" || t === "head") {
89
+ const i = h("thead", this.root);
90
+ i && i.replaceWith(this._headRender());
91
+ }
92
+ if (t === "all" || t === "body") {
93
+ const i = h("tbody", this.root);
94
+ i && i.replaceWith(this._bodyRender());
95
+ }
60
96
  }
61
97
  }
62
- _updateStripe() {
98
+ _changeCssVar(t, i) {
99
+ if (!this.rendered) return;
100
+ const e = `--l-table-${t}`;
101
+ i ? this.style.setProperty(e, i) : this.style.removeProperty(e);
102
+ }
103
+ _changeMaxHeight() {
104
+ let t = this.maxHeight;
105
+ t && typeof t == "number" && (t = `${t}px`), this._changeCssVar("max-height", t);
106
+ }
107
+ _classAttrChannge(t, i) {
63
108
  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"));
109
+ const e = h("table", this.root);
110
+ e && e.classList.toggle(`l-table-${t}`, i);
111
+ }
112
+ }
113
+ _updateFixedHead() {
114
+ if (this.rendered) {
115
+ const t = h("thead", this.root);
116
+ t && (t.classList.toggle("l-fixed", this.fixedHead), t.style.top = this.fixedHead ? "0" : "");
66
117
  }
67
118
  }
68
119
  _headRender() {
69
- const t = o("thead");
120
+ const t = d("thead", {
121
+ class: {
122
+ "l-fixed": this.fixedHead
123
+ },
124
+ style: {
125
+ top: this.fixedHead ? "0" : void 0
126
+ }
127
+ });
70
128
  return this.columns && this._rendHeadRow(t, this.columns), t;
71
129
  }
72
130
  _rendHeadRow(t, i) {
73
- const l = o("tr");
131
+ const e = d("tr");
74
132
  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);
133
+ const r = i[s];
134
+ e.appendChild(this._headColRender(r, s)), r.children && this._rendHeadRow(t, r.children);
77
135
  }
78
- t.appendChild(l);
136
+ t.appendChild(e);
79
137
  }
80
138
  _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", {
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", {
84
142
  textContent: t.title
85
143
  })
86
144
  ), 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);
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);
89
147
  }
90
- return l;
148
+ return this.sortInfo && this.sortInfo.key === t.key && e.classList.add(this.sortInfo.order === "asc" ? "sort-asc" : "sort-desc"), e;
91
149
  }
92
150
  _bodyRender() {
93
- const t = o("tbody");
151
+ const t = d("tbody");
94
152
  if (this.data && this.data.length > 0)
95
- for (let i = 0, l = this.data.length; i < l; i++) {
153
+ for (let i = 0, e = this.data.length; i < e; i++) {
96
154
  const s = this.data[i];
97
155
  if (this.columns) {
98
- const a = o("tr");
156
+ const a = d("tr");
99
157
  this._bodyRowRender(this.columns, i, s, a), t.appendChild(a);
100
158
  }
101
159
  }
102
160
  else {
103
- const i = o("tr"), l = o("td", {
161
+ const i = d("tr"), e = d("td", {
104
162
  class: "l-table__empty-col",
105
163
  textContent: "暂无数据"
106
164
  });
107
- this.columns && (l.colSpan = this.columns.length), i.appendChild(l), t.appendChild(i);
165
+ this.columns && (e.colSpan = this.columns.length), i.appendChild(e), t.appendChild(i);
108
166
  }
109
167
  return t;
110
168
  }
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);
169
+ _bodyRowRender(t, i, e, s) {
170
+ for (let a = 0, r = t.length; a < r; a++) {
171
+ const l = t[a];
172
+ if (l.children && l.children.length > 0)
173
+ this._bodyRowRender(l.children, i, e, s);
116
174
  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);
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);
127
181
  } else
128
- n.textContent = e.key ? l[e.key] : "";
129
- s.appendChild(n);
182
+ o.textContent = l.key ? e[l.key] : "";
183
+ s.appendChild(o);
130
184
  }
131
185
  }
132
186
  }
133
187
  /**
134
188
  * 解析列配置,表头跨行跨列、固定列
135
189
  * @param columns 列配置
136
- * @param fixedLeft 左边固定列
137
- * @param fixedRight 右边固定列
190
+ * @param leftOffset 左边固定列偏移
191
+ * @param rightOffset 右边固定列偏移
138
192
  * @returns
139
193
  */
140
- _parseColumns(t, i, l) {
194
+ _parseColumns(t, i, e) {
141
195
  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]);
196
+ for (let a = 0, r = t.length; a < r; a++) {
197
+ const l = t[a];
198
+ if (l.id || (l.id = l.key || l.title), l.id || (l.id = `${a}_${_(6)}`), l.fixed) {
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);
147
201
  }
148
- if (e.children) {
149
- const n = this._parseColumns(
150
- e.children,
202
+ if (l.children) {
203
+ const o = this._parseColumns(
204
+ l.children,
151
205
  i,
152
- l
206
+ e
153
207
  );
154
- e.titleRowspan = e.titleRowspan || 1, e.titleColspan || (e.titleColspan = n.reduce((r, h) => r + (h.titleColspan || 1), 0)), s.push({ ...e, children: n });
208
+ l.titleRowspan = l.titleRowspan || 1, l.titleColspan || (l.titleColspan = o.reduce((n, c) => n + (c.titleColspan || 1), 0)), s.push({ ...l, children: o });
155
209
  } else
156
- e.titleRowspan = e.titleRowspan || this._getMaxDepth(t), e.titleColspan = e.titleColspan || 1, s.push({ ...e });
210
+ l.titleRowspan = l.titleRowspan || this._getMaxDepth(t), l.titleColspan = l.titleColspan || 1, s.push({ ...l });
157
211
  }
158
212
  return s;
159
213
  }
@@ -164,37 +218,52 @@ class T extends c {
164
218
  */
165
219
  _getMaxDepth(t) {
166
220
  let i = 1;
167
- for (const l of t)
168
- l.children && (i = Math.max(i, this._getMaxDepth(l.children) + 1));
221
+ for (const e of t)
222
+ e.children && (i = Math.max(i, this._getMaxDepth(e.children) + 1));
169
223
  return i;
170
224
  }
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;
225
+ _getColumnStyle(t, i = "td") {
226
+ const e = t.id;
227
+ if (this._globalColStyles && e in this._globalColStyles)
228
+ return this._globalColStyles[e][i];
229
+ const s = {};
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 = {
232
+ th: a,
233
+ td: a + f(t.style || "")
234
+ };
235
+ return this._globalColStyles[e] = r, r[i];
179
236
  }
180
237
  _handleTap = (t) => {
181
- const [i, l, s] = u(
238
+ const [i, e, s] = y(
182
239
  t,
183
240
  "data-action",
184
241
  t.currentTarget
185
242
  );
186
243
  if (i) {
187
244
  const a = s.dataset;
188
- this.emit("action", { detail: a });
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 });
189
250
  }
190
251
  };
191
252
  afterInit() {
192
- C(this.root, "click", this._handleTap);
253
+ this._changeMaxHeight(), u(this.root, "click", this._handleTap);
193
254
  }
194
255
  beforeDestroy() {
195
- y(this.root, "click", this._handleTap);
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
+ });
196
265
  }
197
266
  }
198
267
  export {
199
- T as default
268
+ H as default
200
269
  };
@@ -9,6 +9,10 @@ export interface Column {
9
9
  width?: number | string;
10
10
  /** 是否固定列, left - 固定在左方, right - 固定右方 */
11
11
  fixed?: "left" | "right";
12
+ /** 列固定左时, 左边偏移量 */
13
+ left?: number;
14
+ /** 列固定右时, 右边偏移量 */
15
+ right?: number;
12
16
  /** 多级表头 */
13
17
  children?: Column[];
14
18
  /** 表头跨行 */
@@ -16,7 +20,7 @@ export interface Column {
16
20
  /** 表头跨列 */
17
21
  titleColspan?: number;
18
22
  /** 列是否支持排序 */
19
- sorter?: boolean;
23
+ sorter?: boolean | "custom";
20
24
  /** 列的样式 */
21
25
  style?: Record<string, string | null | undefined>;
22
26
  /** td colspan */
@@ -26,3 +30,7 @@ export interface Column {
26
30
  /** 单元格内容渲染函数 */
27
31
  render?: (rowData: any, rowIndex: number) => HTMLElement | DocumentFragment | HTMLElement[] | string;
28
32
  }
33
+ export interface SortOption {
34
+ key: string;
35
+ order: "asc" | "desc";
36
+ }
package/lib/tag/index.js CHANGED
@@ -66,7 +66,10 @@ class x extends s {
66
66
  o || this.classList.add(`l-tag--${this.type}`);
67
67
  }
68
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))));
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(
70
+ "--l-tag-background",
71
+ n(this.color, 5, !0)
72
+ )));
70
73
  }
71
74
  beforeDestroy() {
72
75
  h(this.root, "click", this.#t);