2025-11-22 20:08:37 +02:00
|
|
|
import { useContext, useEffect, useRef, useState } from "preact/hooks";
|
2025-11-22 19:07:50 +02:00
|
|
|
import Modal from "../react/Modal";
|
|
|
|
|
import "./PopupEditor.css";
|
2025-11-22 20:08:37 +02:00
|
|
|
import { useNoteContext, useNoteLabel, useTriliumEvent } from "../react/hooks";
|
2025-11-22 19:07:50 +02:00
|
|
|
import NoteTitleWidget from "../note_title";
|
|
|
|
|
import NoteIcon from "../note_icon";
|
2025-11-22 19:11:20 +02:00
|
|
|
import NoteContext from "../../components/note_context";
|
2025-11-22 19:25:27 +02:00
|
|
|
import { NoteContextContext, ParentComponent } from "../react/react_utils";
|
2025-11-22 19:17:50 +02:00
|
|
|
import NoteDetail from "../NoteDetail";
|
2025-11-22 20:08:37 +02:00
|
|
|
import { ComponentChildren } from "preact";
|
2025-11-22 19:07:50 +02:00
|
|
|
|
|
|
|
|
export default function PopupEditor() {
|
|
|
|
|
const [ shown, setShown ] = useState(false);
|
2025-11-22 19:34:14 +02:00
|
|
|
const parentComponent = useContext(ParentComponent);
|
2025-11-22 20:08:37 +02:00
|
|
|
const [ noteContext, setNoteContext ] = useState(new NoteContext("_popup-editor"));
|
2025-11-22 19:11:20 +02:00
|
|
|
|
|
|
|
|
useTriliumEvent("openInPopup", async ({ noteIdOrPath }) => {
|
2025-11-22 20:08:37 +02:00
|
|
|
const noteContext = new NoteContext("_popup-editor");
|
2025-11-22 19:11:20 +02:00
|
|
|
await noteContext.setNote(noteIdOrPath, {
|
|
|
|
|
viewScope: {
|
|
|
|
|
readOnlyTemporarilyDisabled: true
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-11-22 19:07:50 +02:00
|
|
|
|
2025-11-22 20:08:37 +02:00
|
|
|
setNoteContext(noteContext);
|
2025-11-22 19:07:50 +02:00
|
|
|
setShown(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return (
|
2025-11-22 19:25:27 +02:00
|
|
|
<NoteContextContext.Provider value={noteContext}>
|
2025-11-22 20:08:37 +02:00
|
|
|
<DialogWrapper>
|
|
|
|
|
<Modal
|
|
|
|
|
title={<TitleRow />}
|
|
|
|
|
className="popup-editor-dialog"
|
|
|
|
|
size="lg"
|
|
|
|
|
show={shown}
|
|
|
|
|
onShown={() => {
|
|
|
|
|
parentComponent?.handleEvent("focusOnDetail", { ntxId: noteContext.ntxId });
|
|
|
|
|
}}
|
|
|
|
|
onHidden={() => setShown(false)}
|
|
|
|
|
>
|
|
|
|
|
<NoteDetail />
|
|
|
|
|
</Modal>
|
|
|
|
|
</DialogWrapper>
|
2025-11-22 19:25:27 +02:00
|
|
|
</NoteContextContext.Provider>
|
2025-11-22 19:07:50 +02:00
|
|
|
)
|
|
|
|
|
}
|
2025-11-22 19:17:50 +02:00
|
|
|
|
2025-11-22 20:08:37 +02:00
|
|
|
export function DialogWrapper({ children }: { children: ComponentChildren }) {
|
|
|
|
|
const { note, ntxId } = useNoteContext();
|
|
|
|
|
const wrapperRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
const colorClass = note?.getColorClass();
|
|
|
|
|
const [ hasTint, setHasTint ] = useState(false);
|
|
|
|
|
|
|
|
|
|
// Apply the tinted-dialog class only if the custom color CSS class specifies a hue
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!wrapperRef.current) return;
|
|
|
|
|
const customHue = getComputedStyle(wrapperRef.current).getPropertyValue("--custom-color-hue");
|
|
|
|
|
setHasTint(!!customHue);
|
|
|
|
|
}, [ note, colorClass ]);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div ref={wrapperRef} class={`quick-edit-dialog-wrapper ${note?.getColorClass()} ${hasTint ? "tinted-quick-edit-dialog" : ""}`}>
|
|
|
|
|
{children}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-22 19:17:50 +02:00
|
|
|
export function TitleRow() {
|
|
|
|
|
return (
|
|
|
|
|
<div className="title-row">
|
|
|
|
|
<NoteIcon />
|
|
|
|
|
<NoteTitleWidget />
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|