@worktile/theia 15.1.8 → 15.1.11

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.
@@ -12370,10 +12370,6 @@ const getColumnsWidth = (cellRow, isColgroup = false) => {
12370
12370
  };
12371
12371
  /**
12372
12372
  * 计算表格列宽
12373
- * 1. 编辑模式下,返回原始列宽
12374
- * 2. 预览模式下,返回基于当前表格宽度计算的列宽
12375
- * a. 打印模式下,按照原宽度比例基于当前表格宽度计算列宽
12376
- * b. 非打印模式下计算
12377
12373
  * @param isReadonly
12378
12374
  * @param element
12379
12375
  * @param tableWidth
@@ -12383,31 +12379,12 @@ const getColumnsWidth = (cellRow, isColgroup = false) => {
12383
12379
  const calcColumnGroups = (isReadonly, element, tableWidth, mode) => {
12384
12380
  const columns = element?.columns;
12385
12381
  if (isReadonly) {
12386
- const isPrint = mode === TheMode.print;
12387
- const numberedColumnWidth = element.options?.numberedColumn ? TABLE_NUMBER_COLUMN : 0;
12388
12382
  if (columns) {
12389
12383
  const opts = new TableOptions();
12390
- const columnsWidth = columns.reduce((a, b) => a + b.width, 0);
12391
- const cellsWidthRatio = columns.map(column => {
12392
- return isPrint ? Math.floor((column.width / columnsWidth) * 100) / 100 : column.width / columnsWidth;
12393
- });
12394
- const newColumns = cellsWidthRatio.map(item => {
12395
- let cellWidth = opts.minWidthPx;
12396
- if (isPrint) {
12397
- // 按照 DPI 96 的 A4 纸宽度是 794, 打印时左右 80px 的边距,所以这里取 794 - 80 * 2 = 634
12398
- // 如果存在序号列,还需要在 634 基础上减去序号列的宽度,剩下的才是内容区域的宽度
12399
- // 为什么减 1, 因为这个宽度是内容区域宽度,但 td 右侧还有一个边框,所以减去 1
12400
- const newTableWidth = 634 - numberedColumnWidth;
12401
- cellWidth = parseInt(`${item * newTableWidth}`) - 1;
12402
- }
12403
- else {
12404
- // 总列宽大于当前表格宽度时,按照设置时的总列宽计算
12405
- const newTableWidth = tableWidth - numberedColumnWidth;
12406
- const columnTotalWidth = columnsWidth > tableWidth ? columnsWidth : newTableWidth;
12407
- cellWidth = item * columnTotalWidth;
12408
- }
12409
- return { width: cellWidth < opts.minWidthPx ? opts.minWidthPx : cellWidth };
12410
- });
12384
+ const isPrint = mode === TheMode.print;
12385
+ const newColumns = isPrint
12386
+ ? calcPrintColumnWidth(element, opts.minWidthPx)
12387
+ : calcColumnWidth(element, tableWidth, opts.minWidthPx);
12411
12388
  return newColumns;
12412
12389
  }
12413
12390
  return [];
@@ -12416,6 +12393,53 @@ const calcColumnGroups = (isReadonly, element, tableWidth, mode) => {
12416
12393
  return columns;
12417
12394
  }
12418
12395
  };
12396
+ /**
12397
+ * 计算表格列宽
12398
+ * @param element
12399
+ * @param tableWidth
12400
+ * @param minWidthPx
12401
+ * @returns number[]
12402
+ */
12403
+ const calcColumnWidth = (element, tableWidth, minWidthPx) => {
12404
+ const columns = element?.columns;
12405
+ const numberedColumnWidth = element.options?.numberedColumn ? TABLE_NUMBER_COLUMN : 0;
12406
+ const columnsWidth = columns.reduce((a, b) => a + b.width, 0);
12407
+ // 总列宽大于当前表格宽度时,按照设置时的总列宽计算
12408
+ const columnTotalWidth = Math.max(columnsWidth, tableWidth - numberedColumnWidth);
12409
+ return columns.map(column => {
12410
+ const cellWidth = (column.width / columnsWidth) * columnTotalWidth;
12411
+ return { width: Math.max(cellWidth, minWidthPx) };
12412
+ });
12413
+ };
12414
+ /**
12415
+ * 打印模式下,按照原宽度比例基于当前表格宽度计算列宽
12416
+ * 1. 所有列的最小列宽总和大于表格宽度时,所有列返回最小宽度
12417
+ * @param element
12418
+ * @param minWidthPx
12419
+ * @returns number[]
12420
+ */
12421
+ const calcPrintColumnWidth = (element, minWidthPx) => {
12422
+ const columns = element?.columns;
12423
+ const numberedColumnWidth = element.options?.numberedColumn ? TABLE_NUMBER_COLUMN : 0;
12424
+ // 按照 DPI 96 的 A4 纸宽度是 794, 打印时左右 80px 的边距,所以这里取 794 - 80 * 2 = 634
12425
+ // 如果存在序号列,还需要在 634 基础上减去序号列的宽度,剩下的才是内容区域的宽度
12426
+ let columnTotalWidth = 634 - numberedColumnWidth;
12427
+ const columnsWidth = columns.reduce((a, b) => a + b.width, 0);
12428
+ // 计算所有列的 minWidth 总和
12429
+ const totalMinWidth = minWidthPx * columns.length;
12430
+ if (totalMinWidth > columnTotalWidth) {
12431
+ // 如果所有列的 minWidth 总和大于 columnTotalWidth,所有列返回最小宽度
12432
+ return columns.map(() => ({ width: minWidthPx }));
12433
+ }
12434
+ // 在剩余的宽度中按比例分配
12435
+ const remainingWidth = columnTotalWidth - totalMinWidth;
12436
+ const remainingWidthRatio = columns.map(column => column.width / columnsWidth);
12437
+ // 为什么减 1, 因为这个宽度是内容区域宽度,但 td 右侧还有一个边框,所以减去 1
12438
+ let newColumnsWidth = remainingWidthRatio.map(ratio => minWidthPx + Math.floor(ratio * remainingWidth) - 1);
12439
+ return columns.map((_, index) => ({
12440
+ width: newColumnsWidth[index]
12441
+ }));
12442
+ };
12419
12443
 
