2025-08-27 18:25:54 +03:00
|
|
|
import { useMemo, useRef } from "preact/hooks";
|
|
|
|
|
import { useLegacyImperativeHandlers, useTriliumEvents } from "../react/hooks";
|
|
|
|
|
import AttributeEditor, { AttributeEditorImperativeHandlers } from "./components/AttributeEditor";
|
2025-08-23 11:44:51 +03:00
|
|
|
import { TabContext } from "./ribbon-interface";
|
|
|
|
|
|
2025-08-27 13:15:38 +03:00
|
|
|
export default function OwnedAttributesTab({ note, hidden, activate, ntxId, ...restProps }: TabContext) {
|
2025-08-27 18:25:54 +03:00
|
|
|
const api = useRef<AttributeEditorImperativeHandlers>(null);
|
|
|
|
|
|
2025-08-27 13:15:38 +03:00
|
|
|
useTriliumEvents([ "addNewLabel", "addNewRelation" ], ({ ntxId: eventNtxId }) => {
|
|
|
|
|
if (ntxId === eventNtxId) {
|
|
|
|
|
activate();
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-08-27 13:05:51 +03:00
|
|
|
|
2025-08-27 18:25:54 +03:00
|
|
|
// Interaction with the attribute editor.
|
|
|
|
|
useLegacyImperativeHandlers(useMemo(() => ({
|
|
|
|
|
saveAttributesCommand: () => api.current?.save(),
|
|
|
|
|
reloadAttributesCommand: () => api.current?.refresh(),
|
|
|
|
|
updateAttributeListCommand: ({ attributes }) => api.current?.renderOwnedAttributes(attributes)
|
|
|
|
|
}), [ api ]));
|
|
|
|
|
|
2025-08-23 11:44:51 +03:00
|
|
|
return (
|
|
|
|
|
<div className="attribute-list">
|
2025-08-23 20:35:19 +03:00
|
|
|
{ note && (
|
2025-08-27 18:25:54 +03:00
|
|
|
<AttributeEditor api={api} ntxId={ntxId} note={note} {...restProps} hidden={hidden} />
|
2025-08-23 20:35:19 +03:00
|
|
|
)}
|
2025-08-23 11:44:51 +03:00
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|