mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-03 15:21:17 -05:00
Scripts: a dialog listener's close(result) decides show() for the default button
- When a click on the default or cancel button has no handler of the button's own, a listener on a container that calls close(result) now decides what show() returns; before, the button's result 1 or 2 replaced it. - An event on objects made to look like controls whose parents form a cycle ends with a TypeError once the chain is longer than a dialog's nesting allows, instead of walking the cycle until the run's fuel is gone. - The Run Script params text says that an unknown event type throws, and the progress line says that only the dialog takes a show listener.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -933,12 +933,16 @@ fn dispatch(i: &mut Interp, target: ObjId, ty: &str, callback: &str) -> JsResult
|
||||
r
|
||||
}
|
||||
|
||||
/// The containers that hold `target`, innermost first.
|
||||
/// The containers that hold `target`, innermost first. A chain longer than a dialog's nesting
|
||||
/// allows comes from objects a script made to look like elements, and is a `TypeError`.
|
||||
fn containers_above(i: &mut Interp, target: ObjId) -> JsResult<Vec<ObjId>> {
|
||||
let mut above = Vec::new();
|
||||
let mut at = object_slot(i, target, PARENT)?;
|
||||
while let Some(p) = at {
|
||||
i.use_fuel()?;
|
||||
if above.len() > MAX_DEPTH {
|
||||
return Err(i.type_error("the event's target is not a ScriptUI window or control"));
|
||||
}
|
||||
above.push(p);
|
||||
at = object_slot(i, p, PARENT)?;
|
||||
}
|
||||
@@ -1331,7 +1335,8 @@ fn answered(i: &mut Interp, keep: &[Value], answer: Value) -> JsResult<Value> {
|
||||
let value = slot(i, ev, "value")?;
|
||||
match event.as_str() {
|
||||
"click" => {
|
||||
if !click_control(i, c, &kind)? && kind == "button" {
|
||||
// A listener above the button that closed the dialog gives the result.
|
||||
if !click_control(i, c, &kind)? && kind == "button" && matches!(slot(i, win, CLOSING)?, Value::Undefined) {
|
||||
let is = |k: usize| matches!(arg(keep, k), Value::Number(n) if n == id as f64);
|
||||
if is(2) {
|
||||
set_slot(i, win, CLOSING, Value::Number(1.0))?;
|
||||
|
||||
@@ -425,16 +425,38 @@ fn listeners_run_in_the_capture_target_and_bubbling_phases_until_one_stops() {
|
||||
"a button with a click listener does not close the dialog by itself, and the same listener is added once"
|
||||
);
|
||||
for (source, want) in [
|
||||
("new Window('dialog').addEventListener('mouseover', function () {})", "addEventListener: the event mouseover is not available yet"),
|
||||
("new Window('dialog').addEventListener('wobble', function () {})", "addEventListener: there is no event wobble"),
|
||||
("new Window('dialog').addEventListener('click', 'code')", "addEventListener: give the handler as a function"),
|
||||
("w.addEventListener('click', function () { w.close(3); })", "3"),
|
||||
("w.addEventListener('click', function () { w.close(3); }, true)", "3"),
|
||||
("w.addEventListener('click', function () {})", "1"),
|
||||
] {
|
||||
let (mut r, _, _) = realm(vec![click(1)]);
|
||||
let source = format!("var w = new Window('dialog'); w.add('button', undefined, 'OK'); {source}; String(w.show())");
|
||||
assert_eq!(r.run(&source).unwrap(), JsValue::String(want.into()), "a dialog listener's close(result) decides what show() gives: {source}");
|
||||
}
|
||||
for (source, want) in [
|
||||
("new Window('dialog').addEventListener('mouseover', function () {})", "Error addEventListener: the event mouseover is not available yet"),
|
||||
("new Window('dialog').addEventListener('wobble', function () {})", "Error addEventListener: there is no event wobble"),
|
||||
("new Window('dialog').addEventListener('click', 'code')", "TypeError addEventListener: give the handler as a function"),
|
||||
] {
|
||||
let (mut r, _, _) = realm(Vec::new());
|
||||
let e = r.run(&format!("try {{ {source}; 'added' }} catch (e) {{ e.message }}")).unwrap();
|
||||
let e = r.run(&format!("try {{ {source}; 'added' }} catch (e) {{ e.name + ' ' + e.message }}")).unwrap();
|
||||
assert_eq!(e, JsValue::String(want.into()), "{source}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_event_on_objects_made_to_look_like_controls_ends_with_a_type_error() {
|
||||
let (mut r, _, _) = realm(Vec::new());
|
||||
let v = r
|
||||
.run(
|
||||
"var b = new Window('dialog').add('button', undefined, 'Go'); var ran = false; \
|
||||
var f = {__vcKind: 'button'}; var g = {__vcKind: 'group'}; f.__vcParent = g; g.__vcParent = f; f.onClick = function () { ran = true; }; \
|
||||
try { b.notify.call(f, 'onClick'); 'ran' } catch (e) { e.name + ' ' + ran }",
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(v, JsValue::String("TypeError false".into()), "a parent cycle ends at once, not when the run's fuel is gone");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lists_find_and_remove_items_and_take_their_items_in_the_creation_properties() {
|
||||
let (mut r, _, _) = realm(Vec::new());
|
||||
|
||||
+3
-2
@@ -2943,8 +2943,9 @@ controls. `vc.api.has("scriptui")` is true. A script builds a modal dialog and s
|
||||
click for a button, a check box and a radio button, and a change for the others.
|
||||
- `addEventListener(type, handler[, capture])` registers a function for `click`, `change`, `changing` or `show`,
|
||||
and `removeEventListener` with the same arguments removes it, so that it does not run even when the event it was
|
||||
waiting for is already running; a function registered twice for the same type and phase runs once. `show` can be registered only on the dialog, and on a control it throws an `Error`. A window or
|
||||
control takes at most 256 handlers, past which `addEventListener` throws a `RangeError` (VectorCraft's own
|
||||
waiting for is already running; a function registered twice for the same type and phase runs once. `show` can
|
||||
be registered only on the dialog, and on a control it throws an `Error`. A window or control takes at most 256
|
||||
handlers, past which `addEventListener` throws a `RangeError` (VectorCraft's own
|
||||
limit). A handler gets an event with `type`, `target`, `currentTarget`, `eventPhase`, `bubbles`, `cancelable`
|
||||
(always false), `detail` (1 for a click), `stopPropagation()` and `preventDefault()`, which does nothing. The
|
||||
containers above the control run their `capture` handlers first, then the control runs its `onClick`,
|
||||
|
||||
@@ -1066,7 +1066,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- Custom arrowheads under `--automation-read-root`: `stroke.arrowheads.list` gives `file` as `null` for an arrowheads file outside the read roots and names it by its file name in `error`, and `stroke.arrowheads.edit` and `stroke.arrowheads.reload` refuse such a file before anything is made, opened, brought to the front or read; inside the roots `edit` opens the file under the client's roots. `crates/engine/src/tests/arrowheads.rs` (`an_agent_outside_the_arrowheads_files_folder_sees_its_file_name_alone_and_cannot_reload_it`, `an_agent_edits_the_arrowheads_file_only_inside_its_read_roots`).
|
||||
- Plug-in, recovery and script report replies under `--automation-read-root`: `plugin.list`, `plugin.info` and `plugin.safeMode` name the plug-in folder, failed files, plug-in sources and disabled plug-ins' files outside the read roots by file name or `null`, `file.recovery.*` leave out a document's original file and the recovery folder outside them, and `ui.inspect`'s `scriptReport` names files a run wrote outside them by file name. `crates/engine/src/tests/plugins.rs` (`plugin_list_leaves_out_paths_outside_the_read_root`), `crates/engine/src/tests/recovery.rs` (`recovery_replies_leave_out_paths_outside_the_read_root`), `crates/ui-egui/src/tests/automation.rs` (`ui_inspect_script_report_leaves_out_files_outside_the_read_root`).
|
||||
- Scripts: `alert`, `confirm` and `prompt` open dialogs during a run, each with a Stop button that ends the run and puts every document back. In the app the run waits at the call for the person's answer; a run over MCP or the command line takes its answers in order from `script.run`'s `answers`, and the report lists each dialog with its answer. `crates/engine/src/tests/script_dialogs.rs`, `crates/ui-egui/src/tests/script_dialogs.rs`.
|
||||
- Scripts: ScriptUI's `new Window("dialog")` builds a modal dialog of groups, panels, static text, edit fields, buttons, check boxes, radio buttons, drop-down lists, list boxes, sliders and progress bars (https://extendscript.docsforadobe.dev/user-interface-tools/window-object/). `show()` waits for the person, runs the controls' `onClick`, `onChanging`, `onChange`, `onShow` and `onClose` handlers, and returns the result of `close(result)`, 1 for the default button or 2 for the cancel button. Controls also take `addEventListener` for clicks, changes and `show`, `notify`, size objects a script can set one side of, and lists' `find` and `remove`, and `Window.alert`, `Window.confirm` and `Window.prompt` open the script dialogs; a run over MCP or the command line takes the clicks and changes from a `window` answer. Palettes, other control types and resource strings throw that they are not available yet. `crates/js/src/scriptui_tests.rs`, `crates/engine/src/tests/script_scriptui.rs`, `crates/ui-egui/src/tests/script_window.rs`.
|
||||
- Scripts: ScriptUI's `new Window("dialog")` builds a modal dialog of groups, panels, static text, edit fields, buttons, check boxes, radio buttons, drop-down lists, list boxes, sliders and progress bars (https://extendscript.docsforadobe.dev/user-interface-tools/window-object/). `show()` waits for the person, runs the controls' `onClick`, `onChanging`, `onChange`, `onShow` and `onClose` handlers, and returns the result of `close(result)`, 1 for the default button or 2 for the cancel button. Controls also take `notify`, size objects a script can set one side of, lists' `find` and `remove`, and `addEventListener` for clicks and changes, which the dialog also takes for `show`; `Window.alert`, `Window.confirm` and `Window.prompt` open the script dialogs; a run over MCP or the command line takes the clicks and changes from a `window` answer. Palettes, other control types and resource strings throw that they are not available yet. `crates/js/src/scriptui_tests.rs`, `crates/engine/src/tests/script_scriptui.rs`, `crates/ui-egui/src/tests/script_window.rs`.
|
||||
- Parameter keys: the engine refuses a key that a command's params description doesn't name before the command runs, in every build and for every caller, including the app's own calls, the commands a command runs and the steps of `command.batch` and `action.batch`. An action recorded by an older version still plays from the Actions panel and the Batch dialog (`Session::replay`). `crates/engine/tests/it/param_keys.rs`.
|
||||
- Parameter key lookups: the engine reads the params description of each built-in command, with the descriptions its `…` entries name, once per process, and answers the key check and the `ids` and `id` questions of each later command from that reading. A plug-in command's description, and a description whose `…` entries name a plug-in command, are still read each time. The accepted keys, the answers and the error messages are the same. In a release build on a one-object document, `object.move` with `ids` and `dx` takes 48 µs of thread CPU time per command instead of 61 µs, and `select.set` with `ids` 2.3 µs instead of 3.2 µs (medians of 7 alternating runs of 20,000 commands in one process, measured while other builds were running; `tests::params_cache::bench_params_keys_once`). The time is saved per command, in scripts, batches and MCP or plug-in call loops, and does not grow with the size of the document. `crates/engine/src/tests/params_cache.rs` compares every built-in command's answers with those of a fresh parse.
|
||||
- Effect parameter types: `effect.apply`, `appearance.addEffect` and `effect.setParams` refuse an effect parameter of another type than the effect reads, for keys only the params text names too (the earlier 3D `perspective`, `lightAzimuth` and `lightElevation`, Scribble's `variation`, Outline Stroke's `width`, Gaussian Blur's `linear`), a Crop Marks `style` other than `roman` or `japanese`, and an installed plug-in effect's parameter of another type than its manifest gives it, in a `command.batch` step too, with the document and undo history unchanged; a replayed action still plays. `effect.setParams` checks the parameters against a Warp's new style, and refuses a `visible` that is not true or false, in a replayed action too. `crates/engine/src/tests/params.rs` (`an_effect_parameter_without_a_default_is_held_to_its_type`, `effect_commands_refuse_an_undefaulted_parameter_of_the_wrong_type`), `crates/engine/src/tests/plugins.rs` (`live_effect_plugins_reshape_editable_art_and_expand`), `crates/engine/src/cmd/effectcmd/tests.rs` (`set_params_refuses_a_visible_that_is_not_true_or_false`, `set_params_checks_the_effect_it_leaves`).
|
||||
|
||||
Reference in New Issue
Block a user