Run autofix code style

This commit is contained in:
Emili Castells Guasch 2024-07-23 14:36:22 +02:00
commit cf8eaba0a3
173 changed files with 14902 additions and 11906 deletions

View file

@ -1,25 +1,21 @@
import DisplayManager from "./common/display-manager/DisplayManager";
import moveWrappedElements from "./common/wrapped-elements";
import DisplayManager from './common/display-manager/DisplayManager';
import moveWrappedElements from './common/wrapped-elements';
document.addEventListener(
'DOMContentLoaded',
() => {
document.addEventListener( 'DOMContentLoaded', () => {
// Wait for current execution context to end.
setTimeout( function () {
moveWrappedElements();
}, 0 );
// Wait for current execution context to end.
setTimeout(function () {
moveWrappedElements();
}, 0);
// Initialize DisplayManager.
const displayManager = new DisplayManager();
// Initialize DisplayManager.
const displayManager = new DisplayManager();
jQuery( '*[data-ppcp-display]' ).each( ( index, el ) => {
const rules = jQuery( el ).data( 'ppcpDisplay' );
for ( const rule of rules ) {
displayManager.addRule( rule );
}
} );
jQuery( '*[data-ppcp-display]' ).each( (index, el) => {
const rules = jQuery(el).data('ppcpDisplay');
for (const rule of rules) {
displayManager.addRule(rule);
}
});
displayManager.register();
}
);
displayManager.register();
} );

View file

@ -1,17 +1,19 @@
import VisibilityAction from "./action/VisibilityAction";
import AttributeAction from "./action/AttributeAction";
import VisibilityAction from './action/VisibilityAction';
import AttributeAction from './action/AttributeAction';
class ActionFactory {
static make(actionConfig) {
switch (actionConfig.type) {
case 'visibility':
return new VisibilityAction(actionConfig);
case 'attribute':
return new AttributeAction(actionConfig);
}
static make( actionConfig ) {
switch ( actionConfig.type ) {
case 'visibility':
return new VisibilityAction( actionConfig );
case 'attribute':
return new AttributeAction( actionConfig );
}
throw new Error('[ActionFactory] Unknown action: ' + actionConfig.type);
}
throw new Error(
'[ActionFactory] Unknown action: ' + actionConfig.type
);
}
}
export default ActionFactory;

View file

@ -1,20 +1,25 @@
import ElementCondition from "./condition/ElementCondition";
import BoolCondition from "./condition/BoolCondition";
import JsVariableCondition from "./condition/JsVariableCondition";
import ElementCondition from './condition/ElementCondition';
import BoolCondition from './condition/BoolCondition';
import JsVariableCondition from './condition/JsVariableCondition';
class ConditionFactory {
static make(conditionConfig, triggerUpdate) {
switch (conditionConfig.type) {
case 'element':
return new ElementCondition(conditionConfig, triggerUpdate);
case 'bool':
return new BoolCondition(conditionConfig, triggerUpdate);
case 'js_variable':
return new JsVariableCondition(conditionConfig, triggerUpdate);
}
static make( conditionConfig, triggerUpdate ) {
switch ( conditionConfig.type ) {
case 'element':
return new ElementCondition( conditionConfig, triggerUpdate );
case 'bool':
return new BoolCondition( conditionConfig, triggerUpdate );
case 'js_variable':
return new JsVariableCondition(
conditionConfig,
triggerUpdate
);
}
throw new Error('[ConditionFactory] Unknown condition: ' + conditionConfig.type);
}
throw new Error(
'[ConditionFactory] Unknown condition: ' + conditionConfig.type
);
}
}
export default ConditionFactory;

View file

