@nativescript/angular 21.0.1-alpha.2 → 21.0.1-alpha.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nativescript/angular",
3
- "version": "21.0.1-alpha.2",
3
+ "version": "21.0.1-alpha.4",
4
4
  "homepage": "https://nativescript.org/",
5
5
  "repository": {
6
6
  "type": "git",
@@ -4,7 +4,7 @@ import * as i0 from '@angular/core';
4
4
  import { InjectionToken, EmbeddedViewRef, ComponentRef, NgModuleRef, ApplicationRef, Provider, EnvironmentProviders, PlatformRef, ɵNgModuleFactory as _NgModuleFactory, Type, CompilerOptions, NgZone, Injector, NgModuleFactory, StaticProvider, Sanitizer, ApplicationConfig as ApplicationConfig$1, ViewContainerRef, ComponentFactoryResolver, TemplateRef, ElementRef, OnInit, OnDestroy, Renderer2, EventEmitter, ChangeDetectorRef, ComponentFactory, AfterViewInit, OnChanges, SimpleChanges, DoCheck, AfterContentInit, IterableDiffer, IterableDiffers, ErrorHandler, RendererStyleFlags2, RendererType2, RendererFactory2, QueryList, EnvironmentInjector, ModuleWithProviders, NgZoneOptions } from '@angular/core';
5
5
  import * as _nativescript_angular from '@nativescript/angular';
6
6
  import * as rxjs from 'rxjs';
7
- import { Observable, Subject, BehaviorSubject } from 'rxjs';
7
+ import { Observable, ReplaySubject, Subject, BehaviorSubject } from 'rxjs';
8
8
  import * as i1 from '@angular/common';
9
9
  import { LocationStrategy, XhrFactory } from '@angular/common';
10
10
  import * as i1$2 from '@angular/router';
@@ -170,7 +170,17 @@ type NgModuleEvent = {
170
170
  reason: NgModuleReason | string;
171
171
  };
172
172
  declare const preAngularDisposal$: Subject<NgModuleEvent>;
173
- declare const postAngularBootstrap$: Subject<NgModuleEvent>;
173
+ /**
174
+ * Stream that emits when an Angular module finishes bootstrapping. Modeled
175
+ * as a `ReplaySubject(1)` so consumers (e.g. `NativeDialog`) instantiated
176
+ * lazily — *after* the bootstrap event has already fired — still receive
177
+ * the latest event and can react. Without buffering, a service that the
178
+ * user app injects on first need (after bootstrap) would silently miss the
179
+ * `hotreload` notification and skip HMR-only work like restoring captured
180
+ * modal state. The buffer size of 1 means each new HMR cycle replaces the
181
+ * cached event so cycle N's late subscribers don't see cycle N-1's event.
182
+ */
183
+ declare const postAngularBootstrap$: ReplaySubject<NgModuleEvent>;
174
184
  /**
175
185
  * @deprecated
176
186
  */
@@ -1084,6 +1094,22 @@ declare class NativeDialogConfig<D = any> {
1084
1094
  /** Alternate `ComponentFactoryResolver` to use when resolving the associated component. */
1085
1095
  componentFactoryResolver?: ComponentFactoryResolver;
1086
1096
  nativeOptions?: NativeShowModalOptions;
1097
+ /**
1098
+ * When true, this dialog will be re-opened automatically on Angular HMR
1099
+ * reboots so the user does not lose context every time a related file
1100
+ * changes. The new dialog reuses the same component class and `data` payload
1101
+ * (provided via `data`); other config such as `nativeOptions` is preserved
1102
+ * verbatim.
1103
+ *
1104
+ * The original `dialogRef.afterClosed()` subject is wired to the restored
1105
+ * dialog so consumers `await openModal(...)` resolve normally when the user
1106
+ * eventually closes the restored modal.
1107
+ *
1108
+ * Only opens via component class are restorable — `TemplateRef` openings
1109
+ * carry references that don't survive an HMR reboot and are silently
1110
+ * skipped. Has no effect outside of HMR.
1111
+ */
1112
+ preserveOnHmr?: boolean;
1087
1113
  }
1088
1114
 
1089
1115
  declare class FrameService {
@@ -1195,6 +1221,16 @@ declare class NativeModalRef {
1195
1221
  portalOutlet: NativeScriptDomPortalOutlet;
1196
1222
  detachedLoaderRef: ComponentRef<DetachedLoader>;
1197
1223
  modalViewRef: NgViewRef<any>;
1224
+ /**
1225
+ * The actual NativeScript view passed to `parentView.showModal(...)`.
1226
+ *
1227
+ * For component portals this is the stable `targetView` ContentView
1228
+ * wrapper that owns the Angular host PVC. For template portals it
1229
+ * remains `modalViewRef.firstNativeLikeView` (the historical
1230
+ * behavior). Keeping a direct reference avoids walking parent
1231
+ * chains when programmatically closing the modal.
1232
+ */
1233
+ modalView?: View;
1198
1234
  private _closeCallback;
1199
1235
  private _isDismissed;
1200
1236
  constructor(_config: NativeDialogConfig, _injector: Injector, location?: NSLocationStrategy);
@@ -1283,9 +1319,24 @@ declare const NATIVE_DIALOG_DEFAULT_OPTIONS: InjectionToken<NativeDialogConfig<a
1283
1319
  * for arbitrary dialog refs and dialog container components.
1284
1320
  */
1285
1321
  declare class NativeDialog implements OnDestroy {
1322
+ /**
1323
+ * Diagnostic instance id. We tag each constructor with a number so
1324
+ * the logs make it obvious when a stale `NativeDialog` keeps
1325
+ * receiving events after a reboot (e.g. due to a leaked subscription
1326
+ * or a service from a previous realm being kept alive).
1327
+ */
1328
+ private readonly _diagInstanceId;
1286
1329
  private _openDialogsAtThisLevel;
1287
1330
  private readonly _afterAllClosedAtThisLevel;
1288
1331
  private readonly _afterOpenedAtThisLevel;
1332
+ /**
1333
+ * Maps each open dialog ref back to the `(componentClass, config)` pair it
1334
+ * was opened with so the HMR snapshot can replay the call later. Dialogs
1335
+ * opened with a `TemplateRef` are tracked with `componentClass: undefined`
1336
+ * — the HMR layer skips them automatically.
1337
+ */
1338
+ private readonly _openDialogMetadata;
1339
+ private _hmrSubscriptions;
1289
1340
  /**
1290
1341
  * Stream that emits when all open dialog have finished closing.
1291
1342
  * Will emit on subscribe if there are no open dialogs to begin with.
@@ -1303,6 +1354,8 @@ declare class NativeDialog implements OnDestroy {
1303
1354
  private _nativeModalType;
1304
1355
  private _dialogDataToken;
1305
1356
  private locationStrategy;
1357
+ private _diagInstanceIdAssign;
1358
+ private _hmrInitMarker;
1306
1359
  /**
1307
1360
  * Opens a modal dialog containing the given component.
1308
1361
  * @param component Type of the component to load into the dialog.
@@ -1328,6 +1381,128 @@ declare class NativeDialog implements OnDestroy {
1328
1381
  */
1329
1382
  getDialogById(id: string): NativeDialogRef<any> | undefined;
1330
1383
  ngOnDestroy(): void;
1384
+ /**
1385
+ * Tracks whether a restore has already been scheduled for this
1386
+ * `NativeDialog` instance's lifetime. We only need to restore once
1387
+ * per HMR cycle — the rxjs `ReplaySubject(1)` for
1388
+ * `postAngularBootstrap$` delivers both the *previous* cycle's
1389
+ * cached event (replay on subscribe) **and** the *current* cycle's
1390
+ * fresh event, and the constructor stash peek can independently
1391
+ * notice pending work. Without this guard each of those triggers
1392
+ * would queue its own `setTimeout` and the logs would show two or
1393
+ * three "scheduling restore" lines per save.
1394
+ *
1395
+ * The guard is per-instance and the stash itself is the source of
1396
+ * truth: `_restorePendingDialogs` calls `consumePendingHmrDialogs()`
1397
+ * which atomically clears the stash, so even if the guard somehow
1398
+ * fired twice, only the first call would do real work.
1399
+ */
1400
+ private _restoreScheduledForThisInstance;
1401
+ /**
1402
+ * Wires up HMR capture/restore. Only the root-level dialog manages the
1403
+ * stash so a stack of `NativeDialog` instances inside a child injector
1404
+ * doesn't fight for it.
1405
+ *
1406
+ * Production short-circuit: `isAngularHmrEnabled()` returns `false` in
1407
+ * release builds and when no NS Vite / webpack HMR runtime is present,
1408
+ * so the long-lived subscriptions below never attach in shipping apps.
1409
+ *
1410
+ * `postAngularBootstrap$` is a `ReplaySubject(1)` (see `application.ts`)
1411
+ * which means a `NativeDialog` instantiated *after* the bootstrap event
1412
+ * has already fired (typical when the user app injects `NativeDialog`
1413
+ * lazily via a service like `view.service.ts`) still receives the
1414
+ * buffered event and runs the restore path.
1415
+ */
1416
+ private _initHmrLifecycle;
1417
+ /**
1418
+ * Schedule a restore exactly once per `NativeDialog` instance.
1419
+ *
1420
+ * The work is deferred to the next macrotask for two reasons:
1421
+ *
1422
+ * 1. `postAngularBootstrap$.next(...)` is fired from inside
1423
+ * `emitModuleBootstrapEvent`, which itself runs inside the
1424
+ * `bootstrapApplication` callback — so the call stack still
1425
+ * contains Angular's ApplicationRef bootstrap pipeline. Doing
1426
+ * `this.open(...)` synchronously re-entered Angular DI while a
1427
+ * `providedIn: 'root'` factory could still be on the resolution
1428
+ * stack, which surfaced as `NG0200: Circular dependency detected
1429
+ * for NativeDialog`. Yielding to a macrotask lets the bootstrap
1430
+ * stack fully unwind first.
1431
+ * 2. The eventual `parent.showModal(...)` cannot present onto a
1432
+ * view controller whose view is not yet in the iOS window
1433
+ * hierarchy (see `_scheduleRestoreOpenWhenReady` for the second
1434
+ * wait stage); a synchronous attempt would silently no-op
1435
+ * because iOS rejects the present without throwing.
1436
+ */
1437
+ private _maybeScheduleRestore;
1438
+ private _captureOpenDialogsForHmr;
1439
+ /**
1440
+ * Per-cycle guard to keep `_restorePendingDialogs` idempotent if more
1441
+ * than one subscriber fires for the same bootstrap event. The
1442
+ * regression we have seen (`postAngularBootstrap$ → restore` logged
1443
+ * twice in the same hot reload) was caused by the `NativeDialogModule`
1444
+ * also listing `NativeDialog` in its `providers` array. That has been
1445
+ * removed, but we keep this flag as a defensive net so a future stray
1446
+ * subscription does not consume the stash twice. The flag is reset
1447
+ * after the consume so subsequent HMR cycles can run their own
1448
+ * restore.
1449
+ */
1450
+ private _restoreInFlight;
1451
+ private _restorePendingDialogs;
1452
+ /**
1453
+ * Resolve the freshest known class object for the captured component
1454
+ * name and re-open the dialog through the normal `open` path, but
1455
+ * only once the new root view is actually attached to the iOS window
1456
+ * hierarchy.
1457
+ *
1458
+ * Why a class lookup at all: an HMR reboot calls
1459
+ * `ɵresetCompiledComponents()` which clears each component's `ɵcmp`
1460
+ * field but **leaves the class identity unchanged**. The patched
1461
+ * `ɵɵdefineComponent` then re-registers the same class object under
1462
+ * the same source name when Angular re-renders the component. A
1463
+ * fresh-class lookup therefore returns either the same object the
1464
+ * stash captured (most common) or, on the rare occasion that the
1465
+ * source file's `@Component` decorator was re-evaluated into a brand
1466
+ * new class object (e.g. the user added `@Component(...)` to a new
1467
+ * exported symbol), the live one. Either way, a single check is
1468
+ * enough — the previous retry schedule was a no-op in 100 % of
1469
+ * observed cycles because the captured class IS the live class.
1470
+ */
1471
+ private _restoreSingleDialog;
1472
+ /**
1473
+ * Maximum time we'll wait for the new root view to attach to the
1474
+ * iOS window before giving up and trying the open anyway. NS Vite's
1475
+ * worst observed reboot-to-rootview-loaded gap is ~250 ms; one
1476
+ * second leaves headroom for slower devices without leaving the
1477
+ * captured dialog stuck in the stash if something genuinely goes
1478
+ * wrong.
1479
+ */
1480
+ private static readonly _ROOT_VIEW_LOADED_TIMEOUT_MS;
1481
+ /**
1482
+ * Defer the actual `this.open(...)` call until the new root view's
1483
+ * underlying iOS `UIViewController.view` is in the window hierarchy.
1484
+ *
1485
+ * iOS silently rejects `presentViewControllerAnimatedCompletion` if
1486
+ * the parent controller's view is not yet attached to a `UIWindow`
1487
+ * (see `view/index.ios.ts::_showNativeModalView`, which logs to
1488
+ * `Trace` and returns without throwing). In dev that would surface
1489
+ * as a vanished modal with no actionable error.
1490
+ *
1491
+ * NS marks a view as `isLoaded === true` from
1492
+ * `UILayoutViewController.viewWillAppear`, which fires once iOS has
1493
+ * decided to add the view to its window. Listening for the
1494
+ * `loadedEvent` (one-shot) plus an extra macrotask gives UIKit a
1495
+ * chance to finish window attachment before we present.
1496
+ */
1497
+ private _scheduleRestoreOpenWhenReady;
1498
+ private _pollForRootView;
1499
+ private _performRestoreOpen;
1500
+ /**
1501
+ * Test/debug helper: discard any captured modals without restoring them.
1502
+ * Mostly useful when projects want to opt out of restoration without
1503
+ * recompiling. Public callers should prefer `preserveOnHmr: false` instead.
1504
+ */
1505
+ static _clearPendingHmrDialogs(): void;
1331
1506
  /**
1332
1507
  * Attaches the user-provided component to the already-created dialog container.
1333
1508
  * @param componentOrTemplateRef The type of component being loaded into the dialog,
@@ -1383,6 +1558,32 @@ declare class NativeDialogCloseDirective implements OnInit, OnChanges {
1383
1558
  static ɵdir: i0.ɵɵDirectiveDeclaration<NativeDialogCloseDirective, "[native-dialog-close], [nativeDialogClose]", ["nativeDialogClose"], { "dialogResult": { "alias": "native-dialog-close"; "required": false; }; "_matDialogClose": { "alias": "nativeDialogClose"; "required": false; }; }, {}, never, never, true, never>;
1384
1559
  }
1385
1560
 
1561
+ /**
1562
+ * Convenience module that re-exports the `NativeDialogCloseDirective` for
1563
+ * template-driven `[nativeDialogClose]` usage.
1564
+ *
1565
+ * **Important**: `NativeDialog` itself is **not** listed in this module's
1566
+ * `providers` array. The service is `@Injectable({ providedIn: 'root' })`,
1567
+ * which already registers a single root-level instance and is fully
1568
+ * tree-shakeable. Listing it here as well caused Angular to treat the
1569
+ * module-level provider and the `providedIn: 'root'` factory as
1570
+ * *separate* registrations once the module was pulled into a standalone
1571
+ * app via `importProvidersFrom(NativeDialogModule, ...)`. The duplicate
1572
+ * registration triggered:
1573
+ *
1574
+ * - Two `NativeDialog` instances in the same root environment injector,
1575
+ * each subscribing to `postAngularBootstrap$`, which produced
1576
+ * duplicate restore attempts during HMR.
1577
+ * - `NG0200: Circular dependency detected for NativeDialog` while a
1578
+ * captured modal was being re-opened during HMR restore, because the
1579
+ * second resolution started while the first was still in progress.
1580
+ *
1581
+ * Removing the redundant entry collapses both providers back into a
1582
+ * single root-level instance, which is what `providedIn: 'root'`
1583
+ * documents. App authors who explicitly wire `NativeDialog` themselves
1584
+ * (e.g. in a feature module's `providers`) keep working unchanged
1585
+ * because they're targeting the same class symbol.
1586
+ */
1386
1587
  declare class NativeDialogModule {
1387
1588
  static ɵfac: i0.ɵɵFactoryDeclaration<NativeDialogModule, never>;
1388
1589
  static ɵmod: i0.ɵɵNgModuleDeclaration<NativeDialogModule, never, [typeof NativeDialogCloseDirective], [typeof NativeDialogCloseDirective]>;
@@ -1448,6 +1649,344 @@ declare function generateNativeScriptView<T>(typeOrTemplate: Type<T> | TemplateR
1448
1649
  detachedLoaderRef?: ComponentRef<DetachedLoader>;
1449
1650
  }): NgViewRef<T>;
1450
1651
 
1652
+ /**
1653
+ * Framework-agnostic Hot-Module-Replacement state cache.
1654
+ *
1655
+ * The {@link HmrCacheStore} class is intentionally free of any Angular
1656
+ * imports so a future `@nativescript/solid` (or any other framework
1657
+ * binding) can lift this file as-is and wrap it with its own DI
1658
+ * primitive. The Angular DI wrapper lives in
1659
+ * `./hmr-cache.service.ts`.
1660
+ *
1661
+ * # What it does
1662
+ *
1663
+ * The NativeScript iOS runtime exposes a Vite-spec compliant
1664
+ * `import.meta.hot` on every imported module (see
1665
+ * `@nativescript/ios` →
1666
+ * `runtime/HMRSupport.{h,mm}::InitializeImportMetaHot`). The runtime
1667
+ * keeps a per-module persistent `data` object alive in C++ across V8
1668
+ * evaluation cycles and canonicalizes the module path so the same
1669
+ * bucket survives the URL variations Vite cycles through during a
1670
+ * save (HMR boot/live tags, versioned bridge paths, common script
1671
+ * extensions). When `@nativescript/vite`'s Angular HMR client calls
1672
+ * `globalThis.__nsRunHmrDispose()` before `__reboot_ng_modules__`,
1673
+ * every registered `dispose(cb)` fires and is handed the same `data`
1674
+ * object the next module evaluation will read from.
1675
+ *
1676
+ * `HmrCacheStore` rides on top of that primitive:
1677
+ *
1678
+ * 1. On construction, it copies any previously-stashed entries out
1679
+ * of `import.meta.hot.data['ns-hmr-cache']` (or whatever
1680
+ * `storageKey` the caller picked) into an in-memory `Map`.
1681
+ * 2. It registers a single `import.meta.hot.dispose` callback that
1682
+ * writes the in-memory `Map` back as a plain object before the
1683
+ * next reboot.
1684
+ * 3. Every `set` re-orders the key to the end of the `Map` (LRU);
1685
+ * when `size > maxEntries`, the oldest entry is evicted. This
1686
+ * stops a long dev session from accumulating unbounded state for
1687
+ * features the developer no longer touches.
1688
+ * 4. It subscribes to a custom HMR event (default
1689
+ * `'ns:cache-invalidate'`) so a Vite plugin or dev server can
1690
+ * push targeted cache evictions — e.g. "the OData schema for
1691
+ * `/safety/forms` changed, drop anything that depends on it".
1692
+ *
1693
+ * In production / `--no-hmr` builds `import.meta.hot` is `undefined`,
1694
+ * the store collapses to a pure in-memory cache that lives for the
1695
+ * lifetime of the process, and the public API is identical so callers
1696
+ * never need to special-case build modes.
1697
+ *
1698
+ * # Why a class and not a plain object
1699
+ *
1700
+ * Encapsulating the LRU bookkeeping behind named methods (`get`,
1701
+ * `set`, `invalidate`, `scope`) lets us evolve the eviction policy
1702
+ * (e.g. add TTLs, weighted entries, structured-clone enforcement)
1703
+ * without touching every call site. The framework wrappers expose
1704
+ * the same surface so app authors learn one API regardless of which
1705
+ * framework they use.
1706
+ */
1707
+ interface HmrCacheStoreOptions {
1708
+ /**
1709
+ * Maximum number of entries to keep before LRU-evicting the
1710
+ * oldest. Set to `0` (or any non-positive number) for unlimited.
1711
+ * Default: `256`.
1712
+ *
1713
+ * Sized for the empirical "depth of features a developer touches in
1714
+ * one dev session" — large enough that a working set of ~30 pages,
1715
+ * each with a handful of cached fields, never trips eviction during
1716
+ * normal hacking; small enough that a runaway producer (e.g. a
1717
+ * scroll-driven loop that mints new keys) gets capped instead of
1718
+ * leaking memory until the simulator OOMs.
1719
+ */
1720
+ maxEntries?: number;
1721
+ /**
1722
+ * Key under which the cache is stashed on `import.meta.hot.data`.
1723
+ * Apps that run multiple isolated cache stores (e.g. a feature-
1724
+ * isolation plugin) can pick distinct keys to keep their state
1725
+ * separate. Default: `'ns-hmr-cache'`.
1726
+ */
1727
+ storageKey?: string;
1728
+ /**
1729
+ * Custom HMR event name the store listens for. Payload schema:
1730
+ *
1731
+ * ```ts
1732
+ * { key?: string }
1733
+ * ```
1734
+ *
1735
+ * If `key` is provided, only that entry is dropped. If omitted, the
1736
+ * entire cache is cleared. A Vite plugin sends events via the dev
1737
+ * server's WebSocket (Vite spec
1738
+ * [`server.ws.send`](https://vite.dev/guide/api-plugin.html#server-ws-send-and-server-ws-on));
1739
+ * the runtime's `__NS_DISPATCH_HOT_EVENT__` then forwards them to
1740
+ * every `import.meta.hot.on` listener. Default:
1741
+ * `'ns:cache-invalidate'`.
1742
+ */
1743
+ invalidateEventName?: string;
1744
+ /**
1745
+ * Optional logger for diagnostic output. The store calls this with
1746
+ * a single string per significant event (rehydrate, dispose, LRU
1747
+ * evict, server-side invalidate). Default: no-op.
1748
+ */
1749
+ log?: (message: string) => void;
1750
+ }
1751
+ /**
1752
+ * A namespaced view of an {@link HmrCacheStore}. Keys are
1753
+ * automatically prefixed with `<scope>:`, so callers don't have to
1754
+ * negotiate global key names. Returned by {@link HmrCacheStore.scope}.
1755
+ */
1756
+ interface HmrCacheScope {
1757
+ readonly prefix: string;
1758
+ get<T>(key: string): T | undefined;
1759
+ set<T>(key: string, value: T): void;
1760
+ has(key: string): boolean;
1761
+ delete(key: string): void;
1762
+ /** Drop every entry whose key starts with this scope's prefix. */
1763
+ clear(): void;
1764
+ /** Number of entries owned by this scope. */
1765
+ size(): number;
1766
+ }
1767
+ declare class HmrCacheStore {
1768
+ private readonly _map;
1769
+ private readonly _maxEntries;
1770
+ private readonly _log;
1771
+ /**
1772
+ * @param initialEntries Entries to seed the store with (typically
1773
+ * the previous session's snapshot read from
1774
+ * `import.meta.hot.data`).
1775
+ * @param options See {@link HmrCacheStoreOptions}.
1776
+ */
1777
+ constructor(initialEntries?: Iterable<[string, unknown]>, options?: HmrCacheStoreOptions);
1778
+ get<T>(key: string): T | undefined;
1779
+ set<T>(key: string, value: T): void;
1780
+ has(key: string): boolean;
1781
+ delete(key: string): void;
1782
+ /**
1783
+ * Drop a specific entry, or every entry when `key` is omitted.
1784
+ * Equivalent to {@link delete} (with key) or {@link clear} (without)
1785
+ * — exposed as a single method so callers and event handlers can
1786
+ * forward an optional key without branching.
1787
+ */
1788
+ invalidate(key?: string): void;
1789
+ /** Drop every cached entry. */
1790
+ clear(): void;
1791
+ /** Total number of cached entries across all scopes. */
1792
+ size(): number;
1793
+ /** Snapshot of every key currently in the cache. */
1794
+ keys(): string[];
1795
+ /**
1796
+ * Returns a namespaced view of this store. All keys passed to the
1797
+ * returned object are auto-prefixed with `<prefix>:`. Useful so
1798
+ * each feature module can avoid stomping on neighbours' keys
1799
+ * without repeating the prefix at every call site.
1800
+ *
1801
+ * @example
1802
+ * ```ts
1803
+ * const cache = createDefaultHmrCacheStore();
1804
+ * const submissions = cache.scope('page-my-submissions');
1805
+ * submissions.set('items', [...]); // stored under 'page-my-submissions:items'
1806
+ * ```
1807
+ */
1808
+ scope(prefix: string): HmrCacheScope;
1809
+ /**
1810
+ * Serialize every entry into a plain object suitable for stashing
1811
+ * on `import.meta.hot.data`. Used by the dispose callback in
1812
+ * {@link createDefaultHmrCacheStore} and re-exported for callers
1813
+ * that want to integrate with another persistence layer (e.g. a
1814
+ * test harness that snapshots between cases).
1815
+ */
1816
+ toObject(): Record<string, unknown>;
1817
+ private _enforceMaxEntries;
1818
+ }
1819
+ /**
1820
+ * Build an {@link HmrCacheStore} bound to the current module's
1821
+ * `import.meta.hot` context — i.e. the store's data survives HMR
1822
+ * reboots and listens for the `'ns:cache-invalidate'` custom event.
1823
+ *
1824
+ * Caller responsibility: invoke this from the module that "owns" the
1825
+ * cache. `import.meta` is per-module, so the dispose callback will be
1826
+ * registered against whichever module physically calls this function.
1827
+ * In `@nativescript/angular` the canonical owner is
1828
+ * `hmr-cache.service.ts`; in `@nativescript/solid` it would be the
1829
+ * equivalent solid-side module.
1830
+ *
1831
+ * Returns a freshly-constructed store. Callers should treat it as a
1832
+ * singleton — calling this twice from the same module yields two
1833
+ * independent stores, which is almost never what you want.
1834
+ */
1835
+ declare function createDefaultHmrCacheStore(options?: HmrCacheStoreOptions): HmrCacheStore;
1836
+
1837
+ /**
1838
+ * Skip the API call your component already paid for last save.
1839
+ *
1840
+ * Inject {@link HmrCacheService} from any Angular component or service
1841
+ * to read and write a per-app key/value cache that **survives the
1842
+ * `__reboot_ng_modules__` cycle** triggered by every HMR file save.
1843
+ * Backed by `@nativescript/ios`'s native `import.meta.hot.data`
1844
+ * (`runtime/HMRSupport.{h,mm}`) and drained via
1845
+ * `@nativescript/vite`'s `globalThis.__nsRunHmrDispose()` hook before
1846
+ * Angular tears down its realm, so the same value the previous
1847
+ * component instance produced is handed straight to the freshly-
1848
+ * instantiated one — no network round-trip, no spinner flash.
1849
+ *
1850
+ * In production / `--no-hmr` builds `import.meta.hot` is `undefined`
1851
+ * and the cache collapses to a plain in-memory object that lives for
1852
+ * the lifetime of the process. The public API is identical, so callers
1853
+ * never need to special-case build modes.
1854
+ *
1855
+ * @example Skip the initial fetch on save
1856
+ * ```ts
1857
+ * import { HmrCacheService } from '@nativescript/angular';
1858
+ *
1859
+ * @Component({...})
1860
+ * export class MyComponent implements OnInit {
1861
+ * private hmrCache = inject(HmrCacheService);
1862
+ *
1863
+ * ngOnInit() {
1864
+ * const cached = this.hmrCache.get<MyResult>('my-feature:items');
1865
+ * if (cached) {
1866
+ * this.applyResult(cached);
1867
+ * return;
1868
+ * }
1869
+ * this.api.load().subscribe((result) => {
1870
+ * this.hmrCache.set('my-feature:items', result);
1871
+ * this.applyResult(result);
1872
+ * });
1873
+ * }
1874
+ * }
1875
+ * ```
1876
+ *
1877
+ * @example Namespaced via {@link scope}
1878
+ * ```ts
1879
+ * private cache = inject(HmrCacheService).scope('page-my-submissions');
1880
+ * // …
1881
+ * this.cache.set('items', items); // → 'page-my-submissions:items'
1882
+ * this.cache.get('items'); // ← 'page-my-submissions:items'
1883
+ * ```
1884
+ *
1885
+ * @example Server-side invalidation from a Vite plugin
1886
+ * ```ts
1887
+ * // vite.config.ts
1888
+ * export default defineConfig({
1889
+ * plugins: [
1890
+ * {
1891
+ * name: 'my-schema-watcher',
1892
+ * configureServer(server) {
1893
+ * server.watcher.on('change', (path) => {
1894
+ * if (path.endsWith('schema.json')) {
1895
+ * server.ws.send({
1896
+ * type: 'custom',
1897
+ * event: 'ns:cache-invalidate',
1898
+ * data: { key: 'my-feature:items' },
1899
+ * });
1900
+ * }
1901
+ * });
1902
+ * },
1903
+ * },
1904
+ * ],
1905
+ * });
1906
+ * ```
1907
+ *
1908
+ * Memory ceiling: the cache LRU-evicts at 256 entries by default. Pass
1909
+ * a custom ceiling via {@link configureHmrCache} if your app churns
1910
+ * through more keys than that in a typical dev session, or set `0` for
1911
+ * unlimited (unbounded growth — only safe for short-lived dev work).
1912
+ *
1913
+ * @see HmrCacheStore — the framework-agnostic engine. Stable enough to
1914
+ * lift into `@nativescript/solid` / other framework bindings without
1915
+ * modification.
1916
+ */
1917
+ declare class HmrCacheService {
1918
+ private readonly _store;
1919
+ /**
1920
+ * `true` when `import.meta.hot` is wired (i.e. NativeScript Vite HMR
1921
+ * is active and `@nativescript/ios` is recent enough to expose
1922
+ * `import.meta.hot.data`). `false` in production / `--no-hmr` /
1923
+ * legacy webpack builds.
1924
+ *
1925
+ * Most callers should NOT branch on this — the public API works
1926
+ * identically in both cases. Use it only when you want to opt OUT
1927
+ * of caching in production (e.g. always fetch fresh data when not
1928
+ * developing).
1929
+ */
1930
+ readonly isHmr: boolean;
1931
+ get<T>(key: string): T | undefined;
1932
+ set<T>(key: string, value: T): void;
1933
+ has(key: string): boolean;
1934
+ delete(key: string): void;
1935
+ /**
1936
+ * Drop a single entry, or every entry when `key` is omitted. Same
1937
+ * shape as the `'ns:cache-invalidate'` HMR-event payload the store
1938
+ * listens for, so application code can call this directly to mirror
1939
+ * a server-side eviction.
1940
+ */
1941
+ invalidate(key?: string): void;
1942
+ /** Drop every cached entry. Equivalent to `invalidate()` with no key. */
1943
+ clear(): void;
1944
+ /** Total number of entries across every scope. */
1945
+ size(): number;
1946
+ /** Snapshot of every key currently cached. Useful for debug overlays. */
1947
+ keys(): string[];
1948
+ /**
1949
+ * Returns a namespaced view of the cache. All `get` / `set` /
1950
+ * `has` / `delete` calls on the returned object are auto-prefixed
1951
+ * with `<scopeName>:`. Recommended over global keys so feature
1952
+ * modules don't accidentally collide.
1953
+ *
1954
+ * @example
1955
+ * ```ts
1956
+ * private cache = inject(HmrCacheService).scope('page-my-submissions');
1957
+ * // …
1958
+ * this.cache.set('items', items); // → 'page-my-submissions:items'
1959
+ * ```
1960
+ */
1961
+ scope(scopeName: string): HmrCacheScope;
1962
+ static ɵfac: i0.ɵɵFactoryDeclaration<HmrCacheService, never>;
1963
+ static ɵprov: i0.ɵɵInjectableDeclaration<HmrCacheService>;
1964
+ }
1965
+ /**
1966
+ * Override the default cache configuration. Must be called BEFORE the
1967
+ * first injection of {@link HmrCacheService} (i.e. before Angular
1968
+ * bootstrap, or as the very first statement in `main.ts`); otherwise
1969
+ * the call is a no-op because the singleton store has already been
1970
+ * built with the previous (or default) options.
1971
+ *
1972
+ * Typical use case: bumping `maxEntries` for a large multi-feature
1973
+ * monorepo dev session, or pointing a custom `invalidateEventName` at
1974
+ * a Vite plugin that prefixes its events with the project name.
1975
+ *
1976
+ * Returns `true` if the configuration was applied, `false` if the
1977
+ * store had already been instantiated by an earlier injection.
1978
+ */
1979
+ declare function configureHmrCache(options: HmrCacheStoreOptions): boolean;
1980
+ /**
1981
+ * Read-only access to the underlying {@link HmrCacheStore}. Exposed
1982
+ * for advanced integrations that want to reuse the LRU + dispose +
1983
+ * server-side-invalidate plumbing without going through Angular's
1984
+ * dependency injection (e.g. a non-component utility that's loaded
1985
+ * before the Angular platform has bootstrapped). Application code
1986
+ * should prefer {@link HmrCacheService}.
1987
+ */
1988
+ declare function getHmrCacheStore(): HmrCacheStore;
1989
+
1451
1990
  declare function registerNativeScriptViewComponents(): void;
1452
1991
 
1453
1992
  type ViewResolver = () => any;
@@ -2076,6 +2615,35 @@ declare class NativeScriptRouterModule {
2076
2615
  declare function rootRoute(router: Router): ActivatedRoute;
2077
2616
  declare function provideNativeScriptRouter(routes: Routes, ...features: RouterFeatures[]): i0.EnvironmentProviders;
2078
2617
 
2618
+ /**
2619
+ * True while the Angular HMR layer is restoring a captured route stack
2620
+ * onto the freshly-bootstrapped router. The window opens just before
2621
+ * `START_PATH` resolves to a deep URL and closes once the router has
2622
+ * walked the entire forward navigation list (or aborted it).
2623
+ *
2624
+ * User-app code that runs default navigations on component init (e.g. a
2625
+ * bottom-nav defaulting to its first tab) can consult this flag to skip
2626
+ * its default navigation so the framework's restored route survives:
2627
+ *
2628
+ * ```ts
2629
+ * if (isAngularHmrRestoringRoute()) {
2630
+ * return; // framework is restoring a deeper route — leave it alone.
2631
+ * }
2632
+ * defaultTabNavigation();
2633
+ * ```
2634
+ *
2635
+ * Returns `false` outside of HMR or after the replay window has closed.
2636
+ * Production builds always see `false` because the framework never
2637
+ * opens the window there.
2638
+ */
2639
+ declare function isAngularHmrRestoringRoute(): boolean;
2640
+ /**
2641
+ * The target route the framework is currently restoring, or `null` when
2642
+ * no replay is in progress. Useful when the consumer wants to compare
2643
+ * against the current router URL.
2644
+ */
2645
+ declare function getAngularHmrRestoringRoute(): string | null;
2646
+
2079
2647
  declare class NativeScriptDebug {
2080
2648
  static readonly animationsTraceCategory = "ns-animations";
2081
2649
  static readonly rendererTraceCategory = "ns-renderer";
@@ -2260,5 +2828,5 @@ declare class NativeScriptNgZone implements NgZone {
2260
2828
  }
2261
2829
  declare function provideNativeScriptNgZone(options?: NgZoneOptions): i0.StaticProvider[];
2262
2830
 
2263
- export { APP_ROOT_VIEW, ActionBarComponent, ActionBarScope, ActionItemDirective, AndroidFilterComponent, AppHostAsyncView, AppHostView, AppleFilterComponent, BasePortalOutlet, BaseValueAccessor, COMMON_PROVIDERS, CdkPortal, CdkPortalOutlet, CheckedValueAccessor, CommentNode, ComponentPortal, DEVICE, DISABLE_ROOT_VIEW_HANDLING, DateValueAccessor, DetachedLoader, DomPortal, ENABLE_REUSABE_VIEWS, EmulatedRenderer, FrameDirective, FramePageComponent, FramePageModule, FrameService, IOSFilterComponent, InjectableAnimationEngine, InvisibleNode, ItemContext, ListViewComponent, ModalDialogParams, ModalDialogService, NAMESPACE_FILTERS, NATIVESCRIPT_MODULE_PROVIDERS, NATIVESCRIPT_MODULE_STATIC_PROVIDERS, NATIVESCRIPT_ROOT_MODULE_ID, NATIVE_DIALOG_DATA, NATIVE_DIALOG_DEFAULT_OPTIONS, NSEmptyOutletComponent, NSFileSystem, NSLocationStrategy, NSRouteReuseStrategy, NSRouterLink, NSRouterLinkActive, NativeDialog, NativeDialogCloseDirective, NativeDialogConfig, NativeDialogModule, NativeDialogRef, NativeDialog as NativeDialogService, NativeDialogState, NativeModalRef, NativeScriptAnimationDriver, NativeScriptAnimationPlayer, NativeScriptAnimationsModule, NativeScriptCommonModule, NativeScriptDocument, NativeScriptDomPortalOutlet, NativeScriptFormsModule, NativeScriptHttpClientModule, NativeScriptLoadingService, NativeScriptModule, NativeScriptNgSafeEvent, NativeScriptNgZone, NativeScriptRendererFactory, NativeScriptRendererHelperService, NativeScriptRouterModule, NativeScriptSanitizer, NativescriptXhrFactory, NavigationButtonDirective, NgViewRef, NsHttpBackEnd, NsTemplatedItem, NumberValueAccessor, Outlet, PAGE_FACTORY, PREVENT_CHANGE_EVENTS_DURING_CD, PREVENT_SPECIFIC_EVENTS_DURING_CD, PageDirective, PageRoute, PageRouterOutlet, PageService, PlatformNamespaceFilter, Portal, PortalModule, RootCompositeModule, RootViewProxy, RouterExtensions, START_PATH, SelectedIndexValueAccessor, TEMPLATED_ITEMS_COMPONENT, TabViewDirective, TabViewItemDirective, TemplateKeyDirective, TemplatePortal, TextNode, TextValueAccessor, TimeValueAccessor, VisionOSFilterComponent, bootstrapApplication, createKeyframeAnimation, customFrameComponentFactory, customFrameDirectiveFactory, customPageFactory, customPageFactoryFromFrame, dashCaseToCamelCase, defaultNavOptions, defaultPageFactory, defaultPageFactoryProvider, detachViewFromParent, disableRootViewHanding, errorHandler, extractSingleViewRecursive, frameMeta, generateDetachedLoader, generateFallbackRootView, generateNativeScriptView, generateRandomId, generateRootLayoutAndProxy, getFirstNativeLikeView, getItemViewRoot, getSingleViewRecursive, getViewClass, getViewMeta, instantiateDefaultStyleNormalizer, instantiateSupportedAnimationDriver, isBlank, isContentView, isDetachedElement, isInvisibleNode, isJsObject, isKnownView, isLayout, isListLikeIterable, isPresent, isView, onAfterLivesync, onBeforeLivesync, once, platformNativeScript, platformNativeScriptDynamic, postAngularBootstrap$, preAngularDisposal$, provideLocationStrategy, provideNativeScriptHttpClient, provideNativeScriptNgZone, provideNativeScriptRouter, registerElement, registerNativeScriptViewComponents, rootRoute, runNativeScriptAngularApp, throwIfAlreadyLoaded, throwNoPortalAttachedError, throwNullPortalError, throwNullPortalOutletError, throwPortalAlreadyAttachedError, throwPortalOutletAlreadyDisposedError, throwUnknownPortalTypeError, COMPONENT_VARIABLE as ɵCOMPONENT_VARIABLE, CONTENT_ATTR as ɵCONTENT_ATTR, HOST_ATTR as ɵHOST_ATTR, NativeScriptDebug as ɵNativeScriptAngularDebug, viewUtil_d as ɵViewUtil, actionBarMeta as ɵactionBarMeta, elementMap as ɵelementMap, isActionItem as ɵisActionItem, isNavigationButton as ɵisNavigationButton };
2264
- export type { AppLaunchView, AppOptions, AppRunOptions, ApplicationConfig, BaseShowModalOptions, CdkPortalOutletAttachedRef, ComponentType, HmrOptions, Keyframe, LocationState, ModalDialogOptions, NamespaceFilter, NativeShowModalOptions, NavigationOptions, NgModuleEvent, NgModuleReason, NgView, NgViewTemplate, PageFactory, PageFactoryOptions, PortalOutlet, RootLocator, SelectableView, SetupItemViewArgs, ShowDialogOptions, TabViewItemDef, TemplatedItemsHost, TextView, ViewClass, ViewClassMeta, ViewExtensions, ViewResolver };
2831
+ export { APP_ROOT_VIEW, ActionBarComponent, ActionBarScope, ActionItemDirective, AndroidFilterComponent, AppHostAsyncView, AppHostView, AppleFilterComponent, BasePortalOutlet, BaseValueAccessor, COMMON_PROVIDERS, CdkPortal, CdkPortalOutlet, CheckedValueAccessor, CommentNode, ComponentPortal, DEVICE, DISABLE_ROOT_VIEW_HANDLING, DateValueAccessor, DetachedLoader, DomPortal, ENABLE_REUSABE_VIEWS, EmulatedRenderer, FrameDirective, FramePageComponent, FramePageModule, FrameService, HmrCacheService, HmrCacheStore, IOSFilterComponent, InjectableAnimationEngine, InvisibleNode, ItemContext, ListViewComponent, ModalDialogParams, ModalDialogService, NAMESPACE_FILTERS, NATIVESCRIPT_MODULE_PROVIDERS, NATIVESCRIPT_MODULE_STATIC_PROVIDERS, NATIVESCRIPT_ROOT_MODULE_ID, NATIVE_DIALOG_DATA, NATIVE_DIALOG_DEFAULT_OPTIONS, NSEmptyOutletComponent, NSFileSystem, NSLocationStrategy, NSRouteReuseStrategy, NSRouterLink, NSRouterLinkActive, NativeDialog, NativeDialogCloseDirective, NativeDialogConfig, NativeDialogModule, NativeDialogRef, NativeDialog as NativeDialogService, NativeDialogState, NativeModalRef, NativeScriptAnimationDriver, NativeScriptAnimationPlayer, NativeScriptAnimationsModule, NativeScriptCommonModule, NativeScriptDocument, NativeScriptDomPortalOutlet, NativeScriptFormsModule, NativeScriptHttpClientModule, NativeScriptLoadingService, NativeScriptModule, NativeScriptNgSafeEvent, NativeScriptNgZone, NativeScriptRendererFactory, NativeScriptRendererHelperService, NativeScriptRouterModule, NativeScriptSanitizer, NativescriptXhrFactory, NavigationButtonDirective, NgViewRef, NsHttpBackEnd, NsTemplatedItem, NumberValueAccessor, Outlet, PAGE_FACTORY, PREVENT_CHANGE_EVENTS_DURING_CD, PREVENT_SPECIFIC_EVENTS_DURING_CD, PageDirective, PageRoute, PageRouterOutlet, PageService, PlatformNamespaceFilter, Portal, PortalModule, RootCompositeModule, RootViewProxy, RouterExtensions, START_PATH, SelectedIndexValueAccessor, TEMPLATED_ITEMS_COMPONENT, TabViewDirective, TabViewItemDirective, TemplateKeyDirective, TemplatePortal, TextNode, TextValueAccessor, TimeValueAccessor, VisionOSFilterComponent, bootstrapApplication, configureHmrCache, createDefaultHmrCacheStore, createKeyframeAnimation, customFrameComponentFactory, customFrameDirectiveFactory, customPageFactory, customPageFactoryFromFrame, dashCaseToCamelCase, defaultNavOptions, defaultPageFactory, defaultPageFactoryProvider, detachViewFromParent, disableRootViewHanding, errorHandler, extractSingleViewRecursive, frameMeta, generateDetachedLoader, generateFallbackRootView, generateNativeScriptView, generateRandomId, generateRootLayoutAndProxy, getAngularHmrRestoringRoute, getFirstNativeLikeView, getHmrCacheStore, getItemViewRoot, getSingleViewRecursive, getViewClass, getViewMeta, instantiateDefaultStyleNormalizer, instantiateSupportedAnimationDriver, isAngularHmrRestoringRoute, isBlank, isContentView, isDetachedElement, isInvisibleNode, isJsObject, isKnownView, isLayout, isListLikeIterable, isPresent, isView, onAfterLivesync, onBeforeLivesync, once, platformNativeScript, platformNativeScriptDynamic, postAngularBootstrap$, preAngularDisposal$, provideLocationStrategy, provideNativeScriptHttpClient, provideNativeScriptNgZone, provideNativeScriptRouter, registerElement, registerNativeScriptViewComponents, rootRoute, runNativeScriptAngularApp, throwIfAlreadyLoaded, throwNoPortalAttachedError, throwNullPortalError, throwNullPortalOutletError, throwPortalAlreadyAttachedError, throwPortalOutletAlreadyDisposedError, throwUnknownPortalTypeError, COMPONENT_VARIABLE as ɵCOMPONENT_VARIABLE, CONTENT_ATTR as ɵCONTENT_ATTR, HOST_ATTR as ɵHOST_ATTR, NativeScriptDebug as ɵNativeScriptAngularDebug, viewUtil_d as ɵViewUtil, actionBarMeta as ɵactionBarMeta, elementMap as ɵelementMap, isActionItem as ɵisActionItem, isNavigationButton as ɵisNavigationButton };
2832
+ export type { AppLaunchView, AppOptions, AppRunOptions, ApplicationConfig, BaseShowModalOptions, CdkPortalOutletAttachedRef, ComponentType, HmrCacheScope, HmrCacheStoreOptions, HmrOptions, Keyframe, LocationState, ModalDialogOptions, NamespaceFilter, NativeShowModalOptions, NavigationOptions, NgModuleEvent, NgModuleReason, NgView, NgViewTemplate, PageFactory, PageFactoryOptions, PortalOutlet, RootLocator, SelectableView, SetupItemViewArgs, ShowDialogOptions, TabViewItemDef, TemplatedItemsHost, TextView, ViewClass, ViewClassMeta, ViewExtensions, ViewResolver };