Files
faunosteo/apps/app/src/editor/state/editorBase.ts
T
bchanot 99b669bf8f feat(editor): header history, save line and Abandonner les modifications
Header Annuler/Retablir on every tab (aria-disabled, commit on pointerdown,
refused blur commit skips the undo). Save line: unsaved count selector
(savedDistance), saveLineState forms, server save time via readSaveTime
(lastSave in the store, never the browser clock). Discard relabelled and
names the stored copy. Tool column pair removed, glyphs in EditorGlyph.

Rewritten or removed assertions (R-24):
- editor-route.test: Revision 3 / unsaved text / Annuler les modifications
  -> save-line testid, Abandonner label, copy sentence in the dialog
- editor-route-conflict, editor-route-recovery: Revision n and copy_cap/
  copy_quota text queries -> save-line testid
- editor-no-loss: discard button label
- editor-annotations-tab: tool column undo/redo test -> no pair left
  (behaviour moved to editor-history-buttons.test)
- e2e journey/annotations/recovery/structures/support saveDraft/lan:
  undo/redo and revision/unsaved text -> historyButton, saveLine helpers;
  structures toHaveCount(0) on old text -> exact Revision n line
- editor-shell clickability: header Annuler/Retablir added
2026-11-08 17:55:49 +01:00

65 lines
1.9 KiB
TypeScript

import type { CataloguePreview } from '@/catalogue/preview'
import { emptyHistory } from './undo'
import type { BlockKind, EditorData, EditorState } from './editorTypes'
export function initialData(): EditorData {
return {
session: 0,
status: 'idle',
failure: null,
userId: null,
versionId: null,
sheetId: null,
canEdit: true,
preview: null,
previewState: null,
handleVersion: 0,
documentText: '',
savedText: '',
savedRevision: 0,
staleBase: false,
unsaved: false,
drawings: [],
drawingFailures: {},
...emptyHistory(),
saving: false,
submitting: false,
reloading: false,
saveFailure: null,
lastSave: null,
conflict: null,
recovery: 'none',
offer: null,
refusedKind: null,
copyWritten: false,
copyIssue: null,
otherCopies: [],
unusableCopy: false,
}
}
/**
* Why a document change cannot run now. A recovery offer, a refused or a restoring copy
* block every change at the store level (keyboard shortcuts included).
*/
export function blockKind(state: EditorState): BlockKind | null {
if (state.status !== 'ready' || state.preview === null) return 'not_ready'
if (state.recovery !== 'none') return 'recovery.pending'
if (!state.canEdit) return 'read_only'
if (state.reloading) return 'busy'
return null
}
/** The handle of a state that accepts document changes, else the reason it does not. */
export function editablePreview(state: EditorState): CataloguePreview | BlockKind {
return blockKind(state) ?? state.preview ?? 'not_ready'
}
/** The leave guard is armed while unsaved or while a recovery offer is not answered. */
export function leaveGuardArmed(state: EditorData): boolean {
return state.unsaved || state.recovery !== 'none'
}
export const canUndo = (state: EditorData): boolean => state.undo.length > 0
export const canRedo = (state: EditorData): boolean => state.redo.length > 0