Skip to content

Build your personal knowledge base with Trilium Notes

chore(react/type_widget): bring back read-only

Elian Doranc8a9b994d673
diff --git a/apps/client/src/widgets/type_widgets/helpers/SplitEditor.tsx b/apps/client/src/widgets/type_widgets/helpers/SplitEditor.tsx
index 62c1b81618..64fffd1fc6 100644
--- a/apps/client/src/widgets/type_widgets/helpers/SplitEditor.tsx
+++ b/apps/client/src/widgets/type_widgets/helpers/SplitEditor.tsx
@@ -1,5 +1,5 @@
import { isMobile } from "../../../services/utils";
-import { useTriliumOption } from "../../react/hooks";
+import { useNoteLabel, useNoteLabelBoolean, useTriliumOption } from "../../react/hooks";
import { TypeWidgetProps } from "../type_widget";
import "./SplitEditor.css";
@@ -12,14 +12,19 @@ import "./SplitEditor.css";
* - Can display errors to the user via {@link setError}.
* - Horizontal or vertical orientation for the editor/preview split, adjustable via the switch split orientation button floating button.
*/
-export default function SplitEditor({ }: TypeWidgetProps) {
+export default function SplitEditor({ note }: TypeWidgetProps) {
const splitEditorOrientation = useSplitOrientation();
+ const [ readOnly ] = useNoteLabelBoolean(note, "readOnly");
+
return (
- <div className={`note-detail-split note-detail-printable ${"split-" + splitEditorOrientation}`}>
- <div className="note-detail-split-editor-col">
- <div className="note-detail-split-editor">Detail goes here.</div>
- <div className="admonition caution note-detail-error-container hidden-ext">Errors go here.</div>
- </div>
+ <div className={`note-detail-split note-detail-printable ${"split-" + splitEditorOrientation} ${readOnly ? "split-read-only" : ""}`}>
+ {!readOnly && (
+ <div className="note-detail-split-editor-col">
+ <div className="note-detail-split-editor">Detail goes here.</div>
+ <div className="admonition caution note-detail-error-container hidden-ext">Errors go here.</div>
+ </div>
+ )}
+
<div className="note-detail-split-preview-col">
<div className="note-detail-split-preview">Preview goes here</div>
<div className="btn-group btn-group-sm map-type-switcher content-floating-buttons preview-buttons bottom-right" role="group">Buttons go here</div>
diff --git a/apps/client/src/widgets/type_widgets_old/abstract_split_type_widget.ts b/apps/client/src/widgets/type_widgets_old/abstract_split_type_widget.ts
index bd2b3b567d..3850bd0830 100644
--- a/apps/client/src/widgets/type_widgets_old/abstract_split_type_widget.ts
+++ b/apps/client/src/widgets/type_widgets_old/abstract_split_type_widget.ts
@@ -85,12 +85,6 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget {
}
#adjustLayoutOrientation() {
- // Read-only
- const isReadOnly = this.note?.hasLabel("readOnly");
- if (this.isReadOnly !== isReadOnly) {
- this.$editorCol.toggle(!isReadOnly);
- }
-
// Vertical vs horizontal layout
if (this.layoutOrientation !== layoutOrientation || this.isReadOnly !== isReadOnly) {
this.$widget
diff --git a/packages/commons/src/lib/attribute_names.ts b/packages/commons/src/lib/attribute_names.ts
index ed527308a7..68fa1af3cf 100644
--- a/packages/commons/src/lib/attribute_names.ts
+++ b/packages/commons/src/lib/attribute_names.ts
@@ -29,7 +29,6 @@ type Labels = {
status: string;
pageSize: number;
geolocation: string;
- readOnly: boolean;
expanded: boolean;
"calendar:hideWeekends": boolean;
"calendar:weekNumbers": boolean;
@@ -42,6 +41,7 @@ type Labels = {
// Note-type specific
webViewSrc: string;
+ readOnly: boolean;
}
/**