From 75690d763d1febf435a21ad7595c1049200867ff Mon Sep 17 00:00:00 2001 From: ingeniumed Date: Tue, 2 Jul 2024 21:18:57 +1000 Subject: [PATCH] Introduce a separation of the block editor assets --- dist/custom-status.build.js | 2 +- .../custom-status/lib/custom-status-block.js | 245 +++++++++--------- 2 files changed, 127 insertions(+), 120 deletions(-) diff --git a/dist/custom-status.build.js b/dist/custom-status.build.js index 1a26bb46..c74975b0 100644 --- a/dist/custom-status.build.js +++ b/dist/custom-status.build.js @@ -1,2 +1,2 @@ -(()=>{"use strict";var t={n:e=>{var n=e&&e.__esModule?()=>e.default:()=>e;return t.d(n,{a:n}),n},d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)};const e=React;var n=t.n(e);function r(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return o(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?o(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0,a=function(){};return{s:a,n:function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}},e:function(t){throw t},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,i=!0,u=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return i=t.done,t},e:function(t){u=!0,s=t},f:function(){try{i||null==n.return||n.return()}finally{if(u)throw s}}}}function o(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n{"use strict";React,wp.i18n.__,wp.editPost.PluginPostStatusInfo,wp.plugins.registerPlugin;var e=wp.data;e.subscribe,e.dispatch,e.select,e.withSelect,e.withDispatch,wp.compose.compose,wp.components.SelectControl,console.log("VIP feature is enabled")})(); //# sourceMappingURL=custom-status.build.js.map \ No newline at end of file diff --git a/modules/custom-status/lib/custom-status-block.js b/modules/custom-status/lib/custom-status-block.js index 2bf61896..3475d3d8 100644 --- a/modules/custom-status/lib/custom-status-block.js +++ b/modules/custom-status/lib/custom-status-block.js @@ -8,133 +8,140 @@ const { subscribe, dispatch, select, withSelect, withDispatch } = wp.data; const { compose } = wp.compose; const { SelectControl } = wp.components; -/** - * Map Custom Statuses as options for SelectControl - */ -const statuses = window.EditFlowCustomStatuses.map( s => ( { label: s.name, value: s.slug } ) ); - -/** - * Subscribe to changes so we can set a default status and update a button's text. - */ -let buttonTextObserver = null; -subscribe( function () { - const postId = select( 'core/editor' ).getCurrentPostId(); - if ( ! postId ) { - // Post isn't ready yet so don't do anything. - return; - } +let is_vip_feature_enabled = true; + +if (is_vip_feature_enabled) { + console.log('VIP feature is enabled'); +} else { + console.log('VIP feature is disabled'); + /** + * Map Custom Statuses as options for SelectControl + */ + const statuses = window.EditFlowCustomStatuses.map(s => ({ label: s.name, value: s.slug })); - // For new posts, we need to force the default custom status. - const isCleanNewPost = select( 'core/editor' ).isCleanNewPost(); - if ( isCleanNewPost ) { - dispatch( 'core/editor' ).editPost( { - status: ef_default_custom_status, - } ); - } + /** + * Subscribe to changes so we can set a default status and update a button's text. + */ + let buttonTextObserver = null; + subscribe(function () { + const postId = select('core/editor').getCurrentPostId(); + if (!postId) { + // Post isn't ready yet so don't do anything. + return; + } - // If the save button exists, let's update the text if needed. - maybeUpdateButtonText( document.querySelector( '.editor-post-save-draft' ) ); - - // The post is being saved, so we need to set up an observer to update the button text when it's back. - if ( - buttonTextObserver === null && - window.MutationObserver && - select( 'core/editor' ).isSavingPost() - ) { - buttonTextObserver = createButtonObserver( - document.querySelector( '.edit-post-header__settings' ) - ); - } -} ); - -/** - * Create a mutation observer that will update the - * save button text right away when it's changed/re-added. - * - * Ideally there will be better ways to go about this in the future. - * @see https://github.com/Automattic/Edit-Flow/issues/583 - */ -function createButtonObserver( parentNode ) { - if ( ! parentNode ) { - return null; - } + // For new posts, we need to force the default custom status. + const isCleanNewPost = select('core/editor').isCleanNewPost(); + if (isCleanNewPost) { + dispatch('core/editor').editPost({ + status: ef_default_custom_status, + }); + } - const observer = new MutationObserver( mutationsList => { - for ( const mutation of mutationsList ) { - for ( const node of mutation.addedNodes ) { - maybeUpdateButtonText( node ); - } + // If the save button exists, let's update the text if needed. + maybeUpdateButtonText(document.querySelector('.editor-post-save-draft')); + + // The post is being saved, so we need to set up an observer to update the button text when it's back. + if ( + buttonTextObserver === null && + window.MutationObserver && + select('core/editor').isSavingPost() + ) { + buttonTextObserver = createButtonObserver( + document.querySelector('.edit-post-header__settings') + ); + } + }); + + /** + * Create a mutation observer that will update the + * save button text right away when it's changed/re-added. + * + * Ideally there will be better ways to go about this in the future. + * @see https://github.com/Automattic/Edit-Flow/issues/583 + */ + function createButtonObserver(parentNode) { + if (!parentNode) { + return null; } - } ); - observer.observe( parentNode, { childList: true } ); - return observer; -} + const observer = new MutationObserver(mutationsList => { + for (const mutation of mutationsList) { + for (const node of mutation.addedNodes) { + maybeUpdateButtonText(node); + } + } + }); -function maybeUpdateButtonText( saveButton ) { - /* - * saveButton.children < 1 accounts for when a user hovers over the save button - * and a tooltip is rendered - */ - if ( - saveButton && - saveButton.children < 1 && - ( saveButton.innerText === __( 'Save Draft' ) || - saveButton.innerText === __( 'Save as Pending' ) ) - ) { - saveButton.innerText = __( 'Save' ); + observer.observe(parentNode, { childList: true }); + return observer; + } + + function maybeUpdateButtonText(saveButton) { + /* + * saveButton.children < 1 accounts for when a user hovers over the save button + * and a tooltip is rendered + */ + if ( + saveButton && + saveButton.children < 1 && + (saveButton.innerText === __('Save Draft') || + saveButton.innerText === __('Save as Pending')) + ) { + saveButton.innerText = __('Save'); + } } -} -/** - * Custom status component - * @param object props - */ -const EditFlowCustomPostStati = ( { onUpdate, status } ) => ( - -

