Skip to content

"Model" API#142

Open
gohabereg wants to merge 2 commits into
mainfrom
feature/model-api
Open

"Model" API#142
gohabereg wants to merge 2 commits into
mainfrom
feature/model-api

Conversation

@gohabereg
Copy link
Copy Markdown
Member

  • Added some API methods to be able to update the model
  • Removed model dependency from AdapterPlugin & DOMAdapters

In a separate PR need to update CollaborationManager to use API as well instead of the model directly

A question for discussion
Each method would require an optional userId parameter for collaboration manager (as it will be dispatching updates from remove users). Maybe we'd like to have parameters as an object to reduce the number of them?

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 13, 2026

⏭️ No files to mutate for ./packages/model

@gohabereg
Copy link
Copy Markdown
Member Author

As a todo, would be good to implement some safeguards for the parameters

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 13, 2026

Coverage report for ./packages/dom-adapters

St.
Category Percentage Covered / Total
🟢 Statements 96.43% 27/28
🟢 Branches 86.96% 20/23
🟢 Functions 100% 5/5
🟢 Lines 96.43% 27/28

Test suite run success

11 tests passing in 2 suites.

Report generated by 🧪jest coverage report action from 3c6f106

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 13, 2026

Coverage report for ./packages/model

St.
Category Percentage Covered / Total
🟢 Statements 99.8% 988/990
🟢 Branches 98.98% 292/295
🟢 Functions 97.45% 229/235
🟢 Lines 99.79% 948/950

Test suite run success

538 tests passing in 25 suites.

Report generated by 🧪jest coverage report action from 3c6f106

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 13, 2026

Coverage report for ./packages/core

St.
Category Percentage Covered / Total
🟢 Statements
90.41% (-9.59% 🔻)
132/146
🟢 Branches
95.92% (-4.08% 🔻)
47/49
🟡 Functions
69.23% (-30.77% 🔻)
27/39
🟢 Lines
89.78% (-10.22% 🔻)
123/137
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟡 api/BlocksAPI.ts 70% 100% 57.14% 68.42%
🔴 api/SelectionAPI.ts 54.55% 0% 33.33% 50%
🔴
... / DocumentAPI.ts
57.14% 100% 50% 50%

Test suite run success

75 tests passing in 7 suites.

Report generated by 🧪jest coverage report action from 3c6f106

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 13, 2026

⏭️ No files to mutate for ./packages/core

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 13, 2026

Coverage report for ./packages/ot-server

St.
Category Percentage Covered / Total
🟡 Statements 70.97% 22/31
🔴 Branches 20% 1/5
🟡 Functions 75% 6/8
🟡 Lines 68.97% 20/29

Test suite run success

4 tests passing in 1 suite.

Report generated by 🧪jest coverage report action from 3c6f106

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 13, 2026

Coverage report for ./packages/collaboration-manager

St.
Category Percentage Covered / Total
🟢 Statements 92.51% 358/387
🟢 Branches 85.51% 118/138
🟢 Functions 98.15% 53/54
🟢 Lines 92.41% 353/382

Test suite run success

117 tests passing in 7 suites.

Report generated by 🧪jest coverage report action from 3c6f106

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the model interaction layer to introduce a richer Editor API surface (Text/Document/Selection/Blocks). Adapters and DOM adapter plugins now consume the API instead of the raw EditorJSModel, decoupling plugins from the model. Also renames internal model events to use namespaced model:* strings and removes the now-unused EditorjsAdapterPluginParams/Params generics.

Changes:

  • New TextAPI and additional methods on BlocksAPI/SelectionAPI/DocumentAPI (interface + core implementation), wired through inversify with a new TOKENS.EditorAPI.
  • Adapters (BlockToolAdapter, DOMBlockToolAdapter, FormattingAdapter, CaretAdapter, InputsRegistry) migrated from EditorJSModel to EditorAPI; DataKey usages relaxed to string at the adapter boundary.
  • Model: EventType values prefixed with model:; EditorJSModel.getDataNode drops _userId/@WithContext and adds a generic; BlockNode/EditorDocument.getDataNode made generic.

Reviewed changes

Copilot reviewed 30 out of 30 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/sdk/src/api/EditorAPI.ts Adds text to the EditorAPI surface.
packages/sdk/src/api/TextAPI.ts New TextAPI interface (insert/remove/format/unformat/getFragments/get).
packages/sdk/src/api/SelectionAPI.ts Adds onCaretUpdate, createCaret, getCaret.
packages/sdk/src/api/DocumentAPI.ts Adds onUpdate listener registration.
packages/sdk/src/api/BlocksAPI.ts Widens delete to id, adds id↔index helpers and data CRUD.
packages/sdk/src/api/index.ts Exports TextAPI types.
packages/sdk/src/entities/EditorjsPlugin.ts Removes Params generic from constructor.
packages/sdk/src/entities/EditorjsAdapterPlugin.ts Removes adapter-specific params type with model.
packages/sdk/src/entities/BlockToolAdapter.ts Switches base adapter from model to EditorAPI; relaxes keys to string.
packages/model/src/EventBus/types/EventType.ts Renames event values to model:*.
packages/model/src/EditorJSModel.ts Drops _userId from getDataNode, adds generic.
packages/model/src/entities/EditorDocument/index.ts Generic propagated to getDataNode.
packages/model/src/entities/BlockNode/index.ts Generic propagated to getDataNode.
packages/dom-adapters/src/tokens.ts Adds EditorAPI DI token.
packages/dom-adapters/src/index.ts Binds API into the IoC container instead of the model.
packages/dom-adapters/src/InputsRegistry/index.ts Maps now keyed by raw string data keys.
packages/dom-adapters/src/CaretAdapter/index.ts Uses EditorAPI for caret/index lookups.
packages/dom-adapters/src/FormattingAdapter/index.ts Uses EditorAPI for fragments and updates.
packages/dom-adapters/src/BlockToolAdapter/index.ts Uses EditorAPI for text/blocks operations; key type widened.
packages/core/src/api/index.ts Wires TextAPI into EditorAPI.
packages/core/src/api/TextAPI.ts Concrete TextAPI implementation delegating to model.
packages/core/src/api/SelectionAPI.ts Adds caret/onCaretUpdate; pulls in model+config.
packages/core/src/api/DocumentAPI/DocumentAPI.ts Adds onUpdate.
packages/core/src/api/BlocksAPI.ts Adds id/index/data helpers backed by model.
packages/core/src/index.ts Stops passing model to adapter plugins.
packages/core/src/api/*.spec.ts, BlocksAPI.integration.spec.ts Updates constructor signatures and mocks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +309 to 311
public getDataNode<V = unknown>(...parameters: Parameters<EditorDocument['getDataNode']>): ReturnType<EditorDocument['getDataNode']> {
return this.#document.getDataNode<V>(...parameters);
}
Comment on lines +54 to +56
* @param indexOrId - index or id of a block to delete
*/
delete(index?: number): void;
delete(indexOrId?: number | string): void;
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 13, 2026

⏭️ No files to mutate for ./packages/dom-adapters

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