12420
12444
  /**
12421
12445
  * 计算最小行跨距单元格
@@ -12757,9 +12781,9 @@ class TheTableComponent extends TheBaseElementComponent {
12757
12781
  });
12758
12782
  this.getIsInTable();
12759
12783
  this.getColControls();
12784
+ this.getColumnGroups();
12760
12785
  }
12761
12786
  this.headerRow = isHeaderRow(this.element);
12762
- this.getColumnGroups();
12763
12787
  }
12764
12788
  constructor(elementRef, eventDispatcher, resizeNotifier, tableStore, cdr, ngZone, tableService, theTableContextMenuService, freezeColumnPipe, freezeRowPipe, renderer, contextService, config) {
12765
12789
  super(elementRef, cdr);
@@ -12840,6 +12864,7 @@ class TheTableComponent extends TheBaseElementComponent {
12840
12864
  this.listenOnSelectedCells();
12841
12865
  this.listenKeydownSelectEvents();
12842
12866
  this.listenTableWrapperScroll();
12867
+ this.getColumnGroups();
12843
12868
  if (this.element.options?.numberedColumn) {
12844
12869
  const loadImageDone = await this.resolveImage();
12845
12870
  // 等待序号列表格内图片加载完成后再去渲染表格行高度
@@ -12868,6 +12893,7 @@ class TheTableComponent extends TheBaseElementComponent {
12868
12893
  this.setStickyRowStyle();
12869
12894
  this.bindTableScrollingShadow();
12870
12895
  this.setHeaderRowShadow();
12896
+ this.getColumnGroups();
12871
12897
  }
12872
12898
  });
12873
12899
  this.contextService.windowResized$.pipe(takeUntil(this.destroy$)).subscribe(result => {
@@ -12880,6 +12906,7 @@ class TheTableComponent extends TheBaseElementComponent {
12880
12906
  }
12881
12907
  getColumnGroups() {
12882
12908
  this.columns = calcColumnGroups(this.readonly, this.element, this.elementRef.nativeElement.offsetWidth, this.config.mode);
12909
+ this.readonly && this.cdr.detectChanges();
12883
12910
  }
12884
12911
  /* 给标题行的左/右加阴影 */
