Skip to content

Commit

Permalink
style: add code style rules
Browse files Browse the repository at this point in the history
  • Loading branch information
zzxming committed Feb 7, 2025
1 parent 061a8b1 commit 9a7afb6
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 107 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"@typescript-eslint/parser": "^8.18.2",
"@vitest/coverage-v8": "^2.0.5",
"@vitest/ui": "^2.0.5",
"@zzxming/eslint-config": "^0.3.5",
"@zzxming/eslint-config": "^0.4.0",
"autoprefixer": "^10.4.19",
"eslint": "^9.17.0",
"gulp": "^4.0.0",
Expand Down
192 changes: 116 additions & 76 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/__tests__/unit/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ expect.extend({
interface TableColDeltaValue extends Omit<TableColValue, 'width' | 'full'> {
width: number;
full?: 'true';
};
}
interface TableCreatorOptions {
isEmpty: boolean;
tableId: string;
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ export class TableUp {
resizeOptions: {},
resizeScaleOptions: {},
} as TableUpOptions, options);
};
}

resolveTexts(options: Partial<TableTextOptions>) {
return Object.assign({
Expand All @@ -328,7 +328,7 @@ export class TableUp {
transparent: 'Transparent',
perWidthInsufficient: 'The percentage width is insufficient. To complete the operation, the table needs to be converted to a fixed width. Do you want to continue?',
}, options);
};
}

pasteTableHandler() {
let tableId = randomId();
Expand Down Expand Up @@ -590,7 +590,7 @@ export class TableUp {
dom.appendChild(isFulllLabel);
}
picker.options.appendChild(dom);
};
}

setCellAttrs(selectedTds: TableCellInnerFormat[], attr: string, value?: any, isStyle: boolean = false) {
if (selectedTds.length === 0) return;
Expand Down Expand Up @@ -1248,7 +1248,7 @@ export function updateTableConstants(data: Partial<TableConstantsData>) {
TableRowFormat.blotName = blotName.tableRow;
TableCellFormat.blotName = blotName.tableCell;
TableCellInnerFormat.blotName = blotName.tableCellInner;
};
}
export function defaultCustomSelect(tableModule: TableUp, picker: QuillThemePicker) {
return createSelectBox({
onSelect: (row: number, col: number) => {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/table-menu/table-menu-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class TableMenuCommon {
defaultColorMap,
}, options);
return value as TableMenuOptions;
};
}

getUsedColors() {
return usedColors;
Expand Down Expand Up @@ -116,7 +116,7 @@ export class TableMenuCommon {
toolBox.appendChild(item);
}
return toolBox;
};
}

createColorChoose(item: HTMLElement, { handle, key }: ToolOption) {
const colorSelectWrapper = document.createElement('div');
Expand Down
4 changes: 2 additions & 2 deletions src/modules/table-resize/table-resize-box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { isTableAlignRight } from './utils';
interface Point {
x: number;
y: number;
};
}
export class TableResizeBox extends TableResizeCommon {
root!: HTMLElement;
tableMain: TableMainFormat;
Expand Down Expand Up @@ -70,7 +70,7 @@ export class TableResizeBox extends TableResizeCommon {
tableSelection.selectedTds = tableSelection.computeSelectedTds(...currentBoundary);
tableSelection.show();
}
};
}

findCurrentColIndex(e: MouseEvent): number {
return Array.from(this.root.getElementsByClassName(this.bem.be('col-separator'))).indexOf(e.target as HTMLElement);
Expand Down
8 changes: 4 additions & 4 deletions src/modules/table-resize/table-resize-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class TableResizeCommon {
}

this.quill.emitter.emit(tableUpEvent.AFTER_TABLE_RESIZE);
};
}

handleColMouseMove(e: MouseEvent): { left: number; width: number } | undefined {
e.preventDefault();
Expand Down Expand Up @@ -213,7 +213,7 @@ export class TableResizeCommon {
left: resX,
width,
};
};
}

handleColMouseDown(e: MouseEvent): { top: number; left: number; height: number } | undefined {
if (e.button !== 0) return;
Expand Down Expand Up @@ -255,7 +255,7 @@ export class TableResizeCommon {
this.dragColBreak = divDom;

return styleValue;
};
}

findCurrentRowIndex(_e: MouseEvent) {
return -1;
Expand Down Expand Up @@ -336,7 +336,7 @@ export class TableResizeCommon {
this.dragRowBreak = divDom;

return styleValue;
};
}

