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
@@ -12,8 +12,11 @@ const BOX =
|
||||
|
||||
/**
|
||||
* True when no open dialog lies over `host`: each open one is `host`, holds it, or comes
|
||||
* before it in the page (the editor's layers are stacked in tree order: the references
|
||||
* dialog after the finding dialog, the reference dialog after both).
|
||||
* before it in the page.
|
||||
* Invariant: an open dialog after `host` in tree order lies over it. The editor's layers
|
||||
* keep it (the finding dialog in the tab body, then the references dialog, then the
|
||||
* reference dialog); a modal mounted earlier in the tree must never open over a form
|
||||
* that uses this confirmation, or its question would be focused under that modal.
|
||||
*/
|
||||
const onTop = (host: Element) =>
|
||||
[...document.querySelectorAll('dialog[open]')].every(
|
||||
|
||||
@@ -90,7 +90,7 @@ function DraftRow({ id, props, onRemove }: RowProps) {
|
||||
)
|
||||
}
|
||||
|
||||
/** « Citer une référence » among those not cited yet, and « Nouvelle référence ». */
|
||||
/** « Citer une référence existante » among those not cited yet, and « Nouvelle référence ». */
|
||||
function AddRow({ props }: { props: DraftListProps }) {
|
||||
const t = useT()
|
||||
const options = useCitableOptions(props.ids)
|
||||
@@ -135,19 +135,25 @@ export default function CitationsDraftList(props: DraftListProps) {
|
||||
{t('editor.findings.references_none')}
|
||||
</p>
|
||||
)}
|
||||
<ul ref={focus.list} className="space-y-2">
|
||||
{ids.map((id, at) => (
|
||||
<DraftRow
|
||||
key={id}
|
||||
id={id}
|
||||
props={props}
|
||||
onRemove={() => {
|
||||
focus.removing(at)
|
||||
props.onRemove(id)
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
{ids.length > 0 && (
|
||||
<ul
|
||||
ref={focus.list}
|
||||
aria-label={t('editor.findings.references')}
|
||||
className="space-y-2"
|
||||
>
|
||||
{ids.map((id, at) => (
|
||||
<DraftRow
|
||||
key={id}
|
||||
id={id}
|
||||
props={props}
|
||||
onRemove={() => {
|
||||
focus.removing(at)
|
||||
props.onRemove(id)
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
<AddRow props={props} />
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -138,7 +138,7 @@ export interface EditorNavigation {
|
||||
openCitations: (citedBy: ElementKey, opener?: Opener) => void
|
||||
/**
|
||||
* A close of the citations dialog: a user one is refused by its draft (it asks first),
|
||||
* a forced one goes (the draft is dropped).
|
||||
* a forced one goes (the draft is dropped, and said so).
|
||||
*/
|
||||
closeCitations: (forced?: boolean) => boolean
|
||||
/** « X références », where the focus returns once the citations dialog is closed. */
|
||||
@@ -393,7 +393,7 @@ function useFindingClosing({ dispatch, announce, guards, mark }: LayerContext) {
|
||||
|
||||
/** The citations dialog over the finding dialog: opened for a family or a node only. */
|
||||
function useCitationsLayer(ctx: LayerContext, openers: Openers) {
|
||||
const { dispatch, guards, mark } = ctx
|
||||
const { dispatch, announce, guards, mark } = ctx
|
||||
const openCitations = useCallback(
|
||||
(citedBy: ElementKey, opener?: Opener) => {
|
||||
if (!isCitable(citedBy)) return
|
||||
@@ -406,12 +406,15 @@ function useCitationsLayer(ctx: LayerContext, openers: Openers) {
|
||||
)
|
||||
const closeCitations = useCallback(
|
||||
(forced = false) => {
|
||||
if (!guards.ask('citations', forced).allowed) return false
|
||||
const answer = guards.ask('citations', forced)
|
||||
if (!answer.allowed) return false
|
||||
// A forced close of a draft says it was dropped, as the other forced closes.
|
||||
if (answer.note) announce(answer.note)
|
||||
mark()
|
||||
dispatch({ type: 'close_citations' })
|
||||
return true
|
||||
},
|
||||
[guards, dispatch, mark],
|
||||
[guards, announce, dispatch, mark],
|
||||
)
|
||||
return { openCitations, closeCitations }
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -1253,7 +1253,7 @@ export const en: Dict = {
|
||||
'editor.references.none_doi': 'None',
|
||||
'editor.references.none_url': 'None',
|
||||
'editor.references.new_tab': '(new tab)',
|
||||
'editor.references.delete_hint': 'To delete this reference, first remove each of its citations: “Go to”, then “Edit” and “Remove” in the finding or the family.',
|
||||
'editor.references.delete_hint': 'To delete this reference, first remove each of its citations: “Go to”, then “X references”, “Edit” and “Remove” in the references of the finding or the family.',
|
||||
'editor.references.add': 'Add a reference',
|
||||
'editor.references.added': 'Reference added: {citation}',
|
||||
'editor.references.added_show': 'Show',
|
||||
@@ -1640,7 +1640,7 @@ export const en: Dict = {
|
||||
'editor.findings.no': 'No',
|
||||
'editor.findings.references': 'Cited references',
|
||||
'editor.findings.references_none': 'No reference cited.',
|
||||
'editor.findings.reference_add': 'Cite a reference',
|
||||
'editor.findings.reference_add': 'Cite an existing reference',
|
||||
'editor.findings.edit': 'Edit',
|
||||
'editor.findings.save': 'Save',
|
||||
'editor.findings.saved': 'Changes saved',
|
||||
|
||||
@@ -1284,7 +1284,7 @@ export const fr: Dict = {
|
||||
'editor.references.none_doi': 'Aucun',
|
||||
'editor.references.none_url': 'Aucune',
|
||||
'editor.references.new_tab': '(nouvel onglet)',
|
||||
'editor.references.delete_hint': 'Pour supprimer cette référence, retirez d\'abord chacune de ses citations : « Aller à », puis « Modifier » et « Retirer » dans le constat ou la famille.',
|
||||
'editor.references.delete_hint': 'Pour supprimer cette référence, retirez d\'abord chacune de ses citations : « Aller à », puis « X références », « Modifier » et « Retirer » dans les références du constat ou de la famille.',
|
||||
'editor.references.add': 'Ajouter une référence',
|
||||
'editor.references.added': 'Référence ajoutée : {citation}',
|
||||
'editor.references.added_show': 'Afficher',
|
||||
@@ -1670,7 +1670,7 @@ export const fr: Dict = {
|
||||
'editor.findings.no': 'Non',
|
||||
'editor.findings.references': 'Références citées',
|
||||
'editor.findings.references_none': 'Aucune référence citée.',
|
||||
'editor.findings.reference_add': 'Citer une référence',
|
||||
'editor.findings.reference_add': 'Citer une référence existante',
|
||||
'editor.findings.edit': 'Modifier',
|
||||
'editor.findings.save': 'Enregistrer',
|
||||
'editor.findings.saved': 'Modifications enregistrées',
|
||||
|
||||
Reference in new issue
Block a user