@estiva-app/conversation 0.15.1 → 0.16.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 CHANGED
@@ -6,6 +6,30 @@ none. A change to how an event is read is a MINOR in `0.x` even when no
6
6
  signature moved, because two apps on different versions would then disagree
7
7
  about a conversation.
8
8
 
9
+ ## 0.16.0 — 2026-10-19
10
+
11
+ **What a comment box shows under itself, for every app's box** (COMM-8; record
12
+ *a-link-on-words-counts-toward-the-card*). `boxReadOf(doc, context)` reads the
13
+ shared box's document as a send writes it and answers the one file that gets
14
+ its default card, the live `part` of each block link (one per file, at most
15
+ `MAX_PARTS`), and the URLs it names for the app's resolver to ask about.
16
+ `embedsToSend` / `embedsToEdit` / `withoutCard` / `namedBefore` are Peek's
17
+ `lib/boxCard.ts` rules, moved here so Leaf, and Ship on the shared box, write
18
+ the `embed` set as Peek does. One change from Peek's copy: a link to a block of
19
+ the file the conversation is on is its chip only and writes no `part` (Miky,
20
+ 2026-10-19).
21
+
22
+ **A link on words is sent.** `composerText` writes words carrying a `link`
23
+ mark — a URL pasted over them in the box — as `[words](url)`; until now the
24
+ block bridge wrote the words and dropped the link. Words holding a bracket, or
25
+ in code, keep their words only. `composerDocument` opens `[words](url)` as the
26
+ words with a `link` mark, so an edit shows the link as it was drawn.
27
+
28
+ Takes `@estiva-app/protocol` ≥ 0.40.0, where a link on words names its file.
29
+
30
+ SPEC: §13.6.1, §13.6.2 — no rule changed; this package now writes what they
31
+ already say, as Peek and Ship do.
32
+
9
33
  ## 0.15.1 — 2026-10-19
10
34
 
