├── .gitattributes ├── .github ├── CODEOWNERS └── workflows │ └── code-linting.yml ├── .gitignore ├── .wordpress-org ├── banner-1544x500.png ├── banner-772x250.png ├── icon-128x128.png └── icon-256x256.png ├── LICENSE ├── README.md ├── block-pattern-explorer.php ├── build ├── block-pattern-explorer-editor-styles.asset.php ├── block-pattern-explorer-editor.asset.php ├── block-pattern-explorer-editor.js └── style-block-pattern-explorer-editor-styles.css ├── composer.json ├── composer.lock ├── includes ├── add-pattern-category-type-support.php ├── class-bpe-block-pattern-category-types-registry.php ├── class-bpe-pattern-category-types-rest-controller.php └── core │ └── add-pattern-category-type-support.php ├── package-lock.json ├── package.json ├── phpcs.xml ├── readme.txt ├── src ├── core-components │ ├── inserter-listbox │ │ ├── context.js │ │ └── index.js │ └── no-results.js ├── core-hooks │ ├── use-insertion-point.js │ └── use-patterns-state.js ├── index.js ├── pattern-explorer.js ├── preview │ ├── header.js │ ├── index.js │ ├── pattern-list.js │ └── pattern.js ├── sidebar.js └── style.scss └── webpack.config.js /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @wpengine/developer-relations -------------------------------------------------------------------------------- /.github/workflows/code-linting.yml: -------------------------------------------------------------------------------- 1 | name: Code Linting - PHP 2 | 3 | on: 4 | pull_request: 5 | branches: [trunk] 6 | push: 7 | branches: [trunk] 8 | 9 | jobs: 10 | phpcs_check: 11 | name: PHPCS check 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout 15 | uses: actions/checkout@5a4ac9002d0be2fb38bd78e4b4dbde5606d7042f # v2.3.4 16 | - name: Setup PHP 17 | uses: shivammathur/setup-php@a7f90656b3be3996d1ec5501e8e25d5d35aa9bb2 # v2.15.0 18 | with: 19 | php-version: 7.4 20 | - name: Get composer cache directory 21 | id: composer-cache 22 | run: | 23 | echo "::set-output name=dir::$(composer config cache-files-dir)" 24 | - name: Cache composer dependencies 25 | uses: actions/cache@c64c572235d810460d0d6876e9c705ad5002b353 # v2.1.6 26 | with: 27 | path: ${{ steps.composer-cache.outputs.dir }} 28 | key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} 29 | restore-keys: | 30 | ${{ runner.os }}-composer- 31 | - name: Install composer packages 32 | run: composer install --no-progress 33 | - name: Check PHP coding standards using PHPCS 34 | run: composer lint -- --runtime-set ignore_warnings_on_exit true --runtime-set testVersion 5.8- -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled source # 2 | ################### 3 | *.com 4 | *.class 5 | *.dll 6 | *.exe 7 | *.o 8 | *.so 9 | 10 | # Packages # 11 | ############ 12 | # It's better to unpack these files and commit the raw source 13 | # git has its own built in compression methods. 14 | *.7z 15 | *.dmg 16 | *.gz 17 | *.iso 18 | *.jar 19 | *.rar 20 | *.tar 21 | *.zip 22 | 23 | # Logs and databases # 24 | ###################### 25 | logs 26 | *.log 27 | *.sql 28 | *.sqlite 29 | 30 | # OS generated files # 31 | ###################### 32 | .DS_Store 33 | .DS_Store? 34 | ._* 35 | .Spotlight-V100 36 | .Trashes 37 | ehthumbs.db 38 | Thumbs.db 39 | 40 | # NPM # 41 | ####### 42 | node_modules/ 43 | 44 | # Composer # 45 | ############ 46 | vendor/ 47 | -------------------------------------------------------------------------------- /.wordpress-org/banner-1544x500.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wpengine/block-pattern-explorer/214f662ea28acd007d4b1036c53bcfdf42f5f8f5/.wordpress-org/banner-1544x500.png -------------------------------------------------------------------------------- /.wordpress-org/banner-772x250.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wpengine/block-pattern-explorer/214f662ea28acd007d4b1036c53bcfdf42f5f8f5/.wordpress-org/banner-772x250.png -------------------------------------------------------------------------------- /.wordpress-org/icon-128x128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wpengine/block-pattern-explorer/214f662ea28acd007d4b1036c53bcfdf42f5f8f5/.wordpress-org/icon-128x128.png -------------------------------------------------------------------------------- /.wordpress-org/icon-256x256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wpengine/block-pattern-explorer/214f662ea28acd007d4b1036c53bcfdf42f5f8f5/.wordpress-org/icon-256x256.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Block Pattern Explorer 2 | 3 | [![License](https://img.shields.io/badge/license-GPL--2.0%2B-green.svg)](https://github.com/wpengine/block-pattern-explorer/blob/master/LICENSE.txt) 4 | 5 | ![Block Pattern Explorer](https://user-images.githubusercontent.com/4832319/149385531-404f1d6f-4401-4786-9bfe-50b0be212adc.png) 6 | 7 | The Block Pattern Explorer is an experimental WordPress plugin based **heavily** on the work currently being done in [Gutenberg](https://github.com/WordPress/gutenberg). 8 | 9 | The purpose of this project is to isolate the pattern explorer into a standalone plugin that WordPress users/developers can interact with immediately, provide feedback on, and begin implementing into their own websites. Ideally, this initiative will also help inform the direction of core development. 10 | 11 | Once the pattern explorer is fully integrated into WordPress proper, this project will be sunsetted in favor of the core offering. Below is a list of current pull requests that are related to the Block Pattern Explorer in Gutenberg. 12 | 13 | - [#35006](https://github.com/WordPress/gutenberg/pull/35006) 14 | - [#35773](https://github.com/WordPress/gutenberg/pull/35773) 15 | 16 | ## Requirements 17 | 18 | - WordPress 5.8+ 19 | - [Gutenberg](https://github.com/WordPress/gutenberg) plugin (Not required if using WordPress 5.9+) 20 | - PHP 7.1+ 21 | 22 | ## Development 23 | 24 | 1. Set up a local WordPress development environment, we recommend using [Local](https://localwp.com/). 25 | 2. Clone / download this repository into the `wp-content/plugins` folder. 26 | 3. Navigate to the `wp-content/plugins/block-pattern-explorer` folder in the command line. 27 | 4. Run `npm install` to install the plugin's dependencies within a `/node_modules/` folder. 28 | 5. Run `composer install` to install the additional WordPress composer tools within a `/vendor/` folder. 29 | 6. Run `npm run start` to compile and watch source files for changes while developing. 30 | 31 | Refer to `package.json` and `composer.json` for additional commands. 32 | -------------------------------------------------------------------------------- /block-pattern-explorer.php: -------------------------------------------------------------------------------- 1 | array(), 72 | 'version' => BPE_VERSION, 73 | ); 74 | } 75 | 76 | /** 77 | * Load the plugin language file. 78 | * 79 | * @since 0.1.0 80 | * @return void 81 | */ 82 | function load_textdomain() { 83 | load_plugin_textdomain( 'block-pattern-explorer', false, BPE_ABSPATH . 'languages' ); 84 | } 85 | add_action( 'init', __NAMESPACE__ . '\load_textdomain' ); 86 | 87 | /** 88 | * Enqueue the editor scripts translations. 89 | * 90 | * @since 0.1.0 91 | * @return void 92 | */ 93 | function enqueue_script_translations() { 94 | wp_set_script_translations( 95 | 'block-pattern-explorer-editor-scripts', 96 | 'block-pattern-explorer', 97 | BPE_ABSPATH . 'languages' 98 | ); 99 | } 100 | add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\enqueue_script_translations' ); 101 | 102 | // Custom pattern category type implementation. 103 | require_once BPE_ABSPATH . '/includes/add-pattern-category-type-support.php'; 104 | 105 | // (Experimental) Will be used once Block Editor settings are filterable in core. 106 | // include_once BPE_ABSPATH . '/includes/core/add-pattern-category-type-support.php'; 107 | -------------------------------------------------------------------------------- /build/block-pattern-explorer-editor-styles.asset.php: -------------------------------------------------------------------------------- 1 | array(), 'version' => 'cddfd4692978207258dadf42142f9888'); -------------------------------------------------------------------------------- /build/block-pattern-explorer-editor.asset.php: -------------------------------------------------------------------------------- 1 | array('lodash', 'wp-a11y', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-element', 'wp-i18n', 'wp-notices', 'wp-primitives'), 'version' => '8e154aca5638c6dd0aad10b3072f2d02'); -------------------------------------------------------------------------------- /build/block-pattern-explorer-editor.js: -------------------------------------------------------------------------------- 1 | !function(){var e={184:function(e,t){var r;!function(){"use strict";var n={}.hasOwnProperty;function a(){for(var e=[],t=0;ta.map((e=>e.name))),[a]),u="block-pattern-explorer__sidebar";return(0,e.createElement)("div",{className:u},(0,e.createElement)("div",{className:`${u}__search`},(0,e.createElement)(o.SearchControl,{value:i,onChange:c,label:(0,n.__)("Search patterns","block-pattern-explorer")})),a.map((t=>{const n=r.filter((e=>{var r;return"uncategorized"===t.name?!(null!=e&&e.categoryTypes)||e.categoryTypes.every((e=>!p.includes(e))):null===(r=e.categoryTypes)||void 0===r?void 0:r.includes(t.name)}));return n.length?(0,e.createElement)("div",{key:t,className:`${u}__category-type`},null!=t&&t.hideLabelFromVision?(0,e.createElement)(o.VisuallyHidden,{as:"h2"},t.label):(0,e.createElement)("h2",{className:`${u}__category-type__title`},t.label),(0,e.createElement)("div",{className:`${u}__category-type__categories`},(0,e.createElement)(o.MenuGroup,{className:`${u}__categories-list`},n.map((t=>(0,e.createElement)(o.MenuItem,{key:t.name,label:t.label,className:`${u}__categories-list__item`,isPressed:!i&&t.name===l,onClick:()=>function(e){s(e),c("")}(t.name)},t.label)))))):null})))}var c=window.wp.compose,p=window.wp.a11y,u=r(184),d=r.n(u),m=(0,e.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,e.createElement)(l.Path,{d:"M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"})),v=(0,e.createElement)(l.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,e.createElement)(l.Path,{d:"M5 4v11h14V4H5zm3 15.8h8v-1.5H8v1.5z"})),g=(0,e.createElement)(l.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,e.createElement)(l.Path,{d:"M6 5.5h3a.5.5 0 01.5.5v3a.5.5 0 01-.5.5H6a.5.5 0 01-.5-.5V6a.5.5 0 01.5-.5zM4 6a2 2 0 012-2h3a2 2 0 012 2v3a2 2 0 01-2 2H6a2 2 0 01-2-2V6zm11-.5h3a.5.5 0 01.5.5v3a.5.5 0 01-.5.5h-3a.5.5 0 01-.5-.5V6a.5.5 0 01.5-.5zM13 6a2 2 0 012-2h3a2 2 0 012 2v3a2 2 0 01-2 2h-3a2 2 0 01-2-2V6zm5 8.5h-3a.5.5 0 00-.5.5v3a.5.5 0 00.5.5h3a.5.5 0 00.5-.5v-3a.5.5 0 00-.5-.5zM15 13a2 2 0 00-2 2v3a2 2 0 002 2h3a2 2 0 002-2v-3a2 2 0 00-2-2h-3zm-9 1.5h3a.5.5 0 01.5.5v3a.5.5 0 01-.5.5H6a.5.5 0 01-.5-.5v-3a.5.5 0 01.5-.5zM4 15a2 2 0 012-2h3a2 2 0 012 2v3a2 2 0 01-2 2H6a2 2 0 01-2-2v-3z",fillRule:"evenodd",clipRule:"evenodd"}));function h(t){const{viewportWidth:r,setViewportWidth:a,isGrid:l,setIsGrid:s,shownPatterns:i,searchValue:c,isLoading:p}=t,u=[{label:(0,n.__)("Desktop","block-pattern-explorer"),slug:"desktop",value:1300,active:1300===r},{label:(0,n.__)("Tablet","block-pattern-explorer"),slug:"tablet",value:778,active:778===r},{label:(0,n.__)("Mobile","block-pattern-explorer"),slug:"mobile",value:358,active:358===r}],h="block-pattern-explorer__preview-header";return(0,e.createElement)("div",{className:h},(0,e.createElement)("div",{className:`${h}__search-results`},p&&(0,e.createElement)(o.Spinner,null),c&&c.length>1&&(0,n.sprintf)(// translators: %1$d: Number of patterns. %2$s: The search input. 2 | (0,n._n)('%1$d search result for "%2$s"','%1$d search results for "%2$s"',i.length,"block-pattern-explorer"),i.length,c)),(0,e.createElement)("div",{className:`${h}__controls`},(0,e.createElement)(o.DropdownMenu,{icon:"",text:(0,n.__)("Preview","block-pattern-explorer"),className:"viewport-toggle",toggleProps:{isTertiary:!0},popoverProps:{focusOnMount:"container",position:"bottom left"}},(()=>(0,e.createElement)(o.MenuGroup,null,u.map((t=>(0,e.createElement)(o.MenuItem,{key:t.slug,className:d()({disabled:!t.active}),icon:t.active?m:"",onClick:()=>function(e){e.active||a(e.value)}(t)},t.label)))))),(0,e.createElement)(o.Button,{label:(0,n.__)("Individual Pattern","block-pattern-explorer"),icon:v,isPressed:!l,onClick:()=>s(!l)}),(0,e.createElement)(o.Button,{label:(0,n.__)("Grid View","block-pattern-explorer"),icon:g,isPressed:l,onClick:()=>s(!l)})))}function y(){return y=Object.assign||function(e){for(var t=1;t(0,E.cloneBlock)(e)))),p&&(0,a.dispatch)("core/block-editor").removeBlock(u),g((0,n.sprintf)(// Translators: Name of the pattern being inserted. 3 | (0,n.__)('Block pattern "%s" inserted.',"block-pattern-explorer"),r.title),{type:"snackbar"})}const _="block-pattern-explorer__preview-pattern-list__item";return(0,e.createElement)("div",{className:_,"aria-label":r.title,"aria-describedby":null!=r&&r.description?h:void 0},(0,e.createElement)(o.__unstableCompositeItem,y({role:"option",as:"div"},i,{className:`${_}-preview`,onClick:b}),(0,e.createElement)(x.BlockPreview,{blocks:v,viewportWidth:s})),(0,e.createElement)("div",{className:`${_}-actions`},(0,e.createElement)("div",{className:`${_}-title`},d),!!r.description&&(0,e.createElement)(o.VisuallyHidden,{id:h},r.description),(0,e.createElement)(o.Button,{isSecondary:!0,onClick:b},(0,n.__)("Add Pattern","block-pattern-explorer"))))}function P(r){const{isGrid:l,isLoading:s,searchValue:i,shownPatterns:c,viewportWidth:u}=r,[m,h]=function(r){let{rootClientId:o="",insertionIndex:l,clientId:s,isAppender:i,onSelect:c,shouldFocusBlock:u=!0}={shouldFocusBlock:!0};const{getSelectedBlock:d}=(0,a.useSelect)(x.store),{destinationRootClientId:m,destinationIndex:v}=(0,a.useSelect)((e=>{const{getSelectedBlockClientId:t,getBlockRootClientId:r,getBlockIndex:n,getBlockOrder:a}=e(x.store),c=t();let p,u=o;return void 0!==l?p=l:s?p=n(s,u):!i&&c?(u=r(c),p=n(c,u)+1):p=a(u).length,{destinationRootClientId:u,destinationIndex:p}}),[o,l,s,i]),{replaceBlocks:g,insertBlocks:h,showInsertionPoint:y,hideInsertionPoint:b}=(0,a.useDispatch)(x.store),_=(0,e.useCallback)((function(e,r){let a=arguments.length>2&&void 0!==arguments[2]&&arguments[2];const o=d();!i&&o&&(0,E.isUnmodifiedDefaultBlock)(o)?g(o.clientId,e,null,u||a?0:null,r):h(e,v,m,!0,u||a?0:null,r);const l=(0,n.sprintf)(// translators: %d: the name of the block that has been added 4 | (0,n._n)("%d block added.","%d blocks added.",(0,t.castArray)(e).length),(0,t.castArray)(e).length);(0,p.speak)(l),c&&c()}),[i,d,g,h,m,v,c,u]),w=(0,e.useCallback)((e=>{e?y(m,v):b()}),[y,b,m,v]);return[m,_,w]}(),b=(0,t.isEmpty)(c)&&!i&&!s,_=(0,t.isEmpty)(c)&&i,k=!b&&!_,P=!k&&_?(0,n.__)("No search results found.","block-pattern-explorer"):(0,n.__)("No patterns were found for this category.","block-pattern-explorer"),S=(0,o.__unstableUseCompositeState)();return(0,e.createElement)(f,null,!k&&(0,e.createElement)(w,{icon:l?g:v,label:P}),k&&(0,e.createElement)(o.__unstableComposite,y({},S,{role:"listbox",className:d()("block-pattern-explorer__preview-pattern-list",{"is-grid":l,"is-loading":s,"preview-tablet":778===u,"preview-mobile":358===u}),"aria-label":(0,n.__)("Patterns","block-pattern-explorer")}),c.map((t=>(0,e.createElement)(C,{key:t.name,pattern:t,onInsertPattern:h,viewportWidth:u,composite:S})))))}function S(r){const{allPatterns:a,patternCategories:o,selectedCategory:l,searchValue:s}=r,[i,u]=(0,e.useState)(1300),[d,m]=(0,e.useState)(!0),v=(0,c.useDebounce)(p.speak,500),g=(0,e.useMemo)((()=>o.map((e=>e.name))),[o]),y=(0,e.useMemo)((()=>{let e=[];const r=s&&s.length>1;return r&&(e=a.filter((e=>{const r=s.toLowerCase();if(e.title.toLowerCase().includes(r))return!0;if(null!=e&&e.keywords&&!(0,t.isEmpty)(null==e?void 0:e.keywords)){const n=e.keywords.filter((e=>e.includes(r)));return!(0,t.isEmpty)(n)}return!1}))),r||(e=a.filter((e=>{var t,r;return"uncategorized"===l?!(null!==(r=e.categories)&&void 0!==r&&r.length)||e.categories.every((e=>!g.includes(e))):null===(t=e.categories)||void 0===t?void 0:t.includes(l)}))),e}),[s,l,a]),b=(0,c.useAsyncList)(y,{step:3}),_=b.length{if(!s||_)return;const e=y.length,t=(0,n.sprintf)( 5 | /* translators: %d: number of patterns found. */ 6 | (0,n._n)("%d pattern found.","%d patterns found.",e,"block-pattern-explorer"),e);v(t)}),[s,v]),(0,e.createElement)("div",{className:"block-pattern-explorer__preview"},(0,e.createElement)(h,{viewportWidth:i,setViewportWidth:u,isGrid:d,setIsGrid:m,shownPatterns:b,searchValue:s,isLoading:_}),(0,e.createElement)(P,{viewportWidth:i,isGrid:d,shownPatterns:b,searchValue:s,isLoading:_}))}function V(t){const{allPatterns:r,initialCategory:n,patternCategories:a,patternCategoryTypes:o}=t,[l,s]=(0,e.useState)(null==n?void 0:n.name),[c,p]=(0,e.useState)("");return(0,e.createElement)("div",{className:"block-pattern-explorer"},(0,e.createElement)(i,{patternCategories:a,patternCategoryTypes:o,selectedCategory:l,setSelectedCategory:s,searchValue:c,setSearchValue:p}),(0,e.createElement)(S,{allPatterns:r,patternCategories:a,selectedCategory:l,searchValue:c}))}var z=window.wp.notices;function B(){const[r,l]=(0,e.useState)(!1),[i,c,p]=((r,o)=>{const{patterns:l,patternCategories:s,patternCategoryTypes:i}=(0,a.useSelect)((e=>{var t;const{__experimentalGetAllowedPatterns:r,getSettings:n}=e(x.store),{getEntityRecord:a}=e("core"),l=a("block-pattern-explorer/v1","patternCategoryTypes");return{patterns:r(o),patternCategories:n().__experimentalBlockPatternCategories,patternCategoryTypes:null!==(t=null==l?void 0:l.patternCategoryTypes)&&void 0!==t?t:"fetching"}}),[o]),{createSuccessNotice:c}=(0,a.useDispatch)(z.store);return[l,s,i,(0,e.useCallback)(((e,a)=>{r((0,t.map)(a,(e=>(0,E.cloneBlock)(e))),e.name),c((0,n.sprintf)( 7 | /* translators: %s: block pattern title. */ 8 | (0,n.__)('Block pattern "%s" inserted.',"block-pattern-explorer"),e.title),{type:"snackbar"})}),[])]})(),u="fetching"===p?[]:p,d=(0,e.useCallback)((e=>!(!e.categories||!e.categories.length)&&e.categories.some((e=>c.some((t=>t.name===e))))),[c]),m=(0,e.useCallback)((e=>!(!e.categoryTypes||!e.categoryTypes.length)&&e.categoryTypes.some((e=>u.some((t=>t.name===e))))),[u]),v=(0,e.useMemo)((()=>{const e=c.filter((e=>i.some((t=>{var r;return null===(r=t.categories)||void 0===r?void 0:r.includes(e.name)})))).sort(((e,t)=>{let{name:r}=e,{name:n}=t;return[r,n].includes("featured")?"featured"===r?-1:1:0}));return i.some((e=>!d(e)))&&!e.find((e=>"uncategorized"===e.name))&&e.push({name:"uncategorized",label:(0,n.__)("Uncategorized","block-pattern-explorer")}),e}),[i,c]),g=(0,e.useMemo)((()=>{const e=u.filter((e=>v.some((t=>{var r;return null===(r=t.categoryTypes)||void 0===r?void 0:r.includes(e.name)}))));return v.some((e=>!m(e)))&&!e.find((e=>"uncategorized"===e.name))&&e.unshift({name:"uncategorized",label:(0,n.__)("Uncategorized","block-pattern-explorer"),hideLabelFromVision:!0}),e}),[v,u]),h=v.filter((e=>{var t,r;return"uncategorized"===g[0].name?!e.categoryTypes||!e.categoryTypes.length||(null===(r=e.categoryTypes)||void 0===r?void 0:r.includes("uncategorized")):null===(t=e.categoryTypes)||void 0===t?void 0:t.includes(g[0].name)}))[0];return(0,t.isEmpty)(i)?null:(0,e.createElement)(e.Fragment,null,(0,e.createElement)(o.Button,{icon:s,label:(0,n.__)("Explore Patterns","block-pattern-explorer"),onClick:()=>l(!0)}),r&&(0,e.createElement)(o.Modal,{title:(0,n.__)("Patterns","block-pattern-explorer"),closeLabel:(0,n.__)("Close","block-pattern-explorer"),onRequestClose:()=>l(!1),className:"block-pattern-explorer__modal",isFullScreen:!0},(0,e.createElement)(V,{allPatterns:i,initialCategory:h,patternCategories:v,patternCategoryTypes:g,categoryTypes:!0})))}(0,a.subscribe)((()=>{document.querySelector("#block-pattern-explorer")||wp.domReady((()=>{const t=document.querySelector(".edit-post-header-toolbar__left");if(!t)return;const r=document.createElement("div");r.id="block-pattern-explorer",t.appendChild(r),(0,e.render)((0,e.createElement)(B,null),document.getElementById("block-pattern-explorer"))}))})),(0,a.dispatch)("core").addEntities([{label:(0,n.__)("Pattern Category Types","block-pattern-explorer"),kind:"block-pattern-explorer/v1",name:"patternCategoryTypes",baseURL:"/block-pattern-explorer/v1/pattern-category-types"}])}()}(); -------------------------------------------------------------------------------- /build/style-block-pattern-explorer-editor-styles.css: -------------------------------------------------------------------------------- 1 | .block-pattern-explorer__modal .components-modal__content{flex:1;overflow:auto;padding:0}.block-pattern-explorer__modal .components-modal__content:before{margin-bottom:0}.block-pattern-explorer{align-items:stretch;display:flex;height:100%}.block-pattern-explorer.is-error{display:block;margin:24px 32px}.block-pattern-explorer .components-notice{margin:0}.block-pattern-explorer .components-notice .components-notice__content{margin-bottom:8px;margin-top:8px}.block-pattern-explorer .components-notice.is-error{background-color:#f8ebea}.block-pattern-explorer .components-notice p{margin:12px 0 0}.block-pattern-explorer .components-notice p:first-child{margin-top:0}.block-pattern-explorer .block-pattern-explorer__preview{display:flex;flex-direction:column;flex-shrink:0;overflow:auto;padding:32px 32px 100px;width:calc(100% - 281px)}.block-pattern-explorer .block-pattern-explorer__preview .block-editor-inserter__no-results{align-items:center;display:flex;height:100%;justify-content:center}.block-pattern-explorer .block-pattern-explorer__preview-header{align-items:center;display:inline-flex;justify-content:space-between;margin-bottom:2rem}.block-pattern-explorer .block-pattern-explorer__preview-header__search-results{display:inline-flex}.block-pattern-explorer .block-pattern-explorer__preview-header__search-results .components-spinner{margin:0 12px 0 0}.block-pattern-explorer .block-pattern-explorer__preview-header__controls{display:inline-flex}.block-pattern-explorer .block-pattern-explorer__preview-header__controls .viewport-toggle{margin-right:6px}.block-pattern-explorer .block-pattern-explorer__preview-header__controls>button{margin-left:6px}.block-pattern-explorer .block-pattern-explorer__preview-header .components-popover__content{margin-right:48px!important;margin-top:-50px}.block-pattern-explorer .block-pattern-explorer__preview-pattern-list{width:100%}.block-pattern-explorer .block-pattern-explorer__preview-pattern-list>div{margin-bottom:2rem}.block-pattern-explorer .block-pattern-explorer__preview-pattern-list.preview-tablet>div{margin:0 auto 4rem;max-width:790px}.block-pattern-explorer .block-pattern-explorer__preview-pattern-list.preview-mobile>div{margin:0 auto 4rem;max-width:358px}.block-pattern-explorer .block-pattern-explorer__preview-pattern-list.is-grid{grid-gap:32px;-ms-grid-columns:1fr;display:-ms-grid;display:grid;grid-template:inherit;grid-template-columns:repeat(1,1fr)}@media(min-width:1080px){.block-pattern-explorer .block-pattern-explorer__preview-pattern-list.is-grid{-ms-grid-columns:(1fr)[2];grid-template-columns:repeat(2,1fr)}}@media(min-width:1440px){.block-pattern-explorer .block-pattern-explorer__preview-pattern-list.is-grid{-ms-grid-columns:(1fr)[3];grid-template-columns:repeat(3,1fr)}}.block-pattern-explorer .block-pattern-explorer__preview-pattern-list.is-grid>div{margin-bottom:0}.block-pattern-explorer .block-pattern-explorer__preview-pattern-list.is-grid.preview-mobile>div,.block-pattern-explorer .block-pattern-explorer__preview-pattern-list.is-grid.preview-tablet>div{margin:0}.block-pattern-explorer .block-pattern-explorer__preview-pattern-list.is-grid .block-editor-block-preview__container{max-height:400px;overflow:scroll}.block-pattern-explorer .block-pattern-explorer__preview-pattern-list.no-results{align-items:center;display:flex;height:100%;justify-content:center}.block-pattern-explorer .block-pattern-explorer__preview-pattern-list__item{border:1px solid #ddd;border-radius:2px;display:flex;flex-direction:column;justify-content:space-between;position:relative;transition:all .05s ease-in-out;width:100%}.block-pattern-explorer .block-pattern-explorer__preview-pattern-list__item:hover{border-color:var(--wp-admin-theme-color)}.block-pattern-explorer .block-pattern-explorer__preview-pattern-list__item-preview{align-items:center;background:#f0f0f0;cursor:pointer;display:flex;flex-grow:1;min-height:200px}.block-pattern-explorer .block-pattern-explorer__preview-pattern-list__item-preview img{width:100%}.block-pattern-explorer .block-pattern-explorer__preview-pattern-list__item-actions{align-items:center;background:#fff;border-top:1px solid #ddd;display:flex;justify-content:space-between;padding:10px}.block-pattern-explorer .block-pattern-explorer__preview-pattern-list__item-title{font-size:12px;padding:6px;text-align:center}.block-pattern-explorer .block-pattern-explorer__preview-loading{display:flex;justify-content:center;margin:64px 0;width:100%}.block-pattern-explorer .block-pattern-explorer__sidebar{border-right:1px solid #ddd;display:flex;flex-direction:column;flex-shrink:0;overflow-y:scroll;padding:32px;width:280px}.block-pattern-explorer .block-pattern-explorer__sidebar__search{margin-bottom:16px}.block-pattern-explorer .block-pattern-explorer__sidebar__search .components-base-control__field{margin-bottom:0}.block-pattern-explorer .block-pattern-explorer__sidebar__category-type__title{color:#757575;font-size:11px;font-weight:500;margin:0;padding:16px 12px 0;text-transform:uppercase}.block-pattern-explorer .block-pattern-explorer__sidebar__category-type__categories{padding:16px 0} 2 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wpengine/block-pattern-explorer", 3 | "type": "wordpress-plugin", 4 | "description": "An experimental plugin to preview and insert block patterns in the Block Editor.", 5 | "homepage": "https://github.com/wpengine/block-pattern-explorer", 6 | "license": "GPL-2.0-or-later", 7 | "require": { 8 | "php": ">=5.6" 9 | }, 10 | "require-dev": { 11 | "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", 12 | "squizlabs/php_codesniffer": "^3.4.2", 13 | "phpcompatibility/php-compatibility": "^9.2.0", 14 | "phpcompatibility/phpcompatibility-wp": "^2.1", 15 | "wp-coding-standards/wpcs": "^2.1.1" 16 | }, 17 | "scripts": { 18 | "lint": "@php ./vendor/bin/phpcs", 19 | "lint-fix": "@php ./vendor/bin/phpcbf" 20 | }, 21 | "config": { 22 | "allow-plugins": { 23 | "dealerdirect/phpcodesniffer-composer-installer": true 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", 5 | "This file is @generated automatically" 6 | ], 7 | "content-hash": "f1208c6a6b41cd7604bb032736117d31", 8 | "packages": [], 9 | "packages-dev": [ 10 | { 11 | "name": "dealerdirect/phpcodesniffer-composer-installer", 12 | "version": "v0.7.1", 13 | "source": { 14 | "type": "git", 15 | "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", 16 | "reference": "fe390591e0241955f22eb9ba327d137e501c771c" 17 | }, 18 | "dist": { 19 | "type": "zip", 20 | "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/fe390591e0241955f22eb9ba327d137e501c771c", 21 | "reference": "fe390591e0241955f22eb9ba327d137e501c771c", 22 | "shasum": "" 23 | }, 24 | "require": { 25 | "composer-plugin-api": "^1.0 || ^2.0", 26 | "php": ">=5.3", 27 | "squizlabs/php_codesniffer": "^2.0 || ^3.0 || ^4.0" 28 | }, 29 | "require-dev": { 30 | "composer/composer": "*", 31 | "phpcompatibility/php-compatibility": "^9.0", 32 | "sensiolabs/security-checker": "^4.1.0" 33 | }, 34 | "type": "composer-plugin", 35 | "extra": { 36 | "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" 37 | }, 38 | "autoload": { 39 | "psr-4": { 40 | "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" 41 | } 42 | }, 43 | "notification-url": "https://packagist.org/downloads/", 44 | "license": [ 45 | "MIT" 46 | ], 47 | "authors": [ 48 | { 49 | "name": "Franck Nijhof", 50 | "email": "franck.nijhof@dealerdirect.com", 51 | "homepage": "http://www.frenck.nl", 52 | "role": "Developer / IT Manager" 53 | } 54 | ], 55 | "description": "PHP_CodeSniffer Standards Composer Installer Plugin", 56 | "homepage": "http://www.dealerdirect.com", 57 | "keywords": [ 58 | "PHPCodeSniffer", 59 | "PHP_CodeSniffer", 60 | "code quality", 61 | "codesniffer", 62 | "composer", 63 | "installer", 64 | "phpcs", 65 | "plugin", 66 | "qa", 67 | "quality", 68 | "standard", 69 | "standards", 70 | "style guide", 71 | "stylecheck", 72 | "tests" 73 | ], 74 | "support": { 75 | "issues": "https://github.com/dealerdirect/phpcodesniffer-composer-installer/issues", 76 | "source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer" 77 | }, 78 | "time": "2020-12-07T18:04:37+00:00" 79 | }, 80 | { 81 | "name": "phpcompatibility/php-compatibility", 82 | "version": "9.3.5", 83 | "source": { 84 | "type": "git", 85 | "url": "https://github.com/PHPCompatibility/PHPCompatibility.git", 86 | "reference": "9fb324479acf6f39452e0655d2429cc0d3914243" 87 | }, 88 | "dist": { 89 | "type": "zip", 90 | "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibility/zipball/9fb324479acf6f39452e0655d2429cc0d3914243", 91 | "reference": "9fb324479acf6f39452e0655d2429cc0d3914243", 92 | "shasum": "" 93 | }, 94 | "require": { 95 | "php": ">=5.3", 96 | "squizlabs/php_codesniffer": "^2.3 || ^3.0.2" 97 | }, 98 | "conflict": { 99 | "squizlabs/php_codesniffer": "2.6.2" 100 | }, 101 | "require-dev": { 102 | "phpunit/phpunit": "~4.5 || ^5.0 || ^6.0 || ^7.0" 103 | }, 104 | "suggest": { 105 | "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically.", 106 | "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." 107 | }, 108 | "type": "phpcodesniffer-standard", 109 | "notification-url": "https://packagist.org/downloads/", 110 | "license": [ 111 | "LGPL-3.0-or-later" 112 | ], 113 | "authors": [ 114 | { 115 | "name": "Wim Godden", 116 | "homepage": "https://github.com/wimg", 117 | "role": "lead" 118 | }, 119 | { 120 | "name": "Juliette Reinders Folmer", 121 | "homepage": "https://github.com/jrfnl", 122 | "role": "lead" 123 | }, 124 | { 125 | "name": "Contributors", 126 | "homepage": "https://github.com/PHPCompatibility/PHPCompatibility/graphs/contributors" 127 | } 128 | ], 129 | "description": "A set of sniffs for PHP_CodeSniffer that checks for PHP cross-version compatibility.", 130 | "homepage": "http://techblog.wimgodden.be/tag/codesniffer/", 131 | "keywords": [ 132 | "compatibility", 133 | "phpcs", 134 | "standards" 135 | ], 136 | "support": { 137 | "issues": "https://github.com/PHPCompatibility/PHPCompatibility/issues", 138 | "source": "https://github.com/PHPCompatibility/PHPCompatibility" 139 | }, 140 | "time": "2019-12-27T09:44:58+00:00" 141 | }, 142 | { 143 | "name": "phpcompatibility/phpcompatibility-paragonie", 144 | "version": "1.3.1", 145 | "source": { 146 | "type": "git", 147 | "url": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie.git", 148 | "reference": "ddabec839cc003651f2ce695c938686d1086cf43" 149 | }, 150 | "dist": { 151 | "type": "zip", 152 | "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityParagonie/zipball/ddabec839cc003651f2ce695c938686d1086cf43", 153 | "reference": "ddabec839cc003651f2ce695c938686d1086cf43", 154 | "shasum": "" 155 | }, 156 | "require": { 157 | "phpcompatibility/php-compatibility": "^9.0" 158 | }, 159 | "require-dev": { 160 | "dealerdirect/phpcodesniffer-composer-installer": "^0.7", 161 | "paragonie/random_compat": "dev-master", 162 | "paragonie/sodium_compat": "dev-master" 163 | }, 164 | "suggest": { 165 | "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", 166 | "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." 167 | }, 168 | "type": "phpcodesniffer-standard", 169 | "notification-url": "https://packagist.org/downloads/", 170 | "license": [ 171 | "LGPL-3.0-or-later" 172 | ], 173 | "authors": [ 174 | { 175 | "name": "Wim Godden", 176 | "role": "lead" 177 | }, 178 | { 179 | "name": "Juliette Reinders Folmer", 180 | "role": "lead" 181 | } 182 | ], 183 | "description": "A set of rulesets for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by the Paragonie polyfill libraries.", 184 | "homepage": "http://phpcompatibility.com/", 185 | "keywords": [ 186 | "compatibility", 187 | "paragonie", 188 | "phpcs", 189 | "polyfill", 190 | "standards" 191 | ], 192 | "support": { 193 | "issues": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie/issues", 194 | "source": "https://github.com/PHPCompatibility/PHPCompatibilityParagonie" 195 | }, 196 | "time": "2021-02-15T10:24:51+00:00" 197 | }, 198 | { 199 | "name": "phpcompatibility/phpcompatibility-wp", 200 | "version": "2.1.3", 201 | "source": { 202 | "type": "git", 203 | "url": "https://github.com/PHPCompatibility/PHPCompatibilityWP.git", 204 | "reference": "d55de55f88697b9cdb94bccf04f14eb3b11cf308" 205 | }, 206 | "dist": { 207 | "type": "zip", 208 | "url": "https://api.github.com/repos/PHPCompatibility/PHPCompatibilityWP/zipball/d55de55f88697b9cdb94bccf04f14eb3b11cf308", 209 | "reference": "d55de55f88697b9cdb94bccf04f14eb3b11cf308", 210 | "shasum": "" 211 | }, 212 | "require": { 213 | "phpcompatibility/php-compatibility": "^9.0", 214 | "phpcompatibility/phpcompatibility-paragonie": "^1.0" 215 | }, 216 | "require-dev": { 217 | "dealerdirect/phpcodesniffer-composer-installer": "^0.7" 218 | }, 219 | "suggest": { 220 | "dealerdirect/phpcodesniffer-composer-installer": "^0.7 || This Composer plugin will sort out the PHP_CodeSniffer 'installed_paths' automatically.", 221 | "roave/security-advisories": "dev-master || Helps prevent installing dependencies with known security issues." 222 | }, 223 | "type": "phpcodesniffer-standard", 224 | "notification-url": "https://packagist.org/downloads/", 225 | "license": [ 226 | "LGPL-3.0-or-later" 227 | ], 228 | "authors": [ 229 | { 230 | "name": "Wim Godden", 231 | "role": "lead" 232 | }, 233 | { 234 | "name": "Juliette Reinders Folmer", 235 | "role": "lead" 236 | } 237 | ], 238 | "description": "A ruleset for PHP_CodeSniffer to check for PHP cross-version compatibility issues in projects, while accounting for polyfills provided by WordPress.", 239 | "homepage": "http://phpcompatibility.com/", 240 | "keywords": [ 241 | "compatibility", 242 | "phpcs", 243 | "standards", 244 | "wordpress" 245 | ], 246 | "support": { 247 | "issues": "https://github.com/PHPCompatibility/PHPCompatibilityWP/issues", 248 | "source": "https://github.com/PHPCompatibility/PHPCompatibilityWP" 249 | }, 250 | "time": "2021-12-30T16:37:40+00:00" 251 | }, 252 | { 253 | "name": "squizlabs/php_codesniffer", 254 | "version": "3.6.2", 255 | "source": { 256 | "type": "git", 257 | "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", 258 | "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a" 259 | }, 260 | "dist": { 261 | "type": "zip", 262 | "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/5e4e71592f69da17871dba6e80dd51bce74a351a", 263 | "reference": "5e4e71592f69da17871dba6e80dd51bce74a351a", 264 | "shasum": "" 265 | }, 266 | "require": { 267 | "ext-simplexml": "*", 268 | "ext-tokenizer": "*", 269 | "ext-xmlwriter": "*", 270 | "php": ">=5.4.0" 271 | }, 272 | "require-dev": { 273 | "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" 274 | }, 275 | "bin": [ 276 | "bin/phpcs", 277 | "bin/phpcbf" 278 | ], 279 | "type": "library", 280 | "extra": { 281 | "branch-alias": { 282 | "dev-master": "3.x-dev" 283 | } 284 | }, 285 | "notification-url": "https://packagist.org/downloads/", 286 | "license": [ 287 | "BSD-3-Clause" 288 | ], 289 | "authors": [ 290 | { 291 | "name": "Greg Sherwood", 292 | "role": "lead" 293 | } 294 | ], 295 | "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", 296 | "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", 297 | "keywords": [ 298 | "phpcs", 299 | "standards" 300 | ], 301 | "support": { 302 | "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", 303 | "source": "https://github.com/squizlabs/PHP_CodeSniffer", 304 | "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" 305 | }, 306 | "time": "2021-12-12T21:44:58+00:00" 307 | }, 308 | { 309 | "name": "wp-coding-standards/wpcs", 310 | "version": "2.3.0", 311 | "source": { 312 | "type": "git", 313 | "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", 314 | "reference": "7da1894633f168fe244afc6de00d141f27517b62" 315 | }, 316 | "dist": { 317 | "type": "zip", 318 | "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/7da1894633f168fe244afc6de00d141f27517b62", 319 | "reference": "7da1894633f168fe244afc6de00d141f27517b62", 320 | "shasum": "" 321 | }, 322 | "require": { 323 | "php": ">=5.4", 324 | "squizlabs/php_codesniffer": "^3.3.1" 325 | }, 326 | "require-dev": { 327 | "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || ^0.6", 328 | "phpcompatibility/php-compatibility": "^9.0", 329 | "phpcsstandards/phpcsdevtools": "^1.0", 330 | "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" 331 | }, 332 | "suggest": { 333 | "dealerdirect/phpcodesniffer-composer-installer": "^0.6 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." 334 | }, 335 | "type": "phpcodesniffer-standard", 336 | "notification-url": "https://packagist.org/downloads/", 337 | "license": [ 338 | "MIT" 339 | ], 340 | "authors": [ 341 | { 342 | "name": "Contributors", 343 | "homepage": "https://github.com/WordPress/WordPress-Coding-Standards/graphs/contributors" 344 | } 345 | ], 346 | "description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress coding conventions", 347 | "keywords": [ 348 | "phpcs", 349 | "standards", 350 | "wordpress" 351 | ], 352 | "support": { 353 | "issues": "https://github.com/WordPress/WordPress-Coding-Standards/issues", 354 | "source": "https://github.com/WordPress/WordPress-Coding-Standards", 355 | "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki" 356 | }, 357 | "time": "2020-05-13T23:57:56+00:00" 358 | } 359 | ], 360 | "aliases": [], 361 | "minimum-stability": "stable", 362 | "stability-flags": [], 363 | "prefer-stable": false, 364 | "prefer-lowest": false, 365 | "platform": { 366 | "php": ">=5.6" 367 | }, 368 | "platform-dev": [], 369 | "plugin-api-version": "2.2.0" 370 | } 371 | -------------------------------------------------------------------------------- /includes/add-pattern-category-type-support.php: -------------------------------------------------------------------------------- 1 | register_routes(); 24 | } 25 | add_action( 'rest_api_init', __NAMESPACE__ . '\register_routes' ); 26 | 27 | /** 28 | * Include the pattern category type registry. 29 | */ 30 | if ( ! class_exists( 'BPE_Block_Pattern_Category_Types_Registry' ) ) { 31 | require_once BPE_ABSPATH . '/includes/class-bpe-block-pattern-category-types-registry.php'; 32 | } 33 | 34 | /** 35 | * Include our custom REST API controllers. 36 | */ 37 | if ( ! class_exists( 'BPE_Pattern_Category_Types_REST_Controller' ) ) { 38 | require_once BPE_ABSPATH . 'includes/class-bpe-pattern-category-types-rest-controller.php'; 39 | } 40 | -------------------------------------------------------------------------------- /includes/class-bpe-block-pattern-category-types-registry.php: -------------------------------------------------------------------------------- 1 | registered_category_types[ $category_type_name ] = array_merge( 54 | array( 'name' => $category_type_name ), 55 | $category_type_properties 56 | ); 57 | 58 | return true; 59 | } 60 | 61 | /** 62 | * Unregisters a pattern category type. 63 | * 64 | * @since 0.2.0 65 | * 66 | * @param string $category_type_name Pattern category type name including namespace. 67 | * @return bool True if the pattern category type was unregistered with success and false otherwise. 68 | */ 69 | public function unregister( $category_type_name ) { 70 | if ( ! $this->is_registered( $category_type_name ) ) { 71 | _doing_it_wrong( 72 | __METHOD__, 73 | esc_html( 74 | sprintf( 75 | /* translators: %s: Block pattern categpry type name. */ 76 | __( 77 | 'Block pattern category type "%s" not found.', 78 | 'block-pattern-explorer' 79 | ), 80 | $category_type_name 81 | ) 82 | ), 83 | '0.2.0' 84 | ); 85 | return false; 86 | } 87 | 88 | unset( $this->registered_category_types[ $category_type_name ] ); 89 | 90 | return true; 91 | } 92 | 93 | /** 94 | * Retrieves an array containing the properties of a registered pattern category type. 95 | * 96 | * @since 0.2.0 97 | * 98 | * @param string $category_type_name Pattern category type name including namespace. 99 | * @return array Registered pattern category type properties. 100 | */ 101 | public function get_registered( $category_type_name ) { 102 | if ( ! $this->is_registered( $category_type_name ) ) { 103 | return null; 104 | } 105 | 106 | return $this->registered_category_types[ $category_type_name ]; 107 | } 108 | 109 | /** 110 | * Retrieves all registered pattern category types. 111 | * 112 | * @since 0.2.0 113 | * 114 | * @return array Array of arrays containing the registered pattern category types. 115 | */ 116 | public function get_all_registered() { 117 | return array_values( $this->registered_category_types ); 118 | } 119 | 120 | /** 121 | * Checks if a pattern category type is registered. 122 | * 123 | * @since 0.2.0 124 | * 125 | * @param string $category_type_name Pattern category name including namespace. 126 | * @return bool True if the pattern category type is registered, false otherwise. 127 | */ 128 | public function is_registered( $category_type_name ) { 129 | return isset( $this->registered_category_types[ $category_type_name ] ); 130 | } 131 | 132 | /** 133 | * Utility method to retrieve the main instance of the class. 134 | * 135 | * The instance will be created if it does not exist yet. 136 | * 137 | * @since 0.2.0 138 | * 139 | * @return BPE_Block_Pattern_Category_Types_Registry The main instance. 140 | */ 141 | public static function get_instance() { 142 | if ( null === self::$instance ) { 143 | self::$instance = new self(); 144 | } 145 | 146 | return self::$instance; 147 | } 148 | } 149 | 150 | /** 151 | * Registers a new pattern category type. 152 | * 153 | * Note: This function is purposefully not namespaced/prefixed. It is designed 154 | * to emulate a similar function that will be proposed for inclusion in core. 155 | * 156 | * @since 0.2.0 157 | * 158 | * @param string $category_type_name Pattern category type name including namespace. 159 | * @param array $category_type_properties Array containing the properties of the category type. 160 | * @return bool True if the pattern category type was registered with success and false otherwise. 161 | */ 162 | // phpcs:ignore 163 | function register_block_pattern_category_type( $category_type_name, $category_type_properties ) { 164 | return BPE_Block_Pattern_Category_Types_Registry::get_instance()->register( $category_type_name, $category_type_properties ); 165 | } 166 | 167 | /** 168 | * Unregisters a pattern category type. 169 | * 170 | * Note: This function is purposefully not namespaced/prefixed. It is designed 171 | * to emulate a similar function that will be proposed for inclusion in core. 172 | * 173 | * @since 0.2.0 174 | * 175 | * @param string $category_type_name Pattern category type name including namespace. 176 | * @return bool True if the pattern category type was unregistered with success and false otherwise. 177 | */ 178 | // phpcs:ignore 179 | function unregister_block_pattern_category_type( $category_type_name ) { 180 | return BPE_Block_Pattern_Category_Types_Registry::get_instance()->unregister( $category_type_name ); 181 | } 182 | -------------------------------------------------------------------------------- /includes/class-bpe-pattern-category-types-rest-controller.php: -------------------------------------------------------------------------------- 1 | namespace, 37 | '/' . $this->rest_base, 38 | array( 39 | array( 40 | 'methods' => WP_REST_Server::READABLE, 41 | 'callback' => array( $this, 'get_pattern_category_types' ), 42 | 'permission_callback' => '__return_true', // Read only, so anyone can view. 43 | ), 44 | 'schema' => array( $this, 'get_public_item_schema' ), 45 | ) 46 | ); 47 | } 48 | 49 | /** 50 | * Get a collection of items 51 | * 52 | * @return WP_Error|WP_REST_Response 53 | */ 54 | public function get_pattern_category_types() { 55 | 56 | $pattern_category_types = BPE_Block_Pattern_Category_Types_Registry::get_instance()->get_all_registered(); 57 | 58 | if ( is_array( $pattern_category_types ) ) { 59 | // @TODO Possibly add a prepare_settings_for_response function here 60 | // in the future. 61 | return new WP_REST_Response( array( 'patternCategoryTypes' => $pattern_category_types ), 200 ); 62 | } else { 63 | return new WP_Error( '404', __( 'Something went wrong, the category types could not be found.', 'block-pattern-explorer' ), array( 'status' => 404 ) ); 64 | } 65 | } 66 | 67 | /** 68 | * Get the Settings schema, conforming to JSON Schema. 69 | * 70 | * @return array 71 | */ 72 | public function get_item_schema() { 73 | if ( $this->schema ) { 74 | // Since WordPress 5.3, the schema can be cached in the $schema property. 75 | return $this->schema; 76 | } 77 | 78 | $this->schema = array( 79 | '$schema' => 'http://json-schema.org/draft-04/schema#', 80 | 'title' => 'pattern-category-types', 81 | 'type' => 'array', 82 | 'items' => array( 83 | 'type' => 'object', 84 | 'properties' => array( 85 | 'name' => array( 86 | 'type' => 'string', 87 | ), 88 | 'label' => array( 89 | 'type' => 'string', 90 | ), 91 | ), 92 | ), 93 | ); 94 | 95 | return $this->schema; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /includes/core/add-pattern-category-type-support.php: -------------------------------------------------------------------------------- 1 | get_all_registered(); 24 | 25 | return $editor_settings; 26 | } 27 | add_filter( 'block_editor_settings_all', __NAMESPACE__ . '\add_block_editor_settings', 10, 2 ); 28 | 29 | // Include the pattern category type registry. 30 | if ( ! class_exists( 'BPE_Block_Pattern_Category_Types_Registry' ) ) { 31 | require_once BPE_ABSPATH . '/includes/class-bpe-block-pattern-category-types-registry.php'; 32 | } 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "block-pattern-explorer", 3 | "version": "0.2.0", 4 | "description": "An experimental plugin to preview and insert block patterns in the Block Editor.", 5 | "author": "Nick Diego", 6 | "license": "GPL-2.0-or-later", 7 | "main": "build/index.js", 8 | "scripts": { 9 | "build": "wp-scripts build", 10 | "format:js": "wp-scripts format-js", 11 | "lint:css": "wp-scripts lint-style", 12 | "lint:js": "wp-scripts lint-js", 13 | "lint:js:src": "wp-scripts lint-js ./src", 14 | "lint:js:src:fix": "wp-scripts lint-js ./src --fix", 15 | "start": "wp-scripts start", 16 | "packages-update": "wp-scripts packages-update" 17 | }, 18 | "devDependencies": { 19 | "@wordpress/scripts": "^22.4.0", 20 | "classnames": "^2.3.1", 21 | "lodash": "^4.17.21", 22 | "markdown-it": "^12.3.2", 23 | "webpack-remove-empty-scripts": "^0.8.0" 24 | }, 25 | "dependencies": { 26 | "@wordpress/a11y": "^3.6.0", 27 | "@wordpress/api-fetch": "^6.3.0", 28 | "@wordpress/block-editor": "^8.5.1", 29 | "@wordpress/blocks": "^11.5.1", 30 | "@wordpress/components": "^19.8.0", 31 | "@wordpress/compose": "^5.4.0", 32 | "@wordpress/data": "^6.6.0", 33 | "@wordpress/edit-post": "^6.3.1", 34 | "@wordpress/element": "^4.4.0", 35 | "@wordpress/i18n": "^4.6.0", 36 | "@wordpress/icons": "^8.2.0", 37 | "@wordpress/notices": "^3.6.0", 38 | "@wordpress/plugins": "^4.4.0", 39 | "@wordpress/url": "^3.7.0" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /phpcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Rules for Block Pattern Explorer 4 | 5 | 6 | 7 | ./ 8 | 9 | */build/* 10 | */dist/* 11 | */vendor/* 12 | */node_modules/* 13 | */wordpress*/* 14 | */\.* 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === Block Pattern Explorer === 2 | Author URI: https://wwww.nickdiego.com 3 | Contributors: ndiego, bgardner, wpengine 4 | Tags: patterns, blocks, block patterns, starter content 5 | Requires at least: 5.8 6 | Tested up to: 5.9 7 | Requires PHP: 7.1 8 | Stable tag: 0.3.0 9 | License: GPLv2 or later 10 | License URI: https://www.gnu.org/licenses/gpl-2.0.html 11 | 12 | An experimental plugin to preview and insert block patterns in the Block Editor. 13 | 14 | == Description == 15 | 16 | An experimental plugin to preview and insert block patterns in the Block Editor (Gutenberg). 17 | 18 | Please note that no block patterns are included with this plugin. Patterns must be provided by your theme or another plugin. You can also use the patterns provided by WordPress if enabled by your theme. 19 | 20 | Furthermore, this plugin should be used in conjunction with the [Gutenberg plugin](https://wordpress.org/plugins/gutenberg/) until WordPress 5.9 is officially released on January 25, 2022. 21 | 22 | === Mission === 23 | 24 | The Block Pattern Explorer is heavily influenced by the work currently being done in the Gutenberg [GitHub repository](https://github.com/WordPress/gutenberg) on pattern previews. 25 | 26 | The purpose of this project is to isolate the pattern explorer into a standalone plugin that WordPress users/developers can interact with immediately, provide feedback on, and begin implementing into their own websites. Ideally, this initiative will also help inform the direction of core development. 27 | 28 | Once the pattern explorer is fully integrated into WordPress proper, this project will be sunsetted in favor of the core offering. 29 | 30 | == Screenshots == 31 | 32 | 1. Inserting a pattern from the upcoming Twenty Twenty-Two theme into the Block Editor using the block pattern explorer. 33 | 34 | === Stay Connected === 35 | 36 | Stay up-to-date on the Block Pattern Explorer, and Gutenberg development, using the links below. The plugin is also being built transparently on GitHub, so give it a star and follow along! 😉 37 | 38 | * [Follow on Twitter](https://twitter.com/nickmdiego) 39 | * [View on GitHub](https://github.com/wpengine/block-pattern-explorer) 40 | * [Gutenberg plugin](https://wordpress.org/plugins/gutenberg/) 41 | * [Gutenberg on GitHub](https://github.com/WordPress/gutenberg) 42 | 43 | == Installation == 44 | 45 | 1. You have a couple options: 46 | * Go to Plugins → Add New and search for "Block Pattern Explorer". Once found, click "Install". 47 | * Download the Block Pattern Explorer from WordPress.org and make sure the folder is zipped. Then upload via Plugins → Add New → Upload. 48 | 2. Activate the plugin through the 'Plugins' menu in WordPress. 49 | 3. Once activated, navigate to the Block Editor and you will see the "Insert Pattern" button in header toolbar. See the plugin screenshots for reference. 50 | 51 | == Changelog == 52 | 53 | = 0.3.0 - 2022-01-13 = 54 | 55 | **Changed** 56 | 57 | * Replaced custom search component with core version. 58 | * Updated modal styling to match core pattern explorer. 59 | * Updated screenshots. 60 | 61 | **Fixed** 62 | 63 | * Fixed API bug causing the pattern explorer to be inaccessible on themes that do not utilize pattern category types. 64 | * Fixed linting and code quality errors. 65 | 66 | = 0.2.1 - 2021-11-23 = 67 | 68 | **Changed** 69 | 70 | * The button used to launch the Pattern Explorer is now disabled while pattern category types are being retrieved from the REST API. 71 | * Updated tooltip on the button used to launch the Pattern Explorer. 72 | 73 | = 0.2.0 - 2021-11-22 = 74 | 75 | **Added** 76 | 77 | * Added support for the experimental block pattern category types. 78 | 79 | = 0.1.0 - 2021-11-09 = 80 | 81 | Initial release! 🎉 82 | -------------------------------------------------------------------------------- /src/core-components/inserter-listbox/context.js: -------------------------------------------------------------------------------- 1 | /** 2 | * WordPress dependencies 3 | */ 4 | import { createContext } from '@wordpress/element'; 5 | 6 | const InserterListboxContext = createContext(); 7 | 8 | export default InserterListboxContext; 9 | -------------------------------------------------------------------------------- /src/core-components/inserter-listbox/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * WordPress dependencies 3 | */ 4 | import { __unstableUseCompositeState as useCompositeState } from '@wordpress/components'; // eslint-disable-line 5 | 6 | /** 7 | * Internal dependencies 8 | */ 9 | import InserterListboxContext from './context'; 10 | 11 | function InserterListbox( { children } ) { 12 | const compositeState = useCompositeState( { 13 | shift: true, 14 | wrap: 'horizontal', 15 | } ); 16 | return ( 17 | 18 | { children } 19 | 20 | ); 21 | } 22 | 23 | export default InserterListbox; 24 | -------------------------------------------------------------------------------- /src/core-components/no-results.js: -------------------------------------------------------------------------------- 1 | /** 2 | * WordPress dependencies 3 | */ 4 | import { __ } from '@wordpress/i18n'; 5 | import { Icon, blockDefault } from '@wordpress/icons'; 6 | 7 | function InserterNoResults( { icon, label } ) { 8 | return ( 9 |
10 |
11 | 15 |

