| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 | 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 167× 167× 1× 56× 56× 56× 270× 56× 56× 56× 112× 56× 56× 10× 10× 10× 13× 13× 10× 10× 10× 46× 46× 46× 46× 46× 56× 56× 1× 24× 24× 15× 1× 7× 1× 1× 1× 46× 46× 46× 96× 46× 46× 46× 46× 46× 2× 2× 2× 1× 2× 3× 2× 2× 2× 2× 2× 2× 3× 2× 2× 2× 2× 2× 2× 2× 5× 2× 2× 2× 1× 1× 2× 3× 2× 2× 2× 2× 2× 2× 2× 2× 2× 2× 2× 2× 3× 2× 2× 2× 2× 2× 2× 2× 5× 1× 9× 17× 17× 9× 17× 17× 9× 9× 9× 5× 10× 10× 10× 5× 5× 5× 5× 6× 3× 3× 3× 1× 9× 1× 17× 17× 17× 17× 17× 17× 17× 16× 16× 1× 6× 2× 4× 4× 4× 4× 4× 1× 10× 2× 8× 8× 8× 8× 8× 8× 8× 8× 8× 8× 8× 1× 10× 2× 8× 8× 8× 8× 8× 1× 7× 2× 5× 5× 5× 5× 5× 1× 5× 5× 5× 5× 5× 2× 2× 2× 1× 1× 5× 1× 5× 1× 5× 1× 5× 7× 1× 5× 5× 1× 5× 1× 4× 4× 4× 4× 4× 1× 5× 1× 4× 4× 4× 4× 4× 1× 5× 5× 5× 5× 2× 3× 3× 3× 3× 1× 4× 4× 4× 4× 1× 3× 3× 3× 3× 1× 5× 2× 3× 3× 3× 3× 3× 1× 4× 4× 4× 4× 4× 4× 1× 5× 1× 4× 4× 4× 4× 1× 6× 2× 4× 4× 4× 4× 1× 7× 1× 6× 6× 6× 2× 2× 4× 1× 3× 3× 3× 3× 3× 3× 3× 1× 7× 1× 6× 6× 6× 6× 6× 6× 3× 3× 3× 3× 3× 6× 6× 6× 6× 4× 6× 6× 6× 1× 6× 2× 4× 4× 4× 4× 4× 4× 4× 4× 1× 5× 1× 4× 4× 4× 4× 4× 4× 4× 4× 1× 1× 1× 1× 1× 1× 1× 1× 1× 6× 3× 3× 3× 3× 3× 3× 3× 1× 10× 2× 8× 1× 7× 7× 7× 7× 3× 3× 3× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 6× 6× 1× 5× 1× 6× 2× 4× 4× 4× 4× 4× 4× 1× 8× 8× 8× 1× 7× 7× 1× 4× 2× 2× 1× 3× 2× 2× 3× 3× 3× 3× 1× 1× 1× 1× 3× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 3× 1× 1× 1× 1× 3× 1× 1× 3× 1× 1× 1× 1× 1× 1× 3× 1× 8× 1× 1× 1× 7× 1× 8× 7× 1× 1× 1× 1× 1× 1× 1× 5× 5× 5× 1× 62× 62× 62× 3× 59× 1× 19× 19× 19× 4× 15× 1× 7× 1× 6× 1× 5× 11× 11× 11× 11× 11× 5× 5× 5× 1× 68× 68× 68× 1× 2× 1× 1× 1× 1× | /* istanbul ignore next */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; /* istanbul ignore next */ var __generator = (this && this.__generator) || function (thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } }; define(["require", "exports", "../common/index", "../common/index", "../common/index", "../../workbook/common/event", "../../workbook/common/event", "../../workbook/index", "../../workbook/common/index", "../../workbook/common/index", "@syncfusion/ej2-base"], function (require, exports, index_1, index_2, index_3, event_1, event_2, index_4, index_5, index_6, ej2_base_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var CommandExecutor = (function () { function CommandExecutor(parent) { this.batchableActions = new Set(['edit', 'cellFormat', 'numberFormat']); this.parent = parent; } CommandExecutor.prototype.executeHandler = function (commands) { return __awaiter(this, void 0, void 0, function () { var results, i, command, batchAction, batch, result, _a, _b; return __generator(this, function (_c) { switch (_c.label) { case 0: results = []; i = 0; _c.label = 1; case 1: if (!(i < commands.length)) return [3, 5]; command = commands[i]; if (!this.batchableActions.has(command.action)) return [3, 2]; batchAction = command.action; batch = []; while (i < commands.length && commands[i].action === batchAction) { batch.push(commands[i]); i++; } result = batch.length > 1 ? this.executeBatch(batchAction, batch) : this.executeSingleBatchable(batchAction, batch[0].args); results.push(result); return [3, 4]; case 2: _b = (_a = results).push; return [4, this.executeSingle(command)]; case 3: _b.apply(_a, [_c.sent()]); i++; _c.label = 4; case 4: return [3, 1]; case 5: return [2, results]; } }); }); }; CommandExecutor.prototype.executeSingleBatchable = function (action, args) { try { switch (action) { case 'edit': return this.wrapResult(action, this.executeEdit(args)); case 'cellFormat': return this.wrapResult(action, this.executeCellFormat(args)); case 'numberFormat': return this.wrapResult(action, this.executeNumberFormat(args)); default: return this.errorResult(action, 'UNSUPPORTED_BATCH_ACTION', action + " cannot be batched."); } } catch (e) { return this.errorResult(action, 'EXECUTION_ERROR', (e instanceof Error) ? e.message : String(e)); } }; CommandExecutor.prototype.executeSingle = function (command) { return __awaiter(this, void 0, void 0, function () { var action, _a, findResult, _b, _c, _d, _e, e_1; return __generator(this, function (_f) { switch (_f.label) { case 0: action = command.action; _f.label = 1; case 1: _f.trys.push([1, 27, , 28]); _a = action; switch (_a) { case 'analysis': return [3, 2]; case 'reportGeneration': return [3, 3]; case 'findAndReplace': return [3, 4]; case 'find': return [3, 5]; case 'conditionalFormat': return [3, 6]; case 'merge': return [3, 7]; case 'cut': return [3, 8]; case 'copy': return [3, 10]; case 'paste': return [3, 12]; case 'wrap': return [3, 13]; case 'chart': return [3, 14]; case 'dataValidation': return [3, 15]; case 'filter': return [3, 16]; case 'sort': return [3, 17]; case 'insert': return [3, 18]; case 'delete': return [3, 19]; case 'autofill': return [3, 20]; case 'freezePanes': return [3, 21]; case 'hyperlink': return [3, 22]; case 'save': return [3, 23]; case 'insertSheet': return [3, 24]; } return [3, 25]; case 2: return [2, this.wrapResult(action, command.args && command.args.message ? command.args.message : '', { type: 'analysis' })]; case 3: return [2, this.wrapResult(action, command.args && command.args.reportStructure ? this.buildReportNarrative(command.args.reportStructure) : 'Report generation failed: no report structure returned.', { reportStructure: command.args && command.args.reportStructure })]; case 4: return [2, this.wrapResult(action, this.executeFindReplace(command.args))]; case 5: { findResult = this.executeFind(command.args); return [2, this.wrapResult(action, findResult.message, { addresses: findResult.addresses })]; } _f.label = 6; case 6: return [2, this.wrapResult(action, this.executeConditionalFormat(command.args))]; case 7: return [2, this.wrapResult(action, this.executeMerge(command.args))]; case 8: _b = this.wrapResult; _c = [action]; return [4, this.executeCut(command.args)]; case 9: return [2, _b.apply(this, _c.concat([_f.sent()]))]; case 10: _d = this.wrapResult; _e = [action]; return [4, this.executeCopy(command.args)]; case 11: return [2, _d.apply(this, _e.concat([_f.sent()]))]; case 12: return [2, this.wrapResult(action, this.executePaste(command.args))]; case 13: return [2, this.wrapResult(action, this.executeWrap(command.args))]; case 14: return [2, this.wrapResult(action, this.executeChart(command.args))]; case 15: return [2, this.wrapResult(action, this.executeDataValidation(command.args))]; case 16: return [2, this.wrapResult(action, this.executeFilter(command.args))]; case 17: return [2, this.wrapResult(action, this.executeSort(command.args))]; case 18: return [2, this.wrapResult(action, this.executeInsert(command.args))]; case 19: return [2, this.wrapResult(action, this.executeDelete(command.args))]; case 20: return [2, this.wrapResult(action, this.executeAutoFill(command.args))]; case 21: return [2, this.wrapResult(action, this.executeFreezePanes(command.args))]; case 22: return [2, this.wrapResult(action, this.executeHyperlink(command.args))]; case 23: return [2, this.wrapResult(action, this.executeSave(command.args))]; case 24: return [2, this.wrapResult(action, this.executeInsertSheet(command.args))]; case 25: return [2, this.wrapResult(action, command.message || 'I can analyze the sheet, update values, replace content, or apply number formats.', {}, false)]; case 26: return [3, 28]; case 27: e_1 = _f.sent(); return [2, this.errorResult(action, 'EXECUTION_ERROR', (e_1 instanceof Error) ? e_1.message : String(e_1))]; case 28: return [2]; } }); }); }; CommandExecutor.prototype.executeBatch = function (action, commands) { for (var _i = 0, commands_1 = commands; _i < commands_1.length; _i++) { var cmd = commands_1[_i]; this.executeSingleBatchable(action, cmd.args); } var ranges = commands .map(function (cmd) { return cmd.args && (cmd.args.range || cmd.args.address); }) .filter(function (r) { return !ej2_base_1.isNullOrUndefined(r) && r !== ''; }); var rangeText = ranges.length > 0 ? ranges.join(', ') : 'selected cells'; var message; switch (action) { case 'edit': { var addresses = commands .map(function (cmd) { return cmd.args && cmd.args.address; }) .filter(function (a) { return !ej2_base_1.isNullOrUndefined(a) && a !== ''; }); var uniqueValues = Array.from(new Set(commands.map(function (cmd) { return cmd.args && cmd.args.value; }))); var compactRange = addresses.length > 0 ? this.buildAddressRangeText(addresses) : 'selected cells'; var valueText = uniqueValues.length === 1 ? "" + uniqueValues[0] : commands.length + " different values"; message = "Updated cell range " + compactRange + " with " + valueText + "."; break; } case 'cellFormat': message = "Applied cell formatting across " + commands.length + " range(s): " + rangeText + "."; break; case 'numberFormat': { var formats = Array.from(new Set(commands.map(function (cmd) { return cmd.args && cmd.args.format; }).filter(Boolean))); var formatText = formats.length === 1 ? formats[0] : 'multiple formats'; message = "Applied " + formatText + " number format to " + commands.length + " range(s): " + rangeText + "."; break; } default: message = "Applied " + action + " to " + commands.length + " range(s): " + rangeText + "."; } return { action: action, success: true, message: message, data: { ranges: ranges } }; }; CommandExecutor.prototype.executeEdit = function (data) { var sheetName; var address = this.getTargetAddress(data && (data.address)); Iif (address.includes('!')) { var lastIndex = address.lastIndexOf('!'); sheetName = address.substring(0, lastIndex); if (index_4.getSheetIndex(this.parent, sheetName) !== undefined) { return "Sheet \"" + sheetName + "\" not found."; } address = address.substring(lastIndex + 1); } else { sheetName = this.parent.getActiveSheet().name; } var value = data.value; var eventArgs = { address: sheetName + "!" + address, value: value }; this.parent.notify(index_1.applyEditAction, eventArgs); Iif (eventArgs.cancel) { return 'Cannot edit read-only cell or edit was cancelled.'; } return "Updated " + address + " to " + value + "."; }; CommandExecutor.prototype.executeFindReplace = function (data) { if (ej2_base_1.isNullOrUndefined(data) || ej2_base_1.isNullOrUndefined(data.findValue) || ej2_base_1.isNullOrUndefined(data.replaceValue)) { return 'Please provide both the value to replace and the replacement value.'; } var findOptions = { value: (data.findValue).toString(), replaceValue: (data.replaceValue).toString(), mode: 'Sheet', sheetIndex: this.parent.activeSheetIndex, isCSen: data.caseSensitive === true, isEMatch: data.exactMatch === true, searchBy: 'By Row', isAction: true }; this.parent.notify(event_1.replaceAll, findOptions); var caseInfo = data.caseSensitive === true ? ' (case-sensitive)' : ''; var matchInfo = data.exactMatch === true ? ' with exact match' : ''; return "Replaced all occurrences of \"" + data.findValue + "\" with \"" + data.replaceValue + "\"" + caseInfo + matchInfo + "."; }; CommandExecutor.prototype.executeFind = function (data) { if (ej2_base_1.isNullOrUndefined(data) || ej2_base_1.isNullOrUndefined(data.findValue) || data.findValue === '') { return { message: 'Please provide a value to find.', addresses: [] }; } var sheetIndex = this.resolveSheetIndex(data.sheetName); var sheetName = this.parent.sheets[sheetIndex].name; var findCollection = []; var findArgs = { value: data.findValue.toString(), mode: 'Sheet', sheetIndex: sheetIndex, isCSen: data.caseSensitive === true, isEMatch: data.exactMatch === true, findCollection: findCollection }; this.parent.notify(event_2.findAllValues, findArgs); var addresses = this.filterAddressesByRange(findCollection, data.range); var caseInfo = data.caseSensitive === true ? ' (case-sensitive)' : ''; var matchInfo = data.exactMatch === true ? ' with exact match' : ''; var rangeInfo = !ej2_base_1.isNullOrUndefined(data.range) && data.range !== '' ? " in range " + data.range : ''; var message = addresses.length === 0 ? "No matches found for \"" + data.findValue + "\" in sheet \"" + sheetName + "\"" + rangeInfo + caseInfo + matchInfo + "." : "Found " + addresses.length + " match(es) for \"" + data.findValue + "\" in sheet \"" + sheetName + "\"" + rangeInfo + caseInfo + matchInfo + "."; return { message: message, addresses: addresses }; }; CommandExecutor.prototype.executeNumberFormat = function (data) { if (ej2_base_1.isNullOrUndefined(data) || ej2_base_1.isNullOrUndefined(data.format)) { return 'Please provide a number format pattern.'; } var range = this.getTargetRange(data.range); var applyArgs = { format: index_4.getFormatFromType(data.format), range: range }; this.parent.notify(index_3.applyNumberFormat, applyArgs); Iif (applyArgs.cancel) { return ''; } return "Applied number format " + data.format + " to " + range + "."; }; CommandExecutor.prototype.executeCellFormat = function (data) { if (ej2_base_1.isNullOrUndefined(data) || ej2_base_1.isNullOrUndefined(data.formatting) || Object.keys(data.formatting).length === 0) { return 'Please provide style properties to apply.'; } var range = this.getTargetRange(data.range); var sheetName = this.parent.getActiveSheet().name; var src = data.formatting; var style = {}; if (src.bold !== undefined) { style.fontWeight = src.bold === true ? 'bold' : 'normal'; } Iif (src.italic !== undefined) { style.fontStyle = src.italic === true ? 'italic' : 'normal'; } var hasUnderline = src.underline === true; var hasStrike = src.strikethrough === true; Iif (hasUnderline || hasStrike) { style.textDecoration = hasUnderline && hasStrike ? 'underline line-through' : (hasUnderline ? 'underline' : 'line-through'); } if (src.fontSize !== undefined) { var fs = src.fontSize; Iif (typeof fs === 'number') { style.fontSize = fs + "pt"; } else if (typeof fs === 'string' && /^\d+$/.test(fs)) { style.fontSize = fs + "pt"; } else { style.fontSize = fs; } } if (src.fontFamily) { style.fontFamily = src.fontFamily; } if (src.color) { style.color = src.color; } if (src.backgroundColor) { style.backgroundColor = src.backgroundColor; } Object.keys(src).forEach(function (k) { if (['bold', 'italic', 'underline', 'strikethrough', 'fontSize', 'fontFamily', 'color', 'backgroundColor'].indexOf(k) === -1) { style[k] = src[k]; } }); this.parent.notify(index_5.setCellFormat, { range: sheetName + '!' + range, style: style, onActionUpdate: true, refreshRibbon: true }); return "Applied cell style to " + range + "."; }; CommandExecutor.prototype.executeConditionalFormat = function (data) { if (ej2_base_1.isNullOrUndefined(data)) { return 'Please provide conditional format details.'; } var range = this.getTargetRange(data.range); var cfModel = { range: range, type: data.type, value: !ej2_base_1.isNullOrUndefined(data.value) ? String(data.value) : undefined, cFColor: data.cFColor, format: data.format }; var args = { cfModel: cfModel, isAction: true }; this.parent.notify(event_1.setCFRule, args); return "Applied conditional format (" + cfModel.type + ") to " + range + "."; }; CommandExecutor.prototype.executeMerge = function (data) { if (ej2_base_1.isNullOrUndefined(data)) { return 'Please provide merge range or address.'; } var range = this.getTargetRange(data.range); var mergeType = data.direction; var args = { range: range, type: mergeType, merge: true, isAction: true, refreshRibbon: true }; this.parent.notify(event_2.setMerge, args); return "Merged " + range + " as " + mergeType + "."; }; CommandExecutor.prototype.executeCut = function (data) { return __awaiter(this, void 0, void 0, function () { var rangeStr, indices; return __generator(this, function (_a) { if (ej2_base_1.isNullOrUndefined(data) || ej2_base_1.isNullOrUndefined(data.range)) { return [2, 'Please provide a range to cut.']; } rangeStr = this.getTargetRange(data.range); indices = index_5.getSwapRange(index_5.getRangeIndexes(rangeStr)); this.parent.notify(index_1.cut, { range: indices, sId: this.parent.getActiveSheet().id, invokeCopy: true }); return [2, "Cut " + rangeStr + ". Use paste to place it at the target location."]; }); }); }; CommandExecutor.prototype.executeCopy = function (data) { return __awaiter(this, void 0, void 0, function () { var rangeStr, indices; return __generator(this, function (_a) { if (ej2_base_1.isNullOrUndefined(data) || ej2_base_1.isNullOrUndefined(data.range)) { return [2, 'Please provide a range to copy.']; } rangeStr = this.getTargetRange(data.range); indices = index_5.getSwapRange(index_5.getRangeIndexes(rangeStr)); this.parent.notify(index_1.copy, { range: indices, sId: this.parent.getActiveSheet().id, invokeCopy: true }); return [2, "Copied " + rangeStr + "."]; }); }); }; CommandExecutor.prototype.executePaste = function (data) { if (ej2_base_1.isNullOrUndefined(data) || ej2_base_1.isNullOrUndefined(data.range)) { return 'Please provide a paste target address.'; } var rangeStr = this.getTargetRange(data.range); var indices = index_5.getSwapRange(index_5.getRangeIndexes(rangeStr)); var sheetIndex = this.parent.activeSheetIndex; this.parent.notify(index_1.paste, { range: indices, sIdx: sheetIndex, isAction: true, isInternal: true }); return "Pasted into " + rangeStr + "."; }; CommandExecutor.prototype.executeWrap = function (data) { var range = this.getTargetRange(data && data.range); var wrapFlag = data.wrap; var applyArgs = { address: this.parent.getActiveSheet().name + "!" + range, wrap: wrapFlag, range: range }; this.parent.notify(index_2.applyWrapText, applyArgs); Iif (applyArgs.cancel) { return applyArgs.cancel ? 'Cannot change wrap on read-only range or cancelled.' : ''; } return (wrapFlag ? 'Enabled' : 'Disabled') + " wrap for " + range + "."; }; CommandExecutor.prototype.executeChart = function (data) { if (ej2_base_1.isNullOrUndefined(data)) { return 'Please provide chart details such as type and range.'; } var range = this.getTargetRange(data.range); var chartModel = { type: data.chartType, range: this.parent.getActiveSheet().name + "!" + range, theme: data.theme || 'Material', title: data.title || '', isSeriesInRows: data.isSeriesInRows === true, height: data.height || 290, width: data.width || 480, markerSettings: { visible: false, isFilled: true } }; this.parent.notify(event_1.setChart, { chart: [chartModel] }); return "Inserted " + chartModel.type + " chart for range " + range + "."; }; CommandExecutor.prototype.executeDataValidation = function (data) { if (ej2_base_1.isNullOrUndefined(data) || ej2_base_1.isNullOrUndefined(data.dvType)) { return 'Please provide data validation details (type and range).'; } var range = this.getTargetRange(data.range); var fullRange = this.parent.getActiveSheet().name + '!' + range; this.parent.notify(index_2.applyDataValidation, { range: fullRange, value1: data.dvValue1, value2: data.dvValue2 || '', ignoreBlank: data.dvIgnoreBlank !== false, type: data.dvType, operator: data.dvOperator, inCellDropDown: data.dvInCellDropDown !== false, cancel: false }); return "Applied " + data.dvType + " validation (" + data.dvOperator + ") to " + range + "."; }; CommandExecutor.prototype.executeFilter = function (data) { if (ej2_base_1.isNullOrUndefined(data)) { return 'Please provide filter details such as column and value.'; } var range = this.getTargetRange(data.range); var sheetIndex = this.parent.activeSheetIndex; if (data.clearFilter === true) { this.parent.notify(index_3.initiateFilterUI, { range: range, sIdx: sheetIndex, predicates: [], isInternal: false }); return "Cleared filter on " + range + "."; } if (ej2_base_1.isNullOrUndefined(data.filterColumn) || data.filterColumn === '') { return 'Please provide a column to filter.'; } var colLetter = data.filterColumn.toUpperCase().replace(/[^A-Z]/g, ''); var colIndex = index_6.getIndexesFromAddress(colLetter + "1")[1]; var field = index_6.getColumnHeaderText(colIndex + 1); var operator = data.filterOperator; var predicates = [{ field: field, operator: operator, value: data.filterValue, matchCase: false, ignoreAccent: false, predicate: 'and', type: 'string' }]; this.parent.notify(index_3.initiateFilterUI, { predicates: predicates, range: range, sIdx: sheetIndex, isInternal: false }); return "Applied filter on column " + colLetter + ": " + operator + " \"" + data.filterValue + "\"."; }; CommandExecutor.prototype.executeSort = function (data) { if (ej2_base_1.isNullOrUndefined(data)) { return 'Please provide sort details.'; } var sheet = this.parent.getActiveSheet(); var hasRange = !ej2_base_1.isNullOrUndefined(data.range) && data.range !== '' && data.range.toLowerCase() !== 'selected'; var range = hasRange ? data.range : undefined; var effectiveRange = range || sheet.selectedRange; var field; if (!ej2_base_1.isNullOrUndefined(data.sortColumn) && data.sortColumn !== '') { var colLetter = data.sortColumn.toUpperCase().replace(/[^A-Z]/g, ''); var colIndex = index_6.getIndexesFromAddress(colLetter + "1")[1]; field = index_6.getColumnHeaderText(colIndex + 1); } else { var rangeIdx = index_5.getRangeIndexes(effectiveRange); field = index_6.getColumnHeaderText(rangeIdx[1] + 1); } var order = data.sortOrder; var containsHeader = data.sortContainsHeader !== false; var sortArgs = { sortOptions: { sortDescriptors: { field: field, order: order }, containsHeader: containsHeader } }; if (hasRange) { sortArgs.range = range; } this.parent.notify(index_3.applySort, sortArgs); var rangeInfo = hasRange ? " in range " + range : ' in the selected range'; return "Sorted by column " + field + rangeInfo + " in " + order + " order."; }; CommandExecutor.prototype.executeInsert = function (data) { if (ej2_base_1.isNullOrUndefined(data) || ej2_base_1.isNullOrUndefined(data.modelType)) { return 'Please provide modelType (Row or Column) and startIndex.'; } var type = data.modelType; Iif (!type) { return 'Invalid modelType. Please specify "Row" or "Column".'; } var startIdx = Math.max(0, data.startIndex - 1); var count = Math.max(1, data.count); var endIdx = !ej2_base_1.isNullOrUndefined(data.endIndex) ? Math.max(startIdx, data.endIndex - 1) : startIdx + count - 1; this.parent.notify(event_1.insertModel, { model: this.parent.getActiveSheet(), start: startIdx, end: endIdx, modelType: type, isAction: true, insertType: 'above' }); var insertedCount = (endIdx - startIdx) + 1; return "Inserted " + insertedCount + " " + type + "(s) at position " + data.startIndex + "."; }; CommandExecutor.prototype.executeDelete = function (data) { if (ej2_base_1.isNullOrUndefined(data) || ej2_base_1.isNullOrUndefined(data.modelType)) { return 'Please provide modelType (Row or Column) and startIndex.'; } var type = data.modelType; Iif (!type) { return 'Invalid modelType. Please specify "Row" or "Column".'; } var startIdx = Math.max(0, data.startIndex - 1); var count = Math.max(1, data.count); var endIdx = !ej2_base_1.isNullOrUndefined(data.endIndex) ? Math.max(startIdx, data.endIndex - 1) : startIdx + count - 1; this.parent.notify(event_1.deleteModel, { model: this.parent.getActiveSheet(), start: startIdx, end: endIdx, modelType: type, isAction: true }); var deletedCount = (endIdx - startIdx) + 1; return "Deleted " + deletedCount + " " + type + "(s) starting at position " + data.startIndex + "."; }; CommandExecutor.prototype.executeInsertSheet = function (data) { var count = (typeof data.count === 'number' && data.count > 0) ? data.count : 1; var startIndex = typeof data.startIndex === 'number' ? data.startIndex : this.parent.sheets.length; var sheets = []; for (var i = 0; i < count; i++) { sheets.push(count === 1 && data.sheetName ? { name: data.sheetName } : {}); } this.parent.insertSheet(sheets, undefined); return "Inserted " + count + " sheet(s) at position " + startIndex + "."; }; CommandExecutor.prototype.executeAutoFill = function (data) { if (ej2_base_1.isNullOrUndefined(data) || ej2_base_1.isNullOrUndefined(data.dataRange) || ej2_base_1.isNullOrUndefined(data.fillRange)) { return 'Please provide both dataRange (source) and fillRange (target) for autofill.'; } var dataRange = this.getTargetRange(data.dataRange); var fillRange = this.getTargetRange(data.fillRange); var fillRangeIndices = index_5.getRangeIndexes(fillRange); var rangeInfo = { startCell: { rowIndex: fillRangeIndices[0], colIndex: fillRangeIndices[1] }, endCell: { rowIndex: fillRangeIndices[2], colIndex: fillRangeIndices[3] }, fillRange: fillRangeIndices, direction: data.direction || undefined }; this.parent.notify(index_2.performAutoFill, { dAutoFillCell: dataRange, fillType: data.fillType, rangeInfo: rangeInfo }); return "AutoFilled " + fillRange + " from " + dataRange + ")."; }; CommandExecutor.prototype.executeFreezePanes = function (data) { if (ej2_base_1.isNullOrUndefined(data) || ej2_base_1.isNullOrUndefined(data.freezeType)) { return 'Please specify freezeType: "Rows", "Columns", "Panes", or "Unfreeze".'; } if (!this.parent.allowFreezePane) { return 'Freeze pane is not enabled. Set allowFreezePane to true.'; } var freezeType = data.freezeType.toLowerCase().trim(); var row = 0; var column = 0; switch (freezeType) { case 'rows': row = Math.max(1, data.row); column = 0; break; case 'columns': row = 0; column = Math.max(1, data.column); break; case 'panes': row = Math.max(1, data.row); column = Math.max(1, data.column); break; case 'unfreeze': row = 0; column = 0; break; default: return "Unknown freezeType \"" + data.freezeType + "\". Use \"Rows\", \"Columns\", \"Panes\", or \"Unfreeze\"."; } this.parent.notify(index_1.freeze, { row: row, column: column, triggerEvent: true }); if (freezeType === 'unfreeze') { return 'Removed all freeze panes from the active sheet.'; } return "Frozen " + (row > 0 ? row + " row(s)" : '') + (row > 0 && column > 0 ? ' and ' : '') + (column > 0 ? column + " column(s)" : '') + " on the active sheet."; }; CommandExecutor.prototype.executeHyperlink = function (data) { if (ej2_base_1.isNullOrUndefined(data) || ej2_base_1.isNullOrUndefined(data.address) || data.address === '') { return 'Please provide an address (URL or cell/sheet reference) for the hyperlink.'; } var range = this.getTargetRange(data.range); var sheetName = this.parent.getActiveSheet().name; var cellAddress = sheetName + "!" + range; var displayText = !ej2_base_1.isNullOrUndefined(data.displayText) && data.displayText !== '' ? data.displayText : null; this.parent.insertHyperlink(data.address, cellAddress, displayText, false); return "Inserted hyperlink to \"" + data.address + "\" in " + range + (displayText ? " with display text \"" + displayText + "\"" : '') + "."; }; CommandExecutor.prototype.executeSave = function (data) { var type = (data.saveType || 'xlsx').toLowerCase(); var validTypes = ['xlsx', 'xls', 'csv', 'pdf']; if (validTypes.indexOf(type) === -1) { return "Saving in '" + type + "' format is not supported. Valid save types are 'xlsx', 'xls', 'csv', and 'pdf'."; } this.parent.notify(event_1.exportDialog, { item: { id: this.parent.element.id + "_" + (type[0].toUpperCase() + type.substring(1)) } }); return 'Save dialog opened'; }; CommandExecutor.prototype.buildReportNarrative = function (report) { if (typeof report === 'string') { try { report = JSON.parse(report); } catch (_a) { return 'Report generation failed: invalid report structure format.'; } } var escapeCell = function (s) { Iif (s === null || s === undefined) { return ''; } return ("" + s).replace(/\|/g, '\\|').replace(/\r?\n/g, ' '); }; var narrative = '**Report Summary**\n\n'; Eif (report.summary) { narrative += report.summary + "\n\n"; } if (report.kpis && report.kpis.length > 0) { narrative += '**Key KPIs:**\n'; report.kpis.forEach(function (kpi) { narrative += "- " + kpi.name + ": " + kpi.value + (kpi.formula ? " (formula: " + kpi.formula + ")" : '') + '\n'; }); narrative += '\n'; } if (report.topRows && report.topRows.length > 0) { var rows = report.topRows.slice(0, 5); var firstValues = (rows[0] && rows[0].values); var headers_1 = Object.keys(firstValues); Eif (headers_1.length > 0) { narrative += '**Top Rows (sample):**\n\n'; narrative += "| " + headers_1.map(function (h) { return escapeCell(h); }).join(' | ') + " |\n"; narrative += "| " + headers_1.map(function () { return '---'; }).join(' | ') + " |\n"; rows.forEach(function (r) { var vals = headers_1.map(function (h) { return escapeCell((r.values && r.values[h] !== undefined) ? r.values[h] : ''); }); narrative += "| " + vals.join(' | ') + " |\n"; }); narrative += '\n'; } } if (report.visualSuggestions && report.visualSuggestions.length > 0) { narrative += '**Visual Suggestions:**\n'; report.visualSuggestions.forEach(function (v) { narrative += "- " + v.chartType + ": range " + v.range + (v.reason ? " \u2014 " + v.reason : '') + '\n'; }); narrative += '\n'; } if (report.sections && report.sections.length > 0) { report.sections.forEach(function (section) { narrative += "**" + section.heading + "**\n" + section.content + "\n\n"; }); } if (report.kpis && report.kpis.some(function (k) { return k.formula && k.formula.length > 0; })) { narrative += '**Suggested Formulas:**\n'; report.kpis.forEach(function (k) { Eif (k.formula) { narrative += "- " + k.name + ": " + k.formula + "\n"; } }); narrative += '\n'; } return narrative.trim(); }; CommandExecutor.prototype.resolveSheetIndex = function (sheetName) { if (!ej2_base_1.isNullOrUndefined(sheetName) && sheetName !== '') { var idx = this.parent.sheets.findIndex(function (s) { return s.name === sheetName; }); Eif (idx >= 0) { return idx; } } return this.parent.activeSheetIndex; }; CommandExecutor.prototype.filterAddressesByRange = function (addresses, range) { if (ej2_base_1.isNullOrUndefined(range) || range === '' || addresses.length === 0) { return addresses; } try { var _a = index_5.getRangeIndexes(range), r0 = _a[0], c0 = _a[1], r1 = _a[2], c1 = _a[3]; var minRow_1 = Math.min(r0, r1); var maxRow_1 = Math.max(r0, r1); var minCol_1 = Math.min(c0, c1); var maxCol_1 = Math.max(c0, c1); return addresses.filter(function (addr) { var cellPart = addr.indexOf('!') >= 0 ? addr.split('!')[1] : addr; var _a = index_5.getRangeIndexes(cellPart), rr = _a[0], cc = _a[1]; return rr >= minRow_1 && rr <= maxRow_1 && cc >= minCol_1 && cc <= maxCol_1; }); } catch (_b) { return addresses; } }; CommandExecutor.prototype.getTargetRange = function (address) { var sheet = this.parent.getActiveSheet(); var fallback = sheet.selectedRange; if (ej2_base_1.isNullOrUndefined(address) || address === '' || address.toLowerCase() === 'selected') { return fallback; } return address; }; CommandExecutor.prototype.getTargetAddress = function (address) { var sheet = this.parent.getActiveSheet(); var fallback = (sheet.selectedRange).split(':')[0]; if (ej2_base_1.isNullOrUndefined(address) || address === '' || address.toLowerCase() === 'selected') { return fallback; } return address.split(':')[0]; }; CommandExecutor.prototype.buildAddressRangeText = function (addresses) { if (addresses.length === 0) { return ''; } if (addresses.length === 1) { return addresses[0]; } try { var indices = addresses.map(function (a) { return index_5.getRangeIndexes(a); }); var minRow = Math.min.apply(Math, indices.map(function (idx) { return idx[0]; })); var minCol = Math.min.apply(Math, indices.map(function (idx) { return idx[1]; })); var maxRow = Math.max.apply(Math, indices.map(function (idx) { return idx[2] !== undefined ? idx[2] : idx[0]; })); var maxCol = Math.max.apply(Math, indices.map(function (idx) { return idx[3] !== undefined ? idx[3] : idx[1]; })); var startCell = "" + index_6.getColumnHeaderText(minCol + 1) + (minRow + 1); var endCell = "" + index_6.getColumnHeaderText(maxCol + 1) + (maxRow + 1); return startCell === endCell ? startCell : startCell + ":" + endCell; } catch (_a) { return addresses[0] + ":" + addresses[addresses.length - 1]; } }; CommandExecutor.prototype.wrapResult = function (action, message, data, success) { if (data === void 0) { data = {}; } if (success === void 0) { success = true; } return { action: action, success: success, message: message, data: data }; }; CommandExecutor.prototype.errorResult = function (action, code, message) { return { action: action, success: false, message: message, error: { code: code, message: message } }; }; CommandExecutor.prototype.getModuleName = function () { return 'CommandExecuter'; }; CommandExecutor.prototype.destroy = function () { this.parent = null; }; return CommandExecutor; }()); exports.CommandExecutor = CommandExecutor; }); |