@ng-desktop/platform 0.0.0-stage → 0.4.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.
@@ -0,0 +1,200 @@
1
+ import { NgTemplateOutlet } from '@angular/common';
2
+ import { ChangeDetectionStrategy, Component, computed, contentChild, effect, input, output, signal, TemplateRef, } from '@angular/core';
3
+ import { NativeContainerDirective, NativeElementDirective, NativeListDirective, NativeTextWidgetDirective, } from './native-directives.js';
4
+ import * as i0 from "@angular/core";
5
+ /**
6
+ * Computes the visible item slice and spacer heights for a fixed-row-height viewport.
7
+ */
8
+ export function computeVirtualSliceRange(totalItems, scrollTop, viewportHeight, itemHeight, overscan = 4) {
9
+ const safeTotal = Math.max(0, Math.floor(totalItems));
10
+ if (safeTotal === 0) {
11
+ return {
12
+ startIndex: 0,
13
+ endIndex: 0,
14
+ totalItems: 0,
15
+ topSpacerHeight: 0,
16
+ bottomSpacerHeight: 0,
17
+ };
18
+ }
19
+ const safeItemHeight = Math.max(1, itemHeight);
20
+ const safeViewport = Math.max(safeItemHeight, viewportHeight);
21
+ const safeOverscan = Math.max(0, Math.floor(overscan));
22
+ const maxScrollTop = Math.max(0, safeTotal * safeItemHeight - safeViewport);
23
+ const clampedScrollTop = Math.min(Math.max(0, scrollTop), maxScrollTop);
24
+ const firstVisible = Math.floor(clampedScrollTop / safeItemHeight);
25
+ const visibleCount = Math.ceil(safeViewport / safeItemHeight);
26
+ const startIndex = Math.max(0, firstVisible - safeOverscan);
27
+ const endIndex = Math.min(safeTotal, firstVisible + visibleCount + safeOverscan);
28
+ return {
29
+ startIndex,
30
+ endIndex,
31
+ totalItems: safeTotal,
32
+ topSpacerHeight: startIndex * safeItemHeight,
33
+ bottomSpacerHeight: (safeTotal - endIndex) * safeItemHeight,
34
+ };
35
+ }
36
+ /**
37
+ * Virtualized native desktop list component rendering only the visible viewport slice + overscan
38
+ * inside an `<ng-scroll>` + `<ng-list>` hierarchy to keep native widget counts bounded at scale.
39
+ */
40
+ export class NativeVirtualListComponent {
41
+ items = input([], /* @ts-ignore */
42
+ ...(ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []));
43
+ itemHeight = input(48, /* @ts-ignore */
44
+ ...(ngDevMode ? [{ debugName: "itemHeight" }] : /* istanbul ignore next */ []));
45
+ viewportHeight = input(480, /* @ts-ignore */
46
+ ...(ngDevMode ? [{ debugName: "viewportHeight" }] : /* istanbul ignore next */ []));
47
+ overscan = input(4, /* @ts-ignore */
48
+ ...(ngDevMode ? [{ debugName: "overscan" }] : /* istanbul ignore next */ []));
49
+ selectionMode = input('single', /* @ts-ignore */
50
+ ...(ngDevMode ? [{ debugName: "selectionMode" }] : /* istanbul ignore next */ []));
51
+ showSeparators = input(false, /* @ts-ignore */
52
+ ...(ngDevMode ? [{ debugName: "showSeparators" }] : /* istanbul ignore next */ []));
53
+ trackBy = input((index, _item) => index, /* @ts-ignore */
54
+ ...(ngDevMode ? [{ debugName: "trackBy" }] : /* istanbul ignore next */ []));
55
+ itemTemplateInput = input(null, { ...(ngDevMode ? { debugName: "itemTemplateInput" } : /* istanbul ignore next */ {}), alias: 'itemTemplate' });
56
+ projectedTemplate = contentChild(TemplateRef, /* @ts-ignore */
57
+ ...(ngDevMode ? [{ debugName: "projectedTemplate" }] : /* istanbul ignore next */ []));
58
+ rangeChange = output();
59
+ rowActivated = output();
60
+ scrollTop = signal(0, /* @ts-ignore */
61
+ ...(ngDevMode ? [{ debugName: "scrollTop" }] : /* istanbul ignore next */ []));
62
+ resolvedTemplate = computed(() => this.itemTemplateInput() ?? this.projectedTemplate() ?? null, /* @ts-ignore */
63
+ ...(ngDevMode ? [{ debugName: "resolvedTemplate" }] : /* istanbul ignore next */ []));
64
+ range = computed(() => computeVirtualSliceRange(this.items().length, this.scrollTop(), this.viewportHeight(), this.itemHeight(), this.overscan()), /* @ts-ignore */
65
+ ...(ngDevMode ? [{ debugName: "range" }] : /* istanbul ignore next */ []));
66
+ visibleEntries = computed(() => {
67
+ const source = this.items();
68
+ const { startIndex, endIndex } = this.range();
69
+ const trackFn = this.trackBy();
70
+ const entries = [];
71
+ for (let idx = startIndex; idx < endIndex; idx += 1) {
72
+ const item = source[idx];
73
+ entries.push({ item, index: idx, key: trackFn(idx, item) });
74
+ }
75
+ return entries;
76
+ }, /* @ts-ignore */
77
+ ...(ngDevMode ? [{ debugName: "visibleEntries" }] : /* istanbul ignore next */ []));
78
+ lastEmittedRangeKey = '';
79
+ constructor() {
80
+ effect(() => {
81
+ const next = this.range();
82
+ const key = `${next.startIndex}:${next.endIndex}:${next.totalItems}`;
83
+ if (key !== this.lastEmittedRangeKey) {
84
+ this.lastEmittedRangeKey = key;
85
+ this.rangeChange.emit(next);
86
+ }
87
+ });
88
+ }
89
+ onNativeScroll(event) {
90
+ if (!event || typeof event !== 'object') {
91
+ return;
92
+ }
93
+ const obj = event;
94
+ let top = obj['scrollTop'];
95
+ if (typeof top !== 'number' && obj['target'] && typeof obj['target'] === 'object') {
96
+ top = obj['target']['scrollTop'];
97
+ }
98
+ if (typeof top === 'number' && Number.isFinite(top)) {
99
+ this.scrollTop.set(Math.max(0, top));
100
+ }
101
+ }
102
+ onRowActivated(event) {
103
+ if (!event || typeof event !== 'object') {
104
+ return;
105
+ }
106
+ const obj = event;
107
+ const rawIdx = typeof obj['value'] === 'number'
108
+ ? obj['value']
109
+ : typeof obj['index'] === 'number'
110
+ ? obj['index']
111
+ : -1;
112
+ const localIdx = Math.floor(rawIdx);
113
+ const entry = this.visibleEntries()[localIdx];
114
+ if (entry) {
115
+ this.rowActivated.emit({ index: entry.index, item: entry.item });
116
+ }
117
+ }
118
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeVirtualListComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
119
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.2.6", 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 }, 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" }, queries: [{ propertyName: "projectedTemplate", first: true, predicate: TemplateRef, descendants: true, isSignal: true }], ngImport: i0, template: `
120
+ <ng-scroll
121
+ [hexpand]="true"
122
+ [vexpand]="true"
123
+ [min-height]="viewportHeight()"
124
+ (scroll)="onNativeScroll($event)"
125
+ >
126
+ <ng-box orientation="vertical" [spacing]="0" [hexpand]="true">
127
+ @if (range().topSpacerHeight > 0) {
128
+ <ng-box [height]="range().topSpacerHeight"></ng-box>
129
+ }
130
+ <ng-list
131
+ [selection-mode]="selectionMode()"
132
+ [show-separators]="showSeparators()"
133
+ (rowActivated)="onRowActivated($event)"
134
+ >
135
+ @for (entry of visibleEntries(); track entry.key) {
136
+ @if (resolvedTemplate(); as tpl) {
137
+ <ng-container
138
+ [ngTemplateOutlet]="tpl"
139
+ [ngTemplateOutletContext]="{ $implicit: entry.item, index: entry.index }"
140
+ ></ng-container>
141
+ } @else {
142
+ <ng-label [text]="'' + entry.item"></ng-label>
143
+ }
144
+ }
145
+ </ng-list>
146
+ @if (range().bottomSpacerHeight > 0) {
147
+ <ng-box [height]="range().bottomSpacerHeight"></ng-box>
148
+ }
149
+ </ng-box>
150
+ </ng-scroll>
151
+ `, isInline: true, dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: NativeElementDirective, 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", inputs: ["hexpand", "vexpand", "halign", "valign", "width", "height", "min-width", "min-height", "margin", "margin-top", "margin-bottom", "margin-start", "margin-end", "visible", "sensitive", "disabled", "tooltip", "event-mask", "drop-target"] }, { kind: "directive", type: NativeContainerDirective, 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", inputs: ["orientation", "spacing", "gap", "row-spacing", "column-spacing", "min-children", "max-children", "min-per-row", "max-per-row", "homogeneous", "position", "visible-child", "active-page", "transition", "transition-type", "label", "title", "expanded", "open", "max-size", "maximum-size", "scroll-to", "scroll-anchor"] }, { kind: "directive", type: NativeListDirective, selector: "ng-list,ng-table,gtk-list-box,gtk-list-view", inputs: ["selection-mode", "selectionMode", "show-separators", "showSeparators", "separators"] }, { kind: "directive", type: NativeTextWidgetDirective, selector: "ng-button,gtk-button,ng-label,gtk-label", inputs: ["label", "text", "wrap", "selectable", "ellipsize"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
152
+ }
153
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.6", ngImport: i0, type: NativeVirtualListComponent, decorators: [{
154
+ type: Component,
155
+ args: [{
156
+ selector: 'ng-virtual-list',
157
+ standalone: true,
158
+ changeDetection: ChangeDetectionStrategy.OnPush,
159
+ imports: [
160
+ NgTemplateOutlet,
161
+ NativeElementDirective,
162
+ NativeContainerDirective,
163
+ NativeListDirective,
164
+ NativeTextWidgetDirective,
165
+ ],
166
+ template: `
167
+ <ng-scroll
168
+ [hexpand]="true"
169
+ [vexpand]="true"
170
+ [min-height]="viewportHeight()"
171
+ (scroll)="onNativeScroll($event)"
172
+ >
173
+ <ng-box orientation="vertical" [spacing]="0" [hexpand]="true">
174
+ @if (range().topSpacerHeight > 0) {
175
+ <ng-box [height]="range().topSpacerHeight"></ng-box>
176
+ }
177
+ <ng-list
178
+ [selection-mode]="selectionMode()"
179
+ [show-separators]="showSeparators()"
180
+ (rowActivated)="onRowActivated($event)"
181
+ >
182
+ @for (entry of visibleEntries(); track entry.key) {
183
+ @if (resolvedTemplate(); as tpl) {
184
+ <ng-container
185
+ [ngTemplateOutlet]="tpl"
186
+ [ngTemplateOutletContext]="{ $implicit: entry.item, index: entry.index }"
187
+ ></ng-container>
188
+ } @else {
189
+ <ng-label [text]="'' + entry.item"></ng-label>
190
+ }
191
+ }
192
+ </ng-list>
193
+ @if (range().bottomSpacerHeight > 0) {
194
+ <ng-box [height]="range().bottomSpacerHeight"></ng-box>
195
+ }
196
+ </ng-box>
197
+ </ng-scroll>
198
+ `,
199
+ }]
200
+ }], ctorParameters: () => [], propDecorators: { items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: false }] }], itemHeight: [{ type: i0.Input, args: [{ isSignal: true, alias: "itemHeight", 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"] }] } });
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "@ng-desktop/platform",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.4.0",
4
+ "description": "@ng-desktop/platform for Angular Desktop Engine",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "angular",
8
+ "angular22",
9
+ "desktop",
10
+ "native",
11
+ "gtk4",
12
+ "winui3",
13
+ "appkit",
14
+ "rust"
15
+ ],
16
+ "homepage": "https://github.com/Gaspar1992/ng-desktop-engine",
17
+ "bugs": {
18
+ "url": "https://github.com/Gaspar1992/ng-desktop-engine/issues"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/Gaspar1992/ng-desktop-engine.git",
23
+ "directory": "packages/platform-native"
24
+ },
25
+ "publishConfig": {
26
+ "access": "public"
27
+ },
28
+ "type": "module",
29
+ "sideEffects": false,
30
+ "files": [
31
+ "fesm2022",
32
+ "README.md",
33
+ "LICENSE",
34
+ "!**/*.map"
35
+ ],
36
+ "main": "./fesm2022/index.js",
37
+ "module": "./fesm2022/index.js",
38
+ "types": "./fesm2022/index.d.ts",
39
+ "exports": {
40
+ ".": {
41
+ "types": "./fesm2022/index.d.ts",
42
+ "default": "./fesm2022/index.js"
43
+ },
44
+ "./package.json": {
45
+ "default": "./package.json"
46
+ }
47
+ },
48
+ "peerDependencies": {
49
+ "@angular/common": ">=22.0.0",
50
+ "@angular/core": ">=22.0.0"
51
+ }
52
+ }