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() {
@@ -2700,24 +2700,45 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImpor
2700
2700
  }] } });
2701
2701
 
2702
2702
  class PdmSwitchComponent {
2703
- constructor() {
2703
+ constructor(cdr) {
2704
+ this.cdr = cdr;
2704
2705
  this.id = '';
2705
2706
  this.checked = false;
2706
2707
  this.disabled = false;
2707
2708
  this.label = '';
2708
2709
  this.className = '';
2710
+ this.size = 'default';
2709
2711
  this.checkedChange = new EventEmitter();
2710
2712
  }
2711
- onToggle(event) {
2712
- this.checkedChange.emit(event.target.checked);
2713
+ get rootClasses() {
2714
+ return [
2715
+ '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',
2716
+ this.size === 'sm' ? 'h-[14px] w-[24px]' : 'h-[18.4px] w-[32px]',
2717
+ this.checked ? 'bg-primary' : 'bg-input dark:bg-input/80'
2718
+ ];
2719
+ }
2720
+ get thumbClasses() {
2721
+ return [
2722
+ 'pointer-events-none block rounded-full bg-background ring-0 transition-transform',
2723
+ this.size === 'sm' ? 'size-3' : 'size-4',
2724
+ this.checked ? 'translate-x-[calc(100%-2px)]' : 'translate-x-0'
2725
+ ];
2726
+ }
2727
+ onToggle() {
2728
+ if (this.disabled)
2729
+ return;
2730
+ const next = !this.checked;
2731
+ this.checked = next;
2732
+ this.checkedChange.emit(next);
2733
+ this.cdr.markForCheck();
2713
2734
  }
2714
2735
  }
2715
- PdmSwitchComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: PdmSwitchComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2716
- 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 });
2736
+ PdmSwitchComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: PdmSwitchComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
2737
+ 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 });
2717
2738
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: PdmSwitchComponent, decorators: [{
2718
2739
  type: Component,
2719
- 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" }]
2720
- }], propDecorators: { id: [{
2740
+ 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" }]
2741
+ }], ctorParameters: function () { return [{ type: i0.ChangeDetectorRef }]; }, propDecorators: { id: [{
2721
2742
  type: Input
2722
2743
  }], checked: [{
2723
2744
  type: Input
@@ -2727,22 +2748,217 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImpor
2727
2748
  type: Input
2728
2749
  }], className: [{
2729
2750
  type: Input
2751
+ }], size: [{
2752
+ type: Input
2730
2753
  }], checkedChange: [{
2731
2754
  type: Output
2732
2755
  }] } });
2733
2756
 
