@cuby-ui/cdk 0.0.231 → 0.0.233

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,8 +1,8 @@
1
1
  import * as i0 from '@angular/core';
2
- import { QueryList, inject, ChangeDetectorRef, NgZone, InjectionToken, ElementRef, Directive, Output, Input, Injectable, HostListener, EventEmitter, HostBinding, ViewContainerRef, TemplateRef, input, effect, Pipe } from '@angular/core';
2
+ import { QueryList, inject, ChangeDetectorRef, NgZone, InjectionToken, ElementRef, Directive, Output, Input, Injectable, Renderer2, signal, input, output, HostListener, EventEmitter, HostBinding, ViewContainerRef, TemplateRef, effect, Pipe } from '@angular/core';
3
3
  import { __decorate, __metadata } from 'tslib';
4
4
  import { NgControl, NgModel, NG_VALUE_ACCESSOR } from '@angular/forms';
5
- import { pipe, switchMap, EMPTY, fromEvent, tap, Observable, asyncScheduler, BehaviorSubject, timer, map, startWith, share, merge, filter, takeUntil, repeat, withLatestFrom, of, take, distinctUntilChanged, skip, Subject } from 'rxjs';
5
+ import { pipe, switchMap, EMPTY, fromEvent, tap, Observable, asyncScheduler, BehaviorSubject, timer, map, startWith, share, merge, filter, takeUntil, repeat, withLatestFrom, of, take, distinctUntilChanged, skip, Subject, interval } from 'rxjs';
6
6
  import { DOCUMENT } from '@angular/common';
7
7
  import { ɵAnimationEngine as _AnimationEngine } from '@angular/animations/browser';
8
8
  import { toSignal } from '@angular/core/rxjs-interop';
@@ -796,6 +796,222 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImpo
796
796
  type: Injectable
797
797
  }], ctorParameters: () => [{ type: undefined }, { type: undefined }, { type: undefined }] });
798
798
 
