Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up NPM dependencies and update node to v20 #160

Merged
merged 4 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16
20.11.0
2,700 changes: 846 additions & 1,854 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 4 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,16 @@
},
"dependencies": {
"@wordpress/element": "^5.0.0",
"normalize.css": "^8.0.1",
"sprintf-js": "^1.1.1",
"underscore": "^1.12.1"
},
"devDependencies": {
"@10up/cypress-wp-utils": "^0.2.0",
"@wordpress/env": "^8.7.0",
"@wordpress/eslint-plugin": "^14.11.0",
"@wordpress/scripts": "^26.19.0",
"@wordpress/env": "^9.2.0",
"@wordpress/scripts": "^27.1.0",
"cypress": "^13.2.0",
"eslint": "^8.46.0",
"eslint-plugin-prettier": "^5.0.0",
"husky": "^3.1.0",
"typescript": "^5.1.6"
"husky": "^3.1.0"
},
"engines": {
"node": ">=16.0.0"
"node": ">=20.0.0"
}
}
155 changes: 81 additions & 74 deletions src/js/admin.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
import apiFetch from '@wordpress/api-fetch';
import { __ } from '@wordpress/i18n';

const hideElement = (hide, element) => {
if (hide) {
element.classList.add('hidden');
element.setAttribute('aria-hidden', 'true');
const hideElement = ( hide, element ) => {
if ( hide ) {
element.classList.add( 'hidden' );
element.setAttribute( 'aria-hidden', 'true' );
} else {
element.classList.remove('hidden');
element.setAttribute('aria-hidden', 'false');
element.classList.remove( 'hidden' );
element.setAttribute( 'aria-hidden', 'false' );
}
};

document
.querySelector('#icw-fix-content-btn')
.addEventListener('click', async (event) => {
.querySelector( '#icw-fix-content-btn' )
.addEventListener( 'click', async ( event ) => {
event.preventDefault();

const postSelection = document.querySelector(
'#icw-post-selection'
).value;
const postIds = document.querySelector('#icw-post-ids').value;
const postType = document.querySelector('#icw-post-type').value;
const batchSize = +document.querySelector('#icw-batch-size').value;
const dryRun = document.querySelector('#icw-dry-run').checked;
const log = document.querySelector('#icw-fix-log');
const loadingSpinner = document.querySelector('#icw-loading-spinner');
const btn = document.querySelector('#icw-fix-content-btn');
const postIds = document.querySelector( '#icw-post-ids' ).value;
const postType = document.querySelector( '#icw-post-type' ).value;
const batchSize = +document.querySelector( '#icw-batch-size' ).value;
const dryRun = document.querySelector( '#icw-dry-run' ).checked;
const log = document.querySelector( '#icw-fix-log' );
const loadingSpinner = document.querySelector( '#icw-loading-spinner' );
const btn = document.querySelector( '#icw-fix-content-btn' );

const toggleSpinnerVisibility = () => {
loadingSpinner.classList.toggle('hidden');
loadingSpinner.setAttribute('aria-hidden', 'true');
loadingSpinner.classList.toggle( 'hidden' );
loadingSpinner.setAttribute( 'aria-hidden', 'true' );
};

const disableButton = (disable) => {
if (disable) {
btn.setAttribute('disabled', '');
const disableButton = ( disable ) => {
if ( disable ) {
btn.setAttribute( 'disabled', '' );
} else {
btn.removeAttribute('disabled');
btn.removeAttribute( 'disabled' );
}
};

const setLogHTML = (html) => {
const setLogHTML = ( html ) => {
log.innerHTML = html;

log.scrollTop = log.scrollHeight;
};

toggleSpinnerVisibility();
disableButton(true);
setLogHTML('');
hideElement(true, log);
disableButton( true );
setLogHTML( '' );
hideElement( true, log );

const count = await apiFetch({
const count = await apiFetch( {
path: `/icw/v1/count-for-fix`,
method: 'POST',
data: {
Expand All @@ -61,30 +61,31 @@ document
postSelection === 'all_from_post_type' ? postType : '',
batchSize,
},
});
} );

const times = Math.ceil(count / batchSize);
const times = Math.ceil( count / batchSize );

hideElement(false, log);
hideElement( false, log );

const getProgressBar = (time, __times, __batchSize, __count) => {
const getProgressBar = ( time, __times, __batchSize, __count ) => {
const progressBarMax = 50;
const percentage = time > 0 ? Math.ceil((100 / __times) * time) : 0;
const value = (percentage * progressBarMax) / 100;
const percentage =
time > 0 ? Math.ceil( ( 100 / __times ) * time ) : 0;
const value = ( percentage * progressBarMax ) / 100;
const completed = time !== __times ? __batchSize * time : __count;
return `<span>[${'#'.repeat(value)}${'-'.repeat(
return `<span>[${ '#'.repeat( value ) }${ '-'.repeat(
progressBarMax - value
)}] | ${percentage}% || ${completed}/${__count} ${__(
) }] | ${ percentage }% || ${ completed }/${ __count } ${ __(
'posts',
'insecure-content-warning'
)}</span>`;
) }</span>`;
};

setLogHTML(getProgressBar(0, times, batchSize, count));
setLogHTML( getProgressBar( 0, times, batchSize, count ) );
let innerHTML = '';
for (let i = 1; i <= times; i++) {
for ( let i = 1; i <= times; i++ ) {
// eslint-disable-next-line no-await-in-loop
const data = await apiFetch({
const data = await apiFetch( {
path: `/icw/v1/fix`,
method: 'POST',
data: {
Expand All @@ -93,46 +94,52 @@ document
postType:
postSelection === 'all_from_post_type' ? postType : '',
batchSize,
offset: (i - 1) * batchSize,
offset: ( i - 1 ) * batchSize,
dryRun,
},
});
} );

innerHTML += data;
setLogHTML(innerHTML + getProgressBar(i, times, batchSize, count));
setLogHTML(
innerHTML + getProgressBar( i, times, batchSize, count )
);
}

toggleSpinnerVisibility();
disableButton(false);
});

document.querySelector('#icw-post-selection').addEventListener('change', () => {
const postSelection = document.querySelector('#icw-post-selection').value;

const hidePostIdsRow = (hide) => {
const postIdsRow = document.querySelector('#icw-post-ids-row');
hideElement(hide, postIdsRow);
};

const hidePostTypeRow = (hide) => {
const postTypeRow = document.querySelector('#icw-post-type-row');
hideElement(hide, postTypeRow);
};

switch (postSelection) {
case 'all':
hidePostIdsRow(true);
hidePostTypeRow(true);
break;
case 'posts':
hidePostIdsRow(false);
hidePostTypeRow(true);
break;
case 'all_from_post_type':
hidePostTypeRow(false);
hidePostIdsRow(true);
break;
default:
break;
}
});
disableButton( false );
} );

document
.querySelector( '#icw-post-selection' )
.addEventListener( 'change', () => {
const postSelection = document.querySelector(
'#icw-post-selection'
).value;

const hidePostIdsRow = ( hide ) => {
const postIdsRow = document.querySelector( '#icw-post-ids-row' );
hideElement( hide, postIdsRow );
};

const hidePostTypeRow = ( hide ) => {
const postTypeRow = document.querySelector( '#icw-post-type-row' );
hideElement( hide, postTypeRow );
};

switch ( postSelection ) {
case 'all':
hidePostIdsRow( true );
hidePostTypeRow( true );
break;
case 'posts':
hidePostIdsRow( false );
hidePostTypeRow( true );
break;
case 'all_from_post_type':
hidePostTypeRow( false );
hidePostIdsRow( true );
break;
default:
break;
}
} );
80 changes: 41 additions & 39 deletions src/js/classic-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@ import replaceContent from './utils/replace';
import '../css/admin.scss';

// Listen for clicks on the publish button
jQuery(document).on('click', '#publish', (event) => {
jQuery( document ).on( 'click', '#publish', ( event ) => {
blurInsecure();
if (
!jQuery(event.target).hasClass('disabled') &&
jQuery('.js-icw-force-checkbox').prop('checked') !== true
! jQuery( event.target ).hasClass( 'disabled' ) &&
jQuery( '.js-icw-force-checkbox' ).prop( 'checked' ) !== true
) {
checkContent(event);
checkContent( event );
}
});
} );

// Listen for clicks on the force publish checkbox
jQuery(document).on('change', '#icw-force-checkbox', function () {
jQuery( document ).on( 'change', '#icw-force-checkbox', function () {
// Enable or disable the publish button as needed
blurInsecure();
if (jQuery(this).is(':checked')) {
jQuery('#publish').removeClass('disabled');
if ( jQuery( this ).is( ':checked' ) ) {
jQuery( '#publish' ).removeClass( 'disabled' );
} else {
jQuery('#publish').addClass('disabled');
jQuery( '#publish' ).addClass( 'disabled' );
}
});
} );

/**
* If the preview button is clicked after
Expand All @@ -34,72 +34,74 @@ jQuery(document).on('change', '#icw-force-checkbox', function () {
* the update button and then the preview button,
* as it expects a page refresh after updates
*/
jQuery(document).on('click', '#post-preview', () => {
jQuery( document ).on( 'click', '#post-preview', () => {
blurInsecure();
if (document.querySelector('.js-icw-error')) {
if (wp.autosave) {
if ( document.querySelector( '.js-icw-error' ) ) {
if ( wp.autosave ) {
wp.autosave.server.resume();
wp.autosave.enableButtons();
} else {
jQuery(document).trigger('autosave-enable-buttons');
jQuery( document ).trigger( 'autosave-enable-buttons' );
}

jQuery('#major-publishing-actions .spinner').removeClass('is-active');
jQuery( '#major-publishing-actions .spinner' ).removeClass(
'is-active'
);
}
});
} );

// Listen for clicks on the fix asset links
jQuery(document).on('click', '.js-icw-check', function (e) {
jQuery( document ).on( 'click', '.js-icw-check', function ( e ) {
e.preventDefault();
blurInsecure();

const spinner = jQuery(this).next('.js-icw-spinner');
const url = jQuery(this).data('check');
const spinner = jQuery( this ).next( '.js-icw-spinner' );
const url = jQuery( this ).data( 'check' );

spinner.show();

wp.apiRequest({ path: `/icw/v1/check?url=${url}` }).then(
(data) => {
wp.apiRequest( { path: `/icw/v1/check?url=${ url }` } ).then(
( data ) => {
spinner.hide();

// Attempt to replace if https equivalent found.
if (data === true) {
jQuery(this).nextAll('.js-icw-fixed').show();
replaceContent(url);
if ( data === true ) {
jQuery( this ).nextAll( '.js-icw-fixed' ).show();
replaceContent( url );
} else {
// show the error
jQuery(this).nextAll('.js-icw-error').show();
throw new Error('No https equivalent found.');
jQuery( this ).nextAll( '.js-icw-error' ).show();
throw new Error( 'No https equivalent found.' );
}

setTimeout(function () {
checkContent(e);
}, 1000);
setTimeout( function () {
checkContent( e );
}, 1000 );
},
(err) => {
( err ) => {
// Don't recheck if replace unsuccessful.
return err;
}
);
});
} );

jQuery(document).on('click', '.js-icw-view', function (e) {
jQuery( document ).on( 'click', '.js-icw-view', function ( e ) {
e.preventDefault();
blurInsecure();

const url = jQuery(this).data('check');
const elements = findElements(url);
const url = jQuery( this ).data( 'check' );
const elements = findElements( url );

if (elements.length) {
const $element = jQuery(elements[0]);
if ( elements.length ) {
const $element = jQuery( elements[ 0 ] );

jQuery('html, body').animate(
jQuery( 'html, body' ).animate(
{
scrollTop: $element.offset().top,
},
0
);

$element.addClass('js-icw-is-insecure');
$element.addClass( 'js-icw-is-insecure' );
}
});
} );
Loading
Loading