@mun-ui/ui 0.0.0-stage → 0.2.0

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.
Files changed (158) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +104 -2
  3. package/bin/compile.mjs +38 -0
  4. package/bin/dev-protocol.mjs +94 -0
  5. package/bin/formatter.mjs +109 -0
  6. package/bin/hot-reload.mjs +38 -0
  7. package/bin/mun.mjs +521 -0
  8. package/bin/native.mjs +133 -0
  9. package/bin/pnpm-workspace.mjs +58 -0
  10. package/bin/program-patch.mjs +104 -0
  11. package/bin/project.mjs +322 -0
  12. package/bin/watch.mjs +316 -0
  13. package/bin/workflow.mjs +261 -0
  14. package/dist/astro.d.ts +3 -0
  15. package/dist/astro.d.ts.map +1 -0
  16. package/dist/astro.js +3 -0
  17. package/dist/astro.js.map +1 -0
  18. package/dist/closures.d.ts +2 -0
  19. package/dist/closures.d.ts.map +1 -0
  20. package/dist/closures.js +2 -0
  21. package/dist/closures.js.map +1 -0
  22. package/dist/compiler/index.d.ts +2 -0
  23. package/dist/compiler/index.d.ts.map +1 -0
  24. package/dist/compiler/index.js +2 -0
  25. package/dist/compiler/index.js.map +1 -0
  26. package/dist/core.d.ts +3 -0
  27. package/dist/core.d.ts.map +1 -0
  28. package/dist/core.js +3 -0
  29. package/dist/core.js.map +1 -0
  30. package/dist/experimental.d.ts +2 -0
  31. package/dist/experimental.d.ts.map +1 -0
  32. package/dist/experimental.js +2 -0
  33. package/dist/experimental.js.map +1 -0
  34. package/dist/index.d.ts +3 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +3 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/jsx-dev-runtime.d.ts +2 -0
  39. package/dist/jsx-dev-runtime.d.ts.map +1 -0
  40. package/dist/jsx-dev-runtime.js +2 -0
  41. package/dist/jsx-dev-runtime.js.map +1 -0
  42. package/dist/jsx-runtime.d.ts +2 -0
  43. package/dist/jsx-runtime.d.ts.map +1 -0
  44. package/dist/jsx-runtime.js +2 -0
  45. package/dist/jsx-runtime.js.map +1 -0
  46. package/dist/legacy.d.ts +3 -0
  47. package/dist/legacy.d.ts.map +1 -0
  48. package/dist/legacy.js +3 -0
  49. package/dist/legacy.js.map +1 -0
  50. package/dist/mun.d.ts +5 -0
  51. package/dist/mun.d.ts.map +1 -0
  52. package/dist/mun.js +4 -0
  53. package/dist/mun.js.map +1 -0
  54. package/dist/progressive-blur/index.d.ts +8 -0
  55. package/dist/progressive-blur/index.d.ts.map +1 -0
  56. package/dist/progressive-blur/index.js +8 -0
  57. package/dist/progressive-blur/index.js.map +1 -0
  58. package/dist/progressive-blur/plan.d.ts +3 -0
  59. package/dist/progressive-blur/plan.d.ts.map +1 -0
  60. package/dist/progressive-blur/plan.js +3 -0
  61. package/dist/progressive-blur/plan.js.map +1 -0
  62. package/dist/react-types.d.ts +2 -0
  63. package/dist/react-types.d.ts.map +1 -0
  64. package/dist/react-types.js +2 -0
  65. package/dist/react-types.js.map +1 -0
  66. package/dist/rendering-quality.d.ts +4 -0
  67. package/dist/rendering-quality.d.ts.map +1 -0
  68. package/dist/rendering-quality.js +4 -0
  69. package/dist/rendering-quality.js.map +1 -0
  70. package/dist/state.d.ts +2 -0
  71. package/dist/state.d.ts.map +1 -0
  72. package/dist/state.js +2 -0
  73. package/dist/state.js.map +1 -0
  74. package/dist/types.d.ts +2 -0
  75. package/dist/types.d.ts.map +1 -0
  76. package/dist/types.js +2 -0
  77. package/dist/types.js.map +1 -0
  78. package/dist/vite.d.ts +2 -0
  79. package/dist/vite.d.ts.map +1 -0
  80. package/dist/vite.js +2 -0
  81. package/dist/vite.js.map +1 -0
  82. package/editors/install.mjs +102 -0
  83. package/editors/lsp/mun-lsp.mjs +123 -0
  84. package/editors/lsp/service.mjs +306 -0
  85. package/editors/lsp/source.mjs +58 -0
  86. package/editors/vscode/client.mjs +40 -0
  87. package/editors/vscode/dev-client.mjs +83 -0
  88. package/editors/vscode/discovery.mjs +46 -0
  89. package/editors/vscode/export.mjs +42 -0
  90. package/editors/vscode/extension.cjs +226 -0
  91. package/editors/vscode/language-configuration.json +15 -0
  92. package/editors/vscode/package.json +119 -0
  93. package/editors/vscode/protocol.mjs +29 -0
  94. package/editors/vscode/syntaxes/mun.tmLanguage.json +130 -0
  95. package/native/Cargo.lock +3581 -0
  96. package/native/Cargo.toml +21 -0
  97. package/native/README.md +21 -0
  98. package/native/mun-native/Cargo.toml +23 -0
  99. package/native/mun-native/src/accessibility.rs +738 -0
  100. package/native/mun-native/src/dev.rs +604 -0
  101. package/native/mun-native/src/lib.rs +2676 -0
  102. package/native/mun-native/src/main.rs +204 -0
  103. package/native/mun-native/src/offscreen.rs +393 -0
  104. package/native/mun-native/src/rect.wgsl +63 -0
  105. package/native/mun-native/src/text.rs +310 -0
  106. package/native/mun-native/tests/offscreen_rendering.rs +161 -0
  107. package/native/mun-native/tests/stress.rs +408 -0
  108. package/native/mun-native/tests/window_lifecycle.rs +183 -0
  109. package/native/mun-runtime/Cargo.toml +13 -0
  110. package/native/mun-runtime/src/accessibility.rs +193 -0
  111. package/native/mun-runtime/src/collection.rs +1073 -0
  112. package/native/mun-runtime/src/gesture.rs +1070 -0
  113. package/native/mun-runtime/src/input.rs +325 -0
  114. package/native/mun-runtime/src/ir.rs +782 -0
  115. package/native/mun-runtime/src/kinetics.rs +500 -0
  116. package/native/mun-runtime/src/layout.rs +173 -0
  117. package/native/mun-runtime/src/layout_cache.rs +209 -0
  118. package/native/mun-runtime/src/lib.rs +49 -0
  119. package/native/mun-runtime/src/motion.rs +1162 -0
  120. package/native/mun-runtime/src/retained.rs +574 -0
  121. package/native/mun-runtime/src/runtime.rs +7078 -0
  122. package/native/mun-runtime/src/scene.rs +530 -0
  123. package/native/mun-runtime/src/scroll.rs +521 -0
  124. package/native/mun-runtime/src/scroll_view.rs +220 -0
  125. package/native/mun-runtime/src/text_edit.rs +670 -0
  126. package/native/mun-runtime/src/timeline.rs +1534 -0
  127. package/native/mun-runtime/src/validate.rs +677 -0
  128. package/native/mun-runtime/tests/accessibility_semantics.rs +168 -0
  129. package/native/mun-runtime/tests/compiler_contract.rs +110 -0
  130. package/native/mun-runtime/tests/flexible_frames.rs +47 -0
  131. package/native/mun-runtime/tests/hot_update.rs +367 -0
  132. package/native/mun-runtime/tests/incremental_runtime.rs +323 -0
  133. package/native/mun-runtime/tests/ir_validation.rs +167 -0
  134. package/native/mun-runtime/tests/keyed_collections.rs +251 -0
  135. package/native/mun-runtime/tests/native_controls_style.rs +491 -0
  136. package/native/mun-runtime/tests/native_demo.rs +285 -0
  137. package/native/mun-runtime/tests/native_layout_style.rs +175 -0
  138. package/native/mun-runtime/tests/native_settings_pane.rs +152 -0
  139. package/native/mun-runtime/tests/scroll_view.rs +403 -0
  140. package/native/mun-runtime/tests/text_editing.rs +491 -0
  141. package/package.json +210 -3
  142. package/schemas/README.md +19 -0
  143. package/schemas/semantic-ui-ir-v1.schema.json +1972 -0
  144. package/templates/native/App.mun +15 -0
  145. package/templates/native/gitignore +3 -0
  146. package/templates/native/mun.toml +8 -0
  147. package/templates/project/gitignore +5 -0
  148. package/templates/project/index.html +13 -0
  149. package/templates/project/package.json +21 -0
  150. package/templates/project/src/App.mun +13 -0
  151. package/templates/project/src/index.css +21 -0
  152. package/templates/project/src/main.ts +5 -0
  153. package/templates/project/tsconfig.json +20 -0
  154. package/templates/project/vite.config.ts +6 -0
  155. package/templates/vite/src/App.css +134 -0
  156. package/templates/vite/src/App.tsx +91 -0
  157. package/templates/vite/src/index.css +23 -0
  158. 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
+ }