mirror of
https://github.com/zadam/trilium.git
synced 2026-09-02 05:58:22 +02:00
chore(react): prototype for note context
This commit is contained in:
@@ -3,9 +3,9 @@ import Component, { TypedComponent } from "../components/component.js";
|
||||
import froca from "../services/froca.js";
|
||||
import { t } from "../services/i18n.js";
|
||||
import toastService from "../services/toast.js";
|
||||
import { renderReactWidget } from "./react/react_utils.jsx";
|
||||
import { EventNames, EventData } from "../components/app_context.js";
|
||||
import { Handler } from "leaflet";
|
||||
import { renderReactWidgetAtElement } from "./react/react_utils.jsx";
|
||||
import { type default as NoteContextType } from "../../components/note_context";
|
||||
import { EventData } from "../components/app_context.js";
|
||||
|
||||
export class TypedBasicWidget<T extends TypedComponent<any>> extends TypedComponent<T> {
|
||||
protected attrs: Record<string, string>;
|
||||
@@ -281,6 +281,8 @@ export function wrapReactWidgets<T extends TypedComponent<any>>(components: (T |
|
||||
export class ReactWrappedWidget extends BasicWidget {
|
||||
|
||||
private el: VNode;
|
||||
private noteContext: NoteContextType | null;
|
||||
private fragment: DocumentFragment = new DocumentFragment();
|
||||
|
||||
constructor(el: VNode) {
|
||||
super();
|
||||
@@ -288,7 +290,30 @@ export class ReactWrappedWidget extends BasicWidget {
|
||||
}
|
||||
|
||||
doRender() {
|
||||
this.$widget = renderReactWidget(this, this.el);
|
||||
renderReactWidgetAtElement({
|
||||
parentComponent: this,
|
||||
noteContext: this.noteContext
|
||||
}, this.el, this.fragment);
|
||||
this.$widget = $(this.fragment);
|
||||
}
|
||||
|
||||
activeContextChangedEvent({ noteContext }: EventData<"activeContextChanged">) {
|
||||
this.noteContext = noteContext;
|
||||
this.doRender();
|
||||
}
|
||||
|
||||
setNoteContextEvent({ noteContext }: EventData<"setNoteContext">) {
|
||||
this.noteContext = noteContext;
|
||||
this.doRender();
|
||||
}
|
||||
|
||||
noteSwitchedAndActivatedEvent({ noteContext }: EventData<"noteSwitchedAndActivated">) {
|
||||
this.noteContext = noteContext;
|
||||
this.doRender();
|
||||
}
|
||||
|
||||
noteSwitchedEvent({ noteContext }: EventData<"noteSwitched">) {
|
||||
this.doRender();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user