Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

Each release is a heading with its tag. The release workflow uses the words under it as the release's notes.

## v2.0.2

- A sheet that's open while it's built ends showing the right status line and cell. Before, when the last push and the save sent the same page, the status line went back to "Loading…" and the cell's address to A1. The same happened after a push that changed only the description, and in a tab that had nothing to compare the page with, the grid, tabs and charts emptied. The page now draws again, where the person is, after every whole page.
- The folder's hash is `4d046be9c48c`.

## v2.0.1

- On a phone the sheet starts on the first screen. The description folds to two lines with "more", and the two downloads sit under one Download button.
Expand Down
14 changes: 9 additions & 5 deletions sheets/references/sheet-template.html
Original file line number Diff line number Diff line change
Expand Up @@ -1309,14 +1309,18 @@ <h1 data-ss-id="title">SHEET TITLE</h1>
placing = true; render(); select(state.sel); if (i >= 0) putBack(p); if (drafting()) { state.refocus = true; renderBar(); }
placing = false; keepPlace();
}
// A whole page with the same data (a save straight after a push, a new description) still lays the page's source
// over what this script drew: the status line and the cell's address, and with no earlier page to compare against,
// the grid, tabs and charts too. So it's all drawn again, where the person is.
function redraw() { var p = kept; placing = true; render(); select(state.sel); if (p) putBack(p); placing = false; keepPlace(); }
// A batch the agent pushes while it builds replaces #sheet-delta, and the page's "ss:live" event names
// it. It lands outlined, on its own tab unless the person picked one.
document.addEventListener("ss:live", function (e) {
var ids = (e.detail && e.detail.ids) || [];
if (ids.indexOf("sheet-data") >= 0 && text("sheet-data") !== dataText) return retake();
if (ids.indexOf("sheet-delta") < 0 || text("sheet-delta") === deltaText) return;
deltaText = text("sheet-delta");
if (/^\s*(\{\s*\})?\s*$/.test(deltaText)) return; // emptied by a whole-page update: nothing to draw
var ids = (e.detail && e.detail.ids) || [], whole = ids.indexOf("sheet-data") >= 0; // a whole page names every block
if (whole && text("sheet-data") !== dataText) return retake();
var batch = ids.indexOf("sheet-delta") >= 0 && text("sheet-delta") !== deltaText;
if (batch) deltaText = text("sheet-delta");
if (!batch || /^\s*(\{\s*\})?\s*$/.test(deltaText)) { if (whole) redraw(); return; } // no new batch (one a whole page emptied included)
var r = E.applyDelta(data, deltaText);
if (!r.ok) { var st = document.getElementById("status"); st.textContent = "A batch of cells wasn't shown: " + r.why + "."; st.className = "status err"; return; }
var now = Date.now(), tn = r.tab.toLowerCase();
Expand Down
36 changes: 35 additions & 1 deletion tests/live.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,44 @@ module.exports = function ({ E, test, script, PAGE, ROOT }) {
const ui = script("sheet-ui");
assert.match(ui, /function text\(id\) \{ var n = document\.getElementById\(id\); return n \? n\.textContent : ""; \}/);
assert.match(ui, /data = JSON\.parse\(dataText\)/);
assert.match(ui, /if \(ids\.indexOf\("sheet-data"\) >= 0 && text\("sheet-data"\) !== dataText\) return retake\(\);/);
assert.match(ui, /whole = ids\.indexOf\("sheet-data"\) >= 0;/);
assert.match(ui, /if \(whole && text\("sheet-data"\) !== dataText\) return retake\(\);/);
for (const id of ["sheet-engine", "sheet-ui"]) assert.doesNotMatch(script(id), /innerHTML|outerHTML|insertAdjacentHTML|document\.write|new Function|\beval\(/, id);
assert.doesNotMatch(PAGE.match(/<input id="fx"[^>]*>/)[0], /disabled/); // a whole-page update never disables the bar someone types in
});
// Wherever the morph can't tell the pushed page's source from what the page's script drew, it puts the source back:
// always the status line and the cell's address; also the grid, tabs and charts when it has no earlier page to
// compare against. So a whole page with the same data (a save straight after a push of the same page) must still
// make the page draw again. This runs the page's own "ss:live" listener with the blocks as each kind of update
// leaves them.
test("after a whole page with the same data, the page draws again where the person is", () => {
const ui = script("sheet-ui");
const src = /document\.addEventListener\("ss:live", (function \(e\) \{[\s\S]*?\n \})\);/.exec(ui)[1];
const DATA = JSON.stringify(sheet()), ALL = ["title", "lede", "what-changed", "sheet-data", "sheet-delta"];
function live(blocks, detail, was = { data: DATA, delta: "{}" }) {
const calls = [], d = JSON.parse(DATA), state = { ver: 0, sel: "B3", picked: true, draft: null, tab: 1 };
const on = new Function("text", "retake", "redraw", "render", "select", "E", "data", "state", "stamps", "dataText", "deltaText", "savedAt", "return " + src)(
(id) => blocks[id], () => calls.push("retake"), () => calls.push("redraw"), () => calls.push("render"), () => {}, E, d, state, {}, was.data, was.delta, 0);
on({ detail });
return { calls, d };
}
const same = { "sheet-data": DATA, "sheet-delta": "{}" };
// the save of the very page the last push drew, or a page with only a new description: drawn again
assert.deepStrictEqual(live(same, { mode: "morph", ids: ALL }).calls, ["redraw"]);
assert.deepStrictEqual(live(same, { mode: "stream", ids: ALL }).calls, ["redraw"]);
// a whole page that empties a batch block the page had drawn: drawn again, the batch not applied twice
assert.deepStrictEqual(live(same, { mode: "morph", ids: ALL }, { data: DATA, delta: '{"tab":"Budget","cells":{"A2":"x"}}' }).calls, ["redraw"]);
// a whole page with new data: read again (which draws)
const moved = JSON.parse(DATA); moved.tabs[0].cells.B2 = 5;
assert.deepStrictEqual(live({ "sheet-data": JSON.stringify(moved), "sheet-delta": "{}" }, { mode: "morph", ids: ALL }).calls, ["retake"]);
// a batch: applied and drawn once, not drawn again on top
const b = live({ "sheet-data": DATA, "sheet-delta": JSON.stringify({ tab: "Budget", cells: { A2: "Rent", B2: 1200 } }) }, { mode: "patch", ids: ["sheet-delta"] });
assert.deepStrictEqual(b.calls, ["render"]);
assert.strictEqual(b.d.tabs[0].cells.B2, 1200);
// an update that names neither block (a save that changed only the title), or a batch already drawn: nothing drawn
assert.deepStrictEqual(live(same, { mode: "diff", ids: ["title"] }).calls, []);
assert.deepStrictEqual(live(same, { mode: "patch", ids: ["sheet-delta"] }).calls, []);
});

test("a person's typing and place outlast a batch, a rewrite and a reload", () => {
const ui = script("sheet-ui");
Expand Down
Loading