2025-08-21 20:38:19 +03:00
|
|
|
import { useMemo } from "preact/hooks";
|
2025-08-21 20:16:06 +03:00
|
|
|
import Dropdown from "../react/Dropdown";
|
|
|
|
|
import { NOTE_TYPES } from "../../services/note_types";
|
2025-08-21 20:30:12 +03:00
|
|
|
import { FormDivider, FormListBadge, FormListItem } from "../react/FormList";
|
2025-08-21 20:16:06 +03:00
|
|
|
import { t } from "../../services/i18n";
|
2025-08-21 20:38:19 +03:00
|
|
|
import { useNoteContext, useNoteProperty, useTriliumOption } from "../react/hooks";
|
2025-08-21 20:30:12 +03:00
|
|
|
import mime_types from "../../services/mime_types";
|
2025-08-21 20:38:19 +03:00
|
|
|
import { NoteType } from "@triliumnext/commons";
|
2025-08-21 20:16:06 +03:00
|
|
|
|
2025-08-21 19:27:18 +03:00
|
|
|
export default function BasicPropertiesTab() {
|
2025-08-21 20:16:06 +03:00
|
|
|
return (
|
|
|
|
|
<div className="basic-properties-widget">
|
|
|
|
|
<NoteTypeWidget />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function NoteTypeWidget() {
|
|
|
|
|
const noteTypes = useMemo(() => NOTE_TYPES.filter((nt) => !nt.reserved && !nt.static), []);
|
2025-08-21 20:30:12 +03:00
|
|
|
const [ codeNotesMimeTypes ] = useTriliumOption("codeNotesMimeTypes");
|
|
|
|
|
const mimeTypes = useMemo(() => mime_types.getMimeTypes().filter(mimeType => mimeType.enabled), [ codeNotesMimeTypes ]);
|
2025-08-21 20:38:19 +03:00
|
|
|
|
|
|
|
|
const { note } = useNoteContext();
|
|
|
|
|
const type = useNoteProperty(note, "type") ?? undefined;
|
|
|
|
|
const mime = useNoteProperty(note, "mime");
|
2025-08-21 20:16:06 +03:00
|
|
|
|
|
|
|
|
return (
|
2025-08-21 20:38:19 +03:00
|
|
|
<>
|
|
|
|
|
<span>{t("basic_properties.note_type")}:</span>
|
|
|
|
|
<Dropdown
|
|
|
|
|
dropdownContainerClassName="note-type-dropdown"
|
|
|
|
|
text={<span className="note-type-desc">{findTypeTitle(type, mime)}</span>}
|
|
|
|
|
>
|
|
|
|
|
{noteTypes.map(noteType => {
|
|
|
|
|
const badges: FormListBadge[] = [];
|
|
|
|
|
if (noteType.isNew) {
|
|
|
|
|
badges.push({
|
|
|
|
|
className: "new-note-type-badge",
|
|
|
|
|
text: t("note_types.new-feature")
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (noteType.isBeta) {
|
|
|
|
|
badges.push({
|
|
|
|
|
text: t("note_types.beta-feature")
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (noteType.type !== "code") {
|
|
|
|
|
return (
|
|
|
|
|
<FormListItem
|
|
|
|
|
badges={badges}
|
|
|
|
|
>{noteType.title}</FormListItem>
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<FormDivider />
|
|
|
|
|
<FormListItem disabled>
|
|
|
|
|
<strong>{noteType.title}</strong>
|
|
|
|
|
</FormListItem>
|
|
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
})}
|
|
|
|
|
|
|
|
|
|
{mimeTypes.map(mimeType => (
|
|
|
|
|
<FormListItem>{mimeType.title}</FormListItem>
|
|
|
|
|
))}
|
|
|
|
|
</Dropdown>
|
|
|
|
|
</>
|
2025-08-21 20:16:06 +03:00
|
|
|
)
|
2025-08-21 20:38:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function findTypeTitle(type?: NoteType, mime?: string) {
|
|
|
|
|
if (type === "code") {
|
|
|
|
|
const mimeTypes = mime_types.getMimeTypes();
|
|
|
|
|
const found = mimeTypes.find((mt) => mt.mime === mime);
|
|
|
|
|
|
|
|
|
|
return found ? found.title : mime;
|
|
|
|
|
} else {
|
|
|
|
|
const noteType = NOTE_TYPES.find((nt) => nt.type === type);
|
|
|
|
|
|
|
|
|
|
return noteType ? noteType.title : type;
|
|
|
|
|
}
|
2025-08-21 19:27:18 +03:00
|
|
|
}
|