@estiva-app/ui 0.87.1 → 0.88.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/dist/CommentBox.d.ts +8 -1
- package/dist/CommentBox.d.ts.map +1 -1
- package/dist/editor.js +31 -16
- package/dist/editor.js.map +2 -2
- package/package.json +1 -1
- package/registry.json +1 -1
- package/src/CommentBox.mdx +3 -3
- package/src/CommentBox.test.tsx +65 -3
- package/src/CommentBox.tsx +40 -21
package/package.json
CHANGED
package/registry.json
CHANGED
package/src/CommentBox.mdx
CHANGED
|
@@ -13,8 +13,8 @@ The one box every app writes a comment, a reply and a line of a conversation in:
|
|
|
13
13
|
|
|
14
14
|
- **Writing anything that is sent**, in every app: a comment, a reply, a line in a conversation. The same box writes all of them.
|
|
15
15
|
- `showsAtOnce` when the app shows a send before the relay answers: the box empties at once, and a refusal puts the words back. Without it the box holds the words, shut, until the answer.
|
|
16
|
-
- `edit` to change something already sent: the same box with Cancel and Save, its keys on the left, and the same selection strip over selected words.
|
|
17
|
-
- `upload` to offer files: the paperclip, `/` → Upload, a pasted picture and a dropped file.
|
|
16
|
+
- `edit` to change something already sent: the same box with Cancel and Save, its keys on the left, and the same selection strip over selected words. Its files can be taken off, and with `upload` and `edit.writesFiles` (the app's save writes them) more added. An app that closes the box as Save is pressed and reopens it on a refusal passes `edit.refused`, which is said under the box as it opens.
|
|
17
|
+
- `upload` to offer files: the paperclip, `/` → Upload, a pasted picture and a dropped file. The edit box has no paperclip, since it shows only its keys; the other three work there too.
|
|
18
18
|
- `under` to show, while something is written, the one card it will be sent with (✕ takes it off) and the live part of each block link, drawn as the app draws them under a sent message. An edit box shows the card and no part.
|
|
19
19
|
- `closed` where nothing can be written (archived, signed out): a line saying why, in the box's place. No greyed box.
|
|
20
20
|
- `marked` when the app has its own reason for the bar down the text, besides an urgent mention, which always draws it.
|
|
@@ -63,7 +63,7 @@ const draft = composerDraft(createDraftStore(localStorage), draftKeys.thread(roo
|
|
|
63
63
|
- **It speaks the editor's document.** The text a document sends, and the document an edit or a draft opens with, are `@estiva-app/conversation`'s: `composerText`, `composerDocument`, `composerDraft`. Never write marker text here.
|
|
64
64
|
- **`send` answers.** Resolve `{ accepted: false, reason }` and the words come back with "Not sent: *reason*". A thrown send is a refusal too.
|
|
65
65
|
- **`label` is required**: the editor's accessible name.
|
|
66
|
-
- **`insert` is the app's Insert rows**, after the shared Format section: `commentBoxRows` and the app's own. An edit drops
|
|
66
|
+
- **`insert` is the app's Insert rows**, after the shared Format section: `commentBoxRows` and the app's own. An edit drops Urgent itself (an edit makes nobody urgent); with no `upload` there is no Upload (`commentBoxRows.file` is that row).
|
|
67
67
|
- **Give the box a `key` per destination.** The editor, the rows and `code` are made once, as the box opens; a new thread is a new box.
|
|
68
68
|
- A send shown at once and refused after its box went away writes the words into its draft instead.
|
|
69
69
|
- **`under.read` is the app's reading of the draft**: `@estiva-app/conversation`'s `boxReadOf(body, context)` says which file gets the card and which parts show; the app adds its own view of each. Call `under.changed`'s listener when what a link names comes back. `send`'s third argument is `{ card }`, the card still shown, which the app writes with `embedsToSend` (or `embedsToEdit` for `onSave`).
|
package/src/CommentBox.test.tsx
CHANGED
|
@@ -192,15 +192,77 @@ describe('editing', () => {
|
|
|
192
192
|
expect(editorOf().getText()).toBe('Said before')
|
|
193
193
|
})
|
|
194
194
|
|
|
195
|
-
it('/ offers
|
|
196
|
-
render(<Box upload={async () => ({ accepted: true, value: 1 })} edit={{ body, onSave: async () => ({ accepted: true }), onCancel: () => {} }} />)
|
|
195
|
+
it('/ offers Upload and no Urgent in an edit whose save writes files', async () => {
|
|
196
|
+
render(<Box upload={async () => ({ accepted: true, value: 1 })} edit={{ body, writesFiles: true, onSave: async () => ({ accepted: true }), onCancel: () => {} }} />)
|
|
197
197
|
await type(' /')
|
|
198
198
|
const rows = within(screen.getByRole('listbox')).getAllByRole('option').map((o) => o.textContent ?? '')
|
|
199
199
|
expect(rows.some((r) => r.startsWith('Mention'))).toBe(true)
|
|
200
|
-
expect(rows.some((r) => r.startsWith('Upload')
|
|
200
|
+
expect(rows.some((r) => r.startsWith('Upload'))).toBe(true)
|
|
201
|
+
expect(rows.some((r) => r.startsWith('Urgent'))).toBe(false)
|
|
201
202
|
// Closed here: the editor is destroyed on a timer, and a list it closes then would hold the next test's Enter.
|
|
202
203
|
await press('Escape')
|
|
203
204
|
})
|
|
205
|
+
|
|
206
|
+
it('an edit whose save does not write files offers no Upload and takes no dropped file, so none is lost', async () => {
|
|
207
|
+
render(<Box upload={async () => ({ accepted: true, value: 1 })} edit={{ body, onSave: async () => ({ accepted: true }), onCancel: () => {} }} />)
|
|
208
|
+
expect(document.querySelector('input[type=file]')).toBeNull()
|
|
209
|
+
// Dropped beside Save, so it reaches the box's own drop and not the editor's.
|
|
210
|
+
await act(async () => {
|
|
211
|
+
fireEvent.drop(screen.getByRole('button', { name: 'Save' }), { dataTransfer: { files: [new File(['x'], 'shot.png', { type: 'image/png' })] } })
|
|
212
|
+
})
|
|
213
|
+
expect(screen.queryByText('shot.png')).toBeNull()
|
|
214
|
+
await type(' /')
|
|
215
|
+
const rows = within(screen.getByRole('listbox')).getAllByRole('option').map((o) => o.textContent ?? '')
|
|
216
|
+
expect(rows.some((r) => r.startsWith('Upload'))).toBe(false)
|
|
217
|
+
await press('Escape')
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
it('a file added while editing uploads, Save waits for it, and it is saved with the files already there', async () => {
|
|
221
|
+
const uploaded = later<UploadAnswer>()
|
|
222
|
+
const onSave = vi.fn<CommentBoxEdit['onSave']>(async () => ({ accepted: true }))
|
|
223
|
+
const files = [{ id: 'old', name: 'old.png', state: 'ready' as const, value: 'old-record' }]
|
|
224
|
+
render(<Box upload={() => uploaded.promise} edit={{ body, files, writesFiles: true, onSave, onCancel: () => {} }} />)
|
|
225
|
+
expect(screen.queryByRole('button', { name: 'Attach a file' })).toBeNull()
|
|
226
|
+
const input = document.querySelector('input[type=file]') as HTMLInputElement
|
|
227
|
+
expect(input).not.toBeNull()
|
|
228
|
+
await act(async () => {
|
|
229
|
+
fireEvent.change(input, { target: { files: [new File(['x'], 'shot.png', { type: 'image/png' })] } })
|
|
230
|
+
})
|
|
231
|
+
expect(screen.getByText('Uploading… Save waits for the file.')).toBeTruthy()
|
|
232
|
+
await press('Enter')
|
|
233
|
+
expect(onSave).not.toHaveBeenCalled()
|
|
234
|
+
uploaded.answer({ accepted: true, value: 'new-record' })
|
|
235
|
+
await settle()
|
|
236
|
+
await press('Enter')
|
|
237
|
+
expect(onSave).toHaveBeenCalledTimes(1)
|
|
238
|
+
expect(onSave.mock.calls[0][1]).toMatchObject([{ value: 'old-record' }, { name: 'shot.png', state: 'ready', value: 'new-record' }])
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
it('a file that did not upload holds Save until its ✕ takes it off', async () => {
|
|
242
|
+
const onSave = vi.fn<CommentBoxEdit['onSave']>(async () => ({ accepted: true }))
|
|
243
|
+
render(<Box upload={async () => ({ accepted: false, reason: 'too large' })} edit={{ body, writesFiles: true, onSave, onCancel: () => {} }} />)
|
|
244
|
+
const input = document.querySelector('input[type=file]') as HTMLInputElement
|
|
245
|
+
expect(input).not.toBeNull()
|
|
246
|
+
await act(async () => {
|
|
247
|
+
fireEvent.change(input, { target: { files: [new File(['x'], 'big.mov', { type: 'video/quicktime' })] } })
|
|
248
|
+
})
|
|
249
|
+
await settle()
|
|
250
|
+
expect(screen.getByText('Remove the file that did not upload to save.')).toBeTruthy()
|
|
251
|
+
expect((screen.getByRole('button', { name: 'Save' }) as HTMLButtonElement).disabled).toBe(true)
|
|
252
|
+
await press('Enter')
|
|
253
|
+
expect(onSave).not.toHaveBeenCalled()
|
|
254
|
+
await act(async () => {
|
|
255
|
+
fireEvent.click(screen.getByRole('button', { name: 'Remove big.mov' }))
|
|
256
|
+
})
|
|
257
|
+
await press('Enter')
|
|
258
|
+
expect(onSave).toHaveBeenCalledTimes(1)
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
it('an edit the app reopens after a refusal says why under it as it opens', () => {
|
|
262
|
+
render(<Box edit={{ body, refused: 'rate-limited', onSave: async () => ({ accepted: true }), onCancel: () => {} }} />)
|
|
263
|
+
expect(screen.getByText('Not saved: rate-limited. Your changes are still in the box.')).toBeTruthy()
|
|
264
|
+
expect(editorOf().getText()).toBe('Said before')
|
|
265
|
+
})
|
|
204
266
|
})
|
|
205
267
|
|
|
206
268
|
describe('drafts', () => {
|
package/src/CommentBox.tsx
CHANGED
|
@@ -80,8 +80,15 @@ export interface CommentBoxDraft {
|
|
|
80
80
|
export interface CommentBoxEdit {
|
|
81
81
|
/** What it says now, as `composerDocument` opens it. */
|
|
82
82
|
body: JSONContent
|
|
83
|
-
/** Its files, which can be taken off;
|
|
83
|
+
/** Its files, which can be taken off; with `upload` and `writesFiles`, more can be added by `/` → Upload, a paste or a drop. A box reopened after a refusal is given the files that save carried. */
|
|
84
84
|
files?: BoxFile[]
|
|
85
|
+
/**
|
|
86
|
+
* The app's `onSave` writes the files it is handed, so a file can be added while editing (with `upload`).
|
|
87
|
+
* Opt-in, so an app whose save drops them never offers it: a file added and silently lost.
|
|
88
|
+
*/
|
|
89
|
+
writesFiles?: boolean
|
|
90
|
+
/** Why the relay refused this edit, when the app reopens a box it closed at once: said under it as it opens. Read as the box opens, so a reopen is a new box (a new `key`). */
|
|
91
|
+
refused?: string
|
|
85
92
|
onCancel: () => void
|
|
86
93
|
/** Save; the box holds the words until the answer, and a refusal is said under it. */
|
|
87
94
|
onSave: (body: JSONContent, files: BoxFile[], under: BoxSentUnder) => Promise<SendAnswer>
|
|
@@ -408,7 +415,7 @@ export function CommentBox({
|
|
|
408
415
|
}: CommentBoxProps) {
|
|
409
416
|
const [files, setFiles] = useState<BoxFile[]>(edit?.files ?? [])
|
|
410
417
|
const [sending, setSending] = useState(false)
|
|
411
|
-
const [refused, setRefused] = useState<string | null>(null)
|
|
418
|
+
const [refused, setRefused] = useState<string | null>(edit?.refused ?? null)
|
|
412
419
|
// What shows under the box, and what ✕ took off.
|
|
413
420
|
const [reading, setReading] = useState<BoxUnderRead | undefined>(undefined)
|
|
414
421
|
const [removed, setRemoved] = useState<ReadonlySet<string>>(() => new Set())
|
|
@@ -421,7 +428,7 @@ export function CommentBox({
|
|
|
421
428
|
|
|
422
429
|
const attachFiles = useCallback((picked: File[]): boolean => {
|
|
423
430
|
const uploadOne = latest.current.upload
|
|
424
|
-
if (!uploadOne || latest.current.edit) return false
|
|
431
|
+
if (!uploadOne || (latest.current.edit && !latest.current.edit.writesFiles)) return false
|
|
425
432
|
for (const file of picked) {
|
|
426
433
|
fileCount += 1
|
|
427
434
|
const id = `file-${fileCount}`
|
|
@@ -437,8 +444,9 @@ export function CommentBox({
|
|
|
437
444
|
return true
|
|
438
445
|
}, [])
|
|
439
446
|
|
|
440
|
-
// An edit
|
|
441
|
-
const
|
|
447
|
+
// An edit can add a file, in every app (Miky, 26 Oct, PEEKM-4) whose save writes it, but makes nobody urgent (CON-24); no upload, no File.
|
|
448
|
+
const takesFiles = !!upload && (!edit || !!edit.writesFiles)
|
|
449
|
+
const rows = insert.filter((c) => !(!takesFiles && c.key === commentBoxRows.file.key) && !(edit && c.key === commentBoxRows.urgent.key))
|
|
442
450
|
const { editor, hold } = useBoxEditor({ extensions, referenceView: referenceView ?? null }, edit?.body ?? draft?.read(), {
|
|
443
451
|
editable: !closed,
|
|
444
452
|
editorProps: { attributes: { class: COMPOSE_EDITOR_CLASSES, role: 'textbox', 'aria-multiline': 'true', 'aria-label': label } },
|
|
@@ -529,11 +537,11 @@ export function CommentBox({
|
|
|
529
537
|
// `/` → File asks for a file the way the paperclip does.
|
|
530
538
|
useEffect(() => {
|
|
531
539
|
const box = root.current
|
|
532
|
-
if (!box || !
|
|
540
|
+
if (!box || !takesFiles) return
|
|
533
541
|
const ask = () => picker.current?.click()
|
|
534
542
|
box.addEventListener(ATTACH_EVENT, ask)
|
|
535
543
|
return () => box.removeEventListener(ATTACH_EVENT, ask)
|
|
536
|
-
}, [
|
|
544
|
+
}, [takesFiles])
|
|
537
545
|
|
|
538
546
|
const uploading = files.some((f) => f.state === 'uploading')
|
|
539
547
|
// A file that did not upload holds Send until its ✕ takes it off, so it is never sent without it unnoticed.
|
|
@@ -591,7 +599,7 @@ export function CommentBox({
|
|
|
591
599
|
)
|
|
592
600
|
|
|
593
601
|
save.current = () => {
|
|
594
|
-
if (!editor || !edit || sending || uploading) return true
|
|
602
|
+
if (!editor || !edit || sending || uploading || failed > 0) return true
|
|
595
603
|
setRefused(null)
|
|
596
604
|
setSending(true)
|
|
597
605
|
const body = editor.getJSON()
|
|
@@ -662,9 +670,28 @@ export function CommentBox({
|
|
|
662
670
|
</FieldLine>
|
|
663
671
|
)
|
|
664
672
|
|
|
673
|
+
const onDrop = (event: DragEvent<HTMLDivElement>) => {
|
|
674
|
+
const dropped = Array.from(event.dataTransfer?.files ?? [])
|
|
675
|
+
if (dropped.length === 0 || !takesFiles) return
|
|
676
|
+
event.preventDefault()
|
|
677
|
+
attachFiles(dropped)
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
const fileLines = (
|
|
681
|
+
<>
|
|
682
|
+
{uploading && !sending && <FieldLine>Uploading… {edit ? 'Save' : 'Send'} waits for the file.</FieldLine>}
|
|
683
|
+
{failed > 0 && !uploading && !sending && (
|
|
684
|
+
<FieldLine>
|
|
685
|
+
{failed === 1 ? 'Remove the file that did not upload' : 'Remove the files that did not upload'} to {edit ? 'save' : 'send'}.
|
|
686
|
+
</FieldLine>
|
|
687
|
+
)}
|
|
688
|
+
</>
|
|
689
|
+
)
|
|
690
|
+
|
|
665
691
|
if (edit) {
|
|
692
|
+
// No paperclip: the edit box shows only its keys (Decided 2026-10-17); a file comes by `/` → Upload, a paste or a drop.
|
|
666
693
|
return (
|
|
667
|
-
<div className={cn('flex flex-col gap-1', className)}>
|
|
694
|
+
<div ref={root} className={cn('flex flex-col gap-1', className)} onDragOver={takesFiles ? (e) => e.preventDefault() : undefined} onDrop={onDrop}>
|
|
668
695
|
<BoxFrame
|
|
669
696
|
editor={editor}
|
|
670
697
|
marked={marking}
|
|
@@ -681,7 +708,7 @@ export function CommentBox({
|
|
|
681
708
|
<Button variant="outlined" size="small" onClick={edit.onCancel}>
|
|
682
709
|
Cancel
|
|
683
710
|
</Button>
|
|
684
|
-
<Button variant="primary" size="small" disabled={uploading || sending} onClick={() => save.current()}>
|
|
711
|
+
<Button variant="primary" size="small" disabled={uploading || failed > 0 || sending} onClick={() => save.current()}>
|
|
685
712
|
Save
|
|
686
713
|
</Button>
|
|
687
714
|
</div>
|
|
@@ -689,19 +716,14 @@ export function CommentBox({
|
|
|
689
716
|
}
|
|
690
717
|
/>
|
|
691
718
|
{underBox}
|
|
719
|
+
{takesFiles && <FilePicker ref={picker} multiple accept={accept} onPick={attachFiles} />}
|
|
692
720
|
{sending && <FieldLine>Saving…</FieldLine>}
|
|
721
|
+
{fileLines}
|
|
693
722
|
{refusedLine}
|
|
694
723
|
</div>
|
|
695
724
|
)
|
|
696
725
|
}
|
|
697
726
|
|
|
698
|
-
const onDrop = (event: DragEvent<HTMLDivElement>) => {
|
|
699
|
-
const dropped = Array.from(event.dataTransfer?.files ?? [])
|
|
700
|
-
if (dropped.length === 0 || !upload) return
|
|
701
|
-
event.preventDefault()
|
|
702
|
-
attachFiles(dropped)
|
|
703
|
-
}
|
|
704
|
-
|
|
705
727
|
return (
|
|
706
728
|
<div ref={root} className={cn('flex flex-col gap-1', className)} onDragOver={upload ? (e) => e.preventDefault() : undefined} onDrop={onDrop}>
|
|
707
729
|
<SendBox
|
|
@@ -725,10 +747,7 @@ export function CommentBox({
|
|
|
725
747
|
{underBox}
|
|
726
748
|
{upload && <FilePicker ref={picker} multiple accept={accept} onPick={attachFiles} />}
|
|
727
749
|
{sending && <FieldLine>Sending…</FieldLine>}
|
|
728
|
-
{
|
|
729
|
-
{failed > 0 && !uploading && !sending && (
|
|
730
|
-
<FieldLine>{failed === 1 ? 'Remove the file that did not upload to send.' : 'Remove the files that did not upload to send.'}</FieldLine>
|
|
731
|
-
)}
|
|
750
|
+
{fileLines}
|
|
732
751
|
{refusedLine}
|
|
733
752
|
</div>
|
|
734
753
|
)
|