UNPKG

@wordpress/editor

Version:
8 lines (7 loc) 3.6 kB
{ "version": 3, "sources": ["../../../src/components/post-title/post-title-raw.js"], "sourcesContent": ["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { TextareaControl } from '@wordpress/components';\nimport { __ } from '@wordpress/i18n';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useSelect } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { useState, forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { DEFAULT_CLASSNAMES, REGEXP_NEWLINES } from './constants';\nimport usePostTitleFocus from './use-post-title-focus';\nimport usePostTitle from './use-post-title';\n\n/**\n * Renders a raw post title input field.\n *\n * @param {Object} _ Unused parameter.\n * @param {Element} forwardedRef Reference to the component's DOM node.\n *\n * @return {React.ReactNode} The rendered component.\n */\nfunction PostTitleRaw( _, forwardedRef ) {\n\tconst { placeholder } = useSelect( ( select ) => {\n\t\tconst { getSettings } = select( blockEditorStore );\n\t\tconst { titlePlaceholder } = getSettings();\n\n\t\treturn {\n\t\t\tplaceholder: titlePlaceholder,\n\t\t};\n\t}, [] );\n\n\tconst [ isSelected, setIsSelected ] = useState( false );\n\n\tconst { title, setTitle: onUpdate } = usePostTitle();\n\tconst { ref: focusRef } = usePostTitleFocus( forwardedRef );\n\n\tfunction onChange( value ) {\n\t\tonUpdate( value.replace( REGEXP_NEWLINES, ' ' ) );\n\t}\n\n\tfunction onSelect() {\n\t\tsetIsSelected( true );\n\t}\n\n\tfunction onUnselect() {\n\t\tsetIsSelected( false );\n\t}\n\n\t// The wp-block className is important for editor styles.\n\t// This same block is used in both the visual and the code editor.\n\tconst className = clsx( DEFAULT_CLASSNAMES, {\n\t\t'is-selected': isSelected,\n\t\t'is-raw-text': true,\n\t} );\n\n\tconst decodedPlaceholder =\n\t\tdecodeEntities( placeholder ) || __( 'Add title' );\n\n\treturn (\n\t\t<TextareaControl\n\t\t\tref={ focusRef }\n\t\t\tvalue={ title }\n\t\t\tonChange={ onChange }\n\t\t\tonFocus={ onSelect }\n\t\t\tonBlur={ onUnselect }\n\t\t\tlabel={ placeholder }\n\t\t\tclassName={ className }\n\t\t\tplaceholder={ decodedPlaceholder }\n\t\t\thideLabelFromVision\n\t\t\tautoComplete=\"off\"\n\t\t\tdir=\"auto\"\n\t\t\trows={ 1 }\n\t\t/>\n\t);\n}\n\nexport default forwardRef( PostTitleRaw );\n"], "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,kBAAiB;AAKjB,wBAAgC;AAChC,kBAAmB;AACnB,2BAA+B;AAC/B,kBAA0B;AAC1B,0BAA0C;AAC1C,qBAAqC;AAKrC,uBAAoD;AACpD,kCAA8B;AAC9B,4BAAyB;AAgDvB;AAtCF,SAAS,aAAc,GAAG,cAAe;AACxC,QAAM,EAAE,YAAY,QAAI,uBAAW,CAAE,WAAY;AAChD,UAAM,EAAE,YAAY,IAAI,OAAQ,oBAAAA,KAAiB;AACjD,UAAM,EAAE,iBAAiB,IAAI,YAAY;AAEzC,WAAO;AAAA,MACN,aAAa;AAAA,IACd;AAAA,EACD,GAAG,CAAC,CAAE;AAEN,QAAM,CAAE,YAAY,aAAc,QAAI,yBAAU,KAAM;AAEtD,QAAM,EAAE,OAAO,UAAU,SAAS,QAAI,sBAAAC,SAAa;AACnD,QAAM,EAAE,KAAK,SAAS,QAAI,4BAAAC,SAAmB,YAAa;AAE1D,WAAS,SAAU,OAAQ;AAC1B,aAAU,MAAM,QAAS,kCAAiB,GAAI,CAAE;AAAA,EACjD;AAEA,WAAS,WAAW;AACnB,kBAAe,IAAK;AAAA,EACrB;AAEA,WAAS,aAAa;AACrB,kBAAe,KAAM;AAAA,EACtB;AAIA,QAAM,gBAAY,YAAAC,SAAM,qCAAoB;AAAA,IAC3C,eAAe;AAAA,IACf,eAAe;AAAA,EAChB,CAAE;AAEF,QAAM,yBACL,q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