12885
12912
  setHeaderRowShadow() {
@@ -13433,7 +13460,7 @@ class TheTableComponent extends TheBaseElementComponent {
13433
13460
  }
13434
13461
  }
13435
13462
  TheTableComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.2", ngImport: i0, type: TheTableComponent, deps: [{ token: i0.ElementRef }, { token: TableCellEventDispatcher }, { token: ColumnResizeNotifierSource }, { token: TableStore }, { token: i0.ChangeDetectorRef }, { token: i0.NgZone }, { token: TableService }, { token: TheTableContextMenuService }, { token: TableFreezeColumnPipe }, { token: TableFreezeRowPipe }, { token: i0.Renderer2 }, { token: TheContextService }, { token: THE_MODE_TOKEN }], target: i0.ɵɵFactoryTarget.Component });
13436
- TheTableComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.2", type: TheTableComponent, selector: "the-table, [theTable]", host: { listeners: { "mousedown": "handleMousedown($event)" }, properties: { "class.the-table-with-controls": "isInTable || tableStore.isRightClicking || tableStore.isFocusedInput", "class.the-table-with-sticky-column": "freezeColumnPipe.transform(element, tablePluginOptions)", "class.the-numbered-table": "!readonly && element?.options?.numberedColumn", "class.the-table-selection-hide": "tableStore.isCellSelecting || tableStore.isRightClicking || tableStore.isFocusedInput" } }, providers: [
13463
+ TheTableComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.2", type: TheTableComponent, selector: "the-table, [theTable]", host: { listeners: { "mousedown": "handleMousedown($event)" }, properties: { "class.the-table-with-controls": "isInTable || tableStore.isRightClicking || tableStore.isFocusedInput", "class.the-table-with-sticky-column": "freezeColumnPipe.transform(element, tablePluginOptions)", "class.the-numbered-table": "element?.options?.numberedColumn", "class.the-table-selection-hide": "tableStore.isCellSelecting || tableStore.isRightClicking || tableStore.isFocusedInput" } }, providers: [
13437
13464
  TableStore,
13438
13465
  TableService,
13439
13466
  TheTableContextMenuService,
