{"version":3,"file":"edit.cjs","names":["useToolsPanelDropdownMenuProps","useEntityProp","useEntityBlockEditor","useMemo","__unstableSerializeAndClean","_x","wordCount","sprintf","_n","useBlockProps","InspectorControls","ToolsPanel","__","ToolsPanelItem","ToggleControl"],"sources":["../../src/post-time-to-read/edit.jsx"],"sourcesContent":["import { __, _x, _n, sprintf } from '@wordpress/i18n';\nimport { useMemo } from '@wordpress/element';\nimport { useBlockProps, InspectorControls } from '@wordpress/block-editor';\nimport {\n\tToggleControl,\n\t__experimentalToolsPanel as ToolsPanel,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\nimport { __unstableSerializeAndClean } from '@wordpress/blocks';\nimport { useEntityProp, useEntityBlockEditor } from '@wordpress/core-data';\nimport { count as wordCount } from '@wordpress/wordcount';\nimport { useToolsPanelDropdownMenuProps } from '../utils/hooks';\n\nfunction PostTimeToReadEdit( { attributes, setAttributes, context } ) {\n\tconst { displayAsRange, displayMode, averageReadingSpeed } = attributes;\n\tconst { postId, postType } = context;\n\tconst dropdownMenuProps = useToolsPanelDropdownMenuProps();\n\n\tconst [ contentStructure ] = useEntityProp(\n\t\t'postType',\n\t\tpostType,\n\t\t'content',\n\t\tpostId\n\t);\n\n\tconst [ blocks ] = useEntityBlockEditor( 'postType', postType, {\n\t\tid: postId,\n\t} );\n\n\tconst displayString = useMemo( () => {\n\t\t// Replicates the logic found in getEditedPostContent().\n\t\tlet content;\n\t\tif ( contentStructure instanceof Function ) {\n\t\t\tcontent = contentStructure( { blocks } );\n\t\t} else if ( blocks ) {\n\t\t\t// If we have parsed blocks already, they should be our source of truth.\n\t\t\t// Parsing applies block deprecations and legacy block conversions that\n\t\t\t// unparsed content will not have.\n\t\t\tcontent = __unstableSerializeAndClean( blocks );\n\t\t} else {\n\t\t\tcontent = contentStructure;\n\t\t}\n\n\t\t/*\n\t\t * translators: If your word count is based on single characters (e.g. East Asian characters),\n\t\t * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.\n\t\t * Do not translate into your own language.\n\t\t */\n\t\tconst wordCountType = _x(\n\t\t\t'words',\n\t\t\t'Word count type. Do not translate!'\n\t\t);\n\n\t\tconst totalWords = wordCount( content || '', wordCountType );\n\n\t\t// Add \"time to read\" part, if enabled.\n\t\tif ( displayMode === 'time' ) {\n\t\t\tif ( displayAsRange ) {\n\t\t\t\tlet maxMinutes = Math.max(\n\t\t\t\t\t1,\n\t\t\t\t\tMath.round( ( totalWords / averageReadingSpeed ) * 1.2 )\n\t\t\t\t);\n\t\t\t\tconst minMinutes = Math.max(\n\t\t\t\t\t1,\n\t\t\t\t\tMath.round( ( totalWords / averageReadingSpeed ) * 0.8 )\n\t\t\t\t);\n\n\t\t\t\tif ( minMinutes === maxMinutes ) {\n\t\t\t\t\tmaxMinutes = maxMinutes + 1;\n\t\t\t\t}\n\t\t\t\t// translators: %1$s: minimum minutes, %2$s: maximum minutes to read the post.\n\t\t\t\tconst rangeLabel = _x(\n\t\t\t\t\t'%1$s–%2$s minutes',\n\t\t\t\t\t'Range of minutes to read'\n\t\t\t\t);\n\t\t\t\treturn sprintf( rangeLabel, minMinutes, maxMinutes );\n\t\t\t}\n\t\t\tconst minutesToRead = Math.max(\n\t\t\t\t1,\n\t\t\t\tMath.round( totalWords / averageReadingSpeed )\n\t\t\t);\n\n\t\t\treturn sprintf(\n\t\t\t\t/* translators: %s: the number of minutes to read the post. */\n\t\t\t\t_n( '%s minute', '%s minutes', minutesToRead ),\n\t\t\t\tminutesToRead\n\t\t\t);\n\t\t}\n\n\t\t// Add \"word count\" part, if enabled.\n\t\tif ( displayMode === 'words' ) {\n\t\t\treturn wordCountType === 'words'\n\t\t\t\t? sprintf(\n\t\t\t\t\t\t/* translators: %s: the number of words in the post. */\n\t\t\t\t\t\t_n( '%s word', '%s words', totalWords ),\n\t\t\t\t\t\ttotalWords.toLocaleString()\n\t\t\t\t\t)\n\t\t\t\t: sprintf(\n\t\t\t\t\t\t/* translators: %s: the number of characters in the post. */\n\t\t\t\t\t\t_n( '%s character', '%s characters', totalWords ),\n\t\t\t\t\t\ttotalWords.toLocaleString()\n\t\t\t\t\t);\n\t\t}\n\t}, [\n\t\tcontentStructure,\n\t\tblocks,\n\t\tdisplayAsRange,\n\t\tdisplayMode,\n\t\taverageReadingSpeed,\n\t] );\n\n\tconst blockProps = useBlockProps();\n\n\treturn (\n\t\t<>\n\t\t\t{ displayMode === 'time' && (\n\t\t\t\t<InspectorControls>\n\t\t\t\t\t<ToolsPanel\n\t\t\t\t\t\tlabel={ __( 'Settings' ) }\n\t\t\t\t\t\tresetAll={ () => {\n\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\tdisplayAsRange: true,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tdropdownMenuProps={ dropdownMenuProps }\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToolsPanelItem\n\t\t\t\t\t\t\tisShownByDefault\n\t\t\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t\t\t'Display as range',\n\t\t\t\t\t\t\t\t'Turns reading time range display on or off'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\thasValue={ () => ! displayAsRange }\n\t\t\t\t\t\t\tonDeselect={ () => {\n\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\tdisplayAsRange: true,\n\t\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<ToggleControl\n\t\t\t\t\t\t\t\tlabel={ __( 'Display as range' ) }\n\t\t\t\t\t\t\t\tchecked={ !! displayAsRange }\n\t\t\t\t\t\t\t\tonChange={ () =>\n\t\t\t\t\t\t\t\t\tsetAttributes( {\n\t\t\t\t\t\t\t\t\t\tdisplayAsRange: ! displayAsRange,\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\t</ToolsPanelIt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