UNPKG

@wordpress/block-library

Version:
117 lines (103 loc) 3.5 kB
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck"; import _createClass from "@babel/runtime/helpers/esm/createClass"; import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf"; import _inherits from "@babel/runtime/helpers/esm/inherits"; import { createElement } from "@wordpress/element"; /** * Internal dependencies */ import HeadingToolbar from './heading-toolbar'; /** * External dependencies */ import { View } from 'react-native'; /** * WordPress dependencies */ import { __ } from '@wordpress/i18n'; import { Component } from '@wordpress/element'; import { RichText, BlockControls } from '@wordpress/block-editor'; import { createBlock } from '@wordpress/blocks'; /** * Internal dependencies */ import './editor.scss'; var minHeight = 24; var HeadingEdit = /*#__PURE__*/ function (_Component) { _inherits(HeadingEdit, _Component); function HeadingEdit(props) { var _this; _classCallCheck(this, HeadingEdit); _this = _possibleConstructorReturn(this, _getPrototypeOf(HeadingEdit).call(this, props)); _this.state = { aztecHeight: 0 }; return _this; } _createClass(HeadingEdit, [{ key: "render", value: function render() { var _this2 = this; var _this$props = this.props, attributes = _this$props.attributes, setAttributes = _this$props.setAttributes, mergeBlocks = _this$props.mergeBlocks, insertBlocksAfter = _this$props.insertBlocksAfter; var level = attributes.level, placeholder = attributes.placeholder, content = attributes.content; var tagName = 'h' + level; return createElement(View, null, createElement(BlockControls, null, createElement(HeadingToolbar, { minLevel: 2, maxLevel: 5, selectedLevel: level, onChange: function onChange(newLevel) { return setAttributes({ level: newLevel }); } })), createElement(RichText, { tagName: tagName, value: content, isSelected: this.props.isSelected, onFocus: this.props.onFocus // always assign onFocus as a props , onBlur: this.props.onBlur // always assign onBlur as a props , onCaretVerticalPositionChange: this.props.onCaretVerticalPositionChange, style: { minHeight: Math.max(minHeight, this.state.aztecHeight) }, onChange: function onChange(value) { return setAttributes({ content: value }); }, onMerge: mergeBlocks, onSplit: insertBlocksAfter ? function (before, after) { setAttributes({ content: before }); for (var _len = arguments.length, blocks = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { blocks[_key - 2] = arguments[_key]; } insertBlocksAfter([].concat(blocks, [createBlock('core/paragraph', { content: after })])); } : undefined, onContentSizeChange: function onContentSizeChange(event) { _this2.setState({ aztecHeight: event.aztecHeight }); }, placeholder: placeholder || __('Write heading…') })); } }]); return HeadingEdit; }(Component); export default HeadingEdit; //# sourceMappingURL=edit.native.js.map