Skip to content

Commit

Permalink
Merge pull request #26 from rosswintle/1.13.1
Browse files Browse the repository at this point in the history
Update with code from extension v1.13.1 and fix up!
  • Loading branch information
rosswintle authored Feb 26, 2023
2 parents 105f539 + 089dd91 commit 50777cd
Show file tree
Hide file tree
Showing 25 changed files with 732 additions and 250 deletions.
407 changes: 306 additions & 101 deletions dist/main.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/main.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "turbo-admin",
"version": "1.12.1",
"version": "1.13.2",
"main": "Gruntfile.js",
"author": "Ross Wintle",
"scripts": {
Expand Down
33 changes: 29 additions & 4 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Contributors: magicroundabout
Donate link: https://ko-fi.com/magicroundabout
Tags: menu, commands, shortcuts
Requires at least: 4.9
Tested up to: 6.1
Requires PHP: 7.2
Stable tag: 1.12.1
Tested up to: 6.2
Requires PHP: 7.4
Stable tag: 1.13.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -41,7 +41,7 @@ PLUS the browser extension has features not present in the plugin. Some features
* Block editor welcome guide remover
* Live/dev site labels

Remember, the browser extension it works everywhere that it can detect WordPress, without needing a plugin. And it carries your preferences with you! It's WordPress, your way!
Remember, the browser extension works everywhere that it can detect WordPress, without needing a plugin. And it carries your preferences with you! It's WordPress, your way!

[Check out the Browser Extension and try it for free](https://turbo-admin.com/)

Expand Down Expand Up @@ -184,6 +184,31 @@ If you're reading this then you've probably already done step 1. So what are you

== Changelog ==

= 1.13.2 =

* [ENHANCEMENT] Storage abstraction enhancements
* [ENHANCEMENT] Improved notice handling (again!)
* [FIX] Save Barkeeper state properly
* [FIX] Content API now uses the storage abstraction to work on both plugin and extension.

= 1.13.1 =

This version was skipped in the plugin.

* Version bump for publishing the Firefox extension

= 1.13.0 =

This version was skipped in the plugin.

* [ENHANCEMENT] Some code rewrites because the extension now uses "Manifest v3" which is a new extension format. Hopefully nothing is broken but PLEASE report any issues.
* [ENHANCEMENT] Speed improvements in some situations (cache post types collected from the API).
* [ENHANCEMENT] Improvements to list-table keys (more list-table key nav improvements coming).
* [ENHANCEMENT] Other behind-the-scenes improvements and preparations for other new features.
* [ENHANCEMENT] Add debug mode and suppress most errors if it's turned off.
* [FIX] Fix for WP 6.2 site editor interface (props Courtney Robertson)


= 1.12.1 =
* Version bump for publishing

Expand Down
40 changes: 33 additions & 7 deletions src/apis/class-content-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default class ContentApi {

constructor() {
// this.discoverApiRoot().then(e => null);
// console.log('Discovered API base: ', this.apiBase);
// turboAdminLog('Discovered API base: ', this.apiBase);
this.active = false;
this.store = new Storage();
this.postTypes = [];
Expand All @@ -15,7 +15,7 @@ export default class ContentApi {
}

async discoverApiRoot() {
console.log('Discovering API root');
turboAdminLog('Discovering API root');
let wpApiSettings = null;
this.storageKey = 'wpApiSettings.' + globalThis.taWp.home;

Expand Down Expand Up @@ -63,21 +63,41 @@ export default class ContentApi {
return;
}
// This should be very rare. I should only really see it in development.
console.log('API Route Discovery failed');
turboAdminLog('API Route Discovery failed');
// Making best guess
this.apiBase = globalThis.taWp.home + '/wp-json/wp/v2/';
// TODO: This can't display as the palette isn't created yet.
// globalThis.turboAdmin.turboAdminPalette.showPaletteNotice('Can\'t find the WP API. Try visiting the dashboard to refresh things.');
}

async discoverPostTypes() {
console.log('Discovering post types');
turboAdminLog('Discovering post types');
if (! this.active) {
console.log('Not active');
turboAdminLog('Not active');
this.postTypes = [];
return;
}

const postTypes = await this.store.get('ta-post-types');

// Check local storage cache
if (postTypes && postTypes['ta-post-types'] && postTypes['ta-post-types']['expiry'] > Date.now()) {
turboAdminLog('Using cached post types: ', postTypes['ta-post-types']['data']);
this.postTypes = postTypes['ta-post-types']['data'];
return;
}

this.postTypes = await this.getPostTypes();
console.log('Discovered post types: ', this.postTypes);
turboAdminLog('Discovered post types: ', this.postTypes);

// Cache for 10 minutes
const expiry = Date.now() + (10 * 60 * 1000);
this.store.set({
'ta-post-types': {
expiry: expiry,
data: this.postTypes
}
});
}

userLoggedIn() {
Expand Down Expand Up @@ -265,7 +285,13 @@ export default class ContentApi {
const response = await fetch(`${this.apiBase}${path}/?${params}`, init);

if (response.status < 200 || response.status >= 300) {
globalThis.turboAdmin.turboAdminPalette.showPaletteNotice('WordPress API Error. Try visiting the dashboard to refresh things.');
// TODO: Set a "deferred" notice to show when the palette is created?
if (globalThis.turboAdmin && globalThis.turboAdmin.turboAdminPalette) {
globalThis.turboAdmin.turboAdminPalette.showPaletteNotice('WordPress API Error. Try visiting the dashboard to refresh things.');
} else {
// Always log this as people may look
turboAdminLog( 'TURBO ADMIN: WordPress API Error. Try visiting the WordPress Dashboard to refresh things.' );
}
}

return response;
Expand Down
8 changes: 7 additions & 1 deletion src/apis/class-gravity-forms-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ export default class GravityFormsApi {
const response = await fetch(`${gfApiBase}${path}/?${params}`);

if (response.status < 200 || response.status >= 300) {
globalThis.turboAdmin.turboAdminPalette.showPaletteNotice('Gravity Forms API Error. Try visiting the dashboard to refresh things.');
// TODO: Set a "deferred" notice to show when the palette is created?
if (globalThis.turboAdmin && globalThis.turboAdmin.turboAdminPalette) {
globalThis.turboAdmin.turboAdminPalette.showPaletteNotice('Gravity Forms API Error. Try visiting the dashboard to refresh things.');
} else {
// Always log this as people may look
turboAdminLog('TURBO ADMIN: Gravity Forms API Error. Try visiting the WordPress Dashboard to refresh things.');
}
}

return response;
Expand Down
8 changes: 7 additions & 1 deletion src/apis/class-woocommerce-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@ export default class WoocommerceApi {
return false;
}
if ( (response.status < 200 || response.status >= 300) ) {
globalThis.turboAdmin.turboAdminPalette.showPaletteNotice('WooCommerce API Error. Try visiting the dashboard to refresh things.');
// TODO: Set a "deferred" notice to show when the palette is created?
if (globalThis.turboAdmin && globalThis.turboAdmin.turboAdminPalette) {
globalThis.turboAdmin.turboAdminPalette.showPaletteNotice('WooCommerce API Error. Try visiting the dashboard to refresh things.');
} else {
// Always log this as people may look
turboAdminLog('TURBO ADMIN: WooCommerce API Error. Try visiting the WordPress Dashboard to refresh things.');
}
}

return response;
Expand Down
7 changes: 4 additions & 3 deletions src/class-list-table-shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default class ListTableShortcuts {
// Move down
if (this.currentRow === null) {
this.currentRowIndex = 0;
} else {
} else if (this.currentRowIndex < this.tableRows.length - 1) {
this.currentRowIndex++;
}
this.updateTable();
Expand All @@ -69,8 +69,9 @@ export default class ListTableShortcuts {

if (this.currentRowIndex > 0) {
this.currentRowIndex--;
this.updateTable();
}

this.updateTable();
}

preTableChange() {
Expand All @@ -88,7 +89,7 @@ export default class ListTableShortcuts {
}

openTableRowItem() {
console.log(this);
turboAdminLog(this);
/** @type {HTMLAnchorElement} */
const link = this.currentRow.querySelector('a.row-title');
if (link) {
Expand Down
26 changes: 16 additions & 10 deletions src/class-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,32 @@ export default class Storage {
/** @type {null|storageStorageArea|WindowLocalStorage} */
this.store = null;

if ('undefined' === typeof (browser)) {
this.store = window.localStorage;
if (this.inExtension()) {
this.store = chrome.storage.local;
} else {
this.store = browser.storage.local;
this.store = window.localStorage;
}
}

/**
* Returns true if we are in the extension.
*/
inExtension() {
return window.turboAdminIsExtension();
}

/**
* Set/save extension data. Must be passed an object with key/value
* pairs.
*
* @param {Object} dataObject
*/
async set(dataObject) {
if ('undefined' === typeof (browser)) {
if (this.inExtension()) {
await this.store.set(dataObject);
} else {
const keys = Object.keys(dataObject);
keys.forEach(key => this.store.setItem(key, JSON.stringify(dataObject[key])));
} else {
await this.store.set(dataObject);
}
}

Expand All @@ -52,7 +59,9 @@ export default class Storage {
* @returns {Promise<Object>}
*/
async get(key) {
if ('undefined' === typeof (browser)) {
if (this.inExtension()) {
return await this.store.get(key);
} else {
let returnObj = {};
let item = this.store.getItem(key);
if (! item) {
Expand All @@ -66,9 +75,6 @@ export default class Storage {
}
returnObj[key] = itemObject;
return returnObj;
} else {
return await this.store.get(key);
}
}

}
16 changes: 8 additions & 8 deletions src/class-turbo-admin-palette.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class TurboAdminPalette {

constructor(paletteData, options) {

console.log('Initialising TurboAdmin');
turboAdminLog('Initialising TurboAdmin');

this.options = options;

Expand Down Expand Up @@ -201,7 +201,7 @@ export default class TurboAdminPalette {
* @param {ContentItem[]} contentItems
*/
injectContentItems(contentItems, andRunSearch = true) {
console.log('Injecting items');
turboAdminLog('Injecting items');

if (contentItems.length > 0) {
contentItems.forEach(this.injectItem.bind(this));
Expand All @@ -227,11 +227,11 @@ export default class TurboAdminPalette {
const itemType = item.subtype;
const itemUrl = item.url;

// console.log('Adding item: ' + itemTitle);
// turboAdminLog('Adding item: ' + itemTitle);

// // Check if item already exists
if (this.contentItemExists(itemUrl)) {
console.log('Not adding duplicate');
turboAdminLog('Not adding duplicate');
return;
}

Expand Down Expand Up @@ -366,7 +366,7 @@ export default class TurboAdminPalette {
if (newKey === 'Backspace') {
newInputValue = newInputValue.slice(0, -1);
}
// console.log(`Checking palette input value ${newInputValue} for keyword`);
// turboAdminLog(`Checking palette input value ${newInputValue} for keyword`);
if (this.isKeyword(newInputValue)) {
this.paletteSearchModeTabNoticeText.innerText = `Search for ${newInputValue}`;
this.paletteSearchModeTabNotice.classList.add('active');
Expand Down Expand Up @@ -468,10 +468,10 @@ export default class TurboAdminPalette {
* Tabbing looks for a search mode keyword.
*/
if (! this.inSearchMode() && (e.code === 'Tab' || e.key === ':')) {
console.log('Checking for search mode');
turboAdminLog('Checking for search mode');
let inputValue = this.paletteInputElement.value;
if (this.isKeyword(inputValue)) {
console.log('Found search mode ' + inputValue)
turboAdminLog('Found search mode ' + inputValue)
e.preventDefault();
// TODO: Work on this.
await this.enterSearchMode(
Expand All @@ -498,7 +498,7 @@ export default class TurboAdminPalette {
* @param {SearchMode} searchMode
*/
async enterSearchMode(searchMode) {
console.log('Entering search mode for keyword ' + searchMode.keyword);
turboAdminLog('Entering search mode for keyword ' + searchMode.keyword);
this.backupPaletteData();

this.paletteData = [];
Expand Down
5 changes: 5 additions & 0 deletions src/class-turbo-admin-wp-block-editor-fullscreen-kill.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ export default class TurboAdminWpBlockEditorFullscreenKill {

constructor() {

// Don't run on the site editor screen
if (document.body.classList.contains( 'site-editor-php' )) {
return;
}

const attrObserver = new MutationObserver((mutations) => {
mutations.forEach(mu => {
// Check if we already killed fullscreen
Expand Down
Loading

0 comments on commit 50777cd

Please sign in to comment.