2734
2757
  class PdmTableComponent {
2735
- constructor() {
2758
+ constructor(renderer) {
2759
+ this.renderer = renderer;
2760
+ this.variant = 'default';
2761
+ this.reorderRows = false;
2762
+ this.dragHandleSelector = '[data-drag-handle],[data-slot=row-drag-handle],.row-drag-handle,[data-auto-drag-handle]';
2736
2763
  this.className = '';
2764
+ this.rowOrderChange = new EventEmitter();
2765
+ this.cleanupListeners = [];
2766
+ this.draggedRow = null;
2767
+ }
2768
+ ngAfterViewInit() {
2769
+ this.syncReorderBehavior();
2770
+ }
2771
+ ngOnChanges(changes) {
2772
+ if (changes['reorderRows'] || changes['variant']) {
2773
+ this.syncReorderBehavior();
2774
+ }
2775
+ }
2776
+ ngOnDestroy() {
2777
+ this.cleanupReorderBehavior();
2778
+ }
2779
+ get wrapperClasses() {
2780
+ return [
2781
+ 'relative w-full overflow-auto',
2782
+ this.variant === 'interactive' ? 'overflow-x-auto overflow-y-hidden rounded-xl border border-border bg-background' : '',
2783
+ this.variant === 'data' ? 'overflow-hidden rounded-md border border-border bg-background' : '',
2784
+ this.className
2785
+ ];
2786
+ }
2787
+ get tableClasses() {
2788
+ return [
2789
+ 'w-full caption-bottom text-sm',
2790
+ this.variant === 'data'
2791
+ ? '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'
2792
+ : '',
2793
+ this.variant === 'interactive'
2794
+ ? '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'
2795
+ : ''
2796
+ ];
2797
+ }
2798
+ syncReorderBehavior() {
2799
+ this.cleanupReorderBehavior();
2800
+ if (!this.isReorderEnabled) {
2801
+ return;
2802
+ }
2803
+ const tbody = this.getTbody();
2804
+ if (!tbody) {
2805
+ return;
2806
+ }
2807
+ this.setRowsDraggable(tbody, true);
2808
+ 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()));
2809
+ this.observer = new MutationObserver(() => this.setRowsDraggable(tbody, true));
2810
+ this.observer.observe(tbody, { childList: true });
2811
+ }
2812
+ cleanupReorderBehavior() {
2813
+ this.cleanupListeners.forEach((dispose) => dispose());
2814
+ this.cleanupListeners = [];
2815
+ if (this.observer) {
2816
+ this.observer.disconnect();
2817
+ this.observer = undefined;
2818
+ }
2819
+ const tbody = this.getTbody();
2820
+ if (tbody) {
2821
+ this.setRowsDraggable(tbody, false);
2822
+ }
2823
+ this.draggedRow = null;
2824
+ }
2825
+ get isReorderEnabled() {
2826
+ return this.reorderRows;
2827
+ }
2828
+ getTbody() {
2829
+ var _a, _b;
2830
+ return (_b = (_a = this.tableElement) === null || _a === void 0 ? void 0 : _a.nativeElement.tBodies.item(0)) !== null && _b !== void 0 ? _b : null;
2831
+ }
2832
+ setRowsDraggable(tbody, enabled) {
2833
+ const rows = Array.from(tbody.rows);
2834
+ rows.forEach((row) => {
2835
+ this.syncAutoDragHandle(row, enabled);
2836
+ row.draggable = false;
2837
+ if (!enabled) {
2838
+ delete row.dataset['dragging'];
2839
+ delete row.dataset['dragArmed'];
2840
+ }
2841
+ });
2842
+ }
2843
+ syncAutoDragHandle(row, enabled) {
2844
+ const firstCell = row.cells.item(0);
2845
+ if (!firstCell) {
2846
+ return;
2847
+ }
2848
+ const existingAutoHandle = firstCell.querySelector('[data-auto-drag-handle]');
2849
+ if (!enabled) {
2850
+ existingAutoHandle === null || existingAutoHandle === void 0 ? void 0 : existingAutoHandle.remove();
2851
+ return;
2852
+ }
2853
+ const hasCustomHandle = !!firstCell.querySelector('[data-drag-handle],[data-slot=row-drag-handle],.row-drag-handle');
2854
+ if (hasCustomHandle || existingAutoHandle) {
2855
+ return;
2856
+ }
2857
+ const button = this.renderer.createElement('button');
2858
+ this.renderer.setAttribute(button, 'type', 'button');
2859
+ this.renderer.setAttribute(button, 'aria-label', 'Drag row');
2860
+ this.renderer.setAttribute(button, 'data-auto-drag-handle', 'true');
2861
+ this.renderer.addClass(button, 'inline-flex');
2862
+ this.renderer.addClass(button, 'h-7');
2863
+ this.renderer.addClass(button, 'w-7');
2864
+ this.renderer.addClass(button, 'items-center');
2865
+ this.renderer.addClass(button, 'justify-center');
2866
+ this.renderer.addClass(button, 'cursor-grab');
2867
+ this.renderer.addClass(button, 'active:cursor-grabbing');
2868
+ this.renderer.addClass(button, 'text-muted-foreground');
2869
+ const dots = this.renderer.createElement('span');
2870
+ this.renderer.addClass(dots, 'text-sm');
2871
+ this.renderer.addClass(dots, 'leading-none');
2872
+ this.renderer.setProperty(dots, 'textContent', '⋮⋮');
2873
+ this.renderer.appendChild(button, dots);
2874
+ this.renderer.insertBefore(firstCell, button, firstCell.firstChild);
2875
+ }
2876
+ onDragStart(event) {
2877
+ const target = event.target;
2878
+ const row = target === null || target === void 0 ? void 0 : target.closest('tr');
2879
+ if (!row) {
2880
+ return;
2881
+ }
2882
+ const handle = target === null || target === void 0 ? void 0 : target.closest(this.dragHandleSelector);
2883
+ const isArmed = row.dataset['dragArmed'] === 'true';
2884
+ if ((!handle || !row.contains(handle)) && !isArmed) {
2885
+ event.preventDefault();
2886
+ return;
2887
+ }
2888
+ this.draggedRow = row;
2889
+ this.draggedRow.dataset['dragging'] = 'true';
2890
+ if (event.dataTransfer) {
2891
+ event.dataTransfer.effectAllowed = 'move';
2892
+ event.dataTransfer.setData('text/plain', '');
2893
+ }
2894
+ }
2895
+ onDragOver(event, tbody) {
2896
+ if (!this.draggedRow) {
2897
+ return;
2898
+ }
2899
+ event.preventDefault();
2900
+ const target = event.target;
2901
+ const targetRow = target === null || target === void 0 ? void 0 : target.closest('tr');
2902
+ if (!targetRow || targetRow === this.draggedRow) {
2903
+ return;
2904
+ }
2905
+ const rect = targetRow.getBoundingClientRect();
2906
+ const shouldInsertBefore = event.clientY < rect.top + rect.height / 2;
2907
+ tbody.insertBefore(this.draggedRow, shouldInsertBefore ? targetRow : targetRow.nextSibling);
2908
+ }
2909
+ onDrop(event) {
2910
+ event.preventDefault();
2911
+ }
2912
+ onDragEnd() {
2913
+ const tbody = this.getTbody();
2914
+ if (tbody) {
2915
+ Array.from(tbody.rows).forEach((row) => {
2916
+ row.draggable = false;
2917
+ delete row.dataset['dragArmed'];
2918
+ });
2919
+ }
2920
+ if (this.draggedRow) {
2921
+ delete this.draggedRow.dataset['dragging'];
2922
+ this.draggedRow = null;
2923
+ }
2924
+ if (!tbody) {
2925
+ return;
2926
+ }
2927
+ const order = Array.from(tbody.rows).map((row, index) => row.getAttribute('data-row-id') || String(index));
2928
+ this.rowOrderChange.emit(order);
2929
+ }
2930
+ armDragFromHandle(event) {
2931
+ const target = event.target;
2932
+ const handle = target === null || target === void 0 ? void 0 : target.closest(this.dragHandleSelector);
2933
+ if (!handle) {
2934
+ return;
2935
+ }
2936
+ const row = handle.closest('tr');
2937
+ if (!row) {
2938
+ return;
2939
+ }
2940
+ row.draggable = true;
2941
+ row.dataset['dragArmed'] = 'true';
2737
2942
  }
2738
2943
  }
2739
- PdmTableComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: PdmTableComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
2740
- 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 });
2944
+ PdmTableComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: PdmTableComponent, deps: [{ token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Component });
2945
+ 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 });
2741
2946
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.3.0", ngImport: i0, type: PdmTableComponent, decorators: [{
2742
2947
  type: Component,
2743
- 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" }]
2744
- }], propDecorators: { className: [{
2948
+ 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" }]
2949
+ }], ctorParameters: function () { return [{ type: i0.Renderer2 }]; }, propDecorators: { variant: [{
2745
2950
  type: Input
2951
+ }], reorderRows: [{
2952
+ type: Input
2953
+ }], dragHandleSelector: [{
2954
+ type: Input
2955
+ }], className: [{
2956
+ type: Input
2957
+ }], rowOrderChange: [{
2958
+ type: Output
2959
+ }], tableElement: [{
2960
+ type: ViewChild,
2961
+ args: ['tableElement']
2746
2962
  }] } });
2747
2963
 
2748
2964
  class PdmTabsComponent {