mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 12:21:08 +01:00
Plug-ins: File › Place keeps a named importer and its params for every file
- file.place with `importer` and `params` and `paths`, or with no file, opened the Place dialog with only the files, so its OK read them with the built-in reader. Each dialog entry now carries the importer and its params, from the paths given, the desktop pick and the web pick, and OK passes them to file.place and file.place.queue. - On the web, each picked file carries its own pick's importer and params. Picked files with other ones, or that arrive while a Place dialog is open, wait for the next dialog. - The Place dialog does not read the start of a PDF, .ai, EPS or PostScript file placed with an importer named to tell whether Link would place it as a document. - A path placed or opened with `importer` named is refused from its size before any of it is read. Before, its first 64 KiB were read first. - docs/plugins.md and docs/mcp.md say when the size check runs, that the web's File › Place reads the picked file in the browser, that File › Place's filters leave out extensions a built-in format reads, and that a dropped file a built-in format reads goes to that format.
This commit is contained in:
1 parent
c664ce630b
commit
977e896fd0
10 files changed
+233
-39
No files matched your search
@@ -431,9 +431,12 @@ impl eframe::App for WebShell {
|
||||
match f.bytes_async().await {
|
||||
Ok(bytes) => {
|
||||
match target {
|
||||
DropTarget::Place(d) => {
|
||||
place_inbox.lock().unwrap_or_else(|e| e.into_inner()).push(PlaceArrival { name, bytes, drop: Some(d) })
|
||||
}
|
||||
DropTarget::Place(d) => place_inbox.lock().unwrap_or_else(|e| e.into_inner()).push(PlaceArrival {
|
||||
name,
|
||||
bytes,
|
||||
drop: Some(d),
|
||||
with: serde_json::Value::Null,
|
||||
}),
|
||||
DropTarget::Open => inbox.lock().unwrap_or_else(|e| e.into_inner()).push((name, bytes)),
|
||||
}
|
||||
repaint.request_repaint();
|
||||
@@ -477,8 +480,9 @@ fn services(
|
||||
});
|
||||
})),
|
||||
script_inbox: Some(script_inbox),
|
||||
// File → Place…: the picked files go to the Place dialog.
|
||||
place_async: Some(Box::new(move || {
|
||||
// File → Place…: the picked files go to the Place dialog, with the importer plug-in and
|
||||
// parameters `with` names.
|
||||
place_async: Some(Box::new(move |with: serde_json::Value| {
|
||||
let inbox = picked.clone();
|
||||
let ctx = place_ctx.clone();
|
||||
wasm_bindgen_futures::spawn_local(async move {
|
||||
@@ -493,7 +497,7 @@ fn services(
|
||||
};
|
||||
let mut arrived = vec![];
|
||||
for f in files {
|
||||
arrived.push(PlaceArrival { name: f.file_name(), bytes: f.read().await, drop: None });
|
||||
arrived.push(PlaceArrival { name: f.file_name(), bytes: f.read().await, drop: None, with: with.clone() });
|
||||
}
|
||||
inbox.lock().unwrap_or_else(|e| e.into_inner()).extend(arrived);
|
||||
ctx.request_repaint();
|
||||
|
||||
@@ -148,7 +148,8 @@ fn check_data_for(p: &Value, mode: Mode, cmd: &str) -> Result<()> {
|
||||
/// `importer` names, or an extension no built-in format reads that an importer lists) is read up
|
||||
/// to [`import::MAX_INPUT_BYTES`]: past that, it is an error, unless the start of the file shows a
|
||||
/// built-in format and no importer was named, which is read whole as any other file is. A file past
|
||||
/// the limit that isn't read whole is reported from its size, without reading it.
|
||||
/// the limit that isn't read whole is reported from its size: with `importer` named, before any of
|
||||
/// it is read, and otherwise after the start of it is read to look for a built-in format.
|
||||
pub(super) fn read_path(path: &str, p: &Value) -> Result<Vec<u8>> {
|
||||
read_path_for(path, p, Mode::Import, C)
|
||||
}
|
||||
@@ -157,21 +158,32 @@ pub(super) fn read_path(path: &str, p: &Value) -> Result<Vec<u8>> {
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn read_path_for(path: &str, p: &Value, mode: Mode, cmd: &str) -> Result<Vec<u8>> {
|
||||
let explicit = named(p, cmd)?.is_some();
|
||||
if !explicit && !importer_reads(&extension(path), mode) {
|
||||
if explicit {
|
||||
return read_for_importer(path, mode);
|
||||
}
|
||||
if !importer_reads(&extension(path), mode) {
|
||||
return super::read_file(path);
|
||||
}
|
||||
let head = super::read_file_head(path, SNIFF_BYTES)?;
|
||||
if head.len() < SNIFF_BYTES {
|
||||
return Ok(head);
|
||||
}
|
||||
if !explicit && detect(path, &head).is_some() {
|
||||
if detect(path, &head).is_some() {
|
||||
return super::read_file(path);
|
||||
}
|
||||
let size = std::fs::metadata(path).map_err(|e| EngineError::Other(format!("{path}: {e}")))?.len();
|
||||
if size > import::MAX_INPUT_BYTES as u64 {
|
||||
read_for_importer(path, mode)
|
||||
}
|
||||
|
||||
/// The file at `path` for an importer: refused from its size, before any of it is read, when it is
|
||||
/// past [`import::MAX_INPUT_BYTES`].
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn read_for_importer(path: &str, mode: Mode) -> Result<Vec<u8>> {
|
||||
super::may_read(path)?;
|
||||
let meta = std::fs::metadata(path).map_err(|e| EngineError::Other(format!("{path}: {e}")))?;
|
||||
if meta.is_file() && meta.len() > import::MAX_INPUT_BYTES as u64 {
|
||||
return Err(too_large(path, mode));
|
||||
}
|
||||
// The file can grow after the size is read.
|
||||
// The file can grow after the size is read; anything but a regular file is refused here.
|
||||
let file = super::read_file_head(path, import::MAX_INPUT_BYTES + 1)?;
|
||||
if file.len() > import::MAX_INPUT_BYTES {
|
||||
return Err(too_large(path, mode));
|
||||
|
||||
@@ -280,3 +280,44 @@ fn failures_place_nothing() {
|
||||
assert_eq!(state(&mut s), before, "too large");
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// A file past the limit, placed with `importer` named, is refused from its size before any of it
|
||||
/// is read: here the file can't be read at all, and the error is still the size.
|
||||
#[test]
|
||||
fn a_named_importer_refuses_a_large_file_before_reading_it() {
|
||||
let mut s = with_document();
|
||||
install(&mut s, &tpl::returning(&placing("test.place.unread", r#"["tpu"]"#), ART));
|
||||
let dir = std::env::temp_dir().join(format!("vc-plugin-place-unread-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let big = dir.join("big.tpu");
|
||||
std::fs::File::create(&big).unwrap().set_len(vectorcraft_plugins::import::MAX_INPUT_BYTES as u64 + 1).unwrap();
|
||||
// Unix: no read permission. Windows: another handle that shares nothing.
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
std::fs::set_permissions(&big, std::fs::Permissions::from_mode(0o000)).unwrap();
|
||||
}
|
||||
#[cfg(windows)]
|
||||
let _held = {
|
||||
use std::os::windows::fs::OpenOptionsExt;
|
||||
std::fs::OpenOptions::new().read(true).share_mode(0).open(&big).unwrap()
|
||||
};
|
||||
// A user that reads the file anyway (root) can't show the order of the checks.
|
||||
if std::fs::File::open(&big).is_ok() {
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
return;
|
||||
}
|
||||
let before = state(&mut s);
|
||||
let e = s.execute("file.place", &json!({"path": big.to_string_lossy(), "importer": "plugin.test.place.unread"})).unwrap_err().to_string();
|
||||
assert!(e.contains("can't place `big.tpu`") && e.contains("larger than"), "{e}");
|
||||
assert_eq!(state(&mut s), before);
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
let _ = std::fs::set_permissions(&big, std::fs::Permissions::from_mode(0o644));
|
||||
}
|
||||
#[cfg(windows)]
|
||||
drop(_held);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
@@ -273,6 +273,100 @@ fn a_named_placing_importer_skips_built_in_import_options() {
|
||||
app.run("plugin.remove", json!({"id": "test.ui.namedplace"})).unwrap();
|
||||
}
|
||||
|
||||
/// `file.place` with `paths`, `importer` and `params` opens the Place dialog, and its OK places the
|
||||
/// files with that importer and those parameters: one file at once, several through the place
|
||||
/// cursor. The files are SVG files by their extension, which the built-in reader can't read.
|
||||
#[test]
|
||||
fn the_place_dialog_places_paths_with_the_importer_and_params_given() {
|
||||
let dir = tmp_dir("placepaths");
|
||||
let mut app = app();
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
let params = r#"{"density":{"type":"number","min":0,"max":10,"default":4}}"#;
|
||||
let manifest = tpl::importer("test.ui.placepaths", r#"["svg"]"#, params).replace(r#""kind":"importer""#, r#""kind":"importer","place":true"#);
|
||||
install(&mut app, &tpl::when_given(&manifest, Given::Params, r#""density":7.0"#, RECT));
|
||||
let paths: Vec<String> = ["a.svg", "b.svg"]
|
||||
.iter()
|
||||
.map(|n| {
|
||||
let p = dir.join(n);
|
||||
std::fs::write(&p, b"?").unwrap();
|
||||
p.to_string_lossy().into_owned()
|
||||
})
|
||||
.collect();
|
||||
let given =
|
||||
|paths: &[String]| json!({"paths": paths, "importer": "plugin.test.ui.placepaths", "params": {"density": 7}, "showImportOptions": false});
|
||||
|
||||
app.run("file.place", given(&paths[..1])).unwrap();
|
||||
assert_eq!(app.ui.dialog.as_ref().map(|d| d.kind.as_str()), Some(crate::dialogs::place::KIND));
|
||||
let steps = app.session.active().unwrap().history.undo.len();
|
||||
let r = crate::dialogs::confirm(&mut app).unwrap();
|
||||
assert_eq!(r["format"], "plugin.test.ui.placepaths", "{r} {}", app.ui.status);
|
||||
assert_eq!(app.session.active().unwrap().history.undo.len(), steps + 1);
|
||||
|
||||
app.run("file.place", given(&paths)).unwrap();
|
||||
crate::dialogs::confirm(&mut app).unwrap();
|
||||
assert_eq!(app.session.tool_options()["count"], 2, "{}", app.ui.status);
|
||||
|
||||
app.run("plugin.remove", json!({"id": "test.ui.placepaths"})).unwrap();
|
||||
}
|
||||
|
||||
/// A PDF file placed with an importer plug-in named is not read to tell whether Link would place it
|
||||
/// as a document: the Place dialog counts it as a file the importer embeds. The file here doesn't
|
||||
/// exist, which counts as a document when its start is read.
|
||||
#[test]
|
||||
fn the_place_dialog_does_not_read_a_file_a_named_importer_places() {
|
||||
let dir = tmp_dir("placenamedpdf");
|
||||
let mut app = app();
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
let manifest = tpl::importer("test.ui.placepdf", r#"["pdf"]"#, "{}").replace(r#""kind":"importer""#, r#""kind":"importer","place":true"#);
|
||||
install(&mut app, &tpl::returning(&manifest, RECT));
|
||||
let path = dir.join("missing.pdf").to_string_lossy().into_owned();
|
||||
let fields = |app: &mut VectorcraftApp, p: serde_json::Value| {
|
||||
app.run("file.place", p).unwrap();
|
||||
let d = app.ui.dialog.take().expect("the Place dialog");
|
||||
(d.fields["__documents"].clone(), d.fields["__others"].clone())
|
||||
};
|
||||
assert_eq!(fields(&mut app, json!({"paths": [path]})), (json!(true), json!(false)));
|
||||
assert_eq!(fields(&mut app, json!({"paths": [path], "importer": "plugin.test.ui.placepdf"})), (json!(false), json!(true)));
|
||||
app.run("plugin.remove", json!({"id": "test.ui.placepdf"})).unwrap();
|
||||
}
|
||||
|
||||
/// On the web, `file.place` with `importer` and `params` and no file starts the browser's pick, and
|
||||
/// the Place dialog's OK places the picked file with that importer and those parameters. Each
|
||||
/// pick's files keep that pick's importer, also when another pick started before they arrived, and
|
||||
/// a pick with another importer waits for its own dialog.
|
||||
#[test]
|
||||
fn a_web_pick_places_with_the_importer_and_params_given() {
|
||||
let mut app = app();
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
let params = r#"{"density":{"type":"number","min":0,"max":10,"default":4}}"#;
|
||||
let manifest = tpl::importer("test.ui.webpick", r#"["svg"]"#, params).replace(r#""kind":"importer""#, r#""kind":"importer","place":true"#);
|
||||
install(&mut app, &tpl::when_given(&manifest, Given::Params, r#""density":7.0"#, RECT));
|
||||
let inbox = crate::place::PlaceInbox::default();
|
||||
app.services.place_inbox = Some(inbox.clone());
|
||||
let started: std::rc::Rc<std::cell::RefCell<Vec<serde_json::Value>>> = Default::default();
|
||||
let starts = started.clone();
|
||||
app.services.place_async = Some(Box::new(move |with| starts.borrow_mut().push(with)));
|
||||
|
||||
app.run("file.place", json!({"importer": "plugin.test.ui.webpick", "params": {"density": 7}, "showImportOptions": false})).unwrap();
|
||||
app.run("file.place", json!({})).unwrap();
|
||||
let arrive = |name: &str, with: serde_json::Value| {
|
||||
inbox.lock().unwrap().push(crate::place::PlaceArrival { name: name.into(), bytes: b"?".to_vec(), drop: None, with })
|
||||
};
|
||||
arrive("a.svg", started.borrow()[0].clone());
|
||||
arrive("b.svg", started.borrow()[1].clone());
|
||||
crate::place::drain(&mut app);
|
||||
let files = |app: &VectorcraftApp| app.ui.dialog.as_ref().filter(|d| d.kind == crate::dialogs::place::KIND).map(|d| d.fields["files"].clone());
|
||||
assert_eq!(files(&app), Some(json!([{"name": "a.svg", "importer": "plugin.test.ui.webpick", "params": {"density": 7}}])));
|
||||
let steps = app.session.active().unwrap().history.undo.len();
|
||||
let r = crate::dialogs::confirm(&mut app).unwrap();
|
||||
assert_eq!(r["format"], "plugin.test.ui.webpick", "{r} {}", app.ui.status);
|
||||
assert_eq!(app.session.active().unwrap().history.undo.len(), steps + 1);
|
||||
crate::place::drain(&mut app);
|
||||
assert_eq!(files(&app), Some(json!([{"name": "b.svg"}])));
|
||||
|
||||
app.run("plugin.remove", json!({"id": "test.ui.webpick"})).unwrap();
|
||||
}
|
||||
|
||||
/// The extensions File › Open's filters leave out of importers' (`fileio::opens_as_other`) are the
|
||||
/// ones File › Open installs, imports, checks or loads as something other than a document.
|
||||
#[test]
|
||||
|
||||
+48
-14
@@ -23,6 +23,9 @@ pub struct PlaceArrival {
|
||||
pub name: String,
|
||||
pub bytes: Vec<u8>,
|
||||
pub drop: Option<DropAt>,
|
||||
/// A picked file's importer plug-in and parameters, from the `file.place` that started the pick
|
||||
/// (`importer`, `params`; `null` or `{}` without them).
|
||||
pub with: Value,
|
||||
}
|
||||
|
||||
pub type PlaceInbox = Arc<Mutex<Vec<PlaceArrival>>>;
|
||||
@@ -223,8 +226,8 @@ fn place_file_in(app: &mut VectorcraftApp, p: &Value, read: Read) -> Result<Valu
|
||||
}
|
||||
if p.get("path").is_none() && p.get("dataBase64").is_none() {
|
||||
let files: Vec<Value> = match p.get("paths").and_then(Value::as_array) {
|
||||
Some(a) => a.iter().filter_map(Value::as_str).map(|path| json!({ "path": path })).collect(),
|
||||
None => return pick(app).map(|_| Value::Null),
|
||||
Some(a) => a.iter().filter_map(Value::as_str).map(|path| with_importer(json!({ "path": path }), &p)).collect(),
|
||||
None => return pick(app, &p).map(|_| Value::Null),
|
||||
};
|
||||
if files.is_empty() {
|
||||
return Err("paths: give at least one file".into());
|
||||
@@ -280,10 +283,11 @@ fn place_file_in(app: &mut VectorcraftApp, p: &Value, read: Read) -> Result<Valu
|
||||
}
|
||||
}
|
||||
|
||||
/// Pick files to place: the Place dialog opens with them (on the web once they arrive).
|
||||
fn pick(app: &mut VectorcraftApp) -> Result<(), String> {
|
||||
/// Pick files to place: the Place dialog opens with them (on the web once they arrive), placed with
|
||||
/// the importer plug-in and parameters `p` names ([`with_importer`]).
|
||||
fn pick(app: &mut VectorcraftApp, p: &Value) -> Result<(), String> {
|
||||
if let Some(f) = app.services.place_async.as_mut() {
|
||||
f();
|
||||
f(with_importer(json!({}), p));
|
||||
return Ok(());
|
||||
}
|
||||
let paths = if app.services.pick_open_multi.is_some() {
|
||||
@@ -296,10 +300,25 @@ fn pick(app: &mut VectorcraftApp) -> Result<(), String> {
|
||||
if paths.is_empty() {
|
||||
return Err("cancelled".into());
|
||||
}
|
||||
open_dialog(app, paths.into_iter().map(|path| json!({ "path": path })).collect());
|
||||
open_dialog(app, paths.into_iter().map(|path| with_importer(json!({ "path": path }), p)).collect());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// The params of `file.place` that name an importer plug-in and its parameters: a Place dialog file
|
||||
/// entry carries them, and its file is read and placed with them.
|
||||
const IMPORTER_KEYS: [&str; 2] = ["importer", "params"];
|
||||
|
||||
/// Place dialog file entry `file` with the importer plug-in and parameters `p` names
|
||||
/// ([`IMPORTER_KEYS`]).
|
||||
fn with_importer(mut file: Value, p: &Value) -> Value {
|
||||
for k in IMPORTER_KEYS {
|
||||
if let Some(v) = p.get(k).filter(|v| !v.is_null()) {
|
||||
file[k] = v.clone();
|
||||
}
|
||||
}
|
||||
file
|
||||
}
|
||||
|
||||
/// The Place dialog for `files` (`{path}`, or `{name}` with the bytes in [`PlaceState`]).
|
||||
fn open_dialog(app: &mut VectorcraftApp, files: Vec<Value>) {
|
||||
let units = app.session.active().map(|d| d.doc.units).unwrap_or_default();
|
||||
@@ -326,9 +345,13 @@ fn open_dialog(app: &mut VectorcraftApp, files: Vec<Value>) {
|
||||
/// object), or a PDF, `.ai`, EPS or PostScript file on disk? A DCS file (an EPS file naming its
|
||||
/// plates) is placed as a linked image instead. Where the platform reads part of a file, only the
|
||||
/// file's start is read; a file longer than that is taken to be at least as long as its binary EPS
|
||||
/// header says, and one whose header can't be told from it counts as a document.
|
||||
/// header says, and one whose header can't be told from it counts as a document. A file that names
|
||||
/// an importer plug-in is none of these, and none of it is read here.
|
||||
fn is_vectorcraft_file(app: &VectorcraftApp, file: &Value) -> bool {
|
||||
use vectorcraft_engine::cmd::place::{DCS_HEAD_BYTES, head_is_dcs};
|
||||
if file.get("importer").is_some() {
|
||||
return false;
|
||||
}
|
||||
let Some(path) = file.get("path").and_then(Value::as_str) else { return false };
|
||||
let native = ["vectorcraft", vectorcraft_format::LEGACY_EXTENSION, "vctemplate"];
|
||||
// The file's start, and the file's length when that is all of it.
|
||||
@@ -357,14 +380,15 @@ fn is_vectorcraft_file(app: &VectorcraftApp, file: &Value) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
/// The engine params naming `file` (a dialog file entry).
|
||||
/// The engine params naming `file` (a dialog file entry), with the importer plug-in and parameters
|
||||
/// it carries ([`IMPORTER_KEYS`]).
|
||||
fn source(app: &VectorcraftApp, file: &Value) -> Option<Value> {
|
||||
if let Some(path) = file.get("path").and_then(Value::as_str) {
|
||||
return Some(json!({ "path": path }));
|
||||
return Some(with_importer(json!({ "path": path }), file));
|
||||
}
|
||||
let name = file.get("name").and_then(Value::as_str)?;
|
||||
let bytes = app.place.picked.iter().find(|(n, _)| n == name).map(|(_, b)| b)?;
|
||||
Some(json!({ "name": name, "dataBase64": vectorcraft_format::base64_encode(bytes) }))
|
||||
Some(with_importer(json!({ "name": name, "dataBase64": vectorcraft_format::base64_encode(bytes) }), file))
|
||||
}
|
||||
|
||||
/// The Place dialog's line about each of `files`, read at once, or where the files the user places
|
||||
@@ -481,7 +505,9 @@ pub fn confirm(app: &mut VectorcraftApp, d: &crate::state::Dialog) -> Result<Val
|
||||
many => {
|
||||
let paths: Vec<&Value> = many.iter().filter_map(|s| s.get("path")).collect();
|
||||
let files: Vec<&Value> = many.iter().filter(|s| s.get("path").is_none()).collect();
|
||||
let mut q = json!({ "paths": paths, "files": files, "link": link, "template": template });
|
||||
// The files of one dialog come from one `file.place`, with one importer plug-in and its
|
||||
// parameters, if any.
|
||||
let mut q = with_importer(json!({ "paths": paths, "files": files, "link": link, "template": template }), &many[0]);
|
||||
if !ask {
|
||||
// Each text file, DXF drawing and embedded PSD file in the cursor takes the options
|
||||
// confirmed last.
|
||||
@@ -770,21 +796,29 @@ pub fn drop_files(app: &mut VectorcraftApp, mut files: Vec<(DropTarget, DropFile
|
||||
}
|
||||
|
||||
/// Files that arrived to be placed (web): drops go where they were dropped, picked files to the
|
||||
/// Place dialog.
|
||||
/// Place dialog. One dialog holds the files of picks with one importer plug-in and its parameters
|
||||
/// ([`PlaceArrival::with`]); picked files with others, and picked files that arrive while a Place
|
||||
/// dialog is open, wait in the inbox until it closes.
|
||||
pub fn drain(app: &mut VectorcraftApp) {
|
||||
let arrived: Vec<PlaceArrival> =
|
||||
app.services.place_inbox.as_ref().map(|q| std::mem::take(&mut *q.lock().unwrap_or_else(|e| e.into_inner()))).unwrap_or_default();
|
||||
let mut picked = vec![];
|
||||
let open = app.ui.dialog.as_ref().is_some_and(|d| d.kind == crate::dialogs::place::KIND);
|
||||
let (mut picked, mut with, mut waiting) = (vec![], None::<Value>, vec![]);
|
||||
for a in arrived {
|
||||
match a.drop {
|
||||
Some(d) => drop_files(app, vec![(DropTarget::Place(d), (a.name, None, a.bytes))]),
|
||||
None if open || with.as_ref().is_some_and(|w| *w != a.with) => waiting.push(a),
|
||||
None => {
|
||||
picked.push(json!({ "name": a.name }));
|
||||
picked.push(with_importer(json!({ "name": a.name }), &a.with));
|
||||
app.place.picked.retain(|(n, _)| *n != a.name);
|
||||
with = Some(a.with);
|
||||
app.place.picked.push((a.name, a.bytes));
|
||||
}
|
||||
}
|
||||
}
|
||||
if let (false, Some(q)) = (waiting.is_empty(), app.services.place_inbox.as_ref()) {
|
||||
q.lock().unwrap_or_else(|e| e.into_inner()).splice(0..0, waiting);
|
||||
}
|
||||
if !picked.is_empty() {
|
||||
open_dialog(app, picked);
|
||||
}
|
||||
|
||||
@@ -131,8 +131,9 @@ pub struct Services {
|
||||
/// Show an open dialog for several files of the pick's types (a script's `File.openDialog` with
|
||||
/// `multiSelect`); returns their paths (none: cancelled). Without it, an open dialog for one.
|
||||
pub pick_open_files: Option<PickOpenFiles>,
|
||||
/// Web: start an async pick of files to place (they arrive via `place_inbox`).
|
||||
pub place_async: Option<Box<dyn FnMut()>>,
|
||||
/// Web: start an async pick of files to place (they arrive via `place_inbox`), each with the
|
||||
/// importer plug-in and parameters given ([`place::PlaceArrival::with`]).
|
||||
pub place_async: Option<Box<dyn FnMut(serde_json::Value)>>,
|
||||
/// Files that arrived asynchronously to be placed (web: picked for Place, or dropped on the
|
||||
/// canvas).
|
||||
pub place_inbox: Option<place::PlaceInbox>,
|
||||
|
||||
@@ -417,8 +417,9 @@ fn a_file_read_after_another_document_became_active_lands_where_it_was_dropped()
|
||||
DropTarget::Place(d) => d,
|
||||
t => panic!("{t:?}"),
|
||||
};
|
||||
let arrive =
|
||||
|name: &str, drop| inbox.lock().unwrap().push(crate::place::PlaceArrival { name: name.into(), bytes: png(20, 10, 72.0), drop: Some(drop) });
|
||||
let arrive = |name: &str, drop| {
|
||||
inbox.lock().unwrap().push(crate::place::PlaceArrival { name: name.into(), bytes: png(20, 10, 72.0), drop: Some(drop), with: json!(null) })
|
||||
};
|
||||
// Dropped on A; another document opens while the file is read.
|
||||
let on_a = drop_on_active(&app);
|
||||
let want = Xf::new(rect, app.view().unwrap()).to_doc(pos);
|
||||
|
||||
+2
-1
@@ -13300,7 +13300,8 @@ their bounds, Save then asks for a name, and `warnings` holds the importer's war
|
||||
`place` (`place: true` in `document.formats` and `plugin.list`) also places its files: `file.place`, `file.place.info`
|
||||
and `file.place.queue` take `importer?: "plugin.<id>"` (one that sets `place` and lists the file's extension) and
|
||||
`params?`, and without `importer` a file no built-in format reads goes to the first such importer by id that lists its
|
||||
extension. The importer is given at most 128 MiB of the file (a larger file is refused from its size, before it is read)
|
||||
extension. The importer is given at most 128 MiB of the file (a larger file is refused from its size, with `importer`
|
||||
before any of it is read or decoded, and without it after its first 64 KiB are read or decoded)
|
||||
and `_context.mode` `"place"`; its objects, guides left out, are placed as one group named after the file, in the order
|
||||
it returned them, as one undo step, embedded whatever `link` says (`linked: false`). `plugin.run` of an importer is
|
||||
an error that names `document.open`. In the app, File › Open With lists the installed importers, and
|
||||
|
||||
+13
-7
@@ -59,18 +59,24 @@ An importer whose manifest has `"place": true` also places its files. `document.
|
||||
importers that set `place`: when no built-in format reads the file, the first such importer by id that lists its
|
||||
extension reads it, and `"importer": "plugin.<id>"` names one, which must set `place` and list the file's extension,
|
||||
also one a built-in format reads. `"params"?: {…}` holds its parameters, which take their defaults when left out. The
|
||||
importer is given at most 128 MiB of the file (a larger file is refused from its size, before it is read) and
|
||||
`_context.mode` `"place"`, and returns its objects as it does for File › Open. They are placed in the open document as
|
||||
importer is given at most 128 MiB of the file and `_context.mode` `"place"`, and returns its objects as it does for
|
||||
File › Open. They are placed in the open document as
|
||||
one group named after the file, in the order the importer returned them, at the place, size or object `at`, `rect`,
|
||||
`replace` and `template` give, as one undo step; guides are left out, and the group's box is the bounds of what the
|
||||
other objects draw. The file is embedded whatever `link`
|
||||
says, as a format that can't be linked is, and the reply's `linked` is `false`. A decline, invalid output, a trap or
|
||||
Cancel places nothing and leaves the document and its undo steps as they were. An importer without `place` is not used
|
||||
by File › Place, and naming it is an error. In the app, File › Place lists a placing importer's extensions under "All
|
||||
placeable files" and a filter of its own, named after the importer, and on the web its files dropped on the canvas are
|
||||
placed there (the desktop opens a dropped document, as it does an SVG); the importer then runs with its parameters'
|
||||
defaults. A file placed with `importer` goes to that importer without the import options File › Place shows for a
|
||||
text file, a DXF drawing, a PDF or a PSD file. These rules are VectorCraft's own.
|
||||
by File › Place, and naming it is an error. A larger file is refused from its size. With `importer`, a `path` is refused
|
||||
before any of it is read and `dataBase64` before any of it is decoded. Without `importer`, the first 64 KiB of the file
|
||||
are read or decoded first to look for a built-in format. The web's File › Place reads the picked file in the browser
|
||||
before the 128 MiB limit applies. In the app, File › Place lists a placing importer's extensions under "All placeable
|
||||
files" and a filter of its own, named after the importer. Extensions that a built-in format reads are left out of both,
|
||||
and an importer that lists only such extensions gets no filter. On the web, a dropped file that no built-in format
|
||||
reads, by its extension or its content, is placed on the canvas by the first placing importer by id that lists its
|
||||
extension (the desktop opens a dropped document, as it does an SVG); a dropped file that a built-in format reads goes
|
||||
to that format. The importer then runs with its parameters' defaults. A file placed with `importer` goes to that
|
||||
importer without the import options File › Place shows for a text file, a DXF drawing, a PDF or a PSD file. These rules
|
||||
are VectorCraft's own.
|
||||
|
||||
In the app, installed filters appear under **Object › Plug-ins**, next to **Install Plug-in…** and **Reload
|
||||
Plug-ins**; live effects under **Effect › Plug-ins** and in the Appearance panel's effect menu. A plug-in with
|
||||
|
||||
@@ -2645,7 +2645,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
|
||||
- **Exporter plug-ins (G17):** a WebAssembly plug-in of kind `exporter` adds a write-only file format. File › Export › Export As lists it after the built-in formats, with Use Artboards greyed out (the plug-in writes the whole document) and its parameters in a generated dialog once the file is picked; `document.export` writes it by its format id, `plugin.<id>`, or by one of its extensions, and built-in formats keep theirs. The plug-in is given the native file's JSON (large images without their data) and `_context` (`mode`, `extension`, `name`), with 10 G instructions plus 4,000 per byte of input and 300 s, and Background Export's Cancel stops it between two slices of that budget. A decline or invalid output writes nothing; its warnings come back with the export's. Regressions: `crates/engine/tests/plugin_export.rs`, `crates/plugins/tests/abi.rs`, `crates/ui-egui/src/dialogs/tests_plugin_export.rs`. Scores and hours unchanged.
|
||||
- **Importer plug-ins (G17):** a WebAssembly plug-in of kind `importer` adds a read-only file format, as [the help page](https://ai-sdk-2020.84.nz/html/struct_a_i_file_format_suite) describes for file format plug-ins that read: File › Open lists its files under "All readable files" and its own filter, and File › Open With lists each importer by name. `document.open` uses it for a file whose extension no built-in format reads, by content or extension (the importer whose id sorts first, when several list the extension), or the one `importer` names, also for an extension a built-in format reads; a damaged file of a built-in format reports that format's error. The plug-in is given at most 128 MiB of the file and `_context` (`mode: "import"`, `extension`, `name`), and returns paths and compound paths in the filters' object JSON, checked as a filter's output is; they become a new document whose artboard is their bounds, which Save asks a name for. A decline, invalid output, a trap or Cancel opens nothing. The routing rule, the limit and Open With are VectorCraft's own. Regressions: `crates/engine/tests/plugin_import.rs`, `crates/plugins/src/import.rs`, `crates/ui-egui/src/dialogs/tests_plugin_import.rs`. Scores and hours unchanged.
|
||||
- **Importer plug-ins place their files (G17):** an importer whose manifest has `"place": true` also reads its files for File › Place, which lists them under "All placeable files" and a filter named after the importer. `file.place`, `file.place.info` and `file.place.queue` use the importer `importer` names, which must set `place`, or, for a file no built-in format reads, the first such importer by id that lists its extension. It is given at most 128 MiB of the file (a larger file is refused from its size before it is read) and `_context.mode` `"place"`, and its objects are placed as one group named after the file, in the order it returned them, at `at`, in `rect`, over the object Replace swaps or on a template layer, as one undo step, embedded whatever `link` says. A decline, invalid output, a trap or Cancel places nothing and leaves the undo steps as they were; an importer without `place` is not used by File › Place. These rules are VectorCraft's own. Regressions: `crates/engine/tests/plugin_place.rs`, `crates/plugins/src/manifest.rs`. Scores and hours unchanged.
|
||||
- **Importer plug-ins place their files (G17):** an importer whose manifest has `"place": true` also reads its files for File › Place, which lists them under "All placeable files" and a filter named after the importer. `file.place`, `file.place.info` and `file.place.queue` use the importer `importer` names, which must set `place`, or, for a file no built-in format reads, the first such importer by id that lists its extension. It is given at most 128 MiB of the file (a larger file is refused from its size, before any of it is read when `importer` names the importer) and `_context.mode` `"place"`, and its objects are placed as one group named after the file, in the order it returned them, at `at`, in `rect`, over the object Replace swaps or on a template layer, as one undo step, embedded whatever `link` says. A decline, invalid output, a trap or Cancel places nothing and leaves the undo steps as they were; an importer without `place` is not used by File › Place. These rules are VectorCraft's own. Regressions: `crates/engine/tests/plugin_place.rs`, `crates/plugins/src/manifest.rs`. Scores and hours unchanged.
|
||||
|
||||
- **Plug-in parameters as their manifest presents them (G17):** each parameter may have a `label`, a `unit` shown after its value, `help` on its label and a `helpUrl` page opened from a button, a `group` (sections that fold, after the parameters outside any group) and a `visibleWhen` that shows it only while the checkboxes and choices it names have one of the listed values (a hidden parameter still goes to the plug-in). `string` and `numberList` parameters join number, int, bool and choice, and a plug-in declares up to 256 parameters, at most 64 outside groups. The filter, live-effect and exporter dialogs use these keys, and the Appearance panel's effect editor the labels, units, help and conditions; hosts from before them ignore them. Regressions: `crates/plugins/src/dialog.rs`, `crates/plugins/src/manifest.rs`, `crates/ui-egui/src/dialogs/tests_plugin_fields.rs`, `crates/ui-egui/src/panels/appearance.rs`. Scores and hours unchanged.
|
||||
- **Live-effect plug-ins read their object's paints (G17):** a live effect is given the object's `fills` and `strokes` as a filter gets them, read only, and `_context.item` (`"object"`, or the fill or stroke whose own effects hold it); the result is cached by paint too, so a change of paint runs it again. Regressions: `crates/engine/src/tests/plugins.rs`, `crates/plugins/src/effect.rs`. Scores and hours unchanged.
|
||||
|
||||
Reference in new issue
Block a user