ng-hub-ui-utils 22.2.0 → 22.3.2

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,352 @@
1
1
  import * as i0 from '@angular/core';
2
- import { NgZone, InjectionToken, EnvironmentProviders, ElementRef, ApplicationRef, TemplateRef, Type, ViewContainerRef, PipeTransform, OnDestroy, ViewRef, ComponentRef, Signal } from '@angular/core';
2
+ import { TemplateRef, NgZone, InjectionToken, EnvironmentProviders, ElementRef, ApplicationRef, Type, ViewContainerRef, PipeTransform, OnDestroy, ViewRef, ComponentRef, Signal } from '@angular/core';
3
3
  import * as rxjs from 'rxjs';
4
4
  import { Observable, Subscription, Subject, OperatorFunction } from 'rxjs';
5
5
 
6
+ /**
7
+ * Clamps a value into the `[0, max]` range.
8
+ *
9
+ * @param value Value to clamp.
10
+ * @param max Maximum allowed value.
11
+ * @returns The clamped value.
12
+ */
13
+ declare function clamp(value: number, max: number): number;
14
+ /**
15
+ * Moves an item within an array in place (mirrors `@angular/cdk`'s `moveItemInArray`).
16
+ *
17
+ * @param array Array to mutate.
18
+ * @param fromIndex Current index of the item.
19
+ * @param toIndex Target index of the item.
20
+ */
21
+ declare function moveItemInArray<T>(array: T[], fromIndex: number, toIndex: number): void;
22
+ /**
23
+ * Transfers an item from one array to another in place (mirrors `transferArrayItem`).
24
+ *
25
+ * @param source Source array.
26
+ * @param target Target array.
27
+ * @param fromIndex Index of the item in the source array.
28
+ * @param toIndex Insertion index in the target array.
29
+ */
30
+ declare function transferArrayItem<T>(source: T[], target: T[], fromIndex: number, toIndex: number): void;
31
+ /**
32
+ * Copies an item from one array into another in place, leaving the source untouched.
33
+ *
34
+ * @param source Source array.
35
+ * @param target Target array.
36
+ * @param fromIndex Index of the item in the source array.
37
+ * @param toIndex Insertion index in the target array.
38
+ */
39
+ declare function copyArrayItem<T>(source: ReadonlyArray<T>, target: T[], fromIndex: number, toIndex: number): void;
40
+ /**
41
+ * Computes the destination index in the underlying collection from the hovered target index
42
+ * and the drop side. When reordering within the same container, the index is adjusted to
43
+ * account for the gap left by removing the dragged item.
44
+ *
45
+ * @param targetIndex Absolute index of the hovered target item.
46
+ * @param after Whether the item is dropped after (vs before) the target.
47
+ * @param sameContainer Whether source and target collections are the same.
48
+ * @param fromIndex Absolute index the dragged item occupied in the source collection.
49
+ * @returns The resolved destination index.
50
+ */
51
+ declare function computeTargetIndex(targetIndex: number, after: boolean, sameContainer: boolean, fromIndex: number): number;
52
+ /**
53
+ * Maps a paginated visible index to its absolute index in the underlying collection.
54
+ *
55
+ * @param visibleIndex Index within the currently rendered slice.
56
+ * @param sliceStart Absolute index of the first item in the slice.
57
+ * @returns The absolute index.
58
+ */
59
+ declare function toAbsoluteIndex(visibleIndex: number, sliceStart: number): number;
60
+ /**
61
+ * Determines whether `target` is `node` or any of its descendants in a tree, where children
62
+ * are stored under the `childrenKey` property. Used to forbid dropping a node into its own
63
+ * subtree (which would create a cycle).
64
+ *
65
+ * @param node Root node of the subtree to search.
66
+ * @param target Item to look for (e.g. the parent of a candidate drop container).
67
+ * @param childrenKey Property name holding the children collection.
68
+ * @returns `true` when `target` is `node` or one of its descendants.
69
+ */
70
+ declare function containsNode(node: any, target: any, childrenKey: string): boolean;
71
+
72
+ /**
73
+ * Side a dragged item is dropped relative to a hovered target item.
74
+ */
75
+ type DropPosition = 'before' | 'after';
76
+ /**
77
+ * Transport driving a drag gesture: native HTML5 drag-and-drop or the Pointer Events
78
+ * touch/pen fallback.
79
+ */
80
+ type DragPointerMode = 'native' | 'pointer';
81
+ /**
82
+ * Opaque reference to the collection an item belongs to during a drag operation.
83
+ *
84
+ * A draggable surface can be a tree of collections (e.g. a list root plus nested children,
85
+ * or a board's columns each holding cards). A `DragContainerRef` pins the exact collection
86
+ * (its data array) so reorder/transfer operate on the right place — including cross-instance
87
+ * transfers where source and target live in different component instances.
88
+ *
89
+ * Consumers backed by reactive forms can extend this interface to also carry the mirroring
90
+ * `FormArray`; the coordinator treats the reference opaquely and never reads extra fields.
91
+ *
92
+ * @template T Item type held by the collection.
93
+ */
94
+ interface DragContainerRef<T = any> {
95
+ /** Stable key identifying this collection within its owner (used for DOM hit-testing). */
96
+ key: string;
97
+ /** Identifier of the owning component instance. */
98
+ ownerId: string;
99
+ /** Drag group shared across owners, or `null` when the owner has no group. */
100
+ group: string | null;
101
+ /** The data array backing this collection. */
102
+ items: T[];
103
+ /** Parent item owning this collection in a nested structure, or `null` for the root. */
104
+ parentItem: T | null;
105
+ /** Nesting depth (0 for the root collection). */
106
+ depth: number;
107
+ /** Optional discriminator when an owner manages more than one kind of collection. */
108
+ kind?: string;
109
+ }
110
+ /**
111
+ * Snapshot of the item currently being dragged and where it came from.
112
+ *
113
+ * @template T Item type.
114
+ */
115
+ interface ActiveDrag<T = any> {
116
+ /** Identifier of the source owner. */
117
+ sourceId: string;
118
+ /** Drag group of the source owner (`null` when ungrouped). */
119
+ sourceGroup: string | null;
120
+ /** The item being dragged. */
121
+ item: T;
122
+ /** The collection the item was picked from. */
123
+ sourceContainer: DragContainerRef<T>;
124
+ /** Absolute index of the item in its source collection. */
125
+ sourceIndex: number;
126
+ /** Transport driving the gesture. */
127
+ pointerMode: DragPointerMode;
128
+ /** Optional discriminator (e.g. `'card'` vs `'column'`). */
129
+ kind?: string;
130
+ }
131
+ /**
132
+ * Transient drop target updated while hovering during a drag.
133
+ *
134
+ * @template T Item type.
135
+ */
136
+ interface DragTarget<T = any> {
137
+ /** Identifier of the hovered owner. */
138
+ ownerId: string;
139
+ /** The collection being hovered. */
140
+ container: DragContainerRef<T>;
141
+ /** Absolute index of the hovered item (ignored when `atEnd` is `true`). */
142
+ index: number;
143
+ /** Drop side relative to the hovered item. */
144
+ position: DropPosition;
145
+ /** Whether the drop lands at the end of the collection. */
146
+ atEnd: boolean;
147
+ }
148
+ /**
149
+ * Registration entry an owner publishes so the coordinator can resolve its group lazily,
150
+ * refresh/commit on its behalf, and resolve a drop target from a DOM point during the
151
+ * Pointer Events fallback (where hit-testing crosses component instances).
152
+ */
153
+ interface DragRegistration {
154
+ /** Identifier of the owner. */
155
+ ownerId: string;
156
+ /** Lazily reads the owner's current drag group. */
157
+ group: () => string | null;
158
+ /** Re-renders the owner (used after a cross-owner transfer mutates it). */
159
+ refresh?: () => void;
160
+ /** Commits the pending drop as the destination owner. */
161
+ commit?: () => void;
162
+ /** Resolves a drop target inside this owner from a DOM element and pointer coordinates. */
163
+ resolveTarget?: (element: HTMLElement, clientX: number, clientY: number) => DragTarget | null;
164
+ }
165
+
166
+ /**
167
+ * Minimal rectangle shape (a subset of `DOMRect`) used for drop-position math.
168
+ */
169
+ interface DropRect {
170
+ top: number;
171
+ bottom: number;
172
+ left: number;
173
+ right: number;
174
+ width: number;
175
+ height: number;
176
+ }
177
+ /**
178
+ * Layout axis of a draggable collection, used to decide the drop side.
179
+ *
180
+ * - `vertical`: rows stacked top-to-bottom (default lists, board cards).
181
+ * - `horizontal`: items laid left-to-right (board columns).
182
+ * - `grid`: wrapping grid (list `cards` layout) — vertical band first, then horizontal.
183
+ */
184
+ type DragAxis = 'vertical' | 'horizontal' | 'grid';
185
+ /**
186
+ * Resolves whether a dragged item should drop before or after the hovered target, based on
187
+ * the pointer position relative to the target's bounding rectangle and the layout axis.
188
+ *
189
+ * For `vertical` the Y axis decides; for `horizontal` the X axis decides (mirrored in RTL);
190
+ * for `grid` the vertical band decides across rows and the horizontal axis decides within
191
+ * the same row (mirrored in RTL).
192
+ *
193
+ * @param pointerX Pointer X in viewport coordinates.
194
+ * @param pointerY Pointer Y in viewport coordinates.
195
+ * @param rect Bounding rectangle of the target item.
196
+ * @param axis Layout axis of the collection.
197
+ * @param isRtl Whether the collection is in right-to-left mode.
198
+ * @returns `'before'` or `'after'`.
199
+ */
200
+ declare function resolveDropPosition(pointerX: number, pointerY: number, rect: DropRect, axis: DragAxis, isRtl: boolean): DropPosition;
201
+
202
+ /**
203
+ * A rendered drag image, plus a disposer to tear it down once the drag ends.
204
+ */
205
+ interface DragImageResult {
206
+ /** The root element to pass to `dataTransfer.setDragImage`. */
207
+ node: HTMLElement;
208
+ /** Destroys the embedded view and removes the rendered nodes. */
209
+ destroy(): void;
210
+ }
211
+ /**
212
+ * Renders a template off-screen so it can be used as a native drag image
213
+ * (`dataTransfer.setDragImage`). The caller is responsible for calling `setDragImage` and,
214
+ * on `dragend`, the returned `destroy()`.
215
+ *
216
+ * @param template Template to render as the drag preview.
217
+ * @param context Template context (e.g. `{ item }`).
218
+ * @param container Optional host element to mount into; when omitted, an off-screen holder is
219
+ * appended to `document.body`.
220
+ * @returns The rendered image and its disposer, or `null` when nothing renders (e.g. SSR or
221
+ * an empty template).
222
+ */
223
+ declare function createNativeDragImage(template: TemplateRef<any>, context: Record<string, unknown>, container?: HTMLElement): DragImageResult | null;
224
+
225
+ /**
226
+ * Configuration for a Pointer Events drag session — the touch/pen fallback for native
227
+ * HTML5 drag-and-drop, used where native dragging is unavailable (mobile/tablet).
228
+ */
229
+ interface PointerDragSessionConfig {
230
+ /** The `pointerdown` event that initiated the gesture. */
231
+ startEvent: PointerEvent;
232
+ /** The element being dragged. */
233
+ sourceEl: HTMLElement;
234
+ /** Builds the floating ghost content (custom preview render or a clone). */
235
+ ghostFactory: () => HTMLElement;
236
+ /** Distance in pixels the pointer must travel before a drag begins (default 8). */
237
+ threshold?: number;
238
+ /** Called once the gesture passes the threshold and becomes a drag. */
239
+ onStart: () => void;
240
+ /** Called on every move while dragging, with viewport coordinates. */
241
+ onMove: (clientX: number, clientY: number) => void;
242
+ /** Called on drop (pointer up after a real drag), with viewport coordinates. */
243
+ onDrop: (clientX: number, clientY: number) => void;
244
+ /** Called when the gesture is cancelled (e.g. `pointercancel`). */
245
+ onCancel: () => void;
246
+ /** Always called last for cleanup, regardless of outcome. */
247
+ onEnd: () => void;
248
+ }
249
+ /**
250
+ * Handle to an in-progress Pointer Events drag session.
251
+ */
252
+ interface PointerDragSession {
253
+ /** Aborts the session and runs cleanup. */
254
+ destroy(): void;
255
+ }
256
+ /**
257
+ * Creates a Pointer Events drag session that mirrors native drag-and-drop on touch devices.
258
+ *
259
+ * The session waits for the pointer to pass a movement threshold (so taps still behave as
260
+ * taps), then renders a floating ghost that follows the finger, reports hover positions via
261
+ * `onMove`, autoscrolls when near a scroll container's edges, and commits on pointer up.
262
+ *
263
+ * @param config Session configuration.
264
+ * @returns A handle whose `destroy()` aborts the session.
265
+ */
266
+ declare function createPointerDragSession(config: PointerDragSessionConfig): PointerDragSession;
267
+
268
+ /**
269
+ * Singleton coordinator that backs native HTML5 drag-and-drop reordering and cross-instance
270
+ * transfers (e.g. between two lists, or any two owners that share a drag group).
271
+ *
272
+ * A drag spans two component instances (source and target) and the native `dataTransfer`
273
+ * payload is unreadable during `dragover`, so a shared, root-provided service is the only
274
+ * reliable channel to know what is being dragged and from where while hovering. The service
275
+ * only coordinates state; it never mutates the underlying collections.
276
+ */
277
+ declare class HubDragDropService {
278
+ #private;
279
+ /** The drag currently in progress, or `null`. */
280
+ readonly active: i0.Signal<ActiveDrag<any> | null>;
281
+ /** The current drop target, or `null`. */
282
+ readonly target: i0.Signal<DragTarget<any> | null>;
283
+ /** Whether a drag is in progress. */
284
+ readonly isDragging: i0.Signal<boolean>;
285
+ /**
286
+ * Registers an owner so it can participate in (and be a target of) cross-owner transfers.
287
+ *
288
+ * @param registration The owner registration.
289
+ */
290
+ register(registration: DragRegistration): void;
291
+ /**
292
+ * Removes an owner registration (call on destroy).
293
+ *
294
+ * @param ownerId Identifier of the owner to remove.
295
+ */
296
+ unregister(ownerId: string): void;
297
+ /**
298
+ * Starts a drag, recording the active item and clearing any previous target.
299
+ *
300
+ * @param drag The active drag snapshot.
301
+ */
302
+ begin(drag: ActiveDrag): void;
303
+ /**
304
+ * Updates the transient drop target while hovering.
305
+ *
306
+ * @param target The hovered target, or `null` to clear it.
307
+ */
308
+ setTarget(target: DragTarget | null): void;
309
+ /**
310
+ * Ends the current drag and clears all transient state.
311
+ */
312
+ end(): void;
313
+ /**
314
+ * Determines whether the active drag may be dropped on the given owner. An owner always
315
+ * accepts its own items (in-owner reorder); a different owner accepts only when both
316
+ * share the same non-null drag group.
317
+ *
318
+ * @param targetOwnerId Identifier of the candidate target owner.
319
+ * @returns `true` when the drop is allowed.
320
+ */
321
+ canDrop(targetOwnerId: string): boolean;
322
+ /**
323
+ * Re-renders an owner on demand (used by the destination owner to refresh the source owner
324
+ * after a cross-owner transfer).
325
+ *
326
+ * @param ownerId Identifier of the owner to refresh.
327
+ */
328
+ refreshSource(ownerId: string): void;
329
+ /**
330
+ * Asks an owner to commit the pending drop as the destination (Pointer Events fallback,
331
+ * where the source component drives the gesture but the destination must commit/emit).
332
+ *
333
+ * @param ownerId Identifier of the destination owner.
334
+ */
335
+ requestCommit(ownerId: string): void;
336
+ /**
337
+ * Resolves the drop target under a viewport point by hit-testing the DOM and delegating to
338
+ * the owning component (which knows its own collections). Used by the Pointer Events
339
+ * fallback, including cross-owner hovers where the target is a different component.
340
+ *
341
+ * @param clientX Viewport X coordinate.
342
+ * @param clientY Viewport Y coordinate.
343
+ * @returns The resolved target, or `null` when the point is not over a droppable owner.
344
+ */
345
+ resolveTargetAt(clientX: number, clientY: number): DragTarget | null;
346
+ static ɵfac: i0.ɵɵFactoryDeclaration<HubDragDropService, never>;
347
+ static ɵprov: i0.ɵɵInjectableDeclaration<HubDragDropService>;
348
+ }
349
+
6
350
  declare const FOCUSABLE_ELEMENTS_SELECTOR: string;
