feat(block-editor): add Test Block preview

Preview the current unsaved block in a disposable drawing with independent history. Keep normal Draw tools available, append Close Test Block, and return to the original editor without saving. Guard persistence paths and handle refresh and parent-close lifecycle by stable document identity.
This commit is contained in:
Karim Jerbi committed 2026-10-14 14:44:58 +01:00
1 parent 0a29be07f7
commit 9632979d09
22 files changed
+801 -65

No files matched your search

+6
View File
@@ -410,6 +410,12 @@ impl OpenCADStudio {
/// this needs no undo snapshot. Format follows the path extension.
#[cfg(not(target_arch = "wasm32"))]
pub(super) fn control_wblock(&mut self, req: &Value) -> Result<Task<Message>, Value> {
if self.tabs[self.active_tab].block_test.is_some() {
return Err(failure(
"temporary_document",
"Test Block is temporary and cannot be saved",
));
}
let path = string(req, "path")?;
let document = &self.tabs[self.active_tab].scene.document;
// A template base keeps its tables/styles in the exported file
+12
View File
@@ -1148,6 +1148,12 @@ impl OpenCADStudio {
"view_focus" => self.control_view_focus(req)?,
#[cfg(not(target_arch = "wasm32"))]
"save" => {
if self.tabs[i].block_test.is_some() {
return Err(failure(
"temporary_document",
"Test Block is temporary and cannot be saved",
));
}
let path = req["path"]
.as_str()
.map(std::path::PathBuf::from)
@@ -1198,6 +1204,12 @@ impl OpenCADStudio {
// Web: no filesystem path; the drawing comes back in the reply.
#[cfg(target_arch = "wasm32")]
"save" => {
if self.tabs[i].block_test.is_some() {
return Err(failure(
"temporary_document",
"Test Block is temporary and cannot be saved",
));
}
use base64::Engine as _;
let default_is_dxf = crate::io::source_is_dxf(None, &self.tabs[i].scene.document);
let (version, is_dxf) = super::automation::requested_save_target(
+4 -1
View File
@@ -20,7 +20,10 @@ impl OpenCADStudio {
self.set_control_result(json!({ "closed": false, "reason": "start_page" }));
return Ok(Task::none());
}
if self.tabs[index].dirty && !req["discard"].as_bool().unwrap_or(false) {
if self.tabs[index].dirty
&& self.tabs[index].block_test.is_none()
&& !req["discard"].as_bool().unwrap_or(false)
{
return Err(failure(
"document_dirty",
"Save the document or pass discard:true",