799
+ class CuiDragListDirective {
800
+ constructor() {
801
+ this.renderer = inject(Renderer2);
802
+ this.element = inject(ElementRef).nativeElement;
803
+ this.id = inject(CuiIdService).generate();
804
+ this.listId = `${this.id}-list`;
805
+ this.renderer.setAttribute(this.element, 'id', this.listId);
806
+ }
807
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: CuiDragListDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
808
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.13", type: CuiDragListDirective, isStandalone: true, selector: "[cuiDragList]", ngImport: i0 }); }
809
+ }
810
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: CuiDragListDirective, decorators: [{
811
+ type: Directive,
812
+ args: [{
813
+ selector: '[cuiDragList]',
814
+ standalone: true
815
+ }]
816
+ }], ctorParameters: () => [] });
817
+
818
+ class CuiDragDropDirective {
819
+ constructor() {
820
+ this.zone = inject(NgZone);
821
+ this.document = inject(DOCUMENT);
822
+ this.renderer = inject(Renderer2);
823
+ this.element = inject(ElementRef).nativeElement;
824
+ this.dragListDirective = inject(CuiDragListDirective);
825
+ this.PLACEHOLDER_CLASS = 'cc-drag-drop-placeholder';
826
+ this.listId = this.dragListDirective.listId;
827
+ this.itemAttribute = `${this.listId}-drag-item`;
828
+ this.abortController = new AbortController();
829
+ this.hostAbortController = new AbortController();
830
+ this.draggingElement = signal(null);
831
+ this.placeholderElement = signal(null);
832
+ this.dragData = signal({});
833
+ this.disabled = input(false);
834
+ this.elementDragged = output();
835
+ this.initDragItem();
836
+ this.initPointerEvents(this.element);
837
+ }
838
+ ngOnDestroy() {
839
+ this.destroyEvents();
840
+ }
841
+ changePointerEvents(element) {
842
+ this.hostAbortController.abort();
843
+ this.hostAbortController = new AbortController();
844
+ this.initPointerEvents(element);
845
+ }
846
+ onDrag(clientX, clientY) {
847
+ if (!this.draggingElement()) {
848
+ return;
849
+ }
850
+ const elementsFromPoint = this.document.elementsFromPoint(clientX, clientY);
851
+ const elementFromPoint = elementsFromPoint.find((element) => element.closest(`#${this.listId}`));
852
+ if (!elementFromPoint) {
853
+ return;
854
+ }
855
+ const targetElement = elementFromPoint.closest(`[${this.itemAttribute}]`);
856
+ if (!targetElement || targetElement === this.draggingElement()) {
857
+ return;
858
+ }
859
+ this.configurateDragData(targetElement, clientY);
860
+ }
861
+ onDragStart(event) {
862
+ if (this.disabled()) {
863
+ return;
864
+ }
865
+ let isClicked = true;
866
+ const elementClientRect = this.element.getBoundingClientRect();
867
+ const shiftX = event.clientX - elementClientRect.left;
868
+ const shiftY = event.clientY - elementClientRect.top;
869
+ this.prevIndex = this.calculatePreviousIndex();
870
+ this.document.addEventListener('pointermove', ({ clientX, clientY }) => {
871
+ if (isClicked) {
872
+ this.prepareMoving();
873
+ isClicked = false;
874
+ }
875
+ const draggingElement = this.draggingElement();
876
+ this.renderer.setStyle(draggingElement, 'left', clientX - shiftX + 'px');
877
+ this.renderer.setStyle(draggingElement, 'top', clientY - shiftY + 'px');
878
+ this.onDrag(clientX, clientY);
879
+ }, { signal: this.abortController.signal });
880
+ }
881
+ onDragEnd() {
882
+ const { targetElement, pointer } = this.dragData();
883
+ if (targetElement && pointer) {
884
+ this.elementDragged.emit({
885
+ index: this.index,
886
+ prevIndex: this.prevIndex,
887
+ targetElement,
888
+ pointer
889
+ });
890
+ }
891
+ // remove document events
892
+ this.abortController.abort();
893
+ this.abortController = new AbortController();
894
+ this.removeDragElement();
895
+ this.removePlaceholder();
896
+ this.dragData.set({});
897
+ }
898
+ initDragItem() {
899
+ this.renderer.setAttribute(this.element, this.itemAttribute, 'true');
900
+ }
901
+ initPointerEvents(element) {
902
+ const signal = this.hostAbortController.signal;
903
+ this.zone.runOutsideAngular(() => {
904
+ element.addEventListener('pointerup', this.onDragEnd.bind(this), { signal });
905
+ element.addEventListener('pointerdown', this.onDragStart.bind(this), { signal });
906
+ });
907
+ }
908
+ destroyEvents() {
909
+ this.hostAbortController.abort();
910
+ this.abortController.abort();
911
+ }
912
+ prepareMoving() {
913
+ const placeholderElement = this.createPlaceholderElement();
914
+ const draggingElement = this.createDragElement();
915
+ this.document.addEventListener('pointerup', this.onDragEnd.bind(this), {
916
+ signal: this.abortController.signal
917
+ });
918
+ this.element.after(placeholderElement);
919
+ this.draggingElement.set(draggingElement);
920
+ this.element.remove();
921
+ this.document.body.append(draggingElement);
922
+ }
923
+ configurateDragData(targetElement, clientY) {
924
+ const placeholderElement = this.placeholderElement();
925
+ const boundingRect = targetElement.getBoundingClientRect();
926
+ const middleY = boundingRect.top + boundingRect.height / 2;
927
+ if (clientY < middleY) {
928
+ targetElement.before(placeholderElement);
929
+ this.dragData.set({ targetElement, pointer: 'BEFORE' });
930
+ }
931
+ else {
932
+ targetElement.after(placeholderElement);
933
+ this.dragData.set({ targetElement, pointer: 'AFTER' });
934
+ }
935
+ this.index = this.calculateIndex(placeholderElement);
936
+ }
937
+ createDragElement() {
938
+ const width = this.element.clientWidth;
939
+ const draggingElement = this.element.cloneNode(true);
940
+ this.renderer.setStyle(draggingElement, 'position', 'fixed');
941
+ this.renderer.setStyle(draggingElement, 'display', 'block');
942
+ this.renderer.setStyle(draggingElement, 'margin', '0');
943
+ this.renderer.setStyle(draggingElement, 'width', `${width}px`);
944
+ return draggingElement;
945
+ }
946
+ createPlaceholderElement() {
947
+ const element = this.placeholderElement();
948
+ if (element) {
949
+ return element;
950
+ }
951
+ const placeholderElement = this.renderer.createElement('div');
952
+ this.renderer.addClass(placeholderElement, this.PLACEHOLDER_CLASS);
953
+ this.placeholderElement.set(placeholderElement);
954
+ return placeholderElement;
955
+ }
956
+ removeDragElement() {
957
+ const draggingElement = this.draggingElement();
958
+ if (!draggingElement) {
959
+ return;
960
+ }
961
+ draggingElement.remove();
962
+ this.draggingElement.set(null);
963
+ }
964
+ removePlaceholder() {
965
+ const placeholderElement = this.placeholderElement();
966
+ if (!placeholderElement) {
967
+ return;
968
+ }
969
+ placeholderElement.after(this.element);
970
+ placeholderElement.remove();
971
+ this.placeholderElement.set(null);
972
+ }
973
+ calculateIndex(placeholderElement) {
974
+ const childNodes = placeholderElement.parentElement.childNodes;
975
+ const elements = Array.from(childNodes).filter((node) => node instanceof HTMLElement);
976
+ return elements.indexOf(placeholderElement);
977
+ }
978
+ calculatePreviousIndex() {
979
+ let index = 0;
980
+ let currentElement = this.element;
981
+ while (currentElement && currentElement.previousElementSibling) {
982
+ index++;
983
+ currentElement = currentElement.previousElementSibling;
984
+ }
985
+ return index;
986
+ }
987
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: CuiDragDropDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
988
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "18.2.13", type: CuiDragDropDirective, isStandalone: true, selector: "[cuiDragDrop]", inputs: { disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { elementDragged: "elementDragged" }, ngImport: i0 }); }
989
+ }
990
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: CuiDragDropDirective, decorators: [{
991
+ type: Directive,
992
+ args: [{
993
+ selector: '[cuiDragDrop]',
994
+ standalone: true
995
+ }]
996
+ }], ctorParameters: () => [] });
997
+
998
+ class CuiDragPointerDirective {
999
+ constructor() {
1000
+ this.dragDropDirective = inject(CuiDragDropDirective);
1001
+ this.element = inject(ElementRef).nativeElement;
1002
+ this.dragDropDirective.changePointerEvents(this.element);
1003
+ }
1004
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: CuiDragPointerDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
1005
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.13", type: CuiDragPointerDirective, isStandalone: true, selector: "[cuiDragPointer]", ngImport: i0 }); }
1006
+ }
1007
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: CuiDragPointerDirective, decorators: [{
1008
+ type: Directive,
1009
+ args: [{
1010
+ selector: '[cuiDragPointer]',
1011
+ standalone: true
1012
+ }]
1013
+ }], ctorParameters: () => [] });
1014
+
799
1015
  class CuiAutoResizingDirective {
800
1016
  constructor() {
801
1017
  this.window = inject(CUI_WINDOW);
@@ -858,6 +1074,82 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImpo
858
1074
  args: ['input']
859
1075
  }] } });
