UNPKG

@wordpress/editor

Version:
8 lines (7 loc) 3.12 kB
{ "version": 3, "sources": ["../../../src/components/collab-sidebar/format.js"], "sourcesContent": ["import { __ } from '@wordpress/i18n';\nimport { useEffect } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as interfaceStore } from '@wordpress/interface';\nimport { store as editorStore } from '../../store';\nimport { SIDEBARS } from './constants';\nimport { unlock } from '../../lock-unlock';\n\nexport const NOTE_FORMAT_NAME = 'core/note';\n\n/*\n * Anchoring-only format: it serializes an inline note's in-content marker as\n * `<mark class=\"wp-note\" data-id=\"N\">`. Notes are added from the block options\n * menu instead, since an `edit` with UI would fill `RichText.ToolbarControls`,\n * which the format toolbar renders inside the \"More\" (inline styles) dropdown -\n * the wrong home for an action that is neither an inline style nor exclusive to\n * text selections.\n */\nexport const noteFormat = {\n\ttitle: __( 'Note' ),\n\ttagName: 'mark',\n\tclassName: 'wp-note',\n\tattributes: {\n\t\t'data-id': 'data-id',\n\t},\n\tedit: NoteFormat,\n};\n\nfunction NoteFormat( { isActive, activeAttributes } ) {\n\tconst { getActiveComplementaryArea } = useSelect( interfaceStore );\n\tconst { getSelectedNote } = unlock( useSelect( editorStore ) );\n\tconst { selectNote } = unlock( useDispatch( editorStore ) );\n\tconst noteId = activeAttributes?.[ 'data-id' ];\n\n\tuseEffect( () => {\n\t\tif ( ! isActive || ! noteId ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Sync an already-open sidebar to the marker under the caret. Read\n\t\t// imperatively so it triggers on caret movement, not sidebar state.\n\t\tif ( ! SIDEBARS.includes( getActiveComplementaryArea( 'core' ) ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( String( getSelectedNote() ) === String( noteId ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Select-only; no cleanup on leave. The block-level sync owns\n\t\t// clearing/reverting, and deselecting here would drop the block's\n\t\t// note while the caret is still inside the block.\n\t\tselectNote( Number( noteId ) );\n\t}, [\n\t\tisActive,\n\t\tnoteId,\n\t\tgetActiveComplementaryArea,\n\t\tgetSelectedNote,\n\t\tselectNote,\n\t] );\n\n\treturn null;\n}\n"], "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAmB;AACnB,qBAA0B;AAC1B,kBAAuC;AACvC,uBAAwC;AACxC,mBAAqC;AACrC,uBAAyB;AACzB,yBAAuB;AAEhB,IAAM,mBAAmB;AAUzB,IAAM,aAAa;AAAA,EACzB,WAAO,gBAAI,MAAO;AAAA,EAClB,SAAS;AAAA,EACT,WAAW;AAAA,EACX,YAAY;AAAA,IACX,WAAW;AAAA,EACZ;AAAA,EACA,MAAM;AACP;AAEA,SAAS,WAAY,EAAE,UAAU,iBAAiB,GAAI;AACrD,QAAM,EAAE,2BAA2B,QAAI,uBAAW,iBAAAA,KAAe;AACjE,QAAM,EAAE,gBAAgB,QAAI,+BAAQ,uBAAW,aAAAC,KAAY,CAAE;AAC7D,QAAM,EAAE,WAAW,QAAI,+BAAQ,yBAAa,aAAAA,KAAY,CAAE;AAC1D,QAAM,SAAS,mBAAoB,SAAU;AAE7C,gCAAW,MAAM;AAChB,QAAK,CAAE,YAAY,CAAE,QAAS;AAC7B;AAAA,IACD;AAIA,QAAK,CAAE,0BAAS,SAAU,2BAA4B,MAAO,CAAE,GAAI;AAClE;AAAA,IACD;AAEA,QAAK,OAAQ,gBAAgB,CAAE,MAAM,OAAQ,MAAO,GAAI;AACvD;AAAA,IACD;AAKA,eAAY,OAAQ,MAAO,CAAE;AAAA,EAC9B,GAAG;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAE;AAEF,SAAO;AACR;", "names": ["interfaceStore", "editorStore"] }