mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	feat(mermaid): add basic support for vertical layout
This commit is contained in:
		| @@ -89,6 +89,7 @@ import ContextualHelpButton from "../widgets/floating_buttons/help_button.js"; | |||||||
| import CloseZenButton from "../widgets/close_zen_button.js"; | import CloseZenButton from "../widgets/close_zen_button.js"; | ||||||
| import type { AppContext } from "./../components/app_context.js"; | import type { AppContext } from "./../components/app_context.js"; | ||||||
| import type { WidgetsByParent } from "../services/bundle.js"; | import type { WidgetsByParent } from "../services/bundle.js"; | ||||||
|  | import SwitchSplitOrientationButton from "../widgets/floating_buttons/switch_layout_button.js"; | ||||||
|  |  | ||||||
| export default class DesktopLayout { | export default class DesktopLayout { | ||||||
|  |  | ||||||
| @@ -202,6 +203,7 @@ export default class DesktopLayout { | |||||||
|                                                         .child(new WatchedFileUpdateStatusWidget()) |                                                         .child(new WatchedFileUpdateStatusWidget()) | ||||||
|                                                         .child( |                                                         .child( | ||||||
|                                                             new FloatingButtons() |                                                             new FloatingButtons() | ||||||
|  |                                                                 .child(new SwitchSplitOrientationButton()) | ||||||
|                                                                 .child(new EditButton()) |                                                                 .child(new EditButton()) | ||||||
|                                                                 .child(new ShowTocWidgetButton()) |                                                                 .child(new ShowTocWidgetButton()) | ||||||
|                                                                 .child(new ShowHighlightsListWidgetButton()) |                                                                 .child(new ShowHighlightsListWidgetButton()) | ||||||
|   | |||||||
| @@ -0,0 +1,38 @@ | |||||||
|  | import options from "../../services/options.js"; | ||||||
|  | import NoteContextAwareWidget from "../note_context_aware_widget.js"; | ||||||
|  |  | ||||||
|  | const TPL = ` | ||||||
|  | <button type="button" | ||||||
|  |     class="switch-layout-button" | ||||||
|  |     title="Switch layout"> | ||||||
|  |     <span class="bx bxs-dock-bottom"></span> | ||||||
|  | </button> | ||||||
|  | `; | ||||||
|  |  | ||||||
|  | export default class SwitchSplitOrientationButton extends NoteContextAwareWidget { | ||||||
|  |     isEnabled() { | ||||||
|  |         return super.isEnabled() | ||||||
|  |             && ["mermaid"].includes(this.note?.type ?? "") | ||||||
|  |             && this.note?.isContentAvailable() | ||||||
|  |             && this.noteContext?.viewScope?.viewMode === "default"; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     doRender(): void { | ||||||
|  |         super.doRender(); | ||||||
|  |  | ||||||
|  |         this.$widget = $(TPL); | ||||||
|  |         this.$widget.on("click", () => { | ||||||
|  |             const currentOrientation = options.get("splitEditorOrientation"); | ||||||
|  |             options.save("splitEditorOrientation", toggleOrientation(currentOrientation)); | ||||||
|  |         }); | ||||||
|  |         this.contentSized(); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | function toggleOrientation(orientation: string) { | ||||||
|  |     if (orientation === "horizontal") { | ||||||
|  |         return "vertical"; | ||||||
|  |     } else { | ||||||
|  |         return "horizontal"; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -4,9 +4,11 @@ import EditableCodeTypeWidget from "./editable_code.js"; | |||||||
| import TypeWidget from "./type_widget.js"; | import TypeWidget from "./type_widget.js"; | ||||||
| import Split from "split.js"; | import Split from "split.js"; | ||||||
| import { DEFAULT_GUTTER_SIZE } from "../../services/resizer.js"; | import { DEFAULT_GUTTER_SIZE } from "../../services/resizer.js"; | ||||||
|  | import options from "../../services/options.js"; | ||||||
|  | import type SwitchSplitOrientationButton from "../floating_buttons/switch_layout_button.js"; | ||||||
|  |  | ||||||
| const TPL = `\ | const TPL = `\ | ||||||
| <div class="note-detail-split note-detail-printable split-horizontal"> | <div class="note-detail-split note-detail-printable"> | ||||||
|     <div class="note-detail-split-first-col"> |     <div class="note-detail-split-first-col"> | ||||||
|         <div class="note-detail-split-editor"></div> |         <div class="note-detail-split-editor"></div> | ||||||
|         <div class="note-detail-error-container alert alert-warning hidden-ext"></div> |         <div class="note-detail-error-container alert alert-warning hidden-ext"></div> | ||||||
| @@ -37,6 +39,7 @@ const TPL = `\ | |||||||
|  |  | ||||||
|         .note-detail-split .note-detail-split-preview { |         .note-detail-split .note-detail-split-preview { | ||||||
|             transition: opacity 250ms ease-in-out; |             transition: opacity 250ms ease-in-out; | ||||||
|  |             height: 100%; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         .note-detail-split .note-detail-split-preview.on-error { |         .note-detail-split .note-detail-split-preview.on-error { | ||||||
| @@ -58,13 +61,28 @@ const TPL = `\ | |||||||
|             height: 100%; |             height: 100%; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         .note-detail-split-first-col { |         .note-detail-split.split-horizontal .note-detail-split-first-col { | ||||||
|             flex-direction: column; |             flex-direction: column; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         /* Vertical layout */ |         /* Vertical layout */ | ||||||
|  |  | ||||||
|  |         .note-detail-split.split-vertical { | ||||||
|  |             flex-direction: column; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         .note-detail-split.split-vertical > div { | ||||||
|  |             width: 100%; | ||||||
|  |             height: 50%; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         .note-detail-split.split-vertical > .note-detail-split-first-col { | ||||||
|  |             border-top: 1px solid var(--main-border-color); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         .note-detail-split.split-vertical .note-detail-split-second-col { | ||||||
|  |             order: -1; | ||||||
|  |         } | ||||||
|     </style> |     </style> | ||||||
| </div> | </div> | ||||||
| `; | `; | ||||||
| @@ -76,6 +94,7 @@ const TPL = `\ | |||||||
|  * |  * | ||||||
|  * - The two panes are resizeable via a split, on desktop. The split can be optionally customized via {@link buildSplitExtraOptions}. |  * - The two panes are resizeable via a split, on desktop. The split can be optionally customized via {@link buildSplitExtraOptions}. | ||||||
|  * - Can display errors to the user via {@link setError}. |  * - Can display errors to the user via {@link setError}. | ||||||
|  |  * - Horizontal or vertical orientation for the editor/preview split, adjustable via {@link SwitchSplitOrientationButton}. | ||||||
|  */ |  */ | ||||||
| export default abstract class AbstractSplitTypeWidget extends TypeWidget { | export default abstract class AbstractSplitTypeWidget extends TypeWidget { | ||||||
|  |  | ||||||
| @@ -87,6 +106,7 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget { | |||||||
|     private $editor!: JQuery<HTMLElement>; |     private $editor!: JQuery<HTMLElement>; | ||||||
|     private $errorContainer!: JQuery<HTMLElement>; |     private $errorContainer!: JQuery<HTMLElement>; | ||||||
|     private editorTypeWidget: EditableCodeTypeWidget; |     private editorTypeWidget: EditableCodeTypeWidget; | ||||||
|  |     private layoutOrientation!: "horizontal" | "vertical"; | ||||||
|  |  | ||||||
|     constructor() { |     constructor() { | ||||||
|         super(); |         super(); | ||||||
| @@ -98,6 +118,10 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget { | |||||||
|     doRender(): void { |     doRender(): void { | ||||||
|         this.$widget = $(TPL); |         this.$widget = $(TPL); | ||||||
|  |  | ||||||
|  |         const layoutOrientation = options.get("splitEditorOrientation") ?? "horizontal"; | ||||||
|  |         this.$widget.addClass(`split-${layoutOrientation}`); | ||||||
|  |         this.layoutOrientation = layoutOrientation as ("horizontal" | "vertical"); | ||||||
|  |  | ||||||
|         this.$firstCol = this.$widget.find(".note-detail-split-first-col"); |         this.$firstCol = this.$widget.find(".note-detail-split-first-col"); | ||||||
|         this.$secondCol = this.$widget.find(".note-detail-split-second-col"); |         this.$secondCol = this.$widget.find(".note-detail-split-second-col"); | ||||||
|         this.$preview = this.$widget.find(".note-detail-split-preview"); |         this.$preview = this.$widget.find(".note-detail-split-preview"); | ||||||
| @@ -132,7 +156,7 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget { | |||||||
|         this.splitInstance?.destroy(); |         this.splitInstance?.destroy(); | ||||||
|         this.splitInstance = Split([ this.$firstCol[0], this.$secondCol[0] ], { |         this.splitInstance = Split([ this.$firstCol[0], this.$secondCol[0] ], { | ||||||
|             sizes: [ 50, 50 ], |             sizes: [ 50, 50 ], | ||||||
|             direction: "horizontal", |             direction: this.layoutOrientation, | ||||||
|             gutterSize: DEFAULT_GUTTER_SIZE, |             gutterSize: DEFAULT_GUTTER_SIZE, | ||||||
|             ...this.buildSplitExtraOptions() |             ...this.buildSplitExtraOptions() | ||||||
|         }); |         }); | ||||||
| @@ -163,4 +187,5 @@ export default abstract class AbstractSplitTypeWidget extends TypeWidget { | |||||||
|     getData() { |     getData() { | ||||||
|         return this.editorTypeWidget.getData(); |         return this.editorTypeWidget.getData(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -10,7 +10,7 @@ import { listSyntaxHighlightingThemes } from "../../services/code_block_theme.js | |||||||
| import type { OptionNames } from "../../services/options_interface.js"; | import type { OptionNames } from "../../services/options_interface.js"; | ||||||
|  |  | ||||||
| // options allowed to be updated directly in the Options dialog | // options allowed to be updated directly in the Options dialog | ||||||
| const ALLOWED_OPTIONS = new Set([ | const ALLOWED_OPTIONS = new Set<OptionNames>([ | ||||||
|     "eraseEntitiesAfterTimeInSeconds", |     "eraseEntitiesAfterTimeInSeconds", | ||||||
|     "eraseEntitiesAfterTimeScale", |     "eraseEntitiesAfterTimeScale", | ||||||
|     "protectedSessionTimeout", |     "protectedSessionTimeout", | ||||||
| @@ -78,7 +78,8 @@ const ALLOWED_OPTIONS = new Set([ | |||||||
|     "backgroundEffects", |     "backgroundEffects", | ||||||
|     "allowedHtmlTags", |     "allowedHtmlTags", | ||||||
|     "redirectBareDomain", |     "redirectBareDomain", | ||||||
|     "showLoginInShareTheme" |     "showLoginInShareTheme", | ||||||
|  |     "splitEditorOrientation" | ||||||
| ]); | ]); | ||||||
|  |  | ||||||
| function getOptions() { | function getOptions() { | ||||||
| @@ -163,7 +164,10 @@ function getSupportedLocales() { | |||||||
| } | } | ||||||
|  |  | ||||||
| function isAllowed(name: string) { | function isAllowed(name: string) { | ||||||
|     return ALLOWED_OPTIONS.has(name) || name.startsWith("keyboardShortcuts") || name.endsWith("Collapsed") || name.startsWith("hideArchivedNotes"); |     return (ALLOWED_OPTIONS as Set<string>).has(name) | ||||||
|  |         || name.startsWith("keyboardShortcuts") | ||||||
|  |         || name.endsWith("Collapsed") | ||||||
|  |         || name.startsWith("hideArchivedNotes"); | ||||||
| } | } | ||||||
|  |  | ||||||
| export default { | export default { | ||||||
|   | |||||||
| @@ -132,6 +132,9 @@ const defaultOptions: DefaultOption[] = [ | |||||||
|     { name: "promotedAttributesOpenInRibbon", value: "true", isSynced: true }, |     { name: "promotedAttributesOpenInRibbon", value: "true", isSynced: true }, | ||||||
|     { name: "editedNotesOpenInRibbon", value: "true", isSynced: true }, |     { name: "editedNotesOpenInRibbon", value: "true", isSynced: true }, | ||||||
|  |  | ||||||
|  |     // Appearance | ||||||
|  |     { name: "splitEditorOrientation", value: "horizontal", isSynced: true }, | ||||||
|  |  | ||||||
|     // Internationalization |     // Internationalization | ||||||
|     { name: "locale", value: "en", isSynced: true }, |     { name: "locale", value: "en", isSynced: true }, | ||||||
|     { name: "firstDayOfWeek", value: "1", isSynced: true }, |     { name: "firstDayOfWeek", value: "1", isSynced: true }, | ||||||
|   | |||||||
| @@ -45,6 +45,7 @@ export interface OptionDefinitions extends KeyboardShortcutsOptions<KeyboardActi | |||||||
|     passwordVerificationSalt: string; |     passwordVerificationSalt: string; | ||||||
|     passwordDerivedKeySalt: string; |     passwordDerivedKeySalt: string; | ||||||
|     encryptedDataKey: string; |     encryptedDataKey: string; | ||||||
|  |     hoistedNoteId: string; | ||||||
|  |  | ||||||
|     lastSyncedPull: number; |     lastSyncedPull: number; | ||||||
|     lastSyncedPush: number; |     lastSyncedPush: number; | ||||||
| @@ -73,6 +74,9 @@ export interface OptionDefinitions extends KeyboardShortcutsOptions<KeyboardActi | |||||||
|     firstDayOfWeek: number; |     firstDayOfWeek: number; | ||||||
|     languages: string; |     languages: string; | ||||||
|  |  | ||||||
|  |     // Appearance | ||||||
|  |     splitEditorOrientation: "horziontal" | "vertical"; | ||||||
|  |  | ||||||
|     initialized: boolean; |     initialized: boolean; | ||||||
|     isPasswordSet: boolean; |     isPasswordSet: boolean; | ||||||
|     overrideThemeFonts: boolean; |     overrideThemeFonts: boolean; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user