slint-ui 1.6.0-nightly.2024060319 → 1.7.0-nightly.2024060413
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 +6 -6
- package/binaries.json +1 -1
- package/index.js +32 -0
- package/index.ts +35 -1
- package/package.json +6 -6
- package/rust-module.d.ts +2 -0
- package/src/interpreter/component_definition.rs +17 -0
- package/src/interpreter/component_instance.rs +47 -37
package/Cargo.toml
CHANGED
|
@@ -12,7 +12,7 @@ keywords = ["gui", "toolkit", "graphics", "design", "ui"]
|
|
|
12
12
|
license = "GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0"
|
|
13
13
|
repository = "https://github.com/slint-ui/slint"
|
|
14
14
|
rust-version = "1.73"
|
|
15
|
-
version = "1.
|
|
15
|
+
version = "1.7.0"
|
|
16
16
|
categories = ["gui", "development-tools"]
|
|
17
17
|
build = "build.rs"
|
|
18
18
|
|
|
@@ -40,11 +40,11 @@ accessibility = ["slint-interpreter/accessibility"]
|
|
|
40
40
|
[dependencies]
|
|
41
41
|
napi = { version = "2.14.0", default-features = false, features = ["napi8"] }
|
|
42
42
|
napi-derive = "2.14.0"
|
|
43
|
-
i-slint-compiler = { features = ["default"] , git = "https://github.com/slint-ui/slint", rev = "
|
|
44
|
-
i-slint-core = { features = ["default"] , git = "https://github.com/slint-ui/slint", rev = "
|
|
45
|
-
i-slint-backend-selector = { git = "https://github.com/slint-ui/slint", rev = "
|
|
46
|
-
slint-interpreter = { default-features = false , features = ["display-diagnostics", "internal", "compat-1-2"] , git = "https://github.com/slint-ui/slint", rev = "
|
|
47
|
-
spin_on = "0.1"
|
|
43
|
+
i-slint-compiler = { features = ["default"] , git = "https://github.com/slint-ui/slint", rev = "e0c0e8d09c1577c9a231216eb462cffd3d16c199", version = "=1.7.0", default-features = false }
|
|
44
|
+
i-slint-core = { features = ["default"] , git = "https://github.com/slint-ui/slint", rev = "e0c0e8d09c1577c9a231216eb462cffd3d16c199", version = "=1.7.0", default-features = false }
|
|
45
|
+
i-slint-backend-selector = { git = "https://github.com/slint-ui/slint", rev = "e0c0e8d09c1577c9a231216eb462cffd3d16c199", version = "=1.7.0", default-features = false }
|
|
46
|
+
slint-interpreter = { default-features = false , features = ["display-diagnostics", "internal", "compat-1-2"] , git = "https://github.com/slint-ui/slint", rev = "e0c0e8d09c1577c9a231216eb462cffd3d16c199", version = "=1.7.0"}
|
|
47
|
+
spin_on = { version = "0.1" }
|
|
48
48
|
css-color-parser2 = { version = "1.0.1" }
|
|
49
49
|
itertools = { version = "0.12" }
|
|
50
50
|
send_wrapper = { version = "0.6.0" }
|
package/binaries.json
CHANGED
package/index.js
CHANGED
|
@@ -517,6 +517,22 @@ function loadSlint(loadData) {
|
|
|
517
517
|
});
|
|
518
518
|
}
|
|
519
519
|
});
|
|
520
|
+
instance.definition().functions.forEach((cb) => {
|
|
521
|
+
let functionName = cb.replace(/-/g, "_");
|
|
522
|
+
if (componentHandle[functionName] !== undefined) {
|
|
523
|
+
console.warn("Duplicated function name " + functionName);
|
|
524
|
+
}
|
|
525
|
+
else {
|
|
526
|
+
Object.defineProperty(componentHandle, cb.replace(/-/g, "_"), {
|
|
527
|
+
get() {
|
|
528
|
+
return function () {
|
|
529
|
+
return instance.invoke(cb, Array.from(arguments));
|
|
530
|
+
};
|
|
531
|
+
},
|
|
532
|
+
enumerable: true,
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
});
|
|
520
536
|
// globals
|
|
521
537
|
instance.definition().globals.forEach((globalName) => {
|
|
522
538
|
if (componentHandle[globalName] !== undefined) {
|
|
@@ -560,6 +576,22 @@ function loadSlint(loadData) {
|
|
|
560
576
|
});
|
|
561
577
|
}
|
|
562
578
|
});
|
|
579
|
+
instance.definition().globalFunctions(globalName).forEach((cb) => {
|
|
580
|
+
let functionName = cb.replace(/-/g, "_");
|
|
581
|
+
if (globalObject[functionName] !== undefined) {
|
|
582
|
+
console.warn("Duplicated function name " + cb + " on global " + global);
|
|
583
|
+
}
|
|
584
|
+
else {
|
|
585
|
+
Object.defineProperty(globalObject, cb.replace(/-/g, "_"), {
|
|
586
|
+
get() {
|
|
587
|
+
return function () {
|
|
588
|
+
return instance.invokeGlobal(globalName, cb, Array.from(arguments));
|
|
589
|
+
};
|
|
590
|
+
},
|
|
591
|
+
enumerable: true,
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
});
|
|
563
595
|
Object.defineProperty(componentHandle, globalName, {
|
|
564
596
|
get() {
|
|
565
597
|
return globalObject;
|
package/index.ts
CHANGED
|
@@ -350,7 +350,7 @@ export class ArrayModel<T> extends Model<T> {
|
|
|
350
350
|
|
|
351
351
|
/**
|
|
352
352
|
* Removes the last element from the array and returns it.
|
|
353
|
-
*
|
|
353
|
+
*
|
|
354
354
|
* @returns The removed element or undefined if the array is empty.
|
|
355
355
|
*/
|
|
356
356
|
pop(): T | undefined {
|
|
@@ -780,6 +780,23 @@ function loadSlint(loadData: LoadData): Object {
|
|
|
780
780
|
}
|
|
781
781
|
});
|
|
782
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
|
+
|
|
783
800
|
// globals
|
|
784
801
|
instance!.definition().globals.forEach((globalName) => {
|
|
785
802
|
if (componentHandle[globalName] !== undefined) {
|
|
@@ -825,6 +842,23 @@ function loadSlint(loadData: LoadData): Object {
|
|
|
825
842
|
}
|
|
826
843
|
});
|
|
827
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
|
+
|
|
828
862
|
Object.defineProperty(componentHandle, globalName, {
|
|
829
863
|
get() {
|
|
830
864
|
return globalObject;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "slint-ui",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0-nightly.2024060413",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"homepage": "https://github.com/slint-ui/slint",
|
|
@@ -59,10 +59,10 @@
|
|
|
59
59
|
"@napi-rs/cli": "^2.16.5"
|
|
60
60
|
},
|
|
61
61
|
"optionalDependencies": {
|
|
62
|
-
"@slint-ui/slint-ui-binary-linux-x64-gnu": "1.
|
|
63
|
-
"@slint-ui/slint-ui-binary-darwin-x64": "1.
|
|
64
|
-
"@slint-ui/slint-ui-binary-darwin-arm64": "1.
|
|
65
|
-
"@slint-ui/slint-ui-binary-win32-x64-msvc": "1.
|
|
66
|
-
"@slint-ui/slint-ui-binary-win32-ia32-msvc": "1.
|
|
62
|
+
"@slint-ui/slint-ui-binary-linux-x64-gnu": "1.7.0-nightly.2024060413",
|
|
63
|
+
"@slint-ui/slint-ui-binary-darwin-x64": "1.7.0-nightly.2024060413",
|
|
64
|
+
"@slint-ui/slint-ui-binary-darwin-arm64": "1.7.0-nightly.2024060413",
|
|
65
|
+
"@slint-ui/slint-ui-binary-win32-x64-msvc": "1.7.0-nightly.2024060413",
|
|
66
|
+
"@slint-ui/slint-ui-binary-win32-ia32-msvc": "1.7.0-nightly.2024060413"
|
|
67
67
|
}
|
|
68
68
|
}
|
package/rust-module.d.ts
CHANGED
|
@@ -112,9 +112,11 @@ export class ComponentDefinition {
|
|
|
112
112
|
constructor()
|
|
113
113
|
get properties(): Array<JsProperty>
|
|
114
114
|
get callbacks(): Array<string>
|
|
115
|
+
get functions(): Array<string>
|
|
115
116
|
get globals(): Array<string>
|
|
116
117
|
globalProperties(globalName: string): Array<JsProperty> | null
|
|
117
118
|
globalCallbacks(globalName: string): Array<string> | null
|
|
119
|
+
globalFunctions(globalName: string): Array<string> | null
|
|
118
120
|
create(): JsComponentInstance
|
|
119
121
|
get name(): string
|
|
120
122
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
|
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
|
+
use i_slint_compiler::langtype::Type;
|
|
4
5
|
use napi::Result;
|
|
5
6
|
use slint_interpreter::ComponentDefinition;
|
|
6
7
|
|
|
@@ -39,6 +40,15 @@ impl JsComponentDefinition {
|
|
|
39
40
|
self.internal.callbacks().collect()
|
|
40
41
|
}
|
|
41
42
|
|
|
43
|
+
#[napi(getter)]
|
|
44
|
+
pub fn functions(&self) -> Vec<String> {
|
|
45
|
+
self.internal
|
|
46
|
+
.properties_and_callbacks()
|
|
47
|
+
.filter(|(_, ty)| matches!(ty, Type::Function { .. }))
|
|
48
|
+
.map(|(s, _)| s)
|
|
49
|
+
.collect()
|
|
50
|
+
}
|
|
51
|
+
|
|
42
52
|
#[napi(getter)]
|
|
43
53
|
pub fn globals(&self) -> Vec<String> {
|
|
44
54
|
self.internal.globals().collect()
|
|
@@ -57,6 +67,13 @@ impl JsComponentDefinition {
|
|
|
57
67
|
self.internal.global_callbacks(global_name.as_str()).map(|iter| iter.collect())
|
|
58
68
|
}
|
|
59
69
|
|
|
70
|
+
#[napi]
|
|
71
|
+
pub fn global_functions(&self, global_name: String) -> Option<Vec<String>> {
|
|
72
|
+
self.internal.global_properties_and_callbacks(global_name.as_str()).map(|iter| {
|
|
73
|
+
iter.filter(|(_, ty)| matches!(ty, Type::Function { .. })).map(|(s, _)| s).collect()
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
|
|
60
77
|
#[napi]
|
|
61
78
|
pub fn create(&self) -> Result<JsComponentInstance> {
|
|
62
79
|
Ok(self.internal.create().map_err(|e| napi::Error::from_reason(e.to_string()))?.into())
|
|
@@ -239,29 +239,32 @@ impl JsComponentInstance {
|
|
|
239
239
|
)
|
|
240
240
|
})?;
|
|
241
241
|
|
|
242
|
-
let args =
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
242
|
+
let args = match ty {
|
|
243
|
+
Type::Callback { args, .. } | Type::Function { args, .. } => {
|
|
244
|
+
let count = args.len();
|
|
245
|
+
let args = arguments
|
|
246
|
+
.into_iter()
|
|
247
|
+
.zip(args.into_iter())
|
|
248
|
+
.map(|(a, ty)| super::value::to_value(&env, a, &ty))
|
|
249
|
+
.collect::<Result<Vec<_>, _>>()?;
|
|
250
|
+
if args.len() != count {
|
|
251
|
+
return Err(napi::Error::from_reason(
|
|
252
|
+
format!(
|
|
253
|
+
"{} expect {} arguments, but {} where provided",
|
|
254
|
+
callback_name,
|
|
255
|
+
count,
|
|
256
|
+
args.len()
|
|
257
|
+
)
|
|
258
|
+
.as_str(),
|
|
259
|
+
));
|
|
260
|
+
}
|
|
261
|
+
args
|
|
262
|
+
}
|
|
263
|
+
_ => {
|
|
250
264
|
return Err(napi::Error::from_reason(
|
|
251
|
-
format!(
|
|
252
|
-
"{} expect {} arguments, but {} where provided",
|
|
253
|
-
callback_name,
|
|
254
|
-
count,
|
|
255
|
-
args.len()
|
|
256
|
-
)
|
|
257
|
-
.as_str(),
|
|
265
|
+
format!("{} is not a callback or a function", callback_name).as_str(),
|
|
258
266
|
));
|
|
259
267
|
}
|
|
260
|
-
args
|
|
261
|
-
} else {
|
|
262
|
-
return Err(napi::Error::from_reason(
|
|
263
|
-
format!("{} is not a callback", callback_name).as_str(),
|
|
264
|
-
));
|
|
265
268
|
};
|
|
266
269
|
|
|
267
270
|
let result = self
|
|
@@ -296,29 +299,36 @@ impl JsComponentInstance {
|
|
|
296
299
|
)
|
|
297
300
|
})?;
|
|
298
301
|
|
|
299
|
-
let args =
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
302
|
+
let args = match ty {
|
|
303
|
+
Type::Callback { args, .. } | Type::Function { args, .. } => {
|
|
304
|
+
let count = args.len();
|
|
305
|
+
let args = arguments
|
|
306
|
+
.into_iter()
|
|
307
|
+
.zip(args.into_iter())
|
|
308
|
+
.map(|(a, ty)| super::value::to_value(&env, a, &ty))
|
|
309
|
+
.collect::<Result<Vec<_>, _>>()?;
|
|
310
|
+
if args.len() != count {
|
|
311
|
+
return Err(napi::Error::from_reason(
|
|
312
|
+
format!(
|
|
313
|
+
"{} expect {} arguments, but {} where provided",
|
|
314
|
+
callback_name,
|
|
315
|
+
count,
|
|
316
|
+
args.len()
|
|
317
|
+
)
|
|
318
|
+
.as_str(),
|
|
319
|
+
));
|
|
320
|
+
}
|
|
321
|
+
args
|
|
322
|
+
}
|
|
323
|
+
_ => {
|
|
307
324
|
return Err(napi::Error::from_reason(
|
|
308
325
|
format!(
|
|
309
|
-
"{}
|
|
310
|
-
callback_name,
|
|
311
|
-
count,
|
|
312
|
-
args.len()
|
|
326
|
+
"{} is not a callback or a function on global {}",
|
|
327
|
+
callback_name, global_name
|
|
313
328
|
)
|
|
314
329
|
.as_str(),
|
|
315
330
|
));
|
|
316
331
|
}
|
|
317
|
-
args
|
|
318
|
-
} else {
|
|
319
|
-
return Err(napi::Error::from_reason(
|
|
320
|
-
format!("{} is not a callback on global {}", callback_name, global_name).as_str(),
|
|
321
|
-
));
|
|
322
332
|
};
|
|
323
333
|
|
|
324
334
|
let result = self
|