litos-ui 0.17.5 → 0.18.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 (161) hide show
  1. package/README.md +49 -49
  2. package/lib/animation-CTt9qgA7.js +4 -0
  3. package/lib/base-Dm0WS1pK.js +62 -0
  4. package/lib/base.js +111 -147
  5. package/lib/button/index.d.ts +8 -3
  6. package/lib/button/index.js +2 -137
  7. package/lib/button-CC5PmAb1.js +146 -0
  8. package/lib/calendar/index.d.ts +10 -5
  9. package/lib/calendar/index.js +2 -123
  10. package/lib/calendar-DeP6yZB0.js +149 -0
  11. package/lib/carousel/index.js +2 -280
  12. package/lib/carousel/item.js +2 -15
  13. package/lib/carousel-D4Fe3LEx.js +272 -0
  14. package/lib/check/checkbox.js +2 -18
  15. package/lib/check/checkbox_group.js +6 -6
  16. package/lib/check/radio.js +2 -15
  17. package/lib/check/radio_group.js +9 -9
  18. package/lib/check-B0XraJvb.js +73 -0
  19. package/lib/check-CvGaONEx.js +117 -0
  20. package/lib/checkbox-DbWsmAaL.js +16 -0
  21. package/lib/collapse/index.d.ts +18 -11
  22. package/lib/collapse/index.js +2 -88
  23. package/lib/collapse/item.d.ts +28 -9
  24. package/lib/collapse/item.js +2 -115
  25. package/lib/collapse/types.d.ts +7 -0
  26. package/lib/collapse-CeKRZ-43.js +104 -0
  27. package/lib/color_picker/index.js +2 -42
  28. package/lib/color_picker-D0brKFm-.js +41 -0
  29. package/lib/date_picker/index.d.ts +23 -0
  30. package/lib/date_picker/index.js +3 -0
  31. package/lib/date_picker-DQGoiN8v.js +103 -0
  32. package/lib/date_picker_ori/index.js +2 -129
  33. package/lib/date_picker_ori-aRuSSi9D.js +122 -0
  34. package/lib/description_panel/index.js +2 -66
  35. package/lib/description_panel-Df_8rVbX.js +57 -0
  36. package/lib/dialog/dialog_container.js +2 -131
  37. package/lib/dialog/index.js +67 -85
  38. package/lib/dialog_container-DcN87wj0.js +126 -0
  39. package/lib/esm-sVEoAVPu.js +244 -0
  40. package/lib/form/form_item.d.ts +1 -0
  41. package/lib/form/form_item.js +2 -136
  42. package/lib/form/index.js +2 -147
  43. package/lib/form-DdU0yK0k.js +154 -0
  44. package/lib/form_inner-DR9tyB_r.js +117 -0
  45. package/lib/form_item-Bv-YafZK.js +137 -0
  46. package/lib/icon/arrow_down.js +12 -12
  47. package/lib/icon/arrow_left.js +9 -9
  48. package/lib/icon/arrow_right.js +9 -9
  49. package/lib/icon/arrow_up.js +12 -12
  50. package/lib/icon/base.d.ts +16 -2
  51. package/lib/icon/base.js +2 -38
  52. package/lib/icon/calendar.d.ts +5 -0
  53. package/lib/icon/calendar.js +10 -0
  54. package/lib/icon/caret_bottom.js +9 -9
  55. package/lib/icon/caret_top.js +9 -9
  56. package/lib/icon/close.js +9 -9
  57. package/lib/icon/close_filled.js +12 -12
  58. package/lib/icon/d_arrow_left.js +12 -12
  59. package/lib/icon/d_arrow_right.js +12 -12
  60. package/lib/icon/font_icon.d.ts +2 -3
  61. package/lib/icon/font_icon.js +35 -39
  62. package/lib/icon/info.js +12 -12
  63. package/lib/icon/loading.js +9 -9
  64. package/lib/icon/moon.js +12 -12
  65. package/lib/icon/more.js +12 -12
  66. package/lib/icon/reduction.js +12 -12
  67. package/lib/icon/refresh.d.ts +5 -0
  68. package/lib/icon/refresh.js +10 -0
  69. package/lib/icon/refresh_left.js +12 -12
  70. package/lib/icon/refresh_right.js +9 -9
  71. package/lib/icon/search.js +9 -9
  72. package/lib/icon/select.js +12 -12
  73. package/lib/icon/sort.js +9 -9
  74. package/lib/icon/success.js +12 -12
  75. package/lib/icon/sun.js +12 -12
  76. package/lib/icon/theme_default.js +12 -12
  77. package/lib/icon/warn.js +12 -12
  78. package/lib/icon/zoom_in.js +12 -12
  79. package/lib/icon/zoom_out.js +12 -12
  80. package/lib/image/image_preview.js +2 -104
  81. package/lib/image/index.js +2 -176
  82. package/lib/image-CeQVfS-v.js +162 -0
  83. package/lib/image_preview-PzZzwo6m.js +92 -0
  84. package/lib/index.d.ts +10 -4
  85. package/lib/index.js +80 -169
  86. package/lib/input/index.d.ts +6 -2
  87. package/lib/input/index.js +188 -203
  88. package/lib/input-DjKxcxry.js +4 -0
  89. package/lib/input_inner-BKJg9n9A.js +4 -0
  90. package/lib/item-Cuw_ZPyn.js +14 -0
  91. package/lib/item-DV842Aux.js +57 -0
  92. package/lib/item-ZXLWFzSm.js +119 -0
  93. package/lib/list/index.js +2 -58
  94. package/lib/list-CU7vHS6s.js +51 -0
  95. package/lib/loading/index.d.ts +3 -2
  96. package/lib/loading/index.js +109 -127
  97. package/lib/mask/index.js +2 -105
  98. package/lib/mask-BlV5QfTj.js +112 -0
  99. package/lib/md_input/index.js +2 -60
  100. package/lib/md_input-DSQx5TMW.js +58 -0
  101. package/lib/menu/index.js +2 -105
  102. package/lib/menu/menu_item.js +2 -21
  103. package/lib/menu/sub_menu.js +2 -83
  104. package/lib/menu-DAtplYAH.js +91 -0
  105. package/lib/menu_item-BW1Tu11Q.js +20 -0
  106. package/lib/message/index.js +67 -60
  107. package/lib/modal/index.js +2 -196
  108. package/lib/modal/modal_box.js +87 -86
  109. package/lib/modal-DWyWrN-D.js +192 -0
  110. package/lib/page_header/index.js +2 -109
  111. package/lib/page_header-DdeRDN4U.js +101 -0
  112. package/lib/pagination/index.js +2 -248
  113. package/lib/pagination-BoPzSPjT.js +210 -0
  114. package/lib/polygon/index.js +2 -27
  115. package/lib/polygon-C4Ow2lxi.js +20 -0
  116. package/lib/qrcode/index.d.ts +13 -4
  117. package/lib/qrcode/index.js +2 -57
  118. package/lib/qrcode-BFxsD_OP.js +64 -0
  119. package/lib/radio-2mNSYujz.js +13 -0
  120. package/lib/select/index.js +3 -401
  121. package/lib/select-CAgggYh7.js +326 -0
  122. package/lib/select_ori/index.js +47 -50
  123. package/lib/space/index.js +2 -35
  124. package/lib/space-CpTmBfHP.js +38 -0
  125. package/lib/sub_menu-D1s8ABNu.js +75 -0
  126. package/lib/switch/index.js +2 -50
  127. package/lib/switch-BaVBi5Ip.js +48 -0
  128. package/lib/tabbar/index.js +2 -109
  129. package/lib/tabbar/item.js +2 -58
  130. package/lib/tabbar-4_d2Fj1n.js +91 -0
  131. package/lib/table/index.js +2 -269
  132. package/lib/table-Hifj8jAX.js +234 -0
  133. package/lib/tabs/index.js +38 -42
  134. package/lib/tag/index.js +2 -72
  135. package/lib/tag-DPENZf_V.js +76 -0
  136. package/lib/theme/index.js +2 -89
  137. package/lib/theme/theme_color.js +22 -26
  138. package/lib/theme-BRTI2-Yk.js +83 -0
  139. package/lib/utils/clickoutside.js +18 -18
  140. package/lib/utils/context_provide.js +21 -21
  141. package/lib/utils/event.js +13 -18
  142. package/lib/utils/index.js +55 -58
  143. package/lib/utils/popover.d.ts +4 -1
  144. package/lib/utils/popover.js +276 -352
  145. package/lib/utils/transition.js +33 -31
  146. package/package.json +10 -11
  147. package/styles/container.css +4 -0
  148. package/styles/datepicker.css +55 -0
  149. package/styles/popover.css +14 -1
  150. package/lib/animation-DttknHkX.js +0 -4
  151. package/lib/calendar/langs.js +0 -8
  152. package/lib/carousel/timer.js +0 -19
  153. package/lib/check/check.js +0 -118
  154. package/lib/check/index.js +0 -68
  155. package/lib/check-CksURvTv.js +0 -4
  156. package/lib/form/form_inner.js +0 -125
  157. package/lib/form/types.js +0 -1
  158. package/lib/index-CrMiSe0x.js +0 -249
  159. package/lib/index-DY6m9Wbe.js +0 -4
  160. package/lib/litos-ui.css +0 -1
  161. package/lib/table/types.js +0 -1
