2018-02-13 19:03:53 +00:00
/******/ ( function ( modules ) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = { } ;
/******/
/******/ // The require function
/******/ function _ _webpack _require _ _ ( moduleId ) {
/******/
/******/ // Check if module is in cache
/******/ if ( installedModules [ moduleId ] ) {
/******/ return installedModules [ moduleId ] . exports ;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules [ moduleId ] = {
/******/ i : moduleId ,
/******/ l : false ,
/******/ exports : { }
/******/ } ;
/******/
/******/ // Execute the module function
/******/ modules [ moduleId ] . call ( module . exports , module , module . exports , _ _webpack _require _ _ ) ;
/******/
/******/ // Flag the module as loaded
/******/ module . l = true ;
/******/
/******/ // Return the exports of the module
/******/ return module . exports ;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ _ _webpack _require _ _ . m = modules ;
/******/
/******/ // expose the module cache
/******/ _ _webpack _require _ _ . c = installedModules ;
/******/
/******/ // define getter function for harmony exports
/******/ _ _webpack _require _ _ . d = function ( exports , name , getter ) {
/******/ if ( ! _ _webpack _require _ _ . o ( exports , name ) ) {
/******/ Object . defineProperty ( exports , name , {
/******/ configurable : false ,
/******/ enumerable : true ,
/******/ get : getter
/******/ } ) ;
/******/ }
/******/ } ;
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ _ _webpack _require _ _ . n = function ( module ) {
/******/ var getter = module && module . _ _esModule ?
/******/ function getDefault ( ) { return module [ 'default' ] ; } :
/******/ function getModuleExports ( ) { return module ; } ;
/******/ _ _webpack _require _ _ . d ( getter , 'a' , getter ) ;
/******/ return getter ;
/******/ } ;
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ _ _webpack _require _ _ . o = function ( object , property ) { return Object . prototype . hasOwnProperty . call ( object , property ) ; } ;
/******/
/******/ // __webpack_public_path__
/******/ _ _webpack _require _ _ . p = "" ;
/******/
/******/ // Load entry module and return exports
/******/ return _ _webpack _require _ _ ( _ _webpack _require _ _ . s = 0 ) ;
/******/ } )
/************************************************************************/
/******/ ( [
/* 0 */
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
"use strict" ;
var _slicedToArray = function ( ) { function sliceIterator ( arr , i ) { var _arr = [ ] ; var _n = true ; var _d = false ; var _e = undefined ; try { for ( var _i = arr [ Symbol . iterator ] ( ) , _s ; ! ( _n = ( _s = _i . next ( ) ) . done ) ; _n = true ) { _arr . push ( _s . value ) ; if ( i && _arr . length === i ) break ; } } catch ( err ) { _d = true ; _e = err ; } finally { try { if ( ! _n && _i [ "return" ] ) _i [ "return" ] ( ) ; } finally { if ( _d ) throw _e ; } } return _arr ; } return function ( arr , i ) { if ( Array . isArray ( arr ) ) { return arr ; } else if ( Symbol . iterator in Object ( arr ) ) { return sliceIterator ( arr , i ) ; } else { throw new TypeError ( "Invalid attempt to destructure non-iterable instance" ) ; } } ; } ( ) ;
var _extends = Object . assign || function ( target ) { for ( var i = 1 ; i < arguments . length ; i ++ ) { var source = arguments [ i ] ; for ( var key in source ) { if ( Object . prototype . hasOwnProperty . call ( source , key ) ) { target [ key ] = source [ key ] ; } } } return target ; } ;
var _createClass = function ( ) { function defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ( ) ;
2018-02-15 18:16:14 +00:00
var _specificSelect = _ _webpack _require _ _ ( 1 ) ;
var _categorySelect = _ _webpack _require _ _ ( 2 ) ;
var _attributeSelect = _ _webpack _require _ _ ( 3 ) ;
2018-02-13 19:03:53 +00:00
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
function _possibleConstructorReturn ( self , call ) { if ( ! self ) { throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ; } return call && ( typeof call === "object" || typeof call === "function" ) ? call : self ; }
function _inherits ( subClass , superClass ) { if ( typeof superClass !== "function" && superClass !== null ) { throw new TypeError ( "Super expression must either be null or a function, not " + typeof superClass ) ; } subClass . prototype = Object . create ( superClass && superClass . prototype , { constructor : { value : subClass , enumerable : false , writable : true , configurable : true } } ) ; if ( superClass ) Object . setPrototypeOf ? Object . setPrototypeOf ( subClass , superClass ) : subClass . _ _proto _ _ = superClass ; }
var _ _ = wp . i18n . _ _ ;
2018-02-26 20:13:08 +00:00
var RawHTML = wp . element . RawHTML ;
2018-02-13 19:03:53 +00:00
var _wp$blocks = wp . blocks ,
registerBlockType = _wp$blocks . registerBlockType ,
InspectorControls = _wp$blocks . InspectorControls ,
BlockControls = _wp$blocks . BlockControls ;
var _wp$components = wp . components ,
Toolbar = _wp$components . Toolbar ,
withAPIData = _wp$components . withAPIData ,
2018-02-23 14:57:27 +00:00
Dropdown = _wp$components . Dropdown ,
2018-02-26 19:58:19 +00:00
Dashicon = _wp$components . Dashicon ,
2018-03-02 18:05:13 +00:00
RangeControl = _wp$components . RangeControl ,
Tooltip = _wp$components . Tooltip ;
2018-02-26 19:58:19 +00:00
var ToggleControl = InspectorControls . ToggleControl ,
2018-02-13 19:03:53 +00:00
SelectControl = InspectorControls . SelectControl ;
2018-02-15 18:16:14 +00:00
2018-02-15 17:42:24 +00:00
/ * *
* A setting has the following properties :
* title - Display title of the setting .
* description - Display description of the setting .
* value - Display setting slug to set when selected .
* group _container - ( optional ) If set the setting is a parent container .
* /
var PRODUCTS _BLOCK _DISPLAY _SETTINGS = {
'specific' : {
title : _ _ ( 'Individual products' ) ,
description : _ _ ( 'Hand-pick which products to display' ) ,
value : 'specific'
} ,
'category' : {
title : _ _ ( 'Product category' ) ,
description : _ _ ( 'Display products from a specific category or multiple categories' ) ,
value : 'category'
} ,
'filter' : {
title : _ _ ( 'Filter products' ) ,
description : _ _ ( 'E.g. featured products, or products with a specific attribute like size or color' ) ,
value : 'filter' ,
group _container : 'filter'
} ,
'featured' : {
title : _ _ ( 'Featured products' ) ,
description : '' ,
value : 'featured'
} ,
'best_sellers' : {
title : _ _ ( 'Best sellers' ) ,
description : '' ,
value : 'best_sellers'
} ,
'best_rated' : {
title : _ _ ( 'Best rated' ) ,
description : '' ,
value : 'best_rated'
} ,
'on_sale' : {
title : _ _ ( 'On sale' ) ,
description : '' ,
value : 'on_sale'
} ,
'attribute' : {
title : _ _ ( 'Attribute' ) ,
description : '' ,
value : 'attribute'
} ,
'all' : {
title : _ _ ( 'All products' ) ,
description : _ _ ( 'Display all products ordered chronologically' ) ,
value : 'all'
}
} ;
2018-02-13 19:03:53 +00:00
/ * *
2018-02-15 18:16:14 +00:00
* One option from the list of all available ways to display products .
2018-02-13 19:03:53 +00:00
* /
2018-02-15 18:16:14 +00:00
var ProductsBlockSettingsEditorDisplayOption = function ( _React$Component ) {
_inherits ( ProductsBlockSettingsEditorDisplayOption , _React$Component ) ;
2018-02-13 19:03:53 +00:00
2018-02-15 18:16:14 +00:00
function ProductsBlockSettingsEditorDisplayOption ( ) {
_classCallCheck ( this , ProductsBlockSettingsEditorDisplayOption ) ;
2018-02-13 19:03:53 +00:00
2018-02-15 18:16:14 +00:00
return _possibleConstructorReturn ( this , ( ProductsBlockSettingsEditorDisplayOption . _ _proto _ _ || Object . getPrototypeOf ( ProductsBlockSettingsEditorDisplayOption ) ) . apply ( this , arguments ) ) ;
2018-02-13 19:03:53 +00:00
}
2018-02-15 18:16:14 +00:00
_createClass ( ProductsBlockSettingsEditorDisplayOption , [ {
2018-02-15 17:42:24 +00:00
key : 'render' ,
2018-02-13 19:03:53 +00:00
value : function render ( ) {
2018-02-15 18:16:14 +00:00
var _this2 = this ;
2018-02-23 14:57:27 +00:00
var icon = 'arrow-right-alt2' ;
if ( 'filter' === this . props . value && this . props . extended ) {
icon = 'arrow-down-alt2' ;
}
2018-03-14 15:11:36 +00:00
var classes = 'wc-products-display-options__option wc-products-display-options__option--' + this . props . value ;
if ( this . props . current === this . props . value ) {
icon = 'yes' ;
classes += ' wc-products-display-options__option--current' ;
}
2018-02-13 19:03:53 +00:00
return wp . element . createElement (
2018-02-15 17:42:24 +00:00
'div' ,
2018-03-14 15:11:36 +00:00
{ className : classes , onClick : function onClick ( ) {
2018-02-15 18:16:14 +00:00
_this2 . props . update _display _callback ( _this2 . props . value ) ;
} } ,
2018-02-13 19:03:53 +00:00
wp . element . createElement (
2018-02-23 14:57:27 +00:00
'div' ,
2018-02-26 18:26:08 +00:00
{ className : 'wc-products-display-options__option-content' } ,
2018-02-23 14:57:27 +00:00
wp . element . createElement (
'span' ,
{ className : 'wc-products-display-options__option-title' } ,
this . props . title
) ,
wp . element . createElement (
'p' ,
{ className : 'wc-products-display-options__option-description' } ,
this . props . description
)
2018-02-13 19:03:53 +00:00
) ,
2018-02-15 18:16:14 +00:00
wp . element . createElement (
2018-02-23 14:57:27 +00:00
'div' ,
{ className : 'wc-products-display-options__icon' } ,
wp . element . createElement ( Dashicon , { icon : icon } )
2018-02-15 18:16:14 +00:00
)
2018-02-13 19:03:53 +00:00
) ;
}
} ] ) ;
2018-02-15 18:16:14 +00:00
return ProductsBlockSettingsEditorDisplayOption ;
2018-02-13 19:03:53 +00:00
} ( React . Component ) ;
2018-02-15 18:16:14 +00:00
/ * *
* A list of all available ways to display products .
* /
2018-02-13 19:03:53 +00:00
2018-02-15 18:16:14 +00:00
var ProductsBlockSettingsEditorDisplayOptions = function ( _React$Component2 ) {
_inherits ( ProductsBlockSettingsEditorDisplayOptions , _React$Component2 ) ;
2018-02-13 19:03:53 +00:00
2018-02-23 18:22:05 +00:00
/ * *
* Constructor .
* /
function ProductsBlockSettingsEditorDisplayOptions ( props ) {
2018-02-15 18:16:14 +00:00
_classCallCheck ( this , ProductsBlockSettingsEditorDisplayOptions ) ;
2018-02-13 19:03:53 +00:00
2018-02-23 18:22:05 +00:00
var _this3 = _possibleConstructorReturn ( this , ( ProductsBlockSettingsEditorDisplayOptions . _ _proto _ _ || Object . getPrototypeOf ( ProductsBlockSettingsEditorDisplayOptions ) ) . call ( this , props ) ) ;
_this3 . setWrapperRef = _this3 . setWrapperRef . bind ( _this3 ) ;
_this3 . handleClickOutside = _this3 . handleClickOutside . bind ( _this3 ) ;
return _this3 ;
2018-02-15 18:16:14 +00:00
}
2018-02-13 19:03:53 +00:00
2018-02-23 18:22:05 +00:00
/ * *
* Hook in the listener for closing menu when clicked outside .
* /
2018-02-15 18:16:14 +00:00
_createClass ( ProductsBlockSettingsEditorDisplayOptions , [ {
2018-02-23 18:22:05 +00:00
key : 'componentDidMount' ,
value : function componentDidMount ( ) {
if ( this . props . existing ) {
document . addEventListener ( 'mousedown' , this . handleClickOutside ) ;
}
}
/ * *
* Remove the listener for closing menu when clicked outside .
* /
} , {
key : 'componentWillUnmount' ,
value : function componentWillUnmount ( ) {
if ( this . props . existing ) {
document . removeEventListener ( 'mousedown' , this . handleClickOutside ) ;
}
}
/ * *
* Set the wrapper reference .
*
* @ param node DOMNode
* /
} , {
key : 'setWrapperRef' ,
value : function setWrapperRef ( node ) {
this . wrapperRef = node ;
}
/ * *
* Close the menu when user clicks outside the search area .
* /
} , {
key : 'handleClickOutside' ,
value : function handleClickOutside ( evt ) {
2018-02-26 18:26:08 +00:00
if ( this . wrapperRef && ! this . wrapperRef . contains ( event . target ) && 'wc-products-settings-heading__change-button button-link' !== event . target . getAttribute ( 'class' ) ) {
2018-02-23 18:22:05 +00:00
this . props . closeMenu ( ) ;
}
}
/ * *
* Render the list of options .
* /
} , {
2018-02-15 18:16:14 +00:00
key : 'render' ,
value : function render ( ) {
2018-02-23 14:57:27 +00:00
var classes = 'wc-products-display-options' ;
if ( this . props . extended ) {
classes += ' wc-products-display-options--extended' ;
}
2018-02-15 18:16:14 +00:00
if ( this . props . existing ) {
2018-02-23 14:57:27 +00:00
classes += ' wc-products-display-options--popover' ;
2018-02-15 18:16:14 +00:00
}
2018-02-13 19:03:53 +00:00
2018-02-15 18:16:14 +00:00
var display _settings = [ ] ;
for ( var setting _key in PRODUCTS _BLOCK _DISPLAY _SETTINGS ) {
2018-03-14 15:11:36 +00:00
display _settings . push ( wp . element . createElement ( ProductsBlockSettingsEditorDisplayOption , _extends ( { } , PRODUCTS _BLOCK _DISPLAY _SETTINGS [ setting _key ] , { update _display _callback : this . props . update _display _callback , extended : this . props . extended , current : this . props . current } ) ) ) ;
2018-02-15 18:16:14 +00:00
}
2018-02-13 19:03:53 +00:00
2018-02-23 14:57:27 +00:00
var arrow = wp . element . createElement ( 'span' , { className : 'wc-products-display-options--popover__arrow' } ) ;
var description = wp . element . createElement (
'p' ,
{ className : 'wc-products-block-description' } ,
_ _ ( 'Choose which products you\'d like to display:' )
) ;
2018-02-13 19:03:53 +00:00
2018-02-15 18:16:14 +00:00
return wp . element . createElement (
'div' ,
2018-02-23 18:22:05 +00:00
{ className : classes , ref : this . setWrapperRef } ,
2018-02-23 14:57:27 +00:00
this . props . existing && arrow ,
! this . props . existing && description ,
2018-02-15 18:16:14 +00:00
display _settings
) ;
}
} ] ) ;
2018-02-13 19:03:53 +00:00
2018-02-15 18:16:14 +00:00
return ProductsBlockSettingsEditorDisplayOptions ;
} ( React . Component ) ;
2018-02-13 19:03:53 +00:00
/ * *
2018-02-15 18:16:14 +00:00
* The products block when in Edit mode .
2018-02-13 19:03:53 +00:00
* /
2018-02-15 18:16:14 +00:00
var ProductsBlockSettingsEditor = function ( _React$Component3 ) {
_inherits ( ProductsBlockSettingsEditor , _React$Component3 ) ;
2018-02-13 19:03:53 +00:00
/ * *
* Constructor .
* /
2018-02-15 18:16:14 +00:00
function ProductsBlockSettingsEditor ( props ) {
_classCallCheck ( this , ProductsBlockSettingsEditor ) ;
2018-02-13 19:03:53 +00:00
2018-02-15 18:16:14 +00:00
var _this4 = _possibleConstructorReturn ( this , ( ProductsBlockSettingsEditor . _ _proto _ _ || Object . getPrototypeOf ( ProductsBlockSettingsEditor ) ) . call ( this , props ) ) ;
2018-02-13 19:03:53 +00:00
2018-02-15 18:16:14 +00:00
_this4 . state = {
display : props . selected _display ,
menu _visible : props . selected _display ? false : true ,
expanded _group : ''
2018-02-13 19:03:53 +00:00
} ;
2018-02-15 18:16:14 +00:00
_this4 . updateDisplay = _this4 . updateDisplay . bind ( _this4 ) ;
2018-02-23 18:22:05 +00:00
_this4 . closeMenu = _this4 . closeMenu . bind ( _this4 ) ;
2018-02-15 18:16:14 +00:00
return _this4 ;
2018-02-13 19:03:53 +00:00
}
/ * *
2018-02-15 18:16:14 +00:00
* Update the display settings for the block .
2018-02-13 19:03:53 +00:00
*
2018-02-15 18:16:14 +00:00
* @ param value String
2018-02-13 19:03:53 +00:00
* /
2018-02-15 18:16:14 +00:00
_createClass ( ProductsBlockSettingsEditor , [ {
key : 'updateDisplay' ,
value : function updateDisplay ( value ) {
2018-02-13 19:03:53 +00:00
2018-02-15 18:16:14 +00:00
// If not a group update display.
var new _state = {
display : value ,
menu _visible : false ,
expanded _group : ''
} ;
2018-02-13 19:03:53 +00:00
2018-02-15 19:54:03 +00:00
var is _group = 'undefined' !== PRODUCTS _BLOCK _DISPLAY _SETTINGS [ value ] . group _container && PRODUCTS _BLOCK _DISPLAY _SETTINGS [ value ] . group _container ;
if ( is _group ) {
2018-02-19 19:57:37 +00:00
// If the group has not been expanded, expand it.
2018-02-15 18:16:14 +00:00
new _state = {
menu _visible : true ,
expanded _group : value
2018-02-15 19:54:03 +00:00
2018-02-19 19:57:37 +00:00
// If the group has already been expanded, collapse it.
2018-02-15 19:54:03 +00:00
} ; if ( this . state . expanded _group === PRODUCTS _BLOCK _DISPLAY _SETTINGS [ value ] . group _container ) {
new _state . expanded _group = '' ;
}
2018-02-15 18:16:14 +00:00
}
2018-02-13 19:03:53 +00:00
2018-02-15 18:16:14 +00:00
this . setState ( new _state ) ;
2018-02-13 19:03:53 +00:00
2018-02-15 18:16:14 +00:00
// Only update the display setting if a non-group setting was selected.
2018-02-15 19:54:03 +00:00
if ( ! is _group ) {
2018-02-15 18:16:14 +00:00
this . props . update _display _callback ( value ) ;
}
2018-02-13 19:03:53 +00:00
}
2018-02-23 18:22:05 +00:00
} , {
key : 'closeMenu' ,
value : function closeMenu ( ) {
this . setState ( {
menu _visible : false
} ) ;
}
2018-02-13 19:03:53 +00:00
/ * *
2018-02-15 18:16:14 +00:00
* Render the display settings dropdown and any extra contextual settings .
2018-02-13 19:03:53 +00:00
* /
} , {
2018-02-15 17:42:24 +00:00
key : 'render' ,
2018-02-13 19:03:53 +00:00
value : function render ( ) {
2018-02-15 18:16:14 +00:00
var _this5 = this ;
2018-02-13 19:03:53 +00:00
2018-02-15 18:16:14 +00:00
var extra _settings = null ;
if ( 'specific' === this . state . display ) {
2018-02-16 19:40:19 +00:00
extra _settings = wp . element . createElement ( _specificSelect . ProductsSpecificSelect , this . props ) ;
2018-02-15 18:16:14 +00:00
} else if ( 'category' === this . state . display ) {
extra _settings = wp . element . createElement ( _categorySelect . ProductsCategorySelect , this . props ) ;
} else if ( 'attribute' === this . state . display ) {
2018-02-20 19:47:50 +00:00
extra _settings = wp . element . createElement ( _attributeSelect . ProductsAttributeSelect , this . props ) ;
2018-02-15 18:16:14 +00:00
}
2018-02-13 19:03:53 +00:00
2018-03-14 15:11:36 +00:00
var menu = this . state . menu _visible ? wp . element . createElement ( ProductsBlockSettingsEditorDisplayOptions , { extended : this . state . expanded _group ? true : false , existing : this . state . display ? true : false , current : this . state . display , closeMenu : this . closeMenu , update _display _callback : this . updateDisplay } ) : null ;
2018-02-13 19:03:53 +00:00
2018-02-15 18:16:14 +00:00
var heading = null ;
if ( this . state . display ) {
2018-03-14 15:11:36 +00:00
var group _options = [ 'featured' , 'best_sellers' , 'best_rated' , 'on_sale' , 'attribute' ] ;
var should _group _expand = group _options . includes ( this . state . display ? this . state . display : '' ) ;
2018-02-15 18:16:14 +00:00
var menu _link = wp . element . createElement (
2018-02-23 14:57:27 +00:00
'button' ,
{ type : 'button' , className : 'wc-products-settings-heading__change-button button-link' , onClick : function onClick ( ) {
2018-03-14 15:11:36 +00:00
_this5 . setState ( { menu _visible : ! _this5 . state . menu _visible , expanded _group : should _group _expand } ) ;
2018-02-15 18:16:14 +00:00
} } ,
_ _ ( 'Display different products' )
) ;
2018-02-15 17:42:24 +00:00
heading = wp . element . createElement (
'div' ,
2018-02-23 14:57:27 +00:00
{ className : 'wc-products-settings-heading' } ,
2018-02-15 17:42:24 +00:00
wp . element . createElement (
'div' ,
2018-02-23 14:57:27 +00:00
{ className : 'wc-products-settings-heading__current' } ,
2018-02-15 17:42:24 +00:00
_ _ ( 'Displaying ' ) ,
wp . element . createElement (
'strong' ,
null ,
_ _ ( PRODUCTS _BLOCK _DISPLAY _SETTINGS [ this . state . display ] . title )
)
) ,
wp . element . createElement (
'div' ,
2018-02-23 14:57:27 +00:00
{ className : 'wc-products-settings-heading__change' } ,
2018-02-15 17:42:24 +00:00
menu _link
2018-02-13 19:03:53 +00:00
)
) ;
}
2018-03-02 18:05:13 +00:00
var done _button = wp . element . createElement (
'button' ,
{ type : 'button' , className : 'button wc-products-settings__footer-button' , onClick : this . props . done _callback } ,
_ _ ( 'Done' )
) ;
2018-03-09 17:57:08 +00:00
if ( [ '' , 'specific' , 'category' , 'attribute' ] . includes ( this . state . display ) && ! this . props . selected _display _setting . length ) {
2018-03-02 18:05:13 +00:00
var done _tooltips = {
2018-03-12 17:03:51 +00:00
'' : _ _ ( 'Please select which products you\'d like to display' ) ,
2018-03-02 18:05:13 +00:00
specific : _ _ ( 'Please search for and select products to display' ) ,
category : _ _ ( 'Please select at least one category to display' ) ,
attribute : _ _ ( 'Please select an attribute' )
} ;
done _button = wp . element . createElement (
Tooltip ,
{ text : done _tooltips [ this . state . display ] } ,
wp . element . createElement (
'button' ,
{ type : 'button' , className : 'button wc-products-settings__footer-button disabled' } ,
_ _ ( 'Done' )
)
) ;
}
2018-02-13 19:03:53 +00:00
return wp . element . createElement (
2018-02-15 17:42:24 +00:00
'div' ,
2018-02-26 17:10:45 +00:00
{ className : 'wc-products-settings ' + ( this . state . expanded _group ? 'expanded-group-' + this . state . expanded _group : '' ) } ,
2018-02-15 17:42:24 +00:00
wp . element . createElement (
'h4' ,
2018-02-26 17:10:45 +00:00
{ className : 'wc-products-settings__title' } ,
wp . element . createElement ( Dashicon , { icon : 'universal-access-alt' } ) ,
' ' ,
2018-02-15 17:42:24 +00:00
_ _ ( 'Products' )
) ,
2018-02-13 19:03:53 +00:00
heading ,
menu ,
extra _settings ,
wp . element . createElement (
2018-02-15 17:42:24 +00:00
'div' ,
2018-02-26 17:10:45 +00:00
{ className : 'wc-products-settings__footer' } ,
2018-03-02 18:05:13 +00:00
done _button
2018-02-13 19:03:53 +00:00
)
) ;
}
} ] ) ;
return ProductsBlockSettingsEditor ;
} ( React . Component ) ;
/ * *
* One product in the product block preview .
* /
2018-02-15 18:16:14 +00:00
var ProductPreview = function ( _React$Component4 ) {
_inherits ( ProductPreview , _React$Component4 ) ;
2018-02-13 19:03:53 +00:00
function ProductPreview ( ) {
_classCallCheck ( this , ProductPreview ) ;
return _possibleConstructorReturn ( this , ( ProductPreview . _ _proto _ _ || Object . getPrototypeOf ( ProductPreview ) ) . apply ( this , arguments ) ) ;
}
_createClass ( ProductPreview , [ {
2018-02-15 17:42:24 +00:00
key : 'render' ,
2018-02-13 19:03:53 +00:00
value : function render ( ) {
var _props = this . props ,
attributes = _props . attributes ,
product = _props . product ;
var image = null ;
if ( product . images . length ) {
2018-02-15 17:42:24 +00:00
image = wp . element . createElement ( 'img' , { src : product . images [ 0 ] . src } ) ;
2018-02-13 19:03:53 +00:00
}
2018-02-22 20:11:53 +00:00
return wp . element . createElement (
'div' ,
{ className : 'product-preview' } ,
image ,
wp . element . createElement (
2018-02-15 17:42:24 +00:00
'div' ,
{ className : 'product-title' } ,
2018-02-13 19:03:53 +00:00
product . name
2018-02-22 20:11:53 +00:00
) ,
2018-03-09 19:45:53 +00:00
wp . element . createElement ( 'div' , { className : 'product-price' , dangerouslySetInnerHTML : { _ _html : product . price _html } } ) ,
2018-02-22 20:11:53 +00:00
wp . element . createElement (
2018-02-15 17:42:24 +00:00
'span' ,
{ className : 'product-add-to-cart' } ,
2018-02-13 19:03:53 +00:00
_ _ ( 'Add to cart' )
2018-02-22 20:11:53 +00:00
)
2018-02-13 19:03:53 +00:00
) ;
}
} ] ) ;
return ProductPreview ;
} ( React . Component ) ;
/ * *
* Renders a preview of what the block will look like with current settings .
* /
2018-02-15 18:16:14 +00:00
var ProductsBlockPreview = withAPIData ( function ( _ref ) {
var attributes = _ref . attributes ;
2018-02-13 19:03:53 +00:00
var columns = attributes . columns ,
rows = attributes . rows ,
display = attributes . display ,
display _setting = attributes . display _setting ,
2018-02-22 15:33:18 +00:00
block _layout = attributes . block _layout ;
2018-02-13 19:03:53 +00:00
var query = {
2018-02-23 18:46:25 +00:00
per _page : 'list' === block _layout ? rows : rows * columns
2018-02-13 19:03:53 +00:00
} ;
if ( 'specific' === display ) {
2018-02-23 20:05:44 +00:00
query . include = display _setting . join ( ',' ) ;
2018-02-13 19:03:53 +00:00
query . orderby = 'include' ;
} else if ( 'category' === display ) {
query . category = display _setting . join ( ',' ) ;
2018-02-21 19:53:36 +00:00
} else if ( 'attribute' === display && display _setting . length ) {
query . attribute = display _setting [ 0 ] ;
if ( display _setting . length > 1 ) {
query . attribute _term = display _setting . slice ( 1 ) . join ( ',' ) ;
}
2018-02-26 19:58:19 +00:00
} else if ( 'featured' === display ) {
query . featured = 1 ;
} else if ( 'best_sellers' === display ) {
// @todo Not possible in the API yet.
} else if ( 'best_rated' === display ) {
// @todo Not possible in the API yet.
} else if ( 'on_sale' === display ) {
query . on _sale = 1 ;
2018-02-13 19:03:53 +00:00
}
var query _string = '?' ;
var _iteratorNormalCompletion = true ;
var _didIteratorError = false ;
var _iteratorError = undefined ;
try {
for ( var _iterator = Object . keys ( query ) [ Symbol . iterator ] ( ) , _step ; ! ( _iteratorNormalCompletion = ( _step = _iterator . next ( ) ) . done ) ; _iteratorNormalCompletion = true ) {
var key = _step . value ;
query _string += key + '=' + query [ key ] + '&' ;
}
} catch ( err ) {
_didIteratorError = true ;
_iteratorError = err ;
} finally {
try {
if ( ! _iteratorNormalCompletion && _iterator . return ) {
_iterator . return ( ) ;
}
} finally {
if ( _didIteratorError ) {
throw _iteratorError ;
}
}
}
return {
products : '/wc/v2/products' + query _string
} ;
2018-02-15 18:16:14 +00:00
} ) ( function ( _ref2 ) {
var products = _ref2 . products ,
attributes = _ref2 . attributes ;
2018-02-13 19:03:53 +00:00
if ( ! products . data ) {
return _ _ ( 'Loading' ) ;
}
if ( 0 === products . data . length ) {
return _ _ ( 'No products found' ) ;
}
2018-02-22 15:33:18 +00:00
var classes = "wc-products-block-preview " + attributes . block _layout + " cols-" + attributes . columns ;
2018-02-13 19:03:53 +00:00
return wp . element . createElement (
2018-02-15 17:42:24 +00:00
'div' ,
2018-02-13 19:03:53 +00:00
{ className : classes } ,
products . data . map ( function ( product ) {
return wp . element . createElement ( ProductPreview , { key : product . id , product : product , attributes : attributes } ) ;
} )
) ;
} ) ;
/ * *
* Register and run the products block .
* /
registerBlockType ( 'woocommerce/products' , {
title : _ _ ( 'Products' ) ,
icon : 'universal-access-alt' , // @todo Needs a good icon.
category : 'widgets' ,
attributes : {
/ * *
* Layout to use . 'grid' or 'list' .
* /
2018-02-22 15:33:18 +00:00
block _layout : {
2018-02-13 19:03:53 +00:00
type : 'string' ,
default : 'grid'
} ,
/ * *
* Number of columns .
* /
columns : {
type : 'number' ,
2018-03-09 19:45:53 +00:00
default : wc _product _block _data . default _columns
2018-02-13 19:03:53 +00:00
} ,
/ * *
* Number of rows .
* /
rows : {
type : 'number' ,
default : 1
} ,
/ * *
* What types of products to display . 'all' , 'specific' , or 'category' .
* /
display : {
type : 'string' ,
default : ''
} ,
/ * *
* Which products to display if 'display' is 'specific' or 'category' . Array of product ids or category slugs depending on setting .
* /
display _setting : {
type : 'array' ,
default : [ ]
} ,
/ * *
* Whether the block is in edit or preview mode .
* /
edit _mode : {
type : 'boolean' ,
default : true
}
} ,
/ * *
* Renders and manages the block .
* /
edit : function edit ( props ) {
var attributes = props . attributes ,
className = props . className ,
focus = props . focus ,
setAttributes = props . setAttributes ,
setFocus = props . setFocus ;
2018-02-22 15:33:18 +00:00
var block _layout = attributes . block _layout ,
2018-02-13 19:03:53 +00:00
rows = attributes . rows ,
columns = attributes . columns ,
display = attributes . display ,
display _setting = attributes . display _setting ,
edit _mode = attributes . edit _mode ;
/ * *
* Get the components for the sidebar settings area that is rendered while focused on a Products block .
*
* @ return Component
* /
function getInspectorControls ( ) {
2018-02-26 20:21:47 +00:00
// Column controls don't make sense in a list layout.
var columnControl = null ;
if ( 'list' !== block _layout ) {
columnControl = wp . element . createElement ( RangeControl , {
label : _ _ ( 'Columns' ) ,
value : columns ,
onChange : function onChange ( value ) {
return setAttributes ( { columns : value } ) ;
} ,
2018-03-09 19:45:53 +00:00
min : wc _product _block _data . min _columns ,
max : wc _product _block _data . max _columns
2018-02-26 20:21:47 +00:00
} ) ;
}
2018-02-13 19:03:53 +00:00
return wp . element . createElement (
InspectorControls ,
2018-02-15 17:42:24 +00:00
{ key : 'inspector' } ,
2018-02-13 19:03:53 +00:00
wp . element . createElement (
2018-02-15 17:42:24 +00:00
'h3' ,
2018-02-13 19:03:53 +00:00
null ,
_ _ ( 'Layout' )
) ,
2018-02-26 20:21:47 +00:00
columnControl ,
2018-02-13 19:03:53 +00:00
wp . element . createElement ( RangeControl , {
label : _ _ ( 'Rows' ) ,
value : rows ,
onChange : function onChange ( value ) {
return setAttributes ( { rows : value } ) ;
} ,
min : 1 ,
max : 6
} )
) ;
} ;
/ * *
* Get the components for the toolbar area that appears on top of the block when focused .
*
* @ return Component
* /
function getToolbarControls ( ) {
2018-03-09 19:04:01 +00:00
2018-02-13 19:03:53 +00:00
var layoutControls = [ {
icon : 'list-view' ,
title : _ _ ( 'List View' ) ,
onClick : function onClick ( ) {
2018-02-22 15:33:18 +00:00
return setAttributes ( { block _layout : 'list' } ) ;
2018-02-13 19:03:53 +00:00
} ,
2018-02-22 15:33:18 +00:00
isActive : 'list' === block _layout
2018-02-13 19:03:53 +00:00
} , {
icon : 'grid-view' ,
title : _ _ ( 'Grid View' ) ,
onClick : function onClick ( ) {
2018-02-22 15:33:18 +00:00
return setAttributes ( { block _layout : 'grid' } ) ;
2018-02-13 19:03:53 +00:00
} ,
2018-02-22 15:33:18 +00:00
isActive : 'grid' === block _layout
2018-02-13 19:03:53 +00:00
} ] ;
2018-03-12 17:20:00 +00:00
// Edit button should not do anything if valid product selection has not been made.
var shouldDisableEditButton = [ '' , 'specific' , 'category' , 'attribute' ] . includes ( display ) && ! display _setting . length ;
2018-02-13 19:03:53 +00:00
var editButton = [ {
icon : 'edit' ,
title : _ _ ( 'Edit' ) ,
2018-03-12 17:20:00 +00:00
onClick : shouldDisableEditButton ? function ( ) { } : function ( ) {
2018-02-13 19:03:53 +00:00
return setAttributes ( { edit _mode : ! edit _mode } ) ;
} ,
isActive : edit _mode
} ] ;
return wp . element . createElement (
BlockControls ,
2018-02-15 17:42:24 +00:00
{ key : 'controls' } ,
2018-03-12 17:20:00 +00:00
wp . element . createElement ( Toolbar , { controls : edit _mode ? [ ] : layoutControls } ) ,
2018-02-13 19:03:53 +00:00
wp . element . createElement ( Toolbar , { controls : editButton } )
) ;
}
/ * *
* Get the block preview component for preview mode .
*
* @ return Component
* /
function getPreview ( ) {
return wp . element . createElement ( ProductsBlockPreview , { attributes : attributes } ) ;
}
/ * *
* Get the block edit component for edit mode .
*
* @ return Component
* /
function getSettingsEditor ( ) {
2018-03-02 17:39:12 +00:00
var update _display _callback = function update _display _callback ( value ) {
if ( display !== value ) {
setAttributes ( {
display : value ,
display _setting : [ ]
} ) ;
}
} ;
2018-02-13 19:03:53 +00:00
return wp . element . createElement ( ProductsBlockSettingsEditor , {
selected _display : display ,
selected _display _setting : display _setting ,
2018-03-02 17:39:12 +00:00
update _display _callback : update _display _callback ,
2018-02-13 19:03:53 +00:00
update _display _setting _callback : function update _display _setting _callback ( value ) {
return setAttributes ( { display _setting : value } ) ;
} ,
done _callback : function done _callback ( ) {
return setAttributes ( { edit _mode : false } ) ;
}
} ) ;
}
return [ ! ! focus ? getInspectorControls ( ) : null , ! ! focus ? getToolbarControls ( ) : null , edit _mode ? getSettingsEditor ( ) : getPreview ( ) ] ;
} ,
/ * *
* Save the block content in the post content . Block content is saved as a products shortcode .
*
* @ return string
* /
save : function save ( props ) {
var _props$attributes = props . attributes ,
2018-02-22 15:33:18 +00:00
block _layout = _props$attributes . block _layout ,
2018-02-13 19:03:53 +00:00
rows = _props$attributes . rows ,
columns = _props$attributes . columns ,
display = _props$attributes . display ,
2018-02-26 19:12:21 +00:00
display _setting = _props$attributes . display _setting ;
2018-02-13 19:03:53 +00:00
var shortcode _atts = new Map ( ) ;
2018-02-22 15:33:18 +00:00
shortcode _atts . set ( 'limit' , 'grid' === block _layout ? rows * columns : rows ) ;
2018-02-26 19:12:21 +00:00
2018-02-26 20:13:08 +00:00
if ( 'list' === block _layout ) {
shortcode _atts . set ( 'class' , 'list-layout' ) ;
2018-02-26 19:12:21 +00:00
}
2018-02-13 19:03:53 +00:00
2018-02-22 15:33:18 +00:00
if ( 'grid' === block _layout ) {
2018-02-13 19:03:53 +00:00
shortcode _atts . set ( 'columns' , columns ) ;
}
if ( 'specific' === display ) {
2018-03-02 19:18:42 +00:00
shortcode _atts . set ( 'ids' , display _setting . join ( ',' ) ) ;
2018-02-26 19:12:21 +00:00
} else if ( 'category' === display ) {
2018-02-13 19:03:53 +00:00
shortcode _atts . set ( 'category' , display _setting . join ( ',' ) ) ;
2018-02-26 19:12:21 +00:00
} else if ( 'featured' === display ) {
shortcode _atts . set ( 'visibility' , 'featured' ) ;
} else if ( 'best_sellers' === display ) {
shortcode _atts . set ( 'best_selling' , '1' ) ;
} else if ( 'best_rated' === display ) {
shortcode _atts . set ( 'orderby' , 'rating' ) ;
} else if ( 'on_sale' === display ) {
shortcode _atts . set ( 'on_sale' , '1' ) ;
} else if ( 'attribute' === display ) {
var attribute = display _setting . length ? display _setting [ 0 ] : '' ;
var terms = display _setting . length > 1 ? display _setting . slice ( 1 ) . join ( ',' ) : '' ;
shortcode _atts . set ( 'attribute' , attribute ) ;
if ( terms . length ) {
shortcode _atts . set ( 'terms' , terms ) ;
}
2018-02-13 19:03:53 +00:00
}
// Build the shortcode string out of the set shortcode attributes.
var shortcode = '[products' ;
var _iteratorNormalCompletion2 = true ;
var _didIteratorError2 = false ;
var _iteratorError2 = undefined ;
try {
for ( var _iterator2 = shortcode _atts [ Symbol . iterator ] ( ) , _step2 ; ! ( _iteratorNormalCompletion2 = ( _step2 = _iterator2 . next ( ) ) . done ) ; _iteratorNormalCompletion2 = true ) {
2018-02-15 18:16:14 +00:00
var _ref3 = _step2 . value ;
2018-02-13 19:03:53 +00:00
2018-02-15 18:16:14 +00:00
var _ref4 = _slicedToArray ( _ref3 , 2 ) ;
2018-02-13 19:03:53 +00:00
2018-02-15 18:16:14 +00:00
var key = _ref4 [ 0 ] ;
var value = _ref4 [ 1 ] ;
2018-02-13 19:03:53 +00:00
shortcode += ' ' + key + '="' + value + '"' ;
}
} catch ( err ) {
_didIteratorError2 = true ;
_iteratorError2 = err ;
} finally {
try {
if ( ! _iteratorNormalCompletion2 && _iterator2 . return ) {
_iterator2 . return ( ) ;
}
} finally {
if ( _didIteratorError2 ) {
throw _iteratorError2 ;
}
}
}
shortcode += ']' ;
2018-02-26 20:13:08 +00:00
return wp . element . createElement (
RawHTML ,
null ,
shortcode
) ;
2018-02-13 19:03:53 +00:00
}
} ) ;
2018-02-15 18:16:14 +00:00
/***/ } ) ,
/* 1 */
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
var _createClass = function ( ) { function defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ( ) ;
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
function _possibleConstructorReturn ( self , call ) { if ( ! self ) { throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ; } return call && ( typeof call === "object" || typeof call === "function" ) ? call : self ; }
function _inherits ( subClass , superClass ) { if ( typeof superClass !== "function" && superClass !== null ) { throw new TypeError ( "Super expression must either be null or a function, not " + typeof superClass ) ; } subClass . prototype = Object . create ( superClass && superClass . prototype , { constructor : { value : subClass , enumerable : false , writable : true , configurable : true } } ) ; if ( superClass ) Object . setPrototypeOf ? Object . setPrototypeOf ( subClass , superClass ) : subClass . _ _proto _ _ = superClass ; }
var _ _ = wp . i18n . _ _ ;
var _wp$components = wp . components ,
Toolbar = _wp$components . Toolbar ,
withAPIData = _wp$components . withAPIData ,
2018-02-26 22:52:12 +00:00
Dropdown = _wp$components . Dropdown ,
Dashicon = _wp$components . Dashicon ;
2018-02-22 18:48:34 +00:00
var _ReactTransitionGroup = ReactTransitionGroup ,
TransitionGroup = _ReactTransitionGroup . TransitionGroup ,
CSSTransition = _ReactTransitionGroup . CSSTransition ;
2018-02-15 18:16:14 +00:00
2018-03-02 19:18:42 +00:00
/ * *
* Product data cache .
* Reduces the number of API calls and makes UI smoother and faster .
* /
var PRODUCT _DATA = { } ;
2018-02-15 18:16:14 +00:00
/ * *
* When the display mode is 'Specific products' search for and add products to the block .
*
* @ todo Add the functionality and everything .
* /
var ProductsSpecificSelect = exports . ProductsSpecificSelect = function ( _React$Component ) {
_inherits ( ProductsSpecificSelect , _React$Component ) ;
/ * *
* Constructor .
* /
function ProductsSpecificSelect ( props ) {
_classCallCheck ( this , ProductsSpecificSelect ) ;
var _this = _possibleConstructorReturn ( this , ( ProductsSpecificSelect . _ _proto _ _ || Object . getPrototypeOf ( ProductsSpecificSelect ) ) . call ( this , props ) ) ;
_this . state = {
2018-02-16 19:40:19 +00:00
selectedProducts : props . selected _display _setting || [ ]
2018-02-15 18:16:14 +00:00
} ;
return _this ;
}
2018-02-22 18:48:34 +00:00
/ * *
* Add a product to the list of selected products .
*
* @ param id int Product ID .
* /
2018-02-15 18:16:14 +00:00
_createClass ( ProductsSpecificSelect , [ {
2018-02-22 19:06:13 +00:00
key : 'addProduct' ,
2018-02-16 19:40:19 +00:00
value : function addProduct ( id ) {
2018-02-23 19:38:59 +00:00
2018-02-16 19:40:19 +00:00
var selectedProducts = this . state . selectedProducts ;
selectedProducts . push ( id ) ;
2018-02-15 18:16:14 +00:00
2018-02-16 19:40:19 +00:00
this . setState ( {
selectedProducts : selectedProducts
} ) ;
2018-02-23 19:38:59 +00:00
/ * *
* We need to copy the existing data into a new array .
2018-02-26 22:52:12 +00:00
* We can ' t just push the new product onto the end of the existing array because Gutenberg seems
2018-02-23 19:38:59 +00:00
* to do some sort of check by reference to determine whether to * actually * update the attribute
* and will not update it if we just pass back the same array with an extra element on the end .
* /
this . props . update _display _setting _callback ( selectedProducts . slice ( ) ) ;
2018-02-16 19:40:19 +00:00
}
2018-02-22 18:48:34 +00:00
/ * *
* Remove a product from the list of selected products .
*
* @ param id int Product ID .
* /
2018-02-16 19:40:19 +00:00
} , {
2018-02-22 19:06:13 +00:00
key : 'removeProduct' ,
2018-02-16 19:40:19 +00:00
value : function removeProduct ( id ) {
var oldProducts = this . state . selectedProducts ;
var newProducts = [ ] ;
var _iteratorNormalCompletion = true ;
var _didIteratorError = false ;
var _iteratorError = undefined ;
try {
for ( var _iterator = oldProducts [ Symbol . iterator ] ( ) , _step ; ! ( _iteratorNormalCompletion = ( _step = _iterator . next ( ) ) . done ) ; _iteratorNormalCompletion = true ) {
var productId = _step . value ;
if ( productId !== id ) {
newProducts . push ( productId ) ;
}
}
} catch ( err ) {
_didIteratorError = true ;
_iteratorError = err ;
} finally {
try {
if ( ! _iteratorNormalCompletion && _iterator . return ) {
_iterator . return ( ) ;
}
} finally {
if ( _didIteratorError ) {
throw _iteratorError ;
}
}
}
2018-02-15 18:16:14 +00:00
this . setState ( {
2018-02-16 19:40:19 +00:00
selectedProducts : newProducts
2018-02-15 18:16:14 +00:00
} ) ;
2018-02-16 19:40:19 +00:00
this . props . update _display _setting _callback ( newProducts ) ;
2018-02-15 18:16:14 +00:00
}
2018-02-22 18:48:34 +00:00
/ * *
* Render the product specific select screen .
* /
2018-02-15 18:16:14 +00:00
} , {
2018-02-22 19:06:13 +00:00
key : 'render' ,
2018-02-15 18:16:14 +00:00
value : function render ( ) {
return wp . element . createElement (
2018-02-22 19:06:13 +00:00
'div' ,
2018-02-26 22:52:12 +00:00
{ className : 'wc-products-list-card wc-products-list-card--specific' } ,
2018-02-22 18:48:34 +00:00
wp . element . createElement ( ProductsSpecificSearchField , {
addProductCallback : this . addProduct . bind ( this ) ,
selectedProducts : this . state . selectedProducts
} ) ,
wp . element . createElement ( ProductSpecificSelectedProducts , {
2018-03-02 19:18:42 +00:00
productIds : this . state . selectedProducts ,
2018-02-22 18:48:34 +00:00
removeProductCallback : this . removeProduct . bind ( this )
} )
2018-02-16 19:40:19 +00:00
) ;
}
} ] ) ;
return ProductsSpecificSelect ;
} ( React . Component ) ;
/ * *
* Product search area
* /
var ProductsSpecificSearchField = function ( _React$Component2 ) {
_inherits ( ProductsSpecificSearchField , _React$Component2 ) ;
2018-02-22 18:48:34 +00:00
/ * *
* Constructor .
* /
2018-02-16 19:40:19 +00:00
function ProductsSpecificSearchField ( props ) {
_classCallCheck ( this , ProductsSpecificSearchField ) ;
var _this2 = _possibleConstructorReturn ( this , ( ProductsSpecificSearchField . _ _proto _ _ || Object . getPrototypeOf ( ProductsSpecificSearchField ) ) . call ( this , props ) ) ;
_this2 . state = {
searchText : ''
} ;
_this2 . updateSearchResults = _this2 . updateSearchResults . bind ( _this2 ) ;
2018-02-22 19:06:13 +00:00
_this2 . setWrapperRef = _this2 . setWrapperRef . bind ( _this2 ) ;
_this2 . handleClickOutside = _this2 . handleClickOutside . bind ( _this2 ) ;
2018-02-16 19:40:19 +00:00
return _this2 ;
}
2018-02-22 18:48:34 +00:00
/ * *
2018-02-22 19:06:13 +00:00
* Hook in the listener for closing menu when clicked outside .
2018-02-22 18:48:34 +00:00
* /
2018-02-16 19:40:19 +00:00
_createClass ( ProductsSpecificSearchField , [ {
2018-02-22 19:06:13 +00:00
key : 'componentDidMount' ,
value : function componentDidMount ( ) {
document . addEventListener ( 'mousedown' , this . handleClickOutside ) ;
}
/ * *
* Remove the listener for closing menu when clicked outside .
* /
} , {
key : 'componentWillUnmount' ,
value : function componentWillUnmount ( ) {
document . removeEventListener ( 'mousedown' , this . handleClickOutside ) ;
}
/ * *
* Set the wrapper reference .
*
* @ param node DOMNode
* /
} , {
key : 'setWrapperRef' ,
value : function setWrapperRef ( node ) {
this . wrapperRef = node ;
}
/ * *
* Close the menu when user clicks outside the search area .
* /
} , {
key : 'handleClickOutside' ,
value : function handleClickOutside ( evt ) {
if ( this . wrapperRef && ! this . wrapperRef . contains ( event . target ) ) {
this . setState ( {
searchText : ''
} ) ;
}
}
/ * *
* Event handler for updating results when text is typed into the input .
*
* @ param evt Event object .
* /
} , {
key : 'updateSearchResults' ,
2018-02-16 19:40:19 +00:00
value : function updateSearchResults ( evt ) {
this . setState ( {
searchText : evt . target . value
} ) ;
}
2018-02-22 18:48:34 +00:00
/ * *
* Render the product search UI .
* /
2018-02-16 19:40:19 +00:00
} , {
2018-02-22 19:06:13 +00:00
key : 'render' ,
2018-02-16 19:40:19 +00:00
value : function render ( ) {
return wp . element . createElement (
2018-02-22 19:06:13 +00:00
'div' ,
2018-02-26 22:52:12 +00:00
{ className : 'wc-products-list-card__search-wrapper' , ref : this . setWrapperRef } ,
wp . element . createElement ( 'input' , { type : 'search' ,
className : 'wc-products-list-card__search' ,
2018-02-22 18:48:34 +00:00
value : this . state . searchText ,
placeholder : _ _ ( 'Search for products to display' ) ,
onChange : this . updateSearchResults
} ) ,
wp . element . createElement ( ProductSpecificSearchResults , {
searchString : this . state . searchText ,
addProductCallback : this . props . addProductCallback ,
selectedProducts : this . props . selectedProducts
} )
2018-02-15 18:16:14 +00:00
) ;
}
} ] ) ;
2018-02-16 19:40:19 +00:00
return ProductsSpecificSearchField ;
2018-02-15 18:16:14 +00:00
} ( React . Component ) ;
2018-02-16 19:40:19 +00:00
/ * *
2018-02-22 18:48:34 +00:00
* Render product search results based on the text entered into the textbox .
2018-02-16 19:40:19 +00:00
* /
var ProductSpecificSearchResults = withAPIData ( function ( props ) {
if ( ! props . searchString . length ) {
return {
products : [ ]
} ;
}
2018-02-15 18:16:14 +00:00
return {
2018-02-16 19:40:19 +00:00
products : '/wc/v2/products?per_page=10&search=' + props . searchString
2018-02-15 18:16:14 +00:00
} ;
2018-02-16 19:40:19 +00:00
} ) ( function ( _ref ) {
var products = _ref . products ,
2018-02-22 18:48:34 +00:00
addProductCallback = _ref . addProductCallback ,
selectedProducts = _ref . selectedProducts ;
2018-02-15 18:16:14 +00:00
if ( ! products . data ) {
2018-02-16 19:40:19 +00:00
return null ;
2018-02-15 18:16:14 +00:00
}
if ( 0 === products . data . length ) {
return _ _ ( 'No products found' ) ;
}
2018-03-02 19:18:42 +00:00
// Populate the cache.
var _iteratorNormalCompletion2 = true ;
var _didIteratorError2 = false ;
var _iteratorError2 = undefined ;
try {
for ( var _iterator2 = products . data [ Symbol . iterator ] ( ) , _step2 ; ! ( _iteratorNormalCompletion2 = ( _step2 = _iterator2 . next ( ) ) . done ) ; _iteratorNormalCompletion2 = true ) {
var product = _step2 . value ;
PRODUCT _DATA [ product . id ] = product ;
}
} catch ( err ) {
_didIteratorError2 = true ;
_iteratorError2 = err ;
} finally {
try {
if ( ! _iteratorNormalCompletion2 && _iterator2 . return ) {
_iterator2 . return ( ) ;
}
} finally {
if ( _didIteratorError2 ) {
throw _iteratorError2 ;
}
}
}
2018-02-22 18:48:34 +00:00
return wp . element . createElement ( ProductSpecificSearchResultsDropdown , {
products : products . data ,
addProductCallback : addProductCallback ,
selectedProducts : selectedProducts
} ) ;
} ) ;
/ * *
* The dropdown of search results .
* /
var ProductSpecificSearchResultsDropdown = function ( _React$Component3 ) {
_inherits ( ProductSpecificSearchResultsDropdown , _React$Component3 ) ;
function ProductSpecificSearchResultsDropdown ( ) {
_classCallCheck ( this , ProductSpecificSearchResultsDropdown ) ;
return _possibleConstructorReturn ( this , ( ProductSpecificSearchResultsDropdown . _ _proto _ _ || Object . getPrototypeOf ( ProductSpecificSearchResultsDropdown ) ) . apply ( this , arguments ) ) ;
}
_createClass ( ProductSpecificSearchResultsDropdown , [ {
2018-02-22 19:06:13 +00:00
key : 'render' ,
2018-02-22 18:48:34 +00:00
/ * *
* Render dropdown .
* /
value : function render ( ) {
var _props = this . props ,
products = _props . products ,
addProductCallback = _props . addProductCallback ,
selectedProducts = _props . selectedProducts ;
var productElements = [ ] ;
2018-03-02 19:18:42 +00:00
var _iteratorNormalCompletion3 = true ;
var _didIteratorError3 = false ;
var _iteratorError3 = undefined ;
2018-02-22 18:48:34 +00:00
try {
2018-03-02 19:18:42 +00:00
for ( var _iterator3 = products [ Symbol . iterator ] ( ) , _step3 ; ! ( _iteratorNormalCompletion3 = ( _step3 = _iterator3 . next ( ) ) . done ) ; _iteratorNormalCompletion3 = true ) {
var product = _step3 . value ;
2018-02-22 18:48:34 +00:00
if ( selectedProducts . includes ( product . id ) ) {
continue ;
}
productElements . push ( wp . element . createElement (
CSSTransition ,
{
key : product . slug ,
2018-02-27 14:08:32 +00:00
classNames : 'wc-products-list-card__content--transition' ,
2018-02-22 18:48:34 +00:00
timeout : { exit : 700 }
} ,
wp . element . createElement ( ProductSpecificSearchResultsDropdownElement , {
product : product ,
addProductCallback : addProductCallback
} )
) ) ;
}
} catch ( err ) {
2018-03-02 19:18:42 +00:00
_didIteratorError3 = true ;
_iteratorError3 = err ;
2018-02-22 18:48:34 +00:00
} finally {
try {
2018-03-02 19:18:42 +00:00
if ( ! _iteratorNormalCompletion3 && _iterator3 . return ) {
_iterator3 . return ( ) ;
2018-02-22 18:48:34 +00:00
}
} finally {
2018-03-02 19:18:42 +00:00
if ( _didIteratorError3 ) {
throw _iteratorError3 ;
2018-02-22 18:48:34 +00:00
}
}
}
return wp . element . createElement (
2018-02-22 19:06:13 +00:00
'div' ,
2018-02-26 22:52:12 +00:00
{ role : 'menu' , className : 'wc-products-list-card__search-results' , 'aria-orientation' : 'vertical' , 'aria-label' : '{ __( \'Products list\' ) }' } ,
2018-02-22 18:48:34 +00:00
wp . element . createElement (
2018-02-26 22:52:12 +00:00
TransitionGroup ,
2018-02-15 18:16:14 +00:00
null ,
2018-02-26 22:52:12 +00:00
productElements
2018-02-22 18:48:34 +00:00
)
) ;
}
} ] ) ;
return ProductSpecificSearchResultsDropdown ;
} ( React . Component ) ;
/ * *
* One search result .
* /
var ProductSpecificSearchResultsDropdownElement = function ( _React$Component4 ) {
_inherits ( ProductSpecificSearchResultsDropdownElement , _React$Component4 ) ;
/ * *
* Constructor .
* /
function ProductSpecificSearchResultsDropdownElement ( props ) {
_classCallCheck ( this , ProductSpecificSearchResultsDropdownElement ) ;
2018-02-26 22:52:12 +00:00
var _this4 = _possibleConstructorReturn ( this , ( ProductSpecificSearchResultsDropdownElement . _ _proto _ _ || Object . getPrototypeOf ( ProductSpecificSearchResultsDropdownElement ) ) . call ( this , props ) ) ;
2018-02-22 18:48:34 +00:00
2018-02-26 22:52:12 +00:00
_this4 . state = {
2018-02-22 18:48:34 +00:00
clicked : false
} ;
2018-02-26 22:52:12 +00:00
_this4 . handleClick = _this4 . handleClick . bind ( _this4 ) ;
return _this4 ;
2018-02-22 18:48:34 +00:00
}
/ * *
* Add product to main list and change UI to show it was added .
* /
_createClass ( ProductSpecificSearchResultsDropdownElement , [ {
2018-02-22 19:06:13 +00:00
key : 'handleClick' ,
2018-02-22 18:48:34 +00:00
value : function handleClick ( ) {
this . setState ( { clicked : true } ) ;
this . props . addProductCallback ( this . props . product . id ) ;
}
/ * *
* Render one result in the search results .
* /
} , {
2018-02-22 19:06:13 +00:00
key : 'render' ,
2018-02-22 18:48:34 +00:00
value : function render ( ) {
var product = this . props . product ;
return wp . element . createElement (
2018-02-26 22:52:12 +00:00
'div' ,
{ className : 'wc-products-list-card__content' } ,
wp . element . createElement ( 'img' , { src : product . images [ 0 ] . src } ) ,
wp . element . createElement (
'span' ,
{ className : 'wc-products-list-card__content-item-name' } ,
this . state . clicked ? _ _ ( 'Added' ) : product . name
) ,
2018-02-22 18:48:34 +00:00
wp . element . createElement (
2018-02-22 19:06:13 +00:00
'button' ,
{ type : 'button' ,
2018-02-26 22:52:12 +00:00
className : 'button-link' ,
2018-02-22 18:48:34 +00:00
id : 'product-' + product . id ,
onClick : this . handleClick } ,
2018-02-26 22:52:12 +00:00
_ _ ( 'Add' )
2018-02-22 18:48:34 +00:00
)
) ;
}
} ] ) ;
return ProductSpecificSearchResultsDropdownElement ;
} ( React . Component ) ;
2018-02-15 18:16:14 +00:00
2018-02-16 19:40:19 +00:00
/ * *
* List preview of selected products .
* /
2018-02-22 18:48:34 +00:00
2018-02-16 19:40:19 +00:00
var ProductSpecificSelectedProducts = withAPIData ( function ( props ) {
2018-02-15 18:16:14 +00:00
2018-03-02 19:18:42 +00:00
if ( ! props . productIds . length ) {
2018-02-16 19:40:19 +00:00
return {
products : [ ]
} ;
2018-02-15 18:16:14 +00:00
}
2018-03-02 19:18:42 +00:00
// Determine which products are not already in the cache and only fetch uncached products.
var uncachedProducts = [ ] ;
var _iteratorNormalCompletion4 = true ;
var _didIteratorError4 = false ;
var _iteratorError4 = undefined ;
try {
for ( var _iterator4 = props . productIds [ Symbol . iterator ] ( ) , _step4 ; ! ( _iteratorNormalCompletion4 = ( _step4 = _iterator4 . next ( ) ) . done ) ; _iteratorNormalCompletion4 = true ) {
var productId = _step4 . value ;
if ( ! PRODUCT _DATA . hasOwnProperty ( productId ) ) {
uncachedProducts . push ( productId ) ;
}
}
} catch ( err ) {
_didIteratorError4 = true ;
_iteratorError4 = err ;
} finally {
try {
if ( ! _iteratorNormalCompletion4 && _iterator4 . return ) {
_iterator4 . return ( ) ;
}
} finally {
if ( _didIteratorError4 ) {
throw _iteratorError4 ;
}
}
}
2018-02-16 19:40:19 +00:00
return {
2018-03-02 19:18:42 +00:00
products : uncachedProducts . length ? '/wc/v2/products?include=' + uncachedProducts . join ( ',' ) : [ ]
2018-02-16 19:40:19 +00:00
} ;
} ) ( function ( _ref2 ) {
2018-03-02 19:18:42 +00:00
var productIds = _ref2 . productIds ,
products = _ref2 . products ,
2018-02-16 19:40:19 +00:00
removeProductCallback = _ref2 . removeProductCallback ;
2018-03-02 19:18:42 +00:00
// Add new products to cache.
if ( products . data ) {
var _iteratorNormalCompletion5 = true ;
var _didIteratorError5 = false ;
var _iteratorError5 = undefined ;
try {
for ( var _iterator5 = products . data [ Symbol . iterator ] ( ) , _step5 ; ! ( _iteratorNormalCompletion5 = ( _step5 = _iterator5 . next ( ) ) . done ) ; _iteratorNormalCompletion5 = true ) {
var product = _step5 . value ;
PRODUCT _DATA [ product . id ] = product ;
}
} catch ( err ) {
_didIteratorError5 = true ;
_iteratorError5 = err ;
} finally {
try {
if ( ! _iteratorNormalCompletion5 && _iterator5 . return ) {
_iterator5 . return ( ) ;
}
} finally {
if ( _didIteratorError5 ) {
throw _iteratorError5 ;
}
}
}
2018-02-16 19:40:19 +00:00
}
2018-03-02 19:18:42 +00:00
if ( 0 === productIds . length ) {
2018-02-16 19:40:19 +00:00
return _ _ ( 'No products selected' ) ;
}
2018-02-15 18:16:14 +00:00
2018-03-02 19:18:42 +00:00
var productElements = [ ] ;
var _loop = function _loop ( productId ) {
// Skip products that aren't in the cache yet or failed to fetch.
if ( ! PRODUCT _DATA . hasOwnProperty ( productId ) ) {
return 'continue' ;
}
var productData = PRODUCT _DATA [ productId ] ;
productElements . push ( wp . element . createElement (
'li' ,
{ className : 'wc-products-list-card__item' } ,
wp . element . createElement (
'div' ,
{ className : 'wc-products-list-card__content' } ,
wp . element . createElement ( 'img' , { src : productData . images [ 0 ] . src } ) ,
wp . element . createElement (
'span' ,
{ className : 'wc-products-list-card__content-item-name' } ,
productData . name
) ,
wp . element . createElement (
'button' ,
{
type : 'button' ,
id : 'product-' + productData . id ,
onClick : function onClick ( ) {
removeProductCallback ( productData . id ) ;
} } ,
wp . element . createElement ( Dashicon , { icon : 'no-alt' } )
)
)
) ) ;
} ;
var _iteratorNormalCompletion6 = true ;
var _didIteratorError6 = false ;
var _iteratorError6 = undefined ;
try {
for ( var _iterator6 = productIds [ Symbol . iterator ] ( ) , _step6 ; ! ( _iteratorNormalCompletion6 = ( _step6 = _iterator6 . next ( ) ) . done ) ; _iteratorNormalCompletion6 = true ) {
var productId = _step6 . value ;
var _ret = _loop ( productId ) ;
if ( _ret === 'continue' ) continue ;
}
} catch ( err ) {
_didIteratorError6 = true ;
_iteratorError6 = err ;
} finally {
try {
if ( ! _iteratorNormalCompletion6 && _iterator6 . return ) {
_iterator6 . return ( ) ;
}
} finally {
if ( _didIteratorError6 ) {
throw _iteratorError6 ;
}
}
}
2018-02-15 18:16:14 +00:00
return wp . element . createElement (
2018-02-22 19:06:13 +00:00
'div' ,
2018-02-27 11:56:18 +00:00
{ className : 'wc-products-list-card__results-wrapper' } ,
2018-02-16 19:40:19 +00:00
wp . element . createElement (
2018-02-27 11:56:18 +00:00
'div' ,
{ role : 'menu' , className : 'wc-products-list-card__results' , 'aria-orientation' : 'vertical' , 'aria-label' : '{ __( \'Products list\' ) }' } ,
wp . element . createElement (
'ul' ,
null ,
2018-03-02 19:18:42 +00:00
productElements
2018-02-27 11:56:18 +00:00
)
2018-02-16 19:40:19 +00:00
)
2018-02-15 18:16:14 +00:00
) ;
2018-02-16 19:40:19 +00:00
} ) ;
2018-02-15 18:16:14 +00:00
/***/ } ) ,
/* 2 */
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
var _createClass = function ( ) { function defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ( ) ;
2018-02-20 17:00:43 +00:00
function _toConsumableArray ( arr ) { if ( Array . isArray ( arr ) ) { for ( var i = 0 , arr2 = Array ( arr . length ) ; i < arr . length ; i ++ ) { arr2 [ i ] = arr [ i ] ; } return arr2 ; } else { return Array . from ( arr ) ; } }
2018-02-15 18:16:14 +00:00
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
function _possibleConstructorReturn ( self , call ) { if ( ! self ) { throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ; } return call && ( typeof call === "object" || typeof call === "function" ) ? call : self ; }
function _inherits ( subClass , superClass ) { if ( typeof superClass !== "function" && superClass !== null ) { throw new TypeError ( "Super expression must either be null or a function, not " + typeof superClass ) ; } subClass . prototype = Object . create ( superClass && superClass . prototype , { constructor : { value : subClass , enumerable : false , writable : true , configurable : true } } ) ; if ( superClass ) Object . setPrototypeOf ? Object . setPrototypeOf ( subClass , superClass ) : subClass . _ _proto _ _ = superClass ; }
var _ _ = wp . i18n . _ _ ;
var _wp$components = wp . components ,
Toolbar = _wp$components . Toolbar ,
withAPIData = _wp$components . withAPIData ,
2018-02-19 19:57:37 +00:00
Dropdown = _wp$components . Dropdown ,
Dashicon = _wp$components . Dashicon ;
2018-02-15 18:16:14 +00:00
/ * *
* When the display mode is 'Product category' search for and select product categories to pull products from .
* /
var ProductsCategorySelect = exports . ProductsCategorySelect = function ( _React$Component ) {
_inherits ( ProductsCategorySelect , _React$Component ) ;
/ * *
* Constructor .
* /
function ProductsCategorySelect ( props ) {
_classCallCheck ( this , ProductsCategorySelect ) ;
var _this = _possibleConstructorReturn ( this , ( ProductsCategorySelect . _ _proto _ _ || Object . getPrototypeOf ( ProductsCategorySelect ) ) . call ( this , props ) ) ;
_this . state = {
selectedCategories : props . selected _display _setting ,
2018-02-21 13:58:20 +00:00
openAccordion : [ ] ,
filterQuery : '' ,
firstLoad : true
2018-02-15 18:16:14 +00:00
} ;
_this . checkboxChange = _this . checkboxChange . bind ( _this ) ;
2018-02-19 19:57:37 +00:00
_this . accordionToggle = _this . accordionToggle . bind ( _this ) ;
2018-02-15 18:16:14 +00:00
_this . filterResults = _this . filterResults . bind ( _this ) ;
2018-02-21 13:58:20 +00:00
_this . setFirstLoad = _this . setFirstLoad . bind ( _this ) ;
2018-02-15 18:16:14 +00:00
return _this ;
}
/ * *
* Handle checkbox toggle .
*
2018-02-20 17:00:43 +00:00
* @ param Checked ? boolean checked
* @ param Categories array categories
2018-02-15 18:16:14 +00:00
* /
_createClass ( ProductsCategorySelect , [ {
key : "checkboxChange" ,
2018-02-20 17:00:43 +00:00
value : function checkboxChange ( checked , categories ) {
2018-02-15 18:16:14 +00:00
var selectedCategories = this . state . selectedCategories ;
2018-02-20 17:00:43 +00:00
selectedCategories = selectedCategories . filter ( function ( category ) {
return ! categories . includes ( category ) ;
} ) ;
if ( checked ) {
var _selectedCategories ;
( _selectedCategories = selectedCategories ) . push . apply ( _selectedCategories , _toConsumableArray ( categories ) ) ;
2018-02-15 18:16:14 +00:00
}
this . setState ( {
selectedCategories : selectedCategories
} ) ;
this . props . update _display _setting _callback ( selectedCategories ) ;
}
2018-02-19 20:07:32 +00:00
/ * *
* Handle accordion toggle .
*
* @ param Category ID category
* /
2018-02-19 19:57:37 +00:00
} , {
key : "accordionToggle" ,
value : function accordionToggle ( category ) {
2018-02-21 13:58:20 +00:00
var openAccordions = this . state . openAccordion ;
if ( openAccordions . includes ( category ) ) {
openAccordions = openAccordions . filter ( function ( c ) {
return c !== category ;
} ) ;
} else {
openAccordions . push ( category ) ;
2018-02-19 19:57:37 +00:00
}
this . setState ( {
2018-02-21 13:58:20 +00:00
openAccordion : openAccordions
2018-02-19 19:57:37 +00:00
} ) ;
}
2018-02-15 18:16:14 +00:00
/ * *
* Filter categories .
*
* @ param Event object evt
* /
} , {
key : "filterResults" ,
value : function filterResults ( evt ) {
this . setState ( {
filterQuery : evt . target . value
} ) ;
}
2018-02-21 13:58:20 +00:00
/ * *
* Update firstLoad state .
*
* @ param Booolean loaded
* /
} , {
key : "setFirstLoad" ,
value : function setFirstLoad ( loaded ) {
this . setState ( {
firstLoad : ! ! loaded
} ) ;
}
2018-02-15 18:16:14 +00:00
/ * *
* Render the list of categories and the search input .
* /
} , {
key : "render" ,
value : function render ( ) {
return wp . element . createElement (
"div" ,
2018-02-26 17:10:45 +00:00
{ className : "wc-products-list-card wc-products-list-card--taxonomy wc-products-list-card--taxonomy-category" } ,
2018-02-15 18:16:14 +00:00
wp . element . createElement ( ProductCategoryFilter , { filterResults : this . filterResults } ) ,
2018-02-19 19:57:37 +00:00
wp . element . createElement ( ProductCategoryList , {
filterQuery : this . state . filterQuery ,
selectedCategories : this . state . selectedCategories ,
checkboxChange : this . checkboxChange ,
accordionToggle : this . accordionToggle ,
2018-02-21 13:58:20 +00:00
openAccordion : this . state . openAccordion ,
firstLoad : this . state . firstLoad ,
setFirstLoad : this . setFirstLoad
2018-02-19 19:57:37 +00:00
} )
2018-02-15 18:16:14 +00:00
) ;
}
} ] ) ;
return ProductsCategorySelect ;
} ( React . Component ) ;
/ * *
* The category search input .
* /
var ProductCategoryFilter = function ProductCategoryFilter ( _ref ) {
var filterResults = _ref . filterResults ;
return wp . element . createElement (
"div" ,
null ,
2018-02-26 17:10:45 +00:00
wp . element . createElement ( "input" , { className : "wc-products-list-card__search" , type : "search" , placeholder : _ _ ( 'Search for categories' ) , onChange : filterResults } )
2018-02-15 18:16:14 +00:00
) ;
} ;
/ * *
* Fetch and build a tree of product categories .
* /
var ProductCategoryList = withAPIData ( function ( props ) {
return {
categories : '/wc/v2/products/categories'
} ;
} ) ( function ( _ref2 ) {
var categories = _ref2 . categories ,
filterQuery = _ref2 . filterQuery ,
selectedCategories = _ref2 . selectedCategories ,
2018-02-19 19:57:37 +00:00
checkboxChange = _ref2 . checkboxChange ,
accordionToggle = _ref2 . accordionToggle ,
2018-02-21 13:58:20 +00:00
openAccordion = _ref2 . openAccordion ,
firstLoad = _ref2 . firstLoad ,
setFirstLoad = _ref2 . setFirstLoad ;
2018-02-15 18:16:14 +00:00
if ( ! categories . data ) {
return _ _ ( 'Loading' ) ;
}
if ( 0 === categories . data . length ) {
return _ _ ( 'No categories found' ) ;
}
2018-02-20 17:00:43 +00:00
var handleCategoriesToCheck = function handleCategoriesToCheck ( evt , parent , categories ) {
var ids = getCategoryChildren ( parent , categories ) . map ( function ( category ) {
return category . id ;
} ) ;
ids . push ( parent . id ) ;
checkboxChange ( evt . target . checked , ids ) ;
} ;
var getCategoryChildren = function getCategoryChildren ( parent , categories ) {
var children = [ ] ;
categories . filter ( function ( category ) {
return category . parent === parent . id ;
} ) . forEach ( function ( category ) {
children . push ( category ) ;
children . push . apply ( children , _toConsumableArray ( getCategoryChildren ( category , categories ) ) ) ;
} ) ;
return children ;
} ;
var categoryHasChildren = function categoryHasChildren ( parent , categories ) {
return ! ! getCategoryChildren ( parent , categories ) . length ;
} ;
2018-02-21 13:58:20 +00:00
var isIndeterminate = function isIndeterminate ( category , categories ) {
// Currect category selected?
if ( selectedCategories . includes ( category . id ) ) {
return false ;
}
// Has children?
var children = getCategoryChildren ( category , categories ) . map ( function ( category ) {
return category . id ;
} ) ;
var _iteratorNormalCompletion = true ;
var _didIteratorError = false ;
var _iteratorError = undefined ;
try {
for ( var _iterator = children [ Symbol . iterator ] ( ) , _step ; ! ( _iteratorNormalCompletion = ( _step = _iterator . next ( ) ) . done ) ; _iteratorNormalCompletion = true ) {
var child = _step . value ;
if ( selectedCategories . includes ( child ) ) {
return true ;
}
}
} catch ( err ) {
_didIteratorError = true ;
_iteratorError = err ;
} finally {
try {
if ( ! _iteratorNormalCompletion && _iterator . return ) {
_iterator . return ( ) ;
}
} finally {
if ( _didIteratorError ) {
throw _iteratorError ;
}
}
}
return false ;
} ;
2018-02-19 19:57:37 +00:00
var AccordionButton = function AccordionButton ( _ref3 ) {
2018-02-20 17:00:43 +00:00
var category = _ref3 . category ,
categories = _ref3 . categories ;
2018-02-19 19:57:37 +00:00
var icon = 'arrow-down-alt2' ;
2018-02-21 13:58:20 +00:00
if ( openAccordion . includes ( category . id ) ) {
2018-02-19 19:57:37 +00:00
icon = 'arrow-up-alt2' ;
}
2018-02-20 17:00:43 +00:00
var style = null ;
if ( ! categoryHasChildren ( category , categories ) ) {
style = {
visibility : 'hidden'
} ;
} ;
2018-02-19 19:57:37 +00:00
return wp . element . createElement (
"button" ,
{ onClick : function onClick ( ) {
2018-02-20 17:00:43 +00:00
return accordionToggle ( category . id ) ;
2018-02-26 17:10:45 +00:00
} , className : "wc-products-list-card__accordion-button" , style : style , type : "button" } ,
2018-02-19 19:57:37 +00:00
wp . element . createElement ( Dashicon , { icon : icon } )
) ;
} ;
var CategoryTree = function CategoryTree ( _ref4 ) {
var categories = _ref4 . categories ,
parent = _ref4 . parent ;
2018-02-15 18:16:14 +00:00
var filteredCategories = categories . filter ( function ( category ) {
return category . parent === parent ;
} ) ;
2018-02-21 13:58:20 +00:00
if ( firstLoad && selectedCategories . length > 0 ) {
categoriesData . filter ( function ( category ) {
return category . parent === 0 ;
} ) . forEach ( function ( category ) {
var children = getCategoryChildren ( category , categoriesData ) ;
var _iteratorNormalCompletion2 = true ;
var _didIteratorError2 = false ;
var _iteratorError2 = undefined ;
try {
for ( var _iterator2 = children [ Symbol . iterator ] ( ) , _step2 ; ! ( _iteratorNormalCompletion2 = ( _step2 = _iterator2 . next ( ) ) . done ) ; _iteratorNormalCompletion2 = true ) {
var child = _step2 . value ;
if ( selectedCategories . includes ( child . id ) && ! openAccordion . includes ( category . id ) ) {
accordionToggle ( category . id ) ;
break ;
}
}
} catch ( err ) {
_didIteratorError2 = true ;
_iteratorError2 = err ;
} finally {
try {
if ( ! _iteratorNormalCompletion2 && _iterator2 . return ) {
_iterator2 . return ( ) ;
}
} finally {
if ( _didIteratorError2 ) {
throw _iteratorError2 ;
}
}
}
} ) ;
setFirstLoad ( false ) ;
}
2018-02-15 18:16:14 +00:00
return filteredCategories . length > 0 && wp . element . createElement (
"ul" ,
null ,
filteredCategories . map ( function ( category ) {
return wp . element . createElement (
"li" ,
2018-02-26 17:10:45 +00:00
{ key : category . id , className : openAccordion . includes ( category . id ) ? 'wc-products-list-card__item wc-products-list-card__accordion-open' : 'wc-products-list-card__item' } ,
2018-02-15 18:16:14 +00:00
wp . element . createElement (
"label" ,
2018-02-26 17:10:45 +00:00
{ className : 0 === category . parent ? 'wc-products-list-card__content' : '' , htmlFor : 'product-category-' + category . id } ,
2018-02-15 18:16:14 +00:00
wp . element . createElement ( "input" , { type : "checkbox" ,
id : 'product-category-' + category . id ,
value : category . id ,
checked : selectedCategories . includes ( category . id ) ,
2018-02-20 17:00:43 +00:00
onChange : function onChange ( evt ) {
return handleCategoriesToCheck ( evt , category , categories ) ;
2018-02-21 13:58:20 +00:00
} ,
ref : function ref ( el ) {
return el && ( el . indeterminate = isIndeterminate ( category , categories ) ) ;
2018-02-20 17:00:43 +00:00
}
2018-02-15 18:16:14 +00:00
} ) ,
" " ,
2018-02-19 19:57:37 +00:00
category . name ,
2018-02-26 17:10:45 +00:00
0 === category . parent && wp . element . createElement ( AccordionButton , { category : category , categories : categories } ) ,
2018-02-19 19:57:37 +00:00
wp . element . createElement (
"span" ,
2018-02-26 17:10:45 +00:00
{ className : "wc-products-list-card__taxonomy-count" } ,
2018-02-19 19:57:37 +00:00
category . count
2018-02-26 17:10:45 +00:00
)
2018-02-15 18:16:14 +00:00
) ,
wp . element . createElement ( CategoryTree , { categories : categories , parent : category . id } )
) ;
} )
) ;
} ;
var categoriesData = categories . data ;
if ( '' !== filterQuery ) {
categoriesData = categoriesData . filter ( function ( category ) {
return category . slug . includes ( filterQuery . toLowerCase ( ) ) ;
} ) ;
}
return wp . element . createElement (
"div" ,
2018-02-26 17:10:45 +00:00
{ className : "wc-products-list-card__results" } ,
2018-02-15 18:16:14 +00:00
wp . element . createElement ( CategoryTree , { categories : categoriesData , parent : 0 } )
) ;
} ) ;
/***/ } ) ,
/* 3 */
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
"use strict" ;
Object . defineProperty ( exports , "__esModule" , {
value : true
} ) ;
var _createClass = function ( ) { function defineProperties ( target , props ) { for ( var i = 0 ; i < props . length ; i ++ ) { var descriptor = props [ i ] ; descriptor . enumerable = descriptor . enumerable || false ; descriptor . configurable = true ; if ( "value" in descriptor ) descriptor . writable = true ; Object . defineProperty ( target , descriptor . key , descriptor ) ; } } return function ( Constructor , protoProps , staticProps ) { if ( protoProps ) defineProperties ( Constructor . prototype , protoProps ) ; if ( staticProps ) defineProperties ( Constructor , staticProps ) ; return Constructor ; } ; } ( ) ;
function _classCallCheck ( instance , Constructor ) { if ( ! ( instance instanceof Constructor ) ) { throw new TypeError ( "Cannot call a class as a function" ) ; } }
function _possibleConstructorReturn ( self , call ) { if ( ! self ) { throw new ReferenceError ( "this hasn't been initialised - super() hasn't been called" ) ; } return call && ( typeof call === "object" || typeof call === "function" ) ? call : self ; }
function _inherits ( subClass , superClass ) { if ( typeof superClass !== "function" && superClass !== null ) { throw new TypeError ( "Super expression must either be null or a function, not " + typeof superClass ) ; } subClass . prototype = Object . create ( superClass && superClass . prototype , { constructor : { value : subClass , enumerable : false , writable : true , configurable : true } } ) ; if ( superClass ) Object . setPrototypeOf ? Object . setPrototypeOf ( subClass , superClass ) : subClass . _ _proto _ _ = superClass ; }
var _ _ = wp . i18n . _ _ ;
var _wp$components = wp . components ,
Toolbar = _wp$components . Toolbar ,
withAPIData = _wp$components . withAPIData ,
Dropdown = _wp$components . Dropdown ;
2018-02-20 19:47:50 +00:00
/ * *
2018-02-26 17:10:45 +00:00
* Attribute data cache .
2018-02-21 19:59:40 +00:00
* Needed because it takes a lot of API calls to generate attribute info .
2018-02-20 19:47:50 +00:00
* /
var PRODUCT _ATTRIBUTE _DATA = { } ;
2018-02-15 18:16:14 +00:00
/ * *
* When the display mode is 'Attribute' search for and select product attributes to pull products from .
* /
var ProductsAttributeSelect = exports . ProductsAttributeSelect = function ( _React$Component ) {
_inherits ( ProductsAttributeSelect , _React$Component ) ;
2018-02-20 19:47:50 +00:00
/ * *
* Constructor .
* /
function ProductsAttributeSelect ( props ) {
2018-02-15 18:16:14 +00:00
_classCallCheck ( this , ProductsAttributeSelect ) ;
2018-02-26 17:10:45 +00:00
/ * *
2018-02-21 19:59:40 +00:00
* The first item in props . selected _display _setting is the attribute slug .
* The rest are the term ids for any selected terms .
2018-02-21 18:43:21 +00:00
* /
2018-02-20 19:47:50 +00:00
var _this = _possibleConstructorReturn ( this , ( ProductsAttributeSelect . _ _proto _ _ || Object . getPrototypeOf ( ProductsAttributeSelect ) ) . call ( this , props ) ) ;
_this . state = {
2018-02-21 18:43:21 +00:00
selectedAttribute : props . selected _display _setting . length ? props . selected _display _setting [ 0 ] : '' ,
selectedTerms : props . selected _display _setting . length > 1 ? props . selected _display _setting . slice ( 1 ) : [ ] ,
2018-02-20 19:47:50 +00:00
filterQuery : ''
} ;
_this . setSelectedAttribute = _this . setSelectedAttribute . bind ( _this ) ;
_this . addTerm = _this . addTerm . bind ( _this ) ;
_this . removeTerm = _this . removeTerm . bind ( _this ) ;
return _this ;
2018-02-15 18:16:14 +00:00
}
2018-02-20 19:47:50 +00:00
/ * *
* Set the selected attribute .
*
* @ param slug string Attribute slug .
* /
2018-02-15 18:16:14 +00:00
_createClass ( ProductsAttributeSelect , [ {
2018-02-20 19:47:50 +00:00
key : 'setSelectedAttribute' ,
value : function setSelectedAttribute ( slug ) {
this . setState ( {
selectedAttribute : slug ,
selectedTerms : [ ]
} ) ;
2018-02-21 18:43:21 +00:00
this . props . update _display _setting _callback ( [ slug ] ) ;
2018-02-20 19:47:50 +00:00
}
/ * *
* Add a term to the selected attribute ' s terms .
*
2018-02-21 19:53:36 +00:00
* @ param id int Term id .
2018-02-20 19:47:50 +00:00
* /
} , {
key : 'addTerm' ,
2018-02-21 19:53:36 +00:00
value : function addTerm ( id ) {
2018-02-20 19:47:50 +00:00
var terms = this . state . selectedTerms ;
2018-02-21 19:53:36 +00:00
terms . push ( id ) ;
2018-02-20 19:47:50 +00:00
this . setState ( {
selectedTerms : terms
} ) ;
2018-02-21 18:43:21 +00:00
var displaySetting = [ this . state . selectedAttribute ] ;
displaySetting = displaySetting . concat ( terms ) ;
this . props . update _display _setting _callback ( displaySetting ) ;
2018-02-20 19:47:50 +00:00
}
/ * *
* Remove a term from the selected attribute ' s terms .
*
2018-02-21 19:53:36 +00:00
* @ param id int Term id .
2018-02-20 19:47:50 +00:00
* /
} , {
key : 'removeTerm' ,
2018-02-21 19:53:36 +00:00
value : function removeTerm ( id ) {
2018-02-20 19:47:50 +00:00
var newTerms = [ ] ;
var _iteratorNormalCompletion = true ;
var _didIteratorError = false ;
var _iteratorError = undefined ;
try {
for ( var _iterator = this . state . selectedTerms [ Symbol . iterator ] ( ) , _step ; ! ( _iteratorNormalCompletion = ( _step = _iterator . next ( ) ) . done ) ; _iteratorNormalCompletion = true ) {
2018-02-21 19:53:36 +00:00
var termId = _step . value ;
2018-02-20 19:47:50 +00:00
2018-02-21 19:53:36 +00:00
if ( termId !== id ) {
newTerms . push ( termId ) ;
2018-02-20 19:47:50 +00:00
}
}
} catch ( err ) {
_didIteratorError = true ;
_iteratorError = err ;
} finally {
try {
if ( ! _iteratorNormalCompletion && _iterator . return ) {
_iterator . return ( ) ;
}
} finally {
if ( _didIteratorError ) {
throw _iteratorError ;
}
}
}
this . setState ( {
selectedTerms : newTerms
} ) ;
2018-02-21 18:43:21 +00:00
var displaySetting = [ this . state . selectedAttribute ] ;
displaySetting = displaySetting . concat ( newTerms ) ;
this . props . update _display _setting _callback ( displaySetting ) ;
2018-02-20 19:47:50 +00:00
}
2018-02-21 19:53:36 +00:00
/ * *
* Update the search results when typing in the attributes box .
*
* @ param evt Event object
* /
2018-02-21 19:30:47 +00:00
} , {
key : 'updateFilter' ,
value : function updateFilter ( evt ) {
this . setState ( {
filterQuery : evt . target . value
} ) ;
}
2018-02-20 19:47:50 +00:00
/ * *
* Render the whole section .
* /
} , {
key : 'render' ,
2018-02-15 18:16:14 +00:00
value : function render ( ) {
return wp . element . createElement (
2018-02-20 19:47:50 +00:00
'div' ,
2018-02-26 17:10:45 +00:00
{ className : 'wc-products-list-card wc-products-list-card--taxonomy wc-products-list-card--taxonomy-atributes' } ,
2018-02-21 19:30:47 +00:00
wp . element . createElement ( ProductAttributeFilter , { updateFilter : this . updateFilter . bind ( this ) } ) ,
2018-02-20 19:47:50 +00:00
wp . element . createElement ( ProductAttributeList , {
selectedAttribute : this . state . selectedAttribute ,
selectedTerms : this . state . selectedTerms ,
2018-02-21 19:30:47 +00:00
filterQuery : this . state . filterQuery ,
2018-02-20 19:47:50 +00:00
setSelectedAttribute : this . setSelectedAttribute . bind ( this ) ,
addTerm : this . addTerm . bind ( this ) ,
removeTerm : this . removeTerm . bind ( this )
} )
2018-02-15 18:16:14 +00:00
) ;
}
} ] ) ;
return ProductsAttributeSelect ;
} ( React . Component ) ;
2018-02-20 19:47:50 +00:00
/ * *
* Search area for filtering through the attributes list .
* /
2018-02-21 19:30:47 +00:00
var ProductAttributeFilter = function ProductAttributeFilter ( props ) {
2018-02-20 19:47:50 +00:00
return wp . element . createElement (
'div' ,
null ,
2018-02-26 17:10:45 +00:00
wp . element . createElement ( 'input' , { className : 'wc-products-list-card__search' , type : 'search' , placeholder : _ _ ( 'Search for attributes' ) , onChange : props . updateFilter } )
2018-02-20 19:47:50 +00:00
) ;
} ;
/ * *
* List of attributes .
* /
var ProductAttributeList = withAPIData ( function ( props ) {
return {
attributes : '/wc/v2/products/attributes'
} ;
} ) ( function ( _ref ) {
var attributes = _ref . attributes ,
selectedAttribute = _ref . selectedAttribute ,
2018-02-21 19:30:47 +00:00
filterQuery = _ref . filterQuery ,
2018-02-20 19:47:50 +00:00
selectedTerms = _ref . selectedTerms ,
setSelectedAttribute = _ref . setSelectedAttribute ,
addTerm = _ref . addTerm ,
removeTerm = _ref . removeTerm ;
if ( ! attributes . data ) {
return _ _ ( 'Loading' ) ;
}
if ( 0 === attributes . data . length ) {
return _ _ ( 'No attributes found' ) ;
}
2018-02-21 19:30:47 +00:00
var filter = filterQuery . toLowerCase ( ) ;
2018-02-20 19:47:50 +00:00
var attributeElements = [ ] ;
var _iteratorNormalCompletion2 = true ;
var _didIteratorError2 = false ;
var _iteratorError2 = undefined ;
try {
for ( var _iterator2 = attributes . data [ Symbol . iterator ] ( ) , _step2 ; ! ( _iteratorNormalCompletion2 = ( _step2 = _iterator2 . next ( ) ) . done ) ; _iteratorNormalCompletion2 = true ) {
var attribute = _step2 . value ;
2018-02-21 19:30:47 +00:00
// Filter out attributes that don't match the search query.
if ( filter . length && - 1 === attribute . name . toLowerCase ( ) . indexOf ( filter ) ) {
continue ;
}
2018-02-20 19:47:50 +00:00
if ( PRODUCT _ATTRIBUTE _DATA . hasOwnProperty ( attribute . slug ) ) {
attributeElements . push ( wp . element . createElement ( ProductAttributeElement , {
selectedAttribute : selectedAttribute ,
selectedTerms : selectedTerms ,
attribute : attribute ,
setSelectedAttribute : setSelectedAttribute ,
addTerm : addTerm ,
removeTerm : removeTerm
} ) ) ;
} else {
attributeElements . push ( wp . element . createElement ( UncachedProductAttributeElement , {
selectedAttribute : selectedAttribute ,
selectedTerms : selectedTerms ,
attribute : attribute ,
setSelectedAttribute : setSelectedAttribute ,
addTerm : addTerm ,
removeTerm : removeTerm
} ) ) ;
}
}
} catch ( err ) {
_didIteratorError2 = true ;
_iteratorError2 = err ;
} finally {
try {
if ( ! _iteratorNormalCompletion2 && _iterator2 . return ) {
_iterator2 . return ( ) ;
}
} finally {
if ( _didIteratorError2 ) {
throw _iteratorError2 ;
}
}
}
return wp . element . createElement (
'div' ,
2018-02-26 17:10:45 +00:00
{ className : 'wc-products-list-card__results' } ,
2018-02-20 19:47:50 +00:00
attributeElements
) ;
} ) ;
/ * *
* Caches then renders a product attribute term element .
* /
var UncachedProductAttributeElement = withAPIData ( function ( props ) {
return {
terms : '/wc/v2/products/attributes/' + props . attribute . id + '/terms'
} ;
} ) ( function ( _ref2 ) {
var terms = _ref2 . terms ,
selectedAttribute = _ref2 . selectedAttribute ,
selectedTerms = _ref2 . selectedTerms ,
attribute = _ref2 . attribute ,
setSelectedAttribute = _ref2 . setSelectedAttribute ,
addTerm = _ref2 . addTerm ,
removeTerm = _ref2 . removeTerm ;
2018-03-02 17:16:28 +00:00
if ( ! terms . data || 0 === terms . data . length ) {
return null ;
2018-02-20 19:47:50 +00:00
}
// Populate cache.
PRODUCT _ATTRIBUTE _DATA [ attribute . slug ] = { terms : [ ] } ;
var totalCount = 0 ;
var _iteratorNormalCompletion3 = true ;
var _didIteratorError3 = false ;
var _iteratorError3 = undefined ;
try {
for ( var _iterator3 = terms . data [ Symbol . iterator ] ( ) , _step3 ; ! ( _iteratorNormalCompletion3 = ( _step3 = _iterator3 . next ( ) ) . done ) ; _iteratorNormalCompletion3 = true ) {
var term = _step3 . value ;
totalCount += term . count ;
PRODUCT _ATTRIBUTE _DATA [ attribute . slug ] . terms . push ( term ) ;
}
} catch ( err ) {
_didIteratorError3 = true ;
_iteratorError3 = err ;
} finally {
try {
if ( ! _iteratorNormalCompletion3 && _iterator3 . return ) {
_iterator3 . return ( ) ;
}
} finally {
if ( _didIteratorError3 ) {
throw _iteratorError3 ;
}
}
}
PRODUCT _ATTRIBUTE _DATA [ attribute . slug ] . count = totalCount ;
return wp . element . createElement ( ProductAttributeElement , {
selectedAttribute : selectedAttribute ,
selectedTerms : selectedTerms ,
attribute : attribute ,
setSelectedAttribute : setSelectedAttribute ,
addTerm : addTerm ,
removeTerm : removeTerm
} ) ;
} ) ;
/ * *
* A product attribute term element .
* /
var ProductAttributeElement = function ( _React$Component2 ) {
_inherits ( ProductAttributeElement , _React$Component2 ) ;
/ * *
* Constructor .
* /
function ProductAttributeElement ( props ) {
_classCallCheck ( this , ProductAttributeElement ) ;
var _this2 = _possibleConstructorReturn ( this , ( ProductAttributeElement . _ _proto _ _ || Object . getPrototypeOf ( ProductAttributeElement ) ) . call ( this , props ) ) ;
_this2 . handleAttributeChange = _this2 . handleAttributeChange . bind ( _this2 ) ;
_this2 . handleTermChange = _this2 . handleTermChange . bind ( _this2 ) ;
return _this2 ;
}
/ * *
* Propagate and reset values when the selected attribute is changed .
*
* @ param evt Event object
* /
_createClass ( ProductAttributeElement , [ {
key : 'handleAttributeChange' ,
value : function handleAttributeChange ( evt ) {
2018-02-21 18:43:21 +00:00
if ( ! evt . target . checked ) {
2018-02-20 19:47:50 +00:00
return ;
}
2018-02-21 18:43:21 +00:00
var slug = evt . target . value ;
2018-02-20 19:47:50 +00:00
this . props . setSelectedAttribute ( slug ) ;
}
/ * *
* Add or remove selected terms .
*
* @ param evt Event object
* /
} , {
key : 'handleTermChange' ,
value : function handleTermChange ( evt ) {
if ( evt . target . checked ) {
this . props . addTerm ( evt . target . value ) ;
} else {
this . props . removeTerm ( evt . target . value ) ;
}
}
/ * *
* Render the details for one attribute .
* /
} , {
key : 'render' ,
value : function render ( ) {
var _this3 = this ;
var attribute = PRODUCT _ATTRIBUTE _DATA [ this . props . attribute . slug ] ;
var isSelected = this . props . selectedAttribute === this . props . attribute . slug ;
var attributeTerms = null ;
if ( isSelected ) {
attributeTerms = wp . element . createElement (
'ul' ,
2018-02-26 17:10:45 +00:00
null ,
2018-02-20 19:47:50 +00:00
attribute . terms . map ( function ( term ) {
return wp . element . createElement (
'li' ,
2018-02-26 17:10:45 +00:00
{ className : 'wc-products-list-card__item' } ,
2018-02-20 19:47:50 +00:00
wp . element . createElement (
'label' ,
2018-02-26 17:10:45 +00:00
{ className : 'wc-products-list-card__content' } ,
2018-02-20 19:47:50 +00:00
wp . element . createElement ( 'input' , { type : 'checkbox' ,
2018-02-21 19:53:36 +00:00
value : term . id ,
2018-02-20 19:47:50 +00:00
onChange : _this3 . handleTermChange ,
2018-02-21 19:53:36 +00:00
checked : _this3 . props . selectedTerms . includes ( String ( term . id ) )
2018-02-20 19:47:50 +00:00
} ) ,
term . name ,
wp . element . createElement (
'span' ,
2018-02-26 17:10:45 +00:00
{ className : 'wc-products-list-card__taxonomy-count' } ,
2018-02-20 19:47:50 +00:00
term . count
)
)
) ;
} )
) ;
}
2018-02-26 17:10:45 +00:00
var cssClasses = [ 'wc-products-list-card--taxonomy-atributes__atribute' ] ;
if ( isSelected ) {
cssClasses . push ( 'wc-products-list-card__accordion-open' ) ;
}
2018-02-20 19:47:50 +00:00
return wp . element . createElement (
'div' ,
2018-02-26 17:10:45 +00:00
{ className : cssClasses . join ( ' ' ) } ,
2018-02-20 19:47:50 +00:00
wp . element . createElement (
'div' ,
2018-02-26 17:10:45 +00:00
null ,
2018-02-20 19:47:50 +00:00
wp . element . createElement (
'label' ,
2018-02-26 17:10:45 +00:00
{ className : 'wc-products-list-card__content' } ,
2018-02-20 19:47:50 +00:00
wp . element . createElement ( 'input' , { type : 'radio' ,
value : this . props . attribute . slug ,
2018-02-21 18:43:21 +00:00
onChange : this . handleAttributeChange ,
2018-02-20 19:47:50 +00:00
checked : isSelected
} ) ,
this . props . attribute . name ,
wp . element . createElement (
'span' ,
2018-02-26 17:10:45 +00:00
{ className : 'wc-products-list-card__taxonomy-count' } ,
2018-02-20 19:47:50 +00:00
attribute . count
)
)
) ,
attributeTerms
) ;
}
} ] ) ;
return ProductAttributeElement ;
} ( React . Component ) ;
2018-02-13 19:03:53 +00:00
/***/ } )
/******/ ] ) ;