chore(react/type_widget): finalize read-only text

This commit is contained in:
Elian Doran
2025-09-21 20:50:26 +03:00
parent 2947682783
commit 5d833c1ac4
4 changed files with 20 additions and 26 deletions

View File

@@ -44,7 +44,8 @@ export default function NoteDetail() {
note: note!, note: note!,
viewScope, viewScope,
ntxId, ntxId,
parentComponent parentComponent,
noteContext
}; };
useEffect(() => setCorrespondingWidget(getCorrespondingWidget(type, props)), [ note, viewScope, type ]); useEffect(() => setCorrespondingWidget(getCorrespondingWidget(type, props)), [ note, viewScope, type ]);

View File

@@ -15,8 +15,10 @@ import { loadIncludedNote, refreshIncludedNote, setupImageOpening } from "./util
import { renderMathInElement } from "../../../services/math"; import { renderMathInElement } from "../../../services/math";
import link from "../../../services/link"; import link from "../../../services/link";
import { formatCodeBlocks } from "../../../services/syntax_highlight"; import { formatCodeBlocks } from "../../../services/syntax_highlight";
import TouchBar, { TouchBarButton, TouchBarSpacer } from "../../react/TouchBar";
import appContext from "../../../components/app_context";
export default function ReadOnlyText({ note, ntxId }: TypeWidgetProps) { export default function ReadOnlyText({ note, noteContext, ntxId }: TypeWidgetProps) {
const blob = useNoteBlob(note); const blob = useNoteBlob(note);
const contentRef = useRef<HTMLDivElement>(null); const contentRef = useRef<HTMLDivElement>(null);
const { isRtl } = useNoteLanguage(note); const { isRtl } = useNoteLanguage(note);
@@ -57,6 +59,19 @@ export default function ReadOnlyText({ note, ntxId }: TypeWidgetProps) {
className="note-detail-readonly-text-content ck-content use-tn-links" className="note-detail-readonly-text-content ck-content use-tn-links"
html={blob?.content} html={blob?.content}
/> />
<TouchBar>
<TouchBarSpacer size="flexible" />
<TouchBarButton
icon="NSLockUnlockedTemplate"
click={() => {
if (noteContext?.viewScope) {
noteContext.viewScope.readOnlyTemporarilyDisabled = true;
appContext.triggerEvent("readOnlyTemporarilyDisabled", { noteContext });
}
}}
/>
</TouchBar>
</div> </div>
) )
} }

View File

@@ -1,10 +1,12 @@
import FNote from "../../entities/fnote"; import FNote from "../../entities/fnote";
import { ViewScope } from "../../services/link"; import { ViewScope } from "../../services/link";
import { TypedComponent } from "../../components/component"; import { TypedComponent } from "../../components/component";
import NoteContext from "../../components/note_context";
export interface TypeWidgetProps { export interface TypeWidgetProps {
note: FNote; note: FNote;
viewScope: ViewScope | undefined; viewScope: ViewScope | undefined;
ntxId: string | null | undefined; ntxId: string | null | undefined;
parentComponent: TypedComponent<any> | undefined; parentComponent: TypedComponent<any> | undefined;
noteContext: NoteContext | undefined;
} }

View File

@@ -1,24 +0,0 @@
import AbstractTextTypeWidget from "./abstract_text_type_widget.js";
import { formatCodeBlocks } from "../../services/syntax_highlight.js";
import type FNote from "../../entities/fnote.js";
import type { CommandListenerData, EventData } from "../../components/app_context.js";
import appContext from "../../components/app_context.js";
export default class ReadOnlyTextTypeWidget extends AbstractTextTypeWidget {
buildTouchBarCommand({ TouchBar, buildIcon }: CommandListenerData<"buildTouchBar">) {
return [
new TouchBar.TouchBarSpacer({ size: "flexible" }),
new TouchBar.TouchBarButton({
icon: buildIcon("NSLockUnlockedTemplate"),
click: () => {
if (this.noteContext?.viewScope) {
this.noteContext.viewScope.readOnlyTemporarilyDisabled = true;
appContext.triggerEvent("readOnlyTemporarilyDisabled", { noteContext: this.noteContext });
}
this.refresh();
}
})
];
}
}