|
1 | 1 | import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks"; |
2 | | -import { t } from "../../services/i18n"; |
3 | 2 | import { useNoteContext, useNoteProperty, useStaticTooltipWithKeyboardShortcut, useTriliumEvents } from "../react/hooks"; |
4 | 3 | import "./style.css"; |
5 | | -import { VNode } from "preact"; |
6 | | -import BasicPropertiesTab from "./BasicPropertiesTab"; |
7 | | -import FormattingToolbar from "./FormattingToolbar"; |
| 4 | + |
8 | 5 | import { numberObjectsInPlace } from "../../services/utils"; |
9 | | -import { TabContext } from "./ribbon-interface"; |
10 | | -import options from "../../services/options"; |
11 | 6 | import { EventNames } from "../../components/app_context"; |
12 | | -import FNote from "../../entities/fnote"; |
13 | | -import ScriptTab from "./ScriptTab"; |
14 | | -import EditedNotesTab from "./EditedNotesTab"; |
15 | | -import NotePropertiesTab from "./NotePropertiesTab"; |
16 | | -import NoteInfoTab from "./NoteInfoTab"; |
17 | | -import SimilarNotesTab from "./SimilarNotesTab"; |
18 | | -import FilePropertiesTab from "./FilePropertiesTab"; |
19 | | -import ImagePropertiesTab from "./ImagePropertiesTab"; |
20 | | -import NotePathsTab from "./NotePathsTab"; |
21 | | -import NoteMapTab from "./NoteMapTab"; |
22 | | -import OwnedAttributesTab from "./OwnedAttributesTab"; |
23 | | -import InheritedAttributesTab from "./InheritedAttributesTab"; |
24 | | -import CollectionPropertiesTab from "./CollectionPropertiesTab"; |
25 | | -import SearchDefinitionTab from "./SearchDefinitionTab"; |
26 | 7 | import NoteActions from "./NoteActions"; |
27 | 8 | import { KeyboardActionNames } from "@triliumnext/commons"; |
| 9 | +import { RIBBON_TAB_DEFINITIONS } from "./RibbonDefinition"; |
| 10 | +import { TabConfiguration, TitleContext } from "./ribbon-interface"; |
28 | 11 |
|
29 | | -interface TitleContext { |
30 | | - note: FNote | null | undefined; |
31 | | -} |
32 | | - |
33 | | -interface TabConfiguration { |
34 | | - title: string | ((context: TitleContext) => string); |
35 | | - icon: string; |
36 | | - content: (context: TabContext) => VNode | false; |
37 | | - show: boolean | ((context: TitleContext) => boolean | null | undefined); |
38 | | - toggleCommand?: KeyboardActionNames; |
39 | | - activate?: boolean | ((context: TitleContext) => boolean); |
40 | | - /** |
41 | | - * By default the tab content will not be rendered unless the tab is active (i.e. selected by the user). Setting to `true` will ensure that the tab is rendered even when inactive, for cases where the tab needs to be accessible at all times (e.g. for the detached editor toolbar) or if event handling is needed. |
42 | | - */ |
43 | | - stayInDom?: boolean; |
44 | | -} |
45 | | - |
46 | | -const TAB_CONFIGURATION = numberObjectsInPlace<TabConfiguration>([ |
47 | | - { |
48 | | - title: t("classic_editor_toolbar.title"), |
49 | | - icon: "bx bx-text", |
50 | | - show: ({ note }) => note?.type === "text" && options.get("textNoteEditorType") === "ckeditor-classic", |
51 | | - toggleCommand: "toggleRibbonTabClassicEditor", |
52 | | - content: FormattingToolbar, |
53 | | - activate: true, |
54 | | - stayInDom: true |
55 | | - }, |
56 | | - { |
57 | | - title: ({ note }) => note?.isTriliumSqlite() ? t("script_executor.query") : t("script_executor.script"), |
58 | | - icon: "bx bx-play", |
59 | | - content: ScriptTab, |
60 | | - activate: true, |
61 | | - show: ({ note }) => note && |
62 | | - (note.isTriliumScript() || note.isTriliumSqlite()) && |
63 | | - (note.hasLabel("executeDescription") || note.hasLabel("executeButton")) |
64 | | - }, |
65 | | - { |
66 | | - title: t("search_definition.search_parameters"), |
67 | | - icon: "bx bx-search", |
68 | | - content: SearchDefinitionTab, |
69 | | - activate: true, |
70 | | - show: ({ note }) => note?.type === "search" |
71 | | - }, |
72 | | - { |
73 | | - title: t("edited_notes.title"), |
74 | | - icon: "bx bx-calendar-edit", |
75 | | - content: EditedNotesTab, |
76 | | - show: ({ note }) => note?.hasOwnedLabel("dateNote"), |
77 | | - activate: ({ note }) => (note?.getPromotedDefinitionAttributes().length === 0 || !options.is("promotedAttributesOpenInRibbon")) && options.is("editedNotesOpenInRibbon") |
78 | | - }, |
79 | | - { |
80 | | - title: t("book_properties.book_properties"), |
81 | | - icon: "bx bx-book", |
82 | | - content: CollectionPropertiesTab, |
83 | | - show: ({ note }) => note?.type === "book" || note?.type === "search", |
84 | | - toggleCommand: "toggleRibbonTabBookProperties" |
85 | | - }, |
86 | | - { |
87 | | - title: t("note_properties.info"), |
88 | | - icon: "bx bx-info-square", |
89 | | - content: NotePropertiesTab, |
90 | | - show: ({ note }) => !!note?.getLabelValue("pageUrl"), |
91 | | - activate: true |
92 | | - }, |
93 | | - { |
94 | | - title: t("file_properties.title"), |
95 | | - icon: "bx bx-file", |
96 | | - content: FilePropertiesTab, |
97 | | - show: ({ note }) => note?.type === "file", |
98 | | - toggleCommand: "toggleRibbonTabFileProperties", |
99 | | - activate: ({ note }) => note?.mime !== "application/pdf" |
100 | | - }, |
101 | | - { |
102 | | - title: t("image_properties.title"), |
103 | | - icon: "bx bx-image", |
104 | | - content: ImagePropertiesTab, |
105 | | - show: ({ note }) => note?.type === "image", |
106 | | - toggleCommand: "toggleRibbonTabImageProperties", |
107 | | - activate: true, |
108 | | - }, |
109 | | - { |
110 | | - // BasicProperties |
111 | | - title: t("basic_properties.basic_properties"), |
112 | | - icon: "bx bx-slider", |
113 | | - content: BasicPropertiesTab, |
114 | | - show: ({note}) => !note?.isLaunchBarConfig(), |
115 | | - toggleCommand: "toggleRibbonTabBasicProperties" |
116 | | - }, |
117 | | - { |
118 | | - title: t("owned_attribute_list.owned_attributes"), |
119 | | - icon: "bx bx-list-check", |
120 | | - content: OwnedAttributesTab, |
121 | | - show: ({note}) => !note?.isLaunchBarConfig(), |
122 | | - toggleCommand: "toggleRibbonTabOwnedAttributes", |
123 | | - stayInDom: true |
124 | | - }, |
125 | | - { |
126 | | - title: t("inherited_attribute_list.title"), |
127 | | - icon: "bx bx-list-plus", |
128 | | - content: InheritedAttributesTab, |
129 | | - show: ({note}) => !note?.isLaunchBarConfig(), |
130 | | - toggleCommand: "toggleRibbonTabInheritedAttributes" |
131 | | - }, |
132 | | - { |
133 | | - title: t("note_paths.title"), |
134 | | - icon: "bx bx-collection", |
135 | | - content: NotePathsTab, |
136 | | - show: true, |
137 | | - toggleCommand: "toggleRibbonTabNotePaths" |
138 | | - }, |
139 | | - { |
140 | | - title: t("note_map.title"), |
141 | | - icon: "bx bxs-network-chart", |
142 | | - content: NoteMapTab, |
143 | | - show: true, |
144 | | - toggleCommand: "toggleRibbonTabNoteMap" |
145 | | - }, |
146 | | - { |
147 | | - title: t("similar_notes.title"), |
148 | | - icon: "bx bx-bar-chart", |
149 | | - show: ({ note }) => note?.type !== "search" && !note?.isLabelTruthy("similarNotesWidgetDisabled"), |
150 | | - content: SimilarNotesTab, |
151 | | - toggleCommand: "toggleRibbonTabSimilarNotes" |
152 | | - }, |
153 | | - { |
154 | | - title: t("note_info_widget.title"), |
155 | | - icon: "bx bx-info-circle", |
156 | | - show: ({ note }) => !!note, |
157 | | - content: NoteInfoTab, |
158 | | - toggleCommand: "toggleRibbonTabNoteInfo" |
159 | | - } |
160 | | -]); |
| 12 | +const TAB_CONFIGURATION = numberObjectsInPlace<TabConfiguration>(RIBBON_TAB_DEFINITIONS); |
161 | 13 |
|
162 | 14 | export default function Ribbon() { |
163 | 15 | const { note, ntxId, hoistedNoteId, notePath, noteContext, componentId } = useNoteContext(); |
|
0 commit comments