litos-ui 0.17.4 → 0.17.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/base.js CHANGED
@@ -32,7 +32,7 @@ class a extends HTMLElement {
32
32
  this._pendingTask && (cancelAnimationFrame(this._pendingTask), this._pendingTask = void 0, this._pendingUpdate = !1);
33
33
  }
34
34
  batchUpdate() {
35
- this._pendingUpdate || (this.cancelPending(), this._pendingUpdate = !0, requestAnimationFrame(() => {
35
+ this._pendingUpdate || (this.cancelPending(), this._pendingUpdate = !0, this._pendingTask = requestAnimationFrame(() => {
36
36
  const e = new Set(this._changedProperties);
37
37
  this._changedProperties.clear(), this.updateDOM(e), this._pendingUpdate = !1;
38
38
  }));
@@ -3,12 +3,17 @@ type CalendarState = {
3
3
  locale: string;
4
4
  minDate: number;
5
5
  maxDate: number;
6
+ year: number;
7
+ month: number;
8
+ type: "select" | "range";
6
9
  };
7
10
  export default class Calendar extends FormInner<CalendarState> {
8
11
  static baseName: string;
9
- private _currentDate;
10
12
  private _langData;
11
13
  private $container?;
14
+ /** 选择的日期列表 */
15
+ private _selectDates;
16
+ private _range?;
12
17
  constructor();
13
18
  setValue(v: string): void;
14
19
  connectedCallback(): void;
@@ -26,5 +31,6 @@ export default class Calendar extends FormInner<CalendarState> {
26
31
  template?: string | HTMLElement | DocumentFragment;
27
32
  style?: string | string[];
28
33
  };
34
+ private _updateCellsState;
29
35
  }
30
36
  export {};
@@ -1,82 +1,107 @@
1
- import D from "../form/form_inner.js";
2
- import { $one as y } from "ph-utils/dom";
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";
3
4
  import { langs as f } from "./langs.js";
4
- import { get as k } from "ph-utils/storage";
5
- import { parse as w, endOf as H, startOf as C, format as c } from "ph-utils/date";
6
- const T = ":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}";
7
- class A extends D {
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 {
8
9
  static baseName = "calendar";
9
- _currentDate;
10
10
  _langData;
11
11
  $container;
12
+ /** 选择的日期列表 */
13
+ _selectDates;
14
+ _range;
12
15
  constructor() {
13
- super(), this.version = 2, this._currentDate = /* @__PURE__ */ new Date();
14
- const t = k("l_app_locale", "zh-CN", { storage: "session" });
16
+ super(), this.version = 2;
17
+ const t = T("l_app_locale", "zh-CN", { storage: "session" }), e = /* @__PURE__ */ new Date();
15
18
  this._state = {
16
19
  locale: t,
17
20
  minDate: -1 / 0,
18
- maxDate: 1 / 0
19
- }, this._langData = f[t];
21
+ maxDate: 1 / 0,
22
+ year: e.getFullYear(),
23
+ month: e.getMonth(),
24
+ type: "select"
25
+ }, this._langData = f[t], this._selectDates = [];
20
26
  }
21
27
  setValue(t) {
22
- t != this.value && (super.setValue(t), this._currentDate = w(t), this.rerenderBody());
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());
23
29
  }
24
30
  connectedCallback() {
25
31
  super.connectedCallback();
26
32
  }
27
33
  afterInit() {
28
- this.$container = y(".calendar-table", this.root);
34
+ this.$container = m(".calendar-table", this.root);
29
35
  }
30
36
  beforeDestroy() {
31
37
  this.$container = void 0;
32
38
  }
33
39
  static get observedAttributes() {
34
- return [...D.observedAttributes, "locale"];
40
+ return [
41
+ ...u.observedAttributes,
42
+ "locale",
43
+ "year",
44
+ "month",
45
+ "min-date",
46
+ "max-date",
47
+ "type"
48
+ ];
35
49
  }
36
- attributeChanged(t, r, n) {
50
+ attributeChanged(t, e, a) {
37
51
  switch (t) {
38
52
  case "locale":
39
- f.hasOwnProperty(n) && (this._state.locale = n, this._langData = f[n]);
53
+ f.hasOwnProperty(a) && (this._state.locale = a, this._langData = f[a]);
40
54
  break;
41
55
  case "min-date":
42
- this._state.minDate = C(n).getTime();
56
+ this._state.minDate = I(a).getTime();
43
57
  break;
44
58
  case "max-date":
45
- this._state.maxDate = H(n).getTime();
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;
46
69
  break;
47
70
  }
48
71
  }
49
72
  updateDOM(t) {
50
- t.has("locale") && this.rerenderHeader(), this.$container && (this.$container.innerHTML = this.rerender());
73
+ t.has("locale") ? this.rerenderHeader() : (t.has("year") || t.has("month")) && this.$container && (this.$container.innerHTML = this.rerender());
51
74
  }
52
75
  _renderHeader() {
53
- return `<tr>${this._langData.weekdays.map((r) => `<th>${r}</th>`).join("")}</tr>`;
76
+ return `<tr>${this._langData.weekdays.map((e) => `<th>${e}</th>`).join("")}</tr>`;
54
77
  }
55
78
  _renderBody() {
56
- const t = this._currentDate.getFullYear(), r = this._currentDate.getMonth(), n = c(null, "yyyy-mm-dd"), b = new Date(t, r, 1);
57
- let a = b.getDay() - 1;
58
- a < 0 && (a = 6);
59
- const m = new Date(t, r + 1, 0), u = m.getDate(), g = c(m, "yyyy-mm"), p = new Date(t, r, 0), $ = p.getDate(), _ = c(p, "yyyy-mm"), x = new Date(t, r + 1, 1), v = c(x, "yyyy-mm"), d = new Date(b);
60
- d.setDate(d.getDate() - a), d.setHours(0, 0, 0, 0);
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;
61
86
  let i = "";
62
- for (let e = 0; e < 42; e++) {
63
- e % 7 === 0 && (i += "<tr>");
64
- let o, s = "day", l = "";
65
- e < a ? (o = `${$ - a + e + 1}`, s += " prev-month", l = _) : e < a + u ? (o = `${e - a + 1}`, l = g) : (o = `${e - a - u + 1}`, s += " next-month disabled", l = v);
66
- const h = `${l}-${o.padStart(2, "0")}`;
67
- h === n && (s += " today"), h === this.value && (s += " active"), i += `<td class="${s}" title="${h}">${o}</td>`, e % 7 === 6 && (i += "</tr>");
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>");
68
93
  }
69
94
  return i;
70
95
  }
71
96
  rerenderHeader() {
72
97
  if (this.$container) {
73
- const t = y("thead", this.$container);
98
+ const t = m("thead", this.$container);
74
99
  t.innerHTML = this._renderHeader();
75
100
  }
76
101
  }
77
102
  rerenderBody() {
78
103
  if (this.$container) {
79
- const t = y("tbody", this.$container);
104
+ const t = m("tbody", this.$container);
80
105
  t.innerHTML = this._renderBody();
81
106
  }
82
107
  }
@@ -86,10 +111,13 @@ class A extends D {
86
111
  render_v2() {
87
112
  return {
88
113
  template: `<table class="calendar-table">${this.rerender()}</table>`,
89
- style: [T]
114
+ style: [O]
90
115
  };
91
116
  }
117
+ //只要 minDate、maxDate、_rangeStart、_rangeEnd、_hoverDate、_selectedDates 任何一个发生了改变,都调用这个统一的函数。
118
+ _updateCellsState() {
119
+ }
92
120
  }
93
121
  export {
94
- A as default
122
+ Y as default
95
123
  };
@@ -28,6 +28,7 @@ declare class LoadingInstance {
28
28
  /** 隐藏进度条 */
29
29
  hide(): void;
30
30
  destroy(): void;
31
+ updateLoadingText(text: string): void;
31
32
  }
32
33
  declare const _default: {
33
34
  /** 创建并显示进度条 */
@@ -1,49 +1,49 @@
1
1
  import { $ as c, iterate as d, $one as r, addClass as g, hasClass as m, $$ as o } from "ph-utils/dom";
2
- function f(t, e) {
3
- if (m(t, "l-loading")) return;
2
+ function f(e, t) {
3
+ if (m(e, "l-loading")) return;
4
4
  let l;
5
- if (e.fullscreen && r("#l-loading") != null)
5
+ if (t.fullscreen && r("#l-loading") != null)
6
6
  return;
7
7
  const s = ["l-loading"];
8
- (e.mask === 1 || e.mask === 2 && e.shape === "circle") && (l = o("div", {
8
+ (t.mask === 1 || t.mask === 2 && t.shape === "circle") && (l = o("div", {
9
9
  class: "l-loading-mask",
10
10
  style: {
11
- "background-color": e.background,
12
- "--l-loading-zindex": e.zindex
11
+ "background-color": t.background,
12
+ "--l-loading-zindex": t.zindex
13
13
  }
14
- }), t.appendChild(l));
14
+ }), e.appendChild(l));
15
15
  const n = o("div", {
16
- class: `l-loading-spinner l-loading--${e.shape}`,
16
+ class: `l-loading-spinner l-loading--${t.shape}`,
17
17
  style: {
18
- "--l-loading-color": e.color
18
+ "--l-loading-color": t.color
19
19
  }
20
20
  });
21
- if (e.shape === "bar") {
21
+ if (t.shape === "bar") {
22
22
  const i = o("div", { class: "l-loading-progress" });
23
23
  n.appendChild(i);
24
- } else if (e.shape === "circle") {
24
+ } else if (t.shape === "circle") {
25
25
  const i = document.createElementNS("http://www.w3.org/2000/svg", "svg");
26
26
  i.setAttribute("viewBox", "0 0 50 50"), i.classList.add("circle");
27
27
  const a = document.createElementNS("http://www.w3.org/2000/svg", "circle");
28
- if (a.classList.add("path"), a.setAttribute("cx", "25"), a.setAttribute("cy", "25"), a.setAttribute("r", "23"), a.setAttribute("fill", "none"), i.appendChild(a), n.appendChild(i), e.text) {
28
+ if (a.classList.add("path"), a.setAttribute("cx", "25"), a.setAttribute("cy", "25"), a.setAttribute("r", "23"), a.setAttribute("fill", "none"), i.appendChild(a), n.appendChild(i), t.text) {
29
29
  const p = o("p", {
30
30
  class: "l-loading-text",
31
- textContent: e.text
31
+ textContent: t.text
32
32
  });
33
33
  n.appendChild(p);
34
34
  }
35
35
  }
36
- t.appendChild(n), e.lock && s.push("l-loading-lock"), e.fullscreen && (s.push("l-loading-fullscreen"), n.id = "l-loading"), t.classList.add(...s), requestAnimationFrame(() => {
36
+ e.appendChild(n), t.lock && s.push("l-loading-lock"), t.fullscreen && (s.push("l-loading-fullscreen"), n.id = "l-loading"), e.classList.add(...s), requestAnimationFrame(() => {
37
37
  l && (l.style.opacity = "1"), n.style.opacity = "1", g(n, "l-loading-bar--start");
38
38
  });
39
39
  }
40
- function h(t, e) {
41
- const l = t.tagName === "BODY" ? "body" : ".l-loading", s = r(`${l} > .l-loading-mask`, t), n = r(`${l} > .l-loading-spinner`, t);
40
+ function h(e, t) {
41
+ const l = e.tagName === "BODY" ? "body" : ".l-loading", s = r(`${l} > .l-loading-mask`, e), n = r(`${l} > .l-loading-spinner`, e);
42
42
  if (!n) return;
43
43
  function i() {
44
44
  s && s.remove(), n.remove();
45
45
  const a = ["l-loading"];
46
- t.tagName === "BODY" && a.push("l-loading-fullscreen", "l-loading-lock"), t.classList.remove(...a);
46
+ e.tagName === "BODY" && a.push("l-loading-fullscreen", "l-loading-lock"), e.classList.remove(...a);
47
47
  }
48
48
  n.addEventListener("transitionend", i, { once: !0 }), requestAnimationFrame(() => {
49
49
  s && (s.style.opacity = "0"), g(n, "l-loading-bar--finish"), n.style.opacity = "0";
@@ -54,7 +54,7 @@ class b {
54
54
  el;
55
55
  option;
56
56
  isLoading = !1;
57
- constructor(e) {
57
+ constructor(t) {
58
58
  this.option = {
59
59
  fullscreen: !0,
60
60
  lock: !0,
@@ -63,9 +63,9 @@ class b {
63
63
  background: "",
64
64
  color: "",
65
65
  mask: 2,
66
- ...e
66
+ ...t
67
67
  };
68
- const l = (e || {}).to;
68
+ const l = (t || {}).to;
69
69
  let s = null;
70
70
  l != null && (typeof l == "string" ? s = document.querySelector(l) : s = l), (s == null || this.option.fullscreen) && (s = document.body), this.el = s, this.show();
71
71
  }
@@ -80,27 +80,31 @@ class b {
80
80
  destroy() {
81
81
  this.hide(), this.el = void 0;
82
82
  }
83
+ updateLoadingText(t) {
84
+ const l = r(".l-loading-text", this.el);
85
+ l && (l.textContent = t);
86
+ }
83
87
  }
84
- function u(t) {
85
- const e = t.getAttribute("l-loading-text"), l = t.getAttribute("l-loading-lock");
88
+ function u(e) {
89
+ const t = e.getAttribute("l-loading-text"), l = e.getAttribute("l-loading-lock");
86
90
  return {
87
- background: t.getAttribute("l-loading-background"),
88
- text: e ? e === "0" || e === "false" ? void 0 : e : "加载中……",
89
- fullscreen: t.hasAttribute("l-loading-fullscreen"),
91
+ background: e.getAttribute("l-loading-background"),
92
+ text: t ? t === "0" || t === "false" ? void 0 : t : "加载中……",
93
+ fullscreen: e.hasAttribute("l-loading-fullscreen"),
90
94
  lock: !(l === "0" || l === "false"),
91
- mask: Number(t.hasAttribute("l-loading-mask") || 2),
92
- shape: t.getAttribute("l-loading-shape") || "circle",
93
- color: t.getAttribute("l-loading-color")
95
+ mask: Number(e.hasAttribute("l-loading-mask") || 2),
96
+ shape: e.getAttribute("l-loading-shape") || "circle",
97
+ color: e.getAttribute("l-loading-color")
94
98
  };
95
99
  }
96
100
  const k = {
97
101
  /** 创建并显示进度条 */
98
- create(t) {
99
- return new b(t);
102
+ create(e) {
103
+ return new b(e);
100
104
  },
101
105
  /** 根据指令参数初始化进度条 */
102
- init(t) {
103
- const e = t ? `[l-loading="${t}"]` : "[l-loading]", l = c(e);
106
+ init(e) {
107
+ const t = e ? `[l-loading="${e}"]` : "[l-loading]", l = c(t);
104
108
  d(l, (s) => {
105
109
  const n = u(s);
106
110
  f(n.fullscreen ? document.body : s, n);
@@ -114,8 +118,8 @@ const k = {
114
118
  *
115
119
  * @param id 可选参数,指定特定的加载元素 l-loading 对应的值,如果提供,则只关闭匹配该 id 的元素
116
120
  */
117
- close(t) {
118
- const e = t ? `[l-loading="${t}"]` : "[l-loading]", l = c(e);
121
+ close(e) {
122
+ const t = e ? `[l-loading="${e}"]` : "[l-loading]", l = c(t);
119
123
  d(l, (s) => {
120
124
  const n = u(s);
121
125
  h(n.fullscreen ? document.body : s);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "litos-ui",
3
- "version": "0.17.4",
3
+ "version": "0.17.5",
4
4
  "description": "基于 Web Component 的 UI 组件库",
5
5
  "keywords": [
6
6
  "component library",