@estiva-app/protocol 0.8.0 → 0.10.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 +73 -0
- package/dist/blocks.d.ts.map +1 -1
- package/dist/blocks.js +4 -7
- package/dist/blocks.js.map +1 -1
- 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 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/render.d.ts +51 -2
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +32 -0
- package/dist/render.js.map +1 -1
- package/package.json +1 -1
- package/src/blocks.ts +4 -7
- package/src/bridge-content.ts +208 -0
- package/src/content.ts +15 -2
- package/src/index.ts +10 -1
- package/src/render.ts +62 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,79 @@ 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.10.0 — 2026-09-02
|
|
8
|
+
|
|
9
|
+
**Wire behaviour: unchanged.** No builder, tag layout, id computation or
|
|
10
|
+
signature input moved. What this adds is the bridge that lets an app with a
|
|
11
|
+
*text* editor publish a **block document**, which is how a description acquires
|
|
12
|
+
addressable blocks before anybody builds a block editor.
|
|
13
|
+
|
|
14
|
+
- **New: `markerTextToBlockDocument` and `blockDocumentToMarkerText`.** Marker
|
|
15
|
+
text in, a §13.3 document out, and back again.
|
|
16
|
+
|
|
17
|
+
**`markerTextToBlockDocument` takes the previous document and carries its ids
|
|
18
|
+
across**, and that is the entire point rather than a nicety. A description is
|
|
19
|
+
replaced wholesale on every save; re-parsing into fresh blocks each time
|
|
20
|
+
re-mints every id, and **every comment anchored to one detaches silently** —
|
|
21
|
+
a detached comment renders exactly like one that was never anchored. The
|
|
22
|
+
matching rule is written down in the module header: same type and identical
|
|
23
|
+
text wherever it moved to, then same type at the same index, then a fresh id.
|
|
24
|
+
|
|
25
|
+
Its limit is documented *and asserted*: a block moved **and** edited in one
|
|
26
|
+
save matches neither pass and gets a new id. There is a test that fails if
|
|
27
|
+
that ever silently changes, so the header cannot drift from the behaviour.
|
|
28
|
+
|
|
29
|
+
Control: disabling the carry-forward fails 5 tests, including the corpus one.
|
|
30
|
+
|
|
31
|
+
- **An ordered list keeps the number its author wrote.** `BodySegment` of type
|
|
32
|
+
`numbered` gains `start`, `RenderBlock` gains `start`, and a block document
|
|
33
|
+
carries `attrs.start` — all absent when the list begins at 1.
|
|
34
|
+
|
|
35
|
+
This is a **pre-existing rendering defect**, not something the bridge
|
|
36
|
+
introduced. A body can hold two numbered runs split by a paragraph, the
|
|
37
|
+
second written `2.` to continue the first; every renderer built on
|
|
38
|
+
`parseBodySegments` has drawn it as `1.` since the dialect existed. One real
|
|
39
|
+
body in the 152-body corpus does exactly this, and the round trip is what
|
|
40
|
+
made it visible — renumbering somebody's list is a change to what they wrote,
|
|
41
|
+
and it would have been written back to the relay permanently once a
|
|
42
|
+
description is re-saved as blocks.
|
|
43
|
+
|
|
44
|
+
- **A NUL byte, removed from this package's own source.** `keyOf` used a
|
|
45
|
+
literal `\x00` as its separator, which makes a file *binary* to the tools
|
|
46
|
+
that read source: `grep` skips it and reports nothing, so a search for a
|
|
47
|
+
symbol in that file comes back empty and looks like an answer. Ship's
|
|
48
|
+
`fold.ts` carries a comment about this exact trap; this hit it anyway. It is
|
|
49
|
+
an escape now.
|
|
50
|
+
|
|
51
|
+
## 0.9.0 — 2026-09-02
|
|
52
|
+
|
|
53
|
+
**Wire behaviour: unchanged.** Nothing about the bytes moved. One function and
|
|
54
|
+
two constants moved *between packages*, and `@estiva-app/interop` re-exports
|
|
55
|
+
them, so **no consumer of either package has to change anything.**
|
|
56
|
+
|
|
57
|
+
- **`contentFormatOf`, `CONTENT_FORMAT_TAG` and `BLOCK_DOCUMENT_FORMAT` move
|
|
58
|
+
here from `@estiva-app/interop`.** They were defined there because the
|
|
59
|
+
projection layer needed them first, and reading a tag off an event looked
|
|
60
|
+
like a question about a slot.
|
|
61
|
+
|
|
62
|
+
It is not — it is a question about an event, which is this package's subject.
|
|
63
|
+
**Two folds outside the projection layer now need it**: Ship's and the
|
|
64
|
+
agent's, which are one fold in two repositories held to a single recorded
|
|
65
|
+
state by a conformance fixture. Making either depend on the projection layer
|
|
66
|
+
to read a tag is the wrong direction, and a second copy of
|
|
67
|
+
`'estiva-blocks-1'` is what this package exists to prevent.
|
|
68
|
+
|
|
69
|
+
- **`ContentFormat` is the name; `RenderFormat` is now an alias for it.** 0.8.0
|
|
70
|
+
shipped `RenderFormat` and `interop` shipped `ContentFormat`, and they were
|
|
71
|
+
the same three-value union declared twice — a duplicate introduced by 0.8.0
|
|
72
|
+
and removed by this release. The old name still exports, so 0.8.0's consumers
|
|
73
|
+
keep compiling.
|
|
74
|
+
|
|
75
|
+
- `interop` is unchanged in behaviour and re-exports all three names, with its
|
|
76
|
+
147 tests passing untouched. `BODY_SLOT` stays in `interop`: a *slot* is that
|
|
77
|
+
layer's subject, and this package has no opinion about which one carries a
|
|
78
|
+
body.
|
|
79
|
+
|
|
7
80
|
## 0.8.0 — 2026-09-02
|
|
8
81
|
|
|
9
82
|
**Wire behaviour: unchanged.** No builder, tag layout, id computation or
|
package/dist/blocks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../src/blocks.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../src/blocks.ts"],"names":[],"mappings":"AAsBA,OAA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EAAE,EAAE,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,CAY3E;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,CAIjD;AAED,uFAAuF;AACvF,wBAAgB,YAAY,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM,CAEvD"}
|
package/dist/blocks.js
CHANGED
|
@@ -10,13 +10,10 @@
|
|
|
10
10
|
*
|
|
11
11
|
* ## What is deliberately not here
|
|
12
12
|
*
|
|
13
|
-
* **The `content-format` tag.**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* be a second copy of exactly the kind this package exists to prevent, so this
|
|
18
|
-
* module never names it: a document does not know its own tag, and the reader
|
|
19
|
-
* that does is one layer up.
|
|
13
|
+
* **The `content-format` tag.** A document does not know its own tag — the tag
|
|
14
|
+
* is on the event that carries it, and SPEC §13.4's read rule is
|
|
15
|
+
* `contentFormatOf` in `render.ts`. (It lived in `@estiva-app/interop` until
|
|
16
|
+
* two folds outside the projection layer needed it; see that function's note.)
|
|
20
17
|
*
|
|
21
18
|
* **Rendering.** §13.5's safe renderer is RIC-6's, where Ship is the consumer
|
|
22
19
|
* that needs it. What this module owes a renderer is {@link inlineTextOf}, so
|
package/dist/blocks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blocks.js","sourceRoot":"","sources":["../src/blocks.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"blocks.js","sourceRoot":"","sources":["../src/blocks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAC7D,OAAO,EAAuB,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAErE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,WAAW;IACX,SAAS;IACT,YAAY;I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,CAAC,OAAO,CAAC;QAAE,OAAO,EAAE,CAAA;IAC5C,IAAI,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC;QAAE,OAAO,iBAAiB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IACvE,OAAQ,KAAK,CAAC,OAAmB,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAChE,CAAC;AAED,uFAAuF;AACvF,MAAM,UAAU,YAAY,CAAC,GAAkB;IAC7C,OAAO,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACzE,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
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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,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;IACE,I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gE;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,MAAM,EAAE,QAAQ,CAAC,EAAE;IAC1C,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE;IAC/B,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,WAAW,CAAC,EAAE;IACpC,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,QAAQ,CAAC,EAAE;IAChC,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,EA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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.10.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';
|
|
@@ -56,5 +56,6 @@ export { type RelayState, type SocketLike, type RelayCredential, type LiveRelayO
|
|
|
56
56
|
export { type ChannelEventHandler, type ChannelSubscription, type ChannelSubscriptions, createChannelSubscriptions, } from './subscriptions.js';
|
|
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
|
-
export { type RenderInline, type RenderBlock, type RenderFormat, toRenderTree, renderTreeText, } from './render.js';
|
|
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';
|
|
60
61
|
//# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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GAC1B,MAAM,qBAAqB,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.10.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,
|
|
@@ -62,5 +62,6 @@ export { toWebSocketUrl, parseFrame, createLiveRelay, } from './live.js';
|
|
|
62
62
|
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
|
-
export { toRenderTree, renderTreeText, } from './render.js';
|
|
65
|
+
export { CONTENT_FORMAT_TAG, BLOCK_DOCUMENT_FORMAT, contentFormatOf, toRenderTree, renderTreeText, } from './render.js';
|
|
66
|
+
export { markerTextToBlockDocument, blockDocumentToMarkerText, } from './bridge-content.js';
|
|
66
67
|
//# 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,C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AO,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"}
|
package/dist/render.d.ts
CHANGED
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
* to guess.
|
|
31
31
|
*/
|
|
32
32
|
import { type InlineMark } from './content.js';
|
|
33
|
+
import type { SignedEvent } from './events.js';
|
|
33
34
|
/** A run of text and the marks on it. Nothing here needs escaping; it is text. */
|
|
34
35
|
export interface RenderInline {
|
|
35
36
|
text: string;
|
|
@@ -49,14 +50,62 @@ export interface RenderBlock {
|
|
|
49
50
|
id?: string;
|
|
50
51
|
level?: 1 | 2 | 3;
|
|
51
52
|
language?: string;
|
|
53
|
+
/** An ordered list's first number, when the author did not start at 1. */
|
|
54
|
+
start?: number;
|
|
52
55
|
attrs?: Record<string, unknown>;
|
|
53
56
|
/** What the document actually called it, when `type` is `'unknown'`. */
|
|
54
57
|
typeName?: string;
|
|
55
58
|
inline?: RenderInline[];
|
|
56
59
|
children?: RenderBlock[];
|
|
57
60
|
}
|
|
58
|
-
/**
|
|
59
|
-
|
|
61
|
+
/**
|
|
62
|
+
* What content model a body is written in — SPEC §13.4.
|
|
63
|
+
*
|
|
64
|
+
* Three values, not two, and not the raw tag string. A consumer makes a
|
|
65
|
+
* three-way decision and **must not guess the third**:
|
|
66
|
+
*
|
|
67
|
+
* - `marker` — the §13.2 dialect. The default, permanently. 731 published
|
|
68
|
+
* bodies carry no tag and none of them can be given one, so this is not a
|
|
69
|
+
* migration window that closes.
|
|
70
|
+
* - `blocks` — a §13.3 JSON block document.
|
|
71
|
+
* - `unknown` — a format declared after this runtime was written. Render the
|
|
72
|
+
* body as plain text; §13.5 says declining to format is conformant, and
|
|
73
|
+
* parsing it as either known model is what §13 forbids outright.
|
|
74
|
+
*
|
|
75
|
+
* Resolved in one place rather than per consumer for the reason `CLOSED_WIDGETS`
|
|
76
|
+
* is: two copies of `tag === undefined ? marker : tag === 'estiva-blocks-1' ?
|
|
77
|
+
* blocks : text` disagree the first time a third format exists, and the
|
|
78
|
+
* disagreement shows up as one app rendering JSON at a person.
|
|
79
|
+
*/
|
|
80
|
+
export type ContentFormat = 'marker' | 'blocks' | 'unknown';
|
|
81
|
+
/**
|
|
82
|
+
* @deprecated The name this shipped under in 0.8.0. It is `ContentFormat`.
|
|
83
|
+
* Kept as an alias so 0.8.0's consumers keep compiling.
|
|
84
|
+
*/
|
|
85
|
+
export type RenderFormat = ContentFormat;
|
|
86
|
+
/** The tag SPEC §13.4 defines. Absence is a declaration, not an omission. */
|
|
87
|
+
export declare const CONTENT_FORMAT_TAG = "content-format";
|
|
88
|
+
/** The one format §13.3 names today. */
|
|
89
|
+
export declare const BLOCK_DOCUMENT_FORMAT = "estiva-blocks-1";
|
|
90
|
+
/**
|
|
91
|
+
* The content model an event's body is in.
|
|
92
|
+
*
|
|
93
|
+
* **Decided by the tag alone.** §13.4 is explicit that a reader MUST NOT decide
|
|
94
|
+
* by inspecting the body: a legacy description that happens to begin with `{`
|
|
95
|
+
* is marker text, because it carries no tag.
|
|
96
|
+
*
|
|
97
|
+
* **Why this lives here and not in `@estiva-app/interop`, where it was born.**
|
|
98
|
+
* It arrived with the projection layer because that is what needed it first,
|
|
99
|
+
* and reading a tag off an event looked like a question about a slot. It is
|
|
100
|
+
* not — it is a question about an event, which is this package's subject. Two
|
|
101
|
+
* folds now need it and neither is a projection consumer: Ship's and the
|
|
102
|
+
* agent's, which are the same fold in two repositories held to one recorded
|
|
103
|
+
* state. Making either of them depend on the projection layer to read a tag
|
|
104
|
+
* would be the wrong direction, and a second copy of the rule is what this
|
|
105
|
+
* package exists to prevent. `interop` re-exports these, so nothing it
|
|
106
|
+
* published has moved.
|
|
107
|
+
*/
|
|
108
|
+
export declare function contentFormatOf(event: SignedEvent): ContentFormat;
|
|
60
109
|
/**
|
|
61
110
|
* The body, resolved.
|
|
62
111
|
*
|
package/dist/render.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,OAAO,EAEL,KAAK,UAAU,EAIhB,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,OAAO,EAEL,KAAK,UAAU,EAIhB,MAAM,cAAc,CAAA;AAErB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C,kFAAkF;AAClF,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,UAAU,EAAE,CAAA;CACpB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EACA,WAAW,GAAG,SAAS,GAAG,YAAY,GAAG,aAAa,GAAG,UAAU,GACnE,YAAY,GAAG,WAAW,GAAG,OAAO,GAAG,gBAAgB,GACvD,YAAY,GAAG,QAAQ,GAAG,SAAS,CAAA;IACvC;oFACgF;IAChF,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,0EAA0E;IAC1E,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,wEAAwE;IACxE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,YAAY,EAAE,CAAA;IACvB,QAAQ,CAAC,EAAE,WAAW,EAAE,CAAA;CACzB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAA;AAE3D;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,aAAa,CAAA;AAExC,6EAA6E;AAC7E,eAAO,MAAM,kBAAkB,mBAAmB,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
|
@@ -31,6 +31,34 @@
|
|
|
31
31
|
*/
|
|
32
32
|
import { parseBodySegments, parseInlineMarks, } from './content.js';
|
|
33
33
|
import { parseBlockDocument, inlineTextOf } from './blocks.js';
|
|
34
|
+
/** The tag SPEC §13.4 defines. Absence is a declaration, not an omission. */
|
|
35
|
+
export const CONTENT_FORMAT_TAG = 'content-format';
|
|
36
|
+
/** The one format §13.3 names today. */
|
|
37
|
+
export const BLOCK_DOCUMENT_FORMAT = 'estiva-blocks-1';
|
|
38
|
+
/**
|
|
39
|
+
* The content model an event's body is in.
|
|
40
|
+
*
|
|
41
|
+
* **Decided by the tag alone.** §13.4 is explicit that a reader MUST NOT decide
|
|
42
|
+
* by inspecting the body: a legacy description that happens to begin with `{`
|
|
43
|
+
* is marker text, because it carries no tag.
|
|
44
|
+
*
|
|
45
|
+
* **Why this lives here and not in `@estiva-app/interop`, where it was born.**
|
|
46
|
+
* It arrived with the projection layer because that is what needed it first,
|
|
47
|
+
* and reading a tag off an event looked like a question about a slot. It is
|
|
48
|
+
* not — it is a question about an event, which is this package's subject. Two
|
|
49
|
+
* folds now need it and neither is a projection consumer: Ship's and the
|
|
50
|
+
* agent's, which are the same fold in two repositories held to one recorded
|
|
51
|
+
* state. Making either of them depend on the projection layer to read a tag
|
|
52
|
+
* would be the wrong direction, and a second copy of the rule is what this
|
|
53
|
+
* package exists to prevent. `interop` re-exports these, so nothing it
|
|
54
|
+
* published has moved.
|
|
55
|
+
*/
|
|
56
|
+
export function contentFormatOf(event) {
|
|
57
|
+
const declared = event.tags.find((t) => t[0] === CONTENT_FORMAT_TAG)?.[1];
|
|
58
|
+
if (declared === undefined || declared === '')
|
|
59
|
+
return 'marker';
|
|
60
|
+
return declared === BLOCK_DOCUMENT_FORMAT ? 'blocks' : 'unknown';
|
|
61
|
+
}
|
|
34
62
|
const KNOWN = new Set([
|
|
35
63
|
'paragraph', 'heading', 'bulletList', 'orderedList', 'listItem',
|
|
36
64
|
'blockquote', 'codeBlock', 'table', 'horizontalRule', 'attachment', 'widget',
|
|
@@ -62,6 +90,7 @@ function blockFromSegment(seg) {
|
|
|
62
90
|
case 'numbered':
|
|
63
91
|
return {
|
|
64
92
|
type: 'orderedList',
|
|
93
|
+
...(seg.start ? { start: seg.start } : {}),
|
|
65
94
|
children: seg.items.map((item) => ({ type: 'listItem', inline: inlineFromMarkers(item) })),
|
|
66
95
|
};
|
|
67
96
|
case 'quote':
|
|
@@ -92,6 +121,9 @@ function blockFromDocument(block) {
|
|
|
92
121
|
const language = block.attrs?.language;
|
|
93
122
|
if (block.type === 'codeBlock' && typeof language === 'string')
|
|
94
123
|
out.language = language;
|
|
124
|
+
const start = block.attrs?.start;
|
|
125
|
+
if (block.type === 'orderedList' && typeof start === 'number' && start > 1)
|
|
126
|
+
out.start = start;
|
|
95
127
|
if (Array.isArray(block.content)) {
|
|
96
128
|
if (isInlineRun(block.content)) {
|
|
97
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,aAAa,CAAA;
|
|
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,aAAa,CAAA;AA8D9F,6EAA6E;AAC7E,MAAM,CAAC,MAAM,kBAAkB,GAAG,gBAAgB,CAAA;AAElD,wCAAwC;AACxC,MAAM,CAAC,MAAM,qBAAqB,GAAG,iBAAiB,CAAA;AAEtD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,eAAe,CAAC,KAAkB;IAChD,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,kBAAkB,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IACzE,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK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AE,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.10.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/blocks.ts
CHANGED
|
@@ -10,13 +10,10 @@
|
|
|
10
10
|
*
|
|
11
11
|
* ## What is deliberately not here
|
|
12
12
|
*
|
|
13
|
-
* **The `content-format` tag.**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* be a second copy of exactly the kind this package exists to prevent, so this
|
|
18
|
-
* module never names it: a document does not know its own tag, and the reader
|
|
19
|
-
* that does is one layer up.
|
|
13
|
+
* **The `content-format` tag.** A document does not know its own tag — the tag
|
|
14
|
+
* is on the event that carries it, and SPEC §13.4's read rule is
|
|
15
|
+
* `contentFormatOf` in `render.ts`. (It lived in `@estiva-app/interop` until
|
|
16
|
+
* two folds outside the projection layer needed it; see that function's note.)
|
|
20
17
|
*
|
|
21
18
|
* **Rendering.** §13.5's safe renderer is RIC-6's, where Ship is the consumer
|
|
22
19
|
* that needs it. What this module owes a renderer is {@link inlineTextOf}, so
|
|
@@ -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.10.0'
|
|
51
51
|
|
|
52
52
|
export {
|
|
53
53
|
// types
|
|
@@ -200,6 +200,15 @@ export {
|
|
|
200
200
|
type RenderInline,
|
|
201
201
|
type RenderBlock,
|
|
202
202
|
type RenderFormat,
|
|
203
|
+
type ContentFormat,
|
|
204
|
+
CONTENT_FORMAT_TAG,
|
|
205
|
+
BLOCK_DOCUMENT_FORMAT,
|
|
206
|
+
contentFormatOf,
|
|
203
207
|
toRenderTree,
|
|
204
208
|
renderTreeText,
|
|
205
209
|
} from './render.js'
|
|
210
|
+
|
|
211
|
+
export {
|
|
212
|
+
markerTextToBlockDocument,
|
|
213
|
+
blockDocumentToMarkerText,
|
|
214
|
+
} from './bridge-content.js'
|
package/src/render.ts
CHANGED
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
parseInlineMarks,
|
|
38
38
|
} from './content.js'
|
|
39
39
|
import { type Block, type BlockDocument, parseBlockDocument, inlineTextOf } from './blocks.js'
|
|
40
|
+
import type { SignedEvent } from './events.js'
|
|
40
41
|
|
|
41
42
|
/** A run of text and the marks on it. Nothing here needs escaping; it is text. */
|
|
42
43
|
export interface RenderInline {
|
|
@@ -61,6 +62,8 @@ export interface RenderBlock {
|
|
|
61
62
|
id?: string
|
|
62
63
|
level?: 1 | 2 | 3
|
|
63
64
|
language?: string
|
|
65
|
+
/** An ordered list's first number, when the author did not start at 1. */
|
|
66
|
+
start?: number
|
|
64
67
|
attrs?: Record<string, unknown>
|
|
65
68
|
/** What the document actually called it, when `type` is `'unknown'`. */
|
|
66
69
|
typeName?: string
|
|
@@ -68,8 +71,62 @@ export interface RenderBlock {
|
|
|
68
71
|
children?: RenderBlock[]
|
|
69
72
|
}
|
|
70
73
|
|
|
71
|
-
/**
|
|
72
|
-
|
|
74
|
+
/**
|
|
75
|
+
* What content model a body is written in — SPEC §13.4.
|
|
76
|
+
*
|
|
77
|
+
* Three values, not two, and not the raw tag string. A consumer makes a
|
|
78
|
+
* three-way decision and **must not guess the third**:
|
|
79
|
+
*
|
|
80
|
+
* - `marker` — the §13.2 dialect. The default, permanently. 731 published
|
|
81
|
+
* bodies carry no tag and none of them can be given one, so this is not a
|
|
82
|
+
* migration window that closes.
|
|
83
|
+
* - `blocks` — a §13.3 JSON block document.
|
|
84
|
+
* - `unknown` — a format declared after this runtime was written. Render the
|
|
85
|
+
* body as plain text; §13.5 says declining to format is conformant, and
|
|
86
|
+
* parsing it as either known model is what §13 forbids outright.
|
|
87
|
+
*
|
|
88
|
+
* Resolved in one place rather than per consumer for the reason `CLOSED_WIDGETS`
|
|
89
|
+
* is: two copies of `tag === undefined ? marker : tag === 'estiva-blocks-1' ?
|
|
90
|
+
* blocks : text` disagree the first time a third format exists, and the
|
|
91
|
+
* disagreement shows up as one app rendering JSON at a person.
|
|
92
|
+
*/
|
|
93
|
+
export type ContentFormat = 'marker' | 'blocks' | 'unknown'
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @deprecated The name this shipped under in 0.8.0. It is `ContentFormat`.
|
|
97
|
+
* Kept as an alias so 0.8.0's consumers keep compiling.
|
|
98
|
+
*/
|
|
99
|
+
export type RenderFormat = ContentFormat
|
|
100
|
+
|
|
101
|
+
/** The tag SPEC §13.4 defines. Absence is a declaration, not an omission. */
|
|
102
|
+
export const CONTENT_FORMAT_TAG = 'content-format'
|
|
103
|
+
|
|
104
|
+
/** The one format §13.3 names today. */
|
|
105
|
+
export const BLOCK_DOCUMENT_FORMAT = 'estiva-blocks-1'
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The content model an event's body is in.
|
|
109
|
+
*
|
|
110
|
+
* **Decided by the tag alone.** §13.4 is explicit that a reader MUST NOT decide
|
|
111
|
+
* by inspecting the body: a legacy description that happens to begin with `{`
|
|
112
|
+
* is marker text, because it carries no tag.
|
|
113
|
+
*
|
|
114
|
+
* **Why this lives here and not in `@estiva-app/interop`, where it was born.**
|
|
115
|
+
* It arrived with the projection layer because that is what needed it first,
|
|
116
|
+
* and reading a tag off an event looked like a question about a slot. It is
|
|
117
|
+
* not — it is a question about an event, which is this package's subject. Two
|
|
118
|
+
* folds now need it and neither is a projection consumer: Ship's and the
|
|
119
|
+
* agent's, which are the same fold in two repositories held to one recorded
|
|
120
|
+
* state. Making either of them depend on the projection layer to read a tag
|
|
121
|
+
* would be the wrong direction, and a second copy of the rule is what this
|
|
122
|
+
* package exists to prevent. `interop` re-exports these, so nothing it
|
|
123
|
+
* published has moved.
|
|
124
|
+
*/
|
|
125
|
+
export function contentFormatOf(event: SignedEvent): ContentFormat {
|
|
126
|
+
const declared = event.tags.find((t) => t[0] === CONTENT_FORMAT_TAG)?.[1]
|
|
127
|
+
if (declared === undefined || declared === '') return 'marker'
|
|
128
|
+
return declared === BLOCK_DOCUMENT_FORMAT ? 'blocks' : 'unknown'
|
|
129
|
+
}
|
|
73
130
|
|
|
74
131
|
const KNOWN: ReadonlySet<string> = new Set([
|
|
75
132
|
'paragraph', 'heading', 'bulletList', 'orderedList', 'listItem',
|
|
@@ -103,6 +160,7 @@ function blockFromSegment(seg: BodySegment): RenderBlock {
|
|
|
103
160
|
case 'numbered':
|
|
104
161
|
return {
|
|
105
162
|
type: 'orderedList',
|
|
163
|
+
...(seg.start ? { start: seg.start } : {}),
|
|
106
164
|
children: seg.items.map((item) => ({ type: 'listItem' as const, inline: inlineFromMarkers(item) })),
|
|
107
165
|
}
|
|
108
166
|
case 'quote':
|
|
@@ -134,6 +192,8 @@ function blockFromDocument(block: Block): RenderBlock {
|
|
|
134
192
|
if (block.type === 'heading' && (level === 1 || level === 2 || level === 3)) out.level = level
|
|
135
193
|
const language = block.attrs?.language
|
|
136
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
|
|
137
197
|
|
|
138
198
|
if (Array.isArray(block.content)) {
|
|
139
199
|
if (isInlineRun(block.content)) {
|