@estiva-app/ui 0.88.0 → 0.89.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@estiva-app/ui",
3
- "version": "0.88.0",
3
+ "version": "0.89.0",
4
4
  "description": "Estiva's design tokens (the contract) and a small set of primitives (a convenience) for every Estiva app.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -133,8 +133,8 @@
133
133
  },
134
134
  "devDependencies": {
135
135
  "@eslint/js": "^10.0.1",
136
- "@estiva-app/conversation": "^0.17.0",
137
- "@estiva-app/protocol": "^0.41.0",
136
+ "@estiva-app/conversation": "^0.22.0",
137
+ "@estiva-app/protocol": "^0.45.0",
138
138
  "@storybook/addon-a11y": "^10.6.0",
139
139
  "@storybook/addon-docs": "^10.5.10",
140
140
  "@storybook/addon-vitest": "^10.6.0",
package/registry.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "kind": "package",
5
5
  "repo": "estiva-ui",
6
6
  "package": "@estiva-app/ui",
7
- "packageVersion": "0.88.0",
7
+ "packageVersion": "0.89.0",
8
8
  "exports": 210,
9
9
  "typeExports": 211,
10
10
  "files": null
@@ -9,6 +9,7 @@ import { Checkbox, type CheckboxProps } from './Checkbox'
9
9
  import { calloutLook } from './RichText'
10
10
  import { placeOf, type LinkPlace } from './LinkPlaces'
11
11
  import { referenceMenuClick } from './ReferenceMenu'
12
+ import { isSuggestionOpen } from './suggestionPopup'
12
13
 
13
14
  /*
14
15
  * The four nodes an editor of a block document needs that a stock schema does
@@ -760,6 +761,8 @@ export const Checklist = Extension.create({
760
761
  addKeyboardShortcuts() {
761
762
  return {
762
763
  Enter: () => {
764
+ // An open `/`, `@` or `[` list picks its row: running first, this split the line under it and left the `/` behind (LFB-3).
765
+ if (isSuggestionOpen()) return false
763
766
  const { state } = this.editor
764
767
  const item = itemAtCaret(state)
765
768
  const { $from, empty } = state.selection
@@ -12,6 +12,8 @@ import { EditorContent, useEditor } from '@tiptap/react'
12
12
  import StarterKit from '@tiptap/starter-kit'
13
13
  import {
14
14
  CaptionedReference,
15
+ DOCUMENT_FORMATS,
16
+ FORMATS,
15
17
  PersonMention,
16
18
  ReferenceTrigger,
17
19
  SlashCommands,
@@ -593,3 +595,84 @@ describe('/ in a block editor — RIC-19', () => {
593
595
  expect(options()).toEqual(['Text', 'Heading#', 'Subheading##', 'Quote>', 'Code```', 'Bulleted list-', 'Numbered list1.'])
594
596
  })
595
597
  })
598
+
599
+ describe('/ mid-line, in every kind of line — LFB-3', () => {
600
+ function BlockComposer() {
601
+ const made = useEditor({ extensions: [StarterKit, Checklist, Callout, SlashCommands.configure({ sections: [formatSection('block')] })] })
602
+ editor = made
603
+ return <EditorContent editor={made} />
604
+ }
605
+
606
+ const words = (text: string) => [{ type: 'paragraph', content: [{ type: 'text', text }] }]
607
+ const item = (checked?: boolean) => ({ type: 'listItem', ...(checked === undefined ? {} : { attrs: { checked } }), content: words('Some words here') })
608
+ const LINES = {
609
+ paragraph: words('Some words here')[0],
610
+ heading: { type: 'heading', attrs: { level: 1 }, content: [{ type: 'text', text: 'Some words here' }] },
611
+ quote: { type: 'blockquote', content: words('Some words here') },
612
+ bullet: { type: 'bulletList', content: [item()] },
613
+ numbered: { type: 'orderedList', content: [item()] },
614
+ checklist: { type: 'bulletList', content: [item(false)] },
615
+ }
616
+ // Each line as `line()` reads it before a pick, and the row it already is: picking that one rightly leaves it as it was.
617
+ const START = { paragraph: 'paragraph', heading: 'heading:1', quote: 'paragraph<blockquote', bullet: 'paragraph<listItem<bulletList', numbered: 'paragraph<listItem<orderedList', checklist: 'paragraph<listItem☐<bulletList' }
618
+ const ALREADY: Record<string, string> = { paragraph: 'paragraph', heading: 'heading', checklist: 'checklist' }
619
+
620
+ /** The line `kind` between two others, the caret after "Some words", then ` /<query>` typed and the first row picked with Enter. */
621
+ async function pick(kind: keyof typeof LINES, query: string) {
622
+ await act(async () => {
623
+ editor!.commands.setContent({ type: 'doc', content: [...words('Before'), LINES[kind], ...words('After')] })
624
+ let at = 0
625
+ editor!.state.doc.descendants((node, pos) => {
626
+ if (node.isText && node.text === 'Some words here') at = pos + 'Some words'.length
627
+ })
628
+ editor!.chain().focus().setTextSelection(at).run()
629
+ })
630
+ await type(` /${query}`)
631
+ await press('Enter')
632
+ }
633
+
634
+ /** The caret's line: its blocks from the inside out, as `paragraph<listItem☐<bulletList`, a callout with its tone. */
635
+ function line() {
636
+ const { $from } = editor!.state.selection
637
+ const blocks: string[] = []
638
+ for (let depth = $from.depth; depth > 0; depth--) {
639
+ const node = $from.node(depth)
640
+ const tone = node.type.name === 'blockquote' && node.attrs.tone ? `:${node.attrs.tone}` : ''
641
+ blocks.push(`${node.type.name}${node.attrs.level ? `:${node.attrs.level}` : ''}${typeof node.attrs.checked === 'boolean' ? '☐' : ''}${tone}`)
642
+ }
643
+ return { blocks: blocks.join('<'), text: $from.parent.textContent, caret: $from.parentOffset }
644
+ }
645
+
646
+ it('turns a bulleted, numbered or checklist line into a quote, a note or a warning, out of its list', async () => {
647
+ render(<BlockComposer />)
648
+ for (const kind of ['bullet', 'numbered', 'checklist'] as const) {
649
+ for (const [query, blocks] of [['quote', 'paragraph<blockquote'], ['note', 'paragraph<blockquote:note'], ['warning', 'paragraph<blockquote:warning']]) {
650
+ await pick(kind, query)
651
+ expect({ kind, query, ...line() }).toEqual({ kind, query, blocks, text: 'Some words here', caret: 11 })
652
+ }
653
+ }
654
+ })
655
+
656
+ it('keeps a quoted list line quoted when Quote is picked on it', async () => {
657
+ render(<BlockComposer />)
658
+ await act(async () => {
659
+ editor!.commands.setContent({ type: 'doc', content: [{ type: 'blockquote', content: [{ type: 'bulletList', content: [item()] }] }] })
660
+ editor!.chain().focus().setTextSelection(1 + 1 + 1 + 1 + 'Some words'.length).run()
661
+ })
662
+ await type(' /quote')
663
+ await press('Enter')
664
+ expect(line()).toEqual({ blocks: 'paragraph<blockquote', text: 'Some words here', caret: 11 })
665
+ })
666
+
667
+ it('changes the line with every Format row in every kind of line, and leaves no "/" and the caret where it was', async () => {
668
+ render(<BlockComposer />)
669
+ for (const kind of Object.keys(LINES) as (keyof typeof LINES)[]) {
670
+ for (const format of [...FORMATS, ...DOCUMENT_FORMATS]) {
671
+ await pick(kind, format.id)
672
+ const after = line()
673
+ expect({ kind, format: format.id, text: after.text, caret: after.caret }).toEqual({ kind, format: format.id, text: 'Some words here', caret: 11 })
674
+ if (ALREADY[kind] !== format.id) expect({ kind, format: format.id, blocks: after.blocks }).not.toEqual({ kind, format: format.id, blocks: START[kind] })
675
+ }
676
+ }
677
+ })
678
+ })
@@ -583,17 +583,31 @@ export type CodeFormat = 'inline' | 'block'
583
583
  * nothing changed, not that anything failed.
