diff --git a/src/public/app/widgets/attribute_widgets/attribute_detail.ts b/src/public/app/widgets/attribute_widgets/attribute_detail.ts index 866cff805..2a3f3e2b4 100644 --- a/src/public/app/widgets/attribute_widgets/attribute_detail.ts +++ b/src/public/app/widgets/attribute_widgets/attribute_detail.ts @@ -288,7 +288,7 @@ const ATTR_HELP: Record> = { }; interface AttributeDetailOpts { - allAttributes: Attribute[]; + allAttributes?: Attribute[]; attribute: Attribute; isOwned: boolean; x: number; @@ -338,7 +338,7 @@ export default class AttributeDetailWidget extends NoteContextAwareWidget { private relatedNotesSpacedUpdate!: SpacedUpdate; private attribute!: Attribute; - private allAttributes!: Attribute[]; + private allAttributes?: Attribute[]; private attrType!: ReturnType; async refresh() { @@ -434,7 +434,7 @@ export default class AttributeDetailWidget extends NoteContextAwareWidget { this.attribute.value = pathChunks[pathChunks.length - 1]; // noteId - this.triggerCommand("updateAttributeList", { attributes: this.allAttributes }); + this.triggerCommand("updateAttributeList", { attributes: this.allAttributes ?? [] }); this.updateRelatedNotes(); }); @@ -454,7 +454,7 @@ export default class AttributeDetailWidget extends NoteContextAwareWidget { this.$deleteButton = this.$widget.find(".attr-delete-button"); this.$deleteButton.on("click", async () => { await this.triggerCommand("updateAttributeList", { - attributes: this.allAttributes.filter((attr) => attr !== this.attribute) + attributes: (this.allAttributes || []).filter((attr) => attr !== this.attribute) }); await this.triggerCommand("saveAttributes"); @@ -714,7 +714,7 @@ export default class AttributeDetailWidget extends NoteContextAwareWidget { this.attribute.value = String(this.$inputValue.val()); } - this.triggerCommand("updateAttributeList", { attributes: this.allAttributes }); + this.triggerCommand("updateAttributeList", { attributes: this.allAttributes ?? [] }); } buildDefinitionValue() { diff --git a/src/public/app/widgets/ribbon_widgets/inherited_attribute_list.js b/src/public/app/widgets/ribbon_widgets/inherited_attribute_list.ts similarity index 88% rename from src/public/app/widgets/ribbon_widgets/inherited_attribute_list.js rename to src/public/app/widgets/ribbon_widgets/inherited_attribute_list.ts index 6e6f435ed..667f12753 100644 --- a/src/public/app/widgets/ribbon_widgets/inherited_attribute_list.js +++ b/src/public/app/widgets/ribbon_widgets/inherited_attribute_list.ts @@ -3,6 +3,8 @@ import AttributeDetailWidget from "../attribute_widgets/attribute_detail.js"; import attributeRenderer from "../../services/attribute_renderer.js"; import attributeService from "../../services/attributes.js"; import { t } from "../../services/i18n.js"; +import type FNote from "../../entities/fnote.js"; +import type { EventData } from "../../components/app_context.js"; const TPL = `
@@ -10,7 +12,7 @@ const TPL = ` .inherited-attributes-widget { position: relative; } - + .inherited-attributes-container { color: var(--muted-text-color); max-height: 200px; @@ -23,6 +25,11 @@ const TPL = `
`; export default class InheritedAttributesWidget extends NoteContextAwareWidget { + + private attributeDetailWidget: AttributeDetailWidget; + + private $container!: JQuery; + get name() { return "inheritedAttributes"; } @@ -34,7 +41,6 @@ export default class InheritedAttributesWidget extends NoteContextAwareWidget { constructor() { super(); - /** @type {AttributeDetailWidget} */ this.attributeDetailWidget = new AttributeDetailWidget().contentSized().setParent(this); this.child(this.attributeDetailWidget); @@ -42,7 +48,7 @@ export default class InheritedAttributesWidget extends NoteContextAwareWidget { getTitle() { return { - show: !this.note.isLaunchBarConfig(), + show: !this.note?.isLaunchBarConfig(), title: t("inherited_attribute_list.title"), icon: "bx bx-list-plus" }; @@ -56,7 +62,7 @@ export default class InheritedAttributesWidget extends NoteContextAwareWidget { this.$widget.append(this.attributeDetailWidget.render()); } - async refreshWithNote(note) { + async refreshWithNote(note: FNote) { this.$container.empty(); const inheritedAttributes = this.getInheritedAttributes(note); @@ -90,7 +96,7 @@ export default class InheritedAttributesWidget extends NoteContextAwareWidget { } } - getInheritedAttributes(note) { + getInheritedAttributes(note: FNote) { const attrs = note.getAttributes().filter((attr) => attr.noteId !== this.noteId); attrs.sort((a, b) => { @@ -105,7 +111,7 @@ export default class InheritedAttributesWidget extends NoteContextAwareWidget { return attrs; } - entitiesReloadedEvent({ loadResults }) { + entitiesReloadedEvent({ loadResults }: EventData<"entitiesReloaded">) { if (loadResults.getAttributeRows(this.componentId).find((attr) => attributeService.isAffecting(attr, this.note))) { this.refresh(); }