@estiva-app/ui 0.51.0 → 0.52.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.
@@ -0,0 +1,507 @@
1
+ import type { ReactNode } from 'react'
2
+ import { Extension, type Editor } from '@tiptap/core'
3
+ import { PluginKey } from '@tiptap/pm/state'
4
+ import Mention, { type MentionOptions } from '@tiptap/extension-mention'
5
+ import Suggestion from '@tiptap/suggestion'
6
+ import { NodeViewWrapper, ReactNodeViewRenderer, type ReactNodeViewProps } from '@tiptap/react'
7
+ import { Avatar } from './Avatar'
8
+ import { EnterHint } from './Menu'
9
+ import { inlineChipClassName } from './InlineChip'
10
+ import type { SuggestionMenuRow } from './SuggestionMenu'
11
+ import { suggestionPopup, type SuggestionPopupOptions } from './suggestionPopup'
12
+
13
+ /*
14
+ * The four composer triggers every Estiva app shares — `@`, `!@`, `[` and `/`
15
+ * (CON-26, Miky 2026-10-02). Peek built them first and they move here unchanged
16
+ * (CON-27); an app passes in only its own data: its people, the things `[` can
17
+ * reference, and the `/` rows it can perform beside the shared Format section.
18
+ *
19
+ * **What a pick writes is not here.** The text a chip becomes in the body and
20
+ * the tags it earns are `@estiva-app/conversation`'s (`mentionText`,
21
+ * `messageReference`, `urgentTagsFor`), so a client without React writes the
22
+ * same bytes. A chip here carries what that needs: a person's `pubkey`, a
23
+ * reference's `uri`.
24
+ */
25
+
26
+ // ─── @ and !@ ───
27
+
28
+ /** A person `@` and `!@` offer. */
29
+ export interface MentionPerson {
30
+ /** The app's own key for the person — the row's key and the chip's `id`. */
31
+ id: string
32
+ name: string
33
+ /** The second line of the row: a role, a team. */
34
+ description?: string
35
+ /** Their Nostr key, when they have one — what the body is written with (SPEC §13.1). */
36
+ pubkey?: string | null
37
+ /** The face at the row's start. Default: the package `Avatar` for the name. */
38
+ avatar?: ReactNode
39
+ }
40
+
41
+ /** How many people the list shows. */
42
+ export const PEOPLE_LIMIT = 6
43
+
44
+ /** The people whose name holds the query, the first {@link PEOPLE_LIMIT} of them. */
45
+ export function filterPeople(people: readonly MentionPerson[], query: string): MentionPerson[] {
46
+ const q = query.toLowerCase()
47
+ return people.filter((person) => q === '' || person.name.toLowerCase().includes(q)).slice(0, PEOPLE_LIMIT)
48
+ }
49
+
50
+ /**
51
+ * The people list `@` and `!@` open: the face, the name, the second line, and
52
+ * the Enter hint while highlighted — `MenuItem` at its tall size.
53
+ */
54
+ export function peopleMenu(urgent: boolean): SuggestionPopupOptions<MentionPerson> {
55
+ const section = urgent ? 'Urgent mention' : 'People'
56
+ return {
57
+ ariaLabel: section,
58
+ // The people and the reference lists are the same box: 658px, capped at 360.
59
+ width: 'w-[658px]',
60
+ maxHeight: 'max-h-[360px]',
61
+ sections: (people) => [{ label: section, items: people, className: 'px-3 py-1' }],
62
+ itemKey: (person) => person.id,
63
+ row: (person) => ({
64
+ label: person.name,
65
+ description: person.description,
66
+ leading: person.avatar ?? <Avatar size={32} alt={person.name} />,
67
+ hint: <EnterHint />,
68
+ size: 'tall',
69
+ }),
70
+ }
71
+ }
72
+
73
+ export interface PersonMentionOptions {
74
+ /** Everyone the list can offer, asked each time the query changes. */
75
+ people: () => readonly MentionPerson[]
76
+ }
77
+
78
+ type Doc = { descendants: (cb: (node: { type: { name: string }; attrs: Record<string, unknown> }) => boolean | void) => void }
79
+
80
+ function optionsOf<T>(editor: Editor, name: string): T | undefined {
81
+ return editor.extensionManager.extensions.find((one) => one.name === name)?.options as T | undefined
82
+ }
83
+
84
+ /** `@`'s list and pick, or `!@`'s, for the node `name` — the extension's own, so a renamed one still finds its people. */
85
+ function personSuggestion(urgent: boolean, name: string) {
86
+ return {
87
+ ...(urgent ? { char: '!@' } : {}),
88
+ items: ({ query, editor }: { query: string; editor: Editor }) => filterPeople(optionsOf<PersonMentionOptions>(editor, name)?.people() ?? [], query),
89
+ render: suggestionPopup(peopleMenu(urgent)),
90
+ command: ({ editor, range, props: person }: { editor: Editor; range: { from: number; to: number }; props: MentionPerson }) => {
91
+ editor
92
+ .chain()
93
+ .focus()
94
+ .insertContentAt(range, [
95
+ { type: name, attrs: { id: person.id, label: person.name, pubkey: person.pubkey ?? null } },
96
+ { type: 'text', text: ' ' },
97
+ ])
98
+ .run()
99
+ },
100
+ }
101
+ }
102
+
103
+ /*
104
+ What a chip keeps through HTML — a copy and paste, inside an editor or
105
+ between two. The chip's own `renderHTML` writes each as a `data-*` attribute
106
+ and these read them back. Until CON-27 none was written, so a pasted chip
107
+ came back with every value null and was sent as `@null`. What is read is
108
+ checked: a crafted `data-pubkey` that is not a key, or a `data-uri` that is
109
+ not a `nostr:` reference, is dropped rather than written into the body.
110
+ */
111
+ const HEX_KEY = /^[0-9a-f]{64}$/
112
+ const NOSTR_URI = /^nostr:[a-z0-9]+$/i
113
+ const fromData = (name: string, valid?: RegExp) => ({
114
+ parseHTML: (element: HTMLElement) => {
115
+ const value = element.getAttribute(`data-${name}`)
116
+ return value !== null && (!valid || valid.test(value)) ? value : null
117
+ },
118
+ // The node's own `renderHTML` writes it.
119
+ renderHTML: () => ({}),
120
+ })
121
+
122
+ const personAttributes = () => ({
123
+ id: { default: null, ...fromData('id') },
124
+ label: { default: null, ...fromData('label') },
125
+ /**
126
+ * The person's Nostr key, when they have one — SPEC §13.1. `id` is the app's
127
+ * own and means nothing to another app; this is what the body is written
128
+ * with, so a mention survives a rename.
129
+ */
130
+ pubkey: { default: null, ...fromData('pubkey', HEX_KEY) },
131
+ })
132
+
133
+ /** The `data-*` a person chip is written with, so a paste reads it back. */
134
+ function personData(attrs: Record<string, unknown>): Record<string, string> {
135
+ return {
136
+ 'data-id': String(attrs.id ?? ''),
137
+ 'data-label': String(attrs.label ?? ''),
138
+ ...(typeof attrs.pubkey === 'string' && attrs.pubkey ? { 'data-pubkey': attrs.pubkey } : {}),
139
+ }
140
+ }
141
+
142
+ /**
143
+ * `@` — a person, as a chip that writes their key (SPEC §13.1).
144
+ *
145
+ * PersonMention.configure({ people: () => directory })
146
+ *
147
+ * Its `pubkey` and `label` are what `mentionText` takes.
148
+ */
149
+ export const PersonMention = Mention.extend<MentionOptions<MentionPerson, MentionPerson> & PersonMentionOptions>({
150
+ name: 'mention',
151
+ addOptions() {
152
+ return { ...this.parent!(), HTMLAttributes: {}, people: () => [], suggestion: personSuggestion(false, this.name) }
153
+ },
154
+ addAttributes: personAttributes,
155
+ renderHTML({ node }) {
156
+ // No node view, so this spec is what the editor draws: the one chip.
157
+ return ['span', { 'data-mention': 'true', ...personData(node.attrs), class: inlineChipClassName('person', 'cursor-default') }, `@${node.attrs.label}`]
158
+ },
159
+ parseHTML() {
160
+ return [{ tag: 'span[data-mention]' }]
161
+ },
162
+ })
163
+
164
+ /**
165
+ * `!@` — a person, urgently: the same chip in the urgent tone. Its text is an
166
+ * ordinary mention; the urgency travels as a tag (`urgentTagsFor`), so hand the
167
+ * write {@link urgentPubkeys}.
168
+ */
169
+ export const UrgentPersonMention = Mention.extend<MentionOptions<MentionPerson, MentionPerson> & PersonMentionOptions>({
170
+ name: 'urgentMention',
171
+ addOptions() {
172
+ return { ...this.parent!(), HTMLAttributes: {}, people: () => [], suggestion: personSuggestion(true, this.name) }
173
+ },
174
+ addAttributes: personAttributes,
175
+ renderHTML({ node }) {
176
+ return [
177
+ 'span',
178
+ { 'data-urgent-mention': 'true', ...personData(node.attrs), class: inlineChipClassName('urgent', 'cursor-default') },
179
+ `@${node.attrs.label}`,
180
+ ]
181
+ },
182
+ parseHTML() {
183
+ return [{ tag: 'span[data-urgent-mention]' }]
184
+ },
185
+ })
186
+
187
+ /**
188
+ * The keys the document's urgent mentions name — what the write turns into
189
+ * `["urgent", <pubkey>]` tags. A chip with no key has no tag to carry; its text
190
+ * is the old `!@Name`.
191
+ */
192
+ export function urgentPubkeys(editor: { state: { doc: Doc } }): string[] | undefined {
193
+ const urgent: string[] = []
194
+ editor.state.doc.descendants((node) => {
195
+ if (node.type.name === 'urgentMention' && typeof node.attrs.pubkey === 'string' && node.attrs.pubkey) urgent.push(node.attrs.pubkey)
196
+ })
197
+ return urgent.length > 0 ? urgent : undefined
198
+ }
199
+
200
+ // ─── [ ───
201
+
202
+ /** Something `[` offers: a reference drawn as who said it and how it opens. */
203
+ export interface CaptionedItem {
204
+ /** The referenced thing's id — the row's key and the chip's `id`. */
205
+ id: string
206
+ /** Who, as the list shows them. */
207
+ label: string
208
+ /** The opening words, marks stripped: the caption the row and the chip wear. */
209
+ snippet: string
210
+ /** `nostr:…`, exactly as the body will carry it (`messageReference`). */
211
+ uri: string
212
+ /** What the query is matched against beside `label`. Default: `snippet`. */
213
+ search?: string
214
+ }
215
+
216
+ /** How many references the list shows. */
217
+ export const REFERENCE_LIMIT = 6
218
+
219
+ /**
220
+ * The references whose label or text holds the query — the last
221
+ * {@link REFERENCE_LIMIT}, in the order given: a thread is unbounded, and a
222
+ * list that grew with it would be a hundred rows of prose.
223
+ */
224
+ export function filterReferences(items: readonly CaptionedItem[], query: string): CaptionedItem[] {
225
+ const q = query.toLowerCase()
226
+ const shown = q ? items.filter((item) => (item.search ?? item.snippet).toLowerCase().includes(q) || item.label.toLowerCase().includes(q)) : [...items]
227
+ return shown.slice(-REFERENCE_LIMIT)
228
+ }
229
+
230
+ const captionOf = (label: string, snippet: string) => (snippet ? `${label}: ${snippet}` : label)
231
+
232
+ export interface CaptionedReferenceOptions {
233
+ /** Drawn before the caption: a 14px icon. */
234
+ icon: ReactNode
235
+ }
236
+
237
+ /**
238
+ * A reference mid-sentence, drawn as `label: snippet` and written as its `uri`
239
+ * verbatim (SPEC §13.1). The caption is the snapshot it was picked with — a
240
+ * caption, never parsed. Inserted by {@link ReferenceTrigger}, a paste or a
241
+ * draft; it opens no list of its own.
242
+ */
243
+ export const CaptionedReference = Mention.extend<MentionOptions & CaptionedReferenceOptions>({
244
+ name: 'captionedReference',
245
+ group: 'inline',
246
+ inline: true,
247
+ atom: true,
248
+ addOptions() {
249
+ return { ...this.parent!(), HTMLAttributes: {}, icon: null, suggestion: { char: '\0', items: () => [] } }
250
+ },
251
+ addAttributes() {
252
+ return {
253
+ id: { default: null, ...fromData('id') },
254
+ label: { default: null, ...fromData('label') },
255
+ snippet: { default: '', parseHTML: (element: HTMLElement) => element.getAttribute('data-snippet') ?? '', renderHTML: () => ({}) },
256
+ uri: { default: null, ...fromData('uri', NOSTR_URI) },
257
+ }
258
+ },
259
+ renderHTML({ node }) {
260
+ return [
261
+ 'span',
262
+ { [`data-${this.name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)}`]: 'true', 'data-id': String(node.attrs.id ?? ''), 'data-label': String(node.attrs.label ?? ''), 'data-snippet': String(node.attrs.snippet ?? ''), ...(node.attrs.uri ? { 'data-uri': String(node.attrs.uri) } : {}), class: inlineChipClassName('neutral', 'cursor-default') },
263
+ captionOf(node.attrs.label, node.attrs.snippet),
264
+ ]
265
+ },
266
+ parseHTML() {
267
+ return [{ tag: `span[data-${this.name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`)}]` }]
268
+ },
269
+ addNodeView() {
270
+ const icon = this.options.icon
271
+ return ReactNodeViewRenderer(
272
+ ({ node }: ReactNodeViewProps) => (
273
+ <NodeViewWrapper as="span" className={inlineChipClassName('neutral', 'max-w-[24ch] cursor-default')}>
274
+ <span className="flex items-center justify-center w-4 h-4 shrink-0 text-text-secondary">{icon}</span>
275
+ <span className="truncate">{captionOf(node.attrs.label, node.attrs.snippet)}</span>
276
+ </NodeViewWrapper>
277
+ ),
278
+ { as: 'span' },
279
+ )
280
+ },
281
+ })
282
+
283
+ export interface ReferenceMenuOptions {
284
+ /** Names the list, e.g. what can be referenced. */
285
+ ariaLabel: string
286
+ /** The section's heading. */
287
+ sectionLabel: string
288
+ /** At each row's start: a 16px icon. */
289
+ icon: ReactNode
290
+ }
291
+
292
+ /** The list `[` opens: one section of `label: snippet` rows, the same box as the people list. */
293
+ export function referenceMenu({ ariaLabel, sectionLabel, icon }: ReferenceMenuOptions): SuggestionPopupOptions<CaptionedItem> {
294
+ return {
295
+ ariaLabel,
296
+ width: 'w-[658px]',
297
+ maxHeight: 'max-h-[360px]',
298
+ sections: (items) => [{ label: sectionLabel, items, className: 'px-2' }],
299
+ itemKey: (item) => `reference-${item.id}`,
300
+ row: (item) => ({ leading: icon, label: captionOf(item.label, item.snippet), hint: <EnterHint /> }),
301
+ }
302
+ }
303
+
304
+ export interface ReferenceTriggerOptions extends ReferenceMenuOptions {
305
+ /** Everything `[` can offer, asked each time the query changes. */
306
+ items: () => readonly CaptionedItem[]
307
+ /** The node a pick inserts. Default `captionedReference`. */
308
+ nodeName: string
309
+ }
310
+
311
+ /**
312
+ * `[` — reference something, inserted as a {@link CaptionedReference} chip.
313
+ *
314
+ * Its own extension rather than the chip's suggestion, so the chip's text (its
315
+ * `renderText`) does not change with the key that summons the list.
316
+ */
317
+ export const ReferenceTrigger = Extension.create<ReferenceTriggerOptions>({
318
+ name: 'referenceTrigger',
319
+ addOptions() {
320
+ return { items: () => [], nodeName: 'captionedReference', ariaLabel: 'References', sectionLabel: 'References', icon: null }
321
+ },
322
+ addProseMirrorPlugins() {
323
+ const options = this.options
324
+ return [
325
+ Suggestion<CaptionedItem>({
326
+ editor: this.editor,
327
+ char: '[',
328
+ pluginKey: new PluginKey('referenceTrigger'),
329
+ // As a mention's: only where the chip may go.
330
+ allow: ({ state, range }) => {
331
+ const type = state.schema.nodes[options.nodeName]
332
+ return !!type && !!state.doc.resolve(range.from).parent.type.contentMatch.matchType(type)
333
+ },
334
+ items: ({ query }) => filterReferences(options.items(), query),
335
+ render: suggestionPopup(referenceMenu(options)),
336
+ command: ({ editor, range, props: item }) => {
337
+ editor
338
+ .chain()
339
+ .focus()
340
+ .insertContentAt(range, [
341
+ { type: options.nodeName, attrs: { id: item.id, label: item.label, snippet: item.snippet, uri: item.uri } },
342
+ { type: 'text', text: ' ' },
343
+ ])
344
+ .run()
345
+ },
346
+ }),
347
+ ]
348
+ },
349
+ })
350
+
351
+ // ─── / ───
352
+
353
+ /** A row of the `/` list, and what choosing it does. */
354
+ export interface SlashCommand {
355
+ key: string
356
+ row: SuggestionMenuRow
357
+ /** Matched beside the row's label: an id, a trigger, a description. */
358
+ keywords?: readonly string[]
359
+ /** Runs once the `/query` that summoned the list has been removed. */
360
+ run: (editor: Editor) => void
361
+ }
362
+
363
+ export interface SlashSection {
364
+ label: string
365
+ commands: readonly SlashCommand[]
366
+ }
367
+
368
+ export type FormatId = 'paragraph' | 'heading' | 'subheading' | 'quote' | 'bulletList' | 'orderedList' | 'code'
369
+
370
+ export interface FormatDef {
371
+ id: FormatId
372
+ label: string
373
+ /** What you type to get it — the input rule the extension registers. Blank when there is none. */
374
+ trigger?: string
375
+ }
376
+
377
+ /**
378
+ * The formats `/` offers, in order. The hint is what you would type, not a key
379
+ * chord. Bold, italic and underline are absent: they act on text already
380
+ * written, so they are the selection toolbar's.
381
+ */
382
+ export const FORMATS: readonly FormatDef[] = [
383
+ { id: 'paragraph', label: 'Text' },
384
+ { id: 'heading', label: 'Heading', trigger: '#' },
385
+ { id: 'subheading', label: 'Subheading', trigger: '##' },
386
+ { id: 'quote', label: 'Quote', trigger: '>' },
387
+ { id: 'code', label: 'Code', trigger: '`' },
388
+ { id: 'bulletList', label: 'Bulleted list', trigger: '-' },
389
+ { id: 'orderedList', label: 'Numbered list', trigger: '1.' },
390
+ ]
391
+
392
+ /** Code as a mark inside the line, or as a block of its own. */
393
+ export type CodeFormat = 'inline' | 'block'
394
+
395
+ /**
396
+ * Apply one format to the current block. `set*` wherever Tiptap has one:
397
+ * choosing Heading should make a heading, not turn one off. `false` means
398
+ * nothing changed, not that anything failed.
399
+ */
400
+ export function applyFormat(editor: Editor, id: FormatId, code: CodeFormat = 'inline'): boolean {
401
+ const chain = editor.chain().focus()
402
+ /*
403
+ The node's own command, called by name: StarterKit's extensions declare
404
+ them, and this package builds without StarterKit. Its own command, rather
405
+ than the core one it wraps, because a list's runs with the app's options
406
+ (`keepMarks`, `itemTypeName`). An editor without that node changes nothing.
407
+ */
408
+ const run = (command: string, ...args: unknown[]): boolean => {
409
+ const named = (chain as unknown as Record<string, ((...a: unknown[]) => { run: () => boolean }) | undefined>)[command]
410
+ return named ? named(...args).run() : false
411
+ }
412
+ switch (id) {
413
+ case 'paragraph':
414
+ return run('setParagraph')
415
+ case 'heading':
416
+ return run('setHeading', { level: 1 })
417
+ case 'subheading':
418
+ return run('setHeading', { level: 2 })
419
+ case 'quote':
420
+ return run('toggleBlockquote')
421
+ case 'bulletList':
422
+ return run('toggleBulletList')
423
+ case 'orderedList':
424
+ return run('toggleOrderedList')
425
+ case 'code':
426
+ return run(code === 'block' ? 'toggleCodeBlock' : 'toggleCode')
427
+ default:
428
+ return false
429
+ }
430
+ }
431
+
432
+ /** The Format section every app's `/` opens with. */
433
+ export function formatSection(code: CodeFormat = 'inline'): SlashSection {
434
+ return {
435
+ label: 'Format',
436
+ commands: FORMATS.map((format) => ({
437
+ key: `format-${format.id}`,
438
+ row: { label: format.label, shortcut: format.trigger },
439
+ keywords: [format.id],
440
+ run: (editor) => {
441
+ applyFormat(editor, format.id, code)
442
+ },
443
+ })),
444
+ }
445
+ }
446
+
447
+ /** A row that types another trigger, so its own list opens — `@` from `/`. */
448
+ export function typeTrigger(input: string): SlashCommand['run'] {
449
+ // Deferred a frame: the delete of the `/query` has to land first, or the
450
+ // trigger's plugin sees the character arrive inside a range still being removed.
451
+ return (editor) => {
452
+ requestAnimationFrame(() => editor.commands.insertContent(input))
453
+ }
454
+ }
455
+
456
+ function matches(command: SlashCommand, q: string): boolean {
457
+ return [command.row.label, ...(command.keywords ?? [])].some((text) => text.toLowerCase().includes(q))
458
+ }
459
+
460
+ /** The sections narrowed to a query — the text typed after the `/`. Empty sections stay. */
461
+ export function filterSlashSections(sections: readonly SlashSection[], query: string): SlashSection[] {
462
+ const q = query.toLowerCase()
463
+ return sections.map((section) => ({ ...section, commands: q ? section.commands.filter((command) => matches(command, q)) : section.commands }))
464
+ }
465
+
466
+ export interface SlashCommandsOptions {
467
+ /** The sections, in order: {@link formatSection} first, then the app's own. */
468
+ sections: readonly SlashSection[]
469
+ }
470
+
471
+ type SlashRow = SlashCommand & { section: number }
472
+
473
+ /**
474
+ * `/` — format the line or insert something, at the caret, mid-sentence too.
475
+ * A `/` inside a word (`and/or`, a path) opens nothing: the plugin wants a
476
+ * space or the line's start before it.
477
+ */
478
+ export const SlashCommands = Extension.create<SlashCommandsOptions>({
479
+ name: 'slashCommands',
480
+ addOptions() {
481
+ return { sections: [formatSection()] }
482
+ },
483
+ addProseMirrorPlugins() {
484
+ const sections = this.options.sections
485
+ return [
486
+ Suggestion<SlashRow>({
487
+ editor: this.editor,
488
+ char: '/',
489
+ startOfLine: false,
490
+ pluginKey: new PluginKey('slashCommands'),
491
+ items: ({ query }) => filterSlashSections(sections, query).flatMap((section, at) => section.commands.map((command) => ({ ...command, section: at }))),
492
+ command: ({ editor, range, props }) => {
493
+ editor.chain().focus().deleteRange(range).run()
494
+ props.run(editor)
495
+ },
496
+ render: suggestionPopup<SlashRow>({
497
+ ariaLabel: 'Commands',
498
+ width: 'w-[300px]',
499
+ maxHeight: 'max-h-[400px]',
500
+ sections: (rows) => sections.map((section, at) => ({ label: section.label, items: rows.filter((row) => row.section === at) })),
501
+ itemKey: (row) => row.key,
502
+ row: (row) => row.row,
503
+ }),
504
+ }),
505
+ ]
506
+ },
507
+ })
package/src/editor.ts CHANGED
@@ -9,6 +9,35 @@
9
9
  */
10
10
  export { KeptSelection, SelectionToolbar, normalizeHref, type MarkId, type SelectionToolbarProps } from './SelectionToolbar'
11
11
  export { suggestionPopup, isSuggestionActive, isSuggestionOpen, type SuggestionPopupOptions } from './suggestionPopup'
12
+ export {
13
+ PersonMention,
14
+ UrgentPersonMention,
15
+ CaptionedReference,
16
+ ReferenceTrigger,
17
+ SlashCommands,
18
+ peopleMenu,
19
+ referenceMenu,
20
+ filterPeople,
21
+ urgentPubkeys,
22
+ filterReferences,
23
+ formatSection,
24
+ applyFormat,
25
+ typeTrigger,
26
+ filterSlashSections,
27
+ FORMATS,
28
+ type MentionPerson,
29
+ type PersonMentionOptions,
30
+ type CaptionedItem,
31
+ type CaptionedReferenceOptions,
32
+ type ReferenceTriggerOptions,
33
+ type ReferenceMenuOptions,
34
+ type SlashCommand,
35
+ type SlashSection,
36
+ type SlashCommandsOptions,
37
+ type FormatId,
38
+ type FormatDef,
39
+ type CodeFormat,
40
+ } from './ComposerTriggers'
12
41
  export {
13
42
  BlockId,
14
43
  UnknownBlock,
@@ -26,7 +26,7 @@ import { SCHEMA_VERSION, validateRegistry, type Registry, type RegistryEntry } f
26
26
  const root = process.cwd()
27
27
  const registry = buildRegistry({ root })
28
28
  /** Editor extensions: named like components by the catalogue, and not React components. */
29
- const EDITOR_EXTENSIONS = ['KeptSelection', 'BlockId', 'UnknownBlock', 'ReferenceNode', 'AttachmentNode']
29
+ const EDITOR_EXTENSIONS = ['KeptSelection', 'BlockId', 'UnknownBlock', 'ReferenceNode', 'AttachmentNode', 'PersonMention', 'UrgentPersonMention', 'CaptionedReference', 'ReferenceTrigger', 'SlashCommands']
30
30
  const entry = (name: string): RegistryEntry => {
31
31
  const found = registry.entries.find((candidate) => candidate.name === name)
32
32
  if (!found) throw new Error(`no entry for ${name}`)
@@ -48,19 +48,20 @@ describe('the registry builds', () => {
48
48
  expect(registry.entries.map((one) => one.name).sort()).toEqual(values.map((one) => one.name).sort())
49
49
  })
50
50
 
51
- it('counts 105 names over 65 files: 91 components, 13 helpers and 1 hook (NavTree joined on 2 October)', () => {
51
+ it('counts 120 names over 66 files: 96 components, 23 helpers and 1 hook (NavTree and the composer triggers joined on 2 October, CON-27)', () => {
52
52
  // The reconciliation GATES.md §24 explains. If this changes, that changes.
53
- // The five `EDITOR_EXTENSIONS` count as components by their names; they are
54
- // editor extensions, documented on SelectionToolbar's and BlockNodes' pages.
53
+ // The ten `EDITOR_EXTENSIONS` count as components by their names; they are
54
+ // editor extensions, documented on SelectionToolbar's, BlockNodes' and
55
+ // ComposerTriggers' pages.
55
56
  const kinds = registry.entries.reduce<Record<string, number>>((all, one) => ({ ...all, [one.kind]: (all[one.kind] ?? 0) + 1 }), {})
56
- expect(kinds).toEqual({ component: 91, helper: 13, hook: 1 })
57
- expect(new Set(registry.entries.map((one) => one.sourceFile)).size).toBe(65)
57
+ expect(kinds).toEqual({ component: 96, helper: 23, hook: 1 })
58
+ expect(new Set(registry.entries.map((one) => one.sourceFile)).size).toBe(66)
58
59
  })
59
60
 
60
61
  it('gives every entry a purpose, from its own page or from the comment above it', () => {
61
62
  expect(registry.entries.filter((one) => one.purpose.trim() === '')).toEqual([])
62
63
  expect(registry.entries.filter((one) => one.purposeFrom === 'page').length).toBe(62)
63
- expect(registry.entries.filter((one) => one.purposeFrom === 'comment').length).toBe(43)
64
+ expect(registry.entries.filter((one) => one.purposeFrom === 'comment').length).toBe(58)
64
65
  })
65
66
 
66
67
  it('takes a name with a page of its own from the page, and a name without one from the code', () => {
@@ -68,6 +68,7 @@ fork freely, owe nothing back, mention it on the package's ticket.
68
68
  | One window to find something and act on it, opened by a shortcut | **CommandPalette** — rows, forms and written answers, one level at a time |
69
69
  | A list that opens as you type in an editor — `/` for commands, `@` for people | **SuggestionMenu** — the editor keeps the caret and hands it the arrow keys; `suggestionPopup` from `@estiva-app/ui/editor` wires it to a Tiptap plugin |
70
70
  | Bold, italic and the like over selected text in an editor | **SelectionToolbar**, from `@estiva-app/ui/editor` — it follows the selection by itself |
71
+ | A composer's `@`, `!@`, `[` and `/` — mention a person, reference something, format or insert | **ComposerTriggers** — `PersonMention`, `UrgentPersonMention`, `CaptionedReference`, `ReferenceTrigger` and `SlashCommands` from `@estiva-app/ui/editor`; the app passes its people, its items and its own `/` rows |
71
72
  | An editor that saves a block document and must keep its block ids | **BlockNodes** — `BlockId`, `UnknownBlock`, `ReferenceNode` and `AttachmentNode` from `@estiva-app/ui/editor`, beside StarterKit and TableKit |
72
73
  | Anything with a title, body and footer | **DialogShell** |
73
74
  | "Are you sure?" | **ConfirmDialog** |