1 | import _objectSpread from "@babel/runtime/helpers/esm/objectSpread";
|
2 | import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
3 | import _createClass from "@babel/runtime/helpers/esm/createClass";
|
4 | import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
|
5 | import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
|
6 | import _inherits from "@babel/runtime/helpers/esm/inherits";
|
7 | import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
|
8 | import { createElement } from "@wordpress/element";
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | import { View } from 'react-native';
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | import { __ } from '@wordpress/i18n';
|
19 | import { Component } from '@wordpress/element';
|
20 | import { createBlock } from '@wordpress/blocks';
|
21 | import { RichText } from '@wordpress/block-editor';
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | import styles from './style.scss';
|
27 | var name = 'core/paragraph';
|
28 |
|
29 | var ParagraphEdit =
|
30 |
|
31 | function (_Component) {
|
32 | _inherits(ParagraphEdit, _Component);
|
33 |
|
34 | function ParagraphEdit(props) {
|
35 | var _this;
|
36 |
|
37 | _classCallCheck(this, ParagraphEdit);
|
38 |
|
39 | _this = _possibleConstructorReturn(this, _getPrototypeOf(ParagraphEdit).call(this, props));
|
40 | _this.splitBlock = _this.splitBlock.bind(_assertThisInitialized(_assertThisInitialized(_this)));
|
41 | _this.onReplace = _this.onReplace.bind(_assertThisInitialized(_assertThisInitialized(_this)));
|
42 | _this.state = {
|
43 | aztecHeight: 0
|
44 | };
|
45 | return _this;
|
46 | }
|
47 | |
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | _createClass(ParagraphEdit, [{
|
63 | key: "splitBlock",
|
64 | value: function splitBlock(before, after) {
|
65 | var _this$props = this.props,
|
66 | attributes = _this$props.attributes,
|
67 | insertBlocksAfter = _this$props.insertBlocksAfter,
|
68 | setAttributes = _this$props.setAttributes,
|
69 | onReplace = _this$props.onReplace;
|
70 |
|
71 | for (var _len = arguments.length, blocks = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
72 | blocks[_key - 2] = arguments[_key];
|
73 | }
|
74 |
|
75 | if (after !== null) {
|
76 |
|
77 |
|
78 | var newBlock = createBlock(name, {
|
79 | content: after
|
80 | });
|
81 | blocks.push(newBlock);
|
82 | }
|
83 |
|
84 | if (blocks.length && insertBlocksAfter) {
|
85 | insertBlocksAfter(blocks);
|
86 | }
|
87 |
|
88 | var content = attributes.content;
|
89 |
|
90 | if (before === null) {
|
91 | onReplace([]);
|
92 | } else if (content !== before) {
|
93 |
|
94 |
|
95 |
|
96 | setAttributes({
|
97 | content: before
|
98 | });
|
99 | }
|
100 | }
|
101 | }, {
|
102 | key: "onReplace",
|
103 | value: function onReplace(blocks) {
|
104 | var _this$props2 = this.props,
|
105 | attributes = _this$props2.attributes,
|
106 | onReplace = _this$props2.onReplace;
|
107 | onReplace(blocks.map(function (block, index) {
|
108 | return index === 0 && block.name === name ? _objectSpread({}, block, {
|
109 | attributes: _objectSpread({}, attributes, block.attributes)
|
110 | }) : block;
|
111 | }));
|
112 | }
|
113 | }, {
|
114 | key: "render",
|
115 | value: function render() {
|
116 | var _this2 = this;
|
117 |
|
118 | var _this$props3 = this.props,
|
119 | attributes = _this$props3.attributes,
|
120 | setAttributes = _this$props3.setAttributes,
|
121 | mergeBlocks = _this$props3.mergeBlocks,
|
122 | style = _this$props3.style;
|
123 | var placeholder = attributes.placeholder,
|
124 | content = attributes.content;
|
125 | var minHeight = styles.blockText.minHeight;
|
126 | return createElement(View, null, createElement(RichText, {
|
127 | tagName: "p",
|
128 | value: content,
|
129 | isSelected: this.props.isSelected,
|
130 | onFocus: this.props.onFocus
|
131 | ,
|
132 | onBlur: this.props.onBlur
|
133 | ,
|
134 | onCaretVerticalPositionChange: this.props.onCaretVerticalPositionChange,
|
135 | style: _objectSpread({}, style, {
|
136 | minHeight: Math.max(minHeight, this.state.aztecHeight)
|
137 | }),
|
138 | onChange: function onChange(nextContent) {
|
139 | setAttributes({
|
140 | content: nextContent
|
141 | });
|
142 | },
|
143 | onSplit: this.splitBlock,
|
144 | onMerge: mergeBlocks,
|
145 | onReplace: this.onReplace,
|
146 | onContentSizeChange: function onContentSizeChange(event) {
|
147 | _this2.setState({
|
148 | aztecHeight: event.aztecHeight
|
149 | });
|
150 | },
|
151 | placeholder: placeholder || __('Start writing…')
|
152 | }));
|
153 | }
|
154 | }]);
|
155 |
|
156 | return ParagraphEdit;
|
157 | }(Component);
|
158 |
|
159 | export default ParagraphEdit;
|
160 |
|
\ | No newline at end of file |