content.js
1 year ago
export.js
1 year ago
header.js
1 year ago
template.js
5 years ago
templates-content.js
1 year ago
header.js
235 lines
| 1 | /* eslint-disable no-undef */ |
| 2 | import classnames from 'classnames'; |
| 3 | import { v4 as uuidv4 } from 'uuid'; |
| 4 | import { Button } from '@wordpress/components'; |
| 5 | import { withDispatch, withSelect } from '@wordpress/data'; |
| 6 | import { compose } from '@wordpress/compose'; |
| 7 | import { Path, SVG } from '@wordpress/primitives'; |
| 8 | |
| 9 | import { |
| 10 | fetchTemplates, |
| 11 | fetchLibrary, |
| 12 | } from './../data/templates-cloud/index.js'; |
| 13 | |
| 14 | const Icon = ( { title } ) => { |
| 15 | return ( |
| 16 | <SVG |
| 17 | width="100" |
| 18 | height="100" |
| 19 | viewBox="0 0 100 100" |
| 20 | fill="none" |
| 21 | xmlns="http://www.w3.org/2000/svg" |
| 22 | className="tpc-template-cloud-icon" |
| 23 | title={ title } |
| 24 | > |
| 25 | <Path |
| 26 | d="M95.0264 100H4.97356C2.22797 100 0 97.772 0 95.0264V4.97356C0 2.22797 2.22797 0 4.97356 0H95.0264C97.772 0 100 2.22797 100 4.97356V95.0264C100 97.772 97.772 100 95.0264 100Z" |
| 27 | fill="#0366D6" |
| 28 | /> |
| 29 | <Path |
| 30 | d="M82.6941 86.7448V30.8205V18.4653H70.3502H14.4146L26.7584 30.8205H70.3502V74.401L82.6941 86.7448Z" |
| 31 | fill="white" |
| 32 | /> |
| 33 | <Path |
| 34 | d="M42.2416 58.9291L42.2528 71.183L53.2352 82.1653L53.1902 47.9806L18.9941 47.9355L29.9765 58.9066L42.2416 58.9291Z" |
| 35 | fill="white" |
| 36 | /> |
| 37 | </SVG> |
| 38 | ); |
| 39 | }; |
| 40 | |
| 41 | const Header = ( { |
| 42 | getSearchQuery, |
| 43 | getOrder, |
| 44 | onImport, |
| 45 | isFetching, |
| 46 | isPreview, |
| 47 | currentTab, |
| 48 | preview, |
| 49 | setFetching, |
| 50 | togglePreview, |
| 51 | updateCurrentTab, |
| 52 | } ) => { |
| 53 | const syncLibrary = async () => { |
| 54 | window.localStorage.setItem( 'tpcCacheBuster', uuidv4() ); |
| 55 | setFetching( true ); |
| 56 | const order = getOrder(); |
| 57 | |
| 58 | await fetchTemplates( { |
| 59 | search: getSearchQuery(), |
| 60 | ...order, |
| 61 | } ); |
| 62 | |
| 63 | await fetchLibrary( { |
| 64 | search: getSearchQuery(), |
| 65 | ...order, |
| 66 | } ); |
| 67 | setFetching( false ); |
| 68 | }; |
| 69 | |
| 70 | return ( |
| 71 | <div |
| 72 | className={ classnames( 'dialog-header dialog-lightbox-header', { |
| 73 | 'is-dark': |
| 74 | 'dark' === |
| 75 | elementor.settings.editorPreferences.model.get( |
| 76 | 'ui_theme' |
| 77 | ), |
| 78 | } ) } |
| 79 | > |
| 80 | <div className="ti-tpc-templates-modal__header"> |
| 81 | <div className="ti-tpc-templates-modal__header__logo-area"> |
| 82 | { isPreview ? ( |
| 83 | <Button |
| 84 | className="ti-tpc-template-library-header-preview-back" |
| 85 | onClick={ togglePreview } |
| 86 | > |
| 87 | <i className="eicon-" aria-hidden="true"></i> |
| 88 | <span>{ window.tiTpc.library.actions.back }</span> |
| 89 | </Button> |
| 90 | ) : ( |
| 91 | <div className="ti-tpc-templates-modal__header__logo"> |
| 92 | <Icon |
| 93 | title={ window.tiTpc.library.templatesCloud } |
| 94 | /> |
| 95 | </div> |
| 96 | ) } |
| 97 | </div> |
| 98 | |
| 99 | { ! isPreview && ( |
| 100 | <div className="ti-tpc-templates-modal__header__menu-area"> |
| 101 | <Button |
| 102 | className={ classnames( |
| 103 | 'ti-tpc-template-library-menu-item', |
| 104 | { |
| 105 | 'is-active': 'library' === currentTab, |
| 106 | } |
| 107 | ) } |
| 108 | onClick={ () => updateCurrentTab( 'library' ) } |
| 109 | > |
| 110 | { window.tiTpc.library.tabs.library } |
| 111 | </Button> |
| 112 | </div> |
| 113 | ) } |
| 114 | |
| 115 | <div className="ti-tpc-templates-modal__header__items-area"> |
| 116 | <div className="ti-tpc-template-library-header-tools"> |
| 117 | { isPreview ? ( |
| 118 | <div className="ti-tpc-templates-modal__header__item ti-tpc-template-library-header-preview-insert-wrapper"> |
| 119 | <Button |
| 120 | className="ti-tpc-template-library-template-insert elementor-button" |
| 121 | onClick={ () => |
| 122 | onImport( { |
| 123 | id: preview.template_id, |
| 124 | title: preview.template_name, |
| 125 | meta: preview.meta || [], |
| 126 | } ) |
| 127 | } |
| 128 | > |
| 129 | <i |
| 130 | className="eicon-file-download" |
| 131 | aria-hidden="true" |
| 132 | ></i> |
| 133 | <span className="elementor-button-title"> |
| 134 | { window.tiTpc.library.actions.insert } |
| 135 | </span> |
| 136 | </Button> |
| 137 | </div> |
| 138 | ) : ( |
| 139 | <div className="ti-tpc-template-library-header-actions"> |
| 140 | { 'library' === currentTab && ( |
| 141 | <Button |
| 142 | className="ti-tpc-templates-modal__header__item" |
| 143 | onClick={ syncLibrary } |
| 144 | > |
| 145 | <i |
| 146 | className={ classnames( |
| 147 | 'eicon-sync', |
| 148 | { |
| 149 | 'eicon-animation-spin': |
| 150 | isFetching, |
| 151 | } |
| 152 | ) } |
| 153 | aria-hidden="true" |
| 154 | title={ |
| 155 | window.tiTpc.library.actions |
| 156 | .sync |
| 157 | } |
| 158 | ></i> |
| 159 | <span className="elementor-screen-only"> |
| 160 | { |
| 161 | window.tiTpc.library.actions |
| 162 | .sync |
| 163 | } |
| 164 | </span> |
| 165 | </Button> |
| 166 | ) } |
| 167 | |
| 168 | { [ 'wp-post', 'wp-page' ].includes( |
| 169 | elementor.config.document.type |
| 170 | ) && ( |
| 171 | <Button |
| 172 | className="ti-tpc-templates-modal__header__item" |
| 173 | onClick={ () => |
| 174 | updateCurrentTab( 'export' ) |
| 175 | } |
| 176 | > |
| 177 | <i |
| 178 | className="eicon-save-o" |
| 179 | aria-hidden="true" |
| 180 | title={ |
| 181 | window.tiTpc.library.save |
| 182 | } |
| 183 | ></i> |
| 184 | <span className="elementor-screen-only"> |
| 185 | { window.tiTpc.library.save } |
| 186 | </span> |
| 187 | </Button> |
| 188 | ) } |
| 189 | </div> |
| 190 | ) } |
| 191 | </div> |
| 192 | |
| 193 | <Button |
| 194 | className="ti-tpc-templates-modal__header__item ti-tpc-templates-modal__header__close" |
| 195 | onClick={ window.tiTpcModal.hide } |
| 196 | > |
| 197 | <i |
| 198 | className="eicon-close" |
| 199 | aria-hidden="true" |
| 200 | title={ window.tiTpc.library.actions.close } |
| 201 | ></i> |
| 202 | <span className="elementor-screen-only"> |
| 203 | { window.tiTpc.library.actions.close } |
| 204 | </span> |
| 205 | </Button> |
| 206 | </div> |
| 207 | </div> |
| 208 | </div> |
| 209 | ); |
| 210 | }; |
| 211 | |
| 212 | export default compose( |
| 213 | withSelect( ( select ) => { |
| 214 | const { isFetching, isPreview, getCurrentTab, getPreview } = |
| 215 | select( 'tpc/elementor' ); |
| 216 | |
| 217 | return { |
| 218 | isFetching: isFetching(), |
| 219 | isPreview: isPreview(), |
| 220 | currentTab: getCurrentTab(), |
| 221 | preview: getPreview(), |
| 222 | }; |
| 223 | } ), |
| 224 | withDispatch( ( dispatch ) => { |
| 225 | const { setFetching, togglePreview, updateCurrentTab } = |
| 226 | dispatch( 'tpc/elementor' ); |
| 227 | |
| 228 | return { |
| 229 | setFetching, |
| 230 | togglePreview, |
| 231 | updateCurrentTab, |
| 232 | }; |
| 233 | } ) |
| 234 | )( Header ); |
| 235 |