update() {}
destroy() {}
Expand Down
4 changes: 2 additions & 2 deletions src/utils/color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ export interface HSB {
s: number;
b: number;
a: number;
};
}
export interface RGB {
r: number;
g: number;
b: number;
a: number;
};
}
const normalizeValue = function (value: number | string, max: number | string) {
value = Math.min(max as number, Math.max(0, Number.parseFloat(`${value}`)));

Expand Down
2 changes: 1 addition & 1 deletion src/utils/components/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isString } from '../is';
interface ButtonOptions {
type: 'confirm' | 'default';
content: HTMLElement | string;
};
}
export const createButton = (options?: Partial<ButtonOptions>) => {
const { type = 'default', content } = options || {};
const bem = createBEM('button');
Expand Down
2 changes: 1 addition & 1 deletion src/utils/components/color-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { HEXtoRGB, HSBtoHEX, HSBtoRGB, RGBtoHEX, RGBtoHSB, validateHSB } from '.
interface ColorPickerOptions {
color: string;
onChange: (color: string) => void;
};
}
export const createColorPicker = (options: Partial<ColorPickerOptions> = {}) => {
const contentWidth = 230;
const contentHeight = 150;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/components/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface InputOptions {
max?: number;
min?: number;
[key: string]: any;
};
}
export const createInputItem = (label: string, options: InputOptions) => {
const bem = createBEM('input');
options.type || (options.type = 'text');
Expand Down
2 changes: 1 addition & 1 deletion src/utils/components/tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export interface TooltipInstance {
destroy: () => void;
show: (force?: boolean) => void;
hide: (force?: boolean) => void;
};
}
export const createTooltip = (target: HTMLElement, options: ToolTipOptions = {}): TooltipInstance | null => {
const { msg = '', delay = 150, content, direction = 'bottom', type = 'hover', container, onOpen, onClose, closed, onDestroy } = options;
const bem = createBEM('tooltip');
Expand Down
14 changes: 7 additions & 7 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface TableMenuOptions {
tools: Tool[];
localstorageKey: string;
defaultColorMap: string[];
};
}
export interface TableSelectionOptions {
selectColor: string;
tableMenu?: Constructor<InternalModule, [TableUp, Quill, Partial<TableMenuOptions>]>;
Expand All @@ -43,7 +43,7 @@ export interface TableCreatorTextOptions {
colText: string;
notPositiveNumberError: string;
perWidthInsufficient: string;
};
}
export type TableMenuTexts = Record<string, string>;
export interface TableTextOptions extends TableCreatorTextOptions, TableMenuTexts {
custom: string;
Expand Down Expand Up @@ -75,15 +75,15 @@ export interface TableColValue {
width: string;
full?: boolean;
align?: string;
};
}
export interface TableCellValue {
tableId: string;
rowId: string;
colId: string;
rowspan: number;
colspan: number;
style?: string;
};
}
export interface TableRowValue {
tableId: string;
rowId: string;
Expand All @@ -92,7 +92,7 @@ export interface TableValue {
tableId: string;
full?: boolean;
align?: string;
};
}

export interface RelactiveRect {
x: number;
Expand All @@ -108,7 +108,7 @@ export interface InternalModule {
hide: () => void;
update: () => void;
destroy: () => void;
};
}
export type Constructor<T = any, U extends Array<any> = any[]> = new (...args: U) => T;
export interface InternalTableSelectionModule extends InternalModule {
dragging: boolean;
Expand All @@ -132,4 +132,4 @@ export interface TableConstantsData {
blotName: Record<string, string>;
tableUpSize: Record<string, number>;
tableUpEvent: Record<string, string>;
};
}
8 changes: 4 additions & 4 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface ParentBlotReturnMap {
[blotName.tableRow]: TableRowFormat;
[blotName.tableCell]: TableCellFormat;
[blotName.tableCellInner]: TableCellInnerFormat;
};
}
type ParentBlotReturn = {
[key: string]: TypeParchment.Parent;
} & ParentBlotReturnMap;
Expand Down Expand Up @@ -82,7 +82,7 @@ function mixinProps<T = any, U = any>(target: T, source: U) {
Object.defineProperty(target, prop, Object.getOwnPropertyDescriptor(source, prop)!);
}
return target as typeof target & Omit<typeof source, 'constructor'>;
};
}
export function mixinClass<
T extends Constructor,
U extends Constructor[],
Expand All @@ -100,7 +100,7 @@ export function mixinClass<
}

return targetClass;
};
}

const viewportPadding = 8;
export const limitDomInViewPort = (rect: { left: number; top: number; width: number; height: number }) => {
Expand Down Expand Up @@ -134,7 +134,7 @@ export const limitDomInViewPort = (rect: { left: number; top: number; width: num

interface ScrollHandle {
scrollHandler: [HTMLElement, (e: Event) => void][];
};
}
export function addScrollEvent(this: ScrollHandle, dom: HTMLElement, handle: (e: Event) => void) {
dom.addEventListener('scroll', handle);
this.scrollHandler.push([dom, handle]);
Expand Down

0 comments on commit 9a7afb6

Please sign in to comment.