mirror of
https://github.com/zadam/trilium.git
synced 2025-12-21 23:59:59 +01:00
chore(react/type_widget): integrate touch bar for editable code
This commit is contained in:
@@ -3,7 +3,7 @@ import { ViewModeProps } from "../interface";
|
|||||||
import Calendar from "./calendar";
|
import Calendar from "./calendar";
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks";
|
import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
import { useNoteLabel, useNoteLabelBoolean, useResizeObserver, useSpacedUpdate, useTouchBar, useTriliumEvent, useTriliumOption, useTriliumOptionInt } from "../../react/hooks";
|
import { useNoteLabel, useNoteLabelBoolean, useResizeObserver, useSpacedUpdate, useTriliumEvent, useTriliumOption, useTriliumOptionInt } from "../../react/hooks";
|
||||||
import { LOCALE_IDS } from "@triliumnext/commons";
|
import { LOCALE_IDS } from "@triliumnext/commons";
|
||||||
import { Calendar as FullCalendar } from "@fullcalendar/core";
|
import { Calendar as FullCalendar } from "@fullcalendar/core";
|
||||||
import { parseStartEndDateFromEvent, parseStartEndTimeFromEvent } from "./utils";
|
import { parseStartEndDateFromEvent, parseStartEndTimeFromEvent } from "./utils";
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import Map from "./map";
|
import Map from "./map";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
import { ViewModeProps } from "../interface";
|
import { ViewModeProps } from "../interface";
|
||||||
import { useNoteBlob, useNoteLabel, useNoteLabelBoolean, useNoteProperty, useNoteTreeDrag, useSpacedUpdate, useTouchBar, useTriliumEvent } from "../../react/hooks";
|
import { useNoteBlob, useNoteLabel, useNoteLabelBoolean, useNoteProperty, useNoteTreeDrag, useSpacedUpdate, useTriliumEvent } from "../../react/hooks";
|
||||||
import { DEFAULT_MAP_LAYER_NAME } from "./map_layer";
|
import { DEFAULT_MAP_LAYER_NAME } from "./map_layer";
|
||||||
import { divIcon, GPXOptions, LatLng, LeafletMouseEvent } from "leaflet";
|
import { divIcon, GPXOptions, LatLng, LeafletMouseEvent } from "leaflet";
|
||||||
import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "preact/hooks";
|
import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "preact/hooks";
|
||||||
|
|||||||
@@ -700,26 +700,6 @@ export function useNoteTreeDrag(containerRef: MutableRef<HTMLElement | null | un
|
|||||||
}, [ containerRef, callback ]);
|
}, [ containerRef, callback ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useTouchBar(
|
|
||||||
factory: (context: CommandListenerData<"buildTouchBar"> & { parentComponent: Component | null }) => void,
|
|
||||||
inputs: Inputs
|
|
||||||
) {
|
|
||||||
const parentComponent = useContext(ParentComponent);
|
|
||||||
|
|
||||||
useLegacyImperativeHandlers({
|
|
||||||
buildTouchBarCommand(context: CommandListenerData<"buildTouchBar">) {
|
|
||||||
return factory({
|
|
||||||
...context,
|
|
||||||
parentComponent
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
parentComponent?.triggerCommand("refreshTouchBar");
|
|
||||||
}, inputs);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useResizeObserver(ref: RefObject<HTMLElement>, callback: () => void) {
|
export function useResizeObserver(ref: RefObject<HTMLElement>, callback: () => void) {
|
||||||
const resizeObserver = useRef<ResizeObserver>(null);
|
const resizeObserver = useRef<ResizeObserver>(null);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import CodeMirror from "./CodeMirror";
|
|||||||
import utils from "../../../services/utils";
|
import utils from "../../../services/utils";
|
||||||
import { useEditorSpacedUpdate, useNoteBlob, useTriliumOptionBool } from "../../react/hooks";
|
import { useEditorSpacedUpdate, useNoteBlob, useTriliumOptionBool } from "../../react/hooks";
|
||||||
import { t } from "../../../services/i18n";
|
import { t } from "../../../services/i18n";
|
||||||
|
import appContext from "../../../components/app_context";
|
||||||
|
import TouchBar, { TouchBarButton } from "../../react/TouchBar";
|
||||||
|
|
||||||
export function ReadOnlyCode({ note, viewScope, ntxId }: TypeWidgetProps) {
|
export function ReadOnlyCode({ note, viewScope, ntxId }: TypeWidgetProps) {
|
||||||
const [ content, setContent ] = useState("");
|
const [ content, setContent ] = useState("");
|
||||||
@@ -64,6 +66,12 @@ export function EditableCode({ note, ntxId, debounceUpdate }: TypeWidgetProps &
|
|||||||
spacedUpdate.scheduleUpdate();
|
spacedUpdate.scheduleUpdate();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<TouchBar>
|
||||||
|
{(note?.mime.startsWith("application/javascript") || note?.mime === "text/x-sqlite;schema=trilium") && (
|
||||||
|
<TouchBarButton icon="NSImageNameTouchBarPlayTemplate" click={() => appContext.triggerCommand("runActiveNote")} />
|
||||||
|
)}
|
||||||
|
</TouchBar>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,26 +29,4 @@ export default class EditableCodeTypeWidget extends AbstractCodeTypeWidget {
|
|||||||
super.doRender();
|
super.doRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
async doRefresh(note: FNote) {
|
|
||||||
const blob = await this.note?.getBlob();
|
|
||||||
|
|
||||||
if (this.parent && hasTouchBar) {
|
|
||||||
this.triggerCommand("refreshTouchBar");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
buildTouchBarCommand({ TouchBar, buildIcon }: CommandListenerData<"buildTouchBar">) {
|
|
||||||
const items: TouchBarItem[] = [];
|
|
||||||
const note = this.note;
|
|
||||||
|
|
||||||
if (note?.mime.startsWith("application/javascript") || note?.mime === "text/x-sqlite;schema=trilium") {
|
|
||||||
items.push(new TouchBar.TouchBarButton({
|
|
||||||
icon: buildIcon("NSImageNameTouchBarPlayTemplate"),
|
|
||||||
click: () => appContext.triggerCommand("runActiveNote")
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
return items;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user