mirror of
https://github.com/zadam/trilium.git
synced 2025-10-21 23:59:02 +02:00
refactor(react/ribbon): set up keyboard shortcuts
This commit is contained in:
parent
d53faa8c01
commit
9f217b88e4
@ -1,20 +0,0 @@
|
|||||||
export default class AttributeEditorWidget extends NoteContextAwareWidget implements EventListener<"entitiesReloaded">, EventListener<"addNewLabel">, EventListener<"addNewRelation"> {
|
|
||||||
|
|
||||||
// triggered from keyboard shortcut
|
|
||||||
async addNewLabelEvent({ ntxId }: EventData<"addNewLabel">) {
|
|
||||||
if (this.isNoteContext(ntxId)) {
|
|
||||||
await this.refresh();
|
|
||||||
|
|
||||||
this.handleAddNewAttributeCommand("addNewLabel");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// triggered from keyboard shortcut
|
|
||||||
async addNewRelationEvent({ ntxId }: EventData<"addNewRelation">) {
|
|
||||||
if (this.isNoteContext(ntxId)) {
|
|
||||||
await this.refresh();
|
|
||||||
|
|
||||||
this.handleAddNewAttributeCommand("addNewRelation");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -450,7 +450,6 @@ export function useLegacyWidget<T extends BasicWidget>(widgetFactory: () => T, {
|
|||||||
|
|
||||||
// Inject the note context.
|
// Inject the note context.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log("Injecting note context");
|
|
||||||
if (noteContext && widget instanceof NoteContextAwareWidget) {
|
if (noteContext && widget instanceof NoteContextAwareWidget) {
|
||||||
widget.activeContextChangedEvent({ noteContext });
|
widget.activeContextChangedEvent({ noteContext });
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
import AttributeEditor from "./components/AttributeEditor";
|
import AttributeEditor from "./components/AttributeEditor";
|
||||||
import { TabContext } from "./ribbon-interface";
|
import { TabContext } from "./ribbon-interface";
|
||||||
|
|
||||||
export default function OwnedAttributesTab({ note, notePath, componentId }: TabContext) {
|
export default function OwnedAttributesTab({ note, ...restProps }: TabContext) {
|
||||||
return (
|
return (
|
||||||
<div className="attribute-list">
|
<div className="attribute-list">
|
||||||
{ note && (
|
{ note && (
|
||||||
<AttributeEditor
|
<AttributeEditor note={note} {...restProps} />
|
||||||
componentId={componentId}
|
|
||||||
note={note}
|
|
||||||
notePath={notePath}
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
@ -76,7 +76,7 @@ const mentionSetup: MentionFeed[] = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
export default function AttributeEditor({ note, componentId, notePath }: { note: FNote, componentId: string, notePath?: string | null }) {
|
export default function AttributeEditor({ note, componentId, notePath, ntxId }: { note: FNote, componentId: string, notePath?: string | null, ntxId?: string | null }) {
|
||||||
const [ state, setState ] = useState<"normal" | "showHelpTooltip" | "showAttributeDetail">();
|
const [ state, setState ] = useState<"normal" | "showHelpTooltip" | "showAttributeDetail">();
|
||||||
const [ error, setError ] = useState<unknown>();
|
const [ error, setError ] = useState<unknown>();
|
||||||
const [ needsSaving, setNeedsSaving ] = useState(false);
|
const [ needsSaving, setNeedsSaving ] = useState(false);
|
||||||
@ -253,6 +253,16 @@ export default function AttributeEditor({ note, componentId, notePath }: { note:
|
|||||||
reloadAttributesCommand: refresh,
|
reloadAttributesCommand: refresh,
|
||||||
updateAttributeListCommand: ({ attributes }: CommandListenerData<"updateAttributeList">) => renderOwnedAttributes(attributes as FAttribute[], false)
|
updateAttributeListCommand: ({ attributes }: CommandListenerData<"updateAttributeList">) => renderOwnedAttributes(attributes as FAttribute[], false)
|
||||||
}), []));
|
}), []));
|
||||||
|
|
||||||
|
// Keyboard shortcuts
|
||||||
|
useTriliumEventBeta("addNewLabel", ({ ntxId: eventNtxId }) => {
|
||||||
|
if (eventNtxId !== ntxId) return;
|
||||||
|
handleAddNewAttributeCommand("addNewLabel");
|
||||||
|
});
|
||||||
|
useTriliumEventBeta("addNewRelation", ({ ntxId: eventNtxId }) => {
|
||||||
|
if (eventNtxId !== ntxId) return;
|
||||||
|
handleAddNewAttributeCommand("addNewRelation");
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user