slint-ui 1.9.0-nightly.2024101016 → 1.9.0-nightly.2024101417
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/cover.md +58 -10
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/package.json +6 -6
- package/rust/interpreter/component_compiler.rs +61 -0
- package/rust-module.d.ts +1 -0
- package/typescript/index.ts +8 -0
package/Cargo.toml
CHANGED
|
@@ -41,10 +41,10 @@ accessibility = ["slint-interpreter/accessibility"]
|
|
|
41
41
|
[dependencies]
|
|
42
42
|
napi = { version = "2.14.0", default-features = false, features = ["napi8"] }
|
|
43
43
|
napi-derive = "2.14.0"
|
|
44
|
-
i-slint-compiler = { features = ["default"] , git = "https://github.com/slint-ui/slint", rev = "
|
|
45
|
-
i-slint-core = { features = ["default", "gettext-rs"] , git = "https://github.com/slint-ui/slint", rev = "
|
|
46
|
-
i-slint-backend-selector = { git = "https://github.com/slint-ui/slint", rev = "
|
|
47
|
-
slint-interpreter = { default-features = false , features = ["display-diagnostics", "internal", "compat-1-2"] , git = "https://github.com/slint-ui/slint", rev = "
|
|
44
|
+
i-slint-compiler = { features = ["default"] , git = "https://github.com/slint-ui/slint", rev = "c2ebe3ca2a7f77ad4eb88960801dd28e33ef0d04", version = "=1.9.0", default-features = false }
|
|
45
|
+
i-slint-core = { features = ["default", "gettext-rs"] , git = "https://github.com/slint-ui/slint", rev = "c2ebe3ca2a7f77ad4eb88960801dd28e33ef0d04", version = "=1.9.0", default-features = false }
|
|
46
|
+
i-slint-backend-selector = { git = "https://github.com/slint-ui/slint", rev = "c2ebe3ca2a7f77ad4eb88960801dd28e33ef0d04", version = "=1.9.0", default-features = false }
|
|
47
|
+
slint-interpreter = { default-features = false , features = ["display-diagnostics", "internal", "compat-1-2"] , git = "https://github.com/slint-ui/slint", rev = "c2ebe3ca2a7f77ad4eb88960801dd28e33ef0d04", version = "=1.9.0"}
|
|
48
48
|
spin_on = { version = "0.1" }
|
|
49
49
|
css-color-parser2 = { version = "1.0.1" }
|
|
50
50
|
itertools = { version = "0.13" }
|
package/cover.md
CHANGED
|
@@ -66,9 +66,9 @@ This file declares the user interface.
|
|
|
66
66
|
|
|
67
67
|
4. Create a new file called `index.mjs` with the following contents:
|
|
68
68
|
|
|
69
|
-
```
|
|
69
|
+
```js
|
|
70
70
|
import * as slint from "slint-ui";
|
|
71
|
-
let ui = slint.loadFile("main.slint");
|
|
71
|
+
let ui = slint.loadFile(new URL("main.slint", import.meta.url));
|
|
72
72
|
let demo = new ui.Demo();
|
|
73
73
|
|
|
74
74
|
await demo.run();
|
|
@@ -124,9 +124,9 @@ This file declares the user interface.
|
|
|
124
124
|
|
|
125
125
|
3. Create a new file called `index.ts` with the following contents:
|
|
126
126
|
|
|
127
|
-
```
|
|
127
|
+
```ts
|
|
128
128
|
import * as slint from "slint-ui";
|
|
129
|
-
let ui = slint.loadFile("main.slint");
|
|
129
|
+
let ui = slint.loadFile(new URL("main.slint", import.meta.url));
|
|
130
130
|
let demo = new ui.Demo();
|
|
131
131
|
|
|
132
132
|
await demo.run();
|
|
@@ -142,6 +142,54 @@ This is your main JavaScript entry point:
|
|
|
142
142
|
|
|
143
143
|
1. Run the example with `deno run --allow-read --allow-ffi --allow-sys index.ts`
|
|
144
144
|
|
|
145
|
+
|
|
146
|
+
## Getting Started (bun)
|
|
147
|
+
|
|
148
|
+
1. In a new directory, create a new `bun` project by calling [`bun init`](https://bun.sh/docs/cli/init).
|
|
149
|
+
2. Install Slint for your project using [`bun install slint-ui`](https://bun.sh/docs/cli/install).
|
|
150
|
+
3. Create a new file called `main.slint` with the following contents:
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
import { AboutSlint, Button, VerticalBox } from "std-widgets.slint";
|
|
154
|
+
export component Demo inherits Window {
|
|
155
|
+
in-out property <string> greeting <=> label.text;
|
|
156
|
+
VerticalBox {
|
|
157
|
+
alignment: start;
|
|
158
|
+
label := Text {
|
|
159
|
+
text: "Hello World!";
|
|
160
|
+
font-size: 24px;
|
|
161
|
+
horizontal-alignment: center;
|
|
162
|
+
}
|
|
163
|
+
AboutSlint {
|
|
164
|
+
preferred-height: 150px;
|
|
165
|
+
}
|
|
166
|
+
HorizontalLayout { alignment: center; Button { text: "OK!"; } }
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
This file declares the user interface.
|
|
172
|
+
|
|
173
|
+
4. Clear the conent of`index.ts` and add the following code:
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
import * as slint from "slint-ui";
|
|
177
|
+
let ui = slint.loadFile(new URL("main.slint", import.meta.url)) as any;
|
|
178
|
+
let demo = new ui.Demo();
|
|
179
|
+
|
|
180
|
+
await demo.run();
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
This is your main TypeScript entry point:
|
|
184
|
+
|
|
185
|
+
* Import the Slint API as an [ECMAScript module](https://nodejs.org/api/esm.html#modules-ecmascript-modules) module.
|
|
186
|
+
* Invoke `loadFile()` to compile and load the `.slint` file.
|
|
187
|
+
* Instantiate the `Demo` component declared in `main.slint`.
|
|
188
|
+
* Run it by showing it on the screen and reacting to user input.
|
|
189
|
+
|
|
190
|
+
5. Run the example with `bun run index.ts`
|
|
191
|
+
|
|
192
|
+
|
|
145
193
|
## API Overview
|
|
146
194
|
|
|
147
195
|
### Instantiating a Component
|
|
@@ -176,7 +224,7 @@ an object which allow to initialize the value of public properties or callbacks.
|
|
|
176
224
|
import * as slint from "slint-ui";
|
|
177
225
|
// In this example, the main.slint file exports a module which
|
|
178
226
|
// has a counter property and a clicked callback
|
|
179
|
-
let ui = slint.loadFile("ui/main.slint");
|
|
227
|
+
let ui = slint.loadFile(new URL("ui/main.slint", import.meta.url));
|
|
180
228
|
let component = new ui.MainWindow({
|
|
181
229
|
counter: 42,
|
|
182
230
|
clicked: function() { console.log("hello"); }
|
|
@@ -194,7 +242,7 @@ export component MainWindow {
|
|
|
194
242
|
}
|
|
195
243
|
|
|
196
244
|
```js
|
|
197
|
-
let ui = slint.loadFile("main.slint");
|
|
245
|
+
let ui = slint.loadFile(new URL("main.slint", import.meta.url));
|
|
198
246
|
let instance = new ui.MainWindow();
|
|
199
247
|
console.log(instance.age); // Prints 42
|
|
200
248
|
instance.name = "Joe";
|
|
@@ -223,7 +271,7 @@ export component MyComponent inherits Window {
|
|
|
223
271
|
```js
|
|
224
272
|
import * as slint from "slint-ui";
|
|
225
273
|
|
|
226
|
-
let ui = slint.loadFile("ui/my-component.slint");
|
|
274
|
+
let ui = slint.loadFile(new URL("ui/my-component.slint", import.meta.url));
|
|
227
275
|
let component = new ui.MyComponent();
|
|
228
276
|
|
|
229
277
|
// connect to a callback
|
|
@@ -294,7 +342,7 @@ export component MyComponent inherits Window {
|
|
|
294
342
|
|
|
295
343
|
import * as slint from "slint-ui";
|
|
296
344
|
|
|
297
|
-
let ui = slint.loadFile("my-component.slint");
|
|
345
|
+
let ui = slint.loadFile(new URL("my-component.slint", import.meta.url));
|
|
298
346
|
let component = new ui.MyComponent();
|
|
299
347
|
|
|
300
348
|
// object literal
|
|
@@ -330,7 +378,7 @@ export component MyComponent inherits Window {
|
|
|
330
378
|
|
|
331
379
|
import * as slint from "slint-ui";
|
|
332
380
|
|
|
333
|
-
let ui = slint.loadFile("my-component.slint");
|
|
381
|
+
let ui = slint.loadFile(new URL("my-component.slint", import.meta.url));
|
|
334
382
|
let component = new ui.MyComponent();
|
|
335
383
|
|
|
336
384
|
// set enum value as string
|
|
@@ -361,7 +409,7 @@ previous section, you can access `Logic` like this:
|
|
|
361
409
|
```js
|
|
362
410
|
import * as slint from "slint-ui";
|
|
363
411
|
|
|
364
|
-
let ui = slint.loadFile("ui/my-component.slint");
|
|
412
|
+
let ui = slint.loadFile(new URL("ui/my-component.slint", import.meta.url));
|
|
365
413
|
let component = new ui.MyComponent();
|
|
366
414
|
|
|
367
415
|
component.Logic.to_upper_case = (str) => {
|
package/dist/index.d.ts
CHANGED
|
@@ -170,6 +170,10 @@ export interface LoadFileOptions {
|
|
|
170
170
|
* Sets library paths used for looking up `@library` imports to the specified map of library names to paths.
|
|
171
171
|
*/
|
|
172
172
|
libraryPaths?: Record<string, string>;
|
|
173
|
+
/**
|
|
174
|
+
* @hidden
|
|
175
|
+
*/
|
|
176
|
+
fileLoader?: (path: string) => string;
|
|
173
177
|
}
|
|
174
178
|
/**
|
|
175
179
|
* Loads the specified Slint file and returns an object containing functions to construct the exported
|
package/dist/index.js
CHANGED
|
@@ -88,6 +88,9 @@ function loadSlint(loadData) {
|
|
|
88
88
|
if (typeof options.libraryPaths !== "undefined") {
|
|
89
89
|
compiler.libraryPaths = options.libraryPaths;
|
|
90
90
|
}
|
|
91
|
+
if (typeof options.fileLoader !== "undefined") {
|
|
92
|
+
compiler.fileLoader = options.fileLoader;
|
|
93
|
+
}
|
|
91
94
|
}
|
|
92
95
|
const definitions = loadData.from === "file"
|
|
93
96
|
? compiler.buildFromPath(filePath)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "slint-ui",
|
|
3
|
-
"version": "1.9.0-nightly.
|
|
3
|
+
"version": "1.9.0-nightly.2024101417",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"homepage": "https://github.com/slint-ui/slint",
|
|
@@ -67,10 +67,10 @@
|
|
|
67
67
|
"@napi-rs/cli": "2.16.5"
|
|
68
68
|
},
|
|
69
69
|
"optionalDependencies": {
|
|
70
|
-
"@slint-ui/slint-ui-binary-linux-x64-gnu": "1.9.0-nightly.
|
|
71
|
-
"@slint-ui/slint-ui-binary-darwin-x64": "1.9.0-nightly.
|
|
72
|
-
"@slint-ui/slint-ui-binary-darwin-arm64": "1.9.0-nightly.
|
|
73
|
-
"@slint-ui/slint-ui-binary-win32-x64-msvc": "1.9.0-nightly.
|
|
74
|
-
"@slint-ui/slint-ui-binary-win32-ia32-msvc": "1.9.0-nightly.
|
|
70
|
+
"@slint-ui/slint-ui-binary-linux-x64-gnu": "1.9.0-nightly.2024101417",
|
|
71
|
+
"@slint-ui/slint-ui-binary-darwin-x64": "1.9.0-nightly.2024101417",
|
|
72
|
+
"@slint-ui/slint-ui-binary-darwin-arm64": "1.9.0-nightly.2024101417",
|
|
73
|
+
"@slint-ui/slint-ui-binary-win32-x64-msvc": "1.9.0-nightly.2024101417",
|
|
74
|
+
"@slint-ui/slint-ui-binary-win32-ia32-msvc": "1.9.0-nightly.2024101417"
|
|
75
75
|
}
|
|
76
76
|
}
|
|
@@ -2,12 +2,15 @@
|
|
|
2
2
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
|
|
3
3
|
|
|
4
4
|
use crate::to_js_unknown;
|
|
5
|
+
use crate::RefCountedReference;
|
|
5
6
|
|
|
6
7
|
use super::JsComponentDefinition;
|
|
7
8
|
use super::JsDiagnostic;
|
|
8
9
|
use i_slint_compiler::langtype::Type;
|
|
9
10
|
use itertools::Itertools;
|
|
10
11
|
use napi::Env;
|
|
12
|
+
use napi::JsFunction;
|
|
13
|
+
use napi::JsString;
|
|
11
14
|
use napi::JsUnknown;
|
|
12
15
|
use slint_interpreter::Compiler;
|
|
13
16
|
use slint_interpreter::Value;
|
|
@@ -164,6 +167,64 @@ impl JsComponentCompiler {
|
|
|
164
167
|
.collect::<HashMap<String, JsUnknown>>()
|
|
165
168
|
}
|
|
166
169
|
|
|
170
|
+
#[napi(setter)]
|
|
171
|
+
pub fn set_file_loader(&mut self, env: Env, callback: JsFunction) -> napi::Result<()> {
|
|
172
|
+
let function_ref = std::rc::Rc::new(RefCountedReference::new(&env, callback)?);
|
|
173
|
+
|
|
174
|
+
self.internal.set_file_loader(move |path| {
|
|
175
|
+
let path = PathBuf::from(path);
|
|
176
|
+
let function_ref = function_ref.clone();
|
|
177
|
+
Box::pin({
|
|
178
|
+
async move {
|
|
179
|
+
let Ok(callback) = function_ref.get::<JsFunction>() else {
|
|
180
|
+
return Some(Err(std::io::Error::other(
|
|
181
|
+
"Node.js: cannot access file loader callback.",
|
|
182
|
+
)));
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
let Ok(path) = env.create_string(path.display().to_string().as_str()) else {
|
|
186
|
+
return Some(Err(std::io::Error::other(
|
|
187
|
+
"Node.js: wrong argunemt for callback file_loader.",
|
|
188
|
+
)));
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
let result = match callback.call(None, &[path]) {
|
|
192
|
+
Ok(result) => result,
|
|
193
|
+
Err(err) => {
|
|
194
|
+
return Some(Err(std::io::Error::other(err.to_string())));
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
let js_string: napi::Result<JsString> = result.try_into();
|
|
199
|
+
|
|
200
|
+
let Ok(js_string) = js_string else {
|
|
201
|
+
return Some(Err(std::io::Error::other(
|
|
202
|
+
"Node.js: cannot read return value of file loader callback as js string.",
|
|
203
|
+
)));
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
let Ok(utf8_string) = js_string.into_utf8() else {
|
|
207
|
+
return Some(Err(std::io::Error::other(
|
|
208
|
+
"Node.js: cannot convert return value of file loader callback into utf8.",
|
|
209
|
+
)));
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
if let Ok(str) = utf8_string.as_str() {
|
|
213
|
+
let string = str.to_string();
|
|
214
|
+
|
|
215
|
+
return Some(Ok(string));
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
Some(Err(std::io::Error::other(
|
|
219
|
+
"Node.js: cannot convert return value of file loader callback into string.",
|
|
220
|
+
)))
|
|
221
|
+
}
|
|
222
|
+
})
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
Ok(())
|
|
226
|
+
}
|
|
227
|
+
|
|
167
228
|
/// Compile a .slint file into a ComponentDefinition
|
|
168
229
|
///
|
|
169
230
|
/// Returns the compiled `ComponentDefinition` if there were no errors.
|
package/rust-module.d.ts
CHANGED
|
@@ -101,6 +101,7 @@ export class ComponentCompiler {
|
|
|
101
101
|
get diagnostics(): Array<Diagnostic>
|
|
102
102
|
get structs(): Record<string, unknown>
|
|
103
103
|
get enums(): Record<string, unknown>
|
|
104
|
+
set fileLoader(callback: (...args: any[]) => any)
|
|
104
105
|
/**
|
|
105
106
|
* Compile a .slint file into a ComponentDefinition
|
|
106
107
|
*
|
package/typescript/index.ts
CHANGED
|
@@ -247,6 +247,11 @@ export interface LoadFileOptions {
|
|
|
247
247
|
* Sets library paths used for looking up `@library` imports to the specified map of library names to paths.
|
|
248
248
|
*/
|
|
249
249
|
libraryPaths?: Record<string, string>;
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* @hidden
|
|
253
|
+
*/
|
|
254
|
+
fileLoader?: (path: string) => string;
|
|
250
255
|
}
|
|
251
256
|
|
|
252
257
|
type LoadData =
|
|
@@ -285,6 +290,9 @@ function loadSlint(loadData: LoadData): Object {
|
|
|
285
290
|
if (typeof options.libraryPaths !== "undefined") {
|
|
286
291
|
compiler.libraryPaths = options.libraryPaths;
|
|
287
292
|
}
|
|
293
|
+
if (typeof options.fileLoader !== "undefined") {
|
|
294
|
+
compiler.fileLoader = options.fileLoader;
|
|
295
|
+
}
|
|
288
296
|
}
|
|
289
297
|
|
|
290
298
|
const definitions =
|