Skip to content

Implement block conversion — export side and convert API#148

Open
Reversean wants to merge 2 commits into
mainfrom
feature/blocks-convert
Open

Implement block conversion — export side and convert API#148
Reversean wants to merge 2 commits into
mainfrom
feature/blocks-convert

Conversation

@Reversean
Copy link
Copy Markdown

@Reversean Reversean commented May 24, 2026

Summary

  • Add exportTextContent() to BlockToolFacade. Supports a function, a string keypath, or a dot-notation keypath via conversionConfig.export.
  • Add convertBlock() to BlocksManager: exports text from the source block using its conversion config, imports it into the target tool type, and replaces the block at the same index.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 24, 2026

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

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 24, 2026

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

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 24, 2026

Coverage report for ./packages/model

St.
Category Percentage Covered / Total
🟢 Statements 99.71% 1044/1047
🟢 Branches 98.44% 315/320
🟢 Functions 98.39% 244/248
🟢 Lines 99.7% 1002/1005

Test suite run success

563 tests passing in 26 suites.

Report generated by 🧪jest coverage report action from 161783c

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 24, 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 161783c

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 24, 2026

Coverage report for ./packages/core

St.
Category Percentage Covered / Total
🟢 Statements
93.65% (-1.6% 🔻)
295/315
🟢 Branches
89.34% (-0.85% 🔻)
109/122
🟡 Functions
75% (-5.43% 🔻)
48/64
🟢 Lines
93.29% (-1.69% 🔻)
278/298
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟡 api/BlocksAPI.ts 68.18% 71.43% 56.25% 66.67%

Test suite run success

149 tests passing in 8 suites.

Report generated by 🧪jest coverage report action from 161783c

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 24, 2026

Coverage report for ./packages/collaboration-manager

St.
Category Percentage Covered / Total
🟢 Statements 91.88% 396/431
🟢 Branches 85.82% 121/141
🟢 Functions 88.16% 67/76
🟢 Lines 91.71% 387/422

Test suite run success

130 tests passing in 7 suites.

Report generated by 🧪jest coverage report action from 161783c

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 24, 2026

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

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 24, 2026

Coverage report for ./packages/ot-server

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

Test suite run success

4 tests passing in 1 suite.

Report generated by 🧪jest coverage report action from 161783c

@Reversean Reversean force-pushed the feature/blocks-convert branch from fc906c1 to 630d328 Compare May 24, 2026 12:33
Comment thread packages/core/src/api/BlocksAPI.ts Outdated
id: string,
newType: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
dataOverrides?: BlockToolData
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.

Better to leave a to-do if you're not going to implement it in this PR

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Now we're using this parameters to override data.

Comment thread packages/core/src/api/BlocksAPI.ts Outdated
* @param dataOverrides - optional data overrides for the new block @todo implement
*/
public convert(
id: string,
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 use id or index

Also, it would be more scalable to use a single object with parameters and add an optional useId property (see my PR that adds user ID to API methods)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Please use id or index

Done, now we accepting both

Also, it would be more scalable to use a single object with parameters and add an optional useId property (see my PR that adds user ID to API methods)

Good advise, done.

@Reversean Reversean force-pushed the feature/blocks-convert branch from b21e9e7 to 7901a5e Compare May 25, 2026 05:47
Base automatically changed from feature/blocks-split to main May 26, 2026 17:34
@Reversean Reversean force-pushed the feature/blocks-convert branch 2 times, most recently from fcb9202 to 7353118 Compare May 27, 2026 15:55
}));
});

it('exports text from source, imports into target, and replaces block at the same index', () => {
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.

it is a good practice to name a test case starting with "should ...", so the full test will be in a declarative way ("it should ...")

Suggested change
it('exports text from source, imports into target, and replaces block at the same index', () => {
it('should export text from source, imports into target, and replaces block at the same index', () => {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done.

Comment on lines +344 to +345
const targetTool = { importTextContent: jest.fn(() => ({ text: { value: 'Hello',
fragments: [] } })) };
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.

bad line breaks, please format objects in a way where each object property stays on the separate line:

{
  text: {
    value: 'Hello',
    fragments: []
  }
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed.

Comment on lines +360 to +362
{ name: 'paragraph',
data: { text: { value: 'Hello',
fragments: [] } } },
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.

bad formatting

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed.

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

Adds the export side of the block conversion pipeline and a public convert API. BlockToolFacade.exportTextContent() serializes block data to plain text via conversionConfig.export (function or keypath), and BlocksManager.convertBlock() uses it together with the previously added importTextContent() to replace a block in place with a new tool type.

Changes:

  • Add exportTextContent() to BlockToolFacade supporting function and keypath export configs.
  • Add convertBlock() to BlocksManager (remove + re-add at same index, optional dataOverrides/userId).
  • Expose it via BlocksAPI.convert({ block, newType, dataOverrides?, userId? }) and update the interface signature.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/sdk/src/tools/facades/BlockToolFacade.ts Implements exportTextContent() using conversionConfig.export.
packages/sdk/src/tools/facades/BaseToolFacade.spec.ts Unit tests for the three export variants (missing/function/keypath).
packages/sdk/src/api/BlocksAPI.ts Replaces commented convert signature with object-param public API.
packages/core/src/components/BlockManager.ts Implements convertBlock() (export → import → replace).
packages/core/src/components/BlockManager.spec.ts Tests for happy path, overrides, and missing export/import configs.
packages/core/src/api/BlocksAPI.ts Wires convert() to BlocksManager.convertBlock().

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

Comment on lines +381 to +382
const text = sourceTool.exportTextContent(block.data);
const newData = targetTool.importTextContent(text, []);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done.

Comment on lines +378 to +379
const sourceTool = this.#toolsManager.blockTools.get(block.name)!;
const targetTool = this.#toolsManager.blockTools.get(newType)!;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done.

Comment on lines +383 to +386
const finalData = dataOverrides !== undefined
? { ...newData,
...dataOverrides }
: newData;
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added doc for all parameter entry along all convertBlock() pipeline.

Reversean added 2 commits June 1, 2026 17:52
Add exportTextContent() to BlockToolFacade: supports function, string keypath, and dot-notation keypath via conversionConfig.export.

Add convertBlock() to BlocksManager: exports text from the source block,
imports it into the target type, and replaces the block at the same index.
@Reversean Reversean force-pushed the feature/blocks-convert branch from 7353118 to 161783c Compare June 1, 2026 16:20
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.

4 participants