pdm-ui-kit 0.1.18 → 0.1.19
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/esm2020/lib/components/table/table.component.mjs +199 -7
- package/fesm2015/pdm-ui-kit.mjs +199 -6
- package/fesm2015/pdm-ui-kit.mjs.map +1 -1
- package/fesm2020/pdm-ui-kit.mjs +198 -6
- package/fesm2020/pdm-ui-kit.mjs.map +1 -1
- package/lib/components/table/table.component.d.ts +29 -1
- package/package.json +1 -1
package/fesm2020/pdm-ui-kit.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as i1 from '@angular/common';
|
|
2
2
|
import { CommonModule } from '@angular/common';
|
|
3
3
|
import * as i0 from '@angular/core';
|
|
4
|
-
import { EventEmitter, Component, ChangeDetectionStrategy, Input, Output, HostListener, ViewChildren, NgModule } from '@angular/core';
|
|
4
|
+
import { EventEmitter, Component, ChangeDetectionStrategy, Input, Output, HostListener, ViewChildren, ViewChild, NgModule } from '@angular/core';
|
|
5
5
|
|
|
6
6
|
class PdmAccordionComponent {
|
|
7
7
|
constructor() {
|
|
@@ -2749,17 +2749,209 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImpor
|
|
|
2749
2749
|
}] } });
|
|
2750
2750
|
|
|
2751
2751
|
class PdmTableComponent {
|
|
2752
|
-
constructor() {
|
|
2752
|
+
constructor(renderer) {
|
|
2753
|
+
this.renderer = renderer;
|
|
2754
|
+
this.variant = 'default';
|
|
2755
|
+
this.reorderRows = false;
|
|
2756
|
+
this.dragHandleSelector = '[data-drag-handle],[data-slot=row-drag-handle],.row-drag-handle,[data-auto-drag-handle]';
|
|
2753
2757
|
this.className = '';
|
|
2758
|
+
this.rowOrderChange = new EventEmitter();
|
|
2759
|
+
this.cleanupListeners = [];
|
|
2760
|
+
this.draggedRow = null;
|
|
2761
|
+
}
|
|
2762
|
+
ngAfterViewInit() {
|
|
2763
|
+
this.syncReorderBehavior();
|
|
2764
|
+
}
|
|
2765
|
+
ngOnChanges(changes) {
|
|
2766
|
+
if (changes['reorderRows'] || changes['variant']) {
|
|
2767
|
+
this.syncReorderBehavior();
|
|
2768
|
+
}
|
|
2769
|
+
}
|
|
2770
|
+
ngOnDestroy() {
|
|
2771
|
+
this.cleanupReorderBehavior();
|
|
2772
|
+
}
|
|
2773
|
+
get wrapperClasses() {
|
|
2774
|
+
return [
|
|
2775
|
+
'relative w-full overflow-auto',
|
|
2776
|
+
this.variant === 'interactive' ? 'overflow-x-auto overflow-y-hidden rounded-xl border border-border bg-background' : '',
|
|
2777
|
+
this.variant === 'data' ? 'overflow-hidden rounded-md border border-border bg-background' : '',
|
|
2778
|
+
this.className
|
|
2779
|
+
];
|
|
2780
|
+
}
|
|
2781
|
+
get tableClasses() {
|
|
2782
|
+
return [
|
|
2783
|
+
'w-full caption-bottom text-sm',
|
|
2784
|
+
this.variant === 'data'
|
|
2785
|
+
? 'border-collapse text-foreground [&_thead_tr]:border-b [&_thead_tr]:border-border [&_tbody_tr]:border-b [&_tbody_tr]:border-border [&_tbody_tr:last-child]:border-b-0 [&_th]:h-10 [&_th]:px-2 [&_th]:text-left [&_th]:align-middle [&_th]:font-medium [&_td]:p-2 [&_td]:align-middle'
|
|
2786
|
+
: '',
|
|
2787
|
+
this.variant === 'interactive'
|
|
2788
|
+
? 'text-foreground [&_thead]:sticky [&_thead]:top-0 [&_thead]:z-10 [&_thead]:bg-muted/70 [&_thead_tr]:border-b [&_thead_tr]:border-border [&_th]:h-12 [&_th]:px-4 [&_th]:text-left [&_th]:align-middle [&_th]:text-sm [&_th]:font-medium [&_th]:whitespace-nowrap [&_tbody_tr]:border-b [&_tbody_tr]:border-border [&_tbody_tr]:transition-colors [&_tbody_tr:hover]:bg-muted/50 [&_tbody_tr:last-child]:border-b-0 [&_td]:h-14 [&_td]:px-4 [&_td]:align-middle [&_td]:text-sm [&_td]:whitespace-nowrap [&_td:first-child]:w-10 [&_td:last-child]:w-10 [&_svg]:text-muted-foreground'
|
|
2789
|
+
: ''
|
|
2790
|
+
];
|
|
2791
|
+
}
|
|
2792
|
+
syncReorderBehavior() {
|
|
2793
|
+
this.cleanupReorderBehavior();
|
|
2794
|
+
if (!this.isReorderEnabled) {
|
|
2795
|
+
return;
|
|
2796
|
+
}
|
|
2797
|
+
const tbody = this.getTbody();
|
|
2798
|
+
if (!tbody) {
|
|
2799
|
+
return;
|
|
2800
|
+
}
|
|
2801
|
+
this.setRowsDraggable(tbody, true);
|
|
2802
|
+
this.cleanupListeners.push(this.renderer.listen(tbody, 'mousedown', (event) => this.armDragFromHandle(event)), this.renderer.listen(tbody, 'dragstart', (event) => this.onDragStart(event)), this.renderer.listen(tbody, 'dragover', (event) => this.onDragOver(event, tbody)), this.renderer.listen(tbody, 'drop', (event) => this.onDrop(event)), this.renderer.listen(tbody, 'dragend', () => this.onDragEnd()));
|
|
2803
|
+
this.observer = new MutationObserver(() => this.setRowsDraggable(tbody, true));
|
|
2804
|
+
this.observer.observe(tbody, { childList: true });
|
|
2805
|
+
}
|
|
2806
|
+
cleanupReorderBehavior() {
|
|
2807
|
+
this.cleanupListeners.forEach((dispose) => dispose());
|
|
2808
|
+
this.cleanupListeners = [];
|
|
2809
|
+
if (this.observer) {
|
|
2810
|
+
this.observer.disconnect();
|
|
2811
|
+
this.observer = undefined;
|
|
2812
|
+
}
|
|
2813
|
+
const tbody = this.getTbody();
|
|
2814
|
+
if (tbody) {
|
|
2815
|
+
this.setRowsDraggable(tbody, false);
|
|
2816
|
+
}
|
|
2817
|
+
this.draggedRow = null;
|
|
2818
|
+
}
|
|
2819
|
+
get isReorderEnabled() {
|
|
2820
|
+
return this.reorderRows;
|
|
2821
|
+
}
|
|
2822
|
+
getTbody() {
|
|
2823
|
+
return this.tableElement?.nativeElement.tBodies.item(0) ?? null;
|
|
2824
|
+
}
|
|
2825
|
+
setRowsDraggable(tbody, enabled) {
|
|
2826
|
+
const rows = Array.from(tbody.rows);
|
|
2827
|
+
rows.forEach((row) => {
|
|
2828
|
+
this.syncAutoDragHandle(row, enabled);
|
|
2829
|
+
row.draggable = false;
|
|
2830
|
+
if (!enabled) {
|
|
2831
|
+
delete row.dataset['dragging'];
|
|
2832
|
+
delete row.dataset['dragArmed'];
|
|
2833
|
+
}
|
|
2834
|
+
});
|
|
2835
|
+
}
|
|
2836
|
+
syncAutoDragHandle(row, enabled) {
|
|
2837
|
+
const firstCell = row.cells.item(0);
|
|
2838
|
+
if (!firstCell) {
|
|
2839
|
+
return;
|
|
2840
|
+
}
|
|
2841
|
+
const existingAutoHandle = firstCell.querySelector('[data-auto-drag-handle]');
|
|
2842
|
+
if (!enabled) {
|
|
2843
|
+
existingAutoHandle?.remove();
|
|
2844
|
+
return;
|
|
2845
|
+
}
|
|
2846
|
+
const hasCustomHandle = !!firstCell.querySelector('[data-drag-handle],[data-slot=row-drag-handle],.row-drag-handle');
|
|
2847
|
+
if (hasCustomHandle || existingAutoHandle) {
|
|
2848
|
+
return;
|
|
2849
|
+
}
|
|
2850
|
+
const button = this.renderer.createElement('button');
|
|
2851
|
+
this.renderer.setAttribute(button, 'type', 'button');
|
|
2852
|
+
this.renderer.setAttribute(button, 'aria-label', 'Drag row');
|
|
2853
|
+
this.renderer.setAttribute(button, 'data-auto-drag-handle', 'true');
|
|
2854
|
+
this.renderer.addClass(button, 'inline-flex');
|
|
2855
|
+
this.renderer.addClass(button, 'h-7');
|
|
2856
|
+
this.renderer.addClass(button, 'w-7');
|
|
2857
|
+
this.renderer.addClass(button, 'items-center');
|
|
2858
|
+
this.renderer.addClass(button, 'justify-center');
|
|
2859
|
+
this.renderer.addClass(button, 'cursor-grab');
|
|
2860
|
+
this.renderer.addClass(button, 'active:cursor-grabbing');
|
|
2861
|
+
this.renderer.addClass(button, 'text-muted-foreground');
|
|
2862
|
+
const dots = this.renderer.createElement('span');
|
|
2863
|
+
this.renderer.addClass(dots, 'text-sm');
|
|
2864
|
+
this.renderer.addClass(dots, 'leading-none');
|
|
2865
|
+
this.renderer.setProperty(dots, 'textContent', '⋮⋮');
|
|
2866
|
+
this.renderer.appendChild(button, dots);
|
|
2867
|
+
this.renderer.insertBefore(firstCell, button, firstCell.firstChild);
|
|
2868
|
+
}
|
|
2869
|
+
onDragStart(event) {
|
|
2870
|
+
const target = event.target;
|
|
2871
|
+
const row = target?.closest('tr');
|
|
2872
|
+
if (!row) {
|
|
2873
|
+
return;
|
|
2874
|
+
}
|
|
2875
|
+
const handle = target?.closest(this.dragHandleSelector);
|
|
2876
|
+
const isArmed = row.dataset['dragArmed'] === 'true';
|
|
2877
|
+
if ((!handle || !row.contains(handle)) && !isArmed) {
|
|
2878
|
+
event.preventDefault();
|
|
2879
|
+
return;
|
|
2880
|
+
}
|
|
2881
|
+
this.draggedRow = row;
|
|
2882
|
+
this.draggedRow.dataset['dragging'] = 'true';
|
|
2883
|
+
if (event.dataTransfer) {
|
|
2884
|
+
event.dataTransfer.effectAllowed = 'move';
|
|
2885
|
+
event.dataTransfer.setData('text/plain', '');
|
|
2886
|
+
}
|
|
2887
|
+
}
|
|
2888
|
+
onDragOver(event, tbody) {
|
|
2889
|
+
if (!this.draggedRow) {
|
|
2890
|
+
return;
|
|
2891
|
+
}
|
|
2892
|
+
event.preventDefault();
|
|
2893
|
+
const target = event.target;
|
|
2894
|
+
const targetRow = target?.closest('tr');
|
|
2895
|
+
if (!targetRow || targetRow === this.draggedRow) {
|
|
2896
|
+
return;
|
|
2897
|
+
}
|
|
2898
|
+
const rect = targetRow.getBoundingClientRect();
|
|
2899
|
+
const shouldInsertBefore = event.clientY < rect.top + rect.height / 2;
|
|
2900
|
+
tbody.insertBefore(this.draggedRow, shouldInsertBefore ? targetRow : targetRow.nextSibling);
|
|
2901
|
+
}
|
|
2902
|
+
onDrop(event) {
|
|
2903
|
+
event.preventDefault();
|
|
2904
|
+
}
|
|
2905
|
+
onDragEnd() {
|
|
2906
|
+
const tbody = this.getTbody();
|
|
2907
|
+
if (tbody) {
|
|
2908
|
+
Array.from(tbody.rows).forEach((row) => {
|
|
2909
|
+
row.draggable = false;
|
|
2910
|
+
delete row.dataset['dragArmed'];
|
|
2911
|
+
});
|
|
2912
|
+
}
|
|
2913
|
+
if (this.draggedRow) {
|
|
2914
|
+
delete this.draggedRow.dataset['dragging'];
|
|
2915
|
+
this.draggedRow = null;
|
|
2916
|
+
}
|
|
2917
|
+
if (!tbody) {
|
|
2918
|
+
return;
|
|
2919
|
+
}
|
|
2920
|
+
const order = Array.from(tbody.rows).map((row, index) => row.getAttribute('data-row-id') || String(index));
|
|
2921
|
+
this.rowOrderChange.emit(order);
|
|
2922
|
+
}
|
|
2923
|
+
armDragFromHandle(event) {
|
|
2924
|
+
const target = event.target;
|
|
2925
|
+
const handle = target?.closest(this.dragHandleSelector);
|
|
2926
|
+
if (!handle) {
|
|
2927
|
+
return;
|
|
2928
|
+
}
|
|
2929
|
+
const row = handle.closest('tr');
|
|
2930
|
+
if (!row) {
|
|
2931
|
+
return;
|
|
2932
|
+
}
|
|
2933
|
+
row.draggable = true;
|
|
2934
|
+
row.dataset['dragArmed'] = 'true';
|
|
2754
2935
|
}
|
|
2755
2936
|
}
|
|
2756
|
-
PdmTableComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: PdmTableComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
2757
|
-
PdmTableComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.3.0", type: PdmTableComponent, selector: "pdm-table", inputs: { className: "className" }, ngImport: i0, template: "<div [ngClass]=\"['
|
|
2937
|
+
PdmTableComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: PdmTableComponent, deps: [{ token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Component });
|
|
2938
|
+
PdmTableComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.3.0", type: PdmTableComponent, selector: "pdm-table", inputs: { variant: "variant", reorderRows: "reorderRows", dragHandleSelector: "dragHandleSelector", className: "className" }, outputs: { rowOrderChange: "rowOrderChange" }, viewQueries: [{ propertyName: "tableElement", first: true, predicate: ["tableElement"], descendants: true }], usesOnChanges: true, ngImport: i0, template: "<div [ngClass]=\"wrapperClasses\" [attr.data-slot]=\"variant === 'interactive' ? 'table-container' : null\">\n <table #tableElement [ngClass]=\"tableClasses\" [attr.data-slot]=\"variant === 'interactive' ? 'table' : null\">\n <ng-content></ng-content>\n </table>\n</div>\n", dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
|
2758
2939
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: PdmTableComponent, decorators: [{
|
|
2759
2940
|
type: Component,
|
|
2760
|
-
args: [{ selector: 'pdm-table', changeDetection: ChangeDetectionStrategy.OnPush, template: "<div [ngClass]=\"['
|
|
2761
|
-
}], propDecorators: {
|
|
2941
|
+
args: [{ selector: 'pdm-table', changeDetection: ChangeDetectionStrategy.OnPush, template: "<div [ngClass]=\"wrapperClasses\" [attr.data-slot]=\"variant === 'interactive' ? 'table-container' : null\">\n <table #tableElement [ngClass]=\"tableClasses\" [attr.data-slot]=\"variant === 'interactive' ? 'table' : null\">\n <ng-content></ng-content>\n </table>\n</div>\n" }]
|
|
2942
|
+
}], ctorParameters: function () { return [{ type: i0.Renderer2 }]; }, propDecorators: { variant: [{
|
|
2943
|
+
type: Input
|
|
2944
|
+
}], reorderRows: [{
|
|
2945
|
+
type: Input
|
|
2946
|
+
}], dragHandleSelector: [{
|
|
2762
2947
|
type: Input
|
|
2948
|
+
}], className: [{
|
|
2949
|
+
type: Input
|
|
2950
|
+
}], rowOrderChange: [{
|
|
2951
|
+
type: Output
|
|
2952
|
+
}], tableElement: [{
|
|
2953
|
+
type: ViewChild,
|
|
2954
|
+
args: ['tableElement']
|
|
2763
2955
|
}] } });
|
|
2764
2956
|
|
|
2765
2957
|
class PdmTabsComponent {
|