@sneat/datagrid 0.27.51 → 0.27.52
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/fesm2022/sneat-datagrid.mjs +281 -415
- package/fesm2022/sneat-datagrid.mjs.map +1 -1
- package/package.json +2 -2
- package/tsconfig.lib.prod.tsbuildinfo +1 -1
- package/types/sneat-datagrid.d.ts +132 -88
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sneat-datagrid.mjs","sources":["../../../../libs/datagrid/src/lib/components/data-grid/data-grid.component.ts","../../../../libs/datagrid/src/lib/tabulator/tabulator-options.ts","../../../../libs/datagrid/src/sneat-datagrid.ts"],"sourcesContent":["import {\n AfterViewInit,\n Component,\n ElementRef,\n EventEmitter,\n Input,\n OnChanges,\n Output,\n SimpleChanges,\n ViewChild,\n inject,\n ChangeDetectionStrategy\n} from '@angular/core';\nimport { ErrorLogger, IErrorLogger } from '@sneat/core';\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport {\n Tabulator,\n SelectRowModule,\n SelectRangeModule,\n KeybindingsModule,\n MenuModule,\n InteractionModule,\n Module,\n RowContextMenuSignature,\n} from 'tabulator-tables';\nimport type {\n CellComponent,\n Formatter,\n RangeComponent,\n} from 'tabulator-tables';\nimport { IGridColumn } from '@sneat/grid';\nimport { TabulatorColumn, TabulatorOptions } from '../../tabulator';\n\nclass AdvertModule extends Module {\n public static override moduleName = 'advert';\n\n override initialize() {\n return;\n }\n}\n\nTabulator.registerModule([\n InteractionModule,\n SelectRowModule,\n // SelectRange enables opt-in cell/range selection (selectableRange input).\n // KeybindingsModule wires the arrow-key navigation SelectRange relies on;\n // its default bindings are only *active* when we don't disable them via\n // the `keybindings` table option, which we do unless selectableRange is on\n // (see setTabulatorOptions()) so existing consumers see no behaviour change.\n SelectRangeModule,\n KeybindingsModule,\n AdvertModule,\n MenuModule,\n]);\n\n/**\n * A marker rendered unobtrusively in a column's header, e.g. to flag a\n * semantically-recognised field (a declared or inferred `CustomerId`, etc).\n * The grid has no semantic logic of its own — it only renders what the\n * consumer passes here.\n */\nexport interface IDataGridColumnMarker {\n readonly label: string;\n readonly title?: string;\n readonly kind?: 'declared' | 'inferred';\n}\n\n/** Payload emitted by {@link DataGridComponent.cellSelected}. */\nexport interface IDataGridCellSelectedEvent {\n readonly row: unknown;\n readonly column: { readonly field: string; readonly index: number };\n readonly value: unknown;\n readonly rowData: unknown;\n}\n\n// export interface IGridDef {\n// \tcolumns: IGridColumn[],\n// \trows?: unknown[],\n// \tgroupBy?: string;\n// }\n//\n// export const getTabulatorCols = (cols: IGridColumn[]): any[] => cols.map(c => {\n// \tconst v = {...c};\n// \tdelete v.dbType;\n// \treturn v;\n// });\n//\n// export interface IGridColumn {\n// \tfield: string;\n// \tcolName?: string;\n// \tdbType: string;\n// \ttitle: string;\n// \ttooltip?: (cell: any) => string;\n// \tformatter?: any;\n// \thozAlign?: 'left' | 'right';\n// \twidthShrink?: number;\n// \twidthGrow?: number;\n// \twidth?: number | string;\n// }\n\n/**\n * This is a wrapper class for the tabulator JS library.\n * For more info see http://tabulator.info\n */\n@Component({\n selector: 'sneat-datagrid',\n template: `\n <div id=\"tabulator\" #tabulatorDiv></div>\n <p class=\"ion-margin-start\">Rows: {{ data?.length }}</p>\n `,\n changeDetection: ChangeDetectionStrategy.OnPush,\n imports: [],\n})\nexport class DataGridComponent implements AfterViewInit, OnChanges {\n private readonly errorLogger = inject<IErrorLogger>(ErrorLogger);\n\n // TODO: Skipped for migration because:\n // Your application code writes to the input. This prevents migration.\n @Input() layout?: 'fitData' | 'fitColumns' = 'fitColumns';\n // TODO: Skipped for migration because:\n // Your application code writes to the input. This prevents migration.\n @Input() data?: unknown[] = [];\n // TODO: Skipped for migration because:\n // Your application code writes to the input. This prevents migration.\n @Input() columns?: IGridColumn[] = [];\n // TODO: Skipped for migration because:\n // Your application code writes to the input. This prevents migration.\n @Input() groupBy?: string;\n // TODO: Skipped for migration because:\n // Your application code writes to the input. This prevents migration.\n @Input() height?: string;\n // TODO: Skipped for migration because:\n // Your application code writes to the input. This prevents migration.\n @Input() maxHeight?: string | number;\n // TODO: Skipped for migration because:\n // Your application code writes to the input. This prevents migration.\n @Input() rowContextMenu?: RowContextMenuSignature;\n @ViewChild('tabulatorDiv', { static: true }) tabulatorDiv?: ElementRef;\n\n // TODO: Skipped for migration because:\n // Your application code writes to the input. This prevents migration.\n @Input() rowClick?: (event: Event, row: unknown) => void;\n\n @Output() readonly rowSelected = new EventEmitter<{\n row: unknown;\n event?: Event;\n }>();\n\n @Output() readonly rowDeselected = new EventEmitter<{\n row: unknown;\n event?: Event;\n }>();\n\n /**\n * Enables Tabulator's cell/range selection (opt-in; off by default so\n * existing consumers are unaffected). Mirrors Tabulator's own\n * `selectableRange` option: `true` for unlimited ranges, or a number to\n * cap how many ranges can be selected at once. Mutually exclusive with\n * row selection (`selectable`) — Tabulator disables range selection and\n * logs a console warning if both are set.\n */\n @Input() public selectableRange?: boolean | number;\n\n /**\n * Small, unobtrusive markers rendered in column headers, keyed by field.\n * The grid applies no semantic meaning to these — it only renders what\n * the consumer passes (e.g. a semantic-detection layer flagging a\n * `CustomerId` column).\n */\n @Input() public columnMarkers?: Record<string, IDataGridColumnMarker>;\n\n /**\n * Emitted when a single cell becomes the active selection, either via a\n * mouse click (always, regardless of `selectableRange`) or, once\n * `selectableRange` is enabled, via keyboard arrow-key navigation between\n * cells. Not emitted for multi-cell range drag-selection.\n */\n @Output() readonly cellSelected = new EventEmitter<IDataGridCellSelectedEvent>();\n\n // private tab = document.createElement('div');\n private tabulator?: Tabulator;\n\n // TODO: Skipped for migration because:\n // Your application code writes to the input. This prevents migration.\n @Input() public selectable?: boolean | number | 'highlight';\n\n private tabulatorOptions?: TabulatorOptions;\n private clickEvent?: Event;\n\n ngOnChanges(changes: SimpleChanges): void {\n try {\n if (\n (changes['data'] && this.data && this.columns) ||\n (changes['columns'] && this.columns) ||\n (changes['rowClick'] && this.rowClick)\n ) {\n this.drawTable();\n } else if (changes['columnMarkers'] && this.tabulator && this.columns) {\n // columnMarkers can arrive after the initial draw (e.g. a semantic\n // layer resolving markers asynchronously) — refresh header markers\n // in place without a full data redraw.\n const columnDefinitions = this.buildColumnDefinitions();\n if (columnDefinitions) {\n this.tabulator.setColumns(columnDefinitions);\n }\n }\n } catch (ex) {\n this.errorLogger.logError(\n ex,\n 'Failed to process ngOnChanges in DataGridComponent',\n );\n }\n }\n\n // ngOnDestroy(): void {\n // console.log('DataGridComponent.ngOnDestroy()', this.tabulator);\n // try { // TODO: destroy Tabulator\n // \tif (this.tabulator?.element) {\n // \t\t// noinspection TypeScriptValidateJSTypes\n // \t\tthis.tabulator.element.tabulator('destroy');\n // \t}\n // } catch (ex) {\n // \tthis.errorLogger.logError(ex, 'Failed to destroy tabulator');\n // }\n // }\n\n ngAfterViewInit(): void /* Intentionally not ngOnInit */ {\n if (this.tabulator) {\n try {\n this.tabulator.redraw();\n } catch (e) {\n this.errorLogger.logError(e, 'Failed to redraw tabulator', {\n show: false,\n report: false,\n });\n }\n }\n }\n\n private drawTable(): void {\n if (!this.data || !this.columns) {\n console.warn('drawTable()', 'columns:', this.columns, 'data:', this.data);\n return;\n }\n try {\n if (!this.tabulatorDiv) {\n this.errorLogger.logError(new Error('!this.tabulatorDiv'));\n return;\n }\n if (this.tabulatorOptions) {\n this.tabulatorOptions = { ...this.tabulatorOptions, data: this.data };\n this.tabulator\n ?.setData(this.data)\n .catch(this.errorLogger.logErrorHandler('Failed to set data'));\n } else {\n this.createTabulatorGrid();\n }\n // this.tabulatorDiv.nativeElement.appendChild(this.tab);\n // tabulator.redraw();\n } catch (e) {\n this.errorLogger.logError(e, 'Failed to drawTable');\n }\n }\n\n private createTabulatorGrid(): void {\n this.setTabulatorOptions();\n if (!this.tabulator) {\n this.tabulatorOptions = {\n ...this.tabulatorOptions,\n // rowClick: function (e, row) {\n // \tconsole.log('rowClick1', row);\n // },\n // rowSelect: function (row) {\n // \tconsole.log('rowSelect', row);\n // },\n // rowDeselect: function (row) {\n // \tconsole.log('rowDeselect', row);\n // }\n };\n this.tabulator = new Tabulator(\n this.tabulatorDiv?.nativeElement,\n this.tabulatorOptions,\n );\n this.tabulator.on('rowClick', (event: Event, row: unknown) => {\n this.clickEvent = event;\n if (this.rowClick) {\n this.rowClick(event, row);\n }\n });\n this.tabulator.on('rowSelected', (row: unknown) =>\n this.rowSelected.emit({ row, event: this.clickEvent }),\n );\n this.tabulator.on('rowDeselected', (row: unknown) =>\n this.rowDeselected.emit({ row, event: this.clickEvent }),\n );\n // Mouse-click selection: fires regardless of selectableRange.\n this.tabulator.on('cellClick', (_event: UIEvent, cell: CellComponent) => {\n this.emitCellSelected(cell);\n });\n // Keyboard-driven selection: only fires once selectableRange is on —\n // the SelectRange module is inert otherwise. A plain click always\n // creates a *new* range (rangeAdded), so listening to rangeChanged\n // (bounds moved on the *existing* range) picks up arrow-key\n // navigation and single-cell drag adjustments without double-firing\n // alongside the cellClick handler above.\n this.tabulator.on('rangeChanged', (range: RangeComponent) => {\n this.handleRangeChanged(range);\n });\n }\n }\n\n /** column.index is the field's position in the `columns` input array. */\n private emitCellSelected(cell: CellComponent): void {\n const field = cell.getField();\n this.cellSelected.emit({\n row: cell.getRow(),\n column: {\n field,\n index: this.columns?.findIndex((c) => c.field === field) ?? -1,\n },\n value: cell.getValue(),\n rowData: cell.getData(),\n });\n }\n\n private handleRangeChanged(range: RangeComponent): void {\n const bounds = range.getBounds();\n // Only report single-cell selections; multi-cell range drag-selection\n // is visual-only for now (out of scope for this task).\n if (bounds.start.getElement() === bounds.end.getElement()) {\n this.emitCellSelected(bounds.end);\n }\n }\n\n private buildColumnDefinitions(): TabulatorColumn[] | undefined {\n return this.columns?.map((c) => {\n const col: TabulatorColumn = {\n // TODO(help-wanted): Use strongly typed Tabulator col def\n field: c.field,\n title: c.title || c.field || c.title,\n // headerTooltip: () =>\n // \t`${c.colName || c.title || c.field}: ${c.dbType}`,\n };\n if (c.colName !== 'Id' && c.colName?.endsWith('Id')) {\n col.formatter = 'link';\n col.formatterParams = {\n url: 'test-url',\n };\n col.cellClick = (e: Event, cell: unknown) => {\n void cell;\n e.preventDefault();\n e.stopPropagation();\n };\n }\n if (c.tooltip) {\n col.tooltip = c.tooltip;\n }\n if (c.formatter) {\n col.formatter = c.formatter;\n }\n if (c.hozAlign) {\n col.hozAlign = c.hozAlign;\n }\n if (c.headerHozAlign) {\n col.headerHozAlign = c.headerHozAlign;\n }\n if (c.widthGrow) {\n col.widthGrow = c.widthGrow;\n }\n if (c.widthShrink) {\n col.widthShrink = c.widthShrink;\n }\n if (c.width !== undefined) {\n col.width = c.width;\n }\n const marker = c.field ? this.columnMarkers?.[c.field] : undefined;\n if (marker) {\n col.titleFormatter = this.buildColumnMarkerTitleFormatter(marker);\n }\n // console.log('col:', col);\n return col;\n });\n }\n\n /**\n * Renders the column's title text plus an unobtrusive marker badge.\n * Inline styles (rather than a stylesheet) keep this correct regardless\n * of the host app's CSS and Angular's view encapsulation — Tabulator\n * renders headers into plain DOM nodes outside the component's template,\n * which emulated encapsulation would not otherwise scope styles onto.\n */\n private buildColumnMarkerTitleFormatter(\n marker: IDataGridColumnMarker,\n ): Formatter {\n return (cell: CellComponent): HTMLElement => {\n const wrapper = document.createElement('span');\n wrapper.style.display = 'inline-flex';\n wrapper.style.alignItems = 'center';\n wrapper.style.gap = '4px';\n\n const titleSpan = document.createElement('span');\n titleSpan.textContent = String(cell.getValue() ?? '');\n wrapper.appendChild(titleSpan);\n\n const markerSpan = document.createElement('span');\n markerSpan.textContent = marker.label;\n markerSpan.style.display = 'inline-block';\n markerSpan.style.fontSize = '0.65em';\n markerSpan.style.fontWeight = '600';\n markerSpan.style.lineHeight = '1.4';\n markerSpan.style.padding = '0 4px';\n markerSpan.style.borderRadius = '3px';\n markerSpan.style.opacity = '0.75';\n markerSpan.style.whiteSpace = 'nowrap';\n markerSpan.style.border =\n marker.kind === 'inferred'\n ? '1px dashed currentColor'\n : '1px solid currentColor';\n if (marker.kind === 'inferred') {\n markerSpan.style.fontStyle = 'italic';\n }\n if (marker.title) {\n markerSpan.title = marker.title;\n }\n wrapper.appendChild(markerSpan);\n\n return wrapper;\n };\n }\n\n private setTabulatorOptions(): void {\n this.tabulatorOptions = {\n // tooltipsHeader: true, // enable header tooltips\n // tooltipGenerationMode: 'hover',\n rowContextMenu: this.rowContextMenu,\n selectableRows: this.selectable,\n data: this.data,\n // reactiveData: true, // enable data reactivity\n columns: this.buildColumnDefinitions(),\n layout: this.layout || 'fitColumns',\n };\n if (this.selectableRange) {\n this.tabulatorOptions = {\n ...this.tabulatorOptions,\n selectableRange: this.selectableRange,\n };\n } else {\n // Registering KeybindingsModule activates its default arrow/page/home\n // keybindings table-wide (they only *do* something in modules that\n // subscribe to them, but scrolling/focus side effects are otherwise\n // observable). Explicitly disabling them keeps existing consumers'\n // behaviour identical unless they opt into selectableRange.\n this.tabulatorOptions = {\n ...this.tabulatorOptions,\n keybindings: false,\n };\n }\n if (this.height) {\n this.tabulatorOptions = {\n ...this.tabulatorOptions,\n height: this.height,\n };\n }\n if (this.maxHeight) {\n this.tabulatorOptions = {\n ...this.tabulatorOptions,\n maxHeight: this.maxHeight,\n };\n }\n if (this.groupBy) {\n this.tabulatorOptions = {\n ...this.tabulatorOptions,\n groupBy: this.groupBy,\n groupHeader: (value: unknown, count: number) => {\n // value - the value all members of this group share\n // count - the number of rows in this group\n // data - an array of all the row data objects in this group\n // group - the group component for the group\n // console.log('groupHeader', value);\n return `${\n this.groupBy\n }: ${value} <span class=\"ion-margin-start\">(${count} ${\n count === 1 ? 'record' : 'records'\n })</span>`;\n },\n };\n }\n }\n}\n","import { ColumnDefinition, Options } from 'tabulator-tables';\n\nexport type TabulatorColumn = ColumnDefinition;\n\n// export interface TabulatorColumn {\n// \tfield: string;\n// \ttitle?: string;\n// \tformatter?: 'link' | 'progress' | 'html' | 'text' | 'number' | 'money' | 'image' | 'tickCross';\n// \tformatterParams?: unknown;\n// \tcellClick?: (e: Event, cell: unknown) => void;\n// \theaderTooltip?: () => string;\n// \ttooltip?: (cell: unknown) => string;\n// \thozAlign?: 'left' | 'right';\n// \theaderHozAlign?: 'left' | 'right';\n// \twidthShrink?: number;\n// \twidthGrow?: number;\n// \twidth?: number | string;\n// }\n\nexport type TabulatorOptions = Options;\n// export interface TabulatorOptions {\n// \treadonly tooltipsHeader?: boolean;\n// \treadonly tooltipGenerationMode?: 'hover' | 'mouseover';\n// \treadonly reactiveData?: boolean;\n// \treadonly selectable?: boolean | number | 'highlight';\n// \treadonly data?: unknown[];\n// \treadonly layout?: 'fitData' | 'fitColumns';\n// \treadonly columns?: TabulatorColumn[];\n// \treadonly height?: string | number;\n// \treadonly maxHeight?: string | number;\n// \treadonly groupBy?: string;\n// \treadonly groupHeader?: (value: unknown, count: number) => string;\n// \treadonly rowClick?: (event: Event, row: unknown) => void;\n// \treadonly rowSelect?: (row: unknown) => void;\n// \treadonly rowDeselect?: (row: unknown) => void;\n// \treadonly rowContextMenu?: IRowMenu[];\n// }\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;AAkCA,MAAM,YAAa,SAAQ,MAAM,CAAA;aACR,IAAA,CAAA,UAAU,GAAG,QAAQ,CAAC;IAEpC,UAAU,GAAA;QACjB;IACF;;AAGF,SAAS,CAAC,cAAc,CAAC;IACvB,iBAAiB;IACjB,eAAe;;;;;;IAMf,iBAAiB;IACjB,iBAAiB;IACjB,YAAY;IACZ,UAAU;AACX,CAAA,CAAC;AAsBF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA;;;AAGG;MAUU,iBAAiB,CAAA;AAT9B,IAAA,WAAA,GAAA;AAUmB,QAAA,IAAA,CAAA,WAAW,GAAG,MAAM,CAAe,WAAW,CAAC;;;QAIvD,IAAA,CAAA,MAAM,GAA8B,YAA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ACZ,iBAAA;;sBAME;;sBAGA;;sBAGA;;sBAGA;;sBAGA;;sBAGA;;sBAGA;;sBACA,SAAS;AAAC,gBAAA,IAAA,EAAA,CAAA,cAAc,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;;sBAI1C;;sBAEA;;sBAKA;;sBAaA;;sBAQA;;sBAQA;;sBAOA;;;ACrKH;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACpCA;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"sneat-datagrid.mjs","names":[],"sources":["../../../../libs/datagrid/src/lib/components/data-grid/data-grid.component.ts"],"sourcesContent":["import {\n AfterViewInit,\n Component,\n ElementRef,\n EventEmitter,\n Input,\n OnChanges,\n Output,\n SimpleChanges,\n ViewChild,\n inject,\n ChangeDetectionStrategy\n} from '@angular/core';\nimport { ErrorLogger, IErrorLogger } from '@sneat/core';\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport {\n Tabulator,\n SelectRowModule,\n SelectRangeModule,\n KeybindingsModule,\n MenuModule,\n InteractionModule,\n Module,\n RowContextMenuSignature,\n} from 'tabulator-tables';\nimport type {\n CellComponent,\n Formatter,\n RangeComponent,\n} from 'tabulator-tables';\nimport { IGridColumn } from '@sneat/grid';\nimport { TabulatorColumn, TabulatorOptions } from '../../tabulator';\n\nclass AdvertModule extends Module {\n public static override moduleName = 'advert';\n\n override initialize() {\n return;\n }\n}\n\nTabulator.registerModule([\n InteractionModule,\n SelectRowModule,\n // SelectRange enables opt-in cell/range selection (selectableRange input).\n // KeybindingsModule wires the arrow-key navigation SelectRange relies on;\n // its default bindings are only *active* when we don't disable them via\n // the `keybindings` table option, which we do unless selectableRange is on\n // (see setTabulatorOptions()) so existing consumers see no behaviour change.\n SelectRangeModule,\n KeybindingsModule,\n AdvertModule,\n MenuModule,\n]);\n\n/**\n * A marker rendered unobtrusively in a column's header, e.g. to flag a\n * semantically-recognised field (a declared or inferred `CustomerId`, etc).\n * The grid has no semantic logic of its own — it only renders what the\n * consumer passes here.\n */\nexport interface IDataGridColumnMarker {\n readonly label: string;\n readonly title?: string;\n readonly kind?: 'declared' | 'inferred';\n}\n\n/** Payload emitted by {@link DataGridComponent.cellSelected}. */\nexport interface IDataGridCellSelectedEvent {\n readonly row: unknown;\n readonly column: { readonly field: string; readonly index: number };\n readonly value: unknown;\n readonly rowData: unknown;\n}\n\n// export interface IGridDef {\n// \tcolumns: IGridColumn[],\n// \trows?: unknown[],\n// \tgroupBy?: string;\n// }\n//\n// export const getTabulatorCols = (cols: IGridColumn[]): any[] => cols.map(c => {\n// \tconst v = {...c};\n// \tdelete v.dbType;\n// \treturn v;\n// });\n//\n// export interface IGridColumn {\n// \tfield: string;\n// \tcolName?: string;\n// \tdbType: string;\n// \ttitle: string;\n// \ttooltip?: (cell: any) => string;\n// \tformatter?: any;\n// \thozAlign?: 'left' | 'right';\n// \twidthShrink?: number;\n// \twidthGrow?: number;\n// \twidth?: number | string;\n// }\n\n/**\n * This is a wrapper class for the tabulator JS library.\n * For more info see http://tabulator.info\n */\n@Component({\n selector: 'sneat-datagrid',\n template: `\n <div id=\"tabulator\" #tabulatorDiv></div>\n <p class=\"ion-margin-start\">Rows: {{ data?.length }}</p>\n `,\n changeDetection: ChangeDetectionStrategy.OnPush,\n imports: [],\n})\nexport class DataGridComponent implements AfterViewInit, OnChanges {\n private readonly errorLogger = inject<IErrorLogger>(ErrorLogger);\n\n // TODO: Skipped for migration because:\n // Your application code writes to the input. This prevents migration.\n @Input() layout?: 'fitData' | 'fitColumns' = 'fitColumns';\n // TODO: Skipped for migration because:\n // Your application code writes to the input. This prevents migration.\n @Input() data?: unknown[] = [];\n // TODO: Skipped for migration because:\n // Your application code writes to the input. This prevents migration.\n @Input() columns?: IGridColumn[] = [];\n // TODO: Skipped for migration because:\n // Your application code writes to the input. This prevents migration.\n @Input() groupBy?: string;\n // TODO: Skipped for migration because:\n // Your application code writes to the input. This prevents migration.\n @Input() height?: string;\n // TODO: Skipped for migration because:\n // Your application code writes to the input. This prevents migration.\n @Input() maxHeight?: string | number;\n // TODO: Skipped for migration because:\n // Your application code writes to the input. This prevents migration.\n @Input() rowContextMenu?: RowContextMenuSignature;\n @ViewChild('tabulatorDiv', { static: true }) tabulatorDiv?: ElementRef;\n\n // TODO: Skipped for migration because:\n // Your application code writes to the input. This prevents migration.\n @Input() rowClick?: (event: Event, row: unknown) => void;\n\n @Output() readonly rowSelected = new EventEmitter<{\n row: unknown;\n event?: Event;\n }>();\n\n @Output() readonly rowDeselected = new EventEmitter<{\n row: unknown;\n event?: Event;\n }>();\n\n /**\n * Enables Tabulator's cell/range selection (opt-in; off by default so\n * existing consumers are unaffected). Mirrors Tabulator's own\n * `selectableRange` option: `true` for unlimited ranges, or a number to\n * cap how many ranges can be selected at once. Mutually exclusive with\n * row selection (`selectable`) — Tabulator disables range selection and\n * logs a console warning if both are set.\n */\n @Input() public selectableRange?: boolean | number;\n\n /**\n * Small, unobtrusive markers rendered in column headers, keyed by field.\n * The grid applies no semantic meaning to these — it only renders what\n * the consumer passes (e.g. a semantic-detection layer flagging a\n * `CustomerId` column).\n */\n @Input() public columnMarkers?: Record<string, IDataGridColumnMarker>;\n\n /**\n * Emitted when a single cell becomes the active selection, either via a\n * mouse click (always, regardless of `selectableRange`) or, once\n * `selectableRange` is enabled, via keyboard arrow-key navigation between\n * cells. Not emitted for multi-cell range drag-selection.\n */\n @Output() readonly cellSelected = new EventEmitter<IDataGridCellSelectedEvent>();\n\n // private tab = document.createElement('div');\n private tabulator?: Tabulator;\n\n // TODO: Skipped for migration because:\n // Your application code writes to the input. This prevents migration.\n @Input() public selectable?: boolean | number | 'highlight';\n\n private tabulatorOptions?: TabulatorOptions;\n private clickEvent?: Event;\n\n ngOnChanges(changes: SimpleChanges): void {\n try {\n if (\n (changes['data'] && this.data && this.columns) ||\n (changes['columns'] && this.columns) ||\n (changes['rowClick'] && this.rowClick)\n ) {\n this.drawTable();\n } else if (changes['columnMarkers'] && this.tabulator && this.columns) {\n // columnMarkers can arrive after the initial draw (e.g. a semantic\n // layer resolving markers asynchronously) — refresh header markers\n // in place without a full data redraw.\n const columnDefinitions = this.buildColumnDefinitions();\n if (columnDefinitions) {\n this.tabulator.setColumns(columnDefinitions);\n }\n }\n } catch (ex) {\n this.errorLogger.logError(\n ex,\n 'Failed to process ngOnChanges in DataGridComponent',\n );\n }\n }\n\n // ngOnDestroy(): void {\n // console.log('DataGridComponent.ngOnDestroy()', this.tabulator);\n // try { // TODO: destroy Tabulator\n // \tif (this.tabulator?.element) {\n // \t\t// noinspection TypeScriptValidateJSTypes\n // \t\tthis.tabulator.element.tabulator('destroy');\n // \t}\n // } catch (ex) {\n // \tthis.errorLogger.logError(ex, 'Failed to destroy tabulator');\n // }\n // }\n\n ngAfterViewInit(): void /* Intentionally not ngOnInit */ {\n if (this.tabulator) {\n try {\n this.tabulator.redraw();\n } catch (e) {\n this.errorLogger.logError(e, 'Failed to redraw tabulator', {\n show: false,\n report: false,\n });\n }\n }\n }\n\n private drawTable(): void {\n if (!this.data || !this.columns) {\n console.warn('drawTable()', 'columns:', this.columns, 'data:', this.data);\n return;\n }\n try {\n if (!this.tabulatorDiv) {\n this.errorLogger.logError(new Error('!this.tabulatorDiv'));\n return;\n }\n if (this.tabulatorOptions) {\n this.tabulatorOptions = { ...this.tabulatorOptions, data: this.data };\n this.tabulator\n ?.setData(this.data)\n .catch(this.errorLogger.logErrorHandler('Failed to set data'));\n } else {\n this.createTabulatorGrid();\n }\n // this.tabulatorDiv.nativeElement.appendChild(this.tab);\n // tabulator.redraw();\n } catch (e) {\n this.errorLogger.logError(e, 'Failed to drawTable');\n }\n }\n\n private createTabulatorGrid(): void {\n this.setTabulatorOptions();\n if (!this.tabulator) {\n this.tabulatorOptions = {\n ...this.tabulatorOptions,\n // rowClick: function (e, row) {\n // \tconsole.log('rowClick1', row);\n // },\n // rowSelect: function (row) {\n // \tconsole.log('rowSelect', row);\n // },\n // rowDeselect: function (row) {\n // \tconsole.log('rowDeselect', row);\n // }\n };\n this.tabulator = new Tabulator(\n this.tabulatorDiv?.nativeElement,\n this.tabulatorOptions,\n );\n this.tabulator.on('rowClick', (event: Event, row: unknown) => {\n this.clickEvent = event;\n if (this.rowClick) {\n this.rowClick(event, row);\n }\n });\n this.tabulator.on('rowSelected', (row: unknown) =>\n this.rowSelected.emit({ row, event: this.clickEvent }),\n );\n this.tabulator.on('rowDeselected', (row: unknown) =>\n this.rowDeselected.emit({ row, event: this.clickEvent }),\n );\n // Mouse-click selection: fires regardless of selectableRange.\n this.tabulator.on('cellClick', (_event: UIEvent, cell: CellComponent) => {\n this.emitCellSelected(cell);\n });\n // Keyboard-driven selection: only fires once selectableRange is on —\n // the SelectRange module is inert otherwise. A plain click always\n // creates a *new* range (rangeAdded), so listening to rangeChanged\n // (bounds moved on the *existing* range) picks up arrow-key\n // navigation and single-cell drag adjustments without double-firing\n // alongside the cellClick handler above.\n this.tabulator.on('rangeChanged', (range: RangeComponent) => {\n this.handleRangeChanged(range);\n });\n }\n }\n\n /** column.index is the field's position in the `columns` input array. */\n private emitCellSelected(cell: CellComponent): void {\n const field = cell.getField();\n this.cellSelected.emit({\n row: cell.getRow(),\n column: {\n field,\n index: this.columns?.findIndex((c) => c.field === field) ?? -1,\n },\n value: cell.getValue(),\n rowData: cell.getData(),\n });\n }\n\n private handleRangeChanged(range: RangeComponent): void {\n const bounds = range.getBounds();\n // Only report single-cell selections; multi-cell range drag-selection\n // is visual-only for now (out of scope for this task).\n if (bounds.start.getElement() === bounds.end.getElement()) {\n this.emitCellSelected(bounds.end);\n }\n }\n\n private buildColumnDefinitions(): TabulatorColumn[] | undefined {\n return this.columns?.map((c) => {\n const col: TabulatorColumn = {\n // TODO(help-wanted): Use strongly typed Tabulator col def\n field: c.field,\n title: c.title || c.field || c.title,\n // headerTooltip: () =>\n // \t`${c.colName || c.title || c.field}: ${c.dbType}`,\n };\n if (c.colName !== 'Id' && c.colName?.endsWith('Id')) {\n col.formatter = 'link';\n col.formatterParams = {\n url: 'test-url',\n };\n col.cellClick = (e: Event, cell: unknown) => {\n void cell;\n e.preventDefault();\n e.stopPropagation();\n };\n }\n if (c.tooltip) {\n col.tooltip = c.tooltip;\n }\n if (c.formatter) {\n col.formatter = c.formatter;\n }\n if (c.hozAlign) {\n col.hozAlign = c.hozAlign;\n }\n if (c.headerHozAlign) {\n col.headerHozAlign = c.headerHozAlign;\n }\n if (c.widthGrow) {\n col.widthGrow = c.widthGrow;\n }\n if (c.widthShrink) {\n col.widthShrink = c.widthShrink;\n }\n if (c.width !== undefined) {\n col.width = c.width;\n }\n const marker = c.field ? this.columnMarkers?.[c.field] : undefined;\n if (marker) {\n col.titleFormatter = this.buildColumnMarkerTitleFormatter(marker);\n }\n // console.log('col:', col);\n return col;\n });\n }\n\n /**\n * Renders the column's title text plus an unobtrusive marker badge.\n * Inline styles (rather than a stylesheet) keep this correct regardless\n * of the host app's CSS and Angular's view encapsulation — Tabulator\n * renders headers into plain DOM nodes outside the component's template,\n * which emulated encapsulation would not otherwise scope styles onto.\n */\n private buildColumnMarkerTitleFormatter(\n marker: IDataGridColumnMarker,\n ): Formatter {\n return (cell: CellComponent): HTMLElement => {\n const wrapper = document.createElement('span');\n wrapper.style.display = 'inline-flex';\n wrapper.style.alignItems = 'center';\n wrapper.style.gap = '4px';\n\n const titleSpan = document.createElement('span');\n titleSpan.textContent = String(cell.getValue() ?? '');\n wrapper.appendChild(titleSpan);\n\n const markerSpan = document.createElement('span');\n markerSpan.textContent = marker.label;\n markerSpan.style.display = 'inline-block';\n markerSpan.style.fontSize = '0.65em';\n markerSpan.style.fontWeight = '600';\n markerSpan.style.lineHeight = '1.4';\n markerSpan.style.padding = '0 4px';\n markerSpan.style.borderRadius = '3px';\n markerSpan.style.opacity = '0.75';\n markerSpan.style.whiteSpace = 'nowrap';\n markerSpan.style.border =\n marker.kind === 'inferred'\n ? '1px dashed currentColor'\n : '1px solid currentColor';\n if (marker.kind === 'inferred') {\n markerSpan.style.fontStyle = 'italic';\n }\n if (marker.title) {\n markerSpan.title = marker.title;\n }\n wrapper.appendChild(markerSpan);\n\n return wrapper;\n };\n }\n\n private setTabulatorOptions(): void {\n this.tabulatorOptions = {\n // tooltipsHeader: true, // enable header tooltips\n // tooltipGenerationMode: 'hover',\n rowContextMenu: this.rowContextMenu,\n selectableRows: this.selectable,\n data: this.data,\n // reactiveData: true, // enable data reactivity\n columns: this.buildColumnDefinitions(),\n layout: this.layout || 'fitColumns',\n };\n if (this.selectableRange) {\n this.tabulatorOptions = {\n ...this.tabulatorOptions,\n selectableRange: this.selectableRange,\n };\n } else {\n // Registering KeybindingsModule activates its default arrow/page/home\n // keybindings table-wide (they only *do* something in modules that\n // subscribe to them, but scrolling/focus side effects are otherwise\n // observable). Explicitly disabling them keeps existing consumers'\n // behaviour identical unless they opt into selectableRange.\n this.tabulatorOptions = {\n ...this.tabulatorOptions,\n keybindings: false,\n };\n }\n if (this.height) {\n this.tabulatorOptions = {\n ...this.tabulatorOptions,\n height: this.height,\n };\n }\n if (this.maxHeight) {\n this.tabulatorOptions = {\n ...this.tabulatorOptions,\n maxHeight: this.maxHeight,\n };\n }\n if (this.groupBy) {\n this.tabulatorOptions = {\n ...this.tabulatorOptions,\n groupBy: this.groupBy,\n groupHeader: (value: unknown, count: number) => {\n // value - the value all members of this group share\n // count - the number of rows in this group\n // data - an array of all the row data objects in this group\n // group - the group component for the group\n // console.log('groupHeader', value);\n return `${\n this.groupBy\n }: ${value} <span class=\"ion-margin-start\">(${count} ${\n count === 1 ? 'record' : 'records'\n })</span>`;\n },\n };\n }\n }\n}\n"],"mappings":";;;;AAkCA,IAAM,eAAN,cAA2B,OAAM;CACR;EAAA,KAAA,aAAa;CAAS;CAEpC,aAAU,CAEnB;;AAGF,UAAU,eAAe;CACvB;CACA;CAMA;CACA;CACA;CACA;AACD,CAAA;AA4DD,IAAa,oBAAb,MAAa,kBAAiB;CAT9B,cAAA;EAUmB,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AA;IAAA,OAAA;IAAA,WAAA,CAAA,cAAA;IAAA,aAAA;IAAA,QAAA;GAAA,CAAA;GAAA,eAAA;GAAA,UAAA;GAAA,UAPlB;;;;GAGT,UAAA;GAAA,iBAAA,GAAA,wBAAA;EAAA,CAAA;CAAA;;AAIU,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAiB,YAAA,CAAA;EAT7B,MAAA;EAAU,MAAA,CAAA;GACT,UAAU;GACV,UAAU;;;;GAIV,iBAAiB,wBAAwB;GACzC,SAAS,CAAA;EACV,CAAA;;;E,WAME,MAAA,M;E,SAGA,MAAA,M;E,YAGA,MAAA,M;E,YAGA,MAAA,M;E,WAGA,MAAA,M;E,cAGA,MAAA,M;E,mBAGA,MAAA,M;;GACA,MAAA;GAAU,MAAA,CAAA,gBAAgB,EAAE,QAAQ,KAAI,CAAE;;E,aAI1C,MAAA,M;E,gBAEA,MAAA,O;E,kBAKA,MAAA,O;E,oBAaA,MAAA,M;E,kBAQA,MAAA,M;E,iBAQA,MAAA,O;E,eAOA,MAAA,M"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sneat/datagrid",
|
|
3
|
-
"version": "0.27.
|
|
3
|
+
"version": "0.27.52",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"@angular/core": ">=22.0.0 <23.0.0"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"tslib": "2.
|
|
12
|
+
"tslib": "2.9.1"
|
|
13
13
|
},
|
|
14
14
|
"module": "fesm2022/sneat-datagrid.mjs",
|
|
15
15
|
"typings": "types/sneat-datagrid.d.ts",
|