{
  "version": 3,
  "sources": ["../../../src/components/collab-sidebar/add-note.js"],
  "sourcesContent": ["import { __ } from '@wordpress/i18n';\nimport { useRef } from '@wordpress/element';\nimport { __experimentalUseFocusOutside as useFocusOutside } from '@wordpress/compose';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport {\n\tstore as blockEditorStore,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { NoteCard } from './note-card';\nimport { NoteForm } from './note-form';\nimport { FloatingContainer } from './floating-container';\nimport { focusNoteThread } from './utils';\nimport { store as editorStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nconst { useBlockElement } = unlock( blockEditorPrivateApis );\n\nexport function AddNote( { onSubmit, sidebarRef, floating } ) {\n\tconst { clientId } = useSelect( ( select ) => {\n\t\tconst { getSelectedBlockClientId } = select( blockEditorStore );\n\t\treturn {\n\t\t\tclientId: getSelectedBlockClientId(),\n\t\t};\n\t}, [] );\n\tconst selectedNote = useSelect(\n\t\t( select ) => unlock( select( editorStore ) ).getSelectedNote(),\n\t\t[]\n\t);\n\tconst blockElement = useBlockElement( clientId );\n\tconst { toggleBlockSpotlight } = unlock( useDispatch( blockEditorStore ) );\n\tconst { selectNote } = unlock( useDispatch( editorStore ) );\n\tconst { getSelectedNote } = unlock( useSelect( editorStore ) );\n\tconst isSubmittingRef = useRef( false );\n\n\t/*\n\t * Dismiss the form once focus leaves it. `useFocusOutside` keeps the form\n\t * open while focus stays in UI it owns: format popovers (e.g. the Cmd+K\n\t * link UI) portal out of the form's DOM, but their focus events still\n\t * bubble here through the React tree. It also ignores window/tab blur.\n\t */\n\tconst focusOutside = useFocusOutside( ( event ) => {\n\t\t// Keep the form open when focus returns to it, e.g. on link popover Escape.\n\t\tif (\n\t\t\tevent.relatedTarget?.closest(\n\t\t\t\t'.editor-collab-sidebar-panel__add-note'\n\t\t\t)\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t\t// Never dismiss mid-submit; clicking \"Add note\" blurs before it settles.\n\t\tif ( isSubmittingRef.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\t/*\n\t\t * Selection may have moved on before this deferred callback runs; only\n\t\t * clear it while this still owns the selection, or it would wipe out the\n\t\t * newly selected note.\n\t\t */\n\t\tif ( getSelectedNote() === 'new' ) {\n\t\t\ttoggleBlockSpotlight( clientId, false );\n\t\t\tselectNote( undefined );\n\t\t}\n\t} );\n\n\tconst unselectNote = () => {\n\t\tselectNote( undefined );\n\t\tblockElement?.focus();\n\t\ttoggleBlockSpotlight( clientId, false );\n\t};\n\n\tif ( selectedNote !== 'new' || ! clientId ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<FloatingContainer\n\t\t\tfloating={ floating }\n\t\t\tclassName=\"editor-collab-sidebar-panel__add-note is-selected\"\n\t\t\tgap=\"md\"\n\t\t\ttabIndex={ 0 }\n\t\t\taria-label={ __( 'New note' ) }\n\t\t\trole=\"treeitem\"\n\t\t\tstyle={\n\t\t\t\tfloating ? { opacity: ! floating.y ? 0 : undefined } : undefined\n\t\t\t}\n\t\t\t{ ...focusOutside }\n\t\t>\n\t\t\t<NoteCard>\n\t\t\t\t<NoteForm\n\t\t\t\t\tonSubmit={ async ( inputComment ) => {\n\t\t\t\t\t\tisSubmittingRef.current = true;\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t/*\n\t\t\t\t\t\t\t * The create action resolves `undefined` when the\n\t\t\t\t\t\t\t * save fails (it surfaces its own error notice);\n\t\t\t\t\t\t\t * keep the form open so the draft isn't lost.\n\t\t\t\t\t\t\t */\n\t\t\t\t\t\t\tconst savedRecord = await onSubmit( {\n\t\t\t\t\t\t\t\tcontent: inputComment,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\tif ( savedRecord ) {\n\t\t\t\t\t\t\t\tselectNote( savedRecord.id );\n\t\t\t\t\t\t\t\tfocusNoteThread(\n\t\t\t\t\t\t\t\t\tsavedRecord.id,\n\t\t\t\t\t\t\t\t\tsidebarRef.current\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn savedRecord;\n\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\tisSubmittingRef.current = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t} }\n\t\t\t\t\tonCancel={ unselectNote }\n\t\t\t\t\tlabels={ {\n\t\t\t\t\t\tinput: __( 'New note' ),\n\t\t\t\t\t\tplaceholder: __( 'Add a note or @ mention' ),\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t</NoteCard>\n\t\t</FloatingContainer>\n\t);\n}\n"],
  "mappings": ";AAAA,SAAS,UAAU;AACnB,SAAS,cAAc;AACvB,SAAS,iCAAiC,uBAAuB;AACjE,SAAS,WAAW,mBAAmB;AACvC;AAAA,EACC,SAAS;AAAA,EACT,eAAe;AAAA,OACT;AACP,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,yBAAyB;AAClC,SAAS,uBAAuB;AAChC,SAAS,SAAS,mBAAmB;AACrC,SAAS,cAAc;AA4EnB;AA1EJ,IAAM,EAAE,gBAAgB,IAAI,OAAQ,sBAAuB;AAEpD,SAAS,QAAS,EAAE,UAAU,YAAY,SAAS,GAAI;AAC7D,QAAM,EAAE,SAAS,IAAI,UAAW,CAAE,WAAY;AAC7C,UAAM,EAAE,yBAAyB,IAAI,OAAQ,gBAAiB;AAC9D,WAAO;AAAA,MACN,UAAU,yBAAyB;AAAA,IACpC;AAAA,EACD,GAAG,CAAC,CAAE;AACN,QAAM,eAAe;AAAA,IACpB,CAAE,WAAY,OAAQ,OAAQ,WAAY,CAAE,EAAE,gBAAgB;AAAA,IAC9D,CAAC;AAAA,EACF;AACA,QAAM,eAAe,gBAAiB,QAAS;AAC/C,QAAM,EAAE,qBAAqB,IAAI,OAAQ,YAAa,gBAAiB,CAAE;AACzE,QAAM,EAAE,WAAW,IAAI,OAAQ,YAAa,WAAY,CAAE;AAC1D,QAAM,EAAE,gBAAgB,IAAI,OAAQ,UAAW,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