feat(view): explicit persist and nested-plan boundary
Add per-cell Persist backed by lib/writeback and /api/session/cell/persist. Reject nested foreign.session plans with a top-level diagnostic and tests.
This commit is contained in:
1 parent
7dc5e56850
commit
115d1f6c0b
7 files changed
+123
-6
No files matched your search
+41
-4
@@ -3300,6 +3300,20 @@ body.notebook-page .code-head .nb-cell-stdin {
|
||||
color: var(--nb-text);
|
||||
font: 0.62rem/1.2 var(--mono);
|
||||
}
|
||||
body.notebook-page .code-head .nb-persist {
|
||||
order: 6;
|
||||
padding: 0.14rem 0.4rem;
|
||||
border: 1px solid var(--nb-border);
|
||||
border-radius: 3px;
|
||||
background: var(--nb-bg);
|
||||
color: var(--nb-muted);
|
||||
font: 0.62rem/1.2 var(--sans);
|
||||
cursor: pointer;
|
||||
}
|
||||
body.notebook-page .code-head .nb-persist:hover {
|
||||
border-color: var(--nb-accent);
|
||||
color: var(--nb-strong);
|
||||
}
|
||||
body.notebook-page .code-head .nb-clean {
|
||||
order: 5;
|
||||
padding: 0.14rem 0.4rem;
|
||||
@@ -3315,7 +3329,7 @@ body.notebook-page .code-head .nb-clean:hover {
|
||||
color: var(--nb-strong);
|
||||
}
|
||||
body.notebook-page .code-head .nb-badge {
|
||||
order: 6;
|
||||
order: 7;
|
||||
padding: 0.14rem 0.34rem;
|
||||
border: 1px solid var(--nb-border);
|
||||
border-radius: 3px;
|
||||
@@ -3327,7 +3341,7 @@ body.notebook-page .code-head .nb-badge {
|
||||
body.notebook-page .nb-badge.ok { color: var(--nb-success); }
|
||||
body.notebook-page .nb-badge.bad { color: var(--nb-error); }
|
||||
body.notebook-page .code-head .code-actions {
|
||||
order: 7;
|
||||
order: 8;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.3rem;
|
||||
@@ -3694,6 +3708,23 @@ body.notebook-page .wb-source-text { color: var(--nb-text); }
|
||||
}).catch(function (e2) { status(String(e2)); });
|
||||
});
|
||||
}
|
||||
function bindPersist(el) {
|
||||
var btn = el.querySelector(".nb-persist");
|
||||
if (!btn || btn.dataset.bound) return;
|
||||
btn.dataset.bound = "1";
|
||||
btn.addEventListener("click", function (e) {
|
||||
e.preventDefault();
|
||||
var name = el.getAttribute("data-code-name") || "";
|
||||
if (!name) return;
|
||||
if (!live) {
|
||||
status("static export: persist is unavailable");
|
||||
return;
|
||||
}
|
||||
post("api/session/cell/persist", { cell: name, key: name }).then(function (r) {
|
||||
status(r.ok ? "persisted " + name : (r.error || "persist failed"));
|
||||
}).catch(function (e2) { status(String(e2)); });
|
||||
});
|
||||
}
|
||||
function renderRecord(name, rec) {
|
||||
var el = card(name);
|
||||
if (!el || !rec) return;
|
||||
@@ -3902,11 +3933,17 @@ body.notebook-page .wb-source-text { color: var(--nb-text); }
|
||||
ensureKernel(el, false);
|
||||
});
|
||||
}
|
||||
document.querySelectorAll(".code-card").forEach(bindClean);
|
||||
document.querySelectorAll(".code-card").forEach(function (el) {
|
||||
bindClean(el);
|
||||
bindPersist(el);
|
||||
});
|
||||
status("static export · preview only");
|
||||
return;
|
||||
}
|
||||
document.querySelectorAll(".code-card").forEach(bindClean);
|
||||
document.querySelectorAll(".code-card").forEach(function (el) {
|
||||
bindClean(el);
|
||||
bindPersist(el);
|
||||
});
|
||||
bind("nb-run-all", function () { runAll(false); });
|
||||
bind("nb-restart", function () { runAll(true); });
|
||||
bind("nb-interrupt", function () {
|
||||
|
||||
@@ -229,6 +229,11 @@ fn handle(root: &ViewRoot, request: Request) -> Result<()> {
|
||||
notebook_api::api_plan_value(&root.root, body)
|
||||
})
|
||||
}
|
||||
"/api/session/cell/persist" => {
|
||||
return api_debug_post(request, |body| {
|
||||
notebook_api::api_persist_cell(&root.root, body)
|
||||
})
|
||||
}
|
||||
"/api/session/interrupt" => {
|
||||
return api_debug_post(request, |body| {
|
||||
notebook_api::api_interrupt(&root.root, body)
|
||||
|
||||
@@ -170,6 +170,16 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
pub fn api_persist_cell(root: &Path, body: &str) -> serde_json::Value {
|
||||
let v = body_value(body);
|
||||
let cell = v.get("cell").and_then(|x| x.as_str()).unwrap_or("");
|
||||
let key = v.get("key").and_then(|x| x.as_str()).unwrap_or("");
|
||||
if cell.is_empty() {
|
||||
return err("missing cell".into());
|
||||
}
|
||||
with_session(root, body, "persisted", |s| s.persist_cell(cell, key))
|
||||
}
|
||||
|
||||
pub fn api_interrupt(root: &Path, body: &str) -> serde_json::Value {
|
||||
with_session(root, body, "interrupted", |s| s.interrupt())
|
||||
}
|
||||
|
||||
@@ -1260,6 +1260,7 @@ fn render_stmt(
|
||||
<code class="expr">`{name}` =</code>
|
||||
<span class="code-lang">{lang}</span>
|
||||
<button type="button" class="nb-clean" title="Clear this output">Clean</button>
|
||||
<button type="button" class="nb-persist" title="Persist this result with writeback">Persist</button>
|
||||
</div>
|
||||
<pre class="code-body"><code class="language-{lang}">{src}</code></pre>
|
||||
<div class="code-foot">
|
||||
@@ -1539,6 +1540,7 @@ pub(crate) fn render_code_assign_card(name: &str, lang: &str, source: &str) -> S
|
||||
<span class="code-name">{name}</span>
|
||||
<span class="code-lang">{lang}</span>
|
||||
<button type="button" class="nb-clean" title="Clear this output">Clean</button>
|
||||
<button type="button" class="nb-persist" title="Persist this result with writeback">Persist</button>
|
||||
</div>
|
||||
<pre class="code-body"><code class="language-{lang}">{src}</code></pre>
|
||||
<div class="code-foot">
|
||||
|
||||
Reference in new issue
Block a user