"Model" API#142
Conversation
|
⏭️ No files to mutate for |
|
As a todo, would be good to implement some safeguards for the parameters |
Coverage report for
|
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
Coverage report for
|
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
Coverage report for
|
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
|
⏭️ No files to mutate for |
Coverage report for
|
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
Coverage report for
|
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
There was a problem hiding this comment.
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
TextAPIand additional methods onBlocksAPI/SelectionAPI/DocumentAPI(interface + core implementation), wired through inversify with a newTOKENS.EditorAPI. - Adapters (
BlockToolAdapter,DOMBlockToolAdapter,FormattingAdapter,CaretAdapter,InputsRegistry) migrated fromEditorJSModeltoEditorAPI;DataKeyusages relaxed tostringat the adapter boundary. - Model:
EventTypevalues prefixed withmodel:;EditorJSModel.getDataNodedrops_userId/@WithContextand adds a generic;BlockNode/EditorDocument.getDataNodemade 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.
| public getDataNode<V = unknown>(...parameters: Parameters<EditorDocument['getDataNode']>): ReturnType<EditorDocument['getDataNode']> { | ||
| return this.#document.getDataNode<V>(...parameters); | ||
| } |
| * @param indexOrId - index or id of a block to delete | ||
| */ | ||
| delete(index?: number): void; | ||
| delete(indexOrId?: number | string): void; |
|
⏭️ No files to mutate for |
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
userIdparameter 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?