@vdhewei/xlsx-template-lib 1.2.3 → 1.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -2053,16 +2053,16 @@ var RuleMapOptions = class _RuleMapOptions {
2053
2053
  }
2054
2054
  parseDefault(worksheet) {
2055
2055
  this.ruleKeyMap = mergeOption(this.ruleKeyMap, defaultRuleTokenMap);
2056
- if (this.startLine === void 0) {
2056
+ if (this.startLine === void 0 || isNaN(this.startLine) || this.startLine < 0) {
2057
2057
  this.startLine = 1;
2058
2058
  }
2059
- if (this.endLine === void 0) {
2059
+ if (this.endLine === void 0 || isNaN(this.endLine) || this.endLine < 0) {
2060
2060
  this.endLine = worksheet.rowCount;
2061
2061
  }
2062
- if (this.startColumn === void 0) {
2062
+ if (this.startColumn === void 0 || isNaN(this.startColumn) || this.startColumn < 0) {
2063
2063
  this.startColumn = 1;
2064
2064
  }
2065
- if (this.endColumn === void 0) {
2065
+ if (this.endColumn === void 0 || isNaN(this.endColumn) || this.endColumn < 0) {
2066
2066
  this.endColumn = worksheet.columnCount;
2067
2067
  }
2068
2068
  return this;
@@ -3492,13 +3492,31 @@ var compileWorkSheetPlaceholder = function(ctx, sheet, result) {
3492
3492
  }
3493
3493
  return void 0;
3494
3494
  };
3495
+ var loadCompileSheets = (workbook, ruleSheetName) => {
3496
+ let first;
3497
+ let sheets = [];
3498
+ for (const [_, w] of workbook.worksheets.entries()) {
3499
+ if (w.name === ruleSheetName) {
3500
+ continue;
3501
+ }
3502
+ if (first === "") {
3503
+ first = w.name;
3504
+ }
3505
+ if (!w.name.endsWith(".json") && !w.name.endsWith(".config")) {
3506
+ sheets.push(w.name);
3507
+ }
3508
+ }
3509
+ if (sheets.length <= 0 && first !== "") {
3510
+ sheets.push(first);
3511
+ }
3512
+ return sheets;
3513
+ };
3495
3514
  var compile = async function(data, ruleSheetName, options) {
3496
3515
  const workbook = await loadWorkbook(data);
3497
3516
  const sheet = workbook.getWorksheet(ruleSheetName);
3498
3517
  if (sheet === void 0) {
3499
3518
  return {
3500
- workbook,
3501
- errs: [new Error(`compile error, ${ruleSheetName} not exists!`)]
3519
+ workbook
3502
3520
  };
3503
3521
  }
3504
3522
  if (workbook.worksheets === void 0) {
@@ -3511,6 +3529,10 @@ var compile = async function(data, ruleSheetName, options) {
3511
3529
  const excludes = [ruleSheetName];
3512
3530
  options = RuleMapOptions.withAllSheets(workbook, excludes);
3513
3531
  }
3532
+ options = options.parseDefault(sheet);
3533
+ if (options.compileSheets === void 0 || options.compileSheets.length === 0) {
3534
+ options.compileSheets = loadCompileSheets(workbook, ruleSheetName);
3535
+ }
3514
3536
  const result = parseWorkSheetRules(sheet, options);
3515
3537
  const errs = compileCheck(result, options);
3516
3538
  if (errs !== void 0) {
@@ -3573,6 +3595,9 @@ var fetchAlias = (m) => {
3573
3595
  };
3574
3596
  var removeUnExportSheets = (w, options) => {
3575
3597
  const removes = [];
3598
+ if (typeof options.skipRemoveUnExportSheet === "boolean" && options.skipRemoveUnExportSheet === true) {
3599
+ return w;
3600
+ }
3576
3601
  if (options.compileSheets === void 0 || options.compileSheets.length <= 0) {
3577
3602
  for (const [i, v] of w.worksheets.entries()) {
3578
3603
  const sheetName = v.name;
@@ -3615,6 +3640,7 @@ ExprResolver.resolveCompileMacroGen = resolveCompileMacroGen;
3615
3640
  ExprResolver.resolveCompileMacroExpr = resolveCompileMacroExpr;
3616
3641
 
3617
3642
  // src/extends.ts
3643
+ import fs2 from "fs/promises";
3618
3644
  function hasToString(obj) {
3619
3645
  return obj != null && typeof obj.toString === "function";
3620
3646
  }
@@ -3884,6 +3910,12 @@ var autoRegisterAlias = function(values, configure) {
3884
3910
  values[aliasKey] = alias;
3885
3911
  return values;
3886
3912
  };
3913
+ var saveCompile = async (compileOptions, wb) => {
3914
+ if (typeof compileOptions.save === "boolean" && compileOptions.save === true && typeof compileOptions.saveFile === "string" && compileOptions.saveFile !== "") {
3915
+ const path2 = compileOptions.saveFile;
3916
+ await fs2.writeFile(`${path2}compile_${(/* @__PURE__ */ new Date()).valueOf()}.xlsx`, wb);
3917
+ }
3918
+ };
3887
3919
  var generateCommandsXlsxTemplateWithCompile = async function(data, values, compileOptions, options) {
3888
3920
  if (compileOptions.sheetName === void 0 || compileOptions.sheetName === "") {
3889
3921
  compileOptions.sheetName = compileRuleSheetName;
@@ -3895,6 +3927,7 @@ var generateCommandsXlsxTemplateWithCompile = async function(data, values, compi
3895
3927
  values = autoRegisterAlias(values, result.configure);
3896
3928
  result.workbook = ExprResolver.removeUnExportSheets(result.workbook, compileOptions);
3897
3929
  const wb = await ExprResolver.toBuffer(result.workbook);
3930
+ await saveCompile(compileOptions, wb);
3898
3931
  const w = await Workbook.parse(wb, options);
3899
3932
  w.setQueryFunctionHandler(commandExtendQuery);
3900
3933
  await w.substituteAll(values);
@@ -3933,6 +3966,7 @@ export {
3933
3966
  hasGeneratorToken,
3934
3967
  isRuleToken,
3935
3968
  isUrl,
3969
+ loadCompileSheets,
3936
3970
  loadWorkbook,
3937
3971
  mergeMap,
3938
3972
  parseWorkSheetRules,