tor-univer-sheet 1.1.4 → 1.1.6

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.
@@ -1,64 +1,64 @@
1
- import b from "dayjs";
2
- import { CellValueType as j } from "@univerjs/presets";
3
- import V from "decimal.js";
4
- const re = (e, o) => {
5
- for (const r of o)
6
- e[r] = null;
7
- }, F = () => {
1
+ import h from "dayjs";
2
+ import { CellValueType as C } from "@univerjs/presets";
3
+ import B from "decimal.js";
4
+ const ct = (t, r) => {
5
+ for (const n of r)
6
+ t[n] = null;
7
+ }, _ = () => {
8
8
  if (typeof crypto == "object") {
9
9
  if (typeof crypto.randomUUID == "function")
10
10
  return crypto.randomUUID();
11
11
  if (typeof crypto.getRandomValues == "function" && typeof Uint8Array == "function") {
12
- const r = (t) => {
13
- const l = Number(t);
14
- return (l ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> l / 4).toString(16);
12
+ const n = (e) => {
13
+ const c = Number(e);
14
+ return (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16);
15
15
  };
16
- return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, r);
16
+ return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, n);
17
17
  }
18
18
  }
19
- let e = (/* @__PURE__ */ new Date()).getTime(), o = typeof performance < "u" && performance.now && performance.now() * 1e3 || 0;
20
- return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (r) => {
21
- let t = Math.random() * 16;
22
- return e > 0 ? (t = (e + t) % 16 | 0, e = Math.floor(e / 16)) : (t = (o + t) % 16 | 0, o = Math.floor(o / 16)), (r === "x" ? t : t & 3 | 8).toString(16);
19
+ let t = (/* @__PURE__ */ new Date()).getTime(), r = typeof performance < "u" && performance.now && performance.now() * 1e3 || 0;
20
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (n) => {
21
+ let e = Math.random() * 16;
22
+ return t > 0 ? (e = (t + e) % 16 | 0, t = Math.floor(t / 16)) : (e = (r + e) % 16 | 0, r = Math.floor(r / 16)), (n === "x" ? e : e & 3 | 8).toString(16);
23
23
  });
24
24
  };
