Skip to content

Conversation

@kean
Copy link
Contributor

@kean kean commented Oct 20, 2025

Changes

  • Add BlockInserterView and a set or related types to render the blocks in a grid (closes CMM-857)
  • Add context menus for blocks (closes CMM-863)
  • Make the inserter searchable (closes CMM-858)

Testing Instructions

  • Enable "Native Inserter"
  • Tap "+"
  • Verify that the new inserter is shown
  • Verify that you can long-press on a block to reveal more details
  • Verify that you can search for a block using it's name, title, keywords or category (search weights defined in that order)
  • Verify that Dynamic Type and Dark Mode are supported

Note: you can not yet tap to select a block.

Technical Notes

I added SVGKit to render block icons. It seems like the only viable option.

Limitations

  • BlockInserterViewModel establishes some mobile-specific ordering for blocks, but I opened a separate ticket (CMM-875) to further enhance it (see screenshots/comments). I'm considering implementing it on the JS level.
  • There is some non-localized text in this PR. I opened CMM-874.
  • Some block icons contain incorrect SVG (CMM-873). I'm considering fixing it at the source and/or patching them in GBK.

Screenshots

Screenshot 2025-10-21 at 12 59 49 PM Screenshot 2025-10-21 at 1 02 41 PM
Screenshot 2025-10-21 at 1 02 46 PM Screenshot 2025-10-21 at 1 04 00 PM

@kean kean force-pushed the task/show-blocks-in-grid branch 2 times, most recently from 1115994 to 7b5cabb Compare October 20, 2025 20:54
@kean kean changed the title Add basic block inserter features: block grid, search Add basic block inserter features: grid, search, icons, ordering Oct 21, 2025
import Foundation

/// A protocol for items that can be searched
protocol Searchable {
Copy link
Contributor Author

@kean kean Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disclaimer: other code in PR is written by hand, but this file is entirely generated. It uses Levenshtein distance for fuzzy matching, and does scoring depending on weight of searchable fields. It seems to work pretty well, and we do need it in the inserter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Searching worked relatively well from my testing. I noted one thing while searching: we are not honoring the inserter supports attribute for blocks. Blocks setting this to false should not appear in the block inserter or its search results.

*
* @return {string|null} The serialized icon string or null.
*/
function getBlockIcon( blockType ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I generated this too. I might need some help verifying if it makes sense (it works).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it makes sense. It seems necessary given the desired outcome of providing SVG strings to the native host app. I cannot think of a better alternative or specific problems with the approach at this time.

@kean kean requested a review from dcalhoun October 21, 2025 18:34
@kean kean marked this pull request as ready for review October 21, 2025 18:35
keywords: blockType.keywords || [],
};
} );
const blocks = getSerializedBlocks();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't reviewed all the code yet, but wanted to note we need to rebase to include #198 and adapt this implementation so that the remote editor works.

Good news is that the native inserter does work with the remote editor in my quick merge conflict resolution on my local machine.

@kean kean force-pushed the task/show-blocks-in-grid branch from a54f386 to b5f3d7b Compare October 22, 2025 11:42
@kean kean force-pushed the task/show-blocks-in-grid branch from b5f3d7b to a55adca Compare October 22, 2025 12:56
The static import resulted in `window.wp` references prior them being
defined. This problem is unique to the remote editor, which
asynchronously loads site-specific `@wordpress` module scripts. Using a
dynamic import within the function ensures the reference does occur
until after the globals are defined.
@kean kean requested a review from dcalhoun October 22, 2025 18:14
Copy link
Member

@dcalhoun dcalhoun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving as this works well from my testing and other PRs build atop this. My inline comments note one issue we should address regarding inserter block inclusion.

import Foundation

/// A protocol for items that can be searched
protocol Searchable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Searching worked relatively well from my testing. I noted one thing while searching: we are not honoring the inserter supports attribute for blocks. Blocks setting this to false should not appear in the block inserter or its search results.

*
* @return {string|null} The serialized icon string or null.
*/
function getBlockIcon( blockType ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it makes sense. It seems necessary given the desired outcome of providing SVG strings to the native host app. I cannot think of a better alternative or specific problems with the approach at this time.

Comment on lines +78 to +85
return {
name: blockType.name,
title: blockType.title,
description: blockType.description,
category: blockType.category,
keywords: blockType.keywords || [],
icon: getBlockIcon( blockType ),
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted in my comment regarding search, we likely need to include the inserter supports attribute so that we can honor that setting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it as a bug and will address in the upcoming PRs. Thanks!

@kean kean merged commit 29a7bd1 into trunk Oct 23, 2025
11 checks passed
@kean kean deleted the task/show-blocks-in-grid branch October 23, 2025 16:53
@dcalhoun
Copy link
Member

Noting that this may be a breaking change for WordPress-iOS. When we integrate the latest GBK changes, we'll need to address this:

/Library/Developer/Xcode/DerivedData/WordPress-bwtwzztzxastvrfeguwfttopcahk/SourcePackages/checkouts/SVGKit/Source/include/Comment.h:17:12 'Comment' has different definitions in different modules; first difference is definition in module 'SVGKit' found super class with type 'CharacterData'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants