diff --git a/apps/client/src/widgets/ribbon/InheritedAttributesTab.tsx b/apps/client/src/widgets/ribbon/InheritedAttributesTab.tsx new file mode 100644 index 000000000..9bf9692f7 --- /dev/null +++ b/apps/client/src/widgets/ribbon/InheritedAttributesTab.tsx @@ -0,0 +1,56 @@ +import { useEffect, useState } from "preact/hooks"; +import { TabContext } from "./ribbon-interface"; +import FAttribute from "../../entities/fattribute"; +import { useTriliumEventBeta } from "../react/hooks"; +import attributes from "../../services/attributes"; +import { t } from "../../services/i18n"; +import attribute_renderer from "../../services/attribute_renderer"; +import RawHtml from "../react/RawHtml"; +import { joinElements } from "../react/react_utils"; + +export default function InheritedAttributesTab({ note, componentId }: TabContext) { + const [ inheritedAttributes, setInheritedAttributes ] = useState(); + + function refresh() { + const attrs = note.getAttributes().filter((attr) => attr.noteId !== this.noteId); + attrs.sort((a, b) => { + if (a.noteId === b.noteId) { + return a.position - b.position; + } else { + // inherited attributes should stay grouped: https://github.com/zadam/trilium/issues/3761 + return a.noteId < b.noteId ? -1 : 1; + } + }); + + setInheritedAttributes(attrs); + } + + useEffect(refresh, [ note ]); + useTriliumEventBeta("entitiesReloaded", ({ loadResults }) => { + if (loadResults.getAttributeRows(componentId).find((attr) => attributes.isAffecting(attr, this.note))) { + this.refresh(); + } + }); + + return ( +
+
+ {inheritedAttributes?.length > 0 ? ( + joinElements(inheritedAttributes.map(attribute => ( + + )), " ") + ) : ( + <>{t("inherited_attribute_list.no_inherited_attributes")} + )} +
+
+ ) +} +function InheritedAttribute({ attribute }: { attribute: FAttribute }) { + const [ html, setHtml ] = useState | string>(""); + useEffect(() => { + attribute_renderer.renderAttribute(attribute, false).then(setHtml); + }, []); + + return +} \ No newline at end of file diff --git a/apps/client/src/widgets/ribbon/Ribbon.tsx b/apps/client/src/widgets/ribbon/Ribbon.tsx index 74e1d19b4..52887938a 100644 --- a/apps/client/src/widgets/ribbon/Ribbon.tsx +++ b/apps/client/src/widgets/ribbon/Ribbon.tsx @@ -20,6 +20,7 @@ import ImagePropertiesTab from "./ImagePropertiesTab"; import NotePathsTab from "./NotePathsTab"; import NoteMapTab from "./NoteMapTab"; import OwnedAttributesTab from "./OwnedAttributesTab"; +import InheritedAttributesTab from "./InheritedAttributesTab"; interface TitleContext { note: FNote | null | undefined; @@ -113,9 +114,11 @@ const TAB_CONFIGURATION = numberObjectsInPlace([ toggleCommand: "toggleRibbonTabOwnedAttributes" }, { - // InheritedAttributesWidget title: t("inherited_attribute_list.title"), - icon: "bx bx-list-plus" + icon: "bx bx-list-plus", + content: InheritedAttributesTab, + show: ({note}) => !note?.isLaunchBarConfig(), + toggleCommand: "toggleRibbonTabInheritedAttributes" }, { title: t("note_paths.title"), diff --git a/apps/client/src/widgets/ribbon/style.css b/apps/client/src/widgets/ribbon/style.css index b66302a42..9b89090d5 100644 --- a/apps/client/src/widgets/ribbon/style.css +++ b/apps/client/src/widgets/ribbon/style.css @@ -336,4 +336,17 @@ contain: none; } +/* #endregion */ + +/* #region Inherited attributes */ +.inherited-attributes-widget { + position: relative; +} + +.inherited-attributes-container { + color: var(--muted-text-color); + max-height: 200px; + overflow: auto; + padding: 14px 12px 13px 12px; +} /* #endregion */ \ No newline at end of file diff --git a/apps/client/src/widgets/ribbon_widgets/inherited_attribute_list.ts b/apps/client/src/widgets/ribbon_widgets/inherited_attribute_list.ts index 5524e0531..764d4cce4 100644 --- a/apps/client/src/widgets/ribbon_widgets/inherited_attribute_list.ts +++ b/apps/client/src/widgets/ribbon_widgets/inherited_attribute_list.ts @@ -6,37 +6,10 @@ import { t } from "../../services/i18n.js"; import type FNote from "../../entities/fnote.js"; import type { EventData } from "../../components/app_context.js"; -const TPL = /*html*/` -
- - -
-
`; - export default class InheritedAttributesWidget extends NoteContextAwareWidget { private attributeDetailWidget: AttributeDetailWidget; - private $container!: JQuery; - - get name() { - return "inheritedAttributes"; - } - - get toggleCommand() { - return "toggleRibbonTabInheritedAttributes"; - } constructor() { super(); @@ -46,32 +19,15 @@ export default class InheritedAttributesWidget extends NoteContextAwareWidget { this.child(this.attributeDetailWidget); } - getTitle() { - return { - show: !this.note?.isLaunchBarConfig() - }; - } - doRender() { - this.$widget = $(TPL); this.contentSized(); - this.$container = this.$widget.find(".inherited-attributes-container"); this.$widget.append(this.attributeDetailWidget.render()); } async refreshWithNote(note: FNote) { - this.$container.empty(); - - const inheritedAttributes = this.getInheritedAttributes(note); - - if (inheritedAttributes.length === 0) { - this.$container.append(t("inherited_attribute_list.no_inherited_attributes")); - return; - } - for (const attribute of inheritedAttributes) { - const $attr = (await attributeRenderer.renderAttribute(attribute, false)).on("click", (e) => { + .on("click", (e) => { setTimeout( () => this.attributeDetailWidget.showAttributeDetail({ @@ -89,29 +45,6 @@ export default class InheritedAttributesWidget extends NoteContextAwareWidget { 100 ); }); - - this.$container.append($attr).append(" "); - } - } - - getInheritedAttributes(note: FNote) { - const attrs = note.getAttributes().filter((attr) => attr.noteId !== this.noteId); - - attrs.sort((a, b) => { - if (a.noteId === b.noteId) { - return a.position - b.position; - } else { - // inherited attributes should stay grouped: https://github.com/zadam/trilium/issues/3761 - return a.noteId < b.noteId ? -1 : 1; - } - }); - - return attrs; - } - - entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) { - if (loadResults.getAttributeRows(this.componentId).find((attr) => attributeService.isAffecting(attr, this.note))) { - this.refresh(); } } }