@ -1,32 +1,35 @@
import Rule from "./Rule";
import Rule from './Rule';
class DisplayManager {
constructor() {
this.rules = {};
this.ruleStatus = {}; // The current status for each rule. Maybe not necessary, for now just for logging.
constructor() {
this.rules = {};
this.ruleStatus = {}; // The current status for each rule. Maybe not necessary, for now just for logging.
document.ppcpDisplayManagerLog = () => {
console.log( 'DisplayManager', this );
};
}
document.ppcpDisplayManagerLog = () => {
console.log('DisplayManager', this);
}
}
addRule( ruleConfig ) {
const updateStatus = () => {
this.ruleStatus[ ruleConfig.key ] =
this.rules[ ruleConfig.key ].status;
//console.log('ruleStatus', this.ruleStatus);
};
addRule(ruleConfig) {
const updateStatus = () => {
this.ruleStatus[ruleConfig.key] = this.rules[ruleConfig.key].status;
//console.log('ruleStatus', this.ruleStatus);
}
this.rules[ ruleConfig.key ] = new Rule(
ruleConfig,
updateStatus.bind( this )
);
//console.log('Rule', this.rules[ruleConfig.key]);
}
this.rules[ruleConfig.key] = new Rule(ruleConfig, updateStatus.bind(this));
//console.log('Rule', this.rules[ruleConfig.key]);
}
register() {
this.ruleStatus = {};
for (const [key, rule] of Object.entries(this.rules)) {
rule.register();
}
}
register() {
this.ruleStatus = {};
for ( const [ key, rule ] of Object.entries( this.rules ) ) {
rule.register();
}
}
}
export default DisplayManager;

View file

@ -1,68 +1,69 @@
import ConditionFactory from "./ConditionFactory";
import ActionFactory from "./ActionFactory";
import ConditionFactory from './ConditionFactory';
import ActionFactory from './ActionFactory';
class Rule {
constructor( config, triggerUpdate ) {
this.config = config;
this.conditions = {};
this.actions = {};
this.triggerUpdate = triggerUpdate;
this.status = null;
constructor(config, triggerUpdate) {
this.config = config;
this.conditions = {};
this.actions = {};
this.triggerUpdate = triggerUpdate;
this.status = null;
const updateStatus = this.updateStatus.bind( this );
for ( const conditionConfig of this.config.conditions ) {
const condition = ConditionFactory.make(
conditionConfig,
updateStatus
);
this.conditions[ condition.key ] = condition;
const updateStatus = this.updateStatus.bind(this);
for (const conditionConfig of this.config.conditions) {
const condition = ConditionFactory.make(conditionConfig, updateStatus);
this.conditions[condition.key] = condition;
//console.log('Condition', condition);
}
//console.log('Condition', condition);
}
for ( const actionConfig of this.config.actions ) {
const action = ActionFactory.make( actionConfig );
this.actions[ action.key ] = action;
for (const actionConfig of this.config.actions) {
const action = ActionFactory.make(actionConfig);
this.actions[action.key] = action;
//console.log('Action', action);
}
}
//console.log('Action', action);
}
}
get key() {
return this.config.key;
}
get key() {
return this.config.key;
}
updateStatus( forceRunActions = false ) {
let status = true;
updateStatus(forceRunActions = false) {
let status = true;
for ( const [ key, condition ] of Object.entries( this.conditions ) ) {
status &= condition.status;
}
for (const [key, condition] of Object.entries(this.conditions)) {
status &= condition.status;
}
if ( status !== this.status ) {
this.status = status;
this.triggerUpdate();
this.runActions();
} else if ( forceRunActions ) {
this.runActions();
}
}
if (status !== this.status) {
this.status = status;
this.triggerUpdate();
this.runActions();
} else if (forceRunActions) {
this.runActions();
}
}
runActions() {
for ( const [ key, action ] of Object.entries( this.actions ) ) {
action.run( this.status );
}
}
runActions() {
for (const [key, action] of Object.entries(this.actions)) {
action.run(this.status);
}
}
register() {
for (const [key, condition] of Object.entries(this.conditions)) {
condition.register(this.updateStatus.bind(this));
}
for (const [key, action] of Object.entries(this.actions)) {
action.register();
}
this.updateStatus(true);
}
register() {
for ( const [ key, condition ] of Object.entries( this.conditions ) ) {
condition.register( this.updateStatus.bind( this ) );
}
for ( const [ key, action ] of Object.entries( this.actions ) ) {
action.register();
}
this.updateStatus( true );
}
}
export default Rule;

View file

@ -1,17 +1,15 @@
import BaseAction from "./BaseAction";
import BaseAction from './BaseAction';
class AttributeAction extends BaseAction {
run(status) {
if (status) {
jQuery(this.config.selector).addClass(this.config.html_class);
} else {
jQuery(this.config.selector).removeClass(this.config.html_class);
}
}
run( status ) {
if ( status ) {
jQuery( this.config.selector ).addClass( this.config.html_class );
} else {
jQuery( this.config.selector ).removeClass(
this.config.html_class
);
}
}
}
export default AttributeAction;

View file

@ -1,21 +1,19 @@
class BaseAction {
constructor( config ) {
this.config = config;
}
constructor(config) {
this.config = config;
}
get key() {
return this.config.key;
}
get key() {
return this.config.key;
}
register() {
// To override.
}
register() {
// To override.
}
run(status) {
// To override.
}
run( status ) {
// To override.
}
}
export default BaseAction;

View file

@ -1,35 +1,35 @@
import BaseAction from "./BaseAction";
import BaseAction from './BaseAction';
class VisibilityAction extends BaseAction {
run(status) {
if (status) {
if (this.config.action === 'visible') {
jQuery(this.config.selector).removeClass('ppcp-field-hidden');
}
if (this.config.action === 'enable') {
jQuery(this.config.selector).removeClass('ppcp-field-disabled')
.off('mouseup')
.find('> *')
.css('pointer-events', '');
}
} else {
if (this.config.action === 'visible') {
jQuery(this.config.selector).addClass('ppcp-field-hidden');
}
if (this.config.action === 'enable') {
jQuery(this.config.selector).addClass('ppcp-field-disabled')
.on('mouseup', function(event) {
event.stopImmediatePropagation();
})
.find('> *')
.css('pointer-events', 'none');
}
}
}
run( status ) {
if ( status ) {
if ( this.config.action === 'visible' ) {
jQuery( this.config.selector ).removeClass(
'ppcp-field-hidden'
);
}
if ( this.config.action === 'enable' ) {
jQuery( this.config.selector )
.removeClass( 'ppcp-field-disabled' )
.off( 'mouseup' )
.find( '> *' )
.css( 'pointer-events', '' );
}
} else {
if ( this.config.action === 'visible' ) {
jQuery( this.config.selector ).addClass( 'ppcp-field-hidden' );
}
if ( this.config.action === 'enable' ) {
jQuery( this.config.selector )
.addClass( 'ppcp-field-disabled' )
.on( 'mouseup', function ( event ) {
event.stopImmediatePropagation();
} )
.find( '> *' )
.css( 'pointer-events', 'none' );
}
}
}
}
export default VisibilityAction;

View file

@ -1,19 +1,17 @@
class BaseCondition {
constructor( config, triggerUpdate ) {
this.config = config;
this.status = false;
this.triggerUpdate = triggerUpdate;
}
constructor(config, triggerUpdate) {
this.config = config;
this.status = false;
this.triggerUpdate = triggerUpdate;
}
get key() {
return this.config.key;
}
get key() {
return this.config.key;
}
register() {
// To override.
}
register() {
// To override.
}
}
export default BaseCondition;

View file

@ -1,15 +1,13 @@
import BaseCondition from "./BaseCondition";
import BaseCondition from './BaseCondition';
class BoolCondition extends BaseCondition {
register() {
this.status = this.check();
}
register() {
this.status = this.check();
}
check() {
return !! this.config.value;
}
check() {
return !! this.config.value;
}
}
export default BoolCondition;

View file

@ -1,27 +1,25 @@
import BaseCondition from "./BaseCondition";
import {inputValue} from "../../../helper/form";
import BaseCondition from './BaseCondition';
import { inputValue } from '../../../helper/form';
class ElementCondition extends BaseCondition {
register() {
jQuery( document ).on( 'change', this.config.selector, () => {
const status = this.check();
if ( status !== this.status ) {
this.status = status;
this.triggerUpdate();
}
} );
register() {
jQuery(document).on('change', this.config.selector, () => {
const status = this.check();
if (status !== this.status) {
this.status = status;
this.triggerUpdate();
}
});
this.status = this.check();
}
this.status = this.check();
}
check() {
let value = inputValue(this.config.selector);
value = (value !== null ? value.toString() : value);
return this.config.value === value;
}
check() {
let value = inputValue( this.config.selector );
value = value !== null ? value.toString() : value;
return this.config.value === value;
}
}
export default ElementCondition;

View file

@ -1,24 +1,22 @@
import BaseCondition from "./BaseCondition";
import BaseCondition from './BaseCondition';
class JsVariableCondition extends BaseCondition {
register() {
jQuery( document ).on( 'ppcp-display-change', () => {
const status = this.check();
if ( status !== this.status ) {
this.status = status;
this.triggerUpdate();
}
} );
register() {
jQuery(document).on('ppcp-display-change', () => {
const status = this.check();
if (status !== this.status) {
this.status = status;
this.triggerUpdate();
}
});
this.status = this.check();
}
check() {
let value = document[this.config.variable];
return this.config.value === value;
}
this.status = this.check();
}
check() {
const value = document[ this.config.variable ];
return this.config.value === value;
}
}
export default JsVariableCondition;

View file

@ -1,14 +1,13 @@
// This function is needed because WordPress moves our custom notices to the global placeholder.
function moveWrappedElements() {
(($) => {
$('*[data-ppcp-wrapper]').each(function() {
let $wrapper = $('.' + $(this).data('ppcpWrapper'));
if ($wrapper.length) {
$wrapper.append(this);
}
});
})(jQuery)
( ( $ ) => {
$( '*[data-ppcp-wrapper]' ).each( function () {
const $wrapper = $( '.' + $( this ).data( 'ppcpWrapper' ) );
if ( $wrapper.length ) {
$wrapper.append( this );
}
} );
} )( jQuery );
}
export default moveWrappedElements;

View file

@ -1,55 +1,64 @@
window.addEventListener('load', function() {
window.addEventListener( 'load', function () {
function _loadBeaconJS( options ) {
const script = document.createElement( 'script' );
script.src = options.fnUrl;
document.body.appendChild( script );
}
function _loadBeaconJS(options) {
var script = document.createElement('script');
script.src = options.fnUrl;
document.body.appendChild(script);
}
function _injectConfig() {
let script = document.querySelector(
"[fncls='fnparams-dede7cc5-15fd-4c75-a9f4-36c430ee3a99']"
);
if ( script ) {
if ( script.parentNode ) {
script.parentNode.removeChild( script );
}
}
function _injectConfig() {
var script = document.querySelector("[fncls='fnparams-dede7cc5-15fd-4c75-a9f4-36c430ee3a99']");
if (script) {
if (script.parentNode) {
script.parentNode.removeChild(script);
}
}
script = document.createElement( 'script' );
script.id = 'fconfig';
script.type = 'application/json';
script.setAttribute(
'fncls',
'fnparams-dede7cc5-15fd-4c75-a9f4-36c430ee3a99'
);
script = document.createElement('script');
script.id = 'fconfig';
script.type = 'application/json';
script.setAttribute('fncls', 'fnparams-dede7cc5-15fd-4c75-a9f4-36c430ee3a99');
const configuration = {
f: FraudNetConfig.f,
s: FraudNetConfig.s,
};
if ( FraudNetConfig.sandbox === '1' ) {
configuration.sandbox = true;
}
var configuration = {
'f': FraudNetConfig.f,
's': FraudNetConfig.s
};
if(FraudNetConfig.sandbox === '1') {
configuration.sandbox = true;
}
script.text = JSON.stringify( configuration );
document.body.appendChild( script );
script.text = JSON.stringify(configuration);
document.body.appendChild(script);
const payForOrderForm = document.forms.order_review;
if ( payForOrderForm ) {
const puiPayForOrderSessionId = document.createElement( 'input' );
puiPayForOrderSessionId.setAttribute( 'type', 'hidden' );
puiPayForOrderSessionId.setAttribute(
'name',
'pui_pay_for_order_session_id'
);
puiPayForOrderSessionId.setAttribute( 'value', FraudNetConfig.f );
payForOrderForm.appendChild( puiPayForOrderSessionId );
}
const payForOrderForm = document.forms.order_review;
if(payForOrderForm) {
const puiPayForOrderSessionId = document.createElement('input');
puiPayForOrderSessionId.setAttribute('type', 'hidden');
puiPayForOrderSessionId.setAttribute('name', 'pui_pay_for_order_session_id');
puiPayForOrderSessionId.setAttribute('value', FraudNetConfig.f);
payForOrderForm.appendChild(puiPayForOrderSessionId);
}
_loadBeaconJS( { fnUrl: 'https://c.paypal.com/da/r/fb.js' } );
}
_loadBeaconJS({fnUrl: "https://c.paypal.com/da/r/fb.js"})
}
document.addEventListener( 'hosted_fields_loaded', ( event ) => {
if (
PAYPAL.asyncData &&
typeof PAYPAL.asyncData.initAndCollect === 'function'
) {
PAYPAL.asyncData.initAndCollect();
}
document.addEventListener('hosted_fields_loaded', (event) => {
if (PAYPAL.asyncData && typeof PAYPAL.asyncData.initAndCollect === 'function') {
PAYPAL.asyncData.initAndCollect()
}
_injectConfig();
});
_injectConfig();
})
_injectConfig();
} );
_injectConfig();
} );

