slint-ui 1.7.0-nightly.2024062818 → 1.7.0-nightly.2024070213
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 +4 -4
- package/README.md +1 -1
- package/index.d.ts +21 -23
- package/index.js +160 -159
- package/index.ts +326 -326
- package/package.json +6 -6
- package/rust-module.d.ts +27 -27
- package/src/interpreter/component_compiler.rs +17 -14
package/index.ts
CHANGED
|
@@ -389,165 +389,165 @@ export class ArrayModel<T> extends Model<T> {
|
|
|
389
389
|
}
|
|
390
390
|
|
|
391
391
|
export namespace private_api {
|
|
392
|
-
/**
|
|
393
|
-
* Provides rows that are generated by a map function based on the rows of another Model.
|
|
394
|
-
*
|
|
395
|
-
* @template T item type of source model that is mapped to U.
|
|
396
|
-
* @template U the type of the mapped items
|
|
397
|
-
*
|
|
398
|
-
* ## Example
|
|
399
|
-
*
|
|
400
|
-
* Here we have a {@link ArrayModel} holding rows of a custom interface `Name` and a {@link MapModel} that maps the name rows
|
|
401
|
-
* to single string rows.
|
|
402
|
-
*
|
|
403
|
-
* ```ts
|
|
404
|
-
* import { Model, ArrayModel, MapModel } from "./index";
|
|
405
|
-
*
|
|
406
|
-
* interface Name {
|
|
407
|
-
* first: string;
|
|
408
|
-
* last: string;
|
|
409
|
-
* }
|
|
410
|
-
*
|
|
411
|
-
* const model = new ArrayModel<Name>([
|
|
412
|
-
* {
|
|
413
|
-
* first: "Hans",
|
|
414
|
-
* last: "Emil",
|
|
415
|
-
* },
|
|
416
|
-
* {
|
|
417
|
-
* first: "Max",
|
|
418
|
-
* last: "Mustermann",
|
|
419
|
-
* },
|
|
420
|
-
* {
|
|
421
|
-
* first: "Roman",
|
|
422
|
-
* last: "Tisch",
|
|
423
|
-
* },
|
|
424
|
-
* ]);
|
|
425
|
-
*
|
|
426
|
-
* const mappedModel = new MapModel(
|
|
427
|
-
* model,
|
|
428
|
-
* (data) => {
|
|
429
|
-
* return data.last + ", " + data.first;
|
|
430
|
-
* }
|
|
431
|
-
* );
|
|
432
|
-
*
|
|
433
|
-
* // prints "Emil, Hans"
|
|
434
|
-
* console.log(mappedModel.rowData(0));
|
|
435
|
-
*
|
|
436
|
-
* // prints "Mustermann, Max"
|
|
437
|
-
* console.log(mappedModel.rowData(1));
|
|
438
|
-
*
|
|
439
|
-
* // prints "Tisch, Roman"
|
|
440
|
-
* console.log(mappedModel.rowData(2));
|
|
441
|
-
*
|
|
442
|
-
* // Alternatively you can use the shortcut {@link MapModel.map}.
|
|
443
|
-
*
|
|
444
|
-
* const model = new ArrayModel<Name>([
|
|
445
|
-
* {
|
|
446
|
-
* first: "Hans",
|
|
447
|
-
* last: "Emil",
|
|
448
|
-
* },
|
|
449
|
-
* {
|
|
450
|
-
* first: "Max",
|
|
451
|
-
* last: "Mustermann",
|
|
452
|
-
* },
|
|
453
|
-
* {
|
|
454
|
-
* first: "Roman",
|
|
455
|
-
* last: "Tisch",
|
|
456
|
-
* },
|
|
457
|
-
* ]);
|
|
458
|
-
*
|
|
459
|
-
* const mappedModel = model.map(
|
|
460
|
-
* (data) => {
|
|
461
|
-
* return data.last + ", " + data.first;
|
|
462
|
-
* }
|
|
463
|
-
* );
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
* // prints "Emil, Hans"
|
|
467
|
-
* console.log(mappedModel.rowData(0));
|
|
468
|
-
*
|
|
469
|
-
* // prints "Mustermann, Max"
|
|
470
|
-
* console.log(mappedModel.rowData(1));
|
|
471
|
-
*
|
|
472
|
-
* // prints "Tisch, Roman"
|
|
473
|
-
* console.log(mappedModel.rowData(2));
|
|
474
|
-
*
|
|
475
|
-
* // You can modifying the underlying {@link ArrayModel}:
|
|
476
|
-
*
|
|
477
|
-
* const model = new ArrayModel<Name>([
|
|
478
|
-
* {
|
|
479
|
-
* first: "Hans",
|
|
480
|
-
* last: "Emil",
|
|
481
|
-
* },
|
|
482
|
-
* {
|
|
483
|
-
* first: "Max",
|
|
484
|
-
* last: "Mustermann",
|
|
485
|
-
* },
|
|
486
|
-
* {
|
|
487
|
-
* first: "Roman",
|
|
488
|
-
* last: "Tisch",
|
|
489
|
-
* },
|
|
490
|
-
* ]);
|
|
491
|
-
*
|
|
492
|
-
* const mappedModel = model.map(
|
|
493
|
-
* (data) => {
|
|
494
|
-
* return data.last + ", " + data.first;
|
|
495
|
-
* }
|
|
496
|
-
* );
|
|
497
|
-
*
|
|
498
|
-
* model.setRowData(1, { first: "Minnie", last: "Musterfrau" } );
|
|
499
|
-
*
|
|
500
|
-
* // prints "Emil, Hans"
|
|
501
|
-
* console.log(mappedModel.rowData(0));
|
|
502
|
-
*
|
|
503
|
-
* // prints "Musterfrau, Minnie"
|
|
504
|
-
* console.log(mappedModel.rowData(1));
|
|
505
|
-
*
|
|
506
|
-
* // prints "Tisch, Roman"
|
|
507
|
-
* console.log(mappedModel.rowData(2));
|
|
508
|
-
* ```
|
|
509
|
-
*/
|
|
510
|
-
export class MapModel<T, U> extends Model<U> {
|
|
511
|
-
readonly sourceModel: Model<T>;
|
|
512
|
-
#mapFunction: (data: T) => U
|
|
513
|
-
|
|
514
392
|
/**
|
|
515
|
-
*
|
|
393
|
+
* Provides rows that are generated by a map function based on the rows of another Model.
|
|
394
|
+
*
|
|
516
395
|
* @template T item type of source model that is mapped to U.
|
|
517
|
-
* @template U the type of the mapped items
|
|
518
|
-
*
|
|
519
|
-
*
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
396
|
+
* @template U the type of the mapped items
|
|
397
|
+
*
|
|
398
|
+
* ## Example
|
|
399
|
+
*
|
|
400
|
+
* Here we have a {@link ArrayModel} holding rows of a custom interface `Name` and a {@link MapModel} that maps the name rows
|
|
401
|
+
* to single string rows.
|
|
402
|
+
*
|
|
403
|
+
* ```ts
|
|
404
|
+
* import { Model, ArrayModel, MapModel } from "./index";
|
|
405
|
+
*
|
|
406
|
+
* interface Name {
|
|
407
|
+
* first: string;
|
|
408
|
+
* last: string;
|
|
409
|
+
* }
|
|
410
|
+
*
|
|
411
|
+
* const model = new ArrayModel<Name>([
|
|
412
|
+
* {
|
|
413
|
+
* first: "Hans",
|
|
414
|
+
* last: "Emil",
|
|
415
|
+
* },
|
|
416
|
+
* {
|
|
417
|
+
* first: "Max",
|
|
418
|
+
* last: "Mustermann",
|
|
419
|
+
* },
|
|
420
|
+
* {
|
|
421
|
+
* first: "Roman",
|
|
422
|
+
* last: "Tisch",
|
|
423
|
+
* },
|
|
424
|
+
* ]);
|
|
425
|
+
*
|
|
426
|
+
* const mappedModel = new MapModel(
|
|
427
|
+
* model,
|
|
428
|
+
* (data) => {
|
|
429
|
+
* return data.last + ", " + data.first;
|
|
430
|
+
* }
|
|
431
|
+
* );
|
|
432
|
+
*
|
|
433
|
+
* // prints "Emil, Hans"
|
|
434
|
+
* console.log(mappedModel.rowData(0));
|
|
435
|
+
*
|
|
436
|
+
* // prints "Mustermann, Max"
|
|
437
|
+
* console.log(mappedModel.rowData(1));
|
|
438
|
+
*
|
|
439
|
+
* // prints "Tisch, Roman"
|
|
440
|
+
* console.log(mappedModel.rowData(2));
|
|
441
|
+
*
|
|
442
|
+
* // Alternatively you can use the shortcut {@link MapModel.map}.
|
|
443
|
+
*
|
|
444
|
+
* const model = new ArrayModel<Name>([
|
|
445
|
+
* {
|
|
446
|
+
* first: "Hans",
|
|
447
|
+
* last: "Emil",
|
|
448
|
+
* },
|
|
449
|
+
* {
|
|
450
|
+
* first: "Max",
|
|
451
|
+
* last: "Mustermann",
|
|
452
|
+
* },
|
|
453
|
+
* {
|
|
454
|
+
* first: "Roman",
|
|
455
|
+
* last: "Tisch",
|
|
456
|
+
* },
|
|
457
|
+
* ]);
|
|
458
|
+
*
|
|
459
|
+
* const mappedModel = model.map(
|
|
460
|
+
* (data) => {
|
|
461
|
+
* return data.last + ", " + data.first;
|
|
462
|
+
* }
|
|
463
|
+
* );
|
|
464
|
+
*
|
|
465
|
+
*
|
|
466
|
+
* // prints "Emil, Hans"
|
|
467
|
+
* console.log(mappedModel.rowData(0));
|
|
468
|
+
*
|
|
469
|
+
* // prints "Mustermann, Max"
|
|
470
|
+
* console.log(mappedModel.rowData(1));
|
|
471
|
+
*
|
|
472
|
+
* // prints "Tisch, Roman"
|
|
473
|
+
* console.log(mappedModel.rowData(2));
|
|
474
|
+
*
|
|
475
|
+
* // You can modifying the underlying {@link ArrayModel}:
|
|
476
|
+
*
|
|
477
|
+
* const model = new ArrayModel<Name>([
|
|
478
|
+
* {
|
|
479
|
+
* first: "Hans",
|
|
480
|
+
* last: "Emil",
|
|
481
|
+
* },
|
|
482
|
+
* {
|
|
483
|
+
* first: "Max",
|
|
484
|
+
* last: "Mustermann",
|
|
485
|
+
* },
|
|
486
|
+
* {
|
|
487
|
+
* first: "Roman",
|
|
488
|
+
* last: "Tisch",
|
|
489
|
+
* },
|
|
490
|
+
* ]);
|
|
491
|
+
*
|
|
492
|
+
* const mappedModel = model.map(
|
|
493
|
+
* (data) => {
|
|
494
|
+
* return data.last + ", " + data.first;
|
|
495
|
+
* }
|
|
496
|
+
* );
|
|
497
|
+
*
|
|
498
|
+
* model.setRowData(1, { first: "Minnie", last: "Musterfrau" } );
|
|
499
|
+
*
|
|
500
|
+
* // prints "Emil, Hans"
|
|
501
|
+
* console.log(mappedModel.rowData(0));
|
|
502
|
+
*
|
|
503
|
+
* // prints "Musterfrau, Minnie"
|
|
504
|
+
* console.log(mappedModel.rowData(1));
|
|
505
|
+
*
|
|
506
|
+
* // prints "Tisch, Roman"
|
|
507
|
+
* console.log(mappedModel.rowData(2));
|
|
508
|
+
* ```
|
|
509
|
+
*/
|
|
510
|
+
export class MapModel<T, U> extends Model<U> {
|
|
511
|
+
readonly sourceModel: Model<T>;
|
|
512
|
+
#mapFunction: (data: T) => U
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Constructs the MapModel with a source model and map functions.
|
|
516
|
+
* @template T item type of source model that is mapped to U.
|
|
517
|
+
* @template U the type of the mapped items.
|
|
518
|
+
* @param sourceModel the wrapped model.
|
|
519
|
+
* @param mapFunction maps the data from T to U.
|
|
520
|
+
*/
|
|
521
|
+
constructor(
|
|
522
|
+
sourceModel: Model<T>,
|
|
523
|
+
mapFunction: (data: T) => U
|
|
524
|
+
) {
|
|
525
|
+
super();
|
|
526
|
+
this.sourceModel = sourceModel;
|
|
527
|
+
this.#mapFunction = mapFunction;
|
|
528
|
+
}
|
|
529
529
|
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
530
|
+
/**
|
|
531
|
+
* Returns the number of entries in the model.
|
|
532
|
+
*/
|
|
533
|
+
rowCount(): number {
|
|
534
|
+
return this.sourceModel.rowCount();
|
|
535
|
+
}
|
|
536
536
|
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
537
|
+
/**
|
|
538
|
+
* Returns the data at the specified row.
|
|
539
|
+
* @param row index in range 0..(rowCount() - 1).
|
|
540
|
+
* @returns undefined if row is out of range otherwise the data.
|
|
541
|
+
*/
|
|
542
|
+
rowData(row: number): U | undefined {
|
|
543
|
+
let data = this.sourceModel.rowData(row);
|
|
544
|
+
if (data === undefined) {
|
|
545
|
+
return undefined;
|
|
546
|
+
}
|
|
547
|
+
return this.#mapFunction(data);
|
|
546
548
|
}
|
|
547
|
-
return this.#mapFunction(data);
|
|
548
549
|
}
|
|
549
550
|
}
|
|
550
|
-
}
|
|
551
551
|
/**
|
|
552
552
|
* This interface describes the public API of a Slint component that is common to all instances. Use this to
|
|
553
553
|
* show() the window on the screen, access the window and subsequent window properties, or start the
|
|
@@ -681,7 +681,7 @@ type LoadData = {
|
|
|
681
681
|
}
|
|
682
682
|
|
|
683
683
|
function loadSlint(loadData: LoadData): Object {
|
|
684
|
-
const {filePath
|
|
684
|
+
const { filePath, options } = loadData.fileData
|
|
685
685
|
|
|
686
686
|
let compiler = new napi.ComponentCompiler();
|
|
687
687
|
|
|
@@ -697,8 +697,7 @@ function loadSlint(loadData: LoadData): Object {
|
|
|
697
697
|
}
|
|
698
698
|
}
|
|
699
699
|
|
|
700
|
-
let
|
|
701
|
-
|
|
700
|
+
let definitions = loadData.from === 'file' ? compiler.buildFromPath(filePath) : compiler.buildFromSource(loadData.fileData.source, filePath);
|
|
702
701
|
let diagnostics = compiler.diagnostics;
|
|
703
702
|
|
|
704
703
|
if (diagnostics.length > 0) {
|
|
@@ -721,168 +720,171 @@ function loadSlint(loadData: LoadData): Object {
|
|
|
721
720
|
|
|
722
721
|
let slint_module = Object.create({});
|
|
723
722
|
|
|
724
|
-
Object.
|
|
725
|
-
|
|
726
|
-
let instance = definition!.create();
|
|
723
|
+
Object.keys(definitions).forEach((key) => {
|
|
724
|
+
let definition = definitions[key];
|
|
727
725
|
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
);
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
for (var key in properties) {
|
|
735
|
-
let value = properties[key];
|
|
726
|
+
Object.defineProperty(slint_module, definition.name.replace(/-/g, "_"), {
|
|
727
|
+
value: function (properties: any) {
|
|
728
|
+
let instance = definition.create();
|
|
736
729
|
|
|
737
|
-
if (
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
730
|
+
if (instance == null) {
|
|
731
|
+
throw Error(
|
|
732
|
+
"Could not create a component handle for" + filePath
|
|
733
|
+
);
|
|
741
734
|
}
|
|
742
|
-
}
|
|
743
735
|
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
let propName = prop.name.replace(/-/g, "_");
|
|
747
|
-
|
|
748
|
-
if (componentHandle[propName] !== undefined) {
|
|
749
|
-
console.warn("Duplicated property name " + propName);
|
|
750
|
-
} else {
|
|
751
|
-
Object.defineProperty(componentHandle, propName, {
|
|
752
|
-
get() {
|
|
753
|
-
return instance!.getProperty(prop.name);
|
|
754
|
-
},
|
|
755
|
-
set(value) {
|
|
756
|
-
instance!.setProperty(prop.name, value);
|
|
757
|
-
},
|
|
758
|
-
enumerable: true,
|
|
759
|
-
});
|
|
760
|
-
}
|
|
761
|
-
});
|
|
736
|
+
for (var key in properties) {
|
|
737
|
+
let value = properties[key];
|
|
762
738
|
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
} else {
|
|
769
|
-
Object.defineProperty(componentHandle, cb.replace(/-/g, "_"), {
|
|
770
|
-
get() {
|
|
771
|
-
return function () {
|
|
772
|
-
return instance!.invoke(cb, Array.from(arguments));
|
|
773
|
-
};
|
|
774
|
-
},
|
|
775
|
-
set(callback) {
|
|
776
|
-
instance!.setCallback(cb, callback);
|
|
777
|
-
},
|
|
778
|
-
enumerable: true,
|
|
779
|
-
});
|
|
739
|
+
if (value instanceof Function) {
|
|
740
|
+
instance.setCallback(key, value);
|
|
741
|
+
} else {
|
|
742
|
+
instance.setProperty(key, properties[key]);
|
|
743
|
+
}
|
|
780
744
|
}
|
|
781
|
-
});
|
|
782
|
-
|
|
783
|
-
instance!.definition().functions.forEach((cb) => {
|
|
784
|
-
let functionName = cb.replace(/-/g, "_");
|
|
785
|
-
|
|
786
|
-
if (componentHandle[functionName] !== undefined) {
|
|
787
|
-
console.warn("Duplicated function name " + functionName);
|
|
788
|
-
} else {
|
|
789
|
-
Object.defineProperty(componentHandle, cb.replace(/-/g, "_"), {
|
|
790
|
-
get() {
|
|
791
|
-
return function () {
|
|
792
|
-
return instance!.invoke(cb, Array.from(arguments));
|
|
793
|
-
};
|
|
794
|
-
},
|
|
795
|
-
enumerable: true,
|
|
796
|
-
});
|
|
797
|
-
}
|
|
798
|
-
});
|
|
799
|
-
|
|
800
|
-
// globals
|
|
801
|
-
instance!.definition().globals.forEach((globalName) => {
|
|
802
|
-
if (componentHandle[globalName] !== undefined) {
|
|
803
|
-
console.warn("Duplicated property name " + globalName);
|
|
804
|
-
} else {
|
|
805
|
-
let globalObject = Object.create({});
|
|
806
|
-
|
|
807
|
-
instance!.definition().globalProperties(globalName).forEach((prop) => {
|
|
808
|
-
let propName = prop.name.replace(/-/g, "_");
|
|
809
|
-
|
|
810
|
-
if (globalObject[propName] !== undefined) {
|
|
811
|
-
console.warn("Duplicated property name " + propName + " on global " + global);
|
|
812
|
-
} else {
|
|
813
|
-
Object.defineProperty(globalObject, propName, {
|
|
814
|
-
get() {
|
|
815
|
-
return instance!.getGlobalProperty(globalName, prop.name);
|
|
816
|
-
},
|
|
817
|
-
set(value) {
|
|
818
|
-
instance!.setGlobalProperty(globalName, prop.name, value);
|
|
819
|
-
},
|
|
820
|
-
enumerable: true,
|
|
821
|
-
});
|
|
822
|
-
}
|
|
823
|
-
});
|
|
824
|
-
|
|
825
|
-
instance!.definition().globalCallbacks(globalName).forEach((cb) => {
|
|
826
|
-
let callbackName = cb.replace(/-/g, "_");
|
|
827
|
-
|
|
828
|
-
if (globalObject[callbackName] !== undefined) {
|
|
829
|
-
console.warn("Duplicated property name " + cb + " on global " + global);
|
|
830
|
-
} else {
|
|
831
|
-
Object.defineProperty(globalObject, cb.replace(/-/g, "_"), {
|
|
832
|
-
get() {
|
|
833
|
-
return function () {
|
|
834
|
-
return instance!.invokeGlobal(globalName, cb, Array.from(arguments));
|
|
835
|
-
};
|
|
836
|
-
},
|
|
837
|
-
set(callback) {
|
|
838
|
-
instance!.setGlobalCallback(globalName, cb, callback);
|
|
839
|
-
},
|
|
840
|
-
enumerable: true,
|
|
841
|
-
});
|
|
842
|
-
}
|
|
843
|
-
});
|
|
844
|
-
|
|
845
|
-
instance!.definition().globalFunctions(globalName).forEach((cb) => {
|
|
846
|
-
let functionName = cb.replace(/-/g, "_");
|
|
847
|
-
|
|
848
|
-
if (globalObject[functionName] !== undefined) {
|
|
849
|
-
console.warn("Duplicated function name " + cb + " on global " + global);
|
|
850
|
-
} else {
|
|
851
|
-
Object.defineProperty(globalObject, cb.replace(/-/g, "_"), {
|
|
852
|
-
get() {
|
|
853
|
-
return function () {
|
|
854
|
-
return instance!.invokeGlobal(globalName, cb, Array.from(arguments));
|
|
855
|
-
};
|
|
856
|
-
},
|
|
857
|
-
enumerable: true,
|
|
858
|
-
});
|
|
859
|
-
}
|
|
860
|
-
});
|
|
861
|
-
|
|
862
|
-
Object.defineProperty(componentHandle, globalName, {
|
|
863
|
-
get() {
|
|
864
|
-
return globalObject;
|
|
865
|
-
},
|
|
866
|
-
enumerable: true,
|
|
867
|
-
});
|
|
868
|
-
}
|
|
869
|
-
});
|
|
870
745
|
|
|
871
|
-
|
|
872
|
-
|
|
746
|
+
let componentHandle = new Component(instance!);
|
|
747
|
+
instance!.definition().properties.forEach((prop) => {
|
|
748
|
+
let propName = prop.name.replace(/-/g, "_");
|
|
749
|
+
|
|
750
|
+
if (componentHandle[propName] !== undefined) {
|
|
751
|
+
console.warn("Duplicated property name " + propName);
|
|
752
|
+
} else {
|
|
753
|
+
Object.defineProperty(componentHandle, propName, {
|
|
754
|
+
get() {
|
|
755
|
+
return instance!.getProperty(prop.name);
|
|
756
|
+
},
|
|
757
|
+
set(value) {
|
|
758
|
+
instance!.setProperty(prop.name, value);
|
|
759
|
+
},
|
|
760
|
+
enumerable: true,
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
});
|
|
764
|
+
|
|
765
|
+
instance!.definition().callbacks.forEach((cb) => {
|
|
766
|
+
let callbackName = cb.replace(/-/g, "_");
|
|
767
|
+
|
|
768
|
+
if (componentHandle[callbackName] !== undefined) {
|
|
769
|
+
console.warn("Duplicated callback name " + callbackName);
|
|
770
|
+
} else {
|
|
771
|
+
Object.defineProperty(componentHandle, cb.replace(/-/g, "_"), {
|
|
772
|
+
get() {
|
|
773
|
+
return function () {
|
|
774
|
+
return instance!.invoke(cb, Array.from(arguments));
|
|
775
|
+
};
|
|
776
|
+
},
|
|
777
|
+
set(callback) {
|
|
778
|
+
instance!.setCallback(cb, callback);
|
|
779
|
+
},
|
|
780
|
+
enumerable: true,
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
});
|
|
784
|
+
|
|
785
|
+
instance!.definition().functions.forEach((cb) => {
|
|
786
|
+
let functionName = cb.replace(/-/g, "_");
|
|
787
|
+
|
|
788
|
+
if (componentHandle[functionName] !== undefined) {
|
|
789
|
+
console.warn("Duplicated function name " + functionName);
|
|
790
|
+
} else {
|
|
791
|
+
Object.defineProperty(componentHandle, cb.replace(/-/g, "_"), {
|
|
792
|
+
get() {
|
|
793
|
+
return function () {
|
|
794
|
+
return instance!.invoke(cb, Array.from(arguments));
|
|
795
|
+
};
|
|
796
|
+
},
|
|
797
|
+
enumerable: true,
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
});
|
|
801
|
+
|
|
802
|
+
// globals
|
|
803
|
+
instance!.definition().globals.forEach((globalName) => {
|
|
804
|
+
if (componentHandle[globalName] !== undefined) {
|
|
805
|
+
console.warn("Duplicated property name " + globalName);
|
|
806
|
+
} else {
|
|
807
|
+
let globalObject = Object.create({});
|
|
808
|
+
|
|
809
|
+
instance!.definition().globalProperties(globalName).forEach((prop) => {
|
|
810
|
+
let propName = prop.name.replace(/-/g, "_");
|
|
811
|
+
|
|
812
|
+
if (globalObject[propName] !== undefined) {
|
|
813
|
+
console.warn("Duplicated property name " + propName + " on global " + global);
|
|
814
|
+
} else {
|
|
815
|
+
Object.defineProperty(globalObject, propName, {
|
|
816
|
+
get() {
|
|
817
|
+
return instance!.getGlobalProperty(globalName, prop.name);
|
|
818
|
+
},
|
|
819
|
+
set(value) {
|
|
820
|
+
instance!.setGlobalProperty(globalName, prop.name, value);
|
|
821
|
+
},
|
|
822
|
+
enumerable: true,
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
});
|
|
826
|
+
|
|
827
|
+
instance!.definition().globalCallbacks(globalName).forEach((cb) => {
|
|
828
|
+
let callbackName = cb.replace(/-/g, "_");
|
|
829
|
+
|
|
830
|
+
if (globalObject[callbackName] !== undefined) {
|
|
831
|
+
console.warn("Duplicated property name " + cb + " on global " + global);
|
|
832
|
+
} else {
|
|
833
|
+
Object.defineProperty(globalObject, cb.replace(/-/g, "_"), {
|
|
834
|
+
get() {
|
|
835
|
+
return function () {
|
|
836
|
+
return instance!.invokeGlobal(globalName, cb, Array.from(arguments));
|
|
837
|
+
};
|
|
838
|
+
},
|
|
839
|
+
set(callback) {
|
|
840
|
+
instance!.setGlobalCallback(globalName, cb, callback);
|
|
841
|
+
},
|
|
842
|
+
enumerable: true,
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
instance!.definition().globalFunctions(globalName).forEach((cb) => {
|
|
848
|
+
let functionName = cb.replace(/-/g, "_");
|
|
849
|
+
|
|
850
|
+
if (globalObject[functionName] !== undefined) {
|
|
851
|
+
console.warn("Duplicated function name " + cb + " on global " + global);
|
|
852
|
+
} else {
|
|
853
|
+
Object.defineProperty(globalObject, cb.replace(/-/g, "_"), {
|
|
854
|
+
get() {
|
|
855
|
+
return function () {
|
|
856
|
+
return instance!.invokeGlobal(globalName, cb, Array.from(arguments));
|
|
857
|
+
};
|
|
858
|
+
},
|
|
859
|
+
enumerable: true,
|
|
860
|
+
});
|
|
861
|
+
}
|
|
862
|
+
});
|
|
863
|
+
|
|
864
|
+
Object.defineProperty(componentHandle, globalName, {
|
|
865
|
+
get() {
|
|
866
|
+
return globalObject;
|
|
867
|
+
},
|
|
868
|
+
enumerable: true,
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
});
|
|
872
|
+
|
|
873
|
+
return Object.seal(componentHandle);
|
|
874
|
+
},
|
|
875
|
+
});
|
|
873
876
|
});
|
|
874
|
-
|
|
875
877
|
return Object.seal(slint_module);
|
|
876
878
|
}
|
|
877
879
|
|
|
878
880
|
/**
|
|
879
|
-
* Loads the
|
|
880
|
-
*
|
|
881
|
+
* Loads the specified Slint file and returns an object containing functions to construct the exported
|
|
882
|
+
* components defined within the Slint file.
|
|
881
883
|
*
|
|
882
884
|
* The following example loads a "Hello World" style Slint file and changes the Text label to a new greeting:
|
|
883
|
-
*
|
|
885
|
+
* **`main.slint`**:
|
|
884
886
|
* ```
|
|
885
|
-
* export component Main {
|
|
887
|
+
* export component Main inherits Window {
|
|
886
888
|
* in-out property <string> greeting <=> label.text;
|
|
887
889
|
* label := Text {
|
|
888
890
|
* text: "Hello World";
|
|
@@ -890,34 +892,33 @@ function loadSlint(loadData: LoadData): Object {
|
|
|
890
892
|
* }
|
|
891
893
|
* ```
|
|
892
894
|
*
|
|
893
|
-
*
|
|
895
|
+
* **`index.js`**:
|
|
896
|
+
* ```javascript
|
|
894
897
|
* import * as slint from "slint-ui";
|
|
895
898
|
* let ui = slint.loadFile("main.slint");
|
|
896
899
|
* let main = new ui.Main();
|
|
897
900
|
* main.greeting = "Hello friends";
|
|
898
901
|
* ```
|
|
899
902
|
*
|
|
900
|
-
* @param filePath
|
|
901
|
-
*
|
|
902
|
-
* @param options Use {@link LoadFileOptions} to configure additional Slint compilation aspects,
|
|
903
|
+
* @param filePath The path to the file to load. Relative paths are resolved against the process' current working directory.
|
|
904
|
+
* @param options An optional {@link LoadFileOptions} to configure additional Slint compilation settings,
|
|
903
905
|
* such as include search paths, library imports, or the widget style.
|
|
904
|
-
* @returns
|
|
905
|
-
* in the
|
|
906
|
-
*
|
|
907
|
-
*
|
|
908
|
-
* For more details about the exposed properties, see [Instantiating A Component](../index.html#md:instantiating-a-component).
|
|
906
|
+
* @returns Returns an object that is immutable and provides a constructor function for each exported Window component found in the `.slint` file.
|
|
907
|
+
* For instance, in the example above, a `Main` property is available, which can be used to create instances of the `Main` component using the `new` keyword.
|
|
908
|
+
* These instances offer properties and event handlers, adhering to the {@link ComponentHandle} interface.
|
|
909
|
+
* For further information on the available properties, refer to [Instantiating A Component](../index.html#md:instantiating-a-component).
|
|
909
910
|
* @throws {@link CompileError} if errors occur during compilation.
|
|
910
911
|
*/
|
|
911
912
|
export function loadFile(filePath: string, options?: LoadFileOptions): Object {
|
|
912
913
|
return loadSlint({
|
|
913
|
-
fileData:{ filePath, options },
|
|
914
|
-
from:'file',
|
|
914
|
+
fileData: { filePath, options },
|
|
915
|
+
from: 'file',
|
|
915
916
|
})
|
|
916
917
|
}
|
|
917
918
|
|
|
918
919
|
/**
|
|
919
|
-
* Loads the given Slint source code and returns an object that contains a
|
|
920
|
-
*
|
|
920
|
+
* Loads the given Slint source code and returns an object that contains a functions to construct the exported
|
|
921
|
+
* components of the Slint source code.
|
|
921
922
|
*
|
|
922
923
|
* The following example loads a "Hello World" style Slint source code and changes the Text label to a new greeting:
|
|
923
924
|
* ```js
|
|
@@ -933,21 +934,20 @@ export function loadFile(filePath: string, options?: LoadFileOptions): Object {
|
|
|
933
934
|
* main.greeting = "Hello friends";
|
|
934
935
|
* ```
|
|
935
936
|
* @param source The Slint source code to load.
|
|
936
|
-
* @param filePath A path to the file to show log
|
|
937
|
-
* against the process' working directory.
|
|
938
|
-
* @param options
|
|
937
|
+
* @param filePath A path to the file to show log and resolve relative import and images.
|
|
938
|
+
* Relative paths are resolved against the process' current working directory.
|
|
939
|
+
* @param options An optional {@link LoadFileOptions} to configure additional Slint compilation settings,
|
|
939
940
|
* such as include search paths, library imports, or the widget style.
|
|
940
|
-
* @returns
|
|
941
|
-
* in the
|
|
942
|
-
*
|
|
943
|
-
*
|
|
944
|
-
* For more details about the exposed properties, see [Instantiating A Component](../index.html#md:instantiating-a-component).
|
|
941
|
+
* @returns Returns an object that is immutable and provides a constructor function for each exported Window component found in the `.slint` file.
|
|
942
|
+
* For instance, in the example above, a `Main` property is available, which can be used to create instances of the `Main` component using the `new` keyword.
|
|
943
|
+
* These instances offer properties and event handlers, adhering to the {@link ComponentHandle} interface.
|
|
944
|
+
* For further information on the available properties, refer to [Instantiating A Component](../index.html#md:instantiating-a-component).
|
|
945
945
|
* @throws {@link CompileError} if errors occur during compilation.
|
|
946
946
|
*/
|
|
947
947
|
export function loadSource(source: string, filePath: string, options?: LoadFileOptions): Object {
|
|
948
948
|
return loadSlint({
|
|
949
|
-
fileData:{ filePath, options, source },
|
|
950
|
-
from:'source',
|
|
949
|
+
fileData: { filePath, options, source },
|
|
950
|
+
from: 'source',
|
|
951
951
|
})
|
|
952
952
|
}
|
|
953
953
|
|
|
@@ -1021,7 +1021,7 @@ var globalEventLoop: EventLoop = new EventLoop;
|
|
|
1021
1021
|
* application is idle, it continues to consume a low amount of CPU cycles, checking if either
|
|
1022
1022
|
* event loop has any pending events.
|
|
1023
1023
|
*/
|
|
1024
|
-
export function runEventLoop(args?: Function | { runningCallback?: Function; quitOnLastWindowClosed
|
|
1024
|
+
export function runEventLoop(args?: Function | { runningCallback?: Function; quitOnLastWindowClosed?: boolean }): Promise<unknown> {
|
|
1025
1025
|
if (args === undefined) {
|
|
1026
1026
|
return globalEventLoop.start(undefined);
|
|
1027
1027
|
}
|