Skip to content

Commit 33f2dc0

Browse files
authored
Fix inputs and values attachments to be data-first (#127)
* Fix inputs and values attachments to be data-first * Load adapters as plugin * Fix tests * Review comments * (try to) fix test run for core package * Run base branch coverage manually * Fix unit-tests action: use ArtiomTr with pre-generated coverage files * Try just PR branch tests * Try clear before build * Try no cache * Use latest node * Review comments resolved * Resolve review comments * Add destoryBlockToolAdapter method to Adapter plugin
1 parent fd54f16 commit 33f2dc0

53 files changed

Lines changed: 2461 additions & 1382 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v20.9.0
1+
v24.15.0

packages/core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"@editorjs/helpers": "^1.2.1",
4747
"@editorjs/model": "workspace:^",
4848
"@editorjs/sdk": "workspace:^",
49-
"reflect-metadata": "^0.2.2",
50-
"typedi": "^0.10.0"
49+
"inversify": "^8.1.0",
50+
"reflect-metadata": "^0.2.2"
5151
}
5252
}

packages/core/src/api/BlocksAPI.integration.spec.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ jest.unstable_mockModule('../tools/ToolsManager', () => ({
5151
// Import real model (no mock) and mocked adapters
5252
const { EditorJSModel, EventType, BlockAddedEvent, BlockRemovedEvent } = await import('@editorjs/model');
5353
const { EventBus } = await import('@editorjs/sdk');
54-
const { CaretAdapter, FormattingAdapter } = await import('@editorjs/dom-adapters');
5554
const ToolsManager = (await import('../tools/ToolsManager')).default;
5655
const { BlocksManager } = await import('../components/BlockManager.js');
5756
const { BlocksAPI } = await import('./BlocksAPI.js');
@@ -73,19 +72,13 @@ describe('BlocksAPI integration (real model, mocked DOM adapters)', () => {
7372
model = new EditorJSModel(USER_ID, { identifier: DOCUMENT_ID });
7473
eventBus = new EventBus();
7574

76-
// @ts-expect-error — mock constructor, no real DOM needed
77-
const caretAdapter = new CaretAdapter();
7875
// @ts-expect-error — mock constructor
7976
const toolsManager = new ToolsManager();
80-
// @ts-expect-error — mock constructor
81-
const formattingAdapter = new FormattingAdapter();
8277

8378
blocksManager = new BlocksManager(
8479
model,
8580
eventBus,
86-
caretAdapter,
8781
toolsManager,
88-
formattingAdapter,
8982
config
9083
);
9184

@@ -333,7 +326,7 @@ describe('BlocksAPI integration (real model, mocked DOM adapters)', () => {
333326
expect(handler).toHaveBeenCalledWith(expect.any(BlockAddedEvent));
334327
});
335328

336-
it('should emit BlockRemovedEvent on model when delete is called', () => {
329+
it('should emit BlockRemovedEvent on model when delete is called', async () => {
337330
blocksAPI.insert('paragraph');
338331

339332
const handler = jest.fn();
@@ -342,6 +335,8 @@ describe('BlocksAPI integration (real model, mocked DOM adapters)', () => {
342335

343336
blocksAPI.delete(0);
344337

338+
await Promise.resolve(); // flush queueMicrotask used by removeBlock
339+
345340
expect(handler).toHaveBeenCalledWith(expect.any(BlockRemovedEvent));
346341
});
347342
});

packages/core/src/api/BlocksAPI.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'reflect-metadata';
2-
import { Inject, Service } from 'typedi';
2+
import { inject, injectable } from 'inversify';
3+
import { TOKENS } from '../tokens.js';
34
import { BlocksManager } from '../components/BlockManager.js';
45
import { BlockToolData } from '@editorjs/editorjs';
56
import { CoreConfigValidated } from '@editorjs/sdk';
@@ -10,7 +11,7 @@ import { type BlockNodeSerialized, EditorDocumentSerialized } from '@editorjs/mo
1011
* Blocks API
1112
* - provides methods to work with blocks
1213
*/
13-
@Service()
14+
@injectable()
1415
export class BlocksAPI implements BlocksApiInterface {
1516
/**
1617
* BlocksManager instance to work with blocks
@@ -29,7 +30,7 @@ export class BlocksAPI implements BlocksApiInterface {
2930
*/
3031
constructor(
3132
blocksManager: BlocksManager,
32-
@Inject('EditorConfig') config: CoreConfigValidated
33+
@inject(TOKENS.EditorConfig) config: CoreConfigValidated
3334
) {
3435
this.#blocksManager = blocksManager;
3536
this.#config = config;

packages/core/src/api/DocumentAPI/DocumentAPI.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import 'reflect-metadata';
2-
import { Service } from 'typedi';
32

43
import { type EditorDocumentSerialized, EditorJSModel } from '@editorjs/model';
54
import { DocumentAPI as DocumentApiInterface } from '@editorjs/sdk';
5+
import { injectable } from 'inversify';
66

77
/**
88
* Document API
99
* - provides access to document serialized data
1010
*/
11-
@Service()
11+
@injectable()
1212
export class DocumentAPI implements DocumentApiInterface {
1313
/**
1414
* Editor document model instance

packages/core/src/api/SelectionAPI.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'reflect-metadata';
2-
import { Service } from 'typedi';
2+
import { injectable } from 'inversify';
33

44
import { SelectionManager } from '../components/SelectionManager.js';
55
import { createInlineToolName } from '@editorjs/model';
@@ -10,7 +10,7 @@ import { SelectionAPI as SelectionApiInterface } from '@editorjs/sdk';
1010
* Selection API class
1111
* - provides methods to work with selection
1212
*/
13-
@Service()
13+
@injectable()
1414
export class SelectionAPI implements SelectionApiInterface {
1515
#selectionManager: SelectionManager;
1616

packages/core/src/api/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'reflect-metadata';
2-
import { Inject, Service } from 'typedi';
2+
import { inject, injectable } from 'inversify';
33
import { EditorAPI as EditorApiInterface } from '@editorjs/sdk';
44
import { BlocksAPI } from './BlocksAPI.js';
55
import { SelectionAPI } from './SelectionAPI.js';
@@ -8,23 +8,23 @@ import { DocumentAPI } from './DocumentAPI/index.js';
88
/**
99
* Class gathers all Editor's APIs
1010
*/
11-
@Service()
11+
@injectable()
1212
export class EditorAPI implements EditorApiInterface {
1313
/**
1414
* Blocks API instance to work with blocks
1515
*/
16-
@Inject()
16+
@inject(BlocksAPI)
1717
public blocks!: BlocksAPI;
1818

1919
/**
2020
* Selection API instance to work with selection and inline formatting
2121
*/
22-
@Inject()
22+
@inject(SelectionAPI)
2323
public selection!: SelectionAPI;
2424

2525
/**
2626
* Document API instance to work with document
2727
*/
28-
@Inject()
28+
@inject(DocumentAPI)
2929
public document!: DocumentAPI;
3030
}

0 commit comments

Comments
 (0)