Skip to content

feat: add @editorjs/header package#162

Open
Reversean wants to merge 1 commit into
mainfrom
feat/header-api
Open

feat: add @editorjs/header package#162
Reversean wants to merge 1 commit into
mainfrom
feat/header-api

Conversation

@Reversean

@Reversean Reversean commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add packages/tools/header — a new @editorjs/header block tool:

    • Three toolbox entries (H1 / H2 / H3), each with data.level pre-filled
    • Correct event-listener ordering in constructor (addEventListener before registerTextInputKey/registerValueKey so the synchronously-dispatched KeyAddedEvent is never missed)
    • Swaps the heading DOM element on ValueNodeChangedEvent(level) for future Block Tunes integration
    • 36 unit tests covering constructor, render, and all event handlers
  • Fix BlockManager.insert: pass { data, id, name } instead of { ...data, id, name } — the spread silently flattened tool data into top-level BlockNodeInit properties which BlockNode doesn't read, so data.level was always lost

  • Fix ToolboxUI.addTool: use tool.toolbox facade getter (returns normalized ToolboxConfigEntry[]) and iterate with for...of instead of spreading a raw value that may be an array — previously only a single broken entry was added for tools with multi-entry toolboxes

- Add packages/tools/header with Header block tool:
  • three toolbox entries (H1/H2/H3) each carrying their level in data
  • registers text + level keys in the correct order
    (addEventListener before registerTextInputKey/registerValueKey,
     so synchronously-fired KeyAddedEvent is never missed)
  • swaps heading tag on ValueNodeChangedEvent(level)
  • 36 unit tests

- Fix BlockManager.insert: pass { data, id, name } instead of
  { ...data, id, name } so tool data is not silently flattened
  into top-level BlockNodeInit properties

- Fix ToolboxUI.addTool: iterate tool.toolbox (normalized array via
  facade getter) with for…of instead of spreading a raw value that
  may be an array or single object

@gohabereg gohabereg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We have header tool in a separate repo, and there's already a PR for v3 — https://github.com/editor-js/header/pulls

I think it would be better to add it here as a submodule, so the separate repo stays

this.#model.addBlock(userId, {
...data,
data,
id,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please explain the change

@Reversean Reversean Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

BlockNode object created during addBlock execution expects field data, so i thought we shouldn't flatten it here, instead we should provide data object with additional block preferences such as header level.

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