@cngx/common 0.1.0-rc.2 → 0.1.0-rc.4
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/data/README.md +10 -3
- package/display/README.md +1 -0
- package/fesm2022/cngx-common-a11y.mjs +123 -3
- package/fesm2022/cngx-common-a11y.mjs.map +1 -1
- package/fesm2022/cngx-common-card.mjs +8 -8
- package/fesm2022/cngx-common-card.mjs.map +1 -1
- package/fesm2022/cngx-common-data.mjs +999 -54
- package/fesm2022/cngx-common-data.mjs.map +1 -1
- package/fesm2022/cngx-common-display.mjs +320 -8
- package/fesm2022/cngx-common-display.mjs.map +1 -1
- package/fesm2022/cngx-common-interactive.mjs +1603 -75
- package/fesm2022/cngx-common-interactive.mjs.map +1 -1
- package/fesm2022/cngx-common-layout.mjs +187 -3
- package/fesm2022/cngx-common-layout.mjs.map +1 -1
- package/fesm2022/cngx-common-popover.mjs +63 -8
- package/fesm2022/cngx-common-popover.mjs.map +1 -1
- package/fesm2022/cngx-common.mjs +1 -1
- package/interactive/README.md +101 -0
- package/layout/README.md +39 -1
- package/package.json +1 -1
- package/theming/components/cngx-accordion.css +147 -0
- package/theming/components/cngx-badge.css +6 -0
- package/theming/components/cngx-bottom-sheet.css +8 -1
- package/theming/components/cngx-breadcrumb.css +108 -0
- package/theming/components/cngx-button-toggle.css +6 -0
- package/theming/components/cngx-data-grid.css +154 -0
- package/theming/components/cngx-dialog.css +4 -0
- package/theming/components/cngx-divider.css +4 -0
- package/theming/components/cngx-listbox.css +6 -0
- package/theming/components/cngx-menu.css +7 -0
- package/theming/components/cngx-slider.css +237 -0
- package/theming/components/cngx-tooltip.css +6 -0
- package/types/cngx-common-a11y.d.ts +67 -2
- package/types/cngx-common-data.d.ts +837 -23
- package/types/cngx-common-display.d.ts +189 -1
- package/types/cngx-common-interactive.d.ts +1014 -31
- package/types/cngx-common-layout.d.ts +88 -3
- package/types/cngx-common-popover.d.ts +25 -4
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { input, output, inject, ElementRef, signal, afterNextRender, effect, Directive, computed, DestroyRef, model, contentChild, ViewEncapsulation, ChangeDetectionStrategy, Component } from '@angular/core';
|
|
2
|
+
import { input, output, inject, ElementRef, signal, afterNextRender, effect, Directive, computed, DestroyRef, isSignal, untracked, model, contentChild, ViewEncapsulation, ChangeDetectionStrategy, Component } from '@angular/core';
|
|
3
3
|
import { DOCUMENT, NgTemplateOutlet } from '@angular/common';
|
|
4
|
-
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
4
|
+
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
|
|
5
5
|
import { fromEvent } from 'rxjs';
|
|
6
6
|
import * as i1 from '@cngx/common/a11y';
|
|
7
7
|
import { CngxFocusTrap } from '@cngx/common/a11y';
|
|
8
|
+
import { Router, ActivatedRoute } from '@angular/router';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Manages backdrop overlay behavior: visibility, click-to-close, and
|
|
@@ -495,6 +496,189 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
495
496
|
}]
|
|
496
497
|
}], ctorParameters: () => [], propDecorators: { query: [{ type: i0.Input, args: [{ isSignal: true, alias: "cngxMediaQuery", required: true }] }] } });
|
|
497
498
|
|
|
499
|
+
/**
|
|
500
|
+
* Inject-form of {@link CngxMediaQuery}: returns a reactive
|
|
501
|
+
* `Signal<boolean>` that reflects whether the host window currently matches
|
|
502
|
+
* a CSS media query, without needing a host element.
|
|
503
|
+
*
|
|
504
|
+
* Use it where the directive form has nowhere to attach - inside a route
|
|
505
|
+
* guard, a store, a `computed()`, or any injection context that reacts to a
|
|
506
|
+
* viewport or preference query. For host-bound templates, prefer the
|
|
507
|
+
* `[cngxMediaQuery]` directive; for pure styling, prefer CSS `@media` /
|
|
508
|
+
* `@container`.
|
|
509
|
+
*
|
|
510
|
+
* Wraps `window.matchMedia()`: seeds the signal from `MediaQueryList.matches`,
|
|
511
|
+
* updates on the `change` event, and removes the listener via `DestroyRef`
|
|
512
|
+
* when the injection scope is destroyed. In SSR / non-DOM environments (no
|
|
513
|
+
* `defaultView` or no `matchMedia`) it returns a static `false` signal and
|
|
514
|
+
* wires no listener, so it never throws off the browser.
|
|
515
|
+
*
|
|
516
|
+
* Returns a `Signal<boolean>` - never an `Observable`; the reactive boundary
|
|
517
|
+
* stays inside cngx.
|
|
518
|
+
*
|
|
519
|
+
* ```typescript
|
|
520
|
+
* @Component({ … })
|
|
521
|
+
* export class Dashboard {
|
|
522
|
+
* private readonly compact = injectMediaQuery('(max-width: 640px)');
|
|
523
|
+
* protected readonly layout = computed(() => (this.compact() ? 'stacked' : 'grid'));
|
|
524
|
+
* }
|
|
525
|
+
* ```
|
|
526
|
+
*
|
|
527
|
+
* @param query A CSS media query string, e.g. `(max-width: 640px)`.
|
|
528
|
+
* @returns A reactive `Signal<boolean>` tracking the query's match state.
|
|
529
|
+
* @category common/layout
|
|
530
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/observers/inject-media-query.ts
|
|
531
|
+
* @since 0.1.0
|
|
532
|
+
* @relatedTo CngxMediaQuery, CngxResizeObserver
|
|
533
|
+
* <example-url>http://localhost:4200/#/common/layout/media-query/inject-breakpoint-signal</example-url>
|
|
534
|
+
*/
|
|
535
|
+
function injectMediaQuery(query) {
|
|
536
|
+
const win = inject(DOCUMENT).defaultView;
|
|
537
|
+
if (!win || typeof win.matchMedia !== 'function') {
|
|
538
|
+
return signal(false).asReadonly();
|
|
539
|
+
}
|
|
540
|
+
const mql = win.matchMedia(query);
|
|
541
|
+
const matches = signal(mql.matches, ...(ngDevMode ? [{ debugName: "matches" }] : /* istanbul ignore next */ []));
|
|
542
|
+
const handler = (event) => matches.set(event.matches);
|
|
543
|
+
mql.addEventListener('change', handler);
|
|
544
|
+
inject(DestroyRef).onDestroy(() => mql.removeEventListener('change', handler));
|
|
545
|
+
return matches.asReadonly();
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Dev-warning the query-param sync kernel emits when `@angular/router` is
|
|
550
|
+
* not provided. Mirrors {@link warnTabsRouterAbsent} in `@cngx/common/tabs`
|
|
551
|
+
* so the message stays identical across the two sync surfaces; only the
|
|
552
|
+
* `enables` clause differs. A deliberate small copy rather than a shared
|
|
553
|
+
* import - sharing would force the helper onto a `public-api.ts`, and `warn*`
|
|
554
|
+
* matches no approved public-API prefix.
|
|
555
|
+
*
|
|
556
|
+
* @internal
|
|
557
|
+
*/
|
|
558
|
+
function warnRouterAbsent(directive, enables) {
|
|
559
|
+
console.warn(`${directive}: no Router available - directive is a no-op. ` +
|
|
560
|
+
`Provide @angular/router via provideRouter(...) to enable ${enables}.`);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Bidirectional sync between a caller-owned `WritableSignal<T>` and a named
|
|
565
|
+
* query param. URL wins on initial load (deep-link intent); after hydrate the
|
|
566
|
+
* signal is the source and reflects outward. Re-hydrates on browser
|
|
567
|
+
* back/forward. Dev-warns once and no-ops when `@angular/router` is absent.
|
|
568
|
+
*
|
|
569
|
+
* Loop-safety (the core of this helper): the reflect effect writes the URL in
|
|
570
|
+
* `untracked()` and skips `navigate` when the serialized `state()` equals the
|
|
571
|
+
* last value it wrote - a local closure seeded from the initial URL read, not
|
|
572
|
+
* the live URL param (the live param races the navigate-settle window). The
|
|
573
|
+
* hydrate path updates that same closure whenever it accepts a URL value, so
|
|
574
|
+
* back/forward re-hydration never triggers a reflex navigate. A `param` rename
|
|
575
|
+
* is migrated in one navigate (`{ [old]: null, [new]: serialize(state()) }`)
|
|
576
|
+
* by a dedicated effect whose only tracked source is the normalized param
|
|
577
|
+
* signal; its first run seeds bookkeeping and never navigates.
|
|
578
|
+
*
|
|
579
|
+
* The `state.set` inside the hydrate effect is a deliberate signal-write-in-
|
|
580
|
+
* effect: the URL is an external system and `state` is a caller-owned signal
|
|
581
|
+
* the consumer must stay able to toggle, so hydrate cannot be a `computed`. It
|
|
582
|
+
* is edge-guarded by serialized equality and wrapped in `untracked()`.
|
|
583
|
+
*
|
|
584
|
+
* @category common/layout
|
|
585
|
+
* @github https://github.com/cngxjs/cngx/blob/main/projects/common/layout/router/inject-query-param-sync.ts
|
|
586
|
+
* @since 0.1.0
|
|
587
|
+
* @relatedTo CngxStepperRouterSync
|
|
588
|
+
* <example-url>http://localhost:4200/#/common/layout/router/persisted-toggle</example-url>
|
|
589
|
+
*/
|
|
590
|
+
function injectQueryParamSync(state, opts) {
|
|
591
|
+
const router = inject(Router, { optional: true });
|
|
592
|
+
if (!router) {
|
|
593
|
+
warnRouterAbsent('injectQueryParamSync', 'query-param URL sync');
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
const route = inject(ActivatedRoute);
|
|
597
|
+
const paramSignal = isSignal(opts.param) ? opts.param : signal(opts.param);
|
|
598
|
+
const serialize = opts.serialize ?? ((value) => (value ? 'open' : null));
|
|
599
|
+
const deserialize = opts.deserialize ?? ((raw) => (raw != null));
|
|
600
|
+
// Closure bookkeeping, seeded from the initial URL read. `lastWritten` is
|
|
601
|
+
// the serialized value the reflect path last pushed to the URL; the hydrate
|
|
602
|
+
// path also updates it so an accepted URL value is not reflected back.
|
|
603
|
+
const initialParam = paramSignal();
|
|
604
|
+
let lastWritten = route.snapshot.queryParamMap.get(initialParam) ?? null;
|
|
605
|
+
let previousParam = initialParam;
|
|
606
|
+
// URL wins on initial load.
|
|
607
|
+
if (lastWritten != null) {
|
|
608
|
+
const hydrated = deserialize(lastWritten);
|
|
609
|
+
if (!Object.is(hydrated, state())) {
|
|
610
|
+
state.set(hydrated);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
// Reflect: signal change -> URL. Tracks `state()` only; param read untracked.
|
|
614
|
+
effect(() => {
|
|
615
|
+
const raw = serialize(state());
|
|
616
|
+
untracked(() => {
|
|
617
|
+
if (raw === lastWritten) {
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
lastWritten = raw;
|
|
621
|
+
router
|
|
622
|
+
.navigate([], {
|
|
623
|
+
queryParams: { [paramSignal()]: raw },
|
|
624
|
+
queryParamsHandling: 'merge',
|
|
625
|
+
replaceUrl: true,
|
|
626
|
+
})
|
|
627
|
+
.catch((err) => opts.onSyncError?.(err));
|
|
628
|
+
});
|
|
629
|
+
});
|
|
630
|
+
// Re-hydrate: URL change (back/forward) -> signal. Tracks the query-param
|
|
631
|
+
// emission only; param and state reads are untracked. The first run mirrors
|
|
632
|
+
// the initial snapshot already handled synchronously above, so it is skipped
|
|
633
|
+
// - processing it would race the reflect effect's still-pending initial
|
|
634
|
+
// navigate and reset `state` to a stale value. Later runs skip our own
|
|
635
|
+
// reflect echo via the `lastWritten` guard.
|
|
636
|
+
const queryMap = toSignal(route.queryParamMap, {
|
|
637
|
+
initialValue: route.snapshot.queryParamMap,
|
|
638
|
+
});
|
|
639
|
+
let hydrateInitialized = false;
|
|
640
|
+
effect(() => {
|
|
641
|
+
const map = queryMap();
|
|
642
|
+
untracked(() => {
|
|
643
|
+
if (!hydrateInitialized) {
|
|
644
|
+
hydrateInitialized = true;
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
const raw = map.get(paramSignal()) ?? null;
|
|
648
|
+
if (raw === lastWritten) {
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
const next = deserialize(raw);
|
|
652
|
+
if (!Object.is(next, state())) {
|
|
653
|
+
state.set(next);
|
|
654
|
+
}
|
|
655
|
+
lastWritten = raw;
|
|
656
|
+
});
|
|
657
|
+
});
|
|
658
|
+
// Rename migration: param change -> one merged navigate that removes the old
|
|
659
|
+
// key and writes the current value under the new one. Tracks the param
|
|
660
|
+
// signal only; the first run seeds `previousParam` and never navigates.
|
|
661
|
+
effect(() => {
|
|
662
|
+
const param = paramSignal();
|
|
663
|
+
untracked(() => {
|
|
664
|
+
if (param === previousParam) {
|
|
665
|
+
return;
|
|
666
|
+
}
|
|
667
|
+
const oldParam = previousParam;
|
|
668
|
+
previousParam = param;
|
|
669
|
+
const raw = serialize(state());
|
|
670
|
+
lastWritten = raw;
|
|
671
|
+
router
|
|
672
|
+
.navigate([], {
|
|
673
|
+
queryParams: { [oldParam]: null, [param]: raw },
|
|
674
|
+
queryParamsHandling: 'merge',
|
|
675
|
+
replaceUrl: true,
|
|
676
|
+
})
|
|
677
|
+
.catch((err) => opts.onSyncError?.(err));
|
|
678
|
+
});
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
|
|
498
682
|
/**
|
|
499
683
|
* Observes size changes of the host element via the `ResizeObserver` API.
|
|
500
684
|
*
|
|
@@ -1488,5 +1672,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.4", ngImpor
|
|
|
1488
1672
|
* Generated bundle index. Do not edit.
|
|
1489
1673
|
*/
|
|
1490
1674
|
|
|
1491
|
-
export { CngxBackdrop, CngxDrawer, CngxDrawerContent, CngxDrawerPanel, CngxExpandableText, CngxExpandableToggle, CngxHighlight, CngxInfiniteScroll, CngxIntersectionObserver, CngxMediaQuery, CngxResizeObserver, CngxScrollLock, CngxScrollSpy, CngxSkeleton, CngxStickyHeader, CngxTruncate };
|
|
1675
|
+
export { CngxBackdrop, CngxDrawer, CngxDrawerContent, CngxDrawerPanel, CngxExpandableText, CngxExpandableToggle, CngxHighlight, CngxInfiniteScroll, CngxIntersectionObserver, CngxMediaQuery, CngxResizeObserver, CngxScrollLock, CngxScrollSpy, CngxSkeleton, CngxStickyHeader, CngxTruncate, injectMediaQuery, injectQueryParamSync };
|
|
1492
1676
|
//# sourceMappingURL=cngx-common-layout.mjs.map
|