plugin install
This commit is contained in:
@@ -3,24 +3,9 @@ var __webpack_exports__ = {};
|
||||
/*!*********************************************************************************!*\
|
||||
!*** ./src/advanced-custom-fields-pro/assets/src/js/acf-escaped-html-notice.js ***!
|
||||
\*********************************************************************************/
|
||||
(function ($, undefined) {
|
||||
/* global, acf_escaped_html_notice */
|
||||
(function ($) {
|
||||
const $notice = $('.acf-escaped-html-notice');
|
||||
$notice.on('click', '.notice-dismiss', function (e) {
|
||||
const $target = $(e.target).closest('.acf-escaped-html-notice');
|
||||
let to_dismiss = 'escaped_html';
|
||||
if ($target.hasClass('acf-will-escape')) {
|
||||
to_dismiss = 'to_be_escaped';
|
||||
}
|
||||
$.ajax({
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
'action': 'acf/dismiss_escaped_html_notice',
|
||||
'nonce': acf_escaped_html_notice.nonce,
|
||||
'notice': to_dismiss
|
||||
},
|
||||
type: 'post'
|
||||
});
|
||||
});
|
||||
$notice.on('click', '.acf-show-more-details', function (e) {
|
||||
e.preventDefault();
|
||||
const $link = $(e.target);
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"file":"acf-escaped-html-notice.js","mappings":";;;;;AAAA,CAAE,UAAWA,CAAC,EAAEC,SAAS,EAAG;EAE3B,MAAMC,OAAO,GAAGF,CAAC,CAAE,0BAA2B,CAAC;EAE/CE,OAAO,CAACC,EAAE,CAAE,OAAO,EAAE,iBAAiB,EAAE,UAAUC,CAAC,EAAG;IACrD,MAAMC,OAAO,GAAGL,CAAC,CAAEI,CAAC,CAACE,MAAO,CAAC,CAACC,OAAO,CAAE,0BAA2B,CAAC;IAEnE,IAAIC,UAAU,GAAG,cAAc;IAC/B,IAAKH,OAAO,CAACI,QAAQ,CAAE,iBAAkB,CAAC,EAAG;MAC5CD,UAAU,GAAG,eAAe;IAC7B;IAEAR,CAAC,CAACU,IAAI,CAAE;MACPC,GAAG,EAAEC,OAAO;MACZC,IAAI,EAAE;QACL,QAAQ,EAAE,iCAAiC;QAC3C,OAAO,EAAEC,uBAAuB,CAACC,KAAK;QACtC,QAAQ,EAAEP;MACX,CAAC;MACDQ,IAAI,EAAE;IACP,CAAE,CAAC;EACJ,CAAE,CAAC;EAEHd,OAAO,CAACC,EAAE,CAAE,OAAO,EAAE,wBAAwB,EAAE,UAAUC,CAAC,EAAG;IAC5DA,CAAC,CAACa,cAAc,CAAC,CAAC;IAElB,MAAMC,KAAK,GAAGlB,CAAC,CAAEI,CAAC,CAACE,MAAO,CAAC;IAC3B,MAAMa,QAAQ,GAAGD,KAAK,CAACX,OAAO,CAAE,0BAA2B,CAAC,CAACa,IAAI,CAAE,oBAAqB,CAAC;IAEzF,IAAKD,QAAQ,CAACE,EAAE,CAAE,SAAU,CAAC,EAAG;MAC/BF,QAAQ,CAACG,SAAS,CAAE,GAAI,CAAC;MACzBJ,KAAK,CAACK,IAAI,CAAET,uBAAuB,CAACU,YAAa,CAAC;IACnD,CAAC,MAAM;MACNL,QAAQ,CAACM,OAAO,CAAE,GAAI,CAAC;MACvBP,KAAK,CAACK,IAAI,CAAET,uBAAuB,CAACY,YAAa,CAAC;IACnD;EACD,CAAE,CAAC;AAEJ,CAAC,EAAIC,MAAO,CAAC,C","sources":["webpack://advanced-custom-fields-pro/./src/advanced-custom-fields-pro/assets/src/js/acf-escaped-html-notice.js"],"sourcesContent":["( function ( $, undefined ) {\n\n\tconst $notice = $( '.acf-escaped-html-notice' );\n\n\t$notice.on( 'click', '.notice-dismiss', function( e ) {\n\t\tconst $target = $( e.target ).closest( '.acf-escaped-html-notice' );\n\n\t\tlet to_dismiss = 'escaped_html';\n\t\tif ( $target.hasClass( 'acf-will-escape' ) ) {\n\t\t\tto_dismiss = 'to_be_escaped';\n\t\t}\n\n\t\t$.ajax( {\n\t\t\turl: ajaxurl,\n\t\t\tdata: {\n\t\t\t\t'action': 'acf/dismiss_escaped_html_notice',\n\t\t\t\t'nonce': acf_escaped_html_notice.nonce,\n\t\t\t\t'notice': to_dismiss,\n\t\t\t},\n\t\t\ttype: 'post'\n\t\t} );\n\t} );\n\n\t$notice.on( 'click', '.acf-show-more-details', function( e ) {\n\t\te.preventDefault();\n\n\t\tconst $link = $( e.target );\n\t\tconst $details = $link.closest( '.acf-escaped-html-notice' ).find( '.acf-error-details' );\n\n\t\tif ( $details.is( ':hidden' ) ) {\n\t\t\t$details.slideDown( 100 );\n\t\t\t$link.text( acf_escaped_html_notice.hide_details );\n\t\t} else {\n\t\t\t$details.slideUp( 100 );\n\t\t\t$link.text( acf_escaped_html_notice.show_details );\n\t\t}\n\t} );\n\n} )( jQuery );\n"],"names":["$","undefined","$notice","on","e","$target","target","closest","to_dismiss","hasClass","ajax","url","ajaxurl","data","acf_escaped_html_notice","nonce","type","preventDefault","$link","$details","find","is","slideDown","text","hide_details","slideUp","show_details","jQuery"],"sourceRoot":""}
|
||||
{"version":3,"file":"acf-escaped-html-notice.js","mappings":";;;;;AAAA;AACA,CAAE,UAAWA,CAAC,EAAG;EAChB,MAAMC,OAAO,GAAGD,CAAC,CAAE,0BAA2B,CAAC;EAE/CC,OAAO,CAACC,EAAE,CAAE,OAAO,EAAE,wBAAwB,EAAE,UAAWC,CAAC,EAAG;IAC7DA,CAAC,CAACC,cAAc,CAAC,CAAC;IAElB,MAAMC,KAAK,GAAGL,CAAC,CAAEG,CAAC,CAACG,MAAO,CAAC;IAC3B,MAAMC,QAAQ,GAAGF,KAAK,CACpBG,OAAO,CAAE,0BAA2B,CAAC,CACrCC,IAAI,CAAE,oBAAqB,CAAC;IAE9B,IAAKF,QAAQ,CAACG,EAAE,CAAE,SAAU,CAAC,EAAG;MAC/BH,QAAQ,CAACI,SAAS,CAAE,GAAI,CAAC;MACzBN,KAAK,CAACO,IAAI,CAAEC,uBAAuB,CAACC,YAAa,CAAC;IACnD,CAAC,MAAM;MACNP,QAAQ,CAACQ,OAAO,CAAE,GAAI,CAAC;MACvBV,KAAK,CAACO,IAAI,CAAEC,uBAAuB,CAACG,YAAa,CAAC;IACnD;EACD,CAAE,CAAC;AACJ,CAAC,EAAIC,MAAO,CAAC,C","sources":["webpack://advanced-custom-fields-pro/./src/advanced-custom-fields-pro/assets/src/js/acf-escaped-html-notice.js"],"sourcesContent":["/* global, acf_escaped_html_notice */\n( function ( $ ) {\n\tconst $notice = $( '.acf-escaped-html-notice' );\n\n\t$notice.on( 'click', '.acf-show-more-details', function ( e ) {\n\t\te.preventDefault();\n\n\t\tconst $link = $( e.target );\n\t\tconst $details = $link\n\t\t\t.closest( '.acf-escaped-html-notice' )\n\t\t\t.find( '.acf-error-details' );\n\n\t\tif ( $details.is( ':hidden' ) ) {\n\t\t\t$details.slideDown( 100 );\n\t\t\t$link.text( acf_escaped_html_notice.hide_details );\n\t\t} else {\n\t\t\t$details.slideUp( 100 );\n\t\t\t$link.text( acf_escaped_html_notice.show_details );\n\t\t}\n\t} );\n} )( jQuery );\n"],"names":["$","$notice","on","e","preventDefault","$link","target","$details","closest","find","is","slideDown","text","acf_escaped_html_notice","hide_details","slideUp","show_details","jQuery"],"sourceRoot":""}
|
||||
@@ -1 +1 @@
|
||||
!function(e,t){const c=e(".acf-escaped-html-notice");c.on("click",".notice-dismiss",(function(t){let c="escaped_html";e(t.target).closest(".acf-escaped-html-notice").hasClass("acf-will-escape")&&(c="to_be_escaped"),e.ajax({url:ajaxurl,data:{action:"acf/dismiss_escaped_html_notice",nonce:acf_escaped_html_notice.nonce,notice:c},type:"post"})})),c.on("click",".acf-show-more-details",(function(t){t.preventDefault();const c=e(t.target),a=c.closest(".acf-escaped-html-notice").find(".acf-error-details");a.is(":hidden")?(a.slideDown(100),c.text(acf_escaped_html_notice.hide_details)):(a.slideUp(100),c.text(acf_escaped_html_notice.show_details))}))}(jQuery);
|
||||
(()=>{var e;(e=jQuery)(".acf-escaped-html-notice").on("click",".acf-show-more-details",(function(t){t.preventDefault();const c=e(t.target),a=c.closest(".acf-escaped-html-notice").find(".acf-error-details");a.is(":hidden")?(a.slideDown(100),c.text(acf_escaped_html_notice.hide_details)):(a.slideUp(100),c.text(acf_escaped_html_notice.show_details))}))})();
|
||||
@@ -104,7 +104,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
||||
const iconName = fieldType.name.replaceAll('_', '-');
|
||||
return `
|
||||
<a href="#" class="acf-field-type" data-field-type="${fieldType.name}">
|
||||
${fieldType.pro && !acf.get('is_pro') ? '<span class="field-type-requires-pro"><i class="acf-icon acf-icon-lock"></i>PRO</span>' : fieldType.pro ? '<span class="field-type-requires-pro">PRO</span>' : ''}
|
||||
${fieldType.pro && !acf.get('is_pro') ? '<span class="field-type-requires-pro not-pro"></span>' : fieldType.pro ? '<span class="field-type-requires-pro"></span>' : ''}
|
||||
<i class="field-type-icon field-type-icon-${iconName}"></i>
|
||||
<span class="field-type-label">${fieldType.label}</span>
|
||||
</a>
|
||||
@@ -566,6 +566,9 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
||||
$tabLabel: function () {
|
||||
return this.fieldObject.$el.find('.conditional-logic-badge');
|
||||
},
|
||||
$conditionalValueSelect: function () {
|
||||
return this.$('.condition-rule-value');
|
||||
},
|
||||
open: function () {
|
||||
var $div = this.$control();
|
||||
$div.show();
|
||||
@@ -705,51 +708,57 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
||||
if (!this.ruleData('field') || !this.ruleData('operator')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// vars
|
||||
var $select = this.$input('value');
|
||||
var $td = this.$td('value');
|
||||
var val = $select.val();
|
||||
var currentVal = $select.val();
|
||||
var savedValue = this.$rule[0].getAttribute('data-value');
|
||||
|
||||
// get selected field
|
||||
var $field = acf.findFieldObject(this.ruleData('field'));
|
||||
var field = acf.getFieldObject($field);
|
||||
|
||||
// get selected field conditions
|
||||
var conditionTypes = acf.getConditionTypes({
|
||||
fieldType: field.getType(),
|
||||
operator: this.ruleData('operator')
|
||||
});
|
||||
|
||||
// html
|
||||
var conditionType = conditionTypes[0].prototype;
|
||||
var choices = conditionType.choices(field);
|
||||
|
||||
// create html: array
|
||||
if (choices instanceof Array) {
|
||||
var $newSelect = $('<select></select>');
|
||||
let $newSelect;
|
||||
if (choices instanceof jQuery && !!choices.data('acfSelect2Props')) {
|
||||
$newSelect = $select.clone();
|
||||
// If converting from a disabled input, we need to convert it to an active select.
|
||||
if ($newSelect.is('input')) {
|
||||
var classes = $select.attr('class');
|
||||
const $rebuiltSelect = $('<select></select>').addClass(classes).val(savedValue);
|
||||
$newSelect = $rebuiltSelect;
|
||||
}
|
||||
acf.addAction('acf_conditional_value_rendered', function () {
|
||||
acf.newSelect2($newSelect, choices.data('acfSelect2Props'));
|
||||
});
|
||||
} else if (choices instanceof Array) {
|
||||
this.$conditionalValueSelect().removeClass('select2-hidden-accessible');
|
||||
$newSelect = $('<select></select>');
|
||||
acf.renderSelect($newSelect, choices);
|
||||
|
||||
// create html: string (<input />)
|
||||
} else {
|
||||
var $newSelect = $(choices);
|
||||
this.$conditionalValueSelect().removeClass('select2-hidden-accessible');
|
||||
$newSelect = $(choices);
|
||||
}
|
||||
|
||||
// append
|
||||
$select.detach();
|
||||
$td.html($newSelect);
|
||||
|
||||
// copy attrs
|
||||
// timeout needed to avoid browser bug where "disabled" attribute is not applied
|
||||
setTimeout(function () {
|
||||
['class', 'name', 'id'].map(function (attr) {
|
||||
$newSelect.attr(attr, $select.attr(attr));
|
||||
});
|
||||
$select.val(savedValue);
|
||||
acf.doAction('acf_conditional_value_rendered');
|
||||
}, 0);
|
||||
|
||||
// select existing value (if not a disabled input)
|
||||
if (!$newSelect.prop('disabled')) {
|
||||
acf.val($newSelect, val, true);
|
||||
acf.val($newSelect, currentVal, true);
|
||||
}
|
||||
|
||||
// set
|
||||
@@ -774,6 +783,10 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
||||
// remove all tr's except the first one
|
||||
$group2.find('tr').not(':first').remove();
|
||||
|
||||
// Find the remaining tr and render
|
||||
var $tr = $group2.find('tr');
|
||||
this.renderRule($tr);
|
||||
|
||||
// save field
|
||||
this.fieldObject.save();
|
||||
},
|
||||
@@ -1236,7 +1249,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
||||
if ($(e.target).hasClass('acf-input-wrap')) {
|
||||
copyValue = $(e.target).find('input').first().val();
|
||||
} else {
|
||||
copyValue = $(e.target).text();
|
||||
copyValue = $(e.target).text().trim();
|
||||
}
|
||||
navigator.clipboard.writeText(copyValue).then(() => {
|
||||
$(e.target).closest('.copyable').addClass('copied');
|
||||
@@ -2762,6 +2775,14 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
||||
var _field$data;
|
||||
if ((field === null || field === void 0 || (_field$data = field.data) === null || _field$data === void 0 ? void 0 : _field$data.call(field, 'key')) !== 'bidirectional_target') return args;
|
||||
args.dropdownCssClass = 'field-type-select-results';
|
||||
|
||||
// Check for a full modern version of select2 like the one provided by ACF.
|
||||
try {
|
||||
$.fn.select2.amd.require('select2/compat/dropdownCss');
|
||||
} catch (err) {
|
||||
console.warn('ACF was not able to load the full version of select2 due to a conflicting version provided by another plugin or theme taking precedence. Skipping styling of bidirectional settings.');
|
||||
delete args.dropdownCssClass;
|
||||
}
|
||||
args.templateResult = function (selection) {
|
||||
if ('undefined' !== typeof selection.element) {
|
||||
return selection;
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1238,6 +1238,7 @@
|
||||
timeout: 0,
|
||||
dismiss: true,
|
||||
target: false,
|
||||
location: 'before',
|
||||
close: function () {}
|
||||
},
|
||||
events: {
|
||||
@@ -1289,8 +1290,13 @@
|
||||
},
|
||||
show: function () {
|
||||
var $target = this.get('target');
|
||||
var location = this.get('location');
|
||||
if ($target) {
|
||||
$target.prepend(this.$el);
|
||||
if (location === 'after') {
|
||||
$target.append(this.$el);
|
||||
} else {
|
||||
$target.prepend(this.$el);
|
||||
}
|
||||
}
|
||||
},
|
||||
hide: function () {
|
||||
@@ -3323,7 +3329,6 @@
|
||||
|
||||
// filter for 3rd party customization
|
||||
data = acf.applyFilters('prepare_for_ajax', data);
|
||||
|
||||
// return
|
||||
return data;
|
||||
};
|
||||
@@ -3869,7 +3874,6 @@
|
||||
itemsHtml += '<option value="' + acf.escAttr(id) + '"' + (item.disabled ? ' disabled="disabled"' : '') + '>' + acf.strEscape(text) + '</option>';
|
||||
}
|
||||
});
|
||||
|
||||
// return
|
||||
return itemsHtml;
|
||||
};
|
||||
@@ -4349,6 +4353,15 @@
|
||||
acf.doAction('refresh');
|
||||
}, 0);
|
||||
|
||||
/**
|
||||
* Log something to console if we're in debug mode.
|
||||
*
|
||||
* @since 6.3
|
||||
*/
|
||||
acf.debug = function () {
|
||||
if (acf.get('debug')) console.log.apply(null, arguments);
|
||||
};
|
||||
|
||||
// Set up actions from events
|
||||
$(document).ready(function () {
|
||||
acf.doAction('ready');
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -40,7 +40,7 @@ const md5 = __webpack_require__(/*! md5 */ "./node_modules/md5/md5.js");
|
||||
Component
|
||||
} = React;
|
||||
const {
|
||||
withSelect
|
||||
useSelect
|
||||
} = wp.data;
|
||||
const {
|
||||
createHigherOrderComponent
|
||||
@@ -61,6 +61,15 @@ const md5 = __webpack_require__(/*! md5 */ "./node_modules/md5/md5.js");
|
||||
*/
|
||||
const blockTypes = {};
|
||||
|
||||
/**
|
||||
* Data storage for Block Instances and their DynamicHTML components.
|
||||
* This is temporarily stored on the ACF object, but this will be replaced in ACF 6.4.
|
||||
* Developers should not rely on reading or using any aspect of acf.blockInstances.
|
||||
*
|
||||
* @since 6.3
|
||||
*/
|
||||
acf.blockInstances = {};
|
||||
|
||||
/**
|
||||
* Returns a block type for the given name.
|
||||
*
|
||||
@@ -88,6 +97,19 @@ const md5 = __webpack_require__(/*! md5 */ "./node_modules/md5/md5.js");
|
||||
return blockType.acf_block_version || 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a block's validate property. Default true.
|
||||
*
|
||||
* @since 6.3
|
||||
*
|
||||
* @param string name The block name
|
||||
* @return boolean
|
||||
*/
|
||||
function blockSupportsValidation(name) {
|
||||
const blockType = getBlockType(name);
|
||||
return blockType.validate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if a block (identified by client ID) is nested in a query loop block.
|
||||
*
|
||||
@@ -229,7 +251,7 @@ const md5 = __webpack_require__(/*! md5 */ "./node_modules/md5/md5.js");
|
||||
// Remove all empty attribute defaults from PHP values to allow serialisation.
|
||||
// https://github.com/WordPress/gutenberg/issues/7342
|
||||
for (const key in blockType.attributes) {
|
||||
if (blockType.attributes[key].default.length === 0) {
|
||||
if ('default' in blockType.attributes[key] && blockType.attributes[key].default.length === 0) {
|
||||
delete blockType.attributes[key].default;
|
||||
}
|
||||
}
|
||||
@@ -264,7 +286,16 @@ const md5 = __webpack_require__(/*! md5 */ "./node_modules/md5/md5.js");
|
||||
}
|
||||
|
||||
// Set edit and save functions.
|
||||
blockType.edit = props => (0,react__WEBPACK_IMPORTED_MODULE_1__.createElement)(ThisBlockEdit, _objectSpread({}, props));
|
||||
blockType.edit = props => {
|
||||
// Ensure we remove our save lock if a block is removed.
|
||||
wp.element.useEffect(() => {
|
||||
return () => {
|
||||
if (!wp.data.dispatch('core/editor')) return;
|
||||
wp.data.dispatch('core/editor').unlockPostSaving('acf/block/' + props.clientId);
|
||||
};
|
||||
}, []);
|
||||
return (0,react__WEBPACK_IMPORTED_MODULE_1__.createElement)(ThisBlockEdit, _objectSpread({}, props));
|
||||
};
|
||||
blockType.save = () => (0,react__WEBPACK_IMPORTED_MODULE_1__.createElement)(ThisBlockSave, null);
|
||||
|
||||
// Add to storage.
|
||||
@@ -810,48 +841,62 @@ const md5 = __webpack_require__(/*! md5 */ "./node_modules/md5/md5.js");
|
||||
/**
|
||||
* The BlockBody functional component.
|
||||
*
|
||||
* @date 19/2/19
|
||||
* @since 5.7.12
|
||||
*/
|
||||
function _BlockBody(props) {
|
||||
function BlockBody(props) {
|
||||
const {
|
||||
attributes,
|
||||
isSelected,
|
||||
name
|
||||
name,
|
||||
clientId
|
||||
} = props;
|
||||
const {
|
||||
mode
|
||||
} = attributes;
|
||||
const index = useSelect(select => {
|
||||
const rootClientId = select('core/block-editor').getBlockRootClientId(clientId);
|
||||
return select('core/block-editor').getBlockIndex(clientId, rootClientId);
|
||||
});
|
||||
let showForm = true;
|
||||
let additionalClasses = 'acf-block-component acf-block-body';
|
||||
if (mode === 'auto' && !isSelected || mode === 'preview') {
|
||||
additionalClasses += ' acf-block-preview';
|
||||
showForm = false;
|
||||
}
|
||||
|
||||
// Setup block cache if required, and update mode.
|
||||
if (!(clientId in acf.blockInstances)) {
|
||||
acf.blockInstances[clientId] = {
|
||||
validation_errors: false,
|
||||
mode: mode
|
||||
};
|
||||
}
|
||||
acf.blockInstances[clientId].mode = mode;
|
||||
if (!isSelected) {
|
||||
if (blockSupportsValidation(name) && acf.blockInstances[clientId].validation_errors) {
|
||||
additionalClasses += ' acf-block-has-validation-error';
|
||||
}
|
||||
acf.blockInstances[clientId].has_been_deselected = true;
|
||||
}
|
||||
if (getBlockVersion(name) > 1) {
|
||||
return (0,react__WEBPACK_IMPORTED_MODULE_1__.createElement)("div", _objectSpread({}, useBlockProps({
|
||||
className: additionalClasses
|
||||
})), showForm ? (0,react__WEBPACK_IMPORTED_MODULE_1__.createElement)(BlockForm, _objectSpread({}, props)) : (0,react__WEBPACK_IMPORTED_MODULE_1__.createElement)(BlockPreview, _objectSpread({}, props)));
|
||||
})), showForm ? (0,react__WEBPACK_IMPORTED_MODULE_1__.createElement)(BlockForm, _objectSpread(_objectSpread({}, props), {}, {
|
||||
index: index
|
||||
})) : (0,react__WEBPACK_IMPORTED_MODULE_1__.createElement)(BlockPreview, _objectSpread(_objectSpread({}, props), {}, {
|
||||
index: index
|
||||
})));
|
||||
} else {
|
||||
return (0,react__WEBPACK_IMPORTED_MODULE_1__.createElement)("div", _objectSpread({}, useBlockProps()), (0,react__WEBPACK_IMPORTED_MODULE_1__.createElement)("div", {
|
||||
className: "acf-block-component acf-block-body"
|
||||
}, showForm ? (0,react__WEBPACK_IMPORTED_MODULE_1__.createElement)(BlockForm, _objectSpread({}, props)) : (0,react__WEBPACK_IMPORTED_MODULE_1__.createElement)(BlockPreview, _objectSpread({}, props))));
|
||||
}, showForm ? (0,react__WEBPACK_IMPORTED_MODULE_1__.createElement)(BlockForm, _objectSpread(_objectSpread({}, props), {}, {
|
||||
index: index
|
||||
})) : (0,react__WEBPACK_IMPORTED_MODULE_1__.createElement)(BlockPreview, _objectSpread(_objectSpread({}, props), {}, {
|
||||
index: index
|
||||
}))));
|
||||
}
|
||||
}
|
||||
|
||||
// Append blockIndex to component props.
|
||||
const BlockBody = withSelect((select, ownProps) => {
|
||||
const {
|
||||
clientId
|
||||
} = ownProps;
|
||||
// Use optional rootClientId to allow discoverability of child blocks.
|
||||
const rootClientId = select('core/block-editor').getBlockRootClientId(clientId);
|
||||
const index = select('core/block-editor').getBlockIndex(clientId, rootClientId);
|
||||
return {
|
||||
index
|
||||
};
|
||||
})(_BlockBody);
|
||||
|
||||
/**
|
||||
* A react component to append HTMl.
|
||||
*
|
||||
@@ -900,9 +945,6 @@ const md5 = __webpack_require__(/*! md5 */ "./node_modules/md5/md5.js");
|
||||
}
|
||||
}
|
||||
|
||||
// Data storage for DynamicHTML components.
|
||||
const store = {};
|
||||
|
||||
/**
|
||||
* DynamicHTML Class.
|
||||
*
|
||||
@@ -926,42 +968,72 @@ const md5 = __webpack_require__(/*! md5 */ "./node_modules/md5/md5.js");
|
||||
this.el = false;
|
||||
this.subscribed = true;
|
||||
this.renderMethod = 'jQuery';
|
||||
this.passedValidation = false;
|
||||
this.setup(props);
|
||||
|
||||
// Load state.
|
||||
this.loadState();
|
||||
}
|
||||
setup(props) {
|
||||
// Do nothing.
|
||||
const constructor = this.constructor.name;
|
||||
const clientId = props.clientId;
|
||||
if (!(clientId in acf.blockInstances)) {
|
||||
acf.blockInstances[clientId] = {
|
||||
validation_errors: false,
|
||||
mode: props.mode
|
||||
};
|
||||
}
|
||||
if (!(constructor in acf.blockInstances[clientId])) {
|
||||
acf.blockInstances[clientId][constructor] = {};
|
||||
}
|
||||
}
|
||||
fetch() {
|
||||
// Do nothing.
|
||||
}
|
||||
maybePreload(blockId, clientId, form) {
|
||||
if (this.state.html === undefined && !isBlockInQueryLoop(this.props.clientId)) {
|
||||
acf.debug('Preload check', blockId, clientId, form);
|
||||
if (!isBlockInQueryLoop(this.props.clientId)) {
|
||||
const preloadedBlocks = acf.get('preloadedBlocks');
|
||||
const modeText = form ? 'form' : 'preview';
|
||||
if (preloadedBlocks && preloadedBlocks[blockId]) {
|
||||
// Ensure we only preload the correct block state (form or preview).
|
||||
if (form && !preloadedBlocks[blockId].form || !form && preloadedBlocks[blockId].form) return false;
|
||||
if (form && !preloadedBlocks[blockId].form || !form && preloadedBlocks[blockId].form) {
|
||||
acf.debug('Preload failed: state not preloaded.');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set HTML to the preloaded version.
|
||||
return preloadedBlocks[blockId].html.replaceAll(blockId, clientId);
|
||||
preloadedBlocks[blockId].html = preloadedBlocks[blockId].html.replaceAll(blockId, clientId);
|
||||
|
||||
// Replace blockId in errors.
|
||||
if (preloadedBlocks[blockId].validation && preloadedBlocks[blockId].validation.errors) {
|
||||
preloadedBlocks[blockId].validation.errors = preloadedBlocks[blockId].validation.errors.map(error => {
|
||||
error.input = error.input.replaceAll(blockId, clientId);
|
||||
return error;
|
||||
});
|
||||
}
|
||||
|
||||
// Return preloaded object.
|
||||
acf.debug('Preload successful', preloadedBlocks[blockId]);
|
||||
return preloadedBlocks[blockId];
|
||||
}
|
||||
}
|
||||
acf.debug('Preload failed: not preloaded.');
|
||||
return false;
|
||||
}
|
||||
loadState() {
|
||||
this.state = store[this.id] || {};
|
||||
const client = acf.blockInstances[this.props.clientId] || {};
|
||||
this.state = client[this.constructor.name] || {};
|
||||
}
|
||||
setState(state) {
|
||||
store[this.id] = _objectSpread(_objectSpread({}, this.state), state);
|
||||
acf.blockInstances[this.props.clientId][this.constructor.name] = _objectSpread(_objectSpread({}, this.state), state);
|
||||
|
||||
// Update component state if subscribed.
|
||||
// - Allows AJAX callback to update store without modifying state of an unmounted component.
|
||||
if (this.subscribed) {
|
||||
super.setState(state);
|
||||
}
|
||||
acf.debug('SetState', Object.assign({}, this), this.props.clientId, this.constructor.name, Object.assign({}, acf.blockInstances[this.props.clientId][this.constructor.name]));
|
||||
}
|
||||
setHtml(html) {
|
||||
html = html ? html.trim() : '';
|
||||
@@ -1051,6 +1123,13 @@ const md5 = __webpack_require__(/*! md5 */ "./node_modules/md5/md5.js");
|
||||
}
|
||||
}
|
||||
|
||||
// Lock block if required.
|
||||
if (this.getValidationErrors() && this.isNotNewlyAdded()) {
|
||||
this.lockBlockForSaving();
|
||||
} else {
|
||||
this.unlockBlockForSaving();
|
||||
}
|
||||
|
||||
// Call context specific method.
|
||||
switch (context) {
|
||||
case 'append':
|
||||
@@ -1061,6 +1140,9 @@ const md5 = __webpack_require__(/*! md5 */ "./node_modules/md5/md5.js");
|
||||
break;
|
||||
}
|
||||
}
|
||||
validate() {
|
||||
// Do nothing.
|
||||
}
|
||||
componentDidMount() {
|
||||
// Fetch on first load.
|
||||
if (this.state.html === undefined) {
|
||||
@@ -1102,6 +1184,65 @@ const md5 = __webpack_require__(/*! md5 */ "./node_modules/md5/md5.js");
|
||||
acf.doAction('remount', this.state.$el);
|
||||
});
|
||||
}
|
||||
isNotNewlyAdded() {
|
||||
return acf.blockInstances[this.props.clientId].has_been_deselected || false;
|
||||
}
|
||||
hasShownValidation() {
|
||||
return acf.blockInstances[this.props.clientId].shown_validation || false;
|
||||
}
|
||||
setShownValidation() {
|
||||
acf.blockInstances[this.props.clientId].shown_validation = true;
|
||||
}
|
||||
setValidationErrors(errors) {
|
||||
acf.blockInstances[this.props.clientId].validation_errors = errors;
|
||||
}
|
||||
getValidationErrors() {
|
||||
return acf.blockInstances[this.props.clientId].validation_errors;
|
||||
}
|
||||
getMode() {
|
||||
return acf.blockInstances[this.props.clientId].mode;
|
||||
}
|
||||
lockBlockForSaving() {
|
||||
if (!wp.data.dispatch('core/editor')) return;
|
||||
wp.data.dispatch('core/editor').lockPostSaving('acf/block/' + this.props.clientId);
|
||||
}
|
||||
unlockBlockForSaving() {
|
||||
if (!wp.data.dispatch('core/editor')) return;
|
||||
wp.data.dispatch('core/editor').unlockPostSaving('acf/block/' + this.props.clientId);
|
||||
}
|
||||
displayValidation($formEl) {
|
||||
if (!blockSupportsValidation(this.props.name)) {
|
||||
acf.debug('Block does not support validation');
|
||||
return;
|
||||
}
|
||||
if (!$formEl || $formEl.hasClass('acf-empty-block-fields')) {
|
||||
acf.debug('There is no edit form available to validate.');
|
||||
return;
|
||||
}
|
||||
const errors = this.getValidationErrors();
|
||||
acf.debug('Starting handle validation', Object.assign({}, this), Object.assign({}, $formEl), errors);
|
||||
this.setShownValidation();
|
||||
let validator = acf.getBlockFormValidator($formEl);
|
||||
validator.clearErrors();
|
||||
acf.doAction('blocks/validation/pre_apply', errors);
|
||||
if (errors) {
|
||||
validator.addErrors(errors);
|
||||
validator.showErrors('after');
|
||||
this.lockBlockForSaving();
|
||||
} else {
|
||||
// remove previous error message
|
||||
if (validator.has('notice')) {
|
||||
validator.get('notice').update({
|
||||
type: 'success',
|
||||
text: acf.__('Validation successful'),
|
||||
timeout: 1000
|
||||
});
|
||||
validator.set('notice', null);
|
||||
}
|
||||
this.unlockBlockForSaving();
|
||||
}
|
||||
acf.doAction('blocks/validation/post_apply', errors);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1116,46 +1257,93 @@ const md5 = __webpack_require__(/*! md5 */ "./node_modules/md5/md5.js");
|
||||
* @return void
|
||||
*/
|
||||
class BlockForm extends DynamicHTML {
|
||||
setup({
|
||||
clientId
|
||||
}) {
|
||||
this.id = `BlockForm-${clientId}`;
|
||||
setup(props) {
|
||||
this.id = `BlockForm-${props.clientId}`;
|
||||
super.setup(props);
|
||||
}
|
||||
fetch() {
|
||||
fetch(validate_only = false, data = false) {
|
||||
// Extract props.
|
||||
const {
|
||||
attributes,
|
||||
context,
|
||||
clientId
|
||||
clientId,
|
||||
name
|
||||
} = this.props;
|
||||
let {
|
||||
attributes
|
||||
} = this.props;
|
||||
let query = {
|
||||
form: true
|
||||
};
|
||||
if (validate_only) {
|
||||
query = {
|
||||
validate: true
|
||||
};
|
||||
attributes.data = data;
|
||||
}
|
||||
const hash = createBlockAttributesHash(attributes, context);
|
||||
acf.debug('BlockForm fetch', attributes, query);
|
||||
|
||||
// Try preloaded data first.
|
||||
const preloaded = this.maybePreload(hash, clientId, true);
|
||||
if (preloaded) {
|
||||
this.setHtml(preloaded);
|
||||
this.setHtml(acf.applyFilters('blocks/form/render', preloaded.html, true));
|
||||
if (preloaded.validation) this.setValidationErrors(preloaded.validation.errors);
|
||||
return;
|
||||
}
|
||||
if (!blockSupportsValidation(name)) {
|
||||
query.validate = false;
|
||||
}
|
||||
|
||||
// Request AJAX and update HTML on complete.
|
||||
fetchBlock({
|
||||
attributes,
|
||||
context,
|
||||
clientId,
|
||||
query: {
|
||||
form: true
|
||||
}
|
||||
query
|
||||
}).done(({
|
||||
data
|
||||
}) => {
|
||||
this.setHtml(data.form.replaceAll(data.clientId, clientId));
|
||||
acf.debug('fetch block form promise');
|
||||
if (data.form) {
|
||||
this.setHtml(acf.applyFilters('blocks/form/render', data.form.replaceAll(data.clientId, clientId), false));
|
||||
}
|
||||
if (data.validation) this.setValidationErrors(data.validation.errors);
|
||||
if (this.isNotNewlyAdded()) {
|
||||
acf.debug("Block has already shown it's invalid. The form needs to show validation errors");
|
||||
this.validate();
|
||||
}
|
||||
});
|
||||
}
|
||||
validate(loadState = true) {
|
||||
if (loadState) {
|
||||
this.loadState();
|
||||
}
|
||||
acf.debug('BlockForm calling validate with state', Object.assign({}, this));
|
||||
super.displayValidation(this.state.$el);
|
||||
}
|
||||
shouldComponentUpdate(nextProps, nextState) {
|
||||
if (blockSupportsValidation(this.props.name) && this.state.$el && this.isNotNewlyAdded() && !this.hasShownValidation()) {
|
||||
this.validate(false); // Shouldn't update state in shouldComponentUpdate.
|
||||
}
|
||||
return super.shouldComponentUpdate(nextProps, nextState);
|
||||
}
|
||||
componentWillUnmount() {
|
||||
super.componentWillUnmount();
|
||||
|
||||
//TODO: either delete this, or clear validations here (if that's a sensible idea)
|
||||
|
||||
acf.debug('BlockForm Component did unmount');
|
||||
}
|
||||
componentDidRemount() {
|
||||
super.componentDidRemount();
|
||||
acf.debug('BlockForm component did remount');
|
||||
const {
|
||||
$el
|
||||
} = this.state;
|
||||
if (blockSupportsValidation(this.props.name) && this.isNotNewlyAdded()) {
|
||||
acf.debug("Block has already shown it's invalid. The form needs to show validation errors");
|
||||
this.validate();
|
||||
}
|
||||
|
||||
// Make sure our on append events are registered.
|
||||
if ($el.data('acf-events-added') !== true) {
|
||||
@@ -1164,21 +1352,23 @@ const md5 = __webpack_require__(/*! md5 */ "./node_modules/md5/md5.js");
|
||||
}
|
||||
componentDidAppend() {
|
||||
super.componentDidAppend();
|
||||
acf.debug('BlockForm component did append');
|
||||
|
||||
// Extract props.
|
||||
const {
|
||||
attributes,
|
||||
setAttributes,
|
||||
clientId
|
||||
clientId,
|
||||
name
|
||||
} = this.props;
|
||||
const props = this.props;
|
||||
const thisBlockForm = this;
|
||||
const {
|
||||
$el
|
||||
} = this.state;
|
||||
|
||||
// Callback for updating block data.
|
||||
// Callback for updating block data and validation status if we're in an edit only mode.
|
||||
function serializeData(silent = false) {
|
||||
const data = acf.serialize($el, `acf-${clientId}`);
|
||||
const data = acf.serialize($el, `acf-block_${clientId}`);
|
||||
if (silent) {
|
||||
attributes.data = data;
|
||||
} else {
|
||||
@@ -1186,6 +1376,10 @@ const md5 = __webpack_require__(/*! md5 */ "./node_modules/md5/md5.js");
|
||||
data
|
||||
});
|
||||
}
|
||||
if (blockSupportsValidation(name) && !silent && thisBlockForm.getMode() !== 'preview') {
|
||||
acf.debug('No block preview currently available. Need to trigger a validation only fetch.');
|
||||
thisBlockForm.fetch(true, data);
|
||||
}
|
||||
}
|
||||
|
||||
// Add events.
|
||||
@@ -1218,17 +1412,15 @@ const md5 = __webpack_require__(/*! md5 */ "./node_modules/md5/md5.js");
|
||||
* @return void
|
||||
*/
|
||||
class BlockPreview extends DynamicHTML {
|
||||
setup({
|
||||
clientId,
|
||||
name
|
||||
}) {
|
||||
const blockType = getBlockType(name);
|
||||
setup(props) {
|
||||
const blockType = getBlockType(props.name);
|
||||
const contextPostId = acf.isget(this.props, 'context', 'postId');
|
||||
this.id = `BlockPreview-${clientId}`;
|
||||
this.id = `BlockPreview-${props.clientId}`;
|
||||
super.setup(props);
|
||||
|
||||
// Apply the contextPostId to the ID if set to stop query loop ID duplication.
|
||||
if (contextPostId) {
|
||||
this.id = `BlockPreview-${clientId}-${contextPostId}`;
|
||||
this.id = `BlockPreview-${props.clientId}-${contextPostId}`;
|
||||
}
|
||||
if (blockType.supports.jsx) {
|
||||
this.renderMethod = 'jsx';
|
||||
@@ -1256,20 +1448,25 @@ const md5 = __webpack_require__(/*! md5 */ "./node_modules/md5/md5.js");
|
||||
let preloaded = this.maybePreload(hash, clientId, false);
|
||||
if (preloaded) {
|
||||
if (getBlockVersion(name) == 1) {
|
||||
preloaded = '<div class="acf-block-preview">' + preloaded + '</div>';
|
||||
preloaded.html = '<div class="acf-block-preview">' + preloaded.html + '</div>';
|
||||
}
|
||||
this.setHtml(preloaded);
|
||||
this.setHtml(acf.applyFilters('blocks/preview/render', preloaded.html, true));
|
||||
if (preloaded.validation) this.setValidationErrors(preloaded.validation.errors);
|
||||
return;
|
||||
}
|
||||
let query = {
|
||||
preview: true
|
||||
};
|
||||
if (!blockSupportsValidation(name)) {
|
||||
query.validate = false;
|
||||
}
|
||||
|
||||
// Request AJAX and update HTML on complete.
|
||||
fetchBlock({
|
||||
attributes,
|
||||
context,
|
||||
clientId,
|
||||
query: {
|
||||
preview: true
|
||||
},
|
||||
query,
|
||||
delay
|
||||
}).done(({
|
||||
data
|
||||
@@ -1278,9 +1475,24 @@ const md5 = __webpack_require__(/*! md5 */ "./node_modules/md5/md5.js");
|
||||
if (getBlockVersion(name) == 1) {
|
||||
replaceHtml = '<div class="acf-block-preview">' + replaceHtml + '</div>';
|
||||
}
|
||||
this.setHtml(replaceHtml);
|
||||
acf.debug('fetch block render promise');
|
||||
this.setHtml(acf.applyFilters('blocks/preview/render', replaceHtml, false));
|
||||
if (data.validation) {
|
||||
this.setValidationErrors(data.validation.errors);
|
||||
}
|
||||
if (this.isNotNewlyAdded()) {
|
||||
this.validate();
|
||||
}
|
||||
});
|
||||
}
|
||||
validate() {
|
||||
// Check we've got a block form for this instance.
|
||||
const client = acf.blockInstances[this.props.clientId] || {};
|
||||
const blockFormState = client.BlockForm || false;
|
||||
if (blockFormState) {
|
||||
super.displayValidation(blockFormState.$el);
|
||||
}
|
||||
}
|
||||
componentDidAppend() {
|
||||
super.componentDidAppend();
|
||||
this.renderBlockPreviewEvent();
|
||||
@@ -1300,6 +1512,7 @@ const md5 = __webpack_require__(/*! md5 */ "./node_modules/md5/md5.js");
|
||||
if (nextAttributes.anchor !== thisAttributes.anchor) {
|
||||
delay = 300;
|
||||
}
|
||||
acf.debug('Triggering fetch from block preview shouldComponentUpdate');
|
||||
this.fetch({
|
||||
attributes: nextAttributes,
|
||||
context: nextProps.context,
|
||||
@@ -1337,9 +1550,11 @@ const md5 = __webpack_require__(/*! md5 */ "./node_modules/md5/md5.js");
|
||||
}
|
||||
componentDidRemount() {
|
||||
super.componentDidRemount();
|
||||
acf.debug('Checking if fetch is required in BlockPreview componentDidRemount', Object.assign({}, this.state.prevAttributes), Object.assign({}, this.props.attributes), Object.assign({}, this.state.prevContext), Object.assign({}, this.props.context));
|
||||
|
||||
// Update preview if data has changed since last render (changing from "edit" to "preview").
|
||||
if (!compareObjects(this.state.prevAttributes, this.props.attributes) || !compareObjects(this.state.prevContext, this.props.context)) {
|
||||
acf.debug('Triggering block preview fetch from componentDidRemount');
|
||||
this.fetch();
|
||||
}
|
||||
|
||||
@@ -1586,11 +1801,23 @@ const md5 = __webpack_require__(/*! md5 */ "./node_modules/md5/md5.js");
|
||||
* @return string
|
||||
*/
|
||||
function createBlockAttributesHash(attributes, context) {
|
||||
attributes['_acf_context'] = context;
|
||||
return md5(JSON.stringify(Object.keys(attributes).sort().reduce((acc, currValue) => {
|
||||
acc[currValue] = attributes[currValue];
|
||||
attributes['_acf_context'] = sortObjectByKey(context);
|
||||
return md5(JSON.stringify(sortObjectByKey(attributes)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Key sort an object
|
||||
*
|
||||
* @since 6.3.1
|
||||
*
|
||||
* @param object toSort The object to be sorted
|
||||
* @return object
|
||||
*/
|
||||
function sortObjectByKey(toSort) {
|
||||
return Object.keys(toSort).sort().reduce((acc, currValue) => {
|
||||
acc[currValue] = toSort[currValue];
|
||||
return acc;
|
||||
}, {})));
|
||||
}, {});
|
||||
}
|
||||
})(jQuery);
|
||||
|
||||
@@ -2293,7 +2520,7 @@ if (
|
||||
) {
|
||||
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
||||
}
|
||||
var ReactVersion = '18.2.0';
|
||||
var ReactVersion = '18.3.1';
|
||||
|
||||
// ATTENTION
|
||||
// When adding new symbols to this file,
|
||||
@@ -4969,6 +5196,7 @@ exports.PureComponent = PureComponent;
|
||||
exports.StrictMode = REACT_STRICT_MODE_TYPE;
|
||||
exports.Suspense = REACT_SUSPENSE_TYPE;
|
||||
exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = ReactSharedInternals;
|
||||
exports.act = act;
|
||||
exports.cloneElement = cloneElement$1;
|
||||
exports.createContext = createContext;
|
||||
exports.createElement = createElement$1;
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -204,6 +204,7 @@
|
||||
initialize: function () {
|
||||
// add sortable
|
||||
var $tbody = this.$el.parent();
|
||||
$tbody.css('position', 'relative');
|
||||
if (!$tbody.hasClass('ui-sortable')) {
|
||||
$tbody.sortable({
|
||||
items: '> .acf-field-setting-fc_layout',
|
||||
@@ -254,6 +255,7 @@
|
||||
return $settings.hasClass('open');
|
||||
},
|
||||
open: function (element, isAddingLayout) {
|
||||
const $header = element ? element.children('.acf-field-settings-fc_head') : this.$el.children('.acf-field-settings-fc_head');
|
||||
const $settings = element ? element.children('.acf-field-layout-settings') : this.$el.children('.acf-field-layout-settings');
|
||||
const toggle = element ? element.find('.toggle-indicator').first() : this.$el.find('.toggle-indicator').first();
|
||||
|
||||
@@ -275,8 +277,10 @@
|
||||
toggle.removeClass('closed');
|
||||
}
|
||||
$settings.addClass('open');
|
||||
$header.addClass('open');
|
||||
},
|
||||
close: function () {
|
||||
const $header = this.$el.children('.acf-field-settings-fc_head');
|
||||
const $settings = this.$el.children('.acf-field-layout-settings');
|
||||
const toggle = this.$el.find('.toggle-indicator').first();
|
||||
|
||||
@@ -284,6 +288,7 @@
|
||||
$settings.slideUp();
|
||||
$settings.removeClass('open');
|
||||
toggle.removeClass('open');
|
||||
$header.removeClass('open');
|
||||
if (!toggle.hasClass('closed')) {
|
||||
toggle.addClass('closed');
|
||||
}
|
||||
@@ -304,7 +309,7 @@
|
||||
}
|
||||
},
|
||||
onChangeName: function (e, $el) {
|
||||
const sanitizedName = acf.strSanitize($el.val());
|
||||
const sanitizedName = acf.strSanitize($el.val(), false);
|
||||
$el.val(sanitizedName);
|
||||
this.set('layoutName', sanitizedName);
|
||||
this.$el.attr('data-layout-name', sanitizedName);
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user