✨ feat: add patterns to the "/" slash inserter - #140
Open
charl0tee wants to merge 1 commit into
Open
Conversation
The core slash inserter only lists block types and synced patterns, so theme patterns registered in PHP were only reachable from the inserter's "Patterns" tab. Wrap the core `blocks` completer to append the patterns matching what is typed after the "/". Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pourquoi
Dans l'éditeur de blocs, taper
/ne propose que des types de blocs (et les patterns synchroniséswp_block) : le complèteurblocksde@wordpress/block-editorlitgetInserterItems(), qui ignore les patterns enregistrés en PHP. Ceux-ci ne sont donc accessibles que via l'onglet « Compositions » de l'inserteur.Ce que fait la PR
wordpress/theme/src/editor/pattern-slash-inserter.tsx:editor.Autocomplete.completerset enveloppe le complèteurblocks— un seul complèteur peut être actif par préfixe/, il est donc impossible d'en ajouter un second ;__experimentalGetAllowedPatterns(), filtrés sur titre / description / mots-clés / catégories (recherche insensible à la casse et aux accents), 6 maximum, précédés de l'icône « composition » ;Block Types: core/post-content, qui sont des contenus de démarrage de page entière et non des sections à insérer au milieu d'un contenu ;cloneBlock(contenu non synchronisé, comme l'inserteur habituel).Les patterns n'apparaissent qu'à partir du premier caractère tapé, pour laisser la liste par défaut de
/inchangée.Note d'implémentation
useItemsrenvoie un tableau mémoïsé : une nouvelle référence à chaque rendu fait boucler leonChangeOptionsdu composantAutocomplete(erreur React #185).Tests
Vérifié sur tipee.ch (même structure de thème) : dans l'éditeur d'une page,
/heropropose bien les patterns « Hero » du thème et la sélection insère la section complète, sans erreur console.🤖 Generated with Claude Code