mirror of
https://github.com/zadam/trilium.git
synced 2025-12-16 05:09:54 +01:00
feat(layout/note_actions): integrate open API docs
This commit is contained in:
@@ -182,7 +182,7 @@ function RunActiveNoteButton({ note }: FloatingButtonContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function OpenTriliumApiDocsButton({ note }: FloatingButtonContext) {
|
function OpenTriliumApiDocsButton({ note }: FloatingButtonContext) {
|
||||||
const isEnabled = note.mime.startsWith("application/javascript;env=");
|
const isEnabled = !isNewLayout && note.mime.startsWith("application/javascript;env=");
|
||||||
return isEnabled && <FloatingButton
|
return isEnabled && <FloatingButton
|
||||||
icon="bx bx-help-circle"
|
icon="bx bx-help-circle"
|
||||||
text={t("code_buttons.trilium_api_docs_button_title")}
|
text={t("code_buttons.trilium_api_docs_button_title")}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import NoteContext from "../../components/note_context";
|
|||||||
import FNote from "../../entities/fnote";
|
import FNote from "../../entities/fnote";
|
||||||
import { t } from "../../services/i18n";
|
import { t } from "../../services/i18n";
|
||||||
import { downloadFileNote, openNoteExternally } from "../../services/open";
|
import { downloadFileNote, openNoteExternally } from "../../services/open";
|
||||||
|
import { openInAppHelpFromUrl } from "../../services/utils";
|
||||||
import { ViewTypeOptions } from "../collections/interface";
|
import { ViewTypeOptions } from "../collections/interface";
|
||||||
import { buildSaveSqlToNoteHandler } from "../FloatingButtonsDefinitions";
|
import { buildSaveSqlToNoteHandler } from "../FloatingButtonsDefinitions";
|
||||||
import ActionButton from "../react/ActionButton";
|
import ActionButton from "../react/ActionButton";
|
||||||
@@ -22,6 +23,7 @@ interface NoteActionsCustomProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface NoteActionsCustomInnerProps extends NoteActionsCustomProps {
|
interface NoteActionsCustomInnerProps extends NoteActionsCustomProps {
|
||||||
|
noteMime: string;
|
||||||
noteType: NoteType;
|
noteType: NoteType;
|
||||||
isReadOnly: boolean;
|
isReadOnly: boolean;
|
||||||
isDefaultViewMode: boolean;
|
isDefaultViewMode: boolean;
|
||||||
@@ -36,12 +38,14 @@ interface NoteActionsCustomInnerProps extends NoteActionsCustomProps {
|
|||||||
export default function NoteActionsCustom(props: NoteActionsCustomProps) {
|
export default function NoteActionsCustom(props: NoteActionsCustomProps) {
|
||||||
const { note } = props;
|
const { note } = props;
|
||||||
const noteType = useNoteProperty(note, "type");
|
const noteType = useNoteProperty(note, "type");
|
||||||
|
const noteMime = useNoteProperty(note, "mime");
|
||||||
const [ viewType ] = useNoteLabel(note, "viewType");
|
const [ viewType ] = useNoteLabel(note, "viewType");
|
||||||
const parentComponent = useContext(ParentComponent);
|
const parentComponent = useContext(ParentComponent);
|
||||||
const [ isReadOnly ] = useNoteLabelBoolean(note, "readOnly");
|
const [ isReadOnly ] = useNoteLabelBoolean(note, "readOnly");
|
||||||
const innerProps: NoteActionsCustomInnerProps | null | undefined = noteType && parentComponent && {
|
const innerProps: NoteActionsCustomInnerProps | false = !!noteType && !!noteMime && !!parentComponent && {
|
||||||
...props,
|
...props,
|
||||||
noteType,
|
noteType,
|
||||||
|
noteMime,
|
||||||
viewType: viewType as ViewTypeOptions | null | undefined,
|
viewType: viewType as ViewTypeOptions | null | undefined,
|
||||||
isDefaultViewMode: props.noteContext.viewScope?.viewMode === "default",
|
isDefaultViewMode: props.noteContext.viewScope?.viewMode === "default",
|
||||||
parentComponent,
|
parentComponent,
|
||||||
@@ -51,6 +55,7 @@ export default function NoteActionsCustom(props: NoteActionsCustomProps) {
|
|||||||
return (innerProps &&
|
return (innerProps &&
|
||||||
<div className="note-actions-custom">
|
<div className="note-actions-custom">
|
||||||
<RunActiveNoteButton {...innerProps } />
|
<RunActiveNoteButton {...innerProps } />
|
||||||
|
<OpenTriliumApiDocsButton {...innerProps} />
|
||||||
<SwitchSplitOrientationButton {...innerProps} />
|
<SwitchSplitOrientationButton {...innerProps} />
|
||||||
<ToggleReadOnlyButton {...innerProps} />
|
<ToggleReadOnlyButton {...innerProps} />
|
||||||
<SaveToNoteButton {...innerProps} />
|
<SaveToNoteButton {...innerProps} />
|
||||||
@@ -195,3 +200,12 @@ function SaveToNoteButton({ note }: NoteActionsCustomInnerProps) {
|
|||||||
onClick={buildSaveSqlToNoteHandler(note)}
|
onClick={buildSaveSqlToNoteHandler(note)}
|
||||||
/>;
|
/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function OpenTriliumApiDocsButton({ note }: NoteActionsCustomInnerProps) {
|
||||||
|
const isEnabled = note.mime.startsWith("application/javascript;env=");
|
||||||
|
return isEnabled && <ActionButton
|
||||||
|
icon="bx bx-help-circle"
|
||||||
|
text={t("code_buttons.trilium_api_docs_button_title")}
|
||||||
|
onClick={() => openInAppHelpFromUrl(note.mime.endsWith("frontend") ? "Q2z6av6JZVWm" : "MEtfsqa5VwNi")}
|
||||||
|
/>;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user