slint-ui 0.3.5 → 1.0.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 +17 -4
- package/cover.md +164 -0
- package/dist/index.d.ts +172 -0
- package/dist/index.js +184 -0
- package/native/Cargo.toml +7 -4
- package/native/lib.rs +4 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Slint-node
|
|
1
|
+
# Slint-node (Beta)
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/slint-ui)
|
|
4
4
|
|
|
@@ -6,9 +6,12 @@
|
|
|
6
6
|
Slint-node is the integration with node.
|
|
7
7
|
|
|
8
8
|
The complete Node documentation can be viewed online at https://slint-ui.com/docs/node/.
|
|
9
|
+
To get started you can use the [Walk-through tutorial](https://slint-ui.com/docs/tutorial/node).
|
|
10
|
+
We also have a [Getting Started Template](https://github.com/slint-ui/slint-nodejs-template) repository with
|
|
11
|
+
the code of a minimal application using Slint that can be used as a starting point to your program.
|
|
9
12
|
|
|
10
|
-
**Warning:
|
|
11
|
-
Slint is still in the early stages of development: APIs will change and important features are still being developed.
|
|
13
|
+
**Warning: Beta**
|
|
14
|
+
Slint-node is still in the early stages of development: APIs will change and important features are still being developed.
|
|
12
15
|
|
|
13
16
|
## Installing Slint
|
|
14
17
|
|
|
@@ -18,6 +21,16 @@ Slint is available via NPM, so you can install by running the following command:
|
|
|
18
21
|
npm install slint-ui
|
|
19
22
|
```
|
|
20
23
|
|
|
24
|
+
### Dependencies
|
|
25
|
+
|
|
26
|
+
You need to install the following components:
|
|
27
|
+
|
|
28
|
+
* **[Node.js](https://nodejs.org/download/release/v16.19.1/)** (v16. Newer versions currently not supported: [#961](https://github.com/slint-ui/slint/issues/961))
|
|
29
|
+
* **[npm](https://www.npmjs.com/)**
|
|
30
|
+
* **[Rust compiler](https://www.rust-lang.org/tools/install)** (1.66 or newer)
|
|
31
|
+
|
|
32
|
+
You will also need a few more dependencies, see <https://github.com/slint-ui/slint/blob/master/docs/building.md#prerequisites>
|
|
33
|
+
|
|
21
34
|
## Using Slint
|
|
22
35
|
|
|
23
36
|
To initialize the API, you first need to import the `slint-ui` module in our code:
|
|
@@ -144,4 +157,4 @@ component.model = model;
|
|
|
144
157
|
model.push(4); // this works
|
|
145
158
|
// does NOT work, getting the model does not return the right object
|
|
146
159
|
// component.model.push(5);
|
|
147
|
-
|
|
160
|
+
```
|
package/cover.md
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# Slint-node (Beta)
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/slint-ui)
|
|
4
|
+
|
|
5
|
+
[Slint](https://slint-ui.com/) is a UI toolkit that supports different programming languages.
|
|
6
|
+
Slint-node is the integration with node.
|
|
7
|
+
|
|
8
|
+
To get started you can use the [Walk-through tutorial](https://slint-ui.com/docs/tutorial/node).
|
|
9
|
+
We also have a [Getting Started Template](https://github.com/slint-ui/slint-nodejs-template) repository with
|
|
10
|
+
the code of a minimal application using Slint that can be used as a starting point to your program.
|
|
11
|
+
|
|
12
|
+
**Warning: Beta**
|
|
13
|
+
Slint-node is still in the early stages of development: APIs will change and important features are still being developed.
|
|
14
|
+
|
|
15
|
+
## Slint Language Manual
|
|
16
|
+
|
|
17
|
+
The [Slint language manual](../slint) covers the Slint UI description language
|
|
18
|
+
in detail.
|
|
19
|
+
|
|
20
|
+
## Installing Slint
|
|
21
|
+
|
|
22
|
+
Slint is available via NPM, so you can install by running the following command:
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
npm install slint-ui
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Dependencies
|
|
29
|
+
|
|
30
|
+
You need to install the following components:
|
|
31
|
+
|
|
32
|
+
* **[Node.js](https://nodejs.org/download/release/v16.19.1/)** (v16. Newer versions currently not supported: [#961](https://github.com/slint-ui/slint/issues/961))
|
|
33
|
+
* **[npm](https://www.npmjs.com/)**
|
|
34
|
+
* **[Rust compiler](https://www.rust-lang.org/tools/install)** (1.66 or newer)
|
|
35
|
+
|
|
36
|
+
You will also need a few more dependencies, see <https://github.com/slint-ui/slint/blob/master/docs/building.md#prerequisites>
|
|
37
|
+
|
|
38
|
+
## Using Slint
|
|
39
|
+
|
|
40
|
+
To initialize the API, you first need to import the `slint-ui` module in our code:
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
let slint = require("slint-ui");
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
This step also installs a hook in NodeJS that allows you to import `.slint` files directly:
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
let ui = require("../ui/main.slint");
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Combining these two steps leads us to the obligatory "Hello World" example:
|
|
53
|
+
|
|
54
|
+
```js
|
|
55
|
+
require("slint-ui");
|
|
56
|
+
let ui = require("../ui/main.slint");
|
|
57
|
+
let main = new ui.Main();
|
|
58
|
+
main.run();
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
See [/examples/todo/node](https://github.com/slint-ui/slint/tree/master/examples/todo/node) for a full example.
|
|
62
|
+
|
|
63
|
+
## API Overview
|
|
64
|
+
|
|
65
|
+
### Instantiating a component
|
|
66
|
+
|
|
67
|
+
The exported component is exposed as a type constructor. The type constructor takes as parameter
|
|
68
|
+
an object which allow to initialize the value of public properties or callbacks.
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
require("slint-ui");
|
|
72
|
+
// In this example, the main.slint file exports a module which
|
|
73
|
+
// has a counter property and a clicked callback
|
|
74
|
+
let ui = require("ui/main.slint");
|
|
75
|
+
let component = new ui.MainWindow({
|
|
76
|
+
counter: 42,
|
|
77
|
+
clicked: function() { console.log("hello"); }
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Accessing a property
|
|
82
|
+
|
|
83
|
+
Properties are exposed as properties on the component instance
|
|
84
|
+
|
|
85
|
+
```js
|
|
86
|
+
component.counter = 42;
|
|
87
|
+
console.log(component.counter);
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Callbacks
|
|
91
|
+
|
|
92
|
+
The callbacks are also exposed as property that have a setHandler function, and that can can be called.
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
// connect to a callback
|
|
96
|
+
component.clicked.setHandler(function() { console.log("hello"); })
|
|
97
|
+
// emit a callback
|
|
98
|
+
component.clicked();
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Type Mappings
|
|
102
|
+
|
|
103
|
+
| `.slint` Type | JavaScript Type | Notes |
|
|
104
|
+
| --- | --- | --- |
|
|
105
|
+
| `int` | `Number` | |
|
|
106
|
+
| `float` | `Number` | |
|
|
107
|
+
| `string` | `String` | |
|
|
108
|
+
| `color` | `String` | Colors are represented as strings in the form `"#rrggbbaa"`. When setting a color property, any CSS compliant color is accepted as a string. |
|
|
109
|
+
| `length` | `Number` | |
|
|
110
|
+
| `physical_length` | `Number` | |
|
|
111
|
+
| `duration` | `Number` | The number of milliseconds |
|
|
112
|
+
| `angle` | `Number` | The value in degrees |
|
|
113
|
+
| structure | `Object` | Structures are mapped to JavaScrip objects with structure fields mapped to properties. |
|
|
114
|
+
| array | `Array` or Model Object | |
|
|
115
|
+
|
|
116
|
+
### Models
|
|
117
|
+
|
|
118
|
+
For property of array type, they can either be set using an array.
|
|
119
|
+
In that case, getting the property also return an array.
|
|
120
|
+
If the array was set within the .slint file, the array can be obtained
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
component.model = [1, 2, 3];
|
|
124
|
+
// component.model.push(4); // does not work, because it operate on a copy
|
|
125
|
+
// but re-assigning works
|
|
126
|
+
component.model = component.model.concat(4);
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Another option is to set a model object. A model object has the following function:
|
|
130
|
+
|
|
131
|
+
* `rowCount()`: returns the number of element in the model.
|
|
132
|
+
* `rowData(index)`: return the row at the given index
|
|
133
|
+
* `setRowData(index, data)`: called when the model need to be changed. `this.notify.rowDataChanged` must be called if successful.
|
|
134
|
+
|
|
135
|
+
When such an object is set to a model property, it gets a new `notify` object with the following function
|
|
136
|
+
|
|
137
|
+
* `rowDataChanged(index)`: notify the view that the row was changed.
|
|
138
|
+
* `rowAdded(index, count)`: notify the view that rows were added.
|
|
139
|
+
* `rowRemoved(index, count)`: notify the view that a row were removed.
|
|
140
|
+
* `reset()`: notify the view that everything may have changed.
|
|
141
|
+
|
|
142
|
+
As an example, here is the implementation of the `ArrayModel` (which is available as `slint.ArrayModel`)
|
|
143
|
+
|
|
144
|
+
```js
|
|
145
|
+
let array = [1, 2, 3];
|
|
146
|
+
let model = {
|
|
147
|
+
rowCount() { return a.length; },
|
|
148
|
+
rowData(row) { return a[row]; },
|
|
149
|
+
setRowData(row, data) { a[row] = data; this.notify.rowDataChanged(row); },
|
|
150
|
+
push() {
|
|
151
|
+
let size = a.length;
|
|
152
|
+
Array.prototype.push.apply(a, arguments);
|
|
153
|
+
this.notify.rowAdded(size, arguments.length);
|
|
154
|
+
},
|
|
155
|
+
remove(index, size) {
|
|
156
|
+
let r = a.splice(index, size);
|
|
157
|
+
this.notify.rowRemoved(size, arguments.length);
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
component.model = model;
|
|
161
|
+
model.push(4); // this works
|
|
162
|
+
// does NOT work, getting the model does not return the right object
|
|
163
|
+
// component.model.push(5);
|
|
164
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hidden
|
|
3
|
+
*/
|
|
4
|
+
declare function load_native_lib(): any;
|
|
5
|
+
/**
|
|
6
|
+
* @hidden
|
|
7
|
+
*/
|
|
8
|
+
declare let native: any;
|
|
9
|
+
/**
|
|
10
|
+
* @hidden
|
|
11
|
+
*/
|
|
12
|
+
declare class Component {
|
|
13
|
+
protected comp: any;
|
|
14
|
+
constructor(comp: any);
|
|
15
|
+
run(): void;
|
|
16
|
+
show(): void;
|
|
17
|
+
hide(): void;
|
|
18
|
+
get window(): SlintWindow;
|
|
19
|
+
send_mouse_click(x: number, y: number): void;
|
|
20
|
+
send_keyboard_string_sequence(s: String): void;
|
|
21
|
+
}
|
|
22
|
+
interface Point {
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
}
|
|
26
|
+
interface Size {
|
|
27
|
+
width: number;
|
|
28
|
+
height: number;
|
|
29
|
+
}
|
|
30
|
+
interface SlintWindow {
|
|
31
|
+
show(): void;
|
|
32
|
+
hide(): void;
|
|
33
|
+
is_visible: boolean;
|
|
34
|
+
logical_position: Point;
|
|
35
|
+
physical_position: Point;
|
|
36
|
+
logical_size: Size;
|
|
37
|
+
physical_size: Size;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @hidden
|
|
41
|
+
*/
|
|
42
|
+
declare class WindowAPI implements SlintWindow {
|
|
43
|
+
protected impl: any;
|
|
44
|
+
constructor(impl: any);
|
|
45
|
+
show(): void;
|
|
46
|
+
hide(): void;
|
|
47
|
+
get is_visible(): boolean;
|
|
48
|
+
get logical_position(): Point;
|
|
49
|
+
set logical_position(pos: Point);
|
|
50
|
+
get physical_position(): Point;
|
|
51
|
+
set physical_position(pos: Point);
|
|
52
|
+
get logical_size(): Size;
|
|
53
|
+
set logical_size(size: Size);
|
|
54
|
+
get physical_size(): Size;
|
|
55
|
+
set physical_size(size: Size);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* @hidden
|
|
59
|
+
*/
|
|
60
|
+
interface Callback {
|
|
61
|
+
(): any;
|
|
62
|
+
setHandler(cb: any): void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* ModelPeer is the interface that the run-time implements. An instance is
|
|
66
|
+
* set on dynamic Model<T> instances and can be used to notify the run-time
|
|
67
|
+
* of changes in the structure or data of the model.
|
|
68
|
+
*/
|
|
69
|
+
interface ModelPeer {
|
|
70
|
+
/**
|
|
71
|
+
* Call this function from our own model to notify that fields of data
|
|
72
|
+
* in the specified row have changed.
|
|
73
|
+
* @argument row
|
|
74
|
+
*/
|
|
75
|
+
rowDataChanged(row: number): void;
|
|
76
|
+
/**
|
|
77
|
+
* Call this function from your own model to notify that one or multiple
|
|
78
|
+
* rows were added to the model, starting at the specified row.
|
|
79
|
+
* @param row
|
|
80
|
+
* @param count
|
|
81
|
+
*/
|
|
82
|
+
rowAdded(row: number, count: number): void;
|
|
83
|
+
/**
|
|
84
|
+
* Call this function from your own model to notify that one or multiple
|
|
85
|
+
* rows were removed from the model, starting at the specified row.
|
|
86
|
+
* @param row
|
|
87
|
+
* @param count
|
|
88
|
+
*/
|
|
89
|
+
rowRemoved(row: number, count: number): void;
|
|
90
|
+
/**
|
|
91
|
+
* Call this function from your own model to notify that the model has been
|
|
92
|
+
* changed and everything must be reloaded
|
|
93
|
+
*/
|
|
94
|
+
reset(): void;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Model<T> is the interface for feeding dynamic data into
|
|
98
|
+
* `.slint` views.
|
|
99
|
+
*
|
|
100
|
+
* A model is organized like a table with rows of data. The
|
|
101
|
+
* fields of the data type T behave like columns.
|
|
102
|
+
*/
|
|
103
|
+
interface Model<T> {
|
|
104
|
+
/**
|
|
105
|
+
* Implementations of this function must return the current number of rows.
|
|
106
|
+
*/
|
|
107
|
+
rowCount(): number;
|
|
108
|
+
/**
|
|
109
|
+
* Implementations of this function must return the data at the specified row.
|
|
110
|
+
* @param row
|
|
111
|
+
*/
|
|
112
|
+
rowData(row: number): T;
|
|
113
|
+
/**
|
|
114
|
+
* Implementations of this function must store the provided data parameter
|
|
115
|
+
* in the model at the specified row.
|
|
116
|
+
* @param row
|
|
117
|
+
* @param data
|
|
118
|
+
*/
|
|
119
|
+
setRowData(row: number, data: T): void;
|
|
120
|
+
/**
|
|
121
|
+
* This public member is set by the run-time and implementation must use this
|
|
122
|
+
* to notify the run-time of changes in the model.
|
|
123
|
+
*/
|
|
124
|
+
notify: ModelPeer;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* @hidden
|
|
128
|
+
*/
|
|
129
|
+
declare class NullPeer implements ModelPeer {
|
|
130
|
+
rowDataChanged(row: number): void;
|
|
131
|
+
rowAdded(row: number, count: number): void;
|
|
132
|
+
rowRemoved(row: number, count: number): void;
|
|
133
|
+
reset(): void;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* ArrayModel wraps a JavaScript array for use in `.slint` views. The underlying
|
|
137
|
+
* array can be modified with the [[ArrayModel.push]] and [[ArrayModel.remove]] methods.
|
|
138
|
+
*/
|
|
139
|
+
declare class ArrayModel<T> implements Model<T> {
|
|
140
|
+
/**
|
|
141
|
+
* @hidden
|
|
142
|
+
*/
|
|
143
|
+
private a;
|
|
144
|
+
notify: ModelPeer;
|
|
145
|
+
/**
|
|
146
|
+
* Creates a new ArrayModel.
|
|
147
|
+
*
|
|
148
|
+
* @param arr
|
|
149
|
+
*/
|
|
150
|
+
constructor(arr: Array<T>);
|
|
151
|
+
rowCount(): number;
|
|
152
|
+
rowData(row: number): T;
|
|
153
|
+
setRowData(row: number, data: T): void;
|
|
154
|
+
/**
|
|
155
|
+
* Pushes new values to the array that's backing the model and notifies
|
|
156
|
+
* the run-time about the added rows.
|
|
157
|
+
* @param values
|
|
158
|
+
*/
|
|
159
|
+
push(...values: T[]): void;
|
|
160
|
+
/**
|
|
161
|
+
* Removes the specified number of element from the array that's backing
|
|
162
|
+
* the model, starting at the specified index. This is equivalent to calling
|
|
163
|
+
* Array.slice() on the array and notifying the run-time about the removed
|
|
164
|
+
* rows.
|
|
165
|
+
* @param index
|
|
166
|
+
* @param size
|
|
167
|
+
*/
|
|
168
|
+
remove(index: number, size: number): void;
|
|
169
|
+
get length(): number;
|
|
170
|
+
values(): IterableIterator<T>;
|
|
171
|
+
entries(): IterableIterator<[number, T]>;
|
|
172
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
|
|
3
|
+
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
|
|
4
|
+
// Load the native library with `process.dlopen` instead of with `require`.
|
|
5
|
+
// This is only done for autotest that do not require nom or neon_cli to
|
|
6
|
+
// copy the lib to its right place
|
|
7
|
+
/**
|
|
8
|
+
* @hidden
|
|
9
|
+
*/
|
|
10
|
+
function load_native_lib() {
|
|
11
|
+
const os = require('os');
|
|
12
|
+
process.dlopen(module, process.env.SLINT_NODE_NATIVE_LIB, os.constants.dlopen.RTLD_NOW);
|
|
13
|
+
return module.exports;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* @hidden
|
|
17
|
+
*/
|
|
18
|
+
let native = !process.env.SLINT_NODE_NATIVE_LIB ? require('../native/index.node') : load_native_lib();
|
|
19
|
+
/**
|
|
20
|
+
* @hidden
|
|
21
|
+
*/
|
|
22
|
+
class Component {
|
|
23
|
+
constructor(comp) {
|
|
24
|
+
this.comp = comp;
|
|
25
|
+
}
|
|
26
|
+
run() {
|
|
27
|
+
this.comp.run();
|
|
28
|
+
}
|
|
29
|
+
show() {
|
|
30
|
+
this.window.show();
|
|
31
|
+
}
|
|
32
|
+
hide() {
|
|
33
|
+
this.window.hide();
|
|
34
|
+
}
|
|
35
|
+
get window() {
|
|
36
|
+
return new WindowAPI(this.comp.window());
|
|
37
|
+
}
|
|
38
|
+
send_mouse_click(x, y) {
|
|
39
|
+
this.comp.send_mouse_click(x, y);
|
|
40
|
+
}
|
|
41
|
+
send_keyboard_string_sequence(s) {
|
|
42
|
+
this.comp.send_keyboard_string_sequence(s);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* @hidden
|
|
47
|
+
*/
|
|
48
|
+
class WindowAPI {
|
|
49
|
+
constructor(impl) {
|
|
50
|
+
this.impl = impl;
|
|
51
|
+
}
|
|
52
|
+
show() {
|
|
53
|
+
this.impl.show();
|
|
54
|
+
}
|
|
55
|
+
hide() {
|
|
56
|
+
this.impl.hide();
|
|
57
|
+
}
|
|
58
|
+
get is_visible() {
|
|
59
|
+
return this.impl.get_is_visible();
|
|
60
|
+
}
|
|
61
|
+
get logical_position() {
|
|
62
|
+
return this.impl.get_logical_position();
|
|
63
|
+
}
|
|
64
|
+
set logical_position(pos) {
|
|
65
|
+
this.impl.set_logical_position(pos);
|
|
66
|
+
}
|
|
67
|
+
get physical_position() {
|
|
68
|
+
return this.impl.get_physical_position();
|
|
69
|
+
}
|
|
70
|
+
set physical_position(pos) {
|
|
71
|
+
this.impl.set_physical_position(pos);
|
|
72
|
+
}
|
|
73
|
+
get logical_size() {
|
|
74
|
+
return this.impl.get_logical_size();
|
|
75
|
+
}
|
|
76
|
+
set logical_size(size) {
|
|
77
|
+
this.impl.set_logical_size(size);
|
|
78
|
+
}
|
|
79
|
+
get physical_size() {
|
|
80
|
+
return this.impl.get_physical_size();
|
|
81
|
+
}
|
|
82
|
+
set physical_size(size) {
|
|
83
|
+
this.impl.set_physical_size(size);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
require.extensions['.60'] = require.extensions['.slint'] =
|
|
87
|
+
function (module, filename) {
|
|
88
|
+
var c = native.load(filename);
|
|
89
|
+
module.exports[c.name().replace(/-/g, '_')] = function (init_properties) {
|
|
90
|
+
let comp = c.create(init_properties);
|
|
91
|
+
let ret = new Component(comp);
|
|
92
|
+
c.properties().forEach((x) => {
|
|
93
|
+
Object.defineProperty(ret, x.replace(/-/g, '_'), {
|
|
94
|
+
get() { return comp.get_property(x); },
|
|
95
|
+
set(newValue) { comp.set_property(x, newValue); },
|
|
96
|
+
enumerable: true,
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
c.callbacks().forEach((x) => {
|
|
100
|
+
Object.defineProperty(ret, x.replace(/-/g, '_'), {
|
|
101
|
+
get() {
|
|
102
|
+
let callback = function () { return comp.invoke_callback(x, [...arguments]); };
|
|
103
|
+
callback.setHandler = function (callback) { comp.connect_callback(x, callback); };
|
|
104
|
+
return callback;
|
|
105
|
+
},
|
|
106
|
+
enumerable: true,
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
return ret;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* @hidden
|
|
114
|
+
*/
|
|
115
|
+
class NullPeer {
|
|
116
|
+
rowDataChanged(row) { }
|
|
117
|
+
rowAdded(row, count) { }
|
|
118
|
+
rowRemoved(row, count) { }
|
|
119
|
+
reset() { }
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* ArrayModel wraps a JavaScript array for use in `.slint` views. The underlying
|
|
123
|
+
* array can be modified with the [[ArrayModel.push]] and [[ArrayModel.remove]] methods.
|
|
124
|
+
*/
|
|
125
|
+
class ArrayModel {
|
|
126
|
+
/**
|
|
127
|
+
* Creates a new ArrayModel.
|
|
128
|
+
*
|
|
129
|
+
* @param arr
|
|
130
|
+
*/
|
|
131
|
+
constructor(arr) {
|
|
132
|
+
this.a = arr;
|
|
133
|
+
this.notify = new NullPeer();
|
|
134
|
+
}
|
|
135
|
+
rowCount() {
|
|
136
|
+
return this.a.length;
|
|
137
|
+
}
|
|
138
|
+
rowData(row) {
|
|
139
|
+
return this.a[row];
|
|
140
|
+
}
|
|
141
|
+
setRowData(row, data) {
|
|
142
|
+
this.a[row] = data;
|
|
143
|
+
this.notify.rowDataChanged(row);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Pushes new values to the array that's backing the model and notifies
|
|
147
|
+
* the run-time about the added rows.
|
|
148
|
+
* @param values
|
|
149
|
+
*/
|
|
150
|
+
push(...values) {
|
|
151
|
+
let size = this.a.length;
|
|
152
|
+
Array.prototype.push.apply(this.a, values);
|
|
153
|
+
this.notify.rowAdded(size, arguments.length);
|
|
154
|
+
}
|
|
155
|
+
// FIXME: should this be named splice and have the splice api?
|
|
156
|
+
/**
|
|
157
|
+
* Removes the specified number of element from the array that's backing
|
|
158
|
+
* the model, starting at the specified index. This is equivalent to calling
|
|
159
|
+
* Array.slice() on the array and notifying the run-time about the removed
|
|
160
|
+
* rows.
|
|
161
|
+
* @param index
|
|
162
|
+
* @param size
|
|
163
|
+
*/
|
|
164
|
+
remove(index, size) {
|
|
165
|
+
let r = this.a.splice(index, size);
|
|
166
|
+
this.notify.rowRemoved(index, size);
|
|
167
|
+
}
|
|
168
|
+
get length() {
|
|
169
|
+
return this.a.length;
|
|
170
|
+
}
|
|
171
|
+
values() {
|
|
172
|
+
return this.a.values();
|
|
173
|
+
}
|
|
174
|
+
entries() {
|
|
175
|
+
return this.a.entries();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
module.exports = {
|
|
179
|
+
private_api: native,
|
|
180
|
+
ArrayModel: ArrayModel,
|
|
181
|
+
Timer: {
|
|
182
|
+
singleShot: native.singleshot_timer,
|
|
183
|
+
},
|
|
184
|
+
};
|
package/native/Cargo.toml
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
[package]
|
|
5
5
|
name = "slint-node"
|
|
6
|
-
version = "0.
|
|
6
|
+
version = "1.0.0"
|
|
7
7
|
authors = ["Slint Developers <info@slint-ui.com>"]
|
|
8
8
|
edition = "2021"
|
|
9
9
|
build = "build.rs"
|
|
@@ -20,9 +20,9 @@ crate-type = ["cdylib"]
|
|
|
20
20
|
name = "slint_node_native"
|
|
21
21
|
|
|
22
22
|
[dependencies]
|
|
23
|
-
i-slint-compiler = { version = "=0.
|
|
24
|
-
i-slint-core = { version = "=0.
|
|
25
|
-
slint-interpreter = { version = "=0.
|
|
23
|
+
i-slint-compiler = { version = "=1.0.0"}
|
|
24
|
+
i-slint-core = { version = "=1.0.0"}
|
|
25
|
+
slint-interpreter = { version = "=1.0.0", features = ["display-diagnostics"] }
|
|
26
26
|
|
|
27
27
|
vtable = { version = "0.1.6"}
|
|
28
28
|
|
|
@@ -34,5 +34,8 @@ rand = "0.8"
|
|
|
34
34
|
scoped-tls-hkt = "0.1"
|
|
35
35
|
spin_on = "0.1" #FIXME: remove and delegate to async JS instead
|
|
36
36
|
|
|
37
|
+
# Enable image-rs' default features to make all image formats available for nodejs builds
|
|
38
|
+
image = { version = "0.24.0" }
|
|
39
|
+
|
|
37
40
|
[build-dependencies]
|
|
38
41
|
neon-build = "0.8.0"
|
package/native/lib.rs
CHANGED
|
@@ -111,7 +111,7 @@ fn create<'cx>(
|
|
|
111
111
|
cx: &mut CallContext<'cx, impl neon::object::This>,
|
|
112
112
|
component_type: slint_interpreter::ComponentDefinition,
|
|
113
113
|
) -> JsResult<'cx, JsValue> {
|
|
114
|
-
let component = component_type.create();
|
|
114
|
+
let component = component_type.create().unwrap();
|
|
115
115
|
let persistent_context = persistent_context::PersistentContext::new(cx);
|
|
116
116
|
|
|
117
117
|
if let Some(args) = cx.argument_opt(0).and_then(|arg| arg.downcast::<JsObject>().ok()) {
|
|
@@ -341,7 +341,7 @@ declare_types! {
|
|
|
341
341
|
let component = cx.borrow(&this, |x| x.0.as_ref().map(|c| c.clone_strong()));
|
|
342
342
|
let component = component.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
343
343
|
run_scoped(&mut cx,this.downcast().unwrap(), || {
|
|
344
|
-
component.run();
|
|
344
|
+
component.run().unwrap();
|
|
345
345
|
Ok(())
|
|
346
346
|
})?;
|
|
347
347
|
Ok(JsUndefined::new().as_value(&mut cx))
|
|
@@ -490,7 +490,7 @@ declare_types! {
|
|
|
490
490
|
let this = cx.this();
|
|
491
491
|
let window = cx.borrow(&this, |x| x.0.as_ref().cloned());
|
|
492
492
|
let window_adapter = window.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
493
|
-
window_adapter.show();
|
|
493
|
+
window_adapter.show().unwrap();
|
|
494
494
|
Ok(JsUndefined::new().as_value(&mut cx))
|
|
495
495
|
}
|
|
496
496
|
|
|
@@ -498,7 +498,7 @@ declare_types! {
|
|
|
498
498
|
let this = cx.this();
|
|
499
499
|
let window = cx.borrow(&this, |x| x.0.as_ref().cloned());
|
|
500
500
|
let window_adapter = window.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
|
501
|
-
window_adapter.hide();
|
|
501
|
+
window_adapter.hide().unwrap();
|
|
502
502
|
Ok(JsUndefined::new().as_value(&mut cx))
|
|
503
503
|
}
|
|
504
504
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "slint-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"homepage": "https://github.com/slint-ui/slint",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
6
6
|
"repository": {
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"install": "neon build --release && tsc",
|
|
19
19
|
"build": "tsc",
|
|
20
|
-
"docs": "typedoc lib/index.ts"
|
|
20
|
+
"docs": "typedoc --hideGenerator --readme cover.md lib/index.ts"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"typedoc": "^0.19.2"
|
|
24
24
|
}
|
|
25
|
-
}
|
|
25
|
+
}
|