@@ -13463,7 +13490,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.2", ngImpor
13463
13490
  ], host: {
13464
13491
  '[class.the-table-with-controls]': 'isInTable || tableStore.isRightClicking || tableStore.isFocusedInput',
13465
13492
  '[class.the-table-with-sticky-column]': 'freezeColumnPipe.transform(element, tablePluginOptions)',
13466
- '[class.the-numbered-table]': '!readonly && element?.options?.numberedColumn',
13493
+ '[class.the-numbered-table]': 'element?.options?.numberedColumn',
13467
13494
  '[class.the-table-selection-hide]': 'tableStore.isCellSelecting || tableStore.isRightClicking || tableStore.isFocusedInput'
13468
13495
  }, template: "<div class=\"the-table-container\" theColumnResize>\n <div #tableRowControlsWrapper class=\"the-table-row-controls-wrapper\">\n <div\n class=\"the-table-corner-controls the-sticky-corner-controls\"\n #cornerControl\n [ngClass]=\"{\n visible: !readonly && (isInTable || tableStore.isRightClicking || tableStore.isFocusedInput),\n 'control-active': isSelectedAllCell,\n dangerous: tableStore.isSelectedTable && tableStore.dangerousCells.length > 0\n }\"\n >\n <div class=\"the-table-corner-button\" (mousedown)=\"onSelectTable($event)\"></div>\n <div class=\"the-table-corner-controls-insert-row-marker\" *ngIf=\"!headerRow\">\n <the-table-insert-mark type=\"row\" [at]=\"0\" [tableStore]=\"tableStore\"></the-table-insert-mark>\n </div>\n <div class=\"the-table-corner-controls-insert-column-marker\" *ngIf=\"!element.options?.headerColumn\">\n <the-table-insert-mark type=\"column\" [at]=\"0\" [tableStore]=\"tableStore\"></the-table-insert-mark>\n </div>\n </div>\n <div class=\"the-table-row-controls\">\n <div class=\"the-table-row-controls-inner\" #rowControlsInner>\n <div\n class=\"the-table-row-controls-button-wrap\"\n #rowControlsButtonWrapper\n *ngFor=\"let control of rowControls; let i = index; trackBy: trackByFnRowControls\"\n [ngClass]=\"{\n 'control-active': tableStore.selectedRowsIndex.includes(control.rowIndex),\n dangerous: tableStore.dangerousRowsIndex.includes(control.rowIndex) && tableStore.dangerousCells.length > 0\n }\"\n >\n <ng-container\n *ngIf=\"!readonly && (isInTable || tableStore.isRightClicking || tableStore.isFocusedInput) && !element?.options?.numberedColumn\"\n >\n <button\n (mousedown)=\"onRowMousedown($event, control.rowIndex)\"\n type=\"button\"\n [ngStyle]=\"{ height: control.height + 1 + 'px' }\"\n class=\"the-table-row-controls-button the-table-controls-button\"\n ></button>\n </ng-container>\n <ng-container *ngIf=\"element?.options?.numberedColumn\">\n <div\n [contentEditable]=\"false\"\n contenteditable=\"false\"\n (mousedown)=\"onRowMousedown($event, control.rowIndex)\"\n class=\"the-table-numbered-controls-button\"\n [ngStyle]=\"{ height: control.height + 1 + 'px' }\"\n >\n <p class=\"row-number d-flex align-items-center\">{{ headerRow && i === 0 ? '' : headerRow ? i : i + 1 }}</p>\n </div>\n </ng-container>\n <the-table-insert-mark type=\"row\" [at]=\"control.rowIndex + 1\" [tableStore]=\"tableStore\"> </the-table-insert-mark>\n </div>\n </div>\n </div>\n </div>\n <div class=\"the-table-wrapper\" #tableWrapper [ngClass]=\"{ 'the-table-numbered': element?.options?.numberedColumn }\">\n <table class=\"the-table\" #theTable>\n <colgroup #colgroup *ngIf=\"columns\">\n <col *ngIf=\"readonly && element?.options?.numberedColumn\" class=\"the-table-number-col\" />\n <col *ngFor=\"let col of columns\" [ngStyle]=\"{ width: col.width + 'px' }\" />\n </colgroup>\n <thead>\n <tr class=\"the-table-col-controls-wrapper the-sticky-row\" #columnControlsWrapper>\n <th *ngIf=\"readonly && element?.options?.numberedColumn\" class=\"the-table-number-col\"></th>\n <th\n #colControl\n class=\"the-table-col-controls\"\n *ngFor=\"let control of colControls; let i = index; trackBy: trackByFnColControls\"\n [ngClass]=\"{\n 'control-active': tableStore.selectedColumnsIndex.includes(i),\n dangerous: tableStore.dangerousColumnsIndex.includes(i) && tableStore.dangerousCells.length > 0\n }\"\n (mousedown)=\"onColMousedown($event, i)\"\n >\n <the-table-insert-mark\n *ngIf=\"isInTable || tableStore.isRightClicking || tableStore.isFocusedInput\"\n type=\"column\"\n [at]=\"i + 1\"\n [tableStore]=\"tableStore\"\n [parentElement]=\"colControl\"\n >\n </the-table-insert-mark>\n </th>\n </tr>\n </thead>\n <tbody #tbody>\n <slate-children [children]=\"children\" [context]=\"childrenContext\" [viewContext]=\"viewContext\"> </slate-children>\n </tbody>\n <div\n *ngIf=\"!element.options?.headerColumn\"\n #headerRowLeftShadow\n class=\"header-row-shadow header-row-left-shadow\"\n contenteditable=\"false\"\n ></div>\n <div class=\"header-row-shadow header-row-right-shadow\" #headerRowRightShadow contenteditable=\"false\"></div>\n </table>\n </div>\n</div>\n" }]
13469
13496
  }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: TableCellEventDispatcher }, { type: ColumnResizeNotifierSource }, { type: TableStore }, { type: i0.ChangeDetectorRef }, { type: i0.NgZone }, { type: TableService }, { type: TheTableContextMenuService }, { type: TableFreezeColumnPipe }, { type: TableFreezeRowPipe }, { type: i0.Renderer2 }, { type: TheContextService }, { type: TheModeConfig, decorators: [{