File diff suppressed because it is too large Load diff

View file

@ -1,9 +1,9 @@
export const debounce = (callback, delayMs) => {
let timeoutId = null;
return (...args) => {
window.clearTimeout(timeoutId);
timeoutId = window.setTimeout(() => {
callback.apply(null, args);
}, delayMs);
};
export const debounce = ( callback, delayMs ) => {
let timeoutId = null;
return ( ...args ) => {
window.clearTimeout( timeoutId );
timeoutId = window.setTimeout( () => {
callback.apply( null, args );
}, delayMs );
};
};

View file

@ -1,13 +1,11 @@
export const inputValue = (element) => {
const $el = jQuery(element);
export const inputValue = ( element ) => {
const $el = jQuery( element );
if ($el.is(':checkbox') || $el.is(':radio')) {
if ($el.is(':checked')) {
return $el.val();
} else {
return null;
}
} else {
return $el.val();
}
}
if ( $el.is( ':checkbox' ) || $el.is( ':radio' ) ) {
if ( $el.is( ':checked' ) ) {
return $el.val();
}
return null;
}
return $el.val();
};

View file

@ -5,38 +5,39 @@
* @param {string} apmName - Value of the custom attribute `data-ppcp-apm-name`.
* @return {Map<string, {val:Function, el:HTMLInputElement}>}
*/
export function getButtonFormFields(apmName) {
const inputFields = document.querySelectorAll(`[data-ppcp-apm-name="${apmName}"]`);
export function getButtonFormFields( apmName ) {
const inputFields = document.querySelectorAll(
`[data-ppcp-apm-name="${ apmName }"]`
);
return [...inputFields].reduce((fieldMap, el) => {
const key = el.dataset.ppcpFieldName;
let getter = () => el.value;
return [ ...inputFields ].reduce( ( fieldMap, el ) => {
const key = el.dataset.ppcpFieldName;
let getter = () => el.value;
if ('LABEL' === el.tagName) {
el = el.querySelector('input[type="checkbox"]');
getter = () => el.checked;
}
if ( 'LABEL' === el.tagName ) {
el = el.querySelector( 'input[type="checkbox"]' );
getter = () => el.checked;
}
return fieldMap.set(key, {
val: getter,
el,
});
}, new Map());
return fieldMap.set( key, {
val: getter,
el,
} );
}, new Map() );
}
/**
* Returns a function that triggers an update of the specified preview button, when invoked.
* @param {string} apmName
* @return {((object) => void)}
*/
export function buttonRefreshTriggerFactory(apmName) {
const eventName = `ppcp_paypal_render_preview_${apmName}`;
export function buttonRefreshTriggerFactory( apmName ) {
const eventName = `ppcp_paypal_render_preview_${ apmName }`;
return (settings) => {
jQuery(document).trigger(eventName, settings);
};
return ( settings ) => {
jQuery( document ).trigger( eventName, settings );
};
}
/**
@ -45,24 +46,24 @@ export function buttonRefreshTriggerFactory(apmName) {
* @param {string} apmName
* @return {() => {button: {wrapper:string, is_enabled:boolean, style:{}}}}
*/
export function buttonSettingsGetterFactory(apmName) {
const fields = getButtonFormFields(apmName);
export function buttonSettingsGetterFactory( apmName ) {
const fields = getButtonFormFields( apmName );
return () => {
const buttonConfig = {
wrapper: `#ppcp${apmName}ButtonPreview`,
'is_enabled': true,
style: {},
};
return () => {
const buttonConfig = {
wrapper: `#ppcp${ apmName }ButtonPreview`,
is_enabled: true,
style: {},
};
fields.forEach((item, name) => {
if ('is_enabled' === name) {
buttonConfig[name] = item.val();
} else {
buttonConfig.style[name] = item.val();
}
});
fields.forEach( ( item, name ) => {
if ( 'is_enabled' === name ) {
buttonConfig[ name ] = item.val();
} else {
buttonConfig.style[ name ] = item.val();
}
} );
return { button: buttonConfig };
};
return { button: buttonConfig };
};
}

View file

@ -1,18 +1,25 @@
document.addEventListener(
'DOMContentLoaded',
function() {
jQuery('form.checkout').on('checkout_place_order_success', function(type, data) {
if(data.payer_action && data.payer_action !== '') {
const width = screen.width / 2;
const height = screen.height / 2;
const left = width - (width / 2);
const top = height - (height / 2);
window.open(
data.payer_action,
'_blank',
'popup, width=' + width + ', height=' + height + ', top=' + top + ', left=' + left
);
}
});
}
);
document.addEventListener( 'DOMContentLoaded', function () {
jQuery( 'form.checkout' ).on(
'checkout_place_order_success',
function ( type, data ) {
if ( data.payer_action && data.payer_action !== '' ) {
const width = screen.width / 2;
const height = screen.height / 2;
const left = width - width / 2;
const top = height - height / 2;
window.open(
data.payer_action,
'_blank',
'popup, width=' +
width +
', height=' +
height +
', top=' +
top +
', left=' +
left
);
}
}
);
} );

View file

@ -20,6 +20,7 @@ use WooCommerce\PayPalCommerce\ApiClient\Helper\DccApplies;
use WooCommerce\PayPalCommerce\Axo\Gateway\AxoGateway;
use WooCommerce\PayPalCommerce\Button\Helper\MessagesDisclaimers;
use WooCommerce\PayPalCommerce\Common\Pattern\SingletonDecorator;
use WooCommerce\PayPalCommerce\Googlepay\GooglePayGateway;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Onboarding\Render\OnboardingOptionsRenderer;
use WooCommerce\PayPalCommerce\Onboarding\State;
@ -196,6 +197,7 @@ return array(
OXXOGateway::ID,
Settings::PAY_LATER_TAB_ID,
AxoGateway::ID,
GooglePayGateway::ID,
),
true
);
@ -217,6 +219,7 @@ return array(
CardButtonGateway::ID,
Settings::PAY_LATER_TAB_ID,
Settings::CONNECTION_TAB_ID,
GooglePayGateway::ID,
),
true
);

View file

@ -106,6 +106,12 @@ class DisableGateways {
return $methods;
}
// phpcs:ignore WordPress.Security.NonceVerification.Missing
$payment_method = wc_clean( wp_unslash( $_POST['payment_method'] ?? '' ) );
if ( $payment_method && is_string( $payment_method ) ) {
return array( $payment_method => $methods[ $payment_method ] );
}
return array( PayPalGateway::ID => $methods[ PayPalGateway::ID ] );
}

View file

@ -28,7 +28,7 @@ return function ( ContainerInterface $container, array $fields ): array {
$has_enabled_separate_button_gateways = $container->get( 'wcgateway.settings.has_enabled_separate_button_gateways' );
$preview_message = __( 'Standard Card Button Styling Preview', 'woocommerce-paypal-payments' );
$preview_message = __( 'Button Styling Preview', 'woocommerce-paypal-payments' );
$axo_smart_button_location_notice = $container->has( 'axo.smart-button-location-notice' ) ? $container->get( 'axo.smart-button-location-notice' ) : '';