Skip to content

Build your personal knowledge base with Trilium Notes

chore(react/type_widget): integrate touch bar for editable code

Elian Doranc86123e3a92c
diff --git a/apps/client/src/widgets/collections/calendar/index.tsx b/apps/client/src/widgets/collections/calendar/index.tsx
index 3173825931..d7112ca39a 100644
--- a/apps/client/src/widgets/collections/calendar/index.tsx
+++ b/apps/client/src/widgets/collections/calendar/index.tsx
@@ -3,7 +3,7 @@ import { ViewModeProps } from "../interface";
import Calendar from "./calendar";
import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks";
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 { Calendar as FullCalendar } from "@fullcalendar/core";
import { parseStartEndDateFromEvent, parseStartEndTimeFromEvent } from "./utils";
diff --git a/apps/client/src/widgets/collections/geomap/index.tsx b/apps/client/src/widgets/collections/geomap/index.tsx
index ccc1330d19..07e942d199 100644
--- a/apps/client/src/widgets/collections/geomap/index.tsx
+++ b/apps/client/src/widgets/collections/geomap/index.tsx
@@ -1,7 +1,7 @@
import Map from "./map";
import "./index.css";
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 { divIcon, GPXOptions, LatLng, LeafletMouseEvent } from "leaflet";
import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "preact/hooks";
diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx
index 1667ac82fb..0b92b7459c 100644
--- a/apps/client/src/widgets/react/hooks.tsx
+++ b/apps/client/src/widgets/react/hooks.tsx
@@ -700,26 +700,6 @@ export function useNoteTreeDrag(containerRef: MutableRef<HTMLElement | null | un
}, [ 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) {
const resizeObserver = useRef<ResizeObserver>(null);
useEffect(() => {
diff --git a/apps/client/src/widgets/type_widgets/code/Code.tsx b/apps/client/src/widgets/type_widgets/code/Code.tsx
index cdc0391cb2..377f99d031 100644
--- a/apps/client/src/widgets/type_widgets/code/Code.tsx
+++ b/apps/client/src/widgets/type_widgets/code/Code.tsx
@@ -6,6 +6,8 @@ import CodeMirror from "./CodeMirror";
import utils from "../../../services/utils";
import { useEditorSpacedUpdate, useNoteBlob, useTriliumOptionBool } from "../../react/hooks";
import { t } from "../../../services/i18n";
+import appContext from "../../../components/app_context";
+import TouchBar, { TouchBarButton } from "../../react/TouchBar";
export function ReadOnlyCode({ note, viewScope, ntxId }: TypeWidgetProps) {
const [ content, setContent ] = useState("");
@@ -64,6 +66,12 @@ export function EditableCode({ note, ntxId, debounceUpdate }: TypeWidgetProps &
spacedUpdate.scheduleUpdate();
}}
/>
+
+ <TouchBar>
+ {(note?.mime.startsWith("application/javascript") || note?.mime === "text/x-sqlite;schema=trilium") && (
+ <TouchBarButton icon="NSImageNameTouchBarPlayTemplate" click={() => appContext.triggerCommand("runActiveNote")} />
+ )}
+ </TouchBar>
</div>
)
}
diff --git a/apps/client/src/widgets/type_widgets_old/editable_code.ts b/apps/client/src/widgets/type_widgets_old/editable_code.ts
index deb5acbf2c..9d5164616f 100644
--- a/apps/client/src/widgets/type_widgets_old/editable_code.ts
+++ b/apps/client/src/widgets/type_widgets_old/editable_code.ts
@@ -29,26 +29,4 @@ export default class EditableCodeTypeWidget extends AbstractCodeTypeWidget {
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;
- }
-
}