/**
* External dependencies
*/
import apiFetch from '@wordpress/api-fetch';
// Stores the current nonce for the middleware.
let currentNonce = '';
let currentTimestamp = 0;
try {
const storedNonceValue = window.localStorage.getItem( 'storeApiNonce' );
const storedNonce = storedNonceValue ? JSON.parse( storedNonceValue ) : {};
currentNonce = storedNonce?.nonce || '';
currentTimestamp = storedNonce?.timestamp || 0;
} catch {
// We can ignore an error from JSON parse.
}
/**
* Returns whether or not this is a wc/store API request.
*
* @param {Object} options Fetch options.
*
* @return {boolean} Returns true if this is a store request.
*/
const isStoreApiRequest = ( options ) => {
const url = options.url || options.path;
if ( ! url || ! options.method || options.method === 'GET' ) {
return false;
}
return /wc\/store\//.exec( url ) !== null;
};
/**
* Set the current nonce from a header object.
*
* @param {Object} headers Headers object.
*/
const setNonce = ( headers ) => {
const nonce =
typeof headers?.get === 'function'
? headers.get( 'X-WC-Store-API-Nonce' )
: headers[ 'X-WC-Store-API-Nonce' ];
const timestamp =
typeof headers?.get === 'function'
? headers.get( 'X-WC-Store-API-Nonce-Timestamp' )
: headers[ 'X-WC-Store-API-Nonce-Timestamp' ];
if ( nonce ) {
updateNonce( nonce, timestamp );
}
};
/**
* Updates the stored nonce within localStorage so it is persisted between page loads.
*
* @param {string} nonce Incoming nonce string.
* @param {number} timestamp Timestamp from server of nonce.
*/
const updateNonce = ( nonce, timestamp ) => {
// If the "new" nonce matches the current nonce, we don't need to update.
if ( nonce === currentNonce ) {
return;
}
// Only update the nonce if newer. It might be coming from cache.
if ( currentTimestamp && timestamp < currentTimestamp ) {
return;
}
currentNonce = nonce;
currentTimestamp = timestamp || Date.now() / 1000; // Convert ms to seconds to match php time()
// Update the persisted values.
window.localStorage.setItem(
'storeApiNonce',
JSON.stringify( {
nonce: currentNonce,
timestamp: currentTimestamp,
} )
);
};
const appendNonceHeader = ( request ) => {
const headers = request.headers || {};
request.headers = {
...headers,
'X-WC-Store-API-Nonce': currentNonce,
};
return request;
};
/**
* Nonce middleware which appends the current nonce to store API requests.
*
* @param {Object} options Fetch options.
* @param {Function} next The next middleware or fetchHandler to call.
* @return {*} The evaluated result of the remaining middleware chain.
*/
const storeNonceMiddleware = ( options, next ) => {
if ( isStoreApiRequest( options ) ) {
options = appendNonceHeader( options );
// Add nonce to sub-requests
if ( Array.isArray( options?.data?.requests ) ) {
options.data.requests = options.data.requests.map(
appendNonceHeader
);
}
}
return next( options, next );
};
apiFetch.use( storeNonceMiddleware );
apiFetch.setNonce = setNonce;
updateNonce(
// @ts-ignore wcBlocksMiddlewareConfig is window global cache for the initial nonce initialized from hydration.
wcBlocksMiddlewareConfig.storeApiNonce,
// @ts-ignore wcBlocksMiddlewareConfig is window global cache for the initial nonce initialized from hydration.
wcBlocksMiddlewareConfig.storeApiNonceTimestamp
);
@import '../../../../scss/mixins';
.headerWrapper {
align-self: center;
display: flex;
}
.blockCategoryName {
background: transparent;
box-sizing: border-box;
justify-content: space-between;
margin: 0 auto 30px;
padding: 0;
text-align: center;
}
.blockCategoryNameLink {
background: #fff;
border: 1px solid #f1f1f1;
color: $textColorDark;
display: block;
line-height: 60px;
margin: auto;
text-decoration: none;
width: 95%;
}
.currentBlockCategory {
height: 40px;
padding: 0 30px 0 0;
line-height: 40px;
color: #767676;
border-radius: 2px;
font-size: 13px;
cursor: pointer;
position: relative;
&::after {
content: '\f345';
opacity: 0.7;
margin-top: 0;
font-family: dashicons;
position: absolute;
right: 7px;
transform: rotate(0deg);
transform-origin: 50% 50%;
transition: transform 0.1s ease;
font-size: 16px;
}
&:hover {
&::after {
transform: rotate(90deg);
}
&::before {
// This is to prevent our drop down going away when we move our mouse down out of this div
content: '';
position: absolute;
display: block;
left: 0;
right: 0;
bottom: -40px;
top: 100%;
background: transparent;
}
.optionBlockCategoryWrapper {
display: block;
}
}
}
.optionBlockCategoryWrapper {
background: #fff;
border: 1px solid #e0e5e9;
border-radius: 4px;
box-shadow: 0 10px 10px rgba(0, 0, 0, 0.1);
display: none;
line-height: 30px;
min-width: 170px;
padding: 20px;
position: absolute;
left: -20px;
top: 130%;
white-space: nowrap;
z-index: 8;
column-count: 2;
[dir='rtl'] & {
left: unset;
right: -20px;
}
&::after,
&::before {
content: '';
display: block;
position: absolute;
bottom: 100%;
width: 0;
height: 0;
border-style: solid;
}
&::after {
left: 23px;
border-color: transparent transparent #fff;
border-width: 10px;
[dir='rtl'] & {
left: unset;
right: 23px;
}
}
&::before {
left: 23px;
border-color: transparent transparent #e2e2e2;
border-width: 11px;
[dir='rtl'] & {
left: unset;
right: 23px;
}
}
}
.optionBlockCategory {
padding: 0 30px;
}
.optionBlockCategoryLink {
color: $textColorLight;
text-decoration: none;
border: 0;
background: transparent;
padding: 5px 0;
cursor: pointer;
&:hover {
color: $textColorDark;
}
}
.optionBlockCategoryLinkCurrent {
text-decoration: underline;
}
(function($){$.extend({tablesorter:new
function(){var parsers=[],widgets=[];this.defaults={cssHeader:"header",cssAsc:"headerSortUp",cssDesc:"headerSortDown",cssChildRow:"expand-child",sortInitialOrder:"asc",sortMultiSortKey:"shiftKey",sortForce:null,sortAppend:null,sortLocaleCompare:true,textExtraction:"simple",parsers:{},widgets:[],widgetZebra:{css:["even","odd"]},headers:{},widthFixed:false,cancelSelection:true,sortList:[],headerList:[],dateFormat:"us",decimal:'/\.|\,/g',onRenderHeader:null,selectorHeaders:'thead th',debug:false};function benchmark(s,d){log(s+","+(new Date().getTime()-d.getTime())+"ms");}this.benchmark=benchmark;function log(s){if(typeof console!="undefined"&&typeof console.debug!="undefined"){console.log(s);}else{alert(s);}}function buildParserCache(table,$headers){if(table.config.debug){var parsersDebug="";}if(table.tBodies.length==0)return;var rows=table.tBodies[0].rows;if(rows[0]){var list=[],cells=rows[0].cells,l=cells.length;for(var i=0;i1){arr=arr.concat(checkCellColSpan(table,headerArr,row++));}else{if(table.tHead.length==1||(cell.rowSpan>1||!r[row+1])){arr.push(cell);}}}return arr;};function checkHeaderMetadata(cell){if(($.metadata)&&($(cell).metadata().sorter===false)){return true;};return false;}function checkHeaderOptions(table,i){if((table.config.headers[i])&&(table.config.headers[i].sorter===false)){return true;};return false;}function checkHeaderOptionsSortingLocked(table,i){if((table.config.headers[i])&&(table.config.headers[i].lockedOrder))return table.config.headers[i].lockedOrder;return false;}function applyWidget(table){var c=table.config.widgets;var l=c.length;for(var i=0;i');$("tr:first td",table.tBodies[0]).each(function(){colgroup.append($('').css('width',$(this).width()));});$(table).prepend(colgroup);};}function updateHeaderSortCount(table,sortList){var c=table.config,l=sortList.length;for(var i=0;i b["+i+"]) ? 1 : 0));";};function makeSortTextDesc(i){return"((b["+i+"] < a["+i+"]) ? -1 : ((b["+i+"] > a["+i+"]) ? 1 : 0));";};function makeSortNumeric(i){return"a["+i+"]-b["+i+"];";};function makeSortNumericDesc(i){return"b["+i+"]-a["+i+"];";};function sortText(a,b){if(table.config.sortLocaleCompare)return a.localeCompare(b);return((ab)?1:0));};function sortTextDesc(a,b){if(table.config.sortLocaleCompare)return b.localeCompare(a);return((ba)?1:0));};function sortNumeric(a,b){return a-b;};function sortNumericDesc(a,b){return b-a;};function getCachedSortType(parsers,i){return parsers[i].type;};this.construct=function(settings){return this.each(function(){if(!this.tHead||!this.tBodies)return;var $this,$document,$headers,cache,config,shiftDown=0,sortOrder;this.config={};config=$.extend(this.config,$.tablesorter.defaults,settings);$this=$(this);$.data(this,"tablesorter",config);$headers=buildHeaders(this);this.config.parsers=buildParserCache(this,$headers);cache=buildCache(this);var sortCSS=[config.cssDesc,config.cssAsc];fixColumnWidth(this);$headers.click(function(e){var totalRows=($this[0].tBodies[0]&&$this[0].tBodies[0].rows.length)||0;if(!this.sortDisabled&&totalRows>0){$this.trigger("sortStart");var $cell=$(this);var i=this.column;this.order=this.count++%2;if(this.lockedOrder)this.order=this.lockedOrder;if(!e[config.sortMultiSortKey]){config.sortList=[];if(config.sortForce!=null){var a=config.sortForce;for(var j=0;j0){$this.trigger("sorton",[config.sortList]);}applyWidget(this);});};this.addParser=function(parser){var l=parsers.length,a=true;for(var i=0;i