@estiva-app/protocol 0.28.1 → 0.30.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 +46 -0
- package/dist/blocks.d.ts +40 -0
- package/dist/blocks.d.ts.map +1 -1
- package/dist/blocks.js +57 -0
- package/dist/blocks.js.map +1 -1
- package/dist/bridge-content.d.ts +15 -2
- package/dist/bridge-content.d.ts.map +1 -1
- package/dist/bridge-content.js +61 -13
- package/dist/bridge-content.js.map +1 -1
- package/dist/editor.d.ts.map +1 -1
- package/dist/editor.js +89 -5
- package/dist/editor.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/render.d.ts +18 -0
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +18 -2
- package/dist/render.js.map +1 -1
- package/package.json +1 -1
- package/src/blocks.ts +62 -0
- package/src/bridge-content.ts +71 -12
- package/src/editor.ts +96 -6
- package/src/index.ts +8 -1
- package/src/render.ts +32 -2
package/src/editor.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
newBlockId,
|
|
3
|
+
parseBlockDocument,
|
|
4
|
+
serializeBlockDocument,
|
|
5
|
+
inlineTextOf,
|
|
6
|
+
listItemDepths,
|
|
7
|
+
type Block,
|
|
8
|
+
type BlockDocument,
|
|
9
|
+
} from './blocks.js'
|
|
2
10
|
import { markerTextToBlockDocument } from './bridge-content.js'
|
|
3
11
|
import type { InlineMarkNode, InlineTextNode } from './content.js'
|
|
4
12
|
import { BLOCK_DOCUMENT_FORMAT, type ContentFormat } from './render.js'
|
|
@@ -124,6 +132,9 @@ export const EDITOR_BLOCK_TYPES: ReadonlySet<string> = new Set([
|
|
|
124
132
|
*/
|
|
125
133
|
const BLOCK_CONTAINERS = new Set(['bulletList', 'orderedList', 'table', 'tableRow', 'tableHeader', 'tableCell'])
|
|
126
134
|
|
|
135
|
+
/** The two lists — flat on the wire, nested in the editor (MAN-13). */
|
|
136
|
+
const LISTS = new Set(['bulletList', 'orderedList'])
|
|
137
|
+
|
|
127
138
|
/** The node type an unknown block is parked in — `@estiva-app/ui/editor`'s `UnknownBlock`. */
|
|
128
139
|
export const UNKNOWN_BLOCK_NODE = 'unknownBlock'
|
|
129
140
|
/** The node type a `nostr:` reference is drawn as — `@estiva-app/ui/editor`'s `ReferenceNode`. */
|
|
@@ -183,7 +194,7 @@ function blockToEditor(block: Block): EditorNode {
|
|
|
183
194
|
// shows it needs nothing from this package.
|
|
184
195
|
return { type: UNKNOWN_BLOCK_NODE, attrs: { blockId: block.id, source: block, text: inlineTextOf(block) } }
|
|
185
196
|
}
|
|
186
|
-
const attrs = { ...(block.attrs ?? {}), blockId: block.id }
|
|
197
|
+
const attrs: Record<string, unknown> = { ...(block.attrs ?? {}), blockId: block.id }
|
|
187
198
|
|
|
188
199
|
if (block.type === 'codeBlock') {
|
|
189
200
|
// A fence is literal: its newlines are text, not breaks.
|
|
@@ -208,11 +219,19 @@ function blockToEditor(block: Block): EditorNode {
|
|
|
208
219
|
paragraph is that wrapper and nothing else — see `RichText`, which draws
|
|
209
220
|
a list item's *inline* content, so a list item that held anything but one
|
|
210
221
|
paragraph would render empty there.
|
|
222
|
+
|
|
223
|
+
Its `indent` is spent by `listToEditor`, which nests the item instead.
|
|
224
|
+
A `checked` rides along as written, like any attribute: one that is not
|
|
225
|
+
a boolean is a plain item to the editor too (§13.3, RIC-19), and the
|
|
226
|
+
save hands it back unchanged rather than erasing what another app wrote.
|
|
211
227
|
*/
|
|
228
|
+
const { indent: _depth, ...itemAttrs } = attrs
|
|
212
229
|
const inline = isInlineRun(block.content) ? inlineToEditor(block.content) : []
|
|
213
|
-
return { type: 'listItem', attrs, content: [{ type: 'paragraph', content: inline }] }
|
|
230
|
+
return { type: 'listItem', attrs: itemAttrs, content: [{ type: 'paragraph', content: inline }] }
|
|
214
231
|
}
|
|
215
232
|
|
|
233
|
+
if (LISTS.has(block.type)) return listToEditor(block, attrs)
|
|
234
|
+
|
|
216
235
|
if (block.content === undefined) return { type: block.type, attrs }
|
|
217
236
|
const content = isInlineRun(block.content)
|
|
218
237
|
? inlineToEditor(block.content)
|
|
@@ -220,6 +239,45 @@ function blockToEditor(block: Block): EditorNode {
|
|
|
220
239
|
return { type: block.type, attrs, ...(content.length ? { content } : {}) }
|
|
221
240
|
}
|
|
222
241
|
|
|
242
|
+
/**
|
|
243
|
+
* A flat list, nested the way an editor holds it (MAN-13).
|
|
244
|
+
*
|
|
245
|
+
* §13.3 keeps a list flat and says how deep each item is (`attrs.indent`, read
|
|
246
|
+
* by `listItemDepths`); ProseMirror puts a deeper item in a list inside the
|
|
247
|
+
* item above, which is what its Tab does. The lists built here are the
|
|
248
|
+
* editor's alone: they have no id because the wire has no such block, and
|
|
249
|
+
* each takes the type of the list it sits in (Miky, 2026-10-12).
|
|
250
|
+
*/
|
|
251
|
+
function listToEditor(block: Block, attrs: Record<string, unknown>): EditorNode {
|
|
252
|
+
const items = Array.isArray(block.content) && !isInlineRun(block.content) ? (block.content as Block[]) : []
|
|
253
|
+
const depths = listItemDepths(items)
|
|
254
|
+
const root: EditorNode = { type: block.type, attrs, content: [] }
|
|
255
|
+
// The list each depth is filling. A depth one deeper than the last opens a
|
|
256
|
+
// list inside the last item; a shallower one closes the lists below it.
|
|
257
|
+
const open: EditorNode[] = [root]
|
|
258
|
+
items.forEach((item, i) => {
|
|
259
|
+
// At most one below the deepest list open: an item that could not nest
|
|
260
|
+
// (below) leaves the ones after it a level short of what they say.
|
|
261
|
+
let depth = Math.min(depths[i], open.length)
|
|
262
|
+
open.length = Math.min(open.length, depth + 1)
|
|
263
|
+
if (open.length === depth) {
|
|
264
|
+
const parent = open[depth - 1].content!.at(-1)!
|
|
265
|
+
if (parent.type === 'listItem') {
|
|
266
|
+
const nested: EditorNode = { type: block.type, content: [] }
|
|
267
|
+
parent.content = [...(parent.content ?? []), nested]
|
|
268
|
+
open.push(nested)
|
|
269
|
+
} else {
|
|
270
|
+
// Only a list item can hold a list: under a block this version does
|
|
271
|
+
// not know, the item stays at that block's depth.
|
|
272
|
+
depth -= 1
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
open[depth].content!.push(blockToEditor(item))
|
|
276
|
+
})
|
|
277
|
+
if (root.content!.length === 0) delete root.content
|
|
278
|
+
return root
|
|
279
|
+
}
|
|
280
|
+
|
|
223
281
|
/**
|
|
224
282
|
* The document a stored value is edited as, whichever model it arrived in —
|
|
225
283
|
* `format` is `contentFormatOf`'s classification of the event it came from.
|
|
@@ -298,6 +356,9 @@ function claimIds(nodes: readonly EditorNode[], owners: Map<string, Owner>): voi
|
|
|
298
356
|
if (!owner || (!owner.fixed && !owner.holdsText && holds)) owners.set(claimed, { node, holdsText: holds, fixed: false })
|
|
299
357
|
}
|
|
300
358
|
if (BLOCK_CONTAINERS.has(node.type)) claimIds(node.content ?? [], owners)
|
|
359
|
+
// A list inside a list item is the editor's, and has no id to claim; its
|
|
360
|
+
// items are the outer list's, one level in (MAN-13).
|
|
361
|
+
if (node.type === 'listItem') for (const list of nestedLists(node)) claimIds(list.content ?? [], owners)
|
|
301
362
|
}
|
|
302
363
|
}
|
|
303
364
|
|
|
@@ -352,6 +413,28 @@ function sameMarks(a: readonly InlineMarkNode[], b: readonly InlineMarkNode[]):
|
|
|
352
413
|
return a.every((m, i) => m.type === b[i].type)
|
|
353
414
|
}
|
|
354
415
|
|
|
416
|
+
const nestedLists = (item: EditorNode): EditorNode[] => (item.content ?? []).filter((child) => LISTS.has(child.type))
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* A list's items, flattened back onto the wire: an item in a list inside an
|
|
420
|
+
* item comes right after it, one `indent` deeper (MAN-13). Whatever type that
|
|
421
|
+
* inner list was, its items are now the outer list's (Miky, 2026-10-12).
|
|
422
|
+
*/
|
|
423
|
+
function listItemsFromEditor(list: EditorNode, depth: number, claims: IdClaims): Block[] {
|
|
424
|
+
const out: Block[] = []
|
|
425
|
+
for (const child of list.content ?? []) {
|
|
426
|
+
const block = blockFromEditor(child, claims)
|
|
427
|
+
if (block === null) continue
|
|
428
|
+
if (child.type !== 'listItem') {
|
|
429
|
+
out.push(block)
|
|
430
|
+
continue
|
|
431
|
+
}
|
|
432
|
+
out.push(depth > 0 ? { ...block, attrs: { ...block.attrs, indent: depth } } : block)
|
|
433
|
+
for (const inner of nestedLists(child)) out.push(...listItemsFromEditor(inner, depth + 1, claims))
|
|
434
|
+
}
|
|
435
|
+
return out
|
|
436
|
+
}
|
|
437
|
+
|
|
355
438
|
function blockFromEditor(node: EditorNode, claims: IdClaims): Block | null {
|
|
356
439
|
if (node.type === UNKNOWN_BLOCK_NODE) {
|
|
357
440
|
/*
|
|
@@ -394,11 +477,18 @@ function blockFromEditor(node: EditorNode, claims: IdClaims): Block | null {
|
|
|
394
477
|
|
|
395
478
|
if (node.type === 'listItem') {
|
|
396
479
|
// Back out of the paragraph wrapper. A list item carries inline runs on
|
|
397
|
-
// the wire — see `blockToEditor`.
|
|
398
|
-
|
|
399
|
-
|
|
480
|
+
// the wire — see `blockToEditor`. A list inside it is the caller's: its
|
|
481
|
+
// items follow this one (`listItemsFromEditor`), and its depth is the
|
|
482
|
+
// caller's to set, never one an attribute claims.
|
|
483
|
+
const { indent: _depth, ...itemAttrs } = attrs
|
|
484
|
+
const inline = (node.content ?? [])
|
|
485
|
+
.filter((child) => !LISTS.has(child.type))
|
|
486
|
+
.flatMap((child) => inlineFromEditor(child.content ?? []))
|
|
487
|
+
return { type: node.type, id, ...(Object.keys(itemAttrs).length ? { attrs: itemAttrs } : {}), content: inline }
|
|
400
488
|
}
|
|
401
489
|
|
|
490
|
+
if (LISTS.has(node.type)) return { ...base, content: listItemsFromEditor(node, 0, claims) }
|
|
491
|
+
|
|
402
492
|
if (BLOCK_CONTAINERS.has(node.type)) {
|
|
403
493
|
const children = (node.content ?? [])
|
|
404
494
|
.map((child) => blockFromEditor(child, claims))
|
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.30.0'
|
|
51
51
|
|
|
52
52
|
export {
|
|
53
53
|
// types
|
|
@@ -203,6 +203,12 @@ export {
|
|
|
203
203
|
assignMissingBlockIds,
|
|
204
204
|
blockIds,
|
|
205
205
|
findBlock,
|
|
206
|
+
listItemDepths,
|
|
207
|
+
MAX_LIST_DEPTH,
|
|
208
|
+
listItemChecked,
|
|
209
|
+
CALLOUT_TONES,
|
|
210
|
+
type CalloutTone,
|
|
211
|
+
calloutTone,
|
|
206
212
|
inlineTextOf,
|
|
207
213
|
documentText,
|
|
208
214
|
} from './blocks.js'
|
|
@@ -224,6 +230,7 @@ export {
|
|
|
224
230
|
export {
|
|
225
231
|
markerTextToBlockDocument,
|
|
226
232
|
blockDocumentToMarkerText,
|
|
233
|
+
type DescriptionTextOptions,
|
|
227
234
|
} from './bridge-content.js'
|
|
228
235
|
|
|
229
236
|
export {
|
package/src/render.ts
CHANGED
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
parseBodySegments,
|
|
37
37
|
parseInlineMarks,
|
|
38
38
|
} from './content.js'
|
|
39
|
-
import { type Block, type BlockDocument, parseBlockDocument, inlineTextOf } from './blocks.js'
|
|
39
|
+
import { type Block, type BlockDocument, type CalloutTone, parseBlockDocument, inlineTextOf, listItemDepths, listItemChecked, calloutTone } from './blocks.js'
|
|
40
40
|
import type { SignedEvent } from './events.js'
|
|
41
41
|
|
|
42
42
|
/** A run of text and the marks on it. Nothing here needs escaping; it is text. */
|
|
@@ -72,6 +72,23 @@ export interface RenderBlock {
|
|
|
72
72
|
language?: string
|
|
73
73
|
/** An ordered list's first number, when the author did not start at 1. */
|
|
74
74
|
start?: number
|
|
75
|
+
/**
|
|
76
|
+
* How far a list item is indented, when it is (§13.3, MAN-13): its
|
|
77
|
+
* `attrs.indent` as `listItemDepths` reads it, so it is never more than one
|
|
78
|
+
* below the item before. A list's items stay its flat `children`; drawing
|
|
79
|
+
* them nested, and numbering each level from 1, is the reader's.
|
|
80
|
+
*/
|
|
81
|
+
indent?: number
|
|
82
|
+
/**
|
|
83
|
+
* A checklist item's tick (§13.3, RIC-19): `true` or `false` on a checklist
|
|
84
|
+
* item, absent on a plain one — `attrs.checked` as `listItemChecked` reads it.
|
|
85
|
+
*/
|
|
86
|
+
checked?: boolean
|
|
87
|
+
/**
|
|
88
|
+
* A callout's tone (§13.3, RIC-19), absent on a plain quote — `attrs.tone` as
|
|
89
|
+
* `calloutTone` reads it, so an unknown tone is already `note` here.
|
|
90
|
+
*/
|
|
91
|
+
tone?: CalloutTone
|
|
75
92
|
attrs?: Record<string, unknown>
|
|
76
93
|
/** What the document actually called it, when `type` is `'unknown'`. */
|
|
77
94
|
typeName?: string
|
|
@@ -206,6 +223,10 @@ function blockFromDocument(block: Block): RenderBlock {
|
|
|
206
223
|
if (block.type === 'codeBlock' && typeof language === 'string') out.language = language
|
|
207
224
|
const start = block.attrs?.start
|
|
208
225
|
if (block.type === 'orderedList' && typeof start === 'number' && start > 1) out.start = start
|
|
226
|
+
const checked = block.type === 'listItem' ? listItemChecked(block) : undefined
|
|
227
|
+
if (checked !== undefined) out.checked = checked
|
|
228
|
+
const tone = block.type === 'blockquote' ? calloutTone(block) : undefined
|
|
229
|
+
if (tone) out.tone = tone
|
|
209
230
|
|
|
210
231
|
if (Array.isArray(block.content)) {
|
|
211
232
|
if (isInlineRun(block.content)) {
|
|
@@ -219,7 +240,16 @@ function blockFromDocument(block: Block): RenderBlock {
|
|
|
219
240
|
}
|
|
220
241
|
})
|
|
221
242
|
} else {
|
|
222
|
-
|
|
243
|
+
const children = block.content as Block[]
|
|
244
|
+
out.children = children.map(blockFromDocument)
|
|
245
|
+
if (block.type === 'bulletList' || block.type === 'orderedList') {
|
|
246
|
+
// Flat on the wire and flat here, so a reader that draws only `inline`
|
|
247
|
+
// still shows every item; `indent` is the depth it may nest them by.
|
|
248
|
+
const depths = listItemDepths(children)
|
|
249
|
+
out.children.forEach((child, i) => {
|
|
250
|
+
if (child.type === 'listItem' && depths[i] > 0) child.indent = depths[i]
|
|
251
|
+
})
|
|
252
|
+
}
|
|
223
253
|
}
|
|
224
254
|
}
|
|
225
255
|
/*
|