@estiva-app/protocol 0.34.0 → 0.36.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 +30 -0
- package/dist/bridge-content.d.ts +6 -0
- package/dist/bridge-content.d.ts.map +1 -1
- package/dist/bridge-content.js +39 -14
- package/dist/bridge-content.js.map +1 -1
- package/dist/content.d.ts +14 -1
- package/dist/content.d.ts.map +1 -1
- package/dist/content.js +112 -2
- package/dist/content.js.map +1 -1
- package/dist/description-text.d.ts +35 -0
- package/dist/description-text.d.ts.map +1 -0
- package/dist/description-text.js +199 -0
- package/dist/description-text.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/bridge-content.ts +47 -12
- package/src/content.ts +106 -3
- package/src/description-text.ts +204 -0
- package/src/index.ts +3 -1
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A description's text, read whole — SPEC §13.3 "A description as text".
|
|
3
|
+
*
|
|
4
|
+
* {@link markerTextToBlockDocument} with `{ description: true }` reads every
|
|
5
|
+
* block that text spells except one: a table, which §13.2's markers have no
|
|
6
|
+
* syntax for. This reads that too — a GFM pipe table (a header row, a `| --- |`
|
|
7
|
+
* row, then rows, `\|` for a pipe in a cell) becomes a `table` block shaped as
|
|
8
|
+
* an editor saves one. It is the one reader for text that becomes a
|
|
9
|
+
* description: the agent's `edit-issue`, and a markdown paste into an editor
|
|
10
|
+
* that saves a block document (LEAF-10). Moved here from the agent CLI
|
|
11
|
+
* (RIC-20, estiva-agent#75) so the two cannot read the same text differently.
|
|
12
|
+
*
|
|
13
|
+
* A message's text is not read this way: §13.2 has no table, so a pasted table
|
|
14
|
+
* stays text in a message (Miky, 2026-10-15, LEAF-10).
|
|
15
|
+
*/
|
|
16
|
+
import { inlineTextOf, newBlockId } from './blocks.js';
|
|
17
|
+
import { blockDocumentToMarkerText, markerTextToBlockDocument } from './bridge-content.js';
|
|
18
|
+
import { fenceCloses } from './content.js';
|
|
19
|
+
const DESCRIPTION = { description: true };
|
|
20
|
+
const doc = (content) => ({ type: 'doc', content });
|
|
21
|
+
/** Child blocks, as opposed to an inline run or nothing. */
|
|
22
|
+
const childBlocks = (block) => Array.isArray(block.content) && block.content.length > 0 && block.content.every((node) => typeof node.id === 'string')
|
|
23
|
+
? block.content
|
|
24
|
+
: undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Text as a description's block document: marker text read with
|
|
27
|
+
* `{ description: true }`, with each GFM pipe table read as a `table` block.
|
|
28
|
+
* A table is a block boundary, so it stands in the marker text as a
|
|
29
|
+
* placeholder paragraph of its own. `previous` lends the other blocks their
|
|
30
|
+
* ids by index among the blocks that are not tables, so a table added or
|
|
31
|
+
* removed above a paragraph does not cost that paragraph its id. A table
|
|
32
|
+
* takes the ids of a table in `previous` that prints the same; failing that,
|
|
33
|
+
* of the table at its position, but only when the text has as many tables as
|
|
34
|
+
* `previous` — else a deleted table's ids would pass to the next one.
|
|
35
|
+
*/
|
|
36
|
+
export function descriptionTextToBlockDocument(text, previous) {
|
|
37
|
+
const before = previous?.content ?? [];
|
|
38
|
+
const mark = placeholderFor(text);
|
|
39
|
+
const tables = [];
|
|
40
|
+
const lines = text.split('\n');
|
|
41
|
+
const out = [];
|
|
42
|
+
for (let i = 0; i < lines.length; i++) {
|
|
43
|
+
const line = lines[i];
|
|
44
|
+
const fenceEnd = fenceCloses(lines, i);
|
|
45
|
+
if (fenceEnd !== -1) {
|
|
46
|
+
out.push(...lines.slice(i, fenceEnd + 1));
|
|
47
|
+
i = fenceEnd;
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const header = PIPE.test(line) ? rowCells(line) : undefined;
|
|
51
|
+
if (!header || i + 1 >= lines.length || !isSeparator(lines[i + 1], header.length)) {
|
|
52
|
+
out.push(line);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const rows = [header];
|
|
56
|
+
for (i += 2; i < lines.length && lines[i].trim() && PIPE.test(lines[i]); i++)
|
|
57
|
+
rows.push(rowCells(lines[i]));
|
|
58
|
+
i--;
|
|
59
|
+
out.push('', `${mark}${tables.length}${mark}`, '');
|
|
60
|
+
tables.push(rows);
|
|
61
|
+
}
|
|
62
|
+
const aligned = before.filter((block) => block.type !== 'table');
|
|
63
|
+
if (!tables.length)
|
|
64
|
+
return markerTextToBlockDocument(text, doc(aligned), DESCRIPTION);
|
|
65
|
+
// Which blocks are tables' places is known before ids are lent: the blocks
|
|
66
|
+
// the text spells do not depend on `previous`.
|
|
67
|
+
const marked = out.join('\n');
|
|
68
|
+
const places = new Map(tables.map((_, n) => [`${mark}${n}${mark}`, n]));
|
|
69
|
+
const placeOf = (block) => (block.type === 'paragraph' ? places.get(inlineTextOf(block)) : undefined);
|
|
70
|
+
markerTextToBlockDocument(marked, undefined, DESCRIPTION).content.forEach((block, i) => {
|
|
71
|
+
if (placeOf(block) !== undefined)
|
|
72
|
+
aligned.splice(i, 0, { type: 'paragraph', id: '' });
|
|
73
|
+
});
|
|
74
|
+
const oldTables = before.filter((block) => block.type === 'table');
|
|
75
|
+
const used = new Set();
|
|
76
|
+
const lend = (rows, n) => {
|
|
77
|
+
const printed = tableToDescriptionText(tableBlock(rows, undefined));
|
|
78
|
+
const same = oldTables.find((old) => !used.has(old) && printed !== undefined && tableToDescriptionText(old) === printed);
|
|
79
|
+
const positional = oldTables.length === tables.length && !used.has(oldTables[n]) ? oldTables[n] : undefined;
|
|
80
|
+
const old = same ?? positional;
|
|
81
|
+
if (old)
|
|
82
|
+
used.add(old);
|
|
83
|
+
return old;
|
|
84
|
+
};
|
|
85
|
+
return doc(markerTextToBlockDocument(marked, doc(aligned), DESCRIPTION).content.map((block) => {
|
|
86
|
+
const n = placeOf(block);
|
|
87
|
+
return n === undefined ? block : tableBlock(tables[n], lend(tables[n], n));
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* A mark the text does not hold, so nothing a person writes — or pastes — is
|
|
92
|
+
* mistaken for a table's place: a private-use character, or, in text that
|
|
93
|
+
* holds every one of them, one followed by a counter.
|
|
94
|
+
*/
|
|
95
|
+
function placeholderFor(text) {
|
|
96
|
+
for (let code = 0xe000; code <= 0xf8ff; code++) {
|
|
97
|
+
const mark = String.fromCharCode(code);
|
|
98
|
+
if (!text.includes(mark))
|
|
99
|
+
return mark;
|
|
100
|
+
}
|
|
101
|
+
let n = 0;
|
|
102
|
+
while (text.includes(`${n}x`))
|
|
103
|
+
n++;
|
|
104
|
+
return `${n}x`;
|
|
105
|
+
}
|
|
106
|
+
/** An unescaped pipe: a line that can be a table's header or row. */
|
|
107
|
+
const PIPE = /(?<!\\)\|/;
|
|
108
|
+
/** A row's cells, outer pipes optional, `\|` read as a literal pipe. */
|
|
109
|
+
function rowCells(line) {
|
|
110
|
+
const inner = line.trim().replace(/^\|/, '').replace(/(?<!\\)\|$/, '');
|
|
111
|
+
return inner.split(/(?<!\\)\|/).map((cell) => cell.trim().replace(/\\\|/g, '|'));
|
|
112
|
+
}
|
|
113
|
+
/** GFM's delimiter row: one `---` (optionally `:`-aligned) per header cell. */
|
|
114
|
+
function isSeparator(line, width) {
|
|
115
|
+
if (!PIPE.test(line))
|
|
116
|
+
return false;
|
|
117
|
+
const cells = rowCells(line);
|
|
118
|
+
return cells.length === width && cells.every((cell) => /^:?-+:?$/.test(cell));
|
|
119
|
+
}
|
|
120
|
+
/** A table as wide as its widest row, so no cell's text is lost. */
|
|
121
|
+
function tableBlock(rows, old) {
|
|
122
|
+
const width = Math.max(...rows.map((cells) => cells.length));
|
|
123
|
+
const oldRows = old ? (childBlocks(old) ?? []) : [];
|
|
124
|
+
return {
|
|
125
|
+
type: 'table',
|
|
126
|
+
id: old?.id ?? newBlockId(),
|
|
127
|
+
content: rows.map((cells, r) => {
|
|
128
|
+
const oldCells = oldRows[r] ? (childBlocks(oldRows[r]) ?? []) : [];
|
|
129
|
+
const type = r === 0 ? 'tableHeader' : 'tableCell';
|
|
130
|
+
return {
|
|
131
|
+
type: 'tableRow',
|
|
132
|
+
id: oldRows[r]?.id ?? newBlockId(),
|
|
133
|
+
content: Array.from({ length: width }, (_, c) => tableCell(type, cells[c] ?? '', oldCells[c]?.type === type ? oldCells[c] : undefined)),
|
|
134
|
+
};
|
|
135
|
+
}),
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/** A cell as an editor saves one: one paragraph, the text's inline marks kept. */
|
|
139
|
+
function tableCell(type, text, old) {
|
|
140
|
+
const [parsed, ...more] = text ? markerTextToBlockDocument(text).content : [];
|
|
141
|
+
const paragraph = parsed?.type === 'paragraph' && !more.length ? parsed : text ? { type: 'paragraph', id: '', content: [{ type: 'text', text }] } : { type: 'paragraph', id: '' };
|
|
142
|
+
const oldParagraph = old ? childBlocks(old)?.[0] : undefined;
|
|
143
|
+
return {
|
|
144
|
+
type,
|
|
145
|
+
id: old?.id ?? newBlockId(),
|
|
146
|
+
attrs: old?.attrs ?? { colspan: 1, rowspan: 1 },
|
|
147
|
+
content: [{ ...paragraph, id: oldParagraph?.type === 'paragraph' ? oldParagraph.id : newBlockId() }],
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* A table as GFM text, for a table text can carry: a header row first, and
|
|
152
|
+
* each cell one paragraph on one line. `undefined` for any other table, which
|
|
153
|
+
* §13.3 gives no spelling.
|
|
154
|
+
*/
|
|
155
|
+
export function tableToDescriptionText(block) {
|
|
156
|
+
const rows = (childBlocks(block) ?? []).map((row) => childBlocks(row) ?? []);
|
|
157
|
+
if (!rows.length || !rows[0].length)
|
|
158
|
+
return undefined;
|
|
159
|
+
const lines = [];
|
|
160
|
+
for (const [r, cells] of rows.entries()) {
|
|
161
|
+
if (cells.some((cell) => cell.type !== (r === 0 ? 'tableHeader' : 'tableCell')))
|
|
162
|
+
return undefined;
|
|
163
|
+
const texts = cells.map((cell) => {
|
|
164
|
+
const children = childBlocks(cell) ?? [];
|
|
165
|
+
if (children.length > 1 || (children[0] && children[0].type !== 'paragraph'))
|
|
166
|
+
return undefined;
|
|
167
|
+
const line = children[0] && Array.isArray(children[0].content) ? cellParagraphText(children[0]) : '';
|
|
168
|
+
return line.includes('\n') ? undefined : line.replace(/\|/g, '\\|');
|
|
169
|
+
});
|
|
170
|
+
if (texts.some((t) => t === undefined))
|
|
171
|
+
return undefined;
|
|
172
|
+
lines.push(`| ${texts.join(' | ')} |`);
|
|
173
|
+
if (r === 0)
|
|
174
|
+
lines.push(`| ${cells.map(() => '---').join(' | ')} |`);
|
|
175
|
+
}
|
|
176
|
+
return lines.join('\n');
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* A cell's paragraph as marker text, with the whitespace that ends its run
|
|
180
|
+
* dropped first: an editor saves some runs as `"text\n"`, which nobody sees
|
|
181
|
+
* but which would make the cell two lines.
|
|
182
|
+
*/
|
|
183
|
+
const cellParagraphText = (paragraph) => blockDocumentToMarkerText(doc([trimRun(paragraph)]), DESCRIPTION);
|
|
184
|
+
function trimRun(block) {
|
|
185
|
+
const run = [...block.content];
|
|
186
|
+
while (run.length) {
|
|
187
|
+
const last = run[run.length - 1];
|
|
188
|
+
if (last.type !== 'text' || typeof last.text !== 'string')
|
|
189
|
+
break;
|
|
190
|
+
const trimmedText = last.text.trimEnd();
|
|
191
|
+
if (trimmedText) {
|
|
192
|
+
run[run.length - 1] = { ...last, text: trimmedText };
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
run.pop();
|
|
196
|
+
}
|
|
197
|
+
return { ...block, content: run };
|
|
198
|
+
}
|
|
199
|
+
//# sourceMappingURL=description-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"description-text.js","sourceRoot":"","sources":["../src/description-text.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAkC,YAAY,EAAE,UAAU,EAAE,MA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AK,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IACtE,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACzB,CAAC;AAED;;;;GAIG;AACH,MAAM,iBAAiB,GAAG,CAAC,SAAgB,EAAE,EAAE,CAAC,yBAAyB,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,CAAA;AAEjH,SAAS,OAAO,CAAC,KAAY;IAC3B,MAAM,GAAG,GAAG,CAAC,GAAI,KAAK,CAAC,OAA6C,CAAC,CAAA;IACrE,OAAO,GAAG,CAAC,MAAM,EAAE,CAAC;QAClB,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;QAChC,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ;YAAE,MAAK;QAChE,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAA;QACvC,IAAI,WAAW,EAAE,CAAC;YAChB,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,CAAA;YACpD,MAAK;QACP,CAAC;QACD,GAAG,CAAC,GAAG,EAAE,CAAA;IACX,CAAC;IACD,OAAO,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,GAAuB,EAAE,CAAA;AACvD,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.36.0";
|
|
50
50
|
export { type NostrTag, type UnsignedEvent, type SignedEvent, type Profile, type ThreadRef, type ChannelVisibility, type ChannelKind, type MemberRole, type FolderOp, type Label, type ResolutionAction, KIND, MAX_EMOJI_CHARS, MAX_MESSAGE_BYTES, MAX_MENTIONS, MAX_DM_OTHERS, MAX_RATIONALE_BYTES, RELAY_AUTH_TOLERANCE_SECS, ASSERTION_SUBTYPE, computeEventId, toNostrSeconds, canonicalChannelName, threadTags, addr, relayAuthUrl, buildProfile, parseProfile, buildCreateChannel, buildDeleteChannel, buildEditChannelMetadata, buildFolderCommand, buildAddMember, buildDmOpen, buildDmHide, buildReaction, buildDeletion, buildEdit, buildMessage, buildResolution, buildBareFile, buildDocument, 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, encodeNpub, decodeNpub, NOSTR_URI_RE, findNostrUris, } from './nip19.js';
|
|
52
52
|
export { type AuthEventArgs, TIMESTAMP_TOLERANCE_SECS, normalizeUrl, buildUnsignedAuthEvent, base64, authorizationHeaderFor, authorizationHeader, } from './nip98.js';
|
|
@@ -58,6 +58,7 @@ export { type InlineMark, type InlineMarkSpan, type BodySegment, type InlineMark
|
|
|
58
58
|
export { type Block, type BlockDocument, type KnownBlockType, KNOWN_BLOCK_TYPES, BlockDocumentError, validateBlockDocument, parseBlockDocument, serializeBlockDocument, newBlockId, assignMissingBlockIds, blockIds, findBlock, listItemDepths, MAX_LIST_DEPTH, listItemChecked, CALLOUT_TONES, type CalloutTone, calloutTone, 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, standaloneReference, referencesIn, type BlockCard, blockCards, cardLayout, } from './render.js';
|
|
60
60
|
export { markerTextToBlockDocument, blockDocumentToMarkerText, type DescriptionTextOptions, } from './bridge-content.js';
|
|
61
|
+
export { descriptionTextToBlockDocument, tableToDescriptionText } from './description-text.js';
|
|
61
62
|
export { type EditorNode, type EditorDocument, EDITOR_BLOCK_TYPES, UNKNOWN_BLOCK_NODE, REFERENCE_NODE, documentForEditing, toEditorDocument, fromEditorDocument, publishableFromEditor, } from './editor.js';
|
|
62
63
|
export { type BlockAnchor, type Part, type PartPointer, type PartSource, BLOCK_ANCHOR_TAG, PART_TAG, absenceOf, blockAnchorOf, partTag, partsOf, resolveBlockAnchor, resolvePart, } from './anchors.js';
|
|
63
64
|
export { type Embed, type EmbedLayout, type LinkResolver, EMBED_TAG, cardsIn, embedTag, embedsOf, linksAsReferences, referenceOfLink, urlRunsIn } from './embeds.js';
|
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,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,QAAQ,EACb,KAAK,KAAK,EACV,KAAK,gBAAgB,EAErB,IAAI,EACJ,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB,EAEjB,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,UAAU,EACV,IAAI,EACJ,YAAY,EA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,OAAO,EACP,kBAAkB,EAClB,WAAW,GACZ,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,WAAW,EAAE,KAAK,YAAY,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,iBAAiB,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACpK,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,KAAK,EACV,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,QAAQ,EACR,OAAO,EACP,cAAc,EACd,qBAAqB,EACrB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,WAAW,EAChB,kBAAkB,EAClB,SAAS,EACT,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,iBAAiB,EACjB,KAAK,YAAY,EACjB,KAAK,mBAAmB,GACzB,MAAM,YAAY,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.36.0';
|
|
50
50
|
export {
|
|
51
51
|
// constants
|
|
52
52
|
KIND, MAX_EMOJI_CHARS, MAX_MESSAGE_BYTES, MAX_MENTIONS, MAX_DM_OTHERS, MAX_RATIONALE_BYTES, RELAY_AUTH_TOLERANCE_SECS, ASSERTION_SUBTYPE,
|
|
@@ -64,6 +64,7 @@ export { parseInlineMarks, wrapInlineMarks, parseBodySegments, stripInlineFormat
|
|
|
64
64
|
export { KNOWN_BLOCK_TYPES, BlockDocumentError, validateBlockDocument, parseBlockDocument, serializeBlockDocument, newBlockId, assignMissingBlockIds, blockIds, findBlock, listItemDepths, MAX_LIST_DEPTH, listItemChecked, CALLOUT_TONES, calloutTone, inlineTextOf, documentText, } from './blocks.js';
|
|
65
65
|
export { CONTENT_FORMAT_TAG, BLOCK_DOCUMENT_FORMAT, contentFormatOf, toRenderTree, renderTreeText, standaloneReference, referencesIn, blockCards, cardLayout, } from './render.js';
|
|
66
66
|
export { markerTextToBlockDocument, blockDocumentToMarkerText, } from './bridge-content.js';
|
|
67
|
+
export { descriptionTextToBlockDocument, tableToDescriptionText } from './description-text.js';
|
|
67
68
|
export { EDITOR_BLOCK_TYPES, UNKNOWN_BLOCK_NODE, REFERENCE_NODE, documentForEditing, toEditorDocument, fromEditorDocument, publishableFromEditor, } from './editor.js';
|
|
68
69
|
export { BLOCK_ANCHOR_TAG, PART_TAG, absenceOf, blockAnchorOf, partTag, partsOf, resolveBlockAnchor, resolvePart, } from './anchors.js';
|
|
69
70
|
export { EMBED_TAG, cardsIn, embedTag, embedsOf, linksAsReferences, referenceOfLink, urlRunsIn } from './embeds.js';
|
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,QAAQ,CAAA;AAExC,OAAO;AAaL,YAAY;AACZ,IAAI,EACJ,eAAe,EACf,iBAAiB,EACjB,YAAY,EACZ,aAAa,EACb,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,kBAAkB,EAClB,cAAc,EACd,WAAW,EACX,WAAW,EACX,aAAa,EACb,aAAa,EACb,SAAS,EACT,YAAY,EACZ,eAAe,EACf,aAAa,E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AAA;AAEpB,OAAO,EAKL,kBAAkB,EAClB,qBAAqB,EACrB,eAAe,EACf,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,YAAY,EAEZ,UAAU,EACV,UAAU,GACX,MAAM,aAAa,CAAA;AAEpB,OAAO,EACL,yBAAyB,EACzB,yBAAyB,GAE1B,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EAAE,8BAA8B,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAE9F,OAAO,EAGL,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,qBAAqB,GACtB,MAAM,aAAa,CAAA;AAEpB,OAAO,EAKL,gBAAgB,EAChB,QAAQ,EACR,SAAS,EACT,aAAa,EACb,OAAO,EACP,OAAO,EACP,kBAAkB,EAClB,WAAW,GACZ,MAAM,cAAc,CAAA;AACrB,OAAO,EAAmD,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,iBAAiB,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACpK,OAAO,EAGL,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,QAAQ,EACR,OAAO,EACP,cAAc,EACd,qBAAqB,EAIrB,kBAAkB,EAClB,SAAS,EACT,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,iBAAiB,GAGlB,MAAM,YAAY,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estiva-app/protocol",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.36.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/bridge-content.ts
CHANGED
|
@@ -68,6 +68,12 @@ const keyOf = (block: Block) => `${block.type}\u0000${textOf(block)}`
|
|
|
68
68
|
* a checklist item as `- [ ] ` / `- [x] `, GFM's task list, and a callout as a
|
|
69
69
|
* quote whose first line is `[!NOTE]`, GitHub's alert. **Descriptions only**
|
|
70
70
|
* (Miky, 2026-10-13): a message stays §13.2's dialect, where `[x]` is text.
|
|
71
|
+
*
|
|
72
|
+
* Two more, so every list and quote reads back as it printed (d98a5636): an
|
|
73
|
+
* indented item (`attrs.indent`) is spelled two spaces a level and read
|
|
74
|
+
* relative to the item above; and a plain item or quote whose text would read
|
|
75
|
+
* as one of the above is escaped with one more `\` in front, which reading
|
|
76
|
+
* takes off again — `- \[ ] brackets` is a plain item whose text is `[ ] brackets`.
|
|
71
77
|
*/
|
|
72
78
|
export interface DescriptionTextOptions {
|
|
73
79
|
description?: boolean
|
|
@@ -75,21 +81,46 @@ export interface DescriptionTextOptions {
|
|
|
75
81
|
|
|
76
82
|
const TASK = /^\[( |x|X)\] /
|
|
77
83
|
const ALERT = /^\[!([A-Za-z]+)\]$/
|
|
84
|
+
/** Text that reads as a checklist box or a callout line — after any backslashes, which the escape adds one of. */
|
|
85
|
+
const ESCAPED_TASK = /^\\*\[( |x|X)\] /
|
|
86
|
+
const ESCAPED_ALERT = /^\\*\[![A-Za-z]+\]$/
|
|
87
|
+
|
|
88
|
+
/** One `\` more in front of text that would otherwise read as `pattern`, after `lead` whitespace. */
|
|
89
|
+
function escaped(text: string, pattern: RegExp): string {
|
|
90
|
+
const lead = text.length - text.trimStart().length
|
|
91
|
+
return reads(text.slice(lead), pattern) ? `${text.slice(0, lead)}\\${text.slice(lead)}` : text
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The inverse of {@link escaped}: one `\` fewer. */
|
|
95
|
+
function unescaped(text: string, pattern: RegExp): string {
|
|
96
|
+
const lead = text.length - text.trimStart().length
|
|
97
|
+
return text[lead] === '\\' && reads(text.slice(lead), pattern) ? text.slice(0, lead) + text.slice(lead + 1) : text
|
|
98
|
+
}
|
|
78
99
|
|
|
79
|
-
|
|
100
|
+
/** As written or with its trailing space dropped: a box needs the space after `]`, a callout line ends at `]`. */
|
|
101
|
+
const reads = (text: string, pattern: RegExp) => pattern.test(text) || pattern.test(text.trimEnd())
|
|
102
|
+
|
|
103
|
+
function itemFromText(item: string, description: boolean, depth = 0): Block {
|
|
104
|
+
const indent = depth > 0 ? { indent: depth } : undefined
|
|
80
105
|
const task = description ? TASK.exec(item) : null
|
|
81
|
-
if (!task)
|
|
106
|
+
if (!task) {
|
|
107
|
+
const text = description ? unescaped(item, ESCAPED_TASK) : item
|
|
108
|
+
return { type: 'listItem', id: '', ...(indent ? { attrs: indent } : {}), content: markersToInlineNodes(text) }
|
|
109
|
+
}
|
|
82
110
|
return {
|
|
83
111
|
type: 'listItem',
|
|
84
112
|
id: '',
|
|
85
|
-
attrs: { checked: task[1] !== ' ' },
|
|
113
|
+
attrs: { ...indent, checked: task[1] !== ' ' },
|
|
86
114
|
content: markersToInlineNodes(item.slice(task[0].length)),
|
|
87
115
|
}
|
|
88
116
|
}
|
|
89
117
|
|
|
90
118
|
function quoteFromLines(lines: string[], description: boolean): Block {
|
|
91
119
|
const alert = description && lines.length > 0 ? ALERT.exec(lines[0].trim()) : null
|
|
92
|
-
if (!alert)
|
|
120
|
+
if (!alert) {
|
|
121
|
+
const text = description && lines.length > 0 ? [unescaped(lines[0], ESCAPED_ALERT), ...lines.slice(1)] : lines
|
|
122
|
+
return { type: 'blockquote', id: '', content: markersToInlineNodes(text.join('\n')) }
|
|
123
|
+
}
|
|
93
124
|
/*
|
|
94
125
|
The kind is kept as written, lowercased: a tone this version does not know
|
|
95
126
|
is still a callout, and the next save must not turn it into a `note`.
|
|
@@ -105,14 +136,14 @@ function blockFromSegment(seg: BodySegment, description: boolean): Block {
|
|
|
105
136
|
return {
|
|
106
137
|
type: 'bulletList',
|
|
107
138
|
id: '',
|
|
108
|
-
content: seg.items.map((item) => itemFromText(item, description)),
|
|
139
|
+
content: seg.items.map((item, i) => itemFromText(item, description, seg.depths?.[i])),
|
|
109
140
|
}
|
|
110
141
|
case 'numbered':
|
|
111
142
|
return {
|
|
112
143
|
type: 'orderedList',
|
|
113
144
|
id: '',
|
|
114
145
|
...(seg.start ? { attrs: { start: seg.start } } : {}),
|
|
115
|
-
content: seg.items.map((item) => itemFromText(item, description)),
|
|
146
|
+
content: seg.items.map((item, i) => itemFromText(item, description, seg.depths?.[i])),
|
|
116
147
|
}
|
|
117
148
|
case 'quote':
|
|
118
149
|
return quoteFromLines(seg.lines, description)
|
|
@@ -134,7 +165,8 @@ function blockFromSegment(seg: BodySegment, description: boolean): Block {
|
|
|
134
165
|
* still corresponds. The matching rule is in this module's header.
|
|
135
166
|
*/
|
|
136
167
|
export function markerTextToBlockDocument(text: string, previous?: BlockDocument, options: DescriptionTextOptions = {}): BlockDocument {
|
|
137
|
-
const
|
|
168
|
+
const description = options.description === true
|
|
169
|
+
const fresh = parseBodySegments(text, { indentedItems: description }).map((seg) => blockFromSegment(seg, description))
|
|
138
170
|
const old = previous?.content ?? []
|
|
139
171
|
const takenIds = new Set<string>()
|
|
140
172
|
const usedOld = new Set<number>()
|
|
@@ -222,9 +254,9 @@ export function blockDocumentToMarkerText(doc: BlockDocument, options: Descripti
|
|
|
222
254
|
case 'orderedList': {
|
|
223
255
|
/*
|
|
224
256
|
An indented item (MAN-13) is spelled two spaces a level, as Markdown
|
|
225
|
-
does.
|
|
226
|
-
|
|
227
|
-
|
|
257
|
+
does. A description's text reads it back at its depth (d98a5636); a
|
|
258
|
+
message's §13.2 has no nesting, so there it reads back level — still
|
|
259
|
+
every item.
|
|
228
260
|
*/
|
|
229
261
|
const items = (block.content as Block[]) ?? []
|
|
230
262
|
const depths = listItemDepths(items)
|
|
@@ -238,7 +270,8 @@ export function blockDocumentToMarkerText(doc: BlockDocument, options: Descripti
|
|
|
238
270
|
const marker = block.type === 'bulletList' ? '-' : `${next[depth]++}.`
|
|
239
271
|
const checked = description ? listItemChecked(item) : undefined
|
|
240
272
|
const task = checked === undefined ? '' : checked ? '[x] ' : '[ ] '
|
|
241
|
-
|
|
273
|
+
const text = description && checked === undefined ? escaped(itemText(item), ESCAPED_TASK) : itemText(item)
|
|
274
|
+
lines.push(`${' '.repeat(depth)}${marker} ${task}${text}`)
|
|
242
275
|
})
|
|
243
276
|
break
|
|
244
277
|
}
|
|
@@ -246,7 +279,9 @@ export function blockDocumentToMarkerText(doc: BlockDocument, options: Descripti
|
|
|
246
279
|
// The tone as written, not as `calloutTone` reads it: the next save reads back what this spelled.
|
|
247
280
|
const tone = description && typeof block.attrs?.tone === 'string' && /^[A-Za-z]+$/.test(block.attrs.tone) ? block.attrs.tone : ''
|
|
248
281
|
if (tone) lines.push(`> [!${tone.toUpperCase()}]`)
|
|
249
|
-
|
|
282
|
+
const quoted = inline.split('\n')
|
|
283
|
+
if (description && !tone) quoted[0] = escaped(quoted[0], ESCAPED_ALERT)
|
|
284
|
+
for (const line of quoted) lines.push(`> ${line}`)
|
|
250
285
|
break
|
|
251
286
|
}
|
|
252
287
|
case 'codeBlock': {
|
package/src/content.ts
CHANGED
|
@@ -25,6 +25,8 @@
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
import { NOSTR_URI_RE } from './nip19.js'
|
|
28
|
+
// blocks.js imports this module too; MAX_LIST_DEPTH is read only when a body is parsed, never at load.
|
|
29
|
+
import { MAX_LIST_DEPTH } from './blocks.js'
|
|
28
30
|
|
|
29
31
|
/** Marks a run of text can carry. `code` is exclusive — see {@link parseInlineMarks}. */
|
|
30
32
|
export type InlineMark = 'bold' | 'italic' | 'underline' | 'code'
|
|
@@ -50,10 +52,12 @@ export interface InlineMarkSpan {
|
|
|
50
52
|
/** A block-level run, parsed from line prefixes. */
|
|
51
53
|
export type BodySegment =
|
|
52
54
|
| { type: 'text'; lines: string[] }
|
|
53
|
-
| { type: 'bullet'; items: string[] }
|
|
55
|
+
| { type: 'bullet'; items: string[]; depths?: number[] }
|
|
54
56
|
| {
|
|
55
57
|
type: 'numbered'
|
|
56
58
|
items: string[]
|
|
59
|
+
/** How deep each item sits, when it was read with `indentedItems` and any is indented. */
|
|
60
|
+
depths?: number[]
|
|
57
61
|
/**
|
|
58
62
|
* The number the author actually wrote, when it is not 1.
|
|
59
63
|
*
|
|
@@ -232,7 +236,7 @@ const FENCE_RE = /^```/
|
|
|
232
236
|
* render literally, and swallowing the rest of the body because somebody typed
|
|
233
237
|
* three backticks is the opposite of that.
|
|
234
238
|
*/
|
|
235
|
-
function fenceCloses(lines: string[], from: number): number {
|
|
239
|
+
export function fenceCloses(lines: string[], from: number): number {
|
|
236
240
|
if (!FENCE_RE.test(lines[from])) return -1
|
|
237
241
|
for (let j = from + 1; j < lines.length; j++) if (FENCE_RE.test(lines[j])) return j
|
|
238
242
|
return -1
|
|
@@ -245,8 +249,9 @@ function fenceCloses(lines: string[], from: number): number {
|
|
|
245
249
|
* `## ` become headings; three or more `#`s, and a `#123` reference with no
|
|
246
250
|
* space, stay plain text.
|
|
247
251
|
*/
|
|
248
|
-
export function parseBodySegments(body: string): BodySegment[] {
|
|
252
|
+
export function parseBodySegments(body: string, options: { indentedItems?: boolean } = {}): BodySegment[] {
|
|
249
253
|
const lines = body.split('\n')
|
|
254
|
+
if (options.indentedItems) return parseWithIndentedItems(lines)
|
|
250
255
|
const segments: BodySegment[] = []
|
|
251
256
|
let i = 0
|
|
252
257
|
while (i < lines.length) {
|
|
@@ -316,6 +321,104 @@ export function parseBodySegments(body: string): BodySegment[] {
|
|
|
316
321
|
return segments
|
|
317
322
|
}
|
|
318
323
|
|
|
324
|
+
/** A list item line at any indentation: its leading whitespace, its marker, its text. */
|
|
325
|
+
// `[\s\S]`, not `.`: `.` stops at `\r` and U+2028/9, which the opener's test does not (review of d98a5636).
|
|
326
|
+
const INDENTED_ITEM_RE = /^([ \t]*)([-•]|\d+\.)\s([\s\S]*)$/
|
|
327
|
+
const columnOf = (lead: string) => [...lead].reduce((column, c) => column + (c === '\t' ? 4 : 1), 0)
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* {@link parseBodySegments} for a description's text (d98a5636), where an
|
|
331
|
+
* indented list item is one level deeper (§13.3 `attrs.indent`). Only a line at
|
|
332
|
+
* column 0 opens a list, as before; while one is open, an indented item of
|
|
333
|
+
* either marker continues it, because a list is flat on the wire and every
|
|
334
|
+
* indented item is of its list's type.
|
|
335
|
+
*
|
|
336
|
+
* Depth is read relative to the item above, not as a column count, so two,
|
|
337
|
+
* three or four spaces all mean "under the item above": an item indented
|
|
338
|
+
* further than the one above is one level below it; otherwise it is at the
|
|
339
|
+
* level of the nearest item above it at the same or a lesser indentation. Never
|
|
340
|
+
* deeper than {@link MAX_LIST_DEPTH}, the rule §13.3 already gives.
|
|
341
|
+
*/
|
|
342
|
+
function parseWithIndentedItems(lines: string[]): BodySegment[] {
|
|
343
|
+
const segments: BodySegment[] = []
|
|
344
|
+
const fenced = fencedLines(lines)
|
|
345
|
+
let rest: string[] = []
|
|
346
|
+
const flush = () => {
|
|
347
|
+
if (rest.length) segments.push(...parseBodySegments(rest.join('\n')))
|
|
348
|
+
rest = []
|
|
349
|
+
}
|
|
350
|
+
let i = 0
|
|
351
|
+
while (i < lines.length) {
|
|
352
|
+
const opens = /^[-•]\s/.test(lines[i]) ? 'bullet' : /^\d+\.\s/.test(lines[i]) ? 'numbered' : undefined
|
|
353
|
+
// A line inside a fence is the plain parser's, with the fence around it.
|
|
354
|
+
if (!opens || fenced[i]) {
|
|
355
|
+
rest.push(lines[i++])
|
|
356
|
+
continue
|
|
357
|
+
}
|
|
358
|
+
flush()
|
|
359
|
+
const items: string[] = []
|
|
360
|
+
const depths: number[] = []
|
|
361
|
+
// The open items an item can sit under: columns rising, each with its depth.
|
|
362
|
+
const stack: { column: number; depth: number }[] = []
|
|
363
|
+
while (i < lines.length) {
|
|
364
|
+
const match = INDENTED_ITEM_RE.exec(lines[i])
|
|
365
|
+
if (!match) break
|
|
366
|
+
const column = columnOf(match[1])
|
|
367
|
+
const kind = /^\d/.test(match[2]) ? 'numbered' : 'bullet'
|
|
368
|
+
if (column === 0 && kind !== opens) break
|
|
369
|
+
if (column > 0 && items.length === 0) break
|
|
370
|
+
let depth = 0
|
|
371
|
+
if (items.length > 0) {
|
|
372
|
+
const above = stack[stack.length - 1]
|
|
373
|
+
if (column > above.column) depth = Math.min(above.depth + 1, MAX_LIST_DEPTH)
|
|
374
|
+
else {
|
|
375
|
+
// The bottom is the list's first item, at column 0, so it always stays.
|
|
376
|
+
while (stack[stack.length - 1].column > column) stack.pop()
|
|
377
|
+
depth = stack[stack.length - 1].depth
|
|
378
|
+
if (stack[stack.length - 1].column === column) stack.pop()
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
stack.push({ column, depth })
|
|
382
|
+
items.push(match[3])
|
|
383
|
+
depths.push(depth)
|
|
384
|
+
i++
|
|
385
|
+
}
|
|
386
|
+
// Never loop on a line the opener took and the item reader did not: it is text.
|
|
387
|
+
if (items.length === 0) {
|
|
388
|
+
rest.push(lines[i++])
|
|
389
|
+
continue
|
|
390
|
+
}
|
|
391
|
+
const indented = depths.some((depth) => depth > 0) ? { depths } : {}
|
|
392
|
+
if (opens === 'bullet') segments.push({ type: 'bullet', items, ...indented })
|
|
393
|
+
else {
|
|
394
|
+
const first = Number.parseInt(lines[i - items.length], 10)
|
|
395
|
+
segments.push({ type: 'numbered', items, ...(first > 1 ? { start: first } : {}), ...indented })
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
flush()
|
|
399
|
+
return segments
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Which lines sit inside a code fence, by the plain parser's rule — a fence
|
|
404
|
+
* opens only where it closes, and an unclosed one is text. Once, for the whole
|
|
405
|
+
* body: asking per list line re-read everything before it, quadratic in a long
|
|
406
|
+
* list after an unclosed fence (review of d98a5636).
|
|
407
|
+
*/
|
|
408
|
+
function fencedLines(lines: string[]): boolean[] {
|
|
409
|
+
const fenced = lines.map(() => false)
|
|
410
|
+
let open = -1
|
|
411
|
+
for (let i = 0; i < lines.length; i++) {
|
|
412
|
+
if (!FENCE_RE.test(lines[i])) continue
|
|
413
|
+
if (open === -1) open = i
|
|
414
|
+
else {
|
|
415
|
+
for (let j = open; j <= i; j++) fenced[j] = true
|
|
416
|
+
open = -1
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return fenced
|
|
420
|
+
}
|
|
421
|
+
|
|
319
422
|
/**
|
|
320
423
|
* Markers, heading prefixes and fences removed — for one-line previews that
|
|
321
424
|
* render body text raw, outside any renderer.
|