Skip to content

Commit

Permalink
fix: typescript check error in ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Jocs committed Jan 14, 2024
1 parent 7c9834e commit eb064da
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 43 deletions.
13 changes: 7 additions & 6 deletions packages/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Muya from '@muya/index';
import { buildRegexValue, matchString } from '@muya/utils/search';
import { Highlight } from '../inlineRenderer/types';
import { IMatch } from './types';
import TreeNode from '@muya/block/base/treeNode';

class Search {
public value: string = '';
Expand All @@ -16,7 +17,7 @@ class Search {

constructor(public muya: Muya) {}

private updateMatches(isClear = false) {
private _updateMatches(isClear = false) {
const { matches, index } = this;
let i;
const len = matches.length;
Expand Down Expand Up @@ -132,8 +133,8 @@ class Search {

this.index = index;

this.updateMatches(true);
this.updateMatches();
this._updateMatches(true);
this._updateMatches();

return this;
}
Expand All @@ -150,11 +151,11 @@ class Search {
let index = -1;

// Empty last search.
this.updateMatches(true);
this._updateMatches(true);

// Highlight current search.
if (value) {
this.scrollPage.depthFirstTraverse((block) => {
this.scrollPage.depthFirstTraverse((block: TreeNode) => {
if (block.isContent()) {
const { text } = block;
if (text && typeof text === 'string') {
Expand Down Expand Up @@ -185,7 +186,7 @@ class Search {

Object.assign(this, { value, matches, index });

this.updateMatches();
this._updateMatches();

return this;
}
Expand Down
23 changes: 12 additions & 11 deletions packages/state/markdownToState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ const DEFAULT_OPTIONS = {
};

class MarkdownToState {
constructor(private options: MarkdownToStateOptions = DEFAULT_OPTIONS) {}
constructor(private _options: MarkdownToStateOptions = DEFAULT_OPTIONS) {}

generate(markdown: string): TState[] {
return this.convertMarkdownToState(markdown);
return this._convertMarkdownToState(markdown);
}

convertMarkdownToState(markdown: string): TState[] {
private _convertMarkdownToState(markdown: string): TState[] {
const {
footnote = false,
math = true,
isGitlabCompatibilityEnabled = true,
trimUnnecessaryCodeBlockEmptyLines = false,
frontMatter = true,
} = this.options;
} = this._options;

const tokens = lexBlock(markdown, {
footnote,
Expand Down Expand Up @@ -198,13 +198,13 @@ class MarkdownToState {
const isSingleImage = /^<img[^<>]+>$/.test(text);
if (isSingleImage) {
state = {
name: 'paragraph',
name: 'paragraph' as const,
text,
};
parentList[0].push(state);
} else {
state = {
name: 'html-block',
name: 'html-block' as const,
text,
};
parentList[0].push(state);
Expand All @@ -216,7 +216,7 @@ class MarkdownToState {
const text = token.text.trim();
const { mathStyle = '' } = token;
const state = {
name: 'math-block',
name: 'math-block' as const,
text,
meta: { mathStyle },
};
Expand All @@ -241,7 +241,7 @@ class MarkdownToState {
case 'paragraph': {
value = token.text;
state = {
name: 'paragraph',
name: 'paragraph' as const,
text: value,
};
parentList[0].push(state);
Expand All @@ -250,7 +250,7 @@ class MarkdownToState {

case 'blockquote': {
state = {
name: 'block-quote',
name: 'block-quote' as const,
children: [],
};
parentList[0].push(state);
Expand All @@ -262,10 +262,11 @@ class MarkdownToState {

case 'list': {
const { listType, loose, start } = token;
const bulletMarkerOrDelimiter = token.items[0].bulletMarkerOrDelimiter;
const bulletMarkerOrDelimiter =
token.items[0].bulletMarkerOrDelimiter;
const meta: any = {
loose,
}
};
if (listType === 'order') {
meta.start = /^\d+$/.test(start) ? start : 1;
meta.delimiter = bulletMarkerOrDelimiter || '.';
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/baseScrollFloat/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract class BaseScrollFloat extends BaseFloat {
}
}

listen() {
override listen() {
super.listen();
const { eventCenter, domNode } = this.muya;
const handler = (event: Event) => {
Expand Down Expand Up @@ -61,12 +61,12 @@ abstract class BaseScrollFloat extends BaseFloat {
eventCenter.attachDOMEvent(domNode, 'keydown', handler);
}

hide() {
override hide() {
super.hide();
this.reference = null;
}

show(reference: Element | ReferenceObject, cb: (...args: unknown[]) => void = noop) {
override show(reference: Element | ReferenceObject, cb: (...args: unknown[]) => void = noop) {
this.cb = cb;

if (reference instanceof HTMLElement) {
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/codeBlockLanguageSelector/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CodePicker extends BaseScrollFloat {
this.listen();
}

listen() {
override listen() {
super.listen();
const { eventCenter } = this.muya;

Expand Down Expand Up @@ -135,7 +135,7 @@ class CodePicker extends BaseScrollFloat {
return this.floatBox!.querySelector(`[data-label="${name}"]`)!;
}

selectItem(item: { name: string }) {
override selectItem(item: { name: string }) {
const { block, muya } = this;
const { name } = item;

Expand Down
8 changes: 4 additions & 4 deletions packages/ui/emojiSelector/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class EmojiSelector extends BaseScrollFloat {
private _renderObj: Record<string, EmojiType[]> | null = null;
private oldVNode: VNode | null = null;
private emoji: Emoji = new Emoji();
public renderArray: EmojiType[] = [];
public activeItem: EmojiType | null = null;
public override renderArray: EmojiType[] = [];
public override activeItem: EmojiType | null = null;

constructor(muya: Muya) {
const name = 'mu-emoji-picker';
Expand All @@ -50,7 +50,7 @@ class EmojiSelector extends BaseScrollFloat {
}
}

listen() {
override listen() {
super.listen();
const { eventCenter } = this.muya;
eventCenter.on('muya-emoji-picker', ({ reference, emojiText, block }) => {
Expand Down Expand Up @@ -118,7 +118,7 @@ class EmojiSelector extends BaseScrollFloat {
return this.floatBox!.querySelector(`[data-label="${label}"]`) as HTMLElement;
}

destroy() {
override destroy() {
super.destroy();
this.emoji.destroy();
}
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/imageEditTool/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const defaultOptions = {
};

class ImageEditTool extends BaseFloat {
public options: Options;
public override options: Options;
static pluginName = 'imageSelector';
private oldVNode: VNode | null = null;
private imageInfo: {
Expand All @@ -59,7 +59,7 @@ class ImageEditTool extends BaseFloat {
this.listen();
}

listen() {
override listen() {
super.listen();
const { eventCenter } = this.muya;
eventCenter.on('muya-image-selector', ({ block, reference, imageInfo }) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/imageToolbar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ImageToolbar extends BaseFloat {
this.listen();
}

listen() {
override listen() {
const { eventCenter } = this.muya;
super.listen();
eventCenter.on('muya-image-toolbar', ({ block, reference, imageInfo }) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/inlineFormatToolbar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class FormatPicker extends BaseFloat {
private oldVNode: VNode | null = null;
private block: Format | null = null;
private formats: Token[] = [];
public options: BaseOptions;
public override options: BaseOptions;
private icons: FormatToolIcon[] = icons;
private formatContainer: HTMLDivElement = document.createElement('div');

Expand All @@ -40,7 +40,7 @@ class FormatPicker extends BaseFloat {
this.listen();
}

listen() {
override listen() {
const { eventCenter, domNode, editor } = this.muya;
super.listen();
eventCenter.subscribe('muya-format-picker', ({ reference, block }) => {
Expand Down
3 changes: 3 additions & 0 deletions packages/ui/linkTools/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck

import BaseFloat from '../baseFloat';
import { patch, h } from '@muya/utils/snabbdom';
import icons from './config';
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/paragraphFrontMenu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class FrontMenu extends BaseFloat {
this.listen();
}

listen() {
override listen() {
const { container } = this;
const { eventCenter } = this.muya;
super.listen();
Expand Down
10 changes: 5 additions & 5 deletions packages/ui/paragraphQuickInsertMenu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class QuickInsert extends BaseScrollFloat {

public oldVNode: VNode | null = null;
public block: ParagraphContent | null = null;
public activeItem: QuickInsertMenuItem['children'][number] | null = null;
public override activeItem: QuickInsertMenuItem['children'][number] | null = null;
private _renderData: QuickInsertMenuItem[] = [];
// private renderArray: QuickInsertMenuItem["children"][number] = [];

Expand Down Expand Up @@ -61,7 +61,7 @@ class QuickInsert extends BaseScrollFloat {
}
}

listen() {
override listen() {
super.listen();
const { eventCenter, editor, domNode, i18n } = this.muya;

Expand Down Expand Up @@ -101,7 +101,7 @@ class QuickInsert extends BaseScrollFloat {
event.preventDefault();
replaceBlockByLabel({
label,
block: anchorBlock.parent,
block: anchorBlock.parent!,
muya: this.muya,
});
}
Expand Down Expand Up @@ -225,11 +225,11 @@ class QuickInsert extends BaseScrollFloat {
this.render();
}

selectItem({ label }: QuickInsertMenuItem['children'][number]) {
override selectItem({ label }: QuickInsertMenuItem['children'][number]) {
const { block, muya } = this;
replaceBlockByLabel({
label,
block: block!.parent,
block: block!.parent!,
muya,
});
// delay hide to avoid dispatch enter handler
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/previewToolBar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PreviewTools extends BaseFloat {
this.listen();
}

listen() {
override listen() {
const { eventCenter } = this.muya;
super.listen();

Expand Down
4 changes: 4 additions & 0 deletions packages/ui/tableChessboard/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck
import BaseFloat from '../baseFloat';
import { patch, h } from '@muya/utils/snabbdom';
import { EVENT_KEYS } from '@muya/config';
Expand Down Expand Up @@ -76,6 +78,7 @@ class TablePicker extends BaseFloat {
this.select = { row: r, column: c };
this.render();
},
// eslint-disable-next-line @typescript-eslint/no-unused-vars
click: (_) => {
this.selectItem();
},
Expand Down Expand Up @@ -115,6 +118,7 @@ class TablePicker extends BaseFloat {
'button',
{
on: {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
click: (_) => {
this.selectItem();
},
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/tableColumnToolbar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TableColumnTools extends BaseFloat {
this.listen();
}

listen() {
override listen() {
const { eventCenter } = this.muya;
super.listen();

Expand Down Expand Up @@ -150,7 +150,7 @@ class TableColumnTools extends BaseFloat {
}
const offset = block.parent.offset(block);
const { table, row } = block;
const columnCount = row.offset(this.block);
const columnCount = row.offset(this.block!);

switch (item.type) {
case 'remove': {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/tableDragBar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class TableDragBar extends BaseFloat {
this.listen();
}

listen() {
override listen() {
const { eventCenter } = this.muya;
const { container } = this;
super.listen();
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/tableRowColumMenu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TableBarTools extends BaseFloat {
this.listen();
}

listen() {
override listen() {
super.listen();
const { eventCenter } = this.muya;
eventCenter.subscribe(
Expand Down Expand Up @@ -98,7 +98,7 @@ class TableBarTools extends BaseFloat {

const { table, row } = this.block!;
const rowCount = (table.firstChild as TableInner).offset(row);
const columnCount = row.offset(this.block);
const columnCount = row.offset(this.block!);
const { location, action, target } = item;

if (action === 'insert') {
Expand Down
3 changes: 3 additions & 0 deletions packages/ui/tooltip/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-nocheck

import './index.css';
import Muya from '../../index';

Expand Down

0 comments on commit eb064da

Please sign in to comment.