@mun-ui/ui 0.0.0-stage → 0.2.1
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/LICENSE +21 -0
- package/README.md +114 -2
- package/bin/compile.mjs +38 -0
- package/bin/desktop.mjs +143 -0
- package/bin/dev-protocol.mjs +94 -0
- package/bin/formatter.mjs +109 -0
- package/bin/hot-reload.mjs +38 -0
- package/bin/mun.mjs +538 -0
- package/bin/native.mjs +133 -0
- package/bin/pnpm-workspace.mjs +58 -0
- package/bin/program-patch.mjs +104 -0
- package/bin/project.mjs +322 -0
- package/bin/watch.mjs +316 -0
- package/bin/workflow.mjs +261 -0
- package/dist/astro.d.ts +3 -0
- package/dist/astro.d.ts.map +1 -0
- package/dist/astro.js +3 -0
- package/dist/astro.js.map +1 -0
- package/dist/closures.d.ts +2 -0
- package/dist/closures.d.ts.map +1 -0
- package/dist/closures.js +2 -0
- package/dist/closures.js.map +1 -0
- package/dist/compiler/index.d.ts +2 -0
- package/dist/compiler/index.d.ts.map +1 -0
- package/dist/compiler/index.js +2 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/core.d.ts +3 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +3 -0
- package/dist/core.js.map +1 -0
- package/dist/experimental.d.ts +2 -0
- package/dist/experimental.d.ts.map +1 -0
- package/dist/experimental.js +2 -0
- package/dist/experimental.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/jsx-dev-runtime.d.ts +2 -0
- package/dist/jsx-dev-runtime.d.ts.map +1 -0
- package/dist/jsx-dev-runtime.js +2 -0
- package/dist/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx-runtime.d.ts +2 -0
- package/dist/jsx-runtime.d.ts.map +1 -0
- package/dist/jsx-runtime.js +2 -0
- package/dist/jsx-runtime.js.map +1 -0
- package/dist/legacy.d.ts +3 -0
- package/dist/legacy.d.ts.map +1 -0
- package/dist/legacy.js +3 -0
- package/dist/legacy.js.map +1 -0
- package/dist/mun.d.ts +5 -0
- package/dist/mun.d.ts.map +1 -0
- package/dist/mun.js +4 -0
- package/dist/mun.js.map +1 -0
- package/dist/progressive-blur/index.d.ts +8 -0
- package/dist/progressive-blur/index.d.ts.map +1 -0
- package/dist/progressive-blur/index.js +8 -0
- package/dist/progressive-blur/index.js.map +1 -0
- package/dist/progressive-blur/plan.d.ts +3 -0
- package/dist/progressive-blur/plan.d.ts.map +1 -0
- package/dist/progressive-blur/plan.js +3 -0
- package/dist/progressive-blur/plan.js.map +1 -0
- package/dist/react-types.d.ts +2 -0
- package/dist/react-types.d.ts.map +1 -0
- package/dist/react-types.js +2 -0
- package/dist/react-types.js.map +1 -0
- package/dist/rendering-quality.d.ts +4 -0
- package/dist/rendering-quality.d.ts.map +1 -0
- package/dist/rendering-quality.js +4 -0
- package/dist/rendering-quality.js.map +1 -0
- package/dist/state.d.ts +2 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +2 -0
- package/dist/state.js.map +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/vite.d.ts +2 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +2 -0
- package/dist/vite.js.map +1 -0
- package/editors/install.mjs +102 -0
- package/editors/lsp/mun-lsp.mjs +123 -0
- package/editors/lsp/service.mjs +306 -0
- package/editors/lsp/source.mjs +58 -0
- package/editors/vscode/client.mjs +40 -0
- package/editors/vscode/dev-client.mjs +83 -0
- package/editors/vscode/discovery.mjs +46 -0
- package/editors/vscode/export.mjs +42 -0
- package/editors/vscode/extension.cjs +226 -0
- package/editors/vscode/language-configuration.json +15 -0
- package/editors/vscode/package.json +119 -0
- package/editors/vscode/protocol.mjs +29 -0
- package/editors/vscode/syntaxes/mun.tmLanguage.json +130 -0
- package/native/Cargo.lock +3581 -0
- package/native/Cargo.toml +21 -0
- package/native/README.md +21 -0
- package/native/mun-native/Cargo.toml +23 -0
- package/native/mun-native/src/accessibility.rs +738 -0
- package/native/mun-native/src/dev.rs +604 -0
- package/native/mun-native/src/host_services.rs +202 -0
- package/native/mun-native/src/lib.rs +2843 -0
- package/native/mun-native/src/main.rs +204 -0
- package/native/mun-native/src/offscreen.rs +393 -0
- package/native/mun-native/src/rect.wgsl +63 -0
- package/native/mun-native/src/text.rs +401 -0
- package/native/mun-native/tests/offscreen_rendering.rs +161 -0
- package/native/mun-native/tests/stress.rs +408 -0
- package/native/mun-native/tests/window_lifecycle.rs +183 -0
- package/native/mun-runtime/Cargo.toml +13 -0
- package/native/mun-runtime/src/accessibility.rs +193 -0
- package/native/mun-runtime/src/collection.rs +1090 -0
- package/native/mun-runtime/src/gesture.rs +1070 -0
- package/native/mun-runtime/src/input.rs +325 -0
- package/native/mun-runtime/src/ir.rs +852 -0
- package/native/mun-runtime/src/kinetics.rs +500 -0
- package/native/mun-runtime/src/layout.rs +258 -0
- package/native/mun-runtime/src/layout_cache.rs +209 -0
- package/native/mun-runtime/src/lib.rs +52 -0
- package/native/mun-runtime/src/motion.rs +1162 -0
- package/native/mun-runtime/src/retained.rs +574 -0
- package/native/mun-runtime/src/runtime.rs +7449 -0
- package/native/mun-runtime/src/scene.rs +567 -0
- package/native/mun-runtime/src/scroll.rs +521 -0
- package/native/mun-runtime/src/scroll_view.rs +220 -0
- package/native/mun-runtime/src/text_edit.rs +670 -0
- package/native/mun-runtime/src/timeline.rs +1534 -0
- package/native/mun-runtime/src/validate.rs +677 -0
- package/native/mun-runtime/tests/accessibility_semantics.rs +168 -0
- package/native/mun-runtime/tests/compiler_contract.rs +110 -0
- package/native/mun-runtime/tests/flexible_frames.rs +47 -0
- package/native/mun-runtime/tests/host_services.rs +107 -0
- package/native/mun-runtime/tests/hot_update.rs +367 -0
- package/native/mun-runtime/tests/incremental_runtime.rs +323 -0
- package/native/mun-runtime/tests/ir_validation.rs +167 -0
- package/native/mun-runtime/tests/keyed_collections.rs +251 -0
- package/native/mun-runtime/tests/minimum_window_size.rs +80 -0
- package/native/mun-runtime/tests/native_controls_style.rs +491 -0
- package/native/mun-runtime/tests/native_demo.rs +285 -0
- package/native/mun-runtime/tests/native_layout_style.rs +175 -0
- package/native/mun-runtime/tests/native_settings_pane.rs +152 -0
- package/native/mun-runtime/tests/priority_proposals.rs +69 -0
- package/native/mun-runtime/tests/scroll_view.rs +403 -0
- package/native/mun-runtime/tests/text_editing.rs +491 -0
- package/native/mun-runtime/tests/text_proposals.rs +42 -0
- package/native/mun-runtime/tests/typography.rs +63 -0
- package/package.json +213 -3
- package/schemas/README.md +19 -0
- package/schemas/semantic-ui-ir-v1.schema.json +2061 -0
- package/templates/desktop/gitignore +5 -0
- package/templates/desktop/package.json +10 -0
- package/templates/desktop/src-tauri/Cargo.toml +14 -0
- package/templates/desktop/src-tauri/build.rs +1 -0
- package/templates/desktop/src-tauri/capabilities/main.json +12 -0
- package/templates/desktop/src-tauri/icons/icon.icns +0 -0
- package/templates/desktop/src-tauri/icons/icon.ico +0 -0
- package/templates/desktop/src-tauri/icons/icon.png +0 -0
- package/templates/desktop/src-tauri/src/main.rs +2 -0
- package/templates/desktop/src-tauri/tauri.conf.json +42 -0
- package/templates/desktop/vite.config.ts +10 -0
- package/templates/native/App.mun +15 -0
- package/templates/native/gitignore +3 -0
- package/templates/native/mun.toml +8 -0
- package/templates/project/gitignore +5 -0
- package/templates/project/index.html +13 -0
- package/templates/project/package.json +24 -0
- package/templates/project/src/App.mun +13 -0
- package/templates/project/src/index.css +30 -0
- package/templates/project/src/main.ts +5 -0
- package/templates/project/tsconfig.json +20 -0
- package/templates/project/vite.config.ts +6 -0
- package/templates/vite/src/App.css +134 -0
- package/templates/vite/src/App.tsx +91 -0
- package/templates/vite/src/index.css +23 -0
- package/templates/vite/vite.config.ts +10 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
//! The runtime enforces the v1 Semantic UI IR contract strictly and names the
|
|
2
|
+
//! offending node and field.
|
|
3
|
+
use mun_runtime::{Runtime, RuntimeLoadError};
|
|
4
|
+
use serde_json::{Value, json};
|
|
5
|
+
|
|
6
|
+
fn base() -> Value {
|
|
7
|
+
json!({
|
|
8
|
+
"version": 1, "sourceLanguage": "mun", "entry": "V",
|
|
9
|
+
"states": [{"name": "text", "initial": ""}, {"name": "count", "initial": 0}],
|
|
10
|
+
"root": {"kind": "window", "id": "window", "title": "V", "child": {
|
|
11
|
+
"kind": "column", "id": "stack", "children": [
|
|
12
|
+
{"kind": "textField", "id": "field", "state": "text"},
|
|
13
|
+
{"kind": "scroll", "id": "scroll", "axis": "vertical", "children": []},
|
|
14
|
+
{"kind": "radioGroup", "id": "radio", "state": "text", "options": [{"label": "A", "value": "a"}]}
|
|
15
|
+
]
|
|
16
|
+
}}
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
fn rejected(case: usize, edit: impl FnOnce(&mut Value)) -> (Option<String>, String, String) {
|
|
21
|
+
let mut program = base();
|
|
22
|
+
edit(&mut program);
|
|
23
|
+
match Runtime::from_json(&program.to_string()) {
|
|
24
|
+
Err(RuntimeLoadError::Invalid(error)) => (error.node, error.path, error.message),
|
|
25
|
+
Err(other) => panic!("case {case}: expected contract violation, got {other}"),
|
|
26
|
+
Ok(_) => panic!("case {case}: accepted invalid IR"),
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
fn child(program: &mut Value, index: usize) -> &mut Value {
|
|
31
|
+
&mut program["root"]["child"]["children"][index]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
#[test]
|
|
35
|
+
fn malformed_programs_are_rejected_with_node_and_field() {
|
|
36
|
+
assert!(Runtime::from_json(&base().to_string()).is_ok());
|
|
37
|
+
let cases: Vec<(Box<dyn FnOnce(&mut Value)>, Option<&str>, &str, &str)> = vec![
|
|
38
|
+
(
|
|
39
|
+
Box::new(|p| p["extra"] = json!(1)),
|
|
40
|
+
None,
|
|
41
|
+
"/extra",
|
|
42
|
+
"unknown field",
|
|
43
|
+
),
|
|
44
|
+
(
|
|
45
|
+
Box::new(|p| p["root"]["child"]["colour"] = json!("red")),
|
|
46
|
+
Some("stack"),
|
|
47
|
+
"/root/child/colour",
|
|
48
|
+
"unknown field",
|
|
49
|
+
),
|
|
50
|
+
(
|
|
51
|
+
Box::new(|p| child(p, 0)["visual"] = json!({"glow": 1})),
|
|
52
|
+
Some("field"),
|
|
53
|
+
"visual/glow",
|
|
54
|
+
"unknown field",
|
|
55
|
+
),
|
|
56
|
+
(
|
|
57
|
+
Box::new(|p| child(p, 0)["layout"] = json!({"padding": "8"})),
|
|
58
|
+
Some("field"),
|
|
59
|
+
"layout/padding",
|
|
60
|
+
"expected \"number\"",
|
|
61
|
+
),
|
|
62
|
+
(
|
|
63
|
+
Box::new(|p| child(p, 1)["axis"] = json!("diagonal")),
|
|
64
|
+
Some("scroll"),
|
|
65
|
+
"/axis",
|
|
66
|
+
"not one of",
|
|
67
|
+
),
|
|
68
|
+
(
|
|
69
|
+
Box::new(|p| {
|
|
70
|
+
child(p, 1).as_object_mut().unwrap().remove("axis");
|
|
71
|
+
}),
|
|
72
|
+
Some("scroll"),
|
|
73
|
+
"",
|
|
74
|
+
"missing required field 'axis'",
|
|
75
|
+
),
|
|
76
|
+
(
|
|
77
|
+
Box::new(|p| child(p, 0)["kind"] = json!("slider")),
|
|
78
|
+
Some("field"),
|
|
79
|
+
"/kind",
|
|
80
|
+
"unsupported kind",
|
|
81
|
+
),
|
|
82
|
+
(
|
|
83
|
+
Box::new(
|
|
84
|
+
|p| *child(p, 0) = json!({"kind": "window", "id": "w2", "title": "x", "child": {"kind": "column", "id": "c", "children": []}}),
|
|
85
|
+
),
|
|
86
|
+
Some("w2"),
|
|
87
|
+
"/kind",
|
|
88
|
+
"unsupported kind",
|
|
89
|
+
),
|
|
90
|
+
(
|
|
91
|
+
Box::new(|p| child(p, 0)["accessibility"] = json!({"role": "slider"})),
|
|
92
|
+
Some("field"),
|
|
93
|
+
"accessibility/role",
|
|
94
|
+
"not one of",
|
|
95
|
+
),
|
|
96
|
+
(
|
|
97
|
+
Box::new(|p| child(p, 0)["state"] = json!("count")),
|
|
98
|
+
Some("field"),
|
|
99
|
+
"/state",
|
|
100
|
+
"must hold a string",
|
|
101
|
+
),
|
|
102
|
+
(
|
|
103
|
+
Box::new(|p| child(p, 0)["state"] = json!("missing")),
|
|
104
|
+
Some("field"),
|
|
105
|
+
"/state",
|
|
106
|
+
"undeclared state",
|
|
107
|
+
),
|
|
108
|
+
(
|
|
109
|
+
Box::new(|p| {
|
|
110
|
+
child(p, 2)["options"] =
|
|
111
|
+
json!([{"label": "A", "value": "a"}, {"label": "B", "value": "a"}])
|
|
112
|
+
}),
|
|
113
|
+
Some("radio"),
|
|
114
|
+
"options/1/value",
|
|
115
|
+
"duplicate",
|
|
116
|
+
),
|
|
117
|
+
(
|
|
118
|
+
Box::new(|p| {
|
|
119
|
+
p["root"]["child"]["children"].as_array_mut().unwrap().push(json!({"kind": "text", "id": "t", "value": {"kind": "item", "forEach": "list", "path": []}}))
|
|
120
|
+
}),
|
|
121
|
+
Some("t"),
|
|
122
|
+
"value/forEach",
|
|
123
|
+
"outside its forEach",
|
|
124
|
+
),
|
|
125
|
+
(
|
|
126
|
+
Box::new(|p| {
|
|
127
|
+
p["states"]
|
|
128
|
+
.as_array_mut()
|
|
129
|
+
.unwrap()
|
|
130
|
+
.push(json!({"name": "row", "initial": "", "scope": "nowhere"}))
|
|
131
|
+
}),
|
|
132
|
+
None,
|
|
133
|
+
"/states",
|
|
134
|
+
"unknown forEach",
|
|
135
|
+
),
|
|
136
|
+
(
|
|
137
|
+
Box::new(|p| {
|
|
138
|
+
p["states"]
|
|
139
|
+
.as_array_mut()
|
|
140
|
+
.unwrap()
|
|
141
|
+
.push(json!({"name": "text", "initial": ""}))
|
|
142
|
+
}),
|
|
143
|
+
None,
|
|
144
|
+
"/states/2/name",
|
|
145
|
+
"duplicate state",
|
|
146
|
+
),
|
|
147
|
+
];
|
|
148
|
+
for (case, (edit, node, path, message)) in cases.into_iter().enumerate() {
|
|
149
|
+
let (found_node, found_path, found_message) = rejected(case, edit);
|
|
150
|
+
let context = format!("case {case}: {found_node:?} {found_path}: {found_message}");
|
|
151
|
+
assert_eq!(found_node.as_deref(), node, "{context}");
|
|
152
|
+
assert!(found_path.contains(path), "{context}");
|
|
153
|
+
assert!(found_message.contains(message), "{context}");
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
#[test]
|
|
158
|
+
fn unsupported_versions_are_reported_before_field_validation() {
|
|
159
|
+
let mut program = base();
|
|
160
|
+
program["version"] = json!(2);
|
|
161
|
+
program["futureField"] = json!(true);
|
|
162
|
+
let error = Runtime::from_json(&program.to_string()).err().unwrap();
|
|
163
|
+
assert!(
|
|
164
|
+
matches!(error, RuntimeLoadError::UnsupportedVersion { found: 2, .. }),
|
|
165
|
+
"{error}"
|
|
166
|
+
);
|
|
167
|
+
}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
#![recursion_limit = "512"]
|
|
2
|
+
//! Keyed dynamic collections: runtime-owned per-key state scopes.
|
|
3
|
+
use mun_runtime::text_edit::TextEdit;
|
|
4
|
+
use mun_runtime::{InputEvent, Runtime, RuntimeDiagnostic, RuntimeLoadError};
|
|
5
|
+
use serde_json::{Value, json};
|
|
6
|
+
|
|
7
|
+
const NOTE: &str = "@component/row/note";
|
|
8
|
+
|
|
9
|
+
fn item(path: &[&str]) -> Value {
|
|
10
|
+
json!({"kind": "item", "forEach": "list", "path": path})
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
fn collection_action(id: &str, operation: Value) -> Value {
|
|
14
|
+
let mut action = json!({"kind": "collection", "state": "rows", "keyPath": ["id"]});
|
|
15
|
+
action
|
|
16
|
+
.as_object_mut()
|
|
17
|
+
.unwrap()
|
|
18
|
+
.extend(operation.as_object().unwrap().clone());
|
|
19
|
+
json!({"kind": "action", "id": id, "label": id, "action": action})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
fn program(rows: Value) -> String {
|
|
23
|
+
let collection = json!({
|
|
24
|
+
"kind": "conditional",
|
|
25
|
+
"condition": {"kind": "state", "state": "onlyPinned"},
|
|
26
|
+
"then": {"kind": "filter", "collection": {"kind": "state", "state": "rows"}, "path": ["pinned"], "operator": "equal", "value": {"kind": "literal", "value": true}},
|
|
27
|
+
"otherwise": {"kind": "state", "state": "rows"}
|
|
28
|
+
});
|
|
29
|
+
json!({
|
|
30
|
+
"version": 1, "sourceLanguage": "mun", "entry": "Keyed",
|
|
31
|
+
"states": [
|
|
32
|
+
{"name": "rows", "initial": rows},
|
|
33
|
+
{"name": "onlyPinned", "initial": false},
|
|
34
|
+
{"name": "visible", "initial": true},
|
|
35
|
+
{"name": "next", "initial": 10},
|
|
36
|
+
{"name": NOTE, "initial": "", "scope": "list"}
|
|
37
|
+
],
|
|
38
|
+
"root": {"kind": "window", "id": "window", "title": "Keyed", "child": {
|
|
39
|
+
"kind": "column", "id": "stack", "children": [
|
|
40
|
+
{"kind": "conditional", "id": "gate", "condition": {"kind": "state", "state": "visible"}, "then": [
|
|
41
|
+
{"kind": "forEach", "id": "list", "collection": collection, "keyPath": ["id"], "children": [
|
|
42
|
+
{"kind": "row", "id": "row", "children": [
|
|
43
|
+
{"kind": "text", "id": "title", "value": item(&["title"])},
|
|
44
|
+
{"kind": "textField", "id": "note", "state": NOTE},
|
|
45
|
+
collection_action("remove", json!({"operation": "remove", "key": item(&["id"])})),
|
|
46
|
+
collection_action("up", json!({"operation": "move", "key": item(&["id"]), "offset": {"kind": "literal", "value": -1}})),
|
|
47
|
+
collection_action("pin", json!({"operation": "update", "key": item(&["id"]), "path": ["pinned"], "value": {"kind": "not", "value": item(&["pinned"])}}))
|
|
48
|
+
]}
|
|
49
|
+
]}
|
|
50
|
+
], "otherwise": []},
|
|
51
|
+
{"kind": "action", "id": "prepend", "label": "Prepend", "action": {"kind": "sequence", "actions": [
|
|
52
|
+
{"kind": "collection", "state": "rows", "keyPath": ["id"], "operation": "insert",
|
|
53
|
+
"index": {"kind": "literal", "value": 0},
|
|
54
|
+
"value": {"kind": "record", "fields": {
|
|
55
|
+
"id": {"kind": "binary", "operator": "add", "left": {"kind": "literal", "value": "r"}, "right": {"kind": "stringify", "value": {"kind": "state", "state": "next"}}},
|
|
56
|
+
"title": {"kind": "literal", "value": "New"},
|
|
57
|
+
"pinned": {"kind": "literal", "value": false}}}},
|
|
58
|
+
{"kind": "set-state", "state": "next", "value": {"kind": "binary", "operator": "add", "left": {"kind": "state", "state": "next"}, "right": {"kind": "literal", "value": 1}}}
|
|
59
|
+
]}},
|
|
60
|
+
{"kind": "action", "id": "append", "label": "Append", "action": {"kind": "sequence", "actions": [
|
|
61
|
+
{"kind": "collection", "state": "rows", "keyPath": ["id"], "operation": "append",
|
|
62
|
+
"value": {"kind": "record", "fields": {
|
|
63
|
+
"id": {"kind": "binary", "operator": "add", "left": {"kind": "literal", "value": "r"}, "right": {"kind": "stringify", "value": {"kind": "state", "state": "next"}}},
|
|
64
|
+
"title": {"kind": "literal", "value": "Appended"},
|
|
65
|
+
"pinned": {"kind": "literal", "value": false}}}},
|
|
66
|
+
{"kind": "set-state", "state": "next", "value": {"kind": "binary", "operator": "add", "left": {"kind": "state", "state": "next"}, "right": {"kind": "literal", "value": 1}}}
|
|
67
|
+
]}},
|
|
68
|
+
{"kind": "action", "id": "append-dup", "label": "Dup", "action": {"kind": "collection", "state": "rows", "keyPath": ["id"], "operation": "append",
|
|
69
|
+
"value": {"kind": "literal", "value": {"id": "a", "title": "Again", "pinned": false}}}},
|
|
70
|
+
{"kind": "action", "id": "filter", "label": "Filter", "action": {"kind": "toggle-state", "state": "onlyPinned"}},
|
|
71
|
+
{"kind": "action", "id": "hide", "label": "Hide", "action": {"kind": "toggle-state", "state": "visible"}}
|
|
72
|
+
]
|
|
73
|
+
}}
|
|
74
|
+
})
|
|
75
|
+
.to_string()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
fn abc() -> Runtime {
|
|
79
|
+
Runtime::from_json(&program(json!([
|
|
80
|
+
{"id": "a", "title": "Alpha", "pinned": true},
|
|
81
|
+
{"id": "b", "title": "Beta", "pinned": false},
|
|
82
|
+
{"id": "c", "title": "Gamma", "pinned": true}
|
|
83
|
+
])))
|
|
84
|
+
.unwrap()
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
fn node(key: &str, template: &str) -> String {
|
|
88
|
+
format!("{template}[s:{key}]")
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
fn note(r: &Runtime, key: &str) -> Option<String> {
|
|
92
|
+
r.state_value(&node(key, NOTE))
|
|
93
|
+
.and_then(Value::as_str)
|
|
94
|
+
.map(str::to_owned)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
fn type_note(r: &mut Runtime, key: &str, text: &str) {
|
|
98
|
+
assert!(r.focus_action(&node(key, "note")));
|
|
99
|
+
r.handle_input(
|
|
100
|
+
InputEvent::TextEdit(TextEdit::Insert(text.into())),
|
|
101
|
+
400.0,
|
|
102
|
+
600.0,
|
|
103
|
+
)
|
|
104
|
+
.unwrap();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
fn order(r: &Runtime) -> Vec<String> {
|
|
108
|
+
let tree = r.build_accessibility_tree(400.0, 600.0).unwrap();
|
|
109
|
+
tree.nodes
|
|
110
|
+
.iter()
|
|
111
|
+
.filter(|node| node.id.starts_with("title["))
|
|
112
|
+
.map(|node| {
|
|
113
|
+
node.id
|
|
114
|
+
.trim_start_matches("title[s:")
|
|
115
|
+
.trim_end_matches(']')
|
|
116
|
+
.to_owned()
|
|
117
|
+
})
|
|
118
|
+
.collect()
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
#[test]
|
|
122
|
+
fn per_key_state_survives_insertion_before_and_after_and_neighbor_deletion() {
|
|
123
|
+
let mut r = abc();
|
|
124
|
+
type_note(&mut r, "a", "first");
|
|
125
|
+
type_note(&mut r, "b", "second");
|
|
126
|
+
type_note(&mut r, "c", "third");
|
|
127
|
+
assert_eq!(r.scoped_state_count(), 3);
|
|
128
|
+
|
|
129
|
+
r.activate_action("prepend");
|
|
130
|
+
assert_eq!(order(&r), ["r10", "a", "b", "c"]);
|
|
131
|
+
assert_eq!(note(&r, "a").as_deref(), Some("first"));
|
|
132
|
+
assert_eq!(
|
|
133
|
+
note(&r, "r10").as_deref(),
|
|
134
|
+
Some(""),
|
|
135
|
+
"new item starts fresh"
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
// Insertion after existing items.
|
|
139
|
+
r.activate_action("append");
|
|
140
|
+
assert_eq!(order(&r), ["r10", "a", "b", "c", "r11"]);
|
|
141
|
+
assert_eq!(note(&r, "c").as_deref(), Some("third"));
|
|
142
|
+
r.activate_action(&node("c", "up"));
|
|
143
|
+
r.activate_action(&node("c", "up"));
|
|
144
|
+
assert_eq!(order(&r), ["r10", "c", "a", "b", "r11"]);
|
|
145
|
+
|
|
146
|
+
r.activate_action(&node("a", "remove"));
|
|
147
|
+
assert_eq!(order(&r), ["r10", "c", "b", "r11"]);
|
|
148
|
+
assert_eq!(note(&r, "b").as_deref(), Some("second"));
|
|
149
|
+
assert_eq!(note(&r, "c").as_deref(), Some("third"));
|
|
150
|
+
assert_eq!(note(&r, "a"), None, "removed key released its state");
|
|
151
|
+
assert_eq!(r.scoped_state_count(), 4);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
#[test]
|
|
155
|
+
fn a_new_item_never_inherits_state_from_a_removed_item_at_the_same_index() {
|
|
156
|
+
let mut r = abc();
|
|
157
|
+
type_note(&mut r, "a", "owned by a");
|
|
158
|
+
r.activate_action(&node("a", "remove"));
|
|
159
|
+
r.activate_action("prepend");
|
|
160
|
+
assert_eq!(order(&r)[0], "r10");
|
|
161
|
+
assert_eq!(note(&r, "r10").as_deref(), Some(""));
|
|
162
|
+
assert_eq!(note(&r, "a"), None);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
#[test]
|
|
166
|
+
fn reordering_preserves_state_and_focus_by_key() {
|
|
167
|
+
let mut r = abc();
|
|
168
|
+
type_note(&mut r, "b", "beta note");
|
|
169
|
+
let focused = node("b", "note");
|
|
170
|
+
assert_eq!(r.focused_action(), Some(focused.as_str()));
|
|
171
|
+
r.activate_action(&node("c", "up"));
|
|
172
|
+
r.activate_action(&node("c", "up"));
|
|
173
|
+
assert_eq!(order(&r), ["c", "a", "b"]);
|
|
174
|
+
// Activation focuses the activated action; refocus the field and check the
|
|
175
|
+
// editor continues with the same key-scoped binding.
|
|
176
|
+
type_note(&mut r, "b", "!");
|
|
177
|
+
assert_eq!(note(&r, "b").as_deref(), Some("beta note!"));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
#[test]
|
|
181
|
+
fn filtering_keeps_visible_rows_state_and_releases_filtered_keys() {
|
|
182
|
+
let mut r = abc();
|
|
183
|
+
type_note(&mut r, "a", "pinned a");
|
|
184
|
+
type_note(&mut r, "b", "unpinned b");
|
|
185
|
+
r.activate_action("filter");
|
|
186
|
+
assert_eq!(order(&r), ["a", "c"]);
|
|
187
|
+
assert_eq!(note(&r, "a").as_deref(), Some("pinned a"));
|
|
188
|
+
assert_eq!(note(&r, "b"), None, "filtered-out view scope is released");
|
|
189
|
+
r.activate_action("filter");
|
|
190
|
+
assert_eq!(order(&r), ["a", "b", "c"]);
|
|
191
|
+
assert_eq!(
|
|
192
|
+
note(&r, "b").as_deref(),
|
|
193
|
+
Some(""),
|
|
194
|
+
"returns as a new view instance"
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
// Updating an item field through its key participates in filtering.
|
|
198
|
+
r.activate_action(&node("b", "pin"));
|
|
199
|
+
r.activate_action("filter");
|
|
200
|
+
assert_eq!(order(&r), ["a", "b", "c"]);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
#[test]
|
|
204
|
+
fn hiding_the_conditional_parent_preserves_logical_item_scopes() {
|
|
205
|
+
let mut r = abc();
|
|
206
|
+
type_note(&mut r, "c", "kept");
|
|
207
|
+
r.activate_action("hide");
|
|
208
|
+
assert!(order(&r).is_empty());
|
|
209
|
+
assert_eq!(note(&r, "c").as_deref(), Some("kept"));
|
|
210
|
+
r.activate_action("hide");
|
|
211
|
+
assert_eq!(note(&r, "c").as_deref(), Some("kept"));
|
|
212
|
+
assert_eq!(order(&r), ["a", "b", "c"]);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
#[test]
|
|
216
|
+
fn duplicate_keys_fail_explicitly_and_never_alias() {
|
|
217
|
+
let error = Runtime::from_json(&program(json!([
|
|
218
|
+
{"id": "a", "title": "One", "pinned": false},
|
|
219
|
+
{"id": "a", "title": "Two", "pinned": false}
|
|
220
|
+
])))
|
|
221
|
+
.err()
|
|
222
|
+
.expect("duplicate initial keys are a load error");
|
|
223
|
+
assert!(matches!(error, RuntimeLoadError::Collection(_)), "{error}");
|
|
224
|
+
|
|
225
|
+
let mut r = abc();
|
|
226
|
+
type_note(&mut r, "a", "safe");
|
|
227
|
+
assert!(r.activate_action("append-dup").is_none());
|
|
228
|
+
assert_eq!(order(&r), ["a", "b", "c"]);
|
|
229
|
+
assert_eq!(note(&r, "a").as_deref(), Some("safe"));
|
|
230
|
+
assert!(matches!(
|
|
231
|
+
r.take_diagnostics().as_slice(),
|
|
232
|
+
[RuntimeDiagnostic::RejectedTransaction { .. }]
|
|
233
|
+
));
|
|
234
|
+
// A rejected sequence leaves earlier mutations unapplied as well.
|
|
235
|
+
let next = r.state_value("next").cloned();
|
|
236
|
+
assert_eq!(next, Some(json!(10)));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
#[test]
|
|
240
|
+
fn removing_the_focused_row_moves_focus_deterministically_and_drops_its_editor() {
|
|
241
|
+
let mut r = abc();
|
|
242
|
+
type_note(&mut r, "b", "draft");
|
|
243
|
+
assert!(r.focus_action(&node("b", "remove")));
|
|
244
|
+
r.activate_action(&node("b", "remove"));
|
|
245
|
+
assert_ne!(r.focused_action(), Some(node("b", "remove").as_str()));
|
|
246
|
+
assert!(
|
|
247
|
+
r.focused_action().is_some(),
|
|
248
|
+
"focus falls back to a live control"
|
|
249
|
+
);
|
|
250
|
+
assert_eq!(note(&r, "b"), None);
|
|
251
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
//! The minimum window size is derived from the layout: authored minimums,
|
|
2
|
+
//! fixed frames, spacing and padding count; flexible space, ScrollView content
|
|
3
|
+
//! and Text width do not.
|
|
4
|
+
use mun_runtime::Runtime;
|
|
5
|
+
use serde_json::json;
|
|
6
|
+
|
|
7
|
+
fn lit(v: f32) -> serde_json::Value {
|
|
8
|
+
json!({"kind": "literal", "value": v})
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
fn runtime(child: serde_json::Value) -> Runtime {
|
|
12
|
+
let program = json!({
|
|
13
|
+
"version": 1, "sourceLanguage": "mun", "entry": "Min", "states": [{"name": "s", "initial": "a long value that is wider than any minimum width in these tests"}],
|
|
14
|
+
"root": {"kind": "window", "id": "w", "title": "Min", "child": child}
|
|
15
|
+
});
|
|
16
|
+
Runtime::from_json(&program.to_string()).unwrap()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
#[test]
|
|
20
|
+
fn minimum_window_size_sums_mins_fixed_frames_spacing_and_padding() {
|
|
21
|
+
let r = runtime(json!({
|
|
22
|
+
"kind": "column", "id": "col",
|
|
23
|
+
"layout": {"alignment": "leading", "spacing": 10, "padding": 16,
|
|
24
|
+
"maxWidth": "infinity", "maxHeight": "infinity"},
|
|
25
|
+
"children": [
|
|
26
|
+
{"kind": "row", "id": "row", "layout": {"spacing": 8}, "children": [
|
|
27
|
+
// As compiled: padding and frame wrap the (itself flexible) field,
|
|
28
|
+
// whose long content must not hold the row wider than the minWidth.
|
|
29
|
+
{"kind": "overlay", "id": "padded", "layout": {"padding": 6}, "children": [
|
|
30
|
+
{"kind": "overlay", "id": "field", "layout": {"minWidth": 240, "maxWidth": "infinity"}, "children": [
|
|
31
|
+
{"kind": "textField", "id": "input", "state": "s",
|
|
32
|
+
"layout": {"height": lit(36.0), "maxWidth": "infinity"}}
|
|
33
|
+
]}
|
|
34
|
+
]},
|
|
35
|
+
{"kind": "action", "id": "go", "label": "Go", "action": {"kind": "toggle-state", "state": "s"},
|
|
36
|
+
"layout": {"width": lit(60.0), "height": lit(36.0)}}
|
|
37
|
+
]},
|
|
38
|
+
{"kind": "scroll", "id": "list", "axis": "vertical",
|
|
39
|
+
"layout": {"minHeight": 160, "maxHeight": "infinity", "maxWidth": "infinity"},
|
|
40
|
+
"children": [{"kind": "panel", "id": "tall", "layout": {"width": lit(900.0), "height": lit(2000.0)}}]}
|
|
41
|
+
]
|
|
42
|
+
}));
|
|
43
|
+
// width: padding 16 + field (min 240 + padding 12) + spacing 8 + button 60 + padding 16
|
|
44
|
+
// height: padding 16 + row (36 + padding 12) + spacing 10 + scroll min 160 + padding 16
|
|
45
|
+
assert_eq!(r.minimum_window_size(), (352.0, 250.0));
|
|
46
|
+
// At the minimum nothing is clipped: the field sits at its minWidth, the
|
|
47
|
+
// button ends at the padding and the scroll view keeps its minHeight.
|
|
48
|
+
let tree = r.build_accessibility_tree(352.0, 250.0).unwrap();
|
|
49
|
+
assert_eq!(tree.node("field").unwrap().bounds.width, 240.0);
|
|
50
|
+
let go = tree.node("go").unwrap().bounds;
|
|
51
|
+
assert_eq!(go.x + go.width, 336.0);
|
|
52
|
+
let list = tree.node("list").unwrap().bounds;
|
|
53
|
+
assert_eq!((list.height, list.y + list.height), (160.0, 234.0));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
#[test]
|
|
57
|
+
fn fully_flexible_content_only_keeps_padding_and_fixed_parts() {
|
|
58
|
+
let r = runtime(json!({
|
|
59
|
+
"kind": "column", "id": "col",
|
|
60
|
+
"layout": {"padding": 12, "maxWidth": "infinity", "maxHeight": "infinity"},
|
|
61
|
+
"children": [
|
|
62
|
+
{"kind": "text", "id": "label", "value": {"kind": "literal", "value": "a long wrapping sentence"}},
|
|
63
|
+
{"kind": "panel", "id": "fill", "layout": {"maxWidth": "infinity", "maxHeight": "infinity"}},
|
|
64
|
+
{"kind": "action", "id": "ok", "label": "OK", "action": {"kind": "toggle-state", "state": "s"},
|
|
65
|
+
"layout": {"width": lit(50.0), "height": lit(20.0)}}
|
|
66
|
+
]
|
|
67
|
+
}));
|
|
68
|
+
let (width, height) = r.minimum_window_size();
|
|
69
|
+
// Only the fixed button and the padding hold the width; Text gives up
|
|
70
|
+
// width, the flexible panel gives up both axes.
|
|
71
|
+
assert_eq!(width, 74.0);
|
|
72
|
+
let line = r
|
|
73
|
+
.build_accessibility_tree(800.0, 600.0)
|
|
74
|
+
.unwrap()
|
|
75
|
+
.node("label")
|
|
76
|
+
.unwrap()
|
|
77
|
+
.bounds
|
|
78
|
+
.height;
|
|
79
|
+
assert_eq!(height, (24.0 + line + 20.0).ceil());
|
|
80
|
+
}
|