- { status !== 'publish' - ? __( 'Extended Post Status', 'edit-flow' ) - : __( 'Extended Post Status Disabled.', 'edit-flow' ) } -

- - { status !== 'publish' ? ( - - ) : null } - - - { status !== 'publish' - ? __( 'Note: this will override all status settings above.', 'edit-flow' ) - : __( 'To select a custom status, please unpublish the content first.', 'edit-flow' ) } - -
-); - -const mapSelectToProps = select => { - return { - status: select( 'core/editor' ).getEditedPostAttribute( 'status' ), + /** + * Custom status component + * @param object props + */ + const EditFlowCustomPostStati = ({ onUpdate, status }) => ( + +

+ {status !== 'publish' + ? __('Extended Post Status', 'edit-flow') + : __('Extended Post Status Disabled.', 'edit-flow')} +

+ + {status !== 'publish' ? ( + + ) : null} + + + {status !== 'publish' + ? __('Note: this will override all status settings above.', 'edit-flow') + : __('To select a custom status, please unpublish the content first.', 'edit-flow')} + +
+ ); + + const mapSelectToProps = select => { + return { + status: select('core/editor').getEditedPostAttribute('status'), + }; }; -}; -const mapDispatchToProps = dispatch => { - return { - onUpdate( status ) { - dispatch( 'core/editor' ).editPost( { status } ); - }, + const mapDispatchToProps = dispatch => { + return { + onUpdate(status) { + dispatch('core/editor').editPost({ status }); + }, + }; }; -}; - -const plugin = compose( - withSelect( mapSelectToProps ), - withDispatch( mapDispatchToProps ) -)( EditFlowCustomPostStati ); - -/** - * Kick it off - */ -registerPlugin( 'edit-flow-custom-status', { - icon: 'edit-flow', - render: plugin, -} ); + + const plugin = compose( + withSelect(mapSelectToProps), + withDispatch(mapDispatchToProps) + )(EditFlowCustomPostStati); + + /** + * Kick it off + */ + registerPlugin('edit-flow-custom-status', { + icon: 'edit-flow', + render: plugin, + }); +}