2025-11-22 19:11:20 +02:00
|
|
|
import { useContext, useEffect, useState } from "preact/hooks";
|
2025-11-22 19:07:50 +02:00
|
|
|
import Modal from "../react/Modal";
|
|
|
|
|
import "./PopupEditor.css";
|
|
|
|
|
import { useTriliumEvent } from "../react/hooks";
|
|
|
|
|
import NoteTitleWidget from "../note_title";
|
|
|
|
|
import NoteIcon from "../note_icon";
|
2025-11-22 19:11:20 +02:00
|
|
|
import NoteContext from "../../components/note_context";
|
|
|
|
|
import { ParentComponent } from "../react/react_utils";
|
|
|
|
|
|
|
|
|
|
const noteContext = new NoteContext("_popup-editor");
|
2025-11-22 19:07:50 +02:00
|
|
|
|
|
|
|
|
export default function PopupEditor() {
|
|
|
|
|
const [ shown, setShown ] = useState(false);
|
2025-11-22 19:11:20 +02:00
|
|
|
const parentComponent = useContext(ParentComponent);
|
|
|
|
|
|
|
|
|
|
useTriliumEvent("openInPopup", async ({ noteIdOrPath }) => {
|
|
|
|
|
await noteContext.setNote(noteIdOrPath, {
|
|
|
|
|
viewScope: {
|
|
|
|
|
readOnlyTemporarilyDisabled: true
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-11-22 19:07:50 +02:00
|
|
|
|
|
|
|
|
setShown(true);
|
|
|
|
|
});
|
|
|
|
|
|
2025-11-22 19:11:20 +02:00
|
|
|
// Inject the note context
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!shown || !parentComponent) return;
|
|
|
|
|
parentComponent.handleEventInChildren("activeContextChanged", { noteContext });
|
|
|
|
|
}, [ shown ]);
|
|
|
|
|
|
2025-11-22 19:07:50 +02:00
|
|
|
return (
|
|
|
|
|
<Modal
|
|
|
|
|
title={(
|
|
|
|
|
<div className="title-row">
|
|
|
|
|
<NoteIcon />
|
|
|
|
|
<NoteTitleWidget />
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
className="popup-editor-dialog"
|
|
|
|
|
size="lg"
|
|
|
|
|
show={shown}
|
|
|
|
|
onHidden={() => setShown(false)}
|
|
|
|
|
>
|
|
|
|
|
Body goes here
|
|
|
|
|
</Modal>
|
|
|
|
|
)
|
|
|
|
|
}
|