| 1 |
/** |
| 2 |
* PatternsWP — Admin UI (Gutenberg components, no build step). |
| 3 |
* Text domain: patternswp |
| 4 |
*/ |
| 5 |
( function ( wp ) { |
| 6 |
'use strict'; |
| 7 |
|
| 8 |
if ( ! wp || ! wp.element || ! wp.components || ! wp.domReady ) { |
| 9 |
return; |
| 10 |
} |
| 11 |
|
| 12 |
var el = wp.element.createElement; |
| 13 |
var Fragment = wp.element.Fragment; |
| 14 |
var useState = wp.element.useState; |
| 15 |
var useEffect = wp.element.useEffect; |
| 16 |
var createRoot = wp.element.createRoot; |
| 17 |
var render = wp.element.render; |
| 18 |
|
| 19 |
var __ = wp.i18n.__; |
| 20 |
var sprintf = wp.i18n.sprintf; |
| 21 |
|
| 22 |
var c = wp.components; |
| 23 |
var Button = c.Button; |
| 24 |
var Card = c.Card; |
| 25 |
var CardBody = c.CardBody; |
| 26 |
var CardHeader = c.CardHeader; |
| 27 |
var CardFooter = c.CardFooter; |
| 28 |
var ToggleControl = c.ToggleControl; |
| 29 |
var FormToggle = c.FormToggle; |
| 30 |
var TextControl = c.TextControl; |
| 31 |
var Notice = c.Notice; |
| 32 |
var Spinner = c.Spinner; |
| 33 |
var ExternalLink = c.ExternalLink; |
| 34 |
var Flex = c.Flex; |
| 35 |
var FlexItem = c.FlexItem; |
| 36 |
var FlexBlock = c.FlexBlock; |
| 37 |
|
| 38 |
var SVG = wp.primitives && wp.primitives.SVG; |
| 39 |
var Path = wp.primitives && wp.primitives.Path; |
| 40 |
|
| 41 |
var data = window.patternswpAdmin || {}; |
| 42 |
|
| 43 |
function logoIcon() { |
| 44 |
if ( ! SVG || ! Path ) { |
| 45 |
return null; |
| 46 |
} |
| 47 |
return el( |
| 48 |
SVG, |
| 49 |
{ |
| 50 |
xmlns: 'http://www.w3.org/2000/svg', |
| 51 |
viewBox: '0 0 24 24', |
| 52 |
width: 22, |
| 53 |
height: 22, |
| 54 |
fill: 'currentColor', |
| 55 |
'aria-hidden': true, |
| 56 |
}, |
| 57 |
el( Path, { |
| 58 |
d: 'M9.34 24L4.45 21.16L4.03 20.92V15.3L9.34 12V24Z', |
| 59 |
} ), |
| 60 |
el( Path, { |
| 61 |
fillRule: 'evenodd', |
| 62 |
clipRule: 'evenodd', |
| 63 |
d: 'M14.66 9.2L20.97 6L14.66 2.8V9.2Z', |
| 64 |
} ), |
| 65 |
el( Path, { |
| 66 |
d: 'M14.66 2.8L9.34 6L4.03 9.2V2.8L9.34 0L14.66 2.8Z', |
| 67 |
} ), |
| 68 |
el( Path, { |
| 69 |
fillRule: 'evenodd', |
| 70 |
clipRule: 'evenodd', |
| 71 |
d: 'M10.79 11.44V17.84L14.66 15.3L20.97 12V6L14.66 9.2L10.79 11.44Z', |
| 72 |
} ) |
| 73 |
); |
| 74 |
} |
| 75 |
|
| 76 |
function arrowIcon() { |
| 77 |
if ( ! SVG || ! Path ) { |
| 78 |
return '→'; |
| 79 |
} |
| 80 |
return el( |
| 81 |
SVG, |
| 82 |
{ |
| 83 |
xmlns: 'http://www.w3.org/2000/svg', |
| 84 |
viewBox: '0 0 24 24', |
| 85 |
width: 18, |
| 86 |
height: 18, |
| 87 |
fill: 'none', |
| 88 |
stroke: 'currentColor', |
| 89 |
strokeWidth: 2, |
| 90 |
'aria-hidden': true, |
| 91 |
}, |
| 92 |
el( Path, { |
| 93 |
d: 'M5 12h14M13 6l6 6-6 6', |
| 94 |
strokeLinecap: 'round', |
| 95 |
strokeLinejoin: 'round', |
| 96 |
} ) |
| 97 |
); |
| 98 |
} |
| 99 |
|
| 100 |
function ajax( action, body ) { |
| 101 |
var form = new window.FormData(); |
| 102 |
form.append( 'action', action ); |
| 103 |
form.append( 'nonce', data.nonce || '' ); |
| 104 |
|
| 105 |
if ( body && typeof body === 'object' ) { |
| 106 |
Object.keys( body ).forEach( function ( key ) { |
| 107 |
var value = body[ key ]; |
| 108 |
if ( typeof value === 'boolean' ) { |
| 109 |
form.append( key, value ? '1' : '0' ); |
| 110 |
} else if ( value !== undefined && value !== null ) { |
| 111 |
form.append( key, String( value ) ); |
| 112 |
} |
| 113 |
} ); |
| 114 |
} |
| 115 |
|
| 116 |
return window |
| 117 |
.fetch( data.ajaxUrl, { |
| 118 |
method: 'POST', |
| 119 |
credentials: 'same-origin', |
| 120 |
body: form, |
| 121 |
} ) |
| 122 |
.then( function ( response ) { |
| 123 |
return response.text().then( function ( text ) { |
| 124 |
var json = null; |
| 125 |
try { |
| 126 |
json = text ? JSON.parse( text ) : null; |
| 127 |
} catch ( e ) { |
| 128 |
json = null; |
| 129 |
} |
| 130 |
if ( ! json ) { |
| 131 |
throw new Error( |
| 132 |
__( |
| 133 |
'The server did not return a valid response. Please try again.', |
| 134 |
'patternswp' |
| 135 |
) |
| 136 |
); |
| 137 |
} |
| 138 |
return json; |
| 139 |
} ); |
| 140 |
} ) |
| 141 |
.then( function ( json ) { |
| 142 |
if ( ! json || ! json.success ) { |
| 143 |
var message = |
| 144 |
( json && |
| 145 |
json.data && |
| 146 |
( json.data.message || json.data ) ) || |
| 147 |
__( 'Something went wrong. Please try again.', 'patternswp' ); |
| 148 |
throw new Error( |
| 149 |
typeof message === 'string' |
| 150 |
? message |
| 151 |
: __( 'Something went wrong. Please try again.', 'patternswp' ) |
| 152 |
); |
| 153 |
} |
| 154 |
return json.data || {}; |
| 155 |
} ); |
| 156 |
} |
| 157 |
|
| 158 |
function AdminNotice( props ) { |
| 159 |
if ( ! props.notice ) { |
| 160 |
return null; |
| 161 |
} |
| 162 |
return el( |
| 163 |
'div', |
| 164 |
{ className: 'patternswp-admin__notice' }, |
| 165 |
el( |
| 166 |
Notice, |
| 167 |
{ |
| 168 |
status: props.notice.status || 'info', |
| 169 |
isDismissible: true, |
| 170 |
onRemove: props.onDismiss, |
| 171 |
}, |
| 172 |
props.notice.message |
| 173 |
) |
| 174 |
); |
| 175 |
} |
| 176 |
|
| 177 |
function Header( props ) { |
| 178 |
return el( |
| 179 |
'header', |
| 180 |
{ className: 'patternswp-admin__header' }, |
| 181 |
el( |
| 182 |
'div', |
| 183 |
{ className: 'patternswp-admin__brand' }, |
| 184 |
el( 'div', { className: 'patternswp-admin__logo' }, logoIcon() ), |
| 185 |
el( |
| 186 |
'div', |
| 187 |
null, |
| 188 |
el( 'h1', { className: 'patternswp-admin__title' }, 'PatternsWP' ), |
| 189 |
el( |
| 190 |
'p', |
| 191 |
{ className: 'patternswp-admin__subtitle' }, |
| 192 |
props.subtitle || |
| 193 |
__( 'Pattern library for the block editor', 'patternswp' ) |
| 194 |
) |
| 195 |
) |
| 196 |
), |
| 197 |
el( |
| 198 |
'div', |
| 199 |
{ className: 'patternswp-admin__header-actions' }, |
| 200 |
el( |
| 201 |
Button, |
| 202 |
{ |
| 203 |
variant: 'secondary', |
| 204 |
href: 'https://thepatternswp.com/docs/', |
| 205 |
target: '_blank', |
| 206 |
rel: 'noopener noreferrer', |
| 207 |
}, |
| 208 |
__( 'Documentation', 'patternswp' ) |
| 209 |
), |
| 210 |
! data.isLicenseActive && |
| 211 |
el( |
| 212 |
Button, |
| 213 |
{ |
| 214 |
variant: 'primary', |
| 215 |
href: 'https://thepatternswp.com/pricing/', |
| 216 |
target: '_blank', |
| 217 |
rel: 'noopener noreferrer', |
| 218 |
}, |
| 219 |
__( 'Upgrade to Pro', 'patternswp' ) |
| 220 |
) |
| 221 |
) |
| 222 |
); |
| 223 |
} |
| 224 |
|
| 225 |
function Nav( props ) { |
| 226 |
var tabs = [ |
| 227 |
{ |
| 228 |
id: 'dashboard', |
| 229 |
label: __( 'Dashboard', 'patternswp' ), |
| 230 |
slug: 'patternswp-plugin-menu', |
| 231 |
}, |
| 232 |
{ |
| 233 |
id: 'settings', |
| 234 |
label: __( 'Settings', 'patternswp' ), |
| 235 |
slug: 'patternswp-settings', |
| 236 |
}, |
| 237 |
{ |
| 238 |
id: 'support', |
| 239 |
label: __( 'Support', 'patternswp' ), |
| 240 |
slug: 'patternswp-plugin-page-1', |
| 241 |
}, |
| 242 |
{ |
| 243 |
id: 'license', |
| 244 |
label: __( 'License', 'patternswp' ), |
| 245 |
slug: 'patternswp-license_section', |
| 246 |
}, |
| 247 |
]; |
| 248 |
|
| 249 |
return el( |
| 250 |
'nav', |
| 251 |
{ |
| 252 |
className: 'patternswp-admin__nav', |
| 253 |
'aria-label': __( 'PatternsWP sections', 'patternswp' ), |
| 254 |
}, |
| 255 |
tabs.map( function ( tab ) { |
| 256 |
return el( |
| 257 |
'a', |
| 258 |
{ |
| 259 |
key: tab.id, |
| 260 |
href: data.adminUrl + '?page=' + tab.slug, |
| 261 |
className: |
| 262 |
'patternswp-admin__nav-item' + |
| 263 |
( props.current === tab.id ? ' is-active' : '' ), |
| 264 |
'aria-current': props.current === tab.id ? 'page' : undefined, |
| 265 |
}, |
| 266 |
tab.label |
| 267 |
); |
| 268 |
} ) |
| 269 |
); |
| 270 |
} |
| 271 |
|
| 272 |
function DashboardPage() { |
| 273 |
var steps = [ |
| 274 |
{ |
| 275 |
num: '01', |
| 276 |
title: __( 'Open the PatternsWP Library', 'patternswp' ), |
| 277 |
text: __( |
| 278 |
'When editing a page or post, add the PatternsWP Pattern Library block (search “patternswp” or type /patternswp), or use the PatternsWP Library button in the editor header.', |
| 279 |
'patternswp' |
| 280 |
), |
| 281 |
image: data.images && data.images.step1, |
| 282 |
}, |
| 283 |
{ |
| 284 |
num: '02', |
| 285 |
title: __( 'Browse Patterns & Templates', 'patternswp' ), |
| 286 |
text: __( |
| 287 |
'Explore a diverse range of block patterns and full-page layouts. Use search or filter by category to find the right design.', |
| 288 |
'patternswp' |
| 289 |
), |
| 290 |
image: data.images && data.images.step2, |
| 291 |
}, |
| 292 |
{ |
| 293 |
num: '03', |
| 294 |
title: __( 'Add Patterns & Customize', 'patternswp' ), |
| 295 |
text: __( |
| 296 |
'Insert a pattern with one click, then customize colors, typography, and content to match your site.', |
| 297 |
'patternswp' |
| 298 |
), |
| 299 |
image: data.images && data.images.step3, |
| 300 |
}, |
| 301 |
]; |
| 302 |
|
| 303 |
return el( |
| 304 |
Fragment, |
| 305 |
null, |
| 306 |
el( |
| 307 |
'div', |
| 308 |
{ className: 'patternswp-admin__card patternswp-admin__hero' }, |
| 309 |
el( |
| 310 |
'p', |
| 311 |
{ className: 'patternswp-admin__hero-eyebrow' }, |
| 312 |
sprintf( |
| 313 |
/* translators: %s: user display name */ |
| 314 |
__( 'Hello, %s', 'patternswp' ), |
| 315 |
data.userName || __( 'there', 'patternswp' ) |
| 316 |
) |
| 317 |
), |
| 318 |
el( |
| 319 |
'h2', |
| 320 |
{ className: 'patternswp-admin__hero-title' }, |
| 321 |
__( 'Welcome to PatternsWP', 'patternswp' ) |
| 322 |
), |
| 323 |
el( |
| 324 |
'p', |
| 325 |
{ className: 'patternswp-admin__hero-text' }, |
| 326 |
__( |
| 327 |
'Thanks for choosing PatternsWP. Follow these three steps to start building faster with ready-made block patterns.', |
| 328 |
'patternswp' |
| 329 |
) |
| 330 |
), |
| 331 |
el( |
| 332 |
'div', |
| 333 |
{ className: 'patternswp-admin__hero-actions' }, |
| 334 |
el( |
| 335 |
Button, |
| 336 |
{ |
| 337 |
variant: 'primary', |
| 338 |
href: data.newPageUrl, |
| 339 |
}, |
| 340 |
__( 'Start building with PatternsWP', 'patternswp' ) |
| 341 |
), |
| 342 |
el( |
| 343 |
Button, |
| 344 |
{ |
| 345 |
variant: 'tertiary', |
| 346 |
href: data.adminUrl + '?page=patternswp-settings', |
| 347 |
}, |
| 348 |
__( 'Configure settings', 'patternswp' ) |
| 349 |
) |
| 350 |
) |
| 351 |
), |
| 352 |
el( |
| 353 |
'div', |
| 354 |
{ className: 'patternswp-admin__steps' }, |
| 355 |
steps.map( function ( step ) { |
| 356 |
return el( |
| 357 |
'article', |
| 358 |
{ key: step.num, className: 'patternswp-admin__step' }, |
| 359 |
step.image && |
| 360 |
el( |
| 361 |
'div', |
| 362 |
{ className: 'patternswp-admin__step-media' }, |
| 363 |
el( 'img', { |
| 364 |
src: step.image, |
| 365 |
alt: '', |
| 366 |
} ) |
| 367 |
), |
| 368 |
el( |
| 369 |
'div', |
| 370 |
{ className: 'patternswp-admin__step-body' }, |
| 371 |
el( |
| 372 |
'p', |
| 373 |
{ className: 'patternswp-admin__step-num' }, |
| 374 |
step.num |
| 375 |
), |
| 376 |
el( |
| 377 |
'h3', |
| 378 |
{ className: 'patternswp-admin__step-title' }, |
| 379 |
step.title |
| 380 |
), |
| 381 |
el( |
| 382 |
'p', |
| 383 |
{ className: 'patternswp-admin__step-text' }, |
| 384 |
step.text |
| 385 |
) |
| 386 |
) |
| 387 |
); |
| 388 |
} ) |
| 389 |
) |
| 390 |
); |
| 391 |
} |
| 392 |
|
| 393 |
function SettingsPage( props ) { |
| 394 |
var settings = props.settings; |
| 395 |
var setSettings = props.setSettings; |
| 396 |
var setNotice = props.setNotice; |
| 397 |
var saving = props.saving; |
| 398 |
var setSaving = props.setSaving; |
| 399 |
var clearing = props.clearing; |
| 400 |
var setClearing = props.setClearing; |
| 401 |
|
| 402 |
function updateToggle( key, value ) { |
| 403 |
setSettings( Object.assign( {}, settings, { [ key ]: value } ) ); |
| 404 |
} |
| 405 |
|
| 406 |
function saveSettings() { |
| 407 |
setSaving( true ); |
| 408 |
setNotice( null ); |
| 409 |
ajax( 'patternswp_save_settings', { |
| 410 |
hide_theme_patterns: settings.hideThemePatterns, |
| 411 |
hide_uncategorized_patterns: settings.hideUncategorizedPatterns, |
| 412 |
hide_core_patterns: settings.hideCorePatterns, |
| 413 |
} ) |
| 414 |
.then( function ( result ) { |
| 415 |
setNotice( { |
| 416 |
status: 'success', |
| 417 |
message: |
| 418 |
( result && result.message ) || |
| 419 |
__( 'Settings saved.', 'patternswp' ), |
| 420 |
} ); |
| 421 |
} ) |
| 422 |
.catch( function ( error ) { |
| 423 |
setNotice( { |
| 424 |
status: 'error', |
| 425 |
message: error.message, |
| 426 |
} ); |
| 427 |
} ) |
| 428 |
.finally( function () { |
| 429 |
setSaving( false ); |
| 430 |
} ); |
| 431 |
} |
| 432 |
|
| 433 |
function clearCache() { |
| 434 |
setClearing( true ); |
| 435 |
setNotice( null ); |
| 436 |
ajax( 'patternswp_clear_cache_ajax' ) |
| 437 |
.then( function ( result ) { |
| 438 |
setNotice( { |
| 439 |
status: 'success', |
| 440 |
message: |
| 441 |
( result && result.message ) || |
| 442 |
__( 'Cache cleared successfully.', 'patternswp' ), |
| 443 |
} ); |
| 444 |
} ) |
| 445 |
.catch( function ( error ) { |
| 446 |
setNotice( { |
| 447 |
status: 'error', |
| 448 |
message: error.message, |
| 449 |
} ); |
| 450 |
} ) |
| 451 |
.finally( function () { |
| 452 |
setClearing( false ); |
| 453 |
} ); |
| 454 |
} |
| 455 |
|
| 456 |
var rows = [ |
| 457 |
{ |
| 458 |
key: 'hideThemePatterns', |
| 459 |
label: __( 'Hide Theme Patterns', 'patternswp' ), |
| 460 |
help: __( |
| 461 |
'Prevent patterns registered by the active theme from displaying in the patterns list.', |
| 462 |
'patternswp' |
| 463 |
), |
| 464 |
}, |
| 465 |
{ |
| 466 |
key: 'hideUncategorizedPatterns', |
| 467 |
label: __( 'Hide Uncategorized Patterns', 'patternswp' ), |
| 468 |
help: __( |
| 469 |
'Prevent patterns that are not in any registered category from displaying.', |
| 470 |
'patternswp' |
| 471 |
), |
| 472 |
}, |
| 473 |
{ |
| 474 |
key: 'hideCorePatterns', |
| 475 |
label: __( 'Hide Core Patterns', 'patternswp' ), |
| 476 |
help: __( |
| 477 |
'Remove WordPress core patterns from the pattern selector.', |
| 478 |
'patternswp' |
| 479 |
), |
| 480 |
}, |
| 481 |
]; |
| 482 |
|
| 483 |
return el( |
| 484 |
Fragment, |
| 485 |
null, |
| 486 |
el( |
| 487 |
Card, |
| 488 |
{ className: 'patternswp-admin__card' }, |
| 489 |
el( |
| 490 |
CardHeader, |
| 491 |
null, |
| 492 |
el( |
| 493 |
'div', |
| 494 |
null, |
| 495 |
el( |
| 496 |
'h2', |
| 497 |
{ className: 'patternswp-admin__card-title' }, |
| 498 |
__( 'Pattern Visibility', 'patternswp' ) |
| 499 |
), |
| 500 |
el( |
| 501 |
'p', |
| 502 |
{ className: 'patternswp-admin__card-desc' }, |
| 503 |
__( |
| 504 |
'Control which patterns appear in the block editor.', |
| 505 |
'patternswp' |
| 506 |
) |
| 507 |
) |
| 508 |
) |
| 509 |
), |
| 510 |
el( |
| 511 |
CardBody, |
| 512 |
null, |
| 513 |
rows.map( function ( row ) { |
| 514 |
return el( |
| 515 |
'div', |
| 516 |
{ |
| 517 |
key: row.key, |
| 518 |
className: 'patternswp-admin__setting-row', |
| 519 |
}, |
| 520 |
el( |
| 521 |
'div', |
| 522 |
null, |
| 523 |
el( |
| 524 |
'p', |
| 525 |
{ className: 'patternswp-admin__setting-label' }, |
| 526 |
row.label |
| 527 |
), |
| 528 |
el( |
| 529 |
'p', |
| 530 |
{ className: 'patternswp-admin__setting-help' }, |
| 531 |
row.help |
| 532 |
) |
| 533 |
), |
| 534 |
el( FormToggle || ToggleControl, FormToggle |
| 535 |
? { |
| 536 |
checked: !! settings[ row.key ], |
| 537 |
onChange: function () { |
| 538 |
updateToggle( |
| 539 |
row.key, |
| 540 |
! settings[ row.key ] |
| 541 |
); |
| 542 |
}, |
| 543 |
'aria-label': row.label, |
| 544 |
} |
| 545 |
: { |
| 546 |
checked: !! settings[ row.key ], |
| 547 |
onChange: function ( value ) { |
| 548 |
updateToggle( row.key, value ); |
| 549 |
}, |
| 550 |
label: row.label, |
| 551 |
hideLabelFromVision: true, |
| 552 |
__nextHasNoMarginBottom: true, |
| 553 |
} ) |
| 554 |
); |
| 555 |
} ) |
| 556 |
), |
| 557 |
el( |
| 558 |
CardFooter, |
| 559 |
null, |
| 560 |
el( |
| 561 |
Button, |
| 562 |
{ |
| 563 |
variant: 'primary', |
| 564 |
onClick: saveSettings, |
| 565 |
isBusy: saving, |
| 566 |
disabled: saving, |
| 567 |
}, |
| 568 |
saving |
| 569 |
? __( 'Saving…', 'patternswp' ) |
| 570 |
: __( 'Save Settings', 'patternswp' ) |
| 571 |
) |
| 572 |
) |
| 573 |
), |
| 574 |
el( |
| 575 |
Card, |
| 576 |
{ className: 'patternswp-admin__card' }, |
| 577 |
el( |
| 578 |
CardHeader, |
| 579 |
null, |
| 580 |
el( |
| 581 |
'div', |
| 582 |
null, |
| 583 |
el( |
| 584 |
'h2', |
| 585 |
{ className: 'patternswp-admin__card-title' }, |
| 586 |
__( 'Cache Management', 'patternswp' ) |
| 587 |
), |
| 588 |
el( |
| 589 |
'p', |
| 590 |
{ className: 'patternswp-admin__card-desc' }, |
| 591 |
__( |
| 592 |
'Clear cached patterns and data if the library looks out of date.', |
| 593 |
'patternswp' |
| 594 |
) |
| 595 |
) |
| 596 |
) |
| 597 |
), |
| 598 |
el( |
| 599 |
CardBody, |
| 600 |
null, |
| 601 |
el( |
| 602 |
'div', |
| 603 |
{ className: 'patternswp-admin__cache-box' }, |
| 604 |
el( |
| 605 |
'p', |
| 606 |
null, |
| 607 |
__( |
| 608 |
'Clear all cached patterns and related data. Useful after changing visibility settings or if patterns are not updating correctly.', |
| 609 |
'patternswp' |
| 610 |
) |
| 611 |
), |
| 612 |
el( |
| 613 |
Button, |
| 614 |
{ |
| 615 |
variant: 'secondary', |
| 616 |
onClick: clearCache, |
| 617 |
isBusy: clearing, |
| 618 |
disabled: clearing, |
| 619 |
}, |
| 620 |
clearing |
| 621 |
? __( 'Clearing…', 'patternswp' ) |
| 622 |
: __( 'Clear All Cache', 'patternswp' ) |
| 623 |
) |
| 624 |
) |
| 625 |
) |
| 626 |
) |
| 627 |
); |
| 628 |
} |
| 629 |
|
| 630 |
function SupportPage() { |
| 631 |
var links = [ |
| 632 |
{ |
| 633 |
label: __( 'Getting Started with PatternsWP', 'patternswp' ), |
| 634 |
url: 'https://thepatternswp.com/docs/getting-started-with-patternswp/', |
| 635 |
}, |
| 636 |
{ |
| 637 |
label: __( 'How to install PatternsWP', 'patternswp' ), |
| 638 |
url: 'https://thepatternswp.com/docs/how-to-install-patternswp/', |
| 639 |
}, |
| 640 |
{ |
| 641 |
label: __( 'How to Upgrade PatternsWP to Pro', 'patternswp' ), |
| 642 |
url: 'https://thepatternswp.com/docs/how-to-upgrade-patternswp-to-pro/', |
| 643 |
}, |
| 644 |
{ |
| 645 |
label: __( 'PatternsWP Support', 'patternswp' ), |
| 646 |
url: 'https://thepatternswp.com/docs/patternswp-support/', |
| 647 |
}, |
| 648 |
]; |
| 649 |
|
| 650 |
return el( |
| 651 |
Card, |
| 652 |
{ className: 'patternswp-admin__card' }, |
| 653 |
el( |
| 654 |
CardHeader, |
| 655 |
null, |
| 656 |
el( |
| 657 |
'div', |
| 658 |
null, |
| 659 |
el( |
| 660 |
'h2', |
| 661 |
{ className: 'patternswp-admin__card-title' }, |
| 662 |
__( 'Support', 'patternswp' ) |
| 663 |
), |
| 664 |
el( |
| 665 |
'p', |
| 666 |
{ className: 'patternswp-admin__card-desc' }, |
| 667 |
__( |
| 668 |
'Need help? Browse the docs or contact us — we are happy to assist.', |
| 669 |
'patternswp' |
| 670 |
) |
| 671 |
) |
| 672 |
) |
| 673 |
), |
| 674 |
el( |
| 675 |
CardBody, |
| 676 |
null, |
| 677 |
el( |
| 678 |
'div', |
| 679 |
{ className: 'patternswp-admin__support-grid' }, |
| 680 |
el( |
| 681 |
'div', |
| 682 |
null, |
| 683 |
el( |
| 684 |
'h3', |
| 685 |
{ className: 'patternswp-admin__card-title' }, |
| 686 |
__( 'Frequently asked questions', 'patternswp' ) |
| 687 |
), |
| 688 |
el( |
| 689 |
'p', |
| 690 |
{ className: 'patternswp-admin__card-desc' }, |
| 691 |
__( |
| 692 |
'Find answers to common questions about installing, upgrading, and using PatternsWP.', |
| 693 |
'patternswp' |
| 694 |
) |
| 695 |
), |
| 696 |
el( |
| 697 |
'div', |
| 698 |
{ className: 'patternswp-admin__link-row' }, |
| 699 |
el( |
| 700 |
Button, |
| 701 |
{ |
| 702 |
variant: 'primary', |
| 703 |
href: 'https://thepatternswp.com/contact/', |
| 704 |
target: '_blank', |
| 705 |
rel: 'noopener noreferrer', |
| 706 |
}, |
| 707 |
__( 'Contact support', 'patternswp' ) |
| 708 |
), |
| 709 |
el( |
| 710 |
Button, |
| 711 |
{ |
| 712 |
variant: 'secondary', |
| 713 |
href: 'https://thepatternswp.com/docs/', |
| 714 |
target: '_blank', |
| 715 |
rel: 'noopener noreferrer', |
| 716 |
}, |
| 717 |
__( 'View documentation', 'patternswp' ) |
| 718 |
) |
| 719 |
) |
| 720 |
), |
| 721 |
el( |
| 722 |
'ul', |
| 723 |
{ className: 'patternswp-admin__faq-list' }, |
| 724 |
links.map( function ( item ) { |
| 725 |
return el( |
| 726 |
'li', |
| 727 |
{ key: item.url }, |
| 728 |
el( |
| 729 |
'a', |
| 730 |
{ |
| 731 |
className: 'patternswp-admin__faq-link', |
| 732 |
href: item.url, |
| 733 |
target: '_blank', |
| 734 |
rel: 'noopener noreferrer', |
| 735 |
}, |
| 736 |
el( 'span', null, item.label ), |
| 737 |
arrowIcon() |
| 738 |
) |
| 739 |
); |
| 740 |
} ) |
| 741 |
) |
| 742 |
) |
| 743 |
) |
| 744 |
); |
| 745 |
} |
| 746 |
|
| 747 |
function LicensePage( props ) { |
| 748 |
var licenseKey = props.licenseKey; |
| 749 |
var setLicenseKey = props.setLicenseKey; |
| 750 |
var isActive = props.isActive; |
| 751 |
var setIsActive = props.setIsActive; |
| 752 |
var setNotice = props.setNotice; |
| 753 |
var activating = props.activating; |
| 754 |
var setActivating = props.setActivating; |
| 755 |
|
| 756 |
function activate() { |
| 757 |
setActivating( true ); |
| 758 |
setNotice( null ); |
| 759 |
ajax( 'patternswp_activate_license', { |
| 760 |
license_key: licenseKey, |
| 761 |
} ) |
| 762 |
.then( function ( result ) { |
| 763 |
if ( result.maskedKey ) { |
| 764 |
setLicenseKey( result.maskedKey ); |
| 765 |
} |
| 766 |
if ( typeof result.activated !== 'undefined' ) { |
| 767 |
setIsActive( !! result.activated ); |
| 768 |
} |
| 769 |
setNotice( { |
| 770 |
status: result.status || 'success', |
| 771 |
message: |
| 772 |
( result && result.message ) || |
| 773 |
__( 'License activated successfully.', 'patternswp' ), |
| 774 |
} ); |
| 775 |
} ) |
| 776 |
.catch( function ( error ) { |
| 777 |
setNotice( { |
| 778 |
status: 'error', |
| 779 |
message: error.message, |
| 780 |
} ); |
| 781 |
} ) |
| 782 |
.finally( function () { |
| 783 |
setActivating( false ); |
| 784 |
} ); |
| 785 |
} |
| 786 |
|
| 787 |
return el( |
| 788 |
Card, |
| 789 |
{ className: 'patternswp-admin__card' }, |
| 790 |
el( |
| 791 |
CardHeader, |
| 792 |
null, |
| 793 |
el( |
| 794 |
Flex, |
| 795 |
{ align: 'flex-start', justify: 'space-between', gap: 12 }, |
| 796 |
el( |
| 797 |
FlexBlock, |
| 798 |
null, |
| 799 |
el( |
| 800 |
'h2', |
| 801 |
{ className: 'patternswp-admin__card-title' }, |
| 802 |
__( 'License', 'patternswp' ) |
| 803 |
), |
| 804 |
el( |
| 805 |
'p', |
| 806 |
{ className: 'patternswp-admin__card-desc' }, |
| 807 |
__( |
| 808 |
'Already purchased? Enter your license key below to unlock PatternsWP Pro.', |
| 809 |
'patternswp' |
| 810 |
) |
| 811 |
) |
| 812 |
), |
| 813 |
el( |
| 814 |
FlexItem, |
| 815 |
null, |
| 816 |
el( |
| 817 |
'span', |
| 818 |
{ |
| 819 |
className: |
| 820 |
'patternswp-admin__status ' + |
| 821 |
( isActive ? 'is-active' : 'is-inactive' ), |
| 822 |
}, |
| 823 |
isActive |
| 824 |
? __( 'Active', 'patternswp' ) |
| 825 |
: __( 'Inactive', 'patternswp' ) |
| 826 |
) |
| 827 |
) |
| 828 |
) |
| 829 |
), |
| 830 |
el( |
| 831 |
CardBody, |
| 832 |
null, |
| 833 |
el( |
| 834 |
'div', |
| 835 |
{ className: 'patternswp-admin__license-form' }, |
| 836 |
el( TextControl, { |
| 837 |
label: __( 'License key', 'patternswp' ), |
| 838 |
value: licenseKey, |
| 839 |
onChange: setLicenseKey, |
| 840 |
placeholder: __( |
| 841 |
'Enter your license key here…', |
| 842 |
'patternswp' |
| 843 |
), |
| 844 |
type: 'text', |
| 845 |
__nextHasNoMarginBottom: true, |
| 846 |
__next40pxDefaultSize: true, |
| 847 |
} ), |
| 848 |
el( |
| 849 |
'div', |
| 850 |
{ className: 'patternswp-admin__license-actions' }, |
| 851 |
el( |
| 852 |
Button, |
| 853 |
{ |
| 854 |
variant: 'primary', |
| 855 |
onClick: activate, |
| 856 |
isBusy: activating, |
| 857 |
disabled: activating || ! licenseKey, |
| 858 |
}, |
| 859 |
activating |
| 860 |
? __( 'Activating…', 'patternswp' ) |
| 861 |
: __( 'Save & Activate', 'patternswp' ) |
| 862 |
), |
| 863 |
! isActive && |
| 864 |
el( |
| 865 |
ExternalLink, |
| 866 |
{ href: 'https://thepatternswp.com/pricing/' }, |
| 867 |
__( 'Get a license', 'patternswp' ) |
| 868 |
) |
| 869 |
), |
| 870 |
isActive && |
| 871 |
el( |
| 872 |
'p', |
| 873 |
{ className: 'patternswp-admin__card-desc' }, |
| 874 |
__( |
| 875 |
'Your license is active and verified. Enjoy all premium features!', |
| 876 |
'patternswp' |
| 877 |
) |
| 878 |
) |
| 879 |
) |
| 880 |
) |
| 881 |
); |
| 882 |
} |
| 883 |
|
| 884 |
function App() { |
| 885 |
var page = data.currentPage || 'dashboard'; |
| 886 |
var noticeState = useState( data.initialNotice || null ); |
| 887 |
var notice = noticeState[ 0 ]; |
| 888 |
var setNotice = noticeState[ 1 ]; |
| 889 |
|
| 890 |
var settingsState = useState( { |
| 891 |
hideThemePatterns: !! data.settings.hideThemePatterns, |
| 892 |
hideUncategorizedPatterns: !! data.settings.hideUncategorizedPatterns, |
| 893 |
hideCorePatterns: !! data.settings.hideCorePatterns, |
| 894 |
} ); |
| 895 |
var settings = settingsState[ 0 ]; |
| 896 |
var setSettings = settingsState[ 1 ]; |
| 897 |
|
| 898 |
var savingState = useState( false ); |
| 899 |
var saving = savingState[ 0 ]; |
| 900 |
var setSaving = savingState[ 1 ]; |
| 901 |
|
| 902 |
var clearingState = useState( false ); |
| 903 |
var clearing = clearingState[ 0 ]; |
| 904 |
var setClearing = clearingState[ 1 ]; |
| 905 |
|
| 906 |
var licenseState = useState( data.license.maskedKey || '' ); |
| 907 |
var licenseKey = licenseState[ 0 ]; |
| 908 |
var setLicenseKeyLocal = licenseState[ 1 ]; |
| 909 |
|
| 910 |
var activeState = useState( !! data.license.activated ); |
| 911 |
var isActive = activeState[ 0 ]; |
| 912 |
var setIsActive = activeState[ 1 ]; |
| 913 |
|
| 914 |
var activatingState = useState( false ); |
| 915 |
var activating = activatingState[ 0 ]; |
| 916 |
var setActivating = activatingState[ 1 ]; |
| 917 |
|
| 918 |
var subtitles = { |
| 919 |
dashboard: __( 'Get started with PatternsWP', 'patternswp' ), |
| 920 |
settings: __( 'Pattern visibility and cache', 'patternswp' ), |
| 921 |
support: __( 'Help, docs, and contact', 'patternswp' ), |
| 922 |
license: __( 'Activate your Pro license', 'patternswp' ), |
| 923 |
}; |
| 924 |
|
| 925 |
useEffect( function () { |
| 926 |
document.body.classList.add( 'patternswp-admin-body' ); |
| 927 |
return function () { |
| 928 |
document.body.classList.remove( 'patternswp-admin-body' ); |
| 929 |
}; |
| 930 |
}, [] ); |
| 931 |
|
| 932 |
var content; |
| 933 |
if ( page === 'settings' ) { |
| 934 |
content = el( SettingsPage, { |
| 935 |
settings: settings, |
| 936 |
setSettings: setSettings, |
| 937 |
setNotice: setNotice, |
| 938 |
saving: saving, |
| 939 |
setSaving: setSaving, |
| 940 |
clearing: clearing, |
| 941 |
setClearing: setClearing, |
| 942 |
} ); |
| 943 |
} else if ( page === 'support' ) { |
| 944 |
content = el( SupportPage ); |
| 945 |
} else if ( page === 'license' ) { |
| 946 |
content = el( LicensePage, { |
| 947 |
licenseKey: licenseKey, |
| 948 |
setLicenseKey: setLicenseKeyLocal, |
| 949 |
isActive: isActive, |
| 950 |
setIsActive: setIsActive, |
| 951 |
setNotice: setNotice, |
| 952 |
activating: activating, |
| 953 |
setActivating: setActivating, |
| 954 |
} ); |
| 955 |
} else { |
| 956 |
content = el( DashboardPage ); |
| 957 |
} |
| 958 |
|
| 959 |
return el( |
| 960 |
'div', |
| 961 |
{ className: 'patternswp-admin' }, |
| 962 |
el( Header, { subtitle: subtitles[ page ] || subtitles.dashboard } ), |
| 963 |
el( Nav, { current: page } ), |
| 964 |
el( AdminNotice, { |
| 965 |
notice: notice, |
| 966 |
onDismiss: function () { |
| 967 |
setNotice( null ); |
| 968 |
}, |
| 969 |
} ), |
| 970 |
content |
| 971 |
); |
| 972 |
} |
| 973 |
|
| 974 |
function mount() { |
| 975 |
var rootEl = document.getElementById( 'patternswp-admin-root' ); |
| 976 |
if ( ! rootEl ) { |
| 977 |
return; |
| 978 |
} |
| 979 |
if ( createRoot ) { |
| 980 |
createRoot( rootEl ).render( el( App ) ); |
| 981 |
} else { |
| 982 |
render( el( App ), rootEl ); |
| 983 |
} |
| 984 |
} |
| 985 |
|
| 986 |
wp.domReady( mount ); |
| 987 |
} )( window.wp ); |
| 988 |
|