@estiva-app/ui 0.87.0 → 0.87.1
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/DocumentEditor.d.ts.map +1 -1
- package/dist/editor.js +2 -1
- package/dist/editor.js.map +3 -3
- package/package.json +1 -1
- package/registry.json +1 -1
- package/src/DocumentEditor.test.tsx +28 -0
- package/src/DocumentEditor.tsx +4 -2
package/package.json
CHANGED
package/registry.json
CHANGED
|
@@ -134,6 +134,34 @@ describe('saving', () => {
|
|
|
134
134
|
expect(editorOf().getText()).toBe('First line kept')
|
|
135
135
|
})
|
|
136
136
|
|
|
137
|
+
it('closed while its save is out, a refused save is not sent again with the same text', async () => {
|
|
138
|
+
let answer: (ok: boolean) => void = () => {}
|
|
139
|
+
const onCommit = vi.fn<DocumentEditorProps['onCommit']>(() => new Promise<boolean>((resolve) => (answer = resolve)))
|
|
140
|
+
const { unmount } = render(<Doc onCommit={onCommit} />)
|
|
141
|
+
await type(' and more')
|
|
142
|
+
await leave()
|
|
143
|
+
expect(onCommit).toHaveBeenCalledTimes(1)
|
|
144
|
+
// The page goes while the relay has not answered: closing asks to save the same text again.
|
|
145
|
+
unmount()
|
|
146
|
+
await act(async () => answer(false))
|
|
147
|
+
await settle()
|
|
148
|
+
expect(onCommit).toHaveBeenCalledTimes(1)
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
it('a change made while a save is out is saved next', async () => {
|
|
152
|
+
let answer: (ok: boolean) => void = () => {}
|
|
153
|
+
const onCommit = vi.fn<DocumentEditorProps['onCommit']>(() => new Promise<boolean>((resolve) => (answer = resolve)))
|
|
154
|
+
render(<Doc onCommit={onCommit} />)
|
|
155
|
+
await type(' and more')
|
|
156
|
+
await leave()
|
|
157
|
+
await type('!')
|
|
158
|
+
await leave()
|
|
159
|
+
await act(async () => answer(true))
|
|
160
|
+
await settle()
|
|
161
|
+
expect(onCommit).toHaveBeenCalledTimes(2)
|
|
162
|
+
expect(saved(onCommit.mock.calls[1][0])).toEqual([{ id: 'a1', runs: [{ text: 'First line and more!', marks: [] }] }])
|
|
163
|
+
})
|
|
164
|
+
|
|
137
165
|
it('Escape leaves, and so saves', async () => {
|
|
138
166
|
const onCommit = vi.fn(async () => true)
|
|
139
167
|
render(<Doc onCommit={onCommit} />)
|
package/src/DocumentEditor.tsx
CHANGED
|
@@ -283,8 +283,10 @@ export function DocumentEditor({
|
|
|
283
283
|
setSaving(false)
|
|
284
284
|
if (again.current) {
|
|
285
285
|
again.current = false
|
|
286
|
-
// After an ending it is held for after the tap, and a save would only be refused.
|
|
287
|
-
|
|
286
|
+
// After an ending it is held for after the tap, and a save would only be refused. Only a change: leaving
|
|
287
|
+
// while a blur's save is out asks again for the same text, and a refused one would be sent and said twice.
|
|
288
|
+
const waiting = typed.current
|
|
289
|
+
if (!ended() && waiting && latest.current.codec.write(waiting).value !== next.value) void latestSave.current(waiting)
|
|
288
290
|
}
|
|
289
291
|
}
|
|
290
292
|
},
|