{"version":3,"file":"ajf-core-table.mjs","sources":["../../../projects/core/table/src/table-cell.ts","../../../projects/core/table/src/table.ts","../../../projects/core/table/src/table.html","../../../projects/core/table/src/table-module.ts","../../../projects/core/table/src/public_api.ts","../../../projects/core/table/src/ajf-core-table.ts"],"sourcesContent":["/**\n * @license\n * Copyright (C) Gnucoop soc. coop.\n *\n * This file is part of the Advanced JSON forms (ajf).\n *\n * Advanced JSON forms (ajf) is free software: you can redistribute it and/or\n * modify it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the License,\n * or (at your option) any later version.\n *\n * Advanced JSON forms (ajf) is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero\n * General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with Advanced JSON forms (ajf).\n * If not, see http://www.gnu.org/licenses/.\n *\n */\n\nexport interface AjfTableCell {\n  /**\n   * The value to show into the table cell. It can be a string, a number, or html text.\n   * If there is a dialog box to open on click, you can use something like this:\n   * '<div class=\"read_more_cell\"><p class=\"read_more_text\">Read more</p><b class=\"material-icons\">add_circle_outline</b></div>'\n   *\n   */\n  value: any;\n\n  /**\n   * the css style for the cell.\n   * ie: {textAlign: 'left', color: 'black'}\n   */\n  style: any;\n\n  /**\n   * the colspan for the cell\n   */\n  colspan?: number;\n\n  /**\n   * the rowspan for the cell\n   */\n  rowspan?: number;\n\n  /**\n   * if true and if this is a header cell, sorting is enabled on this column\n   */\n  sorted?: boolean;\n\n  /**\n   * contains the html to be displayed in a dialog box when you click on this cell\n   */\n  dialogHtml?: string;\n}\n","/**\n * @license\n * Copyright (C) Gnucoop soc. coop.\n *\n * This file is part of the Advanced JSON forms (ajf).\n *\n * Advanced JSON forms (ajf) is free software: you can redistribute it and/or\n * modify it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the License,\n * or (at your option) any later version.\n *\n * Advanced JSON forms (ajf) is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero\n * General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with Advanced JSON forms (ajf).\n * If not, see http://www.gnu.org/licenses/.\n *\n */\n\nimport {\n  ChangeDetectionStrategy,\n  ChangeDetectorRef,\n  Component,\n  EventEmitter,\n  Input,\n  OnDestroy,\n  Output,\n  SecurityContext,\n  TemplateRef,\n  ViewChild,\n  ViewEncapsulation,\n} from '@angular/core';\nimport {MatDialog, MatDialogConfig} from '@angular/material/dialog';\nimport {Sort} from '@angular/material/sort';\nimport {DomSanitizer} from '@angular/platform-browser';\nimport {AjfTableCell} from './table-cell';\n\n@Component({\n  selector: 'ajf-table',\n  templateUrl: 'table.html',\n  styleUrls: ['table.scss'],\n  changeDetection: ChangeDetectionStrategy.OnPush,\n  encapsulation: ViewEncapsulation.None,\n})\nexport class AjfTable implements OnDestroy {\n  /**\n   * data to be shown in the table\n   */\n  private _data: AjfTableCell[][] = [];\n  get data(): AjfTableCell[][] {\n    return this._data;\n  }\n  @Input()\n  set data(data: AjfTableCell[][]) {\n    this._data = this._fixData(data);\n    this._sortedData = [...this._data];\n    this._cdr.markForCheck();\n  }\n\n  /**\n   * sorted data to be shown in the table\n   */\n  private _sortedData: AjfTableCell[][] = [];\n  get sortedData(): AjfTableCell[][] {\n    return this._sortedData;\n  }\n\n  /**\n   * cellpadding for all rows, include header\n   */\n  private _cellpadding: string = '';\n  get cellpadding(): string {\n    return this._cellpadding;\n  }\n  @Input()\n  set cellpadding(cellpadding: string) {\n    this._cellpadding = cellpadding;\n    this._cdr.markForCheck();\n  }\n\n  /**\n   * Emit an event when sort arrows are selected\n   */\n  @Output()\n  readonly sortSelected = new EventEmitter<Sort>();\n\n  @ViewChild('dialogContent', {read: TemplateRef}) dialogContent!: TemplateRef<HTMLElement>;\n\n  /**\n   * Creates an instance of TableComponent.\n   *\n   *\n   * @memberOf TableComponent\n   */\n  constructor(\n    private _cdr: ChangeDetectorRef,\n    private _domSanitizer: DomSanitizer,\n    private _dialog: MatDialog,\n  ) {}\n\n  private _fixData(data: AjfTableCell[][]): AjfTableCell[][] {\n    (data || []).forEach(elem => {\n      (elem || []).forEach(subElem => {\n        subElem.value = this._domSanitizer.sanitize(\n          SecurityContext.HTML,\n          this._domSanitizer.bypassSecurityTrustHtml(subElem.value),\n        );\n      });\n    });\n    return data;\n  }\n\n  /**\n   * Sort visible data and emit an event to use for paginated table\n   * @param sort\n   * @returns\n   */\n  sortData(sort: Sort): void {\n    if (!sort.active || sort.direction === '') {\n      this._sortedData = [...this._data];\n    } else {\n      const columnIdx = parseInt(sort.active.replace(/^\\D+/, '')) || 0;\n      const sortedData = this._sortedData.slice(1).sort((a, b) => {\n        const isAsc = sort.direction === 'asc';\n        return this._compare(a[columnIdx], b[columnIdx], isAsc);\n      });\n      this._sortedData = [this._data[0], ...sortedData];\n    }\n    this.sortSelected.emit(sort);\n  }\n\n  private _compare(a: AjfTableCell, b: AjfTableCell, isAsc: boolean) {\n    return (a.value < b.value ? -1 : 1) * (isAsc ? 1 : -1);\n  }\n\n  /**\n   * open a dialog when click on cell, if dialogHtmlContent is valid\n   * @param dialogHtmlContent the html to show in the dialog\n   */\n  openDialog(dialogHtmlContent: string | undefined): void {\n    if (dialogHtmlContent) {\n      const dialogConfig = {\n        data: {\n          content: dialogHtmlContent,\n        },\n      } as MatDialogConfig;\n      this._dialog.open(this.dialogContent, dialogConfig);\n    }\n  }\n\n  ngOnDestroy(): void {\n    this.sortSelected.complete();\n  }\n}\n","<table *ngIf=\"sortedData\" matSort (matSortChange)=\"sortData($event)\">\n  <tr *ngIf=\"sortedData.length > 0\">\n    <ng-container *ngFor=\"let headerCell of sortedData[0]; let idx = index\">\n      <ng-container *ngIf=\"headerCell.sorted; else noSortedHeader\">\n        <th\n          [applyStyles]=\"headerCell.style\"\n          [ngStyle]=\"{'padding': cellpadding}\"\n          [attr.colspan]=\"headerCell.colspan\"\n          [attr.rowspan]=\"headerCell.rowspan\"\n          [mat-sort-header]=\"'column' + idx\"\n        ><span [innerHTML]=\"headerCell.value\"></span></th>\n      </ng-container>\n      <ng-template #noSortedHeader>\n        <th\n          [applyStyles]=\"headerCell.style\"\n          [ngStyle]=\"{'padding': cellpadding}\"\n          [attr.colspan]=\"headerCell.colspan\"\n          [attr.rowspan]=\"headerCell.rowspan\"\n        ><span [innerHTML]=\"headerCell.value\"></span></th>\n      </ng-template>\n    </ng-container>\n  </tr>\n  <ng-container *ngIf=\"sortedData.length > 1\">\n    <tr *ngFor=\"let row of sortedData.slice(1)\">\n      <td\n        *ngFor=\"let cell of row\"\n        [applyStyles]=\"cell.style\"\n        [ngStyle]=\"{'padding': cellpadding}\"\n        [attr.colspan]=\"cell.colspan\"\n        [attr.rowspan]=\"cell.rowspan\"\n        [innerHTML]=\"cell.value\"\n        (click)=\"openDialog(cell.dialogHtml)\"\n      ></td>\n    </tr>\n  </ng-container>\n</table>\n\n<ng-template #dialogContent let-data>\n  <div [innerHTML]=\"data.content\"></div>\n</ng-template>\n","/**\n * @license\n * Copyright (C) Gnucoop soc. coop.\n *\n * This file is part of the Advanced JSON forms (ajf).\n *\n * Advanced JSON forms (ajf) is free software: you can redistribute it and/or\n * modify it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the License,\n * or (at your option) any later version.\n *\n * Advanced JSON forms (ajf) is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero\n * General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with Advanced JSON forms (ajf).\n * If not, see http://www.gnu.org/licenses/.\n *\n */\n\nimport {AjfCommonModule} from '@ajf/core/common';\nimport {CommonModule} from '@angular/common';\nimport {MatSortModule} from '@angular/material/sort';\nimport {NgModule} from '@angular/core';\n\nimport {AjfTable} from './table';\n\n@NgModule({\n  imports: [AjfCommonModule, CommonModule, MatSortModule],\n  declarations: [AjfTable],\n  exports: [AjfTable],\n})\nexport class AjfTableModule {}\n","/**\n * @license\n * Copyright (C) Gnucoop soc. coop.\n *\n * This file is part of the Advanced JSON forms (ajf).\n *\n * Advanced JSON forms (ajf) is free software: you can redistribute it and/or\n * modify it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the License,\n * or (at your option) any later version.\n *\n * Advanced JSON forms (ajf) is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero\n * General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with Advanced JSON forms (ajf).\n * If not, see http://www.gnu.org/licenses/.\n *\n */\n\nexport * from './table-cell';\nexport * from './table-module';\nexport * from './table';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;;;;;;;;;;;AAoBG;;ACpBH;;;;;;;;;;;;;;;;;;;;AAoBG;MA2BU,QAAQ,CAAA;AAKnB,IAAA,IAAI,IAAI,GAAA;QACN,OAAO,IAAI,CAAC,KAAK;;IAEnB,IACI,IAAI,CAAC,IAAsB,EAAA;QAC7B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;QAChC,IAAI,CAAC,WAAW,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC;AAClC,QAAA,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;;AAO1B,IAAA,IAAI,UAAU,GAAA;QACZ,OAAO,IAAI,CAAC,WAAW;;AAOzB,IAAA,IAAI,WAAW,GAAA;QACb,OAAO,IAAI,CAAC,YAAY;;IAE1B,IACI,WAAW,CAAC,WAAmB,EAAA;AACjC,QAAA,IAAI,CAAC,YAAY,GAAG,WAAW;A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