PluginProbe ʕ •ᴥ•ʔ
FrontBlocks for Gutenberg/GeneratePress / 1.5.2
FrontBlocks for Gutenberg/GeneratePress v1.5.2
1.5.2 1.5.1 1.4.0 1.5.0 trunk 0.2.0 0.2.1 0.2.2 0.2.3 0.2.4 0.2.5 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1.0 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 ci-artifacts
frontblocks / assets / columns-same-height / frontblocks-columns-same-height-option.js
frontblocks / assets / columns-same-height Last commit date
frontblocks-columns-same-height-option.js 2 months ago frontblocks-columns-same-height-option.jsx 2 months ago frontblocks-columns-same-height.css 2 months ago
frontblocks-columns-same-height-option.js
74 lines
1 "use strict";
2
3 function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4 function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
5 function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6 function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7 function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
8 function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
9 function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
10 var createHigherOrderComponent = wp.compose.createHigherOrderComponent;
11 var Fragment = wp.element.Fragment;
12 var InspectorControls = wp.blockEditor.InspectorControls;
13 var _wp$components = wp.components,
14 PanelBody = _wp$components.PanelBody,
15 ToggleControl = _wp$components.ToggleControl;
16 var __ = wp.i18n.__;
17 var COLUMNS_BLOCK = 'core/columns';
18
19 // Register same-height attribute server-side.
20 wp.hooks.addFilter('blocks.registerBlockType', 'frontblocks/add-same-height-attribute', function (settings, name) {
21 if (COLUMNS_BLOCK !== name) {
22 return settings;
23 }
24 settings.attributes = Object.assign(settings.attributes || {}, {
25 frblSameHeight: {
26 type: 'boolean',
27 default: false
28 }
29 });
30 return settings;
31 });
32
33 // Add data attribute to the block wrapper in the editor for CSS targeting.
34 var withSameHeightWrapper = createHigherOrderComponent(function (BlockListBlock) {
35 return function (props) {
36 if (COLUMNS_BLOCK !== props.name || !props.attributes.frblSameHeight) {
37 return /*#__PURE__*/React.createElement(BlockListBlock, props);
38 }
39 var wrapperProps = _objectSpread(_objectSpread({}, props.wrapperProps || {}), {}, {
40 'data-frbl-same-height': 'true'
41 });
42 return /*#__PURE__*/React.createElement(BlockListBlock, _extends({}, props, {
43 wrapperProps: wrapperProps
44 }));
45 };
46 }, 'withSameHeightWrapper');
47 wp.hooks.addFilter('editor.BlockListBlock', 'frontblocks/columns-same-height-wrapper', withSameHeightWrapper);
48
49 // Add the inspector toggle.
50 var withSameHeightControl = createHigherOrderComponent(function (BlockEdit) {
51 return function (props) {
52 if (COLUMNS_BLOCK !== props.name) {
53 return /*#__PURE__*/React.createElement(BlockEdit, props);
54 }
55 var attributes = props.attributes,
56 setAttributes = props.setAttributes;
57 var isSameHeight = !!attributes.frblSameHeight;
58 return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(BlockEdit, props), /*#__PURE__*/React.createElement(InspectorControls, null, /*#__PURE__*/React.createElement(PanelBody, {
59 title: __('FrontBlocks - Layout', 'frontblocks'),
60 initialOpen: false
61 }, /*#__PURE__*/React.createElement(ToggleControl, {
62 label: __('Same height columns', 'frontblocks'),
63 checked: isSameHeight,
64 onChange: function onChange(value) {
65 return setAttributes({
66 frblSameHeight: value
67 });
68 },
69 help: isSameHeight ? __('All columns stretch to match the tallest one.', 'frontblocks') : __('Enable to force all columns to the same height.', 'frontblocks')
70 }))));
71 };
72 }, 'withSameHeightControl');
73 wp.hooks.addFilter('editor.BlockEdit', 'frontblocks/columns-same-height-control', withSameHeightControl);
74