From 427b232cadcbadf97139575844f921230c4682be Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Thu, 7 Mar 2024 16:44:16 -0500 Subject: [PATCH 1/6] Remove creator, move code to directory --- package.json | 3 - .../plugins/pattern-creator/jest.config.js | 14 - .../plugins/pattern-creator/package.json | 62 ---- .../pattern-creator/pattern-creator.php | 338 ------------------ .../plugins/pattern-creator/postcss.config.js | 4 - .../plugins/pattern-creator/readme.md | 22 -- .../src/api-middleware/filter-endpoints.js | 72 ---- .../src/api-middleware/index.js | 14 - .../src/api-middleware/mock-site-data.js | 35 -- .../src/components/block-editor/index.js | 88 ----- .../src/components/block-editor/style.scss | 27 -- .../src/components/editor/index.js | 141 -------- .../src/components/editor/save-sidebar.js | 46 --- .../src/components/editor/style.scss | 48 --- .../components/header/feature-toggle/index.js | 46 --- .../src/components/header/index.js | 119 ------ .../src/components/header/more-menu/index.js | 70 ---- .../components/header/more-menu/style.scss | 29 -- .../src/components/header/style.scss | 232 ------------ .../header/tools-more-menu-group/index.js | 22 -- .../src/components/header/undo-redo/redo.js | 26 -- .../src/components/header/undo-redo/undo.js | 26 -- .../components/keyboard-shortcuts/index.js | 105 ------ .../pattern-categories-control/index.js | 218 ----------- .../src/components/save-button/draft.js | 66 ---- .../src/components/save-button/index.js | 99 ----- .../secondary-sidebar/inserter-sidebar.js | 42 --- .../secondary-sidebar/list-view-sidebar.js | 54 --- .../components/secondary-sidebar/style.scss | 52 --- .../src/components/sidebar/constants.js | 2 - .../src/components/sidebar/default-sidebar.js | 40 --- .../src/components/sidebar/index.js | 67 ---- .../sidebar/pattern-settings/index.js | 109 ------ .../sidebar/settings-header/index.js | 69 ---- .../sidebar/settings-header/style.scss | 98 ----- .../src/components/sidebar/style.scss | 44 --- .../src/components/url-controller/index.js | 23 -- .../src/components/welcome-guide/images.js | 122 ------- .../src/components/welcome-guide/index.js | 98 ----- .../src/components/welcome-guide/style.scss | 56 --- .../pattern-creator/src/hooks/media.js | 13 - .../src/hooks/use-post-data.js | 25 -- .../plugins/pattern-creator/src/index.js | 47 --- .../pattern-creator/src/lock-unlock.js | 9 - .../pattern-creator/src/store/actions.js | 73 ---- .../pattern-creator/src/store/constants.js | 12 - .../pattern-creator/src/store/defaults.js | 5 - .../pattern-creator/src/store/index.js | 28 -- .../pattern-creator/src/store/reducer.js | 114 ------ .../pattern-creator/src/store/selectors.js | 165 --------- .../pattern-creator/src/store/test/actions.js | 29 -- .../pattern-creator/src/store/test/reducer.js | 106 ------ .../src/store/test/selectors.js | 151 -------- .../plugins/pattern-creator/src/style.scss | 20 -- .../plugins/pattern-creator/view/editor.php | 45 --- .../plugins/pattern-creator/view/log-in.php | 65 ---- .../pattern-creator/view/not-owner.php | 37 -- .../plugins/pattern-creator/webpack.config.js | 12 - .../plugins/pattern-directory/bootstrap.php | 3 + .../includes/admin-patterns.php | 10 + .../includes/admin-stats.php | 4 +- .../pattern-directory/includes/editor.php | 200 +++++++++++ .../includes/mock-blocks.php | 2 +- .../includes/openverse-client.php | 2 +- .../includes/openverse-rest-controller.php | 2 +- .../pattern-directory/includes/openverse.php | 31 ++ .../includes/pattern-post-type.php | 119 +----- .../src/back-button/index.js | 28 ++ .../src}/media-placeholder/index.js | 0 .../src}/openverse/grid-actions.js | 0 .../src}/openverse/grid-items.js | 0 .../src}/openverse/grid.js | 0 .../src}/openverse/index.js | 52 ++- .../src/openverse/modal.scss} | 21 +- .../src}/openverse/pagination.js | 0 .../src}/openverse/powered-by-openverse.png | Bin .../src}/openverse/utils.js | 0 .../details.js => pattern-details/index.js} | 44 ++- .../src/pattern-post-type.js | 59 ++- .../src/pattern-post-type/index.js | 17 - .../src/{pattern-post-type => }/settings.js | 1 + .../src}/submission-modal/images/circle.svg | 0 .../src}/submission-modal/images/square.svg | 0 .../src}/submission-modal/images/triangle.svg | 0 .../src}/submission-modal/index.js | 6 + .../submission-modal/submission-modal.scss} | 5 +- .../unlist-button/index.js | 0 .../unlist-button/modal.js | 0 .../unlist-button/notice.js | 0 .../unlist-button/unlist.scss | 0 .../unlist-button/utils.js | 0 .../plugins/pattern-directory/views/view.php | 2 +- 92 files changed, 422 insertions(+), 3990 deletions(-) delete mode 100644 public_html/wp-content/plugins/pattern-creator/jest.config.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/package.json delete mode 100644 public_html/wp-content/plugins/pattern-creator/pattern-creator.php delete mode 100644 public_html/wp-content/plugins/pattern-creator/postcss.config.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/readme.md delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/api-middleware/filter-endpoints.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/api-middleware/index.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/api-middleware/mock-site-data.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/block-editor/index.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/block-editor/style.scss delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/editor/index.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/editor/save-sidebar.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/editor/style.scss delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/header/feature-toggle/index.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/header/index.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/header/more-menu/index.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/header/more-menu/style.scss delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/header/style.scss delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/header/tools-more-menu-group/index.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/header/undo-redo/redo.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/header/undo-redo/undo.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/keyboard-shortcuts/index.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/pattern-categories-control/index.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/save-button/draft.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/save-button/index.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/secondary-sidebar/inserter-sidebar.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/secondary-sidebar/list-view-sidebar.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/secondary-sidebar/style.scss delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/sidebar/constants.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/sidebar/default-sidebar.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/sidebar/index.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/sidebar/pattern-settings/index.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/sidebar/settings-header/index.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/sidebar/settings-header/style.scss delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/sidebar/style.scss delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/url-controller/index.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/welcome-guide/images.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/welcome-guide/index.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/components/welcome-guide/style.scss delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/hooks/media.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/hooks/use-post-data.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/index.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/lock-unlock.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/store/actions.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/store/constants.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/store/defaults.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/store/index.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/store/reducer.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/store/selectors.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/store/test/actions.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/store/test/reducer.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/store/test/selectors.js delete mode 100644 public_html/wp-content/plugins/pattern-creator/src/style.scss delete mode 100644 public_html/wp-content/plugins/pattern-creator/view/editor.php delete mode 100644 public_html/wp-content/plugins/pattern-creator/view/log-in.php delete mode 100644 public_html/wp-content/plugins/pattern-creator/view/not-owner.php delete mode 100644 public_html/wp-content/plugins/pattern-creator/webpack.config.js create mode 100644 public_html/wp-content/plugins/pattern-directory/includes/editor.php rename public_html/wp-content/plugins/{pattern-creator => pattern-directory}/includes/mock-blocks.php (99%) rename public_html/wp-content/plugins/{pattern-creator => pattern-directory}/includes/openverse-client.php (99%) rename public_html/wp-content/plugins/{pattern-creator => pattern-directory}/includes/openverse-rest-controller.php (98%) create mode 100644 public_html/wp-content/plugins/pattern-directory/includes/openverse.php create mode 100644 public_html/wp-content/plugins/pattern-directory/src/back-button/index.js rename public_html/wp-content/plugins/{pattern-creator/src/components => pattern-directory/src}/media-placeholder/index.js (100%) rename public_html/wp-content/plugins/{pattern-creator/src/components => pattern-directory/src}/openverse/grid-actions.js (100%) rename public_html/wp-content/plugins/{pattern-creator/src/components => pattern-directory/src}/openverse/grid-items.js (100%) rename public_html/wp-content/plugins/{pattern-creator/src/components => pattern-directory/src}/openverse/grid.js (100%) rename public_html/wp-content/plugins/{pattern-creator/src/components => pattern-directory/src}/openverse/index.js (56%) rename public_html/wp-content/plugins/{pattern-creator/src/components/openverse/style.scss => pattern-directory/src/openverse/modal.scss} (90%) rename public_html/wp-content/plugins/{pattern-creator/src/components => pattern-directory/src}/openverse/pagination.js (100%) rename public_html/wp-content/plugins/{pattern-creator/src/components => pattern-directory/src}/openverse/powered-by-openverse.png (100%) rename public_html/wp-content/plugins/{pattern-creator/src/components => pattern-directory/src}/openverse/utils.js (100%) rename public_html/wp-content/plugins/pattern-directory/src/{pattern-post-type/details.js => pattern-details/index.js} (79%) delete mode 100644 public_html/wp-content/plugins/pattern-directory/src/pattern-post-type/index.js rename public_html/wp-content/plugins/pattern-directory/src/{pattern-post-type => }/settings.js (50%) rename public_html/wp-content/plugins/{pattern-creator/src/components => pattern-directory/src}/submission-modal/images/circle.svg (100%) rename public_html/wp-content/plugins/{pattern-creator/src/components => pattern-directory/src}/submission-modal/images/square.svg (100%) rename public_html/wp-content/plugins/{pattern-creator/src/components => pattern-directory/src}/submission-modal/images/triangle.svg (100%) rename public_html/wp-content/plugins/{pattern-creator/src/components => pattern-directory/src}/submission-modal/index.js (98%) rename public_html/wp-content/plugins/{pattern-creator/src/components/submission-modal/style.scss => pattern-directory/src/submission-modal/submission-modal.scss} (92%) rename public_html/wp-content/plugins/pattern-directory/src/{pattern-post-type => }/unlist-button/index.js (100%) rename public_html/wp-content/plugins/pattern-directory/src/{pattern-post-type => }/unlist-button/modal.js (100%) rename public_html/wp-content/plugins/pattern-directory/src/{pattern-post-type => }/unlist-button/notice.js (100%) rename public_html/wp-content/plugins/pattern-directory/src/{pattern-post-type => }/unlist-button/unlist.scss (100%) rename public_html/wp-content/plugins/pattern-directory/src/{pattern-post-type => }/unlist-button/utils.js (100%) diff --git a/package.json b/package.json index 8928dbb1e..3e56e84be 100644 --- a/package.json +++ b/package.json @@ -11,10 +11,8 @@ "@wordpress/stylelint-config": "23.6.0" }, "scripts": { - "build:creator": "npm run build --workspace=wporg-pattern-creator", "build:directory": "npm run build --workspace=wporg-pattern-directory", "build:theme": "npm run build --workspace=wporg-pattern-directory-2024-theme", - "start:creator": "npm run start --workspace=wporg-pattern-creator", "start:directory": "npm run start --workspace=wporg-pattern-directory", "start:theme": "npm run start --workspace=wporg-pattern-directory-2024-theme", "setup:tools": "echo \"Not used.\"", @@ -25,7 +23,6 @@ "test:php": "wp-env run tests-cli --env-cwd=/var/www/html/ ./vendor/bin/phpunit -c wp-content/tests/phpunit/phpunit.xml" }, "workspaces": [ - "public_html/wp-content/plugins/pattern-creator", "public_html/wp-content/plugins/pattern-directory", "public_html/wp-content/themes/wporg-pattern-directory-2024" ] diff --git a/public_html/wp-content/plugins/pattern-creator/jest.config.js b/public_html/wp-content/plugins/pattern-creator/jest.config.js deleted file mode 100644 index bb260342c..000000000 --- a/public_html/wp-content/plugins/pattern-creator/jest.config.js +++ /dev/null @@ -1,14 +0,0 @@ -const defaultConfig = require( '@wordpress/scripts/config/jest-unit.config' ); - -const config = { - ...defaultConfig, - moduleNameMapper: { - ...defaultConfig.moduleNameMapper, - // Force module uuid to resolve with the CJS entry point, because - // Jest does not support package.json.exports. - // See https://github.com/uuidjs/uuid/issues/451 - uuid: require.resolve( 'uuid' ), - }, -}; - -module.exports = config; diff --git a/public_html/wp-content/plugins/pattern-creator/package.json b/public_html/wp-content/plugins/pattern-creator/package.json deleted file mode 100644 index d5736fc1f..000000000 --- a/public_html/wp-content/plugins/pattern-creator/package.json +++ /dev/null @@ -1,62 +0,0 @@ -{ - "name": "wporg-pattern-creator", - "version": "1.0.0", - "description": "Create block patterns on the frontend of a site.", - "author": "The WordPress Meta Team", - "license": "GPL-2.0-or-later", - "scripts": { - "build": "wp-scripts build", - "dev": "NODE_ENV=development wp-scripts build", - "format:js": "wp-scripts format src -- --config=../../../../.prettierrc.js", - "lint:css": "wp-scripts lint-style 'style.css' 'src/**/*.scss'", - "lint:js": "wp-scripts lint-js src", - "start": "wp-scripts start", - "test:unit": "wp-scripts test-unit-js" - }, - "devDependencies": { - "@wordpress/dependency-extraction-webpack-plugin": "5.2.0", - "@wordpress/scripts": "27.2.0", - "autoprefixer": "10.4.17", - "deep-freeze": "0.0.1", - "postcss-custom-properties": "13.3.4" - }, - "dependencies": { - "@wordpress/a11y": "4.14.0", - "@wordpress/api-fetch": "7.14.0", - "@wordpress/block-editor": "14.9.0", - "@wordpress/block-library": "9.14.0", - "@wordpress/blocks": "14.3.0", - "@wordpress/components": "29.0.0", - "@wordpress/compose": "7.14.0", - "@wordpress/core-data": "7.14.0", - "@wordpress/data": "10.14.0", - "@wordpress/dom-ready": "4.14.0", - "@wordpress/edit-post": "8.14.0", - "@wordpress/editor": "14.14.0", - "@wordpress/element": "6.14.0", - "@wordpress/format-library": "5.14.0", - "@wordpress/hooks": "4.14.0", - "@wordpress/i18n": "5.14.0", - "@wordpress/icons": "10.14.0", - "@wordpress/interface": "8.3.0", - "@wordpress/keyboard-shortcuts": "5.14.0", - "@wordpress/keycodes": "4.14.0", - "@wordpress/notices": "5.14.0", - "@wordpress/plugins": "7.14.0", - "@wordpress/primitives": "4.14.0", - "@wordpress/url": "4.14.0", - "classnames": "2.5.1", - "lodash": "4.17.21", - "rememo": "4.0.2" - }, - "eslintConfig": { - "extends": "../../../../.eslintrc.js", - "globals": { - "wporgBlockPattern": "readonly", - "wporgLocale": "readonly" - } - }, - "stylelint": { - "extends": "../../../../.stylelintrc" - } -} diff --git a/public_html/wp-content/plugins/pattern-creator/pattern-creator.php b/public_html/wp-content/plugins/pattern-creator/pattern-creator.php deleted file mode 100644 index d6c7bb5ef..000000000 --- a/public_html/wp-content/plugins/pattern-creator/pattern-creator.php +++ /dev/null @@ -1,338 +0,0 @@ -is_singular( POST_TYPE ) && false !== $wp_query->get( IS_EDIT_VAR, false ); - $is_new = is_page( 'new-pattern' ); - return $is_editor || $is_new; -} - -/** - * Returns whether the pattern is being edited - * - * @return boolean - */ -function is_editing_pattern() { - return '' !== get_query_var( PATTERN_ID_VAR ); -} - -/** - * Add our custom parameter to the list of public query variables. - * - * @param string[] $query_vars The array of allowed query variable names. - * @return stringp[] New query vars. - */ -function add_query_var( $query_vars ) { - $query_vars[] = IS_EDIT_VAR; - $query_vars[] = PATTERN_ID_VAR; - return $query_vars; -} -add_filter( 'query_vars', __NAMESPACE__ . '\add_query_var' ); - -/** - * Register & load the assets, initialize pattern creator. - * - * @throws \Error If the build files don't exist. - */ -function pattern_creator_init() { - global $editor_styles; - - if ( ! should_load_creator() ) { - return; - } - - if ( - ! ( is_editing_pattern() && current_user_can( 'edit_pattern', get_query_var( PATTERN_ID_VAR ) ) ) && - ! ( ! is_editing_pattern() && is_user_logged_in() ) - ) { - return; - } - - wp_deregister_style( 'wporg-style' ); - // These will have no effect if the styles are not registered. - wp_deregister_style( 'wporg-pattern-directory-2024-style' ); - wp_deregister_style( 'wporg-parent-2021-style' ); - wp_deregister_style( 'global-styles' ); - - $dir = dirname( __FILE__ ); - $script_asset_path = "$dir/build/index.asset.php"; - if ( ! file_exists( $script_asset_path ) ) { - throw new \Error( 'You need to run `npm run start:creator` or `npm run build:creator` for the Pattern Creator.' ); - } - - $script_asset = require( $script_asset_path ); - wp_enqueue_script( - 'wp-pattern-creator', - plugins_url( 'build/index.js', __FILE__ ), - $script_asset['dependencies'], - $script_asset['version'], - true - ); - wp_set_script_translations( 'wp-pattern-creator', 'wporg-patterns' ); - - wp_add_inline_script( - 'wp-pattern-creator', - sprintf( - "var wporgLocale = JSON.parse( decodeURIComponent( '%s' ) );", - rawurlencode( wp_json_encode( array( - 'id' => get_locale(), - 'displayName' => is_rosetta_site() ? get_rosetta_name() : '', - ) ) ), - ), - 'before' - ); - - wp_add_inline_script( - 'wp-pattern-creator', - sprintf( - 'var wporgBlockPattern = JSON.parse( decodeURIComponent( \'%s\' ) );', - rawurlencode( wp_json_encode( array( - 'siteUrl' => esc_url( home_url() ), - ) ) ) - ), - 'before' - ); - - wp_enqueue_style( - 'wp-pattern-creator', - plugins_url( 'build/style-index.css', __FILE__ ), - array( 'wp-components' ), - filemtime( "$dir/build/style-index.css" ) - ); - - /** Load in admin post functions for `get_default_post_to_edit`. */ - require_once ABSPATH . 'wp-admin/includes/post.php'; - - if ( is_singular( POST_TYPE ) || is_editing_pattern() ) { - $post_id = is_editing_pattern() ? $post_id = get_query_var( PATTERN_ID_VAR ) : get_the_ID(); - $post = get_post( $post_id ); - } else { - $post = get_default_post_to_edit( POST_TYPE, true ); - $post_id = $post->ID; - // Set up the default locale. - update_post_meta( $post_id, 'wpop_locale', 'en_US' ); - } - - add_filter( 'should_load_separate_core_block_assets', '__return_false', 100 ); - add_filter( 'template', __NAMESPACE__ . '\set_theme_twentytwentythree' ); - add_filter( 'stylesheet', __NAMESPACE__ . '\set_theme_twentytwentythree' ); - - $custom_settings = array( - 'postId' => $post_id, - 'siteUrl' => site_url(), - 'postsPerPage' => get_option( 'posts_per_page' ), - 'styles' => get_block_editor_theme_styles(), - '__experimentalBlockPatterns' => array(), - '__experimentalBlockPatternCategories' => array(), - ); - - wp_deregister_script( 'wporg-global-header-script' ); - - $editor_context = new WP_Block_Editor_Context( array( 'post' => $post ) ); - $settings = get_block_editor_settings( $custom_settings, $editor_context ); - - $settings['defaultStatus'] = get_option( 'wporg-pattern-default_status', 'publish' ); - - remove_filter( 'template', __NAMESPACE__ . '\set_theme_twentytwentythree' ); - remove_filter( 'stylesheet', __NAMESPACE__ . '\set_theme_twentytwentythree' ); - - gutenberg_initialize_editor( - 'block-pattern-creator', - 'pattern-creator', - array( - 'preload_paths' => array(), - 'initializer_name' => 'initialize', - 'editor_settings' => $settings, - ) - ); - - wp_add_inline_script( - 'wp-blocks', - sprintf( 'wp.blocks.setCategories( %s );', wp_json_encode( get_block_categories( $post ) ) ), - 'after' - ); - - wp_enqueue_script( 'wp-edit-site' ); - wp_enqueue_script( 'wp-format-library' ); - wp_enqueue_style( 'wp-edit-site' ); - wp_enqueue_style( 'wp-format-library' ); - wp_enqueue_media(); -} -add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\pattern_creator_init', 20 ); - -/** - * Bypass WordPress template system to load only our editor app. - */ -function inject_editor_template( $template ) { - if ( should_load_creator() ) { - return __DIR__ . '/view/editor.php'; - } - return $template; -} -add_filter( 'template_include', __NAMESPACE__ . '\inject_editor_template' ); - -/** - * Add a rewrite rule to handle editing a pattern. - */ -function rewrite_for_pattern_editing() { - add_rewrite_rule( '^pattern/(\d+)/edit', 'index.php?pagename=new-pattern&' . PATTERN_ID_VAR . '=$matches[1]', 'top' ); -} -add_action( 'init', __NAMESPACE__ . '\rewrite_for_pattern_editing' ); - -/** - * Always disable the admin bar on the creator page. - * - * @param bool $show_admin_bar Whether the admin bar should be shown. Default false. - * @return bool Filtered value. - */ -function show_admin_bar( $show_admin_bar ) { - if ( ! should_load_creator() ) { - return $show_admin_bar; - } - - return false; -} -// Priority needs to be over 1000 to override `logged-out-admin-bar`. -add_filter( 'show_admin_bar', __NAMESPACE__ . '\show_admin_bar', 1001 ); - -/** - * Filter out `upload_files` from all non-admin users. - * - * @param bool[] $allcaps Array of key/value pairs where keys represent a capability name - * and boolean values represent whether the user has that capability. - */ -function disallow_uploads( $allcaps ) { - if ( ! isset( $allcaps['manage_options'] ) ) { - $allcaps['upload_files'] = false; - } - return $allcaps; -} -add_filter( 'user_has_cap', __NAMESPACE__ . '\disallow_uploads' ); - -/** - * Set up any custom endpoints. - */ -function rest_api_init() { - require_once __DIR__ . '/includes/openverse-client.php'; - require_once __DIR__ . '/includes/openverse-rest-controller.php'; - $controller = new \Openverse_REST_Controller(); - $controller->register_routes(); - - // Allow the post type labels through the `types` endpoint when viewing. - // This passes the value back to unauthenticated users, which prevents JS - // errors when the post-date block tries to use them. - register_rest_field( - 'type', // The object-type for the `types` endpoint. - 'labels', - array( - 'schema' => array( - 'description' => __( 'Human-readable labels for the post type for various contexts.', 'wporg-patterns' ), - 'type' => 'object', - 'context' => array( 'edit', 'view' ), - 'readonly' => true, - ), - ) - ); -} -add_action( 'rest_api_init', __NAMESPACE__ . '\rest_api_init' ); - -/** - * Return the appropriate theme slug for the current environment. - * - * @return string Theme slug. - */ -function set_theme_twentytwentythree() { - if ( 'local' === wp_get_environment_type() ) { - return 'twentytwentythree'; - } else { - return 'core/twentytwentythree'; - } -} - -/** - * Temporarily restore gutenberg_initialize_editor() for compat with Gutenberg 16.5.0 - * - * @see https://github.com/WordPress/pattern-directory/issues/601 - */ -function gutenberg_initialize_editor( $editor_name, $editor_script_handle, $settings ) { - - $defaults = array( - 'preload_paths' => array(), - 'initializer_name' => 'initialize', - 'editor_settings' => array(), - ); - - $settings = wp_parse_args( $settings, $defaults ); - - /** - * Preload common data by specifying an array of REST API paths that will be preloaded. - * - * Filters the array of paths that will be preloaded. - * - * @param string[] $preload_paths Array of paths to preload. - */ - $preload_paths = apply_filters( "{$editor_name}_preload_paths", $settings['preload_paths'] ); - - $preload_data = array_reduce( - $preload_paths, - 'rest_preload_api_request', - array() - ); - - wp_add_inline_script( - 'wp-api-fetch', - sprintf( - 'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );', - wp_json_encode( $preload_data ) - ), - 'after' - ); - wp_add_inline_script( - "wp-{$editor_script_handle}", - sprintf( - 'wp.domReady( function() { - wp.%s.%s( "%s", %s ); - } );', - lcfirst( str_replace( '-', '', ucwords( $editor_script_handle, '-' ) ) ), - $settings['initializer_name'], - str_replace( '_', '-', $editor_name ), - wp_json_encode( $settings['editor_settings'] ) - ) - ); - - // Preload server-registered block schemas. - wp_add_inline_script( - 'wp-blocks', - 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');' - ); -} diff --git a/public_html/wp-content/plugins/pattern-creator/postcss.config.js b/public_html/wp-content/plugins/pattern-creator/postcss.config.js deleted file mode 100644 index 4dc1f5191..000000000 --- a/public_html/wp-content/plugins/pattern-creator/postcss.config.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = { - ident: 'postcss', - plugins: [ require( 'autoprefixer' )() ], -}; diff --git a/public_html/wp-content/plugins/pattern-creator/readme.md b/public_html/wp-content/plugins/pattern-creator/readme.md deleted file mode 100644 index 6cadca6fb..000000000 --- a/public_html/wp-content/plugins/pattern-creator/readme.md +++ /dev/null @@ -1,22 +0,0 @@ -# WordPress.org Block Pattern Creator - -This plugin adds an editor interface to the frontend of Block Pattern posts. - -## Requirements - -These should be available if you're using this environment. - -Plugins -- Gutenberg -- Pattern Directory - -Theme -- WordPress.org Pattern Directory (TBD) - -## Try it out - -See the [root Readme for dev environment info.](../../../../readme.md) - -Create some Block Patterns in wp-admin, `/wp-admin/post-new.php?post_type=wporg-pattern`. - -View a published pattern, if you're logged in you should see the pattern editor. Play around & save your pattern. diff --git a/public_html/wp-content/plugins/pattern-creator/src/api-middleware/filter-endpoints.js b/public_html/wp-content/plugins/pattern-creator/src/api-middleware/filter-endpoints.js deleted file mode 100644 index 3377eb795..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/api-middleware/filter-endpoints.js +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Update the `context` query parameter to view for a set of endpoints. - * - * @param {string} path The endpoint path (possibly with a query string). - * @return {string} The path with the updated context. - */ -function maybeUpdateContext( path ) { - if ( ! path.includes( 'context=' ) ) { - return path; - } - - const endpointRegexes = [ - // All post endpoints. - /^\/wp\/v2\/posts/, - /^\/wp\/v2\/blocks/, - /^\/wp\/v2\/tags/, - /^\/wp\/v2\/categories/, - // Category and tag taxonomies. - /^\/wp\/v2\/taxonomies\/(category|post_tag)/, - // All post type endpoints except `wporg-pattern`, which needs to keep the `edit` context. - /^\/wp\/v2\/types(?!\/wporg-pattern)/, - ]; - - if ( endpointRegexes.some( ( regex ) => regex.test( path ) ) ) { - return path.replace( 'context=edit', 'context=view' ); - } - - return path; -} - -// Use a middleware provider to intercept and modify API calls. -// Short-circuit POST requests, bound queries, allow media, etc. -export default async function ( options, next ) { - if ( options.path ) { - // Add limits to all GET queries which attempt unbound queries - options.path = options.path.replace( 'per_page=-1', 'per_page=50' ); - - options.path = maybeUpdateContext( options.path ); - } - - // Wait to get the API response back, so it can be filtered. - const response = await next( options ); - - if ( options.path ) { - if ( options.path.includes( '/wp/v2/types?' ) ) { - // Set posts to viewable, but pages and patterns are not viewable. - // This controls whether these post-types are options in the Query - // Loop block. Pages are disabled because a regular user trying to - // access pages results in a `403` error. Patterns are disabled - // because they won't exist on other sites. - if ( response.post ) { - response.post.viewable = true; - } - if ( response.page ) { - response.page.viewable = false; - } - if ( response[ 'wporg-pattern' ] ) { - response[ 'wporg-pattern' ].viewable = false; - } - } else if ( options.path.includes( '/wp/v2/posts' ) ) { - response.forEach( ( post, index ) => { - if ( post.content && ! post.content.raw ) { - const content = post.content.rendered || ''; - post.content.raw = content; - } - response[ index ] = post; - } ); - } - } - - return response; -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/api-middleware/index.js b/public_html/wp-content/plugins/pattern-creator/src/api-middleware/index.js deleted file mode 100644 index f39514a21..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/api-middleware/index.js +++ /dev/null @@ -1,14 +0,0 @@ -/** - * WordPress dependencies - */ -import apiFetch from '@wordpress/api-fetch'; - -/** - * Internal dependencies - */ -import filterEndpoints from './filter-endpoints'; -import mockSiteData from './mock-site-data'; - -// Set up API middleware. -apiFetch.use( filterEndpoints ); -apiFetch.use( mockSiteData ); diff --git a/public_html/wp-content/plugins/pattern-creator/src/api-middleware/mock-site-data.js b/public_html/wp-content/plugins/pattern-creator/src/api-middleware/mock-site-data.js deleted file mode 100644 index 0265d4d2f..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/api-middleware/mock-site-data.js +++ /dev/null @@ -1,35 +0,0 @@ -/** - * WordPress dependencies - */ -import { __ } from '@wordpress/i18n'; -import apiFetch from '@wordpress/api-fetch'; - -export default apiFetch.createPreloadingMiddleware( { - '/?_fields=description,gmt_offset,home,name,site_icon,site_icon_url,site_logo,timezone_string,url': { - body: { - // Set up default values for use in site-* blocks (site-title, - // site-tagline, site-logo). These placeholders should be the same - // as content returned in `includes/mock-blocks.php`. - name: __( 'Site Title placeholder', 'wporg-patterns' ), - description: __( 'Site Tagline placeholder', 'wporg-patterns' ), - url: 'https://wordpress.org/patterns', - home: 'https://wordpress.org/patterns', - gmt_offset: '0', - timezone_string: '', - // Technically this should be an int (ID), but it's not validated - // since the API reponse is preloaded below. Using "logo" to avoid - // collision with a real media item. - site_logo: 'logo', - site_icon: 0, - site_icon_url: 'https://s.w.org/images/wmark.png', - }, - }, - // Replace the custom logo output with the WordPress W. - '/wp/v2/media/logo?context=view': { - body: { - id: 'logo', - alt_text: __( 'Site logo', 'wporg-patterns' ), - source_url: 'https://s.w.org/images/wmark.png', - }, - }, -} ); diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/block-editor/index.js b/public_html/wp-content/plugins/pattern-creator/src/components/block-editor/index.js deleted file mode 100644 index 0724b0a2f..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/block-editor/index.js +++ /dev/null @@ -1,88 +0,0 @@ -/** - * WordPress dependencies - */ -import { useSelect } from '@wordpress/data'; -import { useRef } from '@wordpress/element'; -import { useEntityBlockEditor } from '@wordpress/core-data'; -/* eslint-disable @wordpress/no-unsafe-wp-apis */ -import { - BlockEditorProvider, - BlockInspector, - BlockList, - BlockTools, - __unstableEditorStyles as EditorStyles, - __unstableIframe as Iframe, - privateApis as blockEditorPrivateApis, - __unstableUseMouseMoveTypingReset as useMouseMoveTypingReset, - __experimentalUseResizeCanvas as useResizeCanvas, - useSettings, - __unstableUseTypingObserver as useTypingObserver, -} from '@wordpress/block-editor'; -/* eslint-enable @wordpress/no-unsafe-wp-apis */ -import { PostTitle, VisualEditorGlobalKeyboardShortcuts } from '@wordpress/editor'; -import { useMergeRefs } from '@wordpress/compose'; - -/** - * Internal dependencies - */ -import { POST_TYPE, store as patternStore } from '../../store'; -import { SidebarInspectorFill } from '../sidebar'; -import { unlock } from '../../lock-unlock'; - -const { LayoutStyle } = unlock( blockEditorPrivateApis ); - -export default function BlockEditor( { setIsInserterOpen } ) { - const { settings, deviceType } = useSelect( - ( select ) => { - const { getSettings, getPreviewDeviceType } = select( patternStore ); - return { - settings: getSettings( setIsInserterOpen ), - deviceType: getPreviewDeviceType(), - }; - }, - [ setIsInserterOpen ] - ); - const [ layout ] = useSettings( 'layout' ); - const [ blocks, onInput, onChange ] = useEntityBlockEditor( 'postType', POST_TYPE ); - const resizedCanvasStyles = useResizeCanvas( deviceType, true ); - const ref = useMouseMoveTypingReset(); - const contentRef = useRef(); - const mergedRefs = useMergeRefs( [ contentRef, useTypingObserver() ] ); - - return ( - - - - - - -
- -
- -
-
- ); -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/block-editor/style.scss b/public_html/wp-content/plugins/pattern-creator/src/components/block-editor/style.scss deleted file mode 100644 index 6f9bbee62..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/block-editor/style.scss +++ /dev/null @@ -1,27 +0,0 @@ -// The button element easily inherits styles that are meant for the editor style. -// These rules enhance the specificity to reduce that inheritance. -// This is duplicated in visual-editor. -.pattern-block-editor__editor-styles-wrapper .components-button { - font-family: $default-font; - font-size: $default-font-size; - padding: 6px 12px; - - &.is-tertiary, - &.has-icon { - padding: 6px; - } -} - -.pattern-visual-editor__post-title-wrapper { - max-width: 960px; - margin-left: auto; - margin-right: auto; - - h1 { - color: $white; - } -} - -.pattern-visual-editor > [name="editor-canvas"] { - margin-top: 0 !important; -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/editor/index.js b/public_html/wp-content/plugins/pattern-creator/src/components/editor/index.js deleted file mode 100644 index 3b8e81d52..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/editor/index.js +++ /dev/null @@ -1,141 +0,0 @@ -/** - * WordPress dependencies - */ -import { __ } from '@wordpress/i18n'; -import { useDispatch, useSelect } from '@wordpress/data'; -import { BlockBreadcrumb } from '@wordpress/block-editor'; -import { useCallback, useEffect, useState } from '@wordpress/element'; -import { - ComplementaryArea, - FullscreenMode, - InterfaceSkeleton, - store as interfaceStore, -} from '@wordpress/interface'; -import { store as coreStore } from '@wordpress/core-data'; -import { store as noticesStore } from '@wordpress/notices'; -import { - EditorNotices, - EditorProvider, - EditorSnackbars, - ErrorBoundary, - UnsavedChangesWarning, -} from '@wordpress/editor'; -import { Notice, Popover, SlotFillProvider } from '@wordpress/components'; -import { ShortcutProvider } from '@wordpress/keyboard-shortcuts'; - -/** - * Internal dependencies - */ -import BlockEditor from '../block-editor'; -import EntitiesSavedStates from './save-sidebar'; -import Header from '../header'; -import InserterSidebar from '../secondary-sidebar/inserter-sidebar'; -import KeyboardShortcuts from '../keyboard-shortcuts'; -import ListViewSidebar from '../secondary-sidebar/list-view-sidebar'; -import { POST_TYPE, store as patternStore } from '../../store'; -import { SidebarComplementaryAreaFills } from '../sidebar'; -import { STORE_NAME } from '../../store/constants'; -import UrlController from '../url-controller'; -import WelcomeGuide from '../welcome-guide'; - -const interfaceLabels = { - secondarySidebar: __( 'Block Library', 'wporg-patterns' ), - actions: __( 'Editor publish', 'wporg-patterns' ), -}; - -function Editor( { onError, postId } ) { - const { isInserterOpen, isListViewOpen, post, sidebarIsOpened, settings } = useSelect( ( select ) => { - const { isInserterOpened, isListViewOpened, getSettings } = select( patternStore ); - const { getEntityRecord } = select( coreStore ); - - return { - isInserterOpen: isInserterOpened(), - isListViewOpen: isListViewOpened(), - post: getEntityRecord( 'postType', POST_TYPE, postId ), - sidebarIsOpened: !! select( interfaceStore ).getActiveComplementaryArea( STORE_NAME ), - settings: getSettings(), - }; - }, [] ); - const { setIsInserterOpened } = useDispatch( patternStore ); - const { createInfoNotice } = useDispatch( noticesStore ); - const [ isEntitiesSavedStatesOpen, setIsEntitiesSavedStatesOpen ] = useState( false ); - const closeEntitiesSavedStates = useCallback( () => { - setIsEntitiesSavedStatesOpen( false ); - }, [] ); - const openEntitiesSavedStates = useCallback( () => { - setIsEntitiesSavedStatesOpen( true ); - }, [] ); - - useEffect( () => { - if ( ! wporgLocale.id.startsWith( 'en_' ) ) { - createInfoNotice( __( 'Patterns should be submitted in English.', 'wporg-patterns' ), { - isDismissible: false, - } ); - } - }, [] ); - - // Don't render the Editor until the settings are set and loaded - if ( ! settings?.siteUrl || ! post ) { - return null; - } - - const secondarySidebar = () => { - if ( isInserterOpen ) { - return ; - } - if ( isListViewOpen ) { - return ; - } - return null; - }; - - return ( - - - - - - - - - - } - header={
} - notices={ } - content={ - <> - - - { ! postId && ( - - { __( - "You attempted to edit an item that doesn't exist. Perhaps it was deleted?", - 'wporg-patterns' - ) } - - ) } - - - } - actions={ - - } - footer={ } - /> - - - - - - - ); -} -export default Editor; diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/editor/save-sidebar.js b/public_html/wp-content/plugins/pattern-creator/src/components/editor/save-sidebar.js deleted file mode 100644 index 290f18a05..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/editor/save-sidebar.js +++ /dev/null @@ -1,46 +0,0 @@ -/** - * WordPress dependencies - */ -import { Button, createSlotFill } from '@wordpress/components'; -import { EntitiesSavedStates, PostPublishPanel } from '@wordpress/editor'; -import { __ } from '@wordpress/i18n'; - -// @todo bring back pre/post publish plugin slots. - -const { Fill, Slot } = createSlotFill( 'ActionsPanel' ); - -export const ActionsPanelFill = Fill; - -export default function ActionsPanel( { - closeEntitiesSavedStates, - openEntitiesSavedStates, - isEntitiesSavedStatesOpen, -} ) { - let unmountableContent; - if ( isEntitiesSavedStatesOpen ) { - unmountableContent = ; - } else { - unmountableContent = ( -
- -
- ); - } - - // Since EntitiesSavedStates controls its own panel, we can keep it - // always mounted to retain its own component state (such as checkboxes). - return ( - <> - { isEntitiesSavedStatesOpen && } - - { ! isEntitiesSavedStatesOpen && unmountableContent } - - ); -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/editor/style.scss b/public_html/wp-content/plugins/pattern-creator/src/components/editor/style.scss deleted file mode 100644 index b8d66cf3b..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/editor/style.scss +++ /dev/null @@ -1,48 +0,0 @@ -// Unset the top spacing to avoid misaligning the creator UI. -html { - margin-top: 0 !important; - scroll-padding-top: 0 !important; -} - -// Push the global header & footer behind the creator UI. -.wp-block-group.global-footer, -.wp-block-group.global-header { - position: relative !important; - z-index: -1 !important; -} - -// Hide the footer to prevent vertical scroll bar. -.wp-block-group.global-footer { - display: none; -} - -.pattern-interface { - // This should always be 0, because we never have an admin bar to contend with. - top: 0 !important; - z-index: 1; -} - -.pattern-visual-editor { - position: relative; - height: 100%; - display: flex; - flex-flow: column; - background: $gray-800; - - iframe { - display: block; - width: 100%; - height: 100%; - background-color: $white; - } -} - -// Adjust the position of the notices -.pattern .components-editor-notices__snackbar { - position: fixed; - left: 0; - right: 0; - bottom: 40px; - padding-left: 16px; - padding-right: 16px; -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/header/feature-toggle/index.js b/public_html/wp-content/plugins/pattern-creator/src/components/header/feature-toggle/index.js deleted file mode 100644 index 96b893d88..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/header/feature-toggle/index.js +++ /dev/null @@ -1,46 +0,0 @@ -/** - * External dependencies - */ -import { flow } from 'lodash'; - -/** - * WordPress dependencies - */ -import { useDispatch, useSelect } from '@wordpress/data'; -import { MenuItem } from '@wordpress/components'; -import { __ } from '@wordpress/i18n'; -import { check } from '@wordpress/icons'; -import { speak } from '@wordpress/a11y'; - -/** - * Internal dependencies - */ -import { store as patternStore } from '../../../store'; - -export default function FeatureToggle( { feature, label, info, messageActivated, messageDeactivated } ) { - const speakMessage = () => { - if ( isActive ) { - speak( messageDeactivated || __( 'Feature deactivated', 'wporg-patterns' ) ); - } else { - speak( messageActivated || __( 'Feature activated', 'wporg-patterns' ) ); - } - }; - - const isActive = useSelect( ( select ) => { - return select( patternStore ).isFeatureActive( feature ); - }, [] ); - - const { toggleFeature } = useDispatch( patternStore ); - - return ( - - { label } - - ); -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/header/index.js b/public_html/wp-content/plugins/pattern-creator/src/components/header/index.js deleted file mode 100644 index 337181184..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/header/index.js +++ /dev/null @@ -1,119 +0,0 @@ -/** - * External dependencies - */ -import classnames from 'classnames'; - -/** - * WordPress dependencies - */ -import { __, _x } from '@wordpress/i18n'; -import { ToolSelector } from '@wordpress/block-editor'; -import { Button, VisuallyHidden } from '@wordpress/components'; -import { Icon, arrowLeft, listView, plus } from '@wordpress/icons'; -import { PinnedItems } from '@wordpress/interface'; -import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts'; -import { useCallback, useRef } from '@wordpress/element'; -import { useDispatch, useSelect } from '@wordpress/data'; -import { useViewportMatch } from '@wordpress/compose'; - -/** - * Internal dependencies - */ -import MoreMenu from './more-menu'; -import RedoButton from './undo-redo/redo'; -import { SaveButton, SaveDraftButton } from '../save-button'; -import { store as patternStore } from '../../store'; -import UndoButton from './undo-redo/undo'; - -const preventDefault = ( event ) => { - event.preventDefault(); -}; - -export default function Header() { - const inserterButton = useRef(); - const { hasReducedUI, isInserterOpen, isListViewOpen, listViewShortcut } = useSelect( ( select ) => { - const { isFeatureActive, isInserterOpened, isListViewOpened } = select( patternStore ); - const { getShortcutRepresentation } = select( keyboardShortcutsStore ); - - return { - hasReducedUI: isFeatureActive( 'reducedUI' ), - isInserterOpen: isInserterOpened(), - isListViewOpen: isListViewOpened(), - listViewShortcut: getShortcutRepresentation( 'core/edit-site/toggle-list-view' ), - }; - }, [] ); - - const { setIsInserterOpened, setIsListViewOpened } = useDispatch( patternStore ); - - const isLargeViewport = useViewportMatch( 'medium' ); - - const openInserter = useCallback( () => { - if ( isInserterOpen ) { - // Focusing the inserter button closes the inserter popover - inserterButton.current.focus(); - } else { - setIsInserterOpened( true ); - } - }, [ isInserterOpen, setIsInserterOpened ] ); - - const toggleListView = useCallback( - () => setIsListViewOpened( ! isListViewOpen ), - [ setIsListViewOpened, isListViewOpen ] - ); - - const classes = classnames( 'pattern-header', { - 'has-reduced-ui': hasReducedUI, - } ); - - return ( -
-
- - - { __( 'Pattern Directory', 'wporg-patterns' ) } - -
-
-
- -
-
- - - - -
-
-
- ); -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/header/more-menu/index.js b/public_html/wp-content/plugins/pattern-creator/src/components/header/more-menu/index.js deleted file mode 100644 index e1eea6fb2..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/header/more-menu/index.js +++ /dev/null @@ -1,70 +0,0 @@ -/** - * WordPress dependencies - */ -import { __, _x } from '@wordpress/i18n'; -import { moreVertical } from '@wordpress/icons'; -import { DropdownMenu, MenuGroup } from '@wordpress/components'; -import { ActionItem } from '@wordpress/interface'; - -/** - * Internal dependencies - */ -import FeatureToggle from '../feature-toggle'; -import ToolsMoreMenuGroup from '../tools-more-menu-group'; - -const POPOVER_PROPS = { - className: 'pattern-more-menu__content', - position: 'bottom left', -}; -const TOGGLE_PROPS = { - tooltipPosition: 'bottom', -}; - -const MoreMenu = () => ( - - { ( { onClose } ) => ( - <> - - - - - - - - - - ) } - -); - -export default MoreMenu; diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/header/more-menu/style.scss b/public_html/wp-content/plugins/pattern-creator/src/components/header/more-menu/style.scss deleted file mode 100644 index 423f6048b..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/header/more-menu/style.scss +++ /dev/null @@ -1,29 +0,0 @@ -.pattern-more-menu { - margin-left: -4px; - - // the padding and margin of the more menu is intentionally non-standard - .components-button { - width: auto; - padding: 0 2px; - } - - @include break-small() { - margin-left: 4px; - - .components-button { - padding: 0 4px; - } - } -} - -.pattern-more-menu__content .components-popover__content { - min-width: 260px; - - .components-dropdown-menu__menu { - padding: 0; - } -} - -.components-popover.pattern-more-menu__content { - z-index: z-index(".components-popover.interface-more-menu__content"); -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/header/style.scss b/public_html/wp-content/plugins/pattern-creator/src/components/header/style.scss deleted file mode 100644 index c257ba65a..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/header/style.scss +++ /dev/null @@ -1,232 +0,0 @@ -$header-toolbar-min-width: 335px; - -.pattern-header { - align-items: center; - background-color: $white; - display: flex; - height: $header-height; - box-sizing: border-box; - width: 100%; - justify-content: space-between; - - .pattern-header_start, - .pattern-header_end { - display: flex; - } - - .pattern-header_center { - display: flex; - align-items: center; - height: 100%; - // Flex items will, by default, refuse to shrink below a minimum - // intrinsic width. In order to shrink this flexbox item, and - // subsequently truncate child text, we set an explicit min-width. - // See https://dev.w3.org/csswg/css-flexbox/#min-size-auto - min-width: 0; - } - - .pattern-header_end { - justify-content: flex-end; - } -} - -// Keeps the document title centered when the sidebar is open -body.is-navigation-sidebar-open { - .pattern-header { - padding-left: 0; - transition: padding-left 20ms linear; - transition-delay: 0ms; - - @include reduce-motion("transition"); - } -} - -// Centred document title on small screens with sidebar open -@media ( max-width: #{ ($break-large - 1) } ) { - body.is-navigation-sidebar-open .pattern-header { - .pattern-header-toolbar__inserter-toggle ~ .components-button, - .pattern-header_end .components-button:not(.is-primary) { - display: none; - } - - .pattern-save-button__button { - margin-right: 0; - } - } -} - -.pattern-header__toolbar { - display: flex; - align-items: center; - padding-left: $grid-unit-10; - - @include break-small() { - padding-left: $grid-unit-30; - } - - @include break-wide() { - padding-right: $grid-unit-10; - } - - .pattern-header-toolbar__inserter-toggle { - margin-right: $grid-unit-10; - min-width: $grid-unit-40; - width: $grid-unit-40; - height: $grid-unit-40; - padding: 0; - - svg { - transition: transform cubic-bezier(0.165, 0.84, 0.44, 1) 0.2s; - - @include reduce-motion("transition"); - } - - &.is-pressed { - svg { - transform: rotate(45deg); - } - } - } -} - -.pattern-header__toolbar-switchers { - align-items: center; - display: flex; -} - -.pattern-header__toolbar-switchers-separator { - margin: 0 -6px 0; -} - -/** - * Buttons in the Toolbar - */ - -.pattern-header__actions { - display: inline-flex; - align-items: center; - flex-wrap: wrap; - padding-right: $grid-unit-05; - - .interface-pinned-items { - display: none; - - @include break-medium() { - display: inline-flex; - } - } - - // Adjust button paddings to scale better to mobile. - .editor-post-saved-state, - .components-button.components-button { - margin-right: $grid-unit-05; - - @include break-small() { - margin-right: $grid-unit-15; - } - } - - .editor-post-saved-state, - .components-button.is-tertiary { - padding: 0 #{$grid-unit-15 * 0.5}; - } - - .pattern-more-menu .components-button, - .interface-pinned-items .components-button { - margin-right: 0; - } - - @include break-small() { - padding-right: $grid-unit-20; - } -} - -.main-dashboard-button { - display: flex; - align-items: center; - align-self: stretch; - justify-content: center; - border: none; - background: $gray-900; - color: $white; - fill: currentColor; - border-radius: 0; - height: $header-height + $border-width; - width: $header-height; - position: relative; - margin-bottom: - $border-width; - - &:hover, - &:active, - &:visited { - color: $white; - } - - &:focus { - box-shadow: none; - } - - &::before { - transition: box-shadow 0.1s ease; - - @include reduce-motion("transition"); - content: ""; - display: block; - position: absolute; - top: 9px; - right: 9px; - bottom: 9px; - left: 9px; - border-radius: $radius-block-ui + $border-width + $border-width; - box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) $gray-900; - } - - // Hover color. - &:hover::before { - box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) $gray-700; - } - - // Lightened spot color focus. - &:focus::before { - box-shadow: - inset 0 0 0 var(--wp-admin-border-width-focus) rgba($white, 0.1), - inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color); - } -} - -.pattern-header.has-reduced-ui { - - @include break-small () { - // Apply transition to every button but the first one. - .pattern-header__toolbar > * + .components-button, - .pattern-header__toolbar > * + .components-dropdown > [aria-expanded="false"] { - transition: opacity 0.1s linear; - - @include reduce-motion("transition"); - } - - // Zero out opacity unless hovered. - &:not(:hover) .pattern-header__toolbar > * + .components-button, - &:not(:hover) .pattern-header__toolbar > * + .components-dropdown > [aria-expanded="false"] { - opacity: 0; - } - } -} - -.pattern-header__actions-more-menu { - margin-left: -4px; - - // The padding and margin of the more menu is intentionally non-standard. - .components-icon-button { - padding: 8px 2px; - width: auto; - } - - @include break-small() { - margin-left: 4px; - - .components-icon-button { - padding: 8px 4px; - } - } -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/header/tools-more-menu-group/index.js b/public_html/wp-content/plugins/pattern-creator/src/components/header/tools-more-menu-group/index.js deleted file mode 100644 index 6de5bbd5c..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/header/tools-more-menu-group/index.js +++ /dev/null @@ -1,22 +0,0 @@ -/** - * External dependencies - */ -import { isEmpty } from 'lodash'; - -/** - * WordPress dependencies - */ -import { MenuGroup, createSlotFill } from '@wordpress/components'; -import { __ } from '@wordpress/i18n'; - -const { Fill: ToolsMoreMenuGroup, Slot } = createSlotFill( 'ToolsMoreMenuGroup' ); - -ToolsMoreMenuGroup.Slot = ( { fillProps } ) => ( - - { ( fills ) => - ! isEmpty( fills ) && { fills } - } - -); - -export default ToolsMoreMenuGroup; diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/header/undo-redo/redo.js b/public_html/wp-content/plugins/pattern-creator/src/components/header/undo-redo/redo.js deleted file mode 100644 index c724c62a9..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/header/undo-redo/redo.js +++ /dev/null @@ -1,26 +0,0 @@ -/** - * WordPress dependencies - */ -import { __, isRTL } from '@wordpress/i18n'; -import { Button } from '@wordpress/components'; -import { useDispatch, useSelect } from '@wordpress/data'; -import { redo as redoIcon, undo as undoIcon } from '@wordpress/icons'; -import { displayShortcut } from '@wordpress/keycodes'; -import { store as coreStore } from '@wordpress/core-data'; - -export default function RedoButton() { - const hasRedo = useSelect( ( select ) => select( coreStore ).hasRedo() ); - const { redo } = useDispatch( coreStore ); - return ( - - - ); -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/save-button/index.js b/public_html/wp-content/plugins/pattern-creator/src/components/save-button/index.js deleted file mode 100644 index ac33f1bca..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/save-button/index.js +++ /dev/null @@ -1,99 +0,0 @@ -/** - * External dependencies - */ -import { get } from 'lodash'; - -/** - * WordPress dependencies - */ -import { __ } from '@wordpress/i18n'; -import { Button } from '@wordpress/components'; -import { store as coreStore } from '@wordpress/core-data'; -import { store as editorStore } from '@wordpress/editor'; -import { useDispatch, useSelect } from '@wordpress/data'; -import { useState } from '@wordpress/element'; - -/** - * Internal dependencies - */ -import SubmissionModal from '../submission-modal'; -import { store as patternStore } from '../../store'; - -export { default as SaveDraftButton } from './draft'; - -export function SaveButton() { - const { - currentStatus, - isDirty, - isSaving, - isAutoSaving, - isSaveable, - isPublished, - isPublishedOrPending, - publishStatus, - } = useSelect( ( select ) => { - const { __experimentalGetDirtyEntityRecords } = select( coreStore ); - const { isAutosavingPost, isSavingPost, getCurrentPost, getCurrentPostId } = select( editorStore ); - const { isPatternSaveable, getSettings } = select( patternStore ); - - const dirtyEntityRecords = __experimentalGetDirtyEntityRecords(); - const _isAutoSaving = isAutosavingPost(); - const _post = getCurrentPost(); - const hasPublishAction = get( _post, [ '_links', 'wp:action-publish' ], false ); - const settings = getSettings(); - return { - currentStatus: _post.status, - isDirty: dirtyEntityRecords.length > 0, - isSaving: isSavingPost() || _isAutoSaving, - isAutoSaving: _isAutoSaving, - isSaveable: isPatternSaveable( getCurrentPostId() ), - isPublished: 'publish' === _post.status, - isPublishedOrPending: [ 'pending', 'publish' ].includes( _post.status ), - publishStatus: hasPublishAction ? settings.defaultStatus : 'pending', - }; - } ); - const { editPost, savePost } = useDispatch( editorStore ); - const [ showModal, setShowModal ] = useState( false ); - - // Button is disabled when not saveable, when it's already saving, or if the draft post is not dirty. - // A draft post can be published without any local changes (the modal will catch if there is no content). - const isDisabled = ! isSaveable || isSaving || ( ! isDirty && isPublishedOrPending ); - - const onClick = () => { - if ( isDisabled ) { - return; - } - if ( isPublished ) { - onSuccess(); - } else { - setShowModal( true ); - } - }; - - const onSuccess = () => { - editPost( { status: publishStatus }, { undoIgnore: true } ); - savePost(); - }; - - return ( - <> - { showModal && ( - setShowModal( false ) } - onSubmit={ onSuccess } - status={ currentStatus } - /> - ) } - - - ); -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/secondary-sidebar/inserter-sidebar.js b/public_html/wp-content/plugins/pattern-creator/src/components/secondary-sidebar/inserter-sidebar.js deleted file mode 100644 index ae8887fba..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/secondary-sidebar/inserter-sidebar.js +++ /dev/null @@ -1,42 +0,0 @@ -/** - * WordPress dependencies - */ -import { useDispatch, useSelect } from '@wordpress/data'; -import { Button } from '@wordpress/components'; -/* eslint-disable-next-line @wordpress/no-unsafe-wp-apis -- Experimental is OK. */ -import { __experimentalLibrary as Library } from '@wordpress/block-editor'; -import { close } from '@wordpress/icons'; -/* eslint-disable-next-line @wordpress/no-unsafe-wp-apis -- Experimental is OK. */ -import { __experimentalUseDialog as useDialog, useViewportMatch } from '@wordpress/compose'; - -/** - * Internal dependencies - */ -import { store as patternStore } from '../../store'; - -export default function InserterSidebar() { - const { setIsInserterOpened } = useDispatch( patternStore ); - const insertionPoint = useSelect( ( select ) => select( patternStore ).__experimentalGetInsertionPoint(), [] ); - - const isMobile = useViewportMatch( 'medium', '<' ); - const [ inserterDialogRef, inserterDialogProps ] = useDialog( { - onClose: () => setIsInserterOpened( false ), - } ); - - return ( -
-
-
-
- -
-
- ); -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/secondary-sidebar/list-view-sidebar.js b/public_html/wp-content/plugins/pattern-creator/src/components/secondary-sidebar/list-view-sidebar.js deleted file mode 100644 index c44d46e85..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/secondary-sidebar/list-view-sidebar.js +++ /dev/null @@ -1,54 +0,0 @@ -/** - * WordPress dependencies - */ -/* eslint-disable-next-line @wordpress/no-unsafe-wp-apis -- Experimental is OK. */ -import { __experimentalListView as ListView } from '@wordpress/block-editor'; -import { Button } from '@wordpress/components'; -import { useFocusOnMount, useFocusReturn, useInstanceId, useMergeRefs } from '@wordpress/compose'; -import { useDispatch } from '@wordpress/data'; -import { __ } from '@wordpress/i18n'; -import { closeSmall } from '@wordpress/icons'; -import { ESCAPE } from '@wordpress/keycodes'; - -/** - * Internal dependencies - */ -import { store as patternStore } from '../../store'; - -// Forked from https://raw.githubusercontent.com/WordPress/gutenberg/1b9157577fce4133e9be89c1d89cdd02918f6ba3/packages/edit-site/src/components/secondary-sidebar/list-view-sidebar.js - -export default function ListViewSidebar() { - const { setIsListViewOpened } = useDispatch( patternStore ); - - const focusOnMountRef = useFocusOnMount( 'firstElement' ); - const headerFocusReturnRef = useFocusReturn(); - const contentFocusReturnRef = useFocusReturn(); - function closeOnEscape( event ) { - if ( event.keyCode === ESCAPE && ! event.defaultPrevented ) { - setIsListViewOpened( false ); - } - } - - const instanceId = useInstanceId( ListViewSidebar ); - const labelId = `pattern__list-view-panel-label-${ instanceId }`; - - return ( - // eslint-disable-next-line jsx-a11y/no-static-element-interactions -
-
- { __( 'List View', 'wporg-patterns' ) } -
-
- -
-
- ); -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/secondary-sidebar/style.scss b/public_html/wp-content/plugins/pattern-creator/src/components/secondary-sidebar/style.scss deleted file mode 100644 index 9a76d2e9c..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/secondary-sidebar/style.scss +++ /dev/null @@ -1,52 +0,0 @@ -.pattern__inserter-panel, -.pattern__list-view-panel { - height: 100%; - display: flex; - flex-direction: column; -} - -.pattern__list-view-panel { - // Same width as the Inserter. - // @see packages/block-editor/src/components/inserter/style.scss - min-width: 350px; -} - -.pattern__inserter-panel-header { - padding-top: $grid-unit-10; - padding-right: $grid-unit-10; - display: flex; - justify-content: flex-end; - - @include break-medium() { - display: none; - } -} - -.pattern__inserter-panel-content, -.pattern__list-view-panel-content { - // Leave space for the close button - height: calc(100% - #{$button-size} - #{$grid-unit-10}); -} - - -.pattern__inserter-panel-content { - - @include break-medium() { - height: 100%; - } -} - -.pattern__list-view-panel-header { - align-items: center; - border-bottom: $border-width solid $gray-300; - display: flex; - justify-content: space-between; - height: $grid-unit-60; - padding-left: $grid-unit-20; - padding-right: $grid-unit-05; -} - -.pattern__list-view-panel-content { - overflow-y: auto; - padding: $grid-unit-10; -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/sidebar/constants.js b/public_html/wp-content/plugins/pattern-creator/src/components/sidebar/constants.js deleted file mode 100644 index 71b52e6f7..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/sidebar/constants.js +++ /dev/null @@ -1,2 +0,0 @@ -export const SIDEBAR_PATTERN = 'pattern-creator/pattern'; -export const SIDEBAR_BLOCK = 'pattern-creator/block-inspector'; diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/sidebar/default-sidebar.js b/public_html/wp-content/plugins/pattern-creator/src/components/sidebar/default-sidebar.js deleted file mode 100644 index e9258a96e..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/sidebar/default-sidebar.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * WordPress dependencies - */ -import { ComplementaryArea, ComplementaryAreaMoreMenuItem } from '@wordpress/interface'; - -/** - * Internal dependencies - */ -import { STORE_NAME } from '../../store/constants'; - -export default function DefaultSidebar( { - className, - identifier, - title, - icon, - children, - closeLabel, - header, - headerClassName, -} ) { - return ( - <> - - { children } - - - { title } - - - ); -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/sidebar/index.js b/public_html/wp-content/plugins/pattern-creator/src/components/sidebar/index.js deleted file mode 100644 index c0fbf9831..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/sidebar/index.js +++ /dev/null @@ -1,67 +0,0 @@ -/** - * WordPress dependencies - */ -import { createSlotFill } from '@wordpress/components'; -import { __, isRTL } from '@wordpress/i18n'; -import { drawerLeft, drawerRight } from '@wordpress/icons'; -import { useEffect } from '@wordpress/element'; -import { useDispatch, useSelect } from '@wordpress/data'; -import { store as interfaceStore } from '@wordpress/interface'; -import { store as blockEditorStore } from '@wordpress/block-editor'; - -/** - * Internal dependencies - */ -import DefaultSidebar from './default-sidebar'; -import PatternSettings from './pattern-settings'; -import { STORE_NAME } from '../../store/constants'; -import SettingsHeader from './settings-header'; -import { SIDEBAR_BLOCK, SIDEBAR_PATTERN } from './constants'; - -const { Slot: InspectorSlot, Fill: InspectorFill } = createSlotFill( 'PatternSidebarInspector' ); -export const SidebarInspectorFill = InspectorFill; - -export function SidebarComplementaryAreaFills() { - const { sidebar, isEditorSidebarOpened, hasBlockSelection } = useSelect( ( select ) => { - const _sidebar = select( interfaceStore ).getActiveComplementaryArea( STORE_NAME ); - const _isEditorSidebarOpened = [ SIDEBAR_BLOCK, SIDEBAR_PATTERN ].includes( _sidebar ); - return { - sidebar: _sidebar, - isEditorSidebarOpened: _isEditorSidebarOpened, - hasBlockSelection: !! select( blockEditorStore ).getBlockSelectionStart(), - }; - }, [] ); - const { enableComplementaryArea } = useDispatch( interfaceStore ); - - useEffect( () => { - if ( ! isEditorSidebarOpened ) { - return; - } - if ( hasBlockSelection ) { - enableComplementaryArea( STORE_NAME, SIDEBAR_BLOCK ); - } else { - enableComplementaryArea( STORE_NAME, SIDEBAR_PATTERN ); - } - }, [ hasBlockSelection, isEditorSidebarOpened ] ); - - let sidebarName = sidebar; - if ( ! isEditorSidebarOpened ) { - sidebarName = hasBlockSelection ? SIDEBAR_BLOCK : SIDEBAR_PATTERN; - } - - return ( - <> - } - headerClassName="pattern-sidebar__panel-tabs" - > - { sidebar === SIDEBAR_PATTERN && } - { sidebar === SIDEBAR_BLOCK && } - - - ); -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/sidebar/pattern-settings/index.js b/public_html/wp-content/plugins/pattern-creator/src/components/sidebar/pattern-settings/index.js deleted file mode 100644 index 724af1318..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/sidebar/pattern-settings/index.js +++ /dev/null @@ -1,109 +0,0 @@ -/** - * WordPress dependencies - */ -import { __ } from '@wordpress/i18n'; -import { - ExternalLink, - FormTokenField, - PanelBody, - PanelRow, - TextControl, - TextareaControl, -} from '@wordpress/components'; -import { store as editorStore } from '@wordpress/editor'; -import { useDispatch, useSelect } from '@wordpress/data'; -import { useCallback } from '@wordpress/element'; - -/** - * Internal dependencies - */ -import PatternCategoriesControl from '../../pattern-categories-control'; -import { KEYWORD_SLUG } from '../../../store'; - -const DESCRIPTION_SLUG = 'wpop_description'; - -function PatternSettings() { - const { description, keywords, link, meta, selectedCategories, status, title } = useSelect( ( select ) => { - const { getCurrentPost, getEditedPostAttribute } = select( editorStore ); - const _meta = getEditedPostAttribute( 'meta' ) || {}; - const _post = getCurrentPost(); - return { - description: _meta[ DESCRIPTION_SLUG ], - keywords: _meta[ KEYWORD_SLUG ].split( ', ' ).filter( ( item ) => item.length ), - link: _post.link, - meta: _meta, - selectedCategories: getEditedPostAttribute( 'pattern-categories' ), - status: _post.status, - title: getEditedPostAttribute( 'title' ) || '', - }; - } ); - - const { editPost } = useDispatch( editorStore ); - const setTitle = useCallback( ( value ) => { - editPost( { title: value } ); - } ); - const setDescription = useCallback( ( value ) => { - editPost( { meta: { ...meta, wpop_description: value } } ); - } ); - const setCategories = useCallback( ( value ) => { - editPost( { 'pattern-categories': value } ); - } ); - const setKeywords = useCallback( ( value ) => { - const keywordsString = value.join( ', ' ); - editPost( { meta: { ...meta, [ KEYWORD_SLUG ]: keywordsString } } ); - } ); - - return ( - <> - - - - - - - - { [ 'pending', 'publish' ].includes( status ) && ( -
-

- { __( 'View pattern', 'wporg-patterns' ) } -

- { link } -
- ) } -
- -

