PluginProbe ʕ •ᴥ•ʔ
FrontBlocks for Gutenberg/GeneratePress / trunk
FrontBlocks for Gutenberg/GeneratePress vtrunk
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 / gravityforms-inline / frontblocks-gf-inline-option.js
frontblocks / assets / gravityforms-inline Last commit date
frontblocks-gf-inline-option.js 7 months ago frontblocks-gf-inline-option.jsx 1 month ago frontblocks-gf-inline.css 4 months ago frontblocks-gf-inline.js 7 months ago
frontblocks-gf-inline-option.js
107 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 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; }
5 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; }
6 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; }
7 function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
8 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); }
9 (function () {
10 'use strict';
11
12 var __ = wp.i18n.__;
13 var el = wp.element.createElement;
14 var InspectorControls = wp.blockEditor.InspectorControls;
15 var _wp$components = wp.components,
16 PanelBody = _wp$components.PanelBody,
17 ToggleControl = _wp$components.ToggleControl,
18 RangeControl = _wp$components.RangeControl;
19 var addFilter = wp.hooks.addFilter;
20 var createHigherOrderComponent = wp.compose.createHigherOrderComponent;
21 var _wp = wp,
22 apiFetch = _wp.apiFetch;
23
24 // Intercept Gravity Forms API requests and remove custom attributes.
25 if (apiFetch && apiFetch.use) {
26 apiFetch.use(function (options, next) {
27 if (options.path && options.path.includes('/wp/v2/block-renderer/gravityforms/form')) {
28 // Remove our custom attributes from the URL.
29 options.path = options.path.replace(/&attributes%5BfrblGfInlineEnabled%5D=[^&]*/g, '').replace(/&attributes%5BfrblGfInlineGap%5D=[^&]*/g, '').replace(/attributes%5BfrblGfInlineEnabled%5D=[^&]*&/g, '').replace(/attributes%5BfrblGfInlineGap%5D=[^&]*&/g, '');
30 }
31 return next(options);
32 });
33 }
34
35 // Add inline layout controls to the Gravity Forms block.
36 addFilter('editor.BlockEdit', 'frontblocks/gf-inline-controls', function (BlockEdit) {
37 return function (props) {
38 // Only add controls to Gravity Forms block.
39 if (props.name !== 'gravityforms/form') {
40 return el(BlockEdit, props);
41 }
42
43 // Check if a form is selected.
44 var attributes = props.attributes,
45 setAttributes = props.setAttributes;
46 var _attributes$frblGfInl = attributes.frblGfInlineEnabled,
47 frblGfInlineEnabled = _attributes$frblGfInl === void 0 ? false : _attributes$frblGfInl,
48 _attributes$frblGfInl2 = attributes.frblGfInlineGap,
49 frblGfInlineGap = _attributes$frblGfInl2 === void 0 ? 10 : _attributes$frblGfInl2,
50 _attributes$formId = attributes.formId,
51 formId = _attributes$formId === void 0 ? 0 : _attributes$formId;
52
53 // Only show options if a form is selected.
54 var showInlineOptions = formId && formId > 0;
55 return el('div', {}, el(BlockEdit, props), showInlineOptions && el(InspectorControls, {}, el(PanelBody, {
56 title: __('FrontBlocks for GravityForms', 'frontblocks'),
57 initialOpen: false
58 }, el(ToggleControl, {
59 label: __('Enable Inline Layout', 'frontblocks'),
60 checked: frblGfInlineEnabled,
61 onChange: function onChange(value) {
62 return setAttributes({
63 frblGfInlineEnabled: value
64 });
65 },
66 help: __('Display form fields and button on the same line', 'frontblocks')
67 }), frblGfInlineEnabled && el(RangeControl, {
68 label: __('Gap between elements (px)', 'frontblocks'),
69 value: frblGfInlineGap,
70 onChange: function onChange(value) {
71 return setAttributes({
72 frblGfInlineGap: value
73 });
74 },
75 min: 0,
76 max: 50,
77 step: 1,
78 help: __('Space between form fields and button', 'frontblocks')
79 }))));
80 };
81 });
82
83 // Add custom class to block wrapper in editor.
84 addFilter('editor.BlockListBlock', 'frontblocks/gf-inline-wrapper-class', createHigherOrderComponent(function (BlockListBlock) {
85 return function (props) {
86 if (props.name === 'gravityforms/form') {
87 var attributes = props.attributes;
88 if (attributes.frblGfInlineEnabled) {
89 // Apply gap CSS variable to editor preview.
90 if (typeof window !== 'undefined') {
91 setTimeout(function () {
92 var blockElement = document.querySelector('[data-block="' + props.clientId + '"]');
93 if (blockElement) {
94 blockElement.style.setProperty('--gf-inline-gap', (attributes.frblGfInlineGap || 10) + 'px');
95 }
96 }, 100);
97 }
98 return el(BlockListBlock, _objectSpread(_objectSpread({}, props), {}, {
99 className: 'frontblocks-gf-inline-preview'
100 }));
101 }
102 }
103 return el(BlockListBlock, props);
104 };
105 }, 'withInlineClass'));
106 })();
107