@estiva-app/conversation 0.15.1 → 0.17.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 +44 -0
- package/README.md +3 -1
- package/dist/boxCard.d.ts +76 -0
- package/dist/boxCard.d.ts.map +1 -0
- package/dist/boxCard.js +87 -0
- package/dist/boxCard.js.map +1 -0
- package/dist/composer.d.ts +2 -1
- package/dist/composer.d.ts.map +1 -1
- package/dist/composer.js +53 -2
- package/dist/composer.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/textMentions.d.ts +57 -0
- package/dist/textMentions.d.ts.map +1 -0
- package/dist/textMentions.js +102 -0
- package/dist/textMentions.js.map +1 -0
- package/package.json +3 -3
- package/src/boxCard.ts +127 -0
- package/src/composer.ts +50 -2
- package/src/index.ts +16 -1
- package/src/textMentions.ts +123 -0
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,50 @@ 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.17.0 — 2026-10-20
|
|
10
|
+
|
|
11
|
+
**A mention in a file's text adds the person** (WBD-2; record
|
|
12
|
+
*a-mention-in-a-files-text-adds-the-person-with-no-unread*).
|
|
13
|
+
`mentionAddsFor(writer, atMs, { file, folder, saved, editedFrom })` is the one
|
|
14
|
+
helper every writer of a page or a description uses: it returns the Add
|
|
15
|
+
(`member:<P>` = `true`, `buildMembershipChange`'s event) for each person the
|
|
16
|
+
saved text names by `nostr:npub` and the version it was edited from did not. A
|
|
17
|
+
creation passes `editedFrom: null`. A typo fix returns nothing, the writer is
|
|
18
|
+
never added, and a run in code or a code block names nobody.
|
|
19
|
+
`peopleNamedInText` reads a block document (a `reference` mark's `uri` only)
|
|
20
|
+
or marker text. Being added shows no unread: that belongs to a document's own
|
|
21
|
+
read state, shaped later.
|
|
22
|
+
|
|
23
|
+
Nothing in how a conversation is read changed, so an app on 0.16 reads
|
|
24
|
+
everything as before, and folds the Add as a join.
|
|
25
|
+
|
|
26
|
+
SPEC: §11.8 *A mention in a file's text*, *Being added is not unread by
|
|
27
|
+
itself*; §13.1 *A file's text is not a message*; §7.3 `format`; C28.
|
|
28
|
+
|
|
29
|
+
## 0.16.0 — 2026-10-19
|
|
30
|
+
|
|
31
|
+
**What a comment box shows under itself, for every app's box** (COMM-8; record
|
|
32
|
+
*a-link-on-words-counts-toward-the-card*). `boxReadOf(doc, context)` reads the
|
|
33
|
+
shared box's document as a send writes it and answers the one file that gets
|
|
34
|
+
its default card, the live `part` of each block link (one per file, at most
|
|
35
|
+
`MAX_PARTS`), and the URLs it names for the app's resolver to ask about.
|
|
36
|
+
`embedsToSend` / `embedsToEdit` / `withoutCard` / `namedBefore` are Peek's
|
|
37
|
+
`lib/boxCard.ts` rules, moved here so Leaf, and Ship on the shared box, write
|
|
38
|
+
the `embed` set as Peek does. One change from Peek's copy: a link to a block of
|
|
39
|
+
the file the conversation is on is its chip only and writes no `part` (Miky,
|
|
40
|
+
2026-10-19).
|
|
41
|
+
|
|
42
|
+
**A link on words is sent.** `composerText` writes words carrying a `link`
|
|
43
|
+
mark — a URL pasted over them in the box — as `[words](url)`; until now the
|
|
44
|
+
block bridge wrote the words and dropped the link. Words holding a bracket, or
|
|
45
|
+
in code, keep their words only. `composerDocument` opens `[words](url)` as the
|
|
46
|
+
words with a `link` mark, so an edit shows the link as it was drawn.
|
|
47
|
+
|
|
48
|
+
Takes `@estiva-app/protocol` ≥ 0.40.0, where a link on words names its file.
|
|
49
|
+
|
|
50
|
+
SPEC: §13.6.1, §13.6.2 — no rule changed; this package now writes what they
|
|
51
|
+
already say, as Peek and Ship do.
|
|
52
|
+
|
|
9
53
|
## 0.15.1 — 2026-10-19
|
|
10
54
|
|
|
11
55
|
**`-"…"` leaves a phrase out**, as the relay reads it (buzz#32).
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ and estiva-agent read conversations through it.
|
|
|
7
7
|
**A convenience, never a requirement.** SPEC §9's conversation checks
|
|
8
8
|
(C10–C18) are written so an app can build conversations from the specification
|
|
9
9
|
alone, and this package's tests are those checks
|
|
10
|
-
(`test/conformance.test.ts` for C10–C16, `test/membership.test.ts` for C17 and C18). If you find this package disagreeing with the
|
|
10
|
+
(`test/conformance.test.ts` for C10–C16, `test/membership.test.ts` for C17 and C18, `test/textMentions.test.ts` for C28). If you find this package disagreeing with the
|
|
11
11
|
SPEC, the package is wrong.
|
|
12
12
|
|
|
13
13
|
```bash
|
|
@@ -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` |
|
|
@@ -38,6 +39,7 @@ pass, the clock is a `createdAtMs` you pass, and drafts take their storage.
|
|
|
38
39
|
| muting | §11.8 | `parseMutedBlob`, `serializeMutedBlob`, `buildMutedEvent`, `mutedFilter`, `mutedFromFollowed` |
|
|
39
40
|
| read state | §11.1–§11.6 | `channelContext`, `fileContext`, `threadContext`, `loadSlotIdentity`, `advanceContexts`, `fetchReadState`, `publishReadState`, `mergeSlots`, `effectiveReadAt`, `THREAD_RULE_FROM`, `REPLY_FLOOR_CONTEXT`, `capReadStateContexts` |
|
|
40
41
|
| unread | §11.3, §11.8 | `unreadIn`, `isUnread` |
|
|
42
|
+
| a mention in a file's text | §11.8, §13.1 | `mentionAddsFor`, `newlyNamedPeople`, `peopleNamedInText` |
|
|
41
43
|
|
|
42
44
|
Chat, an edit, a reaction and a deletion are built with
|
|
43
45
|
`@estiva-app/protocol`'s `buildMessage`, `buildEdit`, `buildReaction` and
|
|
@@ -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,IA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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"}
|
package/dist/boxCard.js
ADDED
|
@@ -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"}
|
package/dist/composer.d.ts
CHANGED
|
@@ -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
|
/**
|
package/dist/composer.d.ts.map
CHANGED
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"composer.d.ts","sourceRoot":"","sources":["../src/composer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;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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.
|
|
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
|
}
|
package/dist/composer.js.map
CHANGED
|
@@ -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,GAAG,IAAI,CAAC,KAAK,EAAE,MAAM,CAAA;IACjC,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAA;AAC3E,CAAC,CAAA;AAED;;;;;GAKG;AACH,SAAS,iBAAiB,CAA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K,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
|
+
export declare const CONVERSATION_VERSION = "0.17.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,9 +23,11 @@ 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';
|
|
29
30
|
export { unreadIn, isUnread, type StreamJudge } from './unread.js';
|
|
31
|
+
export { peopleNamedInText, newlyNamedPeople, mentionAddsFor, type FileText } from './textMentions.js';
|
|
30
32
|
export { createDraftStore, draftKeys, NO_DRAFTS, DRAFT_MAX_AGE_MS, DRAFT_MAX_CHARS, type Draft, type DraftStore, type DraftStorage, } from './drafts.js';
|
|
31
33
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,oBAAoB,WAAW,CAAA;AAE5C,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,S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AuB,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,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,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,cAAc,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAEtG,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
|
+
export const CONVERSATION_VERSION = '0.17.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,9 +23,11 @@ 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';
|
|
29
30
|
export { unreadIn, isUnread } from './unread.js';
|
|
31
|
+
export { peopleNamedInText, newlyNamedPeople, mentionAddsFor } from './textMentions.js';
|
|
30
32
|
export { createDraftStore, draftKeys, NO_DRAFTS, DRAFT_MAX_AGE_MS, DRAFT_MAX_CHARS, } from './drafts.js';
|
|
31
33
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;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,YAAY,EAAiB,MAAM,cAAc,CAAA;AAEpE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,eAAe,EAAE,UAAU,EAAiB,MAAM,YAAY,CAAA;AAE/G,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,cAAc,GAIf,MAAM,gBAAgB,CAAA;AAEvB,OAAO,EAAE,aAAa,EAAoE,MAAM,kBAAkB,CAAA;AAElH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,mBAAmB,EAAE,OAAO,EAAmB,MAA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/**
|
|
2
|
+
* A mention in a file's text — SPEC §11.8 *A mention in a file's text*.
|
|
3
|
+
*
|
|
4
|
+
* A file's text (its root's content, or a prose field's value, §7.3) is not a
|
|
5
|
+
* message: a save of it carries no `p` for the people it names (§13.1). What
|
|
6
|
+
* adds a person is the membership change the writer signs when its save names
|
|
7
|
+
* them and the version it edited from did not, the same Add a Members button
|
|
8
|
+
* writes. A typo fix names nobody new, so it writes nothing, and a person who
|
|
9
|
+
* left stays out. Being added shows no unread by itself.
|
|
10
|
+
*
|
|
11
|
+
* The writer compares the two versions it holds, the one it loaded and the one
|
|
12
|
+
* it saves; nothing is kept between edits. Leaf, Ship, Peek's panel and the
|
|
13
|
+
* agent's description writes all use {@link mentionAddsFor}.
|
|
14
|
+
*
|
|
15
|
+
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-mention-in-a-files-text-adds-the-person-with-no-unread.md
|
|
16
|
+
*/
|
|
17
|
+
import { type BlockDocument, type UnsignedEvent } from '@estiva-app/protocol';
|
|
18
|
+
/**
|
|
19
|
+
* One version of a file's text: what goes in the event's content (or a
|
|
20
|
+
* change's `value`), and its `content-format` tag. A block document may be
|
|
21
|
+
* passed parsed. With no `format`, a string is §13.2 marker text.
|
|
22
|
+
*/
|
|
23
|
+
export interface FileText {
|
|
24
|
+
content: string | BlockDocument;
|
|
25
|
+
format?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The people a version of a file's text names by `nostr:npub…`: a `reference`
|
|
29
|
+
* mark in a block document (§13.3), or the URI itself in marker text (§13.2).
|
|
30
|
+
* A bare key in a document's plain run, a run marked `code`, and a code block
|
|
31
|
+
* name nobody.
|
|
32
|
+
*/
|
|
33
|
+
export declare function peopleNamedInText(text: FileText): Set<string>;
|
|
34
|
+
/**
|
|
35
|
+
* The people `saved` names and `editedFrom` did not, in the order `saved`
|
|
36
|
+
* names them. `editedFrom` is `null` for a creation, which is edited from
|
|
37
|
+
* nothing.
|
|
38
|
+
*/
|
|
39
|
+
export declare function newlyNamedPeople(saved: FileText, editedFrom: FileText | null): string[];
|
|
40
|
+
/**
|
|
41
|
+
* The membership changes a save of a file's text writes beside itself
|
|
42
|
+
* (§11.8): one Add (`member:<P>` = `true`) for each person `saved` names and
|
|
43
|
+
* `editedFrom` did not, signed by `writer`, at most
|
|
44
|
+
* {@link MAX_MENTIONED_PEOPLE}. None for the writer, whose own Add would be a
|
|
45
|
+
* Join, and none when nobody is named anew — a typo fix writes nothing.
|
|
46
|
+
*
|
|
47
|
+
* The save itself carries no `p` for these people (§13.1). Publish each Add
|
|
48
|
+
* with the save; an Add the relay refuses is the person not being told, and is
|
|
49
|
+
* surfaced like any failed write (C9).
|
|
50
|
+
*/
|
|
51
|
+
export declare function mentionAddsFor(writer: string, createdAtMs: number, args: {
|
|
52
|
+
file: string;
|
|
53
|
+
folder: string;
|
|
54
|
+
saved: FileText;
|
|
55
|
+
editedFrom: FileText | null;
|
|
56
|
+
}): UnsignedEvent[];
|
|
57
|
+
//# sourceMappingURL=textMentions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textMentions.d.ts","sourceRoot":"","sources":["../src/textMentions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAKL,KAAK,aAAa,EAElB,KAAK,aAAa,EACnB,MAAM,sBAAsB,CAAA;AAI7B;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,GAAG,aAAa,CAAA;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAiCD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,CAe7D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,GAAG,IAAI,GAAG,MAAM,EAAE,CAGvF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,QAAQ,CAAC;IAAC,UAAU,EAAE,QAAQ,GAAG,IAAI,CAAA;CAAE,GACnF,aAAa,EAAE,CAKjB"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A mention in a file's text — SPEC §11.8 *A mention in a file's text*.
|
|
3
|
+
*
|
|
4
|
+
* A file's text (its root's content, or a prose field's value, §7.3) is not a
|
|
5
|
+
* message: a save of it carries no `p` for the people it names (§13.1). What
|
|
6
|
+
* adds a person is the membership change the writer signs when its save names
|
|
7
|
+
* them and the version it edited from did not, the same Add a Members button
|
|
8
|
+
* writes. A typo fix names nobody new, so it writes nothing, and a person who
|
|
9
|
+
* left stays out. Being added shows no unread by itself.
|
|
10
|
+
*
|
|
11
|
+
* The writer compares the two versions it holds, the one it loaded and the one
|
|
12
|
+
* it saves; nothing is kept between edits. Leaf, Ship, Peek's panel and the
|
|
13
|
+
* agent's description writes all use {@link mentionAddsFor}.
|
|
14
|
+
*
|
|
15
|
+
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-mention-in-a-files-text-adds-the-person-with-no-unread.md
|
|
16
|
+
*/
|
|
17
|
+
import { BLOCK_DOCUMENT_FORMAT, markersToInlineNodes, parseBlockDocument, } from '@estiva-app/protocol';
|
|
18
|
+
import { buildMembershipChange } from './membership.js';
|
|
19
|
+
import { MAX_MENTIONED_PEOPLE, peopleNamedInBody } from './strength.js';
|
|
20
|
+
const isInlineRun = (content) => Array.isArray(content) && content.every((n) => typeof n === 'object' && n !== null && n.type === 'text');
|
|
21
|
+
/** A `reference` mark's `uri`, when the mark is well formed; somebody else's JSON may hold `"attrs": null`. */
|
|
22
|
+
function referenceUri(node) {
|
|
23
|
+
const attrs = node.marks?.find((m) => m.type === 'reference')?.attrs;
|
|
24
|
+
const uri = attrs && typeof attrs === 'object' ? attrs.uri : undefined;
|
|
25
|
+
return typeof uri === 'string' && uri !== '' ? uri : undefined;
|
|
26
|
+
}
|
|
27
|
+
function namedInBlocks(blocks, out) {
|
|
28
|
+
for (const block of blocks) {
|
|
29
|
+
// A code block's text is code, not prose (§13.1): a key in it names nobody.
|
|
30
|
+
if (block.type === 'codeBlock' || !Array.isArray(block.content))
|
|
31
|
+
continue;
|
|
32
|
+
if (!isInlineRun(block.content)) {
|
|
33
|
+
namedInBlocks(block.content, out);
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
namedInRuns(block.content, out);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Only a `reference` mark names a person (§13.1); a bare key in a run's text is text, as a reader draws it. */
|
|
40
|
+
function namedInRuns(nodes, out) {
|
|
41
|
+
for (const node of nodes) {
|
|
42
|
+
if (node.marks?.some((m) => m.type === 'code'))
|
|
43
|
+
continue;
|
|
44
|
+
const uri = referenceUri(node);
|
|
45
|
+
if (uri)
|
|
46
|
+
for (const person of peopleNamedInBody(uri))
|
|
47
|
+
out.add(person);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The people a version of a file's text names by `nostr:npub…`: a `reference`
|
|
52
|
+
* mark in a block document (§13.3), or the URI itself in marker text (§13.2).
|
|
53
|
+
* A bare key in a document's plain run, a run marked `code`, and a code block
|
|
54
|
+
* name nobody.
|
|
55
|
+
*/
|
|
56
|
+
export function peopleNamedInText(text) {
|
|
57
|
+
const out = new Set();
|
|
58
|
+
let doc;
|
|
59
|
+
if (typeof text.content !== 'string')
|
|
60
|
+
doc = text.content;
|
|
61
|
+
else if (text.format === BLOCK_DOCUMENT_FORMAT) {
|
|
62
|
+
try {
|
|
63
|
+
doc = parseBlockDocument(text.content);
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
// A tag that lies about its content: read the string as marker text, as a message is read.
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (doc)
|
|
70
|
+
namedInBlocks(doc.content, out);
|
|
71
|
+
// Marker text through §13.2's own parse, so a key inside `code` stays code.
|
|
72
|
+
else if (typeof text.content === 'string')
|
|
73
|
+
namedInRuns(markersToInlineNodes(text.content), out);
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* The people `saved` names and `editedFrom` did not, in the order `saved`
|
|
78
|
+
* names them. `editedFrom` is `null` for a creation, which is edited from
|
|
79
|
+
* nothing.
|
|
80
|
+
*/
|
|
81
|
+
export function newlyNamedPeople(saved, editedFrom) {
|
|
82
|
+
const before = editedFrom ? peopleNamedInText(editedFrom) : new Set();
|
|
83
|
+
return [...peopleNamedInText(saved)].filter((person) => !before.has(person));
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The membership changes a save of a file's text writes beside itself
|
|
87
|
+
* (§11.8): one Add (`member:<P>` = `true`) for each person `saved` names and
|
|
88
|
+
* `editedFrom` did not, signed by `writer`, at most
|
|
89
|
+
* {@link MAX_MENTIONED_PEOPLE}. None for the writer, whose own Add would be a
|
|
90
|
+
* Join, and none when nobody is named anew — a typo fix writes nothing.
|
|
91
|
+
*
|
|
92
|
+
* The save itself carries no `p` for these people (§13.1). Publish each Add
|
|
93
|
+
* with the save; an Add the relay refuses is the person not being told, and is
|
|
94
|
+
* surfaced like any failed write (C9).
|
|
95
|
+
*/
|
|
96
|
+
export function mentionAddsFor(writer, createdAtMs, args) {
|
|
97
|
+
return newlyNamedPeople(args.saved, args.editedFrom)
|
|
98
|
+
.filter((person) => person !== writer)
|
|
99
|
+
.slice(0, MAX_MENTIONED_PEOPLE)
|
|
100
|
+
.map((person) => buildMembershipChange(writer, createdAtMs, { file: args.file, folder: args.folder, person, member: true }));
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=textMentions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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AAoB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,CAAA;IAC/F,OAAO,GAAG,CAAA;AACZ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAe,EAAE,UAA2B;IAC3E,MAAM,MAAM,GAAG,UAAU,CAAC,CAAC,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,EAAU,CAAA;IAC7E,OAAO,CAAC,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;AAC9E,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAc,EACd,WAAmB,EACnB,IAAoF;IAEpF,OAAO,gBAAgB,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC;SACjD,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,MAAM,CAAC;SACrC,KAAK,CAAC,CAAC,EAAE,oBAAoB,CAAC;SAC9B,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,qBAAqB,CAAC,MAAM,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;AAChI,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@estiva-app/conversation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.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.
|
|
50
|
+
"@estiva-app/protocol": ">=0.40.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@estiva-app/protocol": ">=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.
|
|
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
|
+
export const CONVERSATION_VERSION = '0.17.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,
|
|
@@ -168,6 +181,8 @@ export {
|
|
|
168
181
|
|
|
169
182
|
export { unreadIn, isUnread, type StreamJudge } from './unread.js'
|
|
170
183
|
|
|
184
|
+
export { peopleNamedInText, newlyNamedPeople, mentionAddsFor, type FileText } from './textMentions.js'
|
|
185
|
+
|
|
171
186
|
export {
|
|
172
187
|
createDraftStore,
|
|
173
188
|
draftKeys,
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A mention in a file's text — SPEC §11.8 *A mention in a file's text*.
|
|
3
|
+
*
|
|
4
|
+
* A file's text (its root's content, or a prose field's value, §7.3) is not a
|
|
5
|
+
* message: a save of it carries no `p` for the people it names (§13.1). What
|
|
6
|
+
* adds a person is the membership change the writer signs when its save names
|
|
7
|
+
* them and the version it edited from did not, the same Add a Members button
|
|
8
|
+
* writes. A typo fix names nobody new, so it writes nothing, and a person who
|
|
9
|
+
* left stays out. Being added shows no unread by itself.
|
|
10
|
+
*
|
|
11
|
+
* The writer compares the two versions it holds, the one it loaded and the one
|
|
12
|
+
* it saves; nothing is kept between edits. Leaf, Ship, Peek's panel and the
|
|
13
|
+
* agent's description writes all use {@link mentionAddsFor}.
|
|
14
|
+
*
|
|
15
|
+
* why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-mention-in-a-files-text-adds-the-person-with-no-unread.md
|
|
16
|
+
*/
|
|
17
|
+
import {
|
|
18
|
+
BLOCK_DOCUMENT_FORMAT,
|
|
19
|
+
markersToInlineNodes,
|
|
20
|
+
parseBlockDocument,
|
|
21
|
+
type Block,
|
|
22
|
+
type BlockDocument,
|
|
23
|
+
type InlineTextNode,
|
|
24
|
+
type UnsignedEvent,
|
|
25
|
+
} from '@estiva-app/protocol'
|
|
26
|
+
import { buildMembershipChange } from './membership.js'
|
|
27
|
+
import { MAX_MENTIONED_PEOPLE, peopleNamedInBody } from './strength.js'
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* One version of a file's text: what goes in the event's content (or a
|
|
31
|
+
* change's `value`), and its `content-format` tag. A block document may be
|
|
32
|
+
* passed parsed. With no `format`, a string is §13.2 marker text.
|
|
33
|
+
*/
|
|
34
|
+
export interface FileText {
|
|
35
|
+
content: string | BlockDocument
|
|
36
|
+
format?: string
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const isInlineRun = (content: unknown): content is InlineTextNode[] =>
|
|
40
|
+
Array.isArray(content) && content.every((n) => typeof n === 'object' && n !== null && (n as { type?: unknown }).type === 'text')
|
|
41
|
+
|
|
42
|
+
/** A `reference` mark's `uri`, when the mark is well formed; somebody else's JSON may hold `"attrs": null`. */
|
|
43
|
+
function referenceUri(node: InlineTextNode): string | undefined {
|
|
44
|
+
const attrs = (node.marks?.find((m) => m.type === 'reference') as { attrs?: unknown } | undefined)?.attrs
|
|
45
|
+
const uri = attrs && typeof attrs === 'object' ? (attrs as { uri?: unknown }).uri : undefined
|
|
46
|
+
return typeof uri === 'string' && uri !== '' ? uri : undefined
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function namedInBlocks(blocks: readonly Block[], out: Set<string>): void {
|
|
50
|
+
for (const block of blocks) {
|
|
51
|
+
// A code block's text is code, not prose (§13.1): a key in it names nobody.
|
|
52
|
+
if (block.type === 'codeBlock' || !Array.isArray(block.content)) continue
|
|
53
|
+
if (!isInlineRun(block.content)) {
|
|
54
|
+
namedInBlocks(block.content as Block[], out)
|
|
55
|
+
continue
|
|
56
|
+
}
|
|
57
|
+
namedInRuns(block.content, out)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Only a `reference` mark names a person (§13.1); a bare key in a run's text is text, as a reader draws it. */
|
|
62
|
+
function namedInRuns(nodes: readonly InlineTextNode[], out: Set<string>): void {
|
|
63
|
+
for (const node of nodes) {
|
|
64
|
+
if (node.marks?.some((m) => m.type === 'code')) continue
|
|
65
|
+
const uri = referenceUri(node)
|
|
66
|
+
if (uri) for (const person of peopleNamedInBody(uri)) out.add(person)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The people a version of a file's text names by `nostr:npub…`: a `reference`
|
|
72
|
+
* mark in a block document (§13.3), or the URI itself in marker text (§13.2).
|
|
73
|
+
* A bare key in a document's plain run, a run marked `code`, and a code block
|
|
74
|
+
* name nobody.
|
|
75
|
+
*/
|
|
76
|
+
export function peopleNamedInText(text: FileText): Set<string> {
|
|
77
|
+
const out = new Set<string>()
|
|
78
|
+
let doc: BlockDocument | undefined
|
|
79
|
+
if (typeof text.content !== 'string') doc = text.content
|
|
80
|
+
else if (text.format === BLOCK_DOCUMENT_FORMAT) {
|
|
81
|
+
try {
|
|
82
|
+
doc = parseBlockDocument(text.content)
|
|
83
|
+
} catch {
|
|
84
|
+
// A tag that lies about its content: read the string as marker text, as a message is read.
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (doc) namedInBlocks(doc.content, out)
|
|
88
|
+
// Marker text through §13.2's own parse, so a key inside `code` stays code.
|
|
89
|
+
else if (typeof text.content === 'string') namedInRuns(markersToInlineNodes(text.content), out)
|
|
90
|
+
return out
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The people `saved` names and `editedFrom` did not, in the order `saved`
|
|
95
|
+
* names them. `editedFrom` is `null` for a creation, which is edited from
|
|
96
|
+
* nothing.
|
|
97
|
+
*/
|
|
98
|
+
export function newlyNamedPeople(saved: FileText, editedFrom: FileText | null): string[] {
|
|
99
|
+
const before = editedFrom ? peopleNamedInText(editedFrom) : new Set<string>()
|
|
100
|
+
return [...peopleNamedInText(saved)].filter((person) => !before.has(person))
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* The membership changes a save of a file's text writes beside itself
|
|
105
|
+
* (§11.8): one Add (`member:<P>` = `true`) for each person `saved` names and
|
|
106
|
+
* `editedFrom` did not, signed by `writer`, at most
|
|
107
|
+
* {@link MAX_MENTIONED_PEOPLE}. None for the writer, whose own Add would be a
|
|
108
|
+
* Join, and none when nobody is named anew — a typo fix writes nothing.
|
|
109
|
+
*
|
|
110
|
+
* The save itself carries no `p` for these people (§13.1). Publish each Add
|
|
111
|
+
* with the save; an Add the relay refuses is the person not being told, and is
|
|
112
|
+
* surfaced like any failed write (C9).
|
|
113
|
+
*/
|
|
114
|
+
export function mentionAddsFor(
|
|
115
|
+
writer: string,
|
|
116
|
+
createdAtMs: number,
|
|
117
|
+
args: { file: string; folder: string; saved: FileText; editedFrom: FileText | null },
|
|
118
|
+
): UnsignedEvent[] {
|
|
119
|
+
return newlyNamedPeople(args.saved, args.editedFrom)
|
|
120
|
+
.filter((person) => person !== writer)
|
|
121
|
+
.slice(0, MAX_MENTIONED_PEOPLE)
|
|
122
|
+
.map((person) => buildMembershipChange(writer, createdAtMs, { file: args.file, folder: args.folder, person, member: true }))
|
|
123
|
+
}
|