1 | import { createElement } from "@wordpress/element";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | import HeadingToolbar from './heading-toolbar';
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | import { __ } from '@wordpress/i18n';
|
12 | import { Fragment } from '@wordpress/element';
|
13 | import { PanelBody } from '@wordpress/components';
|
14 | import { createBlock } from '@wordpress/blocks';
|
15 | import { RichText, BlockControls, InspectorControls, AlignmentToolbar } from '@wordpress/block-editor';
|
16 | export default function HeadingEdit(_ref) {
|
17 | var attributes = _ref.attributes,
|
18 | setAttributes = _ref.setAttributes,
|
19 | mergeBlocks = _ref.mergeBlocks,
|
20 | insertBlocksAfter = _ref.insertBlocksAfter,
|
21 | onReplace = _ref.onReplace,
|
22 | className = _ref.className;
|
23 | var align = attributes.align,
|
24 | content = attributes.content,
|
25 | level = attributes.level,
|
26 | placeholder = attributes.placeholder;
|
27 | var tagName = 'h' + level;
|
28 | return createElement(Fragment, null, createElement(BlockControls, null, createElement(HeadingToolbar, {
|
29 | minLevel: 2,
|
30 | maxLevel: 5,
|
31 | selectedLevel: level,
|
32 | onChange: function onChange(newLevel) {
|
33 | return setAttributes({
|
34 | level: newLevel
|
35 | });
|
36 | }
|
37 | })), createElement(InspectorControls, null, createElement(PanelBody, {
|
38 | title: __('Heading Settings')
|
39 | }, createElement("p", null, __('Level')), createElement(HeadingToolbar, {
|
40 | minLevel: 1,
|
41 | maxLevel: 7,
|
42 | selectedLevel: level,
|
43 | onChange: function onChange(newLevel) {
|
44 | return setAttributes({
|
45 | level: newLevel
|
46 | });
|
47 | }
|
48 | }), createElement("p", null, __('Text Alignment')), createElement(AlignmentToolbar, {
|
49 | value: align,
|
50 | onChange: function onChange(nextAlign) {
|
51 | setAttributes({
|
52 | align: nextAlign
|
53 | });
|
54 | }
|
55 | }))), createElement(RichText, {
|
56 | identifier: "content",
|
57 | wrapperClassName: "wp-block-heading",
|
58 | tagName: tagName,
|
59 | value: content,
|
60 | onChange: function onChange(value) {
|
61 | return setAttributes({
|
62 | content: value
|
63 | });
|
64 | },
|
65 | onMerge: mergeBlocks,
|
66 | unstableOnSplit: insertBlocksAfter ? function (before, after) {
|
67 | setAttributes({
|
68 | content: before
|
69 | });
|
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 | insertBlocksAfter([].concat(blocks, [createBlock('core/paragraph', {
|
76 | content: after
|
77 | })]));
|
78 | } : undefined,
|
79 | onRemove: function onRemove() {
|
80 | return onReplace([]);
|
81 | },
|
82 | style: {
|
83 | textAlign: align
|
84 | },
|
85 | className: className,
|
86 | placeholder: placeholder || __('Write heading…')
|
87 | }));
|
88 | }
|
89 |
|
\ | No newline at end of file |