Skip to content

feat(rebemer): smarter default BEM names + configurable type mapping - #63

Merged
jackgranatowski merged 2 commits into
mainfrom
claude/rebemer-default-bem-names-agzxk7
Jun 20, 2026
Merged

feat(rebemer): smarter default BEM names + configurable type mapping#63
jackgranatowski merged 2 commits into
mainfrom
claude/rebemer-default-bem-names-agzxk7

Conversation

@jackgranatowski

@jackgranatowski jackgranatowski commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Reduce how often the reBEMer panel pre-fills weak defaults ("item",
"content") that the user has to retype.

  • Expand ELEMENT_TYPE_LABEL_MAP and SOLE_CHILD_LABEL_OVERRIDES to cover
    many more Bricks element types (divider, social-icons, post-*,
    progress-bar, breadcrumbs, etc.) so far fewer rows fall to "item".
  • Add a version-tolerant getElementTypeLabel() seam in bricks-api that
    reads Bricks' element registry; BemPanel uses the slugified human label
    as a smarter fallback than "item" for unmapped, non-container types.
    Containers still go through child-aware role inference so we never emit
    block__container.
  • Add an admin "reBEMer" tab that persists a sparse element-type -> BEM
    name override map (rebemer_element_map) and a container-naming mode
    (rebemer_container_mode: role | generic). Stored in
    slashed_bricks_settings, sanitized against the same BEM grammar as
    validate.js, localized onto window.slashedBricksEditor, and merged over
    the frozen built-in map at panel-open time.

Extends tests/element-types.test.js and updates docs/rebemer.md. Rebuilt
editor-app and admin-app bundles.

Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01HtPN4CvQjMTdvPLALAW3GE


Summary by cubic

Smarter default BEM names for reBEMer with broader type coverage, a fallback to Bricks’ human labels, and a new admin tab to override type→name defaults and choose container naming mode. This reduces “item”/“content” pre-fills and speeds up naming.

  • New Features

    • Expanded ELEMENT_TYPE_LABEL_MAP and SOLE_CHILD_LABEL_OVERRIDES to cover more Bricks types (e.g., divider, social-icons, post-*, progress-bar, breadcrumbs).
    • Added bricks-api.getElementTypeLabel() to read Bricks’ element registry and use the slugified human label when a type isn’t mapped; containers still use child‑aware role inference (no block__container).
    • Added a reBEMer admin tab to configure defaults:
      • Persists rebemer_element_map (sparse overrides) and rebemer_container_mode (role | generic) in slashed_bricks_settings, sanitized to the BEM grammar and exposed on window.slashedBricksEditor for merge at panel open.
    • Updated docs and tests for element type mapping and container mode.
  • Bug Fixes

    • Synced readme.txt Stable tag to 0.3.4 to fix CI drift with package/plugin versions.

Written for commit 98e9f0c. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • New Features

    • Added reBEMer admin tab for configuring default BEM naming conventions
    • Users can override element type labels and customize container naming modes ("smart role names" or "generic")
    • Configuration settings persist and apply automatically across the editor
  • Tests

    • Expanded test coverage for element naming utilities and container mode behavior

Reduce how often the reBEMer panel pre-fills weak defaults ("item",
"content") that the user has to retype.

- Expand ELEMENT_TYPE_LABEL_MAP and SOLE_CHILD_LABEL_OVERRIDES to cover
  many more Bricks element types (divider, social-icons, post-*,
  progress-bar, breadcrumbs, etc.) so far fewer rows fall to "item".
- Add a version-tolerant getElementTypeLabel() seam in bricks-api that
  reads Bricks' element registry; BemPanel uses the slugified human label
  as a smarter fallback than "item" for unmapped, non-container types.
  Containers still go through child-aware role inference so we never emit
  block__container.
- Add an admin "reBEMer" tab that persists a sparse element-type -> BEM
  name override map (rebemer_element_map) and a container-naming mode
  (rebemer_container_mode: role | generic). Stored in
  slashed_bricks_settings, sanitized against the same BEM grammar as
  validate.js, localized onto window.slashedBricksEditor, and merged over
  the frozen built-in map at panel-open time.

Extends tests/element-types.test.js and updates docs/rebemer.md. Rebuilt
editor-app and admin-app bundles.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HtPN4CvQjMTdvPLALAW3GE
@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a new "reBEMer" configuration feature end-to-end: two new plugin settings (rebemer_element_map, rebemer_container_mode) are stored with defaults, validated/sanitized via REST API, and localized to the editor JS. The editor's element-type naming helpers are extended with more type entries, user override merging, and a container-naming mode parameter. A new admin Svelte tab provides the UI for managing these settings. Tests and docs are updated accordingly.

Changes

reBEMer Configurable Defaults

Layer / File(s) Summary
Backend defaults and tab registration
SLASHED-for-WP/includes/class-token-store.php, SLASHED-for-WP/includes/class-tab-registry.php
PLUGIN_SETTING_DEFAULTS gains rebemer_element_map (empty array) and rebemer_container_mode ('role'); get_view_tabs() gains the rebemerreBEMer slug/label entry.
REST API contract, save, and sanitization
SLASHED-for-WP/includes/class-rest-controller.php
/settings route schema gains rebemer_element_map (object) and rebemer_container_mode (role/generic); save_settings() reads, sanitizes, and persists both; new sanitize_rebemer_element_map() enforces entry cap, BEM grammar regex, and reserved-name blacklist; import_tokens() applies the same sanitization on import.
PHP → JS localization bridge
SLASHED-for-WP/integrations/bricks/includes/class-editor-data.php
localize() conditionally adds rebemerElementMap (array-to-object) and rebemerContainerMode (defaulting to 'role') to the slashedBricksEditor script payload.
Element-type map expansions and runtime override helpers
SLASHED-for-WP/integrations/bricks/editor-app/src/lib/element-types.js, SLASHED-for-WP/integrations/bricks/editor-app/src/lib/bricks-api.js
ELEMENT_TYPE_LABEL_MAP and SOLE_CHILD_LABEL_OVERRIDES gain many new entries; new exports getUserElementMap(), mergedElementTypeMap(), getContainerMode() read from window.slashedBricksEditor; suggestElementName() uses merged map; suggestContainerName() gains a mode parameter; bricks-api.js adds getElementTypeLabel() with multi-source Bricks registry probing.
BemPanel editor integration
SLASHED-for-WP/integrations/bricks/editor-app/src/components/BemPanel.svelte
Imports getContainerMode; Pass 1 name seeding becomes a 3-stage resolution (type-map → getElementTypeLabel slug → 'item' fallback); Pass 2 reads containerMode and passes it to suggestContainerName().
Admin RebemerTab component and App wiring
SLASHED-for-WP/integrations/bricks/admin-app/src/App.svelte, SLASHED-for-WP/integrations/bricks/admin-app/src/components/RebemerTab.svelte, SLASHED-for-WP/integrations/bricks/assets/admin-app/app.css
New RebemerTab.svelte with state management, BEM validation, save/reset handlers, and full UI (container-mode select, per-type name table, footer with status); wired into App.svelte as a read-only tab; CSS bundle updated with rebemer-tab__* styles.
Tests and documentation
tests/element-types.test.js, docs/rebemer.md
Tests cover suggestContainerName modes, new type mappings, SOLE_CHILD_LABEL_OVERRIDES, mergedElementTypeMap override isolation, and getContainerMode defaults; docs expand element-type seeding order and configurable-defaults description.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • codeslash-dev/SLASHED-Plugins#27: Modifies the same save_settings() handler and REST /settings schema in class-rest-controller.php to persist additional plugin-setting fields (manual_css_mode/configurator_url), following the identical extension pattern used here for the reBEMer fields.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: smarter default BEM naming through expanded element coverage and a new feature for configurable admin-level type mapping.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/rebemer-default-bem-names-agzxk7

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 14 files

Re-trigger cubic

readme.txt's Stable tag was left at 0.3.1 while package.json and the
plugin headers are already at 0.3.4, tripping the verify-sync drift
check in tests/sync.test.js. Pre-existing drift on main, surfaced here
because CI runs the check on every PR. Fix is `npm run version-sync`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HtPN4CvQjMTdvPLALAW3GE
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.

2 participants