pdm-ui-kit 0.1.17 → 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.
@@ -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() {
@@ -2694,24 +2694,45 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImpor
2694
2694
  }] } });
2695
2695
 
2696
2696
  class PdmSwitchComponent {
2697
- constructor() {
2697
+ constructor(cdr) {
2698
+ this.cdr = cdr;
2698
2699
  this.id = '';
2699
2700
  this.checked = false;
2700
2701
  this.disabled = false;
2701
2702
  this.label = '';
2702
2703
  this.className = '';
2704
+ this.size = 'default';
2703
2705
  this.checkedChange = new EventEmitter();
2704
2706
  }
2705
- onToggle(event) {
2706
- this.checkedChange.emit(event.target.checked);
2707
+ get rootClasses() {
2708
+ return [
2709
+ 'peer relative inline-flex shrink-0 items-center rounded-full border border-transparent outline-none transition-all focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50',
2710
+ this.size === 'sm' ? 'h-[14px] w-[24px]' : 'h-[18.4px] w-[32px]',
2711
+ this.checked ? 'bg-primary' : 'bg-input dark:bg-input/80'
2712
+ ];
2713
+ }
2714
+ get thumbClasses() {
2715
+ return [
2716
+ 'pointer-events-none block rounded-full bg-background ring-0 transition-transform',
2717
+ this.size === 'sm' ? 'size-3' : 'size-4',
2718
+ this.checked ? 'translate-x-[calc(100%-2px)]' : 'translate-x-0'
2719
+ ];
2720
+ }
2721
+ onToggle() {
2722
+ if (this.disabled)
2723
+ return;
2724
+ const next = !this.checked;
2725
+ this.checked = next;
2726
+ this.checkedChange.emit(next);
2727
+ this.cdr.markForCheck();
2707
2728
  }
2708
2729
  }
2709
- PdmSwitchComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: PdmSwitchComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2710
- PdmSwitchComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.3.0", type: PdmSwitchComponent, selector: "pdm-switch", inputs: { id: "id", checked: "checked", disabled: "disabled", label: "label", className: "className" }, outputs: { checkedChange: "checkedChange" }, ngImport: i0, template: "<label [attr.for]=\"id\" [ngClass]=\"['inline-flex items-center gap-2', className]\">\n <input\n [id]=\"id\"\n type=\"checkbox\"\n class=\"peer sr-only\"\n [checked]=\"checked\"\n [disabled]=\"disabled\"\n (change)=\"onToggle($event)\"\n />\n <span class=\"relative inline-flex h-6 w-11 items-center rounded-full border border-transparent bg-muted transition-colors peer-focus-visible:ring-2 peer-focus-visible:ring-ring peer-focus-visible:ring-offset-2 peer-focus-visible:ring-offset-background peer-disabled:opacity-50 peer-checked:bg-primary\">\n <span class=\"h-5 w-5 translate-x-0.5 rounded-full bg-background shadow-sm transition-transform peer-checked:translate-x-5\"></span>\n </span>\n <span *ngIf=\"label\" class=\"text-sm text-foreground\">{{ label }}</span>\n</label>\n", dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
2730
+ PdmSwitchComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: PdmSwitchComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
2731
+ PdmSwitchComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.3.0", type: PdmSwitchComponent, selector: "pdm-switch", inputs: { id: "id", checked: "checked", disabled: "disabled", label: "label", className: "className", size: "size" }, outputs: { checkedChange: "checkedChange" }, ngImport: i0, template: "<div [ngClass]=\"['flex items-center space-x-2', className]\">\n <button\n type=\"button\"\n role=\"switch\"\n [attr.aria-checked]=\"checked\"\n [attr.aria-disabled]=\"disabled\"\n [attr.data-state]=\"checked ? 'checked' : 'unchecked'\"\n [attr.data-disabled]=\"disabled ? 'true' : 'false'\"\n [attr.data-size]=\"size\"\n [attr.data-slot]=\"'switch'\"\n [attr.value]=\"checked ? 'on' : 'off'\"\n [id]=\"id\"\n [disabled]=\"disabled\"\n [ngClass]=\"rootClasses\"\n (click)=\"onToggle()\"\n >\n <span\n [attr.data-state]=\"checked ? 'checked' : 'unchecked'\"\n [attr.data-slot]=\"'switch-thumb'\"\n [ngClass]=\"thumbClasses\"\n ></span>\n </button>\n <label\n *ngIf=\"label\"\n [attr.for]=\"id\"\n [attr.data-slot]=\"'label'\"\n class=\"flex cursor-pointer items-center gap-2 text-sm leading-none font-medium select-none peer-disabled:cursor-not-allowed peer-disabled:opacity-50\"\n (click)=\"onToggle()\"\n >\n {{ label }}\n </label>\n</div>\n", dependencies: [{ kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
2711
2732
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: PdmSwitchComponent, decorators: [{
2712
2733
  type: Component,
2713
- args: [{ selector: 'pdm-switch', changeDetection: ChangeDetectionStrategy.OnPush, template: "<label [attr.for]=\"id\" [ngClass]=\"['inline-flex items-center gap-2', className]\">\n <input\n [id]=\"id\"\n type=\"checkbox\"\n class=\"peer sr-only\"\n [checked]=\"checked\"\n [disabled]=\"disabled\"\n (change)=\"onToggle($event)\"\n />\n <span class=\"relative inline-flex h-6 w-11 items-center rounded-full border border-transparent bg-muted transition-colors peer-focus-visible:ring-2 peer-focus-visible:ring-ring peer-focus-visible:ring-offset-2 peer-focus-visible:ring-offset-background peer-disabled:opacity-50 peer-checked:bg-primary\">\n <span class=\"h-5 w-5 translate-x-0.5 rounded-full bg-background shadow-sm transition-transform peer-checked:translate-x-5\"></span>\n </span>\n <span *ngIf=\"label\" class=\"text-sm text-foreground\">{{ label }}</span>\n</label>\n" }]
2714
- }], propDecorators: { id: [{
2734
+ args: [{ selector: 'pdm-switch', changeDetection: ChangeDetectionStrategy.OnPush, template: "<div [ngClass]=\"['flex items-center space-x-2', className]\">\n <button\n type=\"button\"\n role=\"switch\"\n [attr.aria-checked]=\"checked\"\n [attr.aria-disabled]=\"disabled\"\n [attr.data-state]=\"checked ? 'checked' : 'unchecked'\"\n [attr.data-disabled]=\"disabled ? 'true' : 'false'\"\n [attr.data-size]=\"size\"\n [attr.data-slot]=\"'switch'\"\n [attr.value]=\"checked ? 'on' : 'off'\"\n [id]=\"id\"\n [disabled]=\"disabled\"\n [ngClass]=\"rootClasses\"\n (click)=\"onToggle()\"\n >\n <span\n [attr.data-state]=\"checked ? 'checked' : 'unchecked'\"\n [attr.data-slot]=\"'switch-thumb'\"\n [ngClass]=\"thumbClasses\"\n ></span>\n </button>\n <label\n *ngIf=\"label\"\n [attr.for]=\"id\"\n [attr.data-slot]=\"'label'\"\n class=\"flex cursor-pointer items-center gap-2 text-sm leading-none font-medium select-none peer-disabled:cursor-not-allowed peer-disabled:opacity-50\"\n (click)=\"onToggle()\"\n >\n {{ label }}\n </label>\n</div>\n" }]
2735
+ }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }]; }, propDecorators: { id: [{
2715
2736
  type: Input
2716
2737
  }], checked: [{
2717
2738
  type: Input
@@ -2721,22 +2742,216 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImpor
2721
2742
  type: Input
2722
2743
  }], className: [{
2723
2744
  type: Input
2745
+ }], size: [{
2746
+ type: Input
2724
2747
  }], checkedChange: [{
2725
2748
  type: Output
2726
2749
  }] } });
2727
2750
 
2728
2751
  class PdmTableComponent {
2729
- 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]';
2730
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';
2731
2935
  }
2732
2936
  }
2733
- PdmTableComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: PdmTableComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2734
- 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]=\"['relative w-full overflow-auto', className]\">\n <table class=\"w-full caption-bottom text-sm\">\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 });
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 });
2735
2939
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: PdmTableComponent, decorators: [{
2736
2940
  type: Component,
2737
- args: [{ selector: 'pdm-table', changeDetection: ChangeDetectionStrategy.OnPush, template: "<div [ngClass]=\"['relative w-full overflow-auto', className]\">\n <table class=\"w-full caption-bottom text-sm\">\n <ng-content></ng-content>\n </table>\n</div>\n" }]
2738
- }], propDecorators: { className: [{
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: [{
2739
2945
  type: Input
2946
+ }], dragHandleSelector: [{
2947
+ type: Input
2948
+ }], className: [{
2949
+ type: Input
2950
+ }], rowOrderChange: [{
2951
+ type: Output
2952
+ }], tableElement: [{
2953
+ type: ViewChild,
2954
+ args: ['tableElement']
2740
2955
  }] } });
2741
2956
 
2742
2957
  class PdmTabsComponent {