25
- function oe(e) {
25
+ function ft(t) {
26
26
  return {
27
- ...e?.workbookData,
28
- id: e?.id || F(),
29
- name: e?.name || "未命名",
30
- appVersion: e?.appVersion || "1.0.0"
27
+ ...t?.workbookData,
28
+ id: t?.id || _(),
29
+ name: t?.name || "未命名",
30
+ appVersion: t?.appVersion || "1.0.0"
31
31
  };
32
32
  }
33
- const $ = Object.prototype.toString, A = (e, o) => $.call(e) === `[object ${o}]`, J = (e) => typeof e < "u", z = (e) => !J(e), B = (e) => e !== null && A(e, "Object"), R = (e) => e == null || typeof e > "u" ? !0 : G(e) || K(e) ? e.length === 0 : e instanceof Map || e instanceof Set ? e.size === 0 : B(e) ? Object.keys(e).length === 0 : !1, Z = (e) => e === null, _ = (e) => z(e) || Z(e), K = (e) => A(e, "String"), G = (e) => e && Array.isArray(e);
34
- class L {
33
+ const K = Object.prototype.toString, J = (t, r) => K.call(t) === `[object ${r}]`, L = (t) => typeof t < "u", Q = (t) => !L(t), W = (t) => t !== null && J(t, "Object"), G = (t) => t == null || typeof t > "u" ? !0 : q(t) || et(t) ? t.length === 0 : t instanceof Map || t instanceof Set ? t.size === 0 : W(t) ? Object.keys(t).length === 0 : !1, X = (t) => t === null, tt = (t) => Q(t) || X(t), et = (t) => J(t, "String"), q = (t) => t && Array.isArray(t);
34
+ class rt {
35
35
  value;
36
- constructor(o) {
37
- this.value = new V(o);
36
+ constructor(r) {
37
+ this.value = new B(r);
38
38
  }
39
39
  /**
40
40
  * 加法运算
41
41
  * @param num 要加的数
42
42
  * @returns DecimalChain 实例,支持链式调用
43
43
  */
44
- add(o) {
45
- return this.value = this.value.add(o || 0), this;
44
+ add(r) {
45
+ return this.value = this.value.add(r || 0), this;
46
46
  }
47
47
  /**
48
48
  * 减法运算
49
49
  * @param num 要减的数
50
50
  * @returns DecimalChain 实例,支持链式调用
51
51
  */
52
- subtract(o) {
53
- return this.value = this.value.sub(o || 0), this;
52
+ subtract(r) {
53
+ return this.value = this.value.sub(r || 0), this;
54
54
  }
55
55
  /**
56
56
  * 乘法运算
57
57
  * @param num 要乘的数
58
58
  * @returns DecimalChain 实例,支持链式调用
59
59
  */
60
- multiply(o) {
61
- return this.value = this.value.mul(o || 0), this;
60
+ multiply(r) {
61
+ return this.value = this.value.mul(r || 0), this;
62
62
  }
63
63
  /**
64
64
  * 除法运算
@@ -66,11 +66,11 @@ class L {
66
66
  * @returns DecimalChain 实例,支持链式调用
67
67
  * @throws 当除数为0时抛出错误
68
68
  */
69
- divide(o) {
70
- const r = new V(o);
71
- if (r.isZero())
69
+ divide(r) {
70
+ const n = new B(r);
71
+ if (n.isZero())
72
72
  throw new Error("除数是0");
73
- return this.value = this.value.div(r), this;
73
+ return this.value = this.value.div(n), this;
74
74
  }
75
75
  /**
76
76
  * 保留小数位数
@@ -78,8 +78,8 @@ class L {
78
78
  * @param rounding 舍入模式,默认为四舍五入
79
79
  * @returns DecimalChain 实例,支持链式调用
80
80
  */
81
- toFixed(o, r) {
82
- return this.value = new V(this.value.toFixed(o, r)), this;
81
+ toFixed(r, n) {
82
+ return this.value = new B(this.value.toFixed(r, n)), this;
83
83
  }
84
84
  /**
85
85
  * 返回当前值
@@ -103,447 +103,457 @@ class L {
103
103
  return this.value.toNumber();
104
104
  }
105
105
  }
106
- function k(e = 0) {
107
- return new L(e);
106
+ function I(t = 0) {
107
+ return new rt(t);
108
108
  }
109
- var Q = /* @__PURE__ */ ((e) => (e.无 = "no", e.年 = "year", e.月 = "month", e.周 = "week", e.天 = "day", e.班组 = "shift", e.小时 = "hour", e.半小时 = "half_hour", e))(Q || {}), W = /* @__PURE__ */ ((e) => (e.view = "view", e.edit = "edit", e))(W || {});
110
- async function ne(e, o) {
111
- if (!o) return Promise.reject("日期不能为空");
112
- switch (e) {
109
+ var nt = /* @__PURE__ */ ((t) => (t.无 = "no", t.年 = "year", t.月 = "month", t.周 = "week", t.天 = "day", t.班组 = "shift", t.小时 = "hour", t.半小时 = "half_hour", t))(nt || {}), ot = /* @__PURE__ */ ((t) => (t.view = "view", t.edit = "edit", t))(ot || {});
110
+ async function mt(t, r) {
111
+ if (!r) return Promise.reject("日期不能为空");
112
+ switch (t) {
113
113
  case "year":
114
- if (G(o))
115
- return Promise.resolve(o);
116
- const r = b(o);
117
- if (!r.isValid())
114
+ if (q(r))
115
+ return Promise.resolve(r);
116
+ const n = h(r);
117
+ if (!n.isValid())
118
118
  return Promise.reject("无效的日期格式");
119
- const t = r.year(), l = `${t}-01`, a = `${t}-12`;
120
- return Promise.resolve([l, a]);
119
+ const e = n.year(), c = `${e}-01`, o = `${e}-12`;
120
+ return Promise.resolve([c, o]);
121
121
  case "month":
122
- if (G(o))
123
- return Promise.resolve(o);
124
- const d = b(o);
125
- if (!d.isValid())
122
+ if (q(r))
123
+ return Promise.resolve(r);
124
+ const i = h(r);
125
+ if (!i.isValid())
126
126
  return Promise.reject("无效的日期格式");
127
- const T = d.startOf("month").format("YYYY-MM-DD"), i = d.endOf("month").format("YYYY-MM-DD");
128
- return Promise.resolve([T, i]);
127
+ const x = i.startOf("month").format("YYYY-MM-DD"), s = i.endOf("month").format("YYYY-MM-DD");
128
+ return Promise.resolve([x, s]);
129
129
  case "day":
130
- if (G(o))
131
- return Promise.resolve(o);
132
- const x = b(o);
133
- if (!x.isValid())
130
+ if (q(r))
131
+ return Promise.resolve(r);
132
+ const w = h(r);
133
+ if (!w.isValid())
134
134
  return Promise.reject("无效的日期格式");
135
- const f = x.startOf("day").format("YYYY-MM-DD HH:mm:ss"), h = x.endOf("day").format("YYYY-MM-DD HH:mm:ss");
136
- return Promise.resolve([f, h]);
135
+ const l = w.startOf("day").format("YYYY-MM-DD HH:mm:ss"), H = w.endOf("day").format("YYYY-MM-DD HH:mm:ss");
136
+ return Promise.resolve([l, H]);
137
137
  default:
138
138
  return Promise.reject("不支持的周期类型");
139
139
  }
140
140
  }
141
- function H(e, o, r) {
142
- if (!r) return 0;
143
- const t = {
141
+ function S(t, r, n) {
142
+ if (!n) return 0;
143
+ const e = {
144
144
  year: "YYYY",
145
145
  month: "YYYY-MM",
146
146
  day: "YYYY-MM-DD",
147
147
  hour: "HH:mm:ss"
148
- }[r];
149
- return ["day", "hour"].includes(r) ? b(o, t).diff(b(e, t), r) + 1 : b(o, t).diff(b(e, t), r);
148
+ }[n];
149
+ return ["day", "hour"].includes(n) ? h(r, e).diff(h(t, e), n) + 1 : h(r, e).diff(h(t, e), n);
150
150
  }
151
- function q(e, o, r) {
152
- const t = {
151
+ function $(t, r, n) {
152
+ if (!n)
153
+ throw new Error("日期类型不能为空");
154
+ const e = {
153
155
  year: "YYYY",
154
156
  month: "YYYY-MM",
155
157
  day: "YYYY-MM-DD",
156
158
  hour: "HH:mm:ss"
157
- }[r];
158
- return b(e).subtract(o, r).format(t);
159
+ }[n];
160
+ return h(t).subtract(r, n).format(e);
159
161
  }
160
- function N(e, o, r, t) {
161
- const l = {
162
- year: "YYYY",
163
- month: "YYYY-MM",
164
- day: "YYYY-MM-DD",
165
- hour: "YYYY-MM-DD HH:mm:ss"
166
- }[o];
167
- return b(e, l).add(r * t, o).format(l);
162
+ function N(t, r, n, e) {
163
+ const c = "YYYY-MM-DD HH:mm:ss", o = U(t, r, n, e), i = h(o);
164
+ if (r === "month") {
165
+ const s = i.month();
166
+ return s === 0 ? [i.startOf("month").format(c), i.date(25).endOf("day").format(c)] : s === 11 ? [i.subtract(1, "month").date(26).startOf("day").format(c), i.endOf("month").format(c)] : [i.subtract(1, "month").date(26).startOf("day").format(c), i.date(25).endOf("day").format(c)];
167
+ }
168
+ const x = { year: "year", day: "day", hour: "hour" };
169
+ return [i.startOf(x[r]).format(c), i.endOf(x[r]).format(c)];
168
170
  }
169
- function I(e, o, r, t) {
170
- const l = {
171
+ function U(t, r, n, e) {
172
+ const c = {
171
173
  year: "YYYY",
172
174
  month: "YYYY-MM",
173
175
  day: "YYYY-MM-DD",
174
176
  hour: "YYYY-MM-DD HH:mm:ss"
175
- }[o];
176
- return b(e, l).subtract(r * t, o).format(l);
177
+ }[r];
178
+ return h(t, c).add(n * e, r).format(c);
177
179
  }
178
- function D(e, o, r) {
179
- return e[o] || (e[o] = {}), e[o][r] || (e[o][r] = {}), e[o][r];
180
+ function M(t, r, n) {
181
+ return t[r] || (t[r] = {}), t[r][n] || (t[r][n] = {}), t[r][n];
180
182
  }
181
- async function se(e) {
182
- if (!e)
183
+ async function lt(t) {
184
+ if (!t)
183
185
  throw new Error("cellData is required");
184
- const o = Object.entries(e).reduce((r, t) => {
185
- const [l, a] = t;
186
- for (const [d, T] of Object.entries(a)) {
187
- const { custom: i, v: x, t: f, s: h } = T;
188
- if (!i) continue;
189
- const { cellType: Y } = i;
190
- if (Y === "indicator") {
191
- const O = D(r, l, d);
192
- O.custom = {
193
- ...i,
194
- required: R(i?.required) ? !1 : i?.required,
195
- defaultShift: R(i?.defaultShift) ? !1 : i?.defaultShift,
196
- forwardPush: R(i?.forwardPush) ? !1 : i?.forwardPush
197
- }, O.s = h, O.t = f, O.v = x;
186
+ const r = Object.entries(t).reduce((n, e) => {
187
+ const [c, o] = e;
188
+ for (const [i, x] of Object.entries(o)) {
189
+ const { custom: s, v: w, t: l, s: H } = x;
190
+ if (!s) continue;
191
+ const { cellType: d } = s;
192
+ if (d === "indicator") {
193
+ const P = M(n, c, i);
194
+ P.custom = {
195
+ ...s,
196
+ required: G(s?.required) ? !1 : s?.required,
197
+ defaultShift: G(s?.defaultShift) ? !1 : s?.defaultShift,
198
+ forwardPush: G(s?.forwardPush) ? !1 : s?.forwardPush,
199
+ forwardPushTimes: G(s?.useDefaultEndDate) ? 0 : s?.forwardPushTimes,
200
+ useDefaultEndDate: G(s?.useDefaultEndDate) ? !1 : s?.useDefaultEndDate
201
+ }, P.s = H, P.t = l, P.v = w;
198
202
  }
199
203
  }
200
- return r;
204
+ return n;
201
205
  }, {});
202
- return !o || R(o) ? Promise.reject(new Error("No data found")) : Promise.resolve(o);
206
+ return !r || G(r) ? Promise.reject(new Error("No data found")) : Promise.resolve(r);
207
+ }
208
+ function E(t, r) {
209
+ return t.replace(/\$\{([^}]+)\}/g, (n, e) => {
210
+ try {
211
+ const c = Object.keys(r), o = Object.values(r);
212
+ return new Function(...c, `return ${e};`)(...o);
213
+ } catch (c) {
214
+ return console.error(`表达式执行失败: ${e}`, c), n;
215
+ }
216
+ });
203
217
  }
204
- function X({
205
- acc: e,
206
- params: o,
207
- initRowNum: r,
208
- initColNum: t,
209
- cellData: l
218
+ function st({
219
+ acc: t,
220
+ params: r,
221
+ initRowNum: n,
222
+ initColNum: e,
223
+ cellData: c
210
224
  }) {
211
- const { rangeData: a, currentDay: d, extraArgs: T } = o;
212
- T?.teamData;
213
- const { cycleType: i, timeIncrement: x, forwardPush: f, copyType: h, copyInterval: Y, defaultShift: O } = l.custom;
214
- let y = 0;
215
- switch (i) {
225
+ const { rangeData: o, currentDay: i, extraArgs: x } = r;
226
+ x?.teamData;
227
+ const { cycleType: s, timeIncrement: w, forwardPush: l, forwardPushTimes: H, copyType: d, copyInterval: P, defaultShift: V, templateStr: T, useDefaultEndDate: k } = c.custom;
228
+ let g = 0;
229
+ switch (s) {
216
230
  case "day": {
217
- let n = "";
218
- if (f && (n = q(
219
- a[0],
220
- 6,
231
+ let a = "";
232
+ if (l && (a = $(
233
+ o[0],
234
+ H,
221
235
  "day"
222
236
  /* day */
223
- )), !h) {
224
- let m = "";
225
- f ? m = n : m = a[0];
226
- const c = D(e, r, t);
227
- c.v = m, c.t = j.STRING;
237
+ )), !d) {
238
+ let u = "";
239
+ l ? u = a : u = o[0];
240
+ const y = M(t, n, e);
241
+ y.v = T ? E(T, { businessDate: u, dayjs: h }) : h(u).format("YYYY-MM-DD"), y.t = C.STRING;
228
242
  break;
229
243
  }
230
- f ? y = H(
231
- n,
232
- a[0],
244
+ l ? g = S(
245
+ a,
246
+ o[0],
233
247
  "day"
234
248
  /* day */
235
- ) : y = H(
236
- a[0],
237
- a[1],
249
+ ) : g = S(
250
+ o[0],
251
+ o[1],
238
252
  "day"
239
253
  /* day */
240
254
  );
241
- for (let m = 0; m <= Math.abs(y === 0 ? 1 : y); m++) {
242
- const c = m * (Y + 1);
243
- let w = "";
244
- f ? w = N(n, "day", m, x) : w = N(a[0], "day", m, x);
245
- const g = h === "right" ? r : r + c, p = h === "right" ? t + c : t, M = D(e, g, p);
246
- M.v = w, M.t = j.STRING;
255
+ for (let u = 0; u <= Math.abs(g === 0 ? 1 : g); u++) {
256
+ const y = u * (P + 1);
257
+ let p = "";
258
+ l ? p = U(a, "day", u, w) : p = U(o[0], "day", u, w);
259
+ const Y = d === "right" ? n : n + y, D = d === "right" ? e + y : e, f = M(t, Y, D);
260
+ f.v = T ? E(T, { businessDate: p, dayjs: h }) : h(p).format("YYYY-MM-DD"), f.t = C.STRING;
247
261
  }
248
262
  break;
249
263
  }
250
264
  case "month": {
251
- if (!h) {
252
- const n = D(e, r, t);
253
- n.v = a[0], n.t = j.STRING;
265
+ if (!d) {
266
+ const [a, u] = N(o[1], "month", 0, 1), y = M(t, n, e);
267
+ y.v = h(u).format("YYYY-MM"), y.t = C.STRING;
254
268
  break;
255
269
  }
256
- y = H(
257
- a[0],
258
- a[1],
270
+ g = S(
271
+ o[0],
272
+ o[1],
259
273
  "month"
260
274
  /* month */
261
275
  );
262
- for (let n = 0; n <= Math.abs(y === 0 ? 1 : y); n++) {
263
- const m = n * (Y + 1), c = h === "right" ? r : r + m, w = h === "right" ? t + m : t, g = D(e, c, w);
264
- g.v = N(a[0], "month", n, x), g.t = j.STRING;
276
+ for (let a = 0; a <= Math.abs(g === 0 ? 1 : g); a++) {
277
+ const u = a * (P + 1), y = d === "right" ? n : n + u, p = d === "right" ? e + u : e, Y = M(t, y, p);
278
+ Y.v = U(o[0], "month", a, w), Y.t = C.STRING;
265
279
  }
266
280
  break;
267
281
  }
268
282
  case "year": {
269
- if (!h) {
270
- const n = D(e, r, t);
271
- n.v = a[0], n.t = j.STRING;
283
+ let a = "";
284
+ if (l && (a = $(
285
+ o[0],
286
+ H || 0,
287
+ "year"
288
+ /* year */
289
+ )), !d) {
290
+ const u = l ? a : o[0], [y, p] = N(u, "year", 0, 1), Y = M(t, n, e), [, D] = N(o[1], "month", 0, 1);
291
+ Y.v = T ? E(T, {
292
+ startTime: y,
293
+ endTime: p,
294
+ rangeData: o,
295
+ dayjs: h
296
+ }) : u, Y.t = C.STRING;
272
297
  break;
273
298
  }
274
- y = H(
275
- a[0],
276
- a[1],
299
+ l ? g = S(
300
+ a,
301
+ o[0],
302
+ "year"
303
+ /* year */
304
+ ) : g = S(
305
+ o[0],
306
+ o[1],
277
307
  "year"
278
308
  /* year */
279
309
  );
280
- for (let n = 0; n <= Math.abs(y === 0 ? 1 : y); n++) {
281
- const m = n * (Y + 1), c = h === "right" ? r : r + m, w = h === "right" ? t + m : t, g = D(e, c, w);
282
- g.v = N(a[0], "year", n, x), g.t = j.STRING;
310
+ for (let u = 0; u <= Math.abs(g === 0 ? 1 : g); u++) {
311
+ const y = u * (P + 1), p = d === "right" ? n : n + y, Y = d === "right" ? e + y : e, [D, f] = N(o[0], "year", u, w), m = M(t, p, Y), b = U(o[0], "year", u, w);
312
+ m.v = T ? E(T, {
313
+ startTime: D,
314
+ endTime: f,
315
+ rangeData: o,
316
+ dayjs: h
317
+ }) : b, m.t = C.STRING;
283
318
  }
284
319
  break;
285
320
  }
286
321
  case "hour": {
287
- if (!h) {
288
- const n = D(e, r, t);
289
- if (n.t = j.STRING, O) {
290
- n.v = b(a[0]).add(1, "hour").format("YYYY-MM-DD HH:mm:ss");
322
+ if (!d) {
323
+ const a = M(t, n, e);
324
+ if (a.t = C.STRING, V) {
325
+ a.v = h(o[0]).add(1, "hour").format("YYYY-MM-DD HH:mm:ss");
291
326
  break;
292
327
  }
293
- n.v = b(d).add(1, "hour").format("YYYY-MM-DD HH:mm:ss");
328
+ a.v = h(i).add(1, "hour").format("YYYY-MM-DD HH:mm:ss");
294
329
  break;
295
330
  }
296
- y = H(
297
- a[0],
298
- a[1],
331
+ g = S(
332
+ o[0],
333
+ o[1],
299
334
  "hour"
300
335
  /* hour */
301
336
  );
302
- for (let n = 0; n < Math.abs(y === 0 ? 1 : y); n++) {
303
- const m = n * (Y + 1), c = h === "right" ? r : r + m, w = h === "right" ? t + m : t, g = D(e, c, w);
304
- if (g.t = j.STRING, O) {
305
- const p = b(a[0]).add(1, "hour").format("YYYY-MM-DD HH:mm:ss");
306
- g.v = N(p, "hour", n, x);
337
+ for (let a = 0; a < Math.abs(g === 0 ? 1 : g); a++) {
338
+ const u = a * (P + 1), y = d === "right" ? n : n + u, p = d === "right" ? e + u : e, Y = M(t, y, p);
339
+ if (Y.t = C.STRING, V) {
340
+ const D = h(o[0]).add(1, "hour").format("YYYY-MM-DD HH:mm:ss");
341
+ Y.v = U(D, "hour", a, w);
307
342
  continue;
308
343
  }
309
- g.v = N(b(d).add(1, "hour").format("YYYY-MM-DD HH:mm:ss"), "hour", n, x);
344
+ Y.v = U(h(i).add(1, "hour").format("YYYY-MM-DD HH:mm:ss"), "hour", a, w);
310
345
  }
311
346
  }
312
347
  }
313
348
  }
314
- async function ae(e, o) {
315
- if (!e)
349
+ async function dt(t, r) {
350
+ if (!t)
316
351
  return Promise.reject("没有可用的单元格数据");
317
- const { extraArgs: r, rangeData: t } = o;
318
- if (!t.length)
352
+ const { extraArgs: n, rangeData: e } = r;
353
+ if (!e.length)
319
354
  return Promise.reject("处理时间范围失败, rangeData不能为空");
320
- r?.teamData;
321
- const l = o?.currentDay || b().format("YYYY-MM-DD"), a = Object.entries(e).reduce((d, T) => {
322
- const [i, x] = T;
323
- for (const [f, h] of Object.entries(x)) {
324
- const { custom: Y } = h;
325
- if (!Y) continue;
326
- const { cellType: O, cycleType: y, timeIncrement: n, forwardPush: m, copyType: c, copyInterval: w, defaultShift: g } = Y;
327
- if (O === "time") {
328
- X({ acc: d, params: o, initRowNum: Number(i), initColNum: Number(f), cellData: h });
355
+ n?.teamData;
356
+ const c = r?.currentDay || h().format("YYYY-MM-DD"), o = Object.entries(t).reduce((i, x) => {
357
+ const [s, w] = x;
358
+ for (const [l, H] of Object.entries(w)) {
359
+ const { custom: d } = H;
360
+ if (!d) continue;
361
+ const { cellType: P, cycleType: V, timeIncrement: T, forwardPush: k, forwardPushTimes: g, copyType: a, copyInterval: u, defaultShift: y, useDefaultEndDate: p } = d;
362
+ if (P === "time") {
363
+ st({ acc: i, params: r, initRowNum: Number(s), initColNum: Number(l), cellData: H });
329
364
  continue;
330
365
  }
331
- const p = {
332
- cycleType: y,
333
- indicatorName: Y.indicatorName,
334
- indicatorCode: Y.indicatorCode,
335
- indicatorId: Y.indicatorId,
336
- indicatorDimensionName: Y.indicatorDimensionName,
337
- indicatorDimensionConfig: Y.indicatorDimensionConfig,
338
- required: _(Y?.required) ?? !1,
339
- cellType: Y.cellType,
340
- defaultShift: Y?.defaultShift || !1
366
+ const Y = {
367
+ cycleType: V,
368
+ indicatorName: d.indicatorName,
369
+ indicatorCode: d.indicatorCode,
370
+ indicatorId: d.indicatorId,
371
+ indicatorDimensionName: d.indicatorDimensionName,
372
+ indicatorDimensionConfig: d.indicatorDimensionConfig,
373
+ required: tt(d?.required) ?? !1,
374
+ cellType: d.cellType,
375
+ defaultShift: d?.defaultShift || !1
341
376
  };
342
- let M = 0;
343
- switch (y) {
377
+ let D = 0;
378
+ switch (V) {
344
379
  case "day": {
345
- let s = "";
346
- if (m && (s = q(
347
- t[0],
348
- 6,
380
+ let f = "";
381
+ if (k && (f = $(
382
+ e[0],
383
+ g || 0,
349
384
  "day"
350
385
  /* day */
351
- )), !c) {
352
- let u = "";
353
- m ? u = s : u = t[0];
354
- const v = D(d, i, f);
355
- v.custom = {
356
- ...p,
357
- businessDate: u,
358
- startTime: "",
359
- endTime: ""
360
- }, g && (v.custom.startTime = t[0], v.custom.endTime = t[1]);
386
+ )), !a) {
387
+ const m = k ? f : e[0], [b, v] = N(m, "day", 0, 1), O = M(i, s, l);
388
+ O.custom = {
389
+ ...Y,
390
+ startTime: b,
391
+ endTime: v
392
+ };
361
393
  break;
362
394
  }
363
- m ? M = H(
364
- s,
365
- t[0],
395
+ k ? D = S(
396
+ f,
397
+ e[0],
366
398
  "day"
367
399
  /* day */
368
- ) : M = H(
369
- t[0],
370
- t[1],
400
+ ) : D = S(
401
+ e[0],
402
+ e[1],
371
403
  "day"
372
404
  /* day */
373
405
  );
374
- for (let u = 0; u < Math.abs(M === 0 ? 1 : M); u++) {
375
- const v = u * (w + 1);
376
- let S = "";
377
- m ? S = N(s, "day", u, n) : S = N(t[0], "day", u, n);
378
- const C = c === "right" ? i : k(i).add(v).toNumber(), U = c === "right" ? k(f).add(v).toNumber() : f, P = D(d, C, U);
379
- P.custom = {
380
- ...p,
381
- businessDate: S,
382
- startTime: "",
383
- endTime: ""
384
- }, g && (P.custom.startTime = I(S, "day", u, n), P.custom.endTime = S);
406
+ for (let m = 0; m < Math.abs(D === 0 ? 1 : D); m++) {
407
+ const b = m * (u + 1), v = k ? f : e[0], [O, j] = N(v, "day", m, T), R = a === "right" ? s : I(s).add(b).toNumber(), A = a === "right" ? I(l).add(b).toNumber() : l, F = M(i, R, A);
408
+ F.custom = {
409
+ ...Y,
410
+ startTime: O,
411
+ endTime: j
412
+ };
385
413
  }
386
414
  break;
387
415
  }
388
416
  case "month": {
389
- if (!c) {
390
- const s = D(d, i, f);
391
- s.custom = {
392
- ...p,
393
- businessDate: t[0],
394
- startTime: "",
395
- endTime: ""
417
+ if (!a) {
418
+ const [f, m] = N(e[1], "month", 0, 1), b = M(i, s, l);
419
+ b.custom = {
420
+ ...Y,
421
+ startTime: f,
422
+ endTime: m
396
423
  };
397
424
  break;
398
425
  }
399
- M = H(
400
- t[0],
401
- t[1],
426
+ D = S(
427
+ e[0],
428
+ e[1],
402
429
  "month"
403
430
  /* month */
404
431
  );
405
- for (let s = 0; s <= Math.abs(M === 0 ? 1 : M); s++) {
406
- const u = s * (w + 1), v = c === "right" ? i : k(i).add(u).toNumber(), S = c === "right" ? k(f).add(u).toNumber() : f, C = D(d, v, S);
407
- C.custom = {
408
- ...p,
409
- startTime: "",
410
- endTime: "",
411
- businessDate: N(t[0], "month", s, n)
432
+ for (let f = 0; f <= Math.abs(D === 0 ? 1 : D); f++) {
433
+ const m = f * (u + 1), b = a === "right" ? s : I(s).add(m).toNumber(), v = a === "right" ? I(l).add(m).toNumber() : l, [O, j] = N(e[0], "month", f, T), R = M(i, b, v);
434
+ R.custom = {
435
+ ...Y,
436
+ startTime: O,
437
+ endTime: j
412
438
  };
413
439
  }
414
440
  break;
415
441
  }
416
442
  case "year": {
417
- if (!c) {
418
- const s = D(d, i, f);
419
- s.custom = {
420
- ...p,
421
- businessDate: t[0],
422
- startTime: "",
423
- endTime: ""
443
+ let f = "";
444
+ if (k && (f = $(
445
+ e[0],
446
+ g || 0,
447
+ "year"
448
+ /* year */
449
+ )), !a) {
450
+ const m = k ? f : e[0], [b, v] = N(m, "year", 0, 1), O = M(i, s, l), [, j] = N(e[1], "month", 0, 1);
451
+ O.custom = {
452
+ ...Y,
453
+ startTime: b,
454
+ endTime: p ? j : v
424
455
  };
425
456
  break;
426
457
  }
427
- M = H(
428
- t[0],
429
- t[1],
458
+ k ? D = S(
459
+ f,
460
+ e[0],
461
+ "year"
462
+ /* year */
463
+ ) : D = S(
464
+ e[0],
465
+ e[1],
430
466
  "year"
431
467
  /* year */
432
468
  );
433
- for (let s = 0; s < Math.abs(M === 0 ? 1 : M); s++) {
434
- const u = s * (w + 1), v = c === "right" ? i : k(i).add(u).toNumber(), S = c === "right" ? k(f).add(u).toNumber() : f, C = D(d, v, S);
435
- C.custom = {
436
- ...p,
437
- startTime: "",
438
- endTime: "",
439
- businessDate: N(t[0], "year", s, n)
469
+ for (let m = 0; m < Math.abs(D === 0 ? 1 : D); m++) {
470
+ const b = m * (u + 1), v = a === "right" ? s : I(s).add(b).toNumber(), O = a === "right" ? I(l).add(b).toNumber() : l, [j, R] = N(e[0], "year", m, T), A = M(i, v, O);
471
+ A.custom = {
472
+ ...Y,
473
+ startTime: j,
474
+ endTime: R
440
475
  };
441
476
  }
442
477
  break;
443
478
  }
444
479
  case "hour": {
445
- if (!c) {
446
- let s = "";
447
- const u = D(d, i, f);
448
- if (g) {
449
- s = N(t[0], "hour", 1, 1), u.custom = {
450
- ...p,
451
- businessDate: s,
452
- startTime: I(s, "hour", 1, 1),
453
- endTime: s
454
- };
455
- break;
456
- }
457
- s = N(t[0] ?? l, "hour", 1, 1), u.custom = {
458
- ...p,
459
- businessDate: s,
460
- startTime: I(s, "hour", 1, 1),
461
- endTime: s
462
- // businessDate: dayjs(currentDay).add(1, 'hour').format('YYYY-MM-DD HH:mm:ss')
480
+ if (!a) {
481
+ const f = y ? e[0] : e[0] ?? c, [m, b] = N(f, "hour", 1, 1), v = M(i, s, l);
482
+ v.custom = {
483
+ ...Y,
484
+ startTime: m,
485
+ endTime: b
463
486
  };
464
487
  break;
465
488
  }
466
- M = H(
467
- t[0],
468
- t[1],
489
+ D = S(
490
+ e[0],
491
+ e[1],
469
492
  "hour"
470
493
  /* hour */
471
494
  );
472
- for (let s = 0; s < Math.abs(M === 0 ? 1 : M); s++) {
473
- let u = "";
474
- const v = s * (w + 1), S = c === "right" ? i : k(i).add(v).toNumber(), C = c === "right" ? k(f).add(v).toNumber() : f, U = D(d, S, C);
475
- if (g) {
476
- const P = b(t[0]).add(1, "hour").format("YYYY-MM-DD HH:mm:ss");
477
- u = N(P, "hour", s, n), U.custom = {
478
- ...p,
479
- businessDate: u,
480
- startTime: I(u, "hour", s, n),
481
- endTime: u
482
- // businessDate: generateTime(laterOneHour, dateTypeEnum.hour, i, timeIncrement)
495
+ for (let f = 0; f < Math.abs(D === 0 ? 1 : D); f++) {
496
+ const m = f * (u + 1), b = a === "right" ? s : I(s).add(m).toNumber(), v = a === "right" ? I(l).add(m).toNumber() : l, O = M(i, b, v);
497
+ if (y) {
498
+ const F = h(e[0]).add(1, "hour").format("YYYY-MM-DD HH:mm:ss"), [z, Z] = N(F, "hour", f, T);
499
+ O.custom = {
500
+ ...Y,
501
+ startTime: z,
502
+ endTime: Z
483
503
  };
484
504
  continue;
485
505
  }
486
- u = N(
487
- b(l).add(1, "hour").format("YYYY-MM-DD HH:mm:ss"),
488
- "hour",
489
- s,
490
- n
491
- ), U.custom = {
492
- ...p,
493
- startTime: I(u, "hour", s, n),
494
- endTime: u
495
- // businessDate: generateTime(
496
- // dayjs(currentDay).add(1, 'hour').format('YYYY-MM-DD HH:mm:ss'),
497
- // dateTypeEnum.hour,
498
- // i,
499
- // timeIncrement
500
- // )
506
+ const j = h(c).add(1, "hour").format("YYYY-MM-DD HH:mm:ss"), [R, A] = N(j, "hour", f, T);
507
+ O.custom = {
508
+ ...Y,
509
+ startTime: R,
510
+ endTime: A
501
511
  };
502
512
  }
503
513
  break;
504
514
  }
505
515
  }
506
516
  }
507
- return d;
517
+ return i;
508
518
  }, {});
509
- return Promise.resolve(a);
519
+ return Promise.resolve(o);
510
520
  }
511
- function ie(e) {
512
- return Object.entries(e).reduce((r, [t, l]) => {
513
- const a = Math.max(...Object.keys(l).map(Number));
514
- return a > r ? r = Number(a) : r = Number(r) || 0, r;
521
+ function ht(t) {
522
+ return Object.entries(t).reduce((n, [e, c]) => {
523
+ const o = Math.max(...Object.keys(c).map(Number));
524
+ return o > n ? n = Number(o) : n = Number(n) || 0, n;
515
525
  }, 0);
516
526
  }
517
- function ue(e, o) {
518
- const r = JSON.parse(JSON.stringify(e || {}));
519
- for (const [t, l] of Object.entries(o)) {
520
- r[t] || (r[t] = {});
521
- for (const [a, d] of Object.entries(l)) {
522
- const T = d, i = r[t]?.[a];
523
- i ? r[t][a] = {
524
- ...i,
525
- ...T,
527
+ function Yt(t, r) {
528
+ const n = JSON.parse(JSON.stringify(t || {}));
529
+ for (const [e, c] of Object.entries(r)) {
530
+ n[e] || (n[e] = {});
531
+ for (const [o, i] of Object.entries(c)) {
532
+ const x = i, s = n[e]?.[o];
533
+ s ? n[e][o] = {
534
+ ...s,
535
+ ...x,
526
536
  custom: {
527
- ...i.custom,
528
- ...T.custom || {}
537
+ ...s.custom,
538
+ ...x.custom || {}
529
539
  }
530
- } : r[t][a] = T;
540
+ } : n[e][o] = x;
531
541
  }
532
542
  }
533
- return r;
543
+ return n;
534
544
  }
535
- const ce = "./style.css";
545
+ const Dt = "./style.css";
536
546
  export {
537
- Q as CycleTypeEnum,
538
- W as ModeEnum,
539
- k as decimal,
540
- se as filterIndicatorsCell,
541
- ae as generateIndicatorsCells,
542
- F as generateUUID,
543
- ie as getNumColumns,
544
- re as handleClearInput,
545
- ne as initDateRange,
546
- ue as mergeCellData,
547
- ce as stylePath,
548
- oe as useData
547
+ nt as CycleTypeEnum,
548
+ ot as ModeEnum,
549
+ I as decimal,
550
+ lt as filterIndicatorsCell,
551
+ dt as generateIndicatorsCells,
552
+ _ as generateUUID,
553
+ ht as getNumColumns,
554
+ ct as handleClearInput,
555
+ mt as initDateRange,
556
+ Yt as mergeCellData,
557
+ Dt as stylePath,
558
+ ft as useData
549
559
  };
@@ -1 +1 @@
1
- (function(Y,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("dayjs"),require("@univerjs/presets"),require("decimal.js")):typeof define=="function"&&define.amd?define(["exports","dayjs","@univerjs/presets","decimal.js"],m):(Y=typeof globalThis<"u"?globalThis:Y||self,m(Y.TorUniverSheet={},Y.dayjs,Y.presets,Y.Decimal))})(this,(function(Y,m,I,G){"use strict";const B=(e,n)=>{for(const r of n)e[r]=null},A=()=>{if(typeof crypto=="object"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"&&typeof Uint8Array=="function"){const r=t=>{const d=Number(t);return(d^crypto.getRandomValues(new Uint8Array(1))[0]&15>>d/4).toString(16)};return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,r)}}let e=new Date().getTime(),n=typeof performance<"u"&&performance.now&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,r=>{let t=Math.random()*16;return e>0?(t=(e+t)%16|0,e=Math.floor(e/16)):(t=(n+t)%16|0,n=Math.floor(n/16)),(r==="x"?t:t&3|8).toString(16)})};function Z(e){return{...e?.workbookData,id:e?.id||A(),name:e?.name||"未命名",appVersion:e?.appVersion||"1.0.0"}}const _=Object.prototype.toString,F=(e,n)=>_.call(e)===`[object ${n}]`,E=e=>typeof e<"u",K=e=>!E(e),L=e=>e!==null&&F(e,"Object"),U=e=>e==null||typeof e>"u"?!0:R(e)||X(e)?e.length===0:e instanceof Map||e instanceof Set?e.size===0:L(e)?Object.keys(e).length===0:!1,Q=e=>e===null,W=e=>K(e)||Q(e),X=e=>F(e,"String"),R=e=>e&&Array.isArray(e);class ee{value;constructor(n){this.value=new G(n)}add(n){return this.value=this.value.add(n||0),this}subtract(n){return this.value=this.value.sub(n||0),this}multiply(n){return this.value=this.value.mul(n||0),this}divide(n){const r=new G(n);if(r.isZero())throw new Error("除数是0");return this.value=this.value.div(r),this}toFixed(n,r){return this.value=new G(this.value.toFixed(n,r)),this}valueOf(){return this.value}toString(){return this.value.toString()}toNumber(){return this.value.toNumber()}}function O(e=0){return new ee(e)}var $=(e=>(e.无="no",e.年="year",e.月="month",e.周="week",e.天="day",e.班组="shift",e.小时="hour",e.半小时="half_hour",e))($||{}),J=(e=>(e.view="view",e.edit="edit",e))(J||{});async function te(e,n){if(!n)return Promise.reject("日期不能为空");switch(e){case"year":if(R(n))return Promise.resolve(n);const r=m(n);if(!r.isValid())return Promise.reject("无效的日期格式");const t=r.year(),d=`${t}-01`,i=`${t}-12`;return Promise.resolve([d,i]);case"month":if(R(n))return Promise.resolve(n);const h=m(n);if(!h.isValid())return Promise.reject("无效的日期格式");const p=h.startOf("month").format("YYYY-MM-DD"),a=h.endOf("month").format("YYYY-MM-DD");return Promise.resolve([p,a]);case"day":if(R(n))return Promise.resolve(n);const v=m(n);if(!v.isValid())return Promise.reject("无效的日期格式");const f=v.startOf("day").format("YYYY-MM-DD HH:mm:ss"),D=v.endOf("day").format("YYYY-MM-DD HH:mm:ss");return Promise.resolve([f,D]);default:return Promise.reject("不支持的周期类型")}}function H(e,n,r){if(!r)return 0;const t={year:"YYYY",month:"YYYY-MM",day:"YYYY-MM-DD",hour:"HH:mm:ss"}[r];return["day","hour"].includes(r)?m(n,t).diff(m(e,t),r)+1:m(n,t).diff(m(e,t),r)}function z(e,n,r){const t={year:"YYYY",month:"YYYY-MM",day:"YYYY-MM-DD",hour:"HH:mm:ss"}[r];return m(e).subtract(n,r).format(t)}function w(e,n,r,t){const d={year:"YYYY",month:"YYYY-MM",day:"YYYY-MM-DD",hour:"YYYY-MM-DD HH:mm:ss"}[n];return m(e,d).add(r*t,n).format(d)}function j(e,n,r,t){const d={year:"YYYY",month:"YYYY-MM",day:"YYYY-MM-DD",hour:"YYYY-MM-DD HH:mm:ss"}[n];return m(e,d).subtract(r*t,n).format(d)}function b(e,n,r){return e[n]||(e[n]={}),e[n][r]||(e[n][r]={}),e[n][r]}async function re(e){if(!e)throw new Error("cellData is required");const n=Object.entries(e).reduce((r,t)=>{const[d,i]=t;for(const[h,p]of Object.entries(i)){const{custom:a,v,t:f,s:D}=p;if(!a)continue;const{cellType:g}=a;if(g==="indicator"){const P=b(r,d,h);P.custom={...a,required:U(a?.required)?!1:a?.required,defaultShift:U(a?.defaultShift)?!1:a?.defaultShift,forwardPush:U(a?.forwardPush)?!1:a?.forwardPush},P.s=D,P.t=f,P.v=v}}return r},{});return!n||U(n)?Promise.reject(new Error("No data found")):Promise.resolve(n)}function ne({acc:e,params:n,initRowNum:r,initColNum:t,cellData:d}){const{rangeData:i,currentDay:h,extraArgs:p}=n;p?.teamData;const{cycleType:a,timeIncrement:v,forwardPush:f,copyType:D,copyInterval:g,defaultShift:P}=d.custom;let y=0;switch(a){case"day":{let o="";if(f&&(o=z(i[0],6,"day")),!D){let c="";f?c=o:c=i[0];const l=b(e,r,t);l.v=c,l.t=I.CellValueType.STRING;break}f?y=H(o,i[0],"day"):y=H(i[0],i[1],"day");for(let c=0;c<=Math.abs(y===0?1:y);c++){const l=c*(g+1);let x="";f?x=w(o,"day",c,v):x=w(i[0],"day",c,v);const M=D==="right"?r:r+l,N=D==="right"?t+l:t,T=b(e,M,N);T.v=x,T.t=I.CellValueType.STRING}break}case"month":{if(!D){const o=b(e,r,t);o.v=i[0],o.t=I.CellValueType.STRING;break}y=H(i[0],i[1],"month");for(let o=0;o<=Math.abs(y===0?1:y);o++){const c=o*(g+1),l=D==="right"?r:r+c,x=D==="right"?t+c:t,M=b(e,l,x);M.v=w(i[0],"month",o,v),M.t=I.CellValueType.STRING}break}case"year":{if(!D){const o=b(e,r,t);o.v=i[0],o.t=I.CellValueType.STRING;break}y=H(i[0],i[1],"year");for(let o=0;o<=Math.abs(y===0?1:y);o++){const c=o*(g+1),l=D==="right"?r:r+c,x=D==="right"?t+c:t,M=b(e,l,x);M.v=w(i[0],"year",o,v),M.t=I.CellValueType.STRING}break}case"hour":{if(!D){const o=b(e,r,t);if(o.t=I.CellValueType.STRING,P){o.v=m(i[0]).add(1,"hour").format("YYYY-MM-DD HH:mm:ss");break}o.v=m(h).add(1,"hour").format("YYYY-MM-DD HH:mm:ss");break}y=H(i[0],i[1],"hour");for(let o=0;o<Math.abs(y===0?1:y);o++){const c=o*(g+1),l=D==="right"?r:r+c,x=D==="right"?t+c:t,M=b(e,l,x);if(M.t=I.CellValueType.STRING,P){const N=m(i[0]).add(1,"hour").format("YYYY-MM-DD HH:mm:ss");M.v=w(N,"hour",o,v);continue}M.v=w(m(h).add(1,"hour").format("YYYY-MM-DD HH:mm:ss"),"hour",o,v)}}}}async function oe(e,n){if(!e)return Promise.reject("没有可用的单元格数据");const{extraArgs:r,rangeData:t}=n;if(!t.length)return Promise.reject("处理时间范围失败, rangeData不能为空");r?.teamData;const d=n?.currentDay||m().format("YYYY-MM-DD"),i=Object.entries(e).reduce((h,p)=>{const[a,v]=p;for(const[f,D]of Object.entries(v)){const{custom:g}=D;if(!g)continue;const{cellType:P,cycleType:y,timeIncrement:o,forwardPush:c,copyType:l,copyInterval:x,defaultShift:M}=g;if(P==="time"){ne({acc:h,params:n,initRowNum:Number(a),initColNum:Number(f),cellData:D});continue}const N={cycleType:y,indicatorName:g.indicatorName,indicatorCode:g.indicatorCode,indicatorId:g.indicatorId,indicatorDimensionName:g.indicatorDimensionName,indicatorDimensionConfig:g.indicatorDimensionConfig,required:W(g?.required)??!1,cellType:g.cellType,defaultShift:g?.defaultShift||!1};let T=0;switch(y){case"day":{let s="";if(c&&(s=z(t[0],6,"day")),!l){let u="";c?u=s:u=t[0];const C=b(h,a,f);C.custom={...N,businessDate:u,startTime:"",endTime:""},M&&(C.custom.startTime=t[0],C.custom.endTime=t[1]);break}c?T=H(s,t[0],"day"):T=H(t[0],t[1],"day");for(let u=0;u<Math.abs(T===0?1:T);u++){const C=u*(x+1);let S="";c?S=w(s,"day",u,o):S=w(t[0],"day",u,o);const k=l==="right"?a:O(a).add(C).toNumber(),q=l==="right"?O(f).add(C).toNumber():f,V=b(h,k,q);V.custom={...N,businessDate:S,startTime:"",endTime:""},M&&(V.custom.startTime=j(S,"day",u,o),V.custom.endTime=S)}break}case"month":{if(!l){const s=b(h,a,f);s.custom={...N,businessDate:t[0],startTime:"",endTime:""};break}T=H(t[0],t[1],"month");for(let s=0;s<=Math.abs(T===0?1:T);s++){const u=s*(x+1),C=l==="right"?a:O(a).add(u).toNumber(),S=l==="right"?O(f).add(u).toNumber():f,k=b(h,C,S);k.custom={...N,startTime:"",endTime:"",businessDate:w(t[0],"month",s,o)}}break}case"year":{if(!l){const s=b(h,a,f);s.custom={...N,businessDate:t[0],startTime:"",endTime:""};break}T=H(t[0],t[1],"year");for(let s=0;s<Math.abs(T===0?1:T);s++){const u=s*(x+1),C=l==="right"?a:O(a).add(u).toNumber(),S=l==="right"?O(f).add(u).toNumber():f,k=b(h,C,S);k.custom={...N,startTime:"",endTime:"",businessDate:w(t[0],"year",s,o)}}break}case"hour":{if(!l){let s="";const u=b(h,a,f);if(M){s=w(t[0],"hour",1,1),u.custom={...N,businessDate:s,startTime:j(s,"hour",1,1),endTime:s};break}s=w(t[0]??d,"hour",1,1),u.custom={...N,businessDate:s,startTime:j(s,"hour",1,1),endTime:s};break}T=H(t[0],t[1],"hour");for(let s=0;s<Math.abs(T===0?1:T);s++){let u="";const C=s*(x+1),S=l==="right"?a:O(a).add(C).toNumber(),k=l==="right"?O(f).add(C).toNumber():f,q=b(h,S,k);if(M){const V=m(t[0]).add(1,"hour").format("YYYY-MM-DD HH:mm:ss");u=w(V,"hour",s,o),q.custom={...N,businessDate:u,startTime:j(u,"hour",s,o),endTime:u};continue}u=w(m(d).add(1,"hour").format("YYYY-MM-DD HH:mm:ss"),"hour",s,o),q.custom={...N,startTime:j(u,"hour",s,o),endTime:u}}break}}}return h},{});return Promise.resolve(i)}function se(e){return Object.entries(e).reduce((r,[t,d])=>{const i=Math.max(...Object.keys(d).map(Number));return i>r?r=Number(i):r=Number(r)||0,r},0)}function ie(e,n){const r=JSON.parse(JSON.stringify(e||{}));for(const[t,d]of Object.entries(n)){r[t]||(r[t]={});for(const[i,h]of Object.entries(d)){const p=h,a=r[t]?.[i];a?r[t][i]={...a,...p,custom:{...a.custom,...p.custom||{}}}:r[t][i]=p}}return r}const ae="./style.css";Y.CycleTypeEnum=$,Y.ModeEnum=J,Y.decimal=O,Y.filterIndicatorsCell=re,Y.generateIndicatorsCells=oe,Y.generateUUID=A,Y.getNumColumns=se,Y.handleClearInput=B,Y.initDateRange=te,Y.mergeCellData=ie,Y.stylePath=ae,Y.useData=Z,Object.defineProperty(Y,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(y,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("dayjs"),require("@univerjs/presets"),require("decimal.js")):typeof define=="function"&&define.amd?define(["exports","dayjs","@univerjs/presets","decimal.js"],f):(y=typeof globalThis<"u"?globalThis:y||self,f(y.TorUniverSheet={},y.dayjs,y.presets,y.Decimal))})(this,(function(y,f,V,B){"use strict";const L=(e,r)=>{for(const n of r)e[n]=null},z=()=>{if(typeof crypto=="object"){if(typeof crypto.randomUUID=="function")return crypto.randomUUID();if(typeof crypto.getRandomValues=="function"&&typeof Uint8Array=="function"){const n=t=>{const c=Number(t);return(c^crypto.getRandomValues(new Uint8Array(1))[0]&15>>c/4).toString(16)};return"10000000-1000-4000-8000-100000000000".replace(/[018]/g,n)}}let e=new Date().getTime(),r=typeof performance<"u"&&performance.now&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,n=>{let t=Math.random()*16;return e>0?(t=(e+t)%16|0,e=Math.floor(e/16)):(t=(r+t)%16|0,r=Math.floor(r/16)),(n==="x"?t:t&3|8).toString(16)})};function Q(e){return{...e?.workbookData,id:e?.id||z(),name:e?.name||"未命名",appVersion:e?.appVersion||"1.0.0"}}const W=Object.prototype.toString,Z=(e,r)=>W.call(e)===`[object ${r}]`,X=e=>typeof e<"u",ee=e=>!X(e),te=e=>e!==null&&Z(e,"Object"),q=e=>e==null||typeof e>"u"?!0:A(e)||oe(e)?e.length===0:e instanceof Map||e instanceof Set?e.size===0:te(e)?Object.keys(e).length===0:!1,re=e=>e===null,ne=e=>ee(e)||re(e),oe=e=>Z(e,"String"),A=e=>e&&Array.isArray(e);class se{value;constructor(r){this.value=new B(r)}add(r){return this.value=this.value.add(r||0),this}subtract(r){return this.value=this.value.sub(r||0),this}multiply(r){return this.value=this.value.mul(r||0),this}divide(r){const n=new B(r);if(n.isZero())throw new Error("除数是0");return this.value=this.value.div(n),this}toFixed(r,n){return this.value=new B(this.value.toFixed(r,n)),this}valueOf(){return this.value}toString(){return this.value.toString()}toNumber(){return this.value.toNumber()}}function H(e=0){return new se(e)}var _=(e=>(e.无="no",e.年="year",e.月="month",e.周="week",e.天="day",e.班组="shift",e.小时="hour",e.半小时="half_hour",e))(_||{}),K=(e=>(e.view="view",e.edit="edit",e))(K||{});async function ae(e,r){if(!r)return Promise.reject("日期不能为空");switch(e){case"year":if(A(r))return Promise.resolve(r);const n=f(r);if(!n.isValid())return Promise.reject("无效的日期格式");const t=n.year(),c=`${t}-01`,o=`${t}-12`;return Promise.resolve([c,o]);case"month":if(A(r))return Promise.resolve(r);const i=f(r);if(!i.isValid())return Promise.reject("无效的日期格式");const N=i.startOf("month").format("YYYY-MM-DD"),s=i.endOf("month").format("YYYY-MM-DD");return Promise.resolve([N,s]);case"day":if(A(r))return Promise.resolve(r);const w=f(r);if(!w.isValid())return Promise.reject("无效的日期格式");const d=w.startOf("day").format("YYYY-MM-DD HH:mm:ss"),k=w.endOf("day").format("YYYY-MM-DD HH:mm:ss");return Promise.resolve([d,k]);default:return Promise.reject("不支持的周期类型")}}function O(e,r,n){if(!n)return 0;const t={year:"YYYY",month:"YYYY-MM",day:"YYYY-MM-DD",hour:"HH:mm:ss"}[n];return["day","hour"].includes(n)?f(r,t).diff(f(e,t),n)+1:f(r,t).diff(f(e,t),n)}function $(e,r,n){if(!n)throw new Error("日期类型不能为空");const t={year:"YYYY",month:"YYYY-MM",day:"YYYY-MM-DD",hour:"HH:mm:ss"}[n];return f(e).subtract(r,n).format(t)}function v(e,r,n,t){const c="YYYY-MM-DD HH:mm:ss",o=R(e,r,n,t),i=f(o);if(r==="month"){const s=i.month();return s===0?[i.startOf("month").format(c),i.date(25).endOf("day").format(c)]:s===11?[i.subtract(1,"month").date(26).startOf("day").format(c),i.endOf("month").format(c)]:[i.subtract(1,"month").date(26).startOf("day").format(c),i.date(25).endOf("day").format(c)]}const N={year:"year",day:"day",hour:"hour"};return[i.startOf(N[r]).format(c),i.endOf(N[r]).format(c)]}function R(e,r,n,t){const c={year:"YYYY",month:"YYYY-MM",day:"YYYY-MM-DD",hour:"YYYY-MM-DD HH:mm:ss"}[r];return f(e,c).add(n*t,r).format(c)}function M(e,r,n){return e[r]||(e[r]={}),e[r][n]||(e[r][n]={}),e[r][n]}async function ie(e){if(!e)throw new Error("cellData is required");const r=Object.entries(e).reduce((n,t)=>{const[c,o]=t;for(const[i,N]of Object.entries(o)){const{custom:s,v:w,t:d,s:k}=N;if(!s)continue;const{cellType:h}=s;if(h==="indicator"){const P=M(n,c,i);P.custom={...s,required:q(s?.required)?!1:s?.required,defaultShift:q(s?.defaultShift)?!1:s?.defaultShift,forwardPush:q(s?.forwardPush)?!1:s?.forwardPush,forwardPushTimes:q(s?.useDefaultEndDate)?0:s?.forwardPushTimes,useDefaultEndDate:q(s?.useDefaultEndDate)?!1:s?.useDefaultEndDate},P.s=k,P.t=d,P.v=w}}return n},{});return!r||q(r)?Promise.reject(new Error("No data found")):Promise.resolve(r)}function F(e,r){return e.replace(/\$\{([^}]+)\}/g,(n,t)=>{try{const c=Object.keys(r),o=Object.values(r);return new Function(...c,`return ${t};`)(...o)}catch(c){return console.error(`表达式执行失败: ${t}`,c),n}})}function ue({acc:e,params:r,initRowNum:n,initColNum:t,cellData:c}){const{rangeData:o,currentDay:i,extraArgs:N}=r;N?.teamData;const{cycleType:s,timeIncrement:w,forwardPush:d,forwardPushTimes:k,copyType:h,copyInterval:P,defaultShift:E,templateStr:C,useDefaultEndDate:U}=c.custom;let T=0;switch(s){case"day":{let a="";if(d&&(a=$(o[0],k,"day")),!h){let u="";d?u=a:u=o[0];const b=M(e,n,t);b.v=C?F(C,{businessDate:u,dayjs:f}):f(u).format("YYYY-MM-DD"),b.t=V.CellValueType.STRING;break}d?T=O(a,o[0],"day"):T=O(o[0],o[1],"day");for(let u=0;u<=Math.abs(T===0?1:T);u++){const b=u*(P+1);let p="";d?p=R(a,"day",u,w):p=R(o[0],"day",u,w);const Y=h==="right"?n:n+b,D=h==="right"?t+b:t,l=M(e,Y,D);l.v=C?F(C,{businessDate:p,dayjs:f}):f(p).format("YYYY-MM-DD"),l.t=V.CellValueType.STRING}break}case"month":{if(!h){const[a,u]=v(o[1],"month",0,1),b=M(e,n,t);b.v=f(u).format("YYYY-MM"),b.t=V.CellValueType.STRING;break}T=O(o[0],o[1],"month");for(let a=0;a<=Math.abs(T===0?1:T);a++){const u=a*(P+1),b=h==="right"?n:n+u,p=h==="right"?t+u:t,Y=M(e,b,p);Y.v=R(o[0],"month",a,w),Y.t=V.CellValueType.STRING}break}case"year":{let a="";if(d&&(a=$(o[0],k||0,"year")),!h){const u=d?a:o[0],[b,p]=v(u,"year",0,1),Y=M(e,n,t),[,D]=v(o[1],"month",0,1);Y.v=C?F(C,{startTime:b,endTime:p,rangeData:o,dayjs:f}):u,Y.t=V.CellValueType.STRING;break}d?T=O(a,o[0],"year"):T=O(o[0],o[1],"year");for(let u=0;u<=Math.abs(T===0?1:T);u++){const b=u*(P+1),p=h==="right"?n:n+b,Y=h==="right"?t+b:t,[D,l]=v(o[0],"year",u,w),m=M(e,p,Y),g=R(o[0],"year",u,w);m.v=C?F(C,{startTime:D,endTime:l,rangeData:o,dayjs:f}):g,m.t=V.CellValueType.STRING}break}case"hour":{if(!h){const a=M(e,n,t);if(a.t=V.CellValueType.STRING,E){a.v=f(o[0]).add(1,"hour").format("YYYY-MM-DD HH:mm:ss");break}a.v=f(i).add(1,"hour").format("YYYY-MM-DD HH:mm:ss");break}T=O(o[0],o[1],"hour");for(let a=0;a<Math.abs(T===0?1:T);a++){const u=a*(P+1),b=h==="right"?n:n+u,p=h==="right"?t+u:t,Y=M(e,b,p);if(Y.t=V.CellValueType.STRING,E){const D=f(o[0]).add(1,"hour").format("YYYY-MM-DD HH:mm:ss");Y.v=R(D,"hour",a,w);continue}Y.v=R(f(i).add(1,"hour").format("YYYY-MM-DD HH:mm:ss"),"hour",a,w)}}}}async function ce(e,r){if(!e)return Promise.reject("没有可用的单元格数据");const{extraArgs:n,rangeData:t}=r;if(!t.length)return Promise.reject("处理时间范围失败, rangeData不能为空");n?.teamData;const c=r?.currentDay||f().format("YYYY-MM-DD"),o=Object.entries(e).reduce((i,N)=>{const[s,w]=N;for(const[d,k]of Object.entries(w)){const{custom:h}=k;if(!h)continue;const{cellType:P,cycleType:E,timeIncrement:C,forwardPush:U,forwardPushTimes:T,copyType:a,copyInterval:u,defaultShift:b,useDefaultEndDate:p}=h;if(P==="time"){ue({acc:i,params:r,initRowNum:Number(s),initColNum:Number(d),cellData:k});continue}const Y={cycleType:E,indicatorName:h.indicatorName,indicatorCode:h.indicatorCode,indicatorId:h.indicatorId,indicatorDimensionName:h.indicatorDimensionName,indicatorDimensionConfig:h.indicatorDimensionConfig,required:ne(h?.required)??!1,cellType:h.cellType,defaultShift:h?.defaultShift||!1};let D=0;switch(E){case"day":{let l="";if(U&&(l=$(t[0],T||0,"day")),!a){const m=U?l:t[0],[g,x]=v(m,"day",0,1),S=M(i,s,d);S.custom={...Y,startTime:g,endTime:x};break}U?D=O(l,t[0],"day"):D=O(t[0],t[1],"day");for(let m=0;m<Math.abs(D===0?1:D);m++){const g=m*(u+1),x=U?l:t[0],[S,I]=v(x,"day",m,C),j=a==="right"?s:H(s).add(g).toNumber(),G=a==="right"?H(d).add(g).toNumber():d,J=M(i,j,G);J.custom={...Y,startTime:S,endTime:I}}break}case"month":{if(!a){const[l,m]=v(t[1],"month",0,1),g=M(i,s,d);g.custom={...Y,startTime:l,endTime:m};break}D=O(t[0],t[1],"month");for(let l=0;l<=Math.abs(D===0?1:D);l++){const m=l*(u+1),g=a==="right"?s:H(s).add(m).toNumber(),x=a==="right"?H(d).add(m).toNumber():d,[S,I]=v(t[0],"month",l,C),j=M(i,g,x);j.custom={...Y,startTime:S,endTime:I}}break}case"year":{let l="";if(U&&(l=$(t[0],T||0,"year")),!a){const m=U?l:t[0],[g,x]=v(m,"year",0,1),S=M(i,s,d),[,I]=v(t[1],"month",0,1);S.custom={...Y,startTime:g,endTime:p?I:x};break}U?D=O(l,t[0],"year"):D=O(t[0],t[1],"year");for(let m=0;m<Math.abs(D===0?1:D);m++){const g=m*(u+1),x=a==="right"?s:H(s).add(g).toNumber(),S=a==="right"?H(d).add(g).toNumber():d,[I,j]=v(t[0],"year",m,C),G=M(i,x,S);G.custom={...Y,startTime:I,endTime:j}}break}case"hour":{if(!a){const l=b?t[0]:t[0]??c,[m,g]=v(l,"hour",1,1),x=M(i,s,d);x.custom={...Y,startTime:m,endTime:g};break}D=O(t[0],t[1],"hour");for(let l=0;l<Math.abs(D===0?1:D);l++){const m=l*(u+1),g=a==="right"?s:H(s).add(m).toNumber(),x=a==="right"?H(d).add(m).toNumber():d,S=M(i,g,x);if(b){const J=f(t[0]).add(1,"hour").format("YYYY-MM-DD HH:mm:ss"),[de,he]=v(J,"hour",l,C);S.custom={...Y,startTime:de,endTime:he};continue}const I=f(c).add(1,"hour").format("YYYY-MM-DD HH:mm:ss"),[j,G]=v(I,"hour",l,C);S.custom={...Y,startTime:j,endTime:G}}break}}}return i},{});return Promise.resolve(o)}function fe(e){return Object.entries(e).reduce((n,[t,c])=>{const o=Math.max(...Object.keys(c).map(Number));return o>n?n=Number(o):n=Number(n)||0,n},0)}function le(e,r){const n=JSON.parse(JSON.stringify(e||{}));for(const[t,c]of Object.entries(r)){n[t]||(n[t]={});for(const[o,i]of Object.entries(c)){const N=i,s=n[t]?.[o];s?n[t][o]={...s,...N,custom:{...s.custom,...N.custom||{}}}:n[t][o]=N}}return n}const me="./style.css";y.CycleTypeEnum=_,y.ModeEnum=K,y.decimal=H,y.filterIndicatorsCell=ie,y.generateIndicatorsCells=ce,y.generateUUID=z,y.getNumColumns=fe,y.handleClearInput=L,y.initDateRange=ae,y.mergeCellData=le,y.stylePath=me,y.useData=Q,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tor-univer-sheet",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "style": "./dist/style.css",
5
5
  "description": "基于 Univer 的 Vue3 电子表格组件",
6
6
  "author": "tortormore",