Skip to content

Make CollaborationManager a Plugin#144

Open
gohabereg wants to merge 4 commits into
feature/api-user-idfrom
feautre/collaboration-plugin
Open

Make CollaborationManager a Plugin#144
gohabereg wants to merge 4 commits into
feature/api-user-idfrom
feautre/collaboration-plugin

Conversation

@gohabereg
Copy link
Copy Markdown
Member

No description provided.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 19, 2026

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

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 19, 2026

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

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 19, 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 11fbc61

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 19, 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 11fbc61

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 19, 2026

Coverage report for ./packages/core

St.
Category Percentage Covered / Total
🟢 Statements
88.67% (-3.42% 🔻)
133/150
🟢 Branches
87.69% (-4.24% 🔻)
57/65
🟡 Functions
64.29% (-7.14% 🔻)
27/42
🟢 Lines
87.94% (-3.66% 🔻)
124/141
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🔴
... / DocumentAPI.ts
45.45% 0% 28.57% 40%

Test suite run success

75 tests passing in 7 suites.

Report generated by 🧪jest coverage report action from 11fbc61

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 19, 2026

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

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 19, 2026

Coverage report for ./packages/ot-server

St.
Category Percentage Covered / Total
🟡 Statements
70.97% (-29.03% 🔻)
22/31
🔴 Branches
20% (-80% 🔻)
1/5
🔴 Functions
50% (-50% 🔻)
6/12
🟡 Lines
68.97% (-31.03% 🔻)
20/29
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / codex-tooltip.ts
100% 100% 0% 100%
🟡
... / DocumentManager.ts
70.97% 20% 75% 68.97%

Test suite run success

4 tests passing in 1 suite.

Report generated by 🧪jest coverage report action from 11fbc61

@gohabereg gohabereg requested a review from Copilot May 19, 2026 17:35
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 19, 2026

Coverage report for ./packages/collaboration-manager

St.
Category Percentage Covered / Total
🟢 Statements
92.27% (-0.23% 🔻)
394/427
🟢 Branches 85.51% 118/138
🟢 Functions
88.16% (-9.99% 🔻)
67/76
🟢 Lines
92.11% (-0.3% 🔻)
385/418
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / codex-tooltip.ts
100% 100% 0% 100%
🟢
... / createManager.ts
92.31% 100% 88.89% 91.67%
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / CollaborationManager.ts
88.99% (-1.6% 🔻)
83.33%
73.33% (-15.56% 🔻)
88.57% (-1.9% 🔻)

Test suite run success

127 tests passing in 7 suites.

Report generated by 🧪jest coverage report action from 11fbc61

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

This PR converts CollaborationManager from a directly-instantiated dependency of Core into a regular Editor.js plugin that consumes the public EditorAPI, decoupling it from the model. It also adds three new write methods (insertData, removeData, modifyData) to the DocumentAPI so the plugin can mutate the document through the public API, and introduces a new core:ready event that triggers the OT-server connection.

Changes:

  • Make CollaborationManager a PluginType.Plugin that receives { api, config, eventBus }, listens to core:undo/redo/ready, applies operations via DocumentAPI, and renders incoming snapshots via blocks.render.
  • Extend DocumentAPI (sdk + core impl) with insertData/removeData/modifyData taking { userId, index, data }, defaulting userId to the editor config; add CoreEventType.Ready dispatched at the end of Core.initialize.
  • Rework collaboration-manager and ot-server tests around the new plugin shape: new createManager helper, refactored OTClient.spec.ts that drives the client directly, and a shared codex-tooltip mock for jsdom-free Jest envs.

Reviewed changes

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

Show a summary per file
File Description
packages/sdk/src/entities/EventBus/events/core/CoreEventType.ts Adds new Ready core event type.
packages/sdk/src/api/DocumentAPI.ts Adds InsertRemoveDataParams/ModifyDataParams and the three write methods to the DocumentAPI interface.
packages/core/src/index.ts Registers CollaborationManager via use(), removes direct wiring/undo-redo listeners, and dispatches CoreEventType.Ready after model init. Fixes a typo in the class comment.
packages/core/src/api/DocumentAPI/DocumentAPI.ts Implements new write methods using the model and injects editor config for default userId.
packages/core/src/api/DocumentAPI/DocumentAPI.spec.ts Updates constructor call to pass a mocked config.
packages/collaboration-manager/src/CollaborationManager.ts Implements EditorjsPlugin, switches from EditorJSModel to EditorAPI, hooks undo/redo/ready via eventBus, adds destroy().
packages/collaboration-manager/src/CollaborationManager.spec.ts Replaces direct constructor calls with the new createManager helper.
packages/collaboration-manager/src/client/OTClient.spec.ts Rewrites tests to exercise OTClient directly instead of through CollaborationManager.
packages/collaboration-manager/test/mocks/createManager.ts New helper that builds a CollaborationManager with a model-backed DocumentAPI and stub APIs.
packages/collaboration-manager/test/mocks/ws.ts Minor type/style cleanup of the WebSocket mock.
packages/collaboration-manager/test/mocks/codex-tooltip.ts, packages/ot-server/test/mocks/codex-tooltip.ts New minimal codex-tooltip mocks to avoid window is not defined in Node test env.
packages/collaboration-manager/jest.config.ts, packages/ot-server/jest.config.ts Map codex-tooltip to the new mocks.

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

Comment thread packages/core/src/api/DocumentAPI/DocumentAPI.ts Outdated
Comment on lines +332 to +337
/**
* Destroys the plugin instance: clears the debounce timer
*/
public destroy(): void {
clearTimeout(this.#debounceTimer);
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@copilot apply the suggested change

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Implemented in 6c10274. destroy() now unsubscribes document/core listeners and closes the OT client connection; I also added lifecycle tests (including websocket close coverage).

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

3 participants