16 | { label 17 | ? label 18 | : __( 'No results found.', 'block-pattern-explorer' ) } 19 |

20 |
21 |
22 | ); 23 | } 24 | 25 | export default InserterNoResults; 26 | -------------------------------------------------------------------------------- /src/core-hooks/use-insertion-point.js: -------------------------------------------------------------------------------- 1 | /** 2 | * External dependencies 3 | */ 4 | import { castArray } from 'lodash'; 5 | 6 | /** 7 | * WordPress dependencies 8 | */ 9 | import { useDispatch, useSelect } from '@wordpress/data'; 10 | import { isUnmodifiedDefaultBlock } from '@wordpress/blocks'; 11 | import { _n, sprintf } from '@wordpress/i18n'; 12 | import { speak } from '@wordpress/a11y'; 13 | import { useCallback } from '@wordpress/element'; 14 | import { store as blockEditorStore } from '@wordpress/block-editor'; 15 | 16 | /** 17 | * @typedef WPInserterConfig 18 | * @property {string=} rootClientId If set, insertion will be into the block with this ID. 19 | * @property {number=} insertionIndex If set, insertion will be into this explicit position. 20 | * @property {string=} clientId If set, insertion will be after the block with this ID. 21 | * @property {boolean=} isAppender Whether the inserter is an appender or not. 22 | * @property {Function=} onSelect Called after insertion. 23 | */ 24 | 25 | /** 26 | * Returns the insertion point state given the inserter config. 27 | * 28 | * @param {WPInserterConfig} config Inserter Config. 29 | * @return {Array} Insertion Point State (rootClientID, onInsertBlocks and onToggle). 30 | */ 31 | export default function useInsertionPoint( { 32 | rootClientId = '', 33 | insertionIndex, 34 | clientId, 35 | isAppender, 36 | onSelect, 37 | shouldFocusBlock = true, 38 | } ) { 39 | const { getSelectedBlock } = useSelect( blockEditorStore ); 40 | const { destinationRootClientId, destinationIndex } = useSelect( 41 | ( select ) => { 42 | const { 43 | getSelectedBlockClientId, 44 | getBlockRootClientId, 45 | getBlockIndex, 46 | getBlockOrder, 47 | } = select( blockEditorStore ); 48 | const selectedBlockClientId = getSelectedBlockClientId(); 49 | 50 | let _destinationRootClientId = rootClientId; 51 | let _destinationIndex; 52 | 53 | if ( insertionIndex !== undefined ) { 54 | // Insert into a specific index. 55 | _destinationIndex = insertionIndex; 56 | } else if ( clientId ) { 57 | // Insert after a specific client ID. 58 | _destinationIndex = getBlockIndex( 59 | clientId, 60 | _destinationRootClientId 61 | ); 62 | } else if ( ! isAppender && selectedBlockClientId ) { 63 | _destinationRootClientId = getBlockRootClientId( 64 | selectedBlockClientId 65 | ); 66 | _destinationIndex = 67 | getBlockIndex( 68 | selectedBlockClientId, 69 | _destinationRootClientId 70 | ) + 1; 71 | } else { 72 | // Insert at the end of the list. 73 | _destinationIndex = getBlockOrder( _destinationRootClientId ) 74 | .length; 75 | } 76 | 77 | return { 78 | destinationRootClientId: _destinationRootClientId, 79 | destinationIndex: _destinationIndex, 80 | }; 81 | }, 82 | [ rootClientId, insertionIndex, clientId, isAppender ] 83 | ); 84 | 85 | const { 86 | replaceBlocks, 87 | insertBlocks, 88 | showInsertionPoint, 89 | hideInsertionPoint, 90 | } = useDispatch( blockEditorStore ); 91 | 92 | const onInsertBlocks = useCallback( 93 | ( blocks, meta, shouldForceFocusBlock = false ) => { 94 | const selectedBlock = getSelectedBlock(); 95 | 96 | if ( 97 | ! isAppender && 98 | selectedBlock && 99 | isUnmodifiedDefaultBlock( selectedBlock ) 100 | ) { 101 | replaceBlocks( 102 | selectedBlock.clientId, 103 | blocks, 104 | null, 105 | shouldFocusBlock || shouldForceFocusBlock ? 0 : null, 106 | meta 107 | ); 108 | } else { 109 | insertBlocks( 110 | blocks, 111 | destinationIndex, 112 | destinationRootClientId, 113 | true, 114 | shouldFocusBlock || shouldForceFocusBlock ? 0 : null, 115 | meta 116 | ); 117 | } 118 | const message = sprintf( 119 | // translators: %d: the name of the block that has been added 120 | _n( 121 | '%d block added.', 122 | '%d blocks added.', 123 | castArray( blocks ).length 124 | ), 125 | castArray( blocks ).length 126 | ); 127 | speak( message ); 128 | 129 | if ( onSelect ) { 130 | onSelect(); 131 | } 132 | }, 133 | [ 134 | isAppender, 135 | getSelectedBlock, 136 | replaceBlocks, 137 | insertBlocks, 138 | destinationRootClientId, 139 | destinationIndex, 140 | onSelect, 141 | shouldFocusBlock, 142 | ] 143 | ); 144 | 145 | const onToggleInsertionPoint = useCallback( 146 | ( show ) => { 147 | if ( show ) { 148 | showInsertionPoint( destinationRootClientId, destinationIndex ); 149 | } else { 150 | hideInsertionPoint(); 151 | } 152 | }, 153 | [ 154 | showInsertionPoint, 155 | hideInsertionPoint, 156 | destinationRootClientId, 157 | destinationIndex, 158 | ] 159 | ); 160 | 161 | return [ destinationRootClientId, onInsertBlocks, onToggleInsertionPoint ]; 162 | } 163 | -------------------------------------------------------------------------------- /src/core-hooks/use-patterns-state.js: -------------------------------------------------------------------------------- 1 | /** 2 | * External dependencies 3 | */ 4 | import { map } from 'lodash'; 5 | 6 | /** 7 | * WordPress dependencies 8 | */ 9 | import { useCallback } from '@wordpress/element'; 10 | import { cloneBlock } from '@wordpress/blocks'; 11 | import { useDispatch, useSelect } from '@wordpress/data'; 12 | import { __, sprintf } from '@wordpress/i18n'; 13 | import { store as noticesStore } from '@wordpress/notices'; 14 | import { store as blockEditorStore } from '@wordpress/block-editor'; 15 | 16 | /** 17 | * Retrieves the block patterns inserter state. 18 | * 19 | * @param {Function} onInsert function called when inserter a list of blocks. 20 | * @param {string=} rootClientId Insertion's root client ID. 21 | * 22 | * @return {Array} Returns the patterns state. (patterns, categories, onSelect handler) 23 | */ 24 | const usePatternsState = ( onInsert, rootClientId ) => { 25 | const { patterns, patternCategories, patternCategoryTypes } = useSelect( 26 | ( select ) => { 27 | const { __experimentalGetAllowedPatterns, getSettings } = select( 28 | blockEditorStore 29 | ); 30 | 31 | // Fetch any register pattern category types with the custom REST 32 | // API endpoint. Eventually replace with core functionality. 33 | const { getEntityRecord } = select( 'core' ); 34 | const categoryTypes = getEntityRecord( 35 | 'block-pattern-explorer/v1', 36 | 'patternCategoryTypes' 37 | ); 38 | 39 | return { 40 | patterns: __experimentalGetAllowedPatterns( rootClientId ), 41 | patternCategories: getSettings() 42 | .__experimentalBlockPatternCategories, 43 | patternCategoryTypes: 44 | categoryTypes?.patternCategoryTypes ?? 'fetching', 45 | // This is new functionality and will need to ultimately be added to the 46 | // Gutenberg Patterns API. Category Types allow theme/plugin developers to 47 | // group pattern categories together in the new Pattern Explorer. 48 | // patternCategoryTypes: getSettings().__experimentalBlockPatternCategoryTypes, 49 | }; 50 | }, 51 | [ rootClientId ] 52 | ); 53 | 54 | const { createSuccessNotice } = useDispatch( noticesStore ); 55 | const onClickPattern = useCallback( ( pattern, blocks ) => { 56 | onInsert( 57 | map( blocks, ( block ) => cloneBlock( block ) ), 58 | pattern.name 59 | ); 60 | createSuccessNotice( 61 | sprintf( 62 | /* translators: %s: block pattern title. */ 63 | __( 'Block pattern "%s" inserted.', 'block-pattern-explorer' ), 64 | pattern.title 65 | ), 66 | { 67 | type: 'snackbar', 68 | } 69 | ); 70 | }, [] ); 71 | 72 | return [ 73 | patterns, 74 | patternCategories, 75 | patternCategoryTypes, 76 | onClickPattern, 77 | ]; 78 | }; 79 | 80 | export default usePatternsState; 81 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * External dependencies. 3 | */ 4 | import { isEmpty } from 'lodash'; 5 | 6 | /** 7 | * WordPress dependencies. 8 | */ 9 | import { __ } from '@wordpress/i18n'; 10 | import { render, useState, useMemo, useCallback } from '@wordpress/element'; 11 | import { dispatch, subscribe } from '@wordpress/data'; 12 | import { Button, Modal } from '@wordpress/components'; 13 | import { layout } from '@wordpress/icons'; 14 | 15 | /** 16 | * Internal dependencies 17 | */ 18 | import PatternExplorer from './pattern-explorer'; 19 | import usePatternsState from './core-hooks/use-patterns-state'; 20 | 21 | /** 22 | * Render the header toolbar button and the accompanying pattern explorer modal. 23 | * 24 | * @since 0.1.0 25 | * @return {string} Return the rendered JSX for the Pattern Explorer Button 26 | */ 27 | function HeaderToolbarButton() { 28 | const [ isModalOpen, setIsModalOpen ] = useState( false ); 29 | const [ allPatterns, allCategories, allCategoryTypes ] = usePatternsState(); 30 | 31 | const fetchedCategoryTypes = 32 | allCategoryTypes === 'fetching' ? [] : allCategoryTypes; 33 | 34 | // Check if a pattern has an assigned pattern category. 35 | const hasRegisteredCategory = useCallback( 36 | ( pattern ) => { 37 | if ( ! pattern.categories || ! pattern.categories.length ) { 38 | return false; 39 | } 40 | 41 | return pattern.categories.some( ( cat ) => 42 | allCategories.some( ( category ) => category.name === cat ) 43 | ); 44 | }, 45 | [ allCategories ] 46 | ); 47 | 48 | // Check if a pattern category has an assigned pattern category type. 49 | const hasRegisteredCategoryType = useCallback( 50 | ( category ) => { 51 | if ( ! category.categoryTypes || ! category.categoryTypes.length ) { 52 | return false; 53 | } 54 | 55 | return category.categoryTypes.some( ( type ) => 56 | fetchedCategoryTypes.some( 57 | ( categoryType ) => categoryType.name === type 58 | ) 59 | ); 60 | }, 61 | [ fetchedCategoryTypes ] 62 | ); 63 | 64 | // Remove any categories without patterns. 65 | const populatedCategories = useMemo( () => { 66 | const categories = allCategories 67 | .filter( ( category ) => 68 | allPatterns.some( ( pattern ) => 69 | pattern.categories?.includes( category.name ) 70 | ) 71 | ) 72 | .sort( ( { name: currentName }, { name: nextName } ) => { 73 | if ( ! [ currentName, nextName ].includes( 'featured' ) ) { 74 | return 0; 75 | } 76 | return currentName === 'featured' ? -1 : 1; 77 | } ); 78 | 79 | // If there are patterns without categories, create Uncategorized. 80 | if ( 81 | allPatterns.some( 82 | ( pattern ) => ! hasRegisteredCategory( pattern ) 83 | ) && 84 | ! categories.find( 85 | ( category ) => category.name === 'uncategorized' 86 | ) 87 | ) { 88 | categories.push( { 89 | name: 'uncategorized', 90 | label: __( 'Uncategorized', 'block-pattern-explorer' ), 91 | } ); 92 | } 93 | 94 | return categories; 95 | }, [ allPatterns, allCategories ] ); 96 | 97 | // Remove any pattern category type without populated pattern categories. 98 | const populatedCategoryTypes = useMemo( () => { 99 | const categoryTypes = fetchedCategoryTypes.filter( ( type ) => 100 | populatedCategories.some( ( category ) => 101 | category.categoryTypes?.includes( type.name ) 102 | ) 103 | ); 104 | 105 | // If there are categories without types, create the Uncategorized type. 106 | if ( 107 | populatedCategories.some( 108 | ( category ) => ! hasRegisteredCategoryType( category ) 109 | ) && 110 | ! categoryTypes.find( ( type ) => type.name === 'uncategorized' ) 111 | ) { 112 | categoryTypes.unshift( { 113 | name: 'uncategorized', 114 | label: __( 'Uncategorized', 'block-pattern-explorer' ), 115 | hideLabelFromVision: true, 116 | } ); 117 | } 118 | 119 | return categoryTypes; 120 | }, [ populatedCategories, fetchedCategoryTypes ] ); 121 | 122 | // Could expand on this in the future, i.e. allow for a configurable 123 | // initial category. For now the initial category is the first category in 124 | // the first category type. 125 | const initialCategory = populatedCategories.filter( ( category ) => { 126 | // If the first category type is 'uncategorized', filter all categories 127 | // without types and all categories with the type 'uncategorized'. 128 | if ( populatedCategoryTypes[ 0 ].name === 'uncategorized' ) { 129 | return ( 130 | ! category.categoryTypes || 131 | ! category.categoryTypes.length || 132 | category.categoryTypes?.includes( 'uncategorized' ) 133 | ); 134 | } 135 | 136 | // If the first type is not 'uncategorized', filter all the categories in the 137 | // first type. 138 | return category.categoryTypes?.includes( 139 | populatedCategoryTypes[ 0 ].name 140 | ); 141 | } )[ 0 ]; 142 | 143 | // If there are no patterns, do not display the pattern explorer button. 144 | if ( isEmpty( allPatterns ) ) { 145 | return null; 146 | } 147 | 148 | return ( 149 | <> 150 | 87 | 88 | 89 | ); 90 | } 91 | -------------------------------------------------------------------------------- /src/sidebar.js: -------------------------------------------------------------------------------- 1 | /** 2 | * WordPress dependencies 3 | */ 4 | import { __ } from '@wordpress/i18n'; 5 | import { 6 | MenuGroup, 7 | MenuItem, 8 | SearchControl, 9 | VisuallyHidden, 10 | } from '@wordpress/components'; 11 | import { useMemo } from '@wordpress/element'; 12 | 13 | /** 14 | * Renders the block pattern category sidebar control. 15 | * 16 | * @since 0.1.0 17 | * @param {Object} props All the props passed to this function 18 | * @return {string} Return the rendered JSX 19 | */ 20 | export default function PatternExplorerSidebar( props ) { 21 | const { 22 | patternCategories, 23 | patternCategoryTypes, 24 | selectedCategory, 25 | setSelectedCategory, 26 | searchValue, 27 | setSearchValue, 28 | } = props; 29 | 30 | function onClickCategory( category ) { 31 | setSelectedCategory( category ); 32 | setSearchValue( '' ); 33 | } 34 | 35 | const registeredCategoryTypes = useMemo( 36 | () => 37 | patternCategoryTypes.map( 38 | ( patternCategoryType ) => patternCategoryType.name 39 | ), 40 | [ patternCategoryTypes ] 41 | ); 42 | 43 | const baseClassName = 'block-pattern-explorer__sidebar'; 44 | 45 | return ( 46 |
47 |
48 | 53 |
54 | { patternCategoryTypes.map( ( categoryType ) => { 55 | const categoriesOfType = patternCategories.filter( 56 | ( category ) => { 57 | // If the selected category is uncategorized, return all 58 | // pattern categories without assigned category types. 59 | if ( categoryType.name === 'uncategorized' ) { 60 | return ( 61 | ! category?.categoryTypes || 62 | category.categoryTypes.every( 63 | ( type ) => 64 | ! registeredCategoryTypes.includes( 65 | type 66 | ) 67 | ) 68 | ); 69 | } 70 | return category.categoryTypes?.includes( 71 | categoryType.name 72 | ); 73 | } 74 | ); 75 | 76 | // If there are no categories in the current type, bail. 77 | if ( ! categoriesOfType.length ) { 78 | return null; 79 | } 80 | 81 | return ( 82 |
86 | { categoryType?.hideLabelFromVision ? ( 87 | 88 | { categoryType.label } 89 | 90 | ) : ( 91 |

94 | { categoryType.label } 95 |

96 | ) } 97 |
100 | 103 | { categoriesOfType.map( ( category ) => { 104 | return ( 105 | 115 | onClickCategory( category.name ) 116 | } 117 | > 118 | { category.label } 119 | 120 | ); 121 | } ) } 122 | 123 |
124 |
125 | ); 126 | } ) } 127 |
128 | ); 129 | } 130 | -------------------------------------------------------------------------------- /src/style.scss: -------------------------------------------------------------------------------- 1 | .block-pattern-explorer__modal { 2 | .components-modal__content { 3 | flex: 1; /* Will likely not be needed in WP 5.9 */ 4 | overflow: auto; 5 | padding: 0; 6 | 7 | &:before { 8 | margin-bottom: 0; 9 | } 10 | } 11 | } 12 | 13 | .block-pattern-explorer { 14 | align-items: stretch; 15 | display: flex; 16 | height: 100%; 17 | 18 | &.is-error { 19 | display: block; 20 | margin: 24px 32px; 21 | } 22 | 23 | .components-notice { 24 | margin: 0; 25 | 26 | .components-notice__content { 27 | margin-top: 8px; 28 | margin-bottom: 8px; 29 | } 30 | 31 | &.is-error { 32 | background-color: #f8ebea; 33 | } 34 | 35 | p { 36 | margin: 12px 0 0; 37 | 38 | &:first-child { 39 | margin-top: 0; 40 | } 41 | } 42 | } 43 | 44 | .block-pattern-explorer__preview { 45 | display: flex; 46 | flex-direction: column; 47 | flex-shrink: 0; 48 | overflow: auto; 49 | padding: 32px 32px 100px; 50 | width: calc(100% - 281px); 51 | 52 | .block-editor-inserter__no-results { 53 | align-items: center; 54 | display: flex; 55 | height: 100%; 56 | justify-content: center; 57 | } 58 | } 59 | 60 | .block-pattern-explorer__preview-header { 61 | align-items: center; 62 | display: inline-flex; 63 | justify-content: space-between; 64 | margin-bottom: 2rem; 65 | 66 | &__search-results { 67 | display: inline-flex; 68 | 69 | .components-spinner { 70 | margin: 0 12px 0 0; 71 | } 72 | } 73 | 74 | &__controls { 75 | display: inline-flex; 76 | 77 | .viewport-toggle { 78 | margin-right: 6px; 79 | } 80 | 81 | &>button { 82 | margin-left: 6px; 83 | } 84 | } 85 | 86 | /* Temp fix for DropdownMenu component. */ 87 | .components-popover__content { 88 | margin-top: -50px; 89 | margin-right: 48px !important; 90 | } 91 | } 92 | 93 | .block-pattern-explorer__preview-pattern-list { 94 | width: 100%; 95 | 96 | &>div { 97 | margin-bottom: 2rem; 98 | } 99 | 100 | &.preview-tablet { 101 | &>div { 102 | max-width: 790px; 103 | margin: 0 auto 4rem; 104 | } 105 | } 106 | 107 | &.preview-mobile { 108 | &>div { 109 | max-width: 358px; 110 | margin: 0 auto 4rem; 111 | } 112 | } 113 | 114 | &.is-grid { 115 | display: grid; 116 | grid-gap: 32px; 117 | grid-template: inherit; 118 | grid-template-columns: repeat(1,1fr); 119 | 120 | @media (min-width: 1080px) { 121 | grid-template-columns: repeat(2,1fr); 122 | } 123 | 124 | @media ( min-width: 1440px ) { 125 | grid-template-columns: repeat(3,1fr); 126 | } 127 | 128 | &>div { 129 | margin-bottom: 0; 130 | } 131 | 132 | &.preview-tablet, 133 | &.preview-mobile { 134 | &>div { 135 | margin: 0; 136 | } 137 | } 138 | 139 | .block-editor-block-preview__container { 140 | max-height: 400px; 141 | overflow: scroll; 142 | } 143 | } 144 | 145 | &.no-results { 146 | align-items: center; 147 | display: flex; 148 | height: 100%; 149 | justify-content: center; 150 | } 151 | 152 | &__item { 153 | border: 1px solid #dddddd; 154 | border-radius: 2px; 155 | display: flex; 156 | flex-direction: column; 157 | justify-content: space-between; 158 | position: relative; 159 | transition: all .05s ease-in-out; 160 | width: 100%; 161 | 162 | &:hover { 163 | border-color: var(--wp-admin-theme-color); 164 | } 165 | 166 | &-preview { 167 | align-items: center; 168 | background: #f0f0f0; 169 | cursor: pointer; 170 | display: flex; 171 | flex-grow: 1; 172 | min-height: 200px; 173 | 174 | img { 175 | width: 100%; 176 | } 177 | } 178 | 179 | &-actions { 180 | align-items: center; 181 | background: #fff; 182 | border-top: 1px solid #ddd; 183 | display: flex; 184 | justify-content: space-between; 185 | padding: 10px; 186 | } 187 | 188 | &-title { 189 | font-size: 12px; 190 | padding: 6px; 191 | text-align: center; 192 | } 193 | } 194 | } 195 | 196 | .block-pattern-explorer__preview-loading { 197 | display: flex; 198 | justify-content: center; 199 | margin: 64px 0; 200 | width: 100%; 201 | } 202 | 203 | .block-pattern-explorer__sidebar { 204 | border-right: 1px solid #ddd; 205 | display: flex; 206 | flex-direction: column; 207 | flex-shrink: 0; 208 | overflow-y: scroll; 209 | padding: 32px; 210 | width: 280px; 211 | 212 | &__search { 213 | margin-bottom: 16px; 214 | 215 | .components-base-control__field { 216 | margin-bottom: 0; 217 | } 218 | } 219 | 220 | &__category-type { 221 | &__title { 222 | color: #757575; 223 | font-size: 11px; 224 | font-weight: 500; 225 | margin: 0; 226 | padding: 16px 12px 0; 227 | text-transform: uppercase; 228 | } 229 | 230 | &__categories { 231 | padding: 16px 0; 232 | } 233 | } 234 | } 235 | } 236 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require( 'path' ); 2 | const defaultConfig = require( '@wordpress/scripts/config/webpack.config' ); 3 | 4 | const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' ); 5 | 6 | module.exports = { 7 | ...defaultConfig, 8 | 9 | entry: { 10 | 'block-pattern-explorer-editor' : path.resolve( process.cwd(), 'src/index.js' ), 11 | 'block-pattern-explorer-editor-styles' : path.resolve( process.cwd(), 'src/style.scss' ), 12 | }, 13 | 14 | output: { 15 | filename: '[name].js', 16 | path: path.resolve( process.cwd(), 'build/' ), 17 | }, 18 | 19 | module: { 20 | ...defaultConfig.module, 21 | rules: [ 22 | ...defaultConfig.module.rules, 23 | // Add additional rules as needed. 24 | ] 25 | }, 26 | 27 | plugins: [ 28 | ...defaultConfig.plugins, 29 | // Add additional plugins as needed. 30 | new RemoveEmptyScriptsPlugin(), 31 | ], 32 | }; 33 | --------------------------------------------------------------------------------