Skip to content

Commit

Permalink
move methods to the document
Browse files Browse the repository at this point in the history
  • Loading branch information
nikmel2803 committed Aug 29, 2024
1 parent 0fe10b8 commit 72c12d1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 21 deletions.
23 changes: 2 additions & 21 deletions packages/model/src/EditorJSModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,7 @@ export class EditorJSModel extends EventBus {
* @param data - data to insert
*/
public insertData(index: Index, data: unknown): void {
switch (true) {
case index.isTextIndex:
this.#document.insertText(index.blockIndex!, index.dataKey!, data as string, index.textRange![0]);
break;

case index.isBlockIndex:
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
this.#document.addBlock(data as Parameters<EditorDocument['addBlock']>[0], index.blockIndex);
default:
throw new Error('Unsupported index');
}
this.#document.insertData(index, data);

Check warning on line 199 in packages/model/src/EditorJSModel.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

/**
Expand All @@ -215,16 +205,7 @@ export class EditorJSModel extends EventBus {
* @param index - index to remove data from
*/
public removeData(index: Index): void {
switch (true) {
case (index.blockIndex !== undefined && index.dataKey !== undefined && index.textRange !== undefined):
this.#document.removeText(index.blockIndex, index.dataKey, index.textRange[0], index.textRange[1]);
break;

case (index.blockIndex !== undefined):
this.#document.removeBlock(index.blockIndex);
default:
throw new Error('Unsupported index');
}
this.#document.removeData(index);

Check warning on line 208 in packages/model/src/EditorJSModel.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

/**
Expand Down
39 changes: 39 additions & 0 deletions packages/model/src/entities/EditorDocument/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from '../../EventBus/events/index.js';
import type { Constructor } from '../../utils/types.js';
import { BaseDocumentEvent } from '../../EventBus/events/BaseEvent.js';
import { Index } from '../Index';

Check failure on line 25 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / lint

All imports in the declaration are only used as types. Use `import type`

Check failure on line 25 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / lint

Missing file extension for "../Index"

/**
* EditorDocument class represents the top-level container for a tree-like structure of BlockNodes in an editor document.
Expand Down Expand Up @@ -323,6 +324,44 @@ export class EditorDocument extends EventBus {
return this.#children[blockIndex].getFragments(dataKey, start, end, tool);
}

/**

Check failure on line 327 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 2 spaces but found 4
* Inserts data to the specified index

Check warning on line 328 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / lint

Expected JSDoc block to be aligned
*
* @param index - index to insert data
* @param data - data to insert
*/
public insertData(index: Index, data: unknown): void {

Check failure on line 333 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 2 spaces but found 4

Check warning on line 333 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
switch (true) {

Check failure on line 334 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 4 spaces but found 6
case index.isTextIndex:

Check failure on line 335 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 6 spaces but found 8
this.insertText(index.blockIndex!, index.dataKey!, data as string, index.textRange![0]);

Check failure on line 336 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 8 spaces but found 10

Check warning on line 336 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
break;

Check failure on line 337 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 8 spaces but found 10

Check warning on line 337 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 337 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

case index.isBlockIndex:

Check failure on line 339 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 6 spaces but found 8
// eslint-disable-next-line @typescript-eslint/no-magic-numbers

Check failure on line 340 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 8 spaces but found 10
this.addBlock(data as Parameters<EditorDocument['addBlock']>[0], index.blockIndex);

Check warning on line 341 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 341 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
default:
throw new Error('Unsupported index');

Check warning on line 343 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 343 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}

Check warning on line 344 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

/**
* Removes data from the specified index
*
* @param index - index to remove data from
*/
public removeData(index: Index): void {

Check warning on line 352 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🕹️ Function is not covered

Warning! Not covered function
switch (true) {
case (index.blockIndex !== undefined && index.dataKey !== undefined && index.textRange !== undefined):

Check warning on line 354 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 354 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

Check warning on line 354 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
this.removeText(index.blockIndex, index.dataKey, index.textRange[0], index.textRange[1]);

Check warning on line 355 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
break;

Check warning on line 356 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 356 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch

case (index.blockIndex !== undefined):
this.removeBlock(index.blockIndex);

Check warning on line 359 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 359 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
default:
throw new Error('Unsupported index');

Check warning on line 361 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement

Check warning on line 361 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🌿 Branch is not covered

Warning! Not covered branch
}

Check warning on line 362 in packages/model/src/entities/EditorDocument/index.ts

View workflow job for this annotation

GitHub Actions / Coverage annotations (🧪 jest-coverage-report-action)

🧾 Statement is not covered

Warning! Not covered statement
}

/**
* Listens to BlockNode events and bubbles them to the EditorDocument
*
Expand Down

0 comments on commit 72c12d1

Please sign in to comment.