{"version":3,"file":"edit.mjs","names":["icon"],"sources":["../../src/footnotes/edit.jsx"],"sourcesContent":["import { BlockIcon, RichText, useBlockProps } from '@wordpress/block-editor';\nimport { useEntityProp } from '@wordpress/core-data';\nimport { __ } from '@wordpress/i18n';\nimport { Placeholder } from '@wordpress/components';\nimport { formatListNumbered as icon } from '@wordpress/icons';\n\nexport default function FootnotesEdit( { context: { postType, postId } } ) {\n\tconst [ meta, updateMeta ] = useEntityProp(\n\t\t'postType',\n\t\tpostType,\n\t\t'meta',\n\t\tpostId\n\t);\n\tconst footnotesSupported = 'string' === typeof meta?.footnotes;\n\t// The meta is a string that something else may have written, so it can be\n\t// malformed or hold something other than an array. Treat anything\n\t// unreadable as no footnotes and fall through to the placeholder below.\n\tlet parsed;\n\ttry {\n\t\tparsed = JSON.parse( meta?.footnotes || '[]' );\n\t} catch {\n\t\t// Left undefined, which the check below treats as no footnotes, along\n\t\t// with a value of the wrong shape.\n\t}\n\tconst footnotes = Array.isArray( parsed ) ? parsed : [];\n\tconst blockProps = useBlockProps();\n\n\tif ( ! footnotesSupported ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Placeholder\n\t\t\t\t\ticon={ <BlockIcon icon={ icon } /> }\n\t\t\t\t\tlabel={ __( 'Footnotes' ) }\n\t\t\t\t\tinstructions={ __(\n\t\t\t\t\t\t'Footnotes are not supported here. Add this block to post or page content.'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t);\n\t}\n\n\tif ( ! footnotes.length ) {\n\t\treturn (\n\t\t\t<div { ...blockProps }>\n\t\t\t\t<Placeholder\n\t\t\t\t\ticon={ <BlockIcon icon={ icon } /> }\n\t\t\t\t\tlabel={ __( 'Footnotes' ) }\n\t\t\t\t\tinstructions={ __(\n\t\t\t\t\t\t'Footnotes found in blocks within this document will be displayed here.'\n\t\t\t\t\t) }\n\t\t\t\t/>\n\t\t\t</div>\n\t\t);\n\t}\n\n\treturn (\n\t\t<ol { ...blockProps }>\n\t\t\t{ footnotes.map( ( { id, content } ) => (\n\t\t\t\t/* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */\n\t\t\t\t<li\n\t\t\t\t\tkey={ id }\n\t\t\t\t\tonMouseDown={ ( event ) => {\n\t\t\t\t\t\t// When clicking on the list item (not on descendants),\n\t\t\t\t\t\t// focus the rich text element since it's only 1px wide when\n\t\t\t\t\t\t// empty.\n\t\t\t\t\t\tif ( event.target === event.currentTarget ) {\n\t\t\t\t\t\t\tevent.target.firstElementChild.focus();\n\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t}\n\t\t\t\t\t} }\n\t\t\t\t>\n\t\t\t\t\t<RichText\n\t\t\t\t\t\tid={ id }\n\t\t\t\t\t\ttagName=\"span\"\n\t\t\t\t\t\tvalue={ content }\n\t\t\t\t\t\tidentifier={ id }\n\t\t\t\t\t\t// To do: figure out why the browser is not scrolling\n\t\t\t\t\t\t// into view when it receives focus.\n\t\t\t\t\t\tonFocus={ ( event ) => {\n\t\t\t\t\t\t\tif ( ! event.target.textContent.trim() ) {\n\t\t\t\t\t\t\t\tevent.target.scrollIntoView();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tonChange={ ( nextFootnote ) => {\n\t\t\t\t\t\t\tupdateMeta( {\n\t\t\t\t\t\t\t\t...meta,\n\t\t\t\t\t\t\t\tfootnotes: JSON.stringify(\n\t\t\t\t\t\t\t\t\tfootnotes.map( ( footnote ) => {\n\t\t\t\t\t\t\t\t\t\treturn footnote.id === id\n\t\t\t\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t\t\t\tcontent: nextFootnote,\n\t\t\t\t\t\t\t\t\t\t\t\t\tid,\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t: footnote;\n\t\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t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