11
35
  **`-"…"` leaves a phrase out**, as the relay reads it (buzz#32).
package/README.md CHANGED
@@ -27,6 +27,7 @@ pass, the clock is a `createdAtMs` you pass, and drafts take their storage.
27
27
  | writing | §6.4, §13.6 | `buildComment`, `buildReply`, `placeOf`, `referenceTagsFor`, `mentionTagsFor` |
28
28
  | what a composer's pick writes | §13.1 | `mentionText`, `messageReference`, `urgentTagsFor`, `URGENT_TAG` |
29
29
  | what the shared comment box holds, as the message it writes, and back | §13.1 | `composerText`, `composerDocument`, `withoutNewUrgency`, `composerDraft` |
30
+ | what a box shows under itself while a comment is written: the one file's card and each block link's part, and the `embed` a send or an edit writes | §13.6.1, §13.6.2 | `boxReadOf`, `boxLinksOf`, `embedsToSend`, `embedsToEdit`, `namedBefore`, `withoutCard`, `linkTargetOf` |
30
31
  | what `[` offers, and in what order | §13.1 | `rankReferences`, `referenceMatch`, `fileReference`, `referenceSearch`, `MESSAGE_TIER`, `FILE_TIER`, `REFERENCE_CAPS` |
31
32
  | ordering | §6.2, §6.3 | `trustedTs`, `orderingMs`, `byOrder` |
32
33
  | edits and attachments | §6.8 | `editTargetOf`, `foldEdits`, `foldAttachments` |
@@ -0,0 +1,76 @@
1
+ /**
2
+ * What a comment box shows under itself, as it will be sent (SPEC §13.6.1,
3
+ * §13.6.2), for every app's box (COMM-8). Peek wrote this rule itself
4
+ * (`lib/boxCard.ts`) and Ship its copy (`lib/messageCard.ts`); it is here once
5
+ * so Leaf, and Ship on the shared box, read a draft as Peek does.
6
+ *
7
+ * - **One file's card.** When what is written names exactly one file, its
8
+ * default card, `["embed", V, "detailed"]`, by protocol's `defaultCardOf`:
9
+ * a Folder, a person, a message and the file the conversation is on do not
10
+ * count, a link on words counts by its target, and a plain web link counts
11
+ * for nothing. ✕ takes it off (the box's to keep).
12
+ * - **The live part of each block link**, as the `part` the message will
13
+ * carry, one per file. A part counts as its file and draws instead of a card,
14
+ * so linking an issue and a block of a page shows the block and no card. A
15
+ * link to a block of the conversation's own file is its chip only and
16
+ * writes no `part` (Miky, 2026-10-19).
17
+ *
18
+ * Read from the marker text the box would send, by the rules a reader draws it
19
+ * by, so what shows under the box is what shows under the message.
20
+ *
21
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-link-on-words-counts-toward-the-card.md
22
+ */
23
+ import { type EditorDocument, type EditorNode, type Embed, type LinkResolver, type PartPointer } from '@estiva-app/protocol';
24
+ /** At most this many blocks show live under one message (SPEC §13.6.1). */
25
+ export declare const MAX_PARTS = 6;
26
+ export interface BoxLinks {
27
+ /** Every address and event id the text names. */
28
+ values: string[];
29
+ /** The block links' parts, one per file, the first link's; none of the conversation's own file. */
30
+ parts: PartPointer[];
31
+ /** The file that gets the default card, before any ✕. */
32
+ card?: string;
33
+ /**
34
+ * Every URL the text names, bare or as a link's target, once each: what the
35
+ * app asks its resolver about, so an answer that comes back later reads again.
36
+ */
37
+ urls: string[];
38
+ }
39
+ export interface BoxLinkContext {
40
+ /** What an app link names for a card (§7.7), as answered so far. */
41
+ resolveLink: LinkResolver;
42
+ /** The file and block a link to one block names, as answered so far. */
43
+ blockOf: (url: string) => PartPointer | undefined;
44
+ /** The file whose conversation this is: it gets no card here, and its blocks no part. */
45
+ here?: string;
46
+ /** An edit's: the values the message named before it, which get no default again. */
47
+ previous?: readonly string[];
48
+ }
49
+ /**
50
+ * What an app link in the box draws as: the file or message it names, or, for
51
+ * a link to one block, its file (§13.6.1), so a pasted block link reads as its
52
+ * file's chip, the block live under the box.
53
+ */
54
+ export declare function linkTargetOf(url: string, context: Pick<BoxLinkContext, 'resolveLink' | 'blockOf'>): string | undefined;
55
+ /** What a marker text names, and the one file it gives the default card. */
56
+ export declare function boxLinksOf(text: string, context: BoxLinkContext): BoxLinks;
57
+ /** {@link boxLinksOf} of a composer's document (`CommentBox`'s JSON), read as {@link composerText} writes it. */
58
+ export declare function boxReadOf(doc: EditorDocument | EditorNode, context: BoxLinkContext): BoxLinks;
59
+ /**
60
+ * What a message named before an edit, for `defaultCardOf`'s `previous`: its
61
+ * values, and the file of each block link, which was named too.
62
+ */
63
+ export declare function namedBefore(text: string, context: Pick<BoxLinkContext, 'resolveLink' | 'blockOf'>): string[];
64
+ /** The `embed` set a new message sends: the default card, unless ✕ took it off. `none` is never written. */
65
+ export declare function embedsToSend(links: Pick<BoxLinks, 'card'>, removed: ReadonlySet<string>): Embed[];
66
+ /**
67
+ * The `embed` set an edit sends, or undefined to leave the message's as it
68
+ * was. Only an edit that names a file first adds its default (`links` read
69
+ * with `previous`), and then it carries the whole folded set with it, since a
70
+ * set replaces (§13.6.2). A card removed with ✕, before sending or after,
71
+ * stays removed.
72
+ */
73
+ export declare function embedsToEdit(links: Pick<BoxLinks, 'card'>, removed: ReadonlySet<string>, folded: readonly Embed[] | undefined): Embed[] | undefined;
74
+ /** ✕ on a sent message's card: the folded set, with that card `none` and every other kept. */
75
+ export declare function withoutCard(folded: readonly Embed[] | undefined, value: string): Embed[];
76
+ //# sourceMappingURL=boxCard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boxCard.d.ts","sourceRoot":"","sources":["../src/boxCard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAKL,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,YAAY,EACjB,KAAK,WAAW,EACjB,MAAM,sBAAsB,CAAA;AAG7B,2EAA2E;AAC3E,eAAO,MAAM,SAAS,IAAI,CAAA;AAE1B,MAAM,WAAW,QAAQ;IACvB,iDAAiD;IACjD,MAAM,EAAE,MAAM,EAAE,CAAA;IAChB,mGAAmG;IACnG,KAAK,EAAE,WAAW,EAAE,CAAA;IACpB,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;OAGG;IACH,IAAI,EAAE,MAAM,EAAE,CAAA;CACf;AAED,MAAM,WAAW,cAAc;IAC7B,oEAAoE;IACpE,WAAW,EAAE,YAAY,CAAA;IACzB,wEAAwE;IACxE,OAAO,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,WAAW,GAAG,SAAS,CAAA;IACjD,yFAAyF;IACzF,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,qFAAqF;IACrF,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAC7B;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,aAAa,GAAG,SAAS,CAAC,GAAG,MAAM,GAAG,SAAS,CAEtH;AAED,4EAA4E;AAC5E,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,QAAQ,CAiB1E;AAED,iHAAiH;AACjH,wBAAgB,SAAS,CAAC,GAAG,EAAE,cAAc,GAAG,UAAU,EAAE,OAAO,EAAE,cAAc,GAAG,QAAQ,CAE7F;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,aAAa,GAAG,SAAS,CAAC,GAAG,MAAM,EAAE,CAI5G;AAED,4GAA4G;AAC5G,wBAAgB,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,KAAK,EAAE,CAEjG;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,KAAK,EAAE,GAAG,SAAS,GAAG,KAAK,EAAE,GAAG,SAAS,CAEnJ;AAED,8FAA8F;AAC9F,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,KAAK,EAAE,CAExF"}
@@ -0,0 +1,87 @@
1
+ /**
2
+ * What a comment box shows under itself, as it will be sent (SPEC §13.6.1,
3
+ * §13.6.2), for every app's box (COMM-8). Peek wrote this rule itself
4
+ * (`lib/boxCard.ts`) and Ship its copy (`lib/messageCard.ts`); it is here once
5
+ * so Leaf, and Ship on the shared box, read a draft as Peek does.
6
+ *
7
+ * - **One file's card.** When what is written names exactly one file, its
8
+ * default card, `["embed", V, "detailed"]`, by protocol's `defaultCardOf`:
9
+ * a Folder, a person, a message and the file the conversation is on do not
10
+ * count, a link on words counts by its target, and a plain web link counts
11
+ * for nothing. ✕ takes it off (the box's to keep).
12
+ * - **The live part of each block link**, as the `part` the message will
13
+ * carry, one per file. A part counts as its file and draws instead of a card,
14
+ * so linking an issue and a block of a page shows the block and no card. A
15
+ * link to a block of the conversation's own file is its chip only and
16
+ * writes no `part` (Miky, 2026-10-19).
17
+ *
18
+ * Read from the marker text the box would send, by the rules a reader draws it
19
+ * by, so what shows under the box is what shows under the message.
20
+ *
21
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-link-on-words-counts-toward-the-card.md
22
+ */
23
+ import { defaultCardOf, toRenderTree, valuesIn, withCard, } from '@estiva-app/protocol';
24
+ import { composerText } from './composer.js';
25
+ /** At most this many blocks show live under one message (SPEC §13.6.1). */
26
+ export const MAX_PARTS = 6;
27
+ /**
28
+ * What an app link in the box draws as: the file or message it names, or, for
29
+ * a link to one block, its file (§13.6.1), so a pasted block link reads as its
30
+ * file's chip, the block live under the box.
31
+ */
32
+ export function linkTargetOf(url, context) {
33
+ return context.resolveLink(url) ?? context.blockOf(url)?.address;
34
+ }
35
+ /** What a marker text names, and the one file it gives the default card. */
36
+ export function boxLinksOf(text, context) {
37
+ // valuesIn asks the resolver about exactly the URLs a reader counts (not one
38
+ // in a code span, nor one in a link's words), so recording its questions
39
+ // gives the URLs without a second URL finder.
40
+ const urls = [];
41
+ const values = valuesIn(text ? toRenderTree(text, 'marker') : [], (url) => {
42
+ if (!urls.includes(url))
43
+ urls.push(url);
44
+ return context.resolveLink(url);
45
+ });
46
+ const parts = new Map();
47
+ for (const url of urls) {
48
+ const part = context.blockOf(url);
49
+ if (part && part.address !== context.here && !parts.has(part.address))
50
+ parts.set(part.address, part);
51
+ }
52
+ const kept = [...parts.values()].slice(0, MAX_PARTS);
53
+ const card = defaultCardOf(values, kept, { here: context.here, previous: context.previous });
54
+ return { values, parts: kept, card, urls };
55
+ }
56
+ /** {@link boxLinksOf} of a composer's document (`CommentBox`'s JSON), read as {@link composerText} writes it. */
57
+ export function boxReadOf(doc, context) {
58
+ return boxLinksOf(composerText(doc).text, context);
59
+ }
60
+ /**
61
+ * What a message named before an edit, for `defaultCardOf`'s `previous`: its
62
+ * values, and the file of each block link, which was named too.
63
+ */
64
+ export function namedBefore(text, context) {
65
+ const { values, urls } = boxLinksOf(text, context);
66
+ const files = urls.map((url) => context.blockOf(url)?.address).filter((v) => !!v);
67
+ return [...new Set([...values, ...files])];
68
+ }
69
+ /** The `embed` set a new message sends: the default card, unless ✕ took it off. `none` is never written. */
70
+ export function embedsToSend(links, removed) {
71
+ return links.card && !removed.has(links.card) ? [{ value: links.card, layout: 'detailed' }] : [];
72
+ }
73
+ /**
74
+ * The `embed` set an edit sends, or undefined to leave the message's as it
75
+ * was. Only an edit that names a file first adds its default (`links` read
76
+ * with `previous`), and then it carries the whole folded set with it, since a
77
+ * set replaces (§13.6.2). A card removed with ✕, before sending or after,
78
+ * stays removed.
79
+ */
80
+ export function embedsToEdit(links, removed, folded) {
81
+ return links.card && !removed.has(links.card) ? withCard(folded ?? [], links.card, 'detailed') : undefined;
82
+ }
83
+ /** ✕ on a sent message's card: the folded set, with that card `none` and every other kept. */
84
+ export function withoutCard(folded, value) {
85
+ return withCard(folded ?? [], value, 'none');
86
+ }
87
+ //# sourceMappingURL=boxCard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boxCard.js","sourceRoot":"","sources":["../src/boxCard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EACL,aAAa,EACb,YAAY,EACZ,QAAQ,EACR,QAAQ,GAMT,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAE5C,2EAA2E;AAC3E,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAA;AA2B1B;;;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AAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,IAAI,EAAE,EAAE,KAAK,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AAC5G,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,WAAW,CAAC,MAAoC,EAAE,KAAa;IAC7E,OAAO,QAAQ,CAAC,MAAM,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;AAC9C,CAAC"}
@@ -53,7 +53,8 @@ export interface ComposerLabels {
53
53
  * tag, so marker text alone cannot say it); a message or a file becomes its
54
54
  * `captionedReference` chip. Whatever `labels` does not know stays the
55
55
  * `reference` it was, and so does one with marks or a card, which a chip
56
- * would lose.
56
+ * would lose. A link on words, `[words](url)`, opens as the words with a
57
+ * `link` mark, as the box drew it while it was written.
57
58
  */
58
59
  export declare function composerDocument(text: string, labels?: ComposerLabels, urgent?: readonly string[]): EditorDocument;
59
60
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"composer.d.ts","sourceRoot":"","sources":["../src/composer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAML,KAAK,cAAc,EACnB,KAAK,UAAU,EAChB,MAAM,sBAAsB,CAAA;AAE7B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C,8FAA8F;AAC9F,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,kGAAkG;IAClG,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;CAClB;AA4BD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,cAAc,GAAG,UAAU,GAAG,YAAY,CAY3E;AAED,oHAAoH;AACpH,MAAM,WAAW,cAAc;IAC7B,yEAAyE;IACzE,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAA;I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WAAW,cAAc;IAC7B,yEAAyE;IACzE,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAA;IACpD,8EAA8E;IAC9E,gBAAgB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAA;CACnF;AAWD;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,GAAE,cAAmB,EAAE,MAAM,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,cAAc,CAuBtH;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAExE;AAED,yDAAyD;AACzD,MAAM,WAAW,aAAa;IAC5B,wEAAwE;IACxE,IAAI,IAAI,cAAc,GAAG,SAAS,CAAA;IAClC,gEAAgE;IAChE,KAAK,CAAC,GAAG,EAAE,cAAc,GAAG,IAAI,CAAA;IAChC,KAAK,IAAI,IAAI,CAAA;CACd;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,cAAmB,GAAG,aAAa,CAcxG"}
package/dist/composer.js CHANGED
@@ -25,6 +25,54 @@ const keyOf = (node) => {
25
25
  const pubkey = node.attrs?.pubkey;
26
26
  return typeof pubkey === 'string' && HEX_KEY.test(pubkey) ? pubkey : null;
27
27
  };
28
+ /**
29
+ * A link on words as the marker format writes it, `[words](url)`, and back:
30
+ * the same alternation protocol's `valuesIn` and ui's `RichText` read, so a
31
+ * URL starting earlier swallows a bracket inside it here as it does there.
32
+ * Words hold no bracket and no line break (COMM-8; Peek's rule).
33
+ */
34
+ const LINK_OR_URL = /(\[([^[\]\n]+)\]\(((?:https?:\/\/|mailto:)[^\s)]+)\))|(https?:\/\/[^\s<>"'`]+)/g;
35
+ const LINK_TARGET = /^(?:https?:\/\/|mailto:)[^\s)]+$/;
36
+ const LINK_WORDS = /^[^[\]\n]+$/;
37
+ const linkMarkOf = (node) => node.marks?.find((m) => m.type === 'link');
38
+ /**
39
+ * Words the box holds as a link (a URL pasted over them) written as
40
+ * `[words](url)`. The block bridge draws and writes no link on words, so
41
+ * without this the words would be sent and the link dropped. A link whose
42
+ * words are its URL is the URL itself; words that cannot be a marker link (a
43
+ * bracket, code) keep their words and lose the link, as the bridge did.
44
+ */
45
+ function linkOnWordsAsMarker(node) {
46
+ const link = linkMarkOf(node);
47
+ const href = link?.attrs?.href;
48
+ if (!link || node.text === undefined)
49
+ return node;
50
+ const marks = (node.marks ?? []).filter((m) => m !== link);
51
+ const kept = marks.length ? { marks } : {};
52
+ const written = typeof href === 'string' && node.text !== href && LINK_TARGET.test(href) && LINK_WORDS.test(node.text) && !marks.some((m) => m.type === 'code');
53
+ return { type: 'text', text: written ? `[${node.text}](${href})` : node.text, ...kept };
54
+ }
55
+ /** Marker text's `[words](url)` in a text node, as the words with a `link` mark the box draws; anything else as it was. */
56
+ function linksOnWordsAsMarks(node) {
57
+ const text = node.text ?? '';
58
+ if (!text.includes('](') || node.marks?.some((m) => m.type === 'code' || m.type === 'link'))
59
+ return [node];
60
+ const out = [];
61
+ let at = 0;
62
+ for (const m of text.matchAll(LINK_OR_URL)) {
63
+ if (!m[1])
64
+ continue;
65
+ if (m.index > at)
66
+ out.push({ ...node, text: text.slice(at, m.index) });
67
+ out.push({ ...node, text: m[2], marks: [...(node.marks ?? []), { type: 'link', attrs: { href: m[3] } }] });
68
+ at = m.index + m[0].length;
69
+ }
70
+ if (out.length === 0)
71
+ return [node];
72
+ if (at < text.length)
73
+ out.push({ ...node, text: text.slice(at) });
74
+ return out;
75
+ }
28
76
  /**
29
77
  * The chips as the block bridge can write them. `fromEditorDocument` knows a
30
78
  * `reference` and drops any inline node it does not, so a picked person would
@@ -32,6 +80,8 @@ const keyOf = (node) => {
32
80
  * names (§13.1), or `@Name` / `!@Name` for somebody with no key.
33
81
  */
34
82
  function chipsAsReferences(node) {
83
+ if (node.type === 'text')
84
+ return linkOnWordsAsMarker(node);
35
85
  if (node.type === 'mention' || node.type === 'urgentMention') {
36
86
  const pubkey = keyOf(node);
37
87
  const written = mentionText({ pubkey, label: String(node.attrs?.label ?? '') }, node.type === 'urgentMention');
@@ -84,7 +134,8 @@ const plainReference = (node) => {
84
134
  * tag, so marker text alone cannot say it); a message or a file becomes its
85
135
  * `captionedReference` chip. Whatever `labels` does not know stays the
86
136
  * `reference` it was, and so does one with marks or a card, which a chip
87
- * would lose.
137
+ * would lose. A link on words, `[words](url)`, opens as the words with a
138
+ * `link` mark, as the box drew it while it was written.
88
139
  */
89
140
  export function composerDocument(text, labels = {}, urgent) {
90
141
  const keys = new Set(urgent ?? []);
@@ -109,7 +160,7 @@ export function composerDocument(text, labels = {}, urgent) {
109
160
  return { type: 'captionedReference', attrs: { id: uri, label: caption.label, snippet: caption.snippet, uri } };
110
161
  return node;
111
162
  }
112
- return node.content ? { ...node, content: node.content.map(walk) } : node;
163
+ return node.content ? { ...node, content: node.content.flatMap((child) => (child.type === 'text' ? linksOnWordsAsMarks(child) : [walk(child)])) } : node;
113
164
  };
114
165
  return walk(toEditorDocument(documentForEditing(text, 'marker')));
115
166
  }
@@ -1 +1 @@
1
- {"version":3,"file":"composer.js","sourceRoot":"","sources":["../src/composer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EACL,yBAAyB,EACzB,UAAU,EACV,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,GAGjB,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAU1C,MAAM,OAAO,GAAG,gBAAgB,CAAA;AAEhC,MAAM,KAAK,GAAG,CAAC,IAAgB,EAAiB,EAAE;IAChD,MAAM,MAAM,GAA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AAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;QACpG,CAAC;QACD,KAAK,CAAC,GAAG;YACP,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,YAAY,CAAC,GAAG,CAAC,CAAA;YAC1C,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,CAAA;QAChC,CAAC;QACD,KAAK;YACH,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QAClB,CAAC;KACF,CAAA;AACH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@
12
12
  * apps: it imports no app's data layer, opens no socket, and takes every
13
13
  * environment touch — the relay read, the clock, storage — as a parameter.
14
14
  */
15
- export declare const CONVERSATION_VERSION = "0.15.1";
15
+ export declare const CONVERSATION_VERSION = "0.16.0";
16
16
  export { KIND_MESSAGE, KIND_COMMENT, KIND_EDIT, KIND_REACTION, KIND_DELETION, KIND_ASSERTION, isConversationKind, isEventId, } from './kinds.js';
17
17
  export { trustedTs, orderingMs, byOrder } from './order.js';
18
18
  export { namedInBody, isReply, anchorsOf, isCommentOn, referencesAddress, strengthOn, threadStrength, referenceTagsFor, mentionTagsFor, peopleNamedInBody, MAX_MENTIONED_PEOPLE, type Strength, } from './strength.js';
@@ -23,6 +23,7 @@ export { decorationsOf, type Decoration, type Decorations, type Resolution, type
23
23
  export { buildComment, buildReply, offersEditAndDelete, placeOf, type CommentRef } from './builders.js';
24
24
  export { eventsNamedInBody, mentionText, messageReference, quoteTagsFor, URGENT_TAG, urgentTagsFor } from './compose.js';
25
25
  export { composerDocument, composerDraft, composerText, withoutNewUrgency, type ComposerDraft, type ComposerLabels, type ComposerText, } from './composer.js';
26
+ export { MAX_PARTS, boxLinksOf, boxReadOf, embedsToEdit, embedsToSend, linkTargetOf, namedBefore, withoutCard, type BoxLinkContext, type BoxLinks, } from './boxCard.js';
26
27
  export { FILE_TIER, fileReference, MESSAGE_TIER, rankReferences, REFERENCE_CAPS, referenceMatch, referenceSearch, refMatch, type RankedReferences, type RankReferencesInput, type ReferenceCandidate, type ReferenceSearch, type ReferenceSearchFn, type ReferenceSearchOptions, type ReferenceType, } from './references.js';
27
28
  export { KIND_CHANGE, MEMBER_FIELD_PREFIX, memberField, memberOfField, mentions, streamOf, membershipOf, membersOf, membershipFilters, candidateFilesOf, buildMembershipChange, MUTED_D_TAG, APPDATA_TAG, parseMutedBlob, serializeMutedBlob, buildMutedEvent, mutedFilter, mutedFromFollowed, type Membership, type MutedList, } from './membership.js';
28
29
  export { READ_STATE_TAG, READ_STATE_D_PREFIX, MAX_CONTEXTS, MAX_CONTEXT_ID_BYTES, MAX_TIMESTAMP, MAX_CLIENT_ID_BYTES, MAX_BLOB_BYTES, MAX_CONTEXTS_BYTES, READ_STATE_HORIZON_DAYS, channelContext, fileContext, threadContext, messageContext, toContextSeconds, isPublishableContextId, loadSlotIdentity, rotateSlotId, readStateDTag, parseReadStateBlob, serializeReadStateBlob, capContextsToBytes, capReadStateContexts, THREAD_RULE_FROM, REPLY_FLOOR_CONTEXT, advanceContexts, buildReadStateEvent, allSlotsFilter, mergeSlots, classifyOwnSlots, effectiveReadAt, threadReadAt, belowReplyFloor, fetchReadState, createSlotCache, publishReadState, type SlotCache, type SlotIdentity, type SlotStorage, type SlotSource, type RandomBytes, type ReadStateBlob, type CappedContexts, type SlotBlob, type OwnSlotVerdict, type Nip44, type FetchedReadState, } from './readState.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,oBAAoB,WAAW,CAAA;AAE5C,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,aAAa,EACb,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,SAAS,GACV,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,SAAS,EA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kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,eAAe,EACf,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,KAAK,KAAK,EACV,KAAK,gBAAgB,GACtB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAA;AAElE,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,eAAe,EACf,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,YAAY,GAClB,MAAM,aAAa,CAAA"}
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@
12
12
  * apps: it imports no app's data layer, opens no socket, and takes every
13
13
  * environment touch — the relay read, the clock, storage — as a parameter.
14
14
  */
15
- export const CONVERSATION_VERSION = '0.15.1';
15
+ export const CONVERSATION_VERSION = '0.16.0';
16
16
  export { KIND_MESSAGE, KIND_COMMENT, KIND_EDIT, KIND_REACTION, KIND_DELETION, KIND_ASSERTION, isConversationKind, isEventId, } from './kinds.js';
17
17
  export { trustedTs, orderingMs, byOrder } from './order.js';
18
18
  export { namedInBody, isReply, anchorsOf, isCommentOn, referencesAddress, strengthOn, threadStrength, referenceTagsFor, mentionTagsFor, peopleNamedInBody, MAX_MENTIONED_PEOPLE, } from './strength.js';
@@ -23,6 +23,7 @@ export { decorationsOf } from './decorations.js';
23
23
  export { buildComment, buildReply, offersEditAndDelete, placeOf } from './builders.js';
24
24
  export { eventsNamedInBody, mentionText, messageReference, quoteTagsFor, URGENT_TAG, urgentTagsFor } from './compose.js';
25
25
  export { composerDocument, composerDraft, composerText, withoutNewUrgency, } from './composer.js';
26
+ export { MAX_PARTS, boxLinksOf, boxReadOf, embedsToEdit, embedsToSend, linkTargetOf, namedBefore, withoutCard, } from './boxCard.js';
26
27
  export { FILE_TIER, fileReference, MESSAGE_TIER, rankReferences, REFERENCE_CAPS, referenceMatch, referenceSearch, refMatch, } from './references.js';
27
28
  export { KIND_CHANGE, MEMBER_FIELD_PREFIX, memberField, memberOfField, mentions, streamOf, membershipOf, membersOf, membershipFilters, candidateFilesOf, buildMembershipChange, MUTED_D_TAG, APPDATA_TAG, parseMutedBlob, serializeMutedBlob, buildMutedEvent, mutedFilter, mutedFromFollowed, } from './membership.js';
28
29
  export { READ_STATE_TAG, READ_STATE_D_PREFIX, MAX_CONTEXTS, MAX_CONTEXT_ID_BYTES, MAX_TIMESTAMP, MAX_CLIENT_ID_BYTES, MAX_BLOB_BYTES, MAX_CONTEXTS_BYTES, READ_STATE_HORIZON_DAYS, channelContext, fileContext, threadContext, messageContext, toContextSeconds, isPublishableContextId, loadSlotIdentity, rotateSlotId, readStateDTag, parseReadStateBlob, serializeReadStateBlob, capContextsToBytes, capReadStateContexts, THREAD_RULE_FROM, REPLY_FLOOR_CONTEXT, advanceContexts, buildReadStateEvent, allSlotsFilter, mergeSlots, classifyOwnSlots, effectiveReadAt, threadReadAt, belowReplyFloor, fetchReadState, createSlotCache, publishReadState, } from './readState.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,QAAQ,CAAA;AAE5C,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,aAAa,EACb,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,SAAS,GACV,MAAM,YAAY,CAAA;AAE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,iBAAiB,GAGlB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,YAAY,EACZ,oBAAoB,EACpB,aAAa,EACb,mBAAmB,EACnB,cAAc,EACd,kBAAkB,EAClB,uBAAuB,EACvB,cAAc,EACd,WAAW,EACX,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,sBAAsB,EACtB,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,eAAe,EACf,cAAc,EACd,eAAe,EACf,gBAAgB,GAYjB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAoB,MAAM,aAAa,CAAA;AAElE,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,eAAe,GAIhB,MAAM,aAAa,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,QAAQ,CAAA;AAE5C,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,aAAa,EACb,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,SAAS,GACV,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3D,OAAO,EACL,WAAW,EACX,OAAO,EACP,SAAS,EACT,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,oBAAoB,GAErB,MAAM,eAAe,CAAA;AAEtB,OAAO,EAAE,QAAQ,EAAE,YAA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B,EAClB,uBAAuB,EACvB,cAAc,EACd,WAAW,EACX,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,sBAAsB,EACtB,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,kBAAkB,EAClB,sBAAsB,EACtB,kBAAkB,EAClB,oBAAoB,EACpB,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,mBAAmB,EACnB,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,eAAe,EACf,cAAc,EACd,eAAe,EACf,gBAAgB,GAYjB,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAoB,MAAM,aAAa,CAAA;AAElE,OAAO,EACL,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,gBAAgB,EAChB,eAAe,GAIhB,MAAM,aAAa,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@estiva-app/conversation",
3
- "version": "0.15.1",
3
+ "version": "0.16.0",
4
4
  "description": "The conversation rules of the Estiva SPEC (§6.2–§6.8, §11): comment and mention strengths, threading, the edit, reaction and attachment folds, NIP-22 comment and reply builders, drafts, NIP-RS read state, membership and unread. A convenience an app adopts, never a requirement.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -47,10 +47,10 @@
47
47
  "prepublishOnly": "npm run build"
48
48
  },
49
49
  "peerDependencies": {
50
- "@estiva-app/protocol": ">=0.31.0"
50
+ "@estiva-app/protocol": ">=0.40.0"
51
51
  },
52
52
  "devDependencies": {
53
- "@estiva-app/protocol": ">=0.31.0",
53
+ "@estiva-app/protocol": ">=0.40.0",
54
54
  "typescript": "~5.9.3"
55
55
  }
56
56
  }
package/src/boxCard.ts ADDED
@@ -0,0 +1,127 @@
1
+ /**
2
+ * What a comment box shows under itself, as it will be sent (SPEC §13.6.1,
3
+ * §13.6.2), for every app's box (COMM-8). Peek wrote this rule itself
4
+ * (`lib/boxCard.ts`) and Ship its copy (`lib/messageCard.ts`); it is here once
5
+ * so Leaf, and Ship on the shared box, read a draft as Peek does.
6
+ *
7
+ * - **One file's card.** When what is written names exactly one file, its
8
+ * default card, `["embed", V, "detailed"]`, by protocol's `defaultCardOf`:
9
+ * a Folder, a person, a message and the file the conversation is on do not
10
+ * count, a link on words counts by its target, and a plain web link counts
11
+ * for nothing. ✕ takes it off (the box's to keep).
12
+ * - **The live part of each block link**, as the `part` the message will
13
+ * carry, one per file. A part counts as its file and draws instead of a card,
14
+ * so linking an issue and a block of a page shows the block and no card. A
15
+ * link to a block of the conversation's own file is its chip only and
16
+ * writes no `part` (Miky, 2026-10-19).
17
+ *
18
+ * Read from the marker text the box would send, by the rules a reader draws it
19
+ * by, so what shows under the box is what shows under the message.
20
+ *
21
+ * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-link-on-words-counts-toward-the-card.md
22
+ */
23
+ import {
24
+ defaultCardOf,
25
+ toRenderTree,
26
+ valuesIn,
27
+ withCard,
28
+ type EditorDocument,
29
+ type EditorNode,
30
+ type Embed,
31
+ type LinkResolver,
32
+ type PartPointer,
33
+ } from '@estiva-app/protocol'
34
+ import { composerText } from './composer.js'
35
+
36
+ /** At most this many blocks show live under one message (SPEC §13.6.1). */
37
+ export const MAX_PARTS = 6
38
+
39
+ export interface BoxLinks {
40
+ /** Every address and event id the text names. */
41
+ values: string[]
42
+ /** The block links' parts, one per file, the first link's; none of the conversation's own file. */
43
+ parts: PartPointer[]
44
+ /** The file that gets the default card, before any ✕. */
45
+ card?: string
46
+ /**
47
+ * Every URL the text names, bare or as a link's target, once each: what the
48
+ * app asks its resolver about, so an answer that comes back later reads again.
49
+ */
50
+ urls: string[]
51
+ }
52
+
53
+ export interface BoxLinkContext {
54
+ /** What an app link names for a card (§7.7), as answered so far. */
55
+ resolveLink: LinkResolver
56
+ /** The file and block a link to one block names, as answered so far. */
57
+ blockOf: (url: string) => PartPointer | undefined
58
+ /** The file whose conversation this is: it gets no card here, and its blocks no part. */
59
+ here?: string
60
+ /** An edit's: the values the message named before it, which get no default again. */
61
+ previous?: readonly string[]
62
+ }
63
+
64
+ /**
65
+ * What an app link in the box draws as: the file or message it names, or, for
66
+ * a link to one block, its file (§13.6.1), so a pasted block link reads as its
67
+ * file's chip, the block live under the box.
68
+ */
69
+ export function linkTargetOf(url: string, context: Pick<BoxLinkContext, 'resolveLink' | 'blockOf'>): string | undefined {
70
+ return context.resolveLink(url) ?? context.blockOf(url)?.address
71
+ }
72
+
73
+ /** What a marker text names, and the one file it gives the default card. */
74
+ export function boxLinksOf(text: string, context: BoxLinkContext): BoxLinks {
75
+ // valuesIn asks the resolver about exactly the URLs a reader counts (not one
76
+ // in a code span, nor one in a link's words), so recording its questions
77
+ // gives the URLs without a second URL finder.
78
+ const urls: string[] = []
79
+ const values = valuesIn(text ? toRenderTree(text, 'marker') : [], (url) => {
80
+ if (!urls.includes(url)) urls.push(url)
81
+ return context.resolveLink(url)
82
+ })
83
+ const parts = new Map<string, PartPointer>()
84
+ for (const url of urls) {
85
+ const part = context.blockOf(url)
86
+ if (part && part.address !== context.here && !parts.has(part.address)) parts.set(part.address, part)
87
+ }
88
+ const kept = [...parts.values()].slice(0, MAX_PARTS)
89
+ const card = defaultCardOf(values, kept, { here: context.here, previous: context.previous })
90
+ return { values, parts: kept, card, urls }
91
+ }
92
+
93
+ /** {@link boxLinksOf} of a composer's document (`CommentBox`'s JSON), read as {@link composerText} writes it. */
94
+ export function boxReadOf(doc: EditorDocument | EditorNode, context: BoxLinkContext): BoxLinks {
95
+ return boxLinksOf(composerText(doc).text, context)
96
+ }
97
+
98
+ /**
99
+ * What a message named before an edit, for `defaultCardOf`'s `previous`: its
100
+ * values, and the file of each block link, which was named too.
101
+ */
102
+ export function namedBefore(text: string, context: Pick<BoxLinkContext, 'resolveLink' | 'blockOf'>): string[] {
103
+ const { values, urls } = boxLinksOf(text, context)
104
+ const files = urls.map((url) => context.blockOf(url)?.address).filter((v): v is string => !!v)
105
+ return [...new Set([...values, ...files])]
106
+ }
107
+
108
+ /** The `embed` set a new message sends: the default card, unless ✕ took it off. `none` is never written. */
109
+ export function embedsToSend(links: Pick<BoxLinks, 'card'>, removed: ReadonlySet<string>): Embed[] {
110
+ return links.card && !removed.has(links.card) ? [{ value: links.card, layout: 'detailed' }] : []
111
+ }
112
+
113
+ /**
114
+ * The `embed` set an edit sends, or undefined to leave the message's as it
115
+ * was. Only an edit that names a file first adds its default (`links` read
116
+ * with `previous`), and then it carries the whole folded set with it, since a
117
+ * set replaces (§13.6.2). A card removed with ✕, before sending or after,
118
+ * stays removed.
119
+ */
120
+ export function embedsToEdit(links: Pick<BoxLinks, 'card'>, removed: ReadonlySet<string>, folded: readonly Embed[] | undefined): Embed[] | undefined {
121
+ return links.card && !removed.has(links.card) ? withCard(folded ?? [], links.card, 'detailed') : undefined
122
+ }
123
+
124
+ /** ✕ on a sent message's card: the folded set, with that card `none` and every other kept. */
125
+ export function withoutCard(folded: readonly Embed[] | undefined, value: string): Embed[] {
126
+ return withCard(folded ?? [], value, 'none')
127
+ }
package/src/composer.ts CHANGED
@@ -44,6 +44,52 @@ const keyOf = (node: EditorNode): string | null => {
44
44
  return typeof pubkey === 'string' && HEX_KEY.test(pubkey) ? pubkey : null
45
45
  }
46
46
 
47
+ /**
48
+ * A link on words as the marker format writes it, `[words](url)`, and back:
49
+ * the same alternation protocol's `valuesIn` and ui's `RichText` read, so a
50
+ * URL starting earlier swallows a bracket inside it here as it does there.
51
+ * Words hold no bracket and no line break (COMM-8; Peek's rule).
52
+ */
53
+ const LINK_OR_URL = /(\[([^[\]\n]+)\]\(((?:https?:\/\/|mailto:)[^\s)]+)\))|(https?:\/\/[^\s<>"'`]+)/g
54
+ const LINK_TARGET = /^(?:https?:\/\/|mailto:)[^\s)]+$/
55
+ const LINK_WORDS = /^[^[\]\n]+$/
56
+
57
+ const linkMarkOf = (node: EditorNode) => node.marks?.find((m) => m.type === 'link')
58
+
59
+ /**
60
+ * Words the box holds as a link (a URL pasted over them) written as
61
+ * `[words](url)`. The block bridge draws and writes no link on words, so
62
+ * without this the words would be sent and the link dropped. A link whose
63
+ * words are its URL is the URL itself; words that cannot be a marker link (a
64
+ * bracket, code) keep their words and lose the link, as the bridge did.
65
+ */
66
+ function linkOnWordsAsMarker(node: EditorNode): EditorNode {
67
+ const link = linkMarkOf(node)
68
+ const href = link?.attrs?.href
69
+ if (!link || node.text === undefined) return node
70
+ const marks = (node.marks ?? []).filter((m) => m !== link)
71
+ const kept = marks.length ? { marks } : {}
72
+ const written = typeof href === 'string' && node.text !== href && LINK_TARGET.test(href) && LINK_WORDS.test(node.text) && !marks.some((m) => m.type === 'code')
73
+ return { type: 'text', text: written ? `[${node.text}](${href})` : node.text, ...kept }
74
+ }
75
+
76
+ /** Marker text's `[words](url)` in a text node, as the words with a `link` mark the box draws; anything else as it was. */
77
+ function linksOnWordsAsMarks(node: EditorNode): EditorNode[] {
78
+ const text = node.text ?? ''
79
+ if (!text.includes('](') || node.marks?.some((m) => m.type === 'code' || m.type === 'link')) return [node]
80
+ const out: EditorNode[] = []
81
+ let at = 0
82
+ for (const m of text.matchAll(LINK_OR_URL)) {
83
+ if (!m[1]) continue
84
+ if (m.index > at) out.push({ ...node, text: text.slice(at, m.index) })
85
+ out.push({ ...node, text: m[2], marks: [...(node.marks ?? []), { type: 'link', attrs: { href: m[3] } }] })
86
+ at = m.index + m[0].length
87
+ }
88
+ if (out.length === 0) return [node]
89
+ if (at < text.length) out.push({ ...node, text: text.slice(at) })
90
+ return out
91
+ }
92
+
47
93
  /**
48
94
  * The chips as the block bridge can write them. `fromEditorDocument` knows a
49
95
  * `reference` and drops any inline node it does not, so a picked person would
@@ -51,6 +97,7 @@ const keyOf = (node: EditorNode): string | null => {
51
97
  * names (§13.1), or `@Name` / `!@Name` for somebody with no key.
52
98
  */
53
99
  function chipsAsReferences(node: EditorNode): EditorNode {
100
+ if (node.type === 'text') return linkOnWordsAsMarker(node)
54
101
  if (node.type === 'mention' || node.type === 'urgentMention') {
55
102
  const pubkey = keyOf(node)
56
103
  const written = mentionText({ pubkey, label: String(node.attrs?.label ?? '') }, node.type === 'urgentMention')
@@ -110,7 +157,8 @@ const plainReference = (node: EditorNode): string | null => {
110
157
  * tag, so marker text alone cannot say it); a message or a file becomes its
111
158
  * `captionedReference` chip. Whatever `labels` does not know stays the
112
159
  * `reference` it was, and so does one with marks or a card, which a chip
113
- * would lose.
160
+ * would lose. A link on words, `[words](url)`, opens as the words with a
161
+ * `link` mark, as the box drew it while it was written.
114
162
  */
115
163
  export function composerDocument(text: string, labels: ComposerLabels = {}, urgent?: readonly string[]): EditorDocument {
116
164
  const keys = new Set(urgent ?? [])
@@ -132,7 +180,7 @@ export function composerDocument(text: string, labels: ComposerLabels = {}, urge
132
180
  if (caption) return { type: 'captionedReference', attrs: { id: uri, label: caption.label, snippet: caption.snippet, uri } }
133
181
  return node
134
182
  }
135
- return node.content ? { ...node, content: node.content.map(walk) } : node
183
+ return node.content ? { ...node, content: node.content.flatMap((child) => (child.type === 'text' ? linksOnWordsAsMarks(child) : [walk(child)])) } : node
136
184
  }
137
185
  return walk(toEditorDocument(documentForEditing(text, 'marker')) as EditorNode) as EditorDocument
138
186
  }
package/src/index.ts CHANGED
@@ -12,7 +12,7 @@
12
12
  * apps: it imports no app's data layer, opens no socket, and takes every
13
13
  * environment touch — the relay read, the clock, storage — as a parameter.
14
14
  */
15
- export const CONVERSATION_VERSION = '0.15.1'
15
+ export const CONVERSATION_VERSION = '0.16.0'
16
16
 
17
17
  export {
18
18
  KIND_MESSAGE,
@@ -76,6 +76,19 @@ export {
76
76
  type ComposerText,
77
77
  } from './composer.js'
78
78
 
79
+ export {
80
+ MAX_PARTS,
81
+ boxLinksOf,
82
+ boxReadOf,
83
+ embedsToEdit,
84
+ embedsToSend,
85
+ linkTargetOf,
86
+ namedBefore,
87
+ withoutCard,
88
+ type BoxLinkContext,
89
+ type BoxLinks,
90
+ } from './boxCard.js'
91
+
79
92
  export {
80
93
  FILE_TIER,
81
94
  fileReference,