UNPKG

@wordpress/editor

Version:
49 lines (48 loc) 1.37 kB
// packages/editor/src/components/collab-sidebar/format.js import { __ } from "@wordpress/i18n"; import { useEffect } from "@wordpress/element"; import { useDispatch, useSelect } from "@wordpress/data"; import { store as interfaceStore } from "@wordpress/interface"; import { store as editorStore } from "../../store/index.mjs"; import { SIDEBARS } from "./constants.mjs"; import { unlock } from "../../lock-unlock.mjs"; var NOTE_FORMAT_NAME = "core/note"; var noteFormat = { title: __("Note"), tagName: "mark", className: "wp-note", attributes: { "data-id": "data-id" }, edit: NoteFormat }; function NoteFormat({ isActive, activeAttributes }) { const { getActiveComplementaryArea } = useSelect(interfaceStore); const { getSelectedNote } = unlock(useSelect(editorStore)); const { selectNote } = unlock(useDispatch(editorStore)); const noteId = activeAttributes?.["data-id"]; useEffect(() => { if (!isActive || !noteId) { return; } if (!SIDEBARS.includes(getActiveComplementaryArea("core"))) { return; } if (String(getSelectedNote()) === String(noteId)) { return; } selectNote(Number(noteId)); }, [ isActive, noteId, getActiveComplementaryArea, getSelectedNote, selectNote ]); return null; } export { NOTE_FORMAT_NAME, noteFormat }; //# sourceMappingURL=format.mjs.map