1 | import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
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 { InspectorControls } from '@wordpress/block-editor';
|
14 | import { Disabled, PanelBody, RangeControl, ToggleControl } from '@wordpress/components';
|
15 | import { ServerSideRender } from '@wordpress/editor';
|
16 | import { Component, Fragment } from '@wordpress/element';
|
17 | import { __ } from '@wordpress/i18n';
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | var MIN_COMMENTS = 1;
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | var MAX_COMMENTS = 100;
|
32 |
|
33 | var LatestComments =
|
34 |
|
35 | function (_Component) {
|
36 | _inherits(LatestComments, _Component);
|
37 |
|
38 | function LatestComments() {
|
39 | var _this;
|
40 |
|
41 | _classCallCheck(this, LatestComments);
|
42 |
|
43 | _this = _possibleConstructorReturn(this, _getPrototypeOf(LatestComments).apply(this, arguments));
|
44 | _this.setCommentsToShow = _this.setCommentsToShow.bind(_assertThisInitialized(_assertThisInitialized(_this)));
|
45 |
|
46 |
|
47 |
|
48 | _this.toggleDisplayAvatar = _this.createToggleAttribute('displayAvatar');
|
49 | _this.toggleDisplayDate = _this.createToggleAttribute('displayDate');
|
50 | _this.toggleDisplayExcerpt = _this.createToggleAttribute('displayExcerpt');
|
51 | return _this;
|
52 | }
|
53 |
|
54 | _createClass(LatestComments, [{
|
55 | key: "createToggleAttribute",
|
56 | value: function createToggleAttribute(propName) {
|
57 | var _this2 = this;
|
58 |
|
59 | return function () {
|
60 | var value = _this2.props.attributes[propName];
|
61 | var setAttributes = _this2.props.setAttributes;
|
62 | setAttributes(_defineProperty({}, propName, !value));
|
63 | };
|
64 | }
|
65 | }, {
|
66 | key: "setCommentsToShow",
|
67 | value: function setCommentsToShow(commentsToShow) {
|
68 | this.props.setAttributes({
|
69 | commentsToShow: commentsToShow
|
70 | });
|
71 | }
|
72 | }, {
|
73 | key: "render",
|
74 | value: function render() {
|
75 | var _this$props$attribute = this.props.attributes,
|
76 | commentsToShow = _this$props$attribute.commentsToShow,
|
77 | displayAvatar = _this$props$attribute.displayAvatar,
|
78 | displayDate = _this$props$attribute.displayDate,
|
79 | displayExcerpt = _this$props$attribute.displayExcerpt;
|
80 | return createElement(Fragment, null, createElement(InspectorControls, null, createElement(PanelBody, {
|
81 | title: __('Latest Comments Settings')
|
82 | }, createElement(ToggleControl, {
|
83 | label: __('Display Avatar'),
|
84 | checked: displayAvatar,
|
85 | onChange: this.toggleDisplayAvatar
|
86 | }), createElement(ToggleControl, {
|
87 | label: __('Display Date'),
|
88 | checked: displayDate,
|
89 | onChange: this.toggleDisplayDate
|
90 | }), createElement(ToggleControl, {
|
91 | label: __('Display Excerpt'),
|
92 | checked: displayExcerpt,
|
93 | onChange: this.toggleDisplayExcerpt
|
94 | }), createElement(RangeControl, {
|
95 | label: __('Number of Comments'),
|
96 | value: commentsToShow,
|
97 | onChange: this.setCommentsToShow,
|
98 | min: MIN_COMMENTS,
|
99 | max: MAX_COMMENTS,
|
100 | required: true
|
101 | }))), createElement(Disabled, null, createElement(ServerSideRender, {
|
102 | block: "core/latest-comments",
|
103 | attributes: this.props.attributes
|
104 | })));
|
105 | }
|
106 | }]);
|
107 |
|
108 | return LatestComments;
|
109 | }(Component);
|
110 |
|
111 | export default LatestComments;
|
112 |
|
\ | No newline at end of file |