860
1076
 
1077
+ class CuiHandleScrollDirective {
1078
+ constructor() {
1079
+ this.window = inject(CUI_WINDOW);
1080
+ this.document = inject(DOCUMENT);
1081
+ this.renderer = inject(Renderer2);
1082
+ this.zone = inject(NgZone);
1083
+ this.abortController = new AbortController();
1084
+ this.SCROLL_AREA_HEIGHT = 100;
1085
+ this.scrollGapElements = signal(null);
1086
+ this.scrollSpeed = input(100);
1087
+ }
1088
+ ngOnDestroy() {
1089
+ this.removeSubscription();
1090
+ }
1091
+ onTargetMove() {
1092
+ const signal = this.abortController.signal;
1093
+ this.zone.runOutsideAngular(this.initScrollEvent.bind(this, signal));
1094
+ }
1095
+ initScrollEvent(signal) {
1096
+ this.document.addEventListener('pointermove', ({ clientY }) => this.handleScroll(clientY), { signal });
1097
+ this.document.addEventListener('pointerup', () => {
1098
+ this.scrollGapElements()?.forEach((element) => element.remove());
1099
+ this.scrollGapElements.set(null);
1100
+ this.removeSubscription();
1101
+ this.abortController.abort();
1102
+ this.abortController = new AbortController();
1103
+ }, { signal });
1104
+ }
1105
+ handleScroll(clientY) {
1106
+ const windowHeight = this.document.documentElement.clientHeight;
1107
+ const scrollSpeed = this.scrollSpeed();
1108
+ if (!this.scrollGapElements()) {
1109
+ this.setScrollGapElements();
1110
+ }
1111
+ if (clientY <= this.SCROLL_AREA_HEIGHT) {
1112
+ this.startScrolling(-scrollSpeed);
1113
+ return;
1114
+ }
1115
+ if (clientY >= windowHeight - this.SCROLL_AREA_HEIGHT) {
1116
+ this.startScrolling(scrollSpeed);
1117
+ return;
1118
+ }
1119
+ this.removeSubscription();
1120
+ }
1121
+ setScrollGapElements() {
1122
+ const scrollGapElement = this.renderer.createElement('div');
1123
+ this.renderer.setStyle(scrollGapElement, 'position', 'fixed');
1124
+ this.renderer.setStyle(scrollGapElement, 'width', '100%');
1125
+ this.renderer.setStyle(scrollGapElement, 'height', '48px');
1126
+ this.renderer.setStyle(scrollGapElement, 'top', '0');
1127
+ const scrollGapBottomElement = scrollGapElement.cloneNode(true);
1128
+ this.renderer.appendChild(this.document.body, scrollGapElement);
1129
+ this.renderer.appendChild(this.document.body, scrollGapBottomElement);
1130
+ this.scrollGapElements.set([scrollGapElement, scrollGapBottomElement]);
1131
+ }
1132
+ startScrolling(speed) {
1133
+ this.removeSubscription();
1134
+ this.scrollSubscription = interval(this.scrollSpeed()).subscribe(() => this.window.scrollBy({ top: speed, behavior: 'smooth' }));
1135
+ }
1136
+ removeSubscription() {
1137
+ this.scrollSubscription?.unsubscribe();
1138
+ }
1139
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: CuiHandleScrollDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
1140
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "18.2.13", type: CuiHandleScrollDirective, isStandalone: true, selector: "[cuiHandleScroll]", inputs: { scrollSpeed: { classPropertyName: "scrollSpeed", publicName: "scrollSpeed", isSignal: true, isRequired: false, transformFunction: null } }, host: { listeners: { "pointerdown": "onTargetMove()" } }, ngImport: i0 }); }
1141
+ }
1142
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImport: i0, type: CuiHandleScrollDirective, decorators: [{
1143
+ type: Directive,
1144
+ args: [{
1145
+ selector: '[cuiHandleScroll]',
1146
+ standalone: true,
1147
+ host: {
1148
+ '(pointerdown)': 'onTargetMove()'
1149
+ }
1150
+ }]
1151
+ }] });
1152
+
861
1153
  class CuiClickOutsideDirective {
862
1154
  constructor() {
863
1155
  this.element = inject(ElementRef).nativeElement;
@@ -1158,5 +1450,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImpo
1158
1450
  * Generated bundle index. Do not edit.
1159
1451
  */
1160
1452
 
1161
- export { CUI_ACTIVE_ELEMENT, CUI_ANIMATION_FRAME, CUI_FALSE_HANDLER, CUI_HISTORY, CUI_IOS_REG_EXP, CUI_IS_ANDROID, CUI_IS_CYPRESS, CUI_IS_E2E, CUI_IS_IOS, CUI_IS_MOBILE, CUI_IS_PLAYWRIGHT, CUI_IS_TOUCH, CUI_IS_WEBKIT, CUI_LOCAL_STORAGE, CUI_NAVIGATOR, CUI_PLATFORM, CUI_REMOVED_ELEMENT, CUI_SAFARI_REG_EXP, CUI_SESSION_STORAGE, CUI_TRUE_HANDLER, CUI_USER_AGENT, CUI_WINDOW, CuiActiveZone, CuiAutoResizingDirective, CuiClickOutsideDirective, CuiContentEditableValueAccessorDirective, CuiDestroyService, CuiDimensionsObserverDirective, CuiElementDirective, CuiFilterPipe, CuiFocusTrapDirective, CuiHovered, CuiHoveredService, CuiIdService, CuiItemDirective, CuiLadderListDirective, CuiLetContext, CuiLetDirective, CuiLetDirectiveImpl, CuiPopoverService, CuiPureException, CuiTargetDirective, CuiTime, EMPTY_ARRAY, EMPTY_CLIENT_RECT, EMPTY_FUNCTION, EMPTY_QUERY, cuiArrayRemove, cuiBlurNativeFocused, cuiClamp, cuiContainsOrAfter, cuiCreateToken, cuiCreateTokenFromFactory, cuiGetActualTarget, cuiGetClosestFocusable, cuiGetDocumentOrShadowRoot, cuiGetElementObscures, cuiGetNativeFocused, cuiHovered, cuiIfMap, cuiInjectElement, cuiIsElement, cuiIsHTMLElement, cuiIsInput, cuiIsIos, cuiIsNativeFocused, cuiIsNativeKeyboardFocusable, cuiIsNativeMouseFocusable, cuiIsPresent, cuiIsTextNode, cuiIsTextarea, cuiIsTextfield, cuiPointToClientRect, cuiProvide, cuiPure, cuiPx, cuiTypedFromEvent, cuiWatch, cuiZoneOptimized, cuiZonefree, cuiZonefreeScheduler, cuiZonefull, cuiZonefullScheduler, svgNodeFilter };
1453
+ export { CUI_ACTIVE_ELEMENT, CUI_ANIMATION_FRAME, CUI_FALSE_HANDLER, CUI_HISTORY, CUI_IOS_REG_EXP, CUI_IS_ANDROID, CUI_IS_CYPRESS, CUI_IS_E2E, CUI_IS_IOS, CUI_IS_MOBILE, CUI_IS_PLAYWRIGHT, CUI_IS_TOUCH, CUI_IS_WEBKIT, CUI_LOCAL_STORAGE, CUI_NAVIGATOR, CUI_PLATFORM, CUI_REMOVED_ELEMENT, CUI_SAFARI_REG_EXP, CUI_SESSION_STORAGE, CUI_TRUE_HANDLER, CUI_USER_AGENT, CUI_WINDOW, CuiActiveZone, CuiAutoResizingDirective, CuiClickOutsideDirective, CuiContentEditableValueAccessorDirective, CuiDestroyService, CuiDimensionsObserverDirective, CuiDragDropDirective, CuiDragListDirective, CuiDragPointerDirective, CuiElementDirective, CuiFilterPipe, CuiFocusTrapDirective, CuiHandleScrollDirective, CuiHovered, CuiHoveredService, CuiIdService, CuiItemDirective, CuiLadderListDirective, CuiLetContext, CuiLetDirective, CuiLetDirectiveImpl, CuiPopoverService, CuiPureException, CuiTargetDirective, CuiTime, EMPTY_ARRAY, EMPTY_CLIENT_RECT, EMPTY_FUNCTION, EMPTY_QUERY, cuiArrayRemove, cuiBlurNativeFocused, cuiClamp, cuiContainsOrAfter, cuiCreateToken, cuiCreateTokenFromFactory, cuiGetActualTarget, cuiGetClosestFocusable, cuiGetDocumentOrShadowRoot, cuiGetElementObscures, cuiGetNativeFocused, cuiHovered, cuiIfMap, cuiInjectElement, cuiIsElement, cuiIsHTMLElement, cuiIsInput, cuiIsIos, cuiIsNativeFocused, cuiIsNativeKeyboardFocusable, cuiIsNativeMouseFocusable, cuiIsPresent, cuiIsTextNode, cuiIsTextarea, cuiIsTextfield, cuiPointToClientRect, cuiProvide, cuiPure, cuiPx, cuiTypedFromEvent, cuiWatch, cuiZoneOptimized, cuiZonefree, cuiZonefreeScheduler, cuiZonefull, cuiZonefullScheduler, svgNodeFilter };
1162
1454
  //# sourceMappingURL=cuby-ui-cdk.mjs.map