slint-ui 1.9.0-nightly.2024101112 → 1.9.0-nightly.2024101520
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/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 = "11128809fb744a93af668082edb0790ef7421d86", version = "=1.9.0", default-features = false }
|
|
45
|
+
i-slint-core = { features = ["default", "gettext-rs"] , git = "https://github.com/slint-ui/slint", rev = "11128809fb744a93af668082edb0790ef7421d86", version = "=1.9.0", default-features = false }
|
|
46
|
+
i-slint-backend-selector = { git = "https://github.com/slint-ui/slint", rev = "11128809fb744a93af668082edb0790ef7421d86", 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 = "11128809fb744a93af668082edb0790ef7421d86", 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/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.2024101520",
|
|
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.2024101520",
|
|
71
|
+
"@slint-ui/slint-ui-binary-darwin-x64": "1.9.0-nightly.2024101520",
|
|
72
|
+
"@slint-ui/slint-ui-binary-darwin-arm64": "1.9.0-nightly.2024101520",
|
|
73
|
+
"@slint-ui/slint-ui-binary-win32-x64-msvc": "1.9.0-nightly.2024101520",
|
|
74
|
+
"@slint-ui/slint-ui-binary-win32-ia32-msvc": "1.9.0-nightly.2024101520"
|
|
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 =
|