Skip to content
Snippets Groups Projects
Commit b3a9ad0f authored by Erick Hitter's avatar Erick Hitter
Browse files

Create block-editor sidebar component

parent 2b7d206c
No related branches found
No related tags found
1 merge request!5Add block-editor support
Pipeline #4947 failed with stages
in 2 minutes
module.exports = function( grunt ) {
module.exports = function ( grunt ) {
'use strict';
// Project configuration
grunt.initConfig( {
pkg: grunt.file.readJSON( 'package.json' ),
addtextdomain: {
......@@ -13,7 +11,7 @@ module.exports = function( grunt ) {
},
update_all_domains: {
options: {
updateDomains: true
updateDomains: true,
},
src: [ '*.php', '**/*.php', '!\.git/**/*', '!bin/**/*', '!node_modules/**/*', '!tests/**/*' ]
}
......@@ -22,8 +20,8 @@ module.exports = function( grunt ) {
wp_readme_to_markdown: {
your_target: {
files: {
'README.md': 'readme.txt'
}
'README.md': 'readme.txt',
},
},
},
......@@ -36,21 +34,20 @@ module.exports = function( grunt ) {
potFilename: 'automatically-paginate-posts.pot',
potHeaders: {
poedit: true,
'x-poedit-keywordslist': true
'x-poedit-keywordslist': true,
},
type: 'wp-plugin',
updateTimestamp: true
}
}
updateTimestamp: true,
},
},
},
} );
grunt.loadNpmTasks( 'grunt-wp-i18n' );
grunt.loadNpmTasks( 'grunt-wp-readme-to-markdown' );
grunt.registerTask( 'default', [ 'i18n','readme' ] );
grunt.registerTask( 'i18n', ['addtextdomain', 'makepot'] );
grunt.registerTask( 'readme', ['wp_readme_to_markdown'] );
grunt.registerTask( 'default', [ 'i18n', 'readme' ] );
grunt.registerTask( 'i18n', [ 'addtextdomain', 'makepot' ] );
grunt.registerTask( 'readme', [ 'wp_readme_to_markdown' ] );
grunt.util.linefeed = '\n';
};
<?php return array('dependencies' => array('wp-components', 'wp-compose', 'wp-data', 'wp-edit-post', 'wp-element', 'wp-i18n', 'wp-plugins', 'wp-primitives'), 'version' => 'ea759c794441056cd75f');
(()=>{"use strict";const e=window.wp.element,t=window.wp.editPost,n=window.wp.i18n,a=window.wp.primitives,i=(0,e.createElement)(a.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,e.createElement)(a.Path,{d:"M7.8 6c0-.7.6-1.2 1.2-1.2h6c.7 0 1.2.6 1.2 1.2v3h1.5V6c0-1.5-1.2-2.8-2.8-2.8H9C7.5 3.2 6.2 4.5 6.2 6v3h1.5V6zm8.4 11c0 .7-.6 1.2-1.2 1.2H9c-.7 0-1.2-.6-1.2-1.2v-3H6.2v3c0 1.5 1.2 2.8 2.8 2.8h6c1.5 0 2.8-1.2 2.8-2.8v-3h-1.5v3zM4 11v1h16v-1H4z"})),o=window.wp.plugins,l=window.wp.components,s=window.wp.compose,g=window.wp.data,{metaKey:c}=autopagingSettings,r=(0,s.compose)([(0,g.withSelect)((e=>{const{getEditedPostAttribute:t}=e("core/editor"),n=t("content");return{disabled:!!t("meta")[c],hasQuicktag:-1!==n.indexOf("wp:nextpage")}})),(0,g.withDispatch)((e=>{const{editPost:t}=e("core/editor");return{setDisabled:e=>{t({meta:{[c]:!!e}})}}}))])((t=>{let{disabled:a,hasQuicktag:i,setDisabled:o}=t;return(0,e.createElement)(e.Fragment,null,i&&(0,e.createElement)("p",{dangerouslySetInnerHTML:{__html:(0,n.__)("Autopaging is disabled because the <em>Page Break</em> block is used.","autopaging")}}),!i&&(0,e.createElement)(e.Fragment,null,(0,e.createElement)(l.ToggleControl,{label:(0,n.__)("Disable autopaging for this post?","autopaging"),help:(0,n.__)("Check the box above to prevent this post from automatically being split over multiple pages.","autopaging"),checked:a,onChange:o})))})),p="autopaging";(0,o.registerPlugin)(p,{icon:i,render:()=>(0,e.createElement)(t.PluginDocumentSettingPanel,{name:p,title:(0,n.__)("Autopaging","autopaging"),className:p},(0,e.createElement)(r,null))})})();
\ No newline at end of file
import './js/index';
import { PluginDocumentSettingPanel } from '@wordpress/edit-post';
import { __ } from '@wordpress/i18n';
import { pageBreak } from '@wordpress/icons';
import { registerPlugin } from '@wordpress/plugins';
import PanelBody from './panel-body';
const slug = 'autopaging';
/**
* Render panel view.
*
* @return {JSX.Element|null} Sidebar panel.
*/
const View = () => (
<PluginDocumentSettingPanel
name={ slug }
title={ __( 'Autopaging', 'autopaging' ) }
className={ slug }
>
<PanelBody />
</PluginDocumentSettingPanel>
);
registerPlugin( slug, {
icon: pageBreak,
render: View,
} );
/* global autopagingSettings */
import { ToggleControl } from '@wordpress/components';
import { compose } from '@wordpress/compose';
import { withSelect, withDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
const { metaKey } = autopagingSettings;
/**
* Render controls.
*
* @param {Object} props Component props.
* @param {boolean} props.disabled Whether autopaging is disabled.
* @param {boolean} props.hasQuicktag Whether post is manually paginated.
* @param {Function} props.setDisabled Save updated setting.
* @return {JSX.Element} Panel body.
*/
const View = ( { disabled, hasQuicktag, setDisabled } ) => (
<>
{ hasQuicktag && (
<p
dangerouslySetInnerHTML={ {
__html: __(
'Autopaging is disabled because the <em>Page Break</em> block is used.',
'autopaging'
),
} }
/>
) }
{ ! hasQuicktag && (
<>
<ToggleControl
label={ __(
'Disable autopaging for this post?',
'autopaging'
) }
help={ __(
'Check the box above to prevent this post from automatically being split over multiple pages.',
'autopaging'
) }
checked={ disabled }
onChange={ setDisabled }
/>
</>
) }
</>
);
/**
* HOC to provide meta values and methods for updating meta.
*/
const PanelBody = compose( [
withSelect( ( select ) => {
const { getEditedPostAttribute } = select( 'core/editor' );
const content = getEditedPostAttribute( 'content' );
const meta = getEditedPostAttribute( 'meta' );
return {
disabled: !! meta[ metaKey ],
hasQuicktag: -1 !== content.indexOf( 'wp:nextpage' ),
};
} ),
withDispatch( ( dispatch ) => {
const { editPost } = dispatch( 'core/editor' );
const setDisabled = ( target ) => {
editPost( {
meta: {
[ metaKey ]: !! target,
},
} );
};
return {
setDisabled,
};
} ),
] )( View );
export default PanelBody;
......@@ -508,7 +508,7 @@ class Automatically_Paginate_Posts {
continue;
}
add_meta_box( 'autopaging', __( 'Post Autopaging', 'autopaging' ), array( $this, 'meta_box_autopaging' ), $post_type, 'side' );
add_meta_box( 'autopaging', __( 'Autopaging', 'autopaging' ), array( $this, 'meta_box_autopaging' ), $post_type, 'side' );
}
}
......@@ -522,7 +522,10 @@ class Automatically_Paginate_Posts {
public function meta_box_autopaging( $post ) {
?>
<p>
<input type="checkbox" name="<?php echo esc_attr( $this->meta_key_disable_autopaging ); ?>" id="<?php echo esc_attr( $this->meta_key_disable_autopaging ); ?>_checkbox" value="1"<?php checked( (bool) get_post_meta( $post->ID, $this->meta_key_disable_autopaging, true ) ); ?> /> <label for="<?php echo esc_attr( $this->meta_key_disable_autopaging ); ?>_checkbox">Disable autopaging for this post?</label>
<input type="checkbox" name="<?php echo esc_attr( $this->meta_key_disable_autopaging ); ?>" id="<?php echo esc_attr( $this->meta_key_disable_autopaging ); ?>_checkbox" value="1"<?php checked( (bool) get_post_meta( $post->ID, $this->meta_key_disable_autopaging, true ) ); ?> />
<label for="<?php echo esc_attr( $this->meta_key_disable_autopaging ); ?>_checkbox">
<?php esc_html_e( 'Disable autopaging for this post?', 'autopaging' ); ?>
</label>
</p>
<p class="description"><?php esc_html__( 'Check the box above to prevent this post from automatically being split over multiple pages.', 'autopaging' ); ?></p>
<p class="description">
......@@ -563,7 +566,7 @@ class Automatically_Paginate_Posts {
}
if ( isset( $_POST[ $this->meta_key_disable_autopaging . '_wpnonce' ] ) && wp_verify_nonce( $_POST[ $this->meta_key_disable_autopaging . '_wpnonce' ], $this->meta_key_disable_autopaging ) ) {
$disable = isset( $_POST[ $this->meta_key_disable_autopaging ] ) ? true : false;
$disable = isset( $_POST[ $this->meta_key_disable_autopaging ] );
if ( $disable ) {
update_post_meta( $post_id, $this->meta_key_disable_autopaging, true );
......
......@@ -103,6 +103,18 @@ class Block_Editor {
* @return void
*/
public function enqueue() {
global $typenow;
if (
! in_array(
$typenow,
$this->autopaging_instance->post_types,
true
)
) {
return;
}
$asset_handle = 'automatically-paginate-posts-block-editor';
$plugin_base_dir = dirname( dirname( __FILE__ ) );
......@@ -118,6 +130,14 @@ class Block_Editor {
true
);
wp_localize_script(
$asset_handle,
'autopagingSettings',
[
'metaKey' => $this->autopaging_instance->meta_key,
]
);
wp_set_script_translations(
$asset_handle,
'autopaging',
......
......@@ -5,7 +5,7 @@ msgstr ""
"Project-Id-Version: Automatically Paginate Posts 0.3\n"
"Report-Msgid-Bugs-To: "
"https://wordpress.org/support/plugin/automatically-paginate-posts\n"
"POT-Creation-Date: 2022-06-26 22:43:32+00:00\n"
"POT-Creation-Date: 2022-06-27 04:45:20+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
......@@ -25,49 +25,61 @@ msgstr ""
"X-Textdomain-Support: yes\n"
"X-Generator: grunt-wp-i18n 1.0.3\n"
#: automatically-paginate-posts.php:183
msgid "Post types can only be retrieved after the \"init\" hook."
msgstr ""
#. Plugin Name of the plugin/theme
msgid "Automatically Paginate Posts"
msgstr ""
#: automatically-paginate-posts.php:244
#: automatically-paginate-posts.php:317
msgid "Supported post types:"
msgstr ""
#: automatically-paginate-posts.php:245
#: automatically-paginate-posts.php:318
msgid "Split post by:"
msgstr ""
#: automatically-paginate-posts.php:323
msgid "Total number of pages: "
#: automatically-paginate-posts.php:396
msgid "Total number of pages:"
msgstr ""
#: automatically-paginate-posts.php:324
msgid "Approximate words per page: "
#: automatically-paginate-posts.php:397
msgid "Approximate words per page:"
msgstr ""
#: automatically-paginate-posts.php:391
#: automatically-paginate-posts.php:474
msgid ""
"If chosen, each page will contain approximately this many words, depending "
"on paragraph lengths."
msgstr ""
#: automatically-paginate-posts.php:421
msgid "Post Autopaging"
#: automatically-paginate-posts.php:511
msgid "Autopaging"
msgstr ""
#: automatically-paginate-posts.php:527
msgid "Disable autopaging for this post?"
msgstr ""
#: automatically-paginate-posts.php:437
#: automatically-paginate-posts.php:530
msgid ""
"Check the box above to prevent this post from automatically being split "
"over multiple pages."
msgstr ""
#: automatically-paginate-posts.php:442
#: automatically-paginate-posts.php:535
#. translators: 1. Quicktag code example.
msgid ""
"Note that if the %1$s Quicktag is used to manually page this post, "
"automatic paging won't be applied, regardless of the setting above."
msgstr ""
#: inc/class-block-editor.php:65
msgid "Whether or not to disable pagination for this post."
msgstr ""
#. Plugin URI of the plugin/theme
msgid "http://www.oomphinc.com/plugins-modules/automatically-paginate-posts/"
msgstr ""
......
source diff could not be displayed: it is too large. Options to address this: view the blob.
{
"name": "automatically-paginate-posts",
"version": "0.1.0",
"main": "Gruntfile.js",
"author": "Erick Hitter & Oomph, Inc.",
"devDependencies": {
"@wordpress/scripts": "^23.3.0",
"grunt": "^1.5.3",
"grunt-wp-i18n": "^1.0.3",
"grunt-wp-readme-to-markdown": "^2.1.0"
},
"scripts": {
"build": "wp-scripts build",
"check-engines": "wp-scripts check-engines",
"check-licenses": "wp-scripts check-licenses",
"format": "wp-scripts format",
"grunt": "grunt",
"lint:css": "wp-scripts lint-style",
"lint:js": "wp-scripts lint-js",
"lint:md:docs": "wp-scripts lint-md-docs",
"lint:pkg-json": "wp-scripts lint-pkg-json",
"packages-update": "wp-scripts packages-update",
"start": "wp-scripts start",
"test": "npm run test:e2e && npm run test:unit",
"test:e2e": "wp-scripts test-e2e --passWithNoTests",
"test:unit": "wp-scripts test-unit-js --passWithNoTests"
}
"name": "automatically-paginate-posts",
"version": "0.1.0",
"main": "Gruntfile.js",
"author": "Erick Hitter & Oomph, Inc.",
"devDependencies": {
"@wordpress/icons": "^9.2.0",
"@wordpress/scripts": "^23.3.0",
"grunt": "^1.5.3",
"grunt-wp-i18n": "^1.0.3",
"grunt-wp-readme-to-markdown": "^2.1.0",
"prettier": "npm:wp-prettier@^2.6.2"
},
"scripts": {
"build": "wp-scripts build",
"check-engines": "wp-scripts check-engines",
"check-licenses": "wp-scripts check-licenses",
"format": "wp-scripts format",
"grunt": "grunt",
"lint:css": "wp-scripts lint-style",
"lint:js": "wp-scripts lint-js",
"lint:md:docs": "wp-scripts lint-md-docs",
"lint:pkg-json": "wp-scripts lint-pkg-json",
"packages-update": "wp-scripts packages-update",
"start": "wp-scripts start",
"test": "npm run test:e2e && npm run test:unit",
"test:e2e": "wp-scripts test-e2e --passWithNoTests",
"test:unit": "wp-scripts test-unit-js --passWithNoTests"
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment