Skip to content

Commit 933132b

Browse files
committed
lint
1 parent 14c1cd3 commit 933132b

File tree

3 files changed

+58
-30
lines changed

3 files changed

+58
-30
lines changed

packages/core/src/components/BlockManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export class BlocksManager {
173173
* without additional storing inputs in the caret adapter
174174
* Thus, it won't care about block index change (block removed, block added, block moved)
175175
*/
176-
this.#caretAdapter.attachBlock(blockToolAdapter, index);
176+
this.#caretAdapter.attachBlock(blockToolAdapter);
177177

178178
const tool = this.#toolsManager.blockTools.get(data.name);
179179

packages/dom-adapters/src/BlockToolAdapter/index.ts

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import {
1111
type ModelEvents,
1212
TextAddedEvent,
1313
TextRemovedEvent,
14-
Index
14+
type Index
1515
} from '@editorjs/model';
1616
import type {
1717
EventBus,
1818
BlockToolAdapter as BlockToolAdapterInterface,
1919
CoreConfig,
2020
BeforeInputUIEvent,
21-
BeforeInputUIEventPayload,
21+
BeforeInputUIEventPayload
2222
} from '@editorjs/sdk';
2323
import { BeforeInputUIEventName } from '@editorjs/sdk';
2424
import type { CaretAdapter } from '../CaretAdapter/index.js';
@@ -306,6 +306,7 @@ export class BlockToolAdapter implements BlockToolAdapterInterface {
306306
*/
307307
if (start !== end) {
308308
this.#model.removeText(this.#config.userId, this.#blockIndex, key, start, end);
309+
309310
return;
310311
}
311312

@@ -359,18 +360,42 @@ export class BlockToolAdapter implements BlockToolAdapterInterface {
359360
this.#model.removeText(this.#config.userId, this.#blockIndex, key, start, end);
360361
}
361362

363+
/**
364+
* True if input contains only the start of the cross-input selection
365+
*
366+
* @param input - input element
367+
* @param range - selection range
368+
*/
362369
#isInputContainsOnlyStartOfSelection(input: HTMLElement, range: StaticRange): boolean {
363370
return input.contains(range.startContainer) && !input.contains(range.endContainer);
364371
}
365372

373+
/**
374+
* True if input contains only the end of the cross-input selection
375+
*
376+
* @param input - input element
377+
* @param range - selection range
378+
*/
366379
#isInputContainsOnlyEndOfSelection(input: HTMLElement, range: StaticRange): boolean {
367380
return input.contains(range.endContainer) && !input.contains(range.startContainer);
368381
}
369382

383+
/**
384+
* True if input contains the whole selection (not cross-input)
385+
*
386+
* @param input - input element
387+
* @param range - selection range
388+
*/
370389
#isInputContainsWholeSelection(input: HTMLElement, range: StaticRange): boolean {
371390
return input.contains(range.startContainer) && input.contains(range.endContainer);
372391
}
373392

393+
/**
394+
* True if input is in between cross-input selection
395+
*
396+
* @param input - input element
397+
* @param range - selection range
398+
*/
374399
#isInputInBetweenSelection(input: HTMLElement, range: StaticRange): boolean {
375400
return !this.#isInputContainsWholeSelection(input, range) &&
376401
!this.#isInputContainsOnlyStartOfSelection(input, range) &&
@@ -397,22 +422,15 @@ export class BlockToolAdapter implements BlockToolAdapterInterface {
397422
let end: number;
398423
let newCaretIndex: number | null = null;
399424

400-
// console.log('delete in input', input);
401-
402425
/**
403426
* If range is fully contained within this input
404427
*/
405428
if (this.#isInputContainsWholeSelection(input, range)) {
406-
// console.log('range is fully contained within this input');
407-
408429
start = getAbsoluteRangeOffset(input, range.startContainer, range.startOffset);
409430
end = getAbsoluteRangeOffset(input, range.endContainer, range.endOffset);
410431

411432
this.#model.removeText(this.#config.userId, this.#blockIndex, key, start, end);
412-
413-
// newCaretIndex = start;
414433
} else if (this.#isInputContainsOnlyStartOfSelection(input, range)) {
415-
// console.log('only start is in this input');
416434
/**
417435
* If only start is in this input, delete from start to end of input
418436
*/
@@ -425,20 +443,18 @@ export class BlockToolAdapter implements BlockToolAdapterInterface {
425443
newCaretIndex = start;
426444
}
427445
} else if (this.#isInputContainsOnlyEndOfSelection(input, range)) {
428-
// console.log('only end is in this input');
429446
/**
430447
* If only end is in this input, delete from start of input to end
431-
*/
432-
start = 0;
433-
end = getAbsoluteRangeOffset(input, range.endContainer, range.endOffset);
448+
*/
449+
start = 0;
450+
end = getAbsoluteRangeOffset(input, range.endContainer, range.endOffset);
434451

452+
const removedText = this.#model.removeText(this.#config.userId, this.#blockIndex, key, start, end);
435453

436-
const removedText = this.#model.removeText(this.#config.userId, this.#blockIndex, key, start, end);
437-
if (isRestoreCaretToTheEnd) {
438-
newCaretIndex = end - removedText.length;
439-
}
454+
if (isRestoreCaretToTheEnd) {
455+
newCaretIndex = end - removedText.length;
456+
}
440457
} else if (this.#isInputInBetweenSelection(input, range)) {
441-
// console.log('range spans across this input');
442458
/**
443459
* If range spans across this input, delete everything
444460
*/
@@ -448,7 +464,6 @@ export class BlockToolAdapter implements BlockToolAdapterInterface {
448464
}
449465

450466
if (newCaretIndex !== null) {
451-
console.info('restore caret: block %o index %o caret %o', this.#blockIndex, newCaretIndex);
452467
this.#caretAdapter.updateIndex(
453468
new IndexBuilder()
454469
.addBlockIndex(this.#blockIndex)
@@ -544,7 +559,7 @@ export class BlockToolAdapter implements BlockToolAdapterInterface {
544559
(this.#isInputContainsOnlyStartOfSelection(input, range) || this.#isInputContainsWholeSelection(input, range)) &&
545560
!payload.isCrossInputSelection
546561
) {
547-
const start = isInputNative ?
562+
start = isInputNative ?
548563
(input as HTMLInputElement | HTMLTextAreaElement).selectionStart as number :
549564
getAbsoluteRangeOffset(input, range.startContainer, range.startOffset);
550565

@@ -783,6 +798,8 @@ export class BlockToolAdapter implements BlockToolAdapterInterface {
783798

784799
/**
785800
* Allows access to a particular input by key
801+
*
802+
* @param key - data key of the input
786803
*/
787804
public getInput(key: DataKey): HTMLElement | undefined {
788805
return this.#attachedInputs.get(key);

packages/dom-adapters/src/CaretAdapter/index.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { isNativeInput } from '@editorjs/dom';
2+
import type {
3+
ModelEvents } from '@editorjs/model';
24
import {
35
BlockRemovedEvent,
46
type Caret,
@@ -7,7 +9,6 @@ import {
79
EventType,
810
Index,
911
IndexBuilder,
10-
ModelEvents,
1112
type TextRange,
1213
createDataKey
1314
} from '@editorjs/model';
@@ -90,9 +91,8 @@ export class CaretAdapter extends EventTarget {
9091
* Adds block to the caret adapter
9192
*
9293
* @param block - block tool adapter
93-
* @param index - index of the block in the model tree
9494
*/
95-
public attachBlock(block: BlockToolAdapter, index: Index): void {
95+
public attachBlock(block: BlockToolAdapter): void {
9696
this.#blocks.push(block);
9797
}
9898

@@ -103,10 +103,12 @@ export class CaretAdapter extends EventTarget {
103103
*/
104104
public detachBlock(index: Index): void {
105105
const block = this.getBlock(index);
106+
106107
if (block) {
107-
const index = this.#blocks.indexOf(block);
108-
if (index !== -1) {
109-
this.#blocks.splice(index, 1);
108+
const blockIndex = this.#blocks.indexOf(block);
109+
110+
if (blockIndex !== -1) {
111+
this.#blocks.splice(blockIndex, 1);
110112
}
111113
}
112114
}
@@ -148,6 +150,7 @@ export class CaretAdapter extends EventTarget {
148150
}
149151

150152
const blockIndex = index.blockIndex;
153+
151154
if (blockIndex === undefined) {
152155
return undefined;
153156
}
@@ -159,11 +162,12 @@ export class CaretAdapter extends EventTarget {
159162
* Finds input by block index and data key
160163
*
161164
* @param blockIndex - index of the block
162-
* @param dataKey - data key of the input
165+
* @param dataKeyRaw - data key of the input
163166
* @returns input element or undefined if not found
164167
*/
165168
public findInput(blockIndex: number, dataKeyRaw: string): HTMLElement | undefined {
166169
const builder = new IndexBuilder();
170+
167171
builder.addBlockIndex(blockIndex);
168172
const block = this.getBlock(builder.build());
169173

@@ -172,6 +176,7 @@ export class CaretAdapter extends EventTarget {
172176
}
173177

174178
const dataKey = createDataKey(dataKeyRaw);
179+
175180
return block.getInput(dataKey);
176181
}
177182

@@ -208,7 +213,10 @@ export class CaretAdapter extends EventTarget {
208213

209214
const builder = new IndexBuilder();
210215

211-
builder.from(block.getBlockIndex()).addDataKey(key).addTextRange(textRange);
216+
builder
217+
.from(block.getBlockIndex())
218+
.addDataKey(key)
219+
.addTextRange(textRange);
212220

213221
this.updateIndex(builder.build());
214222

@@ -230,7 +238,10 @@ export class CaretAdapter extends EventTarget {
230238

231239
const builder = new IndexBuilder();
232240

233-
builder.from(block.getBlockIndex()).addDataKey(key).addTextRange(textRange);
241+
builder
242+
.from(block.getBlockIndex())
243+
.addDataKey(key)
244+
.addTextRange(textRange);
234245

235246
this.updateIndex(builder.build());
236247

0 commit comments

Comments
 (0)