diff --git a/blots/scroll.ts b/blots/scroll.ts index 785f21f699..3ff45598b7 100644 --- a/blots/scroll.ts +++ b/blots/scroll.ts @@ -7,18 +7,17 @@ import { Registry, } from 'parchment'; import { Blot, Parent } from 'parchment/dist/typings/blot/abstract/blot'; -import Delta from 'quill-delta'; import Emitter, { EmitterSource } from '../core/emitter'; import Block, { BlockEmbed } from './block'; import Break from './break'; import Container from './container'; -function isLine(blot: Blot): blot is Block | BlockEmbed { +function isLine(blot: unknown): blot is Block | BlockEmbed { return blot instanceof Block || blot instanceof BlockEmbed; } interface UpdatableEmbed { - updateContent(change: Delta): void; + updateContent(change: unknown): void; } function isUpdatable(blot: Blot): blot is Blot & UpdatableEmbed { @@ -123,12 +122,11 @@ class Scroll extends ScrollBlot { this.optimize(); } - insertBefore(blot, ref) { + insertBefore(blot: Blot, ref?: Blot) { if (blot.statics.scope === Scope.INLINE_BLOT) { - // @ts-expect-error Currently the type is not enforced - const wrapper: Parent = this.scroll.create( + const wrapper = this.scroll.create( this.statics.defaultChild.blotName, - ); + ) as Parent; wrapper.appendChild(blot); super.insertBefore(wrapper, ref); } else { @@ -140,17 +138,14 @@ class Scroll extends ScrollBlot { return this.domNode.getAttribute('contenteditable') === 'true'; } - leaf(index: number): [LeafBlot, number] | [null, -1] { + leaf(index: number): [LeafBlot | null, number] { const last = this.path(index).pop(); if (!last) { return [null, -1]; } const [blot, offset] = last; - if (!(blot instanceof LeafBlot)) { - return [null, -1]; - } - return [blot, offset]; + return blot instanceof LeafBlot ? [blot, offset] : [null, -1]; } line(index: number): [Block | BlockEmbed | null, number] { @@ -194,7 +189,7 @@ class Scroll extends ScrollBlot { } } - path(index) { + path(index: number) { return super.path(index).slice(1); // Exclude self } @@ -202,9 +197,9 @@ class Scroll extends ScrollBlot { // Never remove self } - update(source?: EmitterSource); - update(mutations?: MutationRecord[]); - update(mutations?: MutationRecord[] | EmitterSource) { + update(source?: EmitterSource): void; + update(mutations?: MutationRecord[]): void; + update(mutations?: MutationRecord[] | EmitterSource): void { if (this.batch) { if (Array.isArray(mutations)) { this.batch = this.batch.concat(mutations); @@ -231,7 +226,7 @@ class Scroll extends ScrollBlot { } } - updateEmbedAt(index, key, change) { + updateEmbedAt(index: number, key: string, change: unknown) { // Currently it only supports top-level embeds (BlockEmbed). // We can update `ParentBlot` in parchment to support inline embeds. const [blot] = this.descendant(b => b instanceof BlockEmbed, index); diff --git a/core/quill.ts b/core/quill.ts index 493eb57755..4807d474fc 100644 --- a/core/quill.ts +++ b/core/quill.ts @@ -161,10 +161,10 @@ class Quill { this.root.classList.add('ql-blank'); this.scrollingContainer = this.options.scrollingContainer || this.root; this.emitter = new Emitter(); - // @ts-expect-error - const ScrollBlot: ScrollConstructor = this.options.registry.query( + // @ts-expect-error TODO: fix BlotConstructor + const ScrollBlot = this.options.registry.query( Parchment.ScrollBlot.blotName, - ); + ) as ScrollConstructor; this.scroll = new ScrollBlot(this.options.registry, this.root, { emitter: this.emitter, }); diff --git a/formats/table.ts b/formats/table.ts index 4f16b878b5..91e0dde2c0 100644 --- a/formats/table.ts +++ b/formats/table.ts @@ -24,6 +24,8 @@ class TableCell extends Block { return undefined; } + next: this | null; + cellOffset() { if (this.parent) { return this.parent.children.indexOf(this); @@ -56,15 +58,17 @@ class TableCell extends Block { } class TableRow extends Container { + static blotName = 'table-row'; + static tagName = 'TR'; + + children: LinkedList; + next: this | null; + checkMerge() { if (super.checkMerge() && this.next.children.head != null) { - // @ts-expect-error all children are table cells const thisHead = this.children.head.formats(); - // @ts-expect-error all children are table cells const thisTail = this.children.tail.formats(); - // @ts-expect-error all children are table cells const nextHead = this.next.children.head.formats(); - // @ts-expect-error all children are table cells const nextTail = this.next.children.tail.formats(); return ( thisHead.table === thisTail.table && @@ -78,10 +82,9 @@ class TableRow extends Container { optimize(...args) { // @ts-expect-error super.optimize(...args); - (this.children as LinkedList).forEach(child => { + this.children.forEach(child => { if (child.next == null) return; const childFormats = child.formats(); - // @ts-expect-error const nextFormats = child.next.formats(); if (childFormats.table !== nextFormats.table) { const next = this.splitAfter(child); @@ -109,14 +112,20 @@ class TableRow extends Container { return this.parent && this.parent.parent; } } -TableRow.blotName = 'table-row'; -TableRow.tagName = 'TR'; -class TableBody extends Container {} -TableBody.blotName = 'table-body'; -TableBody.tagName = 'TBODY'; +class TableBody extends Container { + static blotName = 'table-body'; + static tagName = 'TBODY'; + + children: LinkedList; +} class TableContainer extends Container { + static blotName = 'table-container'; + static tagName = 'TABLE'; + + children: LinkedList; + balanceCells() { // @ts-expect-error TODO: fix signature of ParentBlot.descendants const rows = this.descendants(TableRow) as TableRow[]; @@ -137,16 +146,16 @@ class TableContainer extends Container { }); } - cells(column) { + cells(column: number) { return this.rows().map(row => row.children.at(column)); } - deleteColumn(index) { + deleteColumn(index: number) { // @ts-expect-error const [body] = this.descendant(TableBody) as TableBody[]; if (body == null || body.children.head == null) return; body.children.forEach(row => { - const cell = (row as TableRow).children.at(index); + const cell = row.children.at(index); if (cell != null) { cell.remove(); } @@ -157,7 +166,7 @@ class TableContainer extends Container { // @ts-expect-error const [body] = this.descendant(TableBody) as TableBody[]; if (body == null || body.children.head == null) return; - (body.children as LinkedList).forEach(row => { + body.children.forEach(row => { const ref = row.children.at(index); const value = TableCell.formats(row.children.head.domNode); const cell = this.scroll.create(TableCell.blotName, value); @@ -171,7 +180,6 @@ class TableContainer extends Container { if (body == null || body.children.head == null) return; const id = tableId(); const row = this.scroll.create(TableRow.blotName) as TableRow; - // @ts-expect-error body.children.head.children.forEach(() => { const cell = this.scroll.create(TableCell.blotName, id); row.appendChild(cell); @@ -183,12 +191,9 @@ class TableContainer extends Container { rows() { const body = this.children.head; if (body == null) return []; - // @ts-expect-error return body.children.map(row => row); } } -TableContainer.blotName = 'table-container'; -TableContainer.tagName = 'TABLE'; TableContainer.allowedChildren = [TableBody]; TableBody.requiredContainer = TableContainer;