- { __( - 'Patterns are grouped into defined categories to help people browse.', - 'wporg-patterns' - ) } -

- -
- -

- { __( - 'Keywords are words or short phrases that will help people find your pattern. There is a maximum of 10 keywords.', - 'wporg-patterns' - ) } -

- -
- - ); -} - -export default PatternSettings; diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/sidebar/settings-header/index.js b/public_html/wp-content/plugins/pattern-creator/src/components/sidebar/settings-header/index.js deleted file mode 100644 index a2552a5bd..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/sidebar/settings-header/index.js +++ /dev/null @@ -1,69 +0,0 @@ -/** - * WordPress dependencies - */ -import { Button } from '@wordpress/components'; -import { __ } from '@wordpress/i18n'; -import { useDispatch } from '@wordpress/data'; -import { store as interfaceStore } from '@wordpress/interface'; - -/** - * Internal dependencies - */ -import { STORE_NAME } from '../../../store/constants'; -import { SIDEBAR_BLOCK, SIDEBAR_PATTERN } from '../constants'; - -const SettingsHeader = ( { sidebarName } ) => { - const { enableComplementaryArea } = useDispatch( interfaceStore ); - const openPatternSettings = () => enableComplementaryArea( STORE_NAME, SIDEBAR_PATTERN ); - const openBlockSettings = () => enableComplementaryArea( STORE_NAME, SIDEBAR_BLOCK ); - - const [ patternAriaLabel, patternActiveClass ] = - sidebarName === SIDEBAR_PATTERN - ? // translators: ARIA label for the Template sidebar tab, selected. - [ __( 'Pattern (selected)', 'wporg-patterns' ), 'is-active' ] - : // translators: ARIA label for the Template Settings Sidebar tab, not selected. - [ __( 'Pattern', 'wporg-patterns' ), '' ]; - - const [ blockAriaLabel, blockActiveClass ] = - sidebarName === SIDEBAR_BLOCK - ? // translators: ARIA label for the Block Settings Sidebar tab, selected. - [ __( 'Block (selected)', 'wporg-patterns' ), 'is-active' ] - : // translators: ARIA label for the Block Settings Sidebar tab, not selected. - [ __( 'Block', 'wporg-patterns' ), '' ]; - - /* Use a list so screen readers will announce how many tabs there are. */ - return ( -
    -
  • - -
  • -
  • - -
  • -
- ); -}; - -export default SettingsHeader; diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/sidebar/settings-header/style.scss b/public_html/wp-content/plugins/pattern-creator/src/components/sidebar/settings-header/style.scss deleted file mode 100644 index 796b32623..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/sidebar/settings-header/style.scss +++ /dev/null @@ -1,98 +0,0 @@ -.components-panel__header.pattern-sidebar__panel-tabs { - justify-content: flex-start; - padding-left: 0; - padding-right: $grid-unit-20; - border-top: 0; - margin-top: 0; - - ul { - display: flex; - margin: 0; - } - - li { - margin: 0; - } - - .components-button.has-icon { - display: none; - margin: 0 0 0 auto; - padding: 0; - min-width: $icon-size; - height: $icon-size; - - @include break-medium() { - display: flex; - } - } -} - -.components-button.pattern-sidebar__panel-tab { - position: relative; - border-radius: 0; - height: $grid-unit-60; - background: transparent; - border: none; - box-shadow: none; - cursor: pointer; - // Use padding to offset the is-active border, this benefits Windows High Contrast mode. - padding: 3px $grid-unit-20; - margin-left: 0; - font-weight: 500; - - &:focus:not(:disabled) { - position: relative; - box-shadow: none; - } - - // This pseudo-element "duplicates" the tab label and sets the text to bold. - // This ensures that the tab doesn't change width when selected. - // See: https://github.com/WordPress/gutenberg/pull/9793 - &::after { - content: ""; - position: absolute; - right: 0; - bottom: 0; - left: 0; - pointer-events: none; - - // Draw the indicator. - background: var(--wp-admin-theme-color); - height: calc(0 * var(--wp-admin-border-width-focus)); - border-radius: 0; - - // Animation - transition: all 0.1s linear; - - @include reduce-motion("transition"); - } - - // Active. - &.is-active::after { - height: calc(1 * var(--wp-admin-border-width-focus)); - } - - // Focus. - &::before { - content: ""; - position: absolute; - top: $grid-unit-15; - right: $grid-unit-15; - bottom: $grid-unit-15; - left: $grid-unit-15; - pointer-events: none; - - // Draw the indicator. - box-shadow: 0 0 0 0 transparent; - border-radius: $radius-block-ui; - - // Animation - transition: all 0.1s linear; - - @include reduce-motion("transition"); - } - - &:focus-visible::before { - box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color); - } -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/sidebar/style.scss b/public_html/wp-content/plugins/pattern-creator/src/components/sidebar/style.scss deleted file mode 100644 index 70ca024f8..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/sidebar/style.scss +++ /dev/null @@ -1,44 +0,0 @@ -.pattern-sidebar { - width: $sidebar-width; - - > .components-panel { - border-left: 0; - border-right: 0; - margin-bottom: -1px; - margin-top: -1px; - - > .components-panel__header { - background: $gray-100; - } - } - - .block-editor-block-inspector__card { - margin: 0; - } -} - -.pattern-sidebar__preview-link { - margin-top: $grid-unit-10; -} - -.pattern-global-styles-sidebar .interface-complementary-area-header .components-button.has-icon { - margin-left: 0; -} - -.pattern-global-styles-sidebar__reset-button.components-button { - margin-left: auto; -} - -.pattern-global-styles-sidebar__border-controls-row { - display: flex; - justify-content: space-between; - margin-bottom: $grid-unit-15; - - > * { - width: calc(50% - #{ $grid-unit-10 }); - } - - .components-border-style-control__buttons { - margin-bottom: 0; - } -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/url-controller/index.js b/public_html/wp-content/plugins/pattern-creator/src/components/url-controller/index.js deleted file mode 100644 index 27304cf26..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/url-controller/index.js +++ /dev/null @@ -1,23 +0,0 @@ -/** - * WordPress dependencies - */ -import { useEffect } from '@wordpress/element'; -import { useSelect } from '@wordpress/data'; -import { store as coreStore } from '@wordpress/core-data'; - -import { POST_TYPE } from '../../store'; - -const BASE_URL = wporgBlockPattern.siteUrl; - -// Update page URL when the post's status changes, but only if the new status is not auto-draft. -export default function UrlController( { postId } ) { - const post = useSelect( ( select ) => select( coreStore ).getEntityRecord( 'postType', POST_TYPE, postId ) ); - useEffect( () => { - if ( 'auto-draft' !== post.status ) { - const newUrl = `${ BASE_URL }/pattern/${ postId }/edit/`; - window.history.replaceState( {}, '', newUrl ); - } - }, [ post.status ] ); - - return null; -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/welcome-guide/images.js b/public_html/wp-content/plugins/pattern-creator/src/components/welcome-guide/images.js deleted file mode 100644 index 58a06e2d1..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/welcome-guide/images.js +++ /dev/null @@ -1,122 +0,0 @@ -/** - * WordPress dependencies - */ -import { SVG } from '@wordpress/primitives'; - -export const PatternsImage = () => ( - <> - - - - - - - - - - - - - - - - - - - - - - - -); - -export const ImageCollectionImage = () => ( - <> - - - - - - - - - - - - - - - - -); - -export const PatternEditorImage = () => ( - <> - - - - - - - - - - - - - - - - - - - - - - - -); diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/welcome-guide/index.js b/public_html/wp-content/plugins/pattern-creator/src/components/welcome-guide/index.js deleted file mode 100644 index d85acaaf6..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/welcome-guide/index.js +++ /dev/null @@ -1,98 +0,0 @@ -/** - * WordPress dependencies - */ -import { Guide } from '@wordpress/components'; -import { useDispatch, useSelect } from '@wordpress/data'; -import { __ } from '@wordpress/i18n'; - -/** - * Internal dependencies - */ -import { ImageCollectionImage, PatternEditorImage, PatternsImage } from './images'; -import { store as patternStore } from '../../store'; - -/** - * Module constants - */ -export const GUIDE_ID = 'patternWelcomeGuide'; - -export default function WelcomeGuide() { - const isActive = useSelect( ( select ) => select( patternStore ).isFeatureActive( GUIDE_ID ), [] ); - - const { toggleFeature } = useDispatch( patternStore ); - - if ( ! isActive ) { - return null; - } - - return ( - toggleFeature( GUIDE_ID ) } - pages={ [ - { - image: ( -
- -
- ), - content: ( - <> -

- { __( 'Welcome to the pattern editor', 'wporg-patterns' ) } -

-

- { __( - 'Mix and match WordPress blocks together to create unique and compelling designs.', - 'wporg-patterns' - ) } -

- - ), - }, - { - image: ( -
- -
- ), - content: ( - <> -

- { __( 'Use our collection of license-free images', 'wporg-patterns' ) } -

-

- { __( - 'Don’t worry about licensing. We’ve provided a collection of worry-free images and media for you to use.', - 'wporg-patterns' - ) } -

- - ), - }, - { - image: ( -
- -
- ), - content: ( - <> -

- { __( 'Submit your pattern to the directory', 'wporg-patterns' ) } -

-

- { __( - 'Choose a category and share your pattern with the world. All patterns in the directory are available from any WordPress site.', - 'wporg-patterns' - ) } -

- - ), - }, - ] } - /> - ); -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/welcome-guide/style.scss b/public_html/wp-content/plugins/pattern-creator/src/components/welcome-guide/style.scss deleted file mode 100644 index bf1dd7cba..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/components/welcome-guide/style.scss +++ /dev/null @@ -1,56 +0,0 @@ - -.pattern-creator-welcome-guide { - max-width: 320px; -} - -.pattern-creator-welcome-guide__image { - margin-bottom: $grid-unit-10; /* Pushes the dot controls away */ - display: flex; - align-items: center; - justify-content: center; - background: #1d2327; - height: 240px; - overflow: hidden; -} - -/* Change circle indicator color */ -.pattern-creator-welcome-guide .components-guide__page-control [aria-current="step"] circle { - fill: var(--wp-admin-theme-color); -} - -/* Change the close button color */ -.pattern-creator-welcome-guide .components-modal__header button { - background: #000; - color: #fff; -} - -.pattern-creator-welcome-guide__image svg { - position: absolute; -} - -.pattern-creator-welcome-guide__title, -.pattern-creator-welcome-guide p { - margin: 0; - padding: 0 $grid-unit-40; -} - -.pattern-creator-welcome-guide__title { - margin: $grid-unit-20 0; - font-size: 20px; - font-weight: 600; - line-height: normal; -} - -.pattern-creator-welcome-guide p { - margin-bottom: $grid-unit-20; - font-size: 14px; -} - -.pattern-creator-welcome-guide__link { - margin-top: $grid-unit-10; - display: block; -} - -.pattern-creator-welcome-guide .components-guide__footer > button { - padding: $grid-unit-10 $grid-unit-15; -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/hooks/media.js b/public_html/wp-content/plugins/pattern-creator/src/hooks/media.js deleted file mode 100644 index 6f0a1294f..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/hooks/media.js +++ /dev/null @@ -1,13 +0,0 @@ -/** - * WordPress dependencies - */ -import { addFilter } from '@wordpress/hooks'; - -/** - * Internal dependencies - */ -import MediaPlaceholder from '../components/media-placeholder'; -import OpenverseGallery from '../components/openverse'; - -addFilter( 'editor.MediaPlaceholder', 'wporg/patterns/components/media-upload', () => MediaPlaceholder, 100 ); -addFilter( 'editor.MediaUpload', 'wporg-patterns/openverse-media-upload', () => OpenverseGallery, 100 ); diff --git a/public_html/wp-content/plugins/pattern-creator/src/hooks/use-post-data.js b/public_html/wp-content/plugins/pattern-creator/src/hooks/use-post-data.js deleted file mode 100644 index f4693dedb..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/hooks/use-post-data.js +++ /dev/null @@ -1,25 +0,0 @@ -/** - * External dependencies - */ -import { useDispatch, useSelect } from '@wordpress/data'; -import { store } from '@wordpress/editor'; - -/** - * A hook to get and set a post value. - * - * @param {string} property Identifier for a post property to use. - * - * @return {Array<*,Function>} A pair of values: the current property value and a callback to update this value. - */ -export default function usePostData( property ) { - const propValue = useSelect( ( select ) => select( store ).getEditedPostAttribute( property ) ); - - const { editPost } = useDispatch( store ); - const setPropValue = ( value ) => { - editPost( { - [ property ]: value, - } ); - }; - - return [ propValue, setPropValue ]; -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/index.js b/public_html/wp-content/plugins/pattern-creator/src/index.js deleted file mode 100644 index 7ff6c4f09..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/index.js +++ /dev/null @@ -1,47 +0,0 @@ -/** - * WordPress dependencies - */ -import { dispatch } from '@wordpress/data'; -import { registerCoreBlocks } from '@wordpress/block-library'; -import { render, unmountComponentAtNode } from '@wordpress/element'; - -/** - * Internal dependencies - */ -import { store as patternStore } from './store'; -import './hooks/media'; -import Editor from './components/editor'; -import './api-middleware'; -import './style.scss'; - -/** - * Reinitializes the editor after the user chooses to reboot the editor after - * an unhandled error occurs, replacing previously mounted editor element using - * an initial state from prior to the crash. - * - * @param {Element} target DOM node in which editor is rendered. - * @param {Object} settings Editor settings. - * @param {number} settings.postId ID of the current post. - */ -export function reinitializeEditor( target, { postId, ...settings } ) { - unmountComponentAtNode( target ); - const reboot = reinitializeEditor.bind( null, target, settings ); - - // Update the store synchronously before rendering so that we won't trigger - // unnecessary re-renders with useEffect. - dispatch( patternStore ).updateSettings( settings ); - render( , target ); -} - -/** - * Initializes the pattern editor screen. - * - * @param {string} id ID of the root element to render the screen in. - * @param {Object} settings Editor settings. - */ -export function initialize( id, settings ) { - const target = document.getElementById( id ); - - registerCoreBlocks(); - reinitializeEditor( target, settings ); -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/lock-unlock.js b/public_html/wp-content/plugins/pattern-creator/src/lock-unlock.js deleted file mode 100644 index c3859fa5d..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/lock-unlock.js +++ /dev/null @@ -1,9 +0,0 @@ -/** - * WordPress dependencies - */ -import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis'; - -export const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules( - 'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', - '@wordpress/edit-post' // Hack to enable APIs by using a core package. -); diff --git a/public_html/wp-content/plugins/pattern-creator/src/store/actions.js b/public_html/wp-content/plugins/pattern-creator/src/store/actions.js deleted file mode 100644 index 0c79bd4af..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/store/actions.js +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Returns an action object used to toggle a feature flag. - * - * @param {string} feature Feature name. - * - * @return {Object} Action object. - */ -export function toggleFeature( feature ) { - return { - type: 'TOGGLE_FEATURE', - feature: feature, - }; -} - -/** - * Returns an action object used to toggle the width of the editing canvas. - * - * @param {string} deviceType - * - * @return {Object} Action object. - */ -export function setPreviewDeviceType( deviceType ) { - return { - type: 'SET_PREVIEW_DEVICE_TYPE', - deviceType: deviceType, - }; -} - -/** - * Returns an action object used to open/close the inserter. - * - * @param {boolean|Object} value Whether the inserter should be - * opened (true) or closed (false). - * To specify an insertion point, - * use an object. - * @param {string} value.rootClientId The root client ID to insert at. - * @param {number} value.insertionIndex The index to insert at. - * - * @return {Object} Action object. - */ -export function setIsInserterOpened( value ) { - return { - type: 'SET_IS_INSERTER_OPENED', - value: value, - }; -} - -/** - * Returns an action object used to update the settings. - * - * @param {Object} settings New settings. - * - * @return {Object} Action object. - */ -export function updateSettings( settings ) { - return { - type: 'UPDATE_SETTINGS', - settings: settings, - }; -} - -/** - * Sets whether the list view panel should be open. - * - * @param {boolean} isOpen If true, opens the list view. If false, closes it. - * It does not toggle the state, but sets it directly. - */ -export function setIsListViewOpened( isOpen ) { - return { - type: 'SET_IS_LIST_VIEW_OPENED', - isOpen: isOpen, - }; -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/store/constants.js b/public_html/wp-content/plugins/pattern-creator/src/store/constants.js deleted file mode 100644 index 5b4a979e3..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/store/constants.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * The identifier for the data store. - * - * @type {string} - */ -export const STORE_NAME = 'wporg/pattern-creator'; - -export const POST_TYPE = 'wporg-pattern'; - -export const CATEGORY_SLUG = 'wporg-pattern-category'; - -export const KEYWORD_SLUG = 'wpop_keywords'; diff --git a/public_html/wp-content/plugins/pattern-creator/src/store/defaults.js b/public_html/wp-content/plugins/pattern-creator/src/store/defaults.js deleted file mode 100644 index e83e8b31f..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/store/defaults.js +++ /dev/null @@ -1,5 +0,0 @@ -export const PREFERENCES_DEFAULTS = { - features: { - patternWelcomeGuide: true, - }, -}; diff --git a/public_html/wp-content/plugins/pattern-creator/src/store/index.js b/public_html/wp-content/plugins/pattern-creator/src/store/index.js deleted file mode 100644 index 1f69c105b..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/store/index.js +++ /dev/null @@ -1,28 +0,0 @@ -/** - * WordPress dependencies - */ -import { createReduxStore, registerStore } from '@wordpress/data'; - -/** - * Internal dependencies - */ -import reducer from './reducer'; -import * as actions from './actions'; -import * as selectors from './selectors'; -import { STORE_NAME } from './constants'; - -export const storeConfig = { - reducer: reducer, - actions: actions, - selectors: selectors, - persist: [ 'preferences' ], -}; - -export { POST_TYPE, CATEGORY_SLUG, KEYWORD_SLUG } from './constants'; - -export const store = createReduxStore( STORE_NAME, storeConfig ); - -// Technically `registerStore` has been deprecated in favor of `register`, but -// `register` does not support the persistance layer. To switch, we'll need to -// update the `preferences` state to use the `@wordpress/preferences` package. -registerStore( STORE_NAME, storeConfig ); diff --git a/public_html/wp-content/plugins/pattern-creator/src/store/reducer.js b/public_html/wp-content/plugins/pattern-creator/src/store/reducer.js deleted file mode 100644 index 9b8249ddf..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/store/reducer.js +++ /dev/null @@ -1,114 +0,0 @@ -/** - * WordPress dependencies - */ -import { combineReducers } from '@wordpress/data'; - -/** - * Internal dependencies - */ -import { PREFERENCES_DEFAULTS } from './defaults'; - -/** - * Reducer returning the user preferences. - * - * @param {Object} state Current state. - * @param {Object} action Dispatched action. - * @return {Object} Updated state. - */ -export const preferences = combineReducers( { - features( state = PREFERENCES_DEFAULTS.features, action ) { - switch ( action.type ) { - case 'TOGGLE_FEATURE': { - return { - ...state, - [ action.feature ]: ! state[ action.feature ], - }; - } - default: - return state; - } - }, -} ); - -/** - * Reducer returning the editing canvas device type. - * - * @param {Object} state Current state. - * @param {Object} action Dispatched action. - * - * @return {Object} Updated state. - */ -export function deviceType( state = 'Desktop', action ) { - switch ( action.type ) { - case 'SET_PREVIEW_DEVICE_TYPE': - return action.deviceType; - } - - return state; -} - -/** - * Reducer returning the settings. - * - * @param {Object} state Current state. - * @param {Object} action Dispatched action. - * - * @return {Object} Updated state. - */ -export function settings( state = {}, action ) { - switch ( action.type ) { - case 'UPDATE_SETTINGS': - return { - ...state, - ...action.settings, - }; - } - - return state; -} - -/** - * Reducer to set the block inserter panel open or closed. - * - * Note: this reducer interacts with the list view panels reducers - * to make sure that only one of the two panels is open at the same time. - * - * @param {boolean|Object} state Current state. - * @param {Object} action Dispatched action. - */ -export function blockInserterPanel( state = false, action ) { - switch ( action.type ) { - case 'SET_IS_LIST_VIEW_OPENED': - return action.isOpen ? false : state; - case 'SET_IS_INSERTER_OPENED': - return action.value; - } - return state; -} - -/** - * Reducer to set the list view panel open or closed. - * - * Note: this reducer interacts with inserter panels reducers - * to make sure that only one of the two panels is open at the same time. - * - * @param {Object} state Current state. - * @param {Object} action Dispatched action. - */ -export function listViewPanel( state = false, action ) { - switch ( action.type ) { - case 'SET_IS_INSERTER_OPENED': - return action.value ? false : state; - case 'SET_IS_LIST_VIEW_OPENED': - return action.isOpen; - } - return state; -} - -export default combineReducers( { - preferences, - deviceType, - settings, - blockInserterPanel, - listViewPanel, -} ); diff --git a/public_html/wp-content/plugins/pattern-creator/src/store/selectors.js b/public_html/wp-content/plugins/pattern-creator/src/store/selectors.js deleted file mode 100644 index 6073248f0..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/store/selectors.js +++ /dev/null @@ -1,165 +0,0 @@ -/** - * External dependencies - */ -import { get } from 'lodash'; -import createSelector from 'rememo'; - -/** - * WordPress dependencies - */ -import { store as coreStore } from '@wordpress/core-data'; -import { createRegistrySelector } from '@wordpress/data'; -import { - /* eslint-disable-next-line @wordpress/no-unsafe-wp-apis */ - __unstableSerializeAndClean, - getDefaultBlockName, - getFreeformContentHandlerName, -} from '@wordpress/blocks'; - -/** - * Internal dependencies - */ -import { POST_TYPE } from './constants'; - -/** - * Shared reference to an empty object for cases where it is important to avoid - * returning a new object reference on every invocation, as in a connected or - * other pure component which performs `shouldComponentUpdate` check on props. - * This should be used as a last resort, since the normalized data should be - * maintained by the reducer result in state. - */ -const EMPTY_OBJECT = {}; -const EMPTY_ARRAY = []; - -/** - * Returns whether the given feature is enabled or not. - * - * @param {Object} state Global application state. - * @param {string} feature Feature slug. - * - * @return {boolean} Is active. - */ -export function isFeatureActive( state, feature ) { - return get( state.preferences.features, [ feature ], false ); -} - -/** - * Returns the current editing canvas device type. - * - * @param {Object} state Global application state. - * - * @return {string} Device type. - */ -export function getPreviewDeviceType( state ) { - return state.deviceType; -} - -/** - * Returns the settings, taking into account active features and permissions. - * - * @param {Object} state Global application state. - * @param {Function} setIsInserterOpen Setter for the open state of the global inserter. - * - * @return {Object} Settings. - */ -export const getSettings = createSelector( - ( state, setIsInserterOpen ) => { - const settings = { - ...state.settings, - fullscreenMode: true, - outlineMode: true, - focusMode: isFeatureActive( state, 'focusMode' ), - hasFixedToolbar: - isFeatureActive( state, 'fixedToolbar' ) || getPreviewDeviceType( state ) !== 'Desktop', - hasReducedUI: isFeatureActive( state, 'reducedUI' ), - __experimentalLocalAutosaveInterval: 30, - __experimentalSetIsInserterOpened: setIsInserterOpen, - }; - - return settings; - }, - ( state ) => [ - state.settings, - isFeatureActive( state, 'focusMode' ), - isFeatureActive( state, 'fixedToolbar' ), - isFeatureActive( state, 'reducedUI' ), - getPreviewDeviceType( state ), - ] -); - -/** - * Returns the current opened/closed state of the inserter panel. - * - * @param {Object} state Global application state. - * - * @return {boolean} True if the inserter panel should be open; false if closed. - */ -export function isInserterOpened( state ) { - return !! state.blockInserterPanel; -} - -/** - * Get the insertion point for the inserter. - * - * @param {Object} state Global application state. - * - * @return {Object} The root client ID and index to insert at. - */ -export function __experimentalGetInsertionPoint( state ) { - const { rootClientId, insertionIndex } = state.blockInserterPanel; - return { rootClientId, insertionIndex }; -} - -/** - * Returns the current opened/closed state of the list view panel. - * - * @param {Object} state Global application state. - * - * @return {boolean} True if the list view panel should be open; false if closed. - */ -export function isListViewOpened( state ) { - return state.listViewPanel; -} - -/** - * Returns whether the pattern is "saveable". - * - * A pattern can be saved if it has content. The other requirements - * are handled in the publish flow, content is the only thing - * required for saving a draft. - * - * See https://github.com/WordPress/gutenberg/blob/31330dbb737ce30646a4300410faed633061547a/packages/editor/src/store/selectors.js#L531 - * - * @param {Object} state Global application state. - * @param {number} postId The ID of this pattern. - * - * @return {Object} Whether the post can be saved. - */ -export const isPatternSaveable = createRegistrySelector( ( select ) => ( state, postId ) => { - const post = select( coreStore ).getEditedEntityRecord( 'postType', POST_TYPE, postId ) || EMPTY_OBJECT; - - return ! isEditedPostEmpty( post ); -} ); - -function isEditedPostEmpty( post ) { - const blocks = post.blocks || EMPTY_ARRAY; - - if ( blocks.length ) { - if ( blocks.length > 1 ) { - return false; - } - - const blockName = blocks[ 0 ].name; - if ( blockName !== getDefaultBlockName() && blockName !== getFreeformContentHandlerName() ) { - return false; - } - } - - if ( typeof post.content === 'function' ) { - return ! post.content( post ); - } else if ( post.blocks ) { - return ! __unstableSerializeAndClean( post.blocks ); - } else if ( post.content ) { - return ! post.content; - } -} diff --git a/public_html/wp-content/plugins/pattern-creator/src/store/test/actions.js b/public_html/wp-content/plugins/pattern-creator/src/store/test/actions.js deleted file mode 100644 index 031041acb..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/store/test/actions.js +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Internal dependencies - */ -import { setIsListViewOpened, toggleFeature } from '../actions'; - -describe( 'actions', () => { - describe( 'toggleFeature', () => { - it( 'should return TOGGLE_FEATURE action', () => { - const feature = 'name'; - expect( toggleFeature( feature ) ).toEqual( { - type: 'TOGGLE_FEATURE', - feature: feature, - } ); - } ); - } ); - - describe( 'setIsListViewOpened', () => { - it( 'should return the SET_IS_LIST_VIEW_OPENED action', () => { - expect( setIsListViewOpened( true ) ).toEqual( { - type: 'SET_IS_LIST_VIEW_OPENED', - isOpen: true, - } ); - expect( setIsListViewOpened( false ) ).toEqual( { - type: 'SET_IS_LIST_VIEW_OPENED', - isOpen: false, - } ); - } ); - } ); -} ); diff --git a/public_html/wp-content/plugins/pattern-creator/src/store/test/reducer.js b/public_html/wp-content/plugins/pattern-creator/src/store/test/reducer.js deleted file mode 100644 index e22099dc7..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/store/test/reducer.js +++ /dev/null @@ -1,106 +0,0 @@ -/** - * External dependencies - */ -import deepFreeze from 'deep-freeze'; - -/** - * Internal dependencies - */ -import { blockInserterPanel, listViewPanel, preferences, settings } from '../reducer'; -import { PREFERENCES_DEFAULTS } from '../defaults'; - -import { setIsInserterOpened, setIsListViewOpened } from '../actions'; - -describe( 'state', () => { - describe( 'preferences()', () => { - it( 'should apply all defaults', () => { - const state = preferences( undefined, {} ); - - expect( state ).toEqual( PREFERENCES_DEFAULTS ); - } ); - - it( 'should toggle a feature flag', () => { - const state = preferences( deepFreeze( { features: { chicken: true } } ), { - type: 'TOGGLE_FEATURE', - feature: 'chicken', - } ); - - expect( state.features ).toEqual( { chicken: false } ); - } ); - } ); - - describe( 'settings()', () => { - it( 'should apply default state', () => { - expect( settings( undefined, {} ) ).toEqual( {} ); - } ); - - it( 'should default to returning the same state', () => { - const state = {}; - expect( settings( state, {} ) ).toBe( state ); - } ); - - it( 'should update settings with a shallow merge', () => { - expect( - settings( - deepFreeze( { - setting: { key: 'value' }, - otherSetting: 'value', - } ), - { - type: 'UPDATE_SETTINGS', - settings: { setting: { newKey: 'newValue' } }, - } - ) - ).toEqual( { - setting: { newKey: 'newValue' }, - otherSetting: 'value', - } ); - } ); - } ); - - describe( 'blockInserterPanel()', () => { - it( 'should apply default state', () => { - expect( blockInserterPanel( undefined, {} ) ).toEqual( false ); - } ); - - it( 'should default to returning the same state', () => { - expect( blockInserterPanel( true, {} ) ).toBe( true ); - } ); - - it( 'should set the open state of the inserter panel', () => { - expect( blockInserterPanel( false, setIsInserterOpened( true ) ) ).toBe( true ); - expect( blockInserterPanel( true, setIsInserterOpened( false ) ) ).toBe( false ); - } ); - - it( 'should close the inserter when opening the list view panel', () => { - expect( blockInserterPanel( true, setIsListViewOpened( true ) ) ).toBe( false ); - } ); - - it( 'should not change the state when closing the list view panel', () => { - expect( blockInserterPanel( true, setIsListViewOpened( false ) ) ).toBe( true ); - } ); - } ); - - describe( 'listViewPanel()', () => { - it( 'should apply default state', () => { - expect( listViewPanel( undefined, {} ) ).toEqual( false ); - } ); - - it( 'should default to returning the same state', () => { - expect( listViewPanel( true, {} ) ).toBe( true ); - } ); - - it( 'should set the open state of the list view panel', () => { - expect( listViewPanel( false, setIsListViewOpened( true ) ) ).toBe( true ); - expect( listViewPanel( true, setIsListViewOpened( false ) ) ).toBe( false ); - } ); - - it( 'should close the list view when opening the inserter panel', () => { - expect( listViewPanel( true, setIsInserterOpened( true ) ) ).toBe( false ); - } ); - - it( 'should not change the state when closing the inserter panel', () => { - expect( listViewPanel( true, setIsInserterOpened( false ) ) ).toBe( true ); - } ); - } ); -} ); diff --git a/public_html/wp-content/plugins/pattern-creator/src/store/test/selectors.js b/public_html/wp-content/plugins/pattern-creator/src/store/test/selectors.js deleted file mode 100644 index f3984fa3a..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/store/test/selectors.js +++ /dev/null @@ -1,151 +0,0 @@ -/** - * Internal dependencies - */ -import { getSettings, isFeatureActive, isInserterOpened, isListViewOpened, isPatternSaveable } from '../selectors'; - -describe( 'selectors', () => { - describe( 'isFeatureActive', () => { - it( 'is tolerant to an undefined features preference', () => { - // See: https://github.com/WordPress/gutenberg/issues/14580 - const state = { - preferences: {}, - }; - - expect( isFeatureActive( state, 'chicken' ) ).toBe( false ); - } ); - - it( 'should return true if feature is active', () => { - const state = { - preferences: { - features: { - chicken: true, - }, - }, - }; - - expect( isFeatureActive( state, 'chicken' ) ).toBe( true ); - } ); - - it( 'should return false if feature is not active', () => { - const state = { - preferences: { - features: { - chicken: false, - }, - }, - }; - - expect( isFeatureActive( state, 'chicken' ) ).toBe( false ); - } ); - - it( 'should return false if feature is not referred', () => { - const state = { - preferences: { - features: {}, - }, - }; - - expect( isFeatureActive( state, 'chicken' ) ).toBe( false ); - } ); - } ); - - describe( 'getSettings', () => { - it( 'returns the default settings', () => { - const state = { settings: {}, preferences: {} }; - const setInserterOpened = () => {}; - expect( getSettings( state, setInserterOpened ) ).toEqual( { - outlineMode: true, - focusMode: false, - fullscreenMode: true, - hasFixedToolbar: true, - hasReducedUI: false, - __experimentalSetIsInserterOpened: setInserterOpened, - __experimentalLocalAutosaveInterval: 30, - } ); - } ); - - it( 'returns the merged settings', () => { - const state = { - settings: { key: 'value' }, - preferences: { - features: { - focusMode: true, - fixedToolbar: true, - reducedUI: true, - }, - }, - }; - const setInserterOpened = () => {}; - expect( getSettings( state, setInserterOpened ) ).toEqual( { - key: 'value', - outlineMode: true, - focusMode: true, - fullscreenMode: true, - hasFixedToolbar: true, - hasReducedUI: true, - __experimentalSetIsInserterOpened: setInserterOpened, - __experimentalLocalAutosaveInterval: 30, - } ); - } ); - } ); - - describe( 'isInserterOpened', () => { - it( 'returns the block inserter panel isOpened state', () => { - const state = { - blockInserterPanel: true, - }; - expect( isInserterOpened( state ) ).toBe( true ); - state.blockInserterPanel = false; - expect( isInserterOpened( state ) ).toBe( false ); - } ); - } ); - - describe( 'isListViewOpened', () => { - it( 'returns the list view panel isOpened state', () => { - const state = { - listViewPanel: true, - }; - expect( isListViewOpened( state ) ).toBe( true ); - state.listViewPanel = false; - expect( isListViewOpened( state ) ).toBe( false ); - } ); - } ); - - it( 'should return false if post has no blocks', () => { - isPatternSaveable.registry = { - select: jest.fn( () => ( { - getEditedEntityRecord: () => { - return { - blocks: [], - }; - }, - } ) ), - }; - - expect( isPatternSaveable( {} ) ).toBe( false ); - } ); - - describe( 'isPatternSaveable', () => { - it( 'should return true if post has a block', () => { - isPatternSaveable.registry = { - select: jest.fn( () => ( { - getEditedEntityRecord: () => { - return { - blocks: [ - { - attributes: { content: 'w', dropCap: false }, - clientId: 'wordpress', - innerBlocks: [], - isValid: true, - name: 'core/paragraph', - }, - ], - }; - }, - } ) ), - }; - - expect( isPatternSaveable( {} ) ).toBe( true ); - } ); - } ); -} ); diff --git a/public_html/wp-content/plugins/pattern-creator/src/style.scss b/public_html/wp-content/plugins/pattern-creator/src/style.scss deleted file mode 100644 index 5467fab1b..000000000 --- a/public_html/wp-content/plugins/pattern-creator/src/style.scss +++ /dev/null @@ -1,20 +0,0 @@ -/* Base styles */ -@import "~@wordpress/base-styles/colors"; -@import "~@wordpress/base-styles/variables"; -@import "~@wordpress/base-styles/mixins"; -@import "~@wordpress/base-styles/breakpoints"; -@import "~@wordpress/base-styles/animations"; -@import "~@wordpress/base-styles/z-index"; -@import "~@wordpress/base-styles/default-custom-properties"; - -/* Components */ -@import "./components/block-editor/style"; -@import "./components/editor/style"; -@import "./components/header/style"; -@import "./components/header/more-menu/style"; -@import "./components/openverse/style"; -@import "./components/secondary-sidebar/style"; -@import "./components/sidebar/style"; -@import "./components/sidebar/settings-header/style"; -@import "./components/submission-modal/style"; -@import "./components/welcome-guide/style"; diff --git a/public_html/wp-content/plugins/pattern-creator/view/editor.php b/public_html/wp-content/plugins/pattern-creator/view/editor.php deleted file mode 100644 index a8fde1fc0..000000000 --- a/public_html/wp-content/plugins/pattern-creator/view/editor.php +++ /dev/null @@ -1,45 +0,0 @@ -'; -} else { - // Include block content from other files to simplify HTML markup. - ob_start(); - if ( ! $is_logged_in ) { - include __DIR__ . '/log-in.php'; - } elseif ( ! $can_edit ) { - include __DIR__ . '/not-owner.php'; - } - $template_html = sprintf( '
%s
', do_blocks( ob_get_clean() ) ); -} - -?> -> - - - - - -> - - - - - - - diff --git a/public_html/wp-content/plugins/pattern-creator/view/log-in.php b/public_html/wp-content/plugins/pattern-creator/view/log-in.php deleted file mode 100644 index 010cc5fd7..000000000 --- a/public_html/wp-content/plugins/pattern-creator/view/log-in.php +++ /dev/null @@ -1,65 +0,0 @@ - 'new-pattern' ); -if ( get_query_var( PATTERN_ID_VAR ) ) { - $current_page_query_args[ PATTERN_ID_VAR ] = get_query_var( PATTERN_ID_VAR ); -} -$current_page_url = add_query_arg( $current_page_query_args, home_url() ); - -?> - - - -
- - -
- -

- - - -

- -

- - - -
- -
- -
- - - -

- review the guidelines.', 'wporg-patterns' ) ), - esc_url( home_url( '/about/' ) ) - ); - ?> -

- - - - - -
- - -
- - - diff --git a/public_html/wp-content/plugins/pattern-creator/view/not-owner.php b/public_html/wp-content/plugins/pattern-creator/view/not-owner.php deleted file mode 100644 index 364a14cc5..000000000 --- a/public_html/wp-content/plugins/pattern-creator/view/not-owner.php +++ /dev/null @@ -1,37 +0,0 @@ - - - - -
- - -
- - -

- - - -
-
-

-
- - - - - -
- - -
- - - diff --git a/public_html/wp-content/plugins/pattern-creator/webpack.config.js b/public_html/wp-content/plugins/pattern-creator/webpack.config.js deleted file mode 100644 index 88a4832ea..000000000 --- a/public_html/wp-content/plugins/pattern-creator/webpack.config.js +++ /dev/null @@ -1,12 +0,0 @@ -const defaultConfig = require( '@wordpress/scripts/config/webpack.config' ); - -const config = { - ...defaultConfig, - output: { - ...defaultConfig.output, - library: [ 'wp', 'patternCreator' ], - libraryTarget: 'window', - }, -}; - -module.exports = config; diff --git a/public_html/wp-content/plugins/pattern-directory/bootstrap.php b/public_html/wp-content/plugins/pattern-directory/bootstrap.php index 5b0a1e53a..b4a61f401 100644 --- a/public_html/wp-content/plugins/pattern-directory/bootstrap.php +++ b/public_html/wp-content/plugins/pattern-directory/bootstrap.php @@ -11,12 +11,15 @@ require_once __DIR__ . '/includes/class-rest-flags-controller.php'; require_once __DIR__ . '/includes/class-rest-favorite-controller.php'; require_once __DIR__ . '/includes/logging.php'; +require_once __DIR__ . '/includes/openverse.php'; require_once __DIR__ . '/includes/pattern-post-type.php'; require_once __DIR__ . '/includes/pattern-flag-post-type.php'; require_once __DIR__ . '/includes/pattern-validation.php'; +require_once __DIR__ . '/includes/editor.php'; require_once __DIR__ . '/includes/search.php'; require_once __DIR__ . '/includes/favorite.php'; require_once __DIR__ . '/includes/stats.php'; require_once __DIR__ . '/includes/admin.php'; require_once __DIR__ . '/includes/notifications.php'; require_once __DIR__ . '/includes/badges.php'; +require_once __DIR__ . '/includes/mock-blocks.php'; diff --git a/public_html/wp-content/plugins/pattern-directory/includes/admin-patterns.php b/public_html/wp-content/plugins/pattern-directory/includes/admin-patterns.php index 4cbe13f50..50de661f2 100644 --- a/public_html/wp-content/plugins/pattern-directory/includes/admin-patterns.php +++ b/public_html/wp-content/plugins/pattern-directory/includes/admin-patterns.php @@ -422,6 +422,11 @@ function add_row_actions( $actions, $post ) { return $actions; } + $post_type_object = get_post_type_object( $post->post_type ); + if ( ! current_user_can( $post_type_object->cap->edit_others_posts ) ) { + return array_intersect_key( $actions, array_fill_keys( array( 'edit', 'view', 'trash', 'untrash', 'delete' ), true ) ); + } + $saved_actions = array_intersect_key( $actions, array_fill_keys( array( 'trash', 'untrash', 'delete' ), true ) ); $actions = array_intersect_key( $actions, array_fill_keys( array( 'edit', 'view' ), true ) ); @@ -495,6 +500,11 @@ function add_row_actions( $actions, $post ) { function add_bulk_actions( $actions ) { $saved_actions = array_intersect_key( $actions, array_fill_keys( array( 'trash', 'untrash', 'delete' ), true ) ); + $post_type_object = get_post_type_object( PATTERN ); + if ( ! current_user_can( $post_type_object->cap->edit_others_posts ) ) { + return $saved_actions; + } + $actions = array( 'publish' => __( 'Publish', 'wporg-patterns' ), 'spam' => __( 'Spam', 'wporg-patterns' ), diff --git a/public_html/wp-content/plugins/pattern-directory/includes/admin-stats.php b/public_html/wp-content/plugins/pattern-directory/includes/admin-stats.php index 3395ffc1e..ace91251b 100644 --- a/public_html/wp-content/plugins/pattern-directory/includes/admin-stats.php +++ b/public_html/wp-content/plugins/pattern-directory/includes/admin-stats.php @@ -32,7 +32,7 @@ function add_subpage() { $parent_slug, __( 'Pattern Stats', 'wporg-patterns' ), __( 'Stats', 'wporg-patterns' ), - $post_type_object->cap->edit_posts, + $post_type_object->cap->edit_others_posts, PATTERN_POST_TYPE . '-stats', __NAMESPACE__ . '\render_subpage' ); @@ -143,7 +143,7 @@ function handle_csv_export() { return; } - if ( ! current_user_can( $cpt->cap->edit_posts ) ) { + if ( ! current_user_can( $cpt->cap->edit_others_posts ) ) { $csv->error->add( 'no_permission', 'Sorry, you do not have permission to do this.' ); $csv->emit_file(); } diff --git a/public_html/wp-content/plugins/pattern-directory/includes/editor.php b/public_html/wp-content/plugins/pattern-directory/includes/editor.php new file mode 100644 index 000000000..d6177fdb6 --- /dev/null +++ b/public_html/wp-content/plugins/pattern-directory/includes/editor.php @@ -0,0 +1,200 @@ +post_type === POST_TYPE; + } + + return false; +} + +/** + * Set up page for customized editor. + */ +function set_default_theme() { + if ( ! is_pattern_editor() ) { + return; + } + + $theme = ( 'local' === wp_get_environment_type() ) ? 'twentytwentyfour' : 'core/twentytwentyfour'; + + add_filter( + 'template', + function() use ( $theme ) { + return $theme; + } + ); + + add_filter( + 'stylesheet', + function() use ( $theme ) { + return $theme; + } + ); +} + +/** + * Enqueue scripts for the block editor. + * + * @throws Error If the build files don't exist. + */ +function enqueue_editor_assets() { + if ( function_exists( 'get_current_screen' ) && POST_TYPE !== get_current_screen()->id ) { + return; + } + + $dir = dirname( dirname( __FILE__ ) ); + + $script_asset_path = "$dir/build/pattern-post-type.asset.php"; + if ( ! file_exists( $script_asset_path ) ) { + throw new Error( 'You need to run `yarn start` or `yarn build` for the Pattern Directory.' ); + } + + $script_asset = require $script_asset_path; + wp_enqueue_script( + SCRIPT_HANDLE, + plugins_url( 'build/pattern-post-type.js', dirname( __FILE__ ) ), + $script_asset['dependencies'], + $script_asset['version'], + true + ); + + wp_set_script_translations( SCRIPT_HANDLE, 'wporg-patterns' ); + + $locales = ( is_admin() ) ? get_locales_with_english_names() : get_locales_with_native_names(); + + wp_add_inline_script( + SCRIPT_HANDLE, + 'var wporgLocaleData = ' . wp_json_encode( $locales ) . ';', + 'before' + ); + + wp_add_inline_script( + SCRIPT_HANDLE, + sprintf( + "var wporgLocale = JSON.parse( decodeURIComponent( '%s' ) );", + rawurlencode( wp_json_encode( array( + 'id' => get_locale(), + 'displayName' => is_rosetta_site() ? get_rosetta_name() : '', + ) ) ), + ), + 'before' + ); + + wp_add_inline_script( + SCRIPT_HANDLE, + sprintf( + 'var wporgBlockPattern = JSON.parse( decodeURIComponent( \'%s\' ) );', + rawurlencode( wp_json_encode( array( + 'siteUrl' => esc_url( home_url() ), + ) ) ) + ), + 'before' + ); + + wp_enqueue_style( + 'wporg-pattern-post-type', + plugins_url( 'build/pattern-post-type.css', dirname( __FILE__ ) ), + array(), + $script_asset['version'], + ); +} + +/** + * Restrict the set of blocks allowed in block patterns. + * + * @param bool|array $allowed_block_types Array of block type slugs, or boolean to enable/disable all. + * @param WP_Block_Editor_Context $block_editor_context The post resource data. + * + * @return bool|array A (possibly) filtered list of block types. + */ +function remove_disallowed_blocks( $allowed_block_types, $block_editor_context ) { + $disallowed_block_types = array( + // Remove blocks that don't make sense in Block Patterns + 'core/freeform', // Classic block + 'core/legacy-widget', + 'core/more', + 'core/nextpage', + 'core/block', // Reusable blocks + 'core/shortcode', + 'core/template-part', + ); + + if ( isset( $block_editor_context->post ) && POST_TYPE === $block_editor_context->post->post_type ) { + // This can be true if all block types are allowed, so to filter them we + // need to get the list of all registered blocks first. + if ( true === $allowed_block_types ) { + $allowed_block_types = array_keys( WP_Block_Type_Registry::get_instance()->get_all_registered() ); + } + $allowed_block_types = array_diff( $allowed_block_types, $disallowed_block_types ); + + // Remove the "WordPress.org" blocks, like Global Header & Global Footer. + $allowed_block_types = array_filter( + $allowed_block_types, + function ( $block_type ) { + return 'wporg/' !== substr( $block_type, 0, 6 ); + } + ); + } + + return is_array( $allowed_block_types ) ? array_values( $allowed_block_types ) : $allowed_block_types; +} + +/** + * Disable the block directory in wp-admin for patterns. + * + * The block directory file isn't loaded on the frontend, so this is only needed for site admins who can open + * the pattern in the "real" wp-admin editor. + */ +function disable_block_directory() { + if ( is_admin() && POST_TYPE === get_post_type() ) { + remove_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets' ); + remove_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_block_editor_assets_block_directory' ); + } +} diff --git a/public_html/wp-content/plugins/pattern-creator/includes/mock-blocks.php b/public_html/wp-content/plugins/pattern-directory/includes/mock-blocks.php similarity index 99% rename from public_html/wp-content/plugins/pattern-creator/includes/mock-blocks.php rename to public_html/wp-content/plugins/pattern-directory/includes/mock-blocks.php index 4d3e9b3f1..b1aabadf9 100644 --- a/public_html/wp-content/plugins/pattern-creator/includes/mock-blocks.php +++ b/public_html/wp-content/plugins/pattern-directory/includes/mock-blocks.php @@ -3,7 +3,7 @@ * Mock dynamic blocks that use site content. */ -namespace WordPressdotorg\Pattern_Creator\MockBlocks; +namespace WordPressdotorg\Pattern_Directory\MockBlocks; use WP_Block_Supports; diff --git a/public_html/wp-content/plugins/pattern-creator/includes/openverse-client.php b/public_html/wp-content/plugins/pattern-directory/includes/openverse-client.php similarity index 99% rename from public_html/wp-content/plugins/pattern-creator/includes/openverse-client.php rename to public_html/wp-content/plugins/pattern-directory/includes/openverse-client.php index 66ede28b3..f1d745dba 100644 --- a/public_html/wp-content/plugins/pattern-creator/includes/openverse-client.php +++ b/public_html/wp-content/plugins/pattern-directory/includes/openverse-client.php @@ -2,7 +2,7 @@ /** * Class Openverse_Client * - * @package WordPressdotorg\Pattern_Creator + * @package WordPressdotorg\Pattern_Directory */ class Openverse_Client { /** diff --git a/public_html/wp-content/plugins/pattern-creator/includes/openverse-rest-controller.php b/public_html/wp-content/plugins/pattern-directory/includes/openverse-rest-controller.php similarity index 98% rename from public_html/wp-content/plugins/pattern-creator/includes/openverse-rest-controller.php rename to public_html/wp-content/plugins/pattern-directory/includes/openverse-rest-controller.php index 2ce0398e7..421a916e8 100644 --- a/public_html/wp-content/plugins/pattern-creator/includes/openverse-rest-controller.php +++ b/public_html/wp-content/plugins/pattern-directory/includes/openverse-rest-controller.php @@ -4,7 +4,7 @@ * * This serves as a proxy layer to authenticate and cache the Openverse API requests. * - * @package WordPressdotorg\Pattern_Creator + * @package WordPressdotorg\Pattern_Directory */ class Openverse_REST_Controller extends WP_REST_Controller { /** diff --git a/public_html/wp-content/plugins/pattern-directory/includes/openverse.php b/public_html/wp-content/plugins/pattern-directory/includes/openverse.php new file mode 100644 index 000000000..4926a7932 --- /dev/null +++ b/public_html/wp-content/plugins/pattern-directory/includes/openverse.php @@ -0,0 +1,31 @@ +register_routes(); + + // Allow the post type labels through the `types` endpoint when viewing. + // This passes the value back to unauthenticated users, which prevents JS + // errors when the post-date block tries to use them. + register_rest_field( + 'type', // The object-type for the `types` endpoint. + 'labels', + array( + 'schema' => array( + 'description' => __( 'Human-readable labels for the post type for various contexts.', 'wporg-patterns' ), + 'type' => 'object', + 'context' => array( 'edit', 'view' ), + 'readonly' => true, + ), + ) + ); +} diff --git a/public_html/wp-content/plugins/pattern-directory/includes/pattern-post-type.php b/public_html/wp-content/plugins/pattern-directory/includes/pattern-post-type.php index f47b79bf2..baf05979a 100644 --- a/public_html/wp-content/plugins/pattern-directory/includes/pattern-post-type.php +++ b/public_html/wp-content/plugins/pattern-directory/includes/pattern-post-type.php @@ -2,8 +2,7 @@ namespace WordPressdotorg\Pattern_Directory\Pattern_Post_Type; -use Error, WP_Block_Type_Registry; -use function WordPressdotorg\Locales\{ get_locales, get_locales_with_english_names, get_locales_with_native_names }; +use function WordPressdotorg\Locales\{ get_locales }; use function WordPressdotorg\Pattern_Directory\Favorite\get_favorite_count; use const WordPressdotorg\Pattern_Directory\Pattern_Flag_Post_Type\TAX_TYPE as FLAG_REASON; @@ -16,9 +15,6 @@ add_action( 'init', __NAMESPACE__ . '\register_post_statuses' ); add_action( 'transition_post_status', __NAMESPACE__ . '\status_transitions', 10, 3 ); add_action( 'post_updated', __NAMESPACE__ . '\update_contains_block_types_meta' ); -add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\enqueue_editor_assets' ); -add_filter( 'allowed_block_types_all', __NAMESPACE__ . '\remove_disallowed_blocks', 10, 2 ); -add_action( 'enqueue_block_editor_assets', __NAMESPACE__ . '\disable_block_directory', 0 ); add_filter( 'rest_' . POST_TYPE . '_collection_params', __NAMESPACE__ . '\filter_patterns_collection_params' ); add_filter( 'rest_' . POST_TYPE . '_query', __NAMESPACE__ . '\filter_patterns_rest_query', 10, 2 ); add_filter( 'user_has_cap', __NAMESPACE__ . '\set_pattern_caps' ); @@ -80,6 +76,7 @@ function register_post_type_data() { 'show_in_rest' => true, 'rest_base' => 'pattern-categories', 'show_admin_column' => true, + 'show_ui' => current_user_can( 'manage_options' ), 'rewrite' => array( 'slug' => 'categories', ), @@ -100,14 +97,14 @@ function register_post_type_data() { 'show_in_rest' => true, 'rest_base' => 'pattern-keywords', 'show_admin_column' => true, + 'show_ui' => current_user_can( 'manage_options' ), 'rewrite' => array( 'slug' => 'pattern-keywords', ), 'capabilities' => array( - 'assign_terms' => 'edit_patterns', - 'edit_terms' => 'edit_patterns', + 'assign_terms' => 'manage_options', + 'edit_terms' => 'manage_options', ), - 'labels' => array( 'name' => _x( 'Keywords (Internal)', 'taxonomy general name', 'wporg-patterns' ), 'singular_name' => _x( 'Keyword', 'taxonomy singular name', 'wporg-patterns' ), @@ -550,103 +547,6 @@ function can_edit_this_pattern( $allowed, $meta_key, $pattern_id ) { return current_user_can( 'edit_post', $pattern_id ); } -/** - * Enqueue scripts for the block editor. - * - * @throws Error If the build files don't exist. - */ -function enqueue_editor_assets() { - if ( function_exists( 'get_current_screen' ) && POST_TYPE !== get_current_screen()->id ) { - return; - } - - $dir = dirname( dirname( __FILE__ ) ); - - $script_asset_path = "$dir/build/pattern-post-type.asset.php"; - if ( ! file_exists( $script_asset_path ) ) { - throw new Error( 'You need to run `npm run start:directory` or `npm run build:directory` for the Pattern Directory.' ); - } - - $script_asset = require $script_asset_path; - wp_enqueue_script( - 'wporg-pattern-post-type', - plugins_url( 'build/pattern-post-type.js', dirname( __FILE__ ) ), - $script_asset['dependencies'], - $script_asset['version'], - true - ); - - wp_set_script_translations( 'wporg-pattern-post-type', 'wporg-patterns' ); - - $locales = ( is_admin() ) ? get_locales_with_english_names() : get_locales_with_native_names(); - - wp_add_inline_script( - 'wporg-pattern-post-type', - 'var wporgLocaleData = ' . wp_json_encode( $locales ) . ';', - 'before' - ); - - wp_enqueue_style( - 'wporg-pattern-post-type', - plugins_url( 'build/pattern-post-type.css', dirname( __FILE__ ) ), - array(), - $script_asset['version'], - ); -} - -/** - * Restrict the set of blocks allowed in block patterns. - * - * @param bool|array $allowed_block_types Array of block type slugs, or boolean to enable/disable all. - * @param WP_Block_Editor_Context $block_editor_context The post resource data. - * - * @return bool|array A (possibly) filtered list of block types. - */ -function remove_disallowed_blocks( $allowed_block_types, $block_editor_context ) { - $disallowed_block_types = array( - // Remove blocks that don't make sense in Block Patterns - 'core/freeform', // Classic block - 'core/legacy-widget', - 'core/more', - 'core/nextpage', - 'core/block', // Reusable blocks - 'core/shortcode', - 'core/template-part', - ); - - if ( isset( $block_editor_context->post ) && POST_TYPE === $block_editor_context->post->post_type ) { - // This can be true if all block types are allowed, so to filter them we - // need to get the list of all registered blocks first. - if ( true === $allowed_block_types ) { - $allowed_block_types = array_keys( WP_Block_Type_Registry::get_instance()->get_all_registered() ); - } - $allowed_block_types = array_diff( $allowed_block_types, $disallowed_block_types ); - - // Remove the "WordPress.org" blocks, like Global Header & Global Footer. - $allowed_block_types = array_filter( - $allowed_block_types, - function ( $block_type ) { - return 'wporg/' !== substr( $block_type, 0, 6 ); - } - ); - } - - return is_array( $allowed_block_types ) ? array_values( $allowed_block_types ) : $allowed_block_types; -} - -/** - * Disable the block directory in wp-admin for patterns. - * - * The block directory file isn't loaded on the frontend, so this is only needed for site admins who can open - * the pattern in the "real" wp-admin editor. - */ -function disable_block_directory() { - if ( is_admin() && POST_TYPE === get_post_type() ) { - remove_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets' ); - remove_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_block_editor_assets_block_directory' ); - } -} - /** * Filter the collection parameters: * - set a new default for per_page. @@ -851,6 +751,8 @@ function get_block_pattern( $post ) { * @return array */ function set_pattern_caps( $user_caps ) { + global $current_screen; + // Set corresponding caps for all roles. $cap_args = array( 'capability_type' => array( 'pattern', 'patterns' ), @@ -868,7 +770,7 @@ function set_pattern_caps( $user_caps ) { } // Set caps to allow for front end pattern creation. - if ( is_user_logged_in() && ! is_admin() ) { + if ( is_user_logged_in() ) { $user_caps['read'] = true; $user_caps['publish_patterns'] = true; $user_caps['edit_patterns'] = true; @@ -878,6 +780,11 @@ function set_pattern_caps( $user_caps ) { // Note that `edit_others_patterns` & `delete_others_patterns` are separate capabilities. } + // Filter out `upload_files` from all non-admin users. + if ( ! isset( $user_caps['manage_options'] ) ) { + $user_caps['upload_files'] = false; + } + return $user_caps; } diff --git a/public_html/wp-content/plugins/pattern-directory/src/back-button/index.js b/public_html/wp-content/plugins/pattern-directory/src/back-button/index.js new file mode 100644 index 000000000..c0efb5165 --- /dev/null +++ b/public_html/wp-content/plugins/pattern-directory/src/back-button/index.js @@ -0,0 +1,28 @@ +/* global wporgBlockPattern */ +/** + * WordPress dependencies + */ +import { __ } from '@wordpress/i18n'; +import { + /* eslint-disable-next-line @wordpress/no-unsafe-wp-apis */ + __experimentalMainDashboardButton as MainDashboardButton, +} from '@wordpress/edit-post'; +import { Button } from '@wordpress/components'; +import { close } from '@wordpress/icons'; + +const BackButton = () => { + return ( + + + + ); +}; + +export default BackButton; diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/media-placeholder/index.js b/public_html/wp-content/plugins/pattern-directory/src/media-placeholder/index.js similarity index 100% rename from public_html/wp-content/plugins/pattern-creator/src/components/media-placeholder/index.js rename to public_html/wp-content/plugins/pattern-directory/src/media-placeholder/index.js diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/openverse/grid-actions.js b/public_html/wp-content/plugins/pattern-directory/src/openverse/grid-actions.js similarity index 100% rename from public_html/wp-content/plugins/pattern-creator/src/components/openverse/grid-actions.js rename to public_html/wp-content/plugins/pattern-directory/src/openverse/grid-actions.js diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/openverse/grid-items.js b/public_html/wp-content/plugins/pattern-directory/src/openverse/grid-items.js similarity index 100% rename from public_html/wp-content/plugins/pattern-creator/src/components/openverse/grid-items.js rename to public_html/wp-content/plugins/pattern-directory/src/openverse/grid-items.js diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/openverse/grid.js b/public_html/wp-content/plugins/pattern-directory/src/openverse/grid.js similarity index 100% rename from public_html/wp-content/plugins/pattern-creator/src/components/openverse/grid.js rename to public_html/wp-content/plugins/pattern-directory/src/openverse/grid.js diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/openverse/index.js b/public_html/wp-content/plugins/pattern-directory/src/openverse/index.js similarity index 56% rename from public_html/wp-content/plugins/pattern-creator/src/components/openverse/index.js rename to public_html/wp-content/plugins/pattern-directory/src/openverse/index.js index 50bd8784a..4b65ffb29 100644 --- a/public_html/wp-content/plugins/pattern-creator/src/components/openverse/index.js +++ b/public_html/wp-content/plugins/pattern-directory/src/openverse/index.js @@ -2,20 +2,14 @@ * WordPress dependencies */ import { __ } from '@wordpress/i18n'; -import { - Button, - Modal, - SearchControl, - /* @todo Remove StyleProvider workaround when https://github.com/WordPress/gutenberg/pull/36261 is released. */ - /* eslint-disable-next-line @wordpress/no-unsafe-wp-apis -- Experimental is OK. */ - __experimentalStyleProvider as StyleProvider, -} from '@wordpress/components'; +import { Button, Modal, SearchControl } from '@wordpress/components'; import { useState } from '@wordpress/element'; /** * Internal dependencies */ import OpenverseGrid from './grid'; +import './modal.scss'; const suggestedTerms = [ __( 'Mountains', 'wporg-patterns' ), @@ -29,29 +23,27 @@ function OpenverseExplorer( { onClose, ...props } ) { const [ searchTerm, setSearchTerm ] = useState( '' ); return ( - -
-
- - { searchTerm.length ? null : ( -

- { __( 'Suggestions', 'wporg-patterns' ) } - { suggestedTerms.map( ( term, i ) => ( - - ) ) } -

- ) } -
- +
+
+ + { searchTerm.length ? null : ( +

+ { __( 'Suggestions', 'wporg-patterns' ) } + { suggestedTerms.map( ( term, i ) => ( + + ) ) } +

+ ) }
- + +
); } diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/openverse/style.scss b/public_html/wp-content/plugins/pattern-directory/src/openverse/modal.scss similarity index 90% rename from public_html/wp-content/plugins/pattern-creator/src/components/openverse/style.scss rename to public_html/wp-content/plugins/pattern-directory/src/openverse/modal.scss index 58f290d0d..0a1cbfb4c 100644 --- a/public_html/wp-content/plugins/pattern-creator/src/components/openverse/style.scss +++ b/public_html/wp-content/plugins/pattern-directory/src/openverse/modal.scss @@ -1,3 +1,14 @@ +$grid-unit: 8px; +$grid-unit-20: 2 * $grid-unit; // 16px +$grid-unit-30: 3 * $grid-unit; // 24px +$grid-unit-40: 4 * $grid-unit; // 32px + +$white: #fff; +$gray-100: #f0f0f0; +$gray-200: #e0e0e0; +$gray-300: #ddd; +$gray-900: #1e1e1e; + .pattern-openverse__modal { width: 90vw; min-height: 90vh; @@ -21,7 +32,7 @@ display: block; height: 40px; width: 140px; - background: url(./components/openverse/powered-by-openverse.png) no-repeat center; + background: url(./powered-by-openverse.png) no-repeat center; background-size: contain; } } @@ -95,7 +106,7 @@ &.is-selected { &::after { - box-shadow: inset 0 0 0 3px $black; + box-shadow: inset 0 0 0 3px $gray-900; } &::before { @@ -136,7 +147,7 @@ align-items: center; gap: 0.25rem; - @include break-small() { + @media (min-width: 600px) { gap: 0.75rem; } } @@ -170,12 +181,12 @@ color: $white; } - @include break-small() { + @media (min-width: 600px) { padding: 0.75rem; } } -@media (max-width: #{ ($break-small) }) { +@media (max-width: 600px) { .pattern-openverse__pagination-item-previous-page, .pattern-openverse__pagination-item-next-page { .pattern-openverse__pagination-link span[aria-hidden] { diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/openverse/pagination.js b/public_html/wp-content/plugins/pattern-directory/src/openverse/pagination.js similarity index 100% rename from public_html/wp-content/plugins/pattern-creator/src/components/openverse/pagination.js rename to public_html/wp-content/plugins/pattern-directory/src/openverse/pagination.js diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/openverse/powered-by-openverse.png b/public_html/wp-content/plugins/pattern-directory/src/openverse/powered-by-openverse.png similarity index 100% rename from public_html/wp-content/plugins/pattern-creator/src/components/openverse/powered-by-openverse.png rename to public_html/wp-content/plugins/pattern-directory/src/openverse/powered-by-openverse.png diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/openverse/utils.js b/public_html/wp-content/plugins/pattern-directory/src/openverse/utils.js similarity index 100% rename from public_html/wp-content/plugins/pattern-creator/src/components/openverse/utils.js rename to public_html/wp-content/plugins/pattern-directory/src/openverse/utils.js diff --git a/public_html/wp-content/plugins/pattern-directory/src/pattern-post-type/details.js b/public_html/wp-content/plugins/pattern-directory/src/pattern-details/index.js similarity index 79% rename from public_html/wp-content/plugins/pattern-directory/src/pattern-post-type/details.js rename to public_html/wp-content/plugins/pattern-directory/src/pattern-details/index.js index 7c9a923f4..64b23d2ac 100644 --- a/public_html/wp-content/plugins/pattern-directory/src/pattern-post-type/details.js +++ b/public_html/wp-content/plugins/pattern-directory/src/pattern-details/index.js @@ -5,6 +5,7 @@ import { __ } from '@wordpress/i18n'; import { PluginDocumentSettingPanel } from '@wordpress/edit-post'; import { ComboboxControl, FormTokenField, TextControl, TextareaControl } from '@wordpress/components'; import { useDispatch, useSelect } from '@wordpress/data'; +import { store as coreStore } from '@wordpress/core-data'; import { store as editorStore } from '@wordpress/editor'; const KEYWORD_SLUG = 'wpop_keywords'; @@ -33,10 +34,13 @@ const PatternDetails = () => { title: getEditedPostAttribute( 'title' ) || '', }; } ); + const canModeratePatterns = useSelect( ( select ) => { + return select( coreStore ).canUser( 'create', 'posts' ) ?? false; + }, [] ); return ( @@ -93,24 +97,26 @@ const PatternDetails = () => { tokenizeOnSpace={ false } />
- - editPost( { - meta: { - ...meta, - [ LOCALE_SLUG ]: newValue, - }, - } ) - } - help={ __( - 'The language field is used to help users find patterns that were created in their preferred language.', - 'wporg-patterns' - ) } - /> + { canModeratePatterns && ( + + editPost( { + meta: { + ...meta, + [ LOCALE_SLUG ]: newValue, + }, + } ) + } + help={ __( + 'The language field is used to help users find patterns that were created in their preferred language.', + 'wporg-patterns' + ) } + /> + ) } ); }; diff --git a/public_html/wp-content/plugins/pattern-directory/src/pattern-post-type.js b/public_html/wp-content/plugins/pattern-directory/src/pattern-post-type.js index ab3fa15fc..d6dd5026e 100644 --- a/public_html/wp-content/plugins/pattern-directory/src/pattern-post-type.js +++ b/public_html/wp-content/plugins/pattern-directory/src/pattern-post-type.js @@ -1,13 +1,68 @@ /** * External dependencies */ +import { addFilter } from '@wordpress/hooks'; import { registerPlugin } from '@wordpress/plugins'; +import { useDispatch, useSelect } from '@wordpress/data'; +import { store as editPostStore } from '@wordpress/edit-post'; +import { store as editorStore } from '@wordpress/editor'; +import { store as coreStore } from '@wordpress/core-data'; +import { useEffect } from '@wordpress/element'; /** * Internal dependencies */ -import PluginWrapper from './pattern-post-type/'; +import BackButton from './back-button'; +import { NAMESPACE } from './settings'; +import PatternDetails from './pattern-details'; +import { UnlistButton, UnlistNotice } from './unlist-button'; +import MediaPlaceholder from './media-placeholder'; +import OpenverseGallery from './openverse'; -registerPlugin( 'pattern-post-type', { +const PluginWrapper = () => { + const { canModeratePatterns, isDetailsPanelOpen, isFullscreenMode } = useSelect( ( select ) => { + return { + // If a user can create posts, they have a role on the site (moderator). + canModeratePatterns: select( coreStore ).canUser( 'create', 'posts' ), + isDetailsPanelOpen: select( editorStore ).isEditorPanelOpened( NAMESPACE + '/pattern-details' ), + isFullscreenMode: select( editPostStore ).isFeatureActive( 'fullscreenMode' ), + }; + }, [] ); + const { toggleFeature } = useDispatch( editPostStore ); + const { removeEditorPanel, toggleEditorPanelOpened } = useDispatch( editorStore ); + + useEffect( () => { + if ( ! isFullscreenMode ) { + toggleFeature( 'fullscreenMode' ); + } + if ( false === canModeratePatterns ) { + removeEditorPanel( 'post-status' ); + } + if ( ! isDetailsPanelOpen ) { + toggleEditorPanelOpened( NAMESPACE + '/pattern-details' ); + } + }, [ + isFullscreenMode, + toggleFeature, + canModeratePatterns, + removeEditorPanel, + isDetailsPanelOpen, + toggleEditorPanelOpened, + ] ); + + return ( + <> + { canModeratePatterns && } + + + + + ); +}; + +registerPlugin( NAMESPACE, { render: PluginWrapper, } ); + +addFilter( 'editor.MediaPlaceholder', 'wporg/patterns/components/media-upload', () => MediaPlaceholder, 100 ); +addFilter( 'editor.MediaUpload', 'wporg-patterns/openverse-media-upload', () => OpenverseGallery, 100 ); diff --git a/public_html/wp-content/plugins/pattern-directory/src/pattern-post-type/index.js b/public_html/wp-content/plugins/pattern-directory/src/pattern-post-type/index.js deleted file mode 100644 index 036043164..000000000 --- a/public_html/wp-content/plugins/pattern-directory/src/pattern-post-type/index.js +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Internal dependencies - */ -import { UnlistButton, UnlistNotice } from './unlist-button'; -import PatternDetails from './details'; - -const PluginWrapper = () => { - return ( - <> - - - - - ); -}; - -export default PluginWrapper; diff --git a/public_html/wp-content/plugins/pattern-directory/src/pattern-post-type/settings.js b/public_html/wp-content/plugins/pattern-directory/src/settings.js similarity index 50% rename from public_html/wp-content/plugins/pattern-directory/src/pattern-post-type/settings.js rename to public_html/wp-content/plugins/pattern-directory/src/settings.js index 0e31942b8..91784e6e5 100644 --- a/public_html/wp-content/plugins/pattern-directory/src/pattern-post-type/settings.js +++ b/public_html/wp-content/plugins/pattern-directory/src/settings.js @@ -1 +1,2 @@ export const UNLISTED_STATUS = 'unlisted'; +export const NAMESPACE = 'wporg-pattern'; diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/submission-modal/images/circle.svg b/public_html/wp-content/plugins/pattern-directory/src/submission-modal/images/circle.svg similarity index 100% rename from public_html/wp-content/plugins/pattern-creator/src/components/submission-modal/images/circle.svg rename to public_html/wp-content/plugins/pattern-directory/src/submission-modal/images/circle.svg diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/submission-modal/images/square.svg b/public_html/wp-content/plugins/pattern-directory/src/submission-modal/images/square.svg similarity index 100% rename from public_html/wp-content/plugins/pattern-creator/src/components/submission-modal/images/square.svg rename to public_html/wp-content/plugins/pattern-directory/src/submission-modal/images/square.svg diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/submission-modal/images/triangle.svg b/public_html/wp-content/plugins/pattern-directory/src/submission-modal/images/triangle.svg similarity index 100% rename from public_html/wp-content/plugins/pattern-creator/src/components/submission-modal/images/triangle.svg rename to public_html/wp-content/plugins/pattern-directory/src/submission-modal/images/triangle.svg diff --git a/public_html/wp-content/plugins/pattern-creator/src/components/submission-modal/index.js b/public_html/wp-content/plugins/pattern-directory/src/submission-modal/index.js similarity index 98% rename from public_html/wp-content/plugins/pattern-creator/src/components/submission-modal/index.js rename to public_html/wp-content/plugins/pattern-directory/src/submission-modal/index.js index 1227bb1a4..347d011fd 100644 --- a/public_html/wp-content/plugins/pattern-creator/src/components/submission-modal/index.js +++ b/public_html/wp-content/plugins/pattern-directory/src/submission-modal/index.js @@ -1,3 +1,4 @@ +/* global wporgLocale, wporgBlockPattern */ /** * WordPress dependencies */ @@ -10,6 +11,11 @@ import { store as editorStore } from '@wordpress/editor'; import { store as noticesStore } from '@wordpress/notices'; import { useDispatch, useSelect } from '@wordpress/data'; +/** + * Internal Dependencies + */ +import './submission-modal.scss'; + const ForwardButton = ( { children, disabled, onClick } ) => (