@wordpress/block-library
Version:
Block library for the WordPress editor.
1 lines • 8.18 kB
Source Map (JSON)
{"version":3,"file":"edit.cjs","names":["ToolbarButton","formatLTR","_x","isRTL","useSettings","useSelect","blockEditorStore","__","getBlockSupport","InspectorControls","ToolsPanelItem","ToggleControl","useBlockProps","useOnEnter","RichText","useBlockEditingMode","BlockControls"],"sources":["../../src/paragraph/edit.jsx"],"sourcesContent":["import clsx from 'clsx';\nimport { __, _x, isRTL } from '@wordpress/i18n';\nimport {\n\tToolbarButton,\n\tToggleControl,\n\t__experimentalToolsPanelItem as ToolsPanelItem,\n} from '@wordpress/components';\nimport {\n\tBlockControls,\n\tInspectorControls,\n\tRichText,\n\tuseBlockProps,\n\tuseSettings,\n\tuseBlockEditingMode,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport { getBlockSupport } from '@wordpress/blocks';\nimport { formatLTR } from '@wordpress/icons';\nimport { useOnEnter } from './use-enter';\nimport useDeprecatedAlign from './deprecated-attributes';\n\nfunction ParagraphRTLControl( { direction, setDirection } ) {\n\treturn (\n\t\t<ToolbarButton\n\t\t\ticon={ formatLTR }\n\t\t\ttitle={ _x( 'Left to right', 'editor button' ) }\n\t\t\tisActive={ direction === 'ltr' }\n\t\t\tonClick={ () => {\n\t\t\t\tsetDirection( direction === 'ltr' ? undefined : 'ltr' );\n\t\t\t} }\n\t\t/>\n\t);\n}\n\nfunction hasDropCapDisabled( align ) {\n\treturn align === ( isRTL() ? 'left' : 'right' ) || align === 'center';\n}\n\nfunction DropCapControl( { clientId, attributes, setAttributes, name } ) {\n\t// Please do not add a useSelect call to the paragraph block unconditionally.\n\t// Every useSelect added to a (frequently used) block will degrade load\n\t// and type performance. By moving it within InspectorControls, the subscription is\n\t// now only added for the selected block(s).\n\tconst [ isDropCapFeatureEnabled ] = useSettings( 'typography.dropCap' );\n\tconst hasSelectedStyleState = useSelect(\n\t\t( select ) => {\n\t\t\tconst { hasSelectedBlockStyleState } = select( blockEditorStore );\n\n\t\t\treturn hasSelectedBlockStyleState( clientId );\n\t\t},\n\t\t[ clientId ]\n\t);\n\n\tconst { style, dropCap } = attributes;\n\tif ( ( ! isDropCapFeatureEnabled && ! dropCap ) || hasSelectedStyleState ) {\n\t\treturn null;\n\t}\n\n\tconst textAlign = style?.typography?.textAlign;\n\n\tlet helpText;\n\tif ( hasDropCapDisabled( textAlign ) ) {\n\t\thelpText = __( 'Not available for aligned text.' );\n\t} else if ( dropCap ) {\n\t\thelpText = __( 'Showing large initial letter.' );\n\t} else {\n\t\thelpText = __( 'Show a large initial letter.' );\n\t}\n\n\tconst isDropCapControlEnabledByDefault = getBlockSupport(\n\t\tname,\n\t\t'typography.defaultControls.dropCap',\n\t\tfalse\n\t);\n\n\treturn (\n\t\t<InspectorControls group=\"typography\">\n\t\t\t<ToolsPanelItem\n\t\t\t\thasValue={ () => !! dropCap }\n\t\t\t\tlabel={ __( 'Drop cap' ) }\n\t\t\t\tisShownByDefault={ isDropCapControlEnabledByDefault }\n\t\t\t\tonDeselect={ () => setAttributes( { dropCap: false } ) }\n\t\t\t\tresetAllFilter={ () => ( { dropCap: false } ) }\n\t\t\t\tpanelId={ clientId }\n\t\t\t>\n\t\t\t\t<ToggleControl\n\t\t\t\t\tlabel={ __( 'Drop cap' ) }\n\t\t\t\t\tchecked={ !! dropCap }\n\t\t\t\t\tonChange={ () => setAttributes( { dropCap: ! dropCap } ) }\n\t\t\t\t\thelp={ helpText }\n\t\t\t\t\tdisabled={ hasDropCapDisabled( textAlign ) }\n\t\t\t\t/>\n\t\t\t</ToolsPanelItem>\n\t\t</InspectorControls>\n\t);\n}\n\nfunction ParagraphBlock( {\n\tattributes,\n\tmergeBlocks,\n\tonReplace,\n\tonRemove,\n\tsetAttributes,\n\tclientId,\n\tisSelected: isSingleSelected,\n\tname,\n} ) {\n\tconst { content, direction, dropCap, placeholder, style } = attributes;\n\tconst textAlign = style?.typography?.textAlign;\n\tuseDeprecatedAlign( attributes.align, style, setAttributes );\n\tconst blockProps = useBlockProps( {\n\t\tref: useOnEnter( { clientId, content } ),\n\t\tclassName: clsx( {\n\t\t\t'has-drop-cap': hasDropCapDisabled( textAlign ) ? false : dropCap,\n\t\t} ),\n\t\tstyle: { direction },\n\t\t'aria-label': RichText.isEmpty( content )\n\t\t\t? __(\n\t\t\t\t\t'Empty block; start writing or type forward slash to choose a block'\n\t\t\t\t)\n\t\t\t: __( 'Block: Paragraph' ),\n\t} );\n\tconst blockEditingMode = useBlockEditingMode();\n\n\treturn (\n\t\t<>\n\t\t\t{ /* An empty fill would still draw an empty toolbar group. */ }\n\t\t\t{ blockEditingMode === 'default' && isRTL() && (\n\t\t\t\t<BlockControls group=\"block\">\n\t\t\t\t\t<ParagraphRTLControl\n\t\t\t\t\t\tdirection={ direction }\n\t\t\t\t\t\tsetDirection={ ( newDirection ) =>\n\t\t\t\t\t\t\tsetAttributes( { direction: newDirection } )\n\t\t\t\t\t\t}\n\t\t\t\t\t/>\n\t\t\t\t</BlockControls>\n\t\t\t) }\n\t\t\t{ isSingleSelected && (\n\t\t\t\t<DropCapControl\n\t\t\t\t\tname={ name }\n\t\t\t\t\tclientId={ clientId }\n\t\t\t\t\tattributes={ attributes }\n\t\t\t\t\tsetAttributes={ setAttributes }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t<RichText\n\t\t\t\tidentifier=\"content\"\n\t\t\t\ttagName=\"p\"\n\t\t\t\t{ ...blockProps }\n\t\t\t\tvalue={ content }\n\t\t\t\tonChange={ ( newContent ) =>\n\t\t\t\t\tsetAttributes( { content: newContent } )\n\t\t\t\t}\n\t\t\t\tonMerge={ mergeBlocks }\n\t\t\t\tonReplace={ onReplace }\n\t\t\t\tonRemove={ onRemove }\n\t\t\t\tdata-empty={ RichText.isEmpty( content ) }\n\t\t\t\tplaceholder={ placeholder || __( 'Type / to choose a block' ) }\n\t\t\t\tdata-custom-placeholder={ placeholder ? true : undefined }\n\t\t\t\t__unstableEmbedURLOnPaste\n\t\t\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