diff --git a/assets/blocks.js b/assets/blocks.js index 30bf089..d077073 100644 --- a/assets/blocks.js +++ b/assets/blocks.js @@ -1,97 +1 @@ -/******/ (function(modules) { // webpackBootstrap -/******/ // The module cache -/******/ var installedModules = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) { -/******/ return installedModules[moduleId].exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ i: moduleId, -/******/ l: false, -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); -/******/ -/******/ // Flag the module as loaded -/******/ module.l = true; -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/******/ -/******/ // expose the modules object (__webpack_modules__) -/******/ __webpack_require__.m = modules; -/******/ -/******/ // expose the module cache -/******/ __webpack_require__.c = installedModules; -/******/ -/******/ // define getter function for harmony exports -/******/ __webpack_require__.d = function(exports, name, getter) { -/******/ if(!__webpack_require__.o(exports, name)) { -/******/ Object.defineProperty(exports, name, { -/******/ configurable: false, -/******/ enumerable: true, -/******/ get: getter -/******/ }); -/******/ } -/******/ }; -/******/ -/******/ // define __esModule on exports -/******/ __webpack_require__.r = function(exports) { -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __webpack_require__.n = function(module) { -/******/ var getter = module && module.__esModule ? -/******/ function getDefault() { return module['default']; } : -/******/ function getModuleExports() { return module; }; -/******/ __webpack_require__.d(getter, 'a', getter); -/******/ return getter; -/******/ }; -/******/ -/******/ // Object.prototype.hasOwnProperty.call -/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; -/******/ -/******/ // __webpack_public_path__ -/******/ __webpack_require__.p = ""; -/******/ -/******/ -/******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = "./assets/src/blocks.js"); -/******/ }) -/************************************************************************/ -/******/ ({ - -/***/ "./assets/src/blocks.js": -/*!******************************!*\ - !*** ./assets/src/blocks.js ***! - \******************************/ -/*! no exports provided */ -/***/ (function(module, __webpack_exports__, __webpack_require__) { - -"use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _speakers__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./speakers */ \"./assets/src/speakers.js\");\n/* harmony import */ var _speakers__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_speakers__WEBPACK_IMPORTED_MODULE_0__);\n/**\n * Internal dependencies\n */\n\n\n//# sourceURL=webpack:///./assets/src/blocks.js?"); - -/***/ }), - -/***/ "./assets/src/speakers.js": -/*!********************************!*\ - !*** ./assets/src/speakers.js ***! - \********************************/ -/*! no static exports found */ -/***/ (function(module, exports) { - -eval("// License: GPLv2+\nvar registerBlockType = wp.blocks.registerBlockType;\nvar InspectorControls = wp.editor.InspectorControls;\nvar _wp$components = wp.components,\n ServerSideRender = _wp$components.ServerSideRender,\n PanelBody = _wp$components.PanelBody,\n PanelRow = _wp$components.PanelRow,\n CheckboxControl = _wp$components.CheckboxControl,\n RangeControl = _wp$components.RangeControl,\n SelectControl = _wp$components.SelectControl,\n TextControl = _wp$components.TextControl;\nvar el = wp.element.createElement,\n data = WordCampBlocks.speakers || {};\nvar supports = {\n className: false\n};\n/* todo We might be able to use this instead of the PHP version once this becomes fully native JS instead of SSR.\nconst schema = {\n\t'show_all_posts': {\n\t\ttype: 'boolean',\n\t\tdefault: true,\n\t},\n\t'posts_per_page': {\n\t\ttype: 'integer',\n\t\tminimum: 1,\n\t\tmaximum: 100,\n\t\tdefault: 10,\n\t},\n\t'track': {\n\t\ttype: 'array',\n\t\titems: {\n\t\t\ttype: 'string',\n\t\t\tenum: data.options.track, //todo\n\t\t}\n\t},\n\t'groups': {\n\t\ttype: 'array',\n\t\titems: {\n\t\t\ttype: 'string',\n\t\t\tenum: data.options.groups, //todo\n\t\t}\n\t},\n\t'sort': {\n\t\ttype: 'string',\n\t\tenum: data.options.sort, //todo\n\t\tdefault: 'title_asc',\n\t},\n\t'speaker_link': {\n\t\ttype: 'boolean',\n\t\tdefault: false,\n\t},\n\t'show_avatars': {\n\t\ttype: 'boolean',\n\t\tdefault: true,\n\t},\n\t'avatar_size': {\n\t\ttype: 'integer',\n\t\tminimum: 64,\n\t\tmaximum: 512,\n\t\tdefault: 100,\n\t},\n};\n*/\n\nvar schema = data.schema;\nregisterBlockType('wordcamp/speakers', {\n title: data.l10n['block_label'],\n description: data.l10n['block_description'],\n icon: 'megaphone',\n category: 'wordcamp',\n attributes: schema,\n supports: supports,\n edit: function edit(props) {\n var whichControls = [],\n displayControls = [];\n\n if (data.options['track'].length > 1) {\n whichControls.push( // Some controls currently have broken layout within a PanelRow. See https://github.com/WordPress/gutenberg/pull/4564\n //el( PanelRow, {}, [\n el(SelectControl, {\n label: data.l10n['track_label'],\n value: props.attributes['track'],\n options: data.options['track'],\n multiple: true,\n onChange: function onChange(value) {\n props.setAttributes({\n 'track': value\n });\n }\n }) //] )\n );\n }\n\n if (data.options['groups'].length > 1) {\n whichControls.push( // Some controls currently have broken layout within a PanelRow. See https://github.com/WordPress/gutenberg/pull/4564\n //el( PanelRow, {}, [\n el(SelectControl, {\n label: data.l10n['groups_label'],\n value: props.attributes['groups'],\n options: data.options['groups'],\n multiple: true,\n onChange: function onChange(value) {\n props.setAttributes({\n 'groups': value\n });\n }\n }) //] )\n );\n }\n\n whichControls.push(el(PanelRow, {}, [el(CheckboxControl, {\n label: data.l10n['show_all_posts_label'],\n checked: props.attributes['show_all_posts'],\n onChange: function onChange(value) {\n props.setAttributes({\n 'show_all_posts': value\n });\n }\n })]));\n\n if (!props.attributes['show_all_posts']) {\n whichControls.push( // Some controls currently have broken layout within a PanelRow. See https://github.com/WordPress/gutenberg/pull/4564\n //el( PanelRow, {}, [\n el(RangeControl, {\n label: data.l10n['posts_per_page_label'],\n value: props.attributes['posts_per_page'],\n min: schema['posts_per_page'].minimum,\n max: schema['posts_per_page'].maximum,\n initialPosition: schema['posts_per_page'].default,\n allowReset: true,\n onChange: function onChange(value) {\n props.setAttributes({\n 'posts_per_page': value\n });\n }\n }) //] )\n );\n }\n\n whichControls.push( // Some controls currently have broken layout within a PanelRow. See https://github.com/WordPress/gutenberg/pull/4564\n //el( PanelRow, {}, [\n el(SelectControl, {\n label: data.l10n['sort_label'],\n value: props.attributes['sort'],\n options: data.options['sort'],\n onChange: function onChange(value) {\n props.setAttributes({\n 'sort': value\n });\n }\n }) //] )\n );\n displayControls.push(el(PanelRow, {}, [el(CheckboxControl, {\n label: data.l10n['speaker_link_label'],\n help: data.l10n['speaker_link_help'],\n checked: props.attributes['speaker_link'],\n onChange: function onChange(value) {\n props.setAttributes({\n 'speaker_link': value\n });\n }\n })]));\n displayControls.push(el(PanelRow, {}, [el(CheckboxControl, {\n label: data.l10n['show_avatars_label'],\n checked: props.attributes['show_avatars'],\n onChange: function onChange(value) {\n props.setAttributes({\n 'show_avatars': value\n });\n }\n })]));\n\n if (props.attributes['show_avatars']) {\n displayControls.push( // Some controls currently have broken layout within a PanelRow. See https://github.com/WordPress/gutenberg/pull/4564\n //el( PanelRow, {}, [\n el(RangeControl, {\n label: data.l10n['avatar_size_label'],\n help: data.l10n['avatar_size_help'],\n value: props.attributes['avatar_size'],\n min: schema['avatar_size'].minimum,\n max: schema['avatar_size'].maximum,\n initialPosition: schema['avatar_size'].default,\n allowReset: true,\n onChange: function onChange(value) {\n props.setAttributes({\n 'avatar_size': value\n });\n }\n }) //] )\n );\n }\n\n return [el(ServerSideRender, {\n block: 'wordcamp/speakers',\n attributes: props.attributes\n }), el(InspectorControls, {}, [el(PanelBody, {\n title: data.l10n['panel_which_title'],\n initialOpen: true\n }, whichControls), el(PanelBody, {\n title: data.l10n['panel_display_title'],\n initialOpen: false\n }, displayControls)])];\n },\n save: function save() {\n return null;\n }\n});\n\n//# sourceURL=webpack:///./assets/src/speakers.js?"); - -/***/ }) - -/******/ }); \ No newline at end of file +!function(t){var e={};function o(r){if(e[r])return e[r].exports;var a=e[r]={i:r,l:!1,exports:{}};return t[r].call(a.exports,a,a.exports,o),a.l=!0,a.exports}o.m=t,o.c=e,o.d=function(t,e,r){o.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:r})},o.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=1)}([function(t,e){var o=wp.element.createElement,r=WordCampBlocks.speakers||{},a=wp.i18n.__,s=wp.blocks.registerBlockType,n=wp.editor.InspectorControls,i=wp.components,p=i.ServerSideRender,l=i.PanelBody,u=i.PanelRow,c=i.CheckboxControl,m=i.RangeControl,h=i.SelectControl,g=(i.TextControl,r.schema);s("wordcamp/speakers",{title:a("Speakers","wordcamporg"),description:a("Add a list of speakers.","wordcamporg"),icon:"megaphone",category:"wordcamp",attributes:g,supports:{className:!1},edit:function(t){var e=[],s=[];return r.options.track.length>1&&e.push(o(h,{label:a("From which session tracks?","wordcamporg"),value:t.attributes.track,options:r.options.track,multiple:!0,onChange:function(e){t.setAttributes({track:e})}})),r.options.groups.length>1&&e.push(o(h,{label:a("From which speaker groups?","wordcamporg"),value:t.attributes.groups,options:r.options.groups,multiple:!0,onChange:function(e){t.setAttributes({groups:e})}})),e.push(o(u,{},[o(c,{label:a("Show all","wordcamporg"),checked:t.attributes.show_all_posts,onChange:function(e){t.setAttributes({show_all_posts:e})}})])),t.attributes.show_all_posts||e.push(o(m,{label:a("Number to show","wordcamporg"),value:t.attributes.posts_per_page,min:g.posts_per_page.minimum,max:g.posts_per_page.maximum,initialPosition:g.posts_per_page.default,allowReset:!0,onChange:function(e){t.setAttributes({posts_per_page:e})}})),e.push(o(h,{label:a("Sort by","wordcamporg"),value:t.attributes.sort,options:r.options.sort,onChange:function(e){t.setAttributes({sort:e})}})),s.push(o(u,{},[o(c,{label:a("Link titles to single posts","wordcamporg"),help:a("These will not appear in the block preview.","wordcamporg"),checked:t.attributes.speaker_link,onChange:function(e){t.setAttributes({speaker_link:e})}})])),s.push(o(u,{},[o(c,{label:a("Show avatars","wordcamporg"),checked:t.attributes.show_avatars,onChange:function(e){t.setAttributes({show_avatars:e})}})])),t.attributes.show_avatars&&s.push(o(m,{label:a("Avatar size (px)","wordcamporg"),help:a("Height and width in pixels.","wordcamporg"),value:t.attributes.avatar_size,min:g.avatar_size.minimum,max:g.avatar_size.maximum,initialPosition:g.avatar_size.default,allowReset:!0,onChange:function(e){t.setAttributes({avatar_size:e})}})),[o(p,{block:"wordcamp/speakers",attributes:t.attributes}),o(n,{},[o(l,{title:a("Which Speakers?","wordcamporg"),initialOpen:!0},e),o(l,{title:a("Speaker Display","wordcamporg"),initialOpen:!1},s)])]},save:function(){return null}})},function(t,e,o){"use strict";o.r(e);o(0);var r=WordCampBlocks.l10n||{};(0,wp.i18n.setLocaleData)(r,"wordcamporg")}]); \ No newline at end of file diff --git a/assets/src/blocks.js b/assets/src/blocks.js index ea85887..8e151a9 100644 --- a/assets/src/blocks.js +++ b/assets/src/blocks.js @@ -1,3 +1,15 @@ +/** + * External dependencies + */ +const l10n = WordCampBlocks.l10n || {}; + +/** + * WordPress dependencies + */ +const { setLocaleData } = wp.i18n; + +setLocaleData( l10n, 'wordcamporg' ); + /** * Internal dependencies */ diff --git a/assets/src/speakers.js b/assets/src/speakers.js index 9671eac..e135c5f 100644 --- a/assets/src/speakers.js +++ b/assets/src/speakers.js @@ -1,12 +1,19 @@ -// License: GPLv2+ - +// todo Deprecate this +var el = wp.element.createElement; + +/** + * External dependencies + */ +const data = WordCampBlocks.speakers || {}; + +/** + * WordPress dependencies + */ +const { __ } = wp.i18n; const { registerBlockType } = wp.blocks; const { InspectorControls } = wp.editor; const { ServerSideRender, PanelBody, PanelRow, CheckboxControl, RangeControl, SelectControl, TextControl } = wp.components; -var el = wp.element.createElement, - data = WordCampBlocks.speakers || {}; - const supports = { className: false, }; @@ -62,8 +69,8 @@ const schema = { const schema = data.schema; registerBlockType( 'wordcamp/speakers', { - title: data.l10n['block_label'], - description: data.l10n['block_description'], + title: __( 'Speakers', 'wordcamporg' ), + description: __( 'Add a list of speakers.', 'wordcamporg' ), icon: 'megaphone', category: 'wordcamp', attributes: schema, @@ -78,7 +85,7 @@ registerBlockType( 'wordcamp/speakers', { // Some controls currently have broken layout within a PanelRow. See https://github.com/WordPress/gutenberg/pull/4564 //el( PanelRow, {}, [ el( SelectControl, { - label: data.l10n['track_label'], + label: __( 'From which session tracks?', 'wordcamporg' ), value: props.attributes['track'], options: data.options['track'], multiple: true, @@ -93,7 +100,7 @@ registerBlockType( 'wordcamp/speakers', { // Some controls currently have broken layout within a PanelRow. See https://github.com/WordPress/gutenberg/pull/4564 //el( PanelRow, {}, [ el( SelectControl, { - label: data.l10n['groups_label'], + label: __( 'From which speaker groups?', 'wordcamporg' ), value: props.attributes['groups'], options: data.options['groups'], multiple: true, @@ -106,7 +113,7 @@ registerBlockType( 'wordcamp/speakers', { whichControls.push( el( PanelRow, {}, [ el( CheckboxControl, { - label: data.l10n['show_all_posts_label'], + label: __( 'Show all', 'wordcamporg' ), checked: props.attributes['show_all_posts'], onChange: ( value ) => { props.setAttributes( { 'show_all_posts': value } ); }, } ), @@ -118,7 +125,7 @@ registerBlockType( 'wordcamp/speakers', { // Some controls currently have broken layout within a PanelRow. See https://github.com/WordPress/gutenberg/pull/4564 //el( PanelRow, {}, [ el( RangeControl, { - label: data.l10n['posts_per_page_label'], + label: __( 'Number to show', 'wordcamporg' ), value: props.attributes['posts_per_page'], min: schema['posts_per_page'].minimum, max: schema['posts_per_page'].maximum, @@ -134,7 +141,7 @@ registerBlockType( 'wordcamp/speakers', { // Some controls currently have broken layout within a PanelRow. See https://github.com/WordPress/gutenberg/pull/4564 //el( PanelRow, {}, [ el( SelectControl, { - label: data.l10n['sort_label'], + label: __( 'Sort by', 'wordcamporg' ), value: props.attributes['sort'], options: data.options['sort'], onChange: ( value ) => { props.setAttributes( { 'sort': value } ); }, @@ -145,8 +152,8 @@ registerBlockType( 'wordcamp/speakers', { displayControls.push( el( PanelRow, {}, [ el( CheckboxControl, { - label: data.l10n['speaker_link_label'], - help: data.l10n['speaker_link_help'], + label: __( 'Link titles to single posts', 'wordcamporg' ), + help: __( 'These will not appear in the block preview.', 'wordcamporg' ), checked: props.attributes['speaker_link'], onChange: ( value ) => { props.setAttributes( { 'speaker_link': value } ); }, } ), @@ -156,7 +163,7 @@ registerBlockType( 'wordcamp/speakers', { displayControls.push( el( PanelRow, {}, [ el( CheckboxControl, { - label: data.l10n['show_avatars_label'], + label: __( 'Show avatars', 'wordcamporg' ), checked: props.attributes['show_avatars'], onChange: ( value ) => { props.setAttributes( { 'show_avatars': value } ); }, } ), @@ -168,8 +175,8 @@ registerBlockType( 'wordcamp/speakers', { // Some controls currently have broken layout within a PanelRow. See https://github.com/WordPress/gutenberg/pull/4564 //el( PanelRow, {}, [ el( RangeControl, { - label: data.l10n['avatar_size_label'], - help: data.l10n['avatar_size_help'], + label: __( 'Avatar size (px)', 'wordcamporg' ), + help: __( 'Height and width in pixels.', 'wordcamporg' ), value: props.attributes['avatar_size'], min: schema['avatar_size'].minimum, max: schema['avatar_size'].maximum, @@ -189,14 +196,14 @@ registerBlockType( 'wordcamp/speakers', { el( InspectorControls, {}, [ el( PanelBody, { - title: data.l10n['panel_which_title'], + title: __( 'Which Speakers?', 'wordcamporg' ), initialOpen: true, }, whichControls ), el( PanelBody, { - title: data.l10n['panel_display_title'], + title: __( 'Speaker Display', 'wordcamporg' ), initialOpen: false, }, displayControls diff --git a/blocks.php b/blocks.php index 04c1944..f0e83f0 100644 --- a/blocks.php +++ b/blocks.php @@ -48,15 +48,21 @@ function enqueue_assets() { wp_enqueue_script( 'wordcamp-blocks', plugins_url( 'assets/blocks.js', __FILE__ ), - array( 'wp-blocks', 'wp-element', 'wp-components', 'wp-editor' ), + array( 'wp-blocks', 'wp-element', 'wp-components', 'wp-editor', 'wp-i18n' ), filemtime( plugin_dir_path( __FILE__ ) . 'assets/blocks.js' ), false ); + $data = [ + 'l10n' => gutenberg_get_jed_locale_data( 'wordcamporg' ), + ]; + /** + * Filter: Add/modify data sent to WordCamp Blocks JS scripts. * + * @param array $data Associative multidimensional array of data. */ - $data = apply_filters( 'wordcamp_blocks_script_data', [] ); + $data = apply_filters( 'wordcamp_blocks_script_data', $data ); wp_add_inline_script( 'wordcamp-blocks', diff --git a/includes/speakers.php b/includes/speakers.php index 9427d57..2012a51 100644 --- a/includes/speakers.php +++ b/includes/speakers.php @@ -32,7 +32,6 @@ function init() { */ function add_script_data( array $data ) { $data['speakers'] = [ - 'l10n' => get_l10n_strings(), 'schema' => get_attributes_schema(), 'options' => array( 'sort' => get_sort_options(), @@ -81,30 +80,6 @@ function render( $attributes ) { return $wcpt_plugin->shortcode_speakers( $attributes, '' ); } -/** - * Get the translated strings for localizing the JS. - * - * @return array - */ -function get_l10n_strings() { - return array( - 'block_label' => __( 'Speakers', 'wordcamporg' ), - 'block_description' => __( 'Add a list of speakers.' ), - 'panel_which_title' => __( 'Which Speakers?', 'wordcamporg' ), - 'track_label' => __( 'From which session tracks?', 'wordcamporg' ), - 'groups_label' => __( 'From which speaker groups?', 'wordcamporg' ), - 'show_all_posts_label' => __( 'Show all', 'wordcamporg' ), - 'posts_per_page_label' => __( 'Number to show', 'wordcamporg' ), - 'sort_label' => __( 'Sort by', 'wordcamporg' ), - 'panel_display_title' => __( 'Speaker Display', 'wordcamporg' ), - 'speaker_link_label' => __( 'Link titles to single posts', 'wordcamporg' ), - 'speaker_link_help' => __( 'These will not appear in the block preview.', 'wordcamporg' ), - 'show_avatars_label' => __( 'Show avatars', 'wordcamporg' ), - 'avatar_size_label' => __( 'Avatar size (px)', 'wordcamporg' ), - 'avatar_size_help' => __( 'Height and width in pixels.', 'wordcamporg' ), - ); -} - /** * Get the schema for the block's attributes. * diff --git a/l10n.php b/l10n.php new file mode 100644 index 0000000..8d06494 --- /dev/null +++ b/l10n.php @@ -0,0 +1,46 @@ +