fix(editor): Task 12 review minors, delete hint and cite label
This commit is contained in:
1 parent
8c420d4b53
commit
11c2b0c5ee
12 files changed
+113
-47
No files matched your search
@@ -42,7 +42,10 @@ export interface ReferenceMoves {
|
||||
backToFinding: (key: ElementKey) => void
|
||||
}
|
||||
|
||||
/** What the open dialog was started from: its opener, and a citing form for a creation. */
|
||||
/**
|
||||
* What the open dialog was started from: its opener, and a citing form for a creation
|
||||
* (forgotten once the dialog closes or is replaced).
|
||||
*/
|
||||
interface Held {
|
||||
opener: Opener
|
||||
cite: CiteCreated | null
|
||||
@@ -72,22 +75,25 @@ function useOpening({ dispatch, mark }: LayerContext, held: Held) {
|
||||
}
|
||||
|
||||
/** A user close: the form may refuse it (a dirty draft asks first). */
|
||||
function useClose({ dispatch, guards, mark }: LayerContext) {
|
||||
function useClose({ dispatch, guards, mark }: LayerContext, held: Held) {
|
||||
return useCallback(
|
||||
(forced = false) => {
|
||||
if (!guards.ask('reference', forced).allowed) return false
|
||||
held.cite = null
|
||||
mark()
|
||||
dispatch({ type: 'close_reference' })
|
||||
return true
|
||||
},
|
||||
[guards, dispatch, mark],
|
||||
[guards, dispatch, mark, held],
|
||||
)
|
||||
}
|
||||
|
||||
/** The replace that is no Back step; with `text`, forced and said with a dropped draft. */
|
||||
function useReplace({ dispatch, announce, guards, mark }: LayerContext) {
|
||||
function useReplace(ctx: LayerContext, held: Held) {
|
||||
const { dispatch, announce, guards, mark } = ctx
|
||||
return useCallback(
|
||||
(id: string | null, text?: string) => {
|
||||
held.cite = null
|
||||
const note = text ? guards.ask('reference', true).note : undefined
|
||||
if (text) announce(note ? `${note}. ${text}` : text)
|
||||
mark(true)
|
||||
@@ -95,13 +101,13 @@ function useReplace({ dispatch, announce, guards, mark }: LayerContext) {
|
||||
id ? { type: 'open_reference', id } : { type: 'close_reference' },
|
||||
)
|
||||
},
|
||||
[guards, announce, dispatch, mark],
|
||||
[guards, announce, dispatch, mark, held],
|
||||
)
|
||||
}
|
||||
|
||||
/** The moves that take it away: a user close, and the replace that is no Back step. */
|
||||
function useClosing(ctx: LayerContext) {
|
||||
return { close: useClose(ctx), replace: useReplace(ctx) }
|
||||
function useClosing(ctx: LayerContext, held: Held) {
|
||||
return { close: useClose(ctx, held), replace: useReplace(ctx, held) }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,7 +175,7 @@ export function useReferenceMoves(
|
||||
const element = held.opener
|
||||
return element?.isConnected && !element.closest('[hidden]') ? element : null
|
||||
}, [held])
|
||||
const closing = useClosing(ctx)
|
||||
const closing = useClosing(ctx, held)
|
||||
return {
|
||||
...useOpening(ctx, held),
|
||||
...closing,
|
||||
|
||||
Reference in new issue
Block a user