@@ -0,0 +1,146 @@
1
+ import e from "./base.js";
2
+ import { kebabToCamel as t, parseAttrValue as n, unitNumberStr as r } from "./utils/index.js";
3
+ import { t as i } from "./animation-CTt9qgA7.js";
4
+ import { addClass as a, formatClass as o, formatStyle as s, off as c, on as l, removeClass as u, replaceClass as d } from "ph-utils/dom";
5
+ import { adjust as f } from "ph-utils/color";
6
+ //#region src/components/button/index.less?inline
7
+ var p = ":host{--l-btn-padding:0 15px;--l-btn-text-color:#fff;--l-btn-hover-text-color:var(--l-btn-text-color);--l-btn-active-text-color:var(--l-btn-text-color);--l-btn-border-color:var(--l-primary-color,#722ed1);--l-btn-background:var(--l-btn-border-color);--l-btn-hover-border-color:var(--l-primary-color-light1,#9254de);--l-btn-hover-background:var(--l-btn-hover-border-color);--l-btn-active-border-color:var(--l-primary-color-dark1,#531dab);--l-btn-active-background:var(--l-btn-active-border-color);--l-btn-disabled-color:#c9c9c9;--l-btn-disabled-background:#fbfbfb;--l-btn-disabled-border-color:#e6e6e6;--l-btn-height:var(--l-form-control-height,32px);width:auto;height:var(--l-btn-height);text-indent:0;box-sizing:border-box;border-radius:var(--l-border-radius,3px);display:inline-flex}:host([block]){width:100%}:host(.l-btn-small){--l-btn-height:24px;--l-btn-padding:0 7px}:host(.l-btn-large){--l-border-radius:6px;--l-btn-height:40px;--l-btn-padding:0 15px;font-size:16px}.l-btn{cursor:pointer;box-sizing:border-box;vertical-align:middle;width:100%;padding:var(--l-btn-padding);border-radius:inherit;height:100%;color:var(--l-btn-text-color);background:var(--l-btn-background);border:1px solid var(--l-btn-border-color);justify-content:center;align-items:center;gap:var(--l-btn-gap,5px);line-height:1;font-size:inherit;outline:none;transition:border-color .3s,background-color .3s,color .3s;display:inline-flex;position:relative}.l-btn:hover{border-color:var(--l-btn-hover-border-color,var(--l-btn-hover-background));color:var(--l-btn-hover-text-color);background:var(--l-btn-hover-background)}.l-btn:active{border-color:var(--l-btn-active-border-color,var(--l-btn-active-background));color:var(--l-btn-active-text-color);background:var(--l-btn-active-background)}.l-btn-normal{--l-btn-text-color:auto;--l-btn-background:transparent;--l-btn-border-color:#d9d9d9;--l-btn-hover-text-color:var(--l-primary-color-light1,#9254de);--l-btn-active-text-color:var(--l-primary-color-dark1,#531dab);--l-btn-hover-background:#fff;--l-btn-active-background:#fff;--l-btn-hover-border-color:var(--l-btn-hover-text-color);--l-btn-active-border-color:var(--l-btn-active-text-color)}.l-btn-primary{--l-btn-background:var(--l-primary-color,#722ed1);--l-btn-hover-background:var(--l-primary-color-light1,#9254de);--l-btn-active-background:var(--l-primary-color-dark1,#531dab);--l-btn-disabled-border-color:var(--l-primary-color-light2,#b37feb);--l-btn-disabled-background:var(--l-primary-color-light2,#b37feb);--l-btn-disabled-color:#fff}.l-btn:disabled{border-color:var(--l-btn-disabled-border-color);background:var(--l-btn-disabled-background);color:var(--l-btn-disabled-color);cursor:not-allowed;opacity:1}.l-btn.l-btn-loading{cursor:default}.l-btn-text{--l-btn-background:transparent;--l-btn-border-color:transparent;--l-btn-hover-border-color:transparent;--l-btn-active-border-color:transparent;--l-btn-disabled-background:transparent;--l-btn-disabled-border-color:transparent;--l-btn-hover-background:transparent;--l-btn-active-background:transparent;--l-btn-padding:5px}.l-btn-primary.l-btn-text{--l-btn-text-color:var(--l-primary-color,#722ed1);--l-btn-hover-text-color:var(--l-primary-color-light1,#9254de);--l-btn-active-text-color:var(--l-primary-color-dark1,#531dab)}.l-btn-ghost{--l-btn-text-color:var(--l-btn-border-color);--l-btn-background:transparent;--l-btn-hover-background:transparent;--l-btn-active-background:transparent;--l-btn-hover-text-color:var(--l-btn-hover-border-color);--l-btn-active-text-color:var(--l-btn-active-border-color)}.l-btn-round{border-radius:calc(var(--l-form-control-height,32px) / 2)}.l-btn-circle{width:var(--l-form-control-height,32px);border-radius:50%;padding:0}.l-btn:not(.l-btn-text)+.l-btn{margin-left:10px}html.dark .l-btn:disabled{--l-btn-disabled-background:#ffffff14;--l-btn-disabled-color:#ffffff4d;--l-btn-disabled-border-color:#ffffff4d}", m = class extends e {
8
+ static baseName = "button";
9
+ $btn;
10
+ constructor() {
11
+ super(), this.version = 2, this._state = {
12
+ loading: !1,
13
+ htmlType: "button",
14
+ text: !1,
15
+ ghost: !1,
16
+ disabled: !1,
17
+ type: "normal",
18
+ shape: "default",
19
+ loadingText: "加载中……",
20
+ size: "default"
21
+ };
22
+ }
23
+ get disabled() {
24
+ return this._state.disabled;
25
+ }
26
+ set disabled(e) {
27
+ this.setDisabled(e);
28
+ }
29
+ setLoading(e) {
30
+ this.$btn && (e ? (a(this.$btn, "l-btn-loading"), this.$btn.disabled = !0, this.$btn.innerHTML = this.loadingBody()) : (u(this.$btn, "l-btn-loading"), this.$btn.disabled = this.disabled, this.$btn.innerHTML = "<slot></slot>"));
31
+ }
32
+ setDisabled(e) {
33
+ this._state.disabled = e, this.$btn && (this.$btn.disabled = e);
34
+ }
35
+ static get observedAttributes() {
36
+ return [
37
+ "loading",
38
+ "color",
39
+ "text",
40
+ "ghost",
41
+ "disabled",
42
+ "height",
43
+ "html-type",
44
+ "type",
45
+ "shape",
46
+ "loading-text",
47
+ "size"
48
+ ];
49
+ }
50
+ attributeChanged(e, i, a) {
51
+ switch (e) {
52
+ case "color":
53
+ case "shape":
54
+ case "type":
55
+ case "size":
56
+ this._state[e] = a;
57
+ break;
58
+ case "height":
59
+ this._state[e] = r(a);
60
+ break;
61
+ case "text":
62
+ case "ghost":
63
+ case "disabled":
64
+ case "loading":
65
+ this._state[e] = n(a, !1, e);
66
+ break;
67
+ case "html-type":
68
+ case "loading-text":
69
+ this._state[t(e)] = a;
70
+ break;
71
+ }
72
+ }
73
+ updateDOM(e) {
74
+ this.$btn && (e.has("loading") && this.setLoading(this._state.loading), e.has("disabled") && this.setDisabled(this.disabled), e.has("color") && this._state.color && (this.$btn.style.cssText = this.applyColor(this._state.color, this._state.text, this._state.ghost)), e.has("type") && d(this.$btn, 1, `l-btn-${this._state.type || "normal"}`), e.has("size") && d(this.$btn, 2, `l-btn-${this._state.size || "default"}`), e.has("shape") && d(this.$btn, 3, `l-btn-${this._state.shape || "default"}`)), e.has("height") && this._updateHeight();
75
+ }
76
+ connectedCallback() {
77
+ this.className = `l-btn-${this._state.size || "default"} ${this.className}`, super.connectedCallback(), this.isFormButton() && l(this, "click", this._handleClick), this._updateHeight();
78
+ }
79
+ disconnectedCallback() {
80
+ super.disconnectedCallback(), this.isFormButton() && c(this, "click", this._handleClick), this.$btn = void 0;
81
+ }
82
+ isFormButton() {
83
+ let e = this.getHtmlType();
84
+ return e === "submit" || e === "reset";
85
+ }
86
+ getHtmlType() {
87
+ return this._state.htmlType;
88
+ }
89
+ render_v2() {
90
+ return {
91
+ style: [i, p],
92
+ template: this.render()
93
+ };
94
+ }
95
+ render() {
96
+ let e = document.createElement("button"), t = this._state.loading, n = this._state.text, r = this._state.ghost;
97
+ e.className = o([
98
+ "l-btn",
99
+ `l-btn-${this._state.type}`,
100
+ `l-btn-${this._state.size}`,
101
+ `l-btn-${this._state.shape}`,
102
+ r ? "l-btn-ghost" : "",
103
+ n ? "l-btn-text" : "",
104
+ t ? "l-btn-loading" : ""
105
+ ]), (this.disabled || t) && (e.disabled = !0), e.type = this._state.htmlType;
106
+ let i = this.applyColor(this._state.color || "", n, r);
107
+ return i && (e.style.cssText = i), t ? e.innerHTML = this.loadingBody() : e.innerHTML = "<slot></slot>", e.setAttribute("part", "default"), this.$btn = e, e;
108
+ }
109
+ loadingBody() {
110
+ let e = this._state.loadingText, t = ["<l-loading-icon class=\"l-rotate-anim\"></l-loading-icon>"];
111
+ return e ? t.push(`<span>${e}</span>`) : t.push("<slot></slot>"), t.join("");
112
+ }
113
+ applyColor(e, t = !1, n = !1) {
114
+ if (!e) return "";
115
+ let r = f(e, 1, !0), i = f(e, 3, !1);
116
+ return s({
117
+ "--l-btn-border-color": t ? "transparent" : e,
118
+ "--l-btn-text-color": n || t ? e : "#ffffff",
119
+ "--l-btn-hover-text-color": n || t ? r : "#ffffff",
120
+ "--l-btn-background": n || t ? "transparent" : e,
121
+ "--l-btn-active-text-color": n || t ? i : "#ffffff",
122
+ "--l-btn-hover-border-color": t ? "transparent" : r,
123
+ "--l-btn-hover-background": n || t ? "transparent" : r,
124
+ "--l-btn-active-background": n || t ? "transparent" : i,
125
+ "--l-btn-active-border-color": t ? "transparent" : i
126
+ });
127
+ }
128
+ _updateHeight() {
129
+ this._state.height ? this.style.setProperty("--l-btn-height", this._state.height) : this.style.removeProperty("--l-btn-height");
130
+ }
131
+ _replaceBtnClass(e, t) {
132
+ if (this.$btn) {
133
+ let n = this.$btn.classList.item(e);
134
+ n && this.$btn.classList.replace(n, t);
135
+ }
136
+ }
137
+ _handleClick = () => {
138
+ (this._state.htmlType === "reset" || this._state.htmlType === "submit") && this.emit("form-action", {
139
+ bubbles: !0,
140
+ composed: !0,
141
+ detail: this._state.htmlType
142
+ });
143
+ };
144
+ };
145
+ //#endregion
146
+ export { m as t };
@@ -1,4 +1,4 @@
1
- import FormInner from "../form/form_inner";
1
+ import BaseComponent from "../base";
2
2
  type CalendarState = {
3
3
  locale: string;
4
4
  minDate: number;
@@ -7,19 +7,25 @@ type CalendarState = {
7
7
  month: number;
8
8
  type: "select" | "range";
9
9
  };
10
- export default class Calendar extends FormInner<CalendarState> {
10
+ export default class Calendar extends BaseComponent<CalendarState> {
11
11
  static baseName: string;
12
12
  private _langData;
13
13
  private $container?;
14
14
  /** 选择的日期列表 */
15
15
  private _selectDates;
16
- private _range?;
16
+ private _range;
17
+ private _value;
17
18
  constructor();
19
+ get value(): string;
20
+ set value(v: string);
18
21
  setValue(v: string): void;
19
- connectedCallback(): void;
22
+ private _updateValue;
20
23
  afterInit(): void;
21
24
  beforeDestroy(): void;
22
25
  static get observedAttributes(): string[];
26
+ handleCellClick: (e: Event) => void;
27
+ handleCellHover: (e: Event) => void;
28
+ private _emitDayAction;
23
29
  protected attributeChanged(name: string, oldValue: string, newValue: string): void;
24
30
  protected updateDOM(changedProps: Set<string>): void;
25
31
  private _renderHeader;
@@ -31,6 +37,5 @@ export default class Calendar extends FormInner<CalendarState> {
31
37
  template?: string | HTMLElement | DocumentFragment;
32
38
  style?: string | string[];
33
39
  };
34
- private _updateCellsState;
35
40
  }
36
41
  export {};
@@ -1,123 +1,2 @@
1
- import u from "../form/form_inner.js";
2
- import { parseAttrValue as g } from "../utils/index.js";
3
- import { $one as m } from "ph-utils/dom";
4
- import { langs as f } from "./langs.js";
5
- import { get as T } from "ph-utils/storage";
6
- import { parse as w, endOf as M, startOf as I, format as c } from "ph-utils/date";
7
- const O = ":host{display:block;box-sizing:border-box;width:100%;height:100%}.calendar-table{width:100%;height:100%;border-collapse:collapse}.calendar-table thead{height:var(--calendar-header-height, auto)}.calendar-table th{font-weight:400;cursor:default}.calendar-table .prev-month,.calendar-table .next-month{color:var(--l-calendar-off-text-color, #a8abb2)}.calendar-table .today{color:var(--l-primary-color, #007bff)}.day{text-align:center;cursor:pointer;transition:background-color .2s;font-size:13px}.day:hover{background-color:#0000000a}.day.disabled{background-color:#0000000a;cursor:not-allowed}.day.active{background-color:var(--l-primary-color, #007bff);color:#fff;font-weight:700}";
8
- class Y extends u {
9
- static baseName = "calendar";
10
- _langData;
11
- $container;
12
- /** 选择的日期列表 */
13
- _selectDates;
14
- _range;
15
- constructor() {
16
- super(), this.version = 2;
17
- const t = T("l_app_locale", "zh-CN", { storage: "session" }), e = /* @__PURE__ */ new Date();
18
- this._state = {
19
- locale: t,
20
- minDate: -1 / 0,
21
- maxDate: 1 / 0,
22
- year: e.getFullYear(),
23
- month: e.getMonth(),
24
- type: "select"
25
- }, this._langData = f[t], this._selectDates = [];
26
- }
27
- setValue(t) {
28
- t != this.value && (super.setValue(t), this._state.type === "select" ? this._selectDates = t.split(",") : this._range = t.split(",").map((e) => w(e).getTime()), this.batchUpdate());
29
- }
30
- connectedCallback() {
31
- super.connectedCallback();
32
- }
33
- afterInit() {
34
- this.$container = m(".calendar-table", this.root);
35
- }
36
- beforeDestroy() {
37
- this.$container = void 0;
38
- }
39
- static get observedAttributes() {
40
- return [
41
- ...u.observedAttributes,
42
- "locale",
43
- "year",
44
- "month",
45
- "min-date",
46
- "max-date",
47
- "type"
48
- ];
49
- }
50
- attributeChanged(t, e, a) {
51
- switch (t) {
52
- case "locale":
53
- f.hasOwnProperty(a) && (this._state.locale = a, this._langData = f[a]);
54
- break;
55
- case "min-date":
56
- this._state.minDate = I(a).getTime();
57
- break;
58
- case "max-date":
59
- this._state.maxDate = M(a).getTime();
60
- break;
61
- case "year":
62
- this._state.year = g(a, this._state.year);
63
- break;
64
- case "month":
65
- this._state.month = g(a, this._state.month + 1) - 1;
66
- break;
67
- case "type":
68
- this._state.type = a;
69
- break;
70
- }
71
- }
72
- updateDOM(t) {
73
- t.has("locale") ? this.rerenderHeader() : (t.has("year") || t.has("month")) && this.$container && (this.$container.innerHTML = this.rerender());
74
- }
75
- _renderHeader() {
76
- return `<tr>${this._langData.weekdays.map((e) => `<th>${e}</th>`).join("")}</tr>`;
77
- }
78
- _renderBody() {
79
- const t = this._state.year, e = this._state.month, a = c(null, "yyyy-mm-dd"), b = new Date(t, e, 1);
80
- let s = b.getDay() - 1;
81
- s < 0 && (s = 6);
82
- const p = new Date(t, e + 1, 0), D = p.getDate(), $ = c(p, "yyyy-mm"), _ = new Date(t, e, 0), x = _.getDate(), v = c(_, "yyyy-mm"), k = new Date(t, e + 1, 1), C = c(k, "yyyy-mm"), d = new Date(b);
83
- d.setDate(d.getDate() - s);
84
- let h = d.setHours(0, 0, 0, 0);
85
- const H = 864e5;
86
- let i = "";
87
- for (let r = 0; r < 42; r++) {
88
- r % 7 === 0 && (i += "<tr>");
89
- let n, o = "day", l = "";
90
- r < s ? (n = `${x - s + r + 1}`, o += " prev-month", l = v) : r < s + D ? (n = `${r - s + 1}`, l = $) : (n = `${r - s - D + 1}`, o += " next-month", l = C), (h < this._state.minDate || h > this._state.maxDate) && (o += " disabled");
91
- const y = `${l}-${n.padStart(2, "0")}`;
92
- y === a && (o += " today"), y === this.value && (o += " active"), i += `<td class="${o}" title="${y}">${n}</td>`, h += H, r % 7 === 6 && (i += "</tr>");
93
- }
94
- return i;
95
- }
96
- rerenderHeader() {
97
- if (this.$container) {
98
- const t = m("thead", this.$container);
99
- t.innerHTML = this._renderHeader();
100
- }
101
- }
102
- rerenderBody() {
103
- if (this.$container) {
104
- const t = m("tbody", this.$container);
105
- t.innerHTML = this._renderBody();
106
- }
107
- }
108
- rerender() {
109
- return `<thead>${this._renderHeader()}</thead><tbody>${this._renderBody()}</tbody>`;
110
- }
111
- render_v2() {
112
- return {
113
- template: `<table class="calendar-table">${this.rerender()}</table>`,
114
- style: [O]
115
- };
116
- }
117
- //只要 minDate、maxDate、_rangeStart、_rangeEnd、_hoverDate、_selectedDates 任何一个发生了改变,都调用这个统一的函数。
118
- _updateCellsState() {
119
- }
120
- }
121
- export {
122
- Y as default
123
- };
1
+ import { t as e } from "../calendar-DeP6yZB0.js";
2
+ export { e as default };
@@ -0,0 +1,149 @@
1
+ import e from "./base.js";
2
+ import { parseAttrValue as t } from "./utils/index.js";
3
+ import { $one as n, hasClass as r, off as i, on as a, shouldEventNext as o } from "ph-utils/dom";
4
+ import { endOf as s, format as c, startOf as l, timestamp as u } from "ph-utils/date";
5
+ import { get as d } from "ph-utils/storage";
6
+ //#region src/components/calendar/index.less?inline
7
+ var f = ":host{box-sizing:border-box;width:100%;height:100%;display:block}.calendar-table{border-collapse:collapse;table-layout:fixed;width:100%;height:100%}.calendar-table thead{height:var(--l-calendar-header-height,32px)}.calendar-table th{cursor:default;font-weight:400}.calendar-table .excluded{color:var(--l-calendar-off-text-color,#a8abb2)}.day{text-align:center;cursor:pointer;font-size:14px;transition:background-color .2s}:where(.day:hover){background-color:#0000000a}.day.disabled{color:var(--l-calendar-off-text-color,#a8abb2);cursor:not-allowed}.day.active:not(.disabled){background-color:var(--l-primary-color,#007bff);color:#fff;font-weight:700}.day.today{color:var(--l-primary-color,#007bff)}.day.range{background-color:var(--l-primary-color-light4,#cce6ff)}.day.range-start,.day.range-end{background-color:var(--l-primary-color,#007bff);color:#fff}", p = { "zh-CN": { weekdays: [
8
+ "一",
9
+ "二",
10
+ "三",
11
+ "四",
12
+ "五",
13
+ "六",
14
+ "七"
15
+ ] } }, m = class extends e {
16
+ static baseName = "calendar";
17
+ _langData;
18
+ $container;
19
+ _selectDates;
20
+ _range;
21
+ _value;
22
+ constructor() {
23
+ super(), this.version = 2;
24
+ let e = d("l_app_locale", "zh-CN", { storage: "session" }), t = /* @__PURE__ */ new Date();
25
+ this._value = "", this._state = {
26
+ locale: e,
27
+ minDate: -Infinity,
28
+ maxDate: Infinity,
29
+ year: t.getFullYear(),
30
+ type: "select",
31
+ month: t.getMonth()
32
+ }, this._langData = p[e], this._selectDates = /* @__PURE__ */ new Set(), this._range = [0, 0];
33
+ }
34
+ get value() {
35
+ return this._value;
36
+ }
37
+ set value(e) {
38
+ this.setValue(e);
39
+ }
40
+ setValue(e) {
41
+ e != this._value && (this._value = e, this._updateValue());
42
+ }
43
+ _updateValue() {
44
+ this._state.type === "range" ? (this._value ? this._range = this._value.split(",").map((e) => /^\d+$/.test(e) ? e.length === 10 ? Number(e) * 1e3 : Number(e) : u(e, "ms")) : this._range = [0, 0], this._selectDates.clear()) : (this._selectDates = new Set(this._value.split("&")), this._range = [0, 0]), this.batchUpdate();
45
+ }
46
+ afterInit() {
47
+ this.$container = n(".calendar-table", this.root), a(this.root, "click", this.handleCellClick), a(this.$container, "mouseover", this.handleCellHover);
48
+ }
49
+ beforeDestroy() {
50
+ i(this.root, "click", this.handleCellClick), this.$container &&= (i(this.$container, "mouseover", this.handleCellHover), void 0);
51
+ }
52
+ static get observedAttributes() {
53
+ return [
54
+ "value",
55
+ "locale",
56
+ "year",
57
+ "month",
58
+ "min-date",
59
+ "max-date",
60
+ "type"
61
+ ];
62
+ }
63
+ handleCellClick = (e) => {
64
+ let [t, n, r] = o(e, "l-day", this.root);
65
+ t && this._emitDayAction(r, "click", n);
66
+ };
67
+ handleCellHover = (e) => {
68
+ let [t, n, r] = o(e, "l-day", this.root);
69
+ t && this._emitDayAction(r, "hover", n);
70
+ };
71
+ _emitDayAction(e, t, n) {
72
+ this.emit(`day-${t}`, { detail: {
73
+ minTimestamp: this._state.minDate,
74
+ maxTimestamp: this._state.maxDate,
75
+ dayTimestamp: Number(n),
76
+ day: e.title,
77
+ isActiveMonth: !r(e, "excluded")
78
+ } });
79
+ }
80
+ attributeChanged(e, n, r) {
81
+ switch (e) {
82
+ case "locale":
83
+ p.hasOwnProperty(r) && (this._state.locale = r, this._langData = p[r]);
84
+ break;
85
+ case "min-date":
86
+ this._state.minDate = l(r).getTime();
87
+ break;
88
+ case "max-date":
89
+ this._state.maxDate = s(r).getTime();
90
+ break;
91
+ case "year":
92
+ this._state.year = t(r, this._state.year);
93
+ break;
94
+ case "month":
95
+ this._state.month = t(r, this._state.month + 1) - 1;
96
+ break;
97
+ case "type":
98
+ this._state.type = r, this._updateValue();
99
+ break;
100
+ case "value":
101
+ this.setValue(r);
102
+ break;
103
+ }
104
+ }
105
+ updateDOM(e) {
106
+ e.has("locale") ? this.rerenderHeader() : e.has("year") || e.has("month") ? this.$container && (this.$container.innerHTML = this.rerender()) : this.rerenderBody();
107
+ }
108
+ _renderHeader() {
109
+ return `<tr>${this._langData.weekdays.map((e) => `<th>${e}</th>`).join("")}</tr>`;
110
+ }
111
+ _renderBody() {
112
+ let e = this._state.year, t = this._state.month, n = c(null, "yyyy-mm-dd"), r = new Date(e, t, 1), i = r.getDay() - 1;
113
+ i < 0 && (i = 6);
114
+ let a = new Date(e, t + 1, 0), o = a.getDate(), s = c(a, "yyyy-mm"), l = new Date(e, t, 0), u = l.getDate(), d = c(l, "yyyy-mm"), f = c(new Date(e, t + 1, 1), "yyyy-mm"), p = new Date(r);
115
+ p.setDate(p.getDate() - i);
116
+ let m = p.setHours(0, 0, 0, 0), h = "", [g, _] = this._range || [];
117
+ for (let e = 0; e < 42; e++) {
118
+ e % 7 == 0 && (h += "<tr>");
119
+ let t, r = "day", a = "";
120
+ e < i ? (t = `${u - i + e + 1}`, r += " excluded", a = d) : e < i + o ? (t = `${e - i + 1}`, a = s) : (t = `${e - i - o + 1}`, r += " excluded", a = f), (m < this._state.minDate || m > this._state.maxDate) && (r += " disabled");
121
+ let c = `${a}-${t.padStart(2, "0")}`;
122
+ c === n && (r += " today"), this._selectDates.has(c) && (r += " active"), g && _ && (g === m ? r += " range-start" : _ === m ? r += " range-end" : g < m && m < _ && (r += " range")), h += `<td class="${r}" title="${c}" l-day="${m}">${t}</td>`, m += 864e5, e % 7 == 6 && (h += "</tr>");
123
+ }
124
+ return h;
125
+ }
126
+ rerenderHeader() {
127
+ if (this.$container) {
128
+ let e = n("thead", this.$container);
129
+ e.innerHTML = this._renderHeader();
130
+ }
131
+ }
132
+ rerenderBody() {
133
+ if (this.$container) {
134
+ let e = n("tbody", this.$container);
135
+ e.innerHTML = this._renderBody();
136
+ }
137
+ }
138
+ rerender() {
139
+ return `<thead>${this._renderHeader()}</thead><tbody>${this._renderBody()}</tbody>`;
140
+ }
141
+ render_v2() {
142
+ return {
143
+ template: `<table class="calendar-table" l-day="__stop__">${this.rerender()}</table>`,
144
+ style: [f]
145
+ };
146
+ }
147
+ };
148
+ //#endregion
149
+ export { m as t };