584
584
  */
585
585
  export function applyFormat(editor: Editor, id: FormatId, code: CodeFormat = 'inline'): boolean {
586
- const chain = editor.chain().focus()
587
586
  /*
588
587
  The node's own command, called by name: StarterKit's extensions declare
589
588
  them, and this package builds without StarterKit. Its own command, rather
590
589
  than the core one it wraps, because a list's runs with the app's options
591
590
  (`keepMarks`, `itemTypeName`). An editor without that node changes nothing.
591
+ A chain per call: a chain holds the state it was made from, and a quote
592
+ first takes its line out of a list.
592
593
  */
593
594
  const run = (command: string, ...args: unknown[]): boolean => {
595
+ const chain = editor.chain().focus()
594
596
  const named = (chain as unknown as Record<string, ((...a: unknown[]) => { run: () => boolean }) | undefined>)[command]
595
597
  return named ? named(...args).run() : false
596
598
  }
599
+ /*
600
+ A list item's first line cannot be wrapped where it is, so Quote, Note and
601
+ Warning did nothing in a bulleted line once the `/` was gone (LFB-3). The
602
+ line leaves its list first, as Heading's and Code's already do — only in
603
+ an editor that has a quote to make. Whether it left one.
604
+ */
605
+ const leaveList = (): boolean => {
606
+ if (!editor.schema.nodes.blockquote) return false
607
+ let left = false
608
+ while (editor.isActive('listItem') && run('liftListItem', 'listItem')) left = true
609
+ return left
610
+ }
597
611
  switch (id) {
598
612
  case 'paragraph':
599
613
  return run('setParagraph')
@@ -602,6 +616,8 @@ export function applyFormat(editor: Editor, id: FormatId, code: CodeFormat = 'in
602
616
  case 'subheading':
603
617
  return run('setHeading', { level: 2 })
604
618
  case 'quote':
619
+ // A list inside a quote: the line, out of its list, is already quoted, and toggling would unquote it.
620
+ if (leaveList() && editor.isActive('blockquote')) return true
605
621
  return run('toggleBlockquote')
606
622
  case 'bulletList':
607
623
  return run('toggleBulletList')
@@ -618,6 +634,7 @@ export function applyFormat(editor: Editor, id: FormatId, code: CodeFormat = 'in
618
634
  }
619
635
  case 'note':
620
636
  case 'warning': {
637
+ leaveList()
621
638
  if (!editor.isActive('blockquote') && !run('toggleBlockquote')) return false
622
639
  return editor.chain().updateAttributes('blockquote', { tone: id }).run()
623
640
  }
@@ -1,6 +1,9 @@
1
1
  /**
2
2
  * archivedLine, the one sentence every app shows on an archived file (PEEKM-2).
3
+ * It lives in @estiva-app/conversation since PEEKM-8, so the agent prints the
4
+ * same words; this package hands it on unchanged.
3
5
  */
6
+ import { archivedLine as sentence } from '@estiva-app/conversation'
4
7
 
5
8
  /**
6
9
  * The line in the comment box's place on an archived file (CommentBox's
@@ -8,17 +11,17 @@
8
11
  *
9
12
  * A file archived itself says so; one archived with a file above it names the
10
13
  * closest archived one by its kind — "Unarchive the page to comment." — so a
11
- * person unarchives the right thing, and once it is unarchived the next one up
12
- * is named. Which file that is comes from interop: `archive.with` is its
13
- * address, and the app reads its noun.
14
+ * person unarchives the right thing. `options.in` names where to unarchive, for
15
+ * an app with no Unarchive of its own; `options.to` is what waits, "comment"
16
+ * unless said.
17
+ *
18
+ * Typed here rather than inferred, so this package's types never point at
19
+ * @estiva-app/conversation (bundled, not a dependency of an app's).
14
20
  *
15
21
  * why: https://github.com/estiva-app/estiva-docs/blob/main/decisions/a-file-is-archived-with-the-closest-archived-file-above-it.md
16
22
  */
17
- export function archivedLine(archive: { with?: string } | undefined, noun?: string): string | undefined {
18
- if (!archive) return undefined
19
- if (!archive.with) return 'Archived. Unarchive it to comment.'
20
- // A noun arrives as the manifest wrote it; a Folder is a proper noun in every
21
- // app's copy. With no noun, Peek's ArchivedNotice word.
22
- const word = noun?.trim()
23
- return `Unarchive the ${word === 'folder' ? 'Folder' : word || 'parent'} to comment.`
24
- }
23
+ export const archivedLine: (
24
+ archive: { with?: string } | undefined,
25
+ noun?: string,
26
+ options?: { in?: string; to?: string },
27
+ ) => string | undefined = sentence
@@ -1,34 +0,0 @@
1
- /**
2
- * The line in the comment box's place on an archived file names what to
3
- * unarchive: the file itself, or the closest archived one above it by its kind
4
- * (PEEKM-2, record a-file-is-archived-with-the-closest-archived-file-above-it).
5
- */
6
- import { describe, expect, it } from 'vitest'
7
- import { archivedLine } from './archivedLine'
8
-
9
- const ABOVE = '30023:aaaa:plan'
10
-
11
- describe('archivedLine', () => {
12
- it('says nothing for a file that is not archived', () => {
13
- expect(archivedLine(undefined, 'page')).toBeUndefined()
14
- })
15
-
16
- it('tells a person to unarchive the file itself when it is archived itself', () => {
17
- expect(archivedLine({}, 'page')).toBe('Archived. Unarchive it to comment.')
18
- })
19
-
20
- it('names the closest archived file above by its kind', () => {
21
- expect(archivedLine({ with: ABOVE }, 'page')).toBe('Unarchive the page to comment.')
22
- expect(archivedLine({ with: ABOVE }, 'project')).toBe('Unarchive the project to comment.')
23
- expect(archivedLine({ with: ABOVE }, 'PDF')).toBe('Unarchive the PDF to comment.')
24
- })
25
-
26
- it('writes Folder as a proper noun', () => {
27
- expect(archivedLine({ with: ABOVE }, 'folder')).toBe('Unarchive the Folder to comment.')
28
- })
29
-
30
- it('still says what to do when the app has no noun for what is above', () => {
31
- expect(archivedLine({ with: ABOVE })).toBe('Unarchive the parent to comment.')
32
- expect(archivedLine({ with: ABOVE }, ' ')).toBe('Unarchive the parent to comment.')
33
- })
34
- })