feat(app): editor store, undo, recovery copy and geometry accept rules
This commit is contained in:
1 parent
f7e7bf4ee1
commit
7f1d44065b
20 files changed
+2538
-5
No files matched your search
@@ -0,0 +1,63 @@
|
||||
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,
|
||||
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
|
||||
Reference in new issue
Block a user