ngx-kit 9.2.4 → 9.3.1
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/core/README.md +0 -21
- package/fesm2022/ngx-kit-core.mjs +30 -23
- package/fesm2022/ngx-kit-core.mjs.map +1 -1
- package/fesm2022/ngx-kit-drag-resize.mjs +2 -4
- package/fesm2022/ngx-kit-drag-resize.mjs.map +1 -1
- package/fesm2022/ngx-kit-image-editor.mjs +13 -12
- package/fesm2022/ngx-kit-image-editor.mjs.map +1 -1
- package/fesm2022/ngx-kit-image-viewer.mjs +5 -3
- package/fesm2022/ngx-kit-image-viewer.mjs.map +1 -1
- package/fesm2022/ngx-kit-infinite-scroll.mjs +8 -7
- package/fesm2022/ngx-kit-infinite-scroll.mjs.map +1 -1
- package/fesm2022/ngx-kit-notify.mjs +0 -1
- package/fesm2022/ngx-kit-notify.mjs.map +1 -1
- package/package.json +1 -1
- package/types/ngx-kit-core.d.ts +9 -5
- package/types/ngx-kit-image-editor.d.ts +4 -3
- package/types/ngx-kit-image-viewer.d.ts +1 -0
- package/types/ngx-kit-infinite-scroll.d.ts +1 -0
package/core/README.md
CHANGED
|
@@ -65,29 +65,8 @@ const browser = inject(BrowserService);
|
|
|
65
65
|
browser.prefersDarkMode; // boolean — read once at service construction time
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
## Utilities
|
|
69
68
|
|
|
70
|
-
### `startDragSession(callbacks)`
|
|
71
69
|
|
|
72
|
-
Replaces the problematic `@HostListener('document:mousemove', ...)` pattern, which keeps a listener attached to `document` for the entire lifetime of the component — even when nothing is being dragged (a real performance issue on pages with many simultaneous instances). This function only adds a listener for the duration of an actual drag and removes it itself; `touchmove` is handled with `{passive: false}`, so dragging on mobile doesn't also scroll the page.
|
|
73
|
-
|
|
74
|
-
```ts
|
|
75
|
-
import { startDragSession } from 'ngx-kit/core';
|
|
76
|
-
|
|
77
|
-
let stop: (() => void) | undefined;
|
|
78
|
-
|
|
79
|
-
function onPointerDown(ev: MouseEvent | TouchEvent) {
|
|
80
|
-
stop?.();
|
|
81
|
-
stop = startDragSession({
|
|
82
|
-
onMove: (ev) => {
|
|
83
|
-
/* update position */
|
|
84
|
-
},
|
|
85
|
-
onEnd: () => {
|
|
86
|
-
stop = undefined;
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
```
|
|
91
70
|
|
|
92
71
|
> If your component is `OnPush` and uses `startDragSession` (instead of `@HostListener`), make sure to call `ChangeDetectorRef.markForCheck()` inside `onMove`/`onEnd` yourself — unlike `@HostListener`, which automatically marks the view dirty, a manual `addEventListener` does not.
|
|
93
72
|
|
|
@@ -1,31 +1,32 @@
|
|
|
1
1
|
import * as i1 from '@angular/common';
|
|
2
|
-
import { CommonModule, isPlatformBrowser, DOCUMENT } from '@angular/common';
|
|
2
|
+
import { CommonModule, isPlatformBrowser, DOCUMENT as DOCUMENT$1 } from '@angular/common';
|
|
3
3
|
import * as i0 from '@angular/core';
|
|
4
|
-
import { EventEmitter, forwardRef, HostListener, ViewChild, Output, Input, ChangeDetectionStrategy, Component,
|
|
4
|
+
import { EventEmitter, inject, DOCUMENT, forwardRef, HostListener, ViewChild, Output, Input, ChangeDetectionStrategy, Component, ChangeDetectorRef, InjectionToken, PLATFORM_ID, Inject, Injectable, DestroyRef, signal, computed, ApplicationRef, EnvironmentInjector, Injector, createComponent } from '@angular/core';
|
|
5
5
|
import { NG_VALUE_ACCESSOR, NG_VALIDATORS, FormControl, Validators } from '@angular/forms';
|
|
6
6
|
|
|
7
7
|
function getOffsetPosition(evt, parent) {
|
|
8
|
-
|
|
8
|
+
const position = {
|
|
9
9
|
x: 0,
|
|
10
10
|
y: 0,
|
|
11
11
|
};
|
|
12
|
-
if (
|
|
12
|
+
if ('touches' in evt) {
|
|
13
|
+
if (evt.touches.length > 0) {
|
|
14
|
+
position.x = evt.touches[0].pageX;
|
|
15
|
+
position.y = evt.touches[0].pageY;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
13
19
|
position.x = evt.pageX;
|
|
14
20
|
position.y = evt.pageY;
|
|
15
21
|
}
|
|
16
|
-
|
|
17
|
-
position.x = evt.touches[0].pageX;
|
|
18
|
-
position.y = evt.touches[0].pageY;
|
|
19
|
-
}
|
|
20
|
-
// Adjust for the parent's offset
|
|
21
|
-
let parentRect = parent.getBoundingClientRect();
|
|
22
|
+
const parentRect = parent.getBoundingClientRect();
|
|
22
23
|
position.x -= parentRect.left + window.scrollX;
|
|
23
24
|
position.y -= parentRect.top + window.scrollY;
|
|
24
25
|
return position;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
/** با فراخوانی این تابع (مثلاً داخل dragStart) یک نشست درگ شروع میشه. */
|
|
28
|
-
function startDragSession({ onMove, onEnd }) {
|
|
29
|
+
function startDragSession({ doc, onMove, onEnd }) {
|
|
29
30
|
const handleMove = (ev) => {
|
|
30
31
|
if (ev.type === 'touchmove') {
|
|
31
32
|
// جلوگیری از اسکرول شدن صفحه همزمان با درگ کردن روی موبایل/تاچ
|
|
@@ -38,17 +39,17 @@ function startDragSession({ onMove, onEnd }) {
|
|
|
38
39
|
onEnd?.(ev);
|
|
39
40
|
};
|
|
40
41
|
const stop = () => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
doc.removeEventListener('mousemove', handleMove);
|
|
43
|
+
doc.removeEventListener('touchmove', handleMove);
|
|
44
|
+
doc.removeEventListener('mouseup', handleEnd);
|
|
45
|
+
doc.removeEventListener('touchend', handleEnd);
|
|
46
|
+
doc.removeEventListener('touchcancel', handleEnd);
|
|
46
47
|
};
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
doc.addEventListener('mousemove', handleMove);
|
|
49
|
+
doc.addEventListener('touchmove', handleMove, { passive: false });
|
|
50
|
+
doc.addEventListener('mouseup', handleEnd);
|
|
51
|
+
doc.addEventListener('touchend', handleEnd);
|
|
52
|
+
doc.addEventListener('touchcancel', handleEnd);
|
|
52
53
|
// تابع stop برگردونده میشه تا هم بشه دستی صداش زد (مثلاً در ngOnDestroy،
|
|
53
54
|
// اگه کامپوننت درست وسط یه درگ نابود بشه) و هم بهصورت خودکار روی
|
|
54
55
|
// mouseup/touchend صدا زده میشه.
|
|
@@ -107,6 +108,7 @@ class RangeSliderComponent {
|
|
|
107
108
|
sliderRect;
|
|
108
109
|
thumbRect;
|
|
109
110
|
stopDrag;
|
|
111
|
+
doc = inject(DOCUMENT);
|
|
110
112
|
constructor(changeDetectorRef) {
|
|
111
113
|
this.changeDetectorRef = changeDetectorRef;
|
|
112
114
|
}
|
|
@@ -180,6 +182,7 @@ class RangeSliderComponent {
|
|
|
180
182
|
this.selectedIndexChange.emit(this.selectedIndex);
|
|
181
183
|
this.stopDrag?.();
|
|
182
184
|
this.stopDrag = startDragSession({
|
|
185
|
+
doc: this.doc,
|
|
183
186
|
onMove: (moveEv) => this.updateThumbPosition(moveEv),
|
|
184
187
|
onEnd: () => {
|
|
185
188
|
this.isDragging = false;
|
|
@@ -333,6 +336,7 @@ class SaturationComponent {
|
|
|
333
336
|
saturationRect;
|
|
334
337
|
thumbRect;
|
|
335
338
|
stopDrag;
|
|
339
|
+
doc = inject(DOCUMENT);
|
|
336
340
|
constructor() { }
|
|
337
341
|
ngOnDestroy() {
|
|
338
342
|
// اگه کامپوننت درست وسط یه درگ نابود بشه (مثلاً پیکر بسته بشه)، باید
|
|
@@ -390,6 +394,7 @@ class SaturationComponent {
|
|
|
390
394
|
this.updatePosition(ev);
|
|
391
395
|
this.stopDrag?.();
|
|
392
396
|
this.stopDrag = startDragSession({
|
|
397
|
+
doc: this.doc,
|
|
393
398
|
onMove: (moveEv) => this.updatePosition(moveEv),
|
|
394
399
|
onEnd: () => {
|
|
395
400
|
this.isDragging = false;
|
|
@@ -515,6 +520,7 @@ class SliderComponent {
|
|
|
515
520
|
thumbRect;
|
|
516
521
|
stopDrag;
|
|
517
522
|
cd = inject(ChangeDetectorRef);
|
|
523
|
+
doc = inject(DOCUMENT);
|
|
518
524
|
constructor() { }
|
|
519
525
|
ngOnInit() {
|
|
520
526
|
this.myControl.setValidators([Validators.min(this.min), Validators.max(this.max)]);
|
|
@@ -572,6 +578,7 @@ class SliderComponent {
|
|
|
572
578
|
this.updatePosition(ev);
|
|
573
579
|
this.stopDrag?.();
|
|
574
580
|
this.stopDrag = startDragSession({
|
|
581
|
+
doc: this.doc,
|
|
575
582
|
onMove: (moveEv) => this.updatePosition(moveEv),
|
|
576
583
|
onEnd: () => {
|
|
577
584
|
this.isDragging = false;
|
|
@@ -1146,7 +1153,7 @@ function resolveDirection(doc) {
|
|
|
1146
1153
|
* این سرویس انجام میدهد).
|
|
1147
1154
|
*/
|
|
1148
1155
|
class DirectionService {
|
|
1149
|
-
doc = inject(DOCUMENT);
|
|
1156
|
+
doc = inject(DOCUMENT$1);
|
|
1150
1157
|
destroyRef = inject(DestroyRef);
|
|
1151
1158
|
_direction = signal(resolveDirection(this.doc), /* @ts-ignore */
|
|
1152
1159
|
...(ngDevMode ? [{ debugName: "_direction" }] : /* istanbul ignore next */ []));
|
|
@@ -1209,7 +1216,7 @@ const DIALOG_OVERLAY_CLASSNAME = 'ngx-ui-overlay';
|
|
|
1209
1216
|
const OVERLAY_HOST_CLASSNAME = 'ngx-ui-overlay-host';
|
|
1210
1217
|
const BASE_Z_INDEX = 1000;
|
|
1211
1218
|
class OverlayService {
|
|
1212
|
-
document = inject(DOCUMENT);
|
|
1219
|
+
document = inject(DOCUMENT$1);
|
|
1213
1220
|
directionService = inject(DirectionService);
|
|
1214
1221
|
platformId = inject(PLATFORM_ID);
|
|
1215
1222
|
applicationRef = inject(ApplicationRef);
|