slint-ui 1.9.0-nightly.2024092723 → 1.9.0-nightly.2024100103
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/Cargo.toml +5 -4
- package/{index.d.ts → dist/index.d.ts} +147 -309
- package/{index.js → dist/index.js} +167 -384
- package/dist/models.d.ts +169 -0
- package/dist/models.js +235 -0
- package/package.json +10 -10
- package/tsconfig.json +2 -1
- package/{index.ts → typescript/index.ts} +166 -431
- package/typescript/models.ts +278 -0
- /package/{src → rust}/interpreter/component_compiler.rs +0 -0
- /package/{src → rust}/interpreter/component_definition.rs +0 -0
- /package/{src → rust}/interpreter/component_instance.rs +0 -0
- /package/{src → rust}/interpreter/diagnostic.rs +0 -0
- /package/{src → rust}/interpreter/value.rs +0 -0
- /package/{src → rust}/interpreter/window.rs +0 -0
- /package/{src → rust}/interpreter.rs +0 -0
- /package/{src → rust}/lib.rs +0 -0
- /package/{src → rust}/types/brush.rs +0 -0
- /package/{src → rust}/types/image_data.rs +0 -0
- /package/{src → rust}/types/model.rs +0 -0
- /package/{src → rust}/types/point.rs +0 -0
- /package/{src → rust}/types/size.rs +0 -0
- /package/{src → rust}/types.rs +0 -0
|
@@ -2,390 +2,17 @@
|
|
|
2
2
|
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
|
3
3
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.quitEventLoop = exports.runEventLoop = exports.loadSource = exports.loadFile = exports.CompileError = exports.
|
|
6
|
-
const napi = require("
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const row = this.row;
|
|
17
|
-
this.row++;
|
|
18
|
-
return {
|
|
19
|
-
done: false,
|
|
20
|
-
value: this.model.rowData(row),
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
return {
|
|
24
|
-
done: true,
|
|
25
|
-
value: undefined,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Model<T> is the interface for feeding dynamic data into
|
|
31
|
-
* `.slint` views.
|
|
32
|
-
*
|
|
33
|
-
* A model is organized like a table with rows of data. The
|
|
34
|
-
* fields of the data type T behave like columns.
|
|
35
|
-
*
|
|
36
|
-
* @template T the type of the model's items.
|
|
37
|
-
*
|
|
38
|
-
* ### Example
|
|
39
|
-
* As an example let's see the implementation of {@link ArrayModel}
|
|
40
|
-
*
|
|
41
|
-
* ```js
|
|
42
|
-
* export class ArrayModel<T> extends Model<T> {
|
|
43
|
-
* private a: Array<T>
|
|
44
|
-
*
|
|
45
|
-
* constructor(arr: Array<T>) {
|
|
46
|
-
* super();
|
|
47
|
-
* this.a = arr;
|
|
48
|
-
* }
|
|
49
|
-
*
|
|
50
|
-
* rowCount() {
|
|
51
|
-
* return this.a.length;
|
|
52
|
-
* }
|
|
53
|
-
*
|
|
54
|
-
* rowData(row: number) {
|
|
55
|
-
* return this.a[row];
|
|
56
|
-
* }
|
|
57
|
-
*
|
|
58
|
-
* setRowData(row: number, data: T) {
|
|
59
|
-
* this.a[row] = data;
|
|
60
|
-
* this.notifyRowDataChanged(row);
|
|
61
|
-
* }
|
|
62
|
-
*
|
|
63
|
-
* push(...values: T[]) {
|
|
64
|
-
* let size = this.a.length;
|
|
65
|
-
* Array.prototype.push.apply(this.a, values);
|
|
66
|
-
* this.notifyRowAdded(size, arguments.length);
|
|
67
|
-
* }
|
|
68
|
-
*
|
|
69
|
-
* remove(index: number, size: number) {
|
|
70
|
-
* let r = this.a.splice(index, size);
|
|
71
|
-
* this.notifyRowRemoved(index, size);
|
|
72
|
-
* }
|
|
73
|
-
*
|
|
74
|
-
* get length(): number {
|
|
75
|
-
* return this.a.length;
|
|
76
|
-
* }
|
|
77
|
-
*
|
|
78
|
-
* values(): IterableIterator<T> {
|
|
79
|
-
* return this.a.values();
|
|
80
|
-
* }
|
|
81
|
-
*
|
|
82
|
-
* entries(): IterableIterator<[number, T]> {
|
|
83
|
-
* return this.a.entries()
|
|
84
|
-
* }
|
|
85
|
-
*}
|
|
86
|
-
* ```
|
|
87
|
-
*/
|
|
88
|
-
class Model {
|
|
89
|
-
/**
|
|
90
|
-
* @hidden
|
|
91
|
-
*/
|
|
92
|
-
modelNotify;
|
|
93
|
-
constructor() {
|
|
94
|
-
this.modelNotify = napi.jsModelNotifyNew(this);
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Implementations of this function must store the provided data parameter
|
|
98
|
-
* in the model at the specified row.
|
|
99
|
-
* @param _row index in range 0..(rowCount() - 1).
|
|
100
|
-
* @param _data new data item to store on the given row index
|
|
101
|
-
*/
|
|
102
|
-
setRowData(_row, _data) {
|
|
103
|
-
console.log("setRowData called on a model which does not re-implement this method. This happens when trying to modify a read-only model");
|
|
104
|
-
}
|
|
105
|
-
[Symbol.iterator]() {
|
|
106
|
-
return new ModelIterator(this);
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Notifies the view that the data of the current row is changed.
|
|
110
|
-
* @param row index of the changed row.
|
|
111
|
-
*/
|
|
112
|
-
notifyRowDataChanged(row) {
|
|
113
|
-
napi.jsModelNotifyRowDataChanged(this.modelNotify, row);
|
|
114
|
-
}
|
|
115
|
-
/**
|
|
116
|
-
* Notifies the view that multiple rows are added to the model.
|
|
117
|
-
* @param row index of the first added row.
|
|
118
|
-
* @param count the number of added items.
|
|
119
|
-
*/
|
|
120
|
-
notifyRowAdded(row, count) {
|
|
121
|
-
napi.jsModelNotifyRowAdded(this.modelNotify, row, count);
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Notifies the view that multiple rows are removed to the model.
|
|
125
|
-
* @param row index of the first removed row.
|
|
126
|
-
* @param count the number of removed items.
|
|
127
|
-
*/
|
|
128
|
-
notifyRowRemoved(row, count) {
|
|
129
|
-
napi.jsModelNotifyRowRemoved(this.modelNotify, row, count);
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Notifies the view that the complete data must be reload.
|
|
133
|
-
*/
|
|
134
|
-
notifyReset() {
|
|
135
|
-
napi.jsModelNotifyReset(this.modelNotify);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
exports.Model = Model;
|
|
139
|
-
/**
|
|
140
|
-
* ArrayModel wraps a JavaScript array for use in `.slint` views. The underlying
|
|
141
|
-
* array can be modified with the [[ArrayModel.push]] and [[ArrayModel.remove]] methods.
|
|
142
|
-
*/
|
|
143
|
-
class ArrayModel extends Model {
|
|
144
|
-
/**
|
|
145
|
-
* @hidden
|
|
146
|
-
*/
|
|
147
|
-
#array;
|
|
148
|
-
/**
|
|
149
|
-
* Creates a new ArrayModel.
|
|
150
|
-
*
|
|
151
|
-
* @param arr
|
|
152
|
-
*/
|
|
153
|
-
constructor(arr) {
|
|
154
|
-
super();
|
|
155
|
-
this.#array = arr;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Returns the number of entries in the array model.
|
|
159
|
-
*/
|
|
160
|
-
get length() {
|
|
161
|
-
return this.#array.length;
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Returns the number of entries in the array model.
|
|
165
|
-
*/
|
|
166
|
-
rowCount() {
|
|
167
|
-
return this.#array.length;
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Returns the data at the specified row.
|
|
171
|
-
* @param row index in range 0..(rowCount() - 1).
|
|
172
|
-
* @returns undefined if row is out of range otherwise the data.
|
|
173
|
-
*/
|
|
174
|
-
rowData(row) {
|
|
175
|
-
return this.#array[row];
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Stores the given data on the given row index and notifies run-time about the changed row.
|
|
179
|
-
* @param row index in range 0..(rowCount() - 1).
|
|
180
|
-
* @param data new data item to store on the given row index
|
|
181
|
-
*/
|
|
182
|
-
setRowData(row, data) {
|
|
183
|
-
this.#array[row] = data;
|
|
184
|
-
this.notifyRowDataChanged(row);
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Pushes new values to the array that's backing the model and notifies
|
|
188
|
-
* the run-time about the added rows.
|
|
189
|
-
* @param values list of values that will be pushed to the array.
|
|
190
|
-
*/
|
|
191
|
-
push(...values) {
|
|
192
|
-
const size = this.#array.length;
|
|
193
|
-
Array.prototype.push.apply(this.#array, values);
|
|
194
|
-
this.notifyRowAdded(size, arguments.length);
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Removes the last element from the array and returns it.
|
|
198
|
-
*
|
|
199
|
-
* @returns The removed element or undefined if the array is empty.
|
|
200
|
-
*/
|
|
201
|
-
pop() {
|
|
202
|
-
const last = this.#array.pop();
|
|
203
|
-
if (last !== undefined) {
|
|
204
|
-
this.notifyRowRemoved(this.#array.length, 1);
|
|
205
|
-
}
|
|
206
|
-
return last;
|
|
207
|
-
}
|
|
208
|
-
// FIXME: should this be named splice and have the splice api?
|
|
209
|
-
/**
|
|
210
|
-
* Removes the specified number of element from the array that's backing
|
|
211
|
-
* the model, starting at the specified index.
|
|
212
|
-
* @param index index of first row to remove.
|
|
213
|
-
* @param size number of rows to remove.
|
|
214
|
-
*/
|
|
215
|
-
remove(index, size) {
|
|
216
|
-
const r = this.#array.splice(index, size);
|
|
217
|
-
this.notifyRowRemoved(index, size);
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Returns an iterable of values in the array.
|
|
221
|
-
*/
|
|
222
|
-
values() {
|
|
223
|
-
return this.#array.values();
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Returns an iterable of key, value pairs for every entry in the array.
|
|
227
|
-
*/
|
|
228
|
-
entries() {
|
|
229
|
-
return this.#array.entries();
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
exports.ArrayModel = ArrayModel;
|
|
233
|
-
var private_api;
|
|
234
|
-
(function (private_api) {
|
|
235
|
-
/**
|
|
236
|
-
* Provides rows that are generated by a map function based on the rows of another Model.
|
|
237
|
-
*
|
|
238
|
-
* @template T item type of source model that is mapped to U.
|
|
239
|
-
* @template U the type of the mapped items
|
|
240
|
-
*
|
|
241
|
-
* ## Example
|
|
242
|
-
*
|
|
243
|
-
* Here we have a {@link ArrayModel} holding rows of a custom interface `Name` and a {@link MapModel} that maps the name rows
|
|
244
|
-
* to single string rows.
|
|
245
|
-
*
|
|
246
|
-
* ```ts
|
|
247
|
-
* import { Model, ArrayModel, MapModel } from "./index";
|
|
248
|
-
*
|
|
249
|
-
* interface Name {
|
|
250
|
-
* first: string;
|
|
251
|
-
* last: string;
|
|
252
|
-
* }
|
|
253
|
-
*
|
|
254
|
-
* const model = new ArrayModel<Name>([
|
|
255
|
-
* {
|
|
256
|
-
* first: "Hans",
|
|
257
|
-
* last: "Emil",
|
|
258
|
-
* },
|
|
259
|
-
* {
|
|
260
|
-
* first: "Max",
|
|
261
|
-
* last: "Mustermann",
|
|
262
|
-
* },
|
|
263
|
-
* {
|
|
264
|
-
* first: "Roman",
|
|
265
|
-
* last: "Tisch",
|
|
266
|
-
* },
|
|
267
|
-
* ]);
|
|
268
|
-
*
|
|
269
|
-
* const mappedModel = new MapModel(
|
|
270
|
-
* model,
|
|
271
|
-
* (data) => {
|
|
272
|
-
* return data.last + ", " + data.first;
|
|
273
|
-
* }
|
|
274
|
-
* );
|
|
275
|
-
*
|
|
276
|
-
* // prints "Emil, Hans"
|
|
277
|
-
* console.log(mappedModel.rowData(0));
|
|
278
|
-
*
|
|
279
|
-
* // prints "Mustermann, Max"
|
|
280
|
-
* console.log(mappedModel.rowData(1));
|
|
281
|
-
*
|
|
282
|
-
* // prints "Tisch, Roman"
|
|
283
|
-
* console.log(mappedModel.rowData(2));
|
|
284
|
-
*
|
|
285
|
-
* // Alternatively you can use the shortcut {@link MapModel.map}.
|
|
286
|
-
*
|
|
287
|
-
* const model = new ArrayModel<Name>([
|
|
288
|
-
* {
|
|
289
|
-
* first: "Hans",
|
|
290
|
-
* last: "Emil",
|
|
291
|
-
* },
|
|
292
|
-
* {
|
|
293
|
-
* first: "Max",
|
|
294
|
-
* last: "Mustermann",
|
|
295
|
-
* },
|
|
296
|
-
* {
|
|
297
|
-
* first: "Roman",
|
|
298
|
-
* last: "Tisch",
|
|
299
|
-
* },
|
|
300
|
-
* ]);
|
|
301
|
-
*
|
|
302
|
-
* const mappedModel = model.map(
|
|
303
|
-
* (data) => {
|
|
304
|
-
* return data.last + ", " + data.first;
|
|
305
|
-
* }
|
|
306
|
-
* );
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
* // prints "Emil, Hans"
|
|
310
|
-
* console.log(mappedModel.rowData(0));
|
|
311
|
-
*
|
|
312
|
-
* // prints "Mustermann, Max"
|
|
313
|
-
* console.log(mappedModel.rowData(1));
|
|
314
|
-
*
|
|
315
|
-
* // prints "Tisch, Roman"
|
|
316
|
-
* console.log(mappedModel.rowData(2));
|
|
317
|
-
*
|
|
318
|
-
* // You can modifying the underlying {@link ArrayModel}:
|
|
319
|
-
*
|
|
320
|
-
* const model = new ArrayModel<Name>([
|
|
321
|
-
* {
|
|
322
|
-
* first: "Hans",
|
|
323
|
-
* last: "Emil",
|
|
324
|
-
* },
|
|
325
|
-
* {
|
|
326
|
-
* first: "Max",
|
|
327
|
-
* last: "Mustermann",
|
|
328
|
-
* },
|
|
329
|
-
* {
|
|
330
|
-
* first: "Roman",
|
|
331
|
-
* last: "Tisch",
|
|
332
|
-
* },
|
|
333
|
-
* ]);
|
|
334
|
-
*
|
|
335
|
-
* const mappedModel = model.map(
|
|
336
|
-
* (data) => {
|
|
337
|
-
* return data.last + ", " + data.first;
|
|
338
|
-
* }
|
|
339
|
-
* );
|
|
340
|
-
*
|
|
341
|
-
* model.setRowData(1, { first: "Minnie", last: "Musterfrau" } );
|
|
342
|
-
*
|
|
343
|
-
* // prints "Emil, Hans"
|
|
344
|
-
* console.log(mappedModel.rowData(0));
|
|
345
|
-
*
|
|
346
|
-
* // prints "Musterfrau, Minnie"
|
|
347
|
-
* console.log(mappedModel.rowData(1));
|
|
348
|
-
*
|
|
349
|
-
* // prints "Tisch, Roman"
|
|
350
|
-
* console.log(mappedModel.rowData(2));
|
|
351
|
-
* ```
|
|
352
|
-
*/
|
|
353
|
-
class MapModel extends Model {
|
|
354
|
-
sourceModel;
|
|
355
|
-
#mapFunction;
|
|
356
|
-
/**
|
|
357
|
-
* Constructs the MapModel with a source model and map functions.
|
|
358
|
-
* @template T item type of source model that is mapped to U.
|
|
359
|
-
* @template U the type of the mapped items.
|
|
360
|
-
* @param sourceModel the wrapped model.
|
|
361
|
-
* @param mapFunction maps the data from T to U.
|
|
362
|
-
*/
|
|
363
|
-
constructor(sourceModel, mapFunction) {
|
|
364
|
-
super();
|
|
365
|
-
this.sourceModel = sourceModel;
|
|
366
|
-
this.#mapFunction = mapFunction;
|
|
367
|
-
}
|
|
368
|
-
/**
|
|
369
|
-
* Returns the number of entries in the model.
|
|
370
|
-
*/
|
|
371
|
-
rowCount() {
|
|
372
|
-
return this.sourceModel.rowCount();
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* Returns the data at the specified row.
|
|
376
|
-
* @param row index in range 0..(rowCount() - 1).
|
|
377
|
-
* @returns undefined if row is out of range otherwise the data.
|
|
378
|
-
*/
|
|
379
|
-
rowData(row) {
|
|
380
|
-
const data = this.sourceModel.rowData(row);
|
|
381
|
-
if (data === undefined) {
|
|
382
|
-
return undefined;
|
|
383
|
-
}
|
|
384
|
-
return this.#mapFunction(data);
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
private_api.MapModel = MapModel;
|
|
388
|
-
})(private_api || (exports.private_api = private_api = {}));
|
|
5
|
+
exports.private_api = exports.quitEventLoop = exports.runEventLoop = exports.loadSource = exports.loadFile = exports.CompileError = exports.ArrayModel = exports.Model = exports.Brush = exports.RgbaColor = exports.DiagnosticLevel = exports.Diagnostic = void 0;
|
|
6
|
+
const napi = require("../rust-module.cjs");
|
|
7
|
+
var rust_module_cjs_1 = require("../rust-module.cjs");
|
|
8
|
+
Object.defineProperty(exports, "Diagnostic", { enumerable: true, get: function () { return rust_module_cjs_1.Diagnostic; } });
|
|
9
|
+
Object.defineProperty(exports, "DiagnosticLevel", { enumerable: true, get: function () { return rust_module_cjs_1.DiagnosticLevel; } });
|
|
10
|
+
Object.defineProperty(exports, "RgbaColor", { enumerable: true, get: function () { return rust_module_cjs_1.RgbaColor; } });
|
|
11
|
+
Object.defineProperty(exports, "Brush", { enumerable: true, get: function () { return rust_module_cjs_1.Brush; } });
|
|
12
|
+
const models_1 = require("./models");
|
|
13
|
+
Object.defineProperty(exports, "Model", { enumerable: true, get: function () { return models_1.Model; } });
|
|
14
|
+
var models_2 = require("./models");
|
|
15
|
+
Object.defineProperty(exports, "ArrayModel", { enumerable: true, get: function () { return models_2.ArrayModel; } });
|
|
389
16
|
/**
|
|
390
17
|
* @hidden
|
|
391
18
|
*/
|
|
@@ -787,6 +414,162 @@ function quitEventLoop() {
|
|
|
787
414
|
globalEventLoop.quit();
|
|
788
415
|
}
|
|
789
416
|
exports.quitEventLoop = quitEventLoop;
|
|
417
|
+
var private_api;
|
|
418
|
+
(function (private_api) {
|
|
419
|
+
/**
|
|
420
|
+
* Provides rows that are generated by a map function based on the rows of another Model.
|
|
421
|
+
*
|
|
422
|
+
* @template T item type of source model that is mapped to U.
|
|
423
|
+
* @template U the type of the mapped items
|
|
424
|
+
*
|
|
425
|
+
* ## Example
|
|
426
|
+
*
|
|
427
|
+
* Here we have a {@link ArrayModel} holding rows of a custom interface `Name` and a {@link MapModel} that maps the name rows
|
|
428
|
+
* to single string rows.
|
|
429
|
+
*
|
|
430
|
+
* ```ts
|
|
431
|
+
* import { Model, ArrayModel, MapModel } from "./index";
|
|
432
|
+
*
|
|
433
|
+
* interface Name {
|
|
434
|
+
* first: string;
|
|
435
|
+
* last: string;
|
|
436
|
+
* }
|
|
437
|
+
*
|
|
438
|
+
* const model = new ArrayModel<Name>([
|
|
439
|
+
* {
|
|
440
|
+
* first: "Hans",
|
|
441
|
+
* last: "Emil",
|
|
442
|
+
* },
|
|
443
|
+
* {
|
|
444
|
+
* first: "Max",
|
|
445
|
+
* last: "Mustermann",
|
|
446
|
+
* },
|
|
447
|
+
* {
|
|
448
|
+
* first: "Roman",
|
|
449
|
+
* last: "Tisch",
|
|
450
|
+
* },
|
|
451
|
+
* ]);
|
|
452
|
+
*
|
|
453
|
+
* const mappedModel = new MapModel(
|
|
454
|
+
* model,
|
|
455
|
+
* (data) => {
|
|
456
|
+
* return data.last + ", " + data.first;
|
|
457
|
+
* }
|
|
458
|
+
* );
|
|
459
|
+
*
|
|
460
|
+
* // prints "Emil, Hans"
|
|
461
|
+
* console.log(mappedModel.rowData(0));
|
|
462
|
+
*
|
|
463
|
+
* // prints "Mustermann, Max"
|
|
464
|
+
* console.log(mappedModel.rowData(1));
|
|
465
|
+
*
|
|
466
|
+
* // prints "Tisch, Roman"
|
|
467
|
+
* console.log(mappedModel.rowData(2));
|
|
468
|
+
*
|
|
469
|
+
* // Alternatively you can use the shortcut {@link MapModel.map}.
|
|
470
|
+
*
|
|
471
|
+
* const model = new ArrayModel<Name>([
|
|
472
|
+
* {
|
|
473
|
+
* first: "Hans",
|
|
474
|
+
* last: "Emil",
|
|
475
|
+
* },
|
|
476
|
+
* {
|
|
477
|
+
* first: "Max",
|
|
478
|
+
* last: "Mustermann",
|
|
479
|
+
* },
|
|
480
|
+
* {
|
|
481
|
+
* first: "Roman",
|
|
482
|
+
* last: "Tisch",
|
|
483
|
+
* },
|
|
484
|
+
* ]);
|
|
485
|
+
*
|
|
486
|
+
* const mappedModel = model.map(
|
|
487
|
+
* (data) => {
|
|
488
|
+
* return data.last + ", " + data.first;
|
|
489
|
+
* }
|
|
490
|
+
* );
|
|
491
|
+
*
|
|
492
|
+
*
|
|
493
|
+
* // prints "Emil, Hans"
|
|
494
|
+
* console.log(mappedModel.rowData(0));
|
|
495
|
+
*
|
|
496
|
+
* // prints "Mustermann, Max"
|
|
497
|
+
* console.log(mappedModel.rowData(1));
|
|
498
|
+
*
|
|
499
|
+
* // prints "Tisch, Roman"
|
|
500
|
+
* console.log(mappedModel.rowData(2));
|
|
501
|
+
*
|
|
502
|
+
* // You can modifying the underlying {@link ArrayModel}:
|
|
503
|
+
*
|
|
504
|
+
* const model = new ArrayModel<Name>([
|
|
505
|
+
* {
|
|
506
|
+
* first: "Hans",
|
|
507
|
+
* last: "Emil",
|
|
508
|
+
* },
|
|
509
|
+
* {
|
|
510
|
+
* first: "Max",
|
|
511
|
+
* last: "Mustermann",
|
|
512
|
+
* },
|
|
513
|
+
* {
|
|
514
|
+
* first: "Roman",
|
|
515
|
+
* last: "Tisch",
|
|
516
|
+
* },
|
|
517
|
+
* ]);
|
|
518
|
+
*
|
|
519
|
+
* const mappedModel = model.map(
|
|
520
|
+
* (data) => {
|
|
521
|
+
* return data.last + ", " + data.first;
|
|
522
|
+
* }
|
|
523
|
+
* );
|
|
524
|
+
*
|
|
525
|
+
* model.setRowData(1, { first: "Minnie", last: "Musterfrau" } );
|
|
526
|
+
*
|
|
527
|
+
* // prints "Emil, Hans"
|
|
528
|
+
* console.log(mappedModel.rowData(0));
|
|
529
|
+
*
|
|
530
|
+
* // prints "Musterfrau, Minnie"
|
|
531
|
+
* console.log(mappedModel.rowData(1));
|
|
532
|
+
*
|
|
533
|
+
* // prints "Tisch, Roman"
|
|
534
|
+
* console.log(mappedModel.rowData(2));
|
|
535
|
+
* ```
|
|
536
|
+
*/
|
|
537
|
+
class MapModel extends models_1.Model {
|
|
538
|
+
sourceModel;
|
|
539
|
+
#mapFunction;
|
|
540
|
+
/**
|
|
541
|
+
* Constructs the MapModel with a source model and map functions.
|
|
542
|
+
* @template T item type of source model that is mapped to U.
|
|
543
|
+
* @template U the type of the mapped items.
|
|
544
|
+
* @param sourceModel the wrapped model.
|
|
545
|
+
* @param mapFunction maps the data from T to U.
|
|
546
|
+
*/
|
|
547
|
+
constructor(sourceModel, mapFunction) {
|
|
548
|
+
super(sourceModel.modelNotify);
|
|
549
|
+
this.sourceModel = sourceModel;
|
|
550
|
+
this.#mapFunction = mapFunction;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Returns the number of entries in the model.
|
|
554
|
+
*/
|
|
555
|
+
rowCount() {
|
|
556
|
+
return this.sourceModel.rowCount();
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Returns the data at the specified row.
|
|
560
|
+
* @param row index in range 0..(rowCount() - 1).
|
|
561
|
+
* @returns undefined if row is out of range otherwise the data.
|
|
562
|
+
*/
|
|
563
|
+
rowData(row) {
|
|
564
|
+
const data = this.sourceModel.rowData(row);
|
|
565
|
+
if (data === undefined) {
|
|
566
|
+
return undefined;
|
|
567
|
+
}
|
|
568
|
+
return this.#mapFunction(data);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
private_api.MapModel = MapModel;
|
|
572
|
+
})(private_api || (exports.private_api = private_api = {}));
|
|
790
573
|
/**
|
|
791
574
|
* @hidden
|
|
792
575
|
*/
|