Skip to content

Commit

Permalink
Merge branch 'release/2.31.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Misplon committed Dec 11, 2024
2 parents d7a3f89 + 4b8959b commit 7a2e707
Show file tree
Hide file tree
Showing 9 changed files with 252 additions and 108 deletions.
21 changes: 21 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
== Changelog ==

= 2.31.1 – 11 December 2024 =
* Layouts Block: Prevented double toolbar when in development mode.
* Improved row, cell, and widget attribute handling.

= 2.31.0 – 22 November 2024 =
* Styles Fields: Added `multi-select`.
* Admin Interface: Styling improvements to the Edit Row modal.
* Layouts Block: General styling improvements and fixes.

= 2.30.0 – 26 October 2024 =
* Image Overlay: Prevent iOS fixed background display issues.
* Styles Settings: Converted Border Thickness to a multi-measurement field.
* Styles Settings: Ensured color picker field and clear button are on a dedicated line.

= 2.29.22 – 30 September 2024 =
* Layout Block: Removed content filter attributes from the front-end.

= 2.29.21 – 17 September 2024 =
* Prebuilt Local Layouts: Resolved a potential error.
* Prebuilt Local Layouts: Restricted layout files to JSON.

= 2.29.20 – 08 August 2024 =
* Rank Math: Resolved content analysis issue when multiple blocks in use.

Expand Down
155 changes: 100 additions & 55 deletions compat/js/siteorigin-panels-layout-block.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
"use strict";

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
Expand Down Expand Up @@ -61,55 +67,90 @@ function (_wp$element$Component) {
_classCallCheck(this, SiteOriginPanelsLayoutBlock);

_this2 = _super.call(this, props);
var hasPanelsData = _typeof(props.panelsData) === 'object' && Object.keys(props.panelsData).length > 0;
var isDefaultModeEdit = window.soPanelsBlockEditorAdmin.defaultMode === 'edit';
var editMode = hasPanelsData === true ? isDefaultModeEdit : true;
_this2.state = {
editing: editMode,
loadingPreview: !editMode,
previewHtml: '',
previewInitialized: !editMode,
pendingPreviewRequest: false,
panelsInitialized: false
};

_this2.initializeState(props);

_this2.panelsContainer = wp.element.createRef();
_this2.previewContainer = wp.element.createRef();
_this2.fetchPreviewTimer;
_this2.fetchPreviewTimer = null;
_this2.currentFetchRequest = null;
return _this2;
}

_createClass(SiteOriginPanelsLayoutBlock, [{
key: "initializeState",
value: function initializeState(props) {
var newState = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var hasPanelsData = _typeof(props.panelsData) === 'object' && Object.keys(props.panelsData).length > 0;
var isDefaultModeEdit = window.soPanelsBlockEditorAdmin.defaultMode === 'edit';
var editMode = hasPanelsData === true ? isDefaultModeEdit : true;
this.initialState = {
editing: editMode,
loadingPreview: true,
previewHtml: '',
previewInitialized: !editMode,
pendingPreviewRequest: false,
panelsInitialized: false
}; // Depending on when this function is called, we need to update the
// state differently.

if (newState) {
this.state = _objectSpread({}, this.initialState);
} else {
this.setState(_objectSpread({}, this.initialState));
}
}
}, {
key: "componentDidMount",
value: function componentDidMount() {
this.isStillMounted = true;

if (!this.state.panelsInitialized) {
this.setupPanels();
}

if (!this.previewInitialized) {
clearTimeout(this.fetchPreviewTimer);
var current = this;
this.fetchPreviewTimer = setTimeout(function () {
current.fetchPreview(current.props);
}, 1000);
}
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
var _this3 = this;

this.isStillMounted = false;

if (this.builderView) {
this.builderView.off('content_change');
// Remove builder from global builder list.
if (typeof window.soPanelsBuilderView !== 'undefined') {
window.soPanelsBuilderView = window.soPanelsBuilderView.filter(function (view) {
return view !== _this3.builderView;
});
}

delete this.builderView;
}

if (this.currentFetchRequest && typeof this.currentFetchRequest.abort === 'function') {
this.currentFetchRequest.abort();
}

clearTimeout(this.fetchPreviewTimer);

if (this.panelsContainer) {
jQuery(this.panelsContainer.current).empty();
}

if (this.previewContainer) {
jQuery(this.previewContainer.current).empty();
}

this.initializeState(this.props, false);
}
}, {
key: "componentDidUpdate",
value: function componentDidUpdate(prevProps) {
if (!this.state.panelsInitialized) {
this.setupPanels();
} else if (this.state.loadingPreview) {
if (!this.isStillMounted || !this.state.panelsInitialized) {
return;
}

if (this.state.loadingPreview) {
if (!this.state.pendingPreviewRequest) {
this.setState({
pendingPreviewRequest: true
Expand All @@ -130,10 +171,9 @@ function (_wp$element$Component) {
}, {
key: "setupPanels",
value: function setupPanels() {
var _this3 = this;
var _this4 = this;

// Should we set up panels?
if (this.state.panelsInitialized) {
if (this.state.panelsInitialized || !this.isStillMounted) {
return;
}

Expand All @@ -153,34 +193,34 @@ function (_wp$element$Component) {
var panelsData = JSON.parse(JSON.stringify(jQuery.extend({}, this.props.panelsData))); // Disable block selection while dragging rows or widgets.

var rowOrWidgetMouseDown = function rowOrWidgetMouseDown() {
if (typeof _this3.props.onRowOrWidgetMouseDown === 'function') {
_this3.props.onRowOrWidgetMouseDown();
if (typeof _this4.props.onRowOrWidgetMouseDown === 'function') {
_this4.props.onRowOrWidgetMouseDown();
}

var rowOrWidgetMouseUp = function rowOrWidgetMouseUp() {
jQuery(document).off('mouseup', rowOrWidgetMouseUp);

if (typeof _this3.props.onRowOrWidgetMouseUp === 'function') {
_this3.props.onRowOrWidgetMouseUp();
if (typeof _this4.props.onRowOrWidgetMouseUp === 'function') {
_this4.props.onRowOrWidgetMouseUp();
}
};

jQuery(document).on('mouseup', rowOrWidgetMouseUp);
};

this.builderView.on('row_added', function () {
_this3.builderView.$('.so-row-move').off('mousedown', rowOrWidgetMouseDown);
_this4.builderView.$('.so-row-move').off('mousedown', rowOrWidgetMouseDown);

_this3.builderView.$('.so-row-move').on('mousedown', rowOrWidgetMouseDown);
_this4.builderView.$('.so-row-move').on('mousedown', rowOrWidgetMouseDown);

_this3.builderView.$('.so-widget').off('mousedown', rowOrWidgetMouseDown);
_this4.builderView.$('.so-widget').off('mousedown', rowOrWidgetMouseDown);

_this3.builderView.$('.so-widget').on('mousedown', rowOrWidgetMouseDown);
_this4.builderView.$('.so-widget').on('mousedown', rowOrWidgetMouseDown);
});
this.builderView.on('widget_added', function () {
_this3.builderView.$('.so-widget').off('mousedown', rowOrWidgetMouseDown);
_this4.builderView.$('.so-widget').off('mousedown', rowOrWidgetMouseDown);

_this3.builderView.$('.so-widget').on('mousedown', rowOrWidgetMouseDown);
_this4.builderView.$('.so-widget').on('mousedown', rowOrWidgetMouseDown);
});
this.builderView.render().attach({
container: $panelsContainer
Expand Down Expand Up @@ -214,16 +254,16 @@ function (_wp$element$Component) {
};

this.builderView.on('content_change', function () {
var newPanelsData = _this3.builderView.getData();
var newPanelsData = _this4.builderView.getData();

_this3.panelsDataChanged = !SiteOriginIsPanelsEqual(panelsData, newPanelsData);
_this4.panelsDataChanged = !SiteOriginIsPanelsEqual(panelsData, newPanelsData);

if (_this3.panelsDataChanged) {
if (_this3.props.onContentChange && typeof _this3.props.onContentChange === 'function') {
_this3.props.onContentChange(newPanelsData);
if (_this4.panelsDataChanged) {
if (_this4.props.onContentChange && typeof _this4.props.onContentChange === 'function') {
_this4.props.onContentChange(newPanelsData);
}

_this3.setState({
_this4.setState({
loadingPreview: true,
previewHtml: ''
});
Expand All @@ -243,7 +283,7 @@ function (_wp$element$Component) {
}, {
key: "fetchPreview",
value: function fetchPreview(props) {
var _this4 = this;
var _this5 = this;

if (!this.isStillMounted) {
return;
Expand All @@ -259,20 +299,25 @@ function (_wp$element$Component) {
panelsData: JSON.stringify(this.builderView.getData())
}
}).then(function (preview) {
if (!_this4.isStillMounted) {
if (!_this5.isStillMounted) {
return;
}

setTimeout(function () {
jQuery(document).trigger('panels_setup_preview');
}, 1000);

if (fetchRequest === _this4.currentFetchRequest && preview) {
_this4.setState({
previewHtml: preview,
loadingPreview: false,
previewInitialized: false,
pendingPreviewRequest: false
if (fetchRequest === _this5.currentFetchRequest && preview) {
_this5.setState({
previewHtml: preview
}, // Wait until previewHTML has finished updating to cut
// down on the chance of nothing being rendered.
function () {
_this5.setState({
loadingPreview: false,
previewInitialized: false,
pendingPreviewRequest: false
});
});
}
});
Expand All @@ -281,24 +326,24 @@ function (_wp$element$Component) {
}, {
key: "render",
value: function render() {
var _this5 = this;
var _this6 = this;

var panelsData = this.props.panelsData;

var switchToEditing = function switchToEditing() {
_this5.setState({
_this6.setState({
editing: true
});

var _this = _this5;
var _this = _this6;
setTimeout(function () {
_this.builderView.trigger('builder_resize');
});
};

var switchToPreview = function switchToPreview() {
if (panelsData) {
_this5.setState({
_this6.setState({
editing: false
});
}
Expand Down
Loading

0 comments on commit 7a2e707

Please sign in to comment.