slint-ui 1.9.0-nightly.2024100903 → 1.9.0-nightly.2024101004
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 +69 -0
- package/dist/index.js +46 -13
- package/package.json +6 -6
- package/rust/interpreter/component_compiler.rs +70 -1
- package/rust-module.d.ts +2 -0
- package/typescript/index.ts +242 -219
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"] , 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 = "499a522f993e107a1c1195b1119aa04d2fb17a6c", version = "=1.9.0", default-features = false }
|
|
45
|
+
i-slint-core = { features = ["default"] , git = "https://github.com/slint-ui/slint", rev = "499a522f993e107a1c1195b1119aa04d2fb17a6c", version = "=1.9.0", default-features = false }
|
|
46
|
+
i-slint-backend-selector = { git = "https://github.com/slint-ui/slint", rev = "499a522f993e107a1c1195b1119aa04d2fb17a6c", 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 = "499a522f993e107a1c1195b1119aa04d2fb17a6c", 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/README.md
CHANGED
|
@@ -273,3 +273,72 @@ model.push(4); // this works
|
|
|
273
273
|
// does NOT work, getting the model does not return the right object
|
|
274
274
|
// component.model.push(5);
|
|
275
275
|
```
|
|
276
|
+
|
|
277
|
+
### structs
|
|
278
|
+
|
|
279
|
+
An exported struct can be created either by defing of an object literal or by using the new keyword.
|
|
280
|
+
|
|
281
|
+
**`my-component.slint`**
|
|
282
|
+
|
|
283
|
+
```slint
|
|
284
|
+
export struct Person {
|
|
285
|
+
name: string,
|
|
286
|
+
age: int
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export component MyComponent inherits Window {
|
|
290
|
+
in-out property <Person> person;
|
|
291
|
+
}
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
**`main.js`**
|
|
295
|
+
|
|
296
|
+
```js
|
|
297
|
+
|
|
298
|
+
import * as slint from "slint-ui";
|
|
299
|
+
|
|
300
|
+
let ui = slint.loadFile("my-component.slint");
|
|
301
|
+
let component = new ui.MyComponent();
|
|
302
|
+
|
|
303
|
+
// object literal
|
|
304
|
+
component.person = { name: "Peter", age: 22 };
|
|
305
|
+
|
|
306
|
+
// new keyword (sets property values to default e.g. '' for string)
|
|
307
|
+
component.person = new ui.Person();
|
|
308
|
+
|
|
309
|
+
// new keyword with parameters
|
|
310
|
+
component.person = new ui.Person({ name: "Tim", age: 30 });
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
### enums
|
|
314
|
+
|
|
315
|
+
A value of an exported enum can be set as string or by usign the value from the exported enum.
|
|
316
|
+
|
|
317
|
+
**`my-component.slint`**
|
|
318
|
+
|
|
319
|
+
```slint
|
|
320
|
+
export enum Position {
|
|
321
|
+
top,
|
|
322
|
+
bottom
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
export component MyComponent inherits Window {
|
|
326
|
+
in-out property <Position> position;
|
|
327
|
+
}
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
**`main.js`**
|
|
331
|
+
|
|
332
|
+
```js
|
|
333
|
+
|
|
334
|
+
import * as slint from "slint-ui";
|
|
335
|
+
|
|
336
|
+
let ui = slint.loadFile("my-component.slint");
|
|
337
|
+
let component = new ui.MyComponent();
|
|
338
|
+
|
|
339
|
+
// set enum value as string
|
|
340
|
+
component.position = "top";
|
|
341
|
+
|
|
342
|
+
// use the value of the enum
|
|
343
|
+
component.position = ui.Position.bottom;
|
|
344
|
+
```
|
package/dist/index.js
CHANGED
|
@@ -72,6 +72,9 @@ class CompileError extends Error {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
exports.CompileError = CompileError;
|
|
75
|
+
function translateName(key) {
|
|
76
|
+
return key.replace(/-/g, "_");
|
|
77
|
+
}
|
|
75
78
|
function loadSlint(loadData) {
|
|
76
79
|
const { filePath, options } = loadData.fileData;
|
|
77
80
|
const compiler = new napi.ComponentCompiler();
|
|
@@ -101,14 +104,44 @@ function loadSlint(loadData) {
|
|
|
101
104
|
}
|
|
102
105
|
}
|
|
103
106
|
const slint_module = Object.create({});
|
|
107
|
+
// generate structs
|
|
108
|
+
const structs = compiler.structs;
|
|
109
|
+
for (const key in compiler.structs) {
|
|
110
|
+
Object.defineProperty(slint_module, translateName(key), {
|
|
111
|
+
value: function (properties) {
|
|
112
|
+
const defaultObject = structs[key];
|
|
113
|
+
const newObject = Object.create({});
|
|
114
|
+
for (const propertyKey in defaultObject) {
|
|
115
|
+
const propertyName = translateName(propertyKey);
|
|
116
|
+
const propertyValue = properties !== undefined &&
|
|
117
|
+
Object.hasOwn(properties, propertyName)
|
|
118
|
+
? properties[propertyName]
|
|
119
|
+
: defaultObject[propertyKey];
|
|
120
|
+
Object.defineProperty(newObject, propertyName, {
|
|
121
|
+
value: propertyValue,
|
|
122
|
+
writable: true,
|
|
123
|
+
enumerable: true,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
return Object.seal(newObject);
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
// generate enums
|
|
131
|
+
const enums = compiler.enums;
|
|
132
|
+
for (const key in enums) {
|
|
133
|
+
Object.defineProperty(slint_module, translateName(key), {
|
|
134
|
+
value: Object.seal(enums[key]),
|
|
135
|
+
enumerable: true,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
104
138
|
Object.keys(definitions).forEach((key) => {
|
|
105
139
|
const definition = definitions[key];
|
|
106
|
-
Object.defineProperty(slint_module, definition.name
|
|
140
|
+
Object.defineProperty(slint_module, translateName(definition.name), {
|
|
107
141
|
value: function (properties) {
|
|
108
142
|
const instance = definition.create();
|
|
109
143
|
if (instance == null) {
|
|
110
|
-
throw Error("Could not create a component handle for" +
|
|
111
|
-
filePath);
|
|
144
|
+
throw Error("Could not create a component handle for" + filePath);
|
|
112
145
|
}
|
|
113
146
|
for (var key in properties) {
|
|
114
147
|
const value = properties[key];
|
|
@@ -121,7 +154,7 @@ function loadSlint(loadData) {
|
|
|
121
154
|
}
|
|
122
155
|
const componentHandle = new Component(instance);
|
|
123
156
|
instance.definition().properties.forEach((prop) => {
|
|
124
|
-
const propName = prop.name
|
|
157
|
+
const propName = translateName(prop.name);
|
|
125
158
|
if (componentHandle[propName] !== undefined) {
|
|
126
159
|
console.warn("Duplicated property name " + propName);
|
|
127
160
|
}
|
|
@@ -138,12 +171,12 @@ function loadSlint(loadData) {
|
|
|
138
171
|
}
|
|
139
172
|
});
|
|
140
173
|
instance.definition().callbacks.forEach((cb) => {
|
|
141
|
-
const callbackName = cb
|
|
174
|
+
const callbackName = translateName(cb);
|
|
142
175
|
if (componentHandle[callbackName] !== undefined) {
|
|
143
176
|
console.warn("Duplicated callback name " + callbackName);
|
|
144
177
|
}
|
|
145
178
|
else {
|
|
146
|
-
Object.defineProperty(componentHandle, cb
|
|
179
|
+
Object.defineProperty(componentHandle, translateName(cb), {
|
|
147
180
|
get() {
|
|
148
181
|
return function () {
|
|
149
182
|
return instance.invoke(cb, Array.from(arguments));
|
|
@@ -157,12 +190,12 @@ function loadSlint(loadData) {
|
|
|
157
190
|
}
|
|
158
191
|
});
|
|
159
192
|
instance.definition().functions.forEach((cb) => {
|
|
160
|
-
const functionName = cb
|
|
193
|
+
const functionName = translateName(cb);
|
|
161
194
|
if (componentHandle[functionName] !== undefined) {
|
|
162
195
|
console.warn("Duplicated function name " + functionName);
|
|
163
196
|
}
|
|
164
197
|
else {
|
|
165
|
-
Object.defineProperty(componentHandle, cb
|
|
198
|
+
Object.defineProperty(componentHandle, translateName(cb), {
|
|
166
199
|
get() {
|
|
167
200
|
return function () {
|
|
168
201
|
return instance.invoke(cb, Array.from(arguments));
|
|
@@ -183,7 +216,7 @@ function loadSlint(loadData) {
|
|
|
183
216
|
.definition()
|
|
184
217
|
.globalProperties(globalName)
|
|
185
218
|
.forEach((prop) => {
|
|
186
|
-
const propName = prop.name
|
|
219
|
+
const propName = translateName(prop.name);
|
|
187
220
|
if (globalObject[propName] !== undefined) {
|
|
188
221
|
console.warn("Duplicated property name " +
|
|
189
222
|
propName +
|
|
@@ -206,7 +239,7 @@ function loadSlint(loadData) {
|
|
|
206
239
|
.definition()
|
|
207
240
|
.globalCallbacks(globalName)
|
|
208
241
|
.forEach((cb) => {
|
|
209
|
-
const callbackName = cb
|
|
242
|
+
const callbackName = translateName(cb);
|
|
210
243
|
if (globalObject[callbackName] !== undefined) {
|
|
211
244
|
console.warn("Duplicated property name " +
|
|
212
245
|
cb +
|
|
@@ -214,7 +247,7 @@ function loadSlint(loadData) {
|
|
|
214
247
|
global);
|
|
215
248
|
}
|
|
216
249
|
else {
|
|
217
|
-
Object.defineProperty(globalObject, cb
|
|
250
|
+
Object.defineProperty(globalObject, translateName(cb), {
|
|
218
251
|
get() {
|
|
219
252
|
return function () {
|
|
220
253
|
return instance.invokeGlobal(globalName, cb, Array.from(arguments));
|
|
@@ -231,7 +264,7 @@ function loadSlint(loadData) {
|
|
|
231
264
|
.definition()
|
|
232
265
|
.globalFunctions(globalName)
|
|
233
266
|
.forEach((cb) => {
|
|
234
|
-
const functionName = cb
|
|
267
|
+
const functionName = translateName(cb);
|
|
235
268
|
if (globalObject[functionName] !== undefined) {
|
|
236
269
|
console.warn("Duplicated function name " +
|
|
237
270
|
cb +
|
|
@@ -239,7 +272,7 @@ function loadSlint(loadData) {
|
|
|
239
272
|
global);
|
|
240
273
|
}
|
|
241
274
|
else {
|
|
242
|
-
Object.defineProperty(globalObject, cb
|
|
275
|
+
Object.defineProperty(globalObject, translateName(cb), {
|
|
243
276
|
get() {
|
|
244
277
|
return function () {
|
|
245
278
|
return instance.invokeGlobal(globalName, cb, Array.from(arguments));
|
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.2024101004",
|
|
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.2024101004",
|
|
71
|
+
"@slint-ui/slint-ui-binary-darwin-x64": "1.9.0-nightly.2024101004",
|
|
72
|
+
"@slint-ui/slint-ui-binary-darwin-arm64": "1.9.0-nightly.2024101004",
|
|
73
|
+
"@slint-ui/slint-ui-binary-win32-x64-msvc": "1.9.0-nightly.2024101004",
|
|
74
|
+
"@slint-ui/slint-ui-binary-win32-ia32-msvc": "1.9.0-nightly.2024101004"
|
|
75
75
|
}
|
|
76
76
|
}
|
|
@@ -1,10 +1,16 @@
|
|
|
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 crate::to_js_unknown;
|
|
5
|
+
|
|
4
6
|
use super::JsComponentDefinition;
|
|
5
7
|
use super::JsDiagnostic;
|
|
8
|
+
use i_slint_compiler::langtype::Type;
|
|
6
9
|
use itertools::Itertools;
|
|
10
|
+
use napi::Env;
|
|
11
|
+
use napi::JsUnknown;
|
|
7
12
|
use slint_interpreter::Compiler;
|
|
13
|
+
use slint_interpreter::Value;
|
|
8
14
|
use std::collections::HashMap;
|
|
9
15
|
use std::path::PathBuf;
|
|
10
16
|
|
|
@@ -13,6 +19,7 @@ use std::path::PathBuf;
|
|
|
13
19
|
#[napi(js_name = "ComponentCompiler")]
|
|
14
20
|
pub struct JsComponentCompiler {
|
|
15
21
|
internal: Compiler,
|
|
22
|
+
structs_and_enums: Vec<Type>,
|
|
16
23
|
diagnostics: Vec<slint_interpreter::Diagnostic>,
|
|
17
24
|
}
|
|
18
25
|
|
|
@@ -44,7 +51,7 @@ impl JsComponentCompiler {
|
|
|
44
51
|
|
|
45
52
|
compiler.set_include_paths(include_paths);
|
|
46
53
|
compiler.set_library_paths(library_paths);
|
|
47
|
-
Self { internal: compiler, diagnostics: vec![] }
|
|
54
|
+
Self { internal: compiler, diagnostics: vec![], structs_and_enums: vec![] }
|
|
48
55
|
}
|
|
49
56
|
|
|
50
57
|
#[napi(setter)]
|
|
@@ -99,12 +106,72 @@ impl JsComponentCompiler {
|
|
|
99
106
|
self.diagnostics.iter().map(|d| JsDiagnostic::from(d.clone())).collect()
|
|
100
107
|
}
|
|
101
108
|
|
|
109
|
+
#[napi(getter)]
|
|
110
|
+
pub fn structs(&self, env: Env) -> HashMap<String, JsUnknown> {
|
|
111
|
+
fn convert_type(env: &Env, ty: &Type) -> Option<(String, JsUnknown)> {
|
|
112
|
+
match ty {
|
|
113
|
+
Type::Struct { fields, name: Some(name), node: Some(_), .. } => {
|
|
114
|
+
let struct_instance = to_js_unknown(
|
|
115
|
+
env,
|
|
116
|
+
&Value::Struct(slint_interpreter::Struct::from_iter(fields.iter().map(
|
|
117
|
+
|(name, field_type)| {
|
|
118
|
+
(
|
|
119
|
+
name.to_string(),
|
|
120
|
+
slint_interpreter::default_value_for_type(field_type),
|
|
121
|
+
)
|
|
122
|
+
},
|
|
123
|
+
))),
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
return Some((name.to_string(), struct_instance.ok()?));
|
|
127
|
+
}
|
|
128
|
+
_ => return None,
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
self.structs_and_enums
|
|
133
|
+
.iter()
|
|
134
|
+
.filter_map(|ty| convert_type(&env, ty))
|
|
135
|
+
.into_iter()
|
|
136
|
+
.collect::<HashMap<String, JsUnknown>>()
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
#[napi(getter)]
|
|
140
|
+
pub fn enums(&self, env: Env) -> HashMap<String, JsUnknown> {
|
|
141
|
+
fn convert_type(env: &Env, ty: &Type) -> Option<(String, JsUnknown)> {
|
|
142
|
+
match ty {
|
|
143
|
+
Type::Enumeration(en) => {
|
|
144
|
+
let mut o = env.create_object().ok()?;
|
|
145
|
+
|
|
146
|
+
for value in en.values.iter() {
|
|
147
|
+
let value = value.replace('-', "_");
|
|
148
|
+
o.set_property(
|
|
149
|
+
env.create_string(&value).ok()?,
|
|
150
|
+
env.create_string(&value).ok()?.into_unknown(),
|
|
151
|
+
)
|
|
152
|
+
.ok()?;
|
|
153
|
+
}
|
|
154
|
+
return Some((en.name.clone(), o.into_unknown()));
|
|
155
|
+
}
|
|
156
|
+
_ => return None,
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
self.structs_and_enums
|
|
161
|
+
.iter()
|
|
162
|
+
.filter_map(|ty| convert_type(&env, ty))
|
|
163
|
+
.into_iter()
|
|
164
|
+
.collect::<HashMap<String, JsUnknown>>()
|
|
165
|
+
}
|
|
166
|
+
|
|
102
167
|
/// Compile a .slint file into a ComponentDefinition
|
|
103
168
|
///
|
|
104
169
|
/// Returns the compiled `ComponentDefinition` if there were no errors.
|
|
105
170
|
#[napi]
|
|
106
171
|
pub fn build_from_path(&mut self, path: String) -> HashMap<String, JsComponentDefinition> {
|
|
107
172
|
let r = spin_on::spin_on(self.internal.build_from_path(PathBuf::from(path)));
|
|
173
|
+
self.structs_and_enums =
|
|
174
|
+
r.structs_and_enums(i_slint_core::InternalToken {}).cloned().collect::<Vec<_>>();
|
|
108
175
|
self.diagnostics = r.diagnostics().collect();
|
|
109
176
|
r.components().map(|c| (c.name().to_owned(), c.into())).collect()
|
|
110
177
|
}
|
|
@@ -118,6 +185,8 @@ impl JsComponentCompiler {
|
|
|
118
185
|
) -> HashMap<String, JsComponentDefinition> {
|
|
119
186
|
let r = spin_on::spin_on(self.internal.build_from_source(source_code, PathBuf::from(path)));
|
|
120
187
|
self.diagnostics = r.diagnostics().collect();
|
|
188
|
+
self.structs_and_enums =
|
|
189
|
+
r.structs_and_enums(i_slint_core::InternalToken {}).cloned().collect::<Vec<_>>();
|
|
121
190
|
r.components().map(|c| (c.name().to_owned(), c.into())).collect()
|
|
122
191
|
}
|
|
123
192
|
}
|
package/rust-module.d.ts
CHANGED
|
@@ -98,6 +98,8 @@ export class ComponentCompiler {
|
|
|
98
98
|
set style(style: string)
|
|
99
99
|
get style(): string | null
|
|
100
100
|
get diagnostics(): Array<Diagnostic>
|
|
101
|
+
get structs(): Record<string, unknown>
|
|
102
|
+
get enums(): Record<string, unknown>
|
|
101
103
|
/**
|
|
102
104
|
* Compile a .slint file into a ComponentDefinition
|
|
103
105
|
*
|
package/typescript/index.ts
CHANGED
|
@@ -266,6 +266,10 @@ type LoadData =
|
|
|
266
266
|
from: "source";
|
|
267
267
|
};
|
|
268
268
|
|
|
269
|
+
function translateName(key: string): string {
|
|
270
|
+
return key.replace(/-/g, "_");
|
|
271
|
+
}
|
|
272
|
+
|
|
269
273
|
function loadSlint(loadData: LoadData): Object {
|
|
270
274
|
const { filePath, options } = loadData.fileData;
|
|
271
275
|
|
|
@@ -309,252 +313,271 @@ function loadSlint(loadData: LoadData): Object {
|
|
|
309
313
|
|
|
310
314
|
const slint_module = Object.create({});
|
|
311
315
|
|
|
316
|
+
// generate structs
|
|
317
|
+
const structs = compiler.structs;
|
|
318
|
+
|
|
319
|
+
for (const key in compiler.structs) {
|
|
320
|
+
Object.defineProperty(slint_module, translateName(key), {
|
|
321
|
+
value: function (properties: any) {
|
|
322
|
+
const defaultObject = structs[key];
|
|
323
|
+
const newObject = Object.create({});
|
|
324
|
+
|
|
325
|
+
for (const propertyKey in defaultObject) {
|
|
326
|
+
const propertyName = translateName(propertyKey);
|
|
327
|
+
const propertyValue =
|
|
328
|
+
properties !== undefined &&
|
|
329
|
+
Object.hasOwn(properties, propertyName)
|
|
330
|
+
? properties[propertyName]
|
|
331
|
+
: defaultObject[propertyKey];
|
|
332
|
+
|
|
333
|
+
Object.defineProperty(newObject, propertyName, {
|
|
334
|
+
value: propertyValue,
|
|
335
|
+
writable: true,
|
|
336
|
+
enumerable: true,
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
return Object.seal(newObject);
|
|
341
|
+
},
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// generate enums
|
|
346
|
+
const enums = compiler.enums;
|
|
347
|
+
|
|
348
|
+
for (const key in enums) {
|
|
349
|
+
Object.defineProperty(slint_module, translateName(key), {
|
|
350
|
+
value: Object.seal(enums[key]),
|
|
351
|
+
enumerable: true,
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
|
|
312
355
|
Object.keys(definitions).forEach((key) => {
|
|
313
356
|
const definition = definitions[key];
|
|
314
357
|
|
|
315
|
-
Object.defineProperty(
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
{
|
|
319
|
-
value: function (properties: any) {
|
|
320
|
-
const instance = definition.create();
|
|
321
|
-
|
|
322
|
-
if (instance == null) {
|
|
323
|
-
throw Error(
|
|
324
|
-
"Could not create a component handle for" +
|
|
325
|
-
filePath,
|
|
326
|
-
);
|
|
327
|
-
}
|
|
358
|
+
Object.defineProperty(slint_module, translateName(definition.name), {
|
|
359
|
+
value: function (properties: any) {
|
|
360
|
+
const instance = definition.create();
|
|
328
361
|
|
|
329
|
-
|
|
330
|
-
|
|
362
|
+
if (instance == null) {
|
|
363
|
+
throw Error(
|
|
364
|
+
"Could not create a component handle for" + filePath,
|
|
365
|
+
);
|
|
366
|
+
}
|
|
331
367
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
368
|
+
for (var key in properties) {
|
|
369
|
+
const value = properties[key];
|
|
370
|
+
|
|
371
|
+
if (value instanceof Function) {
|
|
372
|
+
instance.setCallback(key, value);
|
|
373
|
+
} else {
|
|
374
|
+
instance.setProperty(key, properties[key]);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
const componentHandle = new Component(instance!);
|
|
379
|
+
instance!.definition().properties.forEach((prop) => {
|
|
380
|
+
const propName = translateName(prop.name);
|
|
381
|
+
|
|
382
|
+
if (componentHandle[propName] !== undefined) {
|
|
383
|
+
console.warn("Duplicated property name " + propName);
|
|
384
|
+
} else {
|
|
385
|
+
Object.defineProperty(componentHandle, propName, {
|
|
386
|
+
get() {
|
|
387
|
+
return instance!.getProperty(prop.name);
|
|
388
|
+
},
|
|
389
|
+
set(value) {
|
|
390
|
+
instance!.setProperty(prop.name, value);
|
|
391
|
+
},
|
|
392
|
+
enumerable: true,
|
|
393
|
+
});
|
|
337
394
|
}
|
|
395
|
+
});
|
|
338
396
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
const propName = prop.name.replace(/-/g, "_");
|
|
397
|
+
instance!.definition().callbacks.forEach((cb) => {
|
|
398
|
+
const callbackName = translateName(cb);
|
|
342
399
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
400
|
+
if (componentHandle[callbackName] !== undefined) {
|
|
401
|
+
console.warn(
|
|
402
|
+
"Duplicated callback name " + callbackName,
|
|
403
|
+
);
|
|
404
|
+
} else {
|
|
405
|
+
Object.defineProperty(
|
|
406
|
+
componentHandle,
|
|
407
|
+
translateName(cb),
|
|
408
|
+
{
|
|
349
409
|
get() {
|
|
350
|
-
return
|
|
410
|
+
return function () {
|
|
411
|
+
return instance!.invoke(
|
|
412
|
+
cb,
|
|
413
|
+
Array.from(arguments),
|
|
414
|
+
);
|
|
415
|
+
};
|
|
351
416
|
},
|
|
352
|
-
set(
|
|
353
|
-
instance!.
|
|
417
|
+
set(callback) {
|
|
418
|
+
instance!.setCallback(cb, callback);
|
|
354
419
|
},
|
|
355
420
|
enumerable: true,
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
}
|
|
421
|
+
},
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
});
|
|
359
425
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
if (componentHandle[callbackName] !== undefined) {
|
|
364
|
-
console.warn(
|
|
365
|
-
"Duplicated callback name " + callbackName,
|
|
366
|
-
);
|
|
367
|
-
} else {
|
|
368
|
-
Object.defineProperty(
|
|
369
|
-
componentHandle,
|
|
370
|
-
cb.replace(/-/g, "_"),
|
|
371
|
-
{
|
|
372
|
-
get() {
|
|
373
|
-
return function () {
|
|
374
|
-
return instance!.invoke(
|
|
375
|
-
cb,
|
|
376
|
-
Array.from(arguments),
|
|
377
|
-
);
|
|
378
|
-
};
|
|
379
|
-
},
|
|
380
|
-
set(callback) {
|
|
381
|
-
instance!.setCallback(cb, callback);
|
|
382
|
-
},
|
|
383
|
-
enumerable: true,
|
|
384
|
-
},
|
|
385
|
-
);
|
|
386
|
-
}
|
|
387
|
-
});
|
|
426
|
+
instance!.definition().functions.forEach((cb) => {
|
|
427
|
+
const functionName = translateName(cb);
|
|
388
428
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
Array.from(arguments),
|
|
406
|
-
);
|
|
407
|
-
};
|
|
408
|
-
},
|
|
409
|
-
enumerable: true,
|
|
429
|
+
if (componentHandle[functionName] !== undefined) {
|
|
430
|
+
console.warn(
|
|
431
|
+
"Duplicated function name " + functionName,
|
|
432
|
+
);
|
|
433
|
+
} else {
|
|
434
|
+
Object.defineProperty(
|
|
435
|
+
componentHandle,
|
|
436
|
+
translateName(cb),
|
|
437
|
+
{
|
|
438
|
+
get() {
|
|
439
|
+
return function () {
|
|
440
|
+
return instance!.invoke(
|
|
441
|
+
cb,
|
|
442
|
+
Array.from(arguments),
|
|
443
|
+
);
|
|
444
|
+
};
|
|
410
445
|
},
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
446
|
+
enumerable: true,
|
|
447
|
+
},
|
|
448
|
+
);
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
// globals
|
|
453
|
+
instance!.definition().globals.forEach((globalName) => {
|
|
454
|
+
if (componentHandle[globalName] !== undefined) {
|
|
455
|
+
console.warn("Duplicated property name " + globalName);
|
|
456
|
+
} else {
|
|
457
|
+
const globalObject = Object.create({});
|
|
458
|
+
|
|
459
|
+
instance!
|
|
460
|
+
.definition()
|
|
461
|
+
.globalProperties(globalName)
|
|
462
|
+
.forEach((prop) => {
|
|
463
|
+
const propName = translateName(prop.name);
|
|
464
|
+
|
|
465
|
+
if (globalObject[propName] !== undefined) {
|
|
466
|
+
console.warn(
|
|
467
|
+
"Duplicated property name " +
|
|
468
|
+
propName +
|
|
469
|
+
" on global " +
|
|
470
|
+
global,
|
|
471
|
+
);
|
|
472
|
+
} else {
|
|
473
|
+
Object.defineProperty(
|
|
474
|
+
globalObject,
|
|
475
|
+
propName,
|
|
476
|
+
{
|
|
477
|
+
get() {
|
|
478
|
+
return instance!.getGlobalProperty(
|
|
479
|
+
globalName,
|
|
480
|
+
prop.name,
|
|
481
|
+
);
|
|
482
|
+
},
|
|
483
|
+
set(value) {
|
|
484
|
+
instance!.setGlobalProperty(
|
|
485
|
+
globalName,
|
|
486
|
+
prop.name,
|
|
487
|
+
value,
|
|
488
|
+
);
|
|
489
|
+
},
|
|
490
|
+
enumerable: true,
|
|
491
|
+
},
|
|
431
492
|
);
|
|
493
|
+
}
|
|
494
|
+
});
|
|
432
495
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
496
|
+
instance!
|
|
497
|
+
.definition()
|
|
498
|
+
.globalCallbacks(globalName)
|
|
499
|
+
.forEach((cb) => {
|
|
500
|
+
const callbackName = translateName(cb);
|
|
501
|
+
|
|
502
|
+
if (globalObject[callbackName] !== undefined) {
|
|
503
|
+
console.warn(
|
|
504
|
+
"Duplicated property name " +
|
|
505
|
+
cb +
|
|
506
|
+
" on global " +
|
|
507
|
+
global,
|
|
508
|
+
);
|
|
509
|
+
} else {
|
|
510
|
+
Object.defineProperty(
|
|
511
|
+
globalObject,
|
|
512
|
+
translateName(cb),
|
|
513
|
+
{
|
|
514
|
+
get() {
|
|
515
|
+
return function () {
|
|
516
|
+
return instance!.invokeGlobal(
|
|
453
517
|
globalName,
|
|
454
|
-
|
|
455
|
-
|
|
518
|
+
cb,
|
|
519
|
+
Array.from(arguments),
|
|
456
520
|
);
|
|
457
|
-
}
|
|
458
|
-
enumerable: true,
|
|
521
|
+
};
|
|
459
522
|
},
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
cb
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
},
|
|
495
|
-
set(callback) {
|
|
496
|
-
instance!.setGlobalCallback(
|
|
523
|
+
set(callback) {
|
|
524
|
+
instance!.setGlobalCallback(
|
|
525
|
+
globalName,
|
|
526
|
+
cb,
|
|
527
|
+
callback,
|
|
528
|
+
);
|
|
529
|
+
},
|
|
530
|
+
enumerable: true,
|
|
531
|
+
},
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
instance!
|
|
537
|
+
.definition()
|
|
538
|
+
.globalFunctions(globalName)
|
|
539
|
+
.forEach((cb) => {
|
|
540
|
+
const functionName = translateName(cb);
|
|
541
|
+
|
|
542
|
+
if (globalObject[functionName] !== undefined) {
|
|
543
|
+
console.warn(
|
|
544
|
+
"Duplicated function name " +
|
|
545
|
+
cb +
|
|
546
|
+
" on global " +
|
|
547
|
+
global,
|
|
548
|
+
);
|
|
549
|
+
} else {
|
|
550
|
+
Object.defineProperty(
|
|
551
|
+
globalObject,
|
|
552
|
+
translateName(cb),
|
|
553
|
+
{
|
|
554
|
+
get() {
|
|
555
|
+
return function () {
|
|
556
|
+
return instance!.invokeGlobal(
|
|
497
557
|
globalName,
|
|
498
558
|
cb,
|
|
499
|
-
|
|
559
|
+
Array.from(arguments),
|
|
500
560
|
);
|
|
501
|
-
}
|
|
502
|
-
enumerable: true,
|
|
503
|
-
},
|
|
504
|
-
);
|
|
505
|
-
}
|
|
506
|
-
});
|
|
507
|
-
|
|
508
|
-
instance!
|
|
509
|
-
.definition()
|
|
510
|
-
.globalFunctions(globalName)
|
|
511
|
-
.forEach((cb) => {
|
|
512
|
-
const functionName = cb.replace(/-/g, "_");
|
|
513
|
-
|
|
514
|
-
if (
|
|
515
|
-
globalObject[functionName] !== undefined
|
|
516
|
-
) {
|
|
517
|
-
console.warn(
|
|
518
|
-
"Duplicated function name " +
|
|
519
|
-
cb +
|
|
520
|
-
" on global " +
|
|
521
|
-
global,
|
|
522
|
-
);
|
|
523
|
-
} else {
|
|
524
|
-
Object.defineProperty(
|
|
525
|
-
globalObject,
|
|
526
|
-
cb.replace(/-/g, "_"),
|
|
527
|
-
{
|
|
528
|
-
get() {
|
|
529
|
-
return function () {
|
|
530
|
-
return instance!.invokeGlobal(
|
|
531
|
-
globalName,
|
|
532
|
-
cb,
|
|
533
|
-
Array.from(
|
|
534
|
-
arguments,
|
|
535
|
-
),
|
|
536
|
-
);
|
|
537
|
-
};
|
|
538
|
-
},
|
|
539
|
-
enumerable: true,
|
|
561
|
+
};
|
|
540
562
|
},
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
Object.defineProperty(componentHandle, globalName, {
|
|
546
|
-
get() {
|
|
547
|
-
return globalObject;
|
|
548
|
-
},
|
|
549
|
-
enumerable: true,
|
|
563
|
+
enumerable: true,
|
|
564
|
+
},
|
|
565
|
+
);
|
|
566
|
+
}
|
|
550
567
|
});
|
|
551
|
-
}
|
|
552
|
-
});
|
|
553
568
|
|
|
554
|
-
|
|
555
|
-
|
|
569
|
+
Object.defineProperty(componentHandle, globalName, {
|
|
570
|
+
get() {
|
|
571
|
+
return globalObject;
|
|
572
|
+
},
|
|
573
|
+
enumerable: true,
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
return Object.seal(componentHandle);
|
|
556
579
|
},
|
|
557
|
-
);
|
|
580
|
+
});
|
|
558
581
|
});
|
|
559
582
|
return Object.seal(slint_module);
|
|
560
583
|
}
|