tor-univer-sheet 1.1.6 → 1.1.7

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