The source arrives laid out, and a link that carried it follows it
Closes #28.
The Format button goes. A source arrives laid out, so nobody has to ask for it, and a page opened by a link that carried the source keeps the link in step with it.
What changes
- A source arrives laid out. One opened from a link or a file, or pasted over all of the text (or into an empty editor), is laid out, two spaces and a field to a line, and taken out of the code fence a chat put it in. A paste into the text goes in as it is, and so does text that is not JSON: the line under the source says where it stops being JSON. Where the editor cannot load, the textarea lays a whole paste out too.
formatSourcemoves tojson-scan.ts, so the editor's chunk can use it without the author package. - A link that carried the source follows it. A page opened with
#source=replaces its address when the source changes to another JSON source: the source on one line, compressed with raw deflate where the browser hasCompressionStreamand that is shorter, so the link stays short to send on. It ishistory.replaceState, so the history gets no new entry and the page does not read the address back. A change of layout writes nothing, and text that is not JSON leaves the address as it was, so a link never carries a broken source. An emptied editor leaves#source=with nothing after it, so the next source is written; a link that could not be read gives way to the source the person writes. A page opened with no source in its address never writes one. The write waits for a pause in the typing, as Safari allows a hundred in thirty seconds, and one it refuses is tried again at the next change. index.njkandsite.css: the button and its row go. The line that says where the JSON is wrong keeps a line of its own, two below 700 px where its message wraps, so what is under it does not move as a mistake comes and goes: at 1100, 768 and 390 px the usual message moves it by 3 px at most, and a long one that wraps once more by a line; at 320 px every message wraps to three lines and moves it by one. The hint under the source says the two things above.docs/h5p-build-page.mdsays it, under The source editor, and linkseditor.tsandjson-scan.tsnow that both are onmain.
Nothing is sent anywhere: the address is written in the browser, and a fragment no server sees. The page's script is 396 kB (138 kB gzip), up 1 kB; the editor's chunk is the size it was.
Tested
pnpm build, pnpm typecheck and pnpm e2e: 35 pass, where 29 did. The Format test is two now: a whole paste laid out, out of its code fence, and any other paste as it is (into the text, or of text that is not JSON); and a file laid out, with no Format button on the page. A link's source is asserted laid out, and Tab leaves the editor for the next control. New:
- the address following a link's source: nothing written on arrival, one write for a new source, none for a change of layout or for text that is not JSON, no new history entry, a reload that builds what the address carries, and the next source written after the editor was emptied;
- a page opened with no source in its address writing none;
- a link that cannot be read giving way to the source the person writes;
- the JSON as it is where there is no
CompressionStream; - the textarea, where the editor cannot load, laying a whole paste out, and its link following it.
The tests that watch the page still fail on any policy report or page error. I looked at it in light and dark at desktop width and at 390 px, with a mistake in the JSON and without.