DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Q: Content Collector and Placer
Brandon Thomas4eed1d317716
diff --git a/ROADMAP.md b/ROADMAP.mdindex 2723a3141..ba85dc171 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -77,6 +77,7 @@ DesignCraft aims at full Adobe InDesign parity — and to be better: faster, ope- Gap tool (U, `gap.move`): drag the space between objects (or an object and the page edge) and both sides resize.- XML basics (`xml.newTag/deleteTag/tag/mapStyle/structure`, `file.exportXml`, `file.importXml`; Tags panel with structure; View ▸ Show Tagged Frames): tagged frames export in reading order, mapped paragraph styles become elements, imported elements flow into frames with matching tags. Inline text tagging and DTDs aren't there yet.- Adjust Layout / Layout Adjustment (`adjustLayout` on Document Setup and Margins and Columns): objects follow each page's margin box to its new size and position.+- Content Collector and Placer tools (B; `conveyor.collect/place/list/clear`): copies of objects (with stories, styles, images) ride a conveyor between pages and documents; Alt-click keeps them on it.- Drag and drop text editing: drag selected text to move it (Alt copies) with its formatting (`text.release`).- Image Import Options: place any page of a multi-page PDF (`file.place {pdfPage}`; the app asks which page), shown on screen and embedded as that page in PDF export.- Define Lists: named numbered lists that continue across stories in page order (`list.define`, paragraph `listName` / `startAt`), round-tripped through IDML; `null` in `type.para` / `type.char` now removes an override.diff --git a/crates/engine/src/cmd/library.rs b/crates/engine/src/cmd/library.rsindex e0ecc7383..465d79f78 100644--- a/crates/engine/src/cmd/library.rs+++ b/crates/engine/src/cmd/library.rs@@ -113,6 +113,46 @@ pub fn specs() -> Vec<CommandSpec> {lib.save()?;ok()}),+ cmd!(noundo "conveyor.collect", "Collect", [], None, "{ids? (default: the selection)} — each object onto the Content Collector conveyor → {count}", has_selection, |s, p| {+ let ids = super::ids_param(p, "ids").unwrap_or_else(|| s.active().map(|d| d.selection.items.clone()).unwrap_or_default());+ let keep = s.active().map(|d| d.selection.clone());+ for id in ids {+ let name = s.doc()?.doc.item(id).map(|it| it.default_label().trim_matches(|c| c == '<' || c == '>').to_string()).unwrap_or_default();+ if let Ok(st) = s.doc_mut() {+ st.selection = designcraft_doc::Selection::items(vec![id]);+ }+ let snip = super::file::snippet_bytes(s)?;+ s.conveyor.push((name, snip));+ }+ if let (Some(k), Ok(st)) = (keep, s.doc_mut()) {+ st.selection = k;+ }+ Ok(json!({"count": s.conveyor.len()}))+ }),+ cmd!(+ "conveyor.place",+ "Place",+ [],+ None,+ "{index? (0), spread?, x?, y?, keep?: bool (stay on the conveyor)} — the Content Placer: the collected object at x/y (top-left)",+ has_doc,+ |s, p| {+ let i = p.get("index").and_then(Value::as_u64).unwrap_or(0) as usize;+ let (_, snip) = s.conveyor.get(i).cloned().ok_or_else(|| bad("conveyor.place", "the conveyor is empty"))?;+ let mut q = p.clone();+ q["base64"] = json!(super::file::base64_encode(&snip));+ let r = super::file::snippet_place(s, &q)?;+ if !p.get("keep").and_then(Value::as_bool).unwrap_or(false) {+ s.conveyor.remove(i);+ }+ Ok(r)+ }+ ),+ cmd!(query "conveyor.list", "Conveyor", [], None, "{} → [name]", always, |s, _| Ok(json!(s.conveyor.iter().map(|c| c.0.clone()).collect::<Vec<_>>()))),+ cmd!(noundo "conveyor.clear", "Clear Conveyor", [], None, "{}", always, |s, _| {+ s.conveyor.clear();+ ok()+ }),cmd!(noundo "library.close", "Close Library", [], None, "{}", has_library, |s, _| {s.library = None;ok()@@ -153,4 +193,22 @@ mod tests {assert!(t.execute("library.list", &json!({})).unwrap().as_array().unwrap().is_empty());std::fs::remove_dir_all(&dir).ok();}++ #[test]+ fn content_collector_and_placer() {+ let mut s = Session::new();+ s.execute("file.new", &json!({"pages": 2})).unwrap();+ let a = s.execute("frame.create", &json!({"rect": [72, 72, 172, 122], "content": "text", "text": "Reused", "caret": false})).unwrap()["id"]+ .clone();+ let b = s.execute("frame.create", &json!({"rect": [200, 72, 260, 122]})).unwrap()["id"].clone();+ assert_eq!(s.execute("conveyor.collect", &json!({"ids": [a, b]})).unwrap()["count"], 2);+ let r = s.execute("conveyor.place", &json!({"spread": 1, "x": 300, "y": 300})).unwrap();+ let id = designcraft_doc::ItemId(r["ids"][0].as_u64().unwrap());+ let d = &s.doc().unwrap().doc;+ assert_eq!(d.item(id).unwrap().bounds().x0, 300.0);+ assert!(d.find(id).is_some_and(|l| l.spread == designcraft_doc::SpreadRef::Doc(1)));+ assert_eq!(s.execute("conveyor.list", &json!({})).unwrap().as_array().unwrap().len(), 1, "placed objects leave the conveyor");+ s.execute("conveyor.place", &json!({"keep": true})).unwrap();+ assert_eq!(s.execute("conveyor.list", &json!({})).unwrap().as_array().unwrap().len(), 1);+ }}diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rsindex 629266907..f9677b603 100644--- a/crates/engine/src/lib.rs+++ b/crates/engine/src/lib.rs@@ -201,6 +201,8 @@ pub struct Session {pub(crate) text_drag: bool,/// The open Object Library (File › New / Open Library).pub library: Option<cmd::library::Library>,+ /// Content Collector conveyor: collected objects as snippets (name, bytes).+ pub conveyor: Vec<(String, Vec<u8>)>,}impl Default for Session {@@ -226,6 +228,7 @@ impl Session {transforms: Default::default(),text_drag: false,library: None,+ conveyor: Vec::new(),untitled: 0,}}diff --git a/crates/tools/src/lib.rs b/crates/tools/src/lib.rsindex 3238f000b..7744f97a0 100644--- a/crates/tools/src/lib.rs+++ b/crates/tools/src/lib.rs@@ -279,6 +279,8 @@ pub fn create(id: &str) -> Box<dyn Tool> {"page" => Box::new(nav::PageTool),"typeOnPath" => Box::new(nav::PathTypeTool),"gap" => Box::new(nav::GapTool::default()),+ "contentCollector" => Box::new(nav::ConveyorTool::new(false)),+ "contentPlacer" => Box::new(nav::ConveyorTool::new(true)),other => Box::new(NoopTool(tool_info(other).map(|t| t.id).unwrap_or("selection"))),}}diff --git a/crates/tools/src/nav.rs b/crates/tools/src/nav.rsindex 773f30394..e9a0b8546 100644--- a/crates/tools/src/nav.rs+++ b/crates/tools/src/nav.rs@@ -253,3 +253,39 @@ impl Tool for GapTool {self.active}}++/// Content Collector (B): click objects to put copies on the conveyor. Content Placer: click to+/// place the next collected object there.+pub struct ConveyorTool {+ placer: bool,+}++impl ConveyorTool {+ pub fn new(placer: bool) -> Self {+ Self { placer }+ }+}++impl Tool for ConveyorTool {+ fn id(&self) -> &'static str {+ if self.placer { "contentPlacer" } else { "contentCollector" }+ }++ fn pointer(&mut self, cx: &ToolContext, ev: &PointerEvent) -> Vec<Action> {+ if ev.kind != PointerKind::Down {+ return vec![];+ }+ if self.placer {+ let Some((sr, p)) = cx.layout.spread_at(ev.pos) else { return vec![] };+ return vec![Action::Exec("conveyor.place".into(), json!({"spread": crate::spread_json(sr), "x": p.x, "y": p.y, "keep": ev.mods.alt}))];+ }+ match cx.hit(ev.pos) {+ Some((_, id)) => vec![Action::Exec("conveyor.collect".into(), json!({"ids": [id.0]}))],+ None => vec![],+ }+ }++ fn cursor(&self, _cx: &ToolContext, _p: Point, _m: Mods) -> Cursor {+ Cursor::Crosshair+ }+}diff --git a/crates/ui-egui/src/panels/library.rs b/crates/ui-egui/src/panels/library.rsindex 52f936094..40e61bbd8 100644--- a/crates/ui-egui/src/panels/library.rs+++ b/crates/ui-egui/src/panels/library.rs@@ -8,6 +8,20 @@ use crate::theme::Tokens;pub fn show(app: &mut DesignApp, ui: &mut egui::Ui) {let t = Tokens::get(ui.ctx());+ // Content Collector conveyor.+ let conveyor = app.session.conveyor.iter().map(|c| c.0.clone()).collect::<Vec<_>>();+ ui.label(egui::RichText::new(format!("Conveyor ({})", conveyor.len())).strong());+ if conveyor.is_empty() {+ ui.label(+ egui::RichText::new("Collect objects with the Content Collector (B); place them with the Content Placer.").size(10.5).color(t.text_dim),+ );+ } else {+ ui.label(egui::RichText::new(conveyor.join(", ")).size(10.5));+ if ui.small_button("Clear").clicked() {+ let _ = app.run("conveyor.clear", json!({}));+ }+ }+ ui.separator();ui.horizontal(|ui| {if ui.button("New Library…").clicked() {let path = app.services.pick_save.as_mut().and_then(|f| f("Library.dclib"));diff --git a/docs/parity.md b/docs/parity.mdindex c1ed7b462..09c42efa2 100644--- a/docs/parity.md+++ b/docs/parity.md@@ -11,7 +11,7 @@ Each row of the InDesign feature catalogue is scored **D** (done), **P** (partia|---|---|---|---|---|---|| P0 | 102 | 99 | 3 | 0 | 99% || P1 | 97 | 92 | 4 | 1 | 97% |-| P2 | 76 | 29 | 18 | 29 | 50% |+| P2 | 76 | 30 | 18 | 28 | 51% || Area | Parity ||---|---|@@ -30,7 +30,7 @@ Each row of the InDesign feature catalogue is scored **D** (done), **P** (partia| Long documents | 88% || Interactivity & digital | 75% || Output & production | 78% |-| XML & automation | 72% |+| XML & automation | 83% || View & navigation | 88% || Undo, history, saving | 100% || Accessibility | 70% |@@ -293,7 +293,7 @@ Open P0 items: Preferences, Vector/page formats (PDF/AI/SVG/EPS place), Export t| XML & automation | Data Merge | P2 | D || XML & automation | Scripts panel | P2 | P || XML & automation | Script Label | P2 | D |-| XML & automation | Content Collector/Placer | P2 | M |+| XML & automation | Content Collector/Placer | P2 | D || XML & automation | Snippets | P1 | D || XML & automation | Object Library | P2 | D || View & navigation | Zoom commands | P0 | D |