Full Site Editing - Version 1.7

Version Description

  • Save the post before navigation when launching a WordPress.com site.
  • Add handling for site launch on WordPress.com.
  • Performance improvements in the block editor.
Download this release

Release Info

Developer jonsurrell
Plugin Icon wp plugin Full Site Editing
Version 1.7
Comparing to
See all releases

Code changes from version 1.6 to 1.7

block-inserter-modifications/contextual-tips/style.scss CHANGED
@@ -1,3 +1,3 @@
1
- .block-editor-inserter__panel-content .contextual-tip {
2
- margin-top: 20px;
3
}
1
+ .contextual-tip {
2
+ margin: 16px;
3
}
block-inserter-modifications/dist/contextual-tips.asset.php CHANGED
@@ -1 +1 @@
1
- <?php return array('dependencies' => array('lodash', 'wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-polyfill'), 'version' => '7ef96fc991c691a41f395233da562baf');
1
+ <?php return array('dependencies' => array('lodash', 'wp-block-editor', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-polyfill'), 'version' => 'a6f9f4d12a9ace424979170ce9169285');
block-inserter-modifications/dist/contextual-tips.css CHANGED
@@ -1 +1 @@
1
- .block-editor-inserter__panel-content .contextual-tip{margin-top:20px}
1
+ .contextual-tip{margin:16px}
block-inserter-modifications/dist/contextual-tips.rtl.css CHANGED
@@ -1 +1 @@
1
- .block-editor-inserter__panel-content .contextual-tip{margin-top:20px}
1
+ .contextual-tip{margin:16px}
common/dist/data-stores.asset.php CHANGED
@@ -1 +1 @@
1
- <?php return array('dependencies' => array('wp-data', 'wp-polyfill'), 'version' => 'bbe8c147a2096b1d2c69878492561286');
1
+ <?php return array('dependencies' => array('wp-data', 'wp-polyfill'), 'version' => 'f85e4af0d449d6ecb51aa06232cea8c1');
editor-domain-picker/dist/editor-domain-picker.asset.php ADDED
@@ -0,0 +1 @@
1
+ <?php return array('dependencies' => array('a8c-fse-common-data-stores', 'wp-data', 'wp-polyfill'), 'version' => '69a6c7928c3a7d594f65c41fb680d845');
editor-domain-picker/dist/editor-domain-picker.js ADDED
@@ -0,0 +1 @@
1
+ !function(e,t){for(var n in t)e[n]=t[n]}(window,function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t){!function(){e.exports=this.wp.data}()},function(e,t,n){"use strict";n.r(t);n(2);var o,r=n(0);console.log("👋 Hi! I'm the editor-domain-picker bundle running!");var i=setInterval((function(){(o=Object(r.select)("automattic/domains/suggestions").getCategories()).length&&(console.log(o),clearInterval(i),i=void 0)}));setTimeout((function(){i&&(console.log("😢 Timed out before we were able to get Domain Categories."),clearInterval(i))}),5e3)},function(e,t){!function(){e.exports=this["a8c-fse-common-data-stores"]}()}]));
editor-domain-picker/index.php ADDED
@@ -0,0 +1,41 @@
1
+ <?php
2
+ /**
3
+ * File for various functionality which needs to be added to Simple and Atomic
4
+ * sites. The code in this file is always loaded in the block editor.
5
+ *
6
+ * Currently, this module may not be the best place if you need to load
7
+ * front-end assets, but you could always add a separate action for that.
8
+ *
9
+ * @package A8C\FSE
10
+ */
11
+
12
+ namespace A8C\FSE\EditorDomainPicker;
13
+
14
+ /**
15
+ * Enqueue assets
16
+ */
17
+ function enqueue_script_and_style() {
18
+ // @TODO: Remove this block to enable in production
19
+ // Constant to disable the feature for development.
20
+ if ( ! ( defined( 'A8C_FSE_DOMAIN_PICKER_ENABLE' ) && A8C_FSE_DOMAIN_PICKER_ENABLE ) ) {
21
+ return;
22
+ }
23
+
24
+ // Avoid loading assets if possible.
25
+ if ( ! \A8C\FSE\Common\is_block_editor_screen() ) {
26
+ return;
27
+ }
28
+
29
+ $asset_file = include plugin_dir_path( __FILE__ ) . 'dist/editor-domain-picker.asset.php';
30
+ $script_dependencies = isset( $asset_file['dependencies'] ) ? $asset_file['dependencies'] : array();
31
+ $script_version = isset( $asset_file['version'] ) ? $asset_file['version'] : filemtime( plugin_dir_path( __FILE__ ) . 'dist/editor-domain-picker.js' );
32
+
33
+ wp_enqueue_script(
34
+ 'a8c-fse-editor-domain-picker-script',
35
+ plugins_url( 'dist/editor-domain-picker.js', __FILE__ ),
36
+ $script_dependencies,
37
+ $script_version,
38
+ true
39
+ );
40
+ }
41
+ add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\enqueue_script_and_style' );
editor-domain-picker/index.ts ADDED
@@ -0,0 +1,28 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import 'a8c-fse-common-data-stores';
5
+ import { select } from '@wordpress/data';
6
+
7
+ /* eslint-disable no-console */
8
+
9
+ console.log( "👋 Hi! I'm the editor-domain-picker bundle running!" );
10
+
11
+ let results;
12
+ let int: number | undefined = setInterval( () => {
13
+ results = select( 'automattic/domains/suggestions' ).getCategories();
14
+
15
+ if ( results.length ) {
16
+ // eslint-disable-next-line no-console
17
+ console.log( results );
18
+ clearInterval( int );
19
+ int = undefined;
20
+ }
21
+ } );
22
+
23
+ setTimeout( () => {
24
+ if ( int ) {
25
+ console.log( '😢 Timed out before we were able to get Domain Categories.' );
26
+ clearInterval( int );
27
+ }
28
+ }, 5000 );
editor-gutenboarding-launch/dist/editor-gutenboarding-launch.asset.php ADDED
@@ -0,0 +1 @@
1
+ <?php return array('dependencies' => array('wp-data', 'wp-dom-ready', 'wp-editor', 'wp-hooks', 'wp-i18n', 'wp-polyfill'), 'version' => '27ea122731a4f396f15d95bd0abb9623');
editor-gutenboarding-launch/dist/editor-gutenboarding-launch.css ADDED
@@ -0,0 +1 @@
1
+ .editor-gutenberg-launch__fse-overrides .editor-post-switch-to-draft{display:none}.editor-gutenberg-launch__fse-overrides .edit-post-header__settings .editor-post-publish-button__button{color:#007cba!important;background:none!important;border:none!important;box-shadow:none!important}.editor-gutenberg-launch__fse-overrides .edit-post-header__settings .editor-post-publish-button__button[aria-disabled=true]{opacity:.3!important}.editor-gutenberg-launch__launch-button{padding:0 12px;margin:0 12px 0 3px}
editor-gutenboarding-launch/dist/editor-gutenboarding-launch.js ADDED
@@ -0,0 +1 @@
1
+ !function(e,n){for(var t in n)e[t]=n[t]}(window,function(e){var n={};function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:r})},t.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,n){if(1&n&&(e=t(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)t.d(r,o,function(n){return e[n]}.bind(null,o));return r},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},t.p="",t(t.s=5)}([function(e,n){function t(e,n,t,r,o,i,u){try{var c=e[i](u),a=c.value}catch(f){return void t(f)}c.done?n(a):Promise.resolve(a).then(r,o)}e.exports=function(e){return function(){var n=this,r=arguments;return new Promise((function(o,i){var u=e.apply(n,r);function c(e){t(u,o,i,c,a,"next",e)}function a(e){t(u,o,i,c,a,"throw",e)}c(void 0)}))}}},function(e,n){!function(){e.exports=this.wp.i18n}()},function(e,n){!function(){e.exports=this.wp.domReady}()},function(e,n){!function(){e.exports=this.wp.hooks}()},function(e,n){!function(){e.exports=this.wp.data}()},function(e,n,t){"use strict";t.r(n);var r=t(0),o=t.n(r),i=t(1),u=t(2),c=t.n(u),a=t(3),f=t(4);t(6),t(7);c()((function(){l(),Object(a.addAction)("setGutenboardingStatus","a8c-gutenboarding",l)}));var d=!1;function l(){var e,n,t,r;if(!d&&(null===(e=window)||void 0===e||null===(n=e.calypsoifyGutenberg)||void 0===n?void 0:n.isFseGutenboarding)&&(null===(t=window)||void 0===t||null===(r=t.calypsoifyGutenberg)||void 0===r?void 0:r.frankenflowUrl)){d=!0;var u=setInterval((function(){var e,n,t=document.querySelector(".edit-post-header__settings");if(t){clearInterval(u),document.querySelector("body").classList.add("editor-gutenberg-launch__fse-overrides");var r=t.querySelector(".editor-post-publish-button__button"),c=document.createElement("a"),a=null===(e=window)||void 0===e||null===(n=e.calypsoifyGutenberg)||void 0===n?void 0:n.frankenflowUrl;c.href=a,c.target="_top",c.className="editor-gutenberg-launch__launch-button components-button is-primary";var d=document.createTextNode(Object(i.__)("Launch"));c.appendChild(d);var l=function(){var e=o()(regeneratorRuntime.mark((function e(n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n.preventDefault(),e.next=3,Object(f.dispatch)("core/editor").autosave();case 3:window.top.location.href=a;case 4:case"end":return e.stop()}}),e)})));return function(n){return e.apply(this,arguments)}}();c.addEventListener("click",l),t.prepend(c),r&&t.prepend(r)}}))}}},function(e,n){!function(){e.exports=this.wp.editor}()},function(e,n,t){}]));
editor-gutenboarding-launch/dist/editor-gutenboarding-launch.rtl.css ADDED
@@ -0,0 +1 @@
1
+ .editor-gutenberg-launch__fse-overrides .editor-post-switch-to-draft{display:none}.editor-gutenberg-launch__fse-overrides .edit-post-header__settings .editor-post-publish-button__button{color:#007cba!important;background:none!important;border:none!important;box-shadow:none!important}.editor-gutenberg-launch__fse-overrides .edit-post-header__settings .editor-post-publish-button__button[aria-disabled=true]{opacity:.3!important}.editor-gutenberg-launch__launch-button{padding:0 12px;margin:0 3px 0 12px}
editor-gutenboarding-launch/index.php ADDED
@@ -0,0 +1,43 @@
1
+ <?php
2
+ /**
3
+ * File for various functionality which needs to be added to Simple and Atomic
4
+ * sites. The code in this file is always loaded in the block editor.
5
+ *
6
+ * Currently, this module may not be the best place if you need to load
7
+ * front-end assets, but you could always add a separate action for that.
8
+ *
9
+ * @package A8C\FSE
10
+ */
11
+
12
+ namespace A8C\FSE\EditorGutenboardingLaunchButton;
13
+
14
+ /**
15
+ * Enqueue assets
16
+ */
17
+ function enqueue_script_and_style() {
18
+ // Avoid loading assets if possible.
19
+ if ( ! \A8C\FSE\Common\is_block_editor_screen() ) {
20
+ return;
21
+ }
22
+
23
+ $asset_file = include plugin_dir_path( __FILE__ ) . 'dist/editor-gutenboarding-launch.asset.php';
24
+ $script_dependencies = isset( $asset_file['dependences'] ) ? $asset_file['dependencies'] : array();
25
+ $script_version = isset( $asset_file['version'] ) ? $asset_file['version'] : filemtime( plugin_dir_path( __FILE__ ) . 'dist/editor-gutenboarding-launch.js' );
26
+ $style_version = isset( $asset_file['version'] ) ? $asset_file['version'] : filemtime( plugin_dir_path( __FILE__ ) . 'dist/editor-gutenboarding-launch.css' );
27
+
28
+ wp_enqueue_script(
29
+ 'a8c-fse-editor-gutenboarding-launch-script',
30
+ plugins_url( 'dist/editor-gutenboarding-launch.js', __FILE__ ),
31
+ $script_dependencies,
32
+ $script_version,
33
+ true
34
+ );
35
+
36
+ wp_enqueue_style(
37
+ 'a8c-fse-editor-gutenboarding-launch-style',
38
+ plugins_url( 'dist/editor-gutenboarding-launch.css', __FILE__ ),
39
+ array(),
40
+ $style_version
41
+ );
42
+ }
43
+ add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\enqueue_script_and_style' );
editor-gutenboarding-launch/index.scss ADDED
@@ -0,0 +1,25 @@
1
+ // Added to body to allow general overrides
2
+ .editor-gutenberg-launch__fse-overrides {
3
+ .editor-post-switch-to-draft {
4
+ display: none;
5
+ }
6
+
7
+ // Override 'Save' button to have tertiary styles.
8
+ .edit-post-header__settings {
9
+ .editor-post-publish-button__button {
10
+ color: #007cba !important;
11
+ background: none !important;
12
+ border: none !important;
13
+ box-shadow: none !important;
14
+
15
+ &[aria-disabled='true'] {
16
+ opacity: 0.3 !important;
17
+ }
18
+ }
19
+ }
20
+ }
21
+
22
+ .editor-gutenberg-launch__launch-button {
23
+ padding: 0 12px;
24
+ margin: 0 12px 0 3px;
25
+ }
editor-gutenboarding-launch/index.ts ADDED
@@ -0,0 +1,83 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import { __ } from '@wordpress/i18n';
5
+ import domReady from '@wordpress/dom-ready';
6
+ import { addAction } from '@wordpress/hooks';
7
+ import { dispatch } from '@wordpress/data';
8
+ // Depend on `core/editor` store.
9
+ import '@wordpress/editor';
10
+
11
+ /**
12
+ * Internal dependencies
13
+ */
14
+ import './index.scss';
15
+
16
+ interface CalypsoifyWindow extends Window {
17
+ calypsoifyGutenberg?: {
18
+ frankenflowUrl?: string;
19
+ isFseGutenboarding?: boolean;
20
+ [ key: string ]: unknown;
21
+ };
22
+ }
23
+ declare const window: CalypsoifyWindow;
24
+
25
+ domReady( () => {
26
+ updateEditor();
27
+ // Hook fallback incase setGutenboardingStatus runs after initial dom render.
28
+ addAction( 'setGutenboardingStatus', 'a8c-gutenboarding', updateEditor );
29
+ } );
30
+
31
+ let handled = false;
32
+ function updateEditor() {
33
+ if (
34
+ handled ||
35
+ ! window?.calypsoifyGutenberg?.isFseGutenboarding ||
36
+ ! window?.calypsoifyGutenberg?.frankenflowUrl
37
+ ) {
38
+ return;
39
+ }
40
+
41
+ handled = true;
42
+
43
+ const awaitSettingsBar = setInterval( () => {
44
+ const settingsBar = document.querySelector( '.edit-post-header__settings' );
45
+ if ( ! settingsBar ) {
46
+ return;
47
+ }
48
+ clearInterval( awaitSettingsBar );
49
+ const body = document.querySelector( 'body' );
50
+ body.classList.add( 'editor-gutenberg-launch__fse-overrides' );
51
+
52
+ // 'Update'/'Publish' primary button to become 'Save' tertiary button.
53
+ const saveButton = settingsBar.querySelector( '.editor-post-publish-button__button' );
54
+ // This line causes a reconciliation error in React and a page bork
55
+ // leaving it in there until we can decide on the UX for this component
56
+ //saveButton && ( saveButton.innerText = __( 'Save' ) );
57
+
58
+ // Wrap 'Launch' button link to frankenflow.
59
+ const launchLink = document.createElement( 'a' );
60
+
61
+ // Assert reason: We have an early return above with optional and falsy values. This should be a string.
62
+ const launchHref = window?.calypsoifyGutenberg?.frankenflowUrl as string;
63
+
64
+ launchLink.href = launchHref;
65
+ launchLink.target = '_top';
66
+ launchLink.className = 'editor-gutenberg-launch__launch-button components-button is-primary';
67
+ const textContent = document.createTextNode( __( 'Launch' ) );
68
+ launchLink.appendChild( textContent );
69
+
70
+ const saveAndNavigate = async ( e: Event ) => {
71
+ // Disable href navigation
72
+ e.preventDefault();
73
+ await dispatch( 'core/editor' ).autosave();
74
+ // Using window.top to escape from the editor iframe on WordPress.com
75
+ window.top.location.href = launchHref;
76
+ };
77
+ launchLink.addEventListener( 'click', saveAndNavigate );
78
+
79
+ // Put 'Launch' and 'Save' back on bar in desired order.
80
+ settingsBar.prepend( launchLink );
81
+ saveButton && settingsBar.prepend( saveButton );
82
+ } );
83
+ }
full-site-editing-plugin.php CHANGED
@@ -2,7 +2,7 @@
2
/**
3
* Plugin Name: Full Site Editing
4
* Description: Enhances your page creation workflow within the Block Editor.
5
- * Version: 1.6
6
* Author: Automattic
7
* Author URI: https://automattic.com/wordpress-plugins/
8
* License: GPLv2 or later
@@ -35,7 +35,7 @@ namespace A8C\FSE;
35
*
36
* @var string
37
*/
38
- define( 'PLUGIN_VERSION', '1.6' );
39
40
// Always include these helper files for dotcom FSE.
41
require_once __DIR__ . '/dotcom-fse/helpers.php';
@@ -149,6 +149,22 @@ function load_common_module() {
149
}
150
add_action( 'plugins_loaded', __NAMESPACE__ . '\load_common_module' );
151
152
/**
153
* Add front-end CoBlocks gallery block scripts.
154
*
2
/**
3
* Plugin Name: Full Site Editing
4
* Description: Enhances your page creation workflow within the Block Editor.
5
+ * Version: 1.7
6
* Author: Automattic
7
* Author URI: https://automattic.com/wordpress-plugins/
8
* License: GPLv2 or later
35
*
36
* @var string
37
*/
38
+ define( 'PLUGIN_VERSION', '1.7' );
39
40
// Always include these helper files for dotcom FSE.
41
require_once __DIR__ . '/dotcom-fse/helpers.php';
149
}
150
add_action( 'plugins_loaded', __NAMESPACE__ . '\load_common_module' );
151
152
+ /**
153
+ * Sigh: load_editor_domain_picker
154
+ */
155
+ function load_editor_domain_picker() {
156
+ require_once __DIR__ . '/editor-domain-picker/index.php';
157
+ }
158
+ add_action( 'plugins_loaded', __NAMESPACE__ . '\load_editor_domain_picker' );
159
+
160
+ /**
161
+ * Sigh: load_editor_gutenboarding_launch
162
+ */
163
+ function load_editor_gutenboarding_launch() {
164
+ require_once __DIR__ . '/editor-gutenboarding-launch/index.php';
165
+ }
166
+ add_action( 'plugins_loaded', __NAMESPACE__ . '\load_editor_gutenboarding_launch' );
167
+
168
/**
169
* Add front-end CoBlocks gallery block scripts.
170
*
newspack-blocks/index.php CHANGED
@@ -79,8 +79,24 @@ function newspack_blocks_block_args( $args, $name ) {
79
80
$args['editor_script'] = $block_prefix . 'editor';
81
$args['editor_style'] = $block_prefix . 'editor';
82
- $args['script'] = $block_prefix . 'view';
83
- $args['style'] = $block_prefix . 'view';
84
85
wp_set_script_translations( $block_prefix . 'editor', 'full-site-editing' );
86
79
80
$args['editor_script'] = $block_prefix . 'editor';
81
$args['editor_style'] = $block_prefix . 'editor';
82
+
83
+ // This fires from newspack-blocks at render time.
84
+ add_action(
85
+ 'newspack_blocks_render_post_carousel',
86
+ function() {
87
+ wp_enqueue_style( 'carousel-block-view' );
88
+ wp_enqueue_script( 'carousel-block-view' );
89
+ }
90
+ );
91
+
92
+ // This fires from newspack-blocks at render time.
93
+ add_action(
94
+ 'newspack_blocks_render_homepage_articles',
95
+ function() {
96
+ wp_enqueue_style( 'blog-posts-block-view' );
97
+ wp_enqueue_script( 'blog-posts-block-view' );
98
+ }
99
+ );
100
101
wp_set_script_translations( $block_prefix . 'editor', 'full-site-editing' );
102
posts-list-block/class-posts-list-block.php CHANGED
@@ -52,6 +52,10 @@ class Posts_List_Block {
52
* Enqueue block editor scripts.
53
*/
54
public function enqueue_scripts() {
55
$asset_file = include plugin_dir_path( __FILE__ ) . 'dist/posts-list-block.asset.php';
56
$script_dependencies = $asset_file['dependencies'];
57
wp_enqueue_script(
@@ -69,6 +73,10 @@ class Posts_List_Block {
69
* Enqueue block styles.
70
*/
71
public function enqueue_styles() {
72
$style_file = is_rtl()
73
? 'posts-list-block.rtl.css'
74
: 'posts-list-block.css';
@@ -119,7 +127,7 @@ class Posts_List_Block {
119
add_filter( 'excerpt_more', array( $this, 'custom_excerpt_read_more' ) );
120
121
// Prevent situations when the block attempts rendering another a8c/posts-list block.
122
- if ( $this->rendering_block !== true ) {
123
$this->rendering_block = true;
124
125
$content = render_template(
52
* Enqueue block editor scripts.
53
*/
54
public function enqueue_scripts() {
55
+ if ( ! has_block( 'a8c/posts-list' ) ) {
56
+ return;
57
+ }
58
+
59
$asset_file = include plugin_dir_path( __FILE__ ) . 'dist/posts-list-block.asset.php';
60
$script_dependencies = $asset_file['dependencies'];
61
wp_enqueue_script(
73
* Enqueue block styles.
74
*/
75
public function enqueue_styles() {
76
+ if ( ! has_block( 'a8c/posts-list' ) ) {
77
+ return;
78
+ }
79
+
80
$style_file = is_rtl()
81
? 'posts-list-block.rtl.css'
82
: 'posts-list-block.css';
127
add_filter( 'excerpt_more', array( $this, 'custom_excerpt_read_more' ) );
128
129
// Prevent situations when the block attempts rendering another a8c/posts-list block.
130
+ if ( true !== $this->rendering_block ) {
131
$this->rendering_block = true;
132
133
$content = render_template(
premium-content/blocks/container/edit.js CHANGED
@@ -315,7 +315,7 @@ function Edit( props ) {
315
isLarge
316
href={ upgradeURL }
317
target="_blank"
318
- className="premium-content-block-nudge__button"
319
>
320
{ __( 'Upgrade Your Plan', 'premium-content' ) }
321
</Button>
315
isLarge
316
href={ upgradeURL }
317
target="_blank"
318
+ className="premium-content-block-nudge__button plan-nudge__button"
319
>
320
{ __( 'Upgrade Your Plan', 'premium-content' ) }
321
</Button>
premium-content/blocks/container/stripe-nudge.js CHANGED
@@ -27,7 +27,7 @@ export const StripeNudge = ( { autosaveAndRedirect, stripeConnectUrl } ) => (
27
onClick={ autosaveAndRedirect }
28
target="_top"
29
isDefault
30
- className="premium-content-block-nudge__button"
31
>
32
{ __( 'Connect', 'premium-content' ) }
33
</Button>,
27
onClick={ autosaveAndRedirect }
28
target="_top"
29
isDefault
30
+ className="premium-content-block-nudge__button stripe-nudge__button"
31
>
32
{ __( 'Connect', 'premium-content' ) }
33
</Button>,
premium-content/dist/premium-content.asset.php CHANGED
@@ -1 +1 @@
1
- <?php return array('dependencies' => array('lodash', 'react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-rich-text', 'wp-url'), 'version' => 'd1090f81c29390b6221ab6a762f8ec9c');
1
+ <?php return array('dependencies' => array('lodash', 'react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-polyfill', 'wp-rich-text', 'wp-url'), 'version' => '68147f895516e627a7458c607320a41b');
premium-content/dist/premium-content.js CHANGED
@@ -23,4 +23,4 @@ object-assign
23
* @copyright Copyright (c) 2013 Kevin van Zonneveld (http://kvz.io) and Contributors (http://phpjs.org/authors).
24
* @license See CREDITS.md
25
* @see https://github.com/kvz/phpjs/blob/ffe1356af23a6f2512c84c954dd4e828e92579fa/functions/strings/number_format.js
26
- */function Y(e,t,n,r){e=(e+"").replace(/[^0-9+\-Ee.]/g,"");var o=isFinite(+e)?+e:0,i=isFinite(+t)?Math.abs(t):0,c=void 0===r?",":r,s=void 0===n?".":n,a="";return(a=(i?function(e,t){var n=Math.pow(10,t);return""+(Math.round(e*n)/n).toFixed(t)}(o,i):""+Math.round(o)).split("."))[0].length>3&&(a[0]=a[0].replace(/\B(?=(?:\d{3})+(?!\d))/g,c)),(a[1]||"").length<i&&(a[1]=a[1]||"",a[1]+=new Array(i-a[1].length+1).join("0")),a.join(s)}var J=R()("i18n-calypso"),q=[function(e){return e}],X={};function Q(){oe.throwErrors&&"undefined"!=typeof window&&window.console&&window.console.warn&&window.console.warn.apply(window.console,arguments)}function ee(e){return Array.prototype.slice.call(e)}function te(e){var t=e[0];("string"!=typeof t||e.length>3||e.length>2&&"object"==typeof e[1]&&"object"==typeof e[2])&&Q("Deprecated Invocation: `translate()` accepts ( string, [string], [object] ). These arguments passed:",ee(e),". See https://github.com/Automattic/i18n-calypso#translate-method"),2===e.length&&"string"==typeof t&&"string"==typeof e[1]&&Q("Invalid Invocation: `translate()` requires an options object for plural translations, but passed:",ee(e));for(var n={},r=0;r<e.length;r++)"object"==typeof e[r]&&(n=e[r]);if("string"==typeof t?n.original=t:"object"==typeof n.original&&(n.plural=n.original.plural,n.count=n.original.count,n.original=n.original.single),"string"==typeof e[1]&&(n.plural=e[1]),void 0===n.original)throw new Error("Translate called without a `string` value as first argument.");return n}function ne(e,t){return e.dcnpgettext("messages",t.context,t.original,t.plural,t.count)}function re(e,t){for(var n=q.length-1;n>=0;n--){var r=q[n](Object.assign({},t));if(e.state.locale[r.original])return ne(e.state.tannin,r)}return null}function oe(){if(!(this instanceof oe))return new oe;this.defaultLocaleSlug="en",this.defaultPluralForms=function(e){return 1===e?0:1},this.state={numberFormatSettings:{},tannin:void 0,locale:void 0,localeSlug:void 0,textDirection:void 0,translations:H()({max:100})},this.componentUpdateHooks=[],this.translateHooks=[],this.stateObserver=new W.EventEmitter,this.stateObserver.setMaxListeners(0),this.configure()}oe.throwErrors=!1,oe.prototype.on=function(){var e;(e=this.stateObserver).on.apply(e,arguments)},oe.prototype.off=function(){var e;(e=this.stateObserver).off.apply(e,arguments)},oe.prototype.emit=function(){var e;(e=this.stateObserver).emit.apply(e,arguments)},oe.prototype.numberFormat=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n="number"==typeof t?t:t.decimals||0,r=t.decPoint||this.state.numberFormatSettings.decimal_point||".",o=t.thousandsSep||this.state.numberFormatSettings.thousands_sep||",";return Y(e,n,r,o)},oe.prototype.configure=function(e){Object.assign(this,e||{}),this.setLocale()},oe.prototype.setLocale=function(e){var t,n,r;if(e&&e[""]&&e[""]["key-hash"]){var o=e[""]["key-hash"],i=function(e,t){var n=!1===t?"":String(t);if(void 0!==X[n+e])return X[n+e];var r=V()().update(e).digest("hex");return X[n+e]=t?r.substr(0,t):r},c=function(e){return function(t){return t.context?(t.original=i(t.context+String.fromCharCode(4)+t.original,e),delete t.context):t.original=i(t.original,e),t}};if("sha1"===o.substr(0,4))if(4===o.length)q.push(c(!1));else{var s=o.substr(5).indexOf("-");if(s<0){var a=Number(o.substr(5));q.push(c(a))}else for(var l=Number(o.substr(5,s)),u=Number(o.substr(6+s)),p=l;p<=u;p++)q.push(c(p))}}if(e&&e[""].localeSlug)if(e[""].localeSlug===this.state.localeSlug){if(e===this.state.locale)return;Object.assign(this.state.locale,e)}else this.state.locale=Object.assign({},e);else this.state.locale={"":{localeSlug:this.defaultLocaleSlug,plural_forms:this.defaultPluralForms}};this.state.localeSlug=this.state.locale[""].localeSlug,this.state.textDirection=(null===(t=this.state.locale["text directionltr"])||void 0===t?void 0:t[0])||(null===(n=this.state.locale[""])||void 0===n||null===(r=n.momentjs_locale)||void 0===r?void 0:r.textDirection),this.state.tannin=new U(A()({},"messages",this.state.locale)),this.state.numberFormatSettings.decimal_point=ne(this.state.tannin,te(["number_format_decimals"])),this.state.numberFormatSettings.thousands_sep=ne(this.state.tannin,te(["number_format_thousands_sep"])),"number_format_decimals"===this.state.numberFormatSettings.decimal_point&&(this.state.numberFormatSettings.decimal_point="."),"number_format_thousands_sep"===this.state.numberFormatSettings.thousands_sep&&(this.state.numberFormatSettings.thousands_sep=","),this.stateObserver.emit("change")},oe.prototype.getLocale=function(){return this.state.locale},oe.prototype.getLocaleSlug=function(){return this.state.localeSlug},oe.prototype.isRtl=function(){return"rtl"===this.state.textDirection},oe.prototype.addTranslations=function(e){for(var t in e)""!==t&&(this.state.tannin.data.messages[t]=e[t]);this.stateObserver.emit("change")},oe.prototype.hasTranslation=function(){return!!re(this,te(arguments))},oe.prototype.translate=function(){var e=te(arguments),t=re(this,e);if(t||(t=ne(this.state.tannin,e)),e.args){var n=Array.isArray(e.args)?e.args.slice(0):[e.args];n.unshift(t);try{t=Z.apply(void 0,B()(n))}catch(o){if(!window||!window.console)return;var r=this.throwErrors?"error":"warn";"string"!=typeof o?window.console[r](o):window.console[r]("i18n sprintf error:",n)}}return e.components&&(t=D()({mixedString:t,components:e.components,throwErrors:this.throwErrors})),this.translateHooks.forEach((function(n){t=n(t,e)})),t},oe.prototype.reRenderTranslations=function(){J("Re-rendering all translations due to external request"),this.stateObserver.emit("change")},oe.prototype.registerComponentUpdateHook=function(e){this.componentUpdateHooks.push(e)},oe.prototype.registerTranslateHook=function(e){this.translateHooks.push(e)};var ie=oe,ce=n(30),se=n.n(ce),ae=n(31),le=n.n(ae),ue=n(15),pe=n.n(ue),me=n(32),fe=n.n(me),de=n(33),ge=n.n(de),be=n(8),he=n.n(be),ye=n(34);var ve,Oe,je=new ie,we=je.numberFormat.bind(je),Ce=(je.translate.bind(je),je.configure.bind(je),je.setLocale.bind(je),je.getLocale.bind(je),je.getLocaleSlug.bind(je),je.addTranslations.bind(je),je.reRenderTranslations.bind(je),je.registerComponentUpdateHook.bind(je),je.registerTranslateHook.bind(je),je.state,je.stateObserver,je.on.bind(je),je.off.bind(je),je.emit.bind(je),Oe={numberFormat:(ve=je).numberFormat.bind(ve),translate:ve.translate.bind(ve)},function(e){function t(){var t=e.translate.bind(e);return Object.defineProperty(t,"localeSlug",{get:e.getLocaleSlug.bind(e)}),t}}(je),function(e){var t={getCurrentValue:function(){return e.isRtl()},subscribe:function(t){return e.on("change",t),function(){return e.off("change",t)}}};function n(){return Object(ye.useSubscription)(t)}var r=Object(S.createHigherOrderComponent)((function(e){return Object(be.forwardRef)((function(t,r){var o=n();return he.a.createElement(e,C()({},t,{isRtl:o,ref:r}))}))}),"WithRTL");return{useRtl:n,withRtl:r}}(je));Ce.useRtl,Ce.withRtl;function _e(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=b(t);if(!r||isNaN(e))return null;var o=l()({},r,{},n),i=o.decimal,c=o.grouping,s=o.precision,a=o.symbol,u=e<0?"-":"",p=we(Math.abs(e),{decimals:s,thousandsSep:c,decPoint:i});return n.stripZeros&&(p=ke(p,i)),"".concat(u).concat(a).concat(p)}function ke(e,t){var n=new RegExp("\\".concat(t,"0+quot;));return e.replace(n,"")}function xe(e){var t=e.className,n=e.tab,r=e.label,o=e.selectedTab,i=e.onSelected,c=(n.id===o.id?["is-pressed","is-active"]:[]).concat([t,"components-button","components-tab-button"]);return Object(d.createElement)("button",{type:"button",onClick:function(){return i(n)},className:c.join(" ")},r)}function Se(e){var t=e.className,n=e.tabs,r=e.selectedTab,o=e.onSelected,i=e.selectBlock;return Object(d.createElement)("div",{className:"premium-content-tabs block-editor-block-toolbar"},n.map((function(n){return Object(d.createElement)(xe,C()({key:n.id},e,{tab:n,selectedTab:r,className:"".concat(t,"--tab"),label:n.label,onSelected:o}))})),Object(d.createElement)("button",{onClick:function(){Object(E.select)("core/edit-post").isEditorSidebarOpened()||Object(E.dispatch)("core/edit-post").openGeneralSidebar("edit-post/block"),i()},className:"edit components-button is-button is-secondary"},Object(f.__)("Edit","premium-content")))}var Ee=n(3);function Pe(){return Object(d.createElement)("div",{className:"premium-content-wrapper"},Object(d.createElement)(Ee.InnerBlocks,{allowedBlocks:["premium-content/subscriber-view","premium-content/logged-out-view"],templateLock:"all",template:[["premium-content/subscriber-view"],["premium-content/logged-out-view"]]}))}function Fe(e){var t=e.className,n=e.plan,r=e.selectedPlan,o=e.onSelected,i=e.onClose,c=e.getPlanDescription,s=r&&n.id===r.id,a=(s?["is-selected"]:[]).concat([t]).join(" "),l=s?"yes":void 0,u=null;return n&&(u=" "+c(n)),Object(d.createElement)(x.MenuItem,{onClick:function(e){e.preventDefault(),o(n),i()},className:a,key:n.id,value:n.id,selected:s,icon:l},n.title," : ",u)}function Be(e){var t=e.plans,n=e.selectedPlan,r=e.onSelected;return Object(d.createElement)(x.MenuGroup,null,t.map((function(t){return Object(d.createElement)(Fe,C()({},e,{key:t.id,selectedPlan:n,onSelected:r,plan:t}))})))}function Ne(e){return Object(d.createElement)(x.MenuGroup,null,Object(d.createElement)(x.MenuItem,{onClick:function(t){t.preventDefault(),Object(E.select)("core/edit-post").isEditorSidebarOpened()||Object(E.dispatch)("core/edit-post").openGeneralSidebar("edit-post/block");var n=document.getElementById("new-plan-name");null!==n&&n.focus(),e.onClose()}},Object(f.__)("Add a new subscription","premium-content")))}function Ae(e){var t=e.selectedPlanId,n=e.onSelected,r=e.plans,o=e.getPlanDescription,i=r.find((function(e){return e.id===t})),c=null;return i&&(c=" "+o(i)),Object(d.createElement)(Ee.BlockControls,null,Object(d.createElement)(x.Toolbar,null,Object(d.createElement)(x.DropdownMenu,{icon:Object(d.createElement)(d.Fragment,null,Object(d.createElement)(x.Dashicon,{icon:"update"})," ",c&&Object(d.createElement)(d.Fragment,null,c)),label:Object(f.__)("Select a plan","premium-content"),className:"premium-content-toolbar-button"},(function(t){var r=t.onClose;return Object(d.createElement)(d.Fragment,null,Object(d.createElement)(Be,C()({},e,{onSelected:n,onClose:r,selectedPlan:i})),Object(d.createElement)(Ne,C()({},e,{onClose:r})))}))))}function Le(e){var t=Object(d.useState)(0),n=k()(t,2),r=n[0],o=n[1],i=e.attributes,c=e.setAttributes,s=e.className,a=e.savePlan,l=(e.currencies,e.siteSlug);return Object(d.createElement)(Ee.InspectorControls,null,l&&Object(d.createElement)(x.ExternalLink,{href:"https://wordpress.com/earn/payments/".concat(l),className:"wp-block-premium-content-container---link-to-earn"},Object(f.__)("Manage your subscriptions.","premium-content")),Object(d.createElement)(x.PanelBody,{title:"Add a new subscription",initialOpen:!0,className:"".concat(s,"---settings-add_plan")},1===r&&Object(d.createElement)(x.Placeholder,{icon:"lock",label:Object(f.__)("Premium Content","premium-content"),instructions:Object(f.__)("Saving plan...","premium-content")},Object(d.createElement)(x.Spinner,null)),0===r&&Object(d.createElement)("div",null,Object(d.createElement)(x.PanelRow,{className:"plan-name"},Object(d.createElement)(x.TextControl,{id:"new-plan-name",label:"Name",value:i.newPlanName,onChange:function(e){return c({newPlanName:e})}})),Object(d.createElement)(x.PanelRow,{className:"plan-price"},Object(d.createElement)(x.SelectControl,{label:"Currency",onChange:function(e){return c({newPlanCurrency:e})},value:i.newPlanCurrency,options:We}),Object(d.createElement)(x.TextControl,{label:"Price",value:i.newPlanPrice,onChange:function(e){return c({newPlanPrice:parseFloat(e)})},type:"number"})),Object(d.createElement)(x.PanelRow,{className:"plan-interval"},Object(d.createElement)(x.SelectControl,{label:"Interval",onChange:function(e){return c({newPlanInterval:e})},value:i.newPlanInterval,options:[{label:"Month",value:"1 month"},{label:"Year",value:"1 year"}]})),Object(d.createElement)(x.PanelRow,null,Object(d.createElement)(x.Button,{isSecondary:!0,isLarge:!0,onClick:function(t){t.preventDefault(),o(1),a(e.attributes,(function(e){o(0),e&&(c({newPlanPrice:5}),c({newPlanName:""}))}))}},Object(f.__)("Add subscription","premium-content"))))))}var Re=Object(S.compose)([Object(E.withDispatch)((function(e,t){var n,r=t.stripeConnectUrl;return{autosaveAndRedirect:(n=s()(regeneratorRuntime.mark((function t(n){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n.preventDefault(),t.next=3,e("core/editor").savePost();case 3:window.top.location.href=r;case 4:case"end":return t.stop()}}),t)}))),function(e){return n.apply(this,arguments)})}}))])((function(e){var t=e.autosaveAndRedirect,n=e.stripeConnectUrl;return Object(d.createElement)(Ee.Warning,{actions:n&&[Object(d.createElement)(x.Button,{key:"connect",href:n,onClick:t,target:"_top",isDefault:!0,className:"premium-content-block-nudge__button"},Object(f.__)("Connect","premium-content"))],className:"premium-content-block-nudge"},Object(d.createElement)("span",{className:"premium-content-block-nudge__info"},Object(d.createElement)(x.Dashicon,{icon:"star-filled"}),Object(d.createElement)("span",{className:"premium-content-block-nudge__text-container"},Object(d.createElement)("span",{className:"premium-content-block-nudge__title"},Object(f.__)("Connect to Stripe to use this block on your site","premium-content")),Object(d.createElement)("span",{className:"premium-content-block-nudge__message"},Object(f.__)("This block will be hidden from your visitors until you connect to Stripe.","premium-content")))))})),Te={selectedTab:{id:"",className:"",label:Object(d.createElement)(d.Fragment,null)},stripeNudge:null},De=Object(d.createContext)(Te),Me=[{id:"premium",label:Object(d.createElement)("span",null,Object(f.__)("Subscriber View","premium-content")),className:"wp-premium-content-subscriber-view"},{id:"wall",label:Object(d.createElement)("span",null,Object(f.__)("Non-subscriber View","premium-content")),className:"wp-premium-content-logged-out-view"}],Ie=[];function $e(e,t){var n=e.noticeOperations;n.removeAllNotices(),n.createErrorNotice(t)}var Ue=Object(S.compose)([Object(E.withSelect)((function(e,t){return{postId:(0,e("core/editor").getCurrentPostId)(),containerClientId:e("core/block-editor").getBlockHierarchyRootClientId(t.clientId)}})),x.withNotices,Object(E.withDispatch)((function(e,t){var n=e("core/block-editor");return{selectBlock:function(){n.selectBlock(t.containerClientId)}}}))])((function(e){var t=Object(d.useState)(Me[1]),n=k()(t,2),r=n[0],o=n[1],i=Object(d.useState)(!1),c=k()(i,2),s=c[0],a=c[1],l=Object(d.useState)(Ie),u=k()(l,2),m=u[0],g=u[1],b=Object(d.useState)(null),h=k()(b,2),y=h[0],v=h[1],O=Object(d.useState)(0),j=k()(O,2),w=j[0],_=j[1],S=Object(d.useState)(!1),E=k()(S,2),F=E[0],B=E[1],N=Object(d.useState)(""),A=k()(N,2),L=A[0],R=A[1],T=Object(d.useState)(""),D=k()(T,2),M=D[0],I=D[1];function $(t,n){if(!t.newPlanName||0===t.newPlanName.length)return $e(e,Object(f.__)("Plan requires a name","premium-content")),void n(!1);var r=parseFloat(t.newPlanPrice),o=ze(t.newPlanCurrency),i=Object(f.sprintf)(Object(f.__)("Minimum allowed price is %s.","premium-content"),_e(o,t.newPlanCurrency));if(r<o)return $e(e,i),void n(!1);if(!Ze(t.newPlanCurrency,r))return $e(e,Object(f.__)("Plan requires a valid price","premium-content")),void n(!1);var c={path:"/wpcom/v2/memberships/product",method:"POST",data:{currency:t.newPlanCurrency,price:t.newPlanPrice,title:t.newPlanName,interval:t.newPlanInterval}};p()(c).then((function(t){var r={id:t.id,title:t.title,interval:t.interval,price:t.price,currency:t.currency};g(m.concat([r])),U(r),function(e,t){var n=e.noticeOperations;n.removeAllNotices(),n.createNotice({status:"info",content:t})}(e,Object(f.__)("Successfully created plan","premium-content")),n&&n(!0)}),(function(){$e(e,Object(f.__)("There was an error when adding the plan.")),n&&n(!1)}))}function U(t){e.setAttributes({selectedPlanId:t.id})}var K=Object(d.useRef)(null);!function(e,t){function n(n){e.current&&n.target&&n.target instanceof Node&&!e.current.contains(n.target)?t(!1):t(!0)}Object(d.useEffect)((function(){return document.addEventListener("mousedown",n),function(){document.removeEventListener("mousedown",n)}}))}(K,a);var H=e.isSelected,G=e.className;if(Object(d.useEffect)((function(){var t={path:"/wpcom/v2/memberships/status",method:"GET"};p()(t).then((function(t){if(t||"object"==typeof t){if(t.errors&&Object.values(t.errors)&&Object.values(t.errors)[0][0])return _(2),void $e(e,Object.values(t.errors)[0][0]);v(t.connect_url),B(t.should_upgrade_to_access_memberships),R(t.upgrade_url),I(t.site_slug),t.products&&0===t.products.length&&!t.should_upgrade_to_access_memberships&&t.connected_account_id?$({newPlanCurrency:"USD",newPlanPrice:5,newPlanName:Object(f.__)("Monthly Subscription"),newPlanInterval:"1 month"},(function(){_(t.connected_account_id?1:2)})):(t.products&&t.products.length>0&&(g(t.products),e.attributes.selectedPlanId||U(t.products[0])),_(t.connected_account_id?1:2))}}),(function(t){v(null),_(2),$e(e,t.message)})),e.selectBlock()}),[]),0===w)return Object(d.createElement)("div",{className:G,ref:K},e.noticeUI,Object(d.createElement)(x.Placeholder,{icon:"lock",label:Object(f.__)("Premium Content","premium-content"),instructions:Object(f.__)("Loading data...","premium-content")},Object(d.createElement)(x.Spinner,null)));if(F)return Object(d.createElement)("div",{className:G,ref:K},e.noticeUI,Object(d.createElement)(x.Placeholder,{icon:"lock",label:Object(f.__)("Premium Content","premium-content"),instructions:Object(f.__)("You'll need to upgrade your plan to use the Premium Content block.","premium-content")},Object(d.createElement)(x.Button,{isSecondary:!0,isLarge:!0,href:L,target:"_blank",className:"premium-content-block-nudge__button"},Object(f.__)("Upgrade Your Plan","premium-content")),Object(d.createElement)("div",{className:"membership-button__disclaimer"},Object(d.createElement)(x.ExternalLink,{href:"https://wordpress.com/support/premium-content-block/"},Object(f.__)("Read more about Premium Content and related fees.","premium-content")))));var V=null;if(!F&&1!==w&&y){var W=function(e,t){var n,r=e.postId;if(!Object(P.isURL)(t))return null;if(!r)return t;try{var o=Object(P.getQueryArg)(t,"state");"string"==typeof o&&(n=JSON.parse(atob(o)))}catch(i){return t}return n.from_editor_post_id=r,Object(P.addQueryArgs)(t,{state:btoa(JSON.stringify(n))})}(e,y);V=Object(d.createElement)(Re,C()({},e,{stripeConnectUrl:W}))}return Object(d.createElement)("div",{className:G,ref:K},e.noticeUI,(H||s)&&1===w&&Object(d.createElement)(Ae,C()({},e,{plans:m,selectedPlanId:e.attributes.selectedPlanId,onSelected:U,getPlanDescription:function(e){var t=_e(parseFloat(e.price),e.currency);return"1 month"===e.interval?Object(f.sprintf)(Object(f.__)("%s / month","premium-content"),t):"1 year"===e.interval?Object(f.sprintf)(Object(f.__)("%s / year","premium-content"),t):"one-time"===e.interval?t:Object(f.sprintf)(Object(f.__)("%s / %s","premium-content"),t,e.interval)}})),(H||s)&&1===w&&Object(d.createElement)(Le,C()({},e,{savePlan:$,siteSlug:M})),(H||s)&&Object(d.createElement)(Se,C()({},e,{tabs:Me,selectedTab:r,onSelected:o})),Object(d.createElement)(De.Provider,{value:{selectedTab:r,stripeNudge:V}},Object(d.createElement)(Pe,null)))}));var Ke="premium-content/container",He="common",Ge={name:Ke,attributes:{newPlanName:{type:"string",default:"Monthly Subscription"},newPlanCurrency:{type:"string",default:"USD"},newPlanPrice:{type:"number",default:5},newPlanInterval:{type:"string",default:"1 month"},selectedPlanId:{type:"number",default:0}},title:Object(f.__)("Premium Content","premium-content"),description:Object(f.__)("Restrict access to your content for paying subscribers.","premium-content"),category:He,icon:Object(d.createElement)("svg",{width:"25",height:"24",viewBox:"0 0 25 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},Object(d.createElement)("path",{d:"M12.7439 14.4271L8.64053 13.165L8.51431 13.8718L8.09208 20.7415C8.06165 21.2365 8.61087 21.5526 9.02363 21.2776L12.7439 18.799L16.7475 21.304C17.1687 21.5676 17.7094 21.2343 17.6631 20.7396L17.0212 13.8718L17.0212 13.165L12.7439 14.4271Z",fill:"black"}),Object(d.createElement)("circle",{cx:"12.7439",cy:"8.69796",r:"5.94466",stroke:"black",strokeWidth:"1.5",fill:"none"}),Object(d.createElement)("path",{d:"M9.71023 8.12461L11.9543 10.3687L15.7776 6.54533",stroke:"black",strokeWidth:"1.5",fill:"none"})),supports:{html:!1},keywords:["premium-content",Object(f.__)("premium","premium-content"),Object(f.__)("paywall","premium-content")],edit:Ue,save:function(){return Object(d.createElement)("div",{className:"wp-block-premium-content-container"},Object(d.createElement)(Ee.InnerBlocks.Content,null))}},Ve={USD:.5,AUD:.5,BRL:.5,CAD:.5,CHF:.5,DKK:2.5,EUR:.5,GBP:.3,HKD:4,INR:.5,JPY:50,MXN:10,NOK:3,NZD:.5,PLN:2,SEK:3,SGD:.5},We=Object.keys(Ve).map((function(e){var t=b(e).symbol;return{value:e,label:t===e?e:"".concat(e," ").concat(Object(j.trimEnd)(t,"."))}}));function ze(e){return Ve[e]}function Ze(e,t){return!isNaN(t)&&t>=ze(e)}var Ye=Object(S.compose)([Object(E.withSelect)((function(e,t){return{hasInnerBlocks:!!e("core/block-editor").getBlocksByClientId(t.clientId)[0].innerBlocks.length,containerClientId:e("core/block-editor").getBlockHierarchyRootClientId(t.clientId)}})),Object(E.withDispatch)((function(e,t){var n=e("core/block-editor");return{selectBlock:function(){n.selectBlock(t.containerClientId)}}}))])((function(e){return Object(d.useEffect)((function(){e.selectBlock()}),[]),Object(d.createElement)(De.Consumer,null,(function(t){var n=t.selectedTab,r=t.stripeNudge;return Object(d.createElement)("div",{hidden:"wall"===n.id,className:n.className},r,Object(d.createElement)(Ee.InnerBlocks,{renderAppender:!e.hasInnerBlocks&&Ee.InnerBlocks.ButtonBlockAppender,templateLock:!1,template:[["core/paragraph",{placeholder:Object(f.__)("Insert the piece of content you want your visitors to see after they subscribe.","premium-content")}]]}))}))}));var Je="premium-content/subscriber-view",qe="common",Xe={name:Je,category:qe,attributes:{},title:Object(f.__)("Subscriber View","premium-content"),description:Object(f.__)("Subscriber View.","premium-content"),parent:["premium-content/container"],supports:{inserter:!1,html:!1},edit:Ye,save:function(){return Object(d.createElement)("div",{className:"wp-block-premium-content-subscriber-view"},Object(d.createElement)(Ee.InnerBlocks.Content,null))}},Qe=n(35),et=n.n(Qe),tt=window.getComputedStyle,nt=Object(x.withFallbackStyles)((function(e,t){var n,r,o,i,c=t.textButtonColor,s=t.backgroundButtonColor,a=s&&s.color,l=c&&c.color;return!l&&e&&(n=e.querySelector('[contenteditable="true"]')),r=e.querySelector(".wp-block-button__link")?e.querySelector(".wp-block-button__link"):e,e&&r&&(o=tt(r).backgroundColor),n&&(i=tt(n).color),{fallbackBackgroundColor:a||o,fallbackTextColor:l||i}}));var rt=Object(S.compose)([Object(Ee.withColors)({backgroundButtonColor:"background-color"},{textButtonColor:"color"}),nt])((function(e){function t(){var t,n=e.textButtonColor,r=e.backgroundButtonColor,o=Object(j.get)(n,"class"),i=Object(j.get)(r,"class");return et()("wp-block-button__link",(t={"has-text-color":n.color},A()(t,o,o),A()(t,"has-background",r.color),A()(t,i,i),t))}Object(d.useEffect)((function(){!function(){var n=t();e.setAttributes({buttonClasses:n})}(),function(){var t=Object(j.get)(e.textButtonColor,"color"),n=Object(j.get)(e.backgroundButtonColor,"color");void 0!==t&&e.setAttributes({customTextButtonColor:t});void 0!==n&&e.setAttributes({customBackgroundButtonColor:n})}()}),[e.backgroundButtonColor,e.textButtonColor]);var n=e.attributes,r=e.setAttributes,o=e.backgroundButtonColor,i=e.textButtonColor,c=e.setBackgroundButtonColor,s=e.setTextButtonColor,a=e.fallbackBackgroundColor,l=e.fallbackTextColor,u=o.color||a,p=i.color||l,m={border:"none",backgroundColor:u,color:p},g=t();return Object(d.createElement)("div",null,Object(d.createElement)("div",{className:"wp-block-button premium-content-logged-out-view-button"},Object(d.createElement)(Ee.RichText,{placeholder:Object(f.__)("Add text…","premium-content"),value:n.subscribeButtonText,onChange:function(e){return r({subscribeButtonText:e})},className:g,style:m,keepPlaceholderOnFocus:!0}),Object(d.createElement)(Ee.RichText,{placeholder:Object(f.__)("Add text…","premium-content"),value:n.loginButtonText,onChange:function(e){return r({loginButtonText:e})},className:g,style:m,keepPlaceholderOnFocus:!0})),Object(d.createElement)(Ee.InspectorControls,null,Object(d.createElement)(Ee.PanelColorSettings,{title:Object(f.__)("Button Color Settings","premium-content"),colorSettings:[{value:o||void 0,onChange:c,label:Object(f.__)("Background Color","premium-content")},{value:i||void 0,onChange:s,label:Object(f.__)("Text Color","premium-content")}]}),Object(d.createElement)(Ee.ContrastChecker,{textColor:p,backgroundColor:u,fallbackBackgroundColor:a,fallbackTextColor:l})))}));var ot=Object(S.compose)([Object(E.withSelect)((function(e,t){return{containerClientId:e("core/block-editor").getBlockHierarchyRootClientId(t.clientId)}})),Object(E.withDispatch)((function(e,t){var n=e("core/block-editor");return{selectBlock:function(){n.selectBlock(t.containerClientId)}}}))])((function(e){Object(d.useEffect)((function(){e.selectBlock()}),[]);var t=Object(d.createElement)(rt,{attributes:Object(j.pick)(e.attributes,["subscribeButtonText","loginButtonText","backgroundButtonColor","textButtonColor","customBackgroundButtonColor","customTextButtonColor"]),setAttributes:e.setAttributes});return Object(d.createElement)(De.Consumer,null,(function(e){var n=e.selectedTab,r=e.stripeNudge;return Object(d.createElement)("div",{hidden:"premium"===n.id,className:n.className},r,Object(d.createElement)(Ee.InnerBlocks,{templateLock:!1,template:[["core/heading",{content:Object(f.__)("Subscribe to get access","premium-content"),level:3}],["core/paragraph",{content:Object(f.__)("Read more of this content when you subscribe today.","premium-content")}]]}),t)}))}));var it=n(20),ct="premium-content/logged-out-view",st="common",at={name:ct,category:st,attributes:{subscribeButtonText:{type:"string",default:"Subscribe"},loginButtonText:{type:"string",default:"Log In"},buttonClasses:{type:"string",default:""},backgroundButtonColor:{type:"string",default:""},textButtonColor:{type:"string",default:""},customBackgroundButtonColor:{type:"string",default:""},customTextButtonColor:{type:"string",default:""}},title:Object(f.__)("Logged Out View","premium-content"),description:Object(f.__)("Logged Out View.","premium-content"),parent:["premium-content/container"],supports:{inserter:!1,html:!1},edit:ot,save:function(){return Object(d.createElement)("div",{className:"wp-block-premium-content-logged-out-view"},Object(d.createElement)(Ee.InnerBlocks.Content,null))}},lt=Object(E.subscribe)((function(){var e=Object(E.select)("core/rich-text").getFormatType("core/link");if(e){lt(),Object(it.unregisterFormatType)("core/link");var t=Object(S.compose)(Object(E.withSelect)((function(e){return{selectedBlock:e("core/block-editor").getSelectedBlock()}})),Object(S.ifCondition)((function(e){return e.selectedBlock&&e.selectedBlock.name!==ct})))(e.edit);Object(it.registerFormatType)("core/link",l()({},e,{edit:t}))}})),ut=function(e){if(e){var t=e.name,n=e.category,r=e.settings;Object(m.registerBlockType)(t,l()({category:n},r))}},pt=function(){var e=s()(regeneratorRuntime.mark((function e(){var t,n,r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,p()({path:"/wpcom/v2/memberships/status"});case 3:t=e.sent,e.next=9;break;case 6:return e.prev=6,e.t0=e.catch(0),e.abrupt("return");case 9:if(!t.should_upgrade_to_access_memberships){e.next=17;break}if(n=Object(m.getBlockType)(Ke)){e.next=14;break}return e.abrupt("return");case 14:r=Object(f._x)("paid","Short label appearing near a block requiring a paid plan","premium-content"),Object(m.unregisterBlockType)(Ke),Object(m.registerBlockType)(Ke,l()({},n,{title:"".concat(n.title," (").concat(r,")")}));case 17:case"end":return e.stop()}}),e,null,[[0,6]])})));return function(){return e.apply(this,arguments)}}(),mt=function(){[r,i,o].forEach(ut),pt()};mt()}]));
23
* @copyright Copyright (c) 2013 Kevin van Zonneveld (http://kvz.io) and Contributors (http://phpjs.org/authors).
24
* @license See CREDITS.md
25
* @see https://github.com/kvz/phpjs/blob/ffe1356af23a6f2512c84c954dd4e828e92579fa/functions/strings/number_format.js
26
+ */function Y(e,t,n,r){e=(e+"").replace(/[^0-9+\-Ee.]/g,"");var o=isFinite(+e)?+e:0,i=isFinite(+t)?Math.abs(t):0,c=void 0===r?",":r,s=void 0===n?".":n,a="";return(a=(i?function(e,t){var n=Math.pow(10,t);return""+(Math.round(e*n)/n).toFixed(t)}(o,i):""+Math.round(o)).split("."))[0].length>3&&(a[0]=a[0].replace(/\B(?=(?:\d{3})+(?!\d))/g,c)),(a[1]||"").length<i&&(a[1]=a[1]||"",a[1]+=new Array(i-a[1].length+1).join("0")),a.join(s)}var J=R()("i18n-calypso"),q=[function(e){return e}],X={};function Q(){oe.throwErrors&&"undefined"!=typeof window&&window.console&&window.console.warn&&window.console.warn.apply(window.console,arguments)}function ee(e){return Array.prototype.slice.call(e)}function te(e){var t=e[0];("string"!=typeof t||e.length>3||e.length>2&&"object"==typeof e[1]&&"object"==typeof e[2])&&Q("Deprecated Invocation: `translate()` accepts ( string, [string], [object] ). These arguments passed:",ee(e),". See https://github.com/Automattic/i18n-calypso#translate-method"),2===e.length&&"string"==typeof t&&"string"==typeof e[1]&&Q("Invalid Invocation: `translate()` requires an options object for plural translations, but passed:",ee(e));for(var n={},r=0;r<e.length;r++)"object"==typeof e[r]&&(n=e[r]);if("string"==typeof t?n.original=t:"object"==typeof n.original&&(n.plural=n.original.plural,n.count=n.original.count,n.original=n.original.single),"string"==typeof e[1]&&(n.plural=e[1]),void 0===n.original)throw new Error("Translate called without a `string` value as first argument.");return n}function ne(e,t){return e.dcnpgettext("messages",t.context,t.original,t.plural,t.count)}function re(e,t){for(var n=q.length-1;n>=0;n--){var r=q[n](Object.assign({},t));if(e.state.locale[r.original])return ne(e.state.tannin,r)}return null}function oe(){if(!(this instanceof oe))return new oe;this.defaultLocaleSlug="en",this.defaultPluralForms=function(e){return 1===e?0:1},this.state={numberFormatSettings:{},tannin:void 0,locale:void 0,localeSlug:void 0,textDirection:void 0,translations:H()({max:100})},this.componentUpdateHooks=[],this.translateHooks=[],this.stateObserver=new W.EventEmitter,this.stateObserver.setMaxListeners(0),this.configure()}oe.throwErrors=!1,oe.prototype.on=function(){var e;(e=this.stateObserver).on.apply(e,arguments)},oe.prototype.off=function(){var e;(e=this.stateObserver).off.apply(e,arguments)},oe.prototype.emit=function(){var e;(e=this.stateObserver).emit.apply(e,arguments)},oe.prototype.numberFormat=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n="number"==typeof t?t:t.decimals||0,r=t.decPoint||this.state.numberFormatSettings.decimal_point||".",o=t.thousandsSep||this.state.numberFormatSettings.thousands_sep||",";return Y(e,n,r,o)},oe.prototype.configure=function(e){Object.assign(this,e||{}),this.setLocale()},oe.prototype.setLocale=function(e){var t,n,r;if(e&&e[""]&&e[""]["key-hash"]){var o=e[""]["key-hash"],i=function(e,t){var n=!1===t?"":String(t);if(void 0!==X[n+e])return X[n+e];var r=V()().update(e).digest("hex");return X[n+e]=t?r.substr(0,t):r},c=function(e){return function(t){return t.context?(t.original=i(t.context+String.fromCharCode(4)+t.original,e),delete t.context):t.original=i(t.original,e),t}};if("sha1"===o.substr(0,4))if(4===o.length)q.push(c(!1));else{var s=o.substr(5).indexOf("-");if(s<0){var a=Number(o.substr(5));q.push(c(a))}else for(var l=Number(o.substr(5,s)),u=Number(o.substr(6+s)),p=l;p<=u;p++)q.push(c(p))}}if(e&&e[""].localeSlug)if(e[""].localeSlug===this.state.localeSlug){if(e===this.state.locale)return;Object.assign(this.state.locale,e)}else this.state.locale=Object.assign({},e);else this.state.locale={"":{localeSlug:this.defaultLocaleSlug,plural_forms:this.defaultPluralForms}};this.state.localeSlug=this.state.locale[""].localeSlug,this.state.textDirection=(null===(t=this.state.locale["text directionltr"])||void 0===t?void 0:t[0])||(null===(n=this.state.locale[""])||void 0===n||null===(r=n.momentjs_locale)||void 0===r?void 0:r.textDirection),this.state.tannin=new U(A()({},"messages",this.state.locale)),this.state.numberFormatSettings.decimal_point=ne(this.state.tannin,te(["number_format_decimals"])),this.state.numberFormatSettings.thousands_sep=ne(this.state.tannin,te(["number_format_thousands_sep"])),"number_format_decimals"===this.state.numberFormatSettings.decimal_point&&(this.state.numberFormatSettings.decimal_point="."),"number_format_thousands_sep"===this.state.numberFormatSettings.thousands_sep&&(this.state.numberFormatSettings.thousands_sep=","),this.stateObserver.emit("change")},oe.prototype.getLocale=function(){return this.state.locale},oe.prototype.getLocaleSlug=function(){return this.state.localeSlug},oe.prototype.isRtl=function(){return"rtl"===this.state.textDirection},oe.prototype.addTranslations=function(e){for(var t in e)""!==t&&(this.state.tannin.data.messages[t]=e[t]);this.stateObserver.emit("change")},oe.prototype.hasTranslation=function(){return!!re(this,te(arguments))},oe.prototype.translate=function(){var e=te(arguments),t=re(this,e);if(t||(t=ne(this.state.tannin,e)),e.args){var n=Array.isArray(e.args)?e.args.slice(0):[e.args];n.unshift(t);try{t=Z.apply(void 0,B()(n))}catch(o){if(!window||!window.console)return;var r=this.throwErrors?"error":"warn";"string"!=typeof o?window.console[r](o):window.console[r]("i18n sprintf error:",n)}}return e.components&&(t=D()({mixedString:t,components:e.components,throwErrors:this.throwErrors})),this.translateHooks.forEach((function(n){t=n(t,e)})),t},oe.prototype.reRenderTranslations=function(){J("Re-rendering all translations due to external request"),this.stateObserver.emit("change")},oe.prototype.registerComponentUpdateHook=function(e){this.componentUpdateHooks.push(e)},oe.prototype.registerTranslateHook=function(e){this.translateHooks.push(e)};var ie=oe,ce=n(30),se=n.n(ce),ae=n(31),le=n.n(ae),ue=n(15),pe=n.n(ue),me=n(32),fe=n.n(me),de=n(33),ge=n.n(de),be=n(8),he=n.n(be),ye=n(34);var ve,Oe,je=new ie,we=je.numberFormat.bind(je),Ce=(je.translate.bind(je),je.configure.bind(je),je.setLocale.bind(je),je.getLocale.bind(je),je.getLocaleSlug.bind(je),je.addTranslations.bind(je),je.reRenderTranslations.bind(je),je.registerComponentUpdateHook.bind(je),je.registerTranslateHook.bind(je),je.state,je.stateObserver,je.on.bind(je),je.off.bind(je),je.emit.bind(je),Oe={numberFormat:(ve=je).numberFormat.bind(ve),translate:ve.translate.bind(ve)},function(e){function t(){var t=e.translate.bind(e);return Object.defineProperty(t,"localeSlug",{get:e.getLocaleSlug.bind(e)}),t}}(je),function(e){var t={getCurrentValue:function(){return e.isRtl()},subscribe:function(t){return e.on("change",t),function(){return e.off("change",t)}}};function n(){return Object(ye.useSubscription)(t)}var r=Object(S.createHigherOrderComponent)((function(e){return Object(be.forwardRef)((function(t,r){var o=n();return he.a.createElement(e,C()({},t,{isRtl:o,ref:r}))}))}),"WithRTL");return{useRtl:n,withRtl:r}}(je));Ce.useRtl,Ce.withRtl;function _e(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},r=b(t);if(!r||isNaN(e))return null;var o=l()({},r,{},n),i=o.decimal,c=o.grouping,s=o.precision,a=o.symbol,u=e<0?"-":"",p=we(Math.abs(e),{decimals:s,thousandsSep:c,decPoint:i});return n.stripZeros&&(p=ke(p,i)),"".concat(u).concat(a).concat(p)}function ke(e,t){var n=new RegExp("\\".concat(t,"0+quot;));return e.replace(n,"")}function xe(e){var t=e.className,n=e.tab,r=e.label,o=e.selectedTab,i=e.onSelected,c=(n.id===o.id?["is-pressed","is-active"]:[]).concat([t,"components-button","components-tab-button"]);return Object(d.createElement)("button",{type:"button",onClick:function(){return i(n)},className:c.join(" ")},r)}function Se(e){var t=e.className,n=e.tabs,r=e.selectedTab,o=e.onSelected,i=e.selectBlock;return Object(d.createElement)("div",{className:"premium-content-tabs block-editor-block-toolbar"},n.map((function(n){return Object(d.createElement)(xe,C()({key:n.id},e,{tab:n,selectedTab:r,className:"".concat(t,"--tab"),label:n.label,onSelected:o}))})),Object(d.createElement)("button",{onClick:function(){Object(E.select)("core/edit-post").isEditorSidebarOpened()||Object(E.dispatch)("core/edit-post").openGeneralSidebar("edit-post/block"),i()},className:"edit components-button is-button is-secondary"},Object(f.__)("Edit","premium-content")))}var Ee=n(3);function Pe(){return Object(d.createElement)("div",{className:"premium-content-wrapper"},Object(d.createElement)(Ee.InnerBlocks,{allowedBlocks:["premium-content/subscriber-view","premium-content/logged-out-view"],templateLock:"all",template:[["premium-content/subscriber-view"],["premium-content/logged-out-view"]]}))}function Fe(e){var t=e.className,n=e.plan,r=e.selectedPlan,o=e.onSelected,i=e.onClose,c=e.getPlanDescription,s=r&&n.id===r.id,a=(s?["is-selected"]:[]).concat([t]).join(" "),l=s?"yes":void 0,u=null;return n&&(u=" "+c(n)),Object(d.createElement)(x.MenuItem,{onClick:function(e){e.preventDefault(),o(n),i()},className:a,key:n.id,value:n.id,selected:s,icon:l},n.title," : ",u)}function Be(e){var t=e.plans,n=e.selectedPlan,r=e.onSelected;return Object(d.createElement)(x.MenuGroup,null,t.map((function(t){return Object(d.createElement)(Fe,C()({},e,{key:t.id,selectedPlan:n,onSelected:r,plan:t}))})))}function Ne(e){return Object(d.createElement)(x.MenuGroup,null,Object(d.createElement)(x.MenuItem,{onClick:function(t){t.preventDefault(),Object(E.select)("core/edit-post").isEditorSidebarOpened()||Object(E.dispatch)("core/edit-post").openGeneralSidebar("edit-post/block");var n=document.getElementById("new-plan-name");null!==n&&n.focus(),e.onClose()}},Object(f.__)("Add a new subscription","premium-content")))}function Ae(e){var t=e.selectedPlanId,n=e.onSelected,r=e.plans,o=e.getPlanDescription,i=r.find((function(e){return e.id===t})),c=null;return i&&(c=" "+o(i)),Object(d.createElement)(Ee.BlockControls,null,Object(d.createElement)(x.Toolbar,null,Object(d.createElement)(x.DropdownMenu,{icon:Object(d.createElement)(d.Fragment,null,Object(d.createElement)(x.Dashicon,{icon:"update"})," ",c&&Object(d.createElement)(d.Fragment,null,c)),label:Object(f.__)("Select a plan","premium-content"),className:"premium-content-toolbar-button"},(function(t){var r=t.onClose;return Object(d.createElement)(d.Fragment,null,Object(d.createElement)(Be,C()({},e,{onSelected:n,onClose:r,selectedPlan:i})),Object(d.createElement)(Ne,C()({},e,{onClose:r})))}))))}function Le(e){var t=Object(d.useState)(0),n=k()(t,2),r=n[0],o=n[1],i=e.attributes,c=e.setAttributes,s=e.className,a=e.savePlan,l=(e.currencies,e.siteSlug);return Object(d.createElement)(Ee.InspectorControls,null,l&&Object(d.createElement)(x.ExternalLink,{href:"https://wordpress.com/earn/payments/".concat(l),className:"wp-block-premium-content-container---link-to-earn"},Object(f.__)("Manage your subscriptions.","premium-content")),Object(d.createElement)(x.PanelBody,{title:"Add a new subscription",initialOpen:!0,className:"".concat(s,"---settings-add_plan")},1===r&&Object(d.createElement)(x.Placeholder,{icon:"lock",label:Object(f.__)("Premium Content","premium-content"),instructions:Object(f.__)("Saving plan...","premium-content")},Object(d.createElement)(x.Spinner,null)),0===r&&Object(d.createElement)("div",null,Object(d.createElement)(x.PanelRow,{className:"plan-name"},Object(d.createElement)(x.TextControl,{id:"new-plan-name",label:"Name",value:i.newPlanName,onChange:function(e){return c({newPlanName:e})}})),Object(d.createElement)(x.PanelRow,{className:"plan-price"},Object(d.createElement)(x.SelectControl,{label:"Currency",onChange:function(e){return c({newPlanCurrency:e})},value:i.newPlanCurrency,options:We}),Object(d.createElement)(x.TextControl,{label:"Price",value:i.newPlanPrice,onChange:function(e){return c({newPlanPrice:parseFloat(e)})},type:"number"})),Object(d.createElement)(x.PanelRow,{className:"plan-interval"},Object(d.createElement)(x.SelectControl,{label:"Interval",onChange:function(e){return c({newPlanInterval:e})},value:i.newPlanInterval,options:[{label:"Month",value:"1 month"},{label:"Year",value:"1 year"}]})),Object(d.createElement)(x.PanelRow,null,Object(d.createElement)(x.Button,{isSecondary:!0,isLarge:!0,onClick:function(t){t.preventDefault(),o(1),a(e.attributes,(function(e){o(0),e&&(c({newPlanPrice:5}),c({newPlanName:""}))}))}},Object(f.__)("Add subscription","premium-content"))))))}var Re=Object(S.compose)([Object(E.withDispatch)((function(e,t){var n,r=t.stripeConnectUrl;return{autosaveAndRedirect:(n=s()(regeneratorRuntime.mark((function t(n){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return n.preventDefault(),t.next=3,e("core/editor").savePost();case 3:window.top.location.href=r;case 4:case"end":return t.stop()}}),t)}))),function(e){return n.apply(this,arguments)})}}))])((function(e){var t=e.autosaveAndRedirect,n=e.stripeConnectUrl;return Object(d.createElement)(Ee.Warning,{actions:n&&[Object(d.createElement)(x.Button,{key:"connect",href:n,onClick:t,target:"_top",isDefault:!0,className:"premium-content-block-nudge__button stripe-nudge__button"},Object(f.__)("Connect","premium-content"))],className:"premium-content-block-nudge"},Object(d.createElement)("span",{className:"premium-content-block-nudge__info"},Object(d.createElement)(x.Dashicon,{icon:"star-filled"}),Object(d.createElement)("span",{className:"premium-content-block-nudge__text-container"},Object(d.createElement)("span",{className:"premium-content-block-nudge__title"},Object(f.__)("Connect to Stripe to use this block on your site","premium-content")),Object(d.createElement)("span",{className:"premium-content-block-nudge__message"},Object(f.__)("This block will be hidden from your visitors until you connect to Stripe.","premium-content")))))})),Te={selectedTab:{id:"",className:"",label:Object(d.createElement)(d.Fragment,null)},stripeNudge:null},De=Object(d.createContext)(Te),Me=[{id:"premium",label:Object(d.createElement)("span",null,Object(f.__)("Subscriber View","premium-content")),className:"wp-premium-content-subscriber-view"},{id:"wall",label:Object(d.createElement)("span",null,Object(f.__)("Non-subscriber View","premium-content")),className:"wp-premium-content-logged-out-view"}],Ie=[];function $e(e,t){var n=e.noticeOperations;n.removeAllNotices(),n.createErrorNotice(t)}var Ue=Object(S.compose)([Object(E.withSelect)((function(e,t){return{postId:(0,e("core/editor").getCurrentPostId)(),containerClientId:e("core/block-editor").getBlockHierarchyRootClientId(t.clientId)}})),x.withNotices,Object(E.withDispatch)((function(e,t){var n=e("core/block-editor");return{selectBlock:function(){n.selectBlock(t.containerClientId)}}}))])((function(e){var t=Object(d.useState)(Me[1]),n=k()(t,2),r=n[0],o=n[1],i=Object(d.useState)(!1),c=k()(i,2),s=c[0],a=c[1],l=Object(d.useState)(Ie),u=k()(l,2),m=u[0],g=u[1],b=Object(d.useState)(null),h=k()(b,2),y=h[0],v=h[1],O=Object(d.useState)(0),j=k()(O,2),w=j[0],_=j[1],S=Object(d.useState)(!1),E=k()(S,2),F=E[0],B=E[1],N=Object(d.useState)(""),A=k()(N,2),L=A[0],R=A[1],T=Object(d.useState)(""),D=k()(T,2),M=D[0],I=D[1];function $(t,n){if(!t.newPlanName||0===t.newPlanName.length)return $e(e,Object(f.__)("Plan requires a name","premium-content")),void n(!1);var r=parseFloat(t.newPlanPrice),o=ze(t.newPlanCurrency),i=Object(f.sprintf)(Object(f.__)("Minimum allowed price is %s.","premium-content"),_e(o,t.newPlanCurrency));if(r<o)return $e(e,i),void n(!1);if(!Ze(t.newPlanCurrency,r))return $e(e,Object(f.__)("Plan requires a valid price","premium-content")),void n(!1);var c={path:"/wpcom/v2/memberships/product",method:"POST",data:{currency:t.newPlanCurrency,price:t.newPlanPrice,title:t.newPlanName,interval:t.newPlanInterval}};p()(c).then((function(t){var r={id:t.id,title:t.title,interval:t.interval,price:t.price,currency:t.currency};g(m.concat([r])),U(r),function(e,t){var n=e.noticeOperations;n.removeAllNotices(),n.createNotice({status:"info",content:t})}(e,Object(f.__)("Successfully created plan","premium-content")),n&&n(!0)}),(function(){$e(e,Object(f.__)("There was an error when adding the plan.")),n&&n(!1)}))}function U(t){e.setAttributes({selectedPlanId:t.id})}var K=Object(d.useRef)(null);!function(e,t){function n(n){e.current&&n.target&&n.target instanceof Node&&!e.current.contains(n.target)?t(!1):t(!0)}Object(d.useEffect)((function(){return document.addEventListener("mousedown",n),function(){document.removeEventListener("mousedown",n)}}))}(K,a);var H=e.isSelected,G=e.className;if(Object(d.useEffect)((function(){var t={path:"/wpcom/v2/memberships/status",method:"GET"};p()(t).then((function(t){if(t||"object"==typeof t){if(t.errors&&Object.values(t.errors)&&Object.values(t.errors)[0][0])return _(2),void $e(e,Object.values(t.errors)[0][0]);v(t.connect_url),B(t.should_upgrade_to_access_memberships),R(t.upgrade_url),I(t.site_slug),t.products&&0===t.products.length&&!t.should_upgrade_to_access_memberships&&t.connected_account_id?$({newPlanCurrency:"USD",newPlanPrice:5,newPlanName:Object(f.__)("Monthly Subscription"),newPlanInterval:"1 month"},(function(){_(t.connected_account_id?1:2)})):(t.products&&t.products.length>0&&(g(t.products),e.attributes.selectedPlanId||U(t.products[0])),_(t.connected_account_id?1:2))}}),(function(t){v(null),_(2),$e(e,t.message)})),e.selectBlock()}),[]),0===w)return Object(d.createElement)("div",{className:G,ref:K},e.noticeUI,Object(d.createElement)(x.Placeholder,{icon:"lock",label:Object(f.__)("Premium Content","premium-content"),instructions:Object(f.__)("Loading data...","premium-content")},Object(d.createElement)(x.Spinner,null)));if(F)return Object(d.createElement)("div",{className:G,ref:K},e.noticeUI,Object(d.createElement)(x.Placeholder,{icon:"lock",label:Object(f.__)("Premium Content","premium-content"),instructions:Object(f.__)("You'll need to upgrade your plan to use the Premium Content block.","premium-content")},Object(d.createElement)(x.Button,{isSecondary:!0,isLarge:!0,href:L,target:"_blank",className:"premium-content-block-nudge__button plan-nudge__button"},Object(f.__)("Upgrade Your Plan","premium-content")),Object(d.createElement)("div",{className:"membership-button__disclaimer"},Object(d.createElement)(x.ExternalLink,{href:"https://wordpress.com/support/premium-content-block/"},Object(f.__)("Read more about Premium Content and related fees.","premium-content")))));var V=null;if(!F&&1!==w&&y){var W=function(e,t){var n,r=e.postId;if(!Object(P.isURL)(t))return null;if(!r)return t;try{var o=Object(P.getQueryArg)(t,"state");"string"==typeof o&&(n=JSON.parse(atob(o)))}catch(i){return t}return n.from_editor_post_id=r,Object(P.addQueryArgs)(t,{state:btoa(JSON.stringify(n))})}(e,y);V=Object(d.createElement)(Re,C()({},e,{stripeConnectUrl:W}))}return Object(d.createElement)("div",{className:G,ref:K},e.noticeUI,(H||s)&&1===w&&Object(d.createElement)(Ae,C()({},e,{plans:m,selectedPlanId:e.attributes.selectedPlanId,onSelected:U,getPlanDescription:function(e){var t=_e(parseFloat(e.price),e.currency);return"1 month"===e.interval?Object(f.sprintf)(Object(f.__)("%s / month","premium-content"),t):"1 year"===e.interval?Object(f.sprintf)(Object(f.__)("%s / year","premium-content"),t):"one-time"===e.interval?t:Object(f.sprintf)(Object(f.__)("%s / %s","premium-content"),t,e.interval)}})),(H||s)&&1===w&&Object(d.createElement)(Le,C()({},e,{savePlan:$,siteSlug:M})),(H||s)&&Object(d.createElement)(Se,C()({},e,{tabs:Me,selectedTab:r,onSelected:o})),Object(d.createElement)(De.Provider,{value:{selectedTab:r,stripeNudge:V}},Object(d.createElement)(Pe,null)))}));var Ke="premium-content/container",He="common",Ge={name:Ke,attributes:{newPlanName:{type:"string",default:"Monthly Subscription"},newPlanCurrency:{type:"string",default:"USD"},newPlanPrice:{type:"number",default:5},newPlanInterval:{type:"string",default:"1 month"},selectedPlanId:{type:"number",default:0}},title:Object(f.__)("Premium Content","premium-content"),description:Object(f.__)("Restrict access to your content for paying subscribers.","premium-content"),category:He,icon:Object(d.createElement)("svg",{width:"25",height:"24",viewBox:"0 0 25 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},Object(d.createElement)("path",{d:"M12.7439 14.4271L8.64053 13.165L8.51431 13.8718L8.09208 20.7415C8.06165 21.2365 8.61087 21.5526 9.02363 21.2776L12.7439 18.799L16.7475 21.304C17.1687 21.5676 17.7094 21.2343 17.6631 20.7396L17.0212 13.8718L17.0212 13.165L12.7439 14.4271Z",fill:"black"}),Object(d.createElement)("circle",{cx:"12.7439",cy:"8.69796",r:"5.94466",stroke:"black",strokeWidth:"1.5",fill:"none"}),Object(d.createElement)("path",{d:"M9.71023 8.12461L11.9543 10.3687L15.7776 6.54533",stroke:"black",strokeWidth:"1.5",fill:"none"})),supports:{html:!1},keywords:["premium-content",Object(f.__)("premium","premium-content"),Object(f.__)("paywall","premium-content")],edit:Ue,save:function(){return Object(d.createElement)("div",{className:"wp-block-premium-content-container"},Object(d.createElement)(Ee.InnerBlocks.Content,null))}},Ve={USD:.5,AUD:.5,BRL:.5,CAD:.5,CHF:.5,DKK:2.5,EUR:.5,GBP:.3,HKD:4,INR:.5,JPY:50,MXN:10,NOK:3,NZD:.5,PLN:2,SEK:3,SGD:.5},We=Object.keys(Ve).map((function(e){var t=b(e).symbol;return{value:e,label:t===e?e:"".concat(e," ").concat(Object(j.trimEnd)(t,"."))}}));function ze(e){return Ve[e]}function Ze(e,t){return!isNaN(t)&&t>=ze(e)}var Ye=Object(S.compose)([Object(E.withSelect)((function(e,t){return{hasInnerBlocks:!!e("core/block-editor").getBlocksByClientId(t.clientId)[0].innerBlocks.length,containerClientId:e("core/block-editor").getBlockHierarchyRootClientId(t.clientId)}})),Object(E.withDispatch)((function(e,t){var n=e("core/block-editor");return{selectBlock:function(){n.selectBlock(t.containerClientId)}}}))])((function(e){return Object(d.useEffect)((function(){e.selectBlock()}),[]),Object(d.createElement)(De.Consumer,null,(function(t){var n=t.selectedTab,r=t.stripeNudge;return Object(d.createElement)("div",{hidden:"wall"===n.id,className:n.className},r,Object(d.createElement)(Ee.InnerBlocks,{renderAppender:!e.hasInnerBlocks&&Ee.InnerBlocks.ButtonBlockAppender,templateLock:!1,template:[["core/paragraph",{placeholder:Object(f.__)("Insert the piece of content you want your visitors to see after they subscribe.","premium-content")}]]}))}))}));var Je="premium-content/subscriber-view",qe="common",Xe={name:Je,category:qe,attributes:{},title:Object(f.__)("Subscriber View","premium-content"),description:Object(f.__)("Subscriber View.","premium-content"),parent:["premium-content/container"],supports:{inserter:!1,html:!1},edit:Ye,save:function(){return Object(d.createElement)("div",{className:"wp-block-premium-content-subscriber-view"},Object(d.createElement)(Ee.InnerBlocks.Content,null))}},Qe=n(35),et=n.n(Qe),tt=window.getComputedStyle,nt=Object(x.withFallbackStyles)((function(e,t){var n,r,o,i,c=t.textButtonColor,s=t.backgroundButtonColor,a=s&&s.color,l=c&&c.color;return!l&&e&&(n=e.querySelector('[contenteditable="true"]')),r=e.querySelector(".wp-block-button__link")?e.querySelector(".wp-block-button__link"):e,e&&r&&(o=tt(r).backgroundColor),n&&(i=tt(n).color),{fallbackBackgroundColor:a||o,fallbackTextColor:l||i}}));var rt=Object(S.compose)([Object(Ee.withColors)({backgroundButtonColor:"background-color"},{textButtonColor:"color"}),nt])((function(e){function t(){var t,n=e.textButtonColor,r=e.backgroundButtonColor,o=Object(j.get)(n,"class"),i=Object(j.get)(r,"class");return et()("wp-block-button__link",(t={"has-text-color":n.color},A()(t,o,o),A()(t,"has-background",r.color),A()(t,i,i),t))}Object(d.useEffect)((function(){!function(){var n=t();e.setAttributes({buttonClasses:n})}(),function(){var t=Object(j.get)(e.textButtonColor,"color"),n=Object(j.get)(e.backgroundButtonColor,"color");void 0!==t&&e.setAttributes({customTextButtonColor:t});void 0!==n&&e.setAttributes({customBackgroundButtonColor:n})}()}),[e.backgroundButtonColor,e.textButtonColor]);var n=e.attributes,r=e.setAttributes,o=e.backgroundButtonColor,i=e.textButtonColor,c=e.setBackgroundButtonColor,s=e.setTextButtonColor,a=e.fallbackBackgroundColor,l=e.fallbackTextColor,u=o.color||a,p=i.color||l,m={border:"none",backgroundColor:u,color:p},g=t();return Object(d.createElement)("div",null,Object(d.createElement)("div",{className:"wp-block-button premium-content-logged-out-view-button"},Object(d.createElement)(Ee.RichText,{placeholder:Object(f.__)("Add text…","premium-content"),value:n.subscribeButtonText,onChange:function(e){return r({subscribeButtonText:e})},className:g,style:m,keepPlaceholderOnFocus:!0}),Object(d.createElement)(Ee.RichText,{placeholder:Object(f.__)("Add text…","premium-content"),value:n.loginButtonText,onChange:function(e){return r({loginButtonText:e})},className:g,style:m,keepPlaceholderOnFocus:!0})),Object(d.createElement)(Ee.InspectorControls,null,Object(d.createElement)(Ee.PanelColorSettings,{title:Object(f.__)("Button Color Settings","premium-content"),colorSettings:[{value:o||void 0,onChange:c,label:Object(f.__)("Background Color","premium-content")},{value:i||void 0,onChange:s,label:Object(f.__)("Text Color","premium-content")}]}),Object(d.createElement)(Ee.ContrastChecker,{textColor:p,backgroundColor:u,fallbackBackgroundColor:a,fallbackTextColor:l})))}));var ot=Object(S.compose)([Object(E.withSelect)((function(e,t){return{containerClientId:e("core/block-editor").getBlockHierarchyRootClientId(t.clientId)}})),Object(E.withDispatch)((function(e,t){var n=e("core/block-editor");return{selectBlock:function(){n.selectBlock(t.containerClientId)}}}))])((function(e){Object(d.useEffect)((function(){e.selectBlock()}),[]);var t=Object(d.createElement)(rt,{attributes:Object(j.pick)(e.attributes,["subscribeButtonText","loginButtonText","backgroundButtonColor","textButtonColor","customBackgroundButtonColor","customTextButtonColor"]),setAttributes:e.setAttributes});return Object(d.createElement)(De.Consumer,null,(function(e){var n=e.selectedTab,r=e.stripeNudge;return Object(d.createElement)("div",{hidden:"premium"===n.id,className:n.className},r,Object(d.createElement)(Ee.InnerBlocks,{templateLock:!1,template:[["core/heading",{content:Object(f.__)("Subscribe to get access","premium-content"),level:3}],["core/paragraph",{content:Object(f.__)("Read more of this content when you subscribe today.","premium-content")}]]}),t)}))}));var it=n(20),ct="premium-content/logged-out-view",st="common",at={name:ct,category:st,attributes:{subscribeButtonText:{type:"string",default:"Subscribe"},loginButtonText:{type:"string",default:"Log In"},buttonClasses:{type:"string",default:""},backgroundButtonColor:{type:"string",default:""},textButtonColor:{type:"string",default:""},customBackgroundButtonColor:{type:"string",default:""},customTextButtonColor:{type:"string",default:""}},title:Object(f.__)("Logged Out View","premium-content"),description:Object(f.__)("Logged Out View.","premium-content"),parent:["premium-content/container"],supports:{inserter:!1,html:!1},edit:ot,save:function(){return Object(d.createElement)("div",{className:"wp-block-premium-content-logged-out-view"},Object(d.createElement)(Ee.InnerBlocks.Content,null))}},lt=Object(E.subscribe)((function(){var e=Object(E.select)("core/rich-text").getFormatType("core/link");if(e){lt(),Object(it.unregisterFormatType)("core/link");var t=Object(S.compose)(Object(E.withSelect)((function(e){return{selectedBlock:e("core/block-editor").getSelectedBlock()}})),Object(S.ifCondition)((function(e){return e.selectedBlock&&e.selectedBlock.name!==ct})))(e.edit);Object(it.registerFormatType)("core/link",l()({},e,{edit:t}))}})),ut=function(e){if(e){var t=e.name,n=e.category,r=e.settings;Object(m.registerBlockType)(t,l()({category:n},r))}},pt=function(){var e=s()(regeneratorRuntime.mark((function e(){var t,n,r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,p()({path:"/wpcom/v2/memberships/status"});case 3:t=e.sent,e.next=9;break;case 6:return e.prev=6,e.t0=e.catch(0),e.abrupt("return");case 9:if(!t.should_upgrade_to_access_memberships){e.next=17;break}if(n=Object(m.getBlockType)(Ke)){e.next=14;break}return e.abrupt("return");case 14:r=Object(f._x)("paid","Short label appearing near a block requiring a paid plan","premium-content"),Object(m.unregisterBlockType)(Ke),Object(m.registerBlockType)(Ke,l()({},n,{title:"".concat(n.title," (").concat(r,")")}));case 17:case"end":return e.stop()}}),e,null,[[0,6]])})));return function(){return e.apply(this,arguments)}}(),mt=function(){[r,i,o].forEach(ut),pt()};mt()}]));
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: alexislloyd, allancole, automattic, bartkalisz, codebykat, copons,
3
Tags: block, blocks, editor, gutenberg, page
4
Requires at least: 5.0
5
Tested up to: 5.4
6
- Stable tag: 1.6
7
Requires PHP: 5.6.20
8
License: GPLv2 or later
9
License URI: https://www.gnu.org/licenses/gpl-2.0.html
@@ -40,6 +40,11 @@ This plugin is experimental, so we don't provide any support for it outside of w
40
41
== Changelog ==
42
43
= 1.6 =
44
* Remove the "Edit as HTML" options for the inner blocks of the Premium Content Block.
45
* Remove plugin that notified users of the new location of Block Patterns.
3
Tags: block, blocks, editor, gutenberg, page
4
Requires at least: 5.0
5
Tested up to: 5.4
6
+ Stable tag: 1.7
7
Requires PHP: 5.6.20
8
License: GPLv2 or later
9
License URI: https://www.gnu.org/licenses/gpl-2.0.html
40
41
== Changelog ==
42
43
+ = 1.7 =
44
+ * Save the post before navigation when launching a WordPress.com site.
45
+ * Add handling for site launch on WordPress.com.
46
+ * Performance improvements in the block editor.
47
+
48
= 1.6 =
49
* Remove the "Edit as HTML" options for the inner blocks of the Premium Content Block.
50
* Remove plugin that notified users of the new location of Block Patterns.