ng-primitives 0.95.0 → 0.97.0

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,6 +1,6 @@
1
1
  import { Component, input } from '@angular/core';
2
+ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
2
3
  import { ControlValueAccessor } from '@angular/forms';
3
- import { explicitEffect } from 'ng-primitives/internal';
4
4
  import {
5
5
  injectRangeSliderState,
6
6
  NgpRangeSlider,
@@ -10,6 +10,7 @@ import {
10
10
  provideRangeSliderState,
11
11
  } from 'ng-primitives/slider';
12
12
  import { ChangeFn, provideValueAccessor, TouchedFn } from 'ng-primitives/utils';
13
+ import { merge } from 'rxjs';
13
14
 
14
15
  @Component({
15
16
  selector: '<%= prefix %>-range-slider',
@@ -106,9 +107,9 @@ export class RangeSlider<%= componentSuffix %> implements ControlValueAccessor {
106
107
 
107
108
  constructor() {
108
109
  // Whenever either value changes, call the onChange function with the new tuple [low, high].
109
- explicitEffect([this.state().low, this.state().high], ([low, high]) =>
110
- this.onChange?.([low, high]),
111
- );
110
+ merge(this.state().lowChange, this.state().highChange)
111
+ .pipe(takeUntilDestroyed())
112
+ .subscribe(() => this.onChange?.([this.state().low(), this.state().high()]));
112
113
  }
113
114
 
114
115
  writeValue(value: [number, number]): void {
@@ -131,6 +132,6 @@ export class RangeSlider<%= componentSuffix %> implements ControlValueAccessor {
131
132
  }
132
133
 
133
134
  setDisabledState(isDisabled: boolean): void {
134
- this.state().disabled.set(isDisabled);
135
+ this.state().setDisabled(isDisabled);
135
136
  }
136
137
  }
package/slider/index.d.ts CHANGED
@@ -1,10 +1,8 @@
1
1
  import * as _angular_core from '@angular/core';
2
- import { Signal, WritableSignal, ElementRef, OnDestroy } from '@angular/core';
2
+ import { Signal, WritableSignal, ElementRef } from '@angular/core';
3
3
  import { NgpOrientation } from 'ng-primitives/common';
4
4
  import { Observable } from 'rxjs';
5
5
  import { NumberInput, BooleanInput } from '@angular/cdk/coercion';
6
- import * as ng_primitives_state from 'ng-primitives/state';
7
- import * as ng_primitives_slider from 'ng-primitives/slider';
8
6
 
9
7
  /**
10
8
  * Apply the `ngpSliderRange` directive to an element that represents the range of the slider.
@@ -302,79 +300,146 @@ declare class NgpSlider {
302
300
  * Apply the `ngpRangeSliderRange` directive to an element that represents the range between the low and high values.
303
301
  */
304
302
  declare class NgpRangeSliderRange {
305
- /**
306
- * Access the range slider state.
307
- */
308
- protected readonly rangeSliderState: _angular_core.Signal<ng_primitives_state.State<ng_primitives_slider.NgpRangeSlider>>;
303
+ constructor();
309
304
  static ɵfac: _angular_core.ɵɵFactoryDeclaration<NgpRangeSliderRange, never>;
310
305
  static ɵdir: _angular_core.ɵɵDirectiveDeclaration<NgpRangeSliderRange, "[ngpRangeSliderRange]", ["ngpRangeSliderRange"], {}, {}, never, never, true, never>;
311
306
  }
312
307
 
308
+ /**
309
+ * Public state surface for the RangeSliderRange primitive.
310
+ */
311
+ interface NgpRangeSliderRangeState {
312
+ }
313
+ /**
314
+ * Inputs for configuring the RangeSliderRange primitive.
315
+ */
316
+ interface NgpRangeSliderRangeProps {
317
+ }
318
+ declare const ngpRangeSliderRange: ({}: NgpRangeSliderRangeProps) => {};
319
+ declare const injectRangeSliderRangeState: {
320
+ (): _angular_core.Signal<{}>;
321
+ (options: {
322
+ hoisted: true;
323
+ optional?: boolean;
324
+ skipSelf?: boolean;
325
+ }): _angular_core.Signal<{} | null>;
326
+ (options?: {
327
+ hoisted?: boolean;
328
+ optional?: boolean;
329
+ skipSelf?: boolean;
330
+ }): _angular_core.Signal<{}> | _angular_core.Signal<{} | null>;
331
+ };
332
+ declare const provideRangeSliderRangeState: (opts?: {
333
+ inherit?: boolean;
334
+ }) => _angular_core.FactoryProvider;
335
+
313
336
  /**
314
337
  * Apply the `ngpRangeSliderThumb` directive to an element that represents a thumb of the range slider.
315
338
  * Each thumb can be configured to control either the 'low' or 'high' value.
316
339
  */
317
- declare class NgpRangeSliderThumb implements OnDestroy {
318
- /**
319
- * Access the range slider state.
320
- */
321
- protected readonly state: _angular_core.Signal<ng_primitives_state.State<ng_primitives_slider.NgpRangeSlider>>;
322
- /**
323
- * Access the thumb element.
324
- */
325
- private readonly elementRef;
326
- /**
327
- * Determines which value this thumb controls ('low' or 'high').
328
- */
329
- protected readonly thumb: _angular_core.Signal<"low" | "high">;
330
- /**
331
- * Store the dragging state.
332
- */
333
- protected dragging: boolean;
334
- /**
335
- * Get the current value for this thumb.
336
- */
337
- protected readonly value: _angular_core.Signal<number>;
338
- /**
339
- * Get the current percentage for this thumb.
340
- */
341
- protected readonly percentage: _angular_core.Signal<number>;
340
+ declare class NgpRangeSliderThumb {
342
341
  constructor();
343
- ngOnDestroy(): void;
344
- protected handlePointerDown(event: PointerEvent): void;
345
- protected handlePointerUp(): void;
346
- protected handlePointerMove(event: PointerEvent): void;
347
- /**
348
- * Handle keyboard events.
349
- * @param event
350
- */
351
- protected handleKeydown(event: KeyboardEvent): void;
352
342
  static ɵfac: _angular_core.ɵɵFactoryDeclaration<NgpRangeSliderThumb, never>;
353
343
  static ɵdir: _angular_core.ɵɵDirectiveDeclaration<NgpRangeSliderThumb, "[ngpRangeSliderThumb]", ["ngpRangeSliderThumb"], {}, {}, never, never, true, never>;
354
344
  }
355
345
 
356
346
  /**
357
- * Apply the `ngpRangeSliderTrack` directive to an element that represents the track of the range slider.
347
+ * Public state surface for the RangeSliderThumb primitive.
358
348
  */
359
- declare class NgpRangeSliderTrack {
349
+ interface NgpRangeSliderThumbState {
360
350
  /**
361
- * Access the range slider state.
351
+ * Which value this thumb controls ('low' or 'high').
362
352
  */
363
- protected readonly rangeSliderState: _angular_core.Signal<ng_primitives_state.State<ng_primitives_slider.NgpRangeSlider>>;
353
+ readonly thumb: Signal<'low' | 'high'>;
364
354
  /**
365
- * The element that represents the slider track.
355
+ * The current value for this thumb.
366
356
  */
367
- readonly element: _angular_core.ElementRef<HTMLElement>;
368
- constructor();
357
+ readonly value: Signal<number>;
369
358
  /**
370
- * When the slider track is clicked, update the closest thumb value.
371
- * @param event The click event.
359
+ * The current percentage for this thumb.
372
360
  */
373
- protected handlePointerDown(event: PointerEvent): void;
361
+ readonly percentage: Signal<number>;
362
+ }
363
+ /**
364
+ * Inputs for configuring the RangeSliderThumb primitive.
365
+ */
366
+ interface NgpRangeSliderThumbProps {
367
+ }
368
+ declare const ngpRangeSliderThumb: ({}: NgpRangeSliderThumbProps) => {
369
+ thumb: Signal<"low" | "high">;
370
+ value: Signal<number>;
371
+ percentage: Signal<number>;
372
+ };
373
+ declare const injectRangeSliderThumbState: {
374
+ (): Signal<{
375
+ thumb: Signal<"low" | "high">;
376
+ value: Signal<number>;
377
+ percentage: Signal<number>;
378
+ }>;
379
+ (options: {
380
+ hoisted: true;
381
+ optional?: boolean;
382
+ skipSelf?: boolean;
383
+ }): Signal<{
384
+ thumb: Signal<"low" | "high">;
385
+ value: Signal<number>;
386
+ percentage: Signal<number>;
387
+ } | null>;
388
+ (options?: {
389
+ hoisted?: boolean;
390
+ optional?: boolean;
391
+ skipSelf?: boolean;
392
+ }): Signal<{
393
+ thumb: Signal<"low" | "high">;
394
+ value: Signal<number>;
395
+ percentage: Signal<number>;
396
+ }> | Signal<{
397
+ thumb: Signal<"low" | "high">;
398
+ value: Signal<number>;
399
+ percentage: Signal<number>;
400
+ } | null>;
401
+ };
402
+ declare const provideRangeSliderThumbState: (opts?: {
403
+ inherit?: boolean;
404
+ }) => _angular_core.FactoryProvider;
405
+
406
+ /**
407
+ * Apply the `ngpRangeSliderTrack` directive to an element that represents the track of the range slider.
408
+ */
409
+ declare class NgpRangeSliderTrack {
410
+ constructor();
374
411
  static ɵfac: _angular_core.ɵɵFactoryDeclaration<NgpRangeSliderTrack, never>;
375
412
  static ɵdir: _angular_core.ɵɵDirectiveDeclaration<NgpRangeSliderTrack, "[ngpRangeSliderTrack]", ["ngpRangeSliderTrack"], {}, {}, never, never, true, never>;
376
413
  }
377
414
 
415
+ /**
416
+ * Public state surface for the RangeSliderTrack primitive.
417
+ */
418
+ interface NgpRangeSliderTrackState {
419
+ }
420
+ /**
421
+ * Inputs for configuring the RangeSliderTrack primitive.
422
+ */
423
+ interface NgpRangeSliderTrackProps {
424
+ }
425
+ declare const ngpRangeSliderTrack: ({}: NgpRangeSliderTrackProps) => void;
426
+ declare const injectRangeSliderTrackState: {
427
+ (): _angular_core.Signal<void>;
428
+ (options: {
429
+ hoisted: true;
430
+ optional?: boolean;
431
+ skipSelf?: boolean;
432
+ }): _angular_core.Signal<void | null>;
433
+ (options?: {
434
+ hoisted?: boolean;
435
+ optional?: boolean;
436
+ skipSelf?: boolean;
437
+ }): _angular_core.Signal<void> | _angular_core.Signal<void | null>;
438
+ };
439
+ declare const provideRangeSliderTrackState: (opts?: {
440
+ inherit?: boolean;
441
+ }) => _angular_core.FactoryProvider;
442
+
378
443
  /**
379
444
  * Apply the `ngpRangeSlider` directive to an element that represents the range slider and contains the track, range, and thumbs.
380
445
  */
@@ -420,80 +485,175 @@ declare class NgpRangeSlider {
420
485
  */
421
486
  readonly disabled: _angular_core.InputSignalWithTransform<boolean, BooleanInput>;
422
487
  /**
423
- * Access the slider track.
424
- * @internal
488
+ * The state of the range slider.
425
489
  */
426
- readonly track: _angular_core.WritableSignal<NgpRangeSliderTrack | undefined>;
490
+ private readonly state;
491
+ static ɵfac: _angular_core.ɵɵFactoryDeclaration<NgpRangeSlider, never>;
492
+ static ɵdir: _angular_core.ɵɵDirectiveDeclaration<NgpRangeSlider, "[ngpRangeSlider]", ["ngpRangeSlider"], { "id": { "alias": "id"; "required": false; "isSignal": true; }; "low": { "alias": "ngpRangeSliderLow"; "required": false; "isSignal": true; }; "high": { "alias": "ngpRangeSliderHigh"; "required": false; "isSignal": true; }; "min": { "alias": "ngpRangeSliderMin"; "required": false; "isSignal": true; }; "max": { "alias": "ngpRangeSliderMax"; "required": false; "isSignal": true; }; "step": { "alias": "ngpRangeSliderStep"; "required": false; "isSignal": true; }; "orientation": { "alias": "ngpRangeSliderOrientation"; "required": false; "isSignal": true; }; "disabled": { "alias": "ngpRangeSliderDisabled"; "required": false; "isSignal": true; }; }, { "lowChange": "ngpRangeSliderLowChange"; "highChange": "ngpRangeSliderHighChange"; }, never, never, true, never>;
493
+ }
494
+
495
+ /**
496
+ * Inputs for configuring the RangeSlider primitive.
497
+ */
498
+ interface NgpRangeSliderProps {
427
499
  /**
428
- * The thumbs of the range slider.
429
- * @internal
500
+ * The id of the range slider.
501
+ */
502
+ readonly id?: Signal<string>;
503
+ /**
504
+ * The low value of the range slider.
505
+ */
506
+ readonly low?: Signal<number>;
507
+ /**
508
+ * The high value of the range slider.
509
+ */
510
+ readonly high?: Signal<number>;
511
+ /**
512
+ * The minimum value.
513
+ */
514
+ readonly min?: Signal<number>;
515
+ /**
516
+ * The maximum value.
517
+ */
518
+ readonly max?: Signal<number>;
519
+ /**
520
+ * The step value.
521
+ */
522
+ readonly step?: Signal<number>;
523
+ /**
524
+ * The range slider orientation.
525
+ */
526
+ readonly orientation?: Signal<NgpOrientation>;
527
+ /**
528
+ * Whether the range slider is disabled.
529
+ */
530
+ readonly disabled?: Signal<boolean>;
531
+ /**
532
+ * Callback fired when the low value changes.
533
+ */
534
+ readonly onLowChange?: (value: number) => void;
535
+ /**
536
+ * Callback fired when the high value changes.
537
+ */
538
+ readonly onHighChange?: (value: number) => void;
539
+ }
540
+ /**
541
+ * Public state surface for the RangeSlider primitive.
542
+ */
543
+ interface NgpRangeSliderState {
544
+ /**
545
+ * The id of the range slider.
546
+ */
547
+ readonly id: Signal<string>;
548
+ /**
549
+ * The low value of the range slider.
550
+ */
551
+ readonly low: WritableSignal<number>;
552
+ /**
553
+ * The high value of the range slider.
554
+ */
555
+ readonly high: WritableSignal<number>;
556
+ /**
557
+ * The minimum value of the range slider.
430
558
  */
431
- readonly thumbs: _angular_core.WritableSignal<NgpRangeSliderThumb[]>;
559
+ readonly min: Signal<number>;
560
+ /**
561
+ * The maximum value of the range slider.
562
+ */
563
+ readonly max: Signal<number>;
564
+ /**
565
+ * The step value of the range slider.
566
+ */
567
+ readonly step: Signal<number>;
568
+ /**
569
+ * The orientation of the range slider.
570
+ */
571
+ readonly orientation: WritableSignal<NgpOrientation>;
572
+ /**
573
+ * Whether the range slider is disabled.
574
+ */
575
+ readonly disabled: WritableSignal<boolean>;
432
576
  /**
433
577
  * The low value as a percentage based on the min and max values.
434
578
  * @internal
435
579
  */
436
- readonly lowPercentage: _angular_core.Signal<number>;
580
+ readonly lowPercentage: Signal<number>;
437
581
  /**
438
582
  * The high value as a percentage based on the min and max values.
439
583
  * @internal
440
584
  */
441
- readonly highPercentage: _angular_core.Signal<number>;
585
+ readonly highPercentage: Signal<number>;
442
586
  /**
443
587
  * The range between low and high values as a percentage.
444
588
  * @internal
445
589
  */
446
- readonly rangePercentage: _angular_core.Signal<number>;
590
+ readonly rangePercentage: Signal<number>;
447
591
  /**
448
- * The state of the range slider. We use this for the range slider state rather than relying on the inputs.
449
- * @internal
592
+ * @internal The track element reference.
450
593
  */
451
- protected readonly state: ng_primitives_state.CreatedState<NgpRangeSlider>;
452
- constructor();
594
+ readonly track: Signal<ElementRef<HTMLElement> | undefined>;
595
+ /**
596
+ * @internal The thumbs array.
597
+ */
598
+ readonly thumbs: Signal<ElementRef<HTMLElement>[]>;
599
+ /**
600
+ * Emit when the low value changes.
601
+ */
602
+ readonly lowChange: Observable<number>;
603
+ /**
604
+ * Emit when the high value changes.
605
+ */
606
+ readonly highChange: Observable<number>;
453
607
  /**
454
608
  * Updates the low value, ensuring it doesn't exceed the high value.
455
- * @param value The new low value
456
- * @internal
457
609
  */
458
610
  setLowValue(value: number): void;
459
611
  /**
460
612
  * Updates the high value, ensuring it doesn't go below the low value.
461
- * @param value The new high value
462
- * @internal
463
613
  */
464
614
  setHighValue(value: number): void;
465
615
  /**
466
616
  * Determines which thumb should be moved based on the position clicked.
467
- * @param percentage The percentage position of the click
468
- * @returns 'low' or 'high' indicating which thumb should move
469
- *
470
- * @internal
471
617
  */
472
618
  getClosestThumb(percentage: number): 'low' | 'high';
473
619
  /**
474
620
  * Updates the thumbs array when a new thumb is added.
475
- * @param thumb The new thumb to add
476
- * @internal
477
621
  */
478
- addThumb(thumb: NgpRangeSliderThumb): void;
622
+ addThumb(thumb: ElementRef<HTMLElement>): void;
479
623
  /**
480
624
  * Removes a thumb from the thumbs array.
481
- * @param thumb The thumb to remove
482
- * @internal
483
625
  */
484
- removeThumb(thumb: NgpRangeSliderThumb): void;
485
- static ɵfac: _angular_core.ɵɵFactoryDeclaration<NgpRangeSlider, never>;
486
- static ɵdir: _angular_core.ɵɵDirectiveDeclaration<NgpRangeSlider, "[ngpRangeSlider]", ["ngpRangeSlider"], { "id": { "alias": "id"; "required": false; "isSignal": true; }; "low": { "alias": "ngpRangeSliderLow"; "required": false; "isSignal": true; }; "high": { "alias": "ngpRangeSliderHigh"; "required": false; "isSignal": true; }; "min": { "alias": "ngpRangeSliderMin"; "required": false; "isSignal": true; }; "max": { "alias": "ngpRangeSliderMax"; "required": false; "isSignal": true; }; "step": { "alias": "ngpRangeSliderStep"; "required": false; "isSignal": true; }; "orientation": { "alias": "ngpRangeSliderOrientation"; "required": false; "isSignal": true; }; "disabled": { "alias": "ngpRangeSliderDisabled"; "required": false; "isSignal": true; }; }, { "lowChange": "ngpRangeSliderLowChange"; "highChange": "ngpRangeSliderHighChange"; }, never, never, true, never>;
626
+ removeThumb(thumb: ElementRef<HTMLElement>): void;
627
+ /**
628
+ * Set the track element reference.
629
+ */
630
+ setTrack(track: ElementRef<HTMLElement>): void;
631
+ /**
632
+ * Set the disabled state.
633
+ */
634
+ setDisabled(disabled: boolean): void;
635
+ /**
636
+ * Set the orientation.
637
+ */
638
+ setOrientation(orientation: NgpOrientation): void;
487
639
  }
640
+ declare const ngpRangeSlider: ({ id, low: _low, high: _high, min, max, step, orientation: _orientation, disabled: _disabled, onLowChange, onHighChange, }: NgpRangeSliderProps) => NgpRangeSliderState;
641
+ declare const injectRangeSliderState: {
642
+ (): Signal<NgpRangeSliderState>;
643
+ (options: {
644
+ hoisted: true;
645
+ optional?: boolean;
646
+ skipSelf?: boolean;
647
+ }): Signal<NgpRangeSliderState | null>;
648
+ (options?: {
649
+ hoisted?: boolean;
650
+ optional?: boolean;
651
+ skipSelf?: boolean;
652
+ }): Signal<NgpRangeSliderState> | Signal<NgpRangeSliderState | null>;
653
+ };
654
+ declare const provideRangeSliderState: (opts?: {
655
+ inherit?: boolean;
656
+ }) => _angular_core.FactoryProvider;
488
657
 
489
- /**
490
- * Provides the Range Slider state.
491
- */
492
- declare const provideRangeSliderState: (options?: ng_primitives_state.CreateStateProviderOptions) => _angular_core.FactoryProvider;
493
- /**
494
- * Injects the Range Slider state.
495
- */
496
- declare const injectRangeSliderState: <U = NgpRangeSlider>(injectOptions?: _angular_core.InjectOptions) => _angular_core.Signal<ng_primitives_state.State<U>>;
497
-
498
- export { NgpRangeSlider, NgpRangeSliderRange, NgpRangeSliderThumb, NgpRangeSliderTrack, NgpSlider, NgpSliderRange, NgpSliderThumb, NgpSliderTrack, injectRangeSliderState, injectSliderRangeState, injectSliderState, injectSliderThumbState, injectSliderTrackState, ngpSlider, ngpSliderRange, ngpSliderThumb, ngpSliderTrack, provideRangeSliderState, provideSliderRangeState, provideSliderState, provideSliderThumbState, provideSliderTrackState };
499
- export type { NgpSliderProps, NgpSliderRangeProps, NgpSliderRangeState, NgpSliderState, NgpSliderThumbProps, NgpSliderThumbState, NgpSliderTrackProps, NgpSliderTrackState };
658
+ export { NgpRangeSlider, NgpRangeSliderRange, NgpRangeSliderThumb, NgpRangeSliderTrack, NgpSlider, NgpSliderRange, NgpSliderThumb, NgpSliderTrack, injectRangeSliderRangeState, injectRangeSliderState, injectRangeSliderThumbState, injectRangeSliderTrackState, injectSliderRangeState, injectSliderState, injectSliderThumbState, injectSliderTrackState, ngpRangeSlider, ngpRangeSliderRange, ngpRangeSliderThumb, ngpRangeSliderTrack, ngpSlider, ngpSliderRange, ngpSliderThumb, ngpSliderTrack, provideRangeSliderRangeState, provideRangeSliderState, provideRangeSliderThumbState, provideRangeSliderTrackState, provideSliderRangeState, provideSliderState, provideSliderThumbState, provideSliderTrackState };
659
+ export type { NgpRangeSliderProps, NgpRangeSliderRangeProps, NgpRangeSliderRangeState, NgpRangeSliderState, NgpRangeSliderThumbProps, NgpRangeSliderThumbState, NgpRangeSliderTrackProps, NgpRangeSliderTrackState, NgpSliderProps, NgpSliderRangeProps, NgpSliderRangeState, NgpSliderState, NgpSliderThumbProps, NgpSliderThumbState, NgpSliderTrackProps, NgpSliderTrackState };
package/toast/index.d.ts CHANGED
@@ -216,4 +216,4 @@ interface NgpToastRef {
216
216
  }
217
217
 
218
218
  export { NgpToast, NgpToastManager, injectToastContext, provideToastConfig };
219
- export type { NgpToastConfig };
219
+ export type { NgpToastConfig, NgpToastRef };
package/utils/index.d.ts CHANGED
@@ -16,12 +16,6 @@ interface NgpControlStatus {
16
16
  pending: boolean | null;
17
17
  disabled: boolean | null;
18
18
  }
19
- /**
20
- * A utility function to get the status of an Angular form control as a reactive signal.
21
- * This function injects the NgControl and returns a signal that reflects the control's status.
22
- * It supports both classic reactive forms controls and signal-forms interop controls.
23
- * @internal
24
- */
25
19
  declare function controlStatus(): Signal<NgpControlStatus>;
26
20
 
27
21
  /**