@ng-desktop/platform 0.6.0 → 0.7.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.
package/README.md CHANGED
@@ -18,7 +18,6 @@ import { bootstrapNativeApplication, NATIVE_UI_DIRECTIVES } from '@ng-desktop/pl
18
18
 
19
19
  @Component({
20
20
  selector: 'app-root',
21
- standalone: true,
22
21
  imports: [NATIVE_UI_DIRECTIVES],
23
22
  template: `
24
23
  <ng-window id="win" title="Desktop App">
@@ -1,18 +1,23 @@
1
1
  import { type NativeComputeMatch, type NativeXdgDirKind } from './bridge-fs-compute';
2
2
  export type { NativeComputeMatch, NativeXdgDirKind } from './bridge-fs-compute';
3
+ /** Logical transport category reported to Rust `NativeHttpEngine` and telemetry. */
3
4
  export type NativeHttpCallKind = 'json' | 'graphql' | 'asset' | 'batch' | 'text';
5
+ /** OS network reachability classification exposed by `NativeNetworkService`. */
4
6
  export type NativeConnectivity = 'full' | 'limited' | 'offline';
7
+ /** Snapshot of OS connectivity and metered network status. */
5
8
  export interface NativeNetworkStatus {
6
9
  online: boolean;
7
10
  metered: boolean;
8
11
  connectivity: NativeConnectivity;
9
12
  }
13
+ /** Per-request headers and options passed across `bridge.httpRequest`. */
10
14
  export interface NativeHttpRequestOptions {
11
15
  headers?: Record<string, string>;
12
16
  responseType?: string;
13
17
  callKind?: NativeHttpCallKind;
14
18
  withCredentials?: boolean;
15
19
  }
20
+ /** Global configuration shared with Rust `NativeHttpEngine` (HTTP/2, XSRF, caching). */
16
21
  export interface NativeHttpConfig {
17
22
  platform?: string;
18
23
  useFetchTransport?: boolean;
@@ -29,6 +29,11 @@ export interface ParsedStyleRule {
29
29
  }
30
30
  export declare function parsePixelInt(raw: string): number | null;
31
31
  export declare function mapAlignKeyword(raw: string): string | null;
32
+ export interface SharedRuntimeCssVars {
33
+ baseVars: Map<string, string>;
34
+ lightVars: Map<string, string>;
35
+ darkVars: Map<string, string>;
36
+ }
32
37
  /**
33
38
  * Parses component CSS rules at runtime into `ParsedStyleRule` descriptors compatible with
34
39
  * the Rust engine's CSS Flexbox/Grid, pseudo-classes, `@media`, variables, and encapsulation syntax.
@@ -38,4 +43,4 @@ export declare function parseRuntimeStyles(cssSource: string): ParsedStyleRule[]
38
43
  * Formats optional `ParsedStyleRule` layout/typography/media/pseudo fields as space-separated `key=value` tokens.
39
44
  */
40
45
  export declare function formatParsedStyleExtensions(rule: ParsedStyleRule): string;
41
- export declare function registerParsedStyles(bridge: NgNativeBridge, styles: readonly string[], scopedClassesByScope?: Map<string, Set<string>>): void;
46
+ export declare function registerParsedStyles(bridge: NgNativeBridge, styles: readonly string[], scopedClassesByScope?: Map<string, Set<string>>, sharedVars?: SharedRuntimeCssVars): void;
@@ -529,12 +529,12 @@ function applyDeclaration(rule, rawProp, val) {
529
529
  applyRuntimeLayoutDeclaration(rule, prop, val);
530
530
  }
531
531
  }
532
- function parseRuntimeStyleEntries(cssSource) {
532
+ function parseRuntimeStyleEntries(cssSource, sharedVars) {
533
533
  const cleaned = cssSource.replace(/\/\*[\s\S]*?\*\//g, '');
534
534
  const blocks = extractCssBlocks(cleaned);
535
- const baseVars = new Map();
536
- const lightVars = new Map();
537
- const darkVars = new Map();
535
+ const baseVars = sharedVars?.baseVars ?? new Map();
536
+ const lightVars = sharedVars?.lightVars ?? new Map();
537
+ const darkVars = sharedVars?.darkVars ?? new Map();
538
538
  for (const block of blocks) {
539
539
  const selectors = block.selectorText.split(',');
540
540
  if (!selectors.some(isVariableRootSelector)) {
@@ -669,12 +669,12 @@ export function formatParsedStyleExtensions(rule) {
669
669
  }
670
670
  return extensions.join(' ');
671
671
  }
672
- export function registerParsedStyles(bridge, styles, scopedClassesByScope) {
672
+ export function registerParsedStyles(bridge, styles, scopedClassesByScope, sharedVars) {
673
673
  for (const css of styles) {
674
674
  if (typeof css !== 'string' || css.trim().length === 0) {
675
675
  continue;
676
676
  }
677
- for (const entry of parseRuntimeStyleEntries(css)) {
677
+ for (const entry of parseRuntimeStyleEntries(css, sharedVars)) {
678
678
  if (entry.scopeToken && scopedClassesByScope) {
679
679
  let classes = scopedClassesByScope.get(entry.scopeToken);
680
680
  if (!classes) {
@@ -42,8 +42,7 @@ export declare const NATIVE_BRIDGE: InjectionToken<NgNativeBridge>;
42
42
  export declare class NativeStorage implements Storage {
43
43
  private readonly store;
44
44
  private readonly bridge;
45
- private nextId;
46
- constructor(bridge?: NgNativeBridge | null);
45
+ constructor();
47
46
  private ensureTable;
48
47
  get length(): number;
49
48
  key(index: number): string | null;
@@ -51,7 +50,7 @@ export declare class NativeStorage implements Storage {
51
50
  setItem(key: string, value: string): void;
52
51
  removeItem(key: string): void;
53
52
  clear(): void;
54
- static ɵfac: i0.ɵɵFactoryDeclaration<NativeStorage, [{ optional: true; }]>;
53
+ static ɵfac: i0.ɵɵFactoryDeclaration<NativeStorage, never>;
55
54
  static ɵprov: i0.ɵɵInjectableDeclaration<any>;
56
55
  }
57
56
  /**
@@ -61,11 +60,10 @@ export declare class NativeStorage implements Storage {
61
60
  export declare class NativeAriaAnnouncer {
62
61
  private readonly announcements;
63
62
  private readonly bridge;
64
- constructor(bridge?: NgNativeBridge | null);
65
63
  announce(message: string, politeness?: AriaPoliteness): Promise<void>;
66
64
  clear(): void;
67
65
  history(): readonly NativeAriaAnnouncement[];
68
- static ɵfac: i0.ɵɵFactoryDeclaration<NativeAriaAnnouncer, [{ optional: true; }]>;
66
+ static ɵfac: i0.ɵɵFactoryDeclaration<NativeAriaAnnouncer, never>;
69
67
  static ɵprov: i0.ɵɵInjectableDeclaration<any>;
70
68
  }
71
69
  /**
@@ -1,4 +1,4 @@
1
- import { Inject, Injectable, InjectionToken, makeEnvironmentProviders, Optional, } from '@angular/core';
1
+ import { inject, Injectable, InjectionToken, makeEnvironmentProviders, } from '@angular/core';
2
2
  import { ensureNgNativeBridge } from './bridge.js';
3
3
  import { getNativeActiveElement, NativeElementNode } from './native-element.js';
4
4
  import * as i0 from "@angular/core";
@@ -9,16 +9,22 @@ export const NATIVE_BRIDGE = new InjectionToken('NATIVE_BRIDGE', {
9
9
  providedIn: 'root',
10
10
  factory: () => ensureNgNativeBridge(),
11
11
  });
12
+ function resolveOptionalBridge() {
13
+ try {
14
+ return inject(NATIVE_BRIDGE, { optional: true }) ?? ensureNgNativeBridge();
15
+ }
16
+ catch {
17
+ return ensureNgNativeBridge();
18
+ }
19
+ }
12
20
  /**
13
21
  * Web `Storage`-compatible persistence adapter backed by the native SQLite engine (`ng_native_storage`)
14
22
  * and an in-memory map, enabling `@ngrx/store` meta-reducers and state hydration without a browser DOM.
15
23
  */
16
24
  export class NativeStorage {
17
25
  store = new Map();
18
- bridge;
19
- nextId = 1;
20
- constructor(bridge) {
21
- this.bridge = bridge ?? ensureNgNativeBridge();
26
+ bridge = resolveOptionalBridge();
27
+ constructor() {
22
28
  this.ensureTable();
23
29
  }
24
30
  ensureTable() {
@@ -51,11 +57,9 @@ export class NativeStorage {
51
57
  }
52
58
  setItem(key, value) {
53
59
  const strValue = String(value);
54
- const idNum = this.nextId++;
55
60
  this.store.set(key, strValue);
56
61
  try {
57
62
  this.bridge.sqliteExecute(`INSERT OR REPLACE INTO ng_native_storage (key, val) VALUES ('${escapeSqlLiteral(key)}', '${escapeSqlLiteral(strValue)}')`);
58
- this.bridge.setAttribute('__ng_native_storage__', `k_${idNum}`, key);
59
63
  }
60
64
  catch {
61
65
  // In-memory store remains consistent when disk persistence is unavailable
@@ -79,28 +83,20 @@ export class NativeStorage {
79
83
  // Ignore bridge persistence error in restricted sandboxes
80
84
  }
81
85
  }
82
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeStorage, deps: [{ token: NATIVE_BRIDGE, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
86
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeStorage, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
83
87
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeStorage, providedIn: 'root' });
84
88
  }
85
89
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeStorage, decorators: [{
86
90
  type: Injectable,
87
91
  args: [{ providedIn: 'root' }]
88
- }], ctorParameters: () => [{ type: undefined, decorators: [{
89
- type: Optional
90
- }, {
91
- type: Inject,
92
- args: [NATIVE_BRIDGE]
93
- }] }] });
92
+ }], ctorParameters: () => [] });
94
93
  /**
95
94
  * Headless `@angular/cdk/a11y` `LiveAnnouncer`-compatible service for `@angular/aria` and native
96
95
  * GTK4/WinUI/AppKit accessibility announcements.
97
96
  */
98
97
  export class NativeAriaAnnouncer {
99
98
  announcements = [];
100
- bridge;
101
- constructor(bridge) {
102
- this.bridge = bridge ?? ensureNgNativeBridge();
103
- }
99
+ bridge = resolveOptionalBridge();
104
100
  announce(message, politeness = 'polite') {
105
101
  const clean = String(message ?? '').trim();
106
102
  if (!clean) {
@@ -116,18 +112,13 @@ export class NativeAriaAnnouncer {
116
112
  history() {
117
113
  return this.announcements;
118
114
  }
119
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeAriaAnnouncer, deps: [{ token: NATIVE_BRIDGE, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
115
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeAriaAnnouncer, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
120
116
  static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeAriaAnnouncer, providedIn: 'root' });
121
117
  }
122
118
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeAriaAnnouncer, decorators: [{
123
119
  type: Injectable,
124
120
  args: [{ providedIn: 'root' }]
125
- }], ctorParameters: () => [{ type: undefined, decorators: [{
126
- type: Optional
127
- }, {
128
- type: Inject,
129
- args: [NATIVE_BRIDGE]
130
- }] }] });
121
+ }] });
131
122
  /**
132
123
  * Redux DevTools (`__REDUX_DEVTOOLS_EXTENSION__`) bridge allowing `@ngrx/store-devtools`
133
124
  * to attach cleanly inside JavaScriptCore / QuickJS without browser extensions.
@@ -156,7 +156,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImpor
156
156
  type: Directive,
157
157
  args: [{
158
158
  selector: 'ng-window,adw-window,ng-dialog,gtk-dialog,adw-dialog,ng-header-bar,adw-header-bar,gtk-header-bar,ng-scroll,gtk-scrolled-window,ng-box,gtk-box,ng-grid,gtk-grid,ng-separator,gtk-separator,ng-button,gtk-button,ng-label,gtk-label,ng-entry,gtk-entry,ng-switch,gtk-switch,ng-checkbox,ng-check,ng-check-button,gtk-check-button,ng-slider,ng-scale,gtk-scale,ng-select,ng-dropdown,gtk-dropdown,gtk-drop-down,ng-image,adw-image,gtk-picture,ng-picture,ng-level-bar,gtk-level-bar,ng-flow,ng-flow-box,gtk-flow-box,ng-spinner,gtk-spinner,ng-progress-bar,gtk-progress-bar,ng-paned,gtk-paned,ng-stack,gtk-stack,adw-navigation-view,ng-expander,gtk-expander,ng-text-view,gtk-text-view,ng-password-entry,gtk-password-entry,ng-spin-button,gtk-spin-button,ng-search-entry,gtk-search-entry,ng-clamp,adw-clamp,ng-list,ng-table,gtk-list-box,gtk-list-view,ng-popover,gtk-popover,ng-menu,adw-entry-row,adw-password-entry-row,adw-switch-row,adw-combo-row,adw-spin-row',
159
- standalone: true,
160
159
  }]
161
160
  }], propDecorators: { hexpand: [{
162
161
  type: Input
@@ -256,7 +255,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImpor
256
255
  type: Directive,
257
256
  args: [{
258
257
  selector: 'ng-window,adw-window,ng-dialog,gtk-dialog,adw-dialog,ng-header-bar,adw-header-bar,gtk-header-bar',
259
- standalone: true,
260
258
  }]
261
259
  }], propDecorators: { title: [{
262
260
  type: Input
@@ -370,7 +368,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImpor
370
368
  type: Directive,
371
369
  args: [{
372
370
  selector: 'ng-box,gtk-box,ng-grid,gtk-grid,ng-flow,ng-flow-box,gtk-flow-box,ng-paned,gtk-paned,ng-scroll,gtk-scrolled-window,ng-stack,gtk-stack,adw-navigation-view,ng-expander,gtk-expander,ng-clamp,adw-clamp,ng-separator,gtk-separator',
373
- standalone: true,
374
371
  }]
375
372
  }], propDecorators: { orientation: [{
376
373
  type: Input
@@ -462,7 +459,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImpor
462
459
  type: Directive,
463
460
  args: [{
464
461
  selector: 'ng-button,gtk-button,ng-label,gtk-label',
465
- standalone: true,
466
462
  }]
467
463
  }], propDecorators: { label: [{
468
464
  type: Input
@@ -515,7 +511,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImpor
515
511
  type: Directive,
516
512
  args: [{
517
513
  selector: 'ng-image,adw-image,gtk-picture,ng-picture,ng-level-bar,gtk-level-bar,ng-progress-bar,gtk-progress-bar,ng-spinner,gtk-spinner',
518
- standalone: true,
519
514
  }]
520
515
  }], propDecorators: { src: [{
521
516
  type: Input
@@ -585,7 +580,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImpor
585
580
  type: Directive,
586
581
  args: [{
587
582
  selector: 'ng-entry,gtk-entry,ng-search-entry,gtk-search-entry,ng-password-entry,gtk-password-entry,ng-text-view,gtk-text-view,ng-switch,gtk-switch,ng-checkbox,ng-check,ng-check-button,gtk-check-button,ng-slider,ng-scale,gtk-scale,ng-spin-button,gtk-spin-button,ng-select,ng-dropdown,gtk-dropdown,gtk-drop-down,adw-entry-row,adw-password-entry-row,adw-switch-row,adw-combo-row,adw-spin-row',
588
- standalone: true,
589
583
  }]
590
584
  }], propDecorators: { placeholder: [{
591
585
  type: Input
@@ -641,7 +635,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImpor
641
635
  type: Directive,
642
636
  args: [{
643
637
  selector: 'ng-list,ng-table,gtk-list-box,gtk-list-view',
644
- standalone: true,
645
638
  }]
646
639
  }], propDecorators: { selectionModeAttr: [{
647
640
  type: Input,
@@ -690,7 +683,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImpor
690
683
  type: Directive,
691
684
  args: [{
692
685
  selector: 'ng-popover,gtk-popover,ng-menu',
693
- standalone: true,
694
686
  }]
695
687
  }], propDecorators: { open: [{
696
688
  type: Input
@@ -731,7 +723,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImpor
731
723
  type: Directive,
732
724
  args: [{
733
725
  selector: 'ng-slider,ng-scale,gtk-scale,ng-spin-button,gtk-spin-button,adw-spin-row',
734
- standalone: true,
735
726
  }]
736
727
  }], propDecorators: { min: [{
737
728
  type: Input
@@ -79,6 +79,7 @@ export declare class NativeRendererFactory2 implements RendererFactory2 {
79
79
  private readonly defaultRenderer;
80
80
  private readonly registeredTypeIds;
81
81
  private readonly scopedClassesByScope;
82
+ private readonly sharedRootVars;
82
83
  private nodeCounter;
83
84
  private primaryWindowId;
84
85
  private primaryScrollId;
@@ -214,6 +214,7 @@ function mapNativeEventNames(eventName) {
214
214
  case 'dragleave':
215
215
  return ['dragleave'];
216
216
  case 'drop':
217
+ case 'file-drop':
217
218
  return ['drop', 'files-dropped'];
218
219
  default:
219
220
  return [eventName];
@@ -667,7 +668,36 @@ export class NativeRenderer2 extends Renderer2 {
667
668
  removeStyle(el, style, _flags) {
668
669
  el.styles.delete(style);
669
670
  if (!el.isVirtual) {
670
- this.bridge.setAttribute(el.id, style, '');
671
+ const key = style.trim().toLowerCase();
672
+ let nativeAttr = style;
673
+ if (key === 'flex' || key === 'flex-grow' || key === 'width') {
674
+ nativeAttr = 'hexpand';
675
+ }
676
+ else if (key === 'height') {
677
+ nativeAttr = 'vexpand';
678
+ }
679
+ else if (key === 'flex-direction') {
680
+ nativeAttr = 'orientation';
681
+ }
682
+ else if (key === 'gap') {
683
+ nativeAttr = 'spacing';
684
+ }
685
+ else if (key === 'row-gap' || key === 'column-gap') {
686
+ nativeAttr = key.replace('-gap', '-spacing');
687
+ }
688
+ else if (key === 'justify-self') {
689
+ nativeAttr = 'halign';
690
+ }
691
+ else if (key === 'align-self') {
692
+ nativeAttr = 'valign';
693
+ }
694
+ else if (key === 'margin-left') {
695
+ nativeAttr = 'margin-start';
696
+ }
697
+ else if (key === 'margin-right') {
698
+ nativeAttr = 'margin-end';
699
+ }
700
+ this.bridge.setAttribute(el.id, nativeAttr, '');
671
701
  }
672
702
  }
673
703
  setProperty(el, name, value) {
@@ -798,10 +828,12 @@ export class NativeRenderer2 extends Renderer2 {
798
828
  };
799
829
  }
800
830
  if (target.isVirtual) {
801
- // Built-in virtual containers own their internal <ng-scroll> and expose scrollBottom as an Angular output;
802
- // forwarding the host DOM listener to <ng-scroll> would fire every scrollBottom binding twice.
803
- if ((target.tag === 'ng-virtual-list' || target.tag === 'ng-virtual-grid') &&
804
- (eventName === 'scrollBottom' || eventName === 'scroll-bottom')) {
831
+ // Built-in virtual containers own their internal <ng-scroll> / <ng-list> and expose scrollBottom /
832
+ // rowActivated as Angular outputs; forwarding host DOM listeners would fire them twice with raw payloads.
833
+ if (((target.tag === 'ng-virtual-list' || target.tag === 'ng-virtual-grid') &&
834
+ (eventName === 'scrollBottom' || eventName === 'scroll-bottom')) ||
835
+ (target.tag === 'ng-virtual-list' &&
836
+ (eventName === 'rowActivated' || eventName === 'row-activated'))) {
805
837
  return () => { };
806
838
  }
807
839
  const reg = {
@@ -1076,6 +1108,11 @@ export class NativeRendererFactory2 {
1076
1108
  defaultRenderer;
1077
1109
  registeredTypeIds = new Set();
1078
1110
  scopedClassesByScope = new Map();
1111
+ sharedRootVars = {
1112
+ baseVars: new Map(),
1113
+ lightVars: new Map(),
1114
+ darkVars: new Map(),
1115
+ };
1079
1116
  nodeCounter = 1;
1080
1117
  primaryWindowId = null;
1081
1118
  primaryScrollId = null;
@@ -1088,7 +1125,7 @@ export class NativeRendererFactory2 {
1088
1125
  this.primaryWindowId = id;
1089
1126
  }
1090
1127
  }
1091
- else if (tag === 'ng-scroll' || tag === 'adw-scroll') {
1128
+ else if (tag === 'ng-scroll' || tag === 'gtk-scrolled-window') {
1092
1129
  if (!this.primaryScrollId || !this.nodesById.has(this.primaryScrollId)) {
1093
1130
  this.primaryScrollId = id;
1094
1131
  }
@@ -1102,7 +1139,7 @@ export class NativeRendererFactory2 {
1102
1139
  const typeKey = type.id || '__anonymous__';
1103
1140
  if (!this.registeredTypeIds.has(typeKey)) {
1104
1141
  this.registeredTypeIds.add(typeKey);
1105
- registerParsedStyles(this.bridge, type.styles, this.scopedClassesByScope);
1142
+ registerParsedStyles(this.bridge, type.styles, this.scopedClassesByScope, this.sharedRootVars);
1106
1143
  }
1107
1144
  }
1108
1145
  return this.defaultRenderer;
@@ -1131,7 +1168,7 @@ export class NativeRendererFactory2 {
1131
1168
  return this.primaryScrollId;
1132
1169
  }
1133
1170
  for (const node of this.nodesById.values()) {
1134
- if (!node.isVirtual && (node.tag === 'ng-scroll' || node.tag === 'adw-scroll')) {
1171
+ if (!node.isVirtual && (node.tag === 'ng-scroll' || node.tag === 'gtk-scrolled-window')) {
1135
1172
  this.primaryScrollId = node.id;
1136
1173
  return node.id;
1137
1174
  }
@@ -90,7 +90,8 @@ export class NativeKeyEventsPlugin extends EventManagerPlugin {
90
90
  }
91
91
  supports(eventName) {
92
92
  const lower = eventName.trim().toLowerCase();
93
- return (lower.startsWith('keydown.') || lower.startsWith('keyup.')) && lower.length > 8;
93
+ return ((lower.startsWith('keydown.') && lower.length > 8) ||
94
+ (lower.startsWith('keyup.') && lower.length > 6));
94
95
  }
95
96
  addEventListener(element, eventName, handler) {
96
97
  const baseEvent = eventName.trim().toLowerCase().startsWith('keyup.') ? 'keyup' : 'keydown';
@@ -38,6 +38,8 @@ export declare class NativeVirtualGridComponent<T = unknown> {
38
38
  readonly projectedTemplate: import("@angular/core").Signal<TemplateRef<NativeVirtualGridItemContext<T>> | undefined>;
39
39
  readonly rangeChange: import("@angular/core").OutputEmitterRef<VirtualGridSliceRange>;
40
40
  readonly scrollBottom: import("@angular/core").OutputEmitterRef<void>;
41
+ private readonly renderer;
42
+ private readonly scrollHost;
41
43
  readonly scrollTop: import("@angular/core").WritableSignal<number>;
42
44
  readonly measuredWidth: import("@angular/core").WritableSignal<number | null>;
43
45
  readonly measuredHeight: import("@angular/core").WritableSignal<number | null>;
@@ -48,6 +50,8 @@ export declare class NativeVirtualGridComponent<T = unknown> {
48
50
  readonly resolvedTemplate: import("@angular/core").Signal<TemplateRef<NativeVirtualGridItemContext<T>> | null>;
49
51
  readonly effectiveWidth: import("@angular/core").Signal<number>;
50
52
  readonly effectiveHeight: import("@angular/core").Signal<number>;
53
+ /** Builds/updates the Fenwick row-offset tree only when layout geometry or items change, not on scroll. */
54
+ private readonly rowHeightTreeState;
51
55
  readonly range: import("@angular/core").Signal<VirtualGridSliceRange>;
52
56
  readonly visibleEntries: import("@angular/core").Signal<readonly NativeVirtualGridEntry<T>[]>;
53
57
  private lastEmittedRangeKey;
@@ -1,5 +1,5 @@
1
1
  import { NgTemplateOutlet } from '@angular/common';
2
- import { Component, computed, contentChild, effect, input, output, signal, TemplateRef, } from '@angular/core';
2
+ import { Component, computed, contentChild, effect, inject, input, output, Renderer2, signal, TemplateRef, viewChild, } from '@angular/core';
3
3
  import { NativeContainerDirective, NativeElementDirective, NativeTextWidgetDirective, } from './native-directives.js';
4
4
  import { computeVirtualGridSliceRange, FenwickOffsetTree, } from './virtual-layout.js';
5
5
  import * as i0 from "@angular/core";
@@ -39,6 +39,9 @@ export class NativeVirtualGridComponent {
39
39
  ...(ngDevMode ? [{ debugName: "projectedTemplate" }] : /* istanbul ignore next */ []));
40
40
  rangeChange = output();
41
41
  scrollBottom = output();
42
+ renderer = inject(Renderer2);
43
+ scrollHost = viewChild('scrollHost', /* @ts-ignore */
44
+ ...(ngDevMode ? [{ debugName: "scrollHost" }] : /* istanbul ignore next */ []));
42
45
  scrollTop = signal(0, /* @ts-ignore */
43
46
  ...(ngDevMode ? [{ debugName: "scrollTop" }] : /* istanbul ignore next */ []));
44
47
  measuredWidth = signal(null, /* @ts-ignore */
@@ -57,16 +60,17 @@ export class NativeVirtualGridComponent {
57
60
  ...(ngDevMode ? [{ debugName: "effectiveWidth" }] : /* istanbul ignore next */ []));
58
61
  effectiveHeight = computed(() => this.measuredHeight() ?? this.viewportHeight(), /* @ts-ignore */
59
62
  ...(ngDevMode ? [{ debugName: "effectiveHeight" }] : /* istanbul ignore next */ []));
60
- range = computed(() => {
63
+ /** Builds/updates the Fenwick row-offset tree only when layout geometry or items change, not on scroll. */
64
+ rowHeightTreeState = computed(() => {
61
65
  const source = this.items();
62
66
  const resolver = this.rowHeightResolver();
63
67
  this.measureRevision();
64
68
  const baseRowHeight = Math.max(1, this.rowHeight());
65
69
  const effWidth = this.effectiveWidth();
66
70
  const effHeight = this.effectiveHeight();
67
- const baseSlice = computeVirtualGridSliceRange({
71
+ const geometrySlice = computeVirtualGridSliceRange({
68
72
  totalItems: source.length,
69
- scrollTop: this.scrollTop(),
73
+ scrollTop: 0,
70
74
  viewportHeight: effHeight,
71
75
  viewportWidth: effWidth,
72
76
  rowHeight: baseRowHeight,
@@ -77,9 +81,13 @@ export class NativeVirtualGridComponent {
77
81
  overscanRows: this.overscanRows(),
78
82
  });
79
83
  if (resolver === null && this.rowOverrides.size === 0) {
80
- return baseSlice;
84
+ return {
85
+ tree: null,
86
+ baseRowHeight,
87
+ columns: geometrySlice.columns,
88
+ };
81
89
  }
82
- const totalRows = baseSlice.totalRows;
90
+ const totalRows = geometrySlice.totalRows;
83
91
  const overrides = new Map();
84
92
  if (resolver !== null) {
85
93
  for (let r = 0; r < totalRows; r += 1) {
@@ -92,18 +100,24 @@ export class NativeVirtualGridComponent {
92
100
  }
93
101
  }
94
102
  this.rowTree.reset(totalRows, baseRowHeight, overrides);
103
+ return { tree: this.rowTree, baseRowHeight, columns: geometrySlice.columns };
104
+ }, /* @ts-ignore */
105
+ ...(ngDevMode ? [{ debugName: "rowHeightTreeState" }] : /* istanbul ignore next */ []));
106
+ range = computed(() => {
107
+ const source = this.items();
108
+ const { tree, baseRowHeight, columns } = this.rowHeightTreeState();
95
109
  return computeVirtualGridSliceRange({
96
110
  totalItems: source.length,
97
111
  scrollTop: this.scrollTop(),
98
- viewportHeight: effHeight,
99
- viewportWidth: effWidth,
112
+ viewportHeight: this.effectiveHeight(),
113
+ viewportWidth: this.effectiveWidth(),
100
114
  rowHeight: baseRowHeight,
101
115
  minColumnWidth: this.minColumnWidth(),
102
- columns: baseSlice.columns,
116
+ columns,
103
117
  rowGap: this.rowGap(),
104
118
  columnGap: this.columnGap(),
105
119
  overscanRows: this.overscanRows(),
106
- rowHeights: this.rowTree,
120
+ rowHeights: tree ?? undefined,
107
121
  });
108
122
  }, /* @ts-ignore */
109
123
  ...(ngDevMode ? [{ debugName: "range" }] : /* istanbul ignore next */ []));
@@ -166,8 +180,16 @@ export class NativeVirtualGridComponent {
166
180
  const y = this.rowHeightResolver() !== null || this.rowOverrides.size > 0
167
181
  ? Math.round(this.rowTree.offsetOf(targetRow) + targetRow * rowGap)
168
182
  : Math.round(targetRow * (Math.max(1, this.rowHeight()) + rowGap));
183
+ const coords = `0,${y}`;
184
+ const sameCoords = this.scrollToAttr() === coords;
169
185
  this.scrollTop.set(y);
170
- this.scrollToAttr.set(`0,${y}`);
186
+ this.scrollToAttr.set(coords);
187
+ if (sameCoords) {
188
+ const hostEl = this.scrollHost()?.nativeElement;
189
+ if (hostEl) {
190
+ this.renderer.setAttribute(hostEl, 'scroll-to', coords);
191
+ }
192
+ }
171
193
  }
172
194
  onNativeScroll(event) {
173
195
  if (!event || typeof event !== 'object') {
@@ -191,8 +213,9 @@ export class NativeVirtualGridComponent {
191
213
  }
192
214
  }
193
215
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeVirtualGridComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
194
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.3.0", type: NativeVirtualGridComponent, isStandalone: true, selector: "ng-virtual-grid", inputs: { items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: false, transformFunction: null }, rowHeight: { classPropertyName: "rowHeight", publicName: "rowHeight", isSignal: true, isRequired: false, transformFunction: null }, minColumnWidth: { classPropertyName: "minColumnWidth", publicName: "minColumnWidth", isSignal: true, isRequired: false, transformFunction: null }, columns: { classPropertyName: "columns", publicName: "columns", isSignal: true, isRequired: false, transformFunction: null }, viewportHeight: { classPropertyName: "viewportHeight", publicName: "viewportHeight", isSignal: true, isRequired: false, transformFunction: null }, viewportWidth: { classPropertyName: "viewportWidth", publicName: "viewportWidth", isSignal: true, isRequired: false, transformFunction: null }, rowGap: { classPropertyName: "rowGap", publicName: "rowGap", isSignal: true, isRequired: false, transformFunction: null }, columnGap: { classPropertyName: "columnGap", publicName: "columnGap", isSignal: true, isRequired: false, transformFunction: null }, overscanRows: { classPropertyName: "overscanRows", publicName: "overscanRows", isSignal: true, isRequired: false, transformFunction: null }, gridClass: { classPropertyName: "gridClass", publicName: "gridClass", isSignal: true, isRequired: false, transformFunction: null }, gridId: { classPropertyName: "gridId", publicName: "gridId", isSignal: true, isRequired: false, transformFunction: null }, rowHeightResolver: { classPropertyName: "rowHeightResolver", publicName: "rowHeightResolver", isSignal: true, isRequired: false, transformFunction: null }, trackBy: { classPropertyName: "trackBy", publicName: "trackBy", isSignal: true, isRequired: false, transformFunction: null }, itemTemplateInput: { classPropertyName: "itemTemplateInput", publicName: "itemTemplate", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { rangeChange: "rangeChange", scrollBottom: "scrollBottom" }, queries: [{ propertyName: "projectedTemplate", first: true, predicate: TemplateRef, descendants: true, isSignal: true }], ngImport: i0, template: `
216
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.3.0", type: NativeVirtualGridComponent, isStandalone: true, selector: "ng-virtual-grid", inputs: { items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: false, transformFunction: null }, rowHeight: { classPropertyName: "rowHeight", publicName: "rowHeight", isSignal: true, isRequired: false, transformFunction: null }, minColumnWidth: { classPropertyName: "minColumnWidth", publicName: "minColumnWidth", isSignal: true, isRequired: false, transformFunction: null }, columns: { classPropertyName: "columns", publicName: "columns", isSignal: true, isRequired: false, transformFunction: null }, viewportHeight: { classPropertyName: "viewportHeight", publicName: "viewportHeight", isSignal: true, isRequired: false, transformFunction: null }, viewportWidth: { classPropertyName: "viewportWidth", publicName: "viewportWidth", isSignal: true, isRequired: false, transformFunction: null }, rowGap: { classPropertyName: "rowGap", publicName: "rowGap", isSignal: true, isRequired: false, transformFunction: null }, columnGap: { classPropertyName: "columnGap", publicName: "columnGap", isSignal: true, isRequired: false, transformFunction: null }, overscanRows: { classPropertyName: "overscanRows", publicName: "overscanRows", isSignal: true, isRequired: false, transformFunction: null }, gridClass: { classPropertyName: "gridClass", publicName: "gridClass", isSignal: true, isRequired: false, transformFunction: null }, gridId: { classPropertyName: "gridId", publicName: "gridId", isSignal: true, isRequired: false, transformFunction: null }, rowHeightResolver: { classPropertyName: "rowHeightResolver", publicName: "rowHeightResolver", isSignal: true, isRequired: false, transformFunction: null }, trackBy: { classPropertyName: "trackBy", publicName: "trackBy", isSignal: true, isRequired: false, transformFunction: null }, itemTemplateInput: { classPropertyName: "itemTemplateInput", publicName: "itemTemplate", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { rangeChange: "rangeChange", scrollBottom: "scrollBottom" }, queries: [{ propertyName: "projectedTemplate", first: true, predicate: TemplateRef, descendants: true, isSignal: true }], viewQueries: [{ propertyName: "scrollHost", first: true, predicate: ["scrollHost"], descendants: true, isSignal: true }], ngImport: i0, template: `
195
217
  <ng-scroll
218
+ #scrollHost
196
219
  [hexpand]="true"
197
220
  [vexpand]="true"
198
221
  [min-height]="viewportHeight()"
@@ -243,7 +266,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImpor
243
266
  type: Component,
244
267
  args: [{
245
268
  selector: 'ng-virtual-grid',
246
- standalone: true,
247
269
  imports: [
248
270
  NgTemplateOutlet,
249
271
  NativeElementDirective,
@@ -252,6 +274,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImpor
252
274
  ],
253
275
  template: `
254
276
  <ng-scroll
277
+ #scrollHost
255
278
  [hexpand]="true"
256
279
  [vexpand]="true"
257
280
  [min-height]="viewportHeight()"
@@ -298,4 +321,4 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImpor
298
321
  </ng-scroll>
299
322
  `,
300
323
  }]
301
- }], ctorParameters: () => [], propDecorators: { items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: false }] }], rowHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "rowHeight", required: false }] }], minColumnWidth: [{ type: i0.Input, args: [{ isSignal: true, alias: "minColumnWidth", required: false }] }], columns: [{ type: i0.Input, args: [{ isSignal: true, alias: "columns", required: false }] }], viewportHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "viewportHeight", required: false }] }], viewportWidth: [{ type: i0.Input, args: [{ isSignal: true, alias: "viewportWidth", required: false }] }], rowGap: [{ type: i0.Input, args: [{ isSignal: true, alias: "rowGap", required: false }] }], columnGap: [{ type: i0.Input, args: [{ isSignal: true, alias: "columnGap", required: false }] }], overscanRows: [{ type: i0.Input, args: [{ isSignal: true, alias: "overscanRows", required: false }] }], gridClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "gridClass", required: false }] }], gridId: [{ type: i0.Input, args: [{ isSignal: true, alias: "gridId", required: false }] }], rowHeightResolver: [{ type: i0.Input, args: [{ isSignal: true, alias: "rowHeightResolver", required: false }] }], trackBy: [{ type: i0.Input, args: [{ isSignal: true, alias: "trackBy", required: false }] }], itemTemplateInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "itemTemplate", required: false }] }], projectedTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => TemplateRef), { isSignal: true }] }], rangeChange: [{ type: i0.Output, args: ["rangeChange"] }], scrollBottom: [{ type: i0.Output, args: ["scrollBottom"] }] } });
324
+ }], ctorParameters: () => [], propDecorators: { items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: false }] }], rowHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "rowHeight", required: false }] }], minColumnWidth: [{ type: i0.Input, args: [{ isSignal: true, alias: "minColumnWidth", required: false }] }], columns: [{ type: i0.Input, args: [{ isSignal: true, alias: "columns", required: false }] }], viewportHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "viewportHeight", required: false }] }], viewportWidth: [{ type: i0.Input, args: [{ isSignal: true, alias: "viewportWidth", required: false }] }], rowGap: [{ type: i0.Input, args: [{ isSignal: true, alias: "rowGap", required: false }] }], columnGap: [{ type: i0.Input, args: [{ isSignal: true, alias: "columnGap", required: false }] }], overscanRows: [{ type: i0.Input, args: [{ isSignal: true, alias: "overscanRows", required: false }] }], gridClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "gridClass", required: false }] }], gridId: [{ type: i0.Input, args: [{ isSignal: true, alias: "gridId", required: false }] }], rowHeightResolver: [{ type: i0.Input, args: [{ isSignal: true, alias: "rowHeightResolver", required: false }] }], trackBy: [{ type: i0.Input, args: [{ isSignal: true, alias: "trackBy", required: false }] }], itemTemplateInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "itemTemplate", required: false }] }], projectedTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => TemplateRef), { isSignal: true }] }], rangeChange: [{ type: i0.Output, args: ["rangeChange"] }], scrollBottom: [{ type: i0.Output, args: ["scrollBottom"] }], scrollHost: [{ type: i0.ViewChild, args: ['scrollHost', { isSignal: true }] }] } });
@@ -37,13 +37,19 @@ export declare class NativeVirtualListComponent<T = unknown> {
37
37
  readonly rangeChange: import("@angular/core").OutputEmitterRef<VirtualSliceRange>;
38
38
  readonly rowActivated: import("@angular/core").OutputEmitterRef<NativeVirtualRowActivatedEvent<T>>;
39
39
  readonly scrollBottom: import("@angular/core").OutputEmitterRef<void>;
40
+ private readonly renderer;
41
+ private readonly scrollHost;
40
42
  readonly scrollTop: import("@angular/core").WritableSignal<number>;
43
+ readonly measuredHeight: import("@angular/core").WritableSignal<number | null>;
41
44
  readonly scrollToAttr: import("@angular/core").WritableSignal<string | undefined>;
42
45
  private readonly heightTree;
43
46
  private readonly measuredOverrides;
44
47
  private readonly measureRevision;
45
48
  readonly resolvedTemplate: import("@angular/core").Signal<TemplateRef<NativeVirtualItemContext<T>> | null>;
49
+ readonly effectiveHeight: import("@angular/core").Signal<number>;
46
50
  readonly isVariableHeight: import("@angular/core").Signal<boolean>;
51
+ /** Builds/updates the Fenwick row-offset tree only when item heights or list contents change. */
52
+ private readonly heightTreeState;
47
53
  readonly range: import("@angular/core").Signal<VirtualSliceRange>;
48
54
  readonly visibleEntries: import("@angular/core").Signal<readonly NativeVirtualListEntry<T>[]>;
49
55
  private lastEmittedRangeKey;
@@ -59,5 +65,5 @@ export declare class NativeVirtualListComponent<T = unknown> {
59
65
  onNativeScroll(event: unknown): void;
60
66
  onRowActivated(event: unknown): void;
61
67
  static ɵfac: i0.ɵɵFactoryDeclaration<NativeVirtualListComponent<any>, never>;
62
- static ɵcmp: i0.ɵɵComponentDeclaration<NativeVirtualListComponent<any>, "ng-virtual-list", never, { "items": { "alias": "items"; "required": false; "isSignal": true; }; "itemHeight": { "alias": "itemHeight"; "required": false; "isSignal": true; }; "itemHeightResolver": { "alias": "itemHeightResolver"; "required": false; "isSignal": true; }; "viewportHeight": { "alias": "viewportHeight"; "required": false; "isSignal": true; }; "overscan": { "alias": "overscan"; "required": false; "isSignal": true; }; "selectionMode": { "alias": "selectionMode"; "required": false; "isSignal": true; }; "showSeparators": { "alias": "showSeparators"; "required": false; "isSignal": true; }; "trackBy": { "alias": "trackBy"; "required": false; "isSignal": true; }; "itemTemplateInput": { "alias": "itemTemplate"; "required": false; "isSignal": true; }; }, { "rangeChange": "rangeChange"; "rowActivated": "rowActivated"; "scrollBottom": "scrollBottom"; }, ["projectedTemplate"], never, true, never>;
68
+ static ɵcmp: i0.ɵɵComponentDeclaration<NativeVirtualListComponent<any>, "ng-virtual-list", never, { "items": { "alias": "items"; "required": false; "isSignal": true; }; "itemHeight": { "alias": "itemHeight"; "required": false; "isSignal": true; }; "itemHeightResolver": { "alias": "itemHeightResolver"; "required": false; "isSignal": true; }; "viewportHeight": { "alias": "viewportHeight"; "required": false; "isSignal": true; }; "overscan": { "alias": "overscan"; "required": false; "isSignal": true; }; "selectionMode": { "alias": "selectionMode"; "required": false; "isSignal": true; }; "showSeparators": { "alias": "showSeparators"; "required": false; "isSignal": true; }; "trackBy": { "alias": "trackBy"; "required": false; "isSignal": true; }; "itemTemplateInput": { "alias": "itemTemplate"; "required": false; "isSignal": true; }; }, { "rangeChange": "rangeChange"; "rowActivated": "rowActivated"; "scrollBottom": "scrollBottom"; }, ["projectedTemplate"], ["[ngVirtualEmpty]"], true, never>;
63
69
  }
@@ -1,5 +1,5 @@
1
1
  import { NgTemplateOutlet } from '@angular/common';
2
- import { Component, computed, contentChild, effect, input, output, signal, TemplateRef, } from '@angular/core';
2
+ import { Component, computed, contentChild, effect, inject, input, output, Renderer2, signal, TemplateRef, viewChild, } from '@angular/core';
3
3
  import { NativeContainerDirective, NativeElementDirective, NativeListDirective, NativeTextWidgetDirective, } from './native-directives.js';
4
4
  import { computeVariableVirtualSliceRange, computeVirtualSliceRange, FenwickOffsetTree, } from './virtual-layout.js';
5
5
  import * as i0 from "@angular/core";
@@ -32,8 +32,13 @@ export class NativeVirtualListComponent {
32
32
  rangeChange = output();
33
33
  rowActivated = output();
34
34
  scrollBottom = output();
35
+ renderer = inject(Renderer2);
36
+ scrollHost = viewChild('scrollHost', /* @ts-ignore */
37
+ ...(ngDevMode ? [{ debugName: "scrollHost" }] : /* istanbul ignore next */ []));
35
38
  scrollTop = signal(0, /* @ts-ignore */
36
39
  ...(ngDevMode ? [{ debugName: "scrollTop" }] : /* istanbul ignore next */ []));
40
+ measuredHeight = signal(null, /* @ts-ignore */
41
+ ...(ngDevMode ? [{ debugName: "measuredHeight" }] : /* istanbul ignore next */ []));
37
42
  scrollToAttr = signal(undefined, /* @ts-ignore */
38
43
  ...(ngDevMode ? [{ debugName: "scrollToAttr" }] : /* istanbul ignore next */ []));
39
44
  heightTree = new FenwickOffsetTree(0, 48);
@@ -42,16 +47,19 @@ export class NativeVirtualListComponent {
42
47
  ...(ngDevMode ? [{ debugName: "measureRevision" }] : /* istanbul ignore next */ []));
43
48
  resolvedTemplate = computed(() => this.itemTemplateInput() ?? this.projectedTemplate() ?? null, /* @ts-ignore */
44
49
  ...(ngDevMode ? [{ debugName: "resolvedTemplate" }] : /* istanbul ignore next */ []));
50
+ effectiveHeight = computed(() => this.measuredHeight() ?? this.viewportHeight(), /* @ts-ignore */
51
+ ...(ngDevMode ? [{ debugName: "effectiveHeight" }] : /* istanbul ignore next */ []));
45
52
  isVariableHeight = computed(() => this.itemHeightResolver() !== null ||
46
53
  (this.measureRevision() >= 0 && this.measuredOverrides.size > 0), /* @ts-ignore */
47
54
  ...(ngDevMode ? [{ debugName: "isVariableHeight" }] : /* istanbul ignore next */ []));
48
- range = computed(() => {
55
+ /** Builds/updates the Fenwick row-offset tree only when item heights or list contents change. */
56
+ heightTreeState = computed(() => {
49
57
  const source = this.items();
50
58
  const resolver = this.itemHeightResolver();
51
59
  this.measureRevision();
52
60
  const defaultHeight = Math.max(1, this.itemHeight());
53
61
  if (resolver === null && this.measuredOverrides.size === 0) {
54
- return computeVirtualSliceRange(source.length, this.scrollTop(), this.viewportHeight(), defaultHeight, this.overscan());
62
+ return { tree: null, defaultHeight };
55
63
  }
56
64
  const overrides = new Map();
57
65
  if (resolver !== null) {
@@ -65,7 +73,17 @@ export class NativeVirtualListComponent {
65
73
  }
66
74
  }
67
75
  this.heightTree.reset(source.length, defaultHeight, overrides);
68
- return computeVariableVirtualSliceRange(this.heightTree, this.scrollTop(), this.viewportHeight(), this.overscan());
76
+ return { tree: this.heightTree, defaultHeight };
77
+ }, /* @ts-ignore */
78
+ ...(ngDevMode ? [{ debugName: "heightTreeState" }] : /* istanbul ignore next */ []));
79
+ range = computed(() => {
80
+ const source = this.items();
81
+ const { tree, defaultHeight } = this.heightTreeState();
82
+ const effHeight = this.effectiveHeight();
83
+ if (tree === null) {
84
+ return computeVirtualSliceRange(source.length, this.scrollTop(), effHeight, defaultHeight, this.overscan());
85
+ }
86
+ return computeVariableVirtualSliceRange(tree, this.scrollTop(), effHeight, this.overscan());
69
87
  }, /* @ts-ignore */
70
88
  ...(ngDevMode ? [{ debugName: "range" }] : /* istanbul ignore next */ []));
71
89
  visibleEntries = computed(() => {
@@ -124,21 +142,33 @@ export class NativeVirtualListComponent {
124
142
  /** Scrolls the native viewport to bring row `index` into view. */
125
143
  scrollToIndex(index) {
126
144
  const y = this.offsetForIndex(index);
145
+ const coords = `0,${y}`;
146
+ const sameCoords = this.scrollToAttr() === coords;
127
147
  this.scrollTop.set(y);
128
- this.scrollToAttr.set(`0,${y}`);
148
+ this.scrollToAttr.set(coords);
149
+ if (sameCoords) {
150
+ const hostEl = this.scrollHost()?.nativeElement;
151
+ if (hostEl) {
152
+ this.renderer.setAttribute(hostEl, 'scroll-to', coords);
153
+ }
154
+ }
129
155
  }
130
156
  onNativeScroll(event) {
131
157
  if (!event || typeof event !== 'object') {
132
158
  return;
133
159
  }
134
160
  const obj = event;
135
- let top = obj['scrollTop'];
136
- if (typeof top !== 'number' && obj['target'] && typeof obj['target'] === 'object') {
137
- top = obj['target']['scrollTop'];
138
- }
161
+ const target = obj['target'] && typeof obj['target'] === 'object'
162
+ ? obj['target']
163
+ : undefined;
164
+ const top = typeof obj['scrollTop'] === 'number' ? obj['scrollTop'] : target?.['scrollTop'];
139
165
  if (typeof top === 'number' && Number.isFinite(top)) {
140
166
  this.scrollTop.set(Math.max(0, top));
141
167
  }
168
+ const height = typeof obj['clientHeight'] === 'number' ? obj['clientHeight'] : target?.['clientHeight'];
169
+ if (typeof height === 'number' && Number.isFinite(height) && height > 0) {
170
+ this.measuredHeight.set(height);
171
+ }
142
172
  }
143
173
  onRowActivated(event) {
144
174
  if (!event || typeof event !== 'object') {
@@ -157,8 +187,9 @@ export class NativeVirtualListComponent {
157
187
  }
158
188
  }
159
189
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeVirtualListComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
160
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.3.0", type: NativeVirtualListComponent, isStandalone: true, selector: "ng-virtual-list", inputs: { items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: false, transformFunction: null }, itemHeight: { classPropertyName: "itemHeight", publicName: "itemHeight", isSignal: true, isRequired: false, transformFunction: null }, itemHeightResolver: { classPropertyName: "itemHeightResolver", publicName: "itemHeightResolver", isSignal: true, isRequired: false, transformFunction: null }, viewportHeight: { classPropertyName: "viewportHeight", publicName: "viewportHeight", isSignal: true, isRequired: false, transformFunction: null }, overscan: { classPropertyName: "overscan", publicName: "overscan", isSignal: true, isRequired: false, transformFunction: null }, selectionMode: { classPropertyName: "selectionMode", publicName: "selectionMode", isSignal: true, isRequired: false, transformFunction: null }, showSeparators: { classPropertyName: "showSeparators", publicName: "showSeparators", isSignal: true, isRequired: false, transformFunction: null }, trackBy: { classPropertyName: "trackBy", publicName: "trackBy", isSignal: true, isRequired: false, transformFunction: null }, itemTemplateInput: { classPropertyName: "itemTemplateInput", publicName: "itemTemplate", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { rangeChange: "rangeChange", rowActivated: "rowActivated", scrollBottom: "scrollBottom" }, queries: [{ propertyName: "projectedTemplate", first: true, predicate: TemplateRef, descendants: true, isSignal: true }], ngImport: i0, template: `
190
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.3.0", type: NativeVirtualListComponent, isStandalone: true, selector: "ng-virtual-list", inputs: { items: { classPropertyName: "items", publicName: "items", isSignal: true, isRequired: false, transformFunction: null }, itemHeight: { classPropertyName: "itemHeight", publicName: "itemHeight", isSignal: true, isRequired: false, transformFunction: null }, itemHeightResolver: { classPropertyName: "itemHeightResolver", publicName: "itemHeightResolver", isSignal: true, isRequired: false, transformFunction: null }, viewportHeight: { classPropertyName: "viewportHeight", publicName: "viewportHeight", isSignal: true, isRequired: false, transformFunction: null }, overscan: { classPropertyName: "overscan", publicName: "overscan", isSignal: true, isRequired: false, transformFunction: null }, selectionMode: { classPropertyName: "selectionMode", publicName: "selectionMode", isSignal: true, isRequired: false, transformFunction: null }, showSeparators: { classPropertyName: "showSeparators", publicName: "showSeparators", isSignal: true, isRequired: false, transformFunction: null }, trackBy: { classPropertyName: "trackBy", publicName: "trackBy", isSignal: true, isRequired: false, transformFunction: null }, itemTemplateInput: { classPropertyName: "itemTemplateInput", publicName: "itemTemplate", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { rangeChange: "rangeChange", rowActivated: "rowActivated", scrollBottom: "scrollBottom" }, queries: [{ propertyName: "projectedTemplate", first: true, predicate: TemplateRef, descendants: true, isSignal: true }], viewQueries: [{ propertyName: "scrollHost", first: true, predicate: ["scrollHost"], descendants: true, isSignal: true }], ngImport: i0, template: `
161
191
  <ng-scroll
192
+ #scrollHost
162
193
  [hexpand]="true"
163
194
  [vexpand]="true"
164
195
  [min-height]="viewportHeight()"
@@ -170,22 +201,26 @@ export class NativeVirtualListComponent {
170
201
  @if (range().topSpacerHeight > 0) {
171
202
  <ng-box [height]="range().topSpacerHeight"></ng-box>
172
203
  }
173
- <ng-list
174
- [selection-mode]="selectionMode()"
175
- [show-separators]="showSeparators()"
176
- (rowActivated)="onRowActivated($event)"
177
- >
178
- @for (entry of visibleEntries(); track entry.key) {
179
- @if (resolvedTemplate(); as tpl) {
180
- <ng-container
181
- [ngTemplateOutlet]="tpl"
182
- [ngTemplateOutletContext]="{ $implicit: entry.item, index: entry.index }"
183
- ></ng-container>
184
- } @else {
185
- <ng-label [text]="'' + entry.item"></ng-label>
204
+ @if (items().length === 0) {
205
+ <ng-content select="[ngVirtualEmpty]"></ng-content>
206
+ } @else {
207
+ <ng-list
208
+ [selection-mode]="selectionMode()"
209
+ [show-separators]="showSeparators()"
210
+ (rowActivated)="onRowActivated($event)"
211
+ >
212
+ @for (entry of visibleEntries(); track entry.key) {
213
+ @if (resolvedTemplate(); as tpl) {
214
+ <ng-container
215
+ [ngTemplateOutlet]="tpl"
216
+ [ngTemplateOutletContext]="{ $implicit: entry.item, index: entry.index }"
217
+ ></ng-container>
218
+ } @else {
219
+ <ng-label [text]="'' + entry.item"></ng-label>
220
+ }
186
221
  }
187
- }
188
- </ng-list>
222
+ </ng-list>
223
+ }
189
224
  @if (range().bottomSpacerHeight > 0) {
190
225
  <ng-box [height]="range().bottomSpacerHeight"></ng-box>
191
226
  }
@@ -197,7 +232,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImpor
197
232
  type: Component,
198
233
  args: [{
199
234
  selector: 'ng-virtual-list',
200
- standalone: true,
201
235
  imports: [
202
236
  NgTemplateOutlet,
203
237
  NativeElementDirective,
@@ -207,6 +241,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImpor
207
241
  ],
208
242
  template: `
209
243
  <ng-scroll
244
+ #scrollHost
210
245
  [hexpand]="true"
211
246
  [vexpand]="true"
212
247
  [min-height]="viewportHeight()"
@@ -218,22 +253,26 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImpor
218
253
  @if (range().topSpacerHeight > 0) {
219
254
  <ng-box [height]="range().topSpacerHeight"></ng-box>
220
255
  }
221
- <ng-list
222
- [selection-mode]="selectionMode()"
223
- [show-separators]="showSeparators()"
224
- (rowActivated)="onRowActivated($event)"
225
- >
226
- @for (entry of visibleEntries(); track entry.key) {
227
- @if (resolvedTemplate(); as tpl) {
228
- <ng-container
229
- [ngTemplateOutlet]="tpl"
230
- [ngTemplateOutletContext]="{ $implicit: entry.item, index: entry.index }"
231
- ></ng-container>
232
- } @else {
233
- <ng-label [text]="'' + entry.item"></ng-label>
256
+ @if (items().length === 0) {
257
+ <ng-content select="[ngVirtualEmpty]"></ng-content>
258
+ } @else {
259
+ <ng-list
260
+ [selection-mode]="selectionMode()"
261
+ [show-separators]="showSeparators()"
262
+ (rowActivated)="onRowActivated($event)"
263
+ >
264
+ @for (entry of visibleEntries(); track entry.key) {
265
+ @if (resolvedTemplate(); as tpl) {
266
+ <ng-container
267
+ [ngTemplateOutlet]="tpl"
268
+ [ngTemplateOutletContext]="{ $implicit: entry.item, index: entry.index }"
269
+ ></ng-container>
270
+ } @else {
271
+ <ng-label [text]="'' + entry.item"></ng-label>
272
+ }
234
273
  }
235
- }
236
- </ng-list>
274
+ </ng-list>
275
+ }
237
276
  @if (range().bottomSpacerHeight > 0) {
238
277
  <ng-box [height]="range().bottomSpacerHeight"></ng-box>
239
278
  }
@@ -241,4 +280,4 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImpor
241
280
  </ng-scroll>
242
281
  `,
243
282
  }]
244
- }], ctorParameters: () => [], propDecorators: { items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: false }] }], itemHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "itemHeight", required: false }] }], itemHeightResolver: [{ type: i0.Input, args: [{ isSignal: true, alias: "itemHeightResolver", required: false }] }], viewportHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "viewportHeight", required: false }] }], overscan: [{ type: i0.Input, args: [{ isSignal: true, alias: "overscan", required: false }] }], selectionMode: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectionMode", required: false }] }], showSeparators: [{ type: i0.Input, args: [{ isSignal: true, alias: "showSeparators", required: false }] }], trackBy: [{ type: i0.Input, args: [{ isSignal: true, alias: "trackBy", required: false }] }], itemTemplateInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "itemTemplate", required: false }] }], projectedTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => TemplateRef), { isSignal: true }] }], rangeChange: [{ type: i0.Output, args: ["rangeChange"] }], rowActivated: [{ type: i0.Output, args: ["rowActivated"] }], scrollBottom: [{ type: i0.Output, args: ["scrollBottom"] }] } });
283
+ }], ctorParameters: () => [], propDecorators: { items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: false }] }], itemHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "itemHeight", required: false }] }], itemHeightResolver: [{ type: i0.Input, args: [{ isSignal: true, alias: "itemHeightResolver", required: false }] }], viewportHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "viewportHeight", required: false }] }], overscan: [{ type: i0.Input, args: [{ isSignal: true, alias: "overscan", required: false }] }], selectionMode: [{ type: i0.Input, args: [{ isSignal: true, alias: "selectionMode", required: false }] }], showSeparators: [{ type: i0.Input, args: [{ isSignal: true, alias: "showSeparators", required: false }] }], trackBy: [{ type: i0.Input, args: [{ isSignal: true, alias: "trackBy", required: false }] }], itemTemplateInput: [{ type: i0.Input, args: [{ isSignal: true, alias: "itemTemplate", required: false }] }], projectedTemplate: [{ type: i0.ContentChild, args: [i0.forwardRef(() => TemplateRef), { isSignal: true }] }], rangeChange: [{ type: i0.Output, args: ["rangeChange"] }], rowActivated: [{ type: i0.Output, args: ["rowActivated"] }], scrollBottom: [{ type: i0.Output, args: ["scrollBottom"] }], scrollHost: [{ type: i0.ViewChild, args: ['scrollHost', { isSignal: true }] }] } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-desktop/platform",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "@ng-desktop/platform for Angular Desktop Engine",
5
5
  "license": "MIT",
6
6
  "keywords": [