@estiva-app/protocol 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +74 -0
- package/dist/anchors.d.ts +69 -0
- package/dist/anchors.d.ts.map +1 -0
- package/dist/anchors.js +50 -0
- package/dist/anchors.js.map +1 -0
- package/dist/bridge-content.d.ts +17 -0
- package/dist/bridge-content.d.ts.map +1 -0
- package/dist/bridge-content.js +200 -0
- package/dist/bridge-content.js.map +1 -0
- package/dist/content.d.ts +9 -0
- package/dist/content.d.ts.map +1 -1
- package/dist/content.js +2 -1
- package/dist/content.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/render.d.ts +2 -0
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +4 -0
- package/dist/render.js.map +1 -1
- package/package.json +1 -1
- package/src/anchors.ts +76 -0
- package/src/bridge-content.ts +208 -0
- package/src/content.ts +15 -2
- package/src/index.ts +13 -1
- package/src/render.ts +5 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,80 @@ Every entry answers the wire question explicitly, including when the answer is
|
|
|
4
4
|
nothing (ADR 0002 §4b). A change to the bytes an app publishes is a MAJOR — in
|
|
5
5
|
`0.x`, a MINOR — even when no TypeScript signature moved.
|
|
6
6
|
|
|
7
|
+
## 0.11.0 — 2026-09-03
|
|
8
|
+
|
|
9
|
+
**Wire behaviour: unchanged.** No builder, tag layout, id computation or
|
|
10
|
+
signature input moved. This adds a reader for a tag SPEC §13.6 defines, and
|
|
11
|
+
nothing here writes one.
|
|
12
|
+
|
|
13
|
+
- **New: `anchors.ts` — a comment anchored to one block, SPEC §13.6.**
|
|
14
|
+
`BLOCK_ANCHOR_TAG`, `blockAnchorOf`, `resolveBlockAnchor`, and the
|
|
15
|
+
`BlockAnchor` union.
|
|
16
|
+
|
|
17
|
+
**`resolveBlockAnchor` returns which of four states an anchor is in, rather
|
|
18
|
+
than a block or `undefined`**, and that shape is the point. §13.6 requires a
|
|
19
|
+
reader to distinguish *unanchored*, *resolved*, *unaddressable* and
|
|
20
|
+
*detached*, because the pair that matters — detached and unanchored — render
|
|
21
|
+
identically and mean opposite things: a remark about a paragraph somebody
|
|
22
|
+
deleted, versus a remark about the whole object. A signature that lets a
|
|
23
|
+
caller collapse them is a signature that invites the defect.
|
|
24
|
+
|
|
25
|
+
Control: making `detached` return `unanchored` fails exactly the two tests
|
|
26
|
+
written to catch it.
|
|
27
|
+
|
|
28
|
+
- **`unaddressable` is its own state, not a kind of detachment.** Marker text
|
|
29
|
+
has no addressable sub-unit (§13.1), so an anchor against it never resolves
|
|
30
|
+
and nothing was deleted. A reader saying "that paragraph is gone" about a
|
|
31
|
+
marker-text description is wrong twice over.
|
|
32
|
+
|
|
33
|
+
- **A body that claims `blocks` and does not parse is `unaddressable`, not an
|
|
34
|
+
exception.** It has no parts either, and a reader that throws renders nothing
|
|
35
|
+
at all.
|
|
36
|
+
|
|
37
|
+
## 0.10.0 — 2026-09-02
|
|
38
|
+
|
|
39
|
+
**Wire behaviour: unchanged.** No builder, tag layout, id computation or
|
|
40
|
+
signature input moved. What this adds is the bridge that lets an app with a
|
|
41
|
+
*text* editor publish a **block document**, which is how a description acquires
|
|
42
|
+
addressable blocks before anybody builds a block editor.
|
|
43
|
+
|
|
44
|
+
- **New: `markerTextToBlockDocument` and `blockDocumentToMarkerText`.** Marker
|
|
45
|
+
text in, a §13.3 document out, and back again.
|
|
46
|
+
|
|
47
|
+
**`markerTextToBlockDocument` takes the previous document and carries its ids
|
|
48
|
+
across**, and that is the entire point rather than a nicety. A description is
|
|
49
|
+
replaced wholesale on every save; re-parsing into fresh blocks each time
|
|
50
|
+
re-mints every id, and **every comment anchored to one detaches silently** —
|
|
51
|
+
a detached comment renders exactly like one that was never anchored. The
|
|
52
|
+
matching rule is written down in the module header: same type and identical
|
|
53
|
+
text wherever it moved to, then same type at the same index, then a fresh id.
|
|
54
|
+
|
|
55
|
+
Its limit is documented *and asserted*: a block moved **and** edited in one
|
|
56
|
+
save matches neither pass and gets a new id. There is a test that fails if
|
|
57
|
+
that ever silently changes, so the header cannot drift from the behaviour.
|
|
58
|
+
|
|
59
|
+
Control: disabling the carry-forward fails 5 tests, including the corpus one.
|
|
60
|
+
|
|
61
|
+
- **An ordered list keeps the number its author wrote.** `BodySegment` of type
|
|
62
|
+
`numbered` gains `start`, `RenderBlock` gains `start`, and a block document
|
|
63
|
+
carries `attrs.start` — all absent when the list begins at 1.
|
|
64
|
+
|
|
65
|
+
This is a **pre-existing rendering defect**, not something the bridge
|
|
66
|
+
introduced. A body can hold two numbered runs split by a paragraph, the
|
|
67
|
+
second written `2.` to continue the first; every renderer built on
|
|
68
|
+
`parseBodySegments` has drawn it as `1.` since the dialect existed. One real
|
|
69
|
+
body in the 152-body corpus does exactly this, and the round trip is what
|
|
70
|
+
made it visible — renumbering somebody's list is a change to what they wrote,
|
|
71
|
+
and it would have been written back to the relay permanently once a
|
|
72
|
+
description is re-saved as blocks.
|
|
73
|
+
|
|
74
|
+
- **A NUL byte, removed from this package's own source.** `keyOf` used a
|
|
75
|
+
literal `\x00` as its separator, which makes a file *binary* to the tools
|
|
76
|
+
that read source: `grep` skips it and reports nothing, so a search for a
|
|
77
|
+
symbol in that file comes back empty and looks like an answer. Ship's
|
|
78
|
+
`fold.ts` carries a comment about this exact trap; this hit it anyway. It is
|
|
79
|
+
an escape now.
|
|
80
|
+
|
|
7
81
|
## 0.9.0 — 2026-09-02
|
|
8
82
|
|
|
9
83
|
**Wire behaviour: unchanged.** Nothing about the bytes moved. One function and
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A comment anchored to one block — SPEC §13.6, and RFC 0.4 §6's answer.
|
|
3
|
+
*
|
|
4
|
+
* The address says which object; a `block` tag says which part of it. That much
|
|
5
|
+
* is two lines. **The reason this is a module rather than two lines is the
|
|
6
|
+
* unhappy path**: an anchor outlives the thing it points at, and the ways it
|
|
7
|
+
* stops resolving are not the same as each other.
|
|
8
|
+
*
|
|
9
|
+
* §13.6 requires a reader to distinguish four outcomes, and the one that
|
|
10
|
+
* matters is `detached` versus `unanchored`. They render identically if you let
|
|
11
|
+
* them and they mean opposite things — one is a remark about the object, the
|
|
12
|
+
* other a remark about a paragraph somebody has since deleted. A reader that
|
|
13
|
+
* collapses them silently converts the second into the first, and nothing
|
|
14
|
+
* reports it.
|
|
15
|
+
*
|
|
16
|
+
* So {@link resolveBlockAnchor} returns which of the four it is, rather than a
|
|
17
|
+
* block or `undefined`. A caller that wants to be careless has to work at it.
|
|
18
|
+
*/
|
|
19
|
+
import { type Block } from './blocks.js';
|
|
20
|
+
import type { ContentFormat } from './render.js';
|
|
21
|
+
/** The tag SPEC §13.6 defines. */
|
|
22
|
+
export declare const BLOCK_ANCHOR_TAG = "block";
|
|
23
|
+
/**
|
|
24
|
+
* What an anchor resolved to.
|
|
25
|
+
*
|
|
26
|
+
* A discriminated union on purpose: the four states are not degrees of success,
|
|
27
|
+
* and a caller that treats "no anchor" and "the block is gone" as one thing has
|
|
28
|
+
* the defect §13.6 is about.
|
|
29
|
+
*/
|
|
30
|
+
export type BlockAnchor =
|
|
31
|
+
/** The comment carries no `block` tag. It is about the whole object. */
|
|
32
|
+
{
|
|
33
|
+
state: 'unanchored';
|
|
34
|
+
}
|
|
35
|
+
/** The tag names a block that is present. */
|
|
36
|
+
| {
|
|
37
|
+
state: 'resolved';
|
|
38
|
+
id: string;
|
|
39
|
+
block: Block;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The body is not a block document, so it has no parts to point at.
|
|
43
|
+
*
|
|
44
|
+
* Marker text has no addressable sub-unit (§13.1), so this is permanent for
|
|
45
|
+
* that body rather than a failure — it is what two content models means.
|
|
46
|
+
*/
|
|
47
|
+
| {
|
|
48
|
+
state: 'unaddressable';
|
|
49
|
+
id: string;
|
|
50
|
+
}
|
|
51
|
+
/** The tag names a block that is no longer in the document. */
|
|
52
|
+
| {
|
|
53
|
+
state: 'detached';
|
|
54
|
+
id: string;
|
|
55
|
+
};
|
|
56
|
+
/** The block id a comment anchors to, or `undefined` when it anchors to none. */
|
|
57
|
+
export declare function blockAnchorOf(event: {
|
|
58
|
+
tags: string[][];
|
|
59
|
+
}): string | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Which of §13.6's four states an anchor is in, against the body as it is now.
|
|
62
|
+
*
|
|
63
|
+
* `format` comes from the event carrying the *body* — `contentFormatOf` — and
|
|
64
|
+
* never from inspecting `value` (§13.4). Passing `'blocks'` for a body that
|
|
65
|
+
* does not parse yields `unaddressable` rather than throwing: a mis-tagged body
|
|
66
|
+
* has no parts either, and a reader that throws renders nothing at all.
|
|
67
|
+
*/
|
|
68
|
+
export declare function resolveBlockAnchor(id: string | undefined, value: string, format: ContentFormat): BlockAnchor;
|
|
69
|
+
//# sourceMappingURL=anchors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anchors.d.ts","sourceRoot":"","sources":["../src/anchors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAE,KAAK,KAAK,EAAqD,MAAM,aAAa,CAAA;AAC3F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAEhD,kCAAkC;AAClC,eAAO,MAAM,gBAAgB,UAAU,CAAA;AAEvC;;;;;;GAMG;AACH,MAAM,MAAM,WAAW;AACrB,wEAAwE;AACtE;IAAE,KAAK,EAAE,YAAY,CAAA;CAAE;AACzB,6CAA6C;GAC3C;IAAE,KAAK,EAAE,UAAU,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE;AACjD;;;;;GAKG;GACD;IAAE,KAAK,EAAE,eAAe,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE;AACxC,+DAA+D;GAC7D;IAAE,KAAK,EAAE,UAAU,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CAAA;AAErC,iFAAiF;AACjF,wBAAgB,aAAa,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,EAAE,EAAE,CAAA;CAAE,GAAG,MAAM,GAAG,SAAS,CAG7E;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,MAAM,GAAG,SAAS,EACtB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,aAAa,GACpB,WAAW,CAWb"}
|
package/dist/anchors.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A comment anchored to one block — SPEC §13.6, and RFC 0.4 §6's answer.
|
|
3
|
+
*
|
|
4
|
+
* The address says which object; a `block` tag says which part of it. That much
|
|
5
|
+
* is two lines. **The reason this is a module rather than two lines is the
|
|
6
|
+
* unhappy path**: an anchor outlives the thing it points at, and the ways it
|
|
7
|
+
* stops resolving are not the same as each other.
|
|
8
|
+
*
|
|
9
|
+
* §13.6 requires a reader to distinguish four outcomes, and the one that
|
|
10
|
+
* matters is `detached` versus `unanchored`. They render identically if you let
|
|
11
|
+
* them and they mean opposite things — one is a remark about the object, the
|
|
12
|
+
* other a remark about a paragraph somebody has since deleted. A reader that
|
|
13
|
+
* collapses them silently converts the second into the first, and nothing
|
|
14
|
+
* reports it.
|
|
15
|
+
*
|
|
16
|
+
* So {@link resolveBlockAnchor} returns which of the four it is, rather than a
|
|
17
|
+
* block or `undefined`. A caller that wants to be careless has to work at it.
|
|
18
|
+
*/
|
|
19
|
+
import { findBlock, parseBlockDocument } from './blocks.js';
|
|
20
|
+
/** The tag SPEC §13.6 defines. */
|
|
21
|
+
export const BLOCK_ANCHOR_TAG = 'block';
|
|
22
|
+
/** The block id a comment anchors to, or `undefined` when it anchors to none. */
|
|
23
|
+
export function blockAnchorOf(event) {
|
|
24
|
+
const id = event.tags.find((t) => t[0] === BLOCK_ANCHOR_TAG)?.[1];
|
|
25
|
+
return id === undefined || id === '' ? undefined : id;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Which of §13.6's four states an anchor is in, against the body as it is now.
|
|
29
|
+
*
|
|
30
|
+
* `format` comes from the event carrying the *body* — `contentFormatOf` — and
|
|
31
|
+
* never from inspecting `value` (§13.4). Passing `'blocks'` for a body that
|
|
32
|
+
* does not parse yields `unaddressable` rather than throwing: a mis-tagged body
|
|
33
|
+
* has no parts either, and a reader that throws renders nothing at all.
|
|
34
|
+
*/
|
|
35
|
+
export function resolveBlockAnchor(id, value, format) {
|
|
36
|
+
if (id === undefined || id === '')
|
|
37
|
+
return { state: 'unanchored' };
|
|
38
|
+
if (format !== 'blocks')
|
|
39
|
+
return { state: 'unaddressable', id };
|
|
40
|
+
let document;
|
|
41
|
+
try {
|
|
42
|
+
document = parseBlockDocument(value);
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return { state: 'unaddressable', id };
|
|
46
|
+
}
|
|
47
|
+
const block = findBlock(document, id);
|
|
48
|
+
return block ? { state: 'resolved', id, block } : { state: 'detached', id };
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=anchors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anchors.js","sourceRoot":"","sources":["../src/anchors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAAkC,SAAS,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAG3F,kCAAkC;AAClC,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAA;AAwBvC,iFAAiF;AACjF,MAAM,UAAU,aAAa,CAAC,KAA2B;IACvD,MAAM,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IACjE,OAAO,EAAE,KAAK,SAAS,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAA;AACvD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAChC,EAAsB,EACtB,KAAa,EACb,MAAqB;IAErB,IAAI,EAAE,KAAK,SAAS,IAAI,EAAE,KAAK,EAAE;QAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,CAAA;IACjE,IAAI,MAAM,KAAK,QAAQ;QAAE,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,EAAE,EAAE,CAAA;IAC9D,IAAI,QAAuB,CAAA;IAC3B,IAAI,CAAC;QACH,QAAQ,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAA;IACtC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,EAAE,EAAE,CAAA;IACvC,CAAC;IACD,MAAM,KAAK,GAAG,SAAS,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IACrC,OAAO,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,CAAA;AAC7E,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type BlockDocument } from './blocks.js';
|
|
2
|
+
/**
|
|
3
|
+
* Marker text as a block document, keeping `previous`'s ids wherever a block
|
|
4
|
+
* still corresponds. The matching rule is in this module's header.
|
|
5
|
+
*/
|
|
6
|
+
export declare function markerTextToBlockDocument(text: string, previous?: BlockDocument): BlockDocument;
|
|
7
|
+
/**
|
|
8
|
+
* A block document back as marker text, for an editor that edits text.
|
|
9
|
+
*
|
|
10
|
+
* The inverse of {@link markerTextToBlockDocument} for everything the marker
|
|
11
|
+
* dialect can spell, which is everything that function can produce. A document
|
|
12
|
+
* written by a *block* editor may hold a table or a nested list, and §13.2 has
|
|
13
|
+
* no marker for either — those degrade to their text rather than vanishing,
|
|
14
|
+
* which is the rule §13.3 already gives a reader for an unknown block.
|
|
15
|
+
*/
|
|
16
|
+
export declare function blockDocumentToMarkerText(doc: BlockDocument): string;
|
|
17
|
+
//# sourceMappingURL=bridge-content.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge-content.d.ts","sourceRoot":"","sources":["../src/bridge-content.ts"],"names":[],"mappings":"AAuCA,OAAO,EAAc,KAAK,aAAa,EAAc,MAAM,aAAa,CAAA;AA0DxE;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,aAAa,GAAG,aAAa,CAwD/F;AAKD;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAoCpE"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marker text and block documents, converted between — the bridge across §13's
|
|
3
|
+
* two serialisations.
|
|
4
|
+
*
|
|
5
|
+
* SPEC §13 keeps the two content models apart on purpose, and nothing here
|
|
6
|
+
* softens that: a message is still marker text and a rich text field is still a
|
|
7
|
+
* block document. What this module does is let an app whose *editor* produces
|
|
8
|
+
* marker text publish a **block document** anyway, which is the only way a
|
|
9
|
+
* description acquires addressable blocks before somebody builds a block editor.
|
|
10
|
+
*
|
|
11
|
+
* ## The id carry-forward is the whole point
|
|
12
|
+
*
|
|
13
|
+
* A description is replaced wholesale on every save. If each save re-parses the
|
|
14
|
+
* text into fresh blocks, every block gets a new id, and **every comment
|
|
15
|
+
* anchored to one detaches** — silently, because a detached comment renders
|
|
16
|
+
* exactly like a comment that was never anchored. So
|
|
17
|
+
* {@link markerTextToBlockDocument} takes the previous document and carries ids
|
|
18
|
+
* across, by a rule written down here rather than left to be inferred:
|
|
19
|
+
*
|
|
20
|
+
* 1. **Same type and identical text** — reuse that block's id, wherever it
|
|
21
|
+
* moved to. This survives a reorder, and an edit to a *different* block.
|
|
22
|
+
* 2. **Same type at the same index**, among what is left — reuse that id. This
|
|
23
|
+
* survives editing a block's own text in place.
|
|
24
|
+
* 3. Anything still unmatched gets a fresh id.
|
|
25
|
+
*
|
|
26
|
+
* **What that rule does not survive, stated rather than discovered:** a block
|
|
27
|
+
* moved *and* edited in one save matches neither pass and gets a new id, so an
|
|
28
|
+
* anchor to it breaks. That is a real limit of reconstructing structure from
|
|
29
|
+
* text. It is acceptable because the anchor has to fail visibly anyway — a
|
|
30
|
+
* block can always be deleted outright, so a reader that cannot show a broken
|
|
31
|
+
* anchor is broken regardless of this rule.
|
|
32
|
+
*/
|
|
33
|
+
import { markersToInlineNodes, inlineNodesToMarkers, parseBodySegments, } from './content.js';
|
|
34
|
+
import { newBlockId } from './blocks.js';
|
|
35
|
+
const isInlineRun = (content) => Array.isArray(content) &&
|
|
36
|
+
content.length > 0 &&
|
|
37
|
+
typeof content[0] === 'object' &&
|
|
38
|
+
content[0] !== null &&
|
|
39
|
+
content[0].type === 'text';
|
|
40
|
+
/** A block's text, for matching. Cheap and stable: it is what the author sees. */
|
|
41
|
+
function textOf(block) {
|
|
42
|
+
if (!Array.isArray(block.content))
|
|
43
|
+
return '';
|
|
44
|
+
if (isInlineRun(block.content))
|
|
45
|
+
return block.content.map((n) => n.text).join('');
|
|
46
|
+
return block.content.map(textOf).join('\n');
|
|
47
|
+
}
|
|
48
|
+
/*
|
|
49
|
+
`\u0000` as an escape, never the byte. A separator has to be something a
|
|
50
|
+
block type cannot contain, and NUL is the right choice — but writing it
|
|
51
|
+
literally makes this file *binary* to the tools that read source: `grep`
|
|
52
|
+
skips it and says nothing, which is how this very line hid a control
|
|
53
|
+
character until a search for `previous` came back empty. Ship's `fold.ts`
|
|
54
|
+
carries the same warning for the same reason.
|
|
55
|
+
*/
|
|
56
|
+
const keyOf = (block) => `${block.type}\u0000${textOf(block)}`;
|
|
57
|
+
function blockFromSegment(seg) {
|
|
58
|
+
switch (seg.type) {
|
|
59
|
+
case 'heading':
|
|
60
|
+
return { type: 'heading', id: '', attrs: { level: seg.level }, content: markersToInlineNodes(seg.text) };
|
|
61
|
+
case 'bullet':
|
|
62
|
+
return {
|
|
63
|
+
type: 'bulletList',
|
|
64
|
+
id: '',
|
|
65
|
+
content: seg.items.map((item) => ({ type: 'listItem', id: '', content: markersToInlineNodes(item) })),
|
|
66
|
+
};
|
|
67
|
+
case 'numbered':
|
|
68
|
+
return {
|
|
69
|
+
type: 'orderedList',
|
|
70
|
+
id: '',
|
|
71
|
+
...(seg.start ? { attrs: { start: seg.start } } : {}),
|
|
72
|
+
content: seg.items.map((item) => ({ type: 'listItem', id: '', content: markersToInlineNodes(item) })),
|
|
73
|
+
};
|
|
74
|
+
case 'quote':
|
|
75
|
+
return { type: 'blockquote', id: '', content: markersToInlineNodes(seg.lines.join('\n')) };
|
|
76
|
+
case 'code':
|
|
77
|
+
return {
|
|
78
|
+
type: 'codeBlock',
|
|
79
|
+
id: '',
|
|
80
|
+
...(seg.language ? { attrs: { language: seg.language } } : {}),
|
|
81
|
+
// A fence is literal — its content is never mark-parsed.
|
|
82
|
+
content: [{ type: 'text', text: seg.lines.join('\n') }],
|
|
83
|
+
};
|
|
84
|
+
case 'text':
|
|
85
|
+
return { type: 'paragraph', id: '', content: markersToInlineNodes(seg.lines.join('\n')) };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Marker text as a block document, keeping `previous`'s ids wherever a block
|
|
90
|
+
* still corresponds. The matching rule is in this module's header.
|
|
91
|
+
*/
|
|
92
|
+
export function markerTextToBlockDocument(text, previous) {
|
|
93
|
+
const fresh = parseBodySegments(text).map(blockFromSegment);
|
|
94
|
+
const old = previous?.content ?? [];
|
|
95
|
+
const takenIds = new Set();
|
|
96
|
+
const usedOld = new Set();
|
|
97
|
+
// Pass 1 — same type and identical text, wherever it moved to.
|
|
98
|
+
const byKey = new Map();
|
|
99
|
+
old.forEach((block, i) => {
|
|
100
|
+
if (!block.id)
|
|
101
|
+
return;
|
|
102
|
+
const list = byKey.get(keyOf(block)) ?? [];
|
|
103
|
+
list.push(i);
|
|
104
|
+
byKey.set(keyOf(block), list);
|
|
105
|
+
});
|
|
106
|
+
const ids = fresh.map((block) => {
|
|
107
|
+
const candidates = byKey.get(keyOf(block));
|
|
108
|
+
while (candidates && candidates.length) {
|
|
109
|
+
const i = candidates.shift();
|
|
110
|
+
if (usedOld.has(i))
|
|
111
|
+
continue;
|
|
112
|
+
usedOld.add(i);
|
|
113
|
+
takenIds.add(old[i].id);
|
|
114
|
+
return old[i].id;
|
|
115
|
+
}
|
|
116
|
+
return undefined;
|
|
117
|
+
});
|
|
118
|
+
// Pass 2 — same type at the same index, among what is left.
|
|
119
|
+
fresh.forEach((block, i) => {
|
|
120
|
+
if (ids[i] !== undefined)
|
|
121
|
+
return;
|
|
122
|
+
const candidate = old[i];
|
|
123
|
+
if (!candidate || usedOld.has(i) || candidate.type !== block.type || !candidate.id)
|
|
124
|
+
return;
|
|
125
|
+
if (takenIds.has(candidate.id))
|
|
126
|
+
return;
|
|
127
|
+
usedOld.add(i);
|
|
128
|
+
takenIds.add(candidate.id);
|
|
129
|
+
ids[i] = candidate.id;
|
|
130
|
+
});
|
|
131
|
+
// Pass 3 — a fresh id for everything still unmatched, children included.
|
|
132
|
+
const mint = () => {
|
|
133
|
+
let id = newBlockId();
|
|
134
|
+
while (takenIds.has(id))
|
|
135
|
+
id = newBlockId();
|
|
136
|
+
takenIds.add(id);
|
|
137
|
+
return id;
|
|
138
|
+
};
|
|
139
|
+
const fill = (block, id) => {
|
|
140
|
+
const children = Array.isArray(block.content) && !isInlineRun(block.content)
|
|
141
|
+
? block.content.map((child) => fill(child))
|
|
142
|
+
: undefined;
|
|
143
|
+
return {
|
|
144
|
+
...block,
|
|
145
|
+
id: id ?? (block.id || mint()),
|
|
146
|
+
...(children ? { content: children } : {}),
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
return { type: 'doc', content: fresh.map((block, i) => fill(block, ids[i] || undefined)) };
|
|
150
|
+
}
|
|
151
|
+
const itemText = (item) => isInlineRun(item.content) ? inlineNodesToMarkers(item.content) : '';
|
|
152
|
+
/**
|
|
153
|
+
* A block document back as marker text, for an editor that edits text.
|
|
154
|
+
*
|
|
155
|
+
* The inverse of {@link markerTextToBlockDocument} for everything the marker
|
|
156
|
+
* dialect can spell, which is everything that function can produce. A document
|
|
157
|
+
* written by a *block* editor may hold a table or a nested list, and §13.2 has
|
|
158
|
+
* no marker for either — those degrade to their text rather than vanishing,
|
|
159
|
+
* which is the rule §13.3 already gives a reader for an unknown block.
|
|
160
|
+
*/
|
|
161
|
+
export function blockDocumentToMarkerText(doc) {
|
|
162
|
+
const lines = [];
|
|
163
|
+
for (const block of doc.content) {
|
|
164
|
+
const inline = isInlineRun(block.content) ? inlineNodesToMarkers(block.content) : '';
|
|
165
|
+
switch (block.type) {
|
|
166
|
+
case 'heading': {
|
|
167
|
+
const level = block.attrs?.level === 2 ? 2 : 1;
|
|
168
|
+
lines.push(`${'#'.repeat(level)} ${inline}`);
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
case 'bulletList':
|
|
172
|
+
for (const item of block.content ?? [])
|
|
173
|
+
lines.push(`- ${itemText(item)}`);
|
|
174
|
+
break;
|
|
175
|
+
case 'orderedList': {
|
|
176
|
+
const start = typeof block.attrs?.start === 'number' ? block.attrs.start : 1;
|
|
177
|
+
(block.content ?? []).forEach((item, i) => lines.push(`${start + i}. ${itemText(item)}`));
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
case 'blockquote':
|
|
181
|
+
for (const line of inline.split('\n'))
|
|
182
|
+
lines.push(`> ${line}`);
|
|
183
|
+
break;
|
|
184
|
+
case 'codeBlock': {
|
|
185
|
+
const language = typeof block.attrs?.language === 'string' ? block.attrs.language : '';
|
|
186
|
+
lines.push('```' + language, inline, '```');
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
case 'horizontalRule':
|
|
190
|
+
lines.push('---');
|
|
191
|
+
break;
|
|
192
|
+
default:
|
|
193
|
+
// A table, an attachment, a widget, or a type from a later version.
|
|
194
|
+
lines.push(inline || textOf(block));
|
|
195
|
+
}
|
|
196
|
+
lines.push('');
|
|
197
|
+
}
|
|
198
|
+
return lines.join('\n').replace(/\n+$/, '');
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=bridge-content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge-content.js","sourceRoot":"","sources":["../src/bridge-content.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,OAAO,EAGL,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAkC,UAAU,EAAE,MAAM,aAAa,CAAA;AAExE,MAAM,WAAW,GAAG,CAAC,OAAgB,EAA+B,EAAE,CACpE,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC;IACtB,OAAO,CAAC,MAAM,GAAG,CAAC;IAClB,OAAO,OAAO,CAAC,CAAC,CAAC,KAAK,QAAQ;IAC9B,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI;IAClB,OAAO,CAAC,CAAC,CAAwB,CAAC,IAAI,KAAK,MAAM,CAAA;AAEpD,kFAAkF;AAClF,SAAS,MAAM,CAAC,KAAY;IAC1B,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC;QAAE,OAAO,EAAE,CAAA;IAC5C,IAAI,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC;QAAE,OAAO,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAChF,OAAQ,KAAK,CAAC,OAAmB,CAAC,GAAG,C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AK,CAAC,OAAmB,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,GAAG,CAAC,KAAK,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAA;gBACvG,MAAK;YACP,CAAC;YACD,KAAK,YAAY;gBACf,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;oBAAE,KAAK,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAA;gBAC9D,MAAK;YACP,KAAK,WAAW,CAAC,CAAC,CAAC;gBACjB,MAAM,QAAQ,GAAG,OAAO,KAAK,CAAC,KAAK,EAAE,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAA;gBACtF,KAAK,CAAC,IAAI,CAAC,KAAK,GAAG,QAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;gBAC3C,MAAK;YACP,CAAC;YACD,KAAK,gBAAgB;gBACnB,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;gBACjB,MAAK;YACP;gBACE,oEAAoE;gBACpE,KAAK,CAAC,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;QACvC,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAChB,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;AAC7C,CAAC"}
|
package/dist/content.d.ts
CHANGED
|
@@ -43,6 +43,15 @@ export type BodySegment = {
|
|
|
43
43
|
} | {
|
|
44
44
|
type: 'numbered';
|
|
45
45
|
items: string[];
|
|
46
|
+
/**
|
|
47
|
+
* The number the author actually wrote, when it is not 1.
|
|
48
|
+
*
|
|
49
|
+
* A body can hold two numbered runs separated by a paragraph, the second
|
|
50
|
+
* written to continue the first — `2.` after an earlier `1.`. Discarding
|
|
51
|
+
* it renumbers somebody's list, which is a change to what they wrote
|
|
52
|
+
* rather than a rendering choice. Absent means 1.
|
|
53
|
+
*/
|
|
54
|
+
start?: number;
|
|
46
55
|
} | {
|
|
47
56
|
type: 'heading';
|
|
48
57
|
level: 1 | 2;
|
package/dist/content.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,yFAAyF;AACzF,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,MAAM,CAAA;AAEjE,yCAAyC;AACzC,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,IAAI,CAAC,EAAE,OAAO,CAAA;CACf;AAED,oDAAoD;AACpD,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,GACnC;
|
|
1
|
+
{"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,yFAAyF;AACzF,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,MAAM,CAAA;AAEjE,yCAAyC;AACzC,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,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AsF;AACtF,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,CAAC,EAAE,cAAc,EAAE,CAAA;CACzB;AAQD,uCAAuC;AACvC,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,EAAE,CAKnE;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,SAAS,cAAc,EAAE,GAAG,MAAM,CAI7E;AAED,gEAAgE;AAChE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,cAAc,EAAE,GAAG,MAAM,CAE1E"}
|
package/dist/content.js
CHANGED
|
@@ -207,11 +207,12 @@ export function parseBodySegments(body) {
|
|
|
207
207
|
}
|
|
208
208
|
else if (/^\d+\.\s/.test(line)) {
|
|
209
209
|
const items = [];
|
|
210
|
+
const first = Number.parseInt(line, 10);
|
|
210
211
|
while (i < lines.length && /^\d+\.\s/.test(lines[i])) {
|
|
211
212
|
items.push(lines[i].replace(/^\d+\.\s/, ''));
|
|
212
213
|
i++;
|
|
213
214
|
}
|
|
214
|
-
segments.push({ type: 'numbered', items });
|
|
215
|
+
segments.push({ type: 'numbered', items, ...(first > 1 ? { start: first } : {}) });
|
|
215
216
|
}
|
|
216
217
|
else if (QUOTE_LINE_RE.test(line)) {
|
|
217
218
|
const quoteLines = [];
|
package/dist/content.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content.js","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;
|
|
1
|
+
{"version":3,"file":"content.js","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AA6CH;;;;;GAKG;AACH,MAAM,WAAW,GAAgB;IAC/B,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,M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GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;QACzE,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAA;IACtH,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAgC;IACnE,OAAO,KAAK;SACT,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACzF,IAAI,CAAC,EAAE,CAAC,CAAA;AACb,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,iBAAiB,CAAC,KAAgC;IAChE,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AAC1C,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
/** Bumped by hand with the version in package.json — `test/version.test.ts`
|
|
47
47
|
* pins the two together. It exists so "the upgrade reached the app" can be
|
|
48
48
|
* checked by grepping a built bundle rather than by trusting a lockfile. */
|
|
49
|
-
export declare const PROTOCOL_VERSION = "0.
|
|
49
|
+
export declare const PROTOCOL_VERSION = "0.11.0";
|
|
50
50
|
export { type NostrTag, type UnsignedEvent, type SignedEvent, type Profile, type ThreadRef, type ChannelVisibility, type ChannelKind, type MemberRole, type Label, type ResolutionAction, KIND, MAX_EMOJI_CHARS, MAX_MESSAGE_BYTES, MAX_MENTIONS, MAX_RATIONALE_BYTES, RELAY_AUTH_TOLERANCE_SECS, ASSERTION_SUBTYPE, computeEventId, toNostrSeconds, canonicalChannelName, threadTags, addr, relayAuthUrl, buildProfile, parseProfile, buildCreateChannel, buildDeleteChannel, buildEditChannelMetadata, buildAddMember, buildReaction, buildDeletion, buildMessage, buildResolution, buildFile, buildComponent, buildHighlight, buildUnsignedRelayAuthEvent, } from './events.js';
|
|
51
51
|
export { type AddressPointer, type EventPointer, encodeNevent, decodeNevent, convertBits, bech32Encode, bech32Decode, encodeNaddr, decodeNaddr, pointerToAddress, addressToPointer, addrToNaddr, naddrToAddr, referenceToPointer, NADDR_RE, findNaddrs, stripNaddrs, } from './nip19.js';
|
|
52
52
|
export { type AuthEventArgs, TIMESTAMP_TOLERANCE_SECS, normalizeUrl, buildUnsignedAuthEvent, base64, authorizationHeaderFor, authorizationHeader, } from './nip98.js';
|
|
@@ -57,4 +57,6 @@ export { type ChannelEventHandler, type ChannelSubscription, type ChannelSubscri
|
|
|
57
57
|
export { type InlineMark, type InlineMarkSpan, type BodySegment, type InlineMarkNode, type InlineTextNode, parseInlineMarks, wrapInlineMarks, parseBodySegments, stripInlineFormatting, markersToInlineNodes, inlineNodesToMarkers, inlineNodesToText, } from './content.js';
|
|
58
58
|
export { type Block, type BlockDocument, type KnownBlockType, KNOWN_BLOCK_TYPES, BlockDocumentError, validateBlockDocument, parseBlockDocument, serializeBlockDocument, newBlockId, assignMissingBlockIds, blockIds, findBlock, inlineTextOf, documentText, } from './blocks.js';
|
|
59
59
|
export { type RenderInline, type RenderBlock, type RenderFormat, type ContentFormat, CONTENT_FORMAT_TAG, BLOCK_DOCUMENT_FORMAT, contentFormatOf, toRenderTree, renderTreeText, } from './render.js';
|
|
60
|
+
export { markerTextToBlockDocument, blockDocumentToMarkerText, } from './bridge-content.js';
|
|
61
|
+
export { type BlockAnchor, BLOCK_ANCHOR_TAG, blockAnchorOf, resolveBlockAnchor, } from './anchors.js';
|
|
60
62
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH;;4EAE4E;AAC5E,eAAO,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH;;4EAE4E;AAC5E,eAAO,MAAM,gBAAgB,WAAW,CAAA;AAExC,OAAO,EAEL,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,gBAAgB,EAErB,IAAI,EACJ,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB,EAEjB,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,UAAU,EACV,IAAI,EACJ,YAAY,EAEZ,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,cAAc,EACd,aAAa,EACb,aAAa,EACb,YAAY,EACZ,eAAe,EACf,SAAS,EACT,cAAc,EACd,cAAc,EACd,2BAA2B,GAC5B,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,WA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SAAS,EACT,YAAY,EACZ,YAAY,GACb,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,eAAe,EACf,YAAY,EACZ,cAAc,GACf,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EACL,KAAK,WAAW,EAChB,gBAAgB,EAChB,aAAa,EACb,kBAAkB,GACnB,MAAM,cAAc,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
/** Bumped by hand with the version in package.json — `test/version.test.ts`
|
|
47
47
|
* pins the two together. It exists so "the upgrade reached the app" can be
|
|
48
48
|
* checked by grepping a built bundle rather than by trusting a lockfile. */
|
|
49
|
-
export const PROTOCOL_VERSION = '0.
|
|
49
|
+
export const PROTOCOL_VERSION = '0.11.0';
|
|
50
50
|
export {
|
|
51
51
|
// constants
|
|
52
52
|
KIND, MAX_EMOJI_CHARS, MAX_MESSAGE_BYTES, MAX_MENTIONS, MAX_RATIONALE_BYTES, RELAY_AUTH_TOLERANCE_SECS, ASSERTION_SUBTYPE,
|
|
@@ -63,4 +63,6 @@ export { createChannelSubscriptions, } from './subscriptions.js';
|
|
|
63
63
|
export { parseInlineMarks, wrapInlineMarks, parseBodySegments, stripInlineFormatting, markersToInlineNodes, inlineNodesToMarkers, inlineNodesToText, } from './content.js';
|
|
64
64
|
export { KNOWN_BLOCK_TYPES, BlockDocumentError, validateBlockDocument, parseBlockDocument, serializeBlockDocument, newBlockId, assignMissingBlockIds, blockIds, findBlock, inlineTextOf, documentText, } from './blocks.js';
|
|
65
65
|
export { CONTENT_FORMAT_TAG, BLOCK_DOCUMENT_FORMAT, contentFormatOf, toRenderTree, renderTreeText, } from './render.js';
|
|
66
|
+
export { markerTextToBlockDocument, blockDocumentToMarkerText, } from './bridge-content.js';
|
|
67
|
+
export { BLOCK_ANCHOR_TAG, blockAnchorOf, resolveBlockAnchor, } from './anchors.js';
|
|
66
68
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH;;4EAE4E;AAC5E,MAAM,CAAC,MAAM,gBAAgB,GAAG,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AAEH;;4EAE4E;AAC5E,MAAM,CAAC,MAAM,gBAAgB,GAAG,QAAQ,CAAA;AAExC,OAAO;AAYL,YAAY;AACZ,IAAI,EACJ,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB;AACjB,8CAA8C;AAC9C,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,UAAU,EACV,IAAI,EACJ,YAAY;AACZ,WAAW;AACX,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,wBAAwB,EACxB,cAAc,EACd,aAAa,EACb,aAAa,EACb,YAAY,EACZ,eAAe,EACf,SAAS,EACT,cAAc,EACd,cAAc,EACd,2BAA2B,GAC5B,MAAM,aAAa,CAAA;AAEpB,OAAO,EAGL,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,QAAQ,EACR,UAAU,EACV,WAAW,GACZ,MAAM,YAAY,CAAA;AAEnB,OAAO,EAEL,wBAAwB,EACxB,YAAY,EACZ,sBAAsB,EACtB,MAAM,EACN,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,YAAY,CAAA;AAEnB,OAAO,EAGL,mBAAmB,EACnB,SAAS,EACT,eAAe,GAChB,MAAM,WAAW,CAAA;AAElB,OAAO,EAOL,oBAAoB,EACpB,kBAAkB,EAClB,kBAAkB,EAClB,yBAAyB,EACzB,KAAK,GACN,MAAM,aAAa,CAAA;AAEpB,OAAO,EAOL,cAAc,EACd,UAAU,EACV,eAAe,GAChB,MAAM,WAAW,CAAA;AAElB,OAAO,EAIL,0BAA0B,GAC3B,MAAM,oBAAoB,CAAA;AAE3B,OAAO,EAML,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,cAAc,CAAA;AAErB,OAAO,EAIL,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,EAClB,sBAAsB,EACtB,UAAU,EACV,qBAAqB,EACrB,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,YAAY,GACb,MAAM,aAAa,CAAA;AAEpB,OAAO,EAKL,kBAAkB,EAClB,qBAAqB,EACrB,eAAe,EACf,YAAY,EACZ,cAAc,GACf,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAEL,gBAAgB,EAChB,aAAa,EACb,kBAAkB,GACnB,MAAM,cAAc,CAAA"}
|
package/dist/render.d.ts
CHANGED
|
@@ -50,6 +50,8 @@ export interface RenderBlock {
|
|
|
50
50
|
id?: string;
|
|
51
51
|
level?: 1 | 2 | 3;
|
|
52
52
|
language?: string;
|
|
53
|
+
/** An ordered list's first number, when the author did not start at 1. */
|
|
54
|
+
start?: number;
|
|
53
55
|
attrs?: Record<string, unknown>;
|
|
54
56
|
/** What the document actually called it, when `type` is `'unknown'`. */
|
|
55
57
|
typeName?: string;
|
package/dist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AmB,CAAA;AAElD,wCAAwC;AACxC,eAAO,MAAM,qBAAqB,oBAAoB,CAAA;AAEtD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,WAAW,GAAG,aAAa,CAIjE;AA4FD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,WAAW,EAAE,CAY/E;AAMD,mEAAmE;AACnE,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,GAAG,MAAM,CASrE"}
|
package/dist/render.js
CHANGED
|
@@ -90,6 +90,7 @@ function blockFromSegment(seg) {
|
|
|
90
90
|
case 'numbered':
|
|
91
91
|
return {
|
|
92
92
|
type: 'orderedList',
|
|
93
|
+
...(seg.start ? { start: seg.start } : {}),
|
|
93
94
|
children: seg.items.map((item) => ({ type: 'listItem', inline: inlineFromMarkers(item) })),
|
|
94
95
|
};
|
|
95
96
|
case 'quote':
|
|
@@ -120,6 +121,9 @@ function blockFromDocument(block) {
|
|
|
120
121
|
const language = block.attrs?.language;
|
|
121
122
|
if (block.type === 'codeBlock' && typeof language === 'string')
|
|
122
123
|
out.language = language;
|
|
124
|
+
const start = block.attrs?.start;
|
|
125
|
+
if (block.type === 'orderedList' && typeof start === 'number' && start > 1)
|
|
126
|
+
out.start = start;
|
|
123
127
|
if (Array.isArray(block.content)) {
|
|
124
128
|
if (isInlineRun(block.content)) {
|
|
125
129
|
out.inline = block.content.map((node) => ({
|
package/dist/render.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,OAAO,EAIL,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,cAAc,CAAA;AACrB,OAAO,EAAkC,kBAAkB,EAAE,YAAY,EAAE,MAAM,aAA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C,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAA;AAC1F,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,cAAc,CAAC,MAA8B;IAC3D,OAAO,MAAM;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QACT,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACxD,MAAM,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;QACzD,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACvD,CAAC,CAAC;SACD,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC;SACvB,IAAI,CAAC,IAAI,CAAC,CAAA;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estiva-app/protocol",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "The Estiva wire format: Buzz-shaped Nostr event builders, NIP-01 ids, NIP-19 naddr, NIP-98 HTTP auth, and the relay clients. Speaks the protocol; interprets nothing.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/src/anchors.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A comment anchored to one block — SPEC §13.6, and RFC 0.4 §6's answer.
|
|
3
|
+
*
|
|
4
|
+
* The address says which object; a `block` tag says which part of it. That much
|
|
5
|
+
* is two lines. **The reason this is a module rather than two lines is the
|
|
6
|
+
* unhappy path**: an anchor outlives the thing it points at, and the ways it
|
|
7
|
+
* stops resolving are not the same as each other.
|
|
8
|
+
*
|
|
9
|
+
* §13.6 requires a reader to distinguish four outcomes, and the one that
|
|
10
|
+
* matters is `detached` versus `unanchored`. They render identically if you let
|
|
11
|
+
* them and they mean opposite things — one is a remark about the object, the
|
|
12
|
+
* other a remark about a paragraph somebody has since deleted. A reader that
|
|
13
|
+
* collapses them silently converts the second into the first, and nothing
|
|
14
|
+
* reports it.
|
|
15
|
+
*
|
|
16
|
+
* So {@link resolveBlockAnchor} returns which of the four it is, rather than a
|
|
17
|
+
* block or `undefined`. A caller that wants to be careless has to work at it.
|
|
18
|
+
*/
|
|
19
|
+
import { type Block, type BlockDocument, findBlock, parseBlockDocument } from './blocks.js'
|
|
20
|
+
import type { ContentFormat } from './render.js'
|
|
21
|
+
|
|
22
|
+
/** The tag SPEC §13.6 defines. */
|
|
23
|
+
export const BLOCK_ANCHOR_TAG = 'block'
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* What an anchor resolved to.
|
|
27
|
+
*
|
|
28
|
+
* A discriminated union on purpose: the four states are not degrees of success,
|
|
29
|
+
* and a caller that treats "no anchor" and "the block is gone" as one thing has
|
|
30
|
+
* the defect §13.6 is about.
|
|
31
|
+
*/
|
|
32
|
+
export type BlockAnchor =
|
|
33
|
+
/** The comment carries no `block` tag. It is about the whole object. */
|
|
34
|
+
| { state: 'unanchored' }
|
|
35
|
+
/** The tag names a block that is present. */
|
|
36
|
+
| { state: 'resolved'; id: string; block: Block }
|
|
37
|
+
/**
|
|
38
|
+
* The body is not a block document, so it has no parts to point at.
|
|
39
|
+
*
|
|
40
|
+
* Marker text has no addressable sub-unit (§13.1), so this is permanent for
|
|
41
|
+
* that body rather than a failure — it is what two content models means.
|
|
42
|
+
*/
|
|
43
|
+
| { state: 'unaddressable'; id: string }
|
|
44
|
+
/** The tag names a block that is no longer in the document. */
|
|
45
|
+
| { state: 'detached'; id: string }
|
|
46
|
+
|
|
47
|
+
/** The block id a comment anchors to, or `undefined` when it anchors to none. */
|
|
48
|
+
export function blockAnchorOf(event: { tags: string[][] }): string | undefined {
|
|
49
|
+
const id = event.tags.find((t) => t[0] === BLOCK_ANCHOR_TAG)?.[1]
|
|
50
|
+
return id === undefined || id === '' ? undefined : id
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Which of §13.6's four states an anchor is in, against the body as it is now.
|
|
55
|
+
*
|
|
56
|
+
* `format` comes from the event carrying the *body* — `contentFormatOf` — and
|
|
57
|
+
* never from inspecting `value` (§13.4). Passing `'blocks'` for a body that
|
|
58
|
+
* does not parse yields `unaddressable` rather than throwing: a mis-tagged body
|
|
59
|
+
* has no parts either, and a reader that throws renders nothing at all.
|
|
60
|
+
*/
|
|
61
|
+
export function resolveBlockAnchor(
|
|
62
|
+
id: string | undefined,
|
|
63
|
+
value: string,
|
|
64
|
+
format: ContentFormat,
|
|
65
|
+
): BlockAnchor {
|
|
66
|
+
if (id === undefined || id === '') return { state: 'unanchored' }
|
|
67
|
+
if (format !== 'blocks') return { state: 'unaddressable', id }
|
|
68
|
+
let document: BlockDocument
|
|
69
|
+
try {
|
|
70
|
+
document = parseBlockDocument(value)
|
|
71
|
+
} catch {
|
|
72
|
+
return { state: 'unaddressable', id }
|
|
73
|
+
}
|
|
74
|
+
const block = findBlock(document, id)
|
|
75
|
+
return block ? { state: 'resolved', id, block } : { state: 'detached', id }
|
|
76
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marker text and block documents, converted between — the bridge across §13's
|
|
3
|
+
* two serialisations.
|
|
4
|
+
*
|
|
5
|
+
* SPEC §13 keeps the two content models apart on purpose, and nothing here
|
|
6
|
+
* softens that: a message is still marker text and a rich text field is still a
|
|
7
|
+
* block document. What this module does is let an app whose *editor* produces
|
|
8
|
+
* marker text publish a **block document** anyway, which is the only way a
|
|
9
|
+
* description acquires addressable blocks before somebody builds a block editor.
|
|
10
|
+
*
|
|
11
|
+
* ## The id carry-forward is the whole point
|
|
12
|
+
*
|
|
13
|
+
* A description is replaced wholesale on every save. If each save re-parses the
|
|
14
|
+
* text into fresh blocks, every block gets a new id, and **every comment
|
|
15
|
+
* anchored to one detaches** — silently, because a detached comment renders
|
|
16
|
+
* exactly like a comment that was never anchored. So
|
|
17
|
+
* {@link markerTextToBlockDocument} takes the previous document and carries ids
|
|
18
|
+
* across, by a rule written down here rather than left to be inferred:
|
|
19
|
+
*
|
|
20
|
+
* 1. **Same type and identical text** — reuse that block's id, wherever it
|
|
21
|
+
* moved to. This survives a reorder, and an edit to a *different* block.
|
|
22
|
+
* 2. **Same type at the same index**, among what is left — reuse that id. This
|
|
23
|
+
* survives editing a block's own text in place.
|
|
24
|
+
* 3. Anything still unmatched gets a fresh id.
|
|
25
|
+
*
|
|
26
|
+
* **What that rule does not survive, stated rather than discovered:** a block
|
|
27
|
+
* moved *and* edited in one save matches neither pass and gets a new id, so an
|
|
28
|
+
* anchor to it breaks. That is a real limit of reconstructing structure from
|
|
29
|
+
* text. It is acceptable because the anchor has to fail visibly anyway — a
|
|
30
|
+
* block can always be deleted outright, so a reader that cannot show a broken
|
|
31
|
+
* anchor is broken regardless of this rule.
|
|
32
|
+
*/
|
|
33
|
+
import {
|
|
34
|
+
type BodySegment,
|
|
35
|
+
type InlineTextNode,
|
|
36
|
+
markersToInlineNodes,
|
|
37
|
+
inlineNodesToMarkers,
|
|
38
|
+
parseBodySegments,
|
|
39
|
+
} from './content.js'
|
|
40
|
+
import { type Block, type BlockDocument, newBlockId } from './blocks.js'
|
|
41
|
+
|
|
42
|
+
const isInlineRun = (content: unknown): content is InlineTextNode[] =>
|
|
43
|
+
Array.isArray(content) &&
|
|
44
|
+
content.length > 0 &&
|
|
45
|
+
typeof content[0] === 'object' &&
|
|
46
|
+
content[0] !== null &&
|
|
47
|
+
(content[0] as { type?: unknown }).type === 'text'
|
|
48
|
+
|
|
49
|
+
/** A block's text, for matching. Cheap and stable: it is what the author sees. */
|
|
50
|
+
function textOf(block: Block): string {
|
|
51
|
+
if (!Array.isArray(block.content)) return ''
|
|
52
|
+
if (isInlineRun(block.content)) return block.content.map((n) => n.text).join('')
|
|
53
|
+
return (block.content as Block[]).map(textOf).join('\n')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/*
|
|
57
|
+
`\u0000` as an escape, never the byte. A separator has to be something a
|
|
58
|
+
block type cannot contain, and NUL is the right choice — but writing it
|
|
59
|
+
literally makes this file *binary* to the tools that read source: `grep`
|
|
60
|
+
skips it and says nothing, which is how this very line hid a control
|
|
61
|
+
character until a search for `previous` came back empty. Ship's `fold.ts`
|
|
62
|
+
carries the same warning for the same reason.
|
|
63
|
+
*/
|
|
64
|
+
const keyOf = (block: Block) => `${block.type}\u0000${textOf(block)}`
|
|
65
|
+
|
|
66
|
+
function blockFromSegment(seg: BodySegment): Block {
|
|
67
|
+
switch (seg.type) {
|
|
68
|
+
case 'heading':
|
|
69
|
+
return { type: 'heading', id: '', attrs: { level: seg.level }, content: markersToInlineNodes(seg.text) }
|
|
70
|
+
case 'bullet':
|
|
71
|
+
return {
|
|
72
|
+
type: 'bulletList',
|
|
73
|
+
id: '',
|
|
74
|
+
content: seg.items.map((item) => ({ type: 'listItem', id: '', content: markersToInlineNodes(item) })),
|
|
75
|
+
}
|
|
76
|
+
case 'numbered':
|
|
77
|
+
return {
|
|
78
|
+
type: 'orderedList',
|
|
79
|
+
id: '',
|
|
80
|
+
...(seg.start ? { attrs: { start: seg.start } } : {}),
|
|
81
|
+
content: seg.items.map((item) => ({ type: 'listItem', id: '', content: markersToInlineNodes(item) })),
|
|
82
|
+
}
|
|
83
|
+
case 'quote':
|
|
84
|
+
return { type: 'blockquote', id: '', content: markersToInlineNodes(seg.lines.join('\n')) }
|
|
85
|
+
case 'code':
|
|
86
|
+
return {
|
|
87
|
+
type: 'codeBlock',
|
|
88
|
+
id: '',
|
|
89
|
+
...(seg.language ? { attrs: { language: seg.language } } : {}),
|
|
90
|
+
// A fence is literal — its content is never mark-parsed.
|
|
91
|
+
content: [{ type: 'text' as const, text: seg.lines.join('\n') }],
|
|
92
|
+
}
|
|
93
|
+
case 'text':
|
|
94
|
+
return { type: 'paragraph', id: '', content: markersToInlineNodes(seg.lines.join('\n')) }
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Marker text as a block document, keeping `previous`'s ids wherever a block
|
|
100
|
+
* still corresponds. The matching rule is in this module's header.
|
|
101
|
+
*/
|
|
102
|
+
export function markerTextToBlockDocument(text: string, previous?: BlockDocument): BlockDocument {
|
|
103
|
+
const fresh = parseBodySegments(text).map(blockFromSegment)
|
|
104
|
+
const old = previous?.content ?? []
|
|
105
|
+
const takenIds = new Set<string>()
|
|
106
|
+
const usedOld = new Set<number>()
|
|
107
|
+
|
|
108
|
+
// Pass 1 — same type and identical text, wherever it moved to.
|
|
109
|
+
const byKey = new Map<string, number[]>()
|
|
110
|
+
old.forEach((block, i) => {
|
|
111
|
+
if (!block.id) return
|
|
112
|
+
const list = byKey.get(keyOf(block)) ?? []
|
|
113
|
+
list.push(i)
|
|
114
|
+
byKey.set(keyOf(block), list)
|
|
115
|
+
})
|
|
116
|
+
const ids: (string | undefined)[] = fresh.map((block) => {
|
|
117
|
+
const candidates = byKey.get(keyOf(block))
|
|
118
|
+
while (candidates && candidates.length) {
|
|
119
|
+
const i = candidates.shift() as number
|
|
120
|
+
if (usedOld.has(i)) continue
|
|
121
|
+
usedOld.add(i)
|
|
122
|
+
takenIds.add(old[i].id)
|
|
123
|
+
return old[i].id
|
|
124
|
+
}
|
|
125
|
+
return undefined
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
// Pass 2 — same type at the same index, among what is left.
|
|
129
|
+
fresh.forEach((block, i) => {
|
|
130
|
+
if (ids[i] !== undefined) return
|
|
131
|
+
const candidate = old[i]
|
|
132
|
+
if (!candidate || usedOld.has(i) || candidate.type !== block.type || !candidate.id) return
|
|
133
|
+
if (takenIds.has(candidate.id)) return
|
|
134
|
+
usedOld.add(i)
|
|
135
|
+
takenIds.add(candidate.id)
|
|
136
|
+
ids[i] = candidate.id
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
// Pass 3 — a fresh id for everything still unmatched, children included.
|
|
140
|
+
const mint = () => {
|
|
141
|
+
let id = newBlockId()
|
|
142
|
+
while (takenIds.has(id)) id = newBlockId()
|
|
143
|
+
takenIds.add(id)
|
|
144
|
+
return id
|
|
145
|
+
}
|
|
146
|
+
const fill = (block: Block, id?: string): Block => {
|
|
147
|
+
const children = Array.isArray(block.content) && !isInlineRun(block.content)
|
|
148
|
+
? (block.content as Block[]).map((child) => fill(child))
|
|
149
|
+
: undefined
|
|
150
|
+
return {
|
|
151
|
+
...block,
|
|
152
|
+
id: id ?? (block.id || mint()),
|
|
153
|
+
...(children ? { content: children } : {}),
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return { type: 'doc', content: fresh.map((block, i) => fill(block, ids[i] || undefined)) }
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const itemText = (item: Block): string =>
|
|
161
|
+
isInlineRun(item.content) ? inlineNodesToMarkers(item.content) : ''
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* A block document back as marker text, for an editor that edits text.
|
|
165
|
+
*
|
|
166
|
+
* The inverse of {@link markerTextToBlockDocument} for everything the marker
|
|
167
|
+
* dialect can spell, which is everything that function can produce. A document
|
|
168
|
+
* written by a *block* editor may hold a table or a nested list, and §13.2 has
|
|
169
|
+
* no marker for either — those degrade to their text rather than vanishing,
|
|
170
|
+
* which is the rule §13.3 already gives a reader for an unknown block.
|
|
171
|
+
*/
|
|
172
|
+
export function blockDocumentToMarkerText(doc: BlockDocument): string {
|
|
173
|
+
const lines: string[] = []
|
|
174
|
+
for (const block of doc.content) {
|
|
175
|
+
const inline = isInlineRun(block.content) ? inlineNodesToMarkers(block.content) : ''
|
|
176
|
+
switch (block.type) {
|
|
177
|
+
case 'heading': {
|
|
178
|
+
const level = block.attrs?.level === 2 ? 2 : 1
|
|
179
|
+
lines.push(`${'#'.repeat(level)} ${inline}`)
|
|
180
|
+
break
|
|
181
|
+
}
|
|
182
|
+
case 'bulletList':
|
|
183
|
+
for (const item of (block.content as Block[]) ?? []) lines.push(`- ${itemText(item)}`)
|
|
184
|
+
break
|
|
185
|
+
case 'orderedList': {
|
|
186
|
+
const start = typeof block.attrs?.start === 'number' ? block.attrs.start : 1
|
|
187
|
+
;((block.content as Block[]) ?? []).forEach((item, i) => lines.push(`${start + i}. ${itemText(item)}`))
|
|
188
|
+
break
|
|
189
|
+
}
|
|
190
|
+
case 'blockquote':
|
|
191
|
+
for (const line of inline.split('\n')) lines.push(`> ${line}`)
|
|
192
|
+
break
|
|
193
|
+
case 'codeBlock': {
|
|
194
|
+
const language = typeof block.attrs?.language === 'string' ? block.attrs.language : ''
|
|
195
|
+
lines.push('```' + language, inline, '```')
|
|
196
|
+
break
|
|
197
|
+
}
|
|
198
|
+
case 'horizontalRule':
|
|
199
|
+
lines.push('---')
|
|
200
|
+
break
|
|
201
|
+
default:
|
|
202
|
+
// A table, an attachment, a widget, or a type from a later version.
|
|
203
|
+
lines.push(inline || textOf(block))
|
|
204
|
+
}
|
|
205
|
+
lines.push('')
|
|
206
|
+
}
|
|
207
|
+
return lines.join('\n').replace(/\n+$/, '')
|
|
208
|
+
}
|
package/src/content.ts
CHANGED
|
@@ -40,7 +40,19 @@ export interface InlineMarkSpan {
|
|
|
40
40
|
export type BodySegment =
|
|
41
41
|
| { type: 'text'; lines: string[] }
|
|
42
42
|
| { type: 'bullet'; items: string[] }
|
|
43
|
-
| {
|
|
43
|
+
| {
|
|
44
|
+
type: 'numbered'
|
|
45
|
+
items: string[]
|
|
46
|
+
/**
|
|
47
|
+
* The number the author actually wrote, when it is not 1.
|
|
48
|
+
*
|
|
49
|
+
* A body can hold two numbered runs separated by a paragraph, the second
|
|
50
|
+
* written to continue the first — `2.` after an earlier `1.`. Discarding
|
|
51
|
+
* it renumbers somebody's list, which is a change to what they wrote
|
|
52
|
+
* rather than a rendering choice. Absent means 1.
|
|
53
|
+
*/
|
|
54
|
+
start?: number
|
|
55
|
+
}
|
|
44
56
|
| { type: 'heading'; level: 1 | 2; text: string }
|
|
45
57
|
| { type: 'quote'; lines: string[] }
|
|
46
58
|
| { type: 'code'; language?: string; lines: string[] }
|
|
@@ -225,11 +237,12 @@ export function parseBodySegments(body: string): BodySegment[] {
|
|
|
225
237
|
segments.push({ type: 'bullet', items })
|
|
226
238
|
} else if (/^\d+\.\s/.test(line)) {
|
|
227
239
|
const items: string[] = []
|
|
240
|
+
const first = Number.parseInt(line, 10)
|
|
228
241
|
while (i < lines.length && /^\d+\.\s/.test(lines[i])) {
|
|
229
242
|
items.push(lines[i].replace(/^\d+\.\s/, ''))
|
|
230
243
|
i++
|
|
231
244
|
}
|
|
232
|
-
segments.push({ type: 'numbered', items })
|
|
245
|
+
segments.push({ type: 'numbered', items, ...(first > 1 ? { start: first } : {}) })
|
|
233
246
|
} else if (QUOTE_LINE_RE.test(line)) {
|
|
234
247
|
const quoteLines: string[] = []
|
|
235
248
|
while (i < lines.length && QUOTE_LINE_RE.test(lines[i])) {
|
package/src/index.ts
CHANGED
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
/** Bumped by hand with the version in package.json — `test/version.test.ts`
|
|
48
48
|
* pins the two together. It exists so "the upgrade reached the app" can be
|
|
49
49
|
* checked by grepping a built bundle rather than by trusting a lockfile. */
|
|
50
|
-
export const PROTOCOL_VERSION = '0.
|
|
50
|
+
export const PROTOCOL_VERSION = '0.11.0'
|
|
51
51
|
|
|
52
52
|
export {
|
|
53
53
|
// types
|
|
@@ -207,3 +207,15 @@ export {
|
|
|
207
207
|
toRenderTree,
|
|
208
208
|
renderTreeText,
|
|
209
209
|
} from './render.js'
|
|
210
|
+
|
|
211
|
+
export {
|
|
212
|
+
markerTextToBlockDocument,
|
|
213
|
+
blockDocumentToMarkerText,
|
|
214
|
+
} from './bridge-content.js'
|
|
215
|
+
|
|
216
|
+
export {
|
|
217
|
+
type BlockAnchor,
|
|
218
|
+
BLOCK_ANCHOR_TAG,
|
|
219
|
+
blockAnchorOf,
|
|
220
|
+
resolveBlockAnchor,
|
|
221
|
+
} from './anchors.js'
|
package/src/render.ts
CHANGED
|
@@ -62,6 +62,8 @@ export interface RenderBlock {
|
|
|
62
62
|
id?: string
|
|
63
63
|
level?: 1 | 2 | 3
|
|
64
64
|
language?: string
|
|
65
|
+
/** An ordered list's first number, when the author did not start at 1. */
|
|
66
|
+
start?: number
|
|
65
67
|
attrs?: Record<string, unknown>
|
|
66
68
|
/** What the document actually called it, when `type` is `'unknown'`. */
|
|
67
69
|
typeName?: string
|
|
@@ -158,6 +160,7 @@ function blockFromSegment(seg: BodySegment): RenderBlock {
|
|
|
158
160
|
case 'numbered':
|
|
159
161
|
return {
|
|
160
162
|
type: 'orderedList',
|
|
163
|
+
...(seg.start ? { start: seg.start } : {}),
|
|
161
164
|
children: seg.items.map((item) => ({ type: 'listItem' as const, inline: inlineFromMarkers(item) })),
|
|
162
165
|
}
|
|
163
166
|
case 'quote':
|
|
@@ -189,6 +192,8 @@ function blockFromDocument(block: Block): RenderBlock {
|
|
|
189
192
|
if (block.type === 'heading' && (level === 1 || level === 2 || level === 3)) out.level = level
|
|
190
193
|
const language = block.attrs?.language
|
|
191
194
|
if (block.type === 'codeBlock' && typeof language === 'string') out.language = language
|
|
195
|
+
const start = block.attrs?.start
|
|
196
|
+
if (block.type === 'orderedList' && typeof start === 'number' && start > 1) out.start = start
|
|
192
197
|
|
|
193
198
|
if (Array.isArray(block.content)) {
|
|
194
199
|
if (isInlineRun(block.content)) {
|