@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@estiva-app/ui",
3
- "version": "0.87.0",
3
+ "version": "0.87.1",
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",
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.87.0",
7
+ "packageVersion": "0.87.1",
8
8
  "exports": 210,
9
9
  "typeExports": 211,
10
10
  "files": null
@@ -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} />)
@@ -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
- if (!ended()) void latestSave.current(typed.current)
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
  },