mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-01 20:52:27 +08:00
chore(client/ts): port some more files
This commit is contained in:
parent
62706a6af2
commit
7f4f8bcc75
@ -25,6 +25,7 @@ import type { default as NoteContext, GetTextEditorCallback } from "./note_conte
|
||||
import type { ContextMenuEvent } from "../menus/context_menu.js";
|
||||
import type TypeWidget from "../widgets/type_widgets/type_widget.js";
|
||||
import type EditableTextTypeWidget from "../widgets/type_widgets/editable_text.js";
|
||||
import type FAttribute from "../entities/fattribute.js";
|
||||
|
||||
interface Layout {
|
||||
getRootWidget: (appContext: AppContext) => RootWidget;
|
||||
@ -245,7 +246,7 @@ export type CommandMappings = {
|
||||
|
||||
toggleZenMode: CommandData;
|
||||
|
||||
updateAttributeList: CommandData & { attributes: Attribute[] };
|
||||
updateAttributeList: CommandData & { attributes: FAttribute[] };
|
||||
saveAttributes: CommandData;
|
||||
reloadAttributes: CommandData;
|
||||
refreshNoteList: CommandData & { noteId: string };
|
||||
|
@ -28,7 +28,7 @@ const TPL = `
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
type ConfirmDialogCallback = (val: false | ConfirmDialogOptions) => void;
|
||||
export type ConfirmDialogCallback = (val?: false | ConfirmDialogOptions) => void;
|
||||
|
||||
export interface ConfirmDialogOptions {
|
||||
confirmed: boolean;
|
||||
|
@ -1,7 +1,9 @@
|
||||
import type { EventData } from "../../components/app_context.js";
|
||||
import { t } from "../../services/i18n.js";
|
||||
import utils from "../../services/utils.js";
|
||||
import BasicWidget from "../basic_widget.js";
|
||||
import { Modal } from "bootstrap";
|
||||
import type { ConfirmDialogCallback } from "./confirm.js";
|
||||
|
||||
const TPL = `
|
||||
<div class="info-dialog modal mx-auto" tabindex="-1" role="dialog" style="z-index: 2000;">
|
||||
@ -22,6 +24,13 @@ const TPL = `
|
||||
</div>`;
|
||||
|
||||
export default class InfoDialog extends BasicWidget {
|
||||
|
||||
private resolve: ConfirmDialogCallback | null;
|
||||
private modal!: bootstrap.Modal;
|
||||
private $originallyFocused!: JQuery<HTMLElement> | null;
|
||||
private $infoContent!: JQuery<HTMLElement>;
|
||||
private $okButton!: JQuery<HTMLElement>;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
@ -31,7 +40,7 @@ export default class InfoDialog extends BasicWidget {
|
||||
|
||||
doRender() {
|
||||
this.$widget = $(TPL);
|
||||
this.modal = Modal.getOrCreateInstance(this.$widget);
|
||||
this.modal = Modal.getOrCreateInstance(this.$widget[0]);
|
||||
this.$infoContent = this.$widget.find(".info-dialog-content");
|
||||
this.$okButton = this.$widget.find(".info-dialog-ok-button");
|
||||
|
||||
@ -51,10 +60,17 @@ export default class InfoDialog extends BasicWidget {
|
||||
this.$okButton.on("click", () => this.modal.hide());
|
||||
}
|
||||
|
||||
showInfoDialogEvent({ message, callback }) {
|
||||
showInfoDialogEvent({ message, callback }: EventData<"showInfoDialog">) {
|
||||
this.$originallyFocused = $(":focus");
|
||||
|
||||
this.$infoContent.text(message);
|
||||
if (typeof message === "string") {
|
||||
this.$infoContent.text(message);
|
||||
} else if (Array.isArray(message)) {
|
||||
this.$infoContent.html(message[0]);
|
||||
} else {
|
||||
this.$infoContent.html(message as HTMLElement);
|
||||
}
|
||||
|
||||
|
||||
utils.openDialog(this.$widget);
|
||||
|
@ -2,6 +2,7 @@ import { t } from "../../services/i18n.js";
|
||||
import NoteContextAwareWidget from "../note_context_aware_widget.js";
|
||||
import AttributeDetailWidget from "../attribute_widgets/attribute_detail.js";
|
||||
import AttributeEditorWidget from "../attribute_widgets/attribute_editor.js";
|
||||
import type { CommandListenerData } from "../../components/app_context.js";
|
||||
|
||||
const TPL = `
|
||||
<div class="attribute-list">
|
||||
@ -13,17 +14,22 @@ const TPL = `
|
||||
margin-bottom: 2px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
|
||||
.attribute-list-editor p {
|
||||
margin: 0 !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
<div class="attr-editor-placeholder"></div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
export default class OwnedAttributeListWidget extends NoteContextAwareWidget {
|
||||
|
||||
private attributeDetailWidget: AttributeDetailWidget;
|
||||
private attributeEditorWidget: AttributeEditorWidget;
|
||||
private $title!: JQuery<HTMLElement>;
|
||||
|
||||
get name() {
|
||||
return "ownedAttributes";
|
||||
}
|
||||
@ -44,7 +50,7 @@ export default class OwnedAttributeListWidget extends NoteContextAwareWidget {
|
||||
|
||||
getTitle() {
|
||||
return {
|
||||
show: !this.note.isLaunchBarConfig(),
|
||||
show: !this.note?.isLaunchBarConfig(),
|
||||
title: t("owned_attribute_list.owned_attributes"),
|
||||
icon: "bx bx-list-check"
|
||||
};
|
||||
@ -68,7 +74,7 @@ export default class OwnedAttributeListWidget extends NoteContextAwareWidget {
|
||||
await this.attributeEditorWidget.refresh();
|
||||
}
|
||||
|
||||
async updateAttributeListCommand({ attributes }) {
|
||||
async updateAttributeListCommand({ attributes }: CommandListenerData<"updateAttributeList">) {
|
||||
await this.attributeEditorWidget.updateAttributeList(attributes);
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import NoteContextAwareWidget from "../note_context_aware_widget.js";
|
||||
import keyboardActionService from "../../services/keyboard_actions.js";
|
||||
import { t } from "../../services/i18n.js";
|
||||
import type FNote from "../../entities/fnote.js";
|
||||
|
||||
const TPL = `
|
||||
<div class="script-runner-widget">
|
||||
@ -16,13 +17,17 @@ const TPL = `
|
||||
</style>
|
||||
|
||||
<div class="execute-description"></div>
|
||||
|
||||
|
||||
<div style="display: flex; justify-content: space-around">
|
||||
<button data-trigger-command="runActiveNote" class="execute-button btn btn-sm"></button>
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
export default class ScriptExecutorWidget extends NoteContextAwareWidget {
|
||||
|
||||
private $executeButton!: JQuery<HTMLElement>;
|
||||
private $executeDescription!: JQuery<HTMLElement>;
|
||||
|
||||
isEnabled() {
|
||||
return (
|
||||
super.isEnabled() &&
|
||||
@ -33,7 +38,7 @@ export default class ScriptExecutorWidget extends NoteContextAwareWidget {
|
||||
}
|
||||
|
||||
isTriliumSqlite() {
|
||||
return this.note.mime === "text/x-sqlite;schema=trilium";
|
||||
return this.note?.mime === "text/x-sqlite;schema=trilium";
|
||||
}
|
||||
|
||||
getTitle() {
|
||||
@ -53,7 +58,7 @@ export default class ScriptExecutorWidget extends NoteContextAwareWidget {
|
||||
this.$executeDescription = this.$widget.find(".execute-description");
|
||||
}
|
||||
|
||||
async refreshWithNote(note) {
|
||||
async refreshWithNote(note: FNote) {
|
||||
const executeTitle = note.getLabelValue("executeButton") || (this.isTriliumSqlite() ? t("script_executor.execute_query") : t("script_executor.execute_script"));
|
||||
|
||||
this.$executeButton.text(executeTitle);
|
Loading…
x
Reference in New Issue
Block a user