7
351
  /**
8
352
  * Returns first and last focusable elements inside of a given element based on specific CSS selector
@@ -611,5 +955,5 @@ declare function debouncedSignal<T>(sourceSignal: Signal<T>, debounceDelay?: num
611
955
  */
612
956
  declare function getActiveElement(root?: Document | ShadowRoot): Element | null;
613
957
 
614
- export { ContentRef, FOCUSABLE_ELEMENTS_SELECTOR, GetPipe, HUB_TRANSLATION_CONFIG, HubTranslationService, IsObjectPipe, IsObservablePipe, IsStringPipe, OverlayPosition, OverlayRef, OverlayService, PopupService, ScrollBar, TooltipDirective, TranslatePipe, UcfirstPipe, UnwrapAsyncPipe, closest, debouncedSignal, equals, generateUniqueId, getActiveElement, getFocusableBoundaryElements, getValue, getValueInRange, hubCompleteTransition, hubFocusTrap, hubRunTransition, interpolateString, isDefined, isInteger, isNumber, isObject, isPromise, isString, mergeDeep, padNumber, provideHubTranslation, reflow, regExpEscape, removeAccents, runInZone, toInteger, toString };
615
- export type { ConnectionPosition, HorizontalConnectionPos, HubTooltipPlacement, HubTranslationConfig, OverlayConfig, ScrollbarReverter, TransitionCtx, TransitionEndFn, TransitionOptions, TransitionStartFn, VerticalConnectionPos };
958
+ export { ContentRef, FOCUSABLE_ELEMENTS_SELECTOR, GetPipe, HUB_TRANSLATION_CONFIG, HubDragDropService, HubTranslationService, IsObjectPipe, IsObservablePipe, IsStringPipe, OverlayPosition, OverlayRef, OverlayService, PopupService, ScrollBar, TooltipDirective, TranslatePipe, UcfirstPipe, UnwrapAsyncPipe, clamp, closest, computeTargetIndex, containsNode, copyArrayItem, createNativeDragImage, createPointerDragSession, debouncedSignal, equals, generateUniqueId, getActiveElement, getFocusableBoundaryElements, getValue, getValueInRange, hubCompleteTransition, hubFocusTrap, hubRunTransition, interpolateString, isDefined, isInteger, isNumber, isObject, isPromise, isString, mergeDeep, moveItemInArray, padNumber, provideHubTranslation, reflow, regExpEscape, removeAccents, resolveDropPosition, runInZone, toAbsoluteIndex, toInteger, toString, transferArrayItem };
959
+ export type { ActiveDrag, ConnectionPosition, DragAxis, DragContainerRef, DragImageResult, DragPointerMode, DragRegistration, DragTarget, DropPosition, DropRect, HorizontalConnectionPos, HubTooltipPlacement, HubTranslationConfig, OverlayConfig, PointerDragSession, PointerDragSessionConfig, ScrollbarReverter, TransitionCtx, TransitionEndFn, TransitionOptions, TransitionStartFn, VerticalConnectionPos };
Binary file