mirror of
https://github.com/storytold/figcraft.git
synced 2026-10-26 03:16:53 -06:00
Layer data written with node.set {props: {pluginData}} was saved but no
command read it back. node.get (the command, the control method and MCP
get_node) and document.inspect now report pluginData as {key: value}
when a layer or page has any, so a tool keeping state in a file can
read it on its next run. Widget keys are included: the plugin rules
only stop plugins writing them, and widget.list already reports that
state.
31 lines
2.0 KiB
Rust
31 lines
2.0 KiB
Rust
//! Layer data (`pluginData`) reads back through `node.get` and `document.inspect` (#879): what
|
|
//! `node.set` writes on a layer or a page comes back as `{key: value}`, a removed key goes, and a
|
|
//! layer without any reports none.
|
|
|
|
use crate::Session;
|
|
use crate::components::tests::{ex, idv};
|
|
use serde_json::json;
|
|
|
|
#[test]
|
|
fn node_get_reports_the_layer_data_node_set_wrote() {
|
|
let mut s = Session::new();
|
|
let f = idv(&ex(&mut s, "frame.create", json!({"x": 0, "y": 0, "width": 100, "height": 100})));
|
|
let r = idv(&ex(&mut s, "shape.rectangle", json!({"x": 0, "y": 0, "width": 10, "height": 10})));
|
|
let page = s.ds().unwrap().page;
|
|
assert!(ex(&mut s, "node.get", json!({"id": f})).get("pluginData").is_none(), "no data, no field");
|
|
ex(&mut s, "node.set", json!({"ids": [f], "props": {"pluginData": {"com.example.sync": "{\"v\":1}", "n": 2}}}));
|
|
ex(&mut s, "node.set", json!({"ids": [page], "props": {"pluginData": {"com.example.sync": "page"}}}));
|
|
let got = ex(&mut s, "node.get", json!({"id": f}))["pluginData"].clone();
|
|
assert_eq!(got, json!({"com.example.sync": "{\"v\":1}", "n": "2"}), "values read back as the strings stored");
|
|
assert_eq!(ex(&mut s, "node.get", json!({"id": page}))["pluginData"], json!({"com.example.sync": "page"}), "pages keep data too");
|
|
assert!(ex(&mut s, "node.get", json!({"id": r})).get("pluginData").is_none(), "other layers report none");
|
|
// The document tree reports it as well (the page and its children).
|
|
let tree = crate::inspect::document(&s, 2, false);
|
|
assert_eq!(tree["pages"][0]["pluginData"], json!({"com.example.sync": "page"}));
|
|
// A null removes a key; undo brings it back.
|
|
ex(&mut s, "node.set", json!({"ids": [f], "props": {"pluginData": {"n": null}}}));
|
|
assert_eq!(ex(&mut s, "node.get", json!({"id": f}))["pluginData"], json!({"com.example.sync": "{\"v\":1}"}));
|
|
ex(&mut s, "edit.undo", json!({}));
|
|
assert_eq!(ex(&mut s, "node.get", json!({"id": f}))["pluginData